Changeset 1490

Show
Ignore:
Timestamp:
02/17/98 01:45:05 (11 years ago)
Author:
himi
Message:

Meadow--Multilingual Enhancement to GNU Emacs with ADvantages Over Windows

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/GNU/src/cm.c

    r1488 r1490  
    3636 
    3737/* ARGSUSED */ 
    38 int 
    3938evalcost (c) 
    4039     char c; 
     
    4443} 
    4544 
    46 int 
    4745cmputc (c) 
    4846     char c; 
     
    138136 */ 
    139137 
    140 void 
    141138cmcostinit () 
    142139{ 
     
    178175 */ 
    179176 
    180 static int 
     177static 
    181178calccost (srcy, srcx, dsty, dstx, doit) 
    182179{ 
     
    313310#define USECR   3 
    314311 
    315 void 
    316312cmgoto (row, col) 
    317313{ 
     
    416412 */ 
    417413 
    418 void 
    419414Wcm_clear () 
    420415{ 
     
    431426 */ 
    432427 
    433 int 
    434428Wcm_init () 
    435429{ 
  • branches/GNU/src/cm.h

    r1488 r1490  
    178178extern void cmcheckmagic (); 
    179179extern int cmputc (); 
    180 extern void cmcostinit (); 
    181 extern void cmgoto (); 
    182 extern void Wcm_clear (); 
     180extern int cmcostinit (); 
     181extern int cmgoto (); 
     182extern int Wcm_clear (); 
    183183extern int Wcm_init (); 
  • branches/GNU/src/cmds.c

    r1488 r1490  
    11/* Simple built-in editing commands. 
    2    Copyright (C) 1985, 93, 94, 95, 96, 97, 1998 Free Software Foundation, Inc. 
     2   Copyright (C) 1985, 93, 94, 95, 96, 1997 Free Software Foundation, Inc. 
    33 
    44This file is part of GNU Emacs. 
     
    2828#include "window.h" 
    2929#include "keyboard.h" 
    30 #include "dispextern.h" 
    3130 
    3231Lisp_Object Qkill_forward_chars, Qkill_backward_chars, Vblink_paren_function; 
     
    4140Lisp_Object Vself_insert_face_command; 
    4241 
     42/* Offset to add to a non-ASCII value when inserting it.  */ 
     43int nonascii_insert_offset; 
     44 
    4345extern Lisp_Object Qface; 
    4446  
     47/* Return buffer position which is N characters after `point'.  */ 
     48int 
     49forward_point (n) 
     50     int n; 
     51{ 
     52  int pos = PT, c; 
     53 
     54  if (!NILP (current_buffer->enable_multibyte_characters)) 
     55    { 
     56      /* Simply adding N to `point' doesn't work because of multi-byte 
     57         form.  We had better not use INC_POS and DEC_POS because they 
     58         check the gap position every time.  But, for the moment, we 
     59         need working code.  */ 
     60      if (n > 0) 
     61        { 
     62          while (pos < ZV && n--) INC_POS (pos); 
     63          if (pos < ZV) n++; 
     64        } 
     65      else 
     66        { 
     67          while (pos > BEGV && n++) DEC_POS (pos); 
     68          if (pos > BEGV) n--; 
     69        } 
     70    } 
     71  pos += n; 
     72 
     73  return pos; 
     74} 
     75 
    4576DEFUN ("forward-point", Fforward_point, Sforward_point, 1, 1, 0, 
    4677  "Return buffer position N characters after (before if N negative) point.") 
     
    5081  CHECK_NUMBER (n, 0); 
    5182 
    52   return make_number (PT + XINT (n)); 
     83  return make_number (forward_point (XINT (n))); 
    5384} 
    5485 
     
    70101     proposed position, then set point.  */ 
    71102  { 
    72     int new_point = PT + XINT (n); 
     103    int new_point = forward_point (XINT (n)); 
    73104 
    74105    if (new_point < BEGV) 
     
    115146     Lisp_Object n; 
    116147{ 
    117   int opoint = PT, opoint_byte = PT_BYTE; 
    118   int pos, pos_byte; 
    119   int count, shortage; 
    120   int temp; 
     148  int pos2 = PT; 
     149  int pos; 
     150  int count, shortage, negp; 
    121151 
    122152  if (NILP (n)) 
     
    128158    } 
    129159 
    130   if (count <= 0) 
    131     shortage = scan_newline (PT, PT_BYTE, BEGV, BEGV_BYTE, count - 1, 1); 
    132   else 
    133     shortage = scan_newline (PT, PT_BYTE, ZV, ZV_BYTE, count, 1); 
    134  
    135   /* Since scan_newline does TEMP_SET_PT_BOTH, 
    136      and we want to set PT "for real", 
    137      go back to the old point and then come back here.  */ 
    138   pos = PT; 
    139   pos_byte = PT_BYTE; 
    140   TEMP_SET_PT_BOTH (opoint, opoint_byte); 
    141   SET_PT_BOTH (pos, pos_byte); 
    142  
     160  negp = count <= 0; 
     161  pos = scan_buffer ('\n', pos2, 0, count - negp, &shortage, 1); 
    143162  if (shortage > 0 
    144       && (count <= 0 
     163      && (negp 
    145164          || (ZV > BEGV 
    146               && PT != opoint 
    147               && (FETCH_BYTE (PT_BYTE - 1) != '\n')))) 
     165              && pos != pos2 
     166              && FETCH_BYTE (pos - 1) != '\n'))) 
    148167    shortage--; 
    149  
    150   return make_number (count <= 0 ? - shortage : shortage); 
     168  SET_PT (pos); 
     169  return make_number (negp ? - shortage : shortage); 
    151170} 
    152171 
     
    201220  CHECK_NUMBER (n, 0); 
    202221 
    203   pos = PT + XINT (n); 
     222  pos = forward_point (XINT (n)); 
    204223  if (NILP (killflag)) 
    205224    { 
     
    237256  Lisp_Object value; 
    238257  int deleted_special = 0; 
    239   int pos, pos_byte, i; 
     258  int pos, i; 
    240259 
    241260  CHECK_NUMBER (n, 0); 
     
    243262  /* See if we are about to delete a tab or newline backwards.  */ 
    244263  pos = PT; 
    245   pos_byte = PT_BYTE; 
    246   for (i = 0; i < XINT (n) && pos_byte > BEGV_BYTE; i++) 
     264  for (i = 0; i < XINT (n) && pos > BEGV; i++) 
    247265    { 
    248266      int c; 
    249267 
    250       DEC_BOTH (pos, pos_byte); 
    251       c = FETCH_BYTE (pos_byte); 
     268      DEC_POS (pos); 
     269      c = FETCH_BYTE (pos); 
    252270      if (c == '\t' || c == '\n') 
    253271        { 
     
    262280      && ! NILP (current_buffer->overwrite_mode) 
    263281      && ! deleted_special 
    264       && ! (PT == ZV || FETCH_BYTE (PT_BYTE) == '\n')) 
     282      && ! (PT == ZV || FETCH_BYTE (PT) == '\n')) 
    265283    { 
    266284      int column = current_column (); 
     
    269287      i = column - current_column (); 
    270288      Finsert_char (make_number (' '), make_number (i), Qnil); 
    271       /* Whitespace chars are ASCII chars, so we can simply subtract.  */ 
    272       SET_PT_BOTH (PT - i, PT_BYTE - i); 
     289      SET_PT (PT - i); 
    273290    } 
    274291  else 
     
    297314         We pass internal_self_insert the unmodified character 
    298315         because it itself does this offsetting.  */ 
    299       if (! NILP (current_buffer->enable_multibyte_characters)) 
    300         modified_char = unibyte_char_to_multibyte (modified_char); 
     316      if (modified_char >= 0200 && modified_char <= 0377 
     317          && ! NILP (current_buffer->enable_multibyte_characters)) 
     318        modified_char += nonascii_insert_offset; 
    301319 
    302320      XSETFASTINT (n, XFASTINT (n) - 2); 
     
    328346   A value of 2 means this did things that call for an undo boundary.  */ 
    329347 
    330 int 
    331348internal_self_insert (c, noautofill) 
    332349     int c; 
     
    342359  /* Working buffer and pointer for multi-byte form of C.  */ 
    343360  unsigned char workbuf[4], *str; 
    344   int chars_to_delete = 0; 
     361  int number_to_delete = 0; 
    345362  int spaces_to_insert = 0; 
     363 
     364  if (c >= 0200 && c <= 0377 
     365      && ! NILP (current_buffer->enable_multibyte_characters)) 
     366    c += nonascii_insert_offset; 
    346367 
    347368  overwrite = current_buffer->overwrite_mode; 
     
    352373  /* At first, get multi-byte form of C in STR.  */ 
    353374  if (!NILP (current_buffer->enable_multibyte_characters)) 
    354     { 
    355       c = unibyte_char_to_multibyte (c); 
    356       len = CHAR_STRING (c, workbuf, str); 
    357     } 
    358   else 
    359     { 
    360       workbuf[0] = (SINGLE_BYTE_CHAR_P (c) 
    361                     ? c 
    362                     : multibyte_char_to_unibyte (c, Qnil)); 
    363       str = workbuf; 
    364       len = 1; 
    365     } 
     375    len = CHAR_STRING (c, workbuf, str); 
     376  else 
     377    workbuf[0] = c, str = workbuf, len = 1; 
     378 
    366379  if (!NILP (overwrite) 
    367380      && PT < ZV) 
     
    376389         C2 and several characters following C2.  */ 
    377390 
    378       /* This is the character after point.  */ 
    379       int c2 = FETCH_CHAR (PT_BYTE); 
    380  
    381       /* Column the cursor should be placed at after this insertion. 
     391      /* A code at `point'.  Since this is checked only against 
     392         NEWLINE and TAB, we don't need a character code but only the 
     393         first byte of multi-byte form.  */ 
     394      unsigned char c2 = FETCH_BYTE (PT); 
     395      /* A column the cursor should be placed at after this insertion. 
    382396         The correct value should be calculated only when necessary.  */ 
    383397      int target_clm = 0; 
     
    394408                    && XINT (current_buffer->tab_width) > 0 
    395409                    && XFASTINT (current_buffer->tab_width) < 20 
    396                     && (target_clm = (current_column ()  
    397                                       + XINT (Fchar_width (make_number (c2)))), 
     410                    && ((NILP (current_buffer->enable_multibyte_characters) 
     411                         ? (target_clm = current_column () + 1) 
     412                         : (target_clm = current_column () + WIDTH_BY_CHAR_HEAD (str[0]))), 
    398413                        target_clm % XFASTINT (current_buffer->tab_width))))) 
    399414        { 
    400415          int pos = PT; 
    401           int pos_byte = PT_BYTE; 
    402416 
    403417          if (target_clm == 0) 
    404             chars_to_delete = 1
     418            number_to_delete = forward_point (1) - PT
    405419          else 
    406420            { 
     
    413427                = XFASTINT (Fmove_to_column (make_number (target_clm), Qnil)); 
    414428 
    415               chars_to_delete = PT - pos; 
     429              number_to_delete = PT - pos; 
    416430 
    417431              if (actual_clm > target_clm) 
     
    422436                } 
    423437            } 
    424           SET_PT_BOTH (pos, pos_byte); 
     438          SET_PT (pos); 
    425439          hairy = 2; 
    426440        } 
     
    453467    } 
    454468 
    455   if (chars_to_delete) 
    456     { 
    457       string = make_string_from_bytes (str, 1, len); 
     469  if (number_to_delete) 
     470    { 
     471      string = make_string (str, len); 
    458472      if (spaces_to_insert) 
    459473        { 
     
    463477        } 
    464478 
    465       replace_range (PT, PT + chars_to_delete, string, 1, 1, 1); 
    466       Fforward_char (make_number (1 + spaces_to_insert)); 
     479      replace_range (PT, PT + number_to_delete, string, 1, 1); 
     480      SET_PT (PT + XSTRING (string)->size); 
    467481    } 
    468482  else 
     
    476490 
    477491      if (c == '\n') 
    478         /* After inserting a newline, move to previous line and fill 
    479            that.  Must have the newline in place already so filling and 
    480            justification, if any, know where the end is going to be. */ 
    481         SET_PT_BOTH (PT - 1, PT_BYTE - 1); 
     492        /* After inserting a newline, move to previous line and fill */ 
     493        /* that.  Must have the newline in place already so filling and */ 
     494        /* justification, if any, know where the end is going to be. */ 
     495        SET_PT (PT - 1); 
    482496      tem = call0 (current_buffer->auto_fill_function); 
    483497      if (c == '\n') 
    484         SET_PT_BOTH (PT + 1, PT_BYTE + 1); 
     498        SET_PT (PT + 1); 
    485499      if (!NILP (tem)) 
    486500        hairy = 2; 
     
    492506      && EQ (current_kboard->Vlast_command, Vself_insert_face_command)) 
    493507    { 
    494       Fput_text_property (make_number (PT - 1), make_number (PT), 
    495                           Qface, Vself_insert_face, Qnil); 
     508      Lisp_Object before, after; 
     509      XSETINT (before, PT - len); 
     510      XSETINT (after, PT); 
     511      Fput_text_property (before, after, Qface, Vself_insert_face, Qnil); 
    496512      Vself_insert_face = Qnil; 
    497513    } 
     
    511527/* module initialization */ 
    512528 
    513 void 
    514529syms_of_cmds () 
    515530{ 
     
    537552More precisely, a char with closeparen syntax is self-inserted."); 
    538553  Vblink_paren_function = Qnil; 
     554 
     555  DEFVAR_INT ("nonascii-insert-offset", &nonascii_insert_offset, 
     556    "Offset to add to a non-ascii code 0200...0377 when inserting it.\n\ 
     557This applies only when multibyte characters are enabled, and it serves\n\ 
     558to convert a Latin-1 or similar 8-bit character code to the corresponding\n\ 
     559Emacs character code."); 
     560  nonascii_insert_offset = 0; 
    539561 
    540562  defsubr (&Sforward_point); 
     
    551573} 
    552574 
    553 void 
    554575keys_of_cmds () 
    555576{ 
  • branches/GNU/src/coding.c

    r1488 r1490  
    11/* Coding system handler (conversion, detection, and etc). 
    2    Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN. 
     2   Copyright (C) 1995, 1997 Electrotechnical Laboratory, JAPAN. 
    33   Licensed to the Free Software Foundation. 
    44 
     
    2626  3. ISO2022 handlers 
    2727  4. Shift-JIS and BIG5 handlers 
    28   5. CCL handlers 
    29   6. End-of-line handlers 
    30   7. C library functions 
    31   8. Emacs Lisp library functions 
    32   9. Post-amble 
     28  5. End-of-line handlers 
     29  6. C library functions 
     30  7. Emacs Lisp library functions 
     31  8. Post-amble 
    3332 
    3433*/ 
     
    7170  4. Raw text 
    7271 
    73   A coding system for a text containing random 8-bit code.  Emacs does 
    74   no code conversion on such a text except for end-of-line format. 
     72  A coding system to for a text containing random 8-bit code.  Emacs 
     73  does no code conversion on such a text except for end-of-line 
     74  format. 
    7575 
    7676  5. Other 
     
    8181  while reading/writing. 
    8282 
    83   Emacs represents a coding system by a Lisp symbol that has a property 
    84   `coding-system'.  But, before actually using the coding system, the 
     83  Emacs represents a coding-system by a Lisp symbol that has a property 
     84  `coding-system'.  But, before actually using the coding-system, the 
    8585  information about it is set in a structure of type `struct 
    8686  coding_system' for rapid processing.  See section 6 for more details. 
     
    9393  instance, Unix's format is just one byte of `line-feed' code, 
    9494  whereas DOS's format is two-byte sequence of `carriage-return' and 
    95   `line-feed' codes.  MacOS's format is usually one byte of 
    96   `carriage-return'. 
     95  `line-feed' codes.  MacOS's format is one byte of `carriage-return'. 
    9796 
    9897  Since text characters encoding and end-of-line encoding are 
     
    123122  These functions decode SRC_BYTES length text at SOURCE encoded in 
    124123  CODING to Emacs' internal format (emacs-mule).  The resulting text 
    125   goes to a place pointed to by DESTINATION, the length of which 
    126   should not exceed DST_BYTES.  These functions set the information of 
    127   original and decoded texts in the members produced, produced_char, 
    128   consumed, and consumed_char of the structure *CODING. 
    129  
    130   The return value is an integer (CODING_FINISH_XXX) indicating how 
    131   the decoding finished. 
    132  
    133   DST_BYTES zero means that source area and destination area are 
    134   overlapped, which means that we can produce a decoded text until it 
    135   reaches at the head of not-yet-decoded source text. 
    136  
    137   Below is a template of these functions.  */ 
     124  goes to a place pointed to by DESTINATION, the length of which should 
     125  not exceed DST_BYTES.  The number of bytes actually processed is 
     126  returned as *CONSUMED.  The return value is the length of the decoded 
     127  text.  Below is a template of these functions.  */ 
    138128#if 0 
    139 decode_coding_XXX (coding, source, destination, src_bytes, dst_bytes
     129decode_coding_XXX (coding, source, destination, src_bytes, dst_bytes, consumed
    140130     struct coding_system *coding; 
    141131     unsigned char *source, *destination; 
    142132     int src_bytes, dst_bytes; 
     133     int *consumed; 
    143134{ 
    144135  ... 
     
    151142  internal format (emacs-mule) to CODING.  The resulting text goes to 
    152143  a place pointed to by DESTINATION, the length of which should not 
    153   exceed DST_BYTES.  These functions set the information of 
    154   original and encoded texts in the members produced, produced_char, 
    155   consumed, and consumed_char of the structure *CODING. 
    156  
    157   The return value is an integer (CODING_FINISH_XXX) indicating how 
    158   the encoding finished. 
    159  
    160   DST_BYTES zero means that source area and destination area are 
    161   overlapped, which means that we can produce a decoded text until it 
    162   reaches at the head of not-yet-decoded source text. 
    163  
    164   Below is a template of these functions.  */ 
     144  exceed DST_BYTES.  The number of bytes actually processed is 
     145  returned as *CONSUMED.  The return value is the length of the 
     146  encoded text.  Below is a template of these functions.  */ 
    165147#if 0 
    166 encode_coding_XXX (coding, source, destination, src_bytes, dst_bytes
     148encode_coding_XXX (coding, source, destination, src_bytes, dst_bytes, consumed
    167149     struct coding_system *coding; 
    168150     unsigned char *source, *destination; 
    169151     int src_bytes, dst_bytes; 
     152     int *consumed; 
    170153{ 
    171154  ... 
     
    219202      *dst++ = 0xA0, *dst++ = (c) | 0x80;                       \ 
    220203    else                                                        \ 
    221       {                                                         \ 
    222         *dst++ = (c);                                           \ 
    223         coding->produced_char++;                                \ 
    224       }                                                         \ 
     204      *dst++ = (c);                                             \ 
    225205  } while (0) 
    226206 
     
    234214      *dst++ = leading_code + 0x20;                                     \ 
    235215    else                                                                \ 
    236       {                                                                 \ 
    237         *dst++ = leading_code;                                          \ 
    238         coding->produced_char++;                                        \ 
    239       }                                                                 \ 
     216      *dst++ = leading_code;                                            \ 
    240217    if (leading_code = CHARSET_LEADING_CODE_EXT (charset))              \ 
    241218      *dst++ = leading_code;                                            \ 
     
    278255Lisp_Object Qno_conversion, Qundecided; 
    279256Lisp_Object Qcoding_system_history; 
    280 Lisp_Object Qsafe_charsets; 
    281 Lisp_Object Qvalid_codes; 
    282257 
    283258extern Lisp_Object Qinsert_file_contents, Qwrite_region; 
     
    285260Lisp_Object Qstart_process, Qopen_network_stream; 
    286261Lisp_Object Qtarget_idx; 
    287  
    288 Lisp_Object Vselect_safe_coding_system_function; 
    289262 
    290263/* Mnemonic character of each format of end-of-line.  */ 
     
    300273#ifdef emacs 
    301274 
    302 Lisp_Object Vcoding_system_list, Vcoding_system_alist; 
    303  
    304 Lisp_Object Qcoding_system_p, Qcoding_system_error; 
    305  
    306 /* Coding system emacs-mule and raw-text are for converting only 
    307    end-of-line format.  */ 
    308 Lisp_Object Qemacs_mule, Qraw_text; 
     275Lisp_Object Qcoding_system_spec, Qcoding_system_p, Qcoding_system_error; 
     276 
     277/* Coding system emacs-mule is for converting only end-of-line format.  */ 
     278Lisp_Object Qemacs_mule; 
    309279 
    310280/* Coding-systems are handed between Emacs Lisp programs and C internal 
     
    318288 
    319289/* A vector of length 256 which contains information about special 
    320    Latin codes (especially for dealing with Microsoft codes).  */ 
     290   Latin codes (espepcially for dealing with Microsoft code).  */ 
    321291Lisp_Object Vlatin_extra_code_table; 
    322292 
    323293/* Flag to inhibit code conversion of end-of-line format.  */ 
    324294int inhibit_eol_conversion; 
    325  
    326 /* Flag to make buffer-file-coding-system inherit from process-coding.  */ 
    327 int inherit_process_coding_system; 
    328295 
    329296/* Coding system to be used to encode text for terminal display.  */ 
     
    337304struct coding_system keyboard_coding; 
    338305 
    339 /* Default coding system to be used to write a file.  */ 
    340 struct coding_system default_buffer_file_coding; 
    341  
    342306Lisp_Object Vfile_coding_system_alist; 
    343307Lisp_Object Vprocess_coding_system_alist; 
     
    346310#endif /* emacs */ 
    347311 
    348 Lisp_Object Qcoding_category, Qcoding_category_index; 
     312Lisp_Object Qcoding_category_index; 
    349313 
    350314/* List of symbols `coding-category-xxx' ordered by priority.  */ 
    351315Lisp_Object Vcoding_category_list; 
    352316 
    353 /* Table of coding categories (Lisp symbols).  */ 
    354 Lisp_Object Vcoding_category_table
     317/* Table of coding-systems currently assigned to each coding-category.  */ 
     318Lisp_Object coding_category_table[CODING_CATEGORY_IDX_MAX]
    355319 
    356320/* Table of names of symbol for each coding-category.  */ 
     
    359323  "coding-category-sjis", 
    360324  "coding-category-iso-7", 
    361   "coding-category-iso-7-tight", 
    362325  "coding-category-iso-8-1", 
    363326  "coding-category-iso-8-2", 
    364327  "coding-category-iso-7-else", 
    365328  "coding-category-iso-8-else", 
    366   "coding-category-ccl", 
    367329  "coding-category-big5", 
    368330  "coding-category-raw-text", 
     
    370332}; 
    371333 
    372 /* Table of pointers to coding systems corresponding to each coding 
    373    categories.  */ 
    374 struct coding_system *coding_system_table[CODING_CATEGORY_IDX_MAX]; 
    375  
    376 /* Table of coding category masks.  Nth element is a mask for a coding 
    377    cateogry of which priority is Nth.  */ 
    378 static 
    379 int coding_priorities[CODING_CATEGORY_IDX_MAX]; 
    380  
    381 /* Flag to tell if we look up translation table on character code 
     334/* Flag to tell if we look up unification table on character code 
    382335   conversion.  */ 
    383 Lisp_Object Venable_character_translation; 
    384 /* Standard translation table to look up on decoding (reading).  */ 
    385 Lisp_Object Vstandard_translation_table_for_decode; 
    386 /* Standard translation table to look up on encoding (writing).  */ 
    387 Lisp_Object Vstandard_translation_table_for_encode; 
    388  
    389 Lisp_Object Qtranslation_table; 
    390 Lisp_Object Qtranslation_table_id; 
    391 Lisp_Object Qtranslation_table_for_decode; 
    392 Lisp_Object Qtranslation_table_for_encode; 
     336Lisp_Object Venable_character_unification; 
     337/* Standard unification table to look up on decoding (reading).  */ 
     338Lisp_Object Vstandard_character_unification_table_for_decode; 
     339/* Standard unification table to look up on encoding (writing).  */ 
     340Lisp_Object Vstandard_character_unification_table_for_encode; 
     341 
     342Lisp_Object Qcharacter_unification_table; 
     343Lisp_Object Qcharacter_unification_table_for_decode; 
     344Lisp_Object Qcharacter_unification_table_for_encode; 
    393345 
    394346/* Alist of charsets vs revision number.  */ 
     
    446398/* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". 
    447399   Check if a text is encoded in Emacs' internal format.  If it is, 
    448    return CODING_CATEGORY_MASK_EMACS_MULE, else return 0.  */ 
     400   return CODING_CATEGORY_MASK_EMASC_MULE, else return 0.  */ 
    449401 
    450402int 
     
    656608enum iso_code_class_type iso_code_class[256]; 
    657609 
    658 #define CHARSET_OK(idx, charset)                                \ 
    659   (coding_system_table[idx]                                     \ 
    660    && (coding_system_table[idx]->safe_charsets[charset]         \ 
    661        || (CODING_SPEC_ISO_REQUESTED_DESIGNATION                \ 
    662             (coding_system_table[idx], charset)                 \ 
    663            != CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION))) 
    664  
    665 #define SHIFT_OUT_OK(idx) \ 
    666   (CODING_SPEC_ISO_INITIAL_DESIGNATION (coding_system_table[idx], 1) >= 0) 
    667  
    668610/* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". 
    669611   Check if a text is encoded in ISO2022.  If it is, returns an 
    670612   integer in which appropriate flag bits any of: 
    671613        CODING_CATEGORY_MASK_ISO_7 
    672         CODING_CATEGORY_MASK_ISO_7_TIGHT 
    673614        CODING_CATEGORY_MASK_ISO_8_1 
    674615        CODING_CATEGORY_MASK_ISO_8_2 
     
    682623     unsigned char *src, *src_end; 
    683624{ 
    684   int mask = CODING_CATEGORY_MASK_ISO; 
    685   int mask_found = 0; 
    686   int reg[4], shift_out = 0; 
    687   int c, c1, i, charset; 
    688  
    689   reg[0] = CHARSET_ASCII, reg[1] = reg[2] = reg[3] = -1; 
     625  int mask = (CODING_CATEGORY_MASK_ISO_7 
     626              | CODING_CATEGORY_MASK_ISO_8_1 
     627              | CODING_CATEGORY_MASK_ISO_8_2 
     628              | CODING_CATEGORY_MASK_ISO_7_ELSE 
     629              | CODING_CATEGORY_MASK_ISO_8_ELSE 
     630              ); 
     631  int g1 = 0;                   /* 1 iff designating to G1.  */ 
     632  int c, i; 
     633  struct coding_system coding_iso_8_1, coding_iso_8_2; 
     634 
     635  /* Coding systems of these categories may accept latin extra codes.  */ 
     636  setup_coding_system 
     637    (XSYMBOL (coding_category_table[CODING_CATEGORY_IDX_ISO_8_1])->value, 
     638     &coding_iso_8_1); 
     639  setup_coding_system 
     640    (XSYMBOL (coding_category_table[CODING_CATEGORY_IDX_ISO_8_2])->value, 
     641     &coding_iso_8_2); 
     642 
    690643  while (mask && src < src_end) 
    691644    { 
     
    697650            break; 
    698651          c = *src++; 
    699           if (c >= '(' && c <= '/'
     652          if ((c >= '(' && c <= '/')
    700653            { 
    701654              /* Designation sequence for a charset of dimension 1.  */ 
    702655              if (src >= src_end) 
    703656                break; 
    704               c1 = *src++; 
    705               if (c1 < ' ' || c1 >= 0x80 
    706                   || (charset = iso_charset_table[0][c >= ','][c1]) < 0) 
    707                 /* Invalid designation sequence.  Just ignore.  */ 
    708                 break; 
    709               reg[(c - '(') % 4] = charset; 
     657              c = *src++; 
     658              if (c < ' ' || c >= 0x80) 
     659                /* Invalid designation sequence.  */ 
     660                return 0; 
    710661            } 
    711662          else if (c == '$') 
     
    717668              if (c >= '@' && c <= 'B') 
    718669                /* Designation for JISX0208.1978, GB2312, or JISX0208.  */ 
    719                 reg[0] = charset = iso_charset_table[1][0][c]
     670               
    720671              else if (c >= '(' && c <= '/') 
    721672                { 
    722673                  if (src >= src_end) 
    723674                    break; 
    724                   c1 = *src++; 
    725                   if (c1 < ' ' || c1 >= 0x80 
    726                       || (charset = iso_charset_table[1][c >= ','][c1]) < 0) 
    727                     /* Invalid designation sequence.  Just ignore.  */ 
    728                     break; 
    729                   reg[(c - '(') % 4] = charset; 
     675                  c = *src++; 
     676                  if (c < ' ' || c >= 0x80) 
     677                    /* Invalid designation sequence.  */ 
     678                    return 0; 
    730679                } 
    731680              else 
    732                 /* Invalid designation sequence.  Just ignore.  */ 
    733                 break
     681                /* Invalid designation sequence.  */ 
     682                return 0
    734683            } 
    735           else if (c == 'N' || c == 'n') 
    736             { 
    737               if (shift_out == 0 
    738                   && (reg[1] >= 0 
    739                       || SHIFT_OUT_OK (CODING_CATEGORY_IDX_ISO_7_ELSE) 
    740                       || SHIFT_OUT_OK (CODING_CATEGORY_IDX_ISO_8_ELSE))) 
    741                 { 
    742                   /* Locking shift out.  */ 
    743                   mask &= ~CODING_CATEGORY_MASK_ISO_7BIT; 
    744                   mask_found |= CODING_CATEGORY_MASK_ISO_SHIFT; 
    745                   shift_out = 1; 
    746                 } 
    747               break; 
    748             } 
    749           else if (c == 'O' || c == 'o') 
    750             { 
    751               if (shift_out == 1) 
    752                 { 
    753                   /* Locking shift in.  */ 
    754                   mask &= ~CODING_CATEGORY_MASK_ISO_7BIT; 
    755                   mask_found |= CODING_CATEGORY_MASK_ISO_SHIFT; 
    756                   shift_out = 0; 
    757                 } 
    758               break; 
    759             } 
     684          else if (c == 'N' || c == 'O' || c == 'n' || c == 'o') 
     685            /* Locking shift.  */ 
     686            mask &= (CODING_CATEGORY_MASK_ISO_7_ELSE 
     687                     | CODING_CATEGORY_MASK_ISO_8_ELSE); 
    760688          else if (c == '0' || c == '1' || c == '2') 
    761             /* Start/end composition.  Just ignore.  */ 
    762             break
     689            /* Start/end composition.  */ 
     690           
    763691          else 
    764             /* Invalid escape sequence.  Just ignore.  */ 
    765             break; 
    766  
    767           /* We found a valid designation sequence for CHARSET.  */ 
    768           mask &= ~CODING_CATEGORY_MASK_ISO_8BIT; 
    769           if (CHARSET_OK (CODING_CATEGORY_IDX_ISO_7, charset)) 
    770             mask_found |= CODING_CATEGORY_MASK_ISO_7; 
    771           else 
    772             mask &= ~CODING_CATEGORY_MASK_ISO_7; 
    773           if (CHARSET_OK (CODING_CATEGORY_IDX_ISO_7_TIGHT, charset)) 
    774             mask_found |= CODING_CATEGORY_MASK_ISO_7_TIGHT; 
    775           else 
    776             mask &= ~CODING_CATEGORY_MASK_ISO_7_TIGHT; 
    777           if (! CHARSET_OK (CODING_CATEGORY_IDX_ISO_7_ELSE, charset)) 
    778             mask &= ~CODING_CATEGORY_MASK_ISO_7_ELSE; 
    779           if (! CHARSET_OK (CODING_CATEGORY_IDX_ISO_8_ELSE, charset)) 
    780             mask &= ~CODING_CATEGORY_MASK_ISO_8_ELSE; 
     692            /* Invalid escape sequence.  */ 
     693            return 0; 
    781694          break; 
    782695 
    783696        case ISO_CODE_SO: 
    784           if (shift_out == 0 
    785               && (reg[1] >= 0 
    786                   || SHIFT_OUT_OK (CODING_CATEGORY_IDX_ISO_7_ELSE) 
    787                   || SHIFT_OUT_OK (CODING_CATEGORY_IDX_ISO_8_ELSE))) 
    788             { 
    789               /* Locking shift out.  */ 
    790               mask &= ~CODING_CATEGORY_MASK_ISO_7BIT; 
    791               mask_found |= CODING_CATEGORY_MASK_ISO_SHIFT; 
    792             } 
     697          mask &= (CODING_CATEGORY_MASK_ISO_7_ELSE 
     698                   | CODING_CATEGORY_MASK_ISO_8_ELSE); 
    793699          break; 
    794700           
    795         case ISO_CODE_SI: 
    796           if (shift_out == 1) 
    797             { 
    798               /* Locking shift in.  */ 
    799               mask &= ~CODING_CATEGORY_MASK_ISO_7BIT; 
    800               mask_found |= CODING_CATEGORY_MASK_ISO_SHIFT; 
    801             } 
    802           break; 
    803  
    804701        case ISO_CODE_CSI: 
    805702        case ISO_CODE_SS2: 
     
    808705            int newmask = CODING_CATEGORY_MASK_ISO_8_ELSE; 
    809706 
    810             if (c != ISO_CODE_CSI) 
    811               { 
    812                 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_1]->flags 
    813                     & CODING_FLAG_ISO_SINGLE_SHIFT) 
    814                   newmask |= CODING_CATEGORY_MASK_ISO_8_1; 
    815                 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_2]->flags 
    816                     & CODING_FLAG_ISO_SINGLE_SHIFT) 
    817                   newmask |= CODING_CATEGORY_MASK_ISO_8_2; 
    818               } 
    819707            if (VECTORP (Vlatin_extra_code_table) 
    820708                && !NILP (XVECTOR (Vlatin_extra_code_table)->contents[c])) 
    821709              { 
    822                 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_1]->flags 
    823                     & CODING_FLAG_ISO_LATIN_EXTRA) 
     710                if (coding_iso_8_1.flags & CODING_FLAG_ISO_LATIN_EXTRA) 
    824711                  newmask |= CODING_CATEGORY_MASK_ISO_8_1; 
    825                 if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_2]->flags 
    826                     & CODING_FLAG_ISO_LATIN_EXTRA) 
     712                if (coding_iso_8_2.flags & CODING_FLAG_ISO_LATIN_EXTRA) 
    827713                  newmask |= CODING_CATEGORY_MASK_ISO_8_2; 
    828714              } 
    829715            mask &= newmask; 
    830             mask_found |= newmask; 
    831716          } 
    832717          break; 
     
    842727                  int newmask = 0; 
    843728 
    844                   if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_1]->flags 
    845                       & CODING_FLAG_ISO_LATIN_EXTRA) 
     729                  if (coding_iso_8_1.flags & CODING_FLAG_ISO_LATIN_EXTRA) 
    846730                    newmask |= CODING_CATEGORY_MASK_ISO_8_1; 
    847                   if (coding_system_table[CODING_CATEGORY_IDX_ISO_8_2]->flags 
    848                       & CODING_FLAG_ISO_LATIN_EXTRA) 
     731                  if (coding_iso_8_2.flags & CODING_FLAG_ISO_LATIN_EXTRA) 
    849732                    newmask |= CODING_CATEGORY_MASK_ISO_8_2; 
    850733                  mask &= newmask; 
    851                   mask_found |= newmask; 
    852734                } 
    853735              else 
     
    858740              unsigned char *src_begin = src; 
    859741 
    860               mask &= ~(CODING_CATEGORY_MASK_ISO_7BIT 
     742              mask &= ~(CODING_CATEGORY_MASK_ISO_7 
    861743                        | CODING_CATEGORY_MASK_ISO_7_ELSE); 
    862               mask_found |= CODING_CATEGORY_MASK_ISO_8_1; 
    863744              while (src < src_end && *src >= 0xA0) 
    864745                src++; 
    865746              if ((src - src_begin - 1) & 1 && src < src_end) 
    866747                mask &= ~CODING_CATEGORY_MASK_ISO_8_2; 
    867               else 
    868                 mask_found |= CODING_CATEGORY_MASK_ISO_8_2; 
    869748            } 
    870749          break; 
     
    872751    } 
    873752 
    874   return (mask & mask_found)
     753  return mask
    875754} 
    876755 
     
    892771        coding->composing += 2;                                         \ 
    893772      }                                                                 \ 
    894     if (charset_alt >= 0)                                             \ 
     773    if ((charset) >= 0)                                                       \ 
    895774      {                                                                 \ 
    896         if (CHARSET_DIMENSION (charset_alt) == 2)                       \ 
    897           {                                                             \ 
    898             ONE_MORE_BYTE (c2);                                         \ 
    899             if (iso_code_class[(c2) & 0x7F] != ISO_0x20_or_0x7F         \ 
    900                 && iso_code_class[(c2) & 0x7F] != ISO_graphic_plane_0)  \ 
    901               {                                                         \ 
    902                 src--;                                                  \ 
    903                 charset_alt = CHARSET_ASCII;                            \ 
    904               }                                                         \ 
    905           }                                                             \ 
    906         if (!NILP (translation_table)                                   \ 
    907             && ((c_alt = translate_char (translation_table,             \ 
    908                                          -1, charset_alt, c1, c2)) >= 0)) \ 
     775        if (CHARSET_DIMENSION (charset) == 2)                           \ 
     776          ONE_MORE_BYTE (c2);                                           \ 
     777        if (!NILP (unification_table)                                   \ 
     778            && ((c_alt = unify_char (unification_table,                 \ 
     779                                     -1, (charset), c1, c2)) >= 0))     \ 
    909780          SPLIT_CHAR (c_alt, charset_alt, c1, c2);                      \ 
    910781      }                                                                 \ 
     
    921792 
    922793/* Set designation state into CODING.  */ 
    923 #define DECODE_DESIGNATION(reg, dimension, chars, final_char)              \ 
    924   do {                                                                     \ 
    925     int charset = ISO_CHARSET_TABLE (make_number (dimension),              \ 
    926                                      make_number (chars),                  \ 
    927                                      make_number (final_char));            \ 
    928     if (charset >= 0                                                       \ 
    929         && (CODING_SPEC_ISO_REQUESTED_DESIGNATION (coding, charset) == reg \ 
    930             || coding->safe_charsets[charset]))                            \ 
    931       {                &n