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 ** OW Overwrite rewrite original file by converted result
92 ** d Delete \r in line feed
93 ** c Add \r in line feed
94 ** -- other long option
95 ** -- ignore following option (don't use with -O )
99 /******************************/
100 /*
\e$B%G%U%)%k%H$N=PNO%3!<%IA*Br
\e(B */
101 /* Select DEFAULT_CODE */
102 #define DEFAULT_CODE_JIS
103 /* #define DEFAULT_CODE_SJIS */
104 /* #define DEFAULT_CODE_EUC */
105 /* #define DEFAULT_CODE_UTF8 */
106 /******************************/
108 #if (defined(__TURBOC__) || defined(LSI_C)) && !defined(MSDOS)
124 #if defined(MSDOS) || defined(__OS2__)
131 #define setbinmode(fp) fsetbin(fp)
132 #else /* Microsoft C, Turbo C */
133 #define setbinmode(fp) setmode(fileno(fp), O_BINARY)
135 #else /* UNIX,OS/2 */
136 #define setbinmode(fp)
139 #ifdef _IOFBF /* SysV and MSDOS */
140 #define setvbuffer(fp, buf, size) setvbuf(fp, buf, _IOFBF, size)
142 #define setvbuffer(fp, buf, size) setbuffer(fp, buf, size)
145 /*Borland C++ 4.5 EasyWin*/
146 #if defined(__TURBOC__) && defined(_Windows) && !defined(__WIN32__) /*Easy Win */
152 /* added by satoru@isoternet.org */
153 #include <sys/stat.h>
163 /* state of output_mode and input_mode
180 /* Input Assumption */
184 #define LATIN1_INPUT 6
186 #define STRICT_MIME 8
191 #define JAPANESE_EUC 10
195 #define UTF8_INPUT 13
196 #define UTF16_INPUT 14
197 #define UTF16BE_INPUT 15
215 #define is_alnum(c) \
216 (('a'<=c && c<='z')||('A'<= c && c<='Z')||('0'<=c && c<='9'))
218 #define HOLD_SIZE 1024
219 #define IOBUF_SIZE 16384
221 #define DEFAULT_J 'B'
222 #define DEFAULT_R 'B'
224 #define SJ0162 0x00e1 /* 01 - 62 ku offset */
225 #define SJ6394 0x0161 /* 63 - 94 ku offset */
227 #define RANGE_NUM_MAX 18
232 #if defined( UTF8_OUTPUT_ENABLE ) || defined( UTF8_INPUT_ENABLE )
233 #define sizeof_euc_utf8 94
234 #define sizeof_euc_to_utf8_1byte 94
235 #define sizeof_euc_to_utf8_2bytes 94
236 #define sizeof_utf8_to_euc_C2 94
237 #define sizeof_utf8_to_euc_E5B8 64
238 #define sizeof_utf8_to_euc_2bytes 112
239 #define sizeof_utf8_to_euc_3bytes 112
242 /* MIME preprocessor */
245 #ifdef EASYWIN /*Easy Win */
246 extern POINT _BufferSize;
249 /* function prototype */
251 /* #define PROTO(x) () */
253 static int noconvert PROTO((FILE *f));
254 static int kanji_convert PROTO((FILE *f));
255 static int h_conv PROTO((FILE *f,int c2,int c1));
256 static int push_hold_buf PROTO((int c2));
257 static void set_iconv PROTO((int f, int (*iconv_func)()));
258 static int s_iconv PROTO((int c2,int c1,int c0));
259 static int e_iconv PROTO((int c2,int c1,int c0));
260 #ifdef UTF8_INPUT_ENABLE
261 static int w_iconv PROTO((int c2,int c1,int c0));
262 static int w_iconv16 PROTO((int c2,int c1,int c0));
263 static int w_iconv_common PROTO((int c2,int c1,int c0,unsigned short **pp));
265 #ifdef UTF8_OUTPUT_ENABLE
266 static int e2w_conv PROTO((int c2,int c1));
267 static void w_oconv PROTO((int c2,int c1));
268 static void w_oconv16 PROTO((int c2,int c1));
270 static void e_oconv PROTO((int c2,int c1));
271 static void s_oconv PROTO((int c2,int c1));
272 static void j_oconv PROTO((int c2,int c1));
273 static void fold_conv PROTO((int c2,int c1));
274 static void cr_conv PROTO((int c2,int c1));
275 static void z_conv PROTO((int c2,int c1));
276 static void rot_conv PROTO((int c2,int c1));
277 static void hira_conv PROTO((int c2,int c1));
278 static void base64_conv PROTO((int c2,int c1));
279 static void iso2022jp_check_conv PROTO((int c2,int c1));
280 static void no_connection PROTO((int c2,int c1));
281 static int no_connection2 PROTO((int c2,int c1,int c0));
283 static void code_status PROTO((int c));
285 static void std_putc PROTO((int c));
286 static int std_getc PROTO((FILE *f));
287 static int std_ungetc PROTO((int c,FILE *f));
289 static int broken_getc PROTO((FILE *f));
290 static int broken_ungetc PROTO((int c,FILE *f));
292 static int mime_begin PROTO((FILE *f));
293 static int mime_getc PROTO((FILE *f));
294 static int mime_ungetc PROTO((int c,FILE *f));
296 static int mime_begin_strict PROTO((FILE *f));
297 static int mime_getc_buf PROTO((FILE *f));
298 static int mime_ungetc_buf PROTO((int c,FILE *f));
299 static int mime_integrity PROTO((FILE *f,unsigned char *p));
301 static int base64decode PROTO((int c));
302 static void mime_putc PROTO((int c));
303 static void open_mime PROTO((int c));
304 static void close_mime PROTO(());
305 static void usage PROTO(());
306 static void version PROTO(());
307 static void options PROTO((unsigned char *c));
309 static void reinit PROTO(());
314 static unsigned char stdibuf[IOBUF_SIZE];
315 static unsigned char stdobuf[IOBUF_SIZE];
316 static unsigned char hold_buf[HOLD_SIZE*2];
317 static int hold_count;
319 /* MIME preprocessor fifo */
321 #define MIME_BUF_SIZE (1024) /* 2^n ring buffer */
322 #define MIME_BUF_MASK (MIME_BUF_SIZE-1)
323 #define Fifo(n) mime_buf[(n)&MIME_BUF_MASK]
324 static unsigned char mime_buf[MIME_BUF_SIZE];
325 static unsigned int mime_top = 0;
326 static unsigned int mime_last = 0; /* decoded */
327 static unsigned int mime_input = 0; /* undecoded */
330 static int unbuf_f = FALSE;
331 static int estab_f = FALSE;
332 static int nop_f = FALSE;
333 static int binmode_f = TRUE; /* binary mode */
334 static int rot_f = FALSE; /* rot14/43 mode */
335 static int hira_f = FALSE; /* hira/kata henkan */
336 static int input_f = FALSE; /* non fixed input code */
337 static int alpha_f = FALSE; /* convert JIx0208 alphbet to ASCII */
338 static int mime_f = STRICT_MIME; /* convert MIME B base64 or Q */
339 static int mimebuf_f = FALSE; /* MIME buffered input */
340 static int broken_f = FALSE; /* convert ESC-less broken JIS */
341 static int iso8859_f = FALSE; /* ISO8859 through */
342 static int mimeout_f = FALSE; /* base64 mode */
343 #if defined(MSDOS) || defined(__OS2__)
344 static int x0201_f = TRUE; /* Assume JISX0201 kana */
346 static int x0201_f = NO_X0201; /* Assume NO JISX0201 */
348 static int iso2022jp_f = FALSE; /* convert ISO-2022-JP */
349 #ifdef UTF8_OUTPUT_ENABLE
350 static int w_oconv16_begin_f= 0; /* utf-16 header */
354 #ifdef CAP_URL_OPTION
355 static int cap_f = FALSE;
356 static int (*i_cgetc)PROTO((FILE *)) = std_getc; /* input of cgetc */
357 static int (*i_cungetc)PROTO((int c ,FILE *f)) = std_ungetc;
358 static int cap_getc PROTO((FILE *f));
359 static int cap_ungetc PROTO((int c,FILE *f));
361 static int url_f = FALSE;
362 static int (*i_ugetc)PROTO((FILE *)) = std_getc; /* input of ugetc */
363 static int (*i_uungetc)PROTO((int c ,FILE *f)) = std_ungetc;
364 static int url_getc PROTO((FILE *f));
365 static int url_ungetc PROTO((int c,FILE *f));
369 static int noout_f = FALSE;
370 static void no_putc PROTO((int c));
371 static int debug_f = FALSE;
372 static void debug PROTO((char *str));
375 static int e_stat = 0;
376 static int s_stat = 0;
377 #ifdef UTF8_INPUT_ENABLE
378 static int w_stat = 0;
379 static int utf16_mode = UTF16_INPUT;
381 static int w_stat = -1;
384 static int mimeout_mode = 0;
385 static int base64_count = 0;
387 /* X0208 -> ASCII converter */
390 static int f_line = 0; /* chars in line */
391 static int f_prev = 0;
392 static int fold_preserve_f = FALSE; /* preserve new lines */
393 static int fold_f = FALSE;
394 static int fold_len = 0;
397 static unsigned char kanji_intro = DEFAULT_J,
398 ascii_intro = DEFAULT_R;
402 #define FOLD_MARGIN 10
403 #define DEFAULT_FOLD 60
405 static int fold_margin = FOLD_MARGIN;
409 #ifdef DEFAULT_CODE_JIS
410 # define DEFAULT_CONV j_oconv
412 #ifdef DEFAULT_CODE_SJIS
413 # define DEFAULT_CONV s_oconv
415 #ifdef DEFAULT_CODE_EUC
416 # define DEFAULT_CONV e_oconv
418 #ifdef DEFAULT_CODE_UTF8
419 # define DEFAULT_CONV w_oconv
422 /* process default */
423 static void (*output_conv)PROTO((int c2,int c1)) = DEFAULT_CONV;
425 static void (*oconv)PROTO((int c2,int c1)) = no_connection;
426 /* s_iconv or oconv */
427 static int (*iconv)PROTO((int c2,int c1,int c0)) = no_connection2;
429 static void (*o_zconv)PROTO((int c2,int c1)) = no_connection;
430 static void (*o_fconv)PROTO((int c2,int c1)) = no_connection;
431 static void (*o_crconv)PROTO((int c2,int c1)) = no_connection;
432 static void (*o_rot_conv)PROTO((int c2,int c1)) = no_connection;
433 static void (*o_hira_conv)PROTO((int c2,int c1)) = no_connection;
434 static void (*o_base64conv)PROTO((int c2,int c1)) = no_connection;
435 static void (*o_iso2022jp_check_conv)PROTO((int c2,int c1)) = no_connection;
437 /* static redirections */
439 static void (*o_putc)PROTO((int c)) = std_putc;
441 static int (*i_getc)PROTO((FILE *f)) = std_getc; /* general input */
442 static int (*i_ungetc)PROTO((int c,FILE *f)) =std_ungetc;
444 static int (*i_bgetc)PROTO((FILE *)) = std_getc; /* input of mgetc */
445 static int (*i_bungetc)PROTO((int c ,FILE *f)) = std_ungetc;
447 static void (*o_mputc)PROTO((int c)) = std_putc ; /* output of mputc */
449 static int (*i_mgetc)PROTO((FILE *)) = std_getc; /* input of mgetc */
450 static int (*i_mungetc)PROTO((int c ,FILE *f)) = std_ungetc;
452 /* for strict mime */
453 static int (*i_mgetc_buf)PROTO((FILE *)) = std_getc; /* input of mgetc_buf */
454 static int (*i_mungetc_buf)PROTO((int c,FILE *f)) = std_ungetc;
457 static int output_mode = ASCII, /* output kanji mode */
458 input_mode = ASCII, /* input kanji mode */
459 shift_mode = FALSE; /* TRUE shift out, or X0201 */
460 static int mime_decode_mode = FALSE; /* MIME mode B base64, Q hex */
462 /* X0201 / X0208 conversion tables */
464 /* X0201 kana conversion table */
467 unsigned char cv[]= {
468 0x21,0x21,0x21,0x23,0x21,0x56,0x21,0x57,
469 0x21,0x22,0x21,0x26,0x25,0x72,0x25,0x21,
470 0x25,0x23,0x25,0x25,0x25,0x27,0x25,0x29,
471 0x25,0x63,0x25,0x65,0x25,0x67,0x25,0x43,
472 0x21,0x3c,0x25,0x22,0x25,0x24,0x25,0x26,
473 0x25,0x28,0x25,0x2a,0x25,0x2b,0x25,0x2d,
474 0x25,0x2f,0x25,0x31,0x25,0x33,0x25,0x35,
475 0x25,0x37,0x25,0x39,0x25,0x3b,0x25,0x3d,
476 0x25,0x3f,0x25,0x41,0x25,0x44,0x25,0x46,
477 0x25,0x48,0x25,0x4a,0x25,0x4b,0x25,0x4c,
478 0x25,0x4d,0x25,0x4e,0x25,0x4f,0x25,0x52,
479 0x25,0x55,0x25,0x58,0x25,0x5b,0x25,0x5e,
480 0x25,0x5f,0x25,0x60,0x25,0x61,0x25,0x62,
481 0x25,0x64,0x25,0x66,0x25,0x68,0x25,0x69,
482 0x25,0x6a,0x25,0x6b,0x25,0x6c,0x25,0x6d,
483 0x25,0x6f,0x25,0x73,0x21,0x2b,0x21,0x2c,
487 /* X0201 kana conversion table for daguten */
490 unsigned char dv[]= {
491 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
492 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
493 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
494 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
495 0x00,0x00,0x00,0x00,0x00,0x00,0x25,0x74,
496 0x00,0x00,0x00,0x00,0x25,0x2c,0x25,0x2e,
497 0x25,0x30,0x25,0x32,0x25,0x34,0x25,0x36,
498 0x25,0x38,0x25,0x3a,0x25,0x3c,0x25,0x3e,
499 0x25,0x40,0x25,0x42,0x25,0x45,0x25,0x47,
500 0x25,0x49,0x00,0x00,0x00,0x00,0x00,0x00,
501 0x00,0x00,0x00,0x00,0x25,0x50,0x25,0x53,
502 0x25,0x56,0x25,0x59,0x25,0x5c,0x00,0x00,
503 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
504 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
505 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
506 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
509 /* X0201 kana conversion table for han-daguten */
512 unsigned char ev[]= {
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,0x00,0x00,0x00,0x00,
521 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
522 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
523 0x00,0x00,0x00,0x00,0x25,0x51,0x25,0x54,
524 0x25,0x57,0x25,0x5a,0x25,0x5d,0x00,0x00,
525 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
526 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
527 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
528 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
532 /* X0208 kigou conversion table */
533 /* 0x8140 - 0x819e */
535 unsigned char fv[] = {
537 0x00,0x00,0x00,0x00,0x2c,0x2e,0x00,0x3a,
538 0x3b,0x3f,0x21,0x00,0x00,0x27,0x60,0x00,
539 0x5e,0x00,0x5f,0x00,0x00,0x00,0x00,0x00,
540 0x00,0x00,0x00,0x00,0x00,0x2d,0x00,0x2f,
541 0x5c,0x00,0x00,0x7c,0x00,0x00,0x60,0x27,
542 0x22,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,
543 0x7b,0x7d,0x3c,0x3e,0x00,0x00,0x00,0x00,
544 0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,
545 0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,
546 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
547 0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40,
548 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
554 static int file_out = FALSE;
556 static int overwrite = FALSE;
559 static int crmode_f = 0; /* CR, NL, CRLF */
560 #ifdef EASYWIN /*Easy Win */
561 static int end_check;
573 #ifdef EASYWIN /*Easy Win */
574 _BufferSize.y = 400;/*Set Scroll Buffer Size*/
577 for (argc--,argv++; (argc > 0) && **argv == '-'; argc--, argv++) {
581 if(x0201_f == WISH_TRUE)
582 x0201_f = ((!iso2022jp_f)? TRUE : NO_X0201);
584 if (binmode_f == TRUE)
586 if (freopen("","wb",stdout) == NULL)
593 setbuf(stdout, (char *) NULL);
595 setvbuffer(stdout, stdobuf, IOBUF_SIZE);
598 if (binmode_f == TRUE)
600 if (freopen("","rb",stdin) == NULL) return (-1);
604 setvbuffer(stdin, stdibuf, IOBUF_SIZE);
608 kanji_convert(stdin);
614 if ((fin = fopen((origfname = *argv++), "r")) == NULL) {
623 /* reopen file for stdout */
624 if (file_out == TRUE) {
627 outfname = malloc(strlen(origfname)
628 + strlen(".nkftmpXXXXXX")
634 strcpy(outfname, origfname);
638 for (i = strlen(outfname); i; --i){
639 if (outfname[i - 1] == '/'
640 || outfname[i - 1] == '\\'){
646 strcat(outfname, "ntXXXXXX");
648 fd = open(outfname, O_WRONLY | O_CREAT | O_TRUNC,
651 strcat(outfname, ".nkftmpXXXXXX");
652 fd = mkstemp(outfname);
655 || (fd_backup = dup(fileno(stdout))) < 0
656 || dup2(fd, fileno(stdout)) < 0
667 outfname = "nkf.out";
670 if(freopen(outfname, "w", stdout) == NULL) {
674 if (binmode_f == TRUE) {
676 if (freopen("","wb",stdout) == NULL)
683 if (binmode_f == TRUE)
685 if (freopen("","rb",fin) == NULL)
690 setvbuffer(fin, stdibuf, IOBUF_SIZE);
707 if (dup2(fd_backup, fileno(stdout)) < 0){
710 if (stat(origfname, &sb)) {
711 fprintf(stderr, "Can't stat %s\n", origfname);
713 /*
\e$B%Q!<%_%C%7%g%s$rI|85
\e(B */
714 if (chmod(outfname, sb.st_mode)) {
715 fprintf(stderr, "Can't set permission %s\n", outfname);
718 tb[0] = tb[1] = sb.st_mtime;
719 /*
\e$B%?%$%`%9%?%s%W$rI|85
\e(B */
720 if (utime(outfname, tb)) {
721 fprintf(stderr, "Can't set timestamp %s\n", outfname);
724 if (unlink(origfname)){
728 tb.actime = sb.st_atime;
729 tb.modtime = sb.st_mtime;
730 /*
\e$B%?%$%`%9%?%s%W$rI|85
\e(B */
731 if (utime(outfname, &tb)) {
732 fprintf(stderr, "Can't set timestamp %s\n", outfname);
735 if (rename(outfname, origfname)) {
737 fprintf(stderr, "Can't rename %s to %s\n",
738 outfname, origfname);
746 #ifdef EASYWIN /*Easy Win */
747 if (file_out == FALSE)
748 scanf("%d",&end_check);
751 #else /* for Other OS */
752 if (file_out == TRUE)
762 unsigned char *alias;
782 {"katakana-hiragana","h3"},
783 #ifdef UTF8_OUTPUT_ENABLE
787 #ifdef UTF8_INPUT_ENABLE
789 {"utf16-input", "W16"},
791 #ifdef CAP_URL_OPTION
801 static int option_mode;
804 options(unsigned char *cp)
815 case '-': /* literal options */
816 if (!*cp) { /* ignore the rest of arguments */
820 for (i=0;i<sizeof(long_option)/sizeof(long_option[0]);i++) {
822 p = long_option[i].name;
823 for (j=0;*p && *p++ == cp[j];j++);
824 if (! *p && !cp[j]) break;
827 cp = long_option[i].alias;
829 #ifdef CAP_URL_OPTION
830 if (strcmp(long_option[i].name, "cap-input") == 0){
834 if (strcmp(long_option[i].name, "url-input") == 0){
840 if (strcmp(long_option[i].name, "no-output") == 0){
844 if (strcmp(long_option[i].name, "debug") == 0){
851 case 'b': /* buffered mode */
854 case 'u': /* non bufferd mode */
857 case 't': /* transparent mode */
860 case 'j': /* JIS output */
862 output_conv = j_oconv;
864 case 'e': /* AT&T EUC output */
865 output_conv = e_oconv;
867 case 's': /* SJIS output */
868 output_conv = s_oconv;
870 case 'l': /* ISO8859 Latin-1 support, no conversion */
871 iso8859_f = TRUE; /* Only compatible with ISO-2022-JP */
872 input_f = LATIN1_INPUT;
874 case 'i': /* Kanji IN ESC-$-@/B */
875 if (*cp=='@'||*cp=='B')
878 case 'o': /* ASCII IN ESC-(-J/B */
879 if (*cp=='J'||*cp=='B'||*cp=='H')
887 if ('9'>= *cp && *cp>='0')
888 hira_f |= (*cp++ -'0');
895 #if defined(MSDOS) || defined(__OS2__)
910 #ifdef UTF8_OUTPUT_ENABLE
911 case 'w': /* UTF-8 output */
912 if ('1'== cp[0] && '6'==cp[1]) {
913 output_conv = w_oconv16; cp+=2;
915 w_oconv16_begin_f=2; cp++;
918 output_conv = w_oconv;
921 #ifdef UTF8_INPUT_ENABLE
922 case 'W': /* UTF-8 input */
923 if ('1'== cp[0] && '6'==cp[1]) {
924 input_f = UTF16_INPUT;
926 input_f = UTF8_INPUT;
929 /* Input code assumption */
930 case 'J': /* JIS input */
931 case 'E': /* AT&T EUC input */
934 case 'S': /* MS Kanji input */
935 input_f = SJIS_INPUT;
936 if (x0201_f==NO_X0201) x0201_f=TRUE;
938 case 'Z': /* Convert X0208 alphabet to asii */
939 /* bit:0 Convert X0208
940 bit:1 Convert Kankaku to one space
941 bit:2 Convert Kankaku to two spaces
942 bit:3 Convert HTML Entity
944 if ('9'>= *cp && *cp>='0')
945 alpha_f |= 1<<(*cp++ -'0');
949 case 'x': /* Convert X0201 kana to X0208 or X0201 Conversion */
950 x0201_f = FALSE; /* No X0201->X0208 conversion */
952 ESC-(-I in JIS, EUC, MS Kanji
953 SI/SO in JIS, EUC, MS Kanji
954 SSO in EUC, JIS, not in MS Kanji
957 ESC-(-I in JIS (0x20-0x5f)
958 SSO in EUC (0xa0-0xdf)
959 0xa0-0xd in MS Kanji (0xa0-0xdf)
962 case 'X': /* Assume X0201 kana */
963 /* Default value is NO_X0201 for EUC/MS-Kanji mix */
966 case 'F': /* prserve new lines */
967 fold_preserve_f = TRUE;
968 case 'f': /* folding -f60 or -f */
971 while('0'<= *cp && *cp <='9') { /* we don't use atoi here */
973 fold_len += *cp++ - '0';
975 if (!(0<fold_len && fold_len<BUFSIZ))
976 fold_len = DEFAULT_FOLD;
980 while('0'<= *cp && *cp <='9') { /* we don't use atoi here */
982 fold_margin += *cp++ - '0';
986 case 'm': /* MIME support */
987 if (*cp=='B'||*cp=='Q') {
988 mime_decode_mode = *cp++;
989 mimebuf_f = FIXED_MIME;
990 } else if (*cp=='N') {
992 } else if (*cp=='S') {
993 mime_f = STRICT_MIME; cp++;
994 } else if (*cp=='0') {
998 case 'M': /* MIME output */
1001 mimeout_f = FIXED_MIME; cp++;
1002 } else if (*cp=='Q') {
1004 mimeout_f = FIXED_MIME; cp++;
1009 case 'B': /* Broken JIS support */
1011 bit:1 allow any x on ESC-(-x or ESC-$-x
1012 bit:2 reset to ascii on NL
1014 if ('9'>= *cp && *cp>='0')
1015 broken_f |= 1<<(*cp++ -'0');
1020 case 'O':/* for Output file */
1030 case 'c':/* add cr code */
1033 case 'd':/* delete cr code */
1036 case 'I': /* ISO-2022-JP output */
1039 case 'L': /* line mode */
1040 if (*cp=='u') { /* unix */
1042 } else if (*cp=='m') { /* mac */
1044 } else if (*cp=='w') { /* windows */
1046 } else if (*cp=='0') { /* no conversion */
1051 /* module muliple options in a string are allowed for Perl moudle */
1052 while(*cp && *cp!='-') cp++;
1056 /* bogus option but ignored */
1062 void set_iconv(int f, int (*iconv_func)(int c2,int c1,int c0)){
1064 static int (*iconv_for_check)() = 0;
1066 #ifdef INPUT_CODE_FIX
1074 #ifdef INPUT_CODE_FIX
1075 && (f == -TRUE || !input_f) /* -TRUE means "FORCE" */
1081 if (estab_f && iconv_for_check != iconv){
1082 #ifdef UTF8_INPUT_ENABLE
1083 if (iconv == w_iconv) debug("UTF-8\n");
1084 if (iconv == w_iconv16) debug("UTF-16\n");
1086 if (iconv == s_iconv) debug("Shift_JIS\n");
1087 if (iconv == e_iconv) debug("EUC-JP\n");
1088 iconv_for_check = iconv;
1093 void code_status(int c){
1096 if (c <= DEL && estab_f){
1102 || (0xa1 <= c && c <= 0xef && iconv == s_iconv)){
1104 }else if ((0x81 <= c && c < 0xa0) || (0xe0 <= c && c <= 0xea)){
1108 if (iconv == s_iconv) set_iconv(FALSE, 0);
1112 if ((0x40 <= c && c <= 0x7e) || (0x80 <= c && c <= 0xfd)){
1116 if (iconv == s_iconv) set_iconv(FALSE, 0);
1122 if (c <= DEL && estab_f){
1129 }else if (SSO == c || (0xa1 <= c && c <= 0xfe)){
1133 if (iconv == e_iconv) set_iconv(FALSE, 0);
1137 if (0xa1 <= c && c <= 0xfe){
1141 if (iconv == e_iconv) set_iconv(FALSE, 0);
1145 #ifdef UTF8_INPUT_ENABLE
1148 if (c <= DEL && estab_f){
1155 }else if (0xc0 <= c && c <= 0xdf){
1157 }else if (0xe0 <= c && c <= 0xef){
1161 if (iconv == w_iconv) set_iconv(FALSE, 0);
1166 if (0x80 <= c && c <= 0xbf){
1170 if (iconv == w_iconv) set_iconv(FALSE, 0);
1175 if (s_stat < 0 && e_stat < 0 && w_stat == 0){
1176 set_iconv(TRUE, w_iconv);
1179 if (s_stat == 0 && e_stat < 0 && w_stat < 0){
1180 set_iconv(TRUE, s_iconv);
1182 if (s_stat < 0 && e_stat == 0 && w_stat < 0){
1183 set_iconv(TRUE, e_iconv);
1185 if (s_stat < 0 && e_stat < 0 && w_stat < 0){
1187 s_stat = e_stat = 0;
1188 #ifdef UTF8_INPUT_ENABLE
1223 while ((c = (*i_getc)(f)) != EOF)
1232 oconv = output_conv;
1235 /* replace continucation module, from output side */
1237 /* output redicrection */
1246 if (mimeout_f == TRUE) {
1247 o_base64conv = oconv; oconv = base64_conv;
1249 /* base64_count = 0; */
1253 o_crconv = oconv; oconv = cr_conv;
1256 o_rot_conv = oconv; oconv = rot_conv;
1259 o_iso2022jp_check_conv = oconv; oconv = iso2022jp_check_conv;
1262 o_hira_conv = oconv; oconv = hira_conv;
1265 o_fconv = oconv; oconv = fold_conv;
1268 if (alpha_f || x0201_f) {
1269 o_zconv = oconv; oconv = z_conv;
1273 /* input redicrection */
1274 #ifdef CAP_URL_OPTION
1276 i_cgetc = i_getc; i_getc = cap_getc;
1277 i_cungetc = i_ungetc; i_ungetc= cap_ungetc;
1280 i_ugetc = i_getc; i_getc = url_getc;
1281 i_uungetc = i_ungetc; i_ungetc= url_ungetc;
1284 if (mime_f && mimebuf_f==FIXED_MIME) {
1285 i_mgetc = i_getc; i_getc = mime_getc;
1286 i_mungetc = i_ungetc; i_ungetc = mime_ungetc;
1289 i_bgetc = i_getc; i_getc = broken_getc;
1290 i_bungetc = i_ungetc; i_ungetc = broken_ungetc;
1292 if (input_f == JIS_INPUT || input_f == LATIN1_INPUT) {
1293 set_iconv(-TRUE, e_iconv);
1294 } else if (input_f == SJIS_INPUT) {
1295 set_iconv(-TRUE, s_iconv);
1296 #ifdef UTF8_INPUT_ENABLE
1297 } else if (input_f == UTF8_INPUT) {
1298 set_iconv(-TRUE, w_iconv);
1299 } else if (input_f == UTF16_INPUT) {
1300 set_iconv(-TRUE, w_iconv16);
1303 set_iconv(FALSE, e_iconv);
1308 #ifdef UTF8_INPUT_ENABLE
1316 Conversion main loop. Code detection only.
1326 module_connection();
1331 output_mode = ASCII;
1334 #define NEXT continue /* no output, get next */
1335 #define SEND ; /* output c1 and c2, get next */
1336 #define LAST break /* end of loop, go closing */
1338 while ((c1 = (*i_getc)(f)) != EOF) {
1343 /* in case of 8th bit is on */
1345 /* in case of not established yet */
1346 /* It is still ambiguious */
1347 if (h_conv(f, c2, c1)==EOF)
1353 /* in case of already established */
1355 /* ignore bogus code */
1361 /* second byte, 7 bit code */
1362 /* it might be kanji shitfted */
1363 if ((c1 == DEL) || (c1 <= SPACE)) {
1364 /* ignore bogus first code */
1371 if (iconv == w_iconv16) {
1375 } else if (c1 > DEL) {
1377 if (!estab_f && !iso8859_f) {
1378 /* not established yet */
1381 } else { /* estab_f==TRUE */
1386 } else if (SSP<=c1 && c1<0xe0 && iconv == s_iconv) {
1387 /* SJIS X0201 Case... */
1388 if(iso2022jp_f && x0201_f==NO_X0201) {
1389 (*oconv)(GETA1, GETA2);
1396 } else if (c1==SSO && iconv != s_iconv) {
1397 /* EUC X0201 Case */
1398 c1 = (*i_getc)(f); /* skip SSO */
1400 if (SSP<=c1 && c1<0xe0) {
1401 if(iso2022jp_f && x0201_f==NO_X0201) {
1402 (*oconv)(GETA1, GETA2);
1409 } else { /* bogus code, skip SSO and one byte */
1413 /* already established */
1418 } else if ((c1 > SPACE) && (c1 != DEL)) {
1419 /* in case of Roman characters */
1421 /* output 1 shifted byte */
1425 } else if (SPACE<=c1 && c1<(0xe0&0x7f) ){
1426 /* output 1 shifted byte */
1427 if(iso2022jp_f && x0201_f==NO_X0201) {
1428 (*oconv)(GETA1, GETA2);
1435 /* look like bogus code */
1438 } else if (input_mode == X0208) {
1439 /* in case of Kanji shifted */
1442 } else if (c1 == '=' && mime_f && !mime_decode_mode ) {
1443 /* Check MIME code */
1444 if ((c1 = (*i_getc)(f)) == EOF) {
1447 } else if (c1 == '?') {
1448 /* =? is mime conversion start sequence */
1449 if(mime_f == STRICT_MIME) {
1450 /* check in real detail */
1451 if (mime_begin_strict(f) == EOF)
1455 } else if (mime_begin(f) == EOF)
1465 /* normal ASCII code */
1468 } else if (c1 == SI) {
1471 } else if (c1 == SO) {
1474 } else if (c1 == ESC ) {
1475 if ((c1 = (*i_getc)(f)) == EOF) {
1476 /* (*oconv)(0, ESC); don't send bogus code */
1478 } else if (c1 == '$') {
1479 if ((c1 = (*i_getc)(f)) == EOF) {
1481 (*oconv)(0, ESC); don't send bogus code
1482 (*oconv)(0, '$'); */
1484 } else if (c1 == '@'|| c1 == 'B') {
1485 /* This is kanji introduction */
1489 } else if (c1 == '(') {
1490 if ((c1 = (*i_getc)(f)) == EOF) {
1491 /* don't send bogus code
1497 } else if (c1 == '@'|| c1 == 'B') {
1498 /* This is kanji introduction */
1503 /* could be some special code */
1510 } else if (broken_f&0x2) {
1511 /* accept any ESC-(-x as broken code ... */
1521 } else if (c1 == '(') {
1522 if ((c1 = (*i_getc)(f)) == EOF) {
1523 /* don't send bogus code
1525 (*oconv)(0, '('); */
1529 /* This is X0201 kana introduction */
1530 input_mode = X0201; shift_mode = X0201;
1532 } else if (c1 == 'B' || c1 == 'J' || c1 == 'H') {
1533 /* This is X0208 kanji introduction */
1534 input_mode = ASCII; shift_mode = FALSE;
1536 } else if (broken_f&0x2) {
1537 input_mode = ASCII; shift_mode = FALSE;
1542 /* maintain various input_mode here */
1546 } else if ( c1 == 'N' || c1 == 'n' ){
1548 c1 = (*i_getc)(f); /* skip SS2 */
1549 if ( SPACE<=c1 && c1 < 0xe0 ) {
1558 } else if ((c1 == NL || c1 == CR) && broken_f&4) {
1559 input_mode = ASCII; set_iconv(FALSE, 0);
1565 if (input_mode == X0208)
1566 (*oconv)(c2, c1); /* this is JIS, not SJIS/EUC case */
1567 else if (input_mode)
1568 (*oconv)(input_mode, c1); /* other special case */
1569 else if ((*iconv)(c2, c1, 0) < 0){ /* can be EUC/SJIS */
1570 int c0 = (*i_getc)(f);
1573 (*iconv)(c2, c1, c0);
1579 /* goto next_word */
1583 (*iconv)(EOF, 0, 0);
1596 /** it must NOT be in the kanji shifte sequence */
1597 /** it must NOT be written in JIS7 */
1598 /** and it must be after 2 byte 8bit code */
1605 while ((c1 = (*i_getc)(f)) != EOF) {
1611 if (push_hold_buf(c1) == EOF || estab_f){
1617 ** 1) EOF is detected, or
1618 ** 2) Code is established, or
1619 ** 3) Buffer is FULL (but last word is pushed)
1621 ** in 1) and 3) cases, we continue to use
1622 ** Kanji codes by oconv and leave estab_f unchanged.
1626 while (wc < hold_count){
1627 c2 = hold_buf[wc++];
1631 }else if (iconv == s_iconv && 0xa1 <= c2 && c2 <= 0xdf){
1632 (*iconv)(X0201, c2, 0);
1635 if (wc < hold_count){
1636 c1 = hold_buf[wc++];
1639 if (c1 == EOF) break;
1642 if ((*iconv)(c2, c1, 0) < 0){
1644 if (wc < hold_count){
1645 c0 = hold_buf[wc++];
1648 if (c0 == EOF) break;
1651 (*iconv)(c2, c1, c0);
1665 if (hold_count >= HOLD_SIZE*2)
1667 hold_buf[hold_count++] = c2;
1668 return ((hold_count >= HOLD_SIZE*2) ? EOF : hold_count);
1678 } else if ((c2 == EOF) || (c2 == 0) || c2 < SPACE) {
1681 c2 = c2 + c2 - ((c2 <= 0x9f) ? SJ0162 : SJ6394);
1683 c1 = c1 - ((c1 > DEL) ? SPACE : 0x1f);
1700 } else if ((c2 == EOF) || (c2 == 0) || c2 < SPACE) {
1710 #ifdef UTF8_INPUT_ENABLE
1715 extern unsigned short * utf8_to_euc_2bytes[];
1716 extern unsigned short ** utf8_to_euc_3bytes[];
1718 if (0xc0 <= c2 && c2 <= 0xef) {
1719 unsigned short **pp;
1722 if (c0 == 0) return -1;
1723 if (!(0<=c2-0x80 && c2-0x80 <sizeof_utf8_to_euc_3bytes)) return -1;
1724 pp = utf8_to_euc_3bytes[c2 - 0x80];
1726 pp = utf8_to_euc_2bytes;
1730 return w_iconv_common(c2, c1, c0,pp);
1731 } else if (c2 == X0201) {
1739 w_iconv16(c2, c1, c0)
1742 extern unsigned short * utf8_to_euc_2bytes[];
1743 extern unsigned short ** utf8_to_euc_3bytes[];
1744 unsigned short **pp;
1747 if (c2==0376 && c1==0377){
1748 utf16_mode = UTF16_INPUT;
1750 } else if (c2==0377 && c1==0376){
1751 utf16_mode = UTF16BE_INPUT;
1754 if (utf16_mode == UTF16BE_INPUT) {
1756 tmp=c1; c1=c2; c2=tmp;
1758 if (c2==0 || c2==EOF) {
1762 val = ((c2<<8)&0xff00) + c1;
1764 c0 = (0x80 | (c1 & 0x3f));
1765 c1 = (0xc0 | (val >> 6));
1766 pp = utf8_to_euc_2bytes;
1768 c0 = (0x80 | (c1 & 0x3f));
1769 c2 = (0xe0 | (val >> 12));
1770 c1 = (0x80 | ((val >> 6) & 0x3f));
1771 if (c0 == 0) return -1;
1772 if (0<=c2-0x80 && c2-0x80 <sizeof_utf8_to_euc_3bytes)
1773 pp = utf8_to_euc_3bytes[c2 - 0x80];
1777 return w_iconv_common(c2, c1, c0,pp);
1781 w_iconv_common(c2, c1, c0,pp)
1783 unsigned short **pp;
1788 if (pp == 0) return 1;
1789 if (!(0<=c1-0x80 && c1-0x80 <sizeof_utf8_to_euc_C2)) return -1;
1791 if (p == 0) return 1;
1792 if (!(0<=c0-0x80 && c0-0x80 <sizeof_utf8_to_euc_E5B8)) return -1;
1794 if (val ==0 ) return 1;
1796 if (c2 == SO) c2 = X0201;
1804 #ifdef UTF8_OUTPUT_ENABLE
1809 extern unsigned short euc_to_utf8_1byte[];
1810 extern unsigned short * euc_to_utf8_2bytes[];
1814 p = euc_to_utf8_1byte;
1817 c2 = (c2&0x7f) - 0x21;
1818 if (0<=c2 && c2<sizeof_euc_to_utf8_2bytes)
1819 p = euc_to_utf8_2bytes[c2];
1824 c1 = (c1 & 0x7f) - 0x21;
1825 if (0<=c1 && c1<sizeof_euc_to_utf8_1byte)
1836 } else if (c2 == 0) {
1837 output_mode = ASCII;
1839 } else if (c2 == ISO8859_1) {
1840 output_mode = ISO8859_1;
1841 (*o_putc)(c1 | 0x080);
1843 unsigned short val = (unsigned short)e2w_conv(c2, c1);
1846 if (0 < val && val < 0x80){
1848 }else if (val < 0x800){
1849 (*o_putc)(0xc0 | (val >> 6));
1850 (*o_putc)(0x80 | (val & 0x3f));
1852 (*o_putc)(0xe0 | (val >> 12));
1853 (*o_putc)(0x80 | ((val >> 6) & 0x3f));
1854 (*o_putc)(0x80 | (val & 0x3f));
1865 if (w_oconv16_begin_f==2) {
1868 w_oconv16_begin_f=1;
1872 } else if (c2 == 0) {
1875 } else if (c2 == ISO8859_1) {
1877 (*o_putc)(c1 | 0x080);
1879 unsigned short val = (unsigned short)e2w_conv(c2, c1);
1880 (*o_putc)((val&0xff00)>>8);
1881 (*o_putc)(val&0xff);
1894 } else if (c2 == 0) {
1895 output_mode = ASCII;
1897 } else if (c2 == X0201) {
1898 output_mode = JAPANESE_EUC;
1899 (*o_putc)(SSO); (*o_putc)(c1|0x80);
1900 } else if (c2 == ISO8859_1) {
1901 output_mode = ISO8859_1;
1902 (*o_putc)(c1 | 0x080);
1904 if ((c1<0x20 || 0x7e<c1) ||
1905 (c2<0x20 || 0x7e<c2)) {
1906 set_iconv(FALSE, 0);
1907 return; /* too late to rescue this char */
1909 output_mode = JAPANESE_EUC;
1910 (*o_putc)(c2 | 0x080);
1911 (*o_putc)(c1 | 0x080);
1924 } else if (c2 == 0) {
1925 output_mode = ASCII;
1927 } else if (c2 == X0201) {
1928 output_mode = SHIFT_JIS;
1930 } else if (c2 == ISO8859_1) {
1931 output_mode = ISO8859_1;
1932 (*o_putc)(c1 | 0x080);
1934 if ((c1<0x20 || 0x7e<c1) ||
1935 (c2<0x20 || 0x7e<c2)) {
1936 set_iconv(FALSE, 0);
1937 return; /* too late to rescue this char */
1939 output_mode = SHIFT_JIS;
1940 (*o_putc)((((c2 - 1) >> 1) + ((c2 <= 0x5e) ? 0x71 : 0xb1)));
1941 (*o_putc)((c1 + ((c2 & 1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e)));
1951 if (output_mode !=ASCII && output_mode!=ISO8859_1) {
1954 (*o_putc)(ascii_intro);
1955 output_mode = ASCII;
1957 } else if (c2==X0201) {
1958 if (output_mode!=X0201) {
1959 output_mode = X0201;
1965 } else if (c2==ISO8859_1) {
1966 /* iso8859 introduction, or 8th bit on */
1967 /* Can we convert in 7bit form using ESC-'-'-A ?
1969 output_mode = ISO8859_1;
1971 } else if (c2 == 0) {
1972 if (output_mode !=ASCII && output_mode!=ISO8859_1) {
1975 (*o_putc)(ascii_intro);
1976 output_mode = ASCII;
1980 if (output_mode != X0208) {
1981 output_mode = X0208;
1984 (*o_putc)(kanji_intro);
1986 if (c1<0x20 || 0x7e<c1)
1988 if (c2<0x20 || 0x7e<c2)
2000 if (base64_count>50 && !mimeout_mode && c2==0 && c1==SPACE) {
2002 } else if (base64_count>66 && mimeout_mode) {
2003 (*o_base64conv)(EOF,0);
2007 (*o_base64conv)(c2,c1);
2011 static int broken_buf[3];
2012 static int broken_counter = 0;
2013 static int broken_last = 0;
2020 if (broken_counter>0) {
2021 return broken_buf[--broken_counter];
2024 if (c=='$' && broken_last != ESC
2025 && (input_mode==ASCII || input_mode==X0201)) {
2028 if (c1=='@'|| c1=='B') {
2029 broken_buf[0]=c1; broken_buf[1]=c;
2036 } else if (c=='(' && broken_last != ESC
2037 && (input_mode==X0208 || input_mode==X0201)) { /* ) */
2040 if (c1=='J'|| c1=='B') {
2041 broken_buf[0]=c1; broken_buf[1]=c;
2059 if (broken_counter<2)
2060 broken_buf[broken_counter++]=c;
2064 static int prev_cr = 0;
2072 if (! (c2==0&&c1==NL) ) {
2078 } else if (c1=='\r') {
2080 } else if (c1=='\n') {
2081 if (crmode_f==CRLF) {
2082 (*o_crconv)(0,'\r');
2083 } else if (crmode_f==CR) {
2084 (*o_crconv)(0,'\r');
2088 } else if (c1!='\032' || crmode_f!=NL){
2094 Return value of fold_conv()
2096 \n add newline and output char
2097 \r add newline and output nothing
2100 1 (or else) normal output
2102 fold state in prev (previous character)
2104 >0x80 Japanese (X0208/X0201)
2109 This fold algorthm does not preserve heading space in a line.
2110 This is the main difference from fmt.
2113 #define char_size(c2,c1) (c2?2:1)
2123 fold_state=0; /* ignroe cr */
2124 } else if (c1== BS) {
2125 if (f_line>0) f_line--;
2127 } else if (c2==EOF && f_line != 0) { /* close open last line */
2129 } else if (c1=='\n') {
2131 if (fold_preserve_f) {
2134 } else if (f_prev == c1) { /* duplicate newline */
2137 fold_state = '\n'; /* output two newline */
2143 if (f_prev&0x80) { /* Japanese? */
2145 fold_state = 0; /* ignore given single newline */
2146 } else if (f_prev==' ') {
2150 if (++f_line<=fold_len)
2154 fold_state = '\r'; /* fold and output nothing */
2158 } else if (c1=='\f') {
2163 fold_state = '\n'; /* output newline and clear */
2164 } else if ( (c2==0 && c1==' ')||
2165 (c2==0 && c1=='\t')||
2166 (c2=='!'&& c1=='!')) {
2167 /* X0208 kankaku or ascii space */
2168 if (f_prev == ' ') {
2169 fold_state = 0; /* remove duplicate spaces */
2172 if (++f_line<=fold_len)
2173 fold_state = ' '; /* output ASCII space only */
2175 f_prev = ' '; f_line = 0;
2176 fold_state = '\r'; /* fold and output nothing */
2180 prev0 = f_prev; /* we still need this one... , but almost done */
2182 if (c2 || c2==X0201)
2183 f_prev |= 0x80; /* this is Japanese */
2184 f_line += char_size(c2,c1);
2185 if (f_line<=fold_len) { /* normal case */
2188 if (f_line>=fold_len+fold_margin) { /* too many kinsou suspension */
2189 f_line = char_size(c2,c1);
2190 fold_state = '\n'; /* We can't wait, do fold now */
2191 } else if (c2==X0201) {
2192 /* simple kinsoku rules return 1 means no folding */
2193 if (c1==(0xde&0x7f)) fold_state = 1; /*
\e$B!+
\e(B*/
2194 else if (c1==(0xdf&0x7f)) fold_state = 1; /*
\e$B!,
\e(B*/
2195 else if (c1==(0xa4&0x7f)) fold_state = 1; /*
\e$B!#
\e(B*/
2196 else if (c1==(0xa3&0x7f)) fold_state = 1; /*
\e$B!$
\e(B*/
2197 else if (c1==(0xa1&0x7f)) fold_state = 1; /*
\e$B!W
\e(B*/
2198 else if (c1==(0xb0&0x7f)) fold_state = 1; /* - */
2199 else if (SPACE<=c1 && c1<=(0xdf&0x7f)) { /* X0201 */
2201 fold_state = '\n';/* add one new f_line before this character */
2204 fold_state = '\n';/* add one new f_line before this character */
2207 /* kinsoku point in ASCII */
2208 if ( c1==')'|| /* { [ ( */
2219 /* just after special */
2220 } else if (!is_alnum(prev0)) {
2221 f_line = char_size(c2,c1);
2223 } else if ((prev0==' ') || /* ignored new f_line */
2224 (prev0=='\n')|| /* ignored new f_line */
2225 (prev0&0x80)) { /* X0208 - ASCII */
2226 f_line = char_size(c2,c1);
2227 fold_state = '\n';/* add one new f_line before this character */
2229 fold_state = 1; /* default no fold in ASCII */
2233 if (c1=='"') fold_state = 1; /*
\e$B!"
\e(B */
2234 else if (c1=='#') fold_state = 1; /*
\e$B!#
\e(B */
2235 else if (c1=='W') fold_state = 1; /*
\e$B!W
\e(B */
2236 else if (c1=='K') fold_state = 1; /*
\e$B!K
\e(B */
2237 else if (c1=='$') fold_state = 1; /*
\e$B!$
\e(B */
2238 else if (c1=='%') fold_state = 1; /*
\e$B!%
\e(B */
2239 else if (c1=='\'') fold_state = 1; /*
\e$B!\
\e(B */
2240 else if (c1=='(') fold_state = 1; /*
\e$B!(
\e(B */
2241 else if (c1==')') fold_state = 1; /*
\e$B!)
\e(B */
2242 else if (c1=='*') fold_state = 1; /*
\e$B!*
\e(B */
2243 else if (c1=='+') fold_state = 1; /*
\e$B!+
\e(B */
2244 else if (c1==',') fold_state = 1; /*
\e$B!,
\e(B */
2245 /* default no fold in kinsoku */
2248 f_line = char_size(c2,c1);
2249 /* add one new f_line before this character */
2252 f_line = char_size(c2,c1);
2254 /* add one new f_line before this character */
2259 /* terminator process */
2260 switch(fold_state) {
2279 int z_prev2=0,z_prev1=0;
2286 /* if (c2) c1 &= 0x7f; assertion */
2288 if (x0201_f && z_prev2==X0201) { /* X0201 */
2289 if (c1==(0xde&0x7f)) { /*
\e$BByE@
\e(B */
2291 (*o_zconv)(dv[(z_prev1-SPACE)*2],dv[(z_prev1-SPACE)*2+1]);
2293 } else if (c1==(0xdf&0x7f)&&ev[(z_prev1-SPACE)*2]) { /*
\e$BH>ByE@
\e(B */
2295 (*o_zconv)(ev[(z_prev1-SPACE)*2],ev[(z_prev1-SPACE)*2+1]);
2299 (*o_zconv)(cv[(z_prev1-SPACE)*2],cv[(z_prev1-SPACE)*2+1]);
2308 if (x0201_f && c2==X0201) {
2309 if (dv[(c1-SPACE)*2]||ev[(c1-SPACE)*2]) {
2310 /* wait for
\e$BByE@
\e(B or
\e$BH>ByE@
\e(B */
2311 z_prev1 = c1; z_prev2 = c2;
2314 (*o_zconv)(cv[(c1-SPACE)*2],cv[(c1-SPACE)*2+1]);
2319 /* JISX0208 Alphabet */
2320 if (alpha_f && c2 == 0x23 ) {
2322 } else if (alpha_f && c2 == 0x21 ) {
2323 /* JISX0208 Kigou */
2328 } else if (alpha_f&0x4) {
2333 } else if (0x20<c1 && c1<0x7f && fv[c1-0x20]) {
2339 case '>': entity = ">"; break;
2340 case '<': entity = "<"; break;
2341 case '\"': entity = """; break;
2342 case '&': entity = "&"; break;
2345 while (*entity) (*o_zconv)(0, *entity++);
2355 #define rot13(c) ( \
2357 (c <= 'M') ? (c + 13): \
2358 (c <= 'Z') ? (c - 13): \
2360 (c <= 'm') ? (c + 13): \
2361 (c <= 'z') ? (c - 13): \
2365 #define rot47(c) ( \
2367 ( c <= 'O' ) ? (c + 47) : \
2368 ( c <= '~' ) ? (c - 47) : \
2376 if (c2==0 || c2==X0201 || c2==ISO8859_1) {
2382 (*o_rot_conv)(c2,c1);
2389 if ((hira_f & 1) && c2==0x25 && 0x20<c1 && c1<0x74) {
2391 } else if ((hira_f & 2) && c2==0x24 && 0x20<c1 && c1<0x74) {
2394 (*o_hira_conv)(c2,c1);
2399 iso2022jp_check_conv(c2,c1)
2402 static int range[RANGE_NUM_MAX][2] = {
2425 if(c2 >= 0x00 && c2 <= 0x20 && c1 >= 0x7f && c1 <= 0xff) {
2429 if((c2 >= 0x29 && c2 <= 0x2f) || (c2 >= 0x75 && c2 <= 0x7e)) {
2434 for (i = 0; i < RANGE_NUM_MAX; i++) {
2435 start = range[i][0];
2438 if (c >= start && c <= end) {
2443 (*o_iso2022jp_check_conv)(c2,c1);
2447 /* This converts =?ISO-2022-JP?B?HOGE HOGE?= */
2449 unsigned char *mime_pattern[] = {
2450 (unsigned char *)"\075?EUC-JP?B?",
2451 (unsigned char *)"\075?SHIFT_JIS?B?",
2452 (unsigned char *)"\075?ISO-8859-1?Q?",
2453 (unsigned char *)"\075?ISO-2022-JP?B?",
2454 (unsigned char *)"\075?ISO-2022-JP?Q?",
2455 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
2456 (unsigned char *)"\075?UTF-8?B?",
2461 int mime_encode[] = {
2462 JAPANESE_EUC, SHIFT_JIS,ISO8859_1, X0208, X0201,
2463 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
2469 int mime_encode_method[] = {
2470 'B', 'B','Q', 'B', 'Q',
2471 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
2478 #define MAXRECOVER 20
2480 /* I don't trust portablity of toupper */
2481 #define nkf_toupper(c) (('a'<=c && c<='z')?(c-('a'-'A')):c)
2486 if (i_getc!=mime_getc) {
2487 i_mgetc = i_getc; i_getc = mime_getc;
2488 i_mungetc = i_ungetc; i_ungetc = mime_ungetc;
2489 if(mime_f==STRICT_MIME) {
2490 i_mgetc_buf = i_mgetc; i_mgetc = mime_getc_buf;
2491 i_mungetc_buf = i_mungetc; i_mungetc = mime_ungetc_buf;
2497 unswitch_mime_getc()
2499 if(mime_f==STRICT_MIME) {
2500 i_mgetc = i_mgetc_buf;
2501 i_mungetc = i_mungetc_buf;
2504 i_ungetc = i_mungetc;
2508 mime_begin_strict(f)
2513 unsigned char *p,*q;
2514 int r[MAXRECOVER]; /* recovery buffer, max mime pattern lenght */
2516 mime_decode_mode = FALSE;
2517 /* =? has been checked */
2519 p = mime_pattern[j];
2522 for(i=2;p[i]>' ';i++) { /* start at =? */
2523 if ( ((r[i] = c1 = (*i_getc)(f))==EOF) || nkf_toupper(c1) != p[i] ) {
2524 /* pattern fails, try next one */
2526 while ((p = mime_pattern[++j])) {
2527 for(k=2;k<i;k++) /* assume length(p) > i */
2528 if (p[k]!=q[k]) break;
2529 if (k==i && nkf_toupper(c1)==p[k]) break;
2531 if (p) continue; /* found next one, continue */
2532 /* all fails, output from recovery buffer */
2540 mime_decode_mode = p[i-2];
2541 if (mime_decode_mode=='B') {
2542 mimebuf_f = unbuf_f;
2544 /* do MIME integrity check */
2545 return mime_integrity(f,mime_pattern[j]);
2557 /* we don't keep eof of Fifo, becase it contains ?= as
2558 a terminator. It was checked in mime_integrity. */
2559 return ((mimebuf_f)?
2560 (*i_mgetc_buf)(f):Fifo(mime_input++));
2564 mime_ungetc_buf(c,f)
2569 (*i_mungetc_buf)(c,f);
2571 Fifo(--mime_input)=c;
2582 /* In NONSTRICT mode, only =? is checked. In case of failure, we */
2583 /* re-read and convert again from mime_buffer. */
2585 /* =? has been checked */
2587 Fifo(mime_last++)='='; Fifo(mime_last++)='?';
2588 for(i=2;i<MAXRECOVER;i++) { /* start at =? */
2589 /* We accept any character type even if it is breaked by new lines */
2590 c1 = (*i_getc)(f); Fifo(mime_last++)= c1 ;
2591 if (c1=='\n'||c1==' '||c1=='\r'||
2592 c1=='-'||c1=='_'||is_alnum(c1) ) continue;
2594 /* Failed. But this could be another MIME preemble */
2602 c1 = (*i_getc)(f); Fifo(mime_last++) = c1;
2603 if (!(++i<MAXRECOVER) || c1==EOF) break;
2604 if (c1=='b'||c1=='B') {
2605 mime_decode_mode = 'B';
2606 } else if (c1=='q'||c1=='Q') {
2607 mime_decode_mode = 'Q';
2611 c1 = (*i_getc)(f); Fifo(mime_last++) = c1;
2612 if (!(++i<MAXRECOVER) || c1==EOF) break;
2614 mime_decode_mode = FALSE;
2620 if (!mime_decode_mode) {
2621 /* false MIME premble, restart from mime_buffer */
2622 mime_decode_mode = 1; /* no decode, but read from the mime_buffer */
2623 /* Since we are in MIME mode until buffer becomes empty, */
2624 /* we never go into mime_begin again for a while. */
2627 /* discard mime preemble, and goto MIME mode */
2629 /* do no MIME integrity check */
2630 return c1; /* used only for checking EOF */
2650 #ifdef CAP_URL_OPTION
2655 if (isdigit(x)) return x - '0';
2656 return nkf_toupper(x) - 'A' + 10;
2660 hex_getc(ch, f, g, u)
2664 int (*u)(int c, FILE *f);
2672 if (!isxdigit(c2) == EOF){
2677 if (!isxdigit(c3) == EOF){
2682 return (hex2bin(c2) << 4) | hex2bin(c3);
2689 return hex_getc(':', f, i_cgetc, i_cungetc);
2697 return (*i_cungetc)(c, f);
2704 return hex_getc('%', f, i_ugetc, i_uungetc);
2712 return (*i_uungetc)(c, f);
2721 int c1, c2, c3, c4, cc;
2722 int t1, t2, t3, t4, mode, exit_mode;
2724 if (mime_top != mime_last) { /* Something is in FIFO */
2725 return Fifo(mime_top++);
2727 if (mime_decode_mode==1 ||mime_decode_mode==FALSE) {
2728 mime_decode_mode=FALSE;
2729 unswitch_mime_getc();
2730 return (*i_getc)(f);
2733 if (mimebuf_f == FIXED_MIME)
2734 exit_mode = mime_decode_mode;
2737 if (mime_decode_mode == 'Q') {
2738 if ((c1 = (*i_mgetc)(f)) == EOF) return (EOF);
2740 if (c1=='_') return ' ';
2741 if (c1!='=' && c1!='?') {
2745 mime_decode_mode = exit_mode; /* prepare for quit */
2746 if (c1<=' ') return c1;
2747 if ((c2 = (*i_mgetc)(f)) == EOF) return (EOF);
2748 if (c1=='?'&&c2=='=' && mimebuf_f != FIXED_MIME) {
2749 /* end Q encoding */
2750 input_mode = exit_mode;
2751 while((c1=(*i_getc)(f))!=EOF && c1==SPACE
2752 /* && (c1==NL||c1==TAB||c1=='\r') */ ) ;
2755 if (c1=='='&&c2<' ') { /* this is soft wrap */
2756 while((c1 = (*i_mgetc)(f)) <=' ') {
2757 if ((c1 = (*i_mgetc)(f)) == EOF) return (EOF);
2759 mime_decode_mode = 'Q'; /* still in MIME */
2760 goto restart_mime_q;
2763 mime_decode_mode = 'Q'; /* still in MIME */
2767 if ((c3 = (*i_mgetc)(f)) == EOF) return (EOF);
2768 if (c2<=' ') return c2;
2769 mime_decode_mode = 'Q'; /* still in MIME */
2770 #define hex(c) (('0'<=c&&c<='9')?(c-'0'):\
2771 ('A'<=c&&c<='F')?(c-'A'+10):('a'<=c&&c<='f')?(c-'a'+10):0)
2772 return ((hex(c2)<<4) + hex(c3));
2775 if (mime_decode_mode != 'B') {
2776 mime_decode_mode = FALSE;
2777 return (*i_mgetc)(f);
2781 /* Base64 encoding */
2783 MIME allows line break in the middle of
2784 Base64, but we are very pessimistic in decoding
2785 in unbuf mode because MIME encoded code may broken by
2786 less or editor's control sequence (such as ESC-[-K in unbuffered
2787 mode. ignore incomplete MIME.
2789 mode = mime_decode_mode;
2790 mime_decode_mode = exit_mode; /* prepare for quit */
2792 while ((c1 = (*i_mgetc)(f))<=' ') {
2797 if ((c2 = (*i_mgetc)(f))<=' ') {
2800 if (mime_f != STRICT_MIME) goto mime_c2_retry;
2801 if (mimebuf_f!=FIXED_MIME) input_mode = ASCII;
2804 if ((c1 == '?') && (c2 == '=')) {
2806 while((c1=(*i_getc)(f))!=EOF && c1==SPACE
2807 /* && (c1==NL||c1==TAB||c1=='\r') */ ) ;
2811 if ((c3 = (*i_mgetc)(f))<=' ') {
2814 if (mime_f != STRICT_MIME) goto mime_c3_retry;
2815 if (mimebuf_f!=FIXED_MIME) input_mode = ASCII;
2819 if ((c4 = (*i_mgetc)(f))<=' ') {
2822 if (mime_f != STRICT_MIME) goto mime_c4_retry;
2823 if (mimebuf_f!=FIXED_MIME) input_mode = ASCII;
2827 mime_decode_mode = mode; /* still in MIME sigh... */
2829 /* BASE 64 decoding */
2831 t1 = 0x3f & base64decode(c1);
2832 t2 = 0x3f & base64decode(c2);
2833 t3 = 0x3f & base64decode(c3);
2834 t4 = 0x3f & base64decode(c4);
2835 cc = ((t1 << 2) & 0x0fc) | ((t2 >> 4) & 0x03);
2837 Fifo(mime_last++) = cc;
2838 cc = ((t2 << 4) & 0x0f0) | ((t3 >> 2) & 0x0f);
2840 Fifo(mime_last++) = cc;
2841 cc = ((t3 << 6) & 0x0c0) | (t4 & 0x3f);
2843 Fifo(mime_last++) = cc;
2848 return Fifo(mime_top++);
2856 Fifo(--mime_top) = c;
2867 /* In buffered mode, read until =? or NL or buffer full
2869 mime_input = mime_top;
2870 mime_last = mime_top;
2871 while(*p) Fifo(mime_input++) = *p++;
2874 while((c=(*i_getc)(f))!=EOF) {
2875 if (((mime_input-mime_top)&MIME_BUF_MASK)==0) {
2876 break; /* buffer full */
2878 if (c=='=' && d=='?') {
2879 /* checked. skip header, start decode */
2880 Fifo(mime_input++) = c;
2881 /* mime_last_input = mime_input; */
2886 if (!( (c=='+'||c=='/'|| c=='=' || c=='?' || is_alnum(c))))
2888 /* Should we check length mod 4? */
2889 Fifo(mime_input++) = c;
2892 /* In case of Incomplete MIME, no MIME decode */
2893 Fifo(mime_input++) = c;
2894 mime_last = mime_input; /* point undecoded buffer */
2895 mime_decode_mode = 1; /* no decode on Fifo last in mime_getc */
2896 switch_mime_getc(); /* anyway we need buffered getc */
2907 i = c - 'A'; /* A..Z 0-25 */
2909 i = c - 'G' /* - 'a' + 26 */ ; /* a..z 26-51 */
2911 } else if (c > '/') {
2912 i = c - '0' + '4' /* - '0' + 52 */ ; /* 0..9 52-61 */
2913 } else if (c == '+') {
2914 i = '>' /* 62 */ ; /* + 62 */
2916 i = '?' /* 63 */ ; /* / 63 */
2921 static char basis_64[] =
2922 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2932 p = mime_pattern[0];
2933 for(i=0;mime_encode[i];i++) {
2934 if (mode == mime_encode[i]) {
2935 p = mime_pattern[i];
2939 mimeout_mode = mime_encode_method[i];
2941 /* (*o_mputc)(' '); */
2958 #define itoh4(c) (c>=10?c+'A'-10:c+'0')
2964 if (mimeout_f==FIXED_MIME) {
2965 if (base64_count>71) {
2973 if ( c<=DEL &&(output_mode==ASCII ||output_mode == ISO8859_1 )
2974 && mimeout_f!=FIXED_MIME) {
2975 if (mimeout_mode=='Q') {
2982 if (mimeout_mode!='B' || c!=SPACE) {
2991 } else if (!mimeout_mode && mimeout_f!=FIXED_MIME) {
2992 open_mime(output_mode);
2994 } else { /* c==EOF */
2995 switch(mimeout_mode) {
3000 (*o_mputc)(basis_64[((b64c & 0x3)<< 4)]);
3006 (*o_mputc)(basis_64[((b64c & 0xF) << 2)]);
3012 if (mimeout_f!=FIXED_MIME) {
3014 } else if (mimeout_mode != 'Q')
3019 switch(mimeout_mode) {
3023 (*o_mputc)(itoh4(((c>>4)&0xf)));
3024 (*o_mputc)(itoh4((c&0xf)));
3031 (*o_mputc)(basis_64[c>>2]);
3036 (*o_mputc)(basis_64[((b64c & 0x3)<< 4) | ((c & 0xF0) >> 4)]);
3042 (*o_mputc)(basis_64[((b64c & 0xF) << 2) | ((c & 0xC0) >>6)]);
3043 (*o_mputc)(basis_64[c & 0x3F]);
3063 mime_f = STRICT_MIME;
3067 #if defined(MSDOS) || defined(__OS2__)
3072 iso2022jp_f = FALSE;
3074 kanji_intro = DEFAULT_J;
3075 ascii_intro = DEFAULT_R;
3077 output_conv = DEFAULT_CONV;
3078 oconv = DEFAULT_CONV;
3081 i_mungetc = std_ungetc;
3082 i_mgetc_buf = std_getc;
3083 i_mungetc_buf = std_ungetc;
3086 i_ungetc=std_ungetc;
3089 i_bungetc= std_ungetc;
3093 o_crconv = no_connection;
3094 o_rot_conv = no_connection;
3095 o_iso2022jp_check_conv = no_connection;
3096 o_hira_conv = no_connection;
3097 o_fconv = no_connection;
3098 o_zconv = no_connection;
3101 i_ungetc = std_ungetc;
3103 i_mungetc = std_ungetc;
3105 output_mode = ASCII;
3108 mime_decode_mode = FALSE;
3118 #ifdef UTF8_INPUT_ENABLE
3123 #ifdef UTF8_OUTPUT_ENABLE
3124 if (w_oconv16_begin_f) {
3125 w_oconv16_begin_f = 2;
3130 fold_preserve_f = FALSE;
3133 fold_margin = FOLD_MARGIN;
3136 z_prev2=0,z_prev1=0;
3142 no_connection(c2,c1)
3145 no_connection2(c2,c1,0);
3149 no_connection2(c2,c1,c0)
3152 fprintf(stderr,"nkf internal module connection failure.\n");
3160 fprintf(stderr,"USAGE: nkf(nkf32,wnkf,nkf2) -[flags] [in file] .. [out file for -O flag]\n");
3161 fprintf(stderr,"Flags:\n");
3162 fprintf(stderr,"b,u Output is bufferred (DEFAULT),Output is unbufferred\n");
3163 #ifdef DEFAULT_CODE_SJIS
3164 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit, Shift JIS (DEFAULT), AT&T JIS (EUC), UTF-8\n");
3166 #ifdef DEFAULT_CODE_JIS
3167 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit (DEFAULT), Shift JIS, AT&T JIS (EUC), UTF-8\n");
3169 #ifdef DEFAULT_CODE_EUC
3170 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit, Shift JIS, AT&T JIS (EUC) (DEFAULT), UTF-8\n");
3172 #ifdef DEFAULT_CODE_UTF8
3173 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit, Shift JIS, AT&T JIS (EUC), UTF-8 (DEFAULT)\n");
3175 fprintf(stderr,"J,S,E,W Input assumption is JIS 7 bit , Shift JIS, AT&T JIS (EUC), UTF-8\n");
3176 fprintf(stderr,"t no conversion\n");
3177 fprintf(stderr,"i_/o_ Output sequence to designate JIS-kanji/ASCII (DEFAULT B)\n");
3178 fprintf(stderr,"r {de/en}crypt ROT13/47\n");
3179 fprintf(stderr,"h 1 hirakana->katakana, 2 katakana->hirakana,3 both\n");
3180 fprintf(stderr,"v Show this usage. V: show version\n");
3181 fprintf(stderr,"m[BQN0] MIME decode [B:base64,Q:quoted,N:non-strict,0:no decode]\n");
3182 fprintf(stderr,"M[BQ] MIME encode [B:base64 Q:quoted]\n");
3183 fprintf(stderr,"l ISO8859-1 (Latin-1) support\n");
3184 fprintf(stderr,"f/F Folding: -f60 or -f or -f60-10 (fold margin 10) F preserve nl\n");
3185 fprintf(stderr,"Z[0-3] Convert X0208 alphabet to ASCII 1: Kankaku to space,2: 2 spaces,\n");
3186 fprintf(stderr," 3: Convert HTML Entity\n");
3187 fprintf(stderr,"X,x Assume X0201 kana in MS-Kanji, -x preserves X0201\n");
3188 fprintf(stderr,"B[0-2] Broken input 0: missing ESC,1: any X on ESC-[($]-X,2: ASCII on NL\n");
3190 fprintf(stderr,"T Text mode output\n");
3192 fprintf(stderr,"O Output to File (DEFAULT 'nkf.out')\n");
3193 fprintf(stderr,"d,c Delete \\r in line feed and \\032, Add \\r in line feed\n");
3194 fprintf(stderr,"I Convert non ISO-2022-JP charactor to GETA\n");
3195 fprintf(stderr,"-L[uwm] line mode u:LF w:CRLF m:CR (DEFAULT noconversion)\n");
3196 fprintf(stderr,"long name options\n");
3197 fprintf(stderr," --fj,--unix,--mac,--windows convert for the system\n");
3198 fprintf(stderr," --jis,--euc,--sjis,--utf8,--utf16,--mime,--base64 convert for the code\n");
3199 fprintf(stderr," --help,--version\n");
3206 fprintf(stderr,"Network Kanji Filter Version %s (%s) "
3207 #if defined(MSDOS) && !defined(_Windows)
3210 #if !defined(__WIN32__) && defined(_Windows)
3213 #if defined(__WIN32__) && defined(_Windows)
3219 ,Version,Patchlevel);
3220 fprintf(stderr,"\n%s\n",CopyRight);
3225 **
\e$B%Q%C%A@):n<T
\e(B
3226 ** void@merope.pleiades.or.jp (Kusakabe Youichi)
3227 ** NIDE Naoyuki <nide@ics.nara-wu.ac.jp>
3228 ** ohta@src.ricoh.co.jp (Junn Ohta)
3229 ** inouet@strl.nhk.or.jp (Tomoyuki Inoue)
3230 ** kiri@pulser.win.or.jp (Tetsuaki Kiriyama)
3231 ** Kimihiko Sato <sato@sail.t.u-tokyo.ac.jp>
3232 ** a_kuroe@kuroe.aoba.yokohama.jp (Akihiko Kuroe)
3233 ** kono@ie.u-ryukyu.ac.jp (Shinji Kono)
3234 ** GHG00637@nifty-serve.or.jp (COW)
3236 **
\e$B:G=*99?7F|
\e(B