/* XXX may need to modify in the future? */ void canonify_r(struct object **op) { struct object *o = *op; while (o) { switch (o->type) { case T_ALTERNATION: canonify_r(&o->u.alternation.left); canonify_r(&o->u.alternation.right); break; case T_RULE: /* nothing to do */ break; case T_GROUP: canonify_r(&o->u.e.e.group); break; case T_TERMSTR: canonify_str(o); break; case T_TERMRANGE: case T_PROSE: default: /* nothing to do */ break; } o = o->next; } }
/* XXX may need to modify in the future? */ void canonify_r(struct object **op) { struct object *o = *op; while (o) { switch (o->type) { case T_ALTERNATION: canonify_r(&o->u.alternation.left); canonify_r(&o->u.alternation.right); break; case T_RULE: /* nothing to do */ break; case T_GROUP: canonify_r(&o->u.e.e.group); break; case T_TERMSTR: while (o->next && o->next->type == T_TERMSTR && o->u.e.repetition.lo == 1 && o->u.e.repetition.hi == 1 && o->next->u.e.repetition.lo == 1 && o->next->u.e.repetition.hi == 1 && ((o->u.e.e.termstr.flags & F_CASESENSITIVE) == (o->next->u.e.e.termstr.flags & F_CASESENSITIVE))) { int len = strlen(o->u.e.e.termstr.str) + strlen(o->next->u.e.e.termstr.str); char *p = malloc(len + 1); strcpy(p, o->u.e.e.termstr.str); strcat(p, o->next->u.e.e.termstr.str); free(o->u.e.e.termstr.str); o->u.e.e.termstr.str = p; /* XXX leak o->next */ o->next = o->next->next; } if (o->u.e.e.termstr.flags & F_CASESENSITIVE) { int anybad = 0; char *p; for (p = o->u.e.e.termstr.str; *p; p++) { if (isalpha(*p) || *p == '"' || !isprint(*p)) { anybad = 1; break; } } if (anybad == 0) o->u.e.e.termstr.flags &= ~F_CASESENSITIVE; } case T_TERMRANGE: case T_PROSE: default: /* nothing to do */ break; } o = o->next; } }
void canonify(struct rule *rules) { struct rule *r; for (r = rules; r; r = r->next) { if (r->rule) canonify_r(&r->rule); if (r->next == rules) break; } }