diff --git a/b2/subex.c b/b2/subex.c index b073afb..06d5f77 100644 --- a/b2/subex.c +++ b/b2/subex.c @@ -48,7 +48,7 @@ static char *canonicalize(const char *s, char unit) return stralloc(s); res = stralloc(""); while (*s) { - if (*s == unit) { + if (*s == unit && unit != '#') { assert(!seen_unit); if (!s[1]) break; @@ -82,7 +82,8 @@ static char *canonicalize(const char *s, char unit) res_len--; if (mult) append_char(&res, &res_len, mult); - append_char(&res, &res_len, unit); + if (unit != '#') + append_char(&res, &res_len, unit); return res; } diff --git a/b2/subst.c b/b2/subst.c index 0474ee1..a6f10db 100644 --- a/b2/subst.c +++ b/b2/subst.c @@ -55,9 +55,11 @@ static struct subst *alloc_subst(enum subst_type type) static void unit_expr(char **res, int *res_len, char unit) { append(res, res_len, "(-?[0-9]+\\.?[0-9]*[" MULT_CHARS "]?"); - append_char(res, res_len, unit); + if (unit != '#') + append_char(res, res_len, unit); append(res, res_len, "?|-?[0-9]+["); - append_char(res, res_len, unit); + if (unit != '#') + append_char(res, res_len, unit); append(res, res_len, MULT_CHARS "][0-9]*)"); } @@ -90,7 +92,8 @@ static char *prepare_re(const char *re, char *units) case '(': parens++; if (re[1] == '#' && re[2]) { - if ((!isalpha(re[2]) && re[2] != '%') || + if ((!isalpha(re[2]) && + re[2] != '%' && re[2] != '#') || re[3] != ')') yyerrorf("invalid (#unit) syntax"); units[parens-1] = re[2];