diff options
| author | Dave Love | 2002-05-17 20:19:20 +0000 |
|---|---|---|
| committer | Dave Love | 2002-05-17 20:19:20 +0000 |
| commit | 0fa407100f4b56449314b6e9d28e69c4b78d5c76 (patch) | |
| tree | b4110c46681dc3c1aade7a2c95a94f3fecc9d5b5 | |
| parent | e1e529fadbe97ecaa1ae3cb4c4079ee2a66d0ce6 (diff) | |
| download | emacs-0fa407100f4b56449314b6e9d28e69c4b78d5c76.tar.gz emacs-0fa407100f4b56449314b6e9d28e69c4b78d5c76.zip | |
Most of code removed or commented
out.
(codepage-setup): Re-written as trivial, obsolete function.
| -rw-r--r-- | lisp/international/codepage.el | 740 |
1 files changed, 108 insertions, 632 deletions
diff --git a/lisp/international/codepage.el b/lisp/international/codepage.el index c0d5405af68..e11b26e8609 100644 --- a/lisp/international/codepage.el +++ b/lisp/international/codepage.el | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | ;; Author: Eli Zaretskii | 5 | ;; Author: Eli Zaretskii |
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| 7 | ;; Keywords: i18n ms-dos ms-windows codepage | 7 | ;; Keywords: i18n ms-dos ms-windows codepage obsolete |
| 8 | 8 | ||
| 9 | ;; This file is part of GNU Emacs. | 9 | ;; This file is part of GNU Emacs. |
| 10 | 10 | ||
| @@ -26,642 +26,118 @@ | |||
| 26 | ;;; Commentary: | 26 | ;;; Commentary: |
| 27 | 27 | ||
| 28 | ;; Special coding systems for DOS/Windows codepage support. | 28 | ;; Special coding systems for DOS/Windows codepage support. |
| 29 | ;; | 29 | ;; Obsolete. |
| 30 | ;; These coding systems perform conversion from the DOS/Windows | ||
| 31 | ;; codepage encoding to one of the ISO-8859 character sets. Each | ||
| 32 | ;; codepage has its corresponding ISO-8859 charset, chosen so as to be | ||
| 33 | ;; able to convert all (or most) of the characters. The idea is that | ||
| 34 | ;; Emacs internally works with the usual MULE charsets, and the | ||
| 35 | ;; conversion to and from the DOS codepage is performed on I/O only. | ||
| 36 | ;; See term/internal.el for the complementary setup of the DOS | ||
| 37 | ;; terminal display and input methods. | ||
| 38 | ;; | ||
| 39 | ;; Thanks to Ken'ichi Handa <handa@etl.go.jp> for writing the CCL | ||
| 40 | ;; encoders/decoders, and for help in debugging this code. | ||
| 41 | 30 | ||
| 42 | ;;; Code: | 31 | ;;; Code: |
| 43 | 32 | ||
| 44 | (defun cp-coding-system-for-codepage-1 (coding mnemonic iso-name | 33 | ;; I doubt we need compatibility versions of any of these autoloaded |
| 45 | decoder encoder) | 34 | ;; functions apart from codepage-setup, which users may call. |
| 46 | "Make coding system CODING for a DOS codepage using translation tables. | 35 | |
| 47 | MNEMONIC is a character to be displayed on mode line for the coding system. | 36 | ;; ;;;###autoload |
| 48 | ISO-NAME is the name of the ISO-8859 charset which corresponds to this | 37 | ;; (defun cp-make-coding-systems-for-codepage (codepage iso-name offset) |
| 49 | codepage. | 38 | ;; "Create a coding system to convert IBM CODEPAGE into charset ISO-NAME |
| 50 | DECODER is a translation table for converting characters in the DOS codepage | 39 | ;; whose first character is at offset OFFSET from the beginning of 8-bit |
| 51 | encoding to Emacs multibyte characters. | 40 | ;; ASCII table. |
| 52 | ENCODER is a translation table for encoding Emacs multibyte characters into | 41 | |
| 53 | external DOS codepage codes." | 42 | ;; The created coding system has the usual 3 subsidiary systems: for Unix-, |
| 54 | (save-match-data | 43 | ;; DOS- and Mac-style EOL conversion. However, unlike built-in coding |
| 55 | (let* ((coding-name (symbol-name coding)) | 44 | ;; systems, the Mac-style EOL conversion is currently not supported by the |
| 56 | (undef (if (eq system-type 'ms-dos) | 45 | ;; decoder and encoder created by this function." |
| 57 | (if dos-unsupported-char-glyph | 46 | ;; (let* ((decode-table (intern (format "%s-decode-table" codepage))) |
| 58 | (logand dos-unsupported-char-glyph 255) | 47 | ;; (nonascii-table |
| 59 | 127) | 48 | ;; (intern (format "%s-nonascii-translation-table" codepage))) |
| 60 | ??)) | 49 | ;; (decode-translation |
| 61 | (safe-chars (make-char-table 'safe-chars)) | 50 | ;; (intern (format "%s-decode-translation-table" codepage))) |
| 62 | (ccl-decoder | 51 | ;; (encode-translation |
| 63 | (ccl-compile | 52 | ;; (intern (format "%s-encode-translation-table" codepage)))) |
| 64 | ;; The 4 here supplies the buf_magnification parameter | 53 | ;; (set nonascii-table |
| 65 | ;; for the CCL program. A multibyte character may take | 54 | ;; (make-translation-table-from-vector |
| 66 | ;; at most 4-bytes. | 55 | ;; (cp-decoding-vector-for-codepage |
| 67 | `(4 (loop (read r1) | 56 | ;; (symbol-value decode-table) iso-name offset))) |
| 68 | (if (r1 >= 128) | 57 | ;; (define-translation-table encode-translation |
| 69 | ((r0 = ,(charset-id 'ascii)) | 58 | ;; (char-table-extra-slot (symbol-value nonascii-table) 0)) |
| 70 | (translate-character ,decoder r0 r1) | 59 | ;; ;; For charsets other than ascii, eight-bit-* and ISO-NAME, set |
| 71 | (write-multibyte-character r0 r1)) | 60 | ;; ;; `?' for one-column charsets, and some Japanese character for |
| 72 | (write r1)) | 61 | ;; ;; wide-column charsets. CCL encoder convert that Japanese |
| 73 | (repeat))))) | 62 | ;; ;; character to either dos-unsupported-char-glyph or "??". |
| 74 | (ccl-encoder | 63 | ;; (let ((tbl (char-table-extra-slot (symbol-value nonascii-table) 0)) |
| 75 | (ccl-compile | 64 | ;; (undef (if (eq system-type 'ms-dos) |
| 76 | ;; The 2 here supplies the buf_magnification parameter for | 65 | ;; (if dos-unsupported-char-glyph |
| 77 | ;; the CCL program. Since the -dos coding system generates | 66 | ;; (logand dos-unsupported-char-glyph 255) |
| 78 | ;; \r\n for each \n, a factor of 2 covers even the worst case | 67 | ;; 127) |
| 79 | ;; of empty lines with a single \n. | 68 | ;; ??)) |
| 80 | `(2 (loop (read-multibyte-character r0 r1) | 69 | ;; (charsets (delq 'ascii |
| 81 | (if (r0 != ,(charset-id 'ascii)) | 70 | ;; (delq 'eight-bit-control |
| 82 | ((translate-character ,encoder r0 r1) | 71 | ;; (delq 'eight-bit-graphic |
| 83 | (if (r0 == ,(charset-id 'japanese-jisx0208)) | 72 | ;; (delq iso-name |
| 84 | ((r1 = ,undef) | 73 | ;; (copy-sequence charset-list)))))) |
| 85 | (write r1))))) | 74 | ;; (wide-column-char (make-char 'japanese-jisx0208 32 32))) |
| 86 | (write-repeat r1)))))) | 75 | ;; (while charsets |
| 87 | 76 | ;; (aset tbl (make-char (car charsets)) | |
| 88 | ;; Set elements of safe multibyte characters for this codepage | 77 | ;; (if (= (charset-width (car charsets)) 1) undef wide-column-char)) |
| 89 | ;; to t in the char-table safe-chars. | 78 | ;; (setq charsets (cdr charsets)))) |
| 90 | (let ((tbl (get decoder 'translation-table)) | 79 | ;; (define-translation-table decode-translation |
| 91 | (i 128) | 80 | ;; (symbol-value nonascii-table)) |
| 92 | ch) | 81 | ;; (cp-coding-system-for-codepage-1 |
| 93 | (while (< i 256) | 82 | ;; (intern codepage) ?D iso-name decode-translation encode-translation) |
| 94 | (setq ch (aref tbl i)) | 83 | ;; )) |
| 95 | (if ch (aset safe-chars ch t)) | 84 | |
| 96 | (setq i (1+ i)))) | 85 | ;; ;;;###autoload |
| 97 | 86 | ;; (defun cp-charset-for-codepage (codepage) | |
| 98 | ;; Make coding system CODING. | 87 | ;; "Return the charset for which there is a translation table to DOS CODEPAGE. |
| 99 | (make-coding-system | 88 | ;; CODEPAGE must be the name of a DOS codepage, a string." |
| 100 | coding 4 mnemonic | 89 | ;; (let ((cp-decoder (cp-codepage-decoder codepage))) |
| 101 | (concat "8-bit encoding of " (symbol-name iso-name) | 90 | ;; (if (null cp-decoder) |
| 102 | " characters using IBM codepage " coding-name) | 91 | ;; (error "Unsupported codepage %s" codepage) |
| 103 | (cons ccl-decoder ccl-encoder) | 92 | ;; (get cp-decoder 'charset)))) |
| 104 | `((safe-charsets ascii eight-bit-control eight-bit-graphic ,iso-name) | 93 | |
| 105 | (safe-chars . ,safe-chars) | 94 | ;; ;;;###autoload |
| 106 | (valid-codes (0 . 255))))))) | 95 | ;; (defun cp-language-for-codepage (codepage) |
| 107 | 96 | ;; "Return the name of the MULE language environment for CODEPAGE. | |
| 108 | (defun cp-decoding-vector-for-codepage (table charset offset) | 97 | ;; CODEPAGE must be the name of a DOS codepage, a string." |
| 109 | "Create a vector for decoding IBM PC characters using conversion table | 98 | ;; (let ((cp-decoder (cp-codepage-decoder codepage))) |
| 110 | TABLE into an ISO-8859 character set CHARSET whose first non-ASCII | 99 | ;; (if (null cp-decoder) |
| 111 | character is generated by (make-char CHARSET OFFSET)." | 100 | ;; (error "Unsupported codepage %s" codepage) |
| 112 | (let* ((len (length table)) | 101 | ;; (get cp-decoder 'language)))) |
| 113 | (undefined-char | 102 | |
| 114 | (if (eq system-type 'ms-dos) | 103 | ;; ;;;###autoload |
| 115 | (if dos-unsupported-char-glyph | 104 | ;; (defun cp-offset-for-codepage (codepage) |
| 116 | (logand dos-unsupported-char-glyph 255) | 105 | ;; "Return the offset to be used in setting up coding systems for CODEPAGE. |
| 117 | 127) | 106 | ;; CODEPAGE must be the name of a DOS codepage, a string." |
| 118 | 32)) | 107 | ;; (let ((cp-decoder (cp-codepage-decoder codepage))) |
| 119 | (vec1 (make-vector 256 undefined-char)) | 108 | ;; (if (null cp-decoder) |
| 120 | (i 0)) | 109 | ;; (error "Unsupported codepage %s" codepage) |
| 121 | (while (< i 256) | 110 | ;; (get cp-decoder 'offset)))) |
| 122 | (aset vec1 i i) | 111 | |
| 123 | (setq i (1+ i))) | 112 | ;; ;;;###autoload |
| 124 | (setq i 0) | 113 | ;; (defun cp-supported-codepages () |
| 125 | (while (< i len) | 114 | ;; "Return an alist of supported codepages. |
| 126 | (if (aref table i) | 115 | |
| 127 | (aset vec1 (aref table i) (make-char charset (+ i offset)))) | 116 | ;; Each association in the alist has the form (NNN . CHARSET), where NNN is the |
| 128 | (setq i (1+ i))) | 117 | ;; codepage number, and CHARSET is the MULE charset which is the closest match |
| 129 | vec1)) | 118 | ;; for the character set supported by that codepage. |
| 130 | 119 | ||
| 131 | ;;; You don't think I created all these tables below by hand, do you? | 120 | ;; A codepage NNN is supported if a variable called `cpNNN-decode-table' exists, |
| 132 | ;;; The following Awk script will create the table for cp850-to-Latin-1 | 121 | ;; is a vector, and has a charset property." |
| 133 | ;;; conversion from the RFC 1345 file (the other tables are left as an | 122 | ;; (save-match-data |
| 134 | ;;; excercise): | 123 | ;; (let (alist chset sname) |
| 135 | ;;; BEGIN { n_pages = 11; | 124 | ;; (mapatoms |
| 136 | ;;; pn["IBM437"] = 0; pn["IBM850"] = 1; pn["IBM851"] = 2; | 125 | ;; (function |
| 137 | ;;; pn["IBM852"] = 3; pn["IBM855"] = 4; pn["IBM860"] = 5; | 126 | ;; (lambda (sym) |
| 138 | ;;; pn["IBM861"] = 6; pn["IBM862"] = 7; pn["IBM863"] = 8; | 127 | ;; (if (and (boundp sym) |
| 139 | ;;; pn["IBM864"] = 9; pn["IBM865"] = 10; | 128 | ;; (string-match "\\`cp\\([1-9][0-9][0-9][0-9]?\\)-decode-table\\'" |
| 140 | ;;; } | 129 | ;; (setq sname (symbol-name sym))) |
| 141 | ;;; $1 == "&charset" { charset = $2; } | 130 | ;; (vectorp (symbol-value sym)) |
| 142 | ;;; $1 == "&code" { code = $2; } | 131 | ;; (setq chset (get sym 'charset))) |
| 143 | ;;; /^ [^&]/ { | 132 | ;; (setq alist |
| 144 | ;;; if ((charset ~ /^IBM(437|8(5[0125]|6[0-5]))$/) || (charset ~ /^ISO_8859-1/)) | 133 | ;; (cons (cons (match-string 1 sname) chset) alist)))))) |
| 145 | ;;; { | 134 | ;; alist))) |
| 146 | ;;; for (i = 1; i <= NF; i++) | ||
| 147 | ;;; chars[charset,code++] = $i; | ||
| 148 | ;;; } | ||
| 149 | ;;; } | ||
| 150 | ;;; | ||
| 151 | ;;; END { | ||
| 152 | ;;; for (i = 160; i < 256; i++) | ||
| 153 | ;;; { | ||
| 154 | ;;; c = chars["ISO_8859-1:1987",i]; | ||
| 155 | ;;; if (c == "??") # skip unused positions | ||
| 156 | ;;; { | ||
| 157 | ;;; printf " nil"; | ||
| 158 | ;;; if ((i - 159)%16 == 0) | ||
| 159 | ;;; printf "\n"; | ||
| 160 | ;;; continue; | ||
| 161 | ;;; } | ||
| 162 | ;;; found = 0; | ||
| 163 | ;;; for (j in pn) | ||
| 164 | ;;; map[j] = "nil"; | ||
| 165 | ;;; for (combined in chars) | ||
| 166 | ;;; { | ||
| 167 | ;;; candidate = chars[combined]; | ||
| 168 | ;;; split (combined, separate, SUBSEP); | ||
| 169 | ;;; if (separate[1] == "IBM850" && candidate == c) | ||
| 170 | ;;; { | ||
| 171 | ;;; found = 1; | ||
| 172 | ;;; map[separate[1]] = separate[2]; | ||
| 173 | ;;; } | ||
| 174 | ;;; } | ||
| 175 | ;;; printf " %s", map["IBM850"]; | ||
| 176 | ;;; if ((i - 159)%16 == 0) | ||
| 177 | ;;; printf "\n"; | ||
| 178 | ;;; } | ||
| 179 | ;;; } | ||
| 180 | |||
| 181 | ;;; WARNING WARNING WARNING!!! | ||
| 182 | ;;; | ||
| 183 | ;;; If you want to get fancy with these tables, remember that the inverse | ||
| 184 | ;;; tables, created by `cp-decoding-vector-for-codepage' above, are installed | ||
| 185 | ;;; on MS-DOS as nonascii-translation-table (see `dos-codepage-setup' on | ||
| 186 | ;;; internal.el). Therefore, you should NOT put any codes below 128 in | ||
| 187 | ;;; these tables! Otherwise, various Emacs commands and functions will | ||
| 188 | ;;; mysteriously fail! For example, a typical screwup is to map the Latin-N | ||
| 189 | ;;; acute accent character to the apostrophe, and have all regexps which | ||
| 190 | ;;; end with "\\'" begin to fail (e.g., the automatic setting of the major | ||
| 191 | ;;; mode by file name extension will stop working). | ||
| 192 | ;;; | ||
| 193 | ;;; You HAVE BEEN warned! | ||
| 194 | |||
| 195 | ;; US/English/PC-8/IBM-2. This doesn't support Latin-1 characters very | ||
| 196 | ;; well, but why not use what we can salvage? | ||
| 197 | (defvar cp437-decode-table | ||
| 198 | ;; Nth element is the code of a cp437 glyph for the multibyte | ||
| 199 | ;; character created by (make-char 'latin-iso8859-1 (+ N 160)). | ||
| 200 | ;; The element nil means there's no corresponding cp437 glyph. | ||
| 201 | [ | ||
| 202 | 255 173 155 156 nil 157 179 nil nil nil 166 174 170 196 nil nil | ||
| 203 | 248 241 253 nil nil nil nil 249 nil nil 167 175 172 171 nil 168 | ||
| 204 | nil nil nil nil 142 143 146 128 nil 144 nil nil nil nil nil nil | ||
| 205 | nil 165 nil nil nil nil 153 nil nil nil nil nil 154 nil nil 225 | ||
| 206 | 133 160 131 nil 132 134 145 135 138 130 136 137 141 161 140 139 | ||
| 207 | nil 164 149 162 147 nil 148 246 nil 151 163 150 129 nil nil 152] | ||
| 208 | "Table for converting ISO-8859-1 characters into codepage 437 glyphs.") | ||
| 209 | (setplist 'cp437-decode-table | ||
| 210 | '(charset latin-iso8859-1 language "Latin-1" offset 160)) | ||
| 211 | |||
| 212 | ;; Multilingual (Latin-1) | ||
| 213 | (defvar cp850-decode-table | ||
| 214 | ;; Nth element is the code of a cp850 glyph for the multibyte | ||
| 215 | ;; character created by (make-char 'latin-iso8859-1 (+ N 160)). | ||
| 216 | ;; The element nil means there's no corresponding cp850 glyph. | ||
| 217 | [ | ||
| 218 | 255 173 189 156 207 190 221 245 249 184 166 174 170 240 169 nil | ||
| 219 | 248 241 253 252 239 230 244 250 247 251 167 175 172 171 243 168 | ||
| 220 | 183 181 182 199 142 143 146 128 212 144 210 211 222 214 215 216 | ||
| 221 | 209 165 227 224 226 229 153 158 157 235 233 234 154 237 231 225 | ||
| 222 | 133 160 131 198 132 134 145 135 138 130 136 137 141 161 140 139 | ||
| 223 | 208 164 149 162 147 228 148 246 155 151 163 150 129 236 232 152] | ||
| 224 | "Table for converting ISO-8859-1 characters into codepage 850 glyphs.") | ||
| 225 | (setplist 'cp850-decode-table | ||
| 226 | '(charset latin-iso8859-1 language "Latin-1" offset 160)) | ||
| 227 | |||
| 228 | ;; Greek | ||
| 229 | (defvar cp851-decode-table | ||
| 230 | [ | ||
| 231 | 255 nil nil 156 nil nil nil 245 249 nil nil 174 nil 240 nil nil | ||
| 232 | 248 241 nil nil 239 nil 134 nil 141 143 144 175 146 171 149 152 | ||
| 233 | 161 164 165 166 167 168 169 170 172 173 181 182 184 183 189 190 | ||
| 234 | 198 199 nil 207 208 209 210 211 212 213 nil nil 155 157 158 159 | ||
| 235 | 252 214 215 216 221 222 224 225 226 227 228 229 230 231 232 233 | ||
| 236 | 234 235 237 236 238 242 243 244 246 250 160 251 162 163 253 nil] | ||
| 237 | "Table for converting ISO-8859-7 characters into codepage 851 glyphs.") | ||
| 238 | (setplist 'cp851-decode-table | ||
| 239 | '(charset greek-iso8859-7 language "Greek" offset 160)) | ||
| 240 | |||
| 241 | ;; Slavic/Eastern Europe (Latin-2) | ||
| 242 | (defvar cp852-decode-table | ||
| 243 | [ | ||
| 244 | 255 164 244 157 207 149 151 245 249 230 184 155 141 240 166 189 | ||
| 245 | 248 165 247 136 239 150 152 243 242 231 173 156 171 241 167 190 | ||
| 246 | 232 181 182 198 142 145 143 128 172 144 168 211 183 214 215 210 | ||
| 247 | 209 227 213 224 226 138 153 158 252 222 233 235 154 237 221 225 | ||
| 248 | 234 160 131 199 132 146 134 135 159 130 169 137 216 161 140 212 | ||
| 249 | 208 228 229 162 147 139 148 246 253 133 163 251 129 236 238 250] | ||
| 250 | "Table for converting ISO-8859-2 characters into codepage 852 glyphs.") | ||
| 251 | (setplist 'cp852-decode-table | ||
| 252 | '(charset latin-iso8859-2 language "Latin-2" offset 160)) | ||
| 253 | |||
| 254 | ;; Russian | ||
| 255 | (defvar cp855-decode-table | ||
| 256 | [ | ||
| 257 | 255 133 129 131 135 137 139 141 143 145 147 149 151 240 153 155 | ||
| 258 | 161 163 236 173 167 169 234 244 184 190 199 209 211 213 215 221 | ||
| 259 | 226 228 230 232 171 182 165 252 246 250 159 242 238 248 157 224 | ||
| 260 | 160 162 235 172 166 168 233 243 183 189 198 208 210 212 214 216 | ||
| 261 | 225 227 229 231 170 181 164 251 245 249 158 241 237 247 156 222 | ||
| 262 | 239 132 128 130 134 136 138 140 142 144 146 148 150 253 152 154] | ||
| 263 | "Table for converting ISO-8859-5 characters into codepage 855 glyphs.") | ||
| 264 | (setplist 'cp855-decode-table | ||
| 265 | '(charset cyrillic-iso8859-5 language "Cyrillic-ISO" offset 160)) | ||
| 266 | |||
| 267 | ;; Turkish | ||
| 268 | (defvar cp857-decode-table | ||
| 269 | [ | ||
| 270 | 255 nil nil 156 207 nil 245 249 152 158 166 nil 240 nil | ||
| 271 | 248 nil 253 252 239 nil nil nil nil 141 159 167 nil 171 nil | ||
| 272 | 183 181 182 142 nil nil 128 212 144 210 211 222 214 215 216 | ||
| 273 | 165 227 224 226 nil 153 232 nil 235 233 234 154 nil nil 225 | ||
| 274 | 133 160 131 132 nil nil 135 138 130 136 137 236 161 140 139 | ||
| 275 | 164 149 162 147 nil 148 246 nil 151 163 150 129 nil nil 250] | ||
| 276 | "Table for converting ISO-8859-3 characters into codepage 857 glyphs.") | ||
| 277 | (setplist 'cp857-decode-table | ||
| 278 | '(charset latin-iso8859-3 language "Latin-3" offset 160)) | ||
| 279 | |||
| 280 | ;; Portuguese | ||
| 281 | (defvar cp860-decode-table | ||
| 282 | [ | ||
| 283 | 255 173 155 156 nil nil 179 nil nil nil 166 174 170 nil nil nil | ||
| 284 | nil 241 253 nil nil nil nil 249 nil nil 167 175 172 171 nil 168 | ||
| 285 | 145 134 143 142 nil nil nil 128 146 144 137 nil 152 nil 139 nil | ||
| 286 | nil 165 159 169 140 153 nil nil nil 157 150 nil 154 nil nil nil | ||
| 287 | 133 160 131 132 nil nil nil 135 138 130 136 nil 141 161 nil nil | ||
| 288 | nil 164 149 162 147 148 nil 246 nil 151 163 nil 129 nil nil nil] | ||
| 289 | "Table for converting ISO-8859-1 characters into codepage 860 glyphs.") | ||
| 290 | (setplist 'cp860-decode-table | ||
| 291 | '(charset latin-iso8859-1 language "Latin-1" offset 160)) | ||
| 292 | |||
| 293 | ;; Icelandic | ||
| 294 | (defvar cp861-decode-table | ||
| 295 | [ | ||
| 296 | 255 173 nil 156 nil nil nil nil nil nil nil 174 170 nil nil nil | ||
| 297 | nil 241 253 nil nil nil nil 249 nil nil nil 175 172 171 nil 168 | ||
| 298 | nil 164 nil nil 142 143 146 128 nil 144 nil nil nil 165 nil nil | ||
| 299 | 139 nil 159 166 nil nil 153 nil 157 nil 167 nil 154 151 141 nil | ||
| 300 | 133 160 131 nil 132 134 145 135 138 130 136 137 nil 161 nil nil | ||
| 301 | 140 nil nil 162 147 nil 148 246 155 nil 163 150 129 152 149 nil] | ||
| 302 | "Table for converting ISO-8859-1 characters into codepage 861 glyphs.") | ||
| 303 | (setplist 'cp861-decode-table | ||
| 304 | '(charset latin-iso8859-1 language "Latin-1" offset 160)) | ||
| 305 | |||
| 306 | ;; Hebrew | ||
| 307 | (defvar cp862-decode-table | ||
| 308 | ;; Nth element is the code of a cp862 glyph for the multibyte | ||
| 309 | ;; character created by (make-char 'hebrew-iso8859-8 (+ N 160)). | ||
| 310 | ;; The element nil means there's no corresponding cp862 glyph. | ||
| 311 | [ | ||
| 312 | 255 173 155 156 nil 157 179 nil nil nil nil 174 170 196 nil nil | ||
| 313 | 248 241 253 nil nil 230 nil 249 nil nil 246 175 172 171 nil nil | ||
| 314 | nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil | ||
| 315 | nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil 205 | ||
| 316 | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | ||
| 317 | 144 145 146 147 148 149 150 151 152 153 154 nil nil nil nil nil] | ||
| 318 | "Table for converting ISO-8859-8 characters into codepage 862 glyphs.") | ||
| 319 | (setplist 'cp862-decode-table | ||
| 320 | '(charset hebrew-iso8859-8 language "Hebrew" offset 160)) | ||
| 321 | |||
| 322 | ;; French Canadian | ||
| 323 | (defvar cp863-decode-table | ||
| 324 | [ | ||
| 325 | 255 nil 155 156 152 nil 160 143 164 nil nil 174 170 nil nil 167 | ||
| 326 | nil 241 253 166 161 nil 134 249 165 nil nil 175 172 171 173 nil | ||
| 327 | 142 nil 132 nil nil nil nil 128 145 144 146 148 nil nil 168 149 | ||
| 328 | nil nil nil nil 153 nil nil nil nil 157 nil 158 154 nil nil nil | ||
| 329 | 133 nil 131 nil nil nil nil 135 138 130 136 137 141 nil 140 139 | ||
| 330 | nil nil nil 162 147 nil nil 246 nil 151 163 150 129 nil nil nil] | ||
| 331 | "Table for converting ISO-8859-1 characters into codepage 863 glyphs.") | ||
| 332 | (setplist 'cp863-decode-table | ||
| 333 | '(charset latin-iso8859-1 language "Latin-1" offset 160)) | ||
| 334 | |||
| 335 | ;; Arabic | ||
| 336 | ;; FIXME: Emacs doesn't seem to support the "Arabic" language | ||
| 337 | ;; environment yet. So this is only partially usable, for now | ||
| 338 | (defvar cp864-decode-table | ||
| 339 | [ | ||
| 340 | 255 nil nil nil 164 nil nil nil nil nil nil nil 172 161 nil nil | ||
| 341 | nil nil nil nil nil nil nil nil nil nil nil 187 nil nil nil 191 | ||
| 342 | nil 193 194 195 196 nil 198 199 169 201 170 171 173 174 175 207 | ||
| 343 | 208 209 210 188 189 190 235 215 216 223 238 nil nil nil nil nil | ||
| 344 | 224 247 248 252 251 239 242 243 232 233 253 nil nil nil nil nil | ||
| 345 | nil 241 nil nil nil nil nil nil nil nil nil nil nil nil nil nil] | ||
| 346 | "Table for converting ISO-8859-6 characters into codepage 864 glyphs.") | ||
| 347 | (setplist 'cp864-decode-table | ||
| 348 | '(charset arabic-iso8859-6 language nil offset 160)) | ||
| 349 | |||
| 350 | ;; Arabic OEM codepage used by Windows | ||
| 351 | ;; FIXME: Emacs doesn't seem to support the "Arabic" language | ||
| 352 | ;; environment yet. So this is only partially usable, for now | ||
| 353 | (defvar cp720-decode-table | ||
| 354 | [ | ||
| 355 | 255 nil nil nil 148 nil nil nil nil nil nil nil nil 196 nil nil | ||
| 356 | nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil nil | ||
| 357 | nil 152 153 154 155 157 158 159 160 161 162 163 164 165 166 167 | ||
| 358 | 168 169 170 171 172 173 224 225 226 227 228 nil nil nil nil nil | ||
| 359 | 149 229 231 232 233 234 235 236 237 238 239 241 242 243 244 245 | ||
| 360 | 246 145 146 nil nil nil nil nil nil nil nil nil nil nil nil nil] | ||
| 361 | "Table for converting ISO-8859-6 characters into codepage 720 glyphs.") | ||
| 362 | (setplist 'cp720-decode-table | ||
| 363 | '(charset arabic-iso8859-6 language nil offset 160)) | ||
| 364 | |||
| 365 | |||
| 366 | ;; Nordic (Norwegian/Danish) | ||
| 367 | (defvar cp865-decode-table | ||
| 368 | [ | ||
| 369 | 255 173 nil 156 nil nil nil nil nil nil 166 174 170 nil nil nil | ||
| 370 | nil 241 253 nil nil nil nil 249 nil nil 167 175 172 171 nil 168 | ||
| 371 | nil nil nil nil 142 143 146 128 nil 144 nil nil nil nil nil nil | ||
| 372 | nil 165 nil nil nil nil 153 nil 157 nil nil nil 154 nil nil nil | ||
| 373 | 133 160 131 nil 132 134 145 135 138 130 136 137 141 161 140 139 | ||
| 374 | nil 164 149 162 147 nil 148 246 155 151 163 150 129 nil nil 152] | ||
| 375 | "Table for converting ISO-8859-1 characters into codepage 865 glyphs.") | ||
| 376 | (setplist 'cp865-decode-table | ||
| 377 | '(charset latin-iso8859-1 language "Latin-1" offset 160)) | ||
| 378 | |||
| 379 | ;; Russian (Yes, another one! This one's supposed to be used | ||
| 380 | ;; on Windows as the Russian OEM code page.) | ||
| 381 | (defvar cp866-decode-table | ||
| 382 | [ | ||
| 383 | 255 240 nil nil 242 nil nil 244 nil nil nil nil nil nil 246 nil | ||
| 384 | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | ||
| 385 | 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | ||
| 386 | 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | ||
| 387 | 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | ||
| 388 | 252 241 nil nil 243 nil nil 245 nil nil nil nil nil nil 247 nil] | ||
| 389 | "Table for converting ISO-8859-5 characters into codepage 866 glyphs.") | ||
| 390 | (setplist 'cp866-decode-table | ||
| 391 | '(charset cyrillic-iso8859-5 language "Cyrillic-ISO" offset 160)) | ||
| 392 | |||
| 393 | ;; Greek (yes, another one!) | ||
| 394 | (defvar cp869-decode-table | ||
| 395 | [ | ||
| 396 | 255 139 140 156 nil nil 138 245 249 151 nil 174 137 240 nil 142 | ||
| 397 | 248 241 153 154 239 247 134 136 141 143 144 175 146 171 149 152 | ||
| 398 | 161 164 165 166 167 168 169 170 172 173 181 182 183 184 189 190 | ||
| 399 | 198 199 nil 207 208 209 210 211 212 213 145 150 155 157 158 159 | ||
| 400 | 252 214 215 216 221 222 224 225 226 227 228 229 230 231 232 233 | ||
| 401 | 234 235 237 236 238 242 243 244 246 250 160 251 162 163 253 nil] | ||
| 402 | "Table for converting ISO-8859-7 characters into codepage 869 glyphs.") | ||
| 403 | (setplist 'cp869-decode-table | ||
| 404 | '(charset greek-iso8859-7 language "Greek" offset 160)) | ||
| 405 | |||
| 406 | ;; Greek OEM codepage used by Windows | ||
| 407 | (defvar cp737-decode-table | ||
| 408 | [ | ||
| 409 | 255 nil nil nil nil nil 179 nil nil nil nil nil nil 196 nil nil | ||
| 410 | 248 241 253 nil nil nil 234 250 235 236 237 nil 238 nil 239 240 | ||
| 411 | nil 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | ||
| 412 | 143 144 nil 145 146 147 148 149 150 151 244 245 225 226 227 229 | ||
| 413 | nil 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | ||
| 414 | 167 168 170 169 171 172 173 174 175 224 228 232 230 231 233 nil] | ||
| 415 | "Table for converting ISO-8859-7 characters into codepage 737 glyphs.") | ||
| 416 | (setplist 'cp737-decode-table | ||
| 417 | '(charset greek-iso8859-7 language "Greek" offset 160)) | ||
| 418 | |||
| 419 | ;; Conversion from codepages 770-775 to Latin-4 for Baltic countries. | ||
| 420 | ;; FIXME: Once we support Latin-7, these should be remapped into it. | ||
| 421 | (defvar cp770-decode-table | ||
| 422 | [ | ||
| 423 | 255 143 nil nil 155 nil 156 nil 157 159 137 168 nil 196 146 nil | ||
| 424 | 248 133 nil nil nil nil 134 nil nil 158 136 152 nil nil 145 nil | ||
| 425 | 160 nil nil nil 142 nil nil 173 128 nil 139 nil 144 nil nil 161 | ||
| 426 | nil nil nil 163 nil 149 153 nil nil 167 nil nil 154 nil 166 225 | ||
| 427 | 131 nil nil nil 132 nil nil 141 135 nil 138 nil 130 nil nil 140 | ||
| 428 | nil nil nil 162 nil 147 148 247 nil 151 nil nil 129 nil 150 nil] | ||
| 429 | "Table for converting ISO-8859-4 characters into codepage 770 glyphs.") | ||
| 430 | (setplist 'cp770-decode-table | ||
| 431 | '(charset latin-iso8859-4 language "Latin-4" offset 160)) | ||
| 432 | |||
| 433 | (defvar cp773-decode-table | ||
| 434 | [ | ||
| 435 | 255 220 nil 138 150 nil 234 190 166 246 237 149 173 196 252 nil | ||
| 436 | 208 nil nil 139 239 nil 235 nil nil 247 137 133 136 nil 253 nil | ||
| 437 | 160 nil nil nil 142 143 146 244 222 144 240 nil 242 nil nil 161 | ||
| 438 | nil 238 226 232 nil 229 153 158 157 248 nil nil 154 nil 250 225 | ||
| 439 | 131 nil nil nil 132 134 145 245 223 130 241 nil 243 nil nil 140 | ||
| 440 | nil 236 147 233 nil 228 148 198 155 249 nil nil 129 nil 251 nil] | ||
| 441 | "Table for converting ISO-8859-4 characters into codepage 773 glyphs.") | ||
| 442 | (setplist 'cp773-decode-table | ||
| 443 | '(charset latin-iso8859-4 language "Latin-4" offset 160)) | ||
| 444 | |||
| 445 | (defvar cp774-decode-table | ||
| 446 | [ | ||
| 447 | 255 181 nil nil 155 nil nil nil 245 190 nil nil nil 196 207 nil | ||
| 448 | 248 208 nil nil nil nil nil nil nil 213 nil nil nil nil 216 nil | ||
| 449 | nil nil nil nil 142 143 146 189 182 144 183 nil 184 nil nil nil | ||
| 450 | nil nil nil nil nil nil 153 nil nil 198 nil nil 154 nil 199 225 | ||
| 451 | nil 160 nil nil 132 134 145 212 209 130 210 137 211 161 140 nil | ||
| 452 | nil nil nil nil 147 nil 148 246 237 214 163 150 129 nil 215 248] | ||
| 453 | "Table for converting ISO-8859-4 characters into codepage 774 glyphs.") | ||
| 454 | (setplist 'cp774-decode-table | ||
| 455 | '(charset latin-iso8859-4 language "Latin-4" offset 160)) | ||
| 456 | |||
| 457 | (defvar cp775-decode-table | ||
| 458 | [ | ||
| 459 | 255 181 nil 138 150 nil 234 245 166 190 237 149 173 240 207 nil | ||
| 460 | 248 208 nil 139 239 nil 235 nil nil 213 137 133 136 nil 216 nil | ||
| 461 | 160 nil nil nil 142 143 146 189 182 144 183 nil 184 nil nil 161 | ||
| 462 | nil 238 226 232 nil 229 153 158 157 198 nil nil 154 nil 199 225 | ||
| 463 | 131 nil nil nil 132 134 145 212 209 130 210 nil 211 nil nil 140 | ||
| 464 | nil 236 147 233 nil 228 148 247 155 214 nil nil 129 nil 215 nil] | ||
| 465 | "Table for converting ISO-8859-4 characters into codepage 775 glyphs.") | ||
| 466 | (setplist 'cp775-decode-table | ||
| 467 | '(charset latin-iso8859-4 language "Latin-4" offset 160)) | ||
| 468 | |||
| 469 | ;; Support for the Windows 12xx series of codepages that MS has | ||
| 470 | ;; butchered from the ISO-8859 specs. This does not add support for | ||
| 471 | ;; the extended characters that MS has added in the 128 - 159 coding | ||
| 472 | ;; range, only translates those characters that can be expressed in | ||
| 473 | ;; the corresponding iso-8859 charset. | ||
| 474 | |||
| 475 | ;; Codepage Mapping: | ||
| 476 | ;; | ||
| 477 | ;; Windows-1250: ISO-8859-2 (Central Europe) - differs in some positions | ||
| 478 | ;; Windows-1251: ISO-8859-5 (Cyrillic) - differs wildly | ||
| 479 | ;; Windows-1252: ISO-8859-1 (West Europe) - exact match | ||
| 480 | ;; Windows-1253: ISO-8859-7 (Greek) - differs in some positions | ||
| 481 | ;; Windows-1254: ISO-8859-9 (Turkish) - exact match | ||
| 482 | ;; Windows-1255: ISO-8859-8 (Hebrew) - exact match | ||
| 483 | ;; Windows-1256: ISO-8859-6 (Arabic) - half match | ||
| 484 | ;; Windows-1257: ISO-8859-4 (Baltic) - differs, future Latin-7 | ||
| 485 | ;; Windows-1258: VISCII (Vietnamese) - Completely different | ||
| 486 | |||
| 487 | (defvar cp1250-decode-table | ||
| 488 | [ | ||
| 489 | 160 165 162 163 164 188 140 167 168 138 170 141 143 173 142 175 | ||
| 490 | 176 185 178 179 180 190 156 161 184 154 186 157 159 189 158 191 | ||
| 491 | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | ||
| 492 | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | ||
| 493 | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | ||
| 494 | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 ] | ||
| 495 | "ISO-8859-2 to Windows-1250 (Central Europe) codepage decoding table.") | ||
| 496 | (setplist 'cp1250-decode-table | ||
| 497 | '(charset latin-iso8859-2 language "Latin-2" offset 160)) | ||
| 498 | |||
| 499 | (defvar cp1251-decode-table | ||
| 500 | [ | ||
| 501 | 160 168 128 129 170 189 178 175 163 138 140 142 141 173 161 143 | ||
| 502 | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | ||
| 503 | 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | ||
| 504 | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | ||
| 505 | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | ||
| 506 | 185 184 144 131 186 190 179 191 188 154 156 158 157 167 162 159 ] | ||
| 507 | "ISO-8859-5 to Windows-1251 (Cyrillic) codepage decoding table.") | ||
| 508 | (setplist 'cp1251-decode-table | ||
| 509 | '(charset cyrillic-iso8859-5 language "Cyrillic-ISO" offset 160)) | ||
| 510 | |||
| 511 | ;; cp1253 is missing nbsp so we cannot quite translate perfectly. It | ||
| 512 | ;; also has two micro/mu characters which would require more complex | ||
| 513 | ;; processing to accomodate. | ||
| 514 | (defvar cp1253-decode-table | ||
| 515 | [ | ||
| 516 | nil 145 146 163 nil nil 166 167 168 169 nil 171 172 173 nil 151 | ||
| 517 | 176 177 178 179 180 161 162 183 184 185 186 187 188 189 190 191 | ||
| 518 | 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | ||
| 519 | 208 209 nil 211 212 213 214 215 216 217 218 219 220 221 222 223 | ||
| 520 | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | ||
| 521 | 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 nil ] | ||
| 522 | "ISO-8859-7 to Windows-1253 (Greek) codepage decoding table.") | ||
| 523 | (setplist 'cp1253-decode-table | ||
| 524 | '(charset greek-iso8859-7 language "Greek" offset 160)) | ||
| 525 | |||
| 526 | ;; Since Latin-7 is not yet official, and Emacs does not support it, | ||
| 527 | ;; provide translation between Windows-1257 and Latin-4 the best we | ||
| 528 | ;; can. | ||
| 529 | (defvar cp1257-decode-table | ||
| 530 | [ | ||
| 531 | 160 192 nil 170 164 nil 207 167 nil 208 199 204 nil 173 222 nil | ||
| 532 | 176 224 nil 186 nil nil 239 nil nil 240 231 236 nil nil 254 nil | ||
| 533 | 194 nil nil nil 196 197 175 193 200 201 198 nil 203 nil nil 206 | ||
| 534 | nil 210 212 205 nil 213 214 215 168 216 nil nil 220 nil 219 223 | ||
| 535 | 226 nil nil nil 228 229 191 225 232 233 230 nil 235 nil nil 238 | ||
| 536 | nil 242 244 237 nil 245 246 247 184 248 nil nil 252 nil 251 nil ] | ||
| 537 | "ISO-8859-4 to Windows-1257 (Baltic) codepage decoding table.") | ||
| 538 | (setplist 'cp1257-decode-table | ||
| 539 | '(charset latin-iso8859-4 language "Latin-4" offset 160)) | ||
| 540 | |||
| 541 | ;;;###autoload | ||
| 542 | (defun cp-make-coding-systems-for-codepage (codepage iso-name offset) | ||
| 543 | "Create a coding system to convert IBM CODEPAGE into charset ISO-NAME | ||
| 544 | whose first character is at offset OFFSET from the beginning of 8-bit | ||
| 545 | ASCII table. | ||
| 546 | |||
| 547 | The created coding system has the usual 3 subsidiary systems: for Unix-, | ||
| 548 | DOS- and Mac-style EOL conversion. However, unlike built-in coding | ||
| 549 | systems, the Mac-style EOL conversion is currently not supported by the | ||
| 550 | decoder and encoder created by this function." | ||
| 551 | (let* ((decode-table (intern (format "%s-decode-table" codepage))) | ||
| 552 | (nonascii-table | ||
| 553 | (intern (format "%s-nonascii-translation-table" codepage))) | ||
| 554 | (decode-translation | ||
| 555 | (intern (format "%s-decode-translation-table" codepage))) | ||
| 556 | (encode-translation | ||
| 557 | (intern (format "%s-encode-translation-table" codepage)))) | ||
| 558 | (set nonascii-table | ||
| 559 | (make-translation-table-from-vector | ||
| 560 | (cp-decoding-vector-for-codepage | ||
| 561 | (symbol-value decode-table) iso-name offset))) | ||
| 562 | (define-translation-table encode-translation | ||
| 563 | (char-table-extra-slot (symbol-value nonascii-table) 0)) | ||
| 564 | ;; For charsets other than ascii, eight-bit-* and ISO-NAME, set | ||
| 565 | ;; `?' for one-column charsets, and some Japanese character for | ||
| 566 | ;; wide-column charsets. CCL encoder convert that Japanese | ||
| 567 | ;; character to either dos-unsupported-char-glyph or "??". | ||
| 568 | (let ((tbl (char-table-extra-slot (symbol-value nonascii-table) 0)) | ||
| 569 | (undef (if (eq system-type 'ms-dos) | ||
| 570 | (if dos-unsupported-char-glyph | ||
| 571 | (logand dos-unsupported-char-glyph 255) | ||
| 572 | 127) | ||
| 573 | ??)) | ||
| 574 | (charsets (delq 'ascii | ||
| 575 | (delq 'eight-bit-control | ||
| 576 | (delq 'eight-bit-graphic | ||
| 577 | (delq iso-name | ||
| 578 | (copy-sequence charset-list)))))) | ||
| 579 | (wide-column-char (make-char 'japanese-jisx0208 32 32))) | ||
| 580 | (while charsets | ||
| 581 | (aset tbl (make-char (car charsets)) | ||
| 582 | (if (= (charset-width (car charsets)) 1) undef wide-column-char)) | ||
| 583 | (setq charsets (cdr charsets)))) | ||
| 584 | (define-translation-table decode-translation | ||
| 585 | (symbol-value nonascii-table)) | ||
| 586 | (cp-coding-system-for-codepage-1 | ||
| 587 | (intern codepage) ?D iso-name decode-translation encode-translation) | ||
| 588 | )) | ||
| 589 | |||
| 590 | (defun cp-codepage-decoder (codepage) | ||
| 591 | "If CODEPAGE is the name of a supported codepage, return its decode table. | ||
| 592 | Otherwise return nil." | ||
| 593 | (let ((cp (if (symbolp codepage) (symbol-name codepage) codepage))) | ||
| 594 | (cond | ||
| 595 | ((stringp cp) | ||
| 596 | (intern-soft (format "%s-decode-table" cp))) | ||
| 597 | (t nil)))) | ||
| 598 | 135 | ||
| 599 | ;;;###autoload | 136 | ;;;###autoload |
| 600 | (defun cp-charset-for-codepage (codepage) | 137 | (defun codepage-setup (&optional codepage) |
| 601 | "Return the charset for which there is a translation table to DOS CODEPAGE. | 138 | "Obsolete. All coding systems are set up initially." |
| 602 | CODEPAGE must be the name of a DOS codepage, a string." | 139 | (interactive)) |
| 603 | (let ((cp-decoder (cp-codepage-decoder codepage))) | 140 | (make-obsolete 'codepage-setup "no longer relevant" "22.1") |
| 604 | (if (null cp-decoder) | ||
| 605 | (error "Unsupported codepage %s" codepage) | ||
| 606 | (get cp-decoder 'charset)))) | ||
| 607 | |||
| 608 | ;;;###autoload | ||
| 609 | (defun cp-language-for-codepage (codepage) | ||
| 610 | "Return the name of the MULE language environment for CODEPAGE. | ||
| 611 | CODEPAGE must be the name of a DOS codepage, a string." | ||
| 612 | (let ((cp-decoder (cp-codepage-decoder codepage))) | ||
| 613 | (if (null cp-decoder) | ||
| 614 | (error "Unsupported codepage %s" codepage) | ||
| 615 | (get cp-decoder 'language)))) | ||
| 616 | |||
| 617 | ;;;###autoload | ||
| 618 | (defun cp-offset-for-codepage (codepage) | ||
| 619 | "Return the offset to be used in setting up coding systems for CODEPAGE. | ||
| 620 | CODEPAGE must be the name of a DOS codepage, a string." | ||
| 621 | (let ((cp-decoder (cp-codepage-decoder codepage))) | ||
| 622 | (if (null cp-decoder) | ||
| 623 | (error "Unsupported codepage %s" codepage) | ||
| 624 | (get cp-decoder 'offset)))) | ||
| 625 | |||
| 626 | ;;;###autoload | ||
| 627 | (defun cp-supported-codepages () | ||
| 628 | "Return an alist of supported codepages. | ||
| 629 | |||
| 630 | Each association in the alist has the form (NNN . CHARSET), where NNN is the | ||
| 631 | codepage number, and CHARSET is the MULE charset which is the closest match | ||
| 632 | for the character set supported by that codepage. | ||
| 633 | |||
| 634 | A codepage NNN is supported if a variable called `cpNNN-decode-table' exists, | ||
| 635 | is a vector, and has a charset property." | ||
| 636 | (save-match-data | ||
| 637 | (let (alist chset sname) | ||
| 638 | (mapatoms | ||
| 639 | (function | ||
| 640 | (lambda (sym) | ||
| 641 | (if (and (boundp sym) | ||
| 642 | (string-match "\\`cp\\([1-9][0-9][0-9][0-9]?\\)-decode-table\\'" | ||
| 643 | (setq sname (symbol-name sym))) | ||
| 644 | (vectorp (symbol-value sym)) | ||
| 645 | (setq chset (get sym 'charset))) | ||
| 646 | (setq alist | ||
| 647 | (cons (cons (match-string 1 sname) chset) alist)))))) | ||
| 648 | alist))) | ||
| 649 | |||
| 650 | ;;;###autoload | ||
| 651 | (defun codepage-setup (codepage) | ||
| 652 | "Create a coding system cpCODEPAGE to support the IBM codepage CODEPAGE. | ||
| 653 | |||
| 654 | These coding systems are meant for encoding and decoding 8-bit non-ASCII | ||
| 655 | characters used by the IBM codepages, typically in conjunction with files | ||
| 656 | read/written by MS-DOS software, or for display on the MS-DOS terminal." | ||
| 657 | (interactive | ||
| 658 | (let ((completion-ignore-case t) | ||
| 659 | (candidates (cp-supported-codepages))) | ||
| 660 | (list (completing-read "Setup DOS Codepage: (default 437) " candidates | ||
| 661 | nil t nil nil "437")))) | ||
| 662 | (let ((cp (format "cp%s" codepage))) | ||
| 663 | (cp-make-coding-systems-for-codepage | ||
| 664 | cp (cp-charset-for-codepage cp) (cp-offset-for-codepage cp)))) | ||
| 665 | 141 | ||
| 666 | (provide 'codepage) | 142 | (provide 'codepage) |
| 667 | 143 | ||