]> code.delx.au - gnu-emacs/blobdiff - lisp/international/iso-cvt.el
Fix stack overflow in string creation (Bug#6214).
[gnu-emacs] / lisp / international / iso-cvt.el
index 7374c7f5d41aac197d72be155875b8ceccb1838e..8798a4894fbbe43eee5d05e41f6d9092dbf39b4d 100644 (file)
@@ -1,17 +1,18 @@
 ;;; iso-cvt.el --- translate ISO 8859-1 from/to various encodings -*- coding: iso-latin-1 -*-
 ;; This file was formerly called gm-lingo.el.
 
-;; Copyright (C) 1993, 1994, 1995, 1996, 1998, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001,
+;;   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010  Free Software Foundation, Inc.
 
 ;; Author: Michael Gschwind <mike@vlsivie.tuwien.ac.at>
 ;; Keywords: tex, iso, latin, i18n
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 ;; This lisp code is a general framework for translating various
@@ -64,7 +63,7 @@
   "Spanish translation table.")
 
 (defun iso-translate-conventions (from to trans-tab)
-  "Use the translation table TRANS-TAB to translate the current buffer."
+  "Translate between FROM and TO using the translation table TRANS-TAB."
   (save-excursion
     (save-restriction
       (narrow-to-region from to)
@@ -83,7 +82,8 @@
 ;;;###autoload
 (defun iso-spanish (from to &optional buffer)
   "Translate net conventions for Spanish to ISO 8859-1.
-The region between FROM and TO is translated using the table TRANS-TAB.
+Translate the region between FROM and TO using the table
+`iso-spanish-trans-tab'.
 Optional arg BUFFER is ignored (for use in `format-alist')."
   (interactive "*r")
   (iso-translate-conventions from to iso-spanish-trans-tab))
@@ -100,8 +100,8 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
     ("\\\\3" "ß")
     )
   "German translation table.
-This table uses an aggressive translation approach and may erroneously
-translate too much.")
+This table uses an aggressive translation approach
+and may erroneously translate too much.")
 
 (defvar iso-conservative-german-trans-tab
   '(
@@ -115,8 +115,8 @@ translate too much.")
     ("\\([-a-zA-Z\"`]\\)\\\\3" "\\1ß")
     )
   "German translation table.
-This table uses a conservative translation approach and may translate too
-little.")
+This table uses a conservative translation approach
+and may translate too little.")
 
 (defvar iso-german-trans-tab iso-aggressive-german-trans-tab
   "Currently active translation table for German.")
@@ -124,11 +124,12 @@ little.")
 ;;;###autoload
 (defun iso-german (from to &optional buffer)
  "Translate net conventions for German to ISO 8859-1.
-The region between FROM and TO is translated using the table TRANS-TAB.
+Translate the region FROM and TO using the table
+`iso-german-trans-tab'.
 Optional arg BUFFER is ignored (for use in `format-alist')."
  (interactive "*r")
  (iso-translate-conventions from to iso-german-trans-tab))
+
 (defvar iso-iso2tex-trans-tab
   '(
     ("ä" "{\\\\\"a}")
@@ -196,7 +197,8 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
 ;;;###autoload
 (defun iso-iso2tex (from to &optional buffer)
  "Translate ISO 8859-1 characters to TeX sequences.
-The region between FROM and TO is translated using the table TRANS-TAB.
+Translate the region between FROM and TO using the table
+`iso-iso2tex-trans-tab'.
 Optional arg BUFFER is ignored (for use in `format-alist')."
  (interactive "*r")
  (iso-translate-conventions from to iso-iso2tex-trans-tab))
@@ -264,10 +266,16 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
     ("\\\\`e" "è")
     ("\\\\'e" "é")
     ("\\\\^e" "ê")
-    ("\\\\\"\\\\i" "ï")
-    ("\\\\`\\\\i" "ì")
-    ("\\\\'\\\\i" "í")
-    ("\\\\^\\\\i" "î")
+    ;; Discard spaces and/or one EOF after macro \i.
+    ;; Converting it back will use braces.
+    ("\\\\\"\\\\i *\n\n" "ï\n\n")
+    ("\\\\\"\\\\i *\n?" "ï")
+    ("\\\\`\\\\i *\n\n" "ì\n\n")
+    ("\\\\`\\\\i *\n?" "ì")
+    ("\\\\'\\\\i *\n\n" "í\n\n")
+    ("\\\\'\\\\i *\n?" "í")
+    ("\\\\^\\\\i *\n\n" "î\n\n")
+    ("\\\\^\\\\i *\n?" "î")
     ("\\\\\"i" "ï")
     ("\\\\`i" "ì")
     ("\\\\'i" "í")
@@ -376,13 +384,14 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
     ("!`" "¡")
     )
   "Translation table for translating TeX sequences to ISO 8859-1 characters.
-This table is not exhaustive (and due to TeX's power can never be).  It only
-contains commonly used sequences.")
+This table is not exhaustive (and due to TeX's power can never be).
+It only contains commonly used sequences.")
 
 ;;;###autoload
 (defun iso-tex2iso (from to &optional buffer)
  "Translate TeX sequences to ISO 8859-1 characters.
-The region between FROM and TO is translated using the table TRANS-TAB.
+Translate the region between FROM and TO using the table
+`iso-tex2iso-trans-tab'.
 Optional arg BUFFER is ignored (for use in `format-alist')."
  (interactive "*r")
  (iso-translate-conventions from to iso-tex2iso-trans-tab))
@@ -570,8 +579,8 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
     ("\\\\3" "ß")
     )
   "Translation table for translating German TeX sequences to ISO 8859-1.
-This table is not exhaustive (and due to TeX's power can never be).  It only
-contains commonly used sequences.")
+This table is not exhaustive (and due to TeX's power can never be).
+It only contains commonly used sequences.")
 
 (defvar iso-iso2gtex-trans-tab
   '(
@@ -640,7 +649,8 @@ contains commonly used sequences.")
 ;;;###autoload
 (defun iso-gtex2iso (from to &optional buffer)
  "Translate German TeX sequences to ISO 8859-1 characters.
-The region between FROM and TO is translated using the table TRANS-TAB.
+Translate the region between FROM and TO using the table
+`iso-gtex2iso-trans-tab'.
 Optional arg BUFFER is ignored (for use in `format-alist')."
  (interactive "*r")
  (iso-translate-conventions from to iso-gtex2iso-trans-tab))
@@ -648,7 +658,8 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
 ;;;###autoload
 (defun iso-iso2gtex (from to &optional buffer)
  "Translate ISO 8859-1 characters to German TeX sequences.
-The region between FROM and TO is translated using the table TRANS-TAB.
+Translate the region between FROM and TO using the table
+`iso-iso2gtex-trans-tab'.
 Optional arg BUFFER is ignored (for use in `format-alist')."
  (interactive "*r")
  (iso-translate-conventions from to iso-iso2gtex-trans-tab))
@@ -660,12 +671,14 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
     ("Ö" "Oe")
     ("ü" "ue")
     ("Ü" "Ue")
-    ("ß" "ss")))
+    ("ß" "ss"))
+    "Translation table for translating ISO 8859-1 characters to Duden sequences.")
 
 ;;;###autoload
 (defun iso-iso2duden (from to &optional buffer)
- "Translate ISO 8859-1 characters to German TeX sequences.
-The region between FROM and TO is translated using the table TRANS-TAB.
+ "Translate ISO 8859-1 characters to Duden sequences.
+Translate the region between FROM and TO using the table
+`iso-iso2duden-trans-tab'.
 Optional arg BUFFER is ignored (for use in `format-alist')."
  (interactive "*r")
  (iso-translate-conventions from to iso-iso2duden-trans-tab))
@@ -784,6 +797,7 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
     ("&iuml;" "ï")
     ("&eth;" "ð")
     ("&ntilde;" "ñ")
+    ("&nbsp;" " ")
     ("&ograve;" "ò")
     ("&oacute;" "ó")
     ("&ocirc;" "ô")
@@ -801,7 +815,7 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
 ;;;###autoload
 (defun iso-iso2sgml (from to &optional buffer)
  "Translate ISO 8859-1 characters in the region to SGML entities.
-The entities used are from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
+Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
 Optional arg BUFFER is ignored (for use in `format-alist')."
  (interactive "*r")
  (iso-translate-conventions from to iso-iso2sgml-trans-tab))
@@ -809,87 +823,86 @@ Optional arg BUFFER is ignored (for use in `format-alist')."
 ;;;###autoload
 (defun iso-sgml2iso (from to &optional buffer)
  "Translate SGML entities in the region to ISO 8859-1 characters.
-The entities used are from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
+Use entities from \"ISO 8879:1986//ENTITIES Added Latin 1//EN\".
 Optional arg BUFFER is ignored (for use in `format-alist')."
  (interactive "*r")
  (iso-translate-conventions from to iso-sgml2iso-trans-tab))
 
 ;;;###autoload
-(defun iso-cvt-read-only ()
+(defun iso-cvt-read-only (&rest ignore)
   "Warn that format is read-only."
   (interactive)
   (error "This format is read-only; specify another format for writing"))
 
 ;;;###autoload
-(defun iso-cvt-write-only ()
+(defun iso-cvt-write-only (&rest ignore)
   "Warn that format is write-only."
   (interactive)
   (error "This format is write-only"))
-                        
+
 ;;;###autoload
 (defun iso-cvt-define-menu ()
-  "Add submenus to the Files menu, to convert to and from various formats."
+  "Add submenus to the File menu, to convert to and from various formats."
   (interactive)
 
-  (define-key menu-bar-files-menu [load-as-separator] '("--"))
-
-  (define-key menu-bar-files-menu [load-as] '("Load As..."  . load-as))
-  (defvar load-as-menu-map (make-sparse-keymap "Load As..."))
-  (fset 'load-as load-as-menu-map)
-
-  ;;(define-key menu-bar-files-menu [insert-as] '("Insert As..."  . insert-as))
-  (defvar insert-as-menu-map (make-sparse-keymap "Insert As..."))
-  (fset 'insert-as insert-as-menu-map)
-
-  (define-key menu-bar-files-menu [write-as] '("Write As..."  . write-as))
-  (defvar write-as-menu-map (make-sparse-keymap "Write As..."))
-  (fset 'write-as write-as-menu-map)
-
-  (define-key menu-bar-files-menu [translate-separator] '("--"))
-
-  (define-key menu-bar-files-menu [translate-to] '("Translate to..."  . translate-to))
-  (defvar translate-to-menu-map (make-sparse-keymap "Translate to..."))
-  (fset 'translate-to translate-to-menu-map)
-
-  (define-key menu-bar-files-menu [translate-from] '("Translate from..."  . translate-from))
-  (defvar translate-from-menu-map (make-sparse-keymap "Translate from..."))
-  (fset 'translate-from translate-from-menu-map)
-
-  (let ((file-types (reverse format-alist))
-       name
-       str-name)
-    (while file-types
-      (setq name (car (car file-types))
-           str-name (car (cdr (car file-types)))
-           file-types (cdr file-types))
-      (if (stringp str-name)
-         (progn
-           (define-key load-as-menu-map (vector name)
-             (cons str-name
-                   `(lambda (file)
-                      (interactive (format "FFind file (as %s): " ,name))
-                      (format-find-file file ',name))))
-           (define-key insert-as-menu-map (vector name)
-             (cons str-name
-                   `(lambda (file)
-                      (interactive (format "FInsert file (as %s): " ,name))
-                      (format-insert-file file ',name))))
-           (define-key write-as-menu-map (vector name)
-             (cons str-name
-                   `(lambda (file)
-                      (interactive (format "FWrite file (as %s): " ,name))
-                         (format-write-file file ',name))))
-           (define-key translate-to-menu-map (vector name)
-             (cons str-name
-                   `(lambda ()
-                      (interactive)
-                         (format-encode-buffer ',name))))
-           (define-key translate-from-menu-map (vector name)
-             (cons str-name
-                   `(lambda ()
-                      (interactive)
-                      (format-decode-buffer ',name)))))))))
+  (let ((load-as-menu-map (make-sparse-keymap "Load As..."))
+       (insert-as-menu-map (make-sparse-keymap "Insert As..."))
+       (write-as-menu-map (make-sparse-keymap "Write As..."))
+       (translate-to-menu-map (make-sparse-keymap "Translate to..."))
+       (translate-from-menu-map (make-sparse-keymap "Translate from..."))
+       (menu menu-bar-file-menu))
+
+    (define-key menu [load-as-separator] '("--"))
+
+    (define-key menu [load-as] '("Load As..." . iso-cvt-load-as))
+    (fset 'iso-cvt-load-as load-as-menu-map)
+
+    ;;(define-key menu [insert-as] '("Insert As..." . iso-cvt-insert-as))
+    (fset 'iso-cvt-insert-as insert-as-menu-map)
+
+    (define-key menu [write-as] '("Write As..." . iso-cvt-write-as))
+    (fset 'iso-cvt-write-as write-as-menu-map)
+
+    (define-key menu [translate-separator] '("--"))
+
+    (define-key menu [translate-to] '("Translate to..." . iso-cvt-translate-to))
+    (fset 'iso-cvt-translate-to translate-to-menu-map)
+
+    (define-key menu [translate-from] '("Translate from..." . iso-cvt-translate-from))
+    (fset 'iso-cvt-translate-from translate-from-menu-map)
+
+    (dolist (file-type (reverse format-alist))
+      (let ((name (car file-type))
+           (str-name (cadr file-type)))
+       (if (stringp str-name)
+           (progn
+             (define-key load-as-menu-map (vector name)
+               (cons str-name
+                     `(lambda (file)
+                        (interactive ,(format "FFind file (as %s): " name))
+                        (format-find-file file ',name))))
+             (define-key insert-as-menu-map (vector name)
+               (cons str-name
+                     `(lambda (file)
+                        (interactive (format "FInsert file (as %s): " ,name))
+                        (format-insert-file file ',name))))
+             (define-key write-as-menu-map (vector name)
+               (cons str-name
+                     `(lambda (file)
+                        (interactive (format "FWrite file (as %s): " ,name))
+                        (format-write-file file ',name))))
+             (define-key translate-to-menu-map (vector name)
+               (cons str-name
+                     `(lambda ()
+                        (interactive)
+                        (format-encode-buffer ',name))))
+             (define-key translate-from-menu-map (vector name)
+               (cons str-name
+                     `(lambda ()
+                        (interactive)
+                        (format-decode-buffer ',name))))))))))
 
 (provide 'iso-cvt)
 
+;; arch-tag: 64ae843f-ed0e-43e1-ba50-ffd581b90840
 ;;; iso-cvt.el ends here