=================================================================== RCS file: /cvs/mandoc/Attic/mdocterm.c,v retrieving revision 1.5 retrieving revision 1.11 diff -u -p -r1.5 -r1.11 --- mandoc/Attic/mdocterm.c 2009/02/23 12:45:19 1.5 +++ mandoc/Attic/mdocterm.c 2009/02/25 13:30:53 1.11 @@ -1,4 +1,4 @@ - /* $Id: mdocterm.c,v 1.5 2009/02/23 12:45:19 kristaps Exp $ */ +/* $Id: mdocterm.c,v 1.11 2009/02/25 13:30:53 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -24,13 +24,19 @@ #include #include -#ifdef __linux__ +#ifndef __OpenBSD__ #include #endif #include "mmain.h" #include "term.h" +#ifdef __NetBSD__ +#define xisspace(x) isspace((int)(x)) +#else +#define xisspace(x) isspace((x)) +#endif + enum termstyle { STYLE_CLEAR, STYLE_BOLD, @@ -137,11 +143,11 @@ flushln(struct termp *p) * Count up visible word characters. Control sequences * (starting with the CSI) aren't counted. */ - assert( ! isspace(p->buf[i])); + assert( ! xisspace(p->buf[i])); /* LINTED */ for (j = i, vsz = 0; j < p->col; j++) { - if (isspace(p->buf[j])) + if (xisspace(p->buf[j])) break; else if (27 == p->buf[j]) { assert(j + 4 <= p->col); @@ -167,10 +173,9 @@ flushln(struct termp *p) for (j = 0; j < p->offset; j++) putchar(' '); vis = 0; - } else if (vis + vsz >= maxvis) { + } else if (vis + vsz >= maxvis) /* FIXME */ errx(1, "word breaks right margin"); - } /* * Write out the word and a trailing space. Omit the @@ -178,7 +183,7 @@ flushln(struct termp *p) */ for ( ; i < p->col; i++) { - if (isspace(p->buf[i])) + if (xisspace(p->buf[i])) break; putchar(p->buf[i]); } @@ -195,7 +200,7 @@ flushln(struct termp *p) */ if (p->flags & TERMP_NOBREAK) { - for ( ; vis <= maxvis; vis++) + for ( ; vis < maxvis; vis++) putchar(' '); } else putchar('\n'); @@ -216,6 +221,7 @@ newln(struct termp *p) if (0 == p->col) return; flushln(p); + p->flags &= ~TERMP_NOLPAD; } @@ -300,6 +306,10 @@ pescape(struct termp *p, const char *word, size_t *i, stringa(p, "<-"); else if ('-' == word[*i] && '>' == word[*i + 1]) stringa(p, "->"); + else if ('l' == word[*i] && 'q' == word[*i + 1]) + chara(p, '\"'); + else if ('r' == word[*i] && 'q' == word[*i + 1]) + chara(p, '\"'); (*i)++; return; @@ -379,7 +389,7 @@ word(struct termp *p, const char *word) /* LINTED */ for (j = i = 0; i < len; i++) { - if ( ! isspace(word[i])) { + if ( ! xisspace(word[i])) { j++; continue; } @@ -401,28 +411,38 @@ body(struct termp *p, const struct mdoc_meta *meta, const struct mdoc_node *node) { int dochild; + struct termpair pair; /* Pre-processing. */ dochild = 1; + pair.type = 0; + pair.offset = pair.rmargin = 0; + pair.flag = 0; if (MDOC_TEXT != node->type) { if (termacts[node->tok].pre) - if ( ! (*termacts[node->tok].pre)(p, meta, node)) + if ( ! (*termacts[node->tok].pre)(p, &pair, meta, node)) dochild = 0; } else /* MDOC_TEXT == node->type */ word(p, node->data.text.string); /* Children. */ + if (TERMPAIR_FLAG & pair.type) + p->flags |= pair.flag; + if (dochild && node->child) body(p, meta, node->child); + if (TERMPAIR_FLAG & pair.type) + p->flags &= ~pair.flag; + /* Post-processing. */ if (MDOC_TEXT != node->type) if (termacts[node->tok].post) - (*termacts[node->tok].post)(p, meta, node); + (*termacts[node->tok].post)(p, &pair, meta, node); /* Siblings. */ @@ -445,10 +465,10 @@ footer(struct termp *p, const struct mdoc_meta *meta) tm = localtime(&meta->date); -#ifdef __linux__ - if (0 == strftime(buf, p->rmargin, "%B %d, %Y", tm)) -#else +#ifdef __OpenBSD__ if (NULL == strftime(buf, p->rmargin, "%B %d, %Y", tm)) +#else + if (0 == strftime(buf, p->rmargin, "%B %d, %Y", tm)) #endif err(1, "strftime");