3 #include "arg_parser.h"
7 int get_values_from_command_line(int argc
, char **argv
,
14 struct arg_str
*name
= arg_str1("n", "name", "<string>", "the name of the person");
15 struct arg_file
*xpm_file
= arg_file1("f", "xpm_file", "<file>", "the xpm file path");
16 struct arg_int
*day
= arg_int1("d", "day", "int", "the day of birth");
17 struct arg_int
*month
= arg_int1("m", "month", "int", "the month of birth");
18 struct arg_int
*year
= arg_int1("y", "year", "int", "the year of birth");
19 struct arg_lit
*version
= arg_lit0("v", "version", "print the version and exit");
20 struct arg_lit
*help
= arg_lit0(NULL
, "help", "print this help and exit");
21 struct arg_end
*end
= arg_end(20);
22 void* argtable
[] = {name
, xpm_file
, day
, month
, year
, help
, version
, end
};
23 const char* progname
= "wmframepic";
25 int exitcode
= COMMAND_LINE_SUCCESS
;
28 /* verify the argtable[] entries were allocated sucessfully */
29 if (arg_nullcheck(argtable
) != 0) {
30 /* NULL entries were detected, some allocations must have failed */
31 printf("%s: insufficient memory\n", progname
);
32 exitcode
= COMMAND_LINE_FAIL
;
36 /* Parse the command line as defined by argtable[] */
37 nerrors
= arg_parse(argc
,argv
,argtable
);
39 /* special case: '--help' takes precedence over error reporting */
40 if (help
->count
> 0) {
42 "This is a dockapp written for Window Maker and any other window manager\n\
43 that suports the dock (or slit), like the Window Maker itself, Fluxbox, \n\
44 Blackbox and others.\n\n");
46 "It's meant to show the picture of your kid (or any beloved one) on your\n\
47 screen and when pressed, it will show how old he/she is. Pretty silly but\n\
48 I'm sure you will enjoy!\n\n");
50 printf("Usage: %s", progname
);
51 arg_print_syntax(stdout
, argtable
, "\n");
53 arg_print_glossary(stdout
, argtable
, " %-25s %s\n");
54 exitcode
= COMMAND_LINE_HELP
;
58 if (version
->count
> 0) {
59 printf("%s\n", PACKAGE_STRING
);
60 exitcode
= COMMAND_LINE_HELP
;
64 /* If the parser returned any errors then display them and exit */
66 /* Display the error details contained in the arg_end struct.*/
67 arg_print_errors(stdout
, end
, progname
);
68 printf("Try '%s --help' for more information.\n", progname
);
69 exitcode
= COMMAND_LINE_FAIL
;
73 /* only get here is command line arguments were parsed sucessfully */
75 strncpy(my_name
, *name
->sval
, 9);
76 *my_file
= malloc(strlen(xpm_file
->filename
[0]) * sizeof(char) + 1);
77 strcpy(*my_file
, xpm_file
->filename
[0]);
80 *my_month
= *month
->ival
;
81 *my_year
= *year
->ival
;
84 /* deallocate each non-null entry in argtable[] */
85 arg_freetable(argtable
,sizeof(argtable
)/sizeof(argtable
[0]));