From fcaf88782ba68e7c0618a663db51cf4a26cb3926 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Thu, 30 Sep 2010 13:28:34 +0900 Subject: Complement a coding system for encoding arguments and input to a process. --- src/coding.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 92b328091ff..cbebeff6310 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6112,6 +6112,63 @@ coding_inherit_eol_type (coding_system, parent) return coding_system; } + +/* Check if text-conversion and eol-conversion of CODING_SYSTEM are + decided for writing to a process. If not, complement them, and + return a new coding system. */ + +Lisp_Object +complement_process_encoding_system (coding_system) + Lisp_Object coding_system; +{ + Lisp_Object spec, attrs, coding_type, eol_type; + + if (NILP (coding_system)) + coding_system = Qundecided; + spec = CODING_SYSTEM_SPEC (coding_system); + attrs = AREF (spec, 0); + coding_type = CODING_ATTR_TYPE (attrs); + eol_type = AREF (spec, 2); + + if (EQ (coding_type, Qundecided)) + { + /* We must decide the text-conversion part. */ + if (CONSP (Vdefault_process_coding_system)) + { + coding_system = XCDR (Vdefault_process_coding_system); + if (! NILP (coding_system)) + { + spec = CODING_SYSTEM_SPEC (coding_system); + attrs = AREF (spec, 0); + coding_type = CODING_ATTR_TYPE (attrs); + eol_type = AREF (spec, 2); + } + } + if (EQ (coding_type, Qundecided)) + { + coding_system = preferred_coding_system (); + spec = CODING_SYSTEM_SPEC (coding_system); + attrs = AREF (spec, 0); + coding_type = CODING_ATTR_TYPE (attrs); + eol_type = AREF (spec, 2); + } + if (EQ (coding_type, Qundecided)) + { + coding_system = Qraw_text; + coding_type = Qraw_text; + eol_type = Qnil; + } + } + if (NILP (eol_type) || VECTORP (eol_type)) + { + /* We must decide the eol-conversion part. */ + coding_system = coding_inherit_eol_type (coding_system, Qnil); + } + + return coding_system; +} + + /* Emacs has a mechanism to automatically detect a coding system if it is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But, it's impossible to distinguish some coding systems accurately -- cgit v1.2.3 From 1911a33b9dc4beefaf75f67719ea7f6cf447b3ff Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Sat, 2 Oct 2010 10:44:50 +0900 Subject: Fix complementing of a coding system --- src/ChangeLog | 7 +++++++ src/coding.c | 13 +++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src/coding.c') diff --git a/src/ChangeLog b/src/ChangeLog index 773715ed1f2..eb9ba22b0b2 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2010-10-02 Kenichi Handa + + * coding.c (coding_inherit_eol_type): If parent doesn't specify + eol-format, inherit from the system's default. + (complement_process_encoding_system): Make a new coding system + inherit the original eol-format. + 2010-09-30 Kenichi Handa * coding.c (complement_process_encoding_system): New function. diff --git a/src/coding.c b/src/coding.c index cbebeff6310..e2819f62e55 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6073,10 +6073,9 @@ raw_text_coding_system (coding_system) } -/* If CODING_SYSTEM doesn't specify end-of-line format but PARENT - does, return one of the subsidiary that has the same eol-spec as - PARENT. Otherwise, return CODING_SYSTEM. If PARENT is nil, - inherit end-of-line format from the system's setting +/* If CODING_SYSTEM doesn't specify end-of-line format, return one of + the subsidiary that has the same eol-spec as PARENT (if it is not + nil and specifies end-of-line format) or the system's setting (system_eol_type). */ Lisp_Object @@ -6099,6 +6098,8 @@ coding_inherit_eol_type (coding_system, parent) parent_spec = CODING_SYSTEM_SPEC (parent); parent_eol_type = AREF (parent_spec, 2); + if (VECTORP (parent_eol_type)) + parent_eol_type = system_eol_type; } else parent_eol_type = system_eol_type; @@ -6132,7 +6133,7 @@ complement_process_encoding_system (coding_system) if (EQ (coding_type, Qundecided)) { - /* We must decide the text-conversion part. */ + /* We must decide the text-conversion part ar first. */ if (CONSP (Vdefault_process_coding_system)) { coding_system = XCDR (Vdefault_process_coding_system); @@ -6162,7 +6163,7 @@ complement_process_encoding_system (coding_system) if (NILP (eol_type) || VECTORP (eol_type)) { /* We must decide the eol-conversion part. */ - coding_system = coding_inherit_eol_type (coding_system, Qnil); + coding_system = coding_inherit_eol_type (coding_system, coding_system); } return coding_system; -- cgit v1.2.3 From 5886ec9c0c7a250d987ac6180577b4574ea00f21 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Mon, 4 Oct 2010 10:47:51 +0900 Subject: coding.c (complement_process_encoding_system): Fix previous change. --- src/ChangeLog | 5 +++++ src/coding.c | 54 +++++++++++++++++++++++++++++------------------------- 2 files changed, 34 insertions(+), 25 deletions(-) (limited to 'src/coding.c') diff --git a/src/ChangeLog b/src/ChangeLog index eb9ba22b0b2..bb20d5739de 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-10-04 Kenichi Handa + + * coding.c (complement_process_encoding_system): Fix previous + change. + 2010-10-02 Kenichi Handa * coding.c (coding_inherit_eol_type): If parent doesn't specify diff --git a/src/coding.c b/src/coding.c index e2819f62e55..4b52c838d67 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6122,51 +6122,55 @@ Lisp_Object complement_process_encoding_system (coding_system) Lisp_Object coding_system; { - Lisp_Object spec, attrs, coding_type, eol_type; + Lisp_Object coding_base = Qnil, eol_base = Qnil; + Lisp_Object spec, attrs; if (NILP (coding_system)) coding_system = Qundecided; spec = CODING_SYSTEM_SPEC (coding_system); attrs = AREF (spec, 0); - coding_type = CODING_ATTR_TYPE (attrs); - eol_type = AREF (spec, 2); + if (! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) + coding_base = CODING_ATTR_BASE_NAME (attrs); + if (! VECTORP (AREF (spec, 2))) + eol_base = coding_system; - if (EQ (coding_type, Qundecided)) + if (NILP (coding_base)) { /* We must decide the text-conversion part ar first. */ - if (CONSP (Vdefault_process_coding_system)) + if (CONSP (Vdefault_process_coding_system) + && ! NILP (XCDR (Vdefault_process_coding_system))) { coding_system = XCDR (Vdefault_process_coding_system); - if (! NILP (coding_system)) - { - spec = CODING_SYSTEM_SPEC (coding_system); - attrs = AREF (spec, 0); - coding_type = CODING_ATTR_TYPE (attrs); - eol_type = AREF (spec, 2); - } + spec = CODING_SYSTEM_SPEC (coding_system); + attrs = AREF (spec, 0); + if (! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) + coding_base = CODING_ATTR_BASE_NAME (attrs); + if (NILP (eol_base) && ! VECTORP (AREF (spec, 2))) + eol_base = coding_system; } - if (EQ (coding_type, Qundecided)) + if (NILP (coding_base)) { coding_system = preferred_coding_system (); spec = CODING_SYSTEM_SPEC (coding_system); attrs = AREF (spec, 0); - coding_type = CODING_ATTR_TYPE (attrs); - eol_type = AREF (spec, 2); + if (! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) + coding_base = CODING_ATTR_BASE_NAME (attrs); + if (NILP (eol_base) && ! VECTORP (AREF (spec, 2))) + eol_base = coding_system; } - if (EQ (coding_type, Qundecided)) + if (NILP (coding_base)) { - coding_system = Qraw_text; - coding_type = Qraw_text; - eol_type = Qnil; + spec = CODING_SYSTEM_SPEC (Qraw_text); + attrs = AREF (spec, 0); + if (! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) + coding_base = CODING_ATTR_BASE_NAME (attrs); + if (NILP (eol_base) && ! VECTORP (AREF (spec, 2))) + eol_base = coding_system; } } - if (NILP (eol_type) || VECTORP (eol_type)) - { - /* We must decide the eol-conversion part. */ - coding_system = coding_inherit_eol_type (coding_system, coding_system); - } - return coding_system; + /* We must decide the eol-conversion part (if not yet done). */ + return coding_inherit_eol_type (coding_base, eol_base); } -- cgit v1.2.3 From 93d50df81d3aa5fa1db9e50e4107e262523e3ae9 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Fri, 8 Oct 2010 09:43:16 +0900 Subject: coding.c (complement_process_encoding_system): Fix previous change. --- src/ChangeLog | 5 +++++ src/coding.c | 65 ++++++++++++++++++++--------------------------------------- 2 files changed, 27 insertions(+), 43 deletions(-) (limited to 'src/coding.c') diff --git a/src/ChangeLog b/src/ChangeLog index 53adc561021..13ed963f6bf 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2010-10-08 Kenichi Handa + + * coding.c (complement_process_encoding_system): Fix previous + change. + 2010-10-04 Kenichi Handa * coding.c (complement_process_encoding_system): Fix previous diff --git a/src/coding.c b/src/coding.c index 4b52c838d67..8e6642bb80d 100644 --- a/src/coding.c +++ b/src/coding.c @@ -6124,53 +6124,32 @@ complement_process_encoding_system (coding_system) { Lisp_Object coding_base = Qnil, eol_base = Qnil; Lisp_Object spec, attrs; + int i; - if (NILP (coding_system)) - coding_system = Qundecided; - spec = CODING_SYSTEM_SPEC (coding_system); - attrs = AREF (spec, 0); - if (! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) - coding_base = CODING_ATTR_BASE_NAME (attrs); - if (! VECTORP (AREF (spec, 2))) - eol_base = coding_system; - - if (NILP (coding_base)) + for (i = 0; i < 3; i++) { - /* We must decide the text-conversion part ar first. */ - if (CONSP (Vdefault_process_coding_system) - && ! NILP (XCDR (Vdefault_process_coding_system))) - { - coding_system = XCDR (Vdefault_process_coding_system); - spec = CODING_SYSTEM_SPEC (coding_system); - attrs = AREF (spec, 0); - if (! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) - coding_base = CODING_ATTR_BASE_NAME (attrs); - if (NILP (eol_base) && ! VECTORP (AREF (spec, 2))) - eol_base = coding_system; - } - if (NILP (coding_base)) - { - coding_system = preferred_coding_system (); - spec = CODING_SYSTEM_SPEC (coding_system); - attrs = AREF (spec, 0); - if (! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) - coding_base = CODING_ATTR_BASE_NAME (attrs); - if (NILP (eol_base) && ! VECTORP (AREF (spec, 2))) - eol_base = coding_system; - } - if (NILP (coding_base)) - { - spec = CODING_SYSTEM_SPEC (Qraw_text); - attrs = AREF (spec, 0); - if (! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) - coding_base = CODING_ATTR_BASE_NAME (attrs); - if (NILP (eol_base) && ! VECTORP (AREF (spec, 2))) - eol_base = coding_system; - } + if (i == 1) + coding_system = CDR_SAFE (Vdefault_process_coding_system); + else if (i == 2) + coding_system = preferred_coding_system (); + spec = CODING_SYSTEM_SPEC (coding_system); + if (NILP (spec)) + continue; + attrs = AREF (spec, 0); + if (NILP (coding_base) && ! EQ (CODING_ATTR_TYPE (attrs), Qundecided)) + coding_base = CODING_ATTR_BASE_NAME (attrs); + if (NILP (eol_base) && ! VECTORP (AREF (spec, 2))) + eol_base = coding_system; + if (! NILP (coding_base) && ! NILP (eol_base)) + break; } - /* We must decide the eol-conversion part (if not yet done). */ - return coding_inherit_eol_type (coding_base, eol_base); + if (i > 0) + /* The original CODING_SYSTEM didn't specify text-conversion or + eol-conversion. Be sure that we return a fully complemented + coding system. */ + coding_system = coding_inherit_eol_type (coding_base, eol_base); + return coding_system; } -- cgit v1.2.3 From ad1746f5db1b4c52da8d7bdc52359d6b0a5a5e24 Mon Sep 17 00:00:00 2001 From: Kenichi Handa Date: Tue, 12 Oct 2010 21:52:05 +0900 Subject: Fix typos in comments --- src/coding.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'src/coding.c') diff --git a/src/coding.c b/src/coding.c index 8e6642bb80d..137e72a0ba4 100644 --- a/src/coding.c +++ b/src/coding.c @@ -167,7 +167,7 @@ detect_coding_XXX (coding, detect_info) while (1) { - /* Get one byte from the source. If the souce is exausted, jump + /* Get one byte from the source. If the source is exhausted, jump to no_more_source:. */ ONE_MORE_BYTE (c); @@ -181,7 +181,7 @@ detect_coding_XXX (coding, detect_info) return 0; no_more_source: - /* The source exausted successfully. */ + /* The source exhausted successfully. */ detect_info->found |= found; return 1; } @@ -537,7 +537,7 @@ enum iso_code_class_type on output. */ #define CODING_ISO_FLAG_DESIGNATE_AT_BOL 0x0400 -/* If set, do not encode unsafe charactes on output. */ +/* If set, do not encode unsafe characters on output. */ #define CODING_ISO_FLAG_SAFE 0x0800 /* If set, extra latin codes (128..159) are accepted as a valid code @@ -693,7 +693,7 @@ enum coding_category static Lisp_Object Vcoding_category_list; /* Table of coding categories (Lisp symbols). This variable is for - internal use oly. */ + internal use only. */ static Lisp_Object Vcoding_category_table; /* Table of coding-categories ordered by priority. */ @@ -825,7 +825,7 @@ static struct coding_system coding_categories[coding_category_max]; } while (0) -/* Like EMIT_ONE_ASCII_BYTE byt store two bytes; C1 and C2. */ +/* Like EMIT_ONE_ASCII_BYTE but store two bytes; C1 and C2. */ #define EMIT_TWO_ASCII_BYTES(c1, c2) \ do { \ @@ -1241,7 +1241,7 @@ alloc_destination (coding, nbytes, dst) METHOD is one of enum composition_method. - Optionnal COMPOSITION-COMPONENTS are characters and composition + Optional COMPOSITION-COMPONENTS are characters and composition rules. In the case of CODING_ANNOTATE_CHARSET_MASK, one element CHARSET-ID @@ -1954,7 +1954,7 @@ encode_coding_utf_16 (coding) CHARS is 0xA0 plus a number of characters composed by this data, - COMPONENTs are characters of multibye form or composition + COMPONENTs are characters of multibyte form or composition rules encoded by two-byte of ASCII codes. In addition, for backward compatibility, the following formats are @@ -2455,8 +2455,8 @@ decode_coding_emacs_mule (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; - /* We may produce two annocations (charset and composition) in one - loop and one more charset annocation at the end. */ + /* We may produce two annotations (charset and composition) in one + loop and one more charset annotation at the end. */ int *charbuf_end = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3); int consumed_chars = 0, consumed_chars_base; @@ -2532,7 +2532,7 @@ decode_coding_emacs_mule (coding) /* emacs_mule_char can load a charset map from a file, which allocates a large structure and might cause buffer text to be relocated as result. Thus, we need to remember the - original pointer to buffer text, and fixup all related + original pointer to buffer text, and fix up all related pointers after the call. */ const unsigned char *orig = coding->source; EMACS_INT offset; @@ -2559,7 +2559,7 @@ decode_coding_emacs_mule (coding) cmp_status->ncomps -= nchars; } - /* Now if C >= 0, we found a normally encoded characer, if C < + /* Now if C >= 0, we found a normally encoded character, if C < 0, we found an old-style composition component character or rule. */ @@ -3072,7 +3072,7 @@ setup_iso_safe_charsets (attrs) /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". - Check if a text is encoded in one of ISO-2022 based codig systems. + Check if a text is encoded in one of ISO-2022 based coding systems. If it is, return 1, else return 0. */ static int @@ -3484,7 +3484,7 @@ finish_composition (charbuf, cmp_status) return new_chars; } -/* If characers are under composition, finish the composition. */ +/* If characters are under composition, finish the composition. */ #define MAYBE_FINISH_COMPOSITION() \ do { \ if (cmp_status->state != COMPOSING_NO) \ @@ -3591,8 +3591,8 @@ decode_coding_iso_2022 (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; - /* We may produce two annocations (charset and composition) in one - loop and one more charset annocation at the end. */ + /* We may produce two annotations (charset and composition) in one + loop and one more charset annotation at the end. */ int *charbuf_end = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 3); int consumed_chars = 0, consumed_chars_base; @@ -3894,7 +3894,7 @@ decode_coding_iso_2022 (coding) goto invalid_code; /* For the moment, nested direction is not supported. So, `coding->mode & CODING_MODE_DIRECTION' zero means - left-to-right, and nozero means right-to-left. */ + left-to-right, and nonzero means right-to-left. */ ONE_MORE_BYTE (c1); switch (c1) { @@ -4807,7 +4807,7 @@ decode_coding_sjis (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; - /* We may produce one charset annocation in one loop and one more at + /* We may produce one charset annotation in one loop and one more at the end. */ int *charbuf_end = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); @@ -4926,7 +4926,7 @@ decode_coding_big5 (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; - /* We may produce one charset annocation in one loop and one more at + /* We may produce one charset annotation in one loop and one more at the end. */ int *charbuf_end = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); @@ -5592,7 +5592,7 @@ decode_coding_charset (coding) const unsigned char *src_end = coding->source + coding->src_bytes; const unsigned char *src_base; int *charbuf = coding->charbuf + coding->charbuf_used; - /* We may produce one charset annocation in one loop and one more at + /* We may produce one charset annotation in one loop and one more at the end. */ int *charbuf_end = coding->charbuf + coding->charbuf_size - (MAX_ANNOTATION_LENGTH * 2); @@ -6203,14 +6203,14 @@ complement_process_encoding_system (coding_system) o coding-category-iso-7-else The category for a coding system which has the same code range - as ISO2022 of 7-bit environemnt but uses locking shift or + as ISO2022 of 7-bit environment but uses locking shift or single shift functions. Assigned the coding-system (Lisp symbol) `iso-2022-7bit-lock' by default. o coding-category-iso-8-else The category for a coding system which has the same code range - as ISO2022 of 8-bit environemnt but uses locking shift or + as ISO2022 of 8-bit environment but uses locking shift or single shift functions. Assigned the coding-system (Lisp symbol) `iso-2022-8bit-ss2' by default. @@ -7635,7 +7635,7 @@ static Lisp_Object Vcode_conversion_reused_workbuf; static int reused_workbuf_in_use; -/* Return a working buffer of code convesion. MULTIBYTE specifies the +/* Return a working buffer of code conversion. MULTIBYTE specifies the multibyteness of returning buffer. */ static Lisp_Object @@ -8298,7 +8298,7 @@ function `define-coding-system'. */) /* Detect how the bytes at SRC of length SRC_BYTES are encoded. If HIGHEST is nonzero, return the coding system of the highest - priority among the detected coding systems. Otherwize return a + priority among the detected coding systems. Otherwise return a list of detected coding systems sorted by their priorities. If MULTIBYTEP is nonzero, it is assumed that the bytes are in correct multibyte form but contains only ASCII and eight-bit chars. @@ -9423,7 +9423,7 @@ DEFUN ("set-terminal-coding-system-internal", Fset_terminal_coding_system_intern setup_coding_system (Fcheck_coding_system (coding_system), terminal_coding); /* We had better not send unsafe characters to terminal. */ terminal_coding->mode |= CODING_MODE_SAFE_ENCODING; - /* Characer composition should be disabled. */ + /* Character composition should be disabled. */ terminal_coding->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; terminal_coding->src_multibyte = 1; terminal_coding->dst_multibyte = 0; @@ -9440,7 +9440,7 @@ DEFUN ("set-safe-terminal-coding-system-internal", CHECK_SYMBOL (coding_system); setup_coding_system (Fcheck_coding_system (coding_system), &safe_terminal_coding); - /* Characer composition should be disabled. */ + /* Character composition should be disabled. */ safe_terminal_coding.common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; safe_terminal_coding.src_multibyte = 1; safe_terminal_coding.dst_multibyte = 0; @@ -9477,7 +9477,7 @@ DEFUN ("set-keyboard-coding-system-internal", Fset_keyboard_coding_system_intern else Fcheck_coding_system (coding_system); setup_coding_system (coding_system, TERMINAL_KEYBOARD_CODING (t)); - /* Characer composition should be disabled. */ + /* Character composition should be disabled. */ TERMINAL_KEYBOARD_CODING (t)->common_flags &= ~CODING_ANNOTATE_COMPOSITION_MASK; return Qnil; @@ -9854,7 +9854,7 @@ usage: (define-coding-system-internal ...) */) If Nth element is a list of charset IDs, N is the first byte of one of them. The list is sorted by dimensions of the - charsets. A charset of smaller dimension comes firtst. */ + charsets. A charset of smaller dimension comes first. */ val = Fmake_vector (make_number (256), Qnil); for (tail = charset_list; CONSP (tail); tail = XCDR (tail)) -- cgit v1.2.3