X-Git-Url: https://git.cameronkatri.com/mandoc.git/blobdiff_plain/52f37ad3e3a4f0b73bd7004eb2d85958efabb3b0..0d3c1e62ca62e820e20a744760c2767cee37d5c9:/out.c diff --git a/out.c b/out.c index 9e50628a..2a683fae 100644 --- a/out.c +++ b/out.c @@ -1,4 +1,4 @@ -/* $Id: out.c,v 1.19 2010/07/18 23:06:18 kristaps Exp $ */ +/* $Id: out.c,v 1.29 2010/08/29 11:28:09 kristaps Exp $ */ /* * Copyright (c) 2009, 2010 Kristaps Dzonsons * @@ -116,6 +116,7 @@ a2roffsu(const char *src, struct roffsu *dst, enum roffscale def) return(0); } + /* FIXME: do this in the caller. */ if ((dst->scale = atof(buf)) < 0) dst->scale = 0; dst->unit = unit; @@ -171,6 +172,7 @@ a2roffdeco(enum roffdeco *d, const char **word, size_t *sz) int i, j, lim; char term, c; const char *wp; + enum roffdeco dd; *d = DECO_NONE; lim = i = 0; @@ -218,24 +220,16 @@ a2roffdeco(enum roffdeco *d, const char **word, size_t *sz) break; } break; - case ('*'): - *d = DECO_RESERVED; - switch (wp[i++]) { - case ('('): - lim = 2; - break; - case ('['): - term = ']'; - break; - default: - i--; - lim = 1; - break; - } - break; + case ('k'): + /* FALLTHROUGH */ case ('M'): /* FALLTHROUGH */ case ('m'): + /* FALLTHROUGH */ + case ('*'): + if ('*' == c) + *d = DECO_RESERVED; + switch (wp[i++]) { case ('('): lim = 2; @@ -249,11 +243,16 @@ a2roffdeco(enum roffdeco *d, const char **word, size_t *sz) break; } break; + case ('h'): + /* FALLTHROUGH */ + case ('v'): + /* FALLTHROUGH */ case ('s'): - if ('+' == wp[i] || '-' == wp[i]) + j = 0; + if ('+' == wp[i] || '-' == wp[i]) { i++; - - j = ('s' != wp[i - 1]); + j = 1; + } switch (wp[i++]) { case ('('): @@ -265,6 +264,9 @@ a2roffdeco(enum roffdeco *d, const char **word, size_t *sz) case ('\''): term = '\''; break; + case ('0'): + j = 1; + /* FALLTHROUGH */ default: i--; lim = 1; @@ -272,13 +274,31 @@ a2roffdeco(enum roffdeco *d, const char **word, size_t *sz) } if ('+' == wp[i] || '-' == wp[i]) { - if (j++) + if (j) return(i); i++; } - - if (0 == j) - return(i); + + /* Handle embedded numerical subexp or escape. */ + + if ('(' == wp[i]) { + while (wp[i] && ')' != wp[i]) + if ('\\' == wp[i++]) { + /* Handle embedded escape. */ + *word = &wp[i]; + i += a2roffdeco(&dd, word, sz); + } + + if (')' == wp[i++]) + break; + + *d = DECO_NONE; + return(i - 1); + } else if ('\\' == wp[i]) { + *word = &wp[++i]; + i += a2roffdeco(&dd, word, sz); + } + break; case ('['): *d = DECO_SPECIAL; @@ -287,8 +307,24 @@ a2roffdeco(enum roffdeco *d, const char **word, size_t *sz) case ('c'): *d = DECO_NOSPACE; return(i); + case ('z'): + *d = DECO_NONE; + if ('\\' == wp[i]) { + *word = &wp[++i]; + return(i + a2roffdeco(&dd, word, sz)); + } else + lim = 1; + break; + case ('o'): + /* FALLTHROUGH */ + case ('w'): + if ('\'' == wp[i++]) { + term = '\''; + break; + } + /* FALLTHROUGH */ default: - *d = DECO_SPECIAL; + *d = DECO_SSPECIAL; i--; lim = 1; break;