Skip to content

Commit ff7f0d3

Browse files
committed
Add getopt long options
1 parent 44205b9 commit ff7f0d3

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

main.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ static bool no_duplicates;
1919
static bool no_footer;
2020
static bool no_header;
2121

22+
static const struct option long_options[] = {
23+
{"bare", no_argument, NULL, 'b'},
24+
{"help", no_argument, NULL, 'h'},
25+
{"no-duplicates", no_argument, NULL, 'n'},
26+
{0, 0, 0, 0}
27+
};
28+
2229
static const char labwc_menu_generator_usage[] =
2330
"Usage: labwc-menu-generator [options...]\n"
24-
" -h show help message and quit\n"
25-
" -n limit desktop entries to one directory only\n";
31+
" -b, --bare Show no header or footer\n"
32+
" -h, --help Show help message and quit\n"
33+
" -n, --no-duplicates Limit desktop entries to one directory only\n";
2634

2735
static void
2836
usage(void)
@@ -263,7 +271,12 @@ int
263271
main(int argc, char **argv)
264272
{
265273
int c;
266-
while ((c = getopt(argc, argv, "bhn")) != -1) {
274+
while (1) {
275+
int index = 0;
276+
c = getopt_long(argc, argv, "bhn", long_options, &index);
277+
if (c == -1) {
278+
break;
279+
}
267280
switch (c) {
268281
case 'b':
269282
no_footer = true;
@@ -277,6 +290,9 @@ main(int argc, char **argv)
277290
usage();
278291
}
279292
}
293+
if (optind < argc) {
294+
usage();
295+
}
280296

281297
GList *apps = desktop_entries_create();
282298
GList *dirs = directory_entries_create();

0 commit comments

Comments
 (0)