Next: Invoking gengetopt, Previous: Installation, Up: Top [Contents][Index]
gengetopt¤¬À¸À®¤·¤¿´Ø¿ô¤Ç½èÍý¤¹¤ëɬÍפ¬¤¢¤ë¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó¤Ï¡¤ ¥Õ¥¡¥¤¥ë(Ä̾ï¤Ï.ggo¤Î³ÈÄ¥»Ò)¤Ç»ØÄꤷ¤Þ¤¹¡¥¤³¤Î¥Õ¥¡¥¤¥ë¤Ï¡¤°Ê²¼¤Î ¥Õ¥©¡¼¥Þ¥Ã¥È¤Îʸ¤Ç¹½ÃÛ¤·¡¤{}¤Î¥³¥Þ¥ó¥É¤Ï¥ª¥×¥·¥ç¥ó¤Ç¤¹1¡¥
package <packname> version <version> option <long> <short> <desc> {argtype} {typestr="<type descr>"} \ {default="<default value>"} {required} {argoptional} {multiple} option <long> <short> <desc> {typestr="<type descr>"} \ {values="value1","value2",...} {default="<default value>"} \ {required} {argoptional} {multiple} option <long> <short> <desc> flag <on/off>
¤³¤ì¤é¤Î°ÕÌ£¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡¥
package
Æó½Å°úÍÑÉä¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤Ç¤¹¡¥¤³¤ì¤Ï¡¤autoconf¤¬À¸À®¤¹¤ë
PACKAGE
¤ËÍ¥À褷¤Þ¤¹¡¥
version
Æó½Å°úÍÑÉä¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤Ç¤¹¡¥¤³¤ì¤Ï¡¤autoconf¤¬À¸À®¤¹¤ë
VERSION
¤ËÍ¥À褷¤Þ¤¹¡¥
purpose
¥×¥í¥°¥é¥à¤ÎÌÜŪ¤Ç(°ì¹Ô°Ê¾å¤Ç¤â¤«¤Þ¤¤¤Þ¤»¤ó)¡¤¥Ø¥ë¥×¤Ç½ÐÎϤµ¤ì¤Þ¤¹¡¥Æó ½Å°úÍÑÉä¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤Ç¤¹¡¥
long
Ť¤¥ª¥×¥·¥ç¥ó¤Ç¡¤Æó½Å°úÍÑÉä¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤Ç¡¤Âçʸ»ú¤È¾®Ê¸»ú¡¤¿ô»ú¡¤
¥À¥Ã¥·¥å(-
)¡¤¤½¤·¤Æ¥É¥Ã¥È(.
)¤ò»ÈÍѤ·¤Þ¤¹¡¥¥¹¥Ú¡¼¥¹¤ÏÍøÍÑ
¤Ç¤¤Þ¤»¤ó¡¥°ú¿ô¤òÊݸ¤¹¤ë¤¿¤á¤ËÀ¸À®¤µ¤ì¤ëÊÑ¿ô¤Î̾Á°¤Ï(¤³¤Î¥»¥¯¥·¥ç¥ó¤Î
¸å¤ÎÉôʬ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤)¡¤ÀµÅö¤ÊC¤ÎÊÑ¿ô̾¤ËÊÑ´¹¤µ¤ì¤¿Ä¹¤¤¥ª¥×¥·¥ç¥ó
¤Ë¤Ê¤ê¤Þ¤¹¡¥¤³¤ì¤Ï¡¤.
¤È-
¤¬Î¾Êý¤È¤â_
¤ÇÃÖ´¹¤µ¤ì¤ë¤³
¤È¤ò°ÕÌ£¤·¤Þ¤¹¡¥
short
û¤¤¥ª¥×¥·¥ç¥ó¤Ç¡¤Ã±°ì¤ÎÂçʸ»ú¤ä¾®Ê¸»ú¡¤¤Þ¤¿¤Ï¿ô»ú¤Ç¤¹¡¥-
¤¬»ØÄê
¤µ¤ì¤Æ¤¤¤ë¾ì¹ç¡¤Ã»¤¤¥ª¥×¥·¥ç¥ó¤Ï¡¤Ä¹¤¤¥ª¥×¥·¥ç¥ó¤ËÂФ¹¤ë¤â¤Î¤È¤Ï¹Í褵
¤ì¤Þ¤»¤ó(¤³¤Î¤¿¤á¡¤´ØÎþ¤¹¤ëû¤¤¥ª¥×¥·¥ç¥ó¤¬Ìµ¤¤Ä¹¤¤¥ª¥×¥·¥ç¥ó¤¬²Äǽ¤Ë¤Ê
¤ê¤Þ¤¹)¡¥
desc
Æó½Å°úÍÑÉä¤Ç°Ï¤Þ¤ì¤¿Ê¸»úÎó¤Ç¡¤Âçʸ»ú¤È¾®Ê¸»ú¡¤¿ô»ú¡¤¥À¥Ã¥·¥å(-
)¡¤
¤½¤·¤Æ¥É¥Ã¥È(.
)¤ò»ÈÍѤ·¤Þ¤¹¡¥ºÇ½é¤Îʸ»ú¤Ï¥¹¥Ú¡¼¥¹¤Ë¤·¤Æ¤Ï¤¤¤±¤Þ
¤»¤ó¡¥¤³¤Îµ½Ò¤Ï¡¤--help
¤Î½ÐÎϤÇɽ¼¨¤µ¤ì¤Þ¤¹¡¥²þ¹Ô¤Ï¼«Æ°Åª¤Ë¹Ô¤ï
¤ì¡¤\n
¤Ï²þ¹Ô¤¬Í׵ᤵ¤ì¤Æ¤¤¤ë¤â¤Î¤È²ò¼á¤µ¤ì¤Þ¤¹¡¥
argtype
string
¡¤int
¡¤short
¡¤long
¡¤float
¡¤
double
¡¤longdouble
¡¤¤Þ¤¿¤Ïlonglong
¤Ç¤¹¡¥·¿¤¬»ØÄꤵ
¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¡¤¥ª¥×¥·¥ç¥ó¤Ï°ú¿ô¤ò¼õ¤±¤Ä¤±¤Þ¤»¤ó¡¥
typestr
¥ª¥×¥·¥ç¥óÃͤη¿¤Îµ½Ò¤Ç¤¹¡¥¤³¤ì¤Ï¡¤--help
¤Î½ÐÎϤǻÈÍѤµ¤ì¤Þ¤¹
(Î㤨¤Ð¡¤Ã±½ã¤ÊSTRING
¤ÎÂå¤ï¤ê¤Ë"filename"
¡¤Ã±½ã¤Ê
INT
¤ÎÂå¤ï¤ê¤Ë"portnumber"
)¡¥
values
¥ª¥×¥·¥ç¥ó¤ËÅϤ¹¤³¤È¤¬²Äǽ¤ÊÍøÍѲÄǽ¤Ê¤¹¤Ù¤Æ¤ÎÃͤò´Þ¤àʸ»úÎó¤Î¥ê¥¹¥È¤Ç ¤¹¡¥·¿¤Ïʸ»úÎó¤À¤È¹Í褵¤ì¡¤»ØÄꤷ¤Æ¤Ï¤Ê¤ê¤Þ¤»¤ó¡¥
default
¥ª¥×¥·¥ç¥ó¤ËÂФ¹¤ëÄɲäΥǥե©¥ë¥ÈÃͤǤ¹¡¥ÃͤϾï¤ËÆó½Å°úÍÑÉä¤Ç°Ï¤Þ¤ì¤¿ ʸ»úÎó¤È¤·¤Æ»ØÄꤹ¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡¥
required
yes
¤Þ¤¿¤Ïno
¤Ç¤¹¡¥¤³¤ì¤Ï¡¤¤½¤Î¥ª¥×¥·¥ç¥ó¤¬¥×¥í¥°¥é¥à¤Î¸Æ¤Ó
½Ð¤·¤´¤È¤Ëǽ¤¨¤ëɬÍפ¬¤¢¤ë¤«¤É¤¦¤«¤ò»ØÄꤷ¤Þ¤¹¡¥
argoptional
¤³¤Î¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¤¤³¤Î¥ª¥×¥·¥ç¥ó¤ÏÄɲäΰú¿ô¤ò¼è¤ê¤Þ¤¹¡¥
¤³¤Î¾õ¶·¤Ç¤Ï¡¤¥³¥Þ¥ó¥É¥é¥¤¥ó¤Ç°ú¿ô¤ò»ØÄꤹ¤ë¤È¤¡¤Ä¹¤¤¥ª¥×¥·¥ç¥ó¤Î»ÈÍÑ
»þ¤Ë¤Ï=
¤ò»ÈÍѤ·¡¤Ã»¤¤¥ª¥×¥·¥ç¥ó¤Î¾ì¹ç¤Ï¥¹¥Ú¡¼¥¹¤òÆþ¤ì¤Ê¤¤¤Ç²¼¤µ
¤¤¡¥Î㤨¤Ð¡¤Äɲäΰú¿ô¤¬¤¢¤ë¥ª¥×¥·¥ç¥ó¤Ç¤Ï¡¤°Ê²¼¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó¤Î¹½Ê¸
¤ò»ÈÍѤ·¤Æ²¼¤µ¤¤¡¥-B15
¤Þ¤¿¤Ï--bar=15
¤Ç¡¤-B 15
¤Ç¤â
--bar 15
¤Ç¤â¤¢¤ê¤Þ¤»¤ó¡¥
multiple
¤³¤Î¥Õ¥é¥°¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¤¤³¤Î¥ª¥×¥·¥ç¥ó¤Ï¥³¥Þ¥ó¥É¥é¥¤¥ó¤Ç°ìÅÙ°Ê ¾å»ØÄꤹ¤ë¤³¤È¤¬²Äǽ¤Ë¤Ê¤ê¤Þ¤¹¡¥¤³¤Î¥ª¥×¥·¥ç¥ó¤Î¤¹¤Ù¤Æ¤ÎÃͤ¬ÇÛÎó¤ËÊݸ ¤µ¤ì¤Þ¤¹¡¥Multiple Options¤ò»²¾È¤·¤Æ²¼¤µ¤¤¡¥
on/off
on
¤Þ¤¿¤Ïoff
¤Ç¤¹¡¥¤³¤ì¤Ï¡¤¥×¥í¥°¥é¥à³«»Ï»þ¤Î¥Õ¥é¥°¤Î¾õÂÖ¤È
¤Ê¤ê¤Þ¤¹¡¥¥æ¡¼¥¶¤¬¥ª¥×¥·¥ç¥ó»ØÄꤷ¤Æ¤¤¤ë¾ì¹ç¡¤¥Õ¥é¥°¤ÏÀÚÂØ¤¨¤é¤ì¤Þ¤¹¡¥
¥³¥á¥ó¥È¤Ï¹Ô¤ÎǤ°Õ¤Î¾ì½ê¤Î#
¤Ç»Ï¤Þ¤ê¡¤¹Ô¤Î½ª¤ï¤ê¤Ç½ªÎ»¤È¤Ê¤ê¤Þ¤¹¡¥
¥ª¥×¥·¥ç¥ó-h,--help
¤È-V,--version
¤Ï¼«Æ°Åª¤ËÄɲ䵤ì¤Þ¤¹¡¥
û¤¤·Á¼°¤Îh
¤ä¡¤Ä¹¤¤·Á¼°¤Îhelp
¤òÆÈ¼«¤Î¥ª¥×¥·¥ç¥ó¤È¤·¤Æ»ØÄê
¤·¤¿¾ì¹ç¡¤Äɲ䵤ì¤Þ¤»¤ó(¥Ø¥ë¥×¥ª¥×¥·¥ç¥ó¤ò¼êư¤Ç½èÍý¤¹¤ëɬÍפ¬¤¢¤ê¤Þ
¤¹)¡¥-V,--version
¤âƱ¤¸¤Ç¤¹¡¥
¥ª¥×¥·¥ç¥ó¤Ï¥»¥¯¥·¥ç¥ó¤Î°ìÉô¤Ë¤¹¤ë¤³¤È¤¬²Äǽ¤Ç¡¤¥ª¥×¥·¥ç¥ó¤Î¤è¤ê°ÕÌ£¤Î
¤¢¤ëµ½Ò¤òÄ󶡤·¤Þ¤¹¡¥section¤Ï°Ê²¼¤Î¹½Ê¸¤ÇÄêµÁ¤µ¤ì
(sectiondesc
¤Ï¥ª¥×¥·¥ç¥ó¤Ç¤¹)¡¤¡¤¥»¥¯¥·¥ç¥óÀë¸À¤¬Â³¤¯¤¹¤Ù¤Æ¤Î¥ª
¥×¥·¥ç¥ó¤Ï¡¤¥»¥¯¥·¥ç¥ó¤Î°ìÉô¤È¹Í褵¤ì¤Þ¤¹¡¥
section "section name" {sectiondesc="optional section description"}
¥ª¥×¥·¥ç¥ó¤ËÅϤ¹ÃͤΥꥹ¥È¤ò»ØÄꤹ¤ë¤³¤È¤â²Äǽ¤Ç¤¹(¤½¤Î¾õ¶·¤Ç¤Ï¡¤¥ª¥×¥·¥ç
¥ó¤Î·¿¤Ïstring
¤Ç¤¹)¡¥Ãͤ¬ÅϤµ¤ì¤¿¥ê¥¹¥È¤Ë̵¤¤¾ì¹ç¡¤¥¨¥é¡¼¤È¤Ê¤ê
¤Þ¤¹¡¥¤½¤Î¤è¤¦¤Ê¥ª¥×¥·¥ç¥ó¤ÏÎóµó·¿¥ª¥×¥·¥ç¥ó¤À¤È¹Í¤¨¤ë¤³¤È¤¬¤Ç¤
¤Þ¤¹¡¥
°Ê²¼¤Ï¡¤¤½¤Î¤è¤¦¤Ê¥Õ¥¡¥¤¥ë¤ÎÎã¤Ç¤¹(¥Õ¥¡¥¤¥ë¤Ïsample1.ggo¤È¤·¤Þ ¤¹)¡¥
# file sample1.ggo option "str-opt" s "A string option, for a filename" \ string typestr="filename" no option "my-opt" m "Another integer option, \ this time the description of the \ option should be quite long to require wrapping... possibly \ more than one wrapping :-) especially if I\nrequire a line break" int no option "int-opt" i "A int option" int yes section "more involved options" \ sectiondesc="the following options\nare more complex" option "flag-opt" - "A flag option" flag off option "funct-opt" F "A function option" no section "last option section" option "long-opt" - "A long option" long no option "def-opt" - "A string option with default" \ string default="Hello" no option "enum-opt" - "A string option with list of values" \ values="foo","bar","hello" default="hello" no
gengetopt¤ò»ÈÍѤ¹¤ë¤â¤Ã¤È¤â´Êñ¤ÊÊýË¡¤Ï¡¤¤³¤Î¥Õ¥¡¥¤¥ë¤òɸ½àÆþÎϤȤ·¤ÆÅÏ ¤¹ÊýË¡¤Ç¤¹¡¥¤¹¤Ê¤ï¤Á°Ê²¼¤Î¤è¤¦¤Ë¤·¤Þ¤¹¡¥
gengetopt < sample1.ggo
¥Ç¥Õ¥©¥ë¥È¤Ç¡¤gengetopt¤Ïcmdline.h¤Ècmdline.c¤òÀ¸À®¤·¤Þ¤¹¡¥ ¤½¤ì°Ê³°¤Ç¤Ï¡¤¤³¤ì¤é¤Î̾Á°¤ò¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó¤Ç»ØÄꤹ¤ë¤³¤È¤¬²Ä ǽ¤Ç¤¹¡¥
gengetopt < sample1.ggo --file-name=cmdline1 --unamed-opts
¥ª¥×¥·¥ç¥ó--unamed-opts
¤ÇÀ¸À®¤¹¤ë¥³¥Þ¥ó¥É¥é¥¤¥ó¹½Ê¸²òÀÏ´ï¤Ë¤â̾
Á°¤òÉÕ¤±¤ë¤³¤È¤¬²Äǽ¤È¤Ê¤ê¡¤¥ª¥×¥·¥ç¥ó¤¬Ìµ¤¤¾ì¹ç(Î㤨¤Ð¡¤¤½¤ÎÁ°¤Ë¥ª¥×¥·¥ç
¥ó¤¬Ìµ¤±¤ì¤Ð¥Õ¥¡¥¤¥ë̾¤òÅϤ¹¤³¤È¤¬²Äǽ¤Ç¡¤¤½¤³¤Ç¤Ï¡¤*.c
¡¤
foo*.?
¤Ê¤É¤Î¤è¤¦¤Ê¥ï¥¤¥ë¥É¥«¡¼¥É¤ò»ÈÍѤ¹¤ë¤³¤È¤¬²Äǽ¤Ç¤¹)¡¥¤³¤ì
¤é¤Ï¥Ñ¥é¥á¡¼¥¿¤È¤â¸Æ¤Ð¤ì¤Æ¤¤¤Þ¤¹(see Terminology)¡¥¤³¤ì¤é¤Î
ÄɲäÎ̾Á°¤Ë¡¤Äɲäε½Ò¤ò»ØÄꤹ¤ë¤³¤È¤¬²Äǽ¤Ç¤¹(¥Ç¥Õ¥©¥ë¥È¤Ï
FILES
¤Ç¤¹)¡¥
¥Õ¥¡¥¤¥ëcmdline1.h¤Ç¡¤À¸À®¤µ¤ì¤ëC¤Î¹½Â¤ÂΤò¸«¤Ä¤±¤Þ¤·¤ç¤¦¡¥
/* cmdline1.h */ /* File autogenerated by gengetopt version 2.14rc */ #ifndef CMDLINE1_H #define CMDLINE1_H /* If we use autoconf. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #ifndef CMDLINE_PARSER_PACKAGE #define CMDLINE_PARSER_PACKAGE "sample1" #endif #ifndef CMDLINE_PARSER_VERSION #define CMDLINE_PARSER_VERSION "2.0" #endif struct gengetopt_args_info { char * str_opt_arg; /* A string option, for a filename. */ char * str_opt_orig; /* A string option, for a filename original value given at command line. */ int my_opt_arg; /* Another integer option, this time the description of the option should be quite long to require wrapping... possibly more than one wrapping :-) especially if I\nrequire a line break. */ char * my_opt_orig; /* Another integer option, this time the description of the option should be quite long to require wrapping... possibly more than one wrapping :-) especially if I\nrequire a line break original value given at command line. */ int int_opt_arg; /* A int option. */ char * int_opt_orig; /* A int option original value given at command line. */ int flag_opt_flag; /* A flag option (default=off). */ long long_opt_arg; /* A long option. */ char * long_opt_orig; /* A long option original value given at command line. */ char * def_opt_arg; /* A string option with default (default=’Hello’). */ char * def_opt_orig; /* A string option with default original value given at command line. */ char * enum_opt_arg; /* A string option with list of values (default=’hello’). */ char * enum_opt_orig; /* A string option with list of values original value given at command line. */ int help_given ; /* Whether help was given. */ int version_given ; /* Whether version was given. */ int str_opt_given ; /* Whether str-opt was given. */ int my_opt_given ; /* Whether my-opt was given. */ int int_opt_given ; /* Whether int-opt was given. */ int flag_opt_given ; /* Whether flag-opt was given. */ int funct_opt_given ; /* Whether funct-opt was given. */ int long_opt_given ; /* Whether long-opt was given. */ int def_opt_given ; /* Whether def-opt was given. */ int enum_opt_given ; /* Whether enum-opt was given. */ char **inputs ; /* unamed options */ unsigned inputs_num ; /* unamed options number */ } ; int cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info); int cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required); int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info); void cmdline_parser_print_help(void); void cmdline_parser_print_version(void); void cmdline_parser_init (struct gengetopt_args_info *args_info); void cmdline_parser_free (struct gengetopt_args_info *args_info); int cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name); extern char *cmdline_parser_enum_opt_values[] ; /* Possible values for enum-opt. */ #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* CMDLINE1_H */
<option>_given
¥Õ¥£¡¼¥ë¥É¤Ï¡¤<option>
¤Î°ú¿ô¤¬»ØÄꤵ¤ì¤Æ¤¤
¤ë¤È¤¡¤0°Ê³°¤ÎÃͤ¬ÀßÄꤵ¤ì¤Þ¤¹¡¥¥ª¥×¥·¥ç¥ó¤¬°ú¿ô¤ò¼õ¤±Æþ¤ì¡¤
flag
¤Î·¿¤Ç¤Ï¤Ê¤¤¾ì¹ç¡¤<option>_arg
¥Õ¥£¡¼¥ë¥É¤Ï¥³¥Þ¥ó¥É¥é
¥¤¥ó¤ÇÅϤµ¤ì¤¿ÃͤËÀßÄꤵ¤ì¤Þ¤¹¡¥<option>_arg
¥Õ¥£¡¼¥ë¥É¤Ï¡¤
gengetopt¤ËÅϤµ¤ì¤¿¥Õ¥¡¥¤¥ë¤Ç»ØÄꤵ¤ì¤Æ¤¤¤ë¡¤Âбþ¤¹¤ëC¤Î·¿¤ò»ý¤Á¤Þ¤¹¡¥
ÄɲäΥե£¡¼¥ë¥É<option>_orig
¤Ï¾ï¤Ë¡¤¥³¥Þ¥ó¥É¥é¥¤¥ó¤ÇÅϤµ¤ì¤¿¸µ
¤ÎÃͤò´Þ¤àʸ»úÎó¤Ç¤¹¡¥¤³¤ì¤Ï¡¤Î㤨¤Ð¿ôÃͤΰú¿ô¤Î¾õ¶·¤Ç¤Ï°Û¤Ê¤ë²ÄǽÀ¤¬
¤¢¤ê¤Þ¤¹¡¥gengetopt¤ÏÅϤµ¤ì¤¿ÃÍ(ʸ»úÎó)¤òÂбþ¤¹¤ë¿ôÃͤη¿¤ËÊÑ´¹¤·¤Þ¤¹¡¥
ÊÑ´¹¤Î¤¿¤á¡¤ÉâÆ°¾®¿ôÅÀɽ¸½¤Ê¤É¤Ë¤Ê¤ê¡¤¤³¤ì¤Ï¡¤¥³¥Þ¥ó¥É¥é¥¤¥ó¤ÇÅϤµ¤ì¤¿
¸µ¤ÎÃͤȤÏÀµ³Î¤Ë°ìÃפ·¤Ê¤¤²ÄǽÀ¤¬¤¢¤ê¤Þ¤¹¡¥¥æ¡¼¥¶¤Ï¡¤
<option>_arg
¤ÎÂå¤ï¤ê¤Ë<option>_orig
¤ò»ÈÍѤ¹¤ë¤³¤È¤Ç¡¤¤³¤Î
¸µ¤ÎÃͤ˥¢¥¯¥»¥¹¤¹¤ë¤³¤È¤¬¡¤Â¸µ¤ò¸«¤ë¤Î¤ÈƱ¤¸¤¯¤é¤¤¡¤¤¤¤Ä¤Ç¤â²Äǽ¤Ç¤¹
2¡¥Î㤨¤Ð¡¤
gengetopt¼«¿È¡¤¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó¤ò¥Õ¥¡¥¤¥ë¤ËÊݸ¤¹¤ë¤È¤¡¤¸µ¤ÎÃÍ
¤ò»ÈÍѤ·¤Æ¤¤¤Þ¤¹(°Ê²¼¤Î_file_save
´Ø¿ô¤ò»²¾È¤·¤Æ²¼¤µ¤¤)¡¥
flag
¤Î·¿¤Î¾ì¹ç¡¤<option>_flag
¥Õ¥£¡¼¥ë¥É¤À¤±À¸À®¤µ¤ì¤Þ¤¹¡¥
<option>_given
¤¬0¤Î¾ì¹ç¤Ç¤â¡¤Âбþ¤¹¤ë<option>_arg
¤Ï¥Ç¥Õ¥©
¥ë¥ÈÃͤˤʤê¤Þ¤¹(<option>
¤¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç)¡¥¤·¤«¤·¡¤¤³¤Î¾õ¶·
¤Ç¤Ï¡¤<option>_orig
¤ÏNULL
¤ËÀßÄꤵ¤ì¤Þ¤¹¡¥
¥Ç¥Õ¥©¥ë¥È¤Ç¡¤À¸À®¤µ¤ì¤ë´Ø¿ô¤Ïcmdline_parser
¤È¸Æ¤Ð¤ì(¤³¤Î̾Á°¤Ë
Í¥À褵¤»¤ëÊýË¡¤Ï¡¤°Ê²¼¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó¤ò»²¾È¤·¤Æ²¼¤µ¤¤)¡¤
main´Ø¿ô¤¬¼õ¤±¼è¤ë°ú¿ô¤È¡¤Ãͤ¬½¼Å¶¤µ¤ì¤Æ¤¤¤ë¹½Â¤ÂΤؤΥݥ¤¥ó¥¿¤ò¼õ¤±¼è
¤ê¤Þ¤¹¡¥
cmdline_parser_free
¤Ï¡¤Ê¸»úÎó¤ÈÊ£¿ô²ó¥ª¥×¥·¥ç¥ó¤Î¹½Ê¸²òÀÏ´ï¤Ç³Î
Êݤµ¤ì¤¿¥á¥â¥ê¤ò²òÊü¤¹¤ë¤¿¤á¤Ë¸Æ¤Ó½Ð¤¹¤³¤È¤¬²Äǽ¤Ç¤¹¡¥
¤³¤Î´Ø¿ô¤Î¸Æ¤Ó½Ð¤·¸å¡¤¹½Ê¸²òÀÏ´Ø¿ô¤ò¸Æ¤Ó½Ð¤·¤Æ¤Ï¤Ê¤é¤Ê¤¤¤³¤È¤ËÃí°Õ¤·¤Æ ¤¯¤À¤µ¤¤¡¥
cmdline_parser_init
¤Ï¡¤¹½Â¤ÂΤνé´ü²½¤ò¤¹¤ë¤¿¤á¤Ë¸Æ¤Ó½Ð¤¹¤³¤È¤¬
²Äǽ¤Ç¤¹(¤½¤ì¤Ïɬ¿Ü¤Ç¤Ï¤Ê¤¯¡¤¤½¤ÎÍýͳ¤Ï¥³¥Þ¥ó¥É¥é¥¤¥ó¹½Â¤²òÀϴ郎¼«Æ°Åª
¤Ë¹Ô¤¦¤¿¤á¤Ç¤¹)¡¥
cmdline_parser_file_save
3¤Ï¡¤¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó¤ò¥Õ¥¡¥¤¥ë¤ËÊݸ¤¹¤ë¤¿¤á¤Ë»ÈÍѤ¹¤ë
¤³¤È¤¬²Äǽ¤Ç¤¹¡¥¤³¤Î¥Õ¥¡¥¤¥ë¤ÎÆâÍÆ¤Ï¡¤¥³¥ó¥Õ¥£¥°¥ì¡¼¥·¥ç¥ó¥Õ¥¡¥¤¥ë
(Configuration files)¤ÈξΩ¤·¤Þ¤¹¡¥¥ª¥×¥·¥ç¥ó¤Ë¥Ç¥Õ¥©¥ë¥ÈÃͤ¬¤¢¤ë
¾ì¹ç¡¤¤³¤Î¥ª¥×¥·¥ç¥ó¤Ç¤Ï¥³¥Þ¥ó¥É¥é¥¤¥ó¤ÇÌÀ¼¨Åª¤ËÅϤµ¤ì¤¿¤â¤Î(¤Þ¤¿¤Ï¡¤¥³
¥ó¥Õ¥£¥°¥ì¡¼¥·¥ç¥ó¥Õ¥¡¥¤¥ë¤«¤éÆÉ¤ß¹þ¤Þ¤ì¤¿¤â¤Î)¤À¤±¤ò¥Õ¥¡¥¤¥ë¤ËÊݸ¤¹¤ë
¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ¤¤¡¥¤Ä¤Þ¤ê¡¤¥Ç¥Õ¥©¥ë¥ÈÃͤϥե¡¥¤¥ë¤ËÊݸ¤µ¤ì¤Þ¤»¤ó¡¥
°Ê²¼¤Ï¡¤¤³¤ì¤é¤Î´Ø¿ô¤òmain¥×¥í¥°¥é¥à¤Ç»ÈÍѤ¹¤ëÊýË¡¤òµ½Ò¤·¤Æ¤¤¤Þ¤¹¡¥
/* main1.cc */ /* we try to use gengetopt generated file in a C++ program */ /* we don’t use autoconf and automake vars */ #include <iostream> #include "stdlib.h" #include "cmdline1.h" using std::cout; using std::endl; int main (int argc, char **argv) { gengetopt_args_info args_info; cout << "This one is from a C++ program" << endl ; cout << "Try to launch me with some options" << endl ; cout << "(type sample1 --help for the complete list)" << endl ; cout << "For example: ./sample1 *.* --funct-opt" << endl ; /* let’s call our cmdline parser */ if (cmdline_parser (argc, argv, &args_info) != 0) exit(1) ; cout << "Here are the options you passed..." << endl; for ( unsigned i = 0 ; i < args_info.inputs_num ; ++i ) cout << "file: " << args_info.inputs[i] << endl ; if ( args_info.funct_opt_given ) cout << "You chose --funct-opt or -F." << endl ; if ( args_info.str_opt_given ) cout << "You inserted " << args_info.str_opt_arg << " for " << "--str-opt option." << endl ; if ( args_info.int_opt_given ) cout << "This is the integer you input: " << args_info.int_opt_arg << "." << endl; if (args_info.flag_opt_given) cout << "The flag option was given!" << endl; cout << "The flag is " << ( args_info.flag_opt_flag ? "on" : "off" ) << "." << endl ; cout << args_info.def_opt_arg << "! "; cout << "Have a nice day! :-)" << endl ; cmdline_parser_free (&args_info); /* release allocated memory */ return 0; }
¤µ¤Æ¡¤main1.cc¤Ègengetopt¤ÇÀ¸À®¤·¤¿cmdline1.c¤ò¥³¥ó¥Ñ¥¤¥ë
¤·¡¤sample1
¤È¤¤¤¦¼Â¹Ô·Á¼°¤òÆþ¼ê¤¹¤ë¤¿¤á¤Ë¡¤¤¹¤Ù¤Æ¤ò¥ê¥ó¥¯¤¹¤ë¤³
¤È¤¬²Äǽ¤È¤Ê¤ê¤Þ¤·¤¿¡¥
gcc -c cmdline1.c g++ -c main1.cc g++ -o sample1 cmdline1.o main1.o
(¤³¤³¤Ç¤Ï¡¤getopt_long
¤¬É¸½àC¥é¥¤¥Ö¥é¥ê¤«¤é¥¤¥ó¥¯¥ë¡¼¥É¤µ¤ì¤Æ¤¤
¤ë¤³¤È¤ò²¾Äꤷ¤Æ¤¤¤Þ¤¹¡¥Installation¤ÈNo getopt_long¤ò»²¾È
¤·¤Æ¤¯¤À¤µ¤¤)
¤µ¤Æ¡¤¤³¤Î¥×¥í¥°¥é¥à¤Ç¥Æ¥¹¥È¤·¤Æ¤ß¤Þ¤·¤ç¤¦¡¥
$ ./sample1 -s "hello" --int-opt 1234 This one is from a C++ program Try to launch me with some options (type sample1 --help for the complete list) For example: ./sample1 *.* --funct-opt Here are the options you passed... You inserted hello for --str-opt option. This is the integer you input: 1234. The flag is off. Have a nice day! :-)
¤¿¤¯¤µ¤ó¤Î¥Õ¥¡¥¤¥ë̾¤ò¥³¥Þ¥ó¥É¥é¥¤¥ó¤ËÅϤ¹¤³¤È¤â²Äǽ¤Ç¤¹(¤³¤ì¤Ç¤â¥Õ¥é¥° ¤ÎưºîÊýË¡¤¬Ê¬¤«¤ê¤Þ¤¹)¡¥
$ ./sample1 *.h -i -100 -x This one is from a C++ program Try to launch me with some options (type sample1 --help for the complete list) For example: ./sample1 *.* --funct-opt Here are the options you passed... file: cmdline1.h file: cmdline2.h file: cmdline.h file: getopt.h This is the integer you input: -100. The flag is on. Have a nice day! :-)
¤½¤·¤Æ¡¤--int-opt
(¤Þ¤¿¤Ï¡¤-i
)¤ò¾Êά¤·¤Æ¤ß¤ë¤È¡¤¤½¤ì¤Ïɬ
¿Ü¤Ê¤Î¤Ç¥¨¥é¡¼¤Ë¤Ê¤ê¤Þ¤¹¡¥
$ ./sample1 This one is from a C++ program Try to launch me with some options (type sample1 --help for the complete list) For example: ./sample1 *.* --funct-opt sample1: `--int-opt' (`-i') option required!
°Ê²¼¤Ï¡¤--help
¤Î½ÐÎϤǤ¹¡¥
sample1 2.0 Usage: sample1 -iINT|--int-opt=INT [-h|--help] [-V|--version] -sfilename|--str-opt=filename -mINT|--my-opt=INT [--flag-opt] [-F|--funct-opt] --long-opt=LONG --def-opt=STRING [FILES]... -h, --help Print help and exit -V, --version Print version and exit -s, --str-opt=filename A string option, for a filename -m, --my-opt=INT Another integer option, this time the description of the option should be quite long to require wrapping... possibly more than one wrapping :-) especially if I require a line break -i, --int-opt=INT A int option more involved options: the following options are more complex --flag-opt A flag option (default=off) -F, --funct-opt A function option last option section: --long-opt=LONG A long option --def-opt=STRING A string option with default (default=`Hello') --enum-opt=STRING A string option with list of values (possible values="foo", "bar", "hello" default=`hello')
¥ª¥×¥·¥ç¥ó--str-opt
¤ËÂФ·¤Æ¡¤STRING
¤Ç¤Ï¤Ê¤¯
filename
¤¬½ÐÎϤµ¤ì¤ë¤³¤È(typestr
¤¬sample1.ggo¥Õ¥¡
¥¤¥ë¤Ç»ÈÍѤµ¤ì¤Æ¤¤¤Þ¤¹)¡¤--my-opt
¤Îµ½Ò¤¬80ʸ»ú¤Ç¤ª¤ê¤«¤¨¤µ¤ì¤Æ
¤¤¤ë¤³¤È¡¤¤½¤·¤Æ¡¤\n
¤¬¼ÂºÝ¤Ë²þ¹Ô¤¬Í׵ᤵ¤ì¤Æ¤¤¤ë¤³¤È¤È¤·¤Æ²ò¼á¤µ
¤ì¤Æ¤¤¤ë¤³¤È¤ËÃíÌܤ·¤Æ¤¯¤À¤µ¤¤¡¥
¿´ÇۤǤ¢¤ì¤Ð¡¤À¸À®¤µ¤ì¤¿C¥Õ¥¡¥¤¥ëcmdline1.c¤ò¸«¤Æ¤¯¤À¤µ¤¤¡¥
/prefix/share/doc/gengetopt/examples¤ä¡¤¥½¡¼¥¹¤Îtarball¤Î tests¤Ç¾¤ÎÎã¤â¸«¤Ä¤«¤ë¤Ç¤·¤ç¤¦¡¥
Ť¹
¤®¤ë¥³¥Þ¥ó¥É¥é¥¤¥ó¤ÏÊ£¿ô¤Î¹Ô¤Ë\
¤Çʬ³ä¤·¤Þ¤¹¡¥¤â¤Á¤í¤ó¡¤¤³¤ì¤é¤Î
¥³¥Þ¥ó¥É¤Ï¡¤¤¤¤º¤ì¤Ë¤»¤è°ì¹Ô¤À¤±¤Ç¤¢¤¿¤¨¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡¥
<option>_orig
¤Ï¡¤¥ê¥ê¡¼¥¹2.14¤ÇƳÆþ¤µ¤ì¤Þ¤·¤¿
¤³¤Î´Ø¿ô¤Ï¥ê¥ê¡¼¥¹2.14¤ÇƳÆþ¤µ ¤ì¤Þ¤·¤¿
Next: Invoking gengetopt, Previous: Installation, Up: Top [Contents][Index]