From: plugd Date: Mon, 10 Apr 2023 08:18:04 +0000 (+0200) Subject: Dictionary parsing and Z-string decoding. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=ez.git;a=commitdiff_plain;h=923646120250ac9d0987e521e8d835809a64aa6c Dictionary parsing and Z-string decoding. --- diff --git a/ez.el b/ez.el index 268becd..a4cf5e7 100644 --- a/ez.el +++ b/ez.el @@ -294,31 +294,50 @@ (chars (cdr word-count-and-chars)) (cur 0) (lock 0) - (abbrev-char nil) (s "")) - (dolist (char chars) - (cond - (abbrev-char - (let ((abbrev-addr - (* 2 (ez-mem-ref-word (+ ez-abbrevtab-addr - (* 2 (+ (* (- abbrev-char 1) 32) char))))))) - (setq s (concat s (cdr (ez-get-zstring-and-length abbrev-addr))))) - (setq abbrev-char nil)) - ((memq char '(1 2 3)) ;Abbreviation - (setq abbrev-char char)) - ((= char 4) - (setq cur (mod (+ cur 1) 3))) - ((= char 5) - (setq cur (mod (+ 3 (- cur 1)) 3))) - (t - (setq s (concat s (substring (elt ez-zstring-alphabets cur) - char (+ char 1)))) - (setq cur lock)))) + (while (> (length chars) 0) + (let ((char (pop chars))) + (cond + ((memq char '(1 2 3)) ;Abbreviation + (let* ((abbrev-char char) + (abbrev-addr + (* 2 (ez-mem-ref-word (+ ez-abbrevtab-addr + (* 2 (+ (* (- abbrev-char 1) 32) (pop chars)))))))) + (setq s (concat s (cdr (ez-get-zstring-and-length abbrev-addr)))))) + ((= char 4) + (setq cur (mod (+ cur 1) 3))) + ((= char 5) + (setq cur (mod (+ 3 (- cur 1)) 3))) + ((and (= cur 2) (= char 6)) + (setq s (concat s (char-to-string (+ (lsh (pop chars) 5) (pop chars))))) + (setq cur lock)) + (t + (setq s (concat s (substring (elt ez-zstring-alphabets cur) + char (+ char 1)))) + (setq cur lock))))) (cons word-count s))) (defun ez-get-zstring (base-addr) (cdr (ez-get-zstring-and-length base-addr))) +;; Dictionary + +(defun ez-get-dictionary () + (let* ((nseps (ez-mem-ref-byte ez-dict-base)) + (separators + (mapcar (lambda (i) (ez-mem-ref-byte (+ ez-dict-base i))) + (number-sequence 1 nseps))) + (bytes-per-entry (ez-mem-ref-byte (+ ez-dict-base 1 nseps))) + (nentries (ez-mem-ref-word (+ ez-dict-base 1 nseps 1))) + (entries-base (+ ez-dict-base nseps 4)) + (entries nil)) + (dotimes (i nentries) + (let ((this-base (+ entries-base (* 7 i)))) + (setq entries (cons (cons this-base + (ez-get-zstring this-base)) + entries)))) + (list entries separators entries))) + ;; Call stack (defvar ez-call-stack nil)