summaryrefslogtreecommitdiff
path: root/support/dktools/test-opt.ctr
blob: 2b9e7f6dc4a751bc5427845373340d65d4b32c4a (plain)
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
75
76
77
78
79
80

#include "dk4conf.h"
#include "dk4types.h"
#include "dk4mem.h"
#include "dk4opt.h"



$!trace-include



/**	Command line options for program.
*/
static	dk4_option_t	options[] = {
  { { dkT('i'),	dkT("interactive"),	DK4_OPT_ARG_NONE },	{ NULL }, 0},
  { { dkT('s'),	dkT("socket"),		DK4_OPT_ARG_STRING },	{ NULL }, 0},
  { { dkT('h'),	dkT("host"),		DK4_OPT_ARG_STRING },	{ NULL }, 0},
  { { dkT('p'),	dkT("port"),		DK4_OPT_ARG_UNSIGNED },	{ NULL }, 0}
};



static const size_t szoptions = sizeof(options)/sizeof(dk4_option_t);


/**	Main function.
	@param	argc	Number of command line arguments.
	@param	argv	Command line arguments array.
	@return	0 on success, all other values indicate errors.
*/
#if DK4_CHAR_SIZE > 1
int
wmain(int argc, wchar_t *argv[])
#else
int
main(int argc, char *argv[])
#endif
{
  dkChar	*filenames[32];
  size_t	 szfn	= DK4_SIZEOF(filenames,DK4_PDKCHAR);
  int	res;

  $!trace-init	test-opt.deb
  $? "+ main"
  res = dk4opt_process_argv(
    options, szoptions, argc, argv,
    filenames, &szfn, 1, 1, NULL
  );
  if (0 != res) {
    if (0 != options[0].found) {
      fputs("Option -i found.\n", stdout);
    }
    if (0 != options[1].found) {
      fputs("Option -s found.\nArgument: ", stdout);
      if (NULL != options[1].val.t) {
        fputs(options[1].val.t, stdout);
      }
      fputc('\n', stdout);
      fflush(stdout);
    }
    if (0 != options[2].found) {
      fputs("Option -h found.\n", stdout);
      if (NULL != options[2].val.t) {
        fputs(options[2].val.t, stdout);
      }
      fputc('\n', stdout);
      fflush(stdout);
    }
    if (0 != options[3].found) {
      fputs("Option -p found.\n", stdout);
      fprintf(stdout, "Argument: %ju\n", options[3].val.u);
      fflush(stdout);
    }
  }
  $? "- main"
  $!trace-end
  exit(0); return 0;
}