From f25db392c434984141c67fb983517a0dd28c4fe1 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Sun, 22 Feb 2009 15:50:45 +0000 Subject: Initial block-display support. --- term.c | 26 +++++++++++++++--- term.h | 1 + termact.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 111 insertions(+), 7 deletions(-) diff --git a/term.c b/term.c index f09e3d5f..2611d893 100644 --- a/term.c +++ b/term.c @@ -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 c8d6274a..8ec4ff9d 100644 --- a/term.h +++ b/term.h @@ -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 7c3b2161..56b4173e 100644 --- a/termact.c +++ b/termact.c @@ -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, "\""); +} + + -- cgit