use b_plain use cz/vars split_vars() vec *vars vars = split_vars_1_vos(var_protos) vec_free(var_protos) var_protos = vars vars = split_vars_1_vov(local_and_global_vars) vec_free(local_and_global_vars) local_and_global_vars = vars vars = split_vars_1_vov(var_assignments) vec_clear(var_assignments) for_vec(i, vars, vec*) boolean assignment = 0 for_vec(j, *i, cstr) if strchr(*j, '=') assignment = 1 break if assignment vec_push(var_assignments, *i) else vec_push(local_and_global_vars, *i) vec_free(vars) vec *split_vars_1_vos(vec *in) vec *out cz_new_parse_vos(out) for_vec(i, in, cstr) cstr l = *i split_vars_1_s(out, l, l, 0) return out vec *split_vars_1_vov(vec *in) vec *out cz_new_parse_vov(out) for_vec(i, in, vec*) vec *decl = *i cstr l = *(cstr*)vec0(decl) if veclen(decl) > 1 # has a multi-line assignment; # assume it doesn't have multiple variables! vec_push(out, decl) continue split_vars_1_s(out, l, decl, 1) return out split_vars_1_s(vec *out, cstr l, void *decl, boolean is_vov) # this is FUGLY if !strchr(l, ',') vec_push(out, decl) return # we might have multiple variables # FIXME this splitter does not handle all possible C syntax # method: read tokens until find a , notice = [] # before that, and position of name which is previous # token char *type = l int typelen = 0 char *name = NULL int namelen = 0 char *array = NULL char *assign = NULL char *p = l char *after_delim = NULL int bracket_depth = 0 repeat char *p0 = p token_t t = token(&p) if t == BRACKET if bracket_depth == 0 && *p0 == '[' && !assign array = p0 bracket_depth += bracket_type(*p0) if bracket_depth != 0 if t == TOK_EOT error("mismatched brackets: %s", l) continue if t == NAME && !array && !assign name = p0 namelen = p - p0 eif *p0 == '=' && p == p0+1 assign = p0 eif t == TOK_EOT || *p0 == ',' while name > l && among(name[-1], '*', '&') --name ; ++namelen # char *c is ok, char* c is not. if name && !typelen typelen = name - type if !name || !namelen || !typelen || (after_delim && name != after_delim) # too complicated or wrong! # don't split it vec_push(out, decl) break while p0 > l && p0[-1] == ' ' --p0 new(b, buffer, 128) buffer_cat_range(b, type, type+typelen) buffer_cat_range(b, name, p0) cstr l2 = buffer_to_cstr(b) if is_vov New(v, vec, cstr, 1) vec_push(v, l2) vec_push(out, v) else vec_push(out, l2) if t == TOK_EOT break after_delim = p0 + 1 while *after_delim == ' ' ++after_delim if !*after_delim break name = NULL namelen = 0 array = NULL assign = NULL