]> git.cameronkatri.com Git - mandoc.git/blobdiff - term.c
Backed-out warning about Ds.
[mandoc.git] / term.c
diff --git a/term.c b/term.c
index 66847ea245afaddd05e6a1b817be88ecefc26881..5e64262058a4cbf4edbe0e414bd28f6165ab22d7 100644 (file)
--- a/term.c
+++ b/term.c
@@ -1,4 +1,4 @@
-/* $Id: term.c,v 1.29 2009/02/28 20:13:06 kristaps Exp $ */
+/* $Id: term.c,v 1.32 2009/03/01 23:14:15 kristaps Exp $ */
 /*
  * Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -118,6 +118,7 @@ DECL_PREPOST(termp_fd);
 DECL_PREPOST(termp_fn);
 DECL_PREPOST(termp_fo);
 DECL_PREPOST(termp_ft);
+DECL_PREPOST(termp_in);
 DECL_PREPOST(termp_it);
 DECL_PREPOST(termp_op);
 DECL_PREPOST(termp_pf);
@@ -133,7 +134,6 @@ DECL_PRE(termp_at);
 DECL_PRE(termp_bf);
 DECL_PRE(termp_bsx);
 DECL_PRE(termp_bt);
-DECL_PRE(termp_bx);
 DECL_PRE(termp_cd);
 DECL_PRE(termp_cm);
 DECL_PRE(termp_em);
@@ -142,7 +142,6 @@ DECL_PRE(termp_fa);
 DECL_PRE(termp_fl);
 DECL_PRE(termp_fx);
 DECL_PRE(termp_ic);
-DECL_PRE(termp_in);
 DECL_PRE(termp_ms);
 DECL_PRE(termp_nd);
 DECL_PRE(termp_nm);
@@ -164,6 +163,7 @@ DECL_PRE(termp_xr);
 
 DECL_POST(termp___);
 DECL_POST(termp_bl);
+DECL_POST(termp_bx);
 
 const  struct termact __termacts[MDOC_MAX] = {
        { NULL, NULL }, /* \" */
@@ -195,7 +195,7 @@ const       struct termact __termacts[MDOC_MAX] = {
        { termp_fn_pre, termp_fn_post }, /* Fn */ 
        { termp_ft_pre, termp_ft_post }, /* Ft */ 
        { termp_ic_pre, NULL }, /* Ic */ 
-       { termp_in_pre, NULL }, /* In */ 
+       { termp_in_pre, termp_in_post }, /* In */ 
        { NULL, NULL }, /* Li */
        { termp_nd_pre, NULL }, /* Nd */ 
        { termp_nm_pre, NULL }, /* Nm */ 
@@ -227,7 +227,7 @@ const       struct termact __termacts[MDOC_MAX] = {
        { termp_bq_pre, termp_bq_post }, /* Bo */
        { termp_bq_pre, termp_bq_post }, /* Bq */
        { termp_bsx_pre, NULL }, /* Bsx */
-       { termp_bx_pre, NULL }, /* Bx */
+       { NULL, termp_bx_post }, /* Bx */
        { NULL, NULL }, /* Db */
        { NULL, NULL }, /* Dc */
        { termp_dq_pre, termp_dq_post }, /* Do */
@@ -303,7 +303,7 @@ arg_width(const struct mdoc_arg *arg)
                }
 
        }
-       return(strlen(*arg->value) + 2);
+       return(strlen(*arg->value) + 1);
 }
 
 
@@ -550,10 +550,9 @@ termp_it_post(DECL_ARGS)
        p->offset = pair->offset;
        p->rmargin = pair->rmargin;
 
-       if (MDOC_HEAD == node->type) {
+       if (MDOC_HEAD == node->type)
                p->flags &= ~TERMP_NOBREAK;
-               p->flags &= ~TERMP_NORPAD;
-       } else if (MDOC_BODY == node->type)
+       else if (MDOC_BODY == node->type)
                p->flags &= ~TERMP_NOLPAD;
 }
 
@@ -566,9 +565,10 @@ termp_nm_pre(DECL_ARGS)
        if (SEC_SYNOPSIS == node->sec)
                newln(p);
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_PROG]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_PROG]);
        if (NULL == node->child)
                word(p, meta->name);
+
        return(1);
 }
 
@@ -578,7 +578,7 @@ static int
 termp_fl_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_FLAG]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_FLAG]);
        word(p, "\\-");
        p->flags |= TERMP_NOSPACE;
        return(1);
@@ -590,14 +590,11 @@ static int
 termp_ar_pre(DECL_ARGS)
 {
 
-       if (node->child) {
-               TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_ARG]);
-               return(1);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_ARG]);
+       if (NULL == node->child) {
+               word(p, "file");
+               word(p, "...");
        }
-       p->flags |= ttypes[TTYPE_CMD_ARG];
-       word(p, "file");
-       word(p, "...");
-       p->flags &= ~ttypes[TTYPE_CMD_ARG];
        return(1);
 }
 
@@ -642,7 +639,7 @@ static int
 termp_rs_pre(DECL_ARGS)
 {
 
-       if (MDOC_BLOCK == node->type)
+       if (MDOC_BLOCK == node->type && node->prev)
                vspace(p);
        return(1);
 }
@@ -764,7 +761,7 @@ termp_vt_pre(DECL_ARGS)
 {
 
        /* FIXME: this can be "type name". */
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_VAR_DECL]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]);
        return(1);
 }
 
@@ -788,7 +785,7 @@ termp_fd_pre(DECL_ARGS)
         * FIXME: this naming is bad.  This value is used, in general,
         * for the #include header or other preprocessor statement.
         */
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_DECL]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_DECL]);
        return(1);
 }
 
@@ -798,7 +795,10 @@ static void
 termp_fd_post(DECL_ARGS)
 {
 
-       if (node->sec == SEC_SYNOPSIS)
+       if (node->sec != SEC_SYNOPSIS)
+               return;
+       newln(p);
+       if (node->next && MDOC_Fd != node->next->tok)
                vspace(p);
 }
 
@@ -811,7 +811,7 @@ termp_sh_pre(DECL_ARGS)
        switch (node->type) {
        case (MDOC_HEAD):
                vspace(p);
-               TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SECTION]);
+               TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SECTION]);
                break;
        case (MDOC_BODY):
                p->offset = INDENT;
@@ -934,7 +934,7 @@ static int
 termp_ft_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_TYPE]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_TYPE]);
        return(1);
 }
 
@@ -990,7 +990,7 @@ static void
 termp_fn_post(DECL_ARGS)
 {
 
-       if (node->sec == SEC_SYNOPSIS)
+       if (node->sec == SEC_SYNOPSIS && node->next)
                vspace(p);
 
 }
@@ -1001,7 +1001,7 @@ static int
 termp_sx_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_LINK]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_LINK]);
        return(1);
 }
 
@@ -1013,7 +1013,7 @@ termp_fa_pre(DECL_ARGS)
        struct mdoc_node *n;
 
        if (node->parent->tok != MDOC_Fo) {
-               TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FUNC_ARG]);
+               TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FUNC_ARG]);
                return(1);
        }
 
@@ -1040,7 +1040,7 @@ static int
 termp_va_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_VAR_DECL]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_VAR_DECL]);
        return(1);
 }
 
@@ -1054,7 +1054,8 @@ termp_bd_pre(DECL_ARGS)
        int              i;
 
        if (MDOC_BLOCK == node->type) {
-               vspace(p);
+               if (node->prev)
+                       vspace(p);
                return(1);
        } else if (MDOC_BODY != node->type)
                return(1);
@@ -1064,20 +1065,17 @@ termp_bd_pre(DECL_ARGS)
 
        bl = &node->parent->data.block;
 
-
        i = arg_getattr(MDOC_Offset, bl->argc, bl->argv);
        if (-1 != i) {
                assert(1 == bl->argv[i].sz);
                p->offset += arg_offset(&bl->argv[i]);
        }
 
-       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 (MDOC_TEXT != n->type) 
+                       errx(1, "non-text displays unsupported");
                if ((*n->data.text.string)) {
                        word(p, n->data.text.string);
                        flushln(p);
@@ -1139,12 +1137,12 @@ termp_bsx_pre(DECL_ARGS)
 
 
 /* ARGSUSED */
-static int
-termp_bx_pre(DECL_ARGS)
+static void
+termp_bx_post(DECL_ARGS)
 {
 
+       p->flags |= TERMP_NOSPACE;
        word(p, "BSD");
-       return(1);
 }
 
 
@@ -1241,7 +1239,7 @@ termp_ss_pre(DECL_ARGS)
        switch (node->type) {
        case (MDOC_HEAD):
                vspace(p);
-               TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SSECTION]);
+               TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SSECTION]);
                p->offset = INDENT / 2;
                break;
        default:
@@ -1273,7 +1271,7 @@ static int
 termp_pa_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_FILE]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_FILE]);
        return(1);
 }
 
@@ -1283,7 +1281,7 @@ static int
 termp_em_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
        return(1);
 }
 
@@ -1293,7 +1291,7 @@ static int
 termp_cd_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CONFIG]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CONFIG]);
        return(1);
 }
 
@@ -1303,7 +1301,7 @@ static int
 termp_cm_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD_FLAG]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD_FLAG]);
        return(1);
 }
 
@@ -1313,7 +1311,7 @@ static int
 termp_ic_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_CMD]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_CMD]);
        return(1);
 }
 
@@ -1323,11 +1321,30 @@ static int
 termp_in_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_INCLUDE]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_INCLUDE]);
+       word(p, "#include");
+       word(p, "<");
+       p->flags |= TERMP_NOSPACE;
        return(1);
 }
 
 
+/* ARGSUSED */
+static void
+termp_in_post(DECL_ARGS)
+{
+
+       p->flags |= TERMP_NOSPACE;
+       word(p, ">");
+
+       newln(p);
+       if (SEC_SYNOPSIS != node->sec)
+               return;
+       if (node->next && MDOC_In != node->next->tok)
+               vspace(p);
+}
+
+
 /* ARGSUSED */
 static int
 termp_at_pre(DECL_ARGS)
@@ -1352,7 +1369,7 @@ termp_bq_pre(DECL_ARGS)
 
        if (MDOC_BODY != node->type)
                return(1);
-       word(p, "\\[");
+       word(p, "[");
        p->flags |= TERMP_NOSPACE;
        return(1);
 }
@@ -1450,9 +1467,9 @@ termp_bf_pre(DECL_ARGS)
 
        if (NULL == (n = b->head->child)) {
                if (arg_hasattr(MDOC_Emphasis, b->argc, b->argv))
-                       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+                       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
                else if (arg_hasattr(MDOC_Symbolic, b->argc, b->argv))
-                       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMB]);
+                       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);
 
                return(1);
        } 
@@ -1460,9 +1477,9 @@ termp_bf_pre(DECL_ARGS)
        assert(MDOC_TEXT == n->type);
 
        if (0 == strcmp("Em", n->data.text.string))
-               TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+               TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
        else if (0 == strcmp("Sy", n->data.text.string))
-               TERMPAIR_SETFLAG(pair, ttypes[TTYPE_EMPH]);
+               TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_EMPH]);
 
        return(1);
 }
@@ -1473,7 +1490,7 @@ static int
 termp_sy_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMB]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMB]);
        return(1);
 }
 
@@ -1483,7 +1500,7 @@ static int
 termp_ms_pre(DECL_ARGS)
 {
 
-       TERMPAIR_SETFLAG(pair, ttypes[TTYPE_SYMBOL]);
+       TERMPAIR_SETFLAG(p, pair, ttypes[TTYPE_SYMBOL]);
        return(1);
 }