=================================================================== RCS file: /cvs/mandoc/Attic/mdoc_action.c,v retrieving revision 1.61 retrieving revision 1.69 diff -u -p -r1.61 -r1.69 --- mandoc/Attic/mdoc_action.c 2010/05/24 11:59:37 1.61 +++ mandoc/Attic/mdoc_action.c 2010/06/13 20:05:12 1.69 @@ -1,4 +1,4 @@ -/* $Id: mdoc_action.c,v 1.61 2010/05/24 11:59:37 joerg Exp $ */ +/* $Id: mdoc_action.c,v 1.69 2010/06/13 20:05:12 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -52,11 +52,13 @@ static int post_at(POST_ARGS); static int post_bl(POST_ARGS); static int post_bl_head(POST_ARGS); static int post_bl_tagwidth(POST_ARGS); -static int post_bl_width(POST_ARGS); +static int post_bl_width(struct mdoc *, + struct mdoc_node *, int); static int post_dd(POST_ARGS); static int post_display(POST_ARGS); static int post_dt(POST_ARGS); static int post_lb(POST_ARGS); +static int post_li(POST_ARGS); static int post_nm(POST_ARGS); static int post_os(POST_ARGS); static int post_pa(POST_ARGS); @@ -67,9 +69,7 @@ static int post_st(POST_ARGS); static int post_std(POST_ARGS); static int pre_bd(PRE_ARGS); -static int pre_bl(PRE_ARGS); static int pre_dl(PRE_ARGS); -static int pre_offset(PRE_ARGS); static const struct actions mdoc_actions[MDOC_MAX] = { { NULL, NULL }, /* Ap */ @@ -83,7 +83,7 @@ static const struct actions mdoc_actions[MDOC_MAX] = { { pre_dl, post_display }, /* Dl */ { pre_bd, post_display }, /* Bd */ { NULL, NULL }, /* Ed */ - { pre_bl, post_bl }, /* Bl */ + { NULL, post_bl }, /* Bl */ { NULL, NULL }, /* El */ { NULL, NULL }, /* It */ { NULL, NULL }, /* Ad */ @@ -102,7 +102,7 @@ static const struct actions mdoc_actions[MDOC_MAX] = { { NULL, NULL }, /* Ft */ { NULL, NULL }, /* Ic */ { NULL, NULL }, /* In */ - { NULL, NULL }, /* Li */ + { NULL, post_li }, /* Li */ { NULL, NULL }, /* Nd */ { NULL, post_nm }, /* Nm */ { NULL, NULL }, /* Op */ @@ -193,6 +193,7 @@ static const struct actions mdoc_actions[MDOC_MAX] = { { NULL, NULL }, /* br */ { NULL, NULL }, /* sp */ { NULL, NULL }, /* %U */ + { NULL, NULL }, /* Ta */ }; #define RSORD_MAX 14 @@ -498,8 +499,8 @@ post_dt(POST_ARGS) if (NULL == (nn = n->child)) { /* XXX: make these macro values. */ /* FIXME: warn about missing values. */ - m->meta.title = mandoc_strdup("unknown"); - m->meta.vol = mandoc_strdup("local"); + m->meta.title = mandoc_strdup("UNKNOWN"); + m->meta.vol = mandoc_strdup("LOCAL"); m->meta.msec = mandoc_strdup("1"); return(post_prol(m, n)); } @@ -508,12 +509,13 @@ post_dt(POST_ARGS) * --> title = TITLE, volume = local, msec = 0, arch = NULL */ - m->meta.title = mandoc_strdup(nn->string); + m->meta.title = mandoc_strdup + ('\0' == nn->string[0] ? "UNKNOWN" : nn->string); if (NULL == (nn = nn->next)) { /* FIXME: warn about missing msec. */ /* XXX: make this a macro value. */ - m->meta.vol = mandoc_strdup("local"); + m->meta.vol = mandoc_strdup("LOCAL"); m->meta.msec = mandoc_strdup("1"); return(post_prol(m, n)); } @@ -630,33 +632,34 @@ static int post_bl_tagwidth(POST_ARGS) { struct mdoc_node *nn; - size_t sz; + size_t sz, ssz; int i; char buf[NUMSIZ]; - /* Defaults to ten ens. */ + sz = 10; - sz = 10; /* XXX: make this a macro value. */ - for (nn = n->body->child; nn; nn = nn->next) { - if (MDOC_It == nn->tok) - break; - } + if (MDOC_It != nn->tok) + continue; - if (nn) { assert(MDOC_BLOCK == nn->type); nn = nn->head->child; - if (MDOC_TEXT != nn->type) { - sz = mdoc_macro2len(nn->tok); - if (sz == 0) { - if ( ! mdoc_nmsg(m, n, MANDOCERR_NOWIDTHARG)) - return(0); - sz = 10; - } - } else + + if (MDOC_TEXT == nn->type) { sz = strlen(nn->string) + 1; + break; + } + + if (0 != (ssz = mdoc_macro2len(nn->tok))) + sz = ssz; + else if ( ! mdoc_nmsg(m, n, MANDOCERR_NOWIDTHARG)) + return(0); + + break; } + /* Defaults to ten ens. */ + snprintf(buf, NUMSIZ, "%zun", sz); /* @@ -687,25 +690,16 @@ post_bl_tagwidth(POST_ARGS) * scaling width. */ static int -post_bl_width(POST_ARGS) +post_bl_width(struct mdoc *m, struct mdoc_node *n, int pos) { size_t width; - int i; enum mdoct tok; char buf[NUMSIZ]; char *p; - if (NULL == n->args) - return(1); + assert(n->args); + p = n->args->argv[pos].value[0]; - for (i = 0; i < (int)n->args->argc; i++) - if (MDOC_Width == n->args->argv[i].arg) - break; - - if (i == (int)n->args->argc) - return(1); - p = n->args->argv[i].value[0]; - /* * If the value to -width is a macro, then we re-write it to be * the macro's width as set in share/tmac/mdoc/doc-common. @@ -721,8 +715,8 @@ post_bl_width(POST_ARGS) /* The value already exists: free and reallocate it. */ snprintf(buf, NUMSIZ, "%zun", width); - free(n->args->argv[i].value[0]); - n->args->argv[i].value[0] = mandoc_strdup(buf); + free(n->args->argv[pos].value[0]); + n->args->argv[pos].value[0] = mandoc_strdup(buf); return(1); } @@ -738,8 +732,10 @@ post_bl_head(POST_ARGS) int i, c; struct mdoc_node *np, *nn, *nnp; - if (NULL == n->child) + if (LIST_column != n->data.Bl.type) return(1); + else if (NULL == n->child) + return(1); np = n->parent; assert(np->args); @@ -748,8 +744,7 @@ post_bl_head(POST_ARGS) if (MDOC_Column == np->args->argv[c].arg) break; - if (c == (int)np->args->argc) - return(1); + assert(c < (int)np->args->argc); assert(0 == np->args->argv[c].sz); /* @@ -779,7 +774,7 @@ post_bl_head(POST_ARGS) static int post_bl(POST_ARGS) { - int i, r, len; + int i, r, len, width; if (MDOC_HEAD == n->type) return(post_bl_head(m, n)); @@ -796,18 +791,22 @@ post_bl(POST_ARGS) len = (int)(n->args ? n->args->argc : 0); + width = -1; + for (r = i = 0; i < len; i++) { if (MDOC_Tag == n->args->argv[i].arg) r |= 1 << 0; - if (MDOC_Width == n->args->argv[i].arg) + if (MDOC_Width == n->args->argv[i].arg) { + width = i; r |= 1 << 1; + } } if (r & (1 << 0) && ! (r & (1 << 1))) { if ( ! post_bl_tagwidth(m, n)) return(0); } else if (r & (1 << 1)) - if ( ! post_bl_width(m, n)) + if ( ! post_bl_width(m, n, width)) return(0); return(1); @@ -837,6 +836,27 @@ post_pa(POST_ARGS) /* + * Empty `Li' macros get an empty string to make front-ends add an extra + * space. + */ +static int +post_li(POST_ARGS) +{ + struct mdoc_node *np; + + if (n->child) + return(1); + + np = n; + m->next = MDOC_NEXT_CHILD; + if ( ! mdoc_word_alloc(m, n->line, n->pos, "")) + return(0); + m->last = np; + return(1); +} + + +/* * The `Ar' macro defaults to two strings "file ..." if no value is * provided as an argument. */ @@ -913,115 +933,17 @@ pre_dl(PRE_ARGS) } -/* ARGSUSED */ static int -pre_offset(PRE_ARGS) -{ - int i; - - /* - * Make sure that an empty offset produces an 8n length space as - * stipulated by mdoc.samples. - */ - - assert(n->args); - for (i = 0; i < (int)n->args->argc; i++) { - if (MDOC_Offset != n->args->argv[i].arg) - continue; - if (n->args->argv[i].sz) - break; - assert(1 == n->args->refcnt); - /* If no value set, length of . */ - n->args->argv[i].sz++; - n->args->argv[i].value = mandoc_malloc(sizeof(char *)); - n->args->argv[i].value[0] = mandoc_strdup("8n"); - break; - } - - return(1); -} - - -static int -pre_bl(PRE_ARGS) -{ - int pos; - - if (MDOC_BLOCK != n->type) { - assert(n->parent); - assert(MDOC_BLOCK == n->parent->type); - assert(MDOC_Bl == n->parent->tok); - assert(LIST__NONE != n->parent->data.list); - n->data.list = n->parent->data.list; - return(1); - } - - assert(LIST__NONE == n->data.list); - - for (pos = 0; pos < (int)n->args->argc; pos++) { - switch (n->args->argv[pos].arg) { - case (MDOC_Bullet): - n->data.list = LIST_bullet; - break; - case (MDOC_Dash): - n->data.list = LIST_dash; - break; - case (MDOC_Enum): - n->data.list = LIST_enum; - break; - case (MDOC_Hyphen): - n->data.list = LIST_hyphen; - break; - case (MDOC_Item): - n->data.list = LIST_item; - break; - case (MDOC_Tag): - n->data.list = LIST_tag; - break; - case (MDOC_Diag): - n->data.list = LIST_diag; - break; - case (MDOC_Hang): - n->data.list = LIST_hang; - break; - case (MDOC_Ohang): - n->data.list = LIST_ohang; - break; - case (MDOC_Inset): - n->data.list = LIST_inset; - break; - case (MDOC_Column): - n->data.list = LIST_column; - break; - default: - break; - } - if (LIST__NONE != n->data.list) - break; - } - - assert(LIST__NONE != n->data.list); - return(pre_offset(m, n)); -} - - -static int pre_bd(PRE_ARGS) { - int i; - if (MDOC_BLOCK == n->type) - return(pre_offset(m, n)); if (MDOC_BODY != n->type) return(1); - /* Enter literal context if `Bd -literal' or `-unfilled'. */ - - for (n = n->parent, i = 0; i < (int)n->args->argc; i++) - if (MDOC_Literal == n->args->argv[i].arg) - m->flags |= MDOC_LITERAL; - else if (MDOC_Unfilled == n->args->argv[i].arg) - m->flags |= MDOC_LITERAL; + if (DISP_literal == n->data.Bd.type) + m->flags |= MDOC_LITERAL; + if (DISP_unfilled == n->data.Bd.type) + m->flags |= MDOC_LITERAL; return(1); }