Changeset 5106


Ignore:
Timestamp:
Sep 4, 2006, 4:04:41 PM (18 years ago)
Author:
Gary Byers
Message:

Use (UNSIGNED-BYTE 8) for array element type of rdtab.ttab.

Don't treat (code-char #xca) as whitespace; do treat (code-char #xa0)
as whitespace. (The former happens to be how the latter was encoded
in MacRoman.)

Handle U+<hex> syntax in NAME-CHAR.

File:
1 edited

Legend:

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

    r5050 r5106  
    2525
    2626;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     27
    2728
    2829(defparameter *name-char-alist*
     
    6061;;;Otherwise, if it consists of two chars, the first of which  is ^,
    6162;;; return %code-char(c xor 64), where c is the uppercased second char.
    62 ;;;Otherwise, if it consists of octal digits, the digits are
    63 ;;; interpreted as the (mod 256) ascii code of a character.
     63;;;Otherwise, if it starts with the prefix "u+" or "U+" followed by
     64;;; hex digits, the number denoted by those hex digits is interpreted as the
     65;;; unicode code of the character; if this value is less than
     66;;; CHAR-CODE-LIMIT, CODE-CHAR of that value is returned.
     67;;;Otherwise, if it consists of octal digits, the number denoted by
     68;;;  those octal digits is interpreted as per the U+ case above.
    6469;;;Otherwise return NIL.
    6570
     
    7378        (declare (fixnum namelen))
    7479        (or (cdr (assoc name *name-char-alist* :test #'string-equal))
    75          (if (= namelen 1)
    76            (char name 0)
    77            (if (and (= namelen 2) (eq (char name 0) #\^))
    78              (code-char (the fixnum (logxor (the fixnum (char-code (char-upcase (char name 1)))) #x40)))
    79              (let* ((n 0))
    80                (dotimes (i namelen (code-char (logand n (1- char-code-limit))))
    81                  (let* ((code (the fixnum (- (the fixnum (char-code (char name i)))
    82                                              (char-code #\0)))))
    83                    (declare (fixnum code))
    84                    (if (and (>= code 0)
    85                             (<= code 7))
    86                      (setq n (logior code (the fixnum (ash n 3))))
    87                      (return))))))))))))
     80            (if (= namelen 1)
     81              (char name 0)
     82              (if (and (= namelen 2) (eq (char name 0) #\^))
     83                (code-char (the fixnum (logxor (the fixnum (char-code (char-upcase (char name 1)))) #x40)))
     84                (let* ((n 0))
     85                  (or
     86                   (if (and (> namelen 2)
     87                            (or (eql (char name 0) #\U)
     88                                (eql (char name 0) #\u))
     89                            (eql (char name 1) #\+))
     90                     (do* ((i 2 (1+ i)))
     91                          ((= i namelen) (if (< n char-code-limit)
     92                                           (code-char n)))
     93                       (declare (fixnum i))
     94                       (let* ((pos (position (char-upcase (char name i))
     95                                             "0123456789ABCDEF")))
     96                         (if pos
     97                           (setq n (logior (ash n 4) pos))
     98                           (progn
     99                             (setq n 0)
     100                             (return))))))
     101                   (dotimes (i namelen (code-char (mod n char-code-limit)))
     102                     (let* ((code (the fixnum (- (the fixnum (char-code (char name i)))
     103                                                 (char-code #\0)))))
     104                       (declare (fixnum code))
     105                       (if (and (>= code 0)
     106                                (<= code 7))
     107                         (setq n (logior code (the fixnum (ash n 3))))
     108                         (return)))))))))))))
    88109
    89110(eval-when (:compile-toplevel :load-toplevel :execute)
     
    94115                      (set-schar str 3 #\^@)
    95116                      (set-schar str 4 #\^J)
    96                       (set-schar str 5 (%code-char #xCA))
     117                      (set-schar str 5 (code-char #xa0))
    97118                      str))
    98119
     
    104125                        (set-schar str 4 #\^@)
    105126                        (set-schar str 5 #\^J)
    106                         (set-schar str 6 (%code-char #xCA))
     127                        (set-schar str 6 (code-char #xa0))
    107128                        str))
    108129)
     
    165186;;; This -really- gets initialized later in the file
    166187(defvar %initial-readtable%
    167   (let* ((ttab (make-array 256 :element-type '(signed-byte 8)))
     188  (let* ((ttab (make-array 256 :element-type '(unsigned-byte 8)))
    168189         (macs `((#\# . (,#'read-dispatch))))
    169190         (case :upcase))
     
    187208             (readtable-arg to)
    188209             (%istruct 'readtable
    189                         (make-array 256 :element-type '(signed-byte 8))
     210                        (make-array 256 :element-type '(unsigned-byte 8))
    190211                         nil (rdtab.case from))))
    191212  (setf (rdtab.alist to) (copy-tree (rdtab.alist from)))
     
    193214  (let* ((fttab (rdtab.ttab from))
    194215         (tttab (rdtab.ttab to)))
    195     (dotimes (i 256 to)
    196       (setf (uvref tttab i) (uvref fttab i)))))
     216    (%copy-ivector-to-ivector fttab 0 tttab 0 257)))
    197217
    198218(declaim (inline %character-attribute))
     
    200220(defun %character-attribute (char attrtab)
    201221  (declare (character char)
    202            (type (simple-array (signed-byte 8) (*)) attrtab)
     222           (type (simple-array (unsigned-byte 8) (256)) attrtab)
    203223           (optimize (speed 3) (safety 0)))
    204224  (let* ((code (char-code char)))
    205225    (declare (fixnum code))
    206     (aref attrtab code)))
     226    (if (< code 256)
     227      (aref attrtab code)
     228      ;; Should probably have an extension mechanism for things
     229      ;; like NBS.
     230      $cht_cnst)))
    207231
    208232;;; returns: (values attrib <aux-info>), where
Note: See TracChangeset for help on using the changeset viewer.