Next: No getopt_long, Previous: Configuration files, Up: Top [Contents][Index]
¥ª¥×¥·¥ç¥ó¤¬multiple
¤È¤·¤Æ»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¤¤½¤ì¤ò¥³¥Þ¥ó¥É¥é¥¤
¥ó¤ÇÊ£¿ô²ó»ØÄꤹ¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡¥¤³¤³¤Ç¡¤¥ª¥×¥·¥ç¥ó¤òfoo
¤È²¾Äê
¤¹¤ë¤È¡¤À¸À®¤µ¤ì¤ë°ú¿ô¤Î¹½Â¤ÂΤÎfoo_given
¥Õ¥£¡¼¥ë¥É¤Ë¤Ï¡¤»ØÄꤵ
¤ì¤¿²ó¿ô¤¬´Þ¤Þ¤ì¡¤À¸À®¤µ¤ì¤ëfoo_arg
¥Õ¥£¡¼¥ë¥É¤Ï¡¤¤³¤Î¥ª¥×¥·¥ç¥ó
¤Ç»ØÄꤵ¤ì¤¿¤¹¤Ù¤Æ¤ÎÃͤò´Þ¤ó¤Ç¤¤¤ëÇÛÎó¤Ë¤Ê¤ê¤Þ¤¹¡¥
Ê£¿ô²ó¥ª¥×¥·¥ç¥ó¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤ¬»ØÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¤¤½¤ì°Ê³°¤ÎÃͤ¬¥³¥Þ
¥ó¥É¥é¥¤¥ó¤Ç»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç¤À¤±³ä¤êÅö¤Æ¤é¤ì¤ë¤³¤È¤ËÃí°Õ¤·¤Æ¤¯¤À¤µ
¤¤(¤½¤Î¤È¤¤Ï¡¤Âбþ¤¹¤ë_given
¥Õ¥£¡¼¥ë¥É¤Ï1¤ËÀßÄꤵ¤ì¤Þ¤¹)¡¥¤¹¤Ê
¤ï¤Á¡¤¥Ç¥Õ¥©¥ë¥ÈÃͤϾï¤ËÊ£¿ô²ó¥ª¥×¥·¥ç¥ó¤ÎÃͤˤʤë¤ï¤±¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡¥
Î㤨¤Ð¡¤gengetopt¤Ø¤Î¥Õ¥¡¥¤¥ë¤¬°Ê²¼¤Î¤â¤Î¤ò¹Í¤¨¤Þ¤¹¡¥
# test options that can be given more than once option "string" s "string option" string no multiple option "int" i "int option" int no multiple
¤½¤·¤Æ¡¤¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó¤ò°Ê²¼¤Î¤è¤¦¤Ë¤Þ¤È¤á¤ë¤³¤È¤¬²Äǽ¤Ç¤¹¡¥
¥×¥í¥°¥é¥à¤¬°Ê²¼¤Î¥³¥Þ¥ó¥É¥é¥¤¥ó¥ª¥×¥·¥ç¥ó¤Ç¸Æ¤Ó½Ð¤µ¤ì¤ë¤È²¾Äꤷ¤Þ¤¹¡¥
/* test options that can be given more than once */ #include <stdlib.h> #include <stdio.h> #include "test_multiple_cmd.h" static struct gengetopt_args_info args_info; int main (int argc, char **argv) { int i = 0; if (test_multiple_cmd_parser (argc, argv, &args_info) != 0) exit(1) ; for (i = 0; i < args_info.string_given; ++i) printf ("passed string: %s\n", args_info.string_arg[i]); for (i = 0; i < args_info.int_given; ++i) printf ("passed int: %d\n", args_info.int_arg[i]); return 0; }
¥×¥í¥°¥é¥à¤Î½ÐÎϤϰʲ¼¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡¥
passed string: world passed string: hello passed string: bar passed string: foo passed int: 200 passed int: 100
°Ê²¼¤Î¤è¤¦¤Ë¡¤Ê£¿ô²ó¥ª¥×¥·¥ç¥ó¤Ë¥«¥ó¥Þ¤ÇʬΥ¤·¤¿°ú¿ô¤òÅϤ¹¤³¤È¤â²Äǽ¤Ç ¤¹¡¥
./test_multiple -s"foo","bar","hello" -i100,200 -s "world"