;; Return a value of the key in the current line.
(defsubst tit-read-key-value ()
- (if (looking-at "[^ \t\n]+")
+ (if (looking-at "[^ \t\r\n]+")
(car (read-from-string (concat "\"" (match-string 0) "\"")))))
;; Return an appropriate quail-package filename from FILENAME (TIT
(tit-keyprompt nil))
(princ ";; Quail package `")
- (princ package) (princ "' -*- coding:iso-2022-7bit; -*-\n")
+ (princ package)
+ (princ (format "' -*- coding:%s; -*-\n" coding-system-for-write))
(princ ";; Generated by the command `titdic-convert'\n;;\tDate: ")
(princ (current-time-string))
(princ "\n;;\tOriginal TIT dictionary file: ")
Optional argument DIRNAME if specified is the directory name under which
the generated Quail package is saved."
(interactive "FTIT dictionary file: ")
- (let ((coding-system-for-write 'iso-2022-7bit))
+ (let ((coding-system-for-write nil))
(with-temp-file (tit-make-quail-package-file-name filename dirname)
- (set-buffer-file-coding-system 'iso-2022-7bit)
(let ((standard-output (current-buffer)))
(with-temp-buffer
(set-buffer-multibyte nil)
(setq coding-system (nth 1 slot))
(message "Decoding with coding system %s..." coding-system)
(goto-char (point-min))
- (decode-coding-region (point-min) (point-max) coding-system))
+ (decode-coding-region (point-min) (point-max) coding-system)
+ (setq coding-system-for-write coding-system)
+ (remove-text-properties (point-min) (point-max) '(charset nil)))
(set-buffer-multibyte t)
;; Set point the starting position of the body part.
(insert "(quail-define-rules\n")
(save-excursion
(set-buffer dicbuf)
+ ;; Handle double CR line ends, which result when checking out of
+ ;; CVS on MS-Windows.
+ (goto-char (point-min))
+ (while (re-search-forward "\r\r$" nil t)
+ (replace-match ""))
(goto-char (point-min))
(search-forward "A440")
(beginning-of-line)
(or (file-readable-p filename)
(error "%s does not exist" filename))
(let ((tail quail-misc-package-ext-info)
- (default-buffer-file-coding-system 'iso-2022-7bit)
- (coding-system-for-write 'iso-2022-7bit)
+ coding-system-for-write
slot
name title dicfile coding quailfile converter copyright
dicbuf)
(while tail
- (when (or (string-match (nth 2 (car tail)) 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 (nth 2 (car tail)))
- filename)))
- (setq slot (car tail)
- name (car slot)
+ (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)
- dicfile (nth 2 slot)
coding (nth 3 slot)
- quailfile (nth 4 slot)
converter (nth 5 slot)
copyright (nth 6 slot))
(message "Converting %s to %s..." dicfile quailfile)
+ (setq coding-system-for-write coding)
(with-temp-file (expand-file-name quailfile dirname)
- (set-buffer-file-coding-system 'iso-2022-7bit)
- (insert ";; Quail package `" name "' -*- coding:iso-2022-7bit; -*-\n")
+ (insert (format ";; Quail package `%s' -*- coding:%s; -*-\n"
+ name coding))
(insert ";; Generated by the command `miscdic-convert'\n")
(insert ";; Date: " (current-time-string) "\n")
(insert ";; Source dictionary file: " dicfile "\n")
(insert ";;; Code:\n\n")
(insert "(require 'quail)\n")
(insert "(quail-define-package \"" name "\" \""
- (if (eq coding 'big5) "Chinese-BIG5" "Chinese-CNS")
+ (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)
(dicbuf (find-file-noselect filename)))
command-line-args-left (cdr command-line-args-left))
(if (file-directory-p filename)
(dolist (file (directory-files filename t nil t))
- (miscdic-convert file dir))
+ (or (file-directory-p file)
+ (miscdic-convert file dir)))
(miscdic-convert filename dir))))
(kill-emacs 0))
;; coding: iso-2022-7bit
;; End:
+;;; arch-tag: 8ad478b2-a985-4da2-b47f-d8ee5d7c24a3
;;; titdic-cnv.el ends here