Function: tit-miscdic-convert

tit-miscdic-convert is an interactive and byte-compiled function defined in titdic-cnv.el.gz.

Signature

(tit-miscdic-convert FILENAME &optional DIRNAME)

Documentation

Convert a dictionary file FILENAME into a Quail package.

Optional argument DIRNAME if specified is the directory name under which the generated Quail package is saved.

Key Bindings

Aliases

miscdic-convert (obsolete since 30.1)

Source Code

;; Defined in /usr/src/emacs/lisp/international/titdic-cnv.el.gz
(defun tit-miscdic-convert (filename &optional dirname)
  "Convert a dictionary file FILENAME into a Quail package.
Optional argument DIRNAME if specified is the directory name under which
the generated Quail package is saved."
  (interactive "FInput method dictionary file: ")
  (or (file-readable-p filename)
      (error "%s does not exist" filename))
  (let ((tail tit-quail-misc-package-ext-info)
	coding-system-for-write
	slot
	name title dicfile coding quailfile converter copyright)
    (while tail
      (setq slot (car tail)
	    dicfile (nth 2 slot)
	    quailfile (nth 4 slot))
      (when (and (or (string-match dicfile filename)
		     ;; MS-DOS filesystem truncates file names to 8+3
		     ;; limits, so "cangjie-table.cns" becomes
		     ;; "cangjie-.cns", and the above string-match
		     ;; fails.  Give DOS users a chance...
		     (and (fboundp 'msdos-long-file-names)
			  (not (msdos-long-file-names))
			  (string-match (dos-8+3-filename dicfile) filename)))
		 (if (file-newer-than-file-p
		      filename (expand-file-name quailfile dirname))
		     t
		   (message "%s is up to date" quailfile)
		   nil))
	(setq name (car slot)
	      title (nth 1 slot)
	      coding (nth 3 slot)
	      converter (nth 5 slot)
	      copyright (nth 6 slot))
	;; Explicitly set eol format to `unix'.
	(setq coding-system-for-write 'utf-8-unix)
	(with-temp-file (expand-file-name quailfile dirname)
          (generate-lisp-file-heading quailfile 'tit-miscdic-convert)
	  (insert (format-message ";; Quail package `%s'\n" name))
	  (insert ";;   Source dictionary file: " dicfile "\n")
	  (insert ";;   Copyright notice of the source file\n")
	  (insert ";;------------------------------------------------------\n")
	  (insert copyright "\n")
	  (insert ";;------------------------------------------------------\n")
	  (insert "\n")
	  (insert ";;; Code:\n\n")
	  (insert "(require 'quail)\n")
	  (insert "(quail-define-package \"" name "\" \""
		  (if (eq coding 'big5) "Chinese-BIG5"
		    (if (eq coding 'iso-2022-cn-ext) "Chinese-CNS"
		      "Chinese-GB"))
		  "\" \"" title "\" t\n")
          (let ((coding-system-for-read
                 (coding-system-change-eol-conversion coding 'unix))
                (dstbuf (current-buffer)))
            (with-temp-buffer
              (insert-file-contents filename)
              (let ((dicbuf (current-buffer)))
                (with-current-buffer dstbuf
                  (funcall converter dicbuf)))))
          (generate-lisp-file-trailer
           quailfile :inhibit-provide t :compile t :coding nil)))
      (setq tail (cdr tail)))))