File:  [Local Repository] / gnujdoc / gengetopt-2.14 / main1.cc.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{ main1.cc }}@r{@i{*/}}
    4: @r{@i{/*}}@r{@i{ we try to use gengetopt generated file in a C++ program }}@r{@i{*/}}
    5: @r{@i{/*}}@r{@i{ we don't use autoconf and automake vars }}@r{@i{*/}}
    6: 
    7: @b{#include} @t{<iostream>}
    8: @b{#include} @t{"stdlib.h"}
    9: 
   10: @b{#include} @t{"cmdline1.h"}
   11: 
   12: @b{using} std::cout;
   13: @b{using} std::endl;
   14: 
   15: @b{int}
   16: main (@b{int} argc, @b{char} **argv)
   17: @{
   18:   gengetopt_args_info args_info;
   19: 
   20:   cout << @t{"This one is from a C++ program"} << endl ;
   21:   cout << @t{"Try to launch me with some options"} << endl ;
   22:   cout << @t{"(type sample1 --help for the complete list)"} << endl ;
   23:   cout << @t{"For example: ./sample1 *.* --funct-opt"} << endl ;
   24: 
   25:   @r{@i{/*}}@r{@i{ let's call our cmdline parser }}@r{@i{*/}}
   26:   @b{if} (cmdline_parser (argc, argv, &args_info) != 0)
   27:     exit(1) ;
   28: 
   29:   cout << @t{"Here are the options you passed..."} << endl;
   30: 
   31:   @b{for} ( @b{unsigned} i = 0 ; i < args_info.inputs_num ; ++i )
   32:     cout << @t{"file: "} << args_info.inputs[i] << endl ;
   33: 
   34:   @b{if} ( args_info.funct_opt_given )
   35:     cout << @t{"You chose --funct-opt or -F."} << endl ;
   36: 
   37:   @b{if} ( args_info.str_opt_given )
   38:     cout << @t{"You inserted "} << args_info.str_opt_arg << @t{" for "} <<
   39:       @t{"--str-opt option."} << endl ;
   40: 
   41:   @b{if} ( args_info.int_opt_given )
   42:     cout << @t{"This is the integer you input: "} << 
   43:       args_info.int_opt_arg << @t{"."} << endl;
   44: 
   45:   @b{if} (args_info.flag_opt_given)
   46:     cout << @t{"The flag option was given!"} << endl;
   47: 
   48:   cout << @t{"The flag is "} << ( args_info.flag_opt_flag ? @t{"on"} : @t{"off"} ) <<
   49:     @t{"."} << endl ;
   50: 
   51:   cout << args_info.def_opt_arg << @t{"! "};
   52: 
   53:   cout << @t{"Have a nice day! :-)"} << endl ;
   54: 
   55:   cmdline_parser_free (&args_info); @r{@i{/*}}@r{@i{ release allocated memory }}@r{@i{*/}}
   56: 
   57:   @b{return} 0;
   58: @}
   59: 
   60: @end smallexample

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