-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcons_str2glob.c
76 lines (55 loc) · 1.9 KB
/
cons_str2glob.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
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
#include"strglob.h"
/*! @fn STR_GLOB *cons_str2glob(const char *istr)
*
* @brief construct glob linked list from the given string
*
* @param [in] istr an input string that possibly contains one or more glob patterns
*
* @return a glob list representing the provided string after wildcard expansion
*/
STR_GLOB *cons_str2glob(const char *istr) {
register STR_GLOB *restrict pugp = NULL, *restrict pghd = NULL;
const char *input_ptr = NULL;
pghd = calloc(1, sizeof *pghd);
if(!pghd)
exit_verbose("calloc", __FILE__, __LINE__);
pugp = pghd;
input_ptr = istr;
while(input_ptr && *input_ptr) {
char *next_syntax = strpbrk(input_ptr, "[{");
if(!next_syntax) {
input_ptr = next_string(input_ptr, pugp);
#ifdef DEBUG_STRGLOB
fprintf(stderr, "Inside !next_syntax if block! input_ptr: %p pugp: %p\n", input_ptr, pugp);
#endif
break;
}
const char char_syntax = *next_syntax;
*next_syntax = '\0';
if(next_syntax != input_ptr) {
input_ptr = next_string(input_ptr, pugp);
pugp->next = calloc(1, sizeof *pugp);
if(!pugp->next)
perror("calloc");
#ifdef DEBUG_STRGLOB
fprintf(stderr, "STR_GLOB calloc#1: pugp: %p pugp->next: %p\n", (unsigned int)pugp, (unsigned int)pugp->next);
#endif
pugp = pugp->next;
}
if(char_syntax == '[')
input_ptr = open_bracket(next_syntax, pugp);
else if(char_syntax == '{')
input_ptr = open_brace(next_syntax, pugp);
else if(char_syntax == '(')
input_ptr = open_paren(next_syntax, pugp);
pugp->next = calloc(1, sizeof *pugp);
if(!pugp->next)
perror("calloc");
#ifdef DEBUG_STRGLOB
fprintf(stderr, "STR_GLOB calloc#2 pugp: %p pugp->next: %p\n", (unsigned int)pugp, (unsigned int)pugp->next);
#endif
pugp = pugp->next;
}
init_strglob(pghd);
return pghd;
}