diff options
| author | Kenichi Handa | 2010-08-06 17:11:19 +0900 |
|---|---|---|
| committer | Kenichi Handa | 2010-08-06 17:11:19 +0900 |
| commit | 7a84eee5b745ad577d414158716ffe2ee487a117 (patch) | |
| tree | 8941277791414c9648b79f304b5d27de0e46eb76 /src | |
| parent | faa28da9b740a4b5f297fc215d79a66d71bf6f78 (diff) | |
| download | emacs-7a84eee5b745ad577d414158716ffe2ee487a117.tar.gz emacs-7a84eee5b745ad577d414158716ffe2ee487a117.zip | |
Improve the encoding by compound-text-with-extensions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 11 | ||||
| -rw-r--r-- | src/charset.c | 86 | ||||
| -rw-r--r-- | src/coding.c | 2 |
3 files changed, 87 insertions, 12 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 2b413a7958c..514c42cd922 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,14 @@ | |||
| 1 | 2010-08-06 Kenichi Handa <handa@m17n.org> | ||
| 2 | |||
| 3 | * charset.c: Include <stdlib.h> | ||
| 4 | (struct charset_sort_data): New struct. | ||
| 5 | (charset_compare): New function. | ||
| 6 | (Fsort_charsets): New funciton. | ||
| 7 | (syms_of_charset): Declare Fsort_charsets as a Lisp function. | ||
| 8 | |||
| 9 | * coding.c (decode_coding_iso_2022): Fix checking of dimension | ||
| 10 | number in CTEXT extended segment. | ||
| 11 | |||
| 1 | 2010-08-01 Juanma Barranquero <lekktu@gmail.com> | 12 | 2010-08-01 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 13 | ||
| 3 | * w32fns.c (syms_of_w32fns) <x-max-tooltip-size>: Fix typo in docstring. | 14 | * w32fns.c (syms_of_w32fns) <x-max-tooltip-size>: Fix typo in docstring. |
diff --git a/src/charset.c b/src/charset.c index 125c9131687..3b45dc348ed 100644 --- a/src/charset.c +++ b/src/charset.c | |||
| @@ -28,6 +28,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 28 | #include <config.h> | 28 | #include <config.h> |
| 29 | 29 | ||
| 30 | #include <stdio.h> | 30 | #include <stdio.h> |
| 31 | #include <stdlib.h> | ||
| 31 | #include <unistd.h> | 32 | #include <unistd.h> |
| 32 | #include <ctype.h> | 33 | #include <ctype.h> |
| 33 | #include <sys/types.h> | 34 | #include <sys/types.h> |
| @@ -2139,23 +2140,22 @@ that case, find the charset from what supported by that coding system. */) | |||
| 2139 | charset = CHAR_CHARSET (XINT (ch)); | 2140 | charset = CHAR_CHARSET (XINT (ch)); |
| 2140 | else | 2141 | else |
| 2141 | { | 2142 | { |
| 2142 | Lisp_Object charset_list; | ||
| 2143 | |||
| 2144 | if (CONSP (restriction)) | 2143 | if (CONSP (restriction)) |
| 2145 | { | 2144 | { |
| 2146 | for (charset_list = Qnil; CONSP (restriction); | 2145 | int c = XFASTINT (ch); |
| 2147 | restriction = XCDR (restriction)) | 2146 | |
| 2147 | for (; CONSP (restriction); restriction = XCDR (restriction)) | ||
| 2148 | { | 2148 | { |
| 2149 | int id; | 2149 | struct charset *charset; |
| 2150 | 2150 | ||
| 2151 | CHECK_CHARSET_GET_ID (XCAR (restriction), id); | 2151 | CHECK_CHARSET_GET_CHARSET (XCAR (restriction), charset); |
| 2152 | charset_list = Fcons (make_number (id), charset_list); | 2152 | if (ENCODE_CHAR (charset, c) != CHARSET_INVALID_CODE (charset)) |
| 2153 | return XCAR (restriction); | ||
| 2153 | } | 2154 | } |
| 2154 | charset_list = Fnreverse (charset_list); | 2155 | return Qnil; |
| 2155 | } | 2156 | } |
| 2156 | else | 2157 | restriction = coding_system_charset_list (restriction); |
| 2157 | charset_list = coding_system_charset_list (restriction); | 2158 | charset = char_charset (XINT (ch), restriction, NULL); |
| 2158 | charset = char_charset (XINT (ch), charset_list, NULL); | ||
| 2159 | if (! charset) | 2159 | if (! charset) |
| 2160 | return Qnil; | 2160 | return Qnil; |
| 2161 | } | 2161 | } |
| @@ -2312,6 +2312,69 @@ Return charset identification number of CHARSET. */) | |||
| 2312 | return make_number (id); | 2312 | return make_number (id); |
| 2313 | } | 2313 | } |
| 2314 | 2314 | ||
| 2315 | struct charset_sort_data | ||
| 2316 | { | ||
| 2317 | Lisp_Object charset; | ||
| 2318 | int id; | ||
| 2319 | int priority; | ||
| 2320 | }; | ||
| 2321 | |||
| 2322 | static int | ||
| 2323 | charset_compare (const void *d1, const void *d2) | ||
| 2324 | { | ||
| 2325 | const struct charset_sort_data *data1 = d1, *data2 = d2; | ||
| 2326 | return (data1->priority - data2->priority); | ||
| 2327 | } | ||
| 2328 | |||
| 2329 | DEFUN ("sort-charsets", Fsort_charsets, Ssort_charsets, 1, 1, 0, | ||
| 2330 | doc: /* Sort charset list CHARSETS by a priority of each charset. | ||
| 2331 | Return the sorted list. CHARSETS is modified by side effects. | ||
| 2332 | See also `charset-priority-list' and `set-charset-priority'. */) | ||
| 2333 | (Lisp_Object charsets) | ||
| 2334 | { | ||
| 2335 | Lisp_Object len = Flength (charsets); | ||
| 2336 | int n = XFASTINT (len), i, j, done; | ||
| 2337 | Lisp_Object tail, elt, attrs; | ||
| 2338 | struct charset_sort_data *sort_data; | ||
| 2339 | int id, min_id, max_id; | ||
| 2340 | USE_SAFE_ALLOCA; | ||
| 2341 | |||
| 2342 | if (n == 0) | ||
| 2343 | return Qnil; | ||
| 2344 | SAFE_ALLOCA (sort_data, struct charset_sort_data *, sizeof (*sort_data) * n); | ||
| 2345 | for (tail = charsets, i = 0; CONSP (tail); tail = XCDR (tail), i++) | ||
| 2346 | { | ||
| 2347 | elt = XCAR (tail); | ||
| 2348 | CHECK_CHARSET_GET_ATTR (elt, attrs); | ||
| 2349 | sort_data[i].charset = elt; | ||
| 2350 | sort_data[i].id = id = XINT (CHARSET_ATTR_ID (attrs)); | ||
| 2351 | if (i == 0) | ||
| 2352 | min_id = max_id = id; | ||
| 2353 | else if (id < min_id) | ||
| 2354 | min_id = id; | ||
| 2355 | else if (id > max_id) | ||
| 2356 | max_id = id; | ||
| 2357 | } | ||
| 2358 | for (done = 0, tail = Vcharset_ordered_list, i = 0; | ||
| 2359 | done < n && CONSP (tail); tail = XCDR (tail), i++) | ||
| 2360 | { | ||
| 2361 | elt = XCAR (tail); | ||
| 2362 | id = XFASTINT (elt); | ||
| 2363 | if (id >= min_id && id <= max_id) | ||
| 2364 | for (j = 0; j < n; j++) | ||
| 2365 | if (sort_data[j].id == id) | ||
| 2366 | { | ||
| 2367 | sort_data[j].priority = i; | ||
| 2368 | done++; | ||
| 2369 | } | ||
| 2370 | } | ||
| 2371 | qsort (sort_data, n, sizeof *sort_data, charset_compare); | ||
| 2372 | for (i = 0, tail = charsets; CONSP (tail); tail = XCDR (tail), i++) | ||
| 2373 | XSETCAR (tail, sort_data[i].charset); | ||
| 2374 | SAFE_FREE (); | ||
| 2375 | return charsets; | ||
| 2376 | } | ||
| 2377 | |||
| 2315 | 2378 | ||
| 2316 | void | 2379 | void |
| 2317 | init_charset () | 2380 | init_charset () |
| @@ -2414,6 +2477,7 @@ syms_of_charset () | |||
| 2414 | defsubr (&Scharset_priority_list); | 2477 | defsubr (&Scharset_priority_list); |
| 2415 | defsubr (&Sset_charset_priority); | 2478 | defsubr (&Sset_charset_priority); |
| 2416 | defsubr (&Scharset_id_internal); | 2479 | defsubr (&Scharset_id_internal); |
| 2480 | defsubr (&Ssort_charsets); | ||
| 2417 | 2481 | ||
| 2418 | DEFVAR_LISP ("charset-map-path", &Vcharset_map_path, | 2482 | DEFVAR_LISP ("charset-map-path", &Vcharset_map_path, |
| 2419 | doc: /* *List of directories to search for charset map files. */); | 2483 | doc: /* *List of directories to search for charset map files. */); |
diff --git a/src/coding.c b/src/coding.c index bdc37cb7c53..aef80f5cc80 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -3935,7 +3935,7 @@ decode_coding_iso_2022 (coding) | |||
| 3935 | int size; | 3935 | int size; |
| 3936 | 3936 | ||
| 3937 | ONE_MORE_BYTE (dim); | 3937 | ONE_MORE_BYTE (dim); |
| 3938 | if (dim < 0 || dim > 4) | 3938 | if (dim < '0' || dim > '4') |
| 3939 | goto invalid_code; | 3939 | goto invalid_code; |
| 3940 | ONE_MORE_BYTE (M); | 3940 | ONE_MORE_BYTE (M); |
| 3941 | if (M < 128) | 3941 | if (M < 128) |