=================================================================== RCS file: /cvs/mandoc/term.c,v retrieving revision 1.96 retrieving revision 1.98 diff -u -p -r1.96 -r1.98 --- mandoc/term.c 2009/07/27 13:10:08 1.96 +++ mandoc/term.c 2009/09/15 08:16:20 1.98 @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.96 2009/07/27 13:10:08 kristaps Exp $ */ +/* $Id: term.c,v 1.98 2009/09/15 08:16:20 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -104,7 +104,7 @@ term_alloc(enum termenc enc) struct termp *p; if (NULL == (p = malloc(sizeof(struct termp)))) - err(1, "malloc"); + return(NULL); bzero(p, sizeof(struct termp)); p->maxrmargin = 78; p->enc = enc; @@ -392,7 +392,7 @@ do_special(struct termp *p, const char *word, size_t l rhs = term_a2ascii(p->symtab, word, len, &sz); if (NULL == rhs) { -#if 1 +#if 0 fputs("Unknown special character: ", stderr); for (i = 0; i < (int)len; i++) fputc(word[i], stderr); @@ -436,10 +436,11 @@ do_reserved(struct termp *p, const char *word, size_t static void do_escaped(struct termp *p, const char **word) { - int j; + int j, type; const char *wp; wp = *word; + type = 1; if (0 == *(++wp)) { *word = wp; @@ -475,6 +476,7 @@ do_escaped(struct termp *p, const char **word) *word = ++wp; return; case ('['): + type = 0; break; default: do_reserved(p, wp, 1); @@ -490,15 +492,15 @@ do_escaped(struct termp *p, const char **word) switch (*wp) { case ('B'): - p->flags |= TERMP_BOLD; + p->bold++; break; case ('I'): - p->flags |= TERMP_UNDER; + p->under++; break; case ('P'): /* FALLTHROUGH */ case ('R'): - p->flags &= ~TERMP_STYLE; + p->bold = p->under = 0; break; default: break; @@ -522,7 +524,10 @@ do_escaped(struct termp *p, const char **word) return; } - do_special(p, wp - j, (size_t)j); + if (type) + do_special(p, wp - j, (size_t)j); + else + do_reserved(p, wp - j, (size_t)j); *word = wp; } @@ -574,7 +579,7 @@ buffer(struct termp *p, char c) s = p->maxcols * 2; p->buf = realloc(p->buf, s); if (NULL == p->buf) - err(1, "realloc"); + err(1, "realloc"); /* FIXME: shouldn't be here! */ p->maxcols = s; } p->buf[(int)(p->col)++] = c; @@ -585,12 +590,12 @@ static void encode(struct termp *p, char c) { - if (' ' != c && TERMP_STYLE & p->flags) { - if (TERMP_BOLD & p->flags) { + if (' ' != c) { + if (p->bold) { buffer(p, c); buffer(p, 8); } - if (TERMP_UNDER & p->flags) { + if (p->under) { buffer(p, '_'); buffer(p, 8); }