comparison src/coding.h @ 89765:b06a8c2162e5

(SJIS_TO_JIS2, JIS_TO_SJIS2): New macros.
author Kenichi Handa <handa@m17n.org>
date Tue, 27 Jan 2004 12:12:16 +0000
parents d001bbbe12ce
children 623a853556f1
comparison
equal deleted inserted replaced
89764:e3d26232ab78 89765:b06a8c2162e5
477 (j1 = s1 * 2 - ((s1 >= 0xE0) ? 0x161 : 0xE1), \ 477 (j1 = s1 * 2 - ((s1 >= 0xE0) ? 0x161 : 0xE1), \
478 j2 = s2 - ((s2 >= 0x7F) ? 0x20 : 0x1F)); \ 478 j2 = s2 - ((s2 >= 0x7F) ? 0x20 : 0x1F)); \
479 (code) = (j1 << 8) | j2; \ 479 (code) = (j1 << 8) | j2; \
480 } while (0) 480 } while (0)
481 481
482 #define SJIS_TO_JIS2(code) \
483 do { \
484 int s1, s2, j1, j2; \
485 \
486 s1 = (code) >> 8, s2 = (code) & 0xFF; \
487 \
488 if (s2 >= 0x9F) \
489 { \
490 j1 = (s1 == 0xF0 ? 0x28 \
491 : s1 == 0xF1 ? 0x24 \
492 : s1 == 0xF2 ? 0x2C \
493 : s1 == 0xF3 ? 0x2E \
494 : 0x6E + (s1 - 0xF4) * 2); \
495 j2 = s2 - 0x7E; \
496 } \
497 else \
498 { \
499 j1 = (s1 <= 0xF2 ? 0x21 + (s1 - 0xF0) * 2 \
500 : s1 <= 0xF4 ? 0x2D + (s1 - 0xF3) * 2 \
501 : 0x6F + (s1 - 0xF5) * 2); \
502 j2 = s2 - ((s2 >= 0x7F ? 0x20 : 0x1F)); \
503 } \
504 (code) = (j1 << 8) | j2; \
505 } while (0)
506
482 507
483 #define JIS_TO_SJIS(code) \ 508 #define JIS_TO_SJIS(code) \
484 do { \ 509 do { \
485 int s1, s2, j1, j2; \ 510 int s1, s2, j1, j2; \
486 \ 511 \
492 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x70 : 0xB0), \ 517 (s1 = j1 / 2 + ((j1 < 0x5F) ? 0x70 : 0xB0), \
493 s2 = j2 + 0x7E); \ 518 s2 = j2 + 0x7E); \
494 (code) = (s1 << 8) | s2; \ 519 (code) = (s1 << 8) | s2; \
495 } while (0) 520 } while (0)
496 521
522 #define JIS_TO_SJIS2(code) \
523 do { \
524 int s1, s2, j1, j2; \
525 \
526 j1 = (code) >> 8, j2 = (code) & 0xFF; \
527 if (j1 & 1) \
528 { \
529 s1 = (j1 <= 0x25 ? 0xF0 + (j1 - 0x21) / 2 \
530 : j1 <= 0x27 ? 0xF3 + (j1 - 0x2D) / 2 \
531 : 0xF5 + (j1 - 0x6F) / 2); \
532 s2 = j2 + ((j2 >= 0x60) ? 0x20 : 0x1F); \
533 } \
534 else \
535 { \
536 s1 = (j1 == 0x28 ? 0xF0 \
537 : j1 == 0x24 ? 0xF1 \
538 : j1 == 0x2C ? 0xF2 \
539 : j1 == 0x2E ? 0xF3 \
540 : 0xF4 + (j1 - 0x6E) / 2); \
541 s2 = j2 + 0x7E; \
542 } \
543 (code) = (s1 << 8) | s2; \
544 } while (0)
497 545
498 /* Encode the file name NAME using the specified coding system 546 /* Encode the file name NAME using the specified coding system
499 for file names, if any. */ 547 for file names, if any. */
500 #define ENCODE_FILE(name) \ 548 #define ENCODE_FILE(name) \
501 (! NILP (Vfile_name_coding_system) \ 549 (! NILP (Vfile_name_coding_system) \