Changeset 12409 for trunk/source/level-1


Ignore:
Timestamp:
Jul 14, 2009, 2:37:27 PM (10 years ago)
Author:
gb
Message:

Yoshinori Tahara's fix to handle CRLF line-termination.
Use STREAM-POSITION rather than FILE-POSITION, so that this might work
on other kinds of seekable streams (STRING-STREAMs, etc.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-1/l1-reader.lisp

    r12300 r12409  
    24812481         (attrtab (rdtab.ttab readtable))
    24822482         (attr (%character-attribute firstchar attrtab))
    2483          (start-pos (file-position stream)))
     2483         (start-pos (stream-position stream)))
    24842484    (declare (fixnum attr))
    24852485    (when (eql attr $cht_ill)
     
    24992499                                (funcall (car def) stream firstchar))
    25002500                               (t (error "Bogus default dispatch fn: ~S" (car def)) nil))))))
    2501            (end-pos (and start-pos (file-position stream))))
     2501           (end-pos (and start-pos (stream-position stream))))
    25022502      (declare (dynamic-extent vals)
    25032503               (list vals))
     
    31383138           (values form source-note))))
    31393139    (T
    3140        (let* ((start-pos (file-position stream))
     3140       (let* ((start-pos (stream-position stream))
    31413141              (form (read-internal stream nil eofval nil))
    3142               (end-pos (and start-pos (neq form eofval) (file-position stream)))
     3142              (end-pos (and start-pos (neq form eofval) (stream-position stream)))
    31433143              (source-note (and end-pos
    31443144                                (make-source-note :filename file-name
     
    31553155  (declare (fixnum start-offset))
    31563156  (when (< start-offset end-offset)
    3157     (let* ((cur-pos (file-position stream))
     3157    (let* ((cur-pos (stream-position stream))
    31583158           (noctets (- end-offset start-offset))
    31593159           (vec (make-array noctets :element-type '(unsigned-byte 8)))
    3160            (index 0))
     3160           (index 0)
     3161           (crlfp (eq :crlf
     3162                      (cdr (assoc (external-format-line-termination
     3163                                   (stream-external-format stream))
     3164                                  *canonical-line-termination-conventions*)))))
    31613165      (declare (type fixnum end-offset noctets index)
    31623166               (type (simple-array (unsigned-byte 8) (*)) vec))
     
    31653169                      (setf (aref vec index) ,code)
    31663170                      (when (eql (incf index) noctets) (return)))))
    3167         (file-position stream start-offset)
     3171        (stream-position stream start-offset)
    31683172        (loop
    3169           (let ((code (char-code (stream-read-char stream))))
     3173          (let ((code (char-code (read-char stream))))
    31703174            (declare (fixnum code))
    31713175            (cond ((< code #x80)
     3176                   (when (and crlfp (= code (char-code #\NewLine)))
     3177                     (out (char-code #\Return)))
    31723178                   (out code))
    31733179                  ((< code #x800)
     
    31833189                   (out (logior #x80 (ldb (byte 6 6) code)))
    31843190                   (out (logior #x80 (ldb (byte 6 0) code))))))))
    3185       (file-position stream cur-pos)
     3191      (stream-position stream cur-pos)
    31863192      vec)))
    31873193
Note: See TracChangeset for help on using the changeset viewer.