OSDN Git Service

* define HELP_OUTPUT and help and version messages are now output to stdout.
authorNARUSE, Yui <naruse@users.sourceforge.jp>
Sun, 23 Dec 2007 16:25:47 +0000 (16:25 +0000)
committerNARUSE, Yui <naruse@users.sourceforge.jp>
Sun, 23 Dec 2007 16:25:47 +0000 (16:25 +0000)
  [nkf-forum#34150]

nkf.c

diff --git a/nkf.c b/nkf.c
index 1ac640a..24d52ad 100644 (file)
--- a/nkf.c
+++ b/nkf.c
@@ -30,7 +30,7 @@
  * \e$B8=:_!"\e(Bnkf \e$B$O\e(B SorceForge \e$B$K$F%a%s%F%J%s%9$,B3$1$i$l$F$$$^$9!#\e(B
  * http://sourceforge.jp/projects/nkf/
 ***********************************************************************/
-/* $Id: nkf.c,v 1.157 2007/12/22 08:07:23 naruse Exp $ */
+/* $Id: nkf.c,v 1.158 2007/12/23 07:25:47 naruse Exp $ */
 #define NKF_VERSION "2.0.8"
 #define NKF_RELEASE_DATE "2007-12-22"
 #define COPY_RIGHT \
 #define PUT_NEWLINE(func) func(0x0A)
 #define OCONV_NEWLINE(func) func(0, 0x0A)
 #endif
+#ifdef HELP_OUTPUT_STDERR
+#define HELP_OUTPUT stderr
+#else
+#define HELP_OUTPUT stdout
+#endif
 
 #if (defined(__TURBOC__) || defined(_MSC_VER) || defined(LSI_C) || defined(__MINGW32__) || defined(__EMX__) || defined(__MSDOS__) || defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)) && !defined(MSDOS)
 #define MSDOS
@@ -471,7 +476,7 @@ struct input_code{
 };
 
 static char *input_codename = NULL; /* NULL: unestablished, "": BINARY */
-static nkf_encoding *output_encoding;\r
+static nkf_encoding *output_encoding;
 
 #if !defined(PERL_XS) && !defined(WIN32DLL)
 static  nkf_char     noconvert(FILE *f);
@@ -941,7 +946,7 @@ static nkf_encoding *nkf_enc_find(const char *name)
     return nkf_enc_from_index(idx);
 }
 
-#define nkf_enc_name(enc) (enc)->name\r
+#define nkf_enc_name(enc) (enc)->name
 #define nkf_enc_to_index(enc) (enc)->id
 #define nkf_enc_to_base_encoding(enc) (enc)->based_encoding
 
@@ -1530,8 +1535,8 @@ void options(unsigned char *cp)
                 if (strcmp(long_option[i].name, "oc=") == 0){
                    x0201_f = FALSE;
                    nkf_str_upcase(p, codeset, 32);
-                   output_encoding = nkf_enc_find(codeset);\r
-                   switch (nkf_enc_to_index(output_encoding)) {\r
+                   output_encoding = nkf_enc_find(codeset);
+                   switch (nkf_enc_to_index(output_encoding)) {
                    case ISO_2022_JP:
                        output_conv = j_oconv;
                        break;
@@ -1906,16 +1911,16 @@ void options(unsigned char *cp)
         case 'j':           /* JIS output */
         case 'n':
             output_conv = j_oconv;
-            output_encoding = nkf_enc_from_index(ISO_2022_JP);\r
+            output_encoding = nkf_enc_from_index(ISO_2022_JP);
             continue;
         case 'e':           /* AT&T EUC output */
             output_conv = e_oconv;
             cp932inv_f = FALSE;
-            output_encoding = nkf_enc_from_index(EUC_JP);\r
+            output_encoding = nkf_enc_from_index(EUC_JP);
             continue;
         case 's':           /* SJIS output */
             output_conv = s_oconv;
-            output_encoding = nkf_enc_from_index(SHIFT_JIS);\r
+            output_encoding = nkf_enc_from_index(SHIFT_JIS);
             continue;
         case 'l':           /* ISO8859 Latin-1 support, no conversion */
             iso8859_f = TRUE;  /* Only compatible with ISO-2022-JP */
@@ -1963,22 +1968,22 @@ void options(unsigned char *cp)
                output_conv = w_oconv; cp++;
                if (cp[0] == '0'){
                    cp++;
-                   output_encoding = nkf_enc_from_index(UTF_8N);\r
+                   output_encoding = nkf_enc_from_index(UTF_8N);
                } else {
                    output_bom_f = TRUE;
-                   output_encoding = nkf_enc_from_index(UTF_8_BOM);\r
+                   output_encoding = nkf_enc_from_index(UTF_8_BOM);
                }
            } else {
-               int enc_idx;\r
-               if ('1'== cp[0] && '6'==cp[1]) {\r
+               int enc_idx;
+               if ('1'== cp[0] && '6'==cp[1]) {
                    output_conv = w_oconv16; cp+=2;
-                   enc_idx = UTF_16;\r
+                   enc_idx = UTF_16;
                } else if ('3'== cp[0] && '2'==cp[1]) {
                    output_conv = w_oconv32; cp+=2;
-                   enc_idx = UTF_32;\r
+                   enc_idx = UTF_32;
                } else {
                    output_conv = w_oconv;
-                   output_encoding = nkf_enc_from_index(UTF_8);\r
+                   output_encoding = nkf_enc_from_index(UTF_8);
                    continue;
                }
                if (cp[0]=='L') {
@@ -1987,21 +1992,21 @@ void options(unsigned char *cp)
                } else if (cp[0] == 'B') {
                    cp++;
                 } else {
-                   output_encoding = nkf_enc_from_index(enc_idx);\r
+                   output_encoding = nkf_enc_from_index(enc_idx);
                    continue;
                 }
                if (cp[0] == '0'){
                    cp++;
-                   enc_idx = enc_idx == UTF_16\r
+                   enc_idx = enc_idx == UTF_16
                        ? (output_endian == ENDIAN_LITTLE ? UTF_16LE : UTF_16BE)
                        : (output_endian == ENDIAN_LITTLE ? UTF_32LE : UTF_32BE);
                } else {
                    output_bom_f = TRUE;
-                   enc_idx = enc_idx == UTF_16\r
+                   enc_idx = enc_idx == UTF_16
                        ? (output_endian == ENDIAN_LITTLE ? UTF_16LE_BOM : UTF_16BE_BOM)
                        : (output_endian == ENDIAN_LITTLE ? UTF_32LE_BOM : UTF_32BE_BOM);
                }
-               output_encoding = nkf_enc_from_index(enc_idx);\r
+               output_encoding = nkf_enc_from_index(enc_idx);
            }
             continue;
 #endif
@@ -6346,7 +6351,7 @@ void reinit(void)
     iconv_for_check = 0;
 #endif
     input_codename = NULL;
-    output_encoding = nkf_enc_from_index(DEFAULT_ENCODING);\r
+    output_encoding = nkf_enc_from_index(DEFAULT_ENCODING);
 #ifdef WIN32DLL
     reinitdll();
 #endif /*WIN32DLL*/
@@ -6370,87 +6375,87 @@ nkf_char no_connection2(nkf_char c2, nkf_char c1, nkf_char c0)
 #endif
 void usage(void)
 {
-    fprintf(stderr,"USAGE:  nkf(nkf32,wnkf,nkf2) -[flags] [in file] .. [out file for -O flag]\n");
-    fprintf(stderr,"Flags:\n");
-    fprintf(stderr,"b,u      Output is buffered (DEFAULT),Output is unbuffered\n");
+    fprintf(HELP_OUTPUT,"USAGE:  nkf(nkf32,wnkf,nkf2) -[flags] [in file] .. [out file for -O flag]\n");
+    fprintf(HELP_OUTPUT,"Flags:\n");
+    fprintf(HELP_OUTPUT,"b,u      Output is buffered (DEFAULT),Output is unbuffered\n");
 #ifdef DEFAULT_CODE_SJIS
-    fprintf(stderr,"j,s,e,w  Output code is JIS 7 bit, Shift_JIS (DEFAULT), EUC-JP, UTF-8N\n");
+    fprintf(HELP_OUTPUT,"j,s,e,w  Output code is JIS 7 bit, Shift_JIS (DEFAULT), EUC-JP, UTF-8N\n");
 #endif
 #ifdef DEFAULT_CODE_JIS
-    fprintf(stderr,"j,s,e,w  Output code is JIS 7 bit (DEFAULT), Shift JIS, EUC-JP, UTF-8N\n");
+    fprintf(HELP_OUTPUT,"j,s,e,w  Output code is JIS 7 bit (DEFAULT), Shift JIS, EUC-JP, UTF-8N\n");
 #endif
 #ifdef DEFAULT_CODE_EUC
-    fprintf(stderr,"j,s,e,w  Output code is JIS 7 bit, Shift JIS, EUC-JP (DEFAULT), UTF-8N\n");
+    fprintf(HELP_OUTPUT,"j,s,e,w  Output code is JIS 7 bit, Shift JIS, EUC-JP (DEFAULT), UTF-8N\n");
 #endif
 #ifdef DEFAULT_CODE_UTF8
-    fprintf(stderr,"j,s,e,w  Output code is JIS 7 bit, Shift JIS, EUC-JP, UTF-8N (DEFAULT)\n");
+    fprintf(HELP_OUTPUT,"j,s,e,w  Output code is JIS 7 bit, Shift JIS, EUC-JP, UTF-8N (DEFAULT)\n");
 #endif
 #ifdef UTF8_OUTPUT_ENABLE
-    fprintf(stderr,"         After 'w' you can add more options. -w[ 8 [0], 16 [[BL] [0]] ]\n");
+    fprintf(HELP_OUTPUT,"         After 'w' you can add more options. -w[ 8 [0], 16 [[BL] [0]] ]\n");
 #endif
-    fprintf(stderr,"J,S,E,W  Input assumption is JIS 7 bit , Shift JIS, EUC-JP, UTF-8\n");
+    fprintf(HELP_OUTPUT,"J,S,E,W  Input assumption is JIS 7 bit , Shift JIS, EUC-JP, UTF-8\n");
 #ifdef UTF8_INPUT_ENABLE
-    fprintf(stderr,"         After 'W' you can add more options. -W[ 8, 16 [BL] ] \n");
-#endif
-    fprintf(stderr,"t        no conversion\n");
-    fprintf(stderr,"i[@B]    Specify the Esc Seq for JIS X 0208-1978/83 (DEFAULT B)\n");
-    fprintf(stderr,"o[BJH]   Specify the Esc Seq for ASCII/Roman        (DEFAULT B)\n");
-    fprintf(stderr,"r        {de/en}crypt ROT13/47\n");
-    fprintf(stderr,"h        1 katakana->hiragana, 2 hiragana->katakana, 3 both\n");
-    fprintf(stderr,"m[BQN0]  MIME decode [B:base64,Q:quoted,N:non-strict,0:no decode]\n");
-    fprintf(stderr,"M[BQ]    MIME encode [B:base64 Q:quoted]\n");
-    fprintf(stderr,"l        ISO8859-1 (Latin-1) support\n");
-    fprintf(stderr,"f/F      Folding: -f60 or -f or -f60-10 (fold margin 10) F preserve nl\n");
-    fprintf(stderr,"Z[0-4]   Default/0: Convert JISX0208 Alphabet to ASCII\n");
-    fprintf(stderr,"         1: Kankaku to one space  2: to two spaces  3: HTML Entity\n");
-    fprintf(stderr,"         4: JISX0208 Katakana to JISX0201 Katakana\n");
-    fprintf(stderr,"X,x      Assume X0201 kana in MS-Kanji, -x preserves X0201\n");
-    fprintf(stderr,"B[0-2]   Broken input  0: missing ESC,1: any X on ESC-[($]-X,2: ASCII on NL\n");
+    fprintf(HELP_OUTPUT,"         After 'W' you can add more options. -W[ 8, 16 [BL] ] \n");
+#endif
+    fprintf(HELP_OUTPUT,"t        no conversion\n");
+    fprintf(HELP_OUTPUT,"i[@B]    Specify the Esc Seq for JIS X 0208-1978/83 (DEFAULT B)\n");
+    fprintf(HELP_OUTPUT,"o[BJH]   Specify the Esc Seq for ASCII/Roman        (DEFAULT B)\n");
+    fprintf(HELP_OUTPUT,"r        {de/en}crypt ROT13/47\n");
+    fprintf(HELP_OUTPUT,"h        1 katakana->hiragana, 2 hiragana->katakana, 3 both\n");
+    fprintf(HELP_OUTPUT,"m[BQN0]  MIME decode [B:base64,Q:quoted,N:non-strict,0:no decode]\n");
+    fprintf(HELP_OUTPUT,"M[BQ]    MIME encode [B:base64 Q:quoted]\n");
+    fprintf(HELP_OUTPUT,"l        ISO8859-1 (Latin-1) support\n");
+    fprintf(HELP_OUTPUT,"f/F      Folding: -f60 or -f or -f60-10 (fold margin 10) F preserve nl\n");
+    fprintf(HELP_OUTPUT,"Z[0-4]   Default/0: Convert JISX0208 Alphabet to ASCII\n");
+    fprintf(HELP_OUTPUT,"         1: Kankaku to one space  2: to two spaces  3: HTML Entity\n");
+    fprintf(HELP_OUTPUT,"         4: JISX0208 Katakana to JISX0201 Katakana\n");
+    fprintf(HELP_OUTPUT,"X,x      Assume X0201 kana in MS-Kanji, -x preserves X0201\n");
+    fprintf(HELP_OUTPUT,"B[0-2]   Broken input  0: missing ESC,1: any X on ESC-[($]-X,2: ASCII on NL\n");
 #ifdef MSDOS
-    fprintf(stderr,"T        Text mode output\n");
-#endif
-    fprintf(stderr,"O        Output to File (DEFAULT 'nkf.out')\n");
-    fprintf(stderr,"I        Convert non ISO-2022-JP charactor to GETA\n");
-    fprintf(stderr,"d,c      Convert line breaks  -d: LF  -c: CRLF\n");
-    fprintf(stderr,"-L[uwm]  line mode u:LF w:CRLF m:CR (DEFAULT noconversion)\n");
-    fprintf(stderr,"v, V     Show this usage. V: show configuration\n");
-    fprintf(stderr,"\n");
-    fprintf(stderr,"Long name options\n");
-    fprintf(stderr," --ic=<input codeset>  --oc=<output codeset>\n");
-    fprintf(stderr,"                   Specify the input or output codeset\n");
-    fprintf(stderr," --fj  --unix --mac  --windows\n");
-    fprintf(stderr," --jis  --euc  --sjis  --utf8  --utf16  --mime  --base64\n");
-    fprintf(stderr,"                   Convert for the system or code\n");
-    fprintf(stderr," --hiragana  --katakana  --katakana-hiragana\n");
-    fprintf(stderr,"                   To Hiragana/Katakana Conversion\n");
-    fprintf(stderr," --prefix=         Insert escape before troublesome characters of Shift_JIS\n");
+    fprintf(HELP_OUTPUT,"T        Text mode output\n");
+#endif
+    fprintf(HELP_OUTPUT,"O        Output to File (DEFAULT 'nkf.out')\n");
+    fprintf(HELP_OUTPUT,"I        Convert non ISO-2022-JP charactor to GETA\n");
+    fprintf(HELP_OUTPUT,"d,c      Convert line breaks  -d: LF  -c: CRLF\n");
+    fprintf(HELP_OUTPUT,"-L[uwm]  line mode u:LF w:CRLF m:CR (DEFAULT noconversion)\n");
+    fprintf(HELP_OUTPUT,"v, V     Show this usage. V: show configuration\n");
+    fprintf(HELP_OUTPUT,"\n");
+    fprintf(HELP_OUTPUT,"Long name options\n");
+    fprintf(HELP_OUTPUT," --ic=<input codeset>  --oc=<output codeset>\n");
+    fprintf(HELP_OUTPUT,"                   Specify the input or output codeset\n");
+    fprintf(HELP_OUTPUT," --fj  --unix --mac  --windows\n");
+    fprintf(HELP_OUTPUT," --jis  --euc  --sjis  --utf8  --utf16  --mime  --base64\n");
+    fprintf(HELP_OUTPUT,"                   Convert for the system or code\n");
+    fprintf(HELP_OUTPUT," --hiragana  --katakana  --katakana-hiragana\n");
+    fprintf(HELP_OUTPUT,"                   To Hiragana/Katakana Conversion\n");
+    fprintf(HELP_OUTPUT," --prefix=         Insert escape before troublesome characters of Shift_JIS\n");
 #ifdef INPUT_OPTION
-    fprintf(stderr," --cap-input, --url-input  Convert hex after ':' or '%%'\n");
+    fprintf(HELP_OUTPUT," --cap-input, --url-input  Convert hex after ':' or '%%'\n");
 #endif
 #ifdef NUMCHAR_OPTION
-    fprintf(stderr," --numchar-input   Convert Unicode Character Reference\n");
+    fprintf(HELP_OUTPUT," --numchar-input   Convert Unicode Character Reference\n");
 #endif
 #ifdef UTF8_INPUT_ENABLE
-    fprintf(stderr," --fb-{skip, html, xml, perl, java, subchar}\n");
-    fprintf(stderr,"                   Specify how nkf handles unassigned characters\n");
+    fprintf(HELP_OUTPUT," --fb-{skip, html, xml, perl, java, subchar}\n");
+    fprintf(HELP_OUTPUT,"                   Specify how nkf handles unassigned characters\n");
 #endif
 #ifdef OVERWRITE
-    fprintf(stderr," --in-place[=SUFFIX]  --overwrite[=SUFFIX]\n");
-    fprintf(stderr,"                   Overwrite original listed files by filtered result\n");
-    fprintf(stderr,"                   --overwrite preserves timestamp of original files\n");
-#endif
-    fprintf(stderr," -g  --guess       Guess the input code\n");
-    fprintf(stderr," --help  --version Show this help/the version\n");
-    fprintf(stderr,"                   For more information, see also man nkf\n");
-    fprintf(stderr,"\n");
+    fprintf(HELP_OUTPUT," --in-place[=SUFFIX]  --overwrite[=SUFFIX]\n");
+    fprintf(HELP_OUTPUT,"                   Overwrite original listed files by filtered result\n");
+    fprintf(HELP_OUTPUT,"                   --overwrite preserves timestamp of original files\n");
+#endif
+    fprintf(HELP_OUTPUT," -g  --guess       Guess the input code\n");
+    fprintf(HELP_OUTPUT," --help  --version Show this help/the version\n");
+    fprintf(HELP_OUTPUT,"                   For more information, see also man nkf\n");
+    fprintf(HELP_OUTPUT,"\n");
     version();
 }
 
 void show_configuration(void)
 {
-    fprintf(stderr, "Summary of my nkf " NKF_VERSION " (" NKF_RELEASE_DATE ") configuration:\n");
-    fprintf(stderr, "  Compile-time options:\n");
-    fprintf(stderr, "    Default output encoding:     "
+    fprintf(HELP_OUTPUT, "Summary of my nkf " NKF_VERSION " (" NKF_RELEASE_DATE ") configuration:\n");
+    fprintf(HELP_OUTPUT, "  Compile-time options:\n");
+    fprintf(HELP_OUTPUT, "    Default output encoding:     "
 #if defined(DEFAULT_CODE_JIS)
            "ISO-2022-JP"
 #elif defined(DEFAULT_CODE_SJIS)
@@ -6461,7 +6466,7 @@ void show_configuration(void)
            "UTF-8"
 #endif
            "\n");
-    fprintf(stderr, "    Default output newline:      "
+    fprintf(HELP_OUTPUT, "    Default output newline:      "
 #if DEFAULT_NEWLINE == CR
            "CR"
 #elif DEFAULT_NEWLINE == CRLF
@@ -6470,24 +6475,31 @@ void show_configuration(void)
            "LF"
 #endif
            "\n");
-    fprintf(stderr, "    Decode MIME encoded string:  "
+    fprintf(HELP_OUTPUT, "    Decode MIME encoded string:  "
 #if MIME_DECODE_DEFAULT
            "ON"
 #else
            "OFF"
 #endif
            "\n");
-    fprintf(stderr, "    Convert JIS X 0201 Katakana: "
+    fprintf(HELP_OUTPUT, "    Convert JIS X 0201 Katakana: "
 #if X0201_DEFAULT
            "ON"
 #else
            "OFF"
 #endif
            "\n");
+fprintf(HELP_OUTPUT, " --help, --version output: "
+#if HELP_OUTPUT_HELP_OUTPUT
+"HELP_OUTPUT"
+#else
+"STDOUT"
+#endif
+"\n");
 }
 
 void version(void)
 {
-    fprintf(stderr,"Network Kanji Filter Version " NKF_VERSION " (" NKF_RELEASE_DATE ") \n" COPY_RIGHT "\n");
+    fprintf(HELP_OUTPUT,"Network Kanji Filter Version " NKF_VERSION " (" NKF_RELEASE_DATE ") \n" COPY_RIGHT "\n");
 }
 #endif /*PERL_XS*/