次: Terminology, 前: Basic Usage, 上: Top
gengetopt
This program generates a C function that uses getopt_long function
to parse the command line options, validate them and fill a struct.
Usage: gengetopt [OPTIONS]...
-h, --help Print help and exit
-V, --version Print version and exit
-i, --input=filename input file (default std input)
-f, --func-name=name name of generated function
(default=`cmdline_parser')
-a, --arg-struct-name=name name of generated args info struct
(default=`gengetopt_args_info')
-F, --file-name=name name of generated file (default=`cmdline')
-c, --c-extension=ext extension of c file (default=`c')
-H, --header-extension=ext extension of header file (default=`h')
-l, --long-help long usage line in help
-u, --unamed-opts[=STRING] accept options without names (e.g., file names)
(default=`FILES')
-n, --no-handle-help do not handle --help|-h automatically
-N, --no-handle-version do not handle --version|-V automatically
-e, --no-handle-error do not exit on errors
-g, --gen-version put gengetopt version in the generated file
(default=on)
-C, --conf-parser generate a config file parser
--set-package=STRING set the package name (override package defined in
the .ggo file)
--set-version=STRING set the version number (override version defined
in the .ggo file)
--show-help show the output of --help instead of generating
code
--show-version show the output of --version instead of
generating code
オプションは,特に,はっきりとさせておくべきでしょう.
--func-name--func-nameがあたえられていない場合,cmdline_parserがデフォ
ルトになります.
--arg-struct-namegengetopt_args_info).
--long-help--unamed-optssample1 *.hを呼び出しているBasic Usageの例を参照して下さ
い).これらの追加の名前にオプションの記述を指定することが可能です(デフォ
ルトはFILESです).
--no-handle-help--no-handle-version--no-handle-help (--no-handle-version)が与えられている場
合,コマンドラインオプション--help|-h (--version|-V)は,
自動的に処理されないので,プログラマはそれ以外のオプションを出力するこ
とが可能になります.標準的なヘルプ(バージョン)に対応して出力する関数は
使用可能です.この関数は,<parser-name>_print_help
(<parser-name>_print_version)と呼ばれ,<parser-name>の名
前は,--func-nameで指定されたもの,またはデフォルトの
cmdline_parserになります.
--no-handle-error--no-handle-errorが与えられている場合,構文解析時のエラーで,プ
ログラムの終了コードが呼び出されません.その代わりに,構文解析関数は,
エラー時には0以外の値を返し,プログラムはヘルプメッセージを出力し,
gengetopt自身がエラー時に行うことと同じようになります(試してみてください!).
--gen-version既にお分かりかもしれませんが,gengetoptはgengetopt自身を,コマンドライ
ンオプションに対して使用していて,その仕様が書かれているファイルはソー
スディレクトリのcmdline.ggoです.特に,gengetopt自身のコマンドラ
インは,以下のコマンドで生成されています.
gengetopt --input=cmdline.ggo --no-handle-version \
--no-handle-help --no-handle-error
実際,--help|-hがコマンドラインで渡されると,gengetoptは
cmdline_parser_print_help()を呼び出し,バグ報告の行が表示されま
す.--version|-Vが渡されるとき,
cmdline_parser_print_version()が呼び出され,著作権が出力されます.
エラーが生じた場合,画面にメッセージが出力されます.
$ ./gengetopt --zzzz
./gengetopt: unrecognized option `--zzzz'
Run gengetopt --help to see the list of options.