File:  [Local Repository] / gnujdoc / gengetopt-2.14 / test_conf_parser.c.texinfo
Revision 1.1: download - view: text, annotated - select for diffs
Fri Oct 28 13:07:30 2005 UTC (15 years ago) by futoshi
Branches: MAIN
CVS tags: HEAD
Add gengetopt-2.14.

    1: @c Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
    2: @smallexample
    3: @r{@i{/*}}@r{@i{ test_conf_parser.c test }}@r{@i{*/}}
    4: 
    5: @r{@i{/*}}@r{@i{ test all kinds of options and the conf file parser }}@r{@i{*/}}
    6: 
    7: @b{#include} @t{<stdlib.h>}
    8: @b{#include} @t{<stdio.h>}
    9: 
   10: @b{#include} @t{"test_conf_parser_cmd.h"}
   11: 
   12: @b{static} @b{struct} my_args_info args_info;
   13: 
   14: @b{int}
   15: main (@b{int} argc, @b{char} **argv)
   16: @{  
   17:   @b{int} i;
   18:   @b{int} result = 0;
   19: 
   20:   @b{if} (test_conf_parser_cmd_parser (argc, argv, &args_info) != 0) @{
   21:     result = 1;
   22:     @b{goto} stop;
   23:   @}
   24: 
   25:   @r{@i{/*}}@r{@i{ override cmd options, but do not initialize args_info, check for required options }}@r{@i{*/}}
   26:   @b{if} (test_conf_parser_cmd_parser_configfile
   27:       (args_info.conf_file_arg, &args_info, 1, 0, 1) != 0) 
   28:     @{
   29:       result = 1;
   30:       @b{goto} stop;
   31:     @}
   32: 
   33:   printf (@t{"value of required: %s\n"}, args_info.required_arg);
   34:   printf (@t{"value of string: %s\n"}, args_info.string_arg);
   35:   printf (@t{"value of no-short_given: %d\n"}, args_info.no_short_given);
   36:   printf (@t{"value of int: %d\n"}, args_info.int_arg);
   37:   printf (@t{"value of float: %f\n"}, args_info.float_arg);
   38: 
   39:   printf (@t{"value of multi-string_given: %d\n"}, args_info.multi_string_given);
   40:   @b{for} (i = 0; i < args_info.multi_string_given; ++i)
   41:     printf (@t{"  value of multi-string: %s\n"}, args_info.multi_string_arg [i]);
   42: 
   43:   printf (@t{"value of multi-string-def_given: %d\n"},
   44:           args_info.multi_string_def_given);
   45:   @b{for} (i = 0; i < args_info.multi_string_def_given; ++i)
   46:     printf (@t{"  value of multi-string-def: %s\n"},
   47:             args_info.multi_string_def_arg [i]);
   48:   @b{if} (!args_info.multi_string_def_given && args_info.multi_string_def_arg [0])
   49:     printf (@t{"default value of multi-string-def: %s\n"},
   50:             args_info.multi_string_def_arg [0]);
   51: 
   52:   printf (@t{"value of opta: %s\n"}, args_info.opta_arg);
   53: 
   54:   printf (@t{"noarg given %d times\n"}, args_info.noarg_given);
   55:   printf (@t{"noarg_noshort given %d times\n"}, args_info.noarg_noshort_given);
   56: 
   57:   printf (@t{"opt-arg given: %d\n"}, args_info.opt_arg_given);
   58:   printf (@t{"opt-arg value: %s\n"}, (args_info.opt_arg_arg ? args_info.opt_arg_arg : @t{"not given"}));
   59: 
   60:   @b{if} (args_info.file_save_given) @{
   61:     @b{if} (test_conf_parser_cmd_parser_file_save (args_info.file_save_arg, &args_info) == EXIT_FAILURE)
   62:       result = 1;
   63:     @b{else}
   64:       printf (@t{"saved configuration file %s\n"}, args_info.file_save_arg);
   65:   @}
   66: 
   67:  stop:
   68:   test_conf_parser_cmd_parser_free (&args_info);
   69: 
   70:   @b{return} result;
   71: @}
   72: 
   73: @end smallexample

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>