File: more_than_once.c

package info (click to toggle)
gengetopt 2.23%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 5,032 kB
  • sloc: cpp: 14,765; ansic: 8,232; sh: 4,782; makefile: 754; yacc: 514; lex: 179; sed: 3
file content (57 lines) | stat: -rw-r--r-- 1,052 bytes parent folder | download | duplicates (3)
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
/* more_than_once.c test */

/* it will call the command line parser more than once */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <stdio.h>

#include "more_than_once_cmd.h"

void
print_args (void);

static struct gengetopt_args_info args_info;

int
main (int argc, char **argv)
{  
  /* let's call our cmdline parser a first time */
  if (more_than_once_cmd_parser (argc, argv, &args_info) != 0)
    exit (1);

  print_args ();

  more_than_once_cmd_parser_free (&args_info);

  /* OK, let's call it again! */
  if (more_than_once_cmd_parser (argc, argv, &args_info) != 0)
    exit (1);

  print_args ();

  more_than_once_cmd_parser_free (&args_info);

  return 0;
}

void
print_args (void)
{
  unsigned int i;

  if (args_info.foo_given)
    printf ("foo option: %d\n", args_info.foo_arg);

  if (args_info.bar_given)
    printf ("bar option: %s\n", args_info.bar_arg);

  if (args_info.inputs_num)
    {
      for (i = 0; i < args_info.inputs_num; ++i)
        printf ("arg: %s\n", args_info.inputs [i]);
    }
}