Debian Codegraph @

texk/cjkutils/cjkutils-src/extconv/extconv.w

raw
1 % This is the cweb file extconv.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 extconv.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{extconv (CJK Version 4.8.5)}
30
31 \def\topofcontents{
32 \null\vfill
33 \centerline{\titlefont The {\ttitlefont extconv} 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 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 Big~5+ or GBK encoded Chinese characters
67 into a `preprocessed' form. The need of this program arises from the fact
68 that these two encodings use the characters `\.{\\}', `\.{\{}', and `\.{\}}'
69 which have special meanings in \TeX.
70
71 Use this program as a filter:
72
73 \hskip 2em \.{extconv < input\_file > output\_file}
74
75
76 @* The program.
77 The only function of this program is to replace all occurrences of Big~5+
78 and GBK encoded characters \.{XY} (\.{X} and \.{Y} are the first and the
79 second byte of the character) with
80 \.{\char94 \char94 7fX\char94 \char94 7fZZZ\char94 \char94 7f}, where \.{ZZZ}
81 represents the second byte as a decimal number. \.{0x7F} is used as an active
82 character and delimiter.
83
84 Additionally we define a \TeX\ macro at the very beginning to signal a
85 preprocessed file.
86
87 The following code is very simple. No error detection is done because \TeX\
88 which will see the output of \.{extconv} complains loudly if something is
89 wrong.
90
91 @d banner
92 "extconv (CJK ver. 4.8.5)"
93
94 @c
95 #include <stdio.h>
96 #include <stdlib.h>
97 #ifdef WIN32
98 #include <fcntl.h>
99 #include <io.h>
100 #endif@#
101
102
103 int main(int argc, char *argv[])
104 {int ch;
105
106 #ifdef WIN32
107 setmode(fileno(stdout), _O_BINARY);
108 #endif
109
110 fprintf(stdout, "\\def\\CJKpreproc{%s}", banner);@#
111
112 ch = fgetc(stdin);@#
113
114 while(!feof(stdin))
115 {if(ch >= 0x81 && ch <= 0xFE)
116 {fprintf(stdout, "\177%c\177", ch);@#
117
118 ch = fgetc(stdin);
119 if(!feof(stdin))
120 fprintf(stdout, "%d\177", ch);
121 }
122 else
123 fputc(ch, stdout);@#
124
125 ch = fgetc(stdin);
126 }
127 exit(EXIT_SUCCESS);
128 return 0; /* never reached */
129 }