-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_fields.sh
103 lines (89 loc) · 1.47 KB
/
template_fields.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
FIELDS="
rbrace
lbrace
rpar
lpar
frac_s
frac_m
frac_e
pow_s
pow_m
pow_e
prefix_s
prefix_e
atom_s
atom_e
part_s
part_e
sign
unit_s
unit_e
unitfrac_s
unitfrac_m
unitfrac_e
prefix_sep
"
for a in $(echo ${FIELDS}); do
echo -en "\tconst char * ${a} = NULL;\n\tsize_t ${a}_len = 0;\n"
done
echo "
err_t _us_library_parse_template(us_library_t uslib, sexp_t * template)
{
err_t err = {0};
sexp_t * args;
sexp_t * arg;
sexp_t * val;
args = template->next;
arg = args;
while (arg) {
val = arg->list;
if (val->ty != SEXP_VALUE)
return construct_error(ERR_MAJ_INVALID, ERR_MIN_IN_INVALID, LIBRARY_LIST_START_NOT_VALUE);
"
ELSE=" "
for a in $(echo ${FIELDS}); do
echo -n "${ELSE}if (strncmp(val->val, \"${a}\", val->val_used) == 0) {
err = _us_library_tuple_getval(&${a}, &${a}_len, val);
if (!${a}) {
${a} = \"\";
${a}_len = 0;
}
}"
ELSE=" else "
done
echo
echo
echo "
arg = arg->next;
}
"
PLUS=" size_t pos = 0;
size_t length = "
C=0
for a in $(echo ${FIELDS}); do
if [ $C == 5 ]; then
echo -en "\n "
C=0
fi
echo -en "${PLUS}${a}_len"
PLUS=" + "
C=$((C+1))
done
echo ";"
echo "
checked_array_malloc(uslib->storage, char, 2 * length, err, 0, malloc_error);
"
for a in $(echo ${FIELDS}); do
echo "
memcpy(uslib->storage+pos, ${a}, ${a}_len);
uslib->pattern.${a} = uslib->storage+pos;
pos += ${a}_len; uslib->storage[pos++] = '\0';
/*bt_log(\"${a} set\\n\");*/
"
done
echo "
return err;
malloc_error:
return err;
}
"