]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_term.c
basic tag support for function names; written at YYC
[mandoc.git] / mdoc_term.c
index f2b081a6f383c4a9d72fadc9c2b3ea0138ed48c0..7486fa4424031567ecf996357cd721dcbde38118 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: mdoc_term.c,v 1.318 2015/04/18 16:06:41 schwarze Exp $ */
+/*     $Id: mdoc_term.c,v 1.322 2015/07/25 14:18:04 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2012-2015 Ingo Schwarze <schwarze@openbsd.org>
@@ -34,6 +34,7 @@
 #include "mdoc.h"
 #include "out.h"
 #include "term.h"
+#include "tag.h"
 #include "main.h"
 
 struct termpair {
@@ -117,6 +118,7 @@ static      int       termp_skip_pre(DECL_ARGS);
 static int       termp_sm_pre(DECL_ARGS);
 static int       termp_sp_pre(DECL_ARGS);
 static int       termp_ss_pre(DECL_ARGS);
+static int       termp_tag_pre(DECL_ARGS);
 static int       termp_under_pre(DECL_ARGS);
 static int       termp_ud_pre(DECL_ARGS);
 static int       termp_vt_pre(DECL_ARGS);
@@ -145,7 +147,7 @@ static      const struct termact termacts[MDOC_MAX] = {
        { termp_bold_pre, NULL }, /* Cm */
        { NULL, NULL }, /* Dv */
        { NULL, NULL }, /* Er */
-       { NULL, NULL }, /* Ev */
+       { termp_tag_pre, NULL }, /* Ev */
        { termp_ex_pre, NULL }, /* Ex */
        { termp_fa_pre, NULL }, /* Fa */
        { termp_fd_pre, termp_fd_post }, /* Fd */
@@ -249,29 +251,27 @@ static    const struct termact termacts[MDOC_MAX] = {
        { termp_ll_pre, NULL }, /* ll */
 };
 
+static int      fn_prio;
 
 void
 terminal_mdoc(void *arg, const struct roff_man *mdoc)
 {
-       const struct roff_meta  *meta;
        struct roff_node        *n;
        struct termp            *p;
 
        p = (struct termp *)arg;
-
        p->overstep = 0;
        p->rmargin = p->maxrmargin = p->defrmargin;
        p->tabwidth = term_len(p, 5);
 
-       n = mdoc_node(mdoc)->child;
-       meta = mdoc_meta(mdoc);
-
+       n = mdoc->first->child;
        if (p->synopsisonly) {
                while (n != NULL) {
                        if (n->tok == MDOC_Sh && n->sec == SEC_SYNOPSIS) {
                                if (n->child->next->child != NULL)
                                        print_mdoc_nodelist(p, NULL,
-                                           meta, n->child->next->child);
+                                           &mdoc->meta,
+                                           n->child->next->child);
                                term_newln(p);
                                break;
                        }
@@ -280,11 +280,12 @@ terminal_mdoc(void *arg, const struct roff_man *mdoc)
        } else {
                if (p->defindent == 0)
                        p->defindent = 5;
-               term_begin(p, print_mdoc_head, print_mdoc_foot, meta);
+               term_begin(p, print_mdoc_head, print_mdoc_foot,
+                   &mdoc->meta);
                if (n != NULL) {
                        if (n->tok != MDOC_Sh)
                                term_vspace(p);
-                       print_mdoc_nodelist(p, NULL, meta, n);
+                       print_mdoc_nodelist(p, NULL, &mdoc->meta, n);
                }
                term_end(p);
        }
@@ -1051,6 +1052,7 @@ static int
 termp_fl_pre(DECL_ARGS)
 {
 
+       termp_tag_pre(p, pair, meta, n);
        term_fontpush(p, TERMFONT_BOLD);
        term_word(p, "\\-");
 
@@ -1332,6 +1334,7 @@ static int
 termp_bold_pre(DECL_ARGS)
 {
 
+       termp_tag_pre(p, pair, meta, n);
        term_fontpush(p, TERMFONT_BOLD);
        return(1);
 }
@@ -1362,7 +1365,7 @@ termp_sh_pre(DECL_ARGS)
                 * when the previous section was empty.
                 */
                if (n->prev == NULL ||
-                   MDOC_Sh != n->prev->tok ||
+                   n->prev->tok != MDOC_Sh ||
                    (n->prev->body != NULL &&
                     n->prev->body->child != NULL))
                        term_vspace(p);
@@ -1372,8 +1375,16 @@ termp_sh_pre(DECL_ARGS)
                break;
        case ROFFT_BODY:
                p->offset = term_len(p, p->defindent);
-               if (SEC_AUTHORS == n->sec)
+               switch (n->sec) {
+               case SEC_DESCRIPTION:
+                       fn_prio = 0;
+                       break;
+               case SEC_AUTHORS:
                        p->flags &= ~(TERMP_SPLIT|TERMP_NOSPLIT);
+                       break;
+               default:
+                       break;
+               }
                break;
        default:
                break;
@@ -1469,6 +1480,11 @@ termp_fn_pre(DECL_ARGS)
        term_word(p, n->string);
        term_fontpop(p);
 
+       if (n->sec == SEC_DESCRIPTION) {
+               if ( ! tag_get(n->string, 0, ++fn_prio))
+                       tag_put(n->string, 0, fn_prio, p->line);
+       }
+
        if (pretty) {
                term_flushln(p);
                p->flags &= ~(TERMP_NOBREAK | TERMP_BRIND | TERMP_HANG);
@@ -1821,6 +1837,7 @@ termp_sp_pre(DECL_ARGS)
                break;
        default:
                len = 1;
+               fn_prio = 0;
                break;
        }
 
@@ -2254,3 +2271,19 @@ termp_under_pre(DECL_ARGS)
        term_fontpush(p, TERMFONT_UNDER);
        return(1);
 }
+
+static int
+termp_tag_pre(DECL_ARGS)
+{
+
+       if (n->child != NULL &&
+           n->child->type == ROFFT_TEXT &&
+           n->prev == NULL &&
+           (n->parent->tok == MDOC_It ||
+            (n->parent->tok == MDOC_Xo &&
+             n->parent->parent->prev == NULL &&
+             n->parent->parent->parent->tok == MDOC_It)) &&
+           ! tag_get(n->child->string, 0, 1))
+               tag_put(n->child->string, 0, 1, p->line);
+       return(1);
+}