comparison src/coding.c @ 50047:8e17fbb2ac77

(CODING_ADD_COMPOSITION_COMPONENT): If the number of composition components reaches the limit, terminate composing. (COMPOSITION_OK): New macro. (detect_coding_iso2022): Use it if an escapse sequence for composition is found. (coding_restore_composition): Adjust the number of composition components if it is not sane.
author Kenichi Handa <handa@m17n.org>
date Fri, 07 Mar 2003 02:18:35 +0000
parents 23a1cea22d13
children 34d5ae26ea24
comparison
equal deleted inserted replaced
50046:59eb19bd5433 50047:8e17fbb2ac77
686 data[2] = cmp_data->char_offset + end; \ 686 data[2] = cmp_data->char_offset + end; \
687 } while (0) 687 } while (0)
688 688
689 /* Record one COMPONENT (alternate character or composition rule). */ 689 /* Record one COMPONENT (alternate character or composition rule). */
690 690
691 #define CODING_ADD_COMPOSITION_COMPONENT(coding, component) \ 691 #define CODING_ADD_COMPOSITION_COMPONENT(coding, component) \
692 (coding->cmp_data->data[coding->cmp_data->used++] = component) 692 do { \
693 coding->cmp_data->data[coding->cmp_data->used++] = component; \
694 if (coding->cmp_data->used - coding->cmp_data_start \
695 == COMPOSITION_DATA_MAX_BUNCH_LENGTH) \
696 { \
697 CODING_ADD_COMPOSITION_END (coding, coding->produced_char); \
698 coding->composing = COMPOSITION_NO; \
699 } \
700 } while (0)
693 701
694 702
695 /* Get one byte from a data pointed by SRC and increment SRC. If SRC 703 /* Get one byte from a data pointed by SRC and increment SRC. If SRC
696 is not less than SRC_END, return -1 without incrementing Src. */ 704 is not less than SRC_END, return -1 without incrementing Src. */
697 705
1327 != CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION)) 1335 != CODING_SPEC_ISO_NO_REQUESTED_DESIGNATION))
1328 1336
1329 #define SHIFT_OUT_OK(idx) \ 1337 #define SHIFT_OUT_OK(idx) \
1330 (CODING_SPEC_ISO_INITIAL_DESIGNATION (coding_system_table[idx], 1) >= 0) 1338 (CODING_SPEC_ISO_INITIAL_DESIGNATION (coding_system_table[idx], 1) >= 0)
1331 1339
1340 #define COMPOSITION_OK(idx) \
1341 (coding_system_table[idx]->composing != COMPOSITION_DISABLED)
1342
1332 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions". 1343 /* See the above "GENERAL NOTES on `detect_coding_XXX ()' functions".
1333 Check if a text is encoded in ISO2022. If it is, return an 1344 Check if a text is encoded in ISO2022. If it is, return an
1334 integer in which appropriate flag bits any of: 1345 integer in which appropriate flag bits any of:
1335 CODING_CATEGORY_MASK_ISO_7 1346 CODING_CATEGORY_MASK_ISO_7
1336 CODING_CATEGORY_MASK_ISO_7_TIGHT 1347 CODING_CATEGORY_MASK_ISO_7_TIGHT
1404 break; 1415 break;
1405 } 1416 }
1406 else if (c >= '0' && c <= '4') 1417 else if (c >= '0' && c <= '4')
1407 { 1418 {
1408 /* ESC <Fp> for start/end composition. */ 1419 /* ESC <Fp> for start/end composition. */
1409 mask_found |= CODING_CATEGORY_MASK_ISO; 1420 if (COMPOSITION_OK (CODING_CATEGORY_IDX_ISO_7))
1421 mask_found |= CODING_CATEGORY_MASK_ISO_7;
1422 else
1423 mask &= ~CODING_CATEGORY_MASK_ISO_7;
1424 if (COMPOSITION_OK (CODING_CATEGORY_IDX_ISO_7_TIGHT))
1425 mask_found |= CODING_CATEGORY_MASK_ISO_7_TIGHT;
1426 else
1427 mask &= ~CODING_CATEGORY_MASK_ISO_7_TIGHT;
1428 if (COMPOSITION_OK (CODING_CATEGORY_IDX_ISO_8_1))
1429 mask_found |= CODING_CATEGORY_MASK_ISO_8_1;
1430 else
1431 mask &= ~CODING_CATEGORY_MASK_ISO_8_1;
1432 if (COMPOSITION_OK (CODING_CATEGORY_IDX_ISO_8_2))
1433 mask_found |= CODING_CATEGORY_MASK_ISO_8_2;
1434 else
1435 mask &= ~CODING_CATEGORY_MASK_ISO_8_2;
1436 if (COMPOSITION_OK (CODING_CATEGORY_IDX_ISO_7_ELSE))
1437 mask_found |= CODING_CATEGORY_MASK_ISO_7_ELSE;
1438 else
1439 mask &= ~CODING_CATEGORY_MASK_ISO_7_ELSE;
1440 if (COMPOSITION_OK (CODING_CATEGORY_IDX_ISO_8_ELSE))
1441 mask_found |= CODING_CATEGORY_MASK_ISO_8_ELSE;
1442 else
1443 mask &= ~CODING_CATEGORY_MASK_ISO_8_ELSE;
1410 break; 1444 break;
1411 } 1445 }
1412 else 1446 else
1413 /* Invalid escape sequence. Just ignore. */ 1447 /* Invalid escape sequence. Just ignore. */
1414 break; 1448 break;
5287 else 5321 else
5288 { 5322 {
5289 int len = data[0] - 4, j; 5323 int len = data[0] - 4, j;
5290 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1]; 5324 Lisp_Object args[MAX_COMPOSITION_COMPONENTS * 2 - 1];
5291 5325
5326 if (method == COMPOSITION_WITH_RULE_ALTCHARS
5327 && len % 2 == 0)
5328 len --;
5292 for (j = 0; j < len; j++) 5329 for (j = 0; j < len; j++)
5293 args[j] = make_number (data[4 + j]); 5330 args[j] = make_number (data[4 + j]);
5294 components = (method == COMPOSITION_WITH_ALTCHARS 5331 components = (method == COMPOSITION_WITH_ALTCHARS
5295 ? Fstring (len, args) : Fvector (len, args)); 5332 ? Fstring (len, args) : Fvector (len, args));
5296 } 5333 }