1 /** Network Kanji Filter. (PDS Version)
2 ************************************************************************
3 ** Copyright (C) 1987, Fujitsu LTD. (Itaru ICHIKAWA)
4 **
\e$BO"Mm@h!'
\e(B
\e$B!J3t!KIY;NDL8&5f=j!!%=%U%H#38&!!;T@n!!;j
\e(B
5 **
\e$B!J
\e(BE-Mail Address: ichikawa@flab.fujitsu.co.jp
\e$B!K
\e(B
6 ** Copyright (C) 1996,1998
8 **
\e$BO"Mm@h!'
\e(B
\e$BN05eBg3X>pJs9)3X2J
\e(B
\e$B2OLn
\e(B
\e$B??<#
\e(B mime/X0208 support
9 **
\e$B!J
\e(BE-Mail Address: kono@ie.u-ryukyu.ac.jp
\e$B!K
\e(B
10 **
\e$BO"Mm@h!'
\e(B COW for DOS & Win16 & Win32 & OS/2
11 **
\e$B!J
\e(BE-Mail Address: GHG00637@niftyserve.or.p
\e$B!K
\e(B
13 **
\e$B$3$N%=!<%9$N$$$+$J$kJ#<L!$2~JQ!$=$@5$b5vBz$7$^$9!#$?$@$7!"
\e(B
14 **
\e$B$=$N:]$K$O!"C/$,9W8%$7$?$r<($9$3$NItJ,$r;D$9$3$H!#
\e(B
15 **
\e$B:FG[I[$d;(;o$NIUO?$J$I$NLd$$9g$o$;$bI,MW$"$j$^$;$s!#
\e(B
16 **
\e$B1DMxMxMQ$b>e5-$KH?$7$J$$HO0O$G5v2D$7$^$9!#
\e(B
17 **
\e$B%P%$%J%j$NG[I[$N:]$K$O
\e(Bversion message
\e$B$rJ]B8$9$k$3$H$r>r7o$H$7$^$9!#
\e(B
18 **
\e$B$3$N%W%m%0%i%`$K$D$$$F$OFC$K2?$NJ]>Z$b$7$J$$!"0-$7$+$i$:!#
\e(B
20 ** Everyone is permitted to do anything on this program
21 ** including copying, modifying, improving,
22 ** as long as you don't try to pretend that you wrote it.
23 ** i.e., the above copyright notice has to appear in all copies.
24 ** Binary distribution requires original version messages.
25 ** You don't have to ask before copying, redistribution or publishing.
26 ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.
27 ***********************************************************************/
29 /***********************************************************************
30 ** UTF-8
\e$B%5%]!<%H$K$D$$$F
\e(B
31 **
\e$B=>Mh$N
\e(B nkf
\e$B$HF~$l$+$($F$=$N$^$^;H$($k$h$&$K$J$C$F$$$^$9
\e(B
32 ** nkf -e
\e$B$J$I$H$7$F5/F0$9$k$H!"<+F0H=JL$G
\e(B UTF-8
\e$B$HH=Dj$5$l$l$P!"
\e(B
33 **
\e$B$=$N$^$^
\e(B euc-jp
\e$B$KJQ49$5$l$^$9
\e(B
35 **
\e$B$^$@%P%0$,$"$k2DG=@-$,9b$$$G$9!#
\e(B
36 ** (
\e$BFC$K<+F0H=JL!"%3!<%I:.:_!"%(%i!<=hM}7O
\e(B)
38 **
\e$B2?$+LdBj$r8+$D$1$?$i!"
\e(B
39 ** E-Mail: furukawa@tcp-ip.or.jp
40 **
\e$B$^$G8fO"Mm$r$*4j$$$7$^$9!#
\e(B
41 ***********************************************************************/
44 static char *CopyRight =
45 "Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),2000 S. Kono, COW, 2002 Kono, Furukawa";
46 static char *Version =
48 static char *Patchlevel =
55 ** USAGE: nkf [flags] [file]
58 ** b Output is bufferred (DEFAULT)
59 ** u Output is unbufferred
63 ** j Outout code is JIS 7 bit (DEFAULT SELECT)
64 ** s Output code is MS Kanji (DEFAULT SELECT)
65 ** e Output code is AT&T JIS (DEFAULT SELECT)
66 ** w Output code is AT&T JIS (DEFAULT SELECT)
67 ** l Output code is JIS 7bit and ISO8859-1 Latin-1
69 ** m MIME conversion for ISO-2022-JP
70 ** I Convert non ISO-2022-JP charactor to GETA by Pekoe <pekoe@lair.net>
71 ** i_ Output sequence to designate JIS-kanji (DEFAULT_J)
72 ** o_ Output sequence to designate single-byte roman characters (DEFAULT_R)
73 ** M MIME output conversion
75 ** r {de/en}crypt ROT13/47
79 ** T Text mode output (for MS-DOS)
81 ** x Do not convert X0201 kana into X0208
82 ** Z Convert X0208 alphabet to ASCII
87 ** B try to fix broken JIS, missing Escape
88 ** B[1-9] broken level
90 ** O Output to 'nkf.out' file or last file name
91 ** d Delete \r in line feed
92 ** c Add \r in line feed
93 ** -- other long option
94 ** -- ignore following option (don't use with -O )
98 #if (defined(__TURBOC__) || defined(LSI_C)) && !defined(MSDOS)
114 #if defined(MSDOS) || defined(__OS2__)
121 #define setbinmode(fp) fsetbin(fp)
122 #else /* Microsoft C, Turbo C */
123 #define setbinmode(fp) setmode(fileno(fp), O_BINARY)
125 #else /* UNIX,OS/2 */
126 #define setbinmode(fp)
129 #ifdef _IOFBF /* SysV and MSDOS */
130 #define setvbuffer(fp, buf, size) setvbuf(fp, buf, _IOFBF, size)
132 #define setvbuffer(fp, buf, size) setbuffer(fp, buf, size)
135 /*Borland C++ 4.5 EasyWin*/
136 #if defined(__TURBOC__) && defined(_Windows) && !defined(__WIN32__) /*Easy Win */
142 /* added by satoru@isoternet.org */
143 #include <sys/stat.h>
153 /* state of output_mode and input_mode
170 /* Input Assumption */
174 #define LATIN1_INPUT 6
176 #define STRICT_MIME 8
181 #define JAPANESE_EUC 10
185 #define UTF8_INPUT 13
186 #define UTF16_INPUT 14
187 #define UTF16BE_INPUT 15
205 #define is_alnum(c) \
206 (('a'<=c && c<='z')||('A'<= c && c<='Z')||('0'<=c && c<='9'))
208 #define HOLD_SIZE 1024
209 #define IOBUF_SIZE 16384
211 #define DEFAULT_J 'B'
212 #define DEFAULT_R 'B'
214 #define SJ0162 0x00e1 /* 01 - 62 ku offset */
215 #define SJ6394 0x0161 /* 63 - 94 ku offset */
217 #define RANGE_NUM_MAX 18
222 #if defined( UTF8_OUTPUT_ENABLE ) || defined( UTF8_INPUT_ENABLE )
223 #define sizeof_euc_utf8 94
224 #define sizeof_euc_to_utf8_1byte 94
225 #define sizeof_euc_to_utf8_2bytes 94
226 #define sizeof_utf8_to_euc_C2 64
227 #define sizeof_utf8_to_euc_E5B8 64
228 #define sizeof_utf8_to_euc_2bytes 112
229 #define sizeof_utf8_to_euc_3bytes 112
232 /* MIME preprocessor */
235 #ifdef EASYWIN /*Easy Win */
236 extern POINT _BufferSize;
239 /* function prototype */
241 #ifdef ANSI_C_PROTOTYPE
243 #define STATIC static
249 STATIC int noconvert PROTO((FILE *f));
250 STATIC int kanji_convert PROTO((FILE *f));
251 STATIC int h_conv PROTO((FILE *f,int c2,int c1));
252 STATIC int push_hold_buf PROTO((int c2));
253 STATIC void set_iconv PROTO((int f, int (*iconv_func)()));
254 STATIC int s_iconv PROTO((int c2,int c1,int c0));
255 STATIC int e_iconv PROTO((int c2,int c1,int c0));
256 #ifdef UTF8_INPUT_ENABLE
257 STATIC int w2e_conv PROTO((int c2,int c1,int c0,int *p2,int *p1));
258 STATIC int w_iconv PROTO((int c2,int c1,int c0));
259 STATIC int w_iconv16 PROTO((int c2,int c1,int c0));
260 STATIC int w_iconv_common PROTO((int c1,int c0,unsigned short **pp,int psize,int *p2,int *p1));
262 #ifdef UTF8_OUTPUT_ENABLE
263 STATIC int e2w_conv PROTO((int c2,int c1));
264 STATIC void w_oconv PROTO((int c2,int c1));
265 STATIC void w_oconv16 PROTO((int c2,int c1));
267 STATIC void e_oconv PROTO((int c2,int c1));
268 STATIC void s_oconv PROTO((int c2,int c1));
269 STATIC void j_oconv PROTO((int c2,int c1));
270 STATIC void fold_conv PROTO((int c2,int c1));
271 STATIC void cr_conv PROTO((int c2,int c1));
272 STATIC void z_conv PROTO((int c2,int c1));
273 STATIC void rot_conv PROTO((int c2,int c1));
274 STATIC void hira_conv PROTO((int c2,int c1));
275 STATIC void base64_conv PROTO((int c2,int c1));
276 STATIC void iso2022jp_check_conv PROTO((int c2,int c1));
277 STATIC void no_connection PROTO((int c2,int c1));
278 STATIC int no_connection2 PROTO((int c2,int c1,int c0));
280 STATIC void code_status PROTO((int c));
282 STATIC void std_putc PROTO((int c));
283 STATIC int std_getc PROTO((FILE *f));
284 STATIC int std_ungetc PROTO((int c,FILE *f));
286 STATIC int broken_getc PROTO((FILE *f));
287 STATIC int broken_ungetc PROTO((int c,FILE *f));
289 STATIC int mime_begin PROTO((FILE *f));
290 STATIC int mime_getc PROTO((FILE *f));
291 STATIC int mime_ungetc PROTO((int c,FILE *f));
293 STATIC int mime_begin_strict PROTO((FILE *f));
294 STATIC int mime_getc_buf PROTO((FILE *f));
295 STATIC int mime_ungetc_buf PROTO((int c,FILE *f));
296 STATIC int mime_integrity PROTO((FILE *f,unsigned char *p));
298 STATIC int base64decode PROTO((int c));
299 STATIC void mime_putc PROTO((int c));
300 STATIC void open_mime PROTO((int c));
301 STATIC void close_mime PROTO(());
302 STATIC void usage PROTO(());
303 STATIC void version PROTO(());
304 STATIC void options PROTO((unsigned char *c));
306 STATIC void reinit PROTO(());
311 static unsigned char stdibuf[IOBUF_SIZE];
312 static unsigned char stdobuf[IOBUF_SIZE];
313 static unsigned char hold_buf[HOLD_SIZE*2];
314 static int hold_count;
316 /* MIME preprocessor fifo */
318 #define MIME_BUF_SIZE (1024) /* 2^n ring buffer */
319 #define MIME_BUF_MASK (MIME_BUF_SIZE-1)
320 #define Fifo(n) mime_buf[(n)&MIME_BUF_MASK]
321 static unsigned char mime_buf[MIME_BUF_SIZE];
322 static unsigned int mime_top = 0;
323 static unsigned int mime_last = 0; /* decoded */
324 static unsigned int mime_input = 0; /* undecoded */
327 static int unbuf_f = FALSE;
328 static int estab_f = FALSE;
329 static int nop_f = FALSE;
330 static int binmode_f = TRUE; /* binary mode */
331 static int rot_f = FALSE; /* rot14/43 mode */
332 static int hira_f = FALSE; /* hira/kata henkan */
333 static int input_f = FALSE; /* non fixed input code */
334 static int alpha_f = FALSE; /* convert JIx0208 alphbet to ASCII */
335 static int mime_f = STRICT_MIME; /* convert MIME B base64 or Q */
336 static int mimebuf_f = FALSE; /* MIME buffered input */
337 static int broken_f = FALSE; /* convert ESC-less broken JIS */
338 static int iso8859_f = FALSE; /* ISO8859 through */
339 static int mimeout_f = FALSE; /* base64 mode */
340 #if defined(MSDOS) || defined(__OS2__)
341 static int x0201_f = TRUE; /* Assume JISX0201 kana */
343 static int x0201_f = NO_X0201; /* Assume NO JISX0201 */
345 static int iso2022jp_f = FALSE; /* convert ISO-2022-JP */
346 #ifdef UTF8_OUTPUT_ENABLE
347 static int w_oconv16_begin_f= 0; /* utf-16 header */
351 #ifdef CAP_URL_OPTION
352 static int cap_f = FALSE;
353 static int (*i_cgetc)PROTO((FILE *)) = std_getc; /* input of cgetc */
354 static int (*i_cungetc)PROTO((int c ,FILE *f)) = std_ungetc;
355 STATIC int cap_getc PROTO((FILE *f));
356 STATIC int cap_ungetc PROTO((int c,FILE *f));
358 static int url_f = FALSE;
359 static int (*i_ugetc)PROTO((FILE *)) = std_getc; /* input of ugetc */
360 static int (*i_uungetc)PROTO((int c ,FILE *f)) = std_ungetc;
361 STATIC int url_getc PROTO((FILE *f));
362 STATIC int url_ungetc PROTO((int c,FILE *f));
366 static int noout_f = FALSE;
367 STATIC void no_putc PROTO((int c));
368 static int debug_f = FALSE;
369 STATIC void debug PROTO((char *str));
372 static int e_stat = 0;
373 static int s_stat = 0;
374 #ifdef UTF8_INPUT_ENABLE
375 static int w_stat = 0;
376 static int utf16_mode = UTF16_INPUT;
378 static int w_stat = -1;
381 static int mimeout_mode = 0;
382 static int base64_count = 0;
384 /* X0208 -> ASCII converter */
387 static int f_line = 0; /* chars in line */
388 static int f_prev = 0;
389 static int fold_preserve_f = FALSE; /* preserve new lines */
390 static int fold_f = FALSE;
391 static int fold_len = 0;
394 static unsigned char kanji_intro = DEFAULT_J,
395 ascii_intro = DEFAULT_R;
399 #define FOLD_MARGIN 10
400 #define DEFAULT_FOLD 60
402 static int fold_margin = FOLD_MARGIN;
406 #ifdef DEFAULT_CODE_JIS
407 # define DEFAULT_CONV j_oconv
409 #ifdef DEFAULT_CODE_SJIS
410 # define DEFAULT_CONV s_oconv
412 #ifdef DEFAULT_CODE_EUC
413 # define DEFAULT_CONV e_oconv
415 #ifdef DEFAULT_CODE_UTF8
416 # define DEFAULT_CONV w_oconv
419 /* process default */
420 static void (*output_conv)PROTO((int c2,int c1)) = DEFAULT_CONV;
422 static void (*oconv)PROTO((int c2,int c1)) = no_connection;
423 /* s_iconv or oconv */
424 static int (*iconv)PROTO((int c2,int c1,int c0)) = no_connection2;
426 static void (*o_zconv)PROTO((int c2,int c1)) = no_connection;
427 static void (*o_fconv)PROTO((int c2,int c1)) = no_connection;
428 static void (*o_crconv)PROTO((int c2,int c1)) = no_connection;
429 static void (*o_rot_conv)PROTO((int c2,int c1)) = no_connection;
430 static void (*o_hira_conv)PROTO((int c2,int c1)) = no_connection;
431 static void (*o_base64conv)PROTO((int c2,int c1)) = no_connection;
432 static void (*o_iso2022jp_check_conv)PROTO((int c2,int c1)) = no_connection;
434 /* static redirections */
436 static void (*o_putc)PROTO((int c)) = std_putc;
438 static int (*i_getc)PROTO((FILE *f)) = std_getc; /* general input */
439 static int (*i_ungetc)PROTO((int c,FILE *f)) =std_ungetc;
441 static int (*i_bgetc)PROTO((FILE *)) = std_getc; /* input of mgetc */
442 static int (*i_bungetc)PROTO((int c ,FILE *f)) = std_ungetc;
444 static void (*o_mputc)PROTO((int c)) = std_putc ; /* output of mputc */
446 static int (*i_mgetc)PROTO((FILE *)) = std_getc; /* input of mgetc */
447 static int (*i_mungetc)PROTO((int c ,FILE *f)) = std_ungetc;
449 /* for strict mime */
450 static int (*i_mgetc_buf)PROTO((FILE *)) = std_getc; /* input of mgetc_buf */
451 static int (*i_mungetc_buf)PROTO((int c,FILE *f)) = std_ungetc;
454 static int output_mode = ASCII, /* output kanji mode */
455 input_mode = ASCII, /* input kanji mode */
456 shift_mode = FALSE; /* TRUE shift out, or X0201 */
457 static int mime_decode_mode = FALSE; /* MIME mode B base64, Q hex */
459 /* X0201 / X0208 conversion tables */
461 /* X0201 kana conversion table */
464 unsigned char cv[]= {
465 0x21,0x21,0x21,0x23,0x21,0x56,0x21,0x57,
466 0x21,0x22,0x21,0x26,0x25,0x72,0x25,0x21,
467 0x25,0x23,0x25,0x25,0x25,0x27,0x25,0x29,
468 0x25,0x63,0x25,0x65,0x25,0x67,0x25,0x43,
469 0x21,0x3c,0x25,0x22,0x25,0x24,0x25,0x26,
470 0x25,0x28,0x25,0x2a,0x25,0x2b,0x25,0x2d,
471 0x25,0x2f,0x25,0x31,0x25,0x33,0x25,0x35,
472 0x25,0x37,0x25,0x39,0x25,0x3b,0x25,0x3d,
473 0x25,0x3f,0x25,0x41,0x25,0x44,0x25,0x46,
474 0x25,0x48,0x25,0x4a,0x25,0x4b,0x25,0x4c,
475 0x25,0x4d,0x25,0x4e,0x25,0x4f,0x25,0x52,
476 0x25,0x55,0x25,0x58,0x25,0x5b,0x25,0x5e,
477 0x25,0x5f,0x25,0x60,0x25,0x61,0x25,0x62,
478 0x25,0x64,0x25,0x66,0x25,0x68,0x25,0x69,
479 0x25,0x6a,0x25,0x6b,0x25,0x6c,0x25,0x6d,
480 0x25,0x6f,0x25,0x73,0x21,0x2b,0x21,0x2c,
484 /* X0201 kana conversion table for daguten */
487 unsigned char dv[]= {
488 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
489 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
490 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
491 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
492 0x00,0x00,0x00,0x00,0x00,0x00,0x25,0x74,
493 0x00,0x00,0x00,0x00,0x25,0x2c,0x25,0x2e,
494 0x25,0x30,0x25,0x32,0x25,0x34,0x25,0x36,
495 0x25,0x38,0x25,0x3a,0x25,0x3c,0x25,0x3e,
496 0x25,0x40,0x25,0x42,0x25,0x45,0x25,0x47,
497 0x25,0x49,0x00,0x00,0x00,0x00,0x00,0x00,
498 0x00,0x00,0x00,0x00,0x25,0x50,0x25,0x53,
499 0x25,0x56,0x25,0x59,0x25,0x5c,0x00,0x00,
500 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
501 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
502 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
503 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
506 /* X0201 kana conversion table for han-daguten */
509 unsigned char ev[]= {
510 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
511 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
512 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
513 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
514 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
515 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
516 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
517 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
518 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
519 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
520 0x00,0x00,0x00,0x00,0x25,0x51,0x25,0x54,
521 0x25,0x57,0x25,0x5a,0x25,0x5d,0x00,0x00,
522 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
523 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
524 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
525 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
529 /* X0208 kigou conversion table */
530 /* 0x8140 - 0x819e */
532 unsigned char fv[] = {
534 0x00,0x00,0x00,0x00,0x2c,0x2e,0x00,0x3a,
535 0x3b,0x3f,0x21,0x00,0x00,0x27,0x60,0x00,
536 0x5e,0x00,0x5f,0x00,0x00,0x00,0x00,0x00,
537 0x00,0x00,0x00,0x00,0x00,0x2d,0x00,0x2f,
538 0x5c,0x00,0x00,0x7c,0x00,0x00,0x60,0x27,
539 0x22,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,
540 0x7b,0x7d,0x3c,0x3e,0x00,0x00,0x00,0x00,
541 0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,
542 0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,
543 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
544 0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40,
545 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
551 static int file_out = FALSE;
553 static int overwrite = FALSE;
556 static int crmode_f = 0; /* CR, NL, CRLF */
557 #ifdef EASYWIN /*Easy Win */
558 static int end_check;
570 #ifdef EASYWIN /*Easy Win */
571 _BufferSize.y = 400;/*Set Scroll Buffer Size*/
574 for (argc--,argv++; (argc > 0) && **argv == '-'; argc--, argv++) {
575 cp = (unsigned char *)*argv;
578 if(x0201_f == WISH_TRUE)
579 x0201_f = ((!iso2022jp_f)? TRUE : NO_X0201);
581 if (binmode_f == TRUE)
583 if (freopen("","wb",stdout) == NULL)
590 setbuf(stdout, (char *) NULL);
592 setvbuffer(stdout, stdobuf, IOBUF_SIZE);
595 if (binmode_f == TRUE)
597 if (freopen("","rb",stdin) == NULL) return (-1);
601 setvbuffer(stdin, stdibuf, IOBUF_SIZE);
605 kanji_convert(stdin);
611 if ((fin = fopen((origfname = *argv++), "r")) == NULL) {
620 /* reopen file for stdout */
621 if (file_out == TRUE) {
624 outfname = malloc(strlen(origfname)
625 + strlen(".nkftmpXXXXXX")
631 strcpy(outfname, origfname);
635 for (i = strlen(outfname); i; --i){
636 if (outfname[i - 1] == '/'
637 || outfname[i - 1] == '\\'){
643 strcat(outfname, "ntXXXXXX");
645 fd = open(outfname, O_WRONLY | O_CREAT | O_TRUNC,
648 strcat(outfname, ".nkftmpXXXXXX");
649 fd = mkstemp(outfname);
652 || (fd_backup = dup(fileno(stdout))) < 0
653 || dup2(fd, fileno(stdout)) < 0
664 outfname = "nkf.out";
667 if(freopen(outfname, "w", stdout) == NULL) {
671 if (binmode_f == TRUE) {
673 if (freopen("","wb",stdout) == NULL)
680 if (binmode_f == TRUE)
682 if (freopen("","rb",fin) == NULL)
687 setvbuffer(fin, stdibuf, IOBUF_SIZE);
704 if (dup2(fd_backup, fileno(stdout)) < 0){
707 if (stat(origfname, &sb)) {
708 fprintf(stderr, "Can't stat %s\n", origfname);
710 /*
\e$B%Q!<%_%C%7%g%s$rI|85
\e(B */
711 if (chmod(outfname, sb.st_mode)) {
712 fprintf(stderr, "Can't set permission %s\n", outfname);
715 tb[0] = tb[1] = sb.st_mtime;
716 /*
\e$B%?%$%`%9%?%s%W$rI|85
\e(B */
717 if (utime(outfname, tb)) {
718 fprintf(stderr, "Can't set timestamp %s\n", outfname);
721 if (unlink(origfname)){
725 tb.actime = sb.st_atime;
726 tb.modtime = sb.st_mtime;
727 /*
\e$B%?%$%`%9%?%s%W$rI|85
\e(B */
728 if (utime(outfname, &tb)) {
729 fprintf(stderr, "Can't set timestamp %s\n", outfname);
732 if (rename(outfname, origfname)) {
734 fprintf(stderr, "Can't rename %s to %s\n",
735 outfname, origfname);
743 #ifdef EASYWIN /*Easy Win */
744 if (file_out == FALSE)
745 scanf("%d",&end_check);
748 #else /* for Other OS */
749 if (file_out == TRUE)
779 {"katakana-hiragana","h3"},
780 #ifdef UTF8_OUTPUT_ENABLE
784 #ifdef UTF8_INPUT_ENABLE
786 {"utf16-input", "W16"},
791 #ifdef CAP_URL_OPTION
801 static int option_mode;
816 case '-': /* literal options */
817 if (!*cp) { /* ignore the rest of arguments */
821 for (i=0;i<sizeof(long_option)/sizeof(long_option[0]);i++) {
823 p = (unsigned char *)long_option[i].name;
824 for (j=0;*p && *p++ == cp[j];j++);
825 if (! *p && !cp[j]) break;
828 cp = (unsigned char *)long_option[i].alias;
831 if (strcmp(long_option[i].name, "overwrite") == 0){
837 #ifdef CAP_URL_OPTION
838 if (strcmp(long_option[i].name, "cap-input") == 0){
842 if (strcmp(long_option[i].name, "url-input") == 0){
848 if (strcmp(long_option[i].name, "no-output") == 0){
852 if (strcmp(long_option[i].name, "debug") == 0){
859 case 'b': /* buffered mode */
862 case 'u': /* non bufferd mode */
865 case 't': /* transparent mode */
868 case 'j': /* JIS output */
870 output_conv = j_oconv;
872 case 'e': /* AT&T EUC output */
873 output_conv = e_oconv;
875 case 's': /* SJIS output */
876 output_conv = s_oconv;
878 case 'l': /* ISO8859 Latin-1 support, no conversion */
879 iso8859_f = TRUE; /* Only compatible with ISO-2022-JP */
880 input_f = LATIN1_INPUT;
882 case 'i': /* Kanji IN ESC-$-@/B */
883 if (*cp=='@'||*cp=='B')
886 case 'o': /* ASCII IN ESC-(-J/B */
887 if (*cp=='J'||*cp=='B'||*cp=='H')
895 if ('9'>= *cp && *cp>='0')
896 hira_f |= (*cp++ -'0');
903 #if defined(MSDOS) || defined(__OS2__)
918 #ifdef UTF8_OUTPUT_ENABLE
919 case 'w': /* UTF-8 output */
920 if ('1'== cp[0] && '6'==cp[1]) {
921 output_conv = w_oconv16; cp+=2;
923 w_oconv16_begin_f=2; cp++;
926 output_conv = w_oconv;
929 #ifdef UTF8_INPUT_ENABLE
930 case 'W': /* UTF-8 input */
931 if ('1'== cp[0] && '6'==cp[1]) {
932 input_f = UTF16_INPUT;
934 input_f = UTF8_INPUT;
937 /* Input code assumption */
938 case 'J': /* JIS input */
939 case 'E': /* AT&T EUC input */
942 case 'S': /* MS Kanji input */
943 input_f = SJIS_INPUT;
944 if (x0201_f==NO_X0201) x0201_f=TRUE;
946 case 'Z': /* Convert X0208 alphabet to asii */
947 /* bit:0 Convert X0208
948 bit:1 Convert Kankaku to one space
949 bit:2 Convert Kankaku to two spaces
950 bit:3 Convert HTML Entity
952 if ('9'>= *cp && *cp>='0')
953 alpha_f |= 1<<(*cp++ -'0');
957 case 'x': /* Convert X0201 kana to X0208 or X0201 Conversion */
958 x0201_f = FALSE; /* No X0201->X0208 conversion */
960 ESC-(-I in JIS, EUC, MS Kanji
961 SI/SO in JIS, EUC, MS Kanji
962 SSO in EUC, JIS, not in MS Kanji
965 ESC-(-I in JIS (0x20-0x5f)
966 SSO in EUC (0xa0-0xdf)
967 0xa0-0xd in MS Kanji (0xa0-0xdf)
970 case 'X': /* Assume X0201 kana */
971 /* Default value is NO_X0201 for EUC/MS-Kanji mix */
974 case 'F': /* prserve new lines */
975 fold_preserve_f = TRUE;
976 case 'f': /* folding -f60 or -f */
979 while('0'<= *cp && *cp <='9') { /* we don't use atoi here */
981 fold_len += *cp++ - '0';
983 if (!(0<fold_len && fold_len<BUFSIZ))
984 fold_len = DEFAULT_FOLD;
988 while('0'<= *cp && *cp <='9') { /* we don't use atoi here */
990 fold_margin += *cp++ - '0';
994 case 'm': /* MIME support */
995 if (*cp=='B'||*cp=='Q') {
996 mime_decode_mode = *cp++;
997 mimebuf_f = FIXED_MIME;
998 } else if (*cp=='N') {
1000 } else if (*cp=='S') {
1001 mime_f = STRICT_MIME; cp++;
1002 } else if (*cp=='0') {
1006 case 'M': /* MIME output */
1009 mimeout_f = FIXED_MIME; cp++;
1010 } else if (*cp=='Q') {
1012 mimeout_f = FIXED_MIME; cp++;
1017 case 'B': /* Broken JIS support */
1019 bit:1 allow any x on ESC-(-x or ESC-$-x
1020 bit:2 reset to ascii on NL
1022 if ('9'>= *cp && *cp>='0')
1023 broken_f |= 1<<(*cp++ -'0');
1028 case 'O':/* for Output file */
1032 case 'c':/* add cr code */
1035 case 'd':/* delete cr code */
1038 case 'I': /* ISO-2022-JP output */
1041 case 'L': /* line mode */
1042 if (*cp=='u') { /* unix */
1044 } else if (*cp=='m') { /* mac */
1046 } else if (*cp=='w') { /* windows */
1048 } else if (*cp=='0') { /* no conversion */
1053 /* module muliple options in a string are allowed for Perl moudle */
1054 while(*cp && *cp!='-') cp++;
1058 /* bogus option but ignored */
1064 #ifdef ANSI_C_PROTOTYPE
1065 void set_iconv(int f, int (*iconv_func)(int c2,int c1,int c0))
1067 void set_iconv(f, iconv_func)
1069 int (*iconv_func)();
1073 static int (*iconv_for_check)() = 0;
1075 #ifdef INPUT_CODE_FIX
1083 #ifdef INPUT_CODE_FIX
1084 && (f == -TRUE || !input_f) /* -TRUE means "FORCE" */
1090 if (estab_f && iconv_for_check != iconv){
1091 #ifdef UTF8_INPUT_ENABLE
1092 if (iconv == w_iconv) debug("UTF-8\n");
1093 if (iconv == w_iconv16) debug("UTF-16\n");
1095 if (iconv == s_iconv) debug("Shift_JIS\n");
1096 if (iconv == e_iconv) debug("EUC-JP\n");
1097 iconv_for_check = iconv;
1108 if (c <= DEL && estab_f){
1114 || (0xa1 <= c && c <= 0xef && iconv == s_iconv)){
1116 }else if ((0x81 <= c && c < 0xa0) || (0xe0 <= c && c <= 0xea)){
1120 if (iconv == s_iconv) set_iconv(FALSE, 0);
1124 if ((0x40 <= c && c <= 0x7e) || (0x80 <= c && c <= 0xfd)){
1128 if (iconv == s_iconv) set_iconv(FALSE, 0);
1134 if (c <= DEL && estab_f){
1141 }else if (SSO == c || (0xa1 <= c && c <= 0xfe)){
1145 if (iconv == e_iconv) set_iconv(FALSE, 0);
1149 if (0xa1 <= c && c <= 0xfe){
1153 if (iconv == e_iconv) set_iconv(FALSE, 0);
1157 #ifdef UTF8_INPUT_ENABLE
1160 if (c <= DEL && estab_f){
1167 }else if (0xc0 <= c && c <= 0xdf){
1169 }else if (0xe0 <= c && c <= 0xef){
1173 if (iconv == w_iconv) set_iconv(FALSE, 0);
1178 if (0x80 <= c && c <= 0xbf){
1182 if (iconv == w_iconv) set_iconv(FALSE, 0);
1187 if (s_stat < 0 && e_stat < 0 && w_stat == 0){
1188 set_iconv(TRUE, w_iconv);
1191 if (s_stat == 0 && e_stat < 0 && w_stat < 0){
1192 set_iconv(TRUE, s_iconv);
1194 if (s_stat < 0 && e_stat == 0 && w_stat < 0){
1195 set_iconv(TRUE, e_iconv);
1197 if (s_stat < 0 && e_stat < 0 && w_stat < 0){
1199 s_stat = e_stat = 0;
1200 #ifdef UTF8_INPUT_ENABLE
1235 while ((c = (*i_getc)(f)) != EOF)
1244 oconv = output_conv;
1247 /* replace continucation module, from output side */
1249 /* output redicrection */
1258 if (mimeout_f == TRUE) {
1259 o_base64conv = oconv; oconv = base64_conv;
1261 /* base64_count = 0; */
1265 o_crconv = oconv; oconv = cr_conv;
1268 o_rot_conv = oconv; oconv = rot_conv;
1271 o_iso2022jp_check_conv = oconv; oconv = iso2022jp_check_conv;
1274 o_hira_conv = oconv; oconv = hira_conv;
1277 o_fconv = oconv; oconv = fold_conv;
1280 if (alpha_f || x0201_f) {
1281 o_zconv = oconv; oconv = z_conv;
1285 /* input redicrection */
1286 #ifdef CAP_URL_OPTION
1288 i_cgetc = i_getc; i_getc = cap_getc;
1289 i_cungetc = i_ungetc; i_ungetc= cap_ungetc;
1292 i_ugetc = i_getc; i_getc = url_getc;
1293 i_uungetc = i_ungetc; i_ungetc= url_ungetc;
1296 if (mime_f && mimebuf_f==FIXED_MIME) {
1297 i_mgetc = i_getc; i_getc = mime_getc;
1298 i_mungetc = i_ungetc; i_ungetc = mime_ungetc;
1301 i_bgetc = i_getc; i_getc = broken_getc;
1302 i_bungetc = i_ungetc; i_ungetc = broken_ungetc;
1304 if (input_f == JIS_INPUT || input_f == LATIN1_INPUT) {
1305 set_iconv(-TRUE, e_iconv);
1306 } else if (input_f == SJIS_INPUT) {
1307 set_iconv(-TRUE, s_iconv);
1308 #ifdef UTF8_INPUT_ENABLE
1309 } else if (input_f == UTF8_INPUT) {
1310 set_iconv(-TRUE, w_iconv);
1311 } else if (input_f == UTF16_INPUT) {
1312 set_iconv(-TRUE, w_iconv16);
1315 set_iconv(FALSE, e_iconv);
1320 #ifdef UTF8_INPUT_ENABLE
1328 Conversion main loop. Code detection only.
1338 module_connection();
1343 output_mode = ASCII;
1346 #define NEXT continue /* no output, get next */
1347 #define SEND ; /* output c1 and c2, get next */
1348 #define LAST break /* end of loop, go closing */
1350 while ((c1 = (*i_getc)(f)) != EOF) {
1355 /* in case of 8th bit is on */
1357 /* in case of not established yet */
1358 /* It is still ambiguious */
1359 if (h_conv(f, c2, c1)==EOF)
1365 /* in case of already established */
1367 /* ignore bogus code */
1373 /* second byte, 7 bit code */
1374 /* it might be kanji shitfted */
1375 if ((c1 == DEL) || (c1 <= SPACE)) {
1376 /* ignore bogus first code */
1383 if (iconv == w_iconv16) {
1387 } else if (c1 > DEL) {
1389 if (!estab_f && !iso8859_f) {
1390 /* not established yet */
1393 } else { /* estab_f==TRUE */
1398 } else if (SSP<=c1 && c1<0xe0 && iconv == s_iconv) {
1399 /* SJIS X0201 Case... */
1400 if(iso2022jp_f && x0201_f==NO_X0201) {
1401 (*oconv)(GETA1, GETA2);
1408 } else if (c1==SSO && iconv != s_iconv) {
1409 /* EUC X0201 Case */
1410 c1 = (*i_getc)(f); /* skip SSO */
1412 if (SSP<=c1 && c1<0xe0) {
1413 if(iso2022jp_f && x0201_f==NO_X0201) {
1414 (*oconv)(GETA1, GETA2);
1421 } else { /* bogus code, skip SSO and one byte */
1425 /* already established */
1430 } else if ((c1 > SPACE) && (c1 != DEL)) {
1431 /* in case of Roman characters */
1433 /* output 1 shifted byte */
1437 } else if (SPACE<=c1 && c1<(0xe0&0x7f) ){
1438 /* output 1 shifted byte */
1439 if(iso2022jp_f && x0201_f==NO_X0201) {
1440 (*oconv)(GETA1, GETA2);
1447 /* look like bogus code */
1450 } else if (input_mode == X0208) {
1451 /* in case of Kanji shifted */
1454 } else if (c1 == '=' && mime_f && !mime_decode_mode ) {
1455 /* Check MIME code */
1456 if ((c1 = (*i_getc)(f)) == EOF) {
1459 } else if (c1 == '?') {
1460 /* =? is mime conversion start sequence */
1461 if(mime_f == STRICT_MIME) {
1462 /* check in real detail */
1463 if (mime_begin_strict(f) == EOF)
1467 } else if (mime_begin(f) == EOF)
1477 /* normal ASCII code */
1480 } else if (c1 == SI) {
1483 } else if (c1 == SO) {
1486 } else if (c1 == ESC ) {
1487 if ((c1 = (*i_getc)(f)) == EOF) {
1488 /* (*oconv)(0, ESC); don't send bogus code */
1490 } else if (c1 == '$') {
1491 if ((c1 = (*i_getc)(f)) == EOF) {
1493 (*oconv)(0, ESC); don't send bogus code
1494 (*oconv)(0, '$'); */
1496 } else if (c1 == '@'|| c1 == 'B') {
1497 /* This is kanji introduction */
1501 } else if (c1 == '(') {
1502 if ((c1 = (*i_getc)(f)) == EOF) {
1503 /* don't send bogus code
1509 } else if (c1 == '@'|| c1 == 'B') {
1510 /* This is kanji introduction */
1515 /* could be some special code */
1522 } else if (broken_f&0x2) {
1523 /* accept any ESC-(-x as broken code ... */
1533 } else if (c1 == '(') {
1534 if ((c1 = (*i_getc)(f)) == EOF) {
1535 /* don't send bogus code
1537 (*oconv)(0, '('); */
1541 /* This is X0201 kana introduction */
1542 input_mode = X0201; shift_mode = X0201;
1544 } else if (c1 == 'B' || c1 == 'J' || c1 == 'H') {
1545 /* This is X0208 kanji introduction */
1546 input_mode = ASCII; shift_mode = FALSE;
1548 } else if (broken_f&0x2) {
1549 input_mode = ASCII; shift_mode = FALSE;
1554 /* maintain various input_mode here */
1558 } else if ( c1 == 'N' || c1 == 'n' ){
1560 c1 = (*i_getc)(f); /* skip SS2 */
1561 if ( SPACE<=c1 && c1 < 0xe0 ) {
1570 } else if ((c1 == NL || c1 == CR) && broken_f&4) {
1571 input_mode = ASCII; set_iconv(FALSE, 0);
1577 if (input_mode == X0208)
1578 (*oconv)(c2, c1); /* this is JIS, not SJIS/EUC case */
1579 else if (input_mode)
1580 (*oconv)(input_mode, c1); /* other special case */
1581 else if ((*iconv)(c2, c1, 0) < 0){ /* can be EUC/SJIS */
1582 int c0 = (*i_getc)(f);
1585 (*iconv)(c2, c1, c0);
1591 /* goto next_word */
1595 (*iconv)(EOF, 0, 0);
1608 /** it must NOT be in the kanji shifte sequence */
1609 /** it must NOT be written in JIS7 */
1610 /** and it must be after 2 byte 8bit code */
1617 while ((c1 = (*i_getc)(f)) != EOF) {
1623 if (push_hold_buf(c1) == EOF || estab_f){
1629 ** 1) EOF is detected, or
1630 ** 2) Code is established, or
1631 ** 3) Buffer is FULL (but last word is pushed)
1633 ** in 1) and 3) cases, we continue to use
1634 ** Kanji codes by oconv and leave estab_f unchanged.
1638 while (wc < hold_count){
1639 c2 = hold_buf[wc++];
1643 }else if (iconv == s_iconv && 0xa1 <= c2 && c2 <= 0xdf){
1644 (*iconv)(X0201, c2, 0);
1647 if (wc < hold_count){
1648 c1 = hold_buf[wc++];
1651 if (c1 == EOF) break;
1654 if ((*iconv)(c2, c1, 0) < 0){
1656 if (wc < hold_count){
1657 c0 = hold_buf[wc++];
1660 if (c0 == EOF) break;
1663 (*iconv)(c2, c1, c0);
1677 if (hold_count >= HOLD_SIZE*2)
1679 hold_buf[hold_count++] = c2;
1680 return ((hold_count >= HOLD_SIZE*2) ? EOF : hold_count);
1683 int s2e_conv(c2, c1, p2, p1)
1687 c2 = c2 + c2 - ((c2 <= 0x9f) ? SJ0162 : SJ6394);
1689 c1 = c1 - ((c1 > DEL) ? SPACE : 0x1f);
1696 return (c2 << 8) | c1;
1706 } else if ((c2 == EOF) || (c2 == 0) || c2 < SPACE) {
1709 s2e_conv(c2, c1, &c2, &c1);
1722 } else if ((c2 == EOF) || (c2 == 0) || c2 < SPACE) {
1732 #ifdef UTF8_INPUT_ENABLE
1734 w2e_conv(c2, c1, c0, p2, p1)
1738 extern unsigned short * utf8_to_euc_2bytes[];
1739 extern unsigned short ** utf8_to_euc_3bytes[];
1741 if (0xc0 <= c2 && c2 <= 0xef) {
1742 unsigned short **pp;
1745 if (c0 == 0) return -1;
1746 pp = utf8_to_euc_3bytes[c2 - 0x80];
1747 return w_iconv_common(c1, c0, pp, sizeof_utf8_to_euc_C2, p2, p1);
1749 return w_iconv_common(c2, c1, utf8_to_euc_2bytes, sizeof_utf8_to_euc_2bytes, p2, p1);
1751 } else if (c2 == X0201) {
1764 int ret = w2e_conv(c2, c1, c0, &c2, &c1);
1772 w_iconv16(c2, c1, c0)
1775 extern unsigned short * utf8_to_euc_2bytes[];
1776 extern unsigned short ** utf8_to_euc_3bytes[];
1777 unsigned short **pp;
1782 if (c2==0376 && c1==0377){
1783 utf16_mode = UTF16_INPUT;
1785 } else if (c2==0377 && c1==0376){
1786 utf16_mode = UTF16BE_INPUT;
1789 if (utf16_mode == UTF16BE_INPUT) {
1791 tmp=c1; c1=c2; c2=tmp;
1793 if (c2==0 || c2==EOF) {
1797 val = ((c2<<8)&0xff00) + c1;
1799 c0 = (0x80 | (c1 & 0x3f));
1800 c1 = (0xc0 | (val >> 6));
1801 pp = utf8_to_euc_2bytes;
1802 psize = sizeof_utf8_to_euc_2bytes;
1804 c0 = (0x80 | (c1 & 0x3f));
1805 c2 = (0xe0 | (val >> 12));
1806 c1 = (0x80 | ((val >> 6) & 0x3f));
1807 if (c0 == 0) return -1;
1808 if (0<=c2-0x80 && c2-0x80 <sizeof_utf8_to_euc_3bytes){
1809 pp = utf8_to_euc_3bytes[c2 - 0x80];
1810 psize = sizeof_utf8_to_euc_C2;
1815 ret = w_iconv_common(c1, c0, pp, psize, &c2, &c1);
1816 if (ret) return ret;
1822 w_iconv_common(c1, c0, pp, psize, p2, p1)
1824 unsigned short **pp;
1832 if (pp == 0) return 1;
1835 if (c1 < 0 || psize <= c1) return 1;
1837 if (p == 0) return 1;
1840 if (c0 < 0 || sizeof_utf8_to_euc_E5B8 <= c0) return 1;
1842 if (val == 0) return 1;
1845 if (c2 == SO) c2 = X0201;
1854 #ifdef UTF8_OUTPUT_ENABLE
1859 extern unsigned short euc_to_utf8_1byte[];
1860 extern unsigned short * euc_to_utf8_2bytes[];
1864 p = euc_to_utf8_1byte;
1867 c2 = (c2&0x7f) - 0x21;
1868 if (0<=c2 && c2<sizeof_euc_to_utf8_2bytes)
1869 p = euc_to_utf8_2bytes[c2];
1874 c1 = (c1 & 0x7f) - 0x21;
1875 if (0<=c1 && c1<sizeof_euc_to_utf8_1byte)
1887 } else if (c2 == 0) {
1888 output_mode = ASCII;
1890 } else if (c2 == ISO8859_1) {
1891 output_mode = ISO8859_1;
1892 (*o_putc)(c1 | 0x080);
1894 unsigned short val = (unsigned short)e2w_conv(c2, c1);
1897 if (0 < val && val < 0x80){
1899 }else if (val < 0x800){
1900 (*o_putc)(0xc0 | (val >> 6));
1901 (*o_putc)(0x80 | (val & 0x3f));
1903 (*o_putc)(0xe0 | (val >> 12));
1904 (*o_putc)(0x80 | ((val >> 6) & 0x3f));
1905 (*o_putc)(0x80 | (val & 0x3f));
1916 if (w_oconv16_begin_f==2) {
1919 w_oconv16_begin_f=1;
1923 } else if (c2 == 0) {
1926 } else if (c2 == ISO8859_1) {
1928 (*o_putc)(c1 | 0x080);
1930 unsigned short val = (unsigned short)e2w_conv(c2, c1);
1931 (*o_putc)((val&0xff00)>>8);
1932 (*o_putc)(val&0xff);
1945 } else if (c2 == 0) {
1946 output_mode = ASCII;
1948 } else if (c2 == X0201) {
1949 output_mode = JAPANESE_EUC;
1950 (*o_putc)(SSO); (*o_putc)(c1|0x80);
1951 } else if (c2 == ISO8859_1) {
1952 output_mode = ISO8859_1;
1953 (*o_putc)(c1 | 0x080);
1955 if ((c1<0x20 || 0x7e<c1) ||
1956 (c2<0x20 || 0x7e<c2)) {
1957 set_iconv(FALSE, 0);
1958 return; /* too late to rescue this char */
1960 output_mode = JAPANESE_EUC;
1961 (*o_putc)(c2 | 0x080);
1962 (*o_putc)(c1 | 0x080);
1975 } else if (c2 == 0) {
1976 output_mode = ASCII;
1978 } else if (c2 == X0201) {
1979 output_mode = SHIFT_JIS;
1981 } else if (c2 == ISO8859_1) {
1982 output_mode = ISO8859_1;
1983 (*o_putc)(c1 | 0x080);
1985 if ((c1<0x20 || 0x7e<c1) ||
1986 (c2<0x20 || 0x7e<c2)) {
1987 set_iconv(FALSE, 0);
1988 return; /* too late to rescue this char */
1990 output_mode = SHIFT_JIS;
1991 (*o_putc)((((c2 - 1) >> 1) + ((c2 <= 0x5e) ? 0x71 : 0xb1)));
1992 (*o_putc)((c1 + ((c2 & 1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e)));
2002 if (output_mode !=ASCII && output_mode!=ISO8859_1) {
2005 (*o_putc)(ascii_intro);
2006 output_mode = ASCII;
2008 } else if (c2==X0201) {
2009 if (output_mode!=X0201) {
2010 output_mode = X0201;
2016 } else if (c2==ISO8859_1) {
2017 /* iso8859 introduction, or 8th bit on */
2018 /* Can we convert in 7bit form using ESC-'-'-A ?
2020 output_mode = ISO8859_1;
2022 } else if (c2 == 0) {
2023 if (output_mode !=ASCII && output_mode!=ISO8859_1) {
2026 (*o_putc)(ascii_intro);
2027 output_mode = ASCII;
2031 if (output_mode != X0208) {
2032 output_mode = X0208;
2035 (*o_putc)(kanji_intro);
2037 if (c1<0x20 || 0x7e<c1)
2039 if (c2<0x20 || 0x7e<c2)
2051 if (base64_count>50 && !mimeout_mode && c2==0 && c1==SPACE) {
2053 } else if (base64_count>66 && mimeout_mode) {
2054 (*o_base64conv)(EOF,0);
2058 (*o_base64conv)(c2,c1);
2062 static int broken_buf[3];
2063 static int broken_counter = 0;
2064 static int broken_last = 0;
2071 if (broken_counter>0) {
2072 return broken_buf[--broken_counter];
2075 if (c=='$' && broken_last != ESC
2076 && (input_mode==ASCII || input_mode==X0201)) {
2079 if (c1=='@'|| c1=='B') {
2080 broken_buf[0]=c1; broken_buf[1]=c;
2087 } else if (c=='(' && broken_last != ESC
2088 && (input_mode==X0208 || input_mode==X0201)) { /* ) */
2091 if (c1=='J'|| c1=='B') {
2092 broken_buf[0]=c1; broken_buf[1]=c;
2110 if (broken_counter<2)
2111 broken_buf[broken_counter++]=c;
2115 static int prev_cr = 0;
2123 if (! (c2==0&&c1==NL) ) {
2129 } else if (c1=='\r') {
2131 } else if (c1=='\n') {
2132 if (crmode_f==CRLF) {
2133 (*o_crconv)(0,'\r');
2134 } else if (crmode_f==CR) {
2135 (*o_crconv)(0,'\r');
2139 } else if (c1!='\032' || crmode_f!=NL){
2145 Return value of fold_conv()
2147 \n add newline and output char
2148 \r add newline and output nothing
2151 1 (or else) normal output
2153 fold state in prev (previous character)
2155 >0x80 Japanese (X0208/X0201)
2160 This fold algorthm does not preserve heading space in a line.
2161 This is the main difference from fmt.
2164 #define char_size(c2,c1) (c2?2:1)
2174 fold_state=0; /* ignroe cr */
2175 } else if (c1== BS) {
2176 if (f_line>0) f_line--;
2178 } else if (c2==EOF && f_line != 0) { /* close open last line */
2180 } else if (c1=='\n') {
2182 if (fold_preserve_f) {
2185 } else if (f_prev == c1) { /* duplicate newline */
2188 fold_state = '\n'; /* output two newline */
2194 if (f_prev&0x80) { /* Japanese? */
2196 fold_state = 0; /* ignore given single newline */
2197 } else if (f_prev==' ') {
2201 if (++f_line<=fold_len)
2205 fold_state = '\r'; /* fold and output nothing */
2209 } else if (c1=='\f') {
2214 fold_state = '\n'; /* output newline and clear */
2215 } else if ( (c2==0 && c1==' ')||
2216 (c2==0 && c1=='\t')||
2217 (c2=='!'&& c1=='!')) {
2218 /* X0208 kankaku or ascii space */
2219 if (f_prev == ' ') {
2220 fold_state = 0; /* remove duplicate spaces */
2223 if (++f_line<=fold_len)
2224 fold_state = ' '; /* output ASCII space only */
2226 f_prev = ' '; f_line = 0;
2227 fold_state = '\r'; /* fold and output nothing */
2231 prev0 = f_prev; /* we still need this one... , but almost done */
2233 if (c2 || c2==X0201)
2234 f_prev |= 0x80; /* this is Japanese */
2235 f_line += char_size(c2,c1);
2236 if (f_line<=fold_len) { /* normal case */
2239 if (f_line>=fold_len+fold_margin) { /* too many kinsou suspension */
2240 f_line = char_size(c2,c1);
2241 fold_state = '\n'; /* We can't wait, do fold now */
2242 } else if (c2==X0201) {
2243 /* simple kinsoku rules return 1 means no folding */
2244 if (c1==(0xde&0x7f)) fold_state = 1; /*
\e$B!+
\e(B*/
2245 else if (c1==(0xdf&0x7f)) fold_state = 1; /*
\e$B!,
\e(B*/
2246 else if (c1==(0xa4&0x7f)) fold_state = 1; /*
\e$B!#
\e(B*/
2247 else if (c1==(0xa3&0x7f)) fold_state = 1; /*
\e$B!$
\e(B*/
2248 else if (c1==(0xa1&0x7f)) fold_state = 1; /*
\e$B!W
\e(B*/
2249 else if (c1==(0xb0&0x7f)) fold_state = 1; /* - */
2250 else if (SPACE<=c1 && c1<=(0xdf&0x7f)) { /* X0201 */
2252 fold_state = '\n';/* add one new f_line before this character */
2255 fold_state = '\n';/* add one new f_line before this character */
2258 /* kinsoku point in ASCII */
2259 if ( c1==')'|| /* { [ ( */
2270 /* just after special */
2271 } else if (!is_alnum(prev0)) {
2272 f_line = char_size(c2,c1);
2274 } else if ((prev0==' ') || /* ignored new f_line */
2275 (prev0=='\n')|| /* ignored new f_line */
2276 (prev0&0x80)) { /* X0208 - ASCII */
2277 f_line = char_size(c2,c1);
2278 fold_state = '\n';/* add one new f_line before this character */
2280 fold_state = 1; /* default no fold in ASCII */
2284 if (c1=='"') fold_state = 1; /*
\e$B!"
\e(B */
2285 else if (c1=='#') fold_state = 1; /*
\e$B!#
\e(B */
2286 else if (c1=='W') fold_state = 1; /*
\e$B!W
\e(B */
2287 else if (c1=='K') fold_state = 1; /*
\e$B!K
\e(B */
2288 else if (c1=='$') fold_state = 1; /*
\e$B!$
\e(B */
2289 else if (c1=='%') fold_state = 1; /*
\e$B!%
\e(B */
2290 else if (c1=='\'') fold_state = 1; /*
\e$B!\
\e(B */
2291 else if (c1=='(') fold_state = 1; /*
\e$B!(
\e(B */
2292 else if (c1==')') fold_state = 1; /*
\e$B!)
\e(B */
2293 else if (c1=='*') fold_state = 1; /*
\e$B!*
\e(B */
2294 else if (c1=='+') fold_state = 1; /*
\e$B!+
\e(B */
2295 else if (c1==',') fold_state = 1; /*
\e$B!,
\e(B */
2296 /* default no fold in kinsoku */
2299 f_line = char_size(c2,c1);
2300 /* add one new f_line before this character */
2303 f_line = char_size(c2,c1);
2305 /* add one new f_line before this character */
2310 /* terminator process */
2311 switch(fold_state) {
2330 int z_prev2=0,z_prev1=0;
2337 /* if (c2) c1 &= 0x7f; assertion */
2339 if (x0201_f && z_prev2==X0201) { /* X0201 */
2340 if (c1==(0xde&0x7f)) { /*
\e$BByE@
\e(B */
2342 (*o_zconv)(dv[(z_prev1-SPACE)*2],dv[(z_prev1-SPACE)*2+1]);
2344 } else if (c1==(0xdf&0x7f)&&ev[(z_prev1-SPACE)*2]) { /*
\e$BH>ByE@
\e(B */
2346 (*o_zconv)(ev[(z_prev1-SPACE)*2],ev[(z_prev1-SPACE)*2+1]);
2350 (*o_zconv)(cv[(z_prev1-SPACE)*2],cv[(z_prev1-SPACE)*2+1]);
2359 if (x0201_f && c2==X0201) {
2360 if (dv[(c1-SPACE)*2]||ev[(c1-SPACE)*2]) {
2361 /* wait for
\e$BByE@
\e(B or
\e$BH>ByE@
\e(B */
2362 z_prev1 = c1; z_prev2 = c2;
2365 (*o_zconv)(cv[(c1-SPACE)*2],cv[(c1-SPACE)*2+1]);
2370 /* JISX0208 Alphabet */
2371 if (alpha_f && c2 == 0x23 ) {
2373 } else if (alpha_f && c2 == 0x21 ) {
2374 /* JISX0208 Kigou */
2379 } else if (alpha_f&0x4) {
2384 } else if (0x20<c1 && c1<0x7f && fv[c1-0x20]) {
2390 case '>': entity = ">"; break;
2391 case '<': entity = "<"; break;
2392 case '\"': entity = """; break;
2393 case '&': entity = "&"; break;
2396 while (*entity) (*o_zconv)(0, *entity++);
2406 #define rot13(c) ( \
2408 (c <= 'M') ? (c + 13): \
2409 (c <= 'Z') ? (c - 13): \
2411 (c <= 'm') ? (c + 13): \
2412 (c <= 'z') ? (c - 13): \
2416 #define rot47(c) ( \
2418 ( c <= 'O' ) ? (c + 47) : \
2419 ( c <= '~' ) ? (c - 47) : \
2427 if (c2==0 || c2==X0201 || c2==ISO8859_1) {
2433 (*o_rot_conv)(c2,c1);
2440 if ((hira_f & 1) && c2==0x25 && 0x20<c1 && c1<0x74) {
2442 } else if ((hira_f & 2) && c2==0x24 && 0x20<c1 && c1<0x74) {
2445 (*o_hira_conv)(c2,c1);
2450 iso2022jp_check_conv(c2,c1)
2453 static int range[RANGE_NUM_MAX][2] = {
2476 if(c2 >= 0x00 && c2 <= 0x20 && c1 >= 0x7f && c1 <= 0xff) {
2480 if((c2 >= 0x29 && c2 <= 0x2f) || (c2 >= 0x75 && c2 <= 0x7e)) {
2485 for (i = 0; i < RANGE_NUM_MAX; i++) {
2486 start = range[i][0];
2489 if (c >= start && c <= end) {
2494 (*o_iso2022jp_check_conv)(c2,c1);
2498 /* This converts =?ISO-2022-JP?B?HOGE HOGE?= */
2500 unsigned char *mime_pattern[] = {
2501 (unsigned char *)"\075?EUC-JP?B?",
2502 (unsigned char *)"\075?SHIFT_JIS?B?",
2503 (unsigned char *)"\075?ISO-8859-1?Q?",
2504 (unsigned char *)"\075?ISO-2022-JP?B?",
2505 (unsigned char *)"\075?ISO-2022-JP?Q?",
2506 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
2507 (unsigned char *)"\075?UTF-8?B?",
2512 int mime_encode[] = {
2513 JAPANESE_EUC, SHIFT_JIS,ISO8859_1, X0208, X0201,
2514 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
2520 int mime_encode_method[] = {
2521 'B', 'B','Q', 'B', 'Q',
2522 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
2529 #define MAXRECOVER 20
2531 /* I don't trust portablity of toupper */
2532 #define nkf_toupper(c) (('a'<=c && c<='z')?(c-('a'-'A')):c)
2537 if (i_getc!=mime_getc) {
2538 i_mgetc = i_getc; i_getc = mime_getc;
2539 i_mungetc = i_ungetc; i_ungetc = mime_ungetc;
2540 if(mime_f==STRICT_MIME) {
2541 i_mgetc_buf = i_mgetc; i_mgetc = mime_getc_buf;
2542 i_mungetc_buf = i_mungetc; i_mungetc = mime_ungetc_buf;
2548 unswitch_mime_getc()
2550 if(mime_f==STRICT_MIME) {
2551 i_mgetc = i_mgetc_buf;
2552 i_mungetc = i_mungetc_buf;
2555 i_ungetc = i_mungetc;
2559 mime_begin_strict(f)
2564 unsigned char *p,*q;
2565 int r[MAXRECOVER]; /* recovery buffer, max mime pattern lenght */
2567 mime_decode_mode = FALSE;
2568 /* =? has been checked */
2570 p = mime_pattern[j];
2573 for(i=2;p[i]>' ';i++) { /* start at =? */
2574 if ( ((r[i] = c1 = (*i_getc)(f))==EOF) || nkf_toupper(c1) != p[i] ) {
2575 /* pattern fails, try next one */
2577 while ((p = mime_pattern[++j])) {
2578 for(k=2;k<i;k++) /* assume length(p) > i */
2579 if (p[k]!=q[k]) break;
2580 if (k==i && nkf_toupper(c1)==p[k]) break;
2582 if (p) continue; /* found next one, continue */
2583 /* all fails, output from recovery buffer */
2591 mime_decode_mode = p[i-2];
2592 if (mime_decode_mode=='B') {
2593 mimebuf_f = unbuf_f;
2595 /* do MIME integrity check */
2596 return mime_integrity(f,mime_pattern[j]);
2608 /* we don't keep eof of Fifo, becase it contains ?= as
2609 a terminator. It was checked in mime_integrity. */
2610 return ((mimebuf_f)?
2611 (*i_mgetc_buf)(f):Fifo(mime_input++));
2615 mime_ungetc_buf(c,f)
2620 (*i_mungetc_buf)(c,f);
2622 Fifo(--mime_input)=c;
2633 /* In NONSTRICT mode, only =? is checked. In case of failure, we */
2634 /* re-read and convert again from mime_buffer. */
2636 /* =? has been checked */
2638 Fifo(mime_last++)='='; Fifo(mime_last++)='?';
2639 for(i=2;i<MAXRECOVER;i++) { /* start at =? */
2640 /* We accept any character type even if it is breaked by new lines */
2641 c1 = (*i_getc)(f); Fifo(mime_last++)= c1 ;
2642 if (c1=='\n'||c1==' '||c1=='\r'||
2643 c1=='-'||c1=='_'||is_alnum(c1) ) continue;
2645 /* Failed. But this could be another MIME preemble */
2653 c1 = (*i_getc)(f); Fifo(mime_last++) = c1;
2654 if (!(++i<MAXRECOVER) || c1==EOF) break;
2655 if (c1=='b'||c1=='B') {
2656 mime_decode_mode = 'B';
2657 } else if (c1=='q'||c1=='Q') {
2658 mime_decode_mode = 'Q';
2662 c1 = (*i_getc)(f); Fifo(mime_last++) = c1;
2663 if (!(++i<MAXRECOVER) || c1==EOF) break;
2665 mime_decode_mode = FALSE;
2671 if (!mime_decode_mode) {
2672 /* false MIME premble, restart from mime_buffer */
2673 mime_decode_mode = 1; /* no decode, but read from the mime_buffer */
2674 /* Since we are in MIME mode until buffer becomes empty, */
2675 /* we never go into mime_begin again for a while. */
2678 /* discard mime preemble, and goto MIME mode */
2680 /* do no MIME integrity check */
2681 return c1; /* used only for checking EOF */
2701 #ifdef CAP_URL_OPTION
2706 if (isdigit(x)) return x - '0';
2707 return nkf_toupper(x) - 'A' + 10;
2710 #ifdef ANSI_C_PROTOTYPE
2711 int hex_getc(int ch, FILE *f, int (*g)(FILE *f), int (*u)(int c, FILE *f))
2714 hex_getc(ch, f, g, u)
2727 if (!isxdigit(c2) == EOF){
2732 if (!isxdigit(c3) == EOF){
2737 return (hex2bin(c2) << 4) | hex2bin(c3);
2744 return hex_getc(':', f, i_cgetc, i_cungetc);
2752 return (*i_cungetc)(c, f);
2759 return hex_getc('%', f, i_ugetc, i_uungetc);
2767 return (*i_uungetc)(c, f);
2776 int c1, c2, c3, c4, cc;
2777 int t1, t2, t3, t4, mode, exit_mode;
2779 if (mime_top != mime_last) { /* Something is in FIFO */
2780 return Fifo(mime_top++);
2782 if (mime_decode_mode==1 ||mime_decode_mode==FALSE) {
2783 mime_decode_mode=FALSE;
2784 unswitch_mime_getc();
2785 return (*i_getc)(f);
2788 if (mimebuf_f == FIXED_MIME)
2789 exit_mode = mime_decode_mode;
2792 if (mime_decode_mode == 'Q') {
2793 if ((c1 = (*i_mgetc)(f)) == EOF) return (EOF);
2795 if (c1=='_') return ' ';
2796 if (c1!='=' && c1!='?') {
2800 mime_decode_mode = exit_mode; /* prepare for quit */
2801 if (c1<=' ') return c1;
2802 if ((c2 = (*i_mgetc)(f)) == EOF) return (EOF);
2803 if (c1=='?'&&c2=='=' && mimebuf_f != FIXED_MIME) {
2804 /* end Q encoding */
2805 input_mode = exit_mode;
2806 while((c1=(*i_getc)(f))!=EOF && c1==SPACE
2807 /* && (c1==NL||c1==TAB||c1=='\r') */ ) ;
2810 if (c1=='='&&c2<' ') { /* this is soft wrap */
2811 while((c1 = (*i_mgetc)(f)) <=' ') {
2812 if ((c1 = (*i_mgetc)(f)) == EOF) return (EOF);
2814 mime_decode_mode = 'Q'; /* still in MIME */
2815 goto restart_mime_q;
2818 mime_decode_mode = 'Q'; /* still in MIME */
2822 if ((c3 = (*i_mgetc)(f)) == EOF) return (EOF);
2823 if (c2<=' ') return c2;
2824 mime_decode_mode = 'Q'; /* still in MIME */
2825 #define hex(c) (('0'<=c&&c<='9')?(c-'0'):\
2826 ('A'<=c&&c<='F')?(c-'A'+10):('a'<=c&&c<='f')?(c-'a'+10):0)
2827 return ((hex(c2)<<4) + hex(c3));
2830 if (mime_decode_mode != 'B') {
2831 mime_decode_mode = FALSE;
2832 return (*i_mgetc)(f);
2836 /* Base64 encoding */
2838 MIME allows line break in the middle of
2839 Base64, but we are very pessimistic in decoding
2840 in unbuf mode because MIME encoded code may broken by
2841 less or editor's control sequence (such as ESC-[-K in unbuffered
2842 mode. ignore incomplete MIME.
2844 mode = mime_decode_mode;
2845 mime_decode_mode = exit_mode; /* prepare for quit */
2847 while ((c1 = (*i_mgetc)(f))<=' ') {
2852 if ((c2 = (*i_mgetc)(f))<=' ') {
2855 if (mime_f != STRICT_MIME) goto mime_c2_retry;
2856 if (mimebuf_f!=FIXED_MIME) input_mode = ASCII;
2859 if ((c1 == '?') && (c2 == '=')) {
2861 while((c1=(*i_getc)(f))!=EOF && c1==SPACE
2862 /* && (c1==NL||c1==TAB||c1=='\r') */ ) ;
2866 if ((c3 = (*i_mgetc)(f))<=' ') {
2869 if (mime_f != STRICT_MIME) goto mime_c3_retry;
2870 if (mimebuf_f!=FIXED_MIME) input_mode = ASCII;
2874 if ((c4 = (*i_mgetc)(f))<=' ') {
2877 if (mime_f != STRICT_MIME) goto mime_c4_retry;
2878 if (mimebuf_f!=FIXED_MIME) input_mode = ASCII;
2882 mime_decode_mode = mode; /* still in MIME sigh... */
2884 /* BASE 64 decoding */
2886 t1 = 0x3f & base64decode(c1);
2887 t2 = 0x3f & base64decode(c2);
2888 t3 = 0x3f & base64decode(c3);
2889 t4 = 0x3f & base64decode(c4);
2890 cc = ((t1 << 2) & 0x0fc) | ((t2 >> 4) & 0x03);
2892 Fifo(mime_last++) = cc;
2893 cc = ((t2 << 4) & 0x0f0) | ((t3 >> 2) & 0x0f);
2895 Fifo(mime_last++) = cc;
2896 cc = ((t3 << 6) & 0x0c0) | (t4 & 0x3f);
2898 Fifo(mime_last++) = cc;
2903 return Fifo(mime_top++);
2911 Fifo(--mime_top) = c;
2922 /* In buffered mode, read until =? or NL or buffer full
2924 mime_input = mime_top;
2925 mime_last = mime_top;
2926 while(*p) Fifo(mime_input++) = *p++;
2929 while((c=(*i_getc)(f))!=EOF) {
2930 if (((mime_input-mime_top)&MIME_BUF_MASK)==0) {
2931 break; /* buffer full */
2933 if (c=='=' && d=='?') {
2934 /* checked. skip header, start decode */
2935 Fifo(mime_input++) = c;
2936 /* mime_last_input = mime_input; */
2941 if (!( (c=='+'||c=='/'|| c=='=' || c=='?' || is_alnum(c))))
2943 /* Should we check length mod 4? */
2944 Fifo(mime_input++) = c;
2947 /* In case of Incomplete MIME, no MIME decode */
2948 Fifo(mime_input++) = c;
2949 mime_last = mime_input; /* point undecoded buffer */
2950 mime_decode_mode = 1; /* no decode on Fifo last in mime_getc */
2951 switch_mime_getc(); /* anyway we need buffered getc */
2962 i = c - 'A'; /* A..Z 0-25 */
2964 i = c - 'G' /* - 'a' + 26 */ ; /* a..z 26-51 */
2966 } else if (c > '/') {
2967 i = c - '0' + '4' /* - '0' + 52 */ ; /* 0..9 52-61 */
2968 } else if (c == '+') {
2969 i = '>' /* 62 */ ; /* + 62 */
2971 i = '?' /* 63 */ ; /* / 63 */
2976 static char basis_64[] =
2977 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2987 p = mime_pattern[0];
2988 for(i=0;mime_encode[i];i++) {
2989 if (mode == mime_encode[i]) {
2990 p = mime_pattern[i];
2994 mimeout_mode = mime_encode_method[i];
2996 /* (*o_mputc)(' '); */
3013 #define itoh4(c) (c>=10?c+'A'-10:c+'0')
3019 if (mimeout_f==FIXED_MIME) {
3020 if (base64_count>71) {
3028 if ( c<=DEL &&(output_mode==ASCII ||output_mode == ISO8859_1 )
3029 && mimeout_f!=FIXED_MIME) {
3030 if (mimeout_mode=='Q') {
3037 if (mimeout_mode!='B' || c!=SPACE) {
3046 } else if (!mimeout_mode && mimeout_f!=FIXED_MIME) {
3047 open_mime(output_mode);
3049 } else { /* c==EOF */
3050 switch(mimeout_mode) {
3055 (*o_mputc)(basis_64[((b64c & 0x3)<< 4)]);
3061 (*o_mputc)(basis_64[((b64c & 0xF) << 2)]);
3067 if (mimeout_f!=FIXED_MIME) {
3069 } else if (mimeout_mode != 'Q')
3074 switch(mimeout_mode) {
3078 (*o_mputc)(itoh4(((c>>4)&0xf)));
3079 (*o_mputc)(itoh4((c&0xf)));
3086 (*o_mputc)(basis_64[c>>2]);
3091 (*o_mputc)(basis_64[((b64c & 0x3)<< 4) | ((c & 0xF0) >> 4)]);
3097 (*o_mputc)(basis_64[((b64c & 0xF) << 2) | ((c & 0xC0) >>6)]);
3098 (*o_mputc)(basis_64[c & 0x3F]);
3118 mime_f = STRICT_MIME;
3122 #if defined(MSDOS) || defined(__OS2__)
3127 iso2022jp_f = FALSE;
3129 kanji_intro = DEFAULT_J;
3130 ascii_intro = DEFAULT_R;
3132 output_conv = DEFAULT_CONV;
3133 oconv = DEFAULT_CONV;
3136 i_mungetc = std_ungetc;
3137 i_mgetc_buf = std_getc;
3138 i_mungetc_buf = std_ungetc;
3141 i_ungetc=std_ungetc;
3144 i_bungetc= std_ungetc;
3148 o_crconv = no_connection;
3149 o_rot_conv = no_connection;
3150 o_iso2022jp_check_conv = no_connection;
3151 o_hira_conv = no_connection;
3152 o_fconv = no_connection;
3153 o_zconv = no_connection;
3156 i_ungetc = std_ungetc;
3158 i_mungetc = std_ungetc;
3160 output_mode = ASCII;
3163 mime_decode_mode = FALSE;
3173 #ifdef UTF8_INPUT_ENABLE
3178 #ifdef UTF8_OUTPUT_ENABLE
3179 if (w_oconv16_begin_f) {
3180 w_oconv16_begin_f = 2;
3185 fold_preserve_f = FALSE;
3188 fold_margin = FOLD_MARGIN;
3191 z_prev2=0,z_prev1=0;
3197 no_connection(c2,c1)
3200 no_connection2(c2,c1,0);
3204 no_connection2(c2,c1,c0)
3207 fprintf(stderr,"nkf internal module connection failure.\n");
3215 fprintf(stderr,"USAGE: nkf(nkf32,wnkf,nkf2) -[flags] [in file] .. [out file for -O flag]\n");
3216 fprintf(stderr,"Flags:\n");
3217 fprintf(stderr,"b,u Output is bufferred (DEFAULT),Output is unbufferred\n");
3218 #ifdef DEFAULT_CODE_SJIS
3219 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit, Shift JIS (DEFAULT), AT&T JIS (EUC), UTF-8\n");
3221 #ifdef DEFAULT_CODE_JIS
3222 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit (DEFAULT), Shift JIS, AT&T JIS (EUC), UTF-8\n");
3224 #ifdef DEFAULT_CODE_EUC
3225 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit, Shift JIS, AT&T JIS (EUC) (DEFAULT), UTF-8\n");
3227 #ifdef DEFAULT_CODE_UTF8
3228 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit, Shift JIS, AT&T JIS (EUC), UTF-8 (DEFAULT)\n");
3230 fprintf(stderr,"J,S,E,W Input assumption is JIS 7 bit , Shift JIS, AT&T JIS (EUC), UTF-8\n");
3231 fprintf(stderr,"t no conversion\n");
3232 fprintf(stderr,"i_/o_ Output sequence to designate JIS-kanji/ASCII (DEFAULT B)\n");
3233 fprintf(stderr,"r {de/en}crypt ROT13/47\n");
3234 fprintf(stderr,"h 1 hirakana->katakana, 2 katakana->hirakana,3 both\n");
3235 fprintf(stderr,"v Show this usage. V: show version\n");
3236 fprintf(stderr,"m[BQN0] MIME decode [B:base64,Q:quoted,N:non-strict,0:no decode]\n");
3237 fprintf(stderr,"M[BQ] MIME encode [B:base64 Q:quoted]\n");
3238 fprintf(stderr,"l ISO8859-1 (Latin-1) support\n");
3239 fprintf(stderr,"f/F Folding: -f60 or -f or -f60-10 (fold margin 10) F preserve nl\n");
3240 fprintf(stderr,"Z[0-3] Convert X0208 alphabet to ASCII 1: Kankaku to space,2: 2 spaces,\n");
3241 fprintf(stderr," 3: Convert HTML Entity\n");
3242 fprintf(stderr,"X,x Assume X0201 kana in MS-Kanji, -x preserves X0201\n");
3243 fprintf(stderr,"B[0-2] Broken input 0: missing ESC,1: any X on ESC-[($]-X,2: ASCII on NL\n");
3245 fprintf(stderr,"T Text mode output\n");
3247 fprintf(stderr,"O Output to File (DEFAULT 'nkf.out')\n");
3248 fprintf(stderr,"d,c Delete \\r in line feed and \\032, Add \\r in line feed\n");
3249 fprintf(stderr,"I Convert non ISO-2022-JP charactor to GETA\n");
3250 fprintf(stderr,"-L[uwm] line mode u:LF w:CRLF m:CR (DEFAULT noconversion)\n");
3251 fprintf(stderr,"long name options\n");
3252 fprintf(stderr," --fj,--unix,--mac,--windows convert for the system\n");
3253 fprintf(stderr," --jis,--euc,--sjis,--utf8,--utf16,--mime,--base64 convert for the code\n");
3254 fprintf(stderr," --help,--version\n");
3261 fprintf(stderr,"Network Kanji Filter Version %s (%s) "
3262 #if defined(MSDOS) && !defined(_Windows)
3265 #if !defined(__WIN32__) && defined(_Windows)
3268 #if defined(__WIN32__) && defined(_Windows)
3274 ,Version,Patchlevel);
3275 fprintf(stderr,"\n%s\n",CopyRight);
3280 **
\e$B%Q%C%A@):n<T
\e(B
3281 ** void@merope.pleiades.or.jp (Kusakabe Youichi)
3282 ** NIDE Naoyuki <nide@ics.nara-wu.ac.jp>
3283 ** ohta@src.ricoh.co.jp (Junn Ohta)
3284 ** inouet@strl.nhk.or.jp (Tomoyuki Inoue)
3285 ** kiri@pulser.win.or.jp (Tetsuaki Kiriyama)
3286 ** Kimihiko Sato <sato@sail.t.u-tokyo.ac.jp>
3287 ** a_kuroe@kuroe.aoba.yokohama.jp (Akihiko Kuroe)
3288 ** kono@ie.u-ryukyu.ac.jp (Shinji Kono)
3289 ** GHG00637@nifty-serve.or.jp (COW)
3291 **
\e$B:G=*99?7F|
\e(B