=================================================================== RCS file: /cvs/mandoc/term.c,v retrieving revision 1.121 retrieving revision 1.123 diff -u -p -r1.121 -r1.123 --- mandoc/term.c 2009/11/05 07:21:02 1.121 +++ mandoc/term.c 2009/11/06 10:31:32 1.123 @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.121 2009/11/05 07:21:02 kristaps Exp $ */ +/* $Id: term.c,v 1.123 2009/11/06 10:31:32 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -15,6 +15,7 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include +#include #include #include #include @@ -373,21 +374,21 @@ do_reserved(struct termp *p, const char *word, size_t static void do_escaped(struct termp *p, const char **word) { - int j, type; + int j, type, sv, t, lim; const char *wp; wp = *word; type = 1; - if (0 == *(++wp)) { + if ('\0' == *(++wp)) { *word = wp; return; } if ('(' == *wp) { wp++; - if (0 == *wp || 0 == *(wp + 1)) { - *word = 0 == *wp ? wp : wp + 1; + if ('\0' == *wp || '\0' == *(wp + 1)) { + *word = '\0' == *wp ? wp : wp + 1; return; } @@ -396,7 +397,7 @@ do_escaped(struct termp *p, const char **word) return; } else if ('*' == *wp) { - if (0 == *(++wp)) { + if ('\0' == *(++wp)) { *word = wp; return; } @@ -404,8 +405,8 @@ do_escaped(struct termp *p, const char **word) switch (*wp) { case ('('): wp++; - if (0 == *wp || 0 == *(wp + 1)) { - *word = 0 == *wp ? wp : wp + 1; + if ('\0' == *wp || '\0' == *(wp + 1)) { + *word = '\0' == *wp ? wp : wp + 1; return; } @@ -420,24 +421,115 @@ do_escaped(struct termp *p, const char **word) *word = wp; return; } - + + } else if ('s' == *wp) { + /* This closely follows mandoc_special(). */ + if ('\0' == *(++wp)) { + *word = wp; + return; + } + + t = 0; + lim = 1; + + if (*wp == '\'') { + lim = 0; + t = 1; + ++wp; + } else if (*wp == '[') { + lim = 0; + t = 2; + ++wp; + } else if (*wp == '(') { + lim = 2; + t = 3; + ++wp; + } + + if (*wp == '+' || *wp == '-') + ++wp; + + if (*wp == '\'') { + if (t) { + *word = wp; + return; + } + lim = 0; + t = 1; + ++wp; + } else if (*wp == '[') { + if (t) { + *word = wp; + return; + } + lim = 0; + t = 2; + ++wp; + } else if (*wp == '(') { + if (t) { + *word = wp; + return; + } + lim = 2; + t = 3; + ++wp; + } + + if ( ! isdigit((u_char)*wp)) { + *word = --wp; + return; + } + + for (j = 0; isdigit((u_char)*wp); j++) { + if (lim && j >= lim) + break; + ++wp; + } + + if (t && t < 3) { + if (1 == t && *wp != '\'') { + *word = --wp; + return; + } + if (2 == t && *wp != ']') { + *word = --wp; + return; + } + ++wp; + } + *word = --wp; + return; + } else if ('f' == *wp) { - if (0 == *(++wp)) { + if ('\0' == *(++wp)) { *word = wp; return; } switch (*wp) { + case ('3'): + /* FALLTHROUGH */ case ('B'): - p->bold++; + p->metamask = p->metafont; + p->metafont |= METAF_BOLD; break; + case ('2'): + /* FALLTHROUGH */ case ('I'): - p->under++; + p->metamask = p->metafont; + p->metafont |= METAF_UNDER; break; case ('P'): + sv = p->metamask; + p->metamask = p->metafont; + p->metafont = sv; + break; + case ('1'): /* FALLTHROUGH */ case ('R'): - p->bold = p->under = 0; + p->metamask = p->metafont; + p->metafont &= ~METAF_UNDER; + p->metafont &= ~METAF_BOLD; break; default: break; @@ -456,7 +548,7 @@ do_escaped(struct termp *p, const char **word) for (j = 0; *wp && ']' != *wp; wp++, j++) /* Loop... */ ; - if (0 == *wp) { + if ('\0' == *wp) { *word = wp; return; } @@ -481,7 +573,7 @@ term_word(struct termp *p, const char *word) sv = word; - if (word[0] && 0 == word[1]) + if (word[0] && '\0' == word[1]) switch (word[0]) { case('.'): /* FALLTHROUGH */ @@ -563,12 +655,12 @@ static void encode(struct termp *p, char c) { - if (' ' != c) { - if (p->under) { + if (isgraph((u_char)c)) { + if (p->under || METAF_UNDER & p->metafont) { buffer(p, '_'); buffer(p, 8); } - if (p->bold) { + if (p->bold || METAF_BOLD & p->metafont) { buffer(p, c); buffer(p, 8); }