blob: e251f5ff7aa16c07b44c7756fa120268ee1f0605 (
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
|
#include <stdio.h>
#include <string.h>
#define X(name) int entry_ ## name (int argc, char **argv);
PROGNAMES_XLIST
#undef X
static char* basename(char *path) {
size_t len = strlen(path);
for (size_t i = len - 1; i != 0; i--) {
if (path[i] == '/') return path + (i + 1);
}
return path;
}
int main(int argc, char **argv) {
const char *prognamearg = basename(argv[0]);
if (strcmp(prognamearg, "drukkedoos") == 0) {
argv++;
argc--;
if (argc == 0) {
#define X(name) " " #name "\n"
fprintf(stderr, "Gebruik: drukkedoos <commando>\n\n"
"Hulpmiddelen:\n"
PROGNAMES_XLIST);
#undef X
return 1;
}
prognamearg = basename(argv[0]);
}
#define X(name) if (strcmp(prognamearg, #name) == 0) return entry_ ## name (argc, argv);
PROGNAMES_XLIST
#undef X
fprintf(stderr, "Onbekend hulpmiddel: '%s'\n", prognamearg);
return 1;
}
|