Debian Codegraph @

texk/cjkutils/cjkutils-src/SJISconv/sjisconv.w

raw
1 % This is the cweb file sjisconv.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 sjisconv.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{sjisconv (CJK Version 4.8.5)}
30
31 \def\topofcontents{
32 \null\vfill
33 \centerline{\titlefont The {\ttitlefont sjisconv} 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 SJIS encoded Japanese 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 \.{sjisconv < input\_file > output\_file}
74
75
76 @* The program.
77 The only function of this program is to replace all occurrences of SJIS
78 encoded two byte characters \.{XY} with
79 \.{\char94 \char94 7fX\char94 \char94 7fZZZ\char94 \char94 7f} (\.{X}
80 and \.{Y} are the first and the second byte of the character; \.{ZZZ}
81 represents the second byte as a decimal number).
82
83 Additionally we define a \TeX\ macro at the very beginning to signal a
84 preprocessed file.
85
86 The following code is very simple. No error detection is done because \TeX\
87 which will see the output of \.{sjisconv} complains loudly if something is
88 wrong.
89
90 Note that the user-defined character area of SJIS (with the first bytes in
91 the range 0xF0--0xFC) is not supported because it is not portable.
92
93 @d banner
94 "sjisconv (CJK ver. 4.8.5)"
95
96 @c
97 #include <stdio.h>
98 #include <stdlib.h>
99 #ifdef WIN32
100 #include <fcntl.h>
101 #include <io.h>
102 #endif@#
103
104
105 int main(int argc, char *argv[])
106 {int ch;
107
108 #ifdef WIN32
109 setmode(fileno(stdout), _O_BINARY);
110 #endif
111 fprintf(stdout, "\\def\\CJKpreproc{%s}", banner);@#
112
113 ch = fgetc(stdin);@#
114
115 while(!feof(stdin))
116 {if((ch >= 0x81 && ch <= 0x9F) || (ch >= 0xE0 && ch <= 0xEF))
117 {fprintf(stdout, "\177%c\177", ch);@#
118
119 ch = fgetc(stdin);
120 if(!feof(stdin))
121 fprintf(stdout, "%d\177", ch);
122 }
123 else
124 fputc(ch, stdout);@#
125
126 ch = fgetc(stdin);
127 }
128 exit(EXIT_SUCCESS);
129 return 0; /* never reached */
130 }