diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-02-26 16:08:11 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2009-02-26 16:08:11 +0000 |
commit | 7253f34bf22e21589e886f61f77fbe93b63852a4 (patch) | |
tree | 51c21b20e119256ec3ce0bc056c2927c67b5c13d | |
parent | 69eda203817e9dc1f6bf992ff8af90702f812b24 (diff) | |
download | mandoc-7253f34bf22e21589e886f61f77fbe93b63852a4.tar.gz |
Support for macro widths (/usr/share/tmac/mdoc/doc-common).
-rw-r--r-- | action.c | 51 | ||||
-rw-r--r-- | private.h | 1 | ||||
-rw-r--r-- | strings.c | 96 | ||||
-rw-r--r-- | term.c | 22 |
4 files changed, 167 insertions, 3 deletions
@@ -17,7 +17,9 @@ * PERFORMANCE OF THIS SOFTWARE. */ #include <assert.h> +#include <stdio.h> #include <stdlib.h> +#include <string.h> #include <time.h> #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 */ @@ -276,6 +279,52 @@ post_os(struct mdoc *mdoc) /* + * Transform -width MACRO values into real widths. + */ +static int +post_bl(struct mdoc *mdoc) +{ + struct mdoc_block *bl; + size_t i, width; + int tok; + char buf[32]; + + if (MDOC_BLOCK != mdoc->last->type) + return(1); + + bl = &mdoc->last->data.block; + + for (i = 0; i < bl->argc; i++) + if (MDOC_Width == bl->argv[i].arg) + break; + + if (i == 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); +} + + +/* * Prologue date must be parsed into document meta-data. */ static int @@ -131,6 +131,7 @@ enum mdoc_msec mdoc_atomsec(const char *); enum mdoc_vol mdoc_atovol(const char *); enum mdoc_arch mdoc_atoarch(const char *); time_t mdoc_atotime(const char *); +size_t mdoc_macro2len(int); char *mdoc_type2a(enum mdoc_type); char *mdoc_node2a(struct mdoc_node *); @@ -404,7 +404,7 @@ mdoc_arch2a(enum mdoc_arch arch) case (ARCH_armish): return("ARMISH"); case (ARCH_aviion): - return("AViion"); + return("AViiON"); case (ARCH_hp300): return("HP300"); case (ARCH_hppa): @@ -726,3 +726,97 @@ mdoc_att2a(enum mdoc_att c) return(p); } + + +size_t +mdoc_macro2len(int macro) +{ + + switch (macro) { + case(MDOC_Ad): + return(12); + case(MDOC_Ao): + return(12); + case(MDOC_An): + return(12); + case(MDOC_Aq): + return(12); + case(MDOC_Ar): + return(12); + case(MDOC_Bo): + return(12); + case(MDOC_Bq): + return(12); + case(MDOC_Cd): + return(12); + case(MDOC_Cm): + return(10); + case(MDOC_Do): + return(10); + case(MDOC_Dq): + return(12); + case(MDOC_Dv): + return(12); + case(MDOC_Eo): + return(12); + case(MDOC_Em): + return(10); + case(MDOC_Er): + return(12); + case(MDOC_Ev): + return(15); + case(MDOC_Fa): + return(12); + case(MDOC_Fl): + return(10); + case(MDOC_Fo): + return(16); + case(MDOC_Fn): + return(16); + case(MDOC_Ic): + return(10); + case(MDOC_Li): + return(16); + case(MDOC_Ms): + return(6); + case(MDOC_Nm): + return(10); + case(MDOC_No): + return(12); + case(MDOC_Oo): + return(10); + case(MDOC_Op): + return(14); + case(MDOC_Pa): + return(32); + case(MDOC_Pf): + return(12); + case(MDOC_Po): + return(12); + case(MDOC_Pq): + return(12); + case(MDOC_Ql): + return(16); + case(MDOC_Qo): + return(12); + case(MDOC_So): + return(12); + case(MDOC_Sq): + return(12); + case(MDOC_Sy): + return(6); + case(MDOC_Sx): + return(16); + case(MDOC_Tn): + return(10); + case(MDOC_Va): + return(12); + case(MDOC_Vt): + return(12); + case(MDOC_Xr): + return(10); + default: + break; + }; + return(0); +} @@ -17,6 +17,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ #include <assert.h> +#include <ctype.h> #include <err.h> #include <stdio.h> #include <stdlib.h> @@ -276,9 +277,29 @@ const struct termact *termacts = __termacts; static size_t arg_width(const struct mdoc_arg *arg) { + size_t len, i, v; /* TODO */ assert(*arg->value); + if (0 == strcmp(*arg->value, "indent")) + return(INDENT); + if (0 == strcmp(*arg->value, "indent-two")) + return(INDENT * 2); + + len = strlen(*arg->value); + assert(len > 0); + + for (i = 0; i < len - 1; i++) + if ( ! isdigit((int)(*arg->value)[i])) + break; + + if (i == len - 1) { + if ('n' == (*arg->value)[len - 1]) { + v = (size_t)atoi(*arg->value); + return(v); + } + + } return(strlen(*arg->value)); } @@ -293,7 +314,6 @@ arg_offset(const struct mdoc_arg *arg) return(INDENT); if (0 == strcmp(*arg->value, "indent-two")) return(INDENT * 2); - return(strlen(*arg->value)); } |