Forums: 公開討議 (Thread #17170)

--help, --version の出力先を切り替えるパッチ (2007-12-22 17:58 by Anonymous #34150)

こんにちは。
2ch の某スレッドでお世話になってます。
個人的に欲しかったので--help, --version の出力先を切り替えるパッチを作ってみました。
diff の量が多かったのでこっちに投稿します。
あまり需要がなさそうなので参考程度ということで。

主な内容は以下のとおりです。
- usage(), show_configuration(), version() の出力先を stderr から HELP_OUTPUT に変更
- HELP_OUTPUT は HELP_OUTPUT_STDOUT が定義されていれば stdout, されていなければ stderr になる
- config.h で HELP_OUTPUT_STDOUT を設定出来るように変更
- show_configuration() に HELP_OUTPUT_STDOUT の情報を表示するようにした

== config.h Revision 1.11
45a46,47
> /* --help, --version の出力先を STDOUT に変更する */
> /* #define HELP_OUTPUT_STDOUT */

== nkf.c Revision 1.157
6370a6371,6375
> #ifdef HELP_OUTPUT_STDOUT
> #define HELP_OUTPUT stdout
> #else
> #define HELP_OUTPUT stderr
> #endif
6373,6375c6378,6380
< 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");
6377c6382
< 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");
6380c6385
< 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");
6383c6388
< 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");
6386c6391
< 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");
6389c6394
< 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");
6391c6396
< 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");
6393c6398
< fprintf(stderr," After 'W' you can add more options. -W[ 8, 16 [BL] ] \n");
---
> fprintf(HELP_OUTPUT," After 'W' you can add more options. -W[ 8, 16 [BL] ] \n");
6395,6408c6400,6413
< 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,"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");
6410c6415
< fprintf(stderr,"T Text mode output\n");
---
> fprintf(HELP_OUTPUT,"T Text mode output\n");
6412,6426c6417,6431
< 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,"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");
6428c6433
< fprintf(stderr," --cap-input, --url-input Convert hex after ':' or '%%'\n");
---
> fprintf(HELP_OUTPUT," --cap-input, --url-input Convert hex after ':' or '%%'\n");
6431c6436
< fprintf(stderr," --numchar-input Convert Unicode Character Reference\n");
---
> fprintf(HELP_OUTPUT," --numchar-input Convert Unicode Character Reference\n");
6434,6435c6439,6440
< 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");
6438,6445c6443,6450
< 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");
6451,6453c6456,6458
< 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: "
6464c6469
< fprintf(stderr, " Default output newline: "
---
> fprintf(HELP_OUTPUT, " Default output newline: "
6473c6478
< fprintf(stderr, " Decode MIME encoded string: "
---
> fprintf(HELP_OUTPUT, " Decode MIME encoded string: "
6480c6485
< fprintf(stderr, " Convert JIS X 0201 Katakana: "
---
> fprintf(HELP_OUTPUT, " Convert JIS X 0201 Katakana: "
6486a6492,6498
> fprintf(HELP_OUTPUT, " --help, --version output: "
> #if HELP_OUTPUT_STDOUT
> "STDOUT"
> #else
> "STDERR"
> #endif
> "\n");
6491c6503
< 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");

Reply to #34150×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login

RE: --help, --version の出力先を切り替えるパッチ (2007-12-23 16:28 by naruse #34158)

わざわざどうもです。
これ、設定可能にしようかデフォルトで変えてしまおうか迷っていたんですよね。

とりあえずデフォルトをstdoutにして、HELP_OUTPUT_STDERRで変更できるようにしました。
HELP_OUTPUT_STDERRは将来削除してしまうかもしれません。
Reply to #34150

Reply to #34158×

You can not use Wiki syntax
You are not logged in. To discriminate your posts from the rest, you need to pick a nickname. (The uniqueness of nickname is not reserved. It is possible that someone else could use the exactly same nickname. If you want assurance of your identity, you are recommended to login before posting.) Login