Debian Codegraph @

texk/cjkutils/cjkutils-src/Bg5conv/bg5conv.w

raw
1 % This is the cweb file bg5conv.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 bg5conv.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{bg5conv (CJK Version 4.8.5)}
30
31 \def\topofcontents{
32 \null\vfill
33 \centerline{\titlefont The {\ttitlefont bg5conv} 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 encoded Chinese characters into a
67 `preprocessed' form. The need of this program arises from the fact that this
68 encoding uses the characters `\.{\\}', `\.{\{}', and `\.{\}}' which have
69 special meanings in \TeX.
70
71 Use this program as a filter:
72
73 \hskip 2em \.{bg5conv < 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 encoded characters \.{XY} (\.{X} and \.{Y} are the first and the second byte
79 of the character) with
80 \.{\char94 \char94 7fX\char94 \char94 7fZZZ\char94 \char94 7f}, where
81 \.{ZZZ} represents the second byte as a decimal number. \.{0x7F} is used as
82 an active 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 \.{bg5conv} complains loudly if something is
89 wrong.
90
91 @d banner
92 "bg5conv (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 fprintf(stdout, "\\def\\CJKpreproc{%s}", banner);@#
110
111 ch = fgetc(stdin);@#
112
113 while(!feof(stdin))
114 {if(ch >= 0xA1 && ch <= 0xFE)
115 {fprintf(stdout, "\177%c\177", ch);@#
116
117 ch = fgetc(stdin);
118 if(!feof(stdin))
119 fprintf(stdout, "%d\177", ch);
120 }
121 else
122 fputc(ch, stdout);@#
123
124 ch = fgetc(stdin);
125 }
126 exit(EXIT_SUCCESS);
127 return 0; /* never reached */
128 }