- /* $Id: mdocterm.c,v 1.4 2009/02/23 09:33:34 kristaps Exp $ */
+ /* $Id: mdocterm.c,v 1.10 2009/02/25 12:27:37 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
#include <stdlib.h>
#include <string.h>
+#ifndef __OpenBSD__
+#include <time.h>
+#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,
const struct mdoc *mdoc;
struct termp termp;
- extern int optreset;
- extern int optind;
-
p = mmain_alloc();
if ( ! mmain_getopt(p, argc, argv, NULL, NULL, NULL, NULL))
* 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);
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
*/
for ( ; i < p->col; i++) {
- if (isspace(p->buf[i]))
+ if (xisspace(p->buf[i]))
break;
putchar(p->buf[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;
/* LINTED */
for (j = i = 0; i < len; i++) {
- if ( ! isspace(word[i])) {
+ if ( ! xisspace(word[i])) {
j++;
continue;
}
const struct mdoc_node *node)
{
int dochild;
+ struct termpair pair;
/* Pre-processing. */
dochild = 1;
+ pair.type = 0;
+ pair.offset = 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. */
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");