-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_function.c
46 lines (31 loc) · 924 Bytes
/
main_function.c
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
#include"strglob.h"
static void show_usage(const char *const anarg) {
fprintf(stderr, "usage: %s STRING\n", anarg);
exit(EX_USAGE);
}
/*!
* Sample of using libstrglob to generate strings based on a glob pattern
*/
int main(int argc, char *argv[]) {
if(argc < 2)
show_usage(*argv);
const char *restrict anarg = strdup(argv[1]);
if(!anarg)
exit_verbose("strdup", __FILE__, __LINE__);
const HAND_GLOB *hand = handle_strglob(anarg);
if(!hand) {
fputs("*** Failure!\n", stderr);
exit(EXIT_FAILURE);
}
char *restrict *restrict strs = copy_strglob(hand);
if(!strs) {
fputs("*** Null string array!\n", stderr);
exit(EXIT_FAILURE);
} else
if(!*strs) {
fputs("*** Empty string array!\n", stderr);
exit(EXIT_FAILURE);
}
fputs_strglob(hand, stdout);
exit(EXIT_SUCCESS);
}