Debian Codegraph @

texk/cjkutils/cjkutils-src/CEFconv/cefconv.w

raw
1 % This is the cweb file cefconv.w of the CJK Package Ver. 4.8.5 16-Oct-2021
2
3 % Copyright (C) 1994-2021 Werner Lemberg <wl@@gnu.org>
4 %
5 % This program is free software; you can redistribute it and/or modify
6 % it under the terms of the GNU General Public License as published by
7 % the Free Software Foundation; either version 2 of the License, or
8 % (at your option) any later version.
9 %
10 % This program is distributed in the hope that it will be useful,
11 % but WITHOUT ANY WARRANTY; without even the implied warranty of
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 % GNU General Public License for more details.
14 %
15 % You should have received a copy of the GNU General Public License
16 % along with this program in doc/COPYING; if not, write to the Free
17 % Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 % MA 02110-1301 USA
19
20 % To print this CWEB file you should (but not must) use the CWEAVE of the
21 % c2cweb-package (found at the CTAN archives, e.g. ftp.dante.de) and then say
22 %
23 % cweave +a cefconv.w
24 %
25 % This (fully compatible) CWEAVE can transform CWEB-files with alternative
26 % output rules (look at the position of braces below!) the author (it's me
27 % too :-) prefer. Otherwise this file will be formatted traditionally.
28
29 \def\title{cefconv (CJK Version 4.8.5)}
30
31 \def\topofcontents{
32 \null\vfill
33 \centerline{\titlefont The {\ttitlefont cefconv} program}
34 \vskip 20pt
35 \centerline{(CJK Version 4.8.5)}
36 \vfill}
37
38 \def\botofcontents{
39 \vfill
40 \noindent
41 Copyright \copyright\ 1996, 1998, 2002 by Werner Lemberg
42 \bigskip\noindent
43 Permission is granted to make and distribute verbatim copies of this
44 document provided that the copyright notice and this permission notice
45 are preserved on all copies.
46
47 \smallskip\noindent
48 Permission is granted to copy and distribute modified versions of this
49 document under the conditions for verbatim copying, provided that the
50 entire resulting derived work is distributed under the terms of a
51 permission notice identical to this one.}
52
53 \pageno=\contentspagenumber \advance\pageno by 1
54 \let\maybe=\iftrue
55 \fullpageheight=240mm
56 \pageheight=223mm
57 \pagewidth=158mm
58 \setpage
59 \frenchspacing
60
61 \noinx
62 \nosecs
63 \nocon
64
65 @* Function and Use.
66 This small program will convert EUC encoding with CNS encoded Chinese
67 characters using the {\it Chinese Encoding Framework (CEF)} into a
68 `preprocessed' form, expanding the CEF macros.
69
70 Use this program as a filter:
71
72 \hskip 2em \.{cefconv < input\_file > output\_file}
73
74
75 @* The program.
76 In contrast to \.{cef5conv} or \.{cefsconv}, only one task will be executed:
77
78 Replacing CEF macros of the form \.{\&xx-yyzz;} (\.{xx} can be C1--C7 for
79 the CNS planes 1--7, C0 for Big~5 encoding, an encoding CX reserved for
80 IRIZ, a private encoding CY, and U for Unicode encoding; \.{yyzz} is a
81 hexadecimal representation of the code point in this plane) with
82 \medskip
83 \quad\.{\char94 \char94 7f72\char94 \char94 7fXX\char94 \char94 7f%
84 \char94 \char94 7f"0yy\char94 \char94 7f"0zz\char94 \char94 7f}\quad.
85 \medskip
86 \.{XX} is the corresponding CJK encoding of \.{xx}; the number `72'
87 specifies a macro in the file \.{MULEenc.sty} which further processes this
88 representation -- it is automatically loaded by the \.{CJK} package.
89
90 Additionally we define an empty \TeX\ macro at the very beginning to signal
91 a preprocessed file.
92
93 The following code is very simple. No error detection is done because \TeX\
94 which will see the output of \.{cefconv} complains loudly if something is
95 wrong.
96
97 @d banner
98 "cefconv (CJK ver. 4.8.5)"
99
100 @c
101 #include <ctype.h>
102 #include <stdio.h>
103 #include <stdlib.h>
104 #ifdef WIN32
105 #include <fcntl.h>
106 #include <io.h>
107 #endif@#
108
109
110 int main(int argc, char *argv[])
111 {int ch, i;
112 unsigned char in[16];
113 unsigned char out[32];
114 unsigned char *inp, *outp;
115
116 #ifdef WIN32
117 setmode(fileno(stdout), _O_BINARY);
118 #endif
119 fprintf(stdout, "\\def\\CNSpreproc{%s}", banner);@#
120
121 ch = fgetc(stdin);@#
122
123 while(!feof(stdin))
124 {if(ch == '&') /* the macro test is hardcoded to make things simple */
125 {inp = in;
126 outp = out;
127 *inp = ch;
128 *(++inp) = fgetc(stdin);@#
129
130 if(*inp == 'C' && !feof(stdin))
131 {*(++inp) = fgetc(stdin);
132 if(*inp == '0' && !feof(stdin))
133 {*(outp++) = 'B';
134 *(outp++) = 'g';
135 *(outp++) = '5';
136 }
137 else if(*inp >= '1' && *inp <= '7' && !feof(stdin))
138 {*(outp++) = 'C';
139 *(outp++) = 'N';
140 *(outp++) = 'S';
141 *(outp++) = *inp;
142 }
143 else if((*inp == 'X' || *inp == 'Y') && !feof(stdin))
144 {*(outp++) = 'C';
145 *(outp++) = 'E';
146 *(outp++) = 'F';
147 *(outp++) = *inp;
148 }
149 else
150 goto no_macro;
151 }
152 else if(*inp == 'U' && !feof(stdin))
153 {*(outp++) = 'U';
154 *(outp++) = 'T';
155 *(outp++) = 'F';
156 *(outp++) = '8';
157 }
158 else
159 goto no_macro;@#
160
161 *(++inp) = fgetc(stdin);
162 if(*inp != '-' || feof(stdin))
163 goto no_macro;@#
164
165 *(outp++) = '\177';
166 *(outp++) = '\177';
167 *(outp++) = '\"';
168 *(outp++) = '0';@#
169
170 *(++inp) = fgetc(stdin);
171 if(isxdigit(*inp) && *inp < 0x80 && !feof(stdin))
172 *(outp++) = toupper(*inp);
173 else
174 goto no_macro;@#
175
176 *(++inp) = fgetc(stdin);
177 if(isxdigit(*inp) && *inp < 0x80 && !feof(stdin))
178 *(outp++) = toupper(*inp);
179 else
180 goto no_macro;@#
181
182 *(outp++) = '\177';
183 *(outp++) = '\"';
184 *(outp++) = '0';@#
185
186 *(++inp) = fgetc(stdin);
187 if(isxdigit(*inp) && *inp < 0x80 && !feof(stdin))
188 *(outp++) = toupper(*inp);
189 else
190 goto no_macro;@#
191
192 *(++inp) = fgetc(stdin);
193 if(isxdigit(*inp) && *inp < 0x80 && !feof(stdin))
194 *(outp++) = toupper(*inp);
195 else
196 goto no_macro;@#
197
198 *(outp++) = '\177';
199 *outp = '\0';@#
200
201 *(++inp) = fgetc(stdin);
202 if(*inp != ';' || feof(stdin))
203 goto no_macro;@#
204
205 outp = out;
206 fprintf(stdout, "\17772\177");
207 while(*outp)
208 fputc(*(outp++), stdout);@#
209
210 ch = fgetc(stdin);
211 continue;@#
212
213 no_macro:
214 ch = *inp;
215 i = inp - in;
216 inp = in;
217 while(i--)
218 fputc(*(inp++), stdout);
219 continue;
220 }
221 else
222 fputc(ch, stdout);@#
223
224 ch = fgetc(stdin);
225 }
226 exit(EXIT_SUCCESS);
227 return 0; /* never reached */
228 }