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 ***********************************************************************/
42 /* $Id: nkf.c,v 1.40 2004/11/19 15:18:43 naruse Exp $ */
43 #define NKF_VERSION "2.0.4"
44 #define NKF_RELEASE_DATE "2004-11-15"
47 static char *CopyRight =
48 "Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),2000 S. Kono, COW, 2002-2004 Kono, Furukawa";
55 ** USAGE: nkf [flags] [file]
58 ** b Output is buffered (DEFAULT)
59 ** u Output is unbuffered
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(_MSC_VER) || defined(LSI_C) || defined(__MINGW32__)) && !defined(MSDOS)
100 #if (defined(__Win32__) || defined(_WIN32)) && !defined(__WIN32__)
115 #if defined(MSDOS) || defined(__OS2__)
122 #define setbinmode(fp) fsetbin(fp)
123 #else /* Microsoft C, Turbo C */
124 #define setbinmode(fp) setmode(fileno(fp), O_BINARY)
126 #else /* UNIX,OS/2 */
127 #define setbinmode(fp)
130 #ifdef _IOFBF /* SysV and MSDOS, Windows */
131 #define setvbuffer(fp, buf, size) setvbuf(fp, buf, _IOFBF, size)
133 #define setvbuffer(fp, buf, size) setbuffer(fp, buf, size)
136 /*Borland C++ 4.5 EasyWin*/
137 #if defined(__TURBOC__) && defined(_Windows) && !defined(__WIN32__) /*Easy Win */
146 /* added by satoru@isoternet.org */
148 #include <sys/stat.h>
149 #ifndef MSDOS /* UNIX, OS/2 */
153 #if defined(_MSC_VER) || defined(__MINGW32__) /* VC++, MinGW */
154 #include <sys/utime.h>
155 #elif defined(__TURBOC__) /* BCC */
157 #elif defined(LSI_C) /* LSI C */
169 /* state of output_mode and input_mode
186 /* Input Assumption */
190 #define LATIN1_INPUT 6
192 #define STRICT_MIME 8
197 #define JAPANESE_EUC 10
201 #define UTF8_INPUT 13
202 #define UTF16LE_INPUT 14
203 #define UTF16BE_INPUT 15
223 #define is_alnum(c) \
224 (('a'<=c && c<='z')||('A'<= c && c<='Z')||('0'<=c && c<='9'))
226 #define HOLD_SIZE 1024
227 #define IOBUF_SIZE 16384
229 #define DEFAULT_J 'B'
230 #define DEFAULT_R 'B'
232 #define SJ0162 0x00e1 /* 01 - 62 ku offset */
233 #define SJ6394 0x0161 /* 63 - 94 ku offset */
235 #define RANGE_NUM_MAX 18
240 #if defined( UTF8_OUTPUT_ENABLE ) || defined( UTF8_INPUT_ENABLE )
241 #define sizeof_euc_utf8 94
242 #define sizeof_euc_to_utf8_1byte 94
243 #define sizeof_euc_to_utf8_2bytes 94
244 #define sizeof_utf8_to_euc_C2 64
245 #define sizeof_utf8_to_euc_E5B8 64
246 #define sizeof_utf8_to_euc_2bytes 112
247 #define sizeof_utf8_to_euc_3bytes 112
250 /* MIME preprocessor */
253 #ifdef EASYWIN /*Easy Win */
254 extern POINT _BufferSize;
257 /* function prototype */
259 #ifdef ANSI_C_PROTOTYPE
261 #define STATIC static
273 void (*status_func)PROTO((struct input_code *, int));
274 int (*iconv_func)PROTO((int c2, int c1, int c0));
278 STATIC char *input_codename = "";
280 STATIC int noconvert PROTO((FILE *f));
281 STATIC int kanji_convert PROTO((FILE *f));
282 STATIC int h_conv PROTO((FILE *f,int c2,int c1));
283 STATIC int push_hold_buf PROTO((int c2));
284 STATIC void set_iconv PROTO((int f, int (*iconv_func)()));
285 STATIC int s_iconv PROTO((int c2,int c1,int c0));
286 STATIC int s2e_conv PROTO((int c2, int c1, int *p2, int *p1));
287 STATIC int e_iconv PROTO((int c2,int c1,int c0));
288 #ifdef UTF8_INPUT_ENABLE
289 STATIC int w2e_conv PROTO((int c2,int c1,int c0,int *p2,int *p1));
290 STATIC int w_iconv PROTO((int c2,int c1,int c0));
291 STATIC int w_iconv16 PROTO((int c2,int c1,int c0));
292 STATIC int w_iconv_common PROTO((int c1,int c0,unsigned short **pp,int psize,int *p2,int *p1));
293 STATIC int ww16_conv PROTO((int c2, int c1, int c0));
295 #ifdef UTF8_OUTPUT_ENABLE
296 STATIC int e2w_conv PROTO((int c2,int c1));
297 STATIC void w_oconv PROTO((int c2,int c1));
298 STATIC void w_oconv16 PROTO((int c2,int c1));
300 STATIC void e_oconv PROTO((int c2,int c1));
301 STATIC void e2s_conv PROTO((int c2, int c1, int *p2, int *p1));
302 STATIC void s_oconv PROTO((int c2,int c1));
303 STATIC void j_oconv PROTO((int c2,int c1));
304 STATIC void fold_conv PROTO((int c2,int c1));
305 STATIC void cr_conv PROTO((int c2,int c1));
306 STATIC void z_conv PROTO((int c2,int c1));
307 STATIC void rot_conv PROTO((int c2,int c1));
308 STATIC void hira_conv PROTO((int c2,int c1));
309 STATIC void base64_conv PROTO((int c2,int c1));
310 STATIC void iso2022jp_check_conv PROTO((int c2,int c1));
311 STATIC void no_connection PROTO((int c2,int c1));
312 STATIC int no_connection2 PROTO((int c2,int c1,int c0));
314 STATIC void code_score PROTO((struct input_code *ptr));
315 STATIC void code_status PROTO((int c));
317 STATIC void std_putc PROTO((int c));
318 STATIC int std_getc PROTO((FILE *f));
319 STATIC int std_ungetc PROTO((int c,FILE *f));
321 STATIC int broken_getc PROTO((FILE *f));
322 STATIC int broken_ungetc PROTO((int c,FILE *f));
324 STATIC int mime_begin PROTO((FILE *f));
325 STATIC int mime_getc PROTO((FILE *f));
326 STATIC int mime_ungetc PROTO((int c,FILE *f));
328 STATIC int mime_begin_strict PROTO((FILE *f));
329 STATIC int mime_getc_buf PROTO((FILE *f));
330 STATIC int mime_ungetc_buf PROTO((int c,FILE *f));
331 STATIC int mime_integrity PROTO((FILE *f,unsigned char *p));
333 STATIC int base64decode PROTO((int c));
334 STATIC void mime_putc PROTO((int c));
335 STATIC void open_mime PROTO((int c));
336 STATIC void close_mime PROTO(());
337 STATIC void usage PROTO(());
338 STATIC void version PROTO(());
339 STATIC void options PROTO((unsigned char *c));
341 STATIC void reinit PROTO(());
346 static unsigned char stdibuf[IOBUF_SIZE];
347 static unsigned char stdobuf[IOBUF_SIZE];
348 static unsigned char hold_buf[HOLD_SIZE*2];
349 static int hold_count;
351 /* MIME preprocessor fifo */
353 #define MIME_BUF_SIZE (1024) /* 2^n ring buffer */
354 #define MIME_BUF_MASK (MIME_BUF_SIZE-1)
355 #define Fifo(n) mime_buf[(n)&MIME_BUF_MASK]
356 static unsigned char mime_buf[MIME_BUF_SIZE];
357 static unsigned int mime_top = 0;
358 static unsigned int mime_last = 0; /* decoded */
359 static unsigned int mime_input = 0; /* undecoded */
362 static int unbuf_f = FALSE;
363 static int estab_f = FALSE;
364 static int nop_f = FALSE;
365 static int binmode_f = TRUE; /* binary mode */
366 static int rot_f = FALSE; /* rot14/43 mode */
367 static int hira_f = FALSE; /* hira/kata henkan */
368 static int input_f = FALSE; /* non fixed input code */
369 static int alpha_f = FALSE; /* convert JIx0208 alphbet to ASCII */
370 static int mime_f = STRICT_MIME; /* convert MIME B base64 or Q */
371 static int mimebuf_f = FALSE; /* MIME buffered input */
372 static int broken_f = FALSE; /* convert ESC-less broken JIS */
373 static int iso8859_f = FALSE; /* ISO8859 through */
374 static int mimeout_f = FALSE; /* base64 mode */
375 #if defined(MSDOS) || defined(__OS2__)
376 static int x0201_f = TRUE; /* Assume JISX0201 kana */
378 static int x0201_f = NO_X0201; /* Assume NO JISX0201 */
380 static int iso2022jp_f = FALSE; /* convert ISO-2022-JP */
381 #ifdef UTF8_OUTPUT_ENABLE
382 static int unicode_bom_f= 0; /* Output Unicode BOM */
383 static int w_oconv16_LE = 0; /* utf-16 little endian */
384 static int ms_ucs_map_f = FALSE; /* Microsoft UCS Mapping Compatible */
388 #ifdef NUMCHAR_OPTION
390 #define CLASS_MASK 0x0f000000
391 #define CLASS_UTF16 0x01000000
395 static int cap_f = FALSE;
396 static int (*i_cgetc)PROTO((FILE *)) = std_getc; /* input of cgetc */
397 static int (*i_cungetc)PROTO((int c ,FILE *f)) = std_ungetc;
398 STATIC int cap_getc PROTO((FILE *f));
399 STATIC int cap_ungetc PROTO((int c,FILE *f));
401 static int url_f = FALSE;
402 static int (*i_ugetc)PROTO((FILE *)) = std_getc; /* input of ugetc */
403 static int (*i_uungetc)PROTO((int c ,FILE *f)) = std_ungetc;
404 STATIC int url_getc PROTO((FILE *f));
405 STATIC int url_ungetc PROTO((int c,FILE *f));
407 static int numchar_f = FALSE;
408 static int (*i_ngetc)PROTO((FILE *)) = std_getc; /* input of ugetc */
409 static int (*i_nungetc)PROTO((int c ,FILE *f)) = std_ungetc;
410 STATIC int numchar_getc PROTO((FILE *f));
411 STATIC int numchar_ungetc PROTO((int c,FILE *f));
415 static int noout_f = FALSE;
416 STATIC void no_putc PROTO((int c));
417 static int debug_f = FALSE;
418 STATIC void debug PROTO((char *str));
421 static int guess_f = FALSE;
422 STATIC void print_guessed_code PROTO((char *filename));
423 STATIC void set_input_codename PROTO((char *codename));
424 static int is_inputcode_mixed = FALSE;
425 static int is_inputcode_set = FALSE;
428 static int exec_f = 0;
431 #ifdef SHIFTJIS_CP932
432 STATIC int cp932_f = TRUE;
433 #define CP932_TABLE_BEGIN (0xfa)
434 #define CP932_TABLE_END (0xfc)
436 STATIC int cp932inv_f = FALSE;
437 #define CP932INV_TABLE_BEGIN (0xed)
438 #define CP932INV_TABLE_END (0xee)
440 #endif /* SHIFTJIS_CP932 */
442 STATIC unsigned char prefix_table[256];
444 STATIC void e_status PROTO((struct input_code *, int));
445 STATIC void s_status PROTO((struct input_code *, int));
447 #ifdef UTF8_INPUT_ENABLE
448 STATIC void w_status PROTO((struct input_code *, int));
449 STATIC void w16_status PROTO((struct input_code *, int));
450 static int utf16_mode = UTF16LE_INPUT;
453 struct input_code input_code_list[] = {
454 {"EUC-JP", 0, 0, 0, {0, 0, 0}, e_status, e_iconv, 0},
455 {"Shift_JIS", 0, 0, 0, {0, 0, 0}, s_status, s_iconv, 0},
456 {"UTF-8", 0, 0, 0, {0, 0, 0}, w_status, w_iconv, 0},
457 {"UTF-16", 0, 0, 0, {0, 0, 0}, w16_status, w_iconv16, 0},
461 static int mimeout_mode = 0;
462 static int base64_count = 0;
464 /* X0208 -> ASCII converter */
467 static int f_line = 0; /* chars in line */
468 static int f_prev = 0;
469 static int fold_preserve_f = FALSE; /* preserve new lines */
470 static int fold_f = FALSE;
471 static int fold_len = 0;
474 static unsigned char kanji_intro = DEFAULT_J;
475 static unsigned char ascii_intro = DEFAULT_R;
479 #define FOLD_MARGIN 10
480 #define DEFAULT_FOLD 60
482 static int fold_margin = FOLD_MARGIN;
486 #ifdef DEFAULT_CODE_JIS
487 # define DEFAULT_CONV j_oconv
489 #ifdef DEFAULT_CODE_SJIS
490 # define DEFAULT_CONV s_oconv
492 #ifdef DEFAULT_CODE_EUC
493 # define DEFAULT_CONV e_oconv
495 #ifdef DEFAULT_CODE_UTF8
496 # define DEFAULT_CONV w_oconv
499 /* process default */
500 static void (*output_conv)PROTO((int c2,int c1)) = DEFAULT_CONV;
502 static void (*oconv)PROTO((int c2,int c1)) = no_connection;
503 /* s_iconv or oconv */
504 static int (*iconv)PROTO((int c2,int c1,int c0)) = no_connection2;
506 static void (*o_zconv)PROTO((int c2,int c1)) = no_connection;
507 static void (*o_fconv)PROTO((int c2,int c1)) = no_connection;
508 static void (*o_crconv)PROTO((int c2,int c1)) = no_connection;
509 static void (*o_rot_conv)PROTO((int c2,int c1)) = no_connection;
510 static void (*o_hira_conv)PROTO((int c2,int c1)) = no_connection;
511 static void (*o_base64conv)PROTO((int c2,int c1)) = no_connection;
512 static void (*o_iso2022jp_check_conv)PROTO((int c2,int c1)) = no_connection;
514 /* static redirections */
516 static void (*o_putc)PROTO((int c)) = std_putc;
518 static int (*i_getc)PROTO((FILE *f)) = std_getc; /* general input */
519 static int (*i_ungetc)PROTO((int c,FILE *f)) =std_ungetc;
521 static int (*i_bgetc)PROTO((FILE *)) = std_getc; /* input of mgetc */
522 static int (*i_bungetc)PROTO((int c ,FILE *f)) = std_ungetc;
524 static void (*o_mputc)PROTO((int c)) = std_putc ; /* output of mputc */
526 static int (*i_mgetc)PROTO((FILE *)) = std_getc; /* input of mgetc */
527 static int (*i_mungetc)PROTO((int c ,FILE *f)) = std_ungetc;
529 /* for strict mime */
530 static int (*i_mgetc_buf)PROTO((FILE *)) = std_getc; /* input of mgetc_buf */
531 static int (*i_mungetc_buf)PROTO((int c,FILE *f)) = std_ungetc;
534 static int output_mode = ASCII, /* output kanji mode */
535 input_mode = ASCII, /* input kanji mode */
536 shift_mode = FALSE; /* TRUE shift out, or X0201 */
537 static int mime_decode_mode = FALSE; /* MIME mode B base64, Q hex */
539 /* X0201 / X0208 conversion tables */
541 /* X0201 kana conversion table */
544 unsigned char cv[]= {
545 0x21,0x21,0x21,0x23,0x21,0x56,0x21,0x57,
546 0x21,0x22,0x21,0x26,0x25,0x72,0x25,0x21,
547 0x25,0x23,0x25,0x25,0x25,0x27,0x25,0x29,
548 0x25,0x63,0x25,0x65,0x25,0x67,0x25,0x43,
549 0x21,0x3c,0x25,0x22,0x25,0x24,0x25,0x26,
550 0x25,0x28,0x25,0x2a,0x25,0x2b,0x25,0x2d,
551 0x25,0x2f,0x25,0x31,0x25,0x33,0x25,0x35,
552 0x25,0x37,0x25,0x39,0x25,0x3b,0x25,0x3d,
553 0x25,0x3f,0x25,0x41,0x25,0x44,0x25,0x46,
554 0x25,0x48,0x25,0x4a,0x25,0x4b,0x25,0x4c,
555 0x25,0x4d,0x25,0x4e,0x25,0x4f,0x25,0x52,
556 0x25,0x55,0x25,0x58,0x25,0x5b,0x25,0x5e,
557 0x25,0x5f,0x25,0x60,0x25,0x61,0x25,0x62,
558 0x25,0x64,0x25,0x66,0x25,0x68,0x25,0x69,
559 0x25,0x6a,0x25,0x6b,0x25,0x6c,0x25,0x6d,
560 0x25,0x6f,0x25,0x73,0x21,0x2b,0x21,0x2c,
564 /* X0201 kana conversion table for daguten */
567 unsigned char dv[]= {
568 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
569 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
570 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
571 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
572 0x00,0x00,0x00,0x00,0x00,0x00,0x25,0x74,
573 0x00,0x00,0x00,0x00,0x25,0x2c,0x25,0x2e,
574 0x25,0x30,0x25,0x32,0x25,0x34,0x25,0x36,
575 0x25,0x38,0x25,0x3a,0x25,0x3c,0x25,0x3e,
576 0x25,0x40,0x25,0x42,0x25,0x45,0x25,0x47,
577 0x25,0x49,0x00,0x00,0x00,0x00,0x00,0x00,
578 0x00,0x00,0x00,0x00,0x25,0x50,0x25,0x53,
579 0x25,0x56,0x25,0x59,0x25,0x5c,0x00,0x00,
580 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
581 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
582 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
583 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
586 /* X0201 kana conversion table for han-daguten */
589 unsigned char ev[]= {
590 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
591 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
592 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
593 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
594 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
595 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
596 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
597 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
598 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
599 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
600 0x00,0x00,0x00,0x00,0x25,0x51,0x25,0x54,
601 0x25,0x57,0x25,0x5a,0x25,0x5d,0x00,0x00,
602 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
603 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
604 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
605 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
609 /* X0208 kigou conversion table */
610 /* 0x8140 - 0x819e */
612 unsigned char fv[] = {
614 0x00,0x00,0x00,0x00,0x2c,0x2e,0x00,0x3a,
615 0x3b,0x3f,0x21,0x00,0x00,0x27,0x60,0x00,
616 0x5e,0x00,0x5f,0x00,0x00,0x00,0x00,0x00,
617 0x00,0x00,0x00,0x00,0x00,0x2d,0x00,0x2f,
618 0x5c,0x00,0x00,0x7c,0x00,0x00,0x60,0x27,
619 0x22,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,
620 0x7b,0x7d,0x3c,0x3e,0x00,0x00,0x00,0x00,
621 0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,
622 0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,
623 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
624 0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40,
625 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
631 static int file_out = FALSE;
633 static int overwrite = FALSE;
636 static int crmode_f = 0; /* CR, NL, CRLF */
637 #ifdef EASYWIN /*Easy Win */
638 static int end_check;
653 #ifdef EASYWIN /*Easy Win */
654 _BufferSize.y = 400;/*Set Scroll Buffer Size*/
657 for (argc--,argv++; (argc > 0) && **argv == '-'; argc--, argv++) {
658 cp = (unsigned char *)*argv;
663 if (pipe(fds) < 0 || (pid = fork()) < 0){
674 execvp(argv[1], &argv[1]);
688 if(x0201_f == WISH_TRUE)
689 x0201_f = ((!iso2022jp_f)? TRUE : NO_X0201);
691 if (binmode_f == TRUE)
693 if (freopen("","wb",stdout) == NULL)
700 setbuf(stdout, (char *) NULL);
702 setvbuffer(stdout, stdobuf, IOBUF_SIZE);
705 if (binmode_f == TRUE)
707 if (freopen("","rb",stdin) == NULL) return (-1);
711 setvbuffer(stdin, stdibuf, IOBUF_SIZE);
715 kanji_convert(stdin);
716 if (guess_f) print_guessed_code(NULL);
721 if ((fin = fopen((origfname = *argv++), "r")) == NULL) {
730 /* reopen file for stdout */
731 if (file_out == TRUE) {
734 outfname = malloc(strlen(origfname)
735 + strlen(".nkftmpXXXXXX")
741 strcpy(outfname, origfname);
745 for (i = strlen(outfname); i; --i){
746 if (outfname[i - 1] == '/'
747 || outfname[i - 1] == '\\'){
753 strcat(outfname, "ntXXXXXX");
755 fd = open(outfname, O_WRONLY | O_CREAT | O_TRUNC,
758 strcat(outfname, ".nkftmpXXXXXX");
759 fd = mkstemp(outfname);
762 || (fd_backup = dup(fileno(stdout))) < 0
763 || dup2(fd, fileno(stdout)) < 0
774 outfname = "nkf.out";
777 if(freopen(outfname, "w", stdout) == NULL) {
781 if (binmode_f == TRUE) {
783 if (freopen("","wb",stdout) == NULL)
790 if (binmode_f == TRUE)
792 if (freopen("","rb",fin) == NULL)
797 setvbuffer(fin, stdibuf, IOBUF_SIZE);
801 char *filename = NULL;
803 if (nfiles > 1) filename = origfname;
804 if (guess_f) print_guessed_code(filename);
810 #if defined(MSDOS) && !defined(__MINGW32__)
818 if (dup2(fd_backup, fileno(stdout)) < 0){
821 if (stat(origfname, &sb)) {
822 fprintf(stderr, "Can't stat %s\n", origfname);
824 /*
\e$B%Q!<%_%C%7%g%s$rI|85
\e(B */
825 if (chmod(outfname, sb.st_mode)) {
826 fprintf(stderr, "Can't set permission %s\n", outfname);
829 /*
\e$B%?%$%`%9%?%s%W$rI|85
\e(B */
830 #if defined(MSDOS) && !defined(__MINGW32__)
831 tb[0] = tb[1] = sb.st_mtime;
832 if (utime(outfname, tb)) {
833 fprintf(stderr, "Can't set timestamp %s\n", outfname);
836 tb.actime = sb.st_atime;
837 tb.modtime = sb.st_mtime;
838 if (utime(outfname, &tb)) {
839 fprintf(stderr, "Can't set timestamp %s\n", outfname);
843 if (unlink(origfname)){
847 if (rename(outfname, origfname)) {
849 fprintf(stderr, "Can't rename %s to %s\n",
850 outfname, origfname);
858 #ifdef EASYWIN /*Easy Win */
859 if (file_out == FALSE)
860 scanf("%d",&end_check);
863 #else /* for Other OS */
864 if (file_out == TRUE)
894 {"katakana-hiragana","h3"},
896 #ifdef UTF8_OUTPUT_ENABLE
901 #ifdef UTF8_INPUT_ENABLE
903 {"utf16-input", "W16"},
912 #ifdef NUMCHAR_OPTION
913 {"numchar-input", ""},
919 #ifdef SHIFTJIS_CP932
930 static int option_mode = 0;
949 case '-': /* literal options */
950 if (!*cp) { /* ignore the rest of arguments */
954 for (i=0;i<sizeof(long_option)/sizeof(long_option[0]);i++) {
956 p = (unsigned char *)long_option[i].name;
957 for (j=0;*p && (*p != '=') && *p == cp[j];p++, j++);
958 if (!*p || *p == cp[j]){
965 cp = (unsigned char *)long_option[i].alias;
968 if (strcmp(long_option[i].name, "overwrite") == 0){
975 if (strcmp(long_option[i].name, "cap-input") == 0){
979 if (strcmp(long_option[i].name, "url-input") == 0){
984 #ifdef NUMCHAR_OPTION
985 if (strcmp(long_option[i].name, "numchar-input") == 0){
991 if (strcmp(long_option[i].name, "no-output") == 0){
995 if (strcmp(long_option[i].name, "debug") == 0){
1000 #ifdef SHIFTJIS_CP932
1001 if (strcmp(long_option[i].name, "no-cp932") == 0){
1005 if (strcmp(long_option[i].name, "cp932inv") == 0){
1011 if (strcmp(long_option[i].name, "exec-in") == 0){
1015 if (strcmp(long_option[i].name, "exec-out") == 0){
1020 #ifdef UTF8_OUTPUT_ENABLE
1021 if (strcmp(long_option[i].name, "ms-ucs-map") == 0){
1022 ms_ucs_map_f = TRUE;
1026 if (strcmp(long_option[i].name, "prefix=") == 0){
1027 if (*p == '=' && ' ' < p[1] && p[1] < 128){
1028 for (i = 2; ' ' < p[i] && p[i] < 128; i++){
1029 prefix_table[p[i]] = p[1];
1036 case 'b': /* buffered mode */
1039 case 'u': /* non bufferd mode */
1042 case 't': /* transparent mode */
1045 case 'j': /* JIS output */
1047 output_conv = j_oconv;
1049 case 'e': /* AT&T EUC output */
1050 output_conv = e_oconv;
1052 case 's': /* SJIS output */
1053 output_conv = s_oconv;
1055 case 'l': /* ISO8859 Latin-1 support, no conversion */
1056 iso8859_f = TRUE; /* Only compatible with ISO-2022-JP */
1057 input_f = LATIN1_INPUT;
1059 case 'i': /* Kanji IN ESC-$-@/B */
1060 if (*cp=='@'||*cp=='B')
1061 kanji_intro = *cp++;
1063 case 'o': /* ASCII IN ESC-(-J/B */
1064 if (*cp=='J'||*cp=='B'||*cp=='H')
1065 ascii_intro = *cp++;
1072 if ('9'>= *cp && *cp>='0')
1073 hira_f |= (*cp++ -'0');
1080 #if defined(MSDOS) || defined(__OS2__)
1095 #ifdef UTF8_OUTPUT_ENABLE
1096 case 'w': /* UTF-8 output */
1097 if ('1'== cp[0] && '6'==cp[1]) {
1098 output_conv = w_oconv16; cp+=2;
1100 unicode_bom_f=2; cp++;
1103 unicode_bom_f=1; cp++;
1105 } else if (cp[0] == 'B') {
1106 unicode_bom_f=2; cp++;
1108 unicode_bom_f=1; cp++;
1111 } else if (cp[0] == '8') {
1112 output_conv = w_oconv; cp++;
1115 unicode_bom_f=1; cp++;
1118 output_conv = w_oconv;
1121 #ifdef UTF8_INPUT_ENABLE
1122 case 'W': /* UTF-8 input */
1123 if ('1'== cp[0] && '6'==cp[1]) {
1124 input_f = UTF16LE_INPUT;
1127 } else if (cp[0] == 'B') {
1129 input_f = UTF16BE_INPUT;
1131 } else if (cp[0] == '8') {
1133 input_f = UTF8_INPUT;
1135 input_f = UTF8_INPUT;
1138 /* Input code assumption */
1139 case 'J': /* JIS input */
1140 case 'E': /* AT&T EUC input */
1141 input_f = JIS_INPUT;
1143 case 'S': /* MS Kanji input */
1144 input_f = SJIS_INPUT;
1145 if (x0201_f==NO_X0201) x0201_f=TRUE;
1147 case 'Z': /* Convert X0208 alphabet to asii */
1148 /* bit:0 Convert X0208
1149 bit:1 Convert Kankaku to one space
1150 bit:2 Convert Kankaku to two spaces
1151 bit:3 Convert HTML Entity
1153 if ('9'>= *cp && *cp>='0')
1154 alpha_f |= 1<<(*cp++ -'0');
1158 case 'x': /* Convert X0201 kana to X0208 or X0201 Conversion */
1159 x0201_f = FALSE; /* No X0201->X0208 conversion */
1161 ESC-(-I in JIS, EUC, MS Kanji
1162 SI/SO in JIS, EUC, MS Kanji
1163 SSO in EUC, JIS, not in MS Kanji
1164 MS Kanji (0xa0-0xdf)
1166 ESC-(-I in JIS (0x20-0x5f)
1167 SSO in EUC (0xa0-0xdf)
1168 0xa0-0xd in MS Kanji (0xa0-0xdf)
1171 case 'X': /* Assume X0201 kana */
1172 /* Default value is NO_X0201 for EUC/MS-Kanji mix */
1175 case 'F': /* prserve new lines */
1176 fold_preserve_f = TRUE;
1177 case 'f': /* folding -f60 or -f */
1180 while('0'<= *cp && *cp <='9') { /* we don't use atoi here */
1182 fold_len += *cp++ - '0';
1184 if (!(0<fold_len && fold_len<BUFSIZ))
1185 fold_len = DEFAULT_FOLD;
1189 while('0'<= *cp && *cp <='9') { /* we don't use atoi here */
1191 fold_margin += *cp++ - '0';
1195 case 'm': /* MIME support */
1196 if (*cp=='B'||*cp=='Q') {
1197 mime_decode_mode = *cp++;
1198 mimebuf_f = FIXED_MIME;
1199 } else if (*cp=='N') {
1200 mime_f = TRUE; cp++;
1201 } else if (*cp=='S') {
1202 mime_f = STRICT_MIME; cp++;
1203 } else if (*cp=='0') {
1204 mime_f = FALSE; cp++;
1207 case 'M': /* MIME output */
1210 mimeout_f = FIXED_MIME; cp++;
1211 } else if (*cp=='Q') {
1213 mimeout_f = FIXED_MIME; cp++;
1218 case 'B': /* Broken JIS support */
1220 bit:1 allow any x on ESC-(-x or ESC-$-x
1221 bit:2 reset to ascii on NL
1223 if ('9'>= *cp && *cp>='0')
1224 broken_f |= 1<<(*cp++ -'0');
1229 case 'O':/* for Output file */
1233 case 'c':/* add cr code */
1236 case 'd':/* delete cr code */
1239 case 'I': /* ISO-2022-JP output */
1242 case 'L': /* line mode */
1243 if (*cp=='u') { /* unix */
1244 crmode_f = NL; cp++;
1245 } else if (*cp=='m') { /* mac */
1246 crmode_f = CR; cp++;
1247 } else if (*cp=='w') { /* windows */
1248 crmode_f = CRLF; cp++;
1249 } else if (*cp=='0') { /* no conversion */
1259 /* module muliple options in a string are allowed for Perl moudle */
1260 while(*cp && *cp!='-') cp++;
1264 /* bogus option but ignored */
1270 #ifdef ANSI_C_PROTOTYPE
1271 struct input_code * find_inputcode_byfunc(int (*iconv_func)(int c2,int c1,int c0))
1273 struct input_code * find_inputcode_byfunc(iconv_func)
1274 int (*iconv_func)();
1278 struct input_code *p = input_code_list;
1280 if (iconv_func == p->iconv_func){
1289 #ifdef ANSI_C_PROTOTYPE
1290 void set_iconv(int f, int (*iconv_func)(int c2,int c1,int c0))
1292 void set_iconv(f, iconv_func)
1294 int (*iconv_func)();
1298 static int (*iconv_for_check)() = 0;
1300 #ifdef INPUT_CODE_FIX
1308 #ifdef INPUT_CODE_FIX
1309 && (f == -TRUE || !input_f) /* -TRUE means "FORCE" */
1315 if (estab_f && iconv_for_check != iconv){
1316 struct input_code *p = find_inputcode_byfunc(iconv);
1318 set_input_codename(p->name);
1319 debug(input_codename);
1321 iconv_for_check = iconv;
1326 #define SCORE_L2 (1) /*
\e$BBh
\e(B2
\e$B?e=`4A;z
\e(B */
1327 #define SCORE_KANA (SCORE_L2 << 1) /*
\e$B$$$o$f$kH>3Q%+%J
\e(B */
1328 #define SCORE_DEPEND (SCORE_KANA << 1) /*
\e$B5!<o0MB8J8;z
\e(B */
1329 #ifdef SHIFTJIS_CP932
1330 #define SCORE_CP932 (SCORE_DEPEND << 1) /* CP932
\e$B$K$h$kFI$_49$(
\e(B */
1331 #define SCORE_NO_EXIST (SCORE_CP932 << 1) /*
\e$BB8:_$7$J$$J8;z
\e(B */
1333 #define SCORE_NO_EXIST (SCORE_DEPEND << 1) /*
\e$BB8:_$7$J$$J8;z
\e(B */
1335 #define SCORE_iMIME (SCORE_NO_EXIST << 1) /* MIME
\e$B$K$h$k;XDj
\e(B */
1336 #define SCORE_ERROR (SCORE_iMIME << 1) /*
\e$B%(%i!<
\e(B */
1338 #define SCORE_INIT (SCORE_iMIME)
1340 int score_table_A0[] = {
1343 0, SCORE_DEPEND, SCORE_DEPEND, SCORE_DEPEND,
1344 SCORE_DEPEND, SCORE_DEPEND, SCORE_DEPEND, SCORE_NO_EXIST,
1347 int score_table_F0[] = {
1348 SCORE_L2, SCORE_L2, SCORE_L2, SCORE_L2,
1349 SCORE_L2, SCORE_DEPEND, SCORE_NO_EXIST, SCORE_NO_EXIST,
1350 SCORE_DEPEND, SCORE_DEPEND, SCORE_DEPEND, SCORE_DEPEND,
1351 SCORE_DEPEND, SCORE_NO_EXIST, SCORE_NO_EXIST, SCORE_ERROR,
1354 void set_code_score(ptr, score)
1355 struct input_code *ptr;
1359 ptr->score |= score;
1363 void clr_code_score(ptr, score)
1364 struct input_code *ptr;
1368 ptr->score &= ~score;
1372 void code_score(ptr)
1373 struct input_code *ptr;
1375 int c2 = ptr->buf[0];
1376 int c1 = ptr->buf[1];
1378 set_code_score(ptr, SCORE_ERROR);
1379 }else if (c2 == SSO){
1380 set_code_score(ptr, SCORE_KANA);
1381 #ifdef UTF8_OUTPUT_ENABLE
1382 }else if (!e2w_conv(c2, c1)){
1383 set_code_score(ptr, SCORE_NO_EXIST);
1385 }else if ((c2 & 0x70) == 0x20){
1386 set_code_score(ptr, score_table_A0[c2 & 0x0f]);
1387 }else if ((c2 & 0x70) == 0x70){
1388 set_code_score(ptr, score_table_F0[c2 & 0x0f]);
1389 }else if ((c2 & 0x70) >= 0x50){
1390 set_code_score(ptr, SCORE_L2);
1394 void status_disable(ptr)
1395 struct input_code *ptr;
1400 if (iconv == ptr->iconv_func) set_iconv(FALSE, 0);
1403 void status_push_ch(ptr, c)
1404 struct input_code *ptr;
1407 ptr->buf[ptr->index++] = c;
1410 void status_clear(ptr)
1411 struct input_code *ptr;
1417 void status_reset(ptr)
1418 struct input_code *ptr;
1421 ptr->score = SCORE_INIT;
1424 void status_reinit(ptr)
1425 struct input_code *ptr;
1428 ptr->_file_stat = 0;
1431 void status_check(ptr, c)
1432 struct input_code *ptr;
1435 if (c <= DEL && estab_f){
1440 void s_status(ptr, c)
1441 struct input_code *ptr;
1446 status_check(ptr, c);
1451 #ifdef NUMCHAR_OPTION
1452 }else if ((c & CLASS_MASK) == CLASS_UTF16){
1455 }else if (0xa1 <= c && c <= 0xdf){
1456 status_push_ch(ptr, SSO);
1457 status_push_ch(ptr, c);
1460 }else if ((0x81 <= c && c < 0xa0) || (0xe0 <= c && c <= 0xef)){
1462 status_push_ch(ptr, c);
1463 #ifdef SHIFTJIS_CP932
1465 && CP932_TABLE_BEGIN <= c && c <= CP932_TABLE_END){
1467 status_push_ch(ptr, c);
1468 #endif /* SHIFTJIS_CP932 */
1470 status_disable(ptr);
1474 if ((0x40 <= c && c <= 0x7e) || (0x80 <= c && c <= 0xfc)){
1475 status_push_ch(ptr, c);
1476 s2e_conv(ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]);
1480 status_disable(ptr);
1483 #ifdef SHIFTJIS_CP932
1485 if ((0x40 <= c && c <= 0x7e) || (0x80 <= c && c <= 0xfc)){
1486 status_push_ch(ptr, c);
1487 if (s2e_conv(ptr->buf[0], ptr->buf[1], &ptr->buf[0], &ptr->buf[1]) == 0){
1488 set_code_score(ptr, SCORE_CP932);
1493 status_disable(ptr);
1495 #endif /* SHIFTJIS_CP932 */
1499 void e_status(ptr, c)
1500 struct input_code *ptr;
1505 status_check(ptr, c);
1510 #ifdef NUMCHAR_OPTION
1511 }else if ((c & CLASS_MASK) == CLASS_UTF16){
1514 }else if (SSO == c || (0xa1 <= c && c <= 0xfe)){
1516 status_push_ch(ptr, c);
1518 status_disable(ptr);
1522 if (0xa1 <= c && c <= 0xfe){
1523 status_push_ch(ptr, c);
1527 status_disable(ptr);
1533 #ifdef UTF8_INPUT_ENABLE
1534 void w16_status(ptr, c)
1535 struct input_code *ptr;
1542 if (ptr->_file_stat == 0){
1543 if (c == 0xfe || c == 0xff){
1545 status_push_ch(ptr, c);
1546 ptr->_file_stat = 1;
1548 status_disable(ptr);
1549 ptr->_file_stat = -1;
1551 }else if (ptr->_file_stat > 0){
1553 status_push_ch(ptr, c);
1554 }else if (ptr->_file_stat < 0){
1555 status_disable(ptr);
1561 status_disable(ptr);
1562 ptr->_file_stat = -1;
1564 status_push_ch(ptr, c);
1571 if (ptr->stat != c && (c == 0xfe || c == 0xff)){
1572 status_push_ch(ptr, c);
1575 status_disable(ptr);
1576 ptr->_file_stat = -1;
1582 void w_status(ptr, c)
1583 struct input_code *ptr;
1588 status_check(ptr, c);
1593 #ifdef NUMCHAR_OPTION
1594 }else if ((c & CLASS_MASK) == CLASS_UTF16){
1597 }else if (0xc0 <= c && c <= 0xdf){
1599 status_push_ch(ptr, c);
1600 }else if (0xe0 <= c && c <= 0xef){
1602 status_push_ch(ptr, c);
1604 status_disable(ptr);
1609 if (0x80 <= c && c <= 0xbf){
1610 status_push_ch(ptr, c);
1611 if (ptr->index > ptr->stat){
1612 int bom = (ptr->buf[0] == 0xef && ptr->buf[1] == 0xbb
1613 && ptr->buf[2] == 0xbf);
1614 w2e_conv(ptr->buf[0], ptr->buf[1], ptr->buf[2],
1615 &ptr->buf[0], &ptr->buf[1]);
1622 status_disable(ptr);
1633 int action_flag = 1;
1634 struct input_code *result = 0;
1635 struct input_code *p = input_code_list;
1637 (p->status_func)(p, c);
1640 }else if(p->stat == 0){
1651 if (result && !estab_f){
1652 set_iconv(TRUE, result->iconv_func);
1653 }else if (c <= DEL){
1654 struct input_code *ptr = input_code_list;
1664 #define STD_GC_BUFSIZE (256)
1665 int std_gc_buf[STD_GC_BUFSIZE];
1675 return std_gc_buf[--std_gc_ndx];
1687 if (std_gc_ndx == STD_GC_BUFSIZE){
1690 std_gc_buf[std_gc_ndx++] = c;
1710 while ((c = (*i_getc)(f)) != EOF)
1719 oconv = output_conv;
1722 /* replace continucation module, from output side */
1724 /* output redicrection */
1726 if (noout_f || guess_f){
1733 if (mimeout_f == TRUE) {
1734 o_base64conv = oconv; oconv = base64_conv;
1736 /* base64_count = 0; */
1740 o_crconv = oconv; oconv = cr_conv;
1743 o_rot_conv = oconv; oconv = rot_conv;
1746 o_iso2022jp_check_conv = oconv; oconv = iso2022jp_check_conv;
1749 o_hira_conv = oconv; oconv = hira_conv;
1752 o_fconv = oconv; oconv = fold_conv;
1755 if (alpha_f || x0201_f) {
1756 o_zconv = oconv; oconv = z_conv;
1760 i_ungetc = std_ungetc;
1761 /* input redicrection */
1764 i_cgetc = i_getc; i_getc = cap_getc;
1765 i_cungetc = i_ungetc; i_ungetc= cap_ungetc;
1768 i_ugetc = i_getc; i_getc = url_getc;
1769 i_uungetc = i_ungetc; i_ungetc= url_ungetc;
1772 #ifdef NUMCHAR_OPTION
1774 i_ngetc = i_getc; i_getc = numchar_getc;
1775 i_nungetc = i_ungetc; i_ungetc= numchar_ungetc;
1778 if (mime_f && mimebuf_f==FIXED_MIME) {
1779 i_mgetc = i_getc; i_getc = mime_getc;
1780 i_mungetc = i_ungetc; i_ungetc = mime_ungetc;
1783 i_bgetc = i_getc; i_getc = broken_getc;
1784 i_bungetc = i_ungetc; i_ungetc = broken_ungetc;
1786 if (input_f == JIS_INPUT || input_f == LATIN1_INPUT) {
1787 set_iconv(-TRUE, e_iconv);
1788 } else if (input_f == SJIS_INPUT) {
1789 set_iconv(-TRUE, s_iconv);
1790 #ifdef UTF8_INPUT_ENABLE
1791 } else if (input_f == UTF8_INPUT) {
1792 set_iconv(-TRUE, w_iconv);
1793 } else if (input_f == UTF16LE_INPUT) {
1794 set_iconv(-TRUE, w_iconv16);
1797 set_iconv(FALSE, e_iconv);
1801 struct input_code *p = input_code_list;
1809 Conversion main loop. Code detection only.
1819 module_connection();
1824 output_mode = ASCII;
1827 #define NEXT continue /* no output, get next */
1828 #define SEND ; /* output c1 and c2, get next */
1829 #define LAST break /* end of loop, go closing */
1831 while ((c1 = (*i_getc)(f)) != EOF) {
1836 /* in case of 8th bit is on */
1838 /* in case of not established yet */
1839 /* It is still ambiguious */
1840 if (h_conv(f, c2, c1)==EOF)
1846 /* in case of already established */
1848 /* ignore bogus code */
1854 /* second byte, 7 bit code */
1855 /* it might be kanji shitfted */
1856 if ((c1 == DEL) || (c1 <= SPACE)) {
1857 /* ignore bogus first code */
1865 #ifdef UTF8_INPUT_ENABLE
1874 #ifdef NUMCHAR_OPTION
1875 } else if ((c1 & CLASS_MASK) == CLASS_UTF16){
1878 } else if (c1 > DEL) {
1880 if (!estab_f && !iso8859_f) {
1881 /* not established yet */
1884 } else { /* estab_f==TRUE */
1889 } else if (SSP<=c1 && c1<0xe0 && iconv == s_iconv) {
1890 /* SJIS X0201 Case... */
1891 if(iso2022jp_f && x0201_f==NO_X0201) {
1892 (*oconv)(GETA1, GETA2);
1899 } else if (c1==SSO && iconv != s_iconv) {
1900 /* EUC X0201 Case */
1901 c1 = (*i_getc)(f); /* skip SSO */
1903 if (SSP<=c1 && c1<0xe0) {
1904 if(iso2022jp_f && x0201_f==NO_X0201) {
1905 (*oconv)(GETA1, GETA2);
1912 } else { /* bogus code, skip SSO and one byte */
1916 /* already established */
1921 } else if ((c1 > SPACE) && (c1 != DEL)) {
1922 /* in case of Roman characters */
1924 /* output 1 shifted byte */
1928 } else if (SPACE<=c1 && c1<(0xe0&0x7f) ){
1929 /* output 1 shifted byte */
1930 if(iso2022jp_f && x0201_f==NO_X0201) {
1931 (*oconv)(GETA1, GETA2);
1938 /* look like bogus code */
1941 } else if (input_mode == X0208) {
1942 /* in case of Kanji shifted */
1945 } else if (c1 == '=' && mime_f && !mime_decode_mode ) {
1946 /* Check MIME code */
1947 if ((c1 = (*i_getc)(f)) == EOF) {
1950 } else if (c1 == '?') {
1951 /* =? is mime conversion start sequence */
1952 if(mime_f == STRICT_MIME) {
1953 /* check in real detail */
1954 if (mime_begin_strict(f) == EOF)
1958 } else if (mime_begin(f) == EOF)
1968 /* normal ASCII code */
1971 } else if (c1 == SI) {
1974 } else if (c1 == SO) {
1977 } else if (c1 == ESC ) {
1978 if ((c1 = (*i_getc)(f)) == EOF) {
1979 /* (*oconv)(0, ESC); don't send bogus code */
1981 } else if (c1 == '$') {
1982 if ((c1 = (*i_getc)(f)) == EOF) {
1984 (*oconv)(0, ESC); don't send bogus code
1985 (*oconv)(0, '$'); */
1987 } else if (c1 == '@'|| c1 == 'B') {
1988 /* This is kanji introduction */
1991 set_input_codename("ISO-2022-JP");
1992 debug(input_codename);
1994 } else if (c1 == '(') {
1995 if ((c1 = (*i_getc)(f)) == EOF) {
1996 /* don't send bogus code
2002 } else if (c1 == '@'|| c1 == 'B') {
2003 /* This is kanji introduction */
2008 /* could be some special code */
2015 } else if (broken_f&0x2) {
2016 /* accept any ESC-(-x as broken code ... */
2026 } else if (c1 == '(') {
2027 if ((c1 = (*i_getc)(f)) == EOF) {
2028 /* don't send bogus code
2030 (*oconv)(0, '('); */
2034 /* This is X0201 kana introduction */
2035 input_mode = X0201; shift_mode = X0201;
2037 } else if (c1 == 'B' || c1 == 'J' || c1 == 'H') {
2038 /* This is X0208 kanji introduction */
2039 input_mode = ASCII; shift_mode = FALSE;
2041 } else if (broken_f&0x2) {
2042 input_mode = ASCII; shift_mode = FALSE;
2047 /* maintain various input_mode here */
2051 } else if ( c1 == 'N' || c1 == 'n' ){
2053 c3 = (*i_getc)(f); /* skip SS2 */
2054 if ( (SPACE<=c3 && c3 < 0x60) || (0xa0<=c3 && c3 < 0xe0)){
2069 } else if ((c1 == NL || c1 == CR) && broken_f&4) {
2070 input_mode = ASCII; set_iconv(FALSE, 0);
2072 } else if (c1 == NL && mime_f && !mime_decode_mode ) {
2073 if ((c1=(*i_getc)(f))!=EOF && c1 == SPACE) {
2081 } else if (c1 == CR && mime_f && !mime_decode_mode ) {
2082 if ((c1=(*i_getc)(f))!=EOF) {
2086 } else if (c1 == NL && (c1=(*i_getc)(f))!=EOF && c1 == SPACE) {
2102 if (input_mode == X0208)
2103 (*oconv)(c2, c1); /* this is JIS, not SJIS/EUC case */
2104 else if (input_mode)
2105 (*oconv)(input_mode, c1); /* other special case */
2106 else if ((*iconv)(c2, c1, 0) < 0){ /* can be EUC/SJIS */
2107 int c0 = (*i_getc)(f);
2110 (*iconv)(c2, c1, c0);
2116 /* goto next_word */
2120 (*iconv)(EOF, 0, 0);
2133 /** it must NOT be in the kanji shifte sequence */
2134 /** it must NOT be written in JIS7 */
2135 /** and it must be after 2 byte 8bit code */
2142 while ((c1 = (*i_getc)(f)) != EOF) {
2148 if (push_hold_buf(c1) == EOF || estab_f){
2154 struct input_code *p = input_code_list;
2155 struct input_code *result = p;
2160 if (p->score < result->score){
2165 set_iconv(FALSE, result->iconv_func);
2170 ** 1) EOF is detected, or
2171 ** 2) Code is established, or
2172 ** 3) Buffer is FULL (but last word is pushed)
2174 ** in 1) and 3) cases, we continue to use
2175 ** Kanji codes by oconv and leave estab_f unchanged.
2180 while (wc < hold_count){
2181 c2 = hold_buf[wc++];
2183 #ifdef NUMCHAR_OPTION
2184 || (c2 & CLASS_MASK) == CLASS_UTF16
2189 }else if (iconv == s_iconv && 0xa1 <= c2 && c2 <= 0xdf){
2190 (*iconv)(X0201, c2, 0);
2193 if (wc < hold_count){
2194 c1 = hold_buf[wc++];
2203 if ((*iconv)(c2, c1, 0) < 0){
2205 if (wc < hold_count){
2206 c0 = hold_buf[wc++];
2215 (*iconv)(c2, c1, c0);
2228 if (hold_count >= HOLD_SIZE*2)
2230 hold_buf[hold_count++] = c2;
2231 return ((hold_count >= HOLD_SIZE*2) ? EOF : hold_count);
2234 int s2e_conv(c2, c1, p2, p1)
2238 #ifdef SHIFTJIS_CP932
2239 if (cp932_f && CP932_TABLE_BEGIN <= c2 && c2 <= CP932_TABLE_END){
2240 extern unsigned short shiftjis_cp932[3][189];
2241 c1 = shiftjis_cp932[c2 - CP932_TABLE_BEGIN][c1 - 0x40];
2242 if (c1 == 0) return 1;
2246 #endif /* SHIFTJIS_CP932 */
2247 c2 = c2 + c2 - ((c2 <= 0x9f) ? SJ0162 : SJ6394);
2249 c1 = c1 - ((c1 > DEL) ? SPACE : 0x1f);
2266 } else if ((c2 == EOF) || (c2 == 0) || c2 < SPACE) {
2269 int ret = s2e_conv(c2, c1, &c2, &c1);
2270 if (ret) return ret;
2283 } else if (c2 == SSO){
2286 } else if ((c2 == EOF) || (c2 == 0) || c2 < SPACE) {
2296 #ifdef UTF8_INPUT_ENABLE
2298 w2e_conv(c2, c1, c0, p2, p1)
2302 extern unsigned short * utf8_to_euc_2bytes[];
2303 extern unsigned short ** utf8_to_euc_3bytes[];
2306 if (0xc0 <= c2 && c2 <= 0xef) {
2307 unsigned short **pp;
2310 if (c0 == 0) return -1;
2311 pp = utf8_to_euc_3bytes[c2 - 0x80];
2312 ret = w_iconv_common(c1, c0, pp, sizeof_utf8_to_euc_C2, p2, p1);
2314 ret = w_iconv_common(c2, c1, utf8_to_euc_2bytes, sizeof_utf8_to_euc_2bytes, p2, p1);
2316 #ifdef NUMCHAR_OPTION
2319 if (p1) *p1 = CLASS_UTF16 | ww16_conv(c2, c1, c0);
2324 } else if (c2 == X0201) {
2337 int ret = w2e_conv(c2, c1, c0, &c2, &c1);
2345 w16w_conv(val, p2, p1, p0)
2353 }else if (val < 0x800){
2354 *p2 = 0xc0 | (val >> 6);
2355 *p1 = 0x80 | (val & 0x3f);
2358 *p2 = 0xe0 | (val >> 12);
2359 *p1 = 0x80 | ((val >> 6) & 0x3f);
2360 *p0 = 0x80 | (val & 0x3f);
2365 ww16_conv(c2, c1, c0)
2370 val = (c2 & 0x0f) << 12;
2371 val |= (c1 & 0x3f) << 6;
2373 }else if (c2 >= 0xc0){
2374 val = (c2 & 0x1f) << 6;
2375 val |= (c1 & 0x3f) << 6;
2383 w16e_conv(val, p2, p1)
2387 extern unsigned short * utf8_to_euc_2bytes[];
2388 extern unsigned short ** utf8_to_euc_3bytes[];
2390 unsigned short **pp;
2394 w16w_conv(val, &c2, &c1, &c0);
2397 pp = utf8_to_euc_3bytes[c2 - 0x80];
2398 psize = sizeof_utf8_to_euc_C2;
2399 ret = w_iconv_common(c1, c0, pp, psize, p2, p1);
2401 pp = utf8_to_euc_2bytes;
2402 psize = sizeof_utf8_to_euc_2bytes;
2403 ret = w_iconv_common(c2, c1, pp, psize, p2, p1);
2405 #ifdef NUMCHAR_OPTION
2408 *p1 = CLASS_UTF16 | val;
2417 w_iconv16(c2, c1, c0)
2422 if (c2==0376 && c1==0377){
2423 utf16_mode = UTF16LE_INPUT;
2425 } else if (c2==0377 && c1==0376){
2426 utf16_mode = UTF16BE_INPUT;
2429 if (c2 != EOF && utf16_mode == UTF16BE_INPUT) {
2431 tmp=c1; c1=c2; c2=tmp;
2433 if ((c2==0 && c1 < 0x80) || c2==EOF) {
2437 ret = w16e_conv(((c2<<8)&0xff00) + c1, &c2, &c1);
2438 if (ret) return ret;
2444 w_iconv_common(c1, c0, pp, psize, p2, p1)
2446 unsigned short **pp;
2454 if (pp == 0) return 1;
2457 if (c1 < 0 || psize <= c1) return 1;
2459 if (p == 0) return 1;
2462 if (c0 < 0 || sizeof_utf8_to_euc_E5B8 <= c0) return 1;
2464 if (val == 0) return 1;
2467 if (c2 == SO) c2 = X0201;
2476 #ifdef UTF8_OUTPUT_ENABLE
2481 extern unsigned short euc_to_utf8_1byte[];
2482 extern unsigned short * euc_to_utf8_2bytes[];
2483 extern unsigned short * euc_to_utf8_2bytes_ms[];
2487 p = euc_to_utf8_1byte;
2490 c2 = (c2&0x7f) - 0x21;
2491 if (0<=c2 && c2<sizeof_euc_to_utf8_2bytes)
2492 p = ms_ucs_map_f ? euc_to_utf8_2bytes_ms[c2] : euc_to_utf8_2bytes[c2];
2497 c1 = (c1 & 0x7f) - 0x21;
2498 if (0<=c1 && c1<sizeof_euc_to_utf8_1byte)
2509 #ifdef NUMCHAR_OPTION
2510 if (c2 == 0 && (c1 & CLASS_MASK) == CLASS_UTF16){
2511 w16w_conv(c1, &c2, &c1, &c0);
2515 if (c0) (*o_putc)(c0);
2524 if (unicode_bom_f==2) {
2532 output_mode = ASCII;
2534 } else if (c2 == ISO8859_1) {
2535 output_mode = ISO8859_1;
2536 (*o_putc)(c1 | 0x080);
2539 w16w_conv((unsigned short)e2w_conv(c2, c1), &c2, &c1, &c0);
2543 if (c0) (*o_putc)(c0);
2558 if (unicode_bom_f==2) {
2560 (*o_putc)((unsigned char)'\377');
2564 (*o_putc)((unsigned char)'\377');
2569 if (c2 == ISO8859_1) {
2572 #ifdef NUMCHAR_OPTION
2573 } else if (c2 == 0 && (c1 & CLASS_MASK) == CLASS_UTF16) {
2574 c2 = (c1 >> 8) & 0xff;
2578 unsigned short val = (unsigned short)e2w_conv(c2, c1);
2579 c2 = (val >> 8) & 0xff;
2598 #ifdef NUMCHAR_OPTION
2599 if (c2 == 0 && (c1 & CLASS_MASK) == CLASS_UTF16){
2600 w16e_conv(c1, &c2, &c1);
2606 } else if (c2 == 0) {
2607 output_mode = ASCII;
2609 } else if (c2 == X0201) {
2610 output_mode = JAPANESE_EUC;
2611 (*o_putc)(SSO); (*o_putc)(c1|0x80);
2612 } else if (c2 == ISO8859_1) {
2613 output_mode = ISO8859_1;
2614 (*o_putc)(c1 | 0x080);
2616 if ((c1<0x21 || 0x7e<c1) ||
2617 (c2<0x21 || 0x7e<c2)) {
2618 set_iconv(FALSE, 0);
2619 return; /* too late to rescue this char */
2621 output_mode = JAPANESE_EUC;
2622 (*o_putc)(c2 | 0x080);
2623 (*o_putc)(c1 | 0x080);
2628 e2s_conv(c2, c1, p2, p1)
2629 int c2, c1, *p2, *p1;
2631 if (p2) *p2 = ((c2 - 1) >> 1) + ((c2 <= 0x5e) ? 0x71 : 0xb1);
2632 if (p1) *p1 = c1 + ((c2 & 1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e);
2640 #ifdef NUMCHAR_OPTION
2641 if (c2 == 0 && (c1 & CLASS_MASK) == CLASS_UTF16){
2642 w16e_conv(c1, &c2, &c1);
2648 } else if (c2 == 0) {
2649 output_mode = ASCII;
2651 } else if (c2 == X0201) {
2652 output_mode = SHIFT_JIS;
2654 } else if (c2 == ISO8859_1) {
2655 output_mode = ISO8859_1;
2656 (*o_putc)(c1 | 0x080);
2658 if ((c1<0x20 || 0x7e<c1) ||
2659 (c2<0x20 || 0x7e<c2)) {
2660 set_iconv(FALSE, 0);
2661 return; /* too late to rescue this char */
2663 output_mode = SHIFT_JIS;
2664 e2s_conv(c2, c1, &c2, &c1);
2666 #ifdef SHIFTJIS_CP932
2668 && CP932INV_TABLE_BEGIN <= c2 && c2 <= CP932INV_TABLE_END){
2669 extern unsigned short cp932inv[2][189];
2670 int c = cp932inv[c2 - CP932INV_TABLE_BEGIN][c1 - 0x40];
2676 #endif /* SHIFTJIS_CP932 */
2679 if (prefix_table[(unsigned char)c1]){
2680 (*o_putc)(prefix_table[(unsigned char)c1]);
2691 #ifdef NUMCHAR_OPTION
2692 if ((c1 & CLASS_MASK) == CLASS_UTF16){
2693 w16e_conv(c1, &c2, &c1);
2697 if (output_mode !=ASCII && output_mode!=ISO8859_1) {
2700 (*o_putc)(ascii_intro);
2701 output_mode = ASCII;
2704 } else if (c2==X0201) {
2705 if (output_mode!=X0201) {
2706 output_mode = X0201;
2712 } else if (c2==ISO8859_1) {
2713 /* iso8859 introduction, or 8th bit on */
2714 /* Can we convert in 7bit form using ESC-'-'-A ?
2716 output_mode = ISO8859_1;
2718 } else if (c2 == 0) {
2719 if (output_mode !=ASCII && output_mode!=ISO8859_1) {
2722 (*o_putc)(ascii_intro);
2723 output_mode = ASCII;
2727 if (output_mode != X0208) {
2728 output_mode = X0208;
2731 (*o_putc)(kanji_intro);
2733 if (c1<0x20 || 0x7e<c1)
2735 if (c2<0x20 || 0x7e<c2)
2747 if (base64_count>50 && !mimeout_mode && c2==0 && c1==SPACE) {
2750 } else if (base64_count>66 && mimeout_mode) {
2751 (*o_base64conv)(EOF,0);
2752 (*o_base64conv)(NL,0);
2753 (*o_base64conv)(SPACE,0);
2755 (*o_base64conv)(c2,c1);
2759 static int broken_buf[3];
2760 static int broken_counter = 0;
2761 static int broken_last = 0;
2768 if (broken_counter>0) {
2769 return broken_buf[--broken_counter];
2772 if (c=='$' && broken_last != ESC
2773 && (input_mode==ASCII || input_mode==X0201)) {
2776 if (c1=='@'|| c1=='B') {
2777 broken_buf[0]=c1; broken_buf[1]=c;
2784 } else if (c=='(' && broken_last != ESC
2785 && (input_mode==X0208 || input_mode==X0201)) { /* ) */
2788 if (c1=='J'|| c1=='B') {
2789 broken_buf[0]=c1; broken_buf[1]=c;
2807 if (broken_counter<2)
2808 broken_buf[broken_counter++]=c;
2812 static int prev_cr = 0;
2820 if (! (c2==0&&c1==NL) ) {
2826 } else if (c1=='\r') {
2828 } else if (c1=='\n') {
2829 if (crmode_f==CRLF) {
2830 (*o_crconv)(0,'\r');
2831 } else if (crmode_f==CR) {
2832 (*o_crconv)(0,'\r');
2836 } else if (c1!='\032' || crmode_f!=NL){
2842 Return value of fold_conv()
2844 \n add newline and output char
2845 \r add newline and output nothing
2848 1 (or else) normal output
2850 fold state in prev (previous character)
2852 >0x80 Japanese (X0208/X0201)
2857 This fold algorthm does not preserve heading space in a line.
2858 This is the main difference from fmt.
2861 #define char_size(c2,c1) (c2?2:1)
2870 if (c1== '\r' && !fold_preserve_f) {
2871 fold_state=0; /* ignore cr */
2872 }else if (c1== '\n'&&f_prev=='\r' && fold_preserve_f) {
2874 fold_state=0; /* ignore cr */
2875 } else if (c1== BS) {
2876 if (f_line>0) f_line--;
2878 } else if (c2==EOF && f_line != 0) { /* close open last line */
2880 } else if ((c1=='\n' && !fold_preserve_f)
2881 || ((c1=='\r'||(c1=='\n'&&f_prev!='\r'))
2882 && fold_preserve_f)) {
2884 if (fold_preserve_f) {
2888 } else if ((f_prev == c1 && !fold_preserve_f)
2889 || (f_prev == '\n' && fold_preserve_f)
2890 ) { /* duplicate newline */
2893 fold_state = '\n'; /* output two newline */
2899 if (f_prev&0x80) { /* Japanese? */
2901 fold_state = 0; /* ignore given single newline */
2902 } else if (f_prev==' ') {
2906 if (++f_line<=fold_len)
2910 fold_state = '\r'; /* fold and output nothing */
2914 } else if (c1=='\f') {
2919 fold_state = '\n'; /* output newline and clear */
2920 } else if ( (c2==0 && c1==' ')||
2921 (c2==0 && c1=='\t')||
2922 (c2=='!'&& c1=='!')) {
2923 /* X0208 kankaku or ascii space */
2924 if (f_prev == ' ') {
2925 fold_state = 0; /* remove duplicate spaces */
2928 if (++f_line<=fold_len)
2929 fold_state = ' '; /* output ASCII space only */
2931 f_prev = ' '; f_line = 0;
2932 fold_state = '\r'; /* fold and output nothing */
2936 prev0 = f_prev; /* we still need this one... , but almost done */
2938 if (c2 || c2==X0201)
2939 f_prev |= 0x80; /* this is Japanese */
2940 f_line += char_size(c2,c1);
2941 if (f_line<=fold_len) { /* normal case */
2944 if (f_line>=fold_len+fold_margin) { /* too many kinsou suspension */
2945 f_line = char_size(c2,c1);
2946 fold_state = '\n'; /* We can't wait, do fold now */
2947 } else if (c2==X0201) {
2948 /* simple kinsoku rules return 1 means no folding */
2949 if (c1==(0xde&0x7f)) fold_state = 1; /*
\e$B!+
\e(B*/
2950 else if (c1==(0xdf&0x7f)) fold_state = 1; /*
\e$B!,
\e(B*/
2951 else if (c1==(0xa4&0x7f)) fold_state = 1; /*
\e$B!#
\e(B*/
2952 else if (c1==(0xa3&0x7f)) fold_state = 1; /*
\e$B!$
\e(B*/
2953 else if (c1==(0xa1&0x7f)) fold_state = 1; /*
\e$B!W
\e(B*/
2954 else if (c1==(0xb0&0x7f)) fold_state = 1; /* - */
2955 else if (SPACE<=c1 && c1<=(0xdf&0x7f)) { /* X0201 */
2957 fold_state = '\n';/* add one new f_line before this character */
2960 fold_state = '\n';/* add one new f_line before this character */
2963 /* kinsoku point in ASCII */
2964 if ( c1==')'|| /* { [ ( */
2975 /* just after special */
2976 } else if (!is_alnum(prev0)) {
2977 f_line = char_size(c2,c1);
2979 } else if ((prev0==' ') || /* ignored new f_line */
2980 (prev0=='\n')|| /* ignored new f_line */
2981 (prev0&0x80)) { /* X0208 - ASCII */
2982 f_line = char_size(c2,c1);
2983 fold_state = '\n';/* add one new f_line before this character */
2985 fold_state = 1; /* default no fold in ASCII */
2989 if (c1=='"') fold_state = 1; /*
\e$B!"
\e(B */
2990 else if (c1=='#') fold_state = 1; /*
\e$B!#
\e(B */
2991 else if (c1=='W') fold_state = 1; /*
\e$B!W
\e(B */
2992 else if (c1=='K') fold_state = 1; /*
\e$B!K
\e(B */
2993 else if (c1=='$') fold_state = 1; /*
\e$B!$
\e(B */
2994 else if (c1=='%') fold_state = 1; /*
\e$B!%
\e(B */
2995 else if (c1=='\'') fold_state = 1; /*
\e$B!\
\e(B */
2996 else if (c1=='(') fold_state = 1; /*
\e$B!(
\e(B */
2997 else if (c1==')') fold_state = 1; /*
\e$B!)
\e(B */
2998 else if (c1=='*') fold_state = 1; /*
\e$B!*
\e(B */
2999 else if (c1=='+') fold_state = 1; /*
\e$B!+
\e(B */
3000 else if (c1==',') fold_state = 1; /*
\e$B!,
\e(B */
3001 /* default no fold in kinsoku */
3004 f_line = char_size(c2,c1);
3005 /* add one new f_line before this character */
3008 f_line = char_size(c2,c1);
3010 /* add one new f_line before this character */
3015 /* terminator process */
3016 switch(fold_state) {
3035 int z_prev2=0,z_prev1=0;
3042 /* if (c2) c1 &= 0x7f; assertion */
3044 if (x0201_f && z_prev2==X0201) { /* X0201 */
3045 if (c1==(0xde&0x7f)) { /*
\e$BByE@
\e(B */
3047 (*o_zconv)(dv[(z_prev1-SPACE)*2],dv[(z_prev1-SPACE)*2+1]);
3049 } else if (c1==(0xdf&0x7f)&&ev[(z_prev1-SPACE)*2]) { /*
\e$BH>ByE@
\e(B */
3051 (*o_zconv)(ev[(z_prev1-SPACE)*2],ev[(z_prev1-SPACE)*2+1]);
3055 (*o_zconv)(cv[(z_prev1-SPACE)*2],cv[(z_prev1-SPACE)*2+1]);
3064 if (x0201_f && c2==X0201) {
3065 if (dv[(c1-SPACE)*2]||ev[(c1-SPACE)*2]) {
3066 /* wait for
\e$BByE@
\e(B or
\e$BH>ByE@
\e(B */
3067 z_prev1 = c1; z_prev2 = c2;
3070 (*o_zconv)(cv[(c1-SPACE)*2],cv[(c1-SPACE)*2+1]);
3075 /* JISX0208 Alphabet */
3076 if (alpha_f && c2 == 0x23 ) {
3078 } else if (alpha_f && c2 == 0x21 ) {
3079 /* JISX0208 Kigou */
3084 } else if (alpha_f&0x4) {
3089 } else if (0x20<c1 && c1<0x7f && fv[c1-0x20]) {
3095 case '>': entity = ">"; break;
3096 case '<': entity = "<"; break;
3097 case '\"': entity = """; break;
3098 case '&': entity = "&"; break;
3101 while (*entity) (*o_zconv)(0, *entity++);
3111 #define rot13(c) ( \
3113 (c <= 'M') ? (c + 13): \
3114 (c <= 'Z') ? (c - 13): \
3116 (c <= 'm') ? (c + 13): \
3117 (c <= 'z') ? (c - 13): \
3121 #define rot47(c) ( \
3123 ( c <= 'O' ) ? (c + 47) : \
3124 ( c <= '~' ) ? (c - 47) : \
3132 if (c2==0 || c2==X0201 || c2==ISO8859_1) {
3138 (*o_rot_conv)(c2,c1);
3145 if ((hira_f & 1) && c2==0x25 && 0x20<c1 && c1<0x74) {
3147 } else if ((hira_f & 2) && c2==0x24 && 0x20<c1 && c1<0x74) {
3150 (*o_hira_conv)(c2,c1);
3155 iso2022jp_check_conv(c2,c1)
3158 static int range[RANGE_NUM_MAX][2] = {
3181 if(c2 >= 0x00 && c2 <= 0x20 && c1 >= 0x7f && c1 <= 0xff) {
3185 if((c2 >= 0x29 && c2 <= 0x2f) || (c2 >= 0x75 && c2 <= 0x7e)) {
3190 for (i = 0; i < RANGE_NUM_MAX; i++) {
3191 start = range[i][0];
3194 if (c >= start && c <= end) {
3199 (*o_iso2022jp_check_conv)(c2,c1);
3203 /* This converts =?ISO-2022-JP?B?HOGE HOGE?= */
3205 unsigned char *mime_pattern[] = {
3206 (unsigned char *)"\075?EUC-JP?B?",
3207 (unsigned char *)"\075?SHIFT_JIS?B?",
3208 (unsigned char *)"\075?ISO-8859-1?Q?",
3209 (unsigned char *)"\075?ISO-8859-1?B?",
3210 (unsigned char *)"\075?ISO-2022-JP?B?",
3211 (unsigned char *)"\075?ISO-2022-JP?Q?",
3212 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
3213 (unsigned char *)"\075?UTF-8?B?",
3214 (unsigned char *)"\075?UTF-8?Q?",
3216 (unsigned char *)"\075?US-ASCII?Q?",
3221 /*
\e$B3:Ev$9$k%3!<%I$NM%@hEY$r>e$2$k$?$a$NL\0u
\e(B */
3222 int (*mime_priority_func[])PROTO((int c2, int c1, int c0)) = {
3223 e_iconv, s_iconv, 0, 0, 0, 0,
3224 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
3230 int mime_encode[] = {
3231 JAPANESE_EUC, SHIFT_JIS,ISO8859_1, ISO8859_1, X0208, X0201,
3232 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
3239 int mime_encode_method[] = {
3240 'B', 'B','Q', 'B', 'B', 'Q',
3241 #if defined(UTF8_INPUT_ENABLE) || defined(UTF8_OUTPUT_ENABLE)
3249 #define MAXRECOVER 20
3251 /* I don't trust portablity of toupper */
3252 #define nkf_toupper(c) (('a'<=c && c<='z')?(c-('a'-'A')):c)
3253 #define nkf_isdigit(c) ('0'<=c && c<='9')
3254 #define nkf_isxdigit(c) (nkf_isdigit(c) || ('a'<=c && c<='f') || ('A'<=c && c <= 'F'))
3259 if (i_getc!=mime_getc) {
3260 i_mgetc = i_getc; i_getc = mime_getc;
3261 i_mungetc = i_ungetc; i_ungetc = mime_ungetc;
3262 if(mime_f==STRICT_MIME) {
3263 i_mgetc_buf = i_mgetc; i_mgetc = mime_getc_buf;
3264 i_mungetc_buf = i_mungetc; i_mungetc = mime_ungetc_buf;
3270 unswitch_mime_getc()
3272 if(mime_f==STRICT_MIME) {
3273 i_mgetc = i_mgetc_buf;
3274 i_mungetc = i_mungetc_buf;
3277 i_ungetc = i_mungetc;
3281 mime_begin_strict(f)
3286 unsigned char *p,*q;
3287 int r[MAXRECOVER]; /* recovery buffer, max mime pattern lenght */
3289 mime_decode_mode = FALSE;
3290 /* =? has been checked */
3292 p = mime_pattern[j];
3295 for(i=2;p[i]>' ';i++) { /* start at =? */
3296 if ( ((r[i] = c1 = (*i_getc)(f))==EOF) || nkf_toupper(c1) != p[i] ) {
3297 /* pattern fails, try next one */
3299 while ((p = mime_pattern[++j])) {
3300 for(k=2;k<i;k++) /* assume length(p) > i */
3301 if (p[k]!=q[k]) break;
3302 if (k==i && nkf_toupper(c1)==p[k]) break;
3304 if (p) continue; /* found next one, continue */
3305 /* all fails, output from recovery buffer */
3313 mime_decode_mode = p[i-2];
3315 clr_code_score(find_inputcode_byfunc(mime_priority_func[j]), SCORE_iMIME);
3317 if (mime_decode_mode=='B') {
3318 mimebuf_f = unbuf_f;
3320 /* do MIME integrity check */
3321 return mime_integrity(f,mime_pattern[j]);
3333 /* we don't keep eof of Fifo, becase it contains ?= as
3334 a terminator. It was checked in mime_integrity. */
3335 return ((mimebuf_f)?
3336 (*i_mgetc_buf)(f):Fifo(mime_input++));
3340 mime_ungetc_buf(c,f)
3345 (*i_mungetc_buf)(c,f);
3347 Fifo(--mime_input)=c;
3358 /* In NONSTRICT mode, only =? is checked. In case of failure, we */
3359 /* re-read and convert again from mime_buffer. */
3361 /* =? has been checked */
3363 Fifo(mime_last++)='='; Fifo(mime_last++)='?';
3364 for(i=2;i<MAXRECOVER;i++) { /* start at =? */
3365 /* We accept any character type even if it is breaked by new lines */
3366 c1 = (*i_getc)(f); Fifo(mime_last++)= c1 ;
3367 if (c1=='\n'||c1==' '||c1=='\r'||
3368 c1=='-'||c1=='_'||is_alnum(c1) ) continue;
3370 /* Failed. But this could be another MIME preemble */
3378 c1 = (*i_getc)(f); Fifo(mime_last++) = c1;
3379 if (!(++i<MAXRECOVER) || c1==EOF) break;
3380 if (c1=='b'||c1=='B') {
3381 mime_decode_mode = 'B';
3382 } else if (c1=='q'||c1=='Q') {
3383 mime_decode_mode = 'Q';
3387 c1 = (*i_getc)(f); Fifo(mime_last++) = c1;
3388 if (!(++i<MAXRECOVER) || c1==EOF) break;
3390 mime_decode_mode = FALSE;
3396 if (!mime_decode_mode) {
3397 /* false MIME premble, restart from mime_buffer */
3398 mime_decode_mode = 1; /* no decode, but read from the mime_buffer */
3399 /* Since we are in MIME mode until buffer becomes empty, */
3400 /* we never go into mime_begin again for a while. */
3403 /* discard mime preemble, and goto MIME mode */
3405 /* do no MIME integrity check */
3406 return c1; /* used only for checking EOF */
3421 fprintf(stderr, "%s\n", str);
3427 set_input_codename (codename)
3432 strcmp(codename, "") != 0 &&
3433 strcmp(codename, input_codename) != 0)
3435 is_inputcode_mixed = TRUE;
3437 input_codename = codename;
3438 is_inputcode_set = TRUE;
3442 print_guessed_code (filename)
3445 char *codename = "BINARY";
3446 if (!is_inputcode_mixed) {
3447 if (strcmp(input_codename, "") == 0) {
3450 codename = input_codename;
3453 if (filename != NULL) printf("%s:", filename);
3454 printf("%s\n", codename);
3461 if (nkf_isdigit(x)) return x - '0';
3462 return nkf_toupper(x) - 'A' + 10;
3467 #ifdef ANSI_C_PROTOTYPE
3468 int hex_getc(int ch, FILE *f, int (*g)(FILE *f), int (*u)(int c, FILE *f))
3471 hex_getc(ch, f, g, u)
3484 if (!nkf_isxdigit(c2)){
3489 if (!nkf_isxdigit(c3)){
3494 return (hex2bin(c2) << 4) | hex2bin(c3);
3501 return hex_getc(':', f, i_cgetc, i_cungetc);
3509 return (*i_cungetc)(c, f);
3516 return hex_getc('%', f, i_ugetc, i_uungetc);
3524 return (*i_uungetc)(c, f);
3528 #ifdef NUMCHAR_OPTION
3533 int (*g)() = i_ngetc;
3534 int (*u)() = i_nungetc;
3545 if (buf[i] == 'x' || buf[i] == 'X'){
3546 for (j = 0; j < 5; j++){
3548 if (!nkf_isxdigit(buf[i])){
3555 c |= hex2bin(buf[i]);
3558 for (j = 0; j < 6; j++){
3562 if (!nkf_isdigit(buf[i])){
3569 c += hex2bin(buf[i]);
3575 return CLASS_UTF16 | c;
3585 numchar_ungetc(c, f)
3589 return (*i_nungetc)(c, f);
3598 int c1, c2, c3, c4, cc;
3599 int t1, t2, t3, t4, mode, exit_mode;
3603 int lwsp_size = 128;
3605 if (mime_top != mime_last) { /* Something is in FIFO */
3606 return Fifo(mime_top++);
3608 if (mime_decode_mode==1 ||mime_decode_mode==FALSE) {
3609 mime_decode_mode=FALSE;
3610 unswitch_mime_getc();
3611 return (*i_getc)(f);
3614 if (mimebuf_f == FIXED_MIME)
3615 exit_mode = mime_decode_mode;
3618 if (mime_decode_mode == 'Q') {
3619 if ((c1 = (*i_mgetc)(f)) == EOF) return (EOF);
3621 if (c1=='_') return ' ';
3622 if (c1!='=' && c1!='?') {
3626 mime_decode_mode = exit_mode; /* prepare for quit */
3627 if (c1<=' ') return c1;
3628 if ((c2 = (*i_mgetc)(f)) == EOF) return (EOF);
3629 if (c1=='?'&&c2=='=' && mimebuf_f != FIXED_MIME) {
3630 /* end Q encoding */
3631 input_mode = exit_mode;
3633 lwsp_buf = malloc((lwsp_size+5)*sizeof(char));
3634 if (lwsp_buf==NULL) {
3635 perror("can't malloc");
3638 while ((c1=(*i_getc)(f))!=EOF) {
3643 if ((c1=(*i_getc)(f))!=EOF && (c1==SPACE||c1==TAB)) {
3651 if ((c1=(*i_getc)(f))!=EOF && c1 == NL) {
3652 if ((c1=(*i_getc)(f))!=EOF && (c1==SPACE||c1==TAB)) {
3667 lwsp_buf[lwsp_count] = c1;
3668 if (lwsp_count++>lwsp_size){
3670 lwsp_buf_new = realloc(lwsp_buf, (lwsp_size+5)*sizeof(char));
3671 if (lwsp_buf_new==NULL) {
3674 perror("can't realloc");
3677 lwsp_buf = lwsp_buf_new;
3683 if (lwsp_count > 0) {
3684 if (c1=='=' && (lwsp_buf[lwsp_count-1]==SPACE||lwsp_buf[lwsp_count-1]==TAB)) {
3688 for(lwsp_count--;lwsp_count>0;lwsp_count--)
3689 i_ungetc(lwsp_buf[lwsp_count],f);
3697 if (c1=='='&&c2<' ') { /* this is soft wrap */
3698 while((c1 = (*i_mgetc)(f)) <=' ') {
3699 if ((c1 = (*i_mgetc)(f)) == EOF) return (EOF);
3701 mime_decode_mode = 'Q'; /* still in MIME */
3702 goto restart_mime_q;
3705 mime_decode_mode = 'Q'; /* still in MIME */
3709 if ((c3 = (*i_mgetc)(f)) == EOF) return (EOF);
3710 if (c2<=' ') return c2;
3711 mime_decode_mode = 'Q'; /* still in MIME */
3712 #define hex(c) (('0'<=c&&c<='9')?(c-'0'):\
3713 ('A'<=c&&c<='F')?(c-'A'+10):('a'<=c&&c<='f')?(c-'a'+10):0)
3714 return ((hex(c2)<<4) + hex(c3));
3717 if (mime_decode_mode != 'B') {
3718 mime_decode_mode = FALSE;
3719 return (*i_mgetc)(f);
3723 /* Base64 encoding */
3725 MIME allows line break in the middle of
3726 Base64, but we are very pessimistic in decoding
3727 in unbuf mode because MIME encoded code may broken by
3728 less or editor's control sequence (such as ESC-[-K in unbuffered
3729 mode. ignore incomplete MIME.
3731 mode = mime_decode_mode;
3732 mime_decode_mode = exit_mode; /* prepare for quit */
3734 while ((c1 = (*i_mgetc)(f))<=' ') {
3739 if ((c2 = (*i_mgetc)(f))<=' ') {
3742 if (mime_f != STRICT_MIME) goto mime_c2_retry;
3743 if (mimebuf_f!=FIXED_MIME) input_mode = ASCII;
3746 if ((c1 == '?') && (c2 == '=')) {
3749 lwsp_buf = malloc((lwsp_size+5)*sizeof(char));
3750 if (lwsp_buf==NULL) {
3751 perror("can't malloc");
3754 while ((c1=(*i_getc)(f))!=EOF) {
3759 if ((c1=(*i_getc)(f))!=EOF && (c1==SPACE||c1==TAB)) {
3767 if ((c1=(*i_getc)(f))!=EOF) {
3771 } else if ((c1=(*i_getc)(f))!=EOF && (c1==SPACE||c1==TAB)) {
3786 lwsp_buf[lwsp_count] = c1;
3787 if (lwsp_count++>lwsp_size){
3789 lwsp_buf_new = realloc(lwsp_buf, (lwsp_size+5)*sizeof(char));
3790 if (lwsp_buf_new==NULL) {
3793 perror("can't realloc");
3796 lwsp_buf = lwsp_buf_new;
3802 if (lwsp_count > 0) {
3803 if (c1=='=' && (lwsp_buf[lwsp_count-1]==SPACE||lwsp_buf[lwsp_count-1]==TAB)) {
3807 for(lwsp_count--;lwsp_count>0;lwsp_count--)
3808 i_ungetc(lwsp_buf[lwsp_count],f);
3817 if ((c3 = (*i_mgetc)(f))<=' ') {
3820 if (mime_f != STRICT_MIME) goto mime_c3_retry;
3821 if (mimebuf_f!=FIXED_MIME) input_mode = ASCII;
3825 if ((c4 = (*i_mgetc)(f))<=' ') {
3828 if (mime_f != STRICT_MIME) goto mime_c4_retry;
3829 if (mimebuf_f!=FIXED_MIME) input_mode = ASCII;
3833 mime_decode_mode = mode; /* still in MIME sigh... */
3835 /* BASE 64 decoding */
3837 t1 = 0x3f & base64decode(c1);
3838 t2 = 0x3f & base64decode(c2);
3839 t3 = 0x3f & base64decode(c3);
3840 t4 = 0x3f & base64decode(c4);
3841 cc = ((t1 << 2) & 0x0fc) | ((t2 >> 4) & 0x03);
3843 Fifo(mime_last++) = cc;
3844 cc = ((t2 << 4) & 0x0f0) | ((t3 >> 2) & 0x0f);
3846 Fifo(mime_last++) = cc;
3847 cc = ((t3 << 6) & 0x0c0) | (t4 & 0x3f);
3849 Fifo(mime_last++) = cc;
3854 return Fifo(mime_top++);
3862 Fifo(--mime_top) = c;
3873 /* In buffered mode, read until =? or NL or buffer full
3875 mime_input = mime_top;
3876 mime_last = mime_top;
3877 while(*p) Fifo(mime_input++) = *p++;
3880 while((c=(*i_getc)(f))!=EOF) {
3881 if (((mime_input-mime_top)&MIME_BUF_MASK)==0) {
3882 break; /* buffer full */
3884 if (c=='=' && d=='?') {
3885 /* checked. skip header, start decode */
3886 Fifo(mime_input++) = c;
3887 /* mime_last_input = mime_input; */
3892 if (!( (c=='+'||c=='/'|| c=='=' || c=='?' || is_alnum(c))))
3894 /* Should we check length mod 4? */
3895 Fifo(mime_input++) = c;
3898 /* In case of Incomplete MIME, no MIME decode */
3899 Fifo(mime_input++) = c;
3900 mime_last = mime_input; /* point undecoded buffer */
3901 mime_decode_mode = 1; /* no decode on Fifo last in mime_getc */
3902 switch_mime_getc(); /* anyway we need buffered getc */
3913 i = c - 'A'; /* A..Z 0-25 */
3915 i = c - 'G' /* - 'a' + 26 */ ; /* a..z 26-51 */
3917 } else if (c > '/') {
3918 i = c - '0' + '4' /* - '0' + 52 */ ; /* 0..9 52-61 */
3919 } else if (c == '+') {
3920 i = '>' /* 62 */ ; /* + 62 */
3922 i = '?' /* 63 */ ; /* / 63 */
3927 static char basis_64[] =
3928 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
3931 #define MIMEOUT_BUF_LENGTH (60)
3932 char mimeout_buf[MIMEOUT_BUF_LENGTH+1];
3933 int mimeout_buf_count = 0;
3934 int mimeout_preserve_space = 0;
3935 #define itoh4(c) (c>=10?c+'A'-10:c+'0')
3944 p = mime_pattern[0];
3945 for(i=0;mime_encode[i];i++) {
3946 if (mode == mime_encode[i]) {
3947 p = mime_pattern[i];
3951 mimeout_mode = mime_encode_method[i];
3954 if (base64_count>45) {
3958 if (!mimeout_preserve_space && mimeout_buf_count>0
3959 && (mimeout_buf[i]==SPACE || mimeout_buf[i]==TAB
3960 || mimeout_buf[i]==CR || mimeout_buf[i]==NL )) {
3964 if (!mimeout_preserve_space) {
3965 for (;i<mimeout_buf_count;i++) {
3966 if (mimeout_buf[i]==SPACE || mimeout_buf[i]==TAB
3967 || mimeout_buf[i]==CR || mimeout_buf[i]==NL ) {
3968 (*o_mputc)(mimeout_buf[i]);
3975 mimeout_preserve_space = FALSE;
3981 j = mimeout_buf_count;
3982 mimeout_buf_count = 0;
3984 mime_putc(mimeout_buf[i]);
4000 switch(mimeout_mode) {
4005 (*o_mputc)(basis_64[((b64c & 0x3)<< 4)]);
4011 (*o_mputc)(basis_64[((b64c & 0xF) << 2)]);
4017 if (mimeout_f!=FIXED_MIME) {
4019 } else if (mimeout_mode != 'Q')
4028 switch(mimeout_mode) {
4032 (*o_mputc)(itoh4(((c>>4)&0xf)));
4033 (*o_mputc)(itoh4((c&0xf)));
4042 (*o_mputc)(basis_64[c>>2]);
4047 (*o_mputc)(basis_64[((b64c & 0x3)<< 4) | ((c & 0xF0) >> 4)]);
4053 (*o_mputc)(basis_64[((b64c & 0xF) << 2) | ((c & 0xC0) >>6)]);
4054 (*o_mputc)(basis_64[c & 0x3F]);
4068 if (mimeout_f==FIXED_MIME && base64_count>50) {
4072 } else if (c==CR||c==NL) {
4075 if (c!=EOF && mimeout_f!=FIXED_MIME) {
4076 if ( c<=DEL &&(output_mode==ASCII ||output_mode == ISO8859_1 ) ) {
4077 if (mimeout_mode=='Q') {
4086 } else if (mimeout_mode) {
4087 if (base64_count>63) {
4092 mimeout_preserve_space = TRUE;
4094 if (c==SPACE || c==TAB || c==CR || c==NL) {
4095 for (i=0;i<mimeout_buf_count;i++) {
4096 if (SPACE<mimeout_buf[i] && mimeout_buf[i]<DEL) {
4098 for (i=0;i<mimeout_buf_count;i++) {
4099 (*o_mputc)(mimeout_buf[i]);
4102 mimeout_buf_count = 0;
4105 mimeout_buf[mimeout_buf_count++] = c;
4106 if (mimeout_buf_count>MIMEOUT_BUF_LENGTH) {
4109 for (i=0;i<mimeout_buf_count;i++) {
4110 (*o_mputc)(mimeout_buf[i]);
4116 if (mimeout_buf_count>0 && SPACE<c) {
4117 mimeout_buf[mimeout_buf_count++] = c;
4118 if (mimeout_buf_count>MIMEOUT_BUF_LENGTH) {
4123 } else if (!mimeout_mode) {
4124 if (c==SPACE || c==TAB || c==CR || c==NL) {
4125 if ((c==CR || c==NL)
4126 &&(mimeout_buf[mimeout_buf_count-1]==SPACE
4127 || mimeout_buf[mimeout_buf_count-1]==TAB)) {
4128 mimeout_buf_count--;
4130 for (i=0;i<mimeout_buf_count;i++) {
4131 (*o_mputc)(mimeout_buf[i]);
4134 mimeout_buf_count = 0;
4136 mimeout_buf[mimeout_buf_count++] = c;
4137 if (mimeout_buf_count>75) {
4138 open_mime(output_mode);
4142 } else if (!mimeout_mode) {
4143 if (mimeout_buf_count>0 && mimeout_buf[mimeout_buf_count-1]==SPACE) {
4144 for (i=0;i<mimeout_buf_count-1;i++) {
4145 (*o_mputc)(mimeout_buf[i]);
4148 mimeout_buf[0] = SPACE;
4149 mimeout_buf_count = 1;
4151 open_mime(output_mode);
4153 } else { /* c==EOF */
4154 j = mimeout_buf_count;
4157 if (mimeout_buf[i]==SPACE || mimeout_buf[i]==TAB
4158 || mimeout_buf[i]==CR || mimeout_buf[i]==NL)
4160 (*mime_putc)(mimeout_buf[i]);
4164 (*o_mputc)(mimeout_buf[i]);
4170 if (mimeout_buf_count>0) {
4171 j = mimeout_buf_count;
4172 mimeout_buf_count = 0;
4174 mimeout_addchar(mimeout_buf[i]);
4186 struct input_code *p = input_code_list;
4199 mime_f = STRICT_MIME;
4204 #if defined(MSDOS) || defined(__OS2__)
4209 iso2022jp_f = FALSE;
4210 #ifdef UTF8_OUTPUT_ENABLE
4213 ms_ucs_map_f = FALSE;
4225 is_inputcode_mixed = FALSE;
4226 is_inputcode_set = FALSE;
4230 #ifdef SHIFTJIS_CP932
4236 for (i = 0; i < 256; i++){
4237 prefix_table[i] = 0;
4240 #ifdef UTF8_INPUT_ENABLE
4241 utf16_mode = UTF16LE_INPUT;
4247 fold_preserve_f = FALSE;
4250 kanji_intro = DEFAULT_J;
4251 ascii_intro = DEFAULT_R;
4252 fold_margin = FOLD_MARGIN;
4253 output_conv = DEFAULT_CONV;
4254 oconv = DEFAULT_CONV;
4255 o_zconv = no_connection;
4256 o_fconv = no_connection;
4257 o_crconv = no_connection;
4258 o_rot_conv = no_connection;
4259 o_hira_conv = no_connection;
4260 o_base64conv = no_connection;
4261 o_iso2022jp_check_conv = no_connection;
4264 i_ungetc = std_ungetc;
4266 i_bungetc = std_ungetc;
4269 i_mungetc = std_ungetc;
4270 i_mgetc_buf = std_getc;
4271 i_mungetc_buf = std_ungetc;
4272 output_mode = ASCII;
4275 mime_decode_mode = FALSE;
4281 z_prev2=0,z_prev1=0;
4287 no_connection(c2,c1)
4290 no_connection2(c2,c1,0);
4294 no_connection2(c2,c1,c0)
4297 fprintf(stderr,"nkf internal module connection failure.\n");
4305 fprintf(stderr,"USAGE: nkf(nkf32,wnkf,nkf2) -[flags] [in file] .. [out file for -O flag]\n");
4306 fprintf(stderr,"Flags:\n");
4307 fprintf(stderr,"b,u Output is buffered (DEFAULT),Output is unbuffered\n");
4308 #ifdef DEFAULT_CODE_SJIS
4309 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit, Shift JIS (DEFAULT), AT&T JIS (EUC), UTF-8\n");
4311 #ifdef DEFAULT_CODE_JIS
4312 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit (DEFAULT), Shift JIS, AT&T JIS (EUC), UTF-8\n");
4314 #ifdef DEFAULT_CODE_EUC
4315 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit, Shift JIS, AT&T JIS (EUC) (DEFAULT), UTF-8\n");
4317 #ifdef DEFAULT_CODE_UTF8
4318 fprintf(stderr,"j,s,e,w Outout code is JIS 7 bit, Shift JIS, AT&T JIS (EUC), UTF-8 (DEFAULT)\n");
4320 #ifdef UTF8_OUTPUT_ENABLE
4321 fprintf(stderr," After 'w' you can add more options. (80?|16((B|L)0?)?) \n");
4323 fprintf(stderr,"J,S,E,W Input assumption is JIS 7 bit , Shift JIS, AT&T JIS (EUC), UTF-8\n");
4324 #ifdef UTF8_INPUT_ENABLE
4325 fprintf(stderr," After 'W' you can add more options. (8|16(B|L)?) \n");
4327 fprintf(stderr,"t no conversion\n");
4328 fprintf(stderr,"i_/o_ Output sequence to designate JIS-kanji/ASCII (DEFAULT B)\n");
4329 fprintf(stderr,"r {de/en}crypt ROT13/47\n");
4330 fprintf(stderr,"h 1 hirakana->katakana, 2 katakana->hirakana,3 both\n");
4331 fprintf(stderr,"v Show this usage. V: show version\n");
4332 fprintf(stderr,"m[BQN0] MIME decode [B:base64,Q:quoted,N:non-strict,0:no decode]\n");
4333 fprintf(stderr,"M[BQ] MIME encode [B:base64 Q:quoted]\n");
4334 fprintf(stderr,"l ISO8859-1 (Latin-1) support\n");
4335 fprintf(stderr,"f/F Folding: -f60 or -f or -f60-10 (fold margin 10) F preserve nl\n");
4336 fprintf(stderr,"Z[0-3] Convert X0208 alphabet to ASCII 1: Kankaku to space,2: 2 spaces,\n");
4337 fprintf(stderr," 3: Convert HTML Entity\n");
4338 fprintf(stderr,"X,x Assume X0201 kana in MS-Kanji, -x preserves X0201\n");
4339 fprintf(stderr,"B[0-2] Broken input 0: missing ESC,1: any X on ESC-[($]-X,2: ASCII on NL\n");
4341 fprintf(stderr,"T Text mode output\n");
4343 fprintf(stderr,"O Output to File (DEFAULT 'nkf.out')\n");
4344 fprintf(stderr,"d,c Delete \\r in line feed and \\032, Add \\r in line feed\n");
4345 fprintf(stderr,"I Convert non ISO-2022-JP charactor to GETA\n");
4346 fprintf(stderr,"-L[uwm] line mode u:LF w:CRLF m:CR (DEFAULT noconversion)\n");
4347 fprintf(stderr,"long name options\n");
4348 fprintf(stderr," --fj,--unix,--mac,--windows convert for the system\n");
4349 fprintf(stderr," --jis,--euc,--sjis,--utf8,--utf16,--mime,--base64 convert for the code\n");
4350 fprintf(stderr," --hiragana, --katakana Hiragana/Katakana Conversion\n");
4352 fprintf(stderr," --cap-input, --url-input Convert hex after ':' or '%'\n");
4354 #ifdef NUMCHAR_OPTION
4355 fprintf(stderr," --numchar-input Convert Unicode Character Reference\n");
4357 #ifdef SHIFTJIS_CP932
4358 fprintf(stderr," --no-cp932 Don't convert Shift_JIS FAxx-FCxx to equivalnet CP932\n");
4359 fprintf(stderr," --cp932inv convert Shift_JIS EDxx-EFxx to equivalnet CP932 FAxx-FCxx\n");
4361 #ifdef UTF8_OUTPUT_ENABLE
4362 fprintf(stderr," --ms-ucs-map Microsoft UCS Mapping Compatible\n");
4365 fprintf(stderr," --overwrite Overwrite original listed files by filtered result\n");
4367 fprintf(stderr," -g, --guess Guess the input code\n");
4368 fprintf(stderr," --help,--version\n");
4375 fprintf(stderr,"Network Kanji Filter Version %s (%s) "
4376 #if defined(MSDOS) && !defined(__WIN32__) && !defined(__WIN16__)
4379 #if defined(MSDOS) && defined(__WIN16__)
4382 #if defined(MSDOS) && defined(__WIN32__)
4388 ,NKF_VERSION,NKF_RELEASE_DATE);
4389 fprintf(stderr,"\n%s\n",CopyRight);
4394 **
\e$B%Q%C%A@):n<T
\e(B
4395 ** void@merope.pleiades.or.jp (Kusakabe Youichi)
4396 ** NIDE Naoyuki <nide@ics.nara-wu.ac.jp>
4397 ** ohta@src.ricoh.co.jp (Junn Ohta)
4398 ** inouet@strl.nhk.or.jp (Tomoyuki Inoue)
4399 ** kiri@pulser.win.or.jp (Tetsuaki Kiriyama)
4400 ** Kimihiko Sato <sato@sail.t.u-tokyo.ac.jp>
4401 ** a_kuroe@kuroe.aoba.yokohama.jp (Akihiko Kuroe)
4402 ** kono@ie.u-ryukyu.ac.jp (Shinji Kono)
4403 ** GHG00637@nifty-serve.or.jp (COW)