-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle_strglob.c
61 lines (43 loc) · 1.3 KB
/
handle_strglob.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
#include"strglob.h"
/*! @fn HAND_GLOB *handle_strglob(const char *apat)
*
* @brief create new handle from provided string that contains glob pattern
*
* @return pointer to a newly created handle data structure
*
* @see fputs_strglob
*/
HAND_GLOB *handle_strglob(const char *apat) {
STR_GLOB *const pugh = cons_str2glob(apat);
int **const sets = cons_glob2ints(pugh);
int *const lens = calc_setlens(sets);
const int *lp = lens;
size_t asiz = 1;
if(lp) {
while(*lp > 0)
lp++;
asiz += (lp - lens);
}
int *cset = malloc(asiz * sizeof *cset);
if(!cset)
exit_verbose("malloc", __FILE__, __LINE__);
HAND_GLOB *const ahnd = malloc(sizeof *ahnd);
if(!ahnd)
exit_verbose("malloc", __FILE__, __LINE__);
int *anindex = malloc(sizeof*anindex);
if(!anindex)
exit_verbose("malloc", __FILE__, __LINE__);
*anindex = 0;
int ***results = malloc(sizeof**results);
if(!results)
exit_verbose("malloc", __FILE__, __LINE__);
*results = NULL;
ahnd->carp = cartesian_product(sets, lens, cset, asiz--, 0, results, anindex);
ahnd->carp = *results;
ahnd->glob = pugh;
#ifdef DEBUG_STRGLOB
fprintf(stderr, "handle_strglob done! ahnd->size: %d\n", ahnd->size);
#endif
ahnd->size = asiz;
return ahnd;
}