Changeset 71 for lang/elisp/pdicv-mode/trunk/nt-readval.el
- Timestamp:
- 01/30/09 23:52:02 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/elisp/pdicv-mode/trunk/nt-readval.el
r67 r71 1 1 ;;; nt-readval.el --- read value or a string from buffer 2 2 ;; 3 ;; Copyright (C) 2005 Naoya TOZUKA. All Rights Reserved.3 ;; Copyright (C) 2005-2009 naoya_t. All Rights Reserved. 4 4 ;; 5 ;; Author: Naoya TOZUKA <pdicviewer@gmail.com> 6 ;; Maintainer: Naoya TOZUKA <pdicviewer@gmail.com> 7 ;; Primary distribution site: http://pdicviewer.naochan.com/el/ 5 ;; Author: naoya_t <naoya.t@aqua.plala.or.jp> 6 ;; Maintainer: naoya_t <naoya.t@aqua.plala.or.jp> 7 ;; Primary distribution site: 8 ;; http://lambdarepos.svnrepository.com/svn/share/lang/elisp/pdicv-mode/trunk 8 9 ;; 9 10 ;; Created: 06 Feb 2005 … … 29 30 (if (not index) (setq index 0)) 30 31 (if (or (< index 0) (<= (length s) index)) (throw 'uchar 'out-of-bounds-exception)) 31 (aref s index) 32 ) 33 ) 32 (aref s index))) 34 33 35 34 ;;=========================================================== … … 48 47 (if (or (< index 0) (<= (length s) index)) (throw 'char 'out-of-bounds-exception)) 49 48 (setq c (aref s index)) 50 (if (< c 128) c (- c 256)) ; =result 51 ); let 52 ); caught 53 ) 49 (if (< c 128) c (- c 256))))) ; =result 54 50 55 51 ;;============================================================== … … 63 59 (if (or (< index 0) (< (- (length s) 2) index)) (throw 'ushort 'out-of-bounds-exception)) 64 60 (+ (lsh (aref s (1+ index)) 8) 65 (aref s index)) 66 ) 67 ) 61 (aref s index)))) 68 62 69 63 (defsubst nt:read-ushort-bigendian (s &optional index) … … 73 67 (if (or (< index 0) (< (- (length s) 2) index)) (throw 'ushort 'out-of-bounds-exception)) 74 68 (+ (lsh (aref s index) 8) 75 (aref s (1+ index))) 76 ) 77 ) 69 (aref s (1+ index))))) 78 70 79 71 (defmacro nt:read-ushort-littleendian (s &optional index) … … 90 82 (let ((us (nt:read-ushort s index))) 91 83 (if (eq us 'out-of-bounds-exception) (throw 'short us)) 92 (if (< us 32768) us (- us 65536)) 93 ) ; let 94 );caught 95 ) 84 (if (< us 32768) us (- us 65536))))) 96 85 97 86 (defsubst nt:read-short-bigendian (s &optional index) … … 100 89 (let ((us (nt:read-ushort-bigendian s index))) 101 90 (if (eq us 'out-of-bounds-exception) (throw 'short us)) 102 (if (< us 32768) us (- us 65536)) 103 ) ; let 104 ) 105 ) 91 (if (< us 32768) us (- us 65536))))) 106 92 107 93 (defmacro nt:read-short-littleendian (s &optional index) … … 123 109 (if (or (< index 0) (< (- (length s) 4) index)) (throw 'long 'out-of-bounds-exception)) 124 110 125 (let* ( 126 (hh (aref s (+ index 3))) 127 (h0 (lsh hh -4)) 128 ) 129 111 (let* ((hh (aref s (+ index 3))) 112 (h0 (lsh hh -4))) 130 113 (cond ((zerop h0) nil) ; plus 131 114 ((= h0 15) nil) ; minus 132 115 ; (t (setq hh (logand 15 hh))) 133 116 ((< h0 8) (throw 'long 'overflow-exception)) 134 ((>= h0 8) (throw 'long 'underflow-exception)) 135 ) 117 ((>= h0 8) (throw 'long 'underflow-exception))) 136 118 ; (logior (lsh (aref s (+ index 3)) 24) 137 119 (logior (lsh hh 24) 138 120 (lsh (aref s (+ index 2)) 16) 139 121 (lsh (aref s (1+ index)) 8) 140 (aref s index)) 141 ) 142 ) 143 ) 122 (aref s index))))) 144 123 145 124 (defsubst nt:read-long-bigendian (s &optional index) … … 150 129 (if (or (< index 0) (< (- (length s) 4) index)) (throw 'long 'out-of-bounds-exception)) 151 130 152 (let* ( 153 (hh (aref s index)) 154 (h0 (lsh hh -4)) 155 ) 156 131 (let* ((hh (aref s index)) 132 (h0 (lsh hh -4))) 157 133 (cond ((zerop h0) nil) ; plus 158 134 ((= h0 15) nil) ; minus 159 135 ; (t (setq hh (logand 15 hh))) 160 136 ((< h0 8) (throw 'long 'overflow-exception)) 161 ((>= h0 8) (throw 'long 'underflow-exception)) 162 ) 137 ((>= h0 8) (throw 'long 'underflow-exception))) 163 138 ; (logior (lsh (aref s (+ index 3)) 24) 164 139 (logior (lsh hh 24) 165 140 (lsh (aref s (1+ index)) 16) 166 141 (lsh (aref s (+ index 2)) 8) 167 (aref s (+ index 3))) 168 ) 169 ) 170 ) 142 (aref s (+ index 3)))))) 171 143 172 144 (defmacro nt:read-long-littleendian (s &optional index) … … 188 160 (if (or (< index 0) (< (- (length s) 4) index)) (throw 'ulong 'out-of-bounds-exception)) 189 161 190 (let* ( 191 (hh (aref s (+ index 3))) 192 (h0 (lsh hh -4)) 193 ) 194 162 (let* ((hh (aref s (+ index 3))) 163 (h0 (lsh hh -4))) 195 164 (cond ((zerop h0) nil) ; plus 196 165 ; (t (setq hh (logand 15 hh))) … … 200 169 (lsh (aref s (+ index 2)) 16) 201 170 (lsh (aref s (1+ index)) 8) 202 (aref s index)) 203 ) 204 ) 205 206 ; (let ((sl (long s index))) 207 ; (if (>= sl 0) sl 0) 208 ; ) 209 ) 171 (aref s index))))) 210 172 211 173 (defsubst nt:read-ulong-bigendian (s &optional index) … … 216 178 (if (or (< index 0) (< (- (length s) 4) index)) (throw 'ulong 'out-of-bounds-exception)) 217 179 218 (let* ( 219 (hh (aref s index)) 220 (h0 (lsh hh -4)) 221 ) 222 180 (let* ((hh (aref s index)) 181 (h0 (lsh hh -4))) 223 182 (cond ((zerop h0) nil) ; plus 224 183 ; (t (setq hh (logand 15 hh))) … … 228 187 (lsh (aref s (1+ index)) 16) 229 188 (lsh (aref s (+ index 2)) 8) 230 (aref s (+ index 3))) 231 ) 232 ) 233 234 ; (let ((sl (long s index))) 235 ; (if (>= sl 0) sl 0) 236 ; ) 237 ) 189 (aref s (+ index 3)))))) 238 190 239 191 (defmacro nt:read-ulong-littleendian (s &optional index) … … 255 207 ; (if (> ofs-max 248) (setq ofs-max 248)) 256 208 (while (< ofs ofs-max) 257 (if (zerop (aref s (+ index ofs))) 258 (throw 'cstring (cons (substring s index (+ index ofs)) ofs) ) 259 ) 260 (setq ofs (1+ ofs)) 261 ) 262 (cons (substring s index nil) ofs-max) 263 ) 264 ) 265 ) 209 (if (zerop (aref s (+ index ofs))) 210 (throw 'cstring (cons (substring s index (+ index ofs)) ofs) )) 211 (setq ofs (1+ ofs))) 212 (cons (substring s index nil) ofs-max)))) 266 213 267 214 ;;============================================== … … 278 225 (size (nt:read-uchar s index)) ) 279 226 (if (> (1+ size) ofs-max) (throw 'pstring 'out-of-bounds-exception)) 280 (throw 'pstring (cons (substring s (1+ index) (+ index 1 size)) size) ) 281 ); let 282 ); caught 283 ) 227 (throw 'pstring (cons (substring s (1+ index) (+ index 1 size)) size) )))) 284 228 285 229 (defsubst nt:read-bcd (s ofs bytes) … … 289 233 (setq c (aref s (+ ofs i))) 290 234 (setq n (+ (* n 100) (* (lsh c -4) 10) (logand c #x0f))) 291 (setq i (1+ i)) ;; (++ i) 292 );wend 293 n 294 );let 295 ) 235 (setq i (1+ i))) ;; (++ i) 236 n)) 296 237 297 238 ;;; nt-readval.el ends here