File: main1.cc.texinfo

package info (click to toggle)
gengetopt 2.22.6+dfsg0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,732 kB
  • sloc: cpp: 14,709; sh: 11,845; ansic: 8,030; makefile: 689; yacc: 514; lex: 171; sed: 3
file content (74 lines) | stat: -rw-r--r-- 2,221 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
@c Generator: GNU source-highlight, by Lorenzo Bettini, http://www.gnu.org/software/src-highlite
@example
@r{@i{/* main1.cc */}}
@r{@i{/* we try to use gengetopt generated file in a C++ program */}}
@r{@i{/* we don't use autoconf and automake vars */}}

@b{#ifdef} HAVE_CONFIG_H
@b{#include} @t{"config.h"}
@b{#endif}

@b{#include} @t{<iostream>}
@b{#include} @t{"stdlib.h"}

@b{#include} @t{"cmdline1.h"}

@b{using} std::cout;
@b{using} std::endl;

@b{int}
main (@b{int} argc, @b{char} **argv)
@{
  gengetopt_args_info args_info;

  cout << @t{"This one is from a C++ program"} << endl ;
  cout << @t{"Try to launch me with some options"} << endl ;
  cout << @t{"(type sample1 --help for the complete list)"} << endl ;
  cout << @t{"For example: ./sample1 *.* --funct-opt"} << endl ;

  @r{@i{/* let's call our cmdline parser */}}
  @b{if} (cmdline_parser (argc, argv, &args_info) != 0)
    exit(1) ;

  cout << @t{"Here are the options you passed..."} << endl;

  @b{for} ( @b{unsigned} i = 0 ; i < args_info.inputs_num ; ++i )
    cout << @t{"file: "} << args_info.inputs[i] << endl ;

  @b{if} ( args_info.funct_opt_given )
    cout << @t{"You chose --funct-opt or -F."} << endl ;

  @b{if} ( args_info.str_opt_given )
    cout << @t{"You inserted "} << args_info.str_opt_arg << @t{" for "} <<
      @t{"--str-opt option."} << endl ;

  @b{if} ( args_info.int_opt_given )
    cout << @t{"This is the integer you input: "} << 
      args_info.int_opt_arg << @t{"."} << endl;

  @b{if} (args_info.flag_opt_given)
    cout << @t{"The flag option was given!"} << endl;

  cout << @t{"The flag is "} << ( args_info.flag_opt_flag ? @t{"on"} : @t{"off"} ) <<
    @t{"."} << endl ;

  @b{if} (args_info.enum_opt_given) @{
    cout << @t{"enum-opt value: "} << args_info.enum_opt_arg << endl;
    cout << @t{"enum-opt (original specified) value: "} 
        << args_info.enum_opt_orig << endl;
  @}

  @b{if} (args_info.secret_given)
    cout << @t{"Secret option was specified: "} << args_info.secret_arg
        << endl;

  cout << args_info.def_opt_arg << @t{"! "};

  cout << @t{"Have a nice day! :-)"} << endl ;

  cmdline_parser_free (&args_info); @r{@i{/* release allocated memory */}}

  @b{return} 0;
@}

@end example