summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--term.c28
-rw-r--r--term.h3
-rw-r--r--termact.c93
3 files changed, 114 insertions, 10 deletions
diff --git a/term.c b/term.c
index 1b67bfc9..5b7111dc 100644
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.7 2009/02/22 14:31:08 kristaps Exp $ */
+/* $Id: term.c,v 1.8 2009/02/22 15:50:45 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -82,6 +82,18 @@ flushln(struct termp *p)
for (j = 0; j < p->offset; j++)
putchar(' ');
+ /*
+ * If we're literal, print out verbatim.
+ */
+ if (p->flags & TERMP_LITERAL) {
+ /* FIXME: count non-printing chars. */
+ for (i = 0; i < p->col; i++)
+ putchar(p->buf[i]);
+ putchar('\n');
+ p->col = 0;
+ return;
+ }
+
for (i = 0; i < p->col; i++) {
/*
* Count up visible word characters. Control sequences
@@ -267,9 +279,10 @@ pword(struct termp *p, const char *word, size_t len)
{
size_t i;
- assert(len > 0);
+ /*assert(len > 0);*/ /* Can be, if literal. */
- if ( ! (p->flags & TERMP_NOSPACE))
+ if ( ! (p->flags & TERMP_NOSPACE) &&
+ ! (p->flags & TERMP_LITERAL))
chara(p, ' ');
p->flags &= ~TERMP_NOSPACE;
@@ -298,12 +311,17 @@ word(struct termp *p, const char *word)
{
size_t i, j, len;
- if (mdoc_isdelim(word))
- p->flags |= TERMP_NOSPACE;
+ if (p->flags & TERMP_LITERAL) {
+ pword(p, word, strlen(word));
+ return;
+ }
len = strlen(word);
assert(len > 0);
+ if (mdoc_isdelim(word))
+ p->flags |= TERMP_NOSPACE;
+
/* LINTED */
for (j = i = 0; i < len; i++) {
if ( ! isspace(word[i])) {
diff --git a/term.h b/term.h
index 48f0be28..28c68b36 100644
--- a/term.h
+++ b/term.h
@@ -1,4 +1,4 @@
-/* $Id: term.h,v 1.2 2009/02/21 21:00:06 kristaps Exp $ */
+/* $Id: term.h,v 1.3 2009/02/22 15:50:45 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -35,6 +35,7 @@ struct termp {
#define TERMP_NOSPACE (1 << 2) /* No space before words. */
#define TERMP_NOLPAD (1 << 3) /* No leftpad before flush. */
#define TERMP_NOBREAK (1 << 4) /* No break after flush. */
+#define TERMP_LITERAL (1 << 5) /* Literal words. */
char *buf;
};
diff --git a/termact.c b/termact.c
index aed99041..44309418 100644
--- a/termact.c
+++ b/termact.c
@@ -1,4 +1,4 @@
-/* $Id: termact.c,v 1.4 2009/02/22 14:31:08 kristaps Exp $ */
+/* $Id: termact.c,v 1.5 2009/02/22 15:50:45 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -83,6 +83,7 @@ static void name##_post(DECL_ARGS)
DECL_PRE(termp_aq);
DECL_PRE(termp_ar);
+DECL_PRE(termp_bd);
DECL_PRE(termp_d1);
DECL_PRE(termp_dq);
DECL_PRE(termp_ex);
@@ -97,9 +98,11 @@ DECL_PRE(termp_nm);
DECL_PRE(termp_ns);
DECL_PRE(termp_op);
DECL_PRE(termp_pp);
+DECL_PRE(termp_qq);
DECL_PRE(termp_sh);
DECL_PRE(termp_sx);
DECL_PRE(termp_ud);
+DECL_PRE(termp_va);
DECL_PRE(termp_vt);
DECL_PRE(termp_xr);
@@ -116,8 +119,10 @@ DECL_POST(termp_ft);
DECL_POST(termp_it);
DECL_POST(termp_nm);
DECL_POST(termp_op);
+DECL_POST(termp_qq);
DECL_POST(termp_sh);
DECL_POST(termp_sx);
+DECL_POST(termp_va);
DECL_POST(termp_vt);
const struct termact __termacts[MDOC_MAX] = {
@@ -130,7 +135,7 @@ const struct termact __termacts[MDOC_MAX] = {
{ termp_pp_pre, NULL }, /* Pp */
{ termp_d1_pre, termp_d1_post }, /* D1 */
{ NULL, NULL }, /* Dl */
- { NULL, NULL }, /* Bd */
+ { termp_bd_pre, NULL }, /* Bd */
{ NULL, NULL }, /* Ed */
{ NULL, termp_bl_post }, /* Bl */
{ NULL, NULL }, /* El */
@@ -159,7 +164,7 @@ const struct termact __termacts[MDOC_MAX] = {
{ NULL, NULL }, /* Pa */
{ NULL, NULL }, /* Rv */
{ NULL, NULL }, /* St */
- { NULL, NULL }, /* Va */
+ { termp_va_pre, termp_va_post }, /* Va */
{ termp_vt_pre, termp_vt_post }, /* Vt */
{ termp_xr_pre, NULL }, /* Xr */
{ NULL, NULL }, /* %A */
@@ -204,7 +209,7 @@ const struct termact __termacts[MDOC_MAX] = {
{ NULL, NULL }, /* Qc */
{ NULL, NULL }, /* Ql */
{ NULL, NULL }, /* Qo */
- { NULL, NULL }, /* Qq */
+ { termp_qq_pre, termp_qq_post }, /* Qq */
{ NULL, NULL }, /* Re */
{ NULL, NULL }, /* Rs */
{ NULL, NULL }, /* Sc */
@@ -884,3 +889,83 @@ termp_fa_post(DECL_ARGS)
}
+/* ARGSUSED */
+static int
+termp_va_pre(DECL_ARGS)
+{
+
+ p->flags |= ttypes[TTYPE_VAR_DECL];
+ return(1);
+}
+
+
+/* ARGSUSED */
+static void
+termp_va_post(DECL_ARGS)
+{
+
+ p->flags &= ~ttypes[TTYPE_VAR_DECL];
+}
+
+
+/* ARGSUSED */
+static int
+termp_bd_pre(DECL_ARGS)
+{
+ const struct mdoc_block *bl;
+ const struct mdoc_node *n;
+
+ if (MDOC_BLOCK == node->type) {
+ vspace(p);
+ return(1);
+ } else if (MDOC_BODY != node->type)
+ return(1);
+
+ assert(MDOC_BLOCK == node->parent->type);
+
+ bl = &node->parent->data.block;
+ if ( ! arg_hasattr(MDOC_Literal, bl->argc, bl->argv))
+ return(1);
+
+ p->flags |= TERMP_LITERAL;
+
+ for (n = node->child; n; n = n->next) {
+ assert(MDOC_TEXT == n->type); /* FIXME */
+ if ((*n->data.text.string)) {
+ word(p, n->data.text.string);
+ flushln(p);
+ } else
+ vspace(p);
+
+ }
+
+ p->flags &= ~TERMP_LITERAL;
+ return(0);
+}
+
+
+/* ARGSUSED */
+static int
+termp_qq_pre(DECL_ARGS)
+{
+
+ if (MDOC_BODY != node->type)
+ return(1);
+ word(p, "\"");
+ p->flags |= TERMP_NOSPACE;
+ return(1);
+}
+
+
+/* ARGSUSED */
+static void
+termp_qq_post(DECL_ARGS)
+{
+
+ if (MDOC_BODY != node->type)
+ return;
+ p->flags |= TERMP_NOSPACE;
+ word(p, "\"");
+}
+
+