Function: tit-process-header
tit-process-header is a byte-compiled function defined in
titdic-cnv.el.gz.
Signature
(tit-process-header FILENAME)
Source Code
;; Defined in /usr/src/emacs/lisp/international/titdic-cnv.el.gz
;; Analyze header part of TIT dictionary and generate an appropriate
;; `quail-define-package' function call.
(defun tit-process-header (filename)
(goto-char (point-min))
;; At first, generate header part of the Quail package while
;; collecting information from the original header.
(let ((package (concat
"chinese-"
(substring (downcase (file-name-nondirectory filename))
0 -4)))
;; TIT keywords and the corresponding default values.
(tit-multichoice t)
(tit-prompt "")
(tit-comments nil)
(tit-backspace "\010\177")
(tit-deleteall "\015\025")
(tit-moveright ".>")
(tit-moveleft ",<")
(tit-keyprompt nil))
(generate-lisp-file-heading filename 'titdic-convert :code nil)
(princ ";; Quail package `")
(princ package)
(princ "\n")
(princ ";;\tOriginal TIT dictionary file: ")
(princ (file-name-nondirectory filename))
(princ "\n\n")
(while (not (eobp))
(let ((ch (following-char))
(pos (point)))
(cond ((eq ch ?C) ; COMMENT
(cond ((looking-at "COMMENT")
(let ((pos (match-end 0))
(to (progn (end-of-line) (point))))
(goto-char pos)
(while (re-search-forward "[\\\"]" to t)
(replace-match "\\\\\\&"))
(goto-char pos)
(while (re-search-forward "['`]" to t)
(replace-match "\\\\\\\\=\\&"))
(end-of-line)
(setq tit-comments
(cons (buffer-substring-no-properties pos (point))
tit-comments))))))
((eq ch ?M) ; MULTICHOICE, MOVERIGHT, MOVELEFT
(cond ((looking-at "MULTICHOICE:[ \t]*")
(goto-char (match-end 0))
(setq tit-multichoice (looking-at "YES")))
((looking-at "MOVERIGHT:[ \t]*")
(goto-char (match-end 0))
(setq tit-moveright (tit-read-key-value)))
((looking-at "MOVELEFT:[ \t]*")
(goto-char (match-end 0))
(setq tit-moveleft (tit-read-key-value)))))
((eq ch ?P) ; PROMPT
(cond ((looking-at "PROMPT:[ \t]*")
(goto-char (match-end 0))
(setq tit-prompt (tit-read-key-value))
;; Some TIT dictionaries that are encoded by
;; euc-china contains invalid character at the tail.
(let* ((last (aref tit-prompt (1- (length tit-prompt))))
(split (split-char last)))
(if (or (eq (nth 1 split) 32)
(eq (nth 2 split) 32))
(setq tit-prompt (substring tit-prompt 0 -1)))))))
((eq ch ?B) ; BACKSPACE, BEGINDICTIONARY,
; BEGINPHRASE
(cond ((looking-at "BACKSPACE:[ \t]*")
(goto-char (match-end 0))
(setq tit-backspace (tit-read-key-value)))
((looking-at "BEGINDICTIONARY")
(setq tit-dictionary t))
((looking-at "BEGINPHRASE")
(setq tit-dictionary nil))))
((eq ch ?K) ; KEYPROMPT
(cond ((looking-at "KEYPROMPT(\\(.*\\)):[ \t]*")
(let ((key-char (match-string 1)))
(goto-char (match-end 0))
(if (string-match "\\\\[0-9]+" key-char)
(setq key-char
(car (read-from-string (format "\"%s\""
key-char)))))
(setq tit-keyprompt
(cons (cons key-char (tit-read-key-value))
tit-keyprompt)))))))
(end-of-line)
(princ ";; ")
(princ (buffer-substring-no-properties pos (point)))
(princ "\n")
(forward-line 1)))
(princ "\n;;; End of the header of original TIT dictionary.\n\n")
(princ ";;; Code:\n\n(require 'quail)\n\n")
(princ "(quail-define-package ")
;; Args NAME, LANGUAGE, TITLE
(let ((title (nth 1 (assoc package quail-cxterm-package-ext-info))))
(princ "\"")
(princ package)
(princ "\" \"")
(princ (nth 2 (assoc tit-encode tit-encode-list)))
(princ "\" \"")
(princ (or title
(if (string-match "[:∷:【]+\\([^:∷:】]+\\)" tit-prompt)
(substring tit-prompt (match-beginning 1) (match-end 1))
tit-prompt)))
(princ "\"\n"))
;; Arg GUIDANCE
(if tit-keyprompt
(progn
(princ " '(")
(while tit-keyprompt
(princ " ")
(princ (format "(%d . \"%s\")\n"
(string-to-char (car (car tit-keyprompt)))
(cdr (car tit-keyprompt))))
(setq tit-keyprompt (cdr tit-keyprompt)))
(princ ")"))
(princ " t\n"))
;; Arg DOCSTRING
(let ((doc (concat tit-prompt "\n"))
(comments (if tit-comments
(mapconcat #'identity (nreverse tit-comments) "\n")))
(doc-ext (nth 2 (assoc package quail-cxterm-package-ext-info))))
(if comments
(setq doc (concat doc "\n" comments "\n")))
(if doc-ext
(setq doc (concat doc "\n" doc-ext "\n")))
(prin1 doc)
(terpri))
;; Arg KEY-BINDINGS
(princ " '(")
(tit-generate-key-bindings tit-backspace 'quail-delete-last-char)
(princ "\n ")
(tit-generate-key-bindings tit-deleteall 'quail-abort-translation)
(princ "\n ")
(tit-generate-key-bindings tit-moveright 'quail-next-translation)
(princ "\n ")
(tit-generate-key-bindings tit-moveleft 'quail-prev-translation)
(princ ")\n")
;; Args FORGET-TRANSLATION, DETERMINISTIC, KBD-TRANSLATE, SHOW-LAYOUT.
;; The remaining args are all nil.
(princ " nil")
(princ (if tit-multichoice " nil" " t"))
(princ (if tit-keyprompt " t t)\n\n" " nil nil)\n\n"))))