=================================================================== RCS file: /cvs/mandoc/Attic/action.c,v retrieving revision 1.16 retrieving revision 1.22 diff -u -p -r1.16 -r1.22 --- mandoc/Attic/action.c 2009/01/21 11:35:26 1.16 +++ mandoc/Attic/action.c 2009/02/27 10:55:16 1.22 @@ -1,4 +1,4 @@ -/* $Id: action.c,v 1.16 2009/01/21 11:35:26 kristaps Exp $ */ +/* $Id: action.c,v 1.22 2009/02/27 10:55:16 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -17,7 +17,9 @@ * PERFORMANCE OF THIS SOFTWARE. */ #include +#include #include +#include #include #include "private.h" @@ -34,6 +36,7 @@ struct actions { /* Per-macro action routines. */ +static int post_bl(struct mdoc *); static int post_sh(struct mdoc *); static int post_os(struct mdoc *); static int post_dt(struct mdoc *); @@ -56,7 +59,7 @@ const struct actions mdoc_actions[MDOC_MAX] = { { NULL }, /* Dl */ { NULL }, /* Bd */ { NULL }, /* Ed */ - { NULL }, /* Bl */ + { post_bl }, /* Bl */ { NULL }, /* El */ { NULL }, /* It */ { NULL }, /* Ad */ @@ -194,6 +197,7 @@ post_sh(struct mdoc *mdoc) if (xstrlcats(buf, mdoc->last->child, 64)) { if (SEC_CUSTOM != (sec = mdoc_atosec(buf))) mdoc->lastnamed = sec; + mdoc->lastsec = sec; return(1); } @@ -216,6 +220,7 @@ post_dt(struct mdoc *mdoc) assert(NULL == mdoc->meta.title); + /* LINTED */ for (i = 0, n = mdoc->last->child; n; n = n->next, i++) { assert(MDOC_TEXT == n->type); p = n->data.text.string; @@ -243,7 +248,7 @@ post_dt(struct mdoc *mdoc) } if (NULL == mdoc->meta.title) - mdoc->meta.title = xstrdup("untitled"); + mdoc->meta.title = xstrdup("UNTITLED"); mdoc_msg(mdoc, "title: %s", mdoc->meta.title); @@ -266,10 +271,56 @@ post_os(struct mdoc *mdoc) if ( ! xstrlcats(buf, mdoc->last->child, 64)) return(mdoc_err(mdoc, "macro parameters too long")); - mdoc->meta.os = xstrdup(buf[0] ? buf : "local"); + mdoc->meta.os = xstrdup(buf[0] ? buf : "LOCAL"); mdoc->lastnamed = SEC_BODY; return(post_prologue(mdoc)); +} + + +/* + * Transform -width MACRO values into real widths. + */ +static int +post_bl(struct mdoc *mdoc) +{ + struct mdoc_block *bl; + size_t width; + int tok, i; + char buf[32]; + + if (MDOC_BLOCK != mdoc->last->type) + return(1); + + bl = &mdoc->last->data.block; + + for (i = 0; i < (int)bl->argc; i++) + if (MDOC_Width == bl->argv[i].arg) + break; + + if (i == (int)bl->argc) + return(1); + + assert(1 == bl->argv[i].sz); + if (MDOC_MAX == (tok = mdoc_find(mdoc, *bl->argv[i].value))) + return(1); + + if (0 == (width = mdoc_macro2len(tok))) + return(mdoc_warn(mdoc, WARN_SYNTAX, + "-%s macro has no length", + mdoc_argnames[MDOC_Width])); + + mdoc_msg(mdoc, "re-writing %s argument: %s -> %zun", + mdoc_argnames[MDOC_Width], + *bl->argv[i].value, width); + + /* FIXME: silently truncates. */ + (void)snprintf(buf, sizeof(buf), "%zun", width); + + free(*bl->argv[i].value); + *bl->argv[i].value = strdup(buf); + + return(1); }