Changeset 11406
- Timestamp:
- 11/30/08 20:46:59 (12 years ago)
- Location:
- branches/open-external-format/src/org/armedbear/lisp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/open-external-format/src/org/armedbear/lisp/FileStream.java
r11403 r11406 55 55 private Writer writer; 56 56 57 public enum EolStyle {58 CR,59 CRLF,60 LF61 }62 63 static final private Symbol keywordCodePage = Packages.internKeyword("CODE-PAGE");64 65 private final static EolStyle platformEolStyle = Utilities.isPlatformWindows ? EolStyle.CRLF : EolStyle.LF;66 67 private EolStyle eolStyle = platformEolStyle;68 private char eolChar = 0;69 70 57 public FileStream(Pathname pathname, String namestring, 71 58 LispObject elementType, LispObject direction, 72 LispObject ifExists, String encoding, EolStyle eol)59 LispObject ifExists, LispObject format) 73 60 throws IOException 74 61 { … … 115 102 } 116 103 } 104 setExternalFormat(format); 105 117 106 // don't touch raf directly after passing it to racf. 118 107 // the state will become inconsistent if you do that. … … 147 136 } 148 137 } 149 eolChar = (eol == EolStyle.CR) ? '\r' : '\n';150 138 } 151 139 … … 296 284 } 297 285 298 286 @Override 299 287 public void _writeChars(char[] chars, int start, int end) 300 288 throws ConditionThrowable { … … 498 486 LispObject externalFormat = sixth; 499 487 500 String encoding = "ISO-8859-1";501 if (externalFormat != NIL) {502 if (externalFormat instanceof Symbol) {503 Symbol enc = (Symbol)externalFormat; //FIXME: class cast exception to be caught504 if (enc != NIL) {505 if (enc != keywordCodePage) {506 encoding = enc.getName();507 }508 //FIXME: the else for the keywordCodePage to be filled in509 }510 //FIXME: the else for the == NIL to be filled in: raise an error...511 } else if (externalFormat instanceof AbstractString) {512 AbstractString encName = (AbstractString) externalFormat;513 encoding = encName.getStringValue();514 }515 }516 517 518 488 if (direction != Keyword.INPUT && direction != Keyword.OUTPUT && 519 489 direction != Keyword.IO) … … 522 492 return new FileStream(pathname, namestring.getStringValue(), 523 493 elementType, direction, ifExists, 524 e ncoding, platformEolStyle);494 externalFormat); 525 495 } 526 496 catch (FileNotFoundException e) { -
branches/open-external-format/src/org/armedbear/lisp/Stream.java
r11404 r11406 81 81 protected int charPos; 82 82 83 public enum EolStyle { 84 RAW, 85 CR, 86 CRLF, 87 LF 88 } 89 90 static final private Symbol keywordDefault = Packages.internKeyword("DEFAULT"); 91 92 static final private Symbol keywordCodePage = Packages.internKeyword("CODE-PAGE"); 93 static final private Symbol keywordID = Packages.internKeyword("ID"); 94 95 static final private Symbol keywordEolStyle = Packages.internKeyword("EOL-STYLE"); 96 static final private Symbol keywordCR = Packages.internKeyword("CR"); 97 static final private Symbol keywordLF = Packages.internKeyword("LF"); 98 static final private Symbol keywordCRLF = Packages.internKeyword("CRLF"); 99 static final private Symbol keywordRAW = Packages.internKeyword("RAW"); 100 101 public final static EolStyle platformEolStyle = Utilities.isPlatformWindows ? EolStyle.CRLF : EolStyle.LF; 102 103 protected EolStyle eolStyle = platformEolStyle; 104 protected char eolChar = 0; 105 protected LispObject externalFormat = LispObject.NIL; 106 protected String encoding = null; 107 83 108 // Binary input. 84 109 private BufferedInputStream in; … … 216 241 } 217 242 243 public LispObject getExternalFormat() { 244 return externalFormat; 245 } 246 247 public String getEncoding() { 248 return encoding; 249 } 250 251 public void setExternalFormat(LispObject format) { 252 if (format == keywordDefault) { 253 encoding = null; 254 eolStyle = platformEolStyle; 255 eolChar = (eolStyle == EolStyle.CR) ? '\r' : '\n'; 256 externalFormat = format; 257 258 return; 259 } 260 261 try { 262 LispObject enc; 263 boolean encIsCp = false; 264 265 if (format instanceof Cons) { 266 // meaning a non-empty list 267 enc = format.car(); 268 269 if (enc == keywordCodePage) { 270 encIsCp = true; 271 272 enc = LispObject.getf(format.cdr(), keywordID, null); 273 } 274 275 LispObject eol = LispObject.getf(format.cdr(), keywordEolStyle, keywordRAW); 276 if (eol == keywordCR) 277 eolStyle = EolStyle.CR; 278 else if (eol == keywordLF) 279 eolStyle = EolStyle.LF; 280 else if (eol == keywordCRLF) 281 eolStyle = EolStyle.CRLF; 282 else if (eol != keywordRAW) 283 //###FIXME: raise an error 284 ; 285 286 } else 287 enc = format; 288 289 if (enc.numberp()) 290 encoding = enc.toString(); 291 else if (enc instanceof AbstractString) 292 encoding = enc.getStringValue(); 293 else if (enc instanceof Symbol) 294 encoding = ((Symbol)enc).getName(); 295 else 296 //###FIXME: raise an error! 297 ; 298 299 if (encIsCp) 300 encoding = "Cp" + encoding; 301 } 302 catch (ConditionThrowable ct) { } 303 304 eolChar = (eolStyle == EolStyle.CR) ? '\r' : '\n'; 305 externalFormat = format; 306 } 307 218 308 public boolean isOpen() 219 309 {
Note: See TracChangeset
for help on using the changeset viewer.