§1  cefconv (CJK Version 4.5.2)  FUNCTION AND USE 1

1. Function and Use.

This small program will convert EUC encoding with CNS encoded Chinese characters using the Chinese Encoding Framework (CEF) into a ‘preprocessed’ form, expanding the CEF macros. Use this program as a filter:

2  THE PROGRAM  cefconv (CJK Version 4.5.2) §2

2. The program.

In contrast to  or  , only one task will be executed:

Replacing CEF macros of the form ( can be C1–C7 for the CNS planes 1–7, C0 for Big 5 encoding, an encoding CX reserved for IRIZ, a private encoding CY, and U for Unicode encoding; is a hexadecimal representation of the code point in this plane) with

.

is the corresponding CJK encoding of ; the number ‘72’ specifies a macro in the file which further processes this representation – it is automatically loaded by the package.

Additionally we define an empty TEX macro at the very beginning to signal a preprocessed file.

The following code is very simple. No error detection is done because TEX which will see the output of complains loudly if something is wrong.

#define banner  ␣    ␣    ␣

#include #include #include

int main(argc, argv )

int argc; char ∗argv [ ];

{int ch, i; unsigned char in[16]; unsigned char out [32]; unsigned char ∗inp, ∗outp;

fprintf (stdout , , banner );

ch = fgetc(stdin);

while (! feof (stdin))

{if (ch ≡ ) /∗ the macro test is hardcoded to make things simple ∗/ {inp = in; outp = out ; ∗inp = ch; ∗(^{++}inp) = fgetc(stdin);

if (∗inp ≡ ∧! feof (stdin)) {∗(^{++}inp) = fgetc(stdin); if (∗inp ≡ ∧! feof (stdin)) {∗(outp^{++}) = ; ∗(outp^{++}) = ; ∗(outp^{++}) = ; } else if (∗inp ≥ ∧ ∗inp ≤ ∧! feof (stdin)) {∗(outp^{++}) = ; ∗(outp^{++}) = ; ∗(outp^{++}) = ; ∗(outp^{++}) = ∗inp; } else if ((∗inp ≡ ∨ ∗inp ≡ ) ∧! feof (stdin)) {∗(outp^{++}) = ; ∗(outp^{++}) = ;

§2  cefconv (CJK Version 4.5.2)  THE PROGRAM 3

∗(outp^{++}) = ; ∗(outp^{++}) = ∗inp; } else

goto no macro; } else if (∗inp ≡ ∧! feof (stdin)) {∗(outp^{++}) = ; ∗(outp^{++}) = ; ∗(outp^{++}) = ; ∗(outp^{++}) = ; } else

goto no macro;

∗(^{++}inp) = fgetc(stdin); if (∗inp ≠ ∨ feof (stdin))

goto no macro;

∗(outp^{++}) = ; ∗(outp^{++}) = ; ∗(outp^{++}) = ; ∗(outp^{++}) = ;

∗(^{++}inp) = fgetc(stdin); if (isxdigit (∗inp) ∧ ∗inp < ^{#}80 ∧! feof (stdin))

∗(outp^{++}) = toupper (∗inp); else

goto no macro;

∗(^{++}inp) = fgetc(stdin); if (isxdigit (∗inp) ∧ ∗inp < ^{#}80 ∧! feof (stdin))

∗(outp^{++}) = toupper (∗inp); else

goto no macro;

∗(outp^{++}) = ; ∗(outp^{++}) = ; ∗(outp^{++}) = ;

∗(^{++}inp) = fgetc(stdin); if (isxdigit (∗inp) ∧ ∗inp < ^{#}80 ∧! feof (stdin))

∗(outp^{++}) = toupper (∗inp); else

goto no macro;

∗(^{++}inp) = fgetc(stdin); if (isxdigit (∗inp) ∧ ∗inp < ^{#}80 ∧! feof (stdin))

∗(outp^{++}) = toupper (∗inp); else

goto no macro;

∗(outp^{++}) = ; ∗outp = ;

∗(^{++}inp) = fgetc(stdin); if (∗inp ≠ ∨ feof (stdin))

goto no macro; outp = out ; fprintf (stdout , ); while (∗outp)

fputc(∗(outp^{++}), stdout );

ch = fgetc(stdin); continue;

no macro:

ch = ∗inp; i = inp − in; inp = in; while (i^{−})

fputc(∗(inp^{++}), stdout ); continue; } else

fputc(ch, stdout );

ch = fgetc(stdin); } exit ( ); return 0; /∗ never reached ∗/ }