Mercurial > emacs
comparison lisp/international/titdic-cnv.el @ 88408:4135242fe433
(titdic-convert): Bind coding-system-for-write to 'iso-2022-7bit.
Don't work on unibyte buffer.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 01 Mar 2002 02:09:14 +0000 |
parents | 67b464da13ec |
children | ec21f1e8ca97 |
comparison
equal
deleted
inserted
replaced
88407:9ae36aa886d5 | 88408:4135242fe433 |
---|---|
463 (defun titdic-convert (filename &optional dirname) | 463 (defun titdic-convert (filename &optional dirname) |
464 "Convert a TIT dictionary of FILENAME into a Quail package. | 464 "Convert a TIT dictionary of FILENAME into a Quail package. |
465 Optional argument DIRNAME if specified is the directory name under which | 465 Optional argument DIRNAME if specified is the directory name under which |
466 the generated Quail package is saved." | 466 the generated Quail package is saved." |
467 (interactive "FTIT dictionary file: ") | 467 (interactive "FTIT dictionary file: ") |
468 (with-temp-file (tit-make-quail-package-file-name filename dirname) | 468 (let ((coding-system-for-write 'iso-2022-7bit)) |
469 (set-buffer-file-coding-system 'iso-2022-7bit) | 469 (with-temp-file (tit-make-quail-package-file-name filename dirname) |
470 (let ((standard-output (current-buffer))) | 470 (set-buffer-file-coding-system 'iso-2022-7bit) |
471 (with-temp-buffer | 471 (let ((standard-output (current-buffer))) |
472 (let ((coding-system-for-read 'no-conversion)) | 472 (with-temp-buffer |
473 (insert-file-contents (expand-file-name filename))) | 473 (let ((coding-system-for-read 'no-conversion)) |
474 (set-buffer-multibyte t) | 474 (insert-file-contents (expand-file-name filename))) |
475 (set-buffer-multibyte t) | |
475 | 476 |
476 ;; Decode the buffer contents from the encoding specified by a | 477 ;; Decode the buffer contents from the encoding specified by a |
477 ;; value of the key "ENCODE:". | 478 ;; value of the key "ENCODE:". |
478 (if (not (search-forward "\nBEGIN" nil t)) | 479 (if (not (search-forward "\nBEGIN" nil t)) |
479 (error "TIT dictionary doesn't have body part")) | 480 (error "TIT dictionary doesn't have body part")) |
480 (let ((limit (point)) | 481 (let ((limit (point)) |
481 coding-system slot) | 482 coding-system slot) |
483 (goto-char (point-min)) | |
484 (if (re-search-forward "^ENCODE:[ \t]*" limit t) | |
485 (progn | |
486 (goto-char (match-end 0)) | |
487 (setq tit-encode (tit-read-key-value))) | |
488 (setq tit-encode tit-default-encode)) | |
489 (setq slot (assoc tit-encode tit-encode-list)) | |
490 (if (not slot) | |
491 (error "Invalid ENCODE: value in TIT dictionary")) | |
492 (setq coding-system (nth 1 slot)) | |
493 (message "Decoding with coding system %s..." coding-system) | |
494 (goto-char (point-min)) | |
495 (decode-coding-region (point-min) (point-max) coding-system)) | |
496 | |
497 ;; Set point the starting position of the body part. | |
482 (goto-char (point-min)) | 498 (goto-char (point-min)) |
483 (if (re-search-forward "^ENCODE:[ \t]*" limit t) | 499 (if (not (search-forward "\nBEGIN" nil t)) |
484 (progn | 500 (error "TIT dictionary can't be decoded correctly")) |
485 (goto-char (match-end 0)) | 501 |
486 (setq tit-encode (tit-read-key-value))) | 502 ;; Process the header part. |
487 (setq tit-encode tit-default-encode)) | 503 (forward-line 1) |
488 (setq slot (assoc tit-encode tit-encode-list)) | 504 (narrow-to-region (point-min) (point)) |
489 (if (not slot) | 505 (tit-process-header filename) |
490 (error "Invalid ENCODE: value in TIT dictionary")) | 506 (widen) |
491 (setq coding-system (nth 1 slot)) | 507 |
492 (message "Decoding with coding system %s..." coding-system) | 508 ;; Process the body part. |
493 (goto-char (point-min)) | 509 (tit-process-body)))))) |
494 (decode-coding-region (point-min) (point-max) coding-system)) | |
495 | |
496 ;; Set point the starting position of the body part. | |
497 (goto-char (point-min)) | |
498 (if (not (search-forward "\nBEGIN" nil t)) | |
499 (error "TIT dictionary can't be decoded correctly")) | |
500 | |
501 ;; Process the header part. | |
502 (forward-line 1) | |
503 (narrow-to-region (point-min) (point)) | |
504 (tit-process-header filename) | |
505 (widen) | |
506 | |
507 ;; Process the body part. For speed, we turn off multibyte facility. | |
508 (with-current-buffer standard-output | |
509 (set-buffer-multibyte nil)) | |
510 (set-buffer-multibyte nil) | |
511 (tit-process-body))))) | |
512 | 510 |
513 ;;;###autoload | 511 ;;;###autoload |
514 (defun batch-titdic-convert (&optional force) | 512 (defun batch-titdic-convert (&optional force) |
515 "Run `titdic-convert' on the files remaining on the command line. | 513 "Run `titdic-convert' on the files remaining on the command line. |
516 Use this from the command line, with `-batch'; | 514 Use this from the command line, with `-batch'; |