=================================================================== RCS file: /cvs/mandoc/mdoc_term.c,v retrieving revision 1.93 retrieving revision 1.101 diff -u -p -r1.93 -r1.101 --- mandoc/mdoc_term.c 2009/10/19 15:18:30 1.93 +++ mandoc/mdoc_term.c 2009/11/10 11:45:57 1.101 @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.93 2009/10/19 15:18:30 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.101 2009/11/10 11:45:57 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -18,7 +18,6 @@ #include #include -#include #include #include #include @@ -48,6 +47,28 @@ struct termact { void (*post)(DECL_ARGS); }; +static size_t a2width(const struct mdoc_argv *, int); +static size_t a2height(const struct mdoc_node *); +static size_t a2offs(const struct mdoc_argv *); + +static int arg_hasattr(int, const struct mdoc_node *); +static int arg_getattrs(const int *, int *, size_t, + const struct mdoc_node *); +static int arg_getattr(int, const struct mdoc_node *); +static int arg_listtype(const struct mdoc_node *); +static void print_bvspace(struct termp *, + const struct mdoc_node *, + const struct mdoc_node *); +static void print_node(DECL_ARGS); +static void print_head(DECL_ARGS); +static void print_body(DECL_ARGS); +static void print_foot(DECL_ARGS); + +#ifdef __linux__ +extern size_t strlcpy(char *, const char *, size_t); +extern size_t strlcat(char *, const char *, size_t); +#endif + static void termp____post(DECL_ARGS); static void termp_an_post(DECL_ARGS); static void termp_aq_post(DECL_ARGS); @@ -236,31 +257,10 @@ static const struct termact termacts[MDOC_MAX] = { { NULL, termp____post }, /* %Q */ { termp_sp_pre, NULL }, /* br */ { termp_sp_pre, NULL }, /* sp */ + { termp_under_pre, termp____post }, /* %U */ }; -#ifdef __linux__ -extern size_t strlcpy(char *, const char *, size_t); -extern size_t strlcat(char *, const char *, size_t); -#endif -static size_t arg2width(const struct mdoc_argv *, int); -static size_t arg2height(const struct mdoc_node *); -static size_t arg2offs(const struct mdoc_argv *); - -static int arg_hasattr(int, const struct mdoc_node *); -static int arg_getattrs(const int *, int *, size_t, - const struct mdoc_node *); -static int arg_getattr(int, const struct mdoc_node *); -static int arg_listtype(const struct mdoc_node *); -static void print_bvspace(struct termp *, - const struct mdoc_node *, - const struct mdoc_node *); -static void print_node(DECL_ARGS); -static void print_head(DECL_ARGS); -static void print_body(DECL_ARGS); -static void print_foot(DECL_ARGS); - - void terminal_mdoc(void *arg, const struct mdoc *mdoc) { @@ -314,7 +314,7 @@ print_node(DECL_ARGS) bold = p->bold; under = p->under; - bzero(&npair, sizeof(struct termpair)); + memset(&npair, 0, sizeof(struct termpair)); npair.ppair = pair; if (MDOC_TEXT != n->type) { @@ -347,9 +347,11 @@ print_node(DECL_ARGS) static void print_foot(DECL_ARGS) { - struct tm *tm; - char *buf, *os; + char buf[DATESIZ], os[BUFSIZ]; + /* Disable meta-fonts. */ + p->metafont = 0; + /* * Output the footer in new-groff style, that is, three columns * with the middle being the manual date and flanking columns @@ -358,18 +360,9 @@ print_foot(DECL_ARGS) * SYSTEM DATE SYSTEM */ - if (NULL == (buf = malloc(p->rmargin))) - err(EXIT_FAILURE, "malloc"); - if (NULL == (os = malloc(p->rmargin))) - err(EXIT_FAILURE, "malloc"); + time2a(m->date, buf, DATESIZ); + strlcpy(os, m->os, BUFSIZ); - tm = localtime(&m->date); - - if (0 == strftime(buf, p->rmargin, "%B %e, %Y", tm)) - err(EXIT_FAILURE, "strftime"); - - (void)strlcpy(os, m->os, p->rmargin); - term_vspace(p); p->offset = 0; @@ -397,9 +390,6 @@ print_foot(DECL_ARGS) p->offset = 0; p->rmargin = p->maxrmargin; p->flags = 0; - - free(buf); - free(os); } @@ -408,16 +398,11 @@ print_foot(DECL_ARGS) static void print_head(DECL_ARGS) { - char *buf, *title; + char buf[BUFSIZ], title[BUFSIZ]; p->rmargin = p->maxrmargin; p->offset = 0; - if (NULL == (buf = malloc(p->rmargin))) - err(EXIT_FAILURE, "malloc"); - if (NULL == (title = malloc(p->rmargin))) - err(EXIT_FAILURE, "malloc"); - /* * The header is strange. It has three components, which are * really two with the first duplicated. It goes like this: @@ -432,15 +417,15 @@ print_head(DECL_ARGS) */ assert(m->vol); - (void)strlcpy(buf, m->vol, p->rmargin); + strlcpy(buf, m->vol, BUFSIZ); if (m->arch) { - (void)strlcat(buf, " (", p->rmargin); - (void)strlcat(buf, m->arch, p->rmargin); - (void)strlcat(buf, ")", p->rmargin); + strlcat(buf, " (", BUFSIZ); + strlcat(buf, m->arch, BUFSIZ); + strlcat(buf, ")", BUFSIZ); } - snprintf(title, p->rmargin, "%s(%d)", m->title, m->msec); + snprintf(title, BUFSIZ, "%s(%d)", m->title, m->msec); p->offset = 0; p->rmargin = (p->maxrmargin - strlen(buf) + 1) / 2; @@ -467,14 +452,11 @@ print_head(DECL_ARGS) p->offset = 0; p->rmargin = p->maxrmargin; p->flags &= ~TERMP_NOSPACE; - - free(title); - free(buf); } static size_t -arg2height(const struct mdoc_node *n) +a2height(const struct mdoc_node *n) { struct roffsu su; @@ -488,7 +470,7 @@ arg2height(const struct mdoc_node *n) static size_t -arg2width(const struct mdoc_argv *arg, int pos) +a2width(const struct mdoc_argv *arg, int pos) { struct roffsu su; @@ -543,7 +525,7 @@ arg_listtype(const struct mdoc_node *n) static size_t -arg2offs(const struct mdoc_argv *arg) +a2offs(const struct mdoc_argv *arg) { struct roffsu su; @@ -722,23 +704,23 @@ termp_it_pre(DECL_ARGS) for (i = 0, nn = n->prev; nn && i < (int)bl->args->argv[vals[2]].sz; nn = nn->prev, i++) - offset += arg2width + offset += a2width (&bl->args->argv[vals[2]], i); /* Whether exceeds maximum column. */ if (i < (int)bl->args->argv[vals[2]].sz) - width = arg2width(&bl->args->argv[vals[2]], i); + width = a2width(&bl->args->argv[vals[2]], i); else width = 0; if (vals[1] >= 0) - offset += arg2offs(&bl->args->argv[vals[1]]); + offset += a2offs(&bl->args->argv[vals[1]]); break; default: if (vals[0] >= 0) - width = arg2width(&bl->args->argv[vals[0]], 0); + width = a2width(&bl->args->argv[vals[0]], 0); if (vals[1] >= 0) - offset += arg2offs(&bl->args->argv[vals[1]]); + offset += a2offs(&bl->args->argv[vals[1]]); break; } @@ -1561,7 +1543,7 @@ termp_bd_pre(DECL_ARGS) type = nn->args->argv[i].arg; break; case (MDOC_Offset): - p->offset += arg2offs(&nn->args->argv[i]); + p->offset += a2offs(&nn->args->argv[i]); break; default: break; @@ -1655,7 +1637,7 @@ termp_xx_pre(DECL_ARGS) pp = "BSDI BSD/OS"; break; case (MDOC_Dx): - pp = "DragonFlyBSD"; + pp = "DragonFly"; break; case (MDOC_Fx): pp = "FreeBSD"; @@ -1816,7 +1798,7 @@ termp_sp_pre(DECL_ARGS) switch (n->tok) { case (MDOC_sp): - len = n->child ? arg2height(n->child) : 1; + len = n->child ? a2height(n->child) : 1; break; case (MDOC_br): len = 0; @@ -2012,6 +1994,8 @@ static void termp____post(DECL_ARGS) { + /* TODO: %U. */ + p->flags |= TERMP_NOSPACE; switch (n->tok) { case (MDOC__T): @@ -2031,16 +2015,17 @@ termp_lk_pre(DECL_ARGS) { const struct mdoc_node *nn; - if (NULL == (nn = n->child->next)) { - p->under++; + p->under++; + nn = n->child; + + if (NULL == nn->next) return(1); - } - p->under++; term_word(p, nn->string); + p->under--; + p->flags |= TERMP_NOSPACE; term_word(p, ":"); - p->under--; p->bold++; for (nn = nn->next; nn; nn = nn->next)