Module Name: src Committed By: joerg Date: Thu Jun 24 17:19:58 UTC 2010
Modified Files: src/external/bsd/mdocml/dist: man_term.c mdoc_action.c mdoc_term.c Log Message: Merge mdocml-1.10.1 To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/external/bsd/mdocml/dist/man_term.c \ src/external/bsd/mdocml/dist/mdoc_term.c cvs rdiff -u -r1.9 -r1.10 src/external/bsd/mdocml/dist/mdoc_action.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/mdocml/dist/man_term.c diff -u src/external/bsd/mdocml/dist/man_term.c:1.2 src/external/bsd/mdocml/dist/man_term.c:1.3 --- src/external/bsd/mdocml/dist/man_term.c:1.2 Thu Jun 17 00:56:03 2010 +++ src/external/bsd/mdocml/dist/man_term.c Thu Jun 24 17:19:58 2010 @@ -1,6 +1,6 @@ -/* $Vendor-Id: man_term.c,v 1.73 2010/06/07 20:57:09 kristaps Exp $ */ +/* $Vendor-Id: man_term.c,v 1.76 2010/06/19 20:46:28 kristaps Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons <krist...@kth.se> + * Copyright (c) 2008, 2009 Kristaps Dzonsons <krist...@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -73,9 +73,9 @@ static int a2width(const struct man_node *); static int a2height(const struct man_node *); -static void print_man_head(struct termp *, const void *); static void print_man_nodelist(DECL_ARGS); static void print_man_node(DECL_ARGS); +static void print_man_head(struct termp *, const void *); static void print_man_foot(struct termp *, const void *); static void print_bvspace(struct termp *, const struct man_node *); @@ -158,6 +158,7 @@ p->overstep = 0; p->maxrmargin = p->defrmargin; + p->tabwidth = 5; if (NULL == p->symtab) switch (p->enc) { @@ -172,7 +173,7 @@ n = man_node(man); m = man_meta(man); - term_begin(p, print_man_head, print_man_foot, man_meta(man)); + term_begin(p, print_man_head, print_man_foot, m); p->flags |= TERMP_NOSPACE; mt.fl = 0; Index: src/external/bsd/mdocml/dist/mdoc_term.c diff -u src/external/bsd/mdocml/dist/mdoc_term.c:1.2 src/external/bsd/mdocml/dist/mdoc_term.c:1.3 --- src/external/bsd/mdocml/dist/mdoc_term.c:1.2 Thu Jun 17 00:56:03 2010 +++ src/external/bsd/mdocml/dist/mdoc_term.c Thu Jun 24 17:19:58 2010 @@ -1,6 +1,6 @@ -/* $Vendor-Id: mdoc_term.c,v 1.144 2010/06/07 20:57:09 kristaps Exp $ */ +/* $Vendor-Id: mdoc_term.c,v 1.156 2010/06/19 20:46:28 kristaps Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons <krist...@kth.se> + * Copyright (c) 2008, 2009 Kristaps Dzonsons <krist...@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -52,22 +52,19 @@ void (*post)(DECL_ARGS); }; -static size_t a2width(const struct mdoc_argv *, int); +static size_t a2width(const char *); static size_t a2height(const struct mdoc_node *); -static size_t a2offs(const struct mdoc_argv *); +static size_t a2offs(const char *); 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_disptype(const struct mdoc_node *); static void print_bvspace(struct termp *, const struct mdoc_node *, const struct mdoc_node *); static void print_mdoc_node(DECL_ARGS); -static void print_mdoc_head(struct termp *, const void *); static void print_mdoc_nodelist(DECL_ARGS); -static void print_foot(struct termp *, const void *); +static void print_mdoc_head(struct termp *, const void *); +static void print_mdoc_foot(struct termp *, const void *); static void synopsis_pre(struct termp *, const struct mdoc_node *); @@ -289,7 +286,7 @@ n = mdoc_node(mdoc); m = mdoc_meta(mdoc); - term_begin(p, print_mdoc_head, print_foot, mdoc_meta(mdoc)); + term_begin(p, print_mdoc_head, print_mdoc_foot, m); if (n->child) print_mdoc_nodelist(p, NULL, m, n->child); @@ -348,9 +345,8 @@ } -/* ARGSUSED */ static void -print_foot(struct termp *p, const void *arg) +print_mdoc_foot(struct termp *p, const void *arg) { char buf[DATESIZ], os[BUFSIZ]; const struct mdoc_meta *m; @@ -400,7 +396,6 @@ } -/* ARGSUSED */ static void print_mdoc_head(struct termp *p, const void *arg) { @@ -479,62 +474,33 @@ static size_t -a2width(const struct mdoc_argv *arg, int pos) +a2width(const char *v) { struct roffsu su; - assert(arg->value[pos]); - if ( ! a2roffsu(arg->value[pos], &su, SCALE_MAX)) - SCALE_HS_INIT(&su, strlen(arg->value[pos])); + assert(v); + if ( ! a2roffsu(v, &su, SCALE_MAX)) + SCALE_HS_INIT(&su, strlen(v)); return(term_hspan(&su)); } -static int -arg_disptype(const struct mdoc_node *n) -{ - int i, len; - - assert(MDOC_BLOCK == n->type); - - len = (int)(n->args ? n->args->argc : 0); - - for (i = 0; i < len; i++) - switch (n->args->argv[i].arg) { - case (MDOC_Centred): - /* FALLTHROUGH */ - case (MDOC_Ragged): - /* FALLTHROUGH */ - case (MDOC_Filled): - /* FALLTHROUGH */ - case (MDOC_Unfilled): - /* FALLTHROUGH */ - case (MDOC_Literal): - return(n->args->argv[i].arg); - default: - break; - } - - return(-1); -} - - static size_t -a2offs(const struct mdoc_argv *arg) +a2offs(const char *v) { struct roffsu su; - if ('\0' == arg->value[0][0]) + if ('\0' == *v) return(0); - else if (0 == strcmp(arg->value[0], "left")) + else if (0 == strcmp(v, "left")) return(0); - else if (0 == strcmp(arg->value[0], "indent")) + else if (0 == strcmp(v, "indent")) return(INDENT + 1); - else if (0 == strcmp(arg->value[0], "indent-two")) + else if (0 == strcmp(v, "indent-two")) return((INDENT + 1) * 2); - else if ( ! a2roffsu(arg->value[0], &su, SCALE_MAX)) - SCALE_HS_INIT(&su, strlen(arg->value[0])); + else if ( ! a2roffsu(v, &su, SCALE_MAX)) + SCALE_HS_INIT(&su, strlen(v)); return(term_hspan(&su)); } @@ -554,39 +520,21 @@ /* * Get the index of an argument in a node's argument list or -1 if it - * does not exist. See arg_getattrs(). + * does not exist. */ static int arg_getattr(int v, const struct mdoc_node *n) { - int val; - - return(arg_getattrs(&v, &val, 1, n) ? val : -1); -} - - -/* - * Walk through the argument list for a node and fill an array "vals" - * with the positions of the argument structures listed in "keys". - * Return the number of elements that were written into "vals", which - * can be zero. - */ -static int -arg_getattrs(const int *keys, int *vals, - size_t sz, const struct mdoc_node *n) -{ - int i, j, k; + int i; if (NULL == n->args) return(0); - for (k = i = 0; i < (int)n->args->argc; i++) - for (j = 0; j < (int)sz; j++) - if (n->args->argv[i].arg == keys[j]) { - vals[j] = i; - k++; - } - return(k); + for (i = 0; i < (int)n->args->argc; i++) + if (n->args->argv[i].arg == v) + return(i); + + return(-1); } @@ -603,7 +551,10 @@ const struct mdoc_node *nn; term_newln(p); - if (arg_hasattr(MDOC_Compact, bl)) + + if (MDOC_Bd == bl->tok && bl->data.Bd.comp) + return; + if (MDOC_Bl == bl->tok && bl->data.Bl.comp) return; /* Do not vspace directly after Ss/Sh. */ @@ -622,13 +573,13 @@ /* A `-column' does not assert vspace within the list. */ - if (MDOC_Bl == bl->tok && LIST_column == bl->data.list) + if (MDOC_Bl == bl->tok && LIST_column == bl->data.Bl.type) if (n->prev && MDOC_It == n->prev->tok) return; /* A `-diag' without body does not vspace. */ - if (MDOC_Bl == bl->tok && LIST_diag == bl->data.list) + if (MDOC_Bl == bl->tok && LIST_diag == bl->data.Bl.type) if (n->prev && MDOC_It == n->prev->tok) { assert(n->prev->body); if (NULL == n->prev->body->child) @@ -672,7 +623,7 @@ { const struct mdoc_node *bl, *nn; char buf[7]; - int i, keys[3], vals[3]; + int i, col; size_t width, offset, ncols, dcol; enum mdoc_list type; @@ -682,18 +633,7 @@ } bl = n->parent->parent->parent; - - /* Get list width, offset, and list type from argument list. */ - - keys[0] = MDOC_Width; - keys[1] = MDOC_Offset; - keys[2] = MDOC_Column; - - vals[0] = vals[1] = vals[2] = -1; - - arg_getattrs(keys, vals, 3, bl); - - type = bl->data.list; + type = bl->data.Bl.type; /* * First calculate width and offset. This is pretty easy unless @@ -703,13 +643,16 @@ width = offset = 0; - if (vals[1] >= 0) - offset = a2offs(&bl->args->argv[vals[1]]); + if (bl->data.Bl.offs) + offset = a2offs(bl->data.Bl.offs); switch (type) { case (LIST_column): if (MDOC_HEAD == n->type) break; + + col = arg_getattr(MDOC_Column, bl); + /* * Imitate groff's column handling: * - For each earlier column, add its width. @@ -719,7 +662,7 @@ * column. * - For more than 5 columns, add only one column. */ - ncols = bl->args->argv[vals[2]].sz; + ncols = bl->args->argv[col].sz; /* LINTED */ dcol = ncols < 5 ? 4 : ncols == 5 ? 3 : 1; @@ -732,8 +675,7 @@ nn->prev && i < (int)ncols; nn = nn->prev, i++) offset += dcol + a2width - (&bl->args->argv[vals[2]], i); - + (bl->args->argv[col].value[i]); /* * When exceeding the declared number of columns, leave @@ -748,10 +690,10 @@ * Use the declared column widths, extended as explained * in the preceding paragraph. */ - width = a2width(&bl->args->argv[vals[2]], i) + dcol; + width = a2width(bl->args->argv[col].value[i]) + dcol; break; default: - if (vals[0] < 0) + if (NULL == bl->data.Bl.width) break; /* @@ -759,7 +701,8 @@ * number for buffering single arguments. See the above * handling for column for how this changes. */ - width = a2width(&bl->args->argv[vals[0]], 0) + 2; + assert(bl->data.Bl.width); + width = a2width(bl->data.Bl.width) + 2; break; } @@ -1021,7 +964,7 @@ if (MDOC_BLOCK == n->type) return; - type = n->parent->parent->parent->data.list; + type = n->parent->parent->parent->data.Bl.type; switch (type) { case (LIST_item): @@ -1634,7 +1577,6 @@ termp_bd_pre(DECL_ARGS) { size_t tabwidth; - int i, type; size_t rm, rmax; const struct mdoc_node *nn; @@ -1644,13 +1586,8 @@ } else if (MDOC_HEAD == n->type) return(0); - nn = n->parent; - - type = arg_disptype(nn); - assert(-1 != type); - - if (-1 != (i = arg_getattr(MDOC_Offset, nn))) - p->offset += a2offs(&nn->args->argv[i]); + if (n->data.Bd.offs) + p->offset += a2offs(n->data.Bd.offs); /* * If -ragged or -filled are specified, the block does nothing @@ -1660,7 +1597,8 @@ * lines are allowed. */ - if (MDOC_Literal != type && MDOC_Unfilled != type) + if (DISP_literal != n->data.Bd.type && + DISP_unfilled != n->data.Bd.type) return(1); tabwidth = p->tabwidth; @@ -1677,8 +1615,8 @@ NULL == nn->next) term_flushln(p); } - p->tabwidth = tabwidth; + p->tabwidth = tabwidth; p->rmargin = rm; p->maxrmargin = rmax; return(0); @@ -1689,19 +1627,16 @@ static void termp_bd_post(DECL_ARGS) { - int type; size_t rm, rmax; if (MDOC_BODY != n->type) return; - type = arg_disptype(n->parent); - assert(-1 != type); - rm = p->rmargin; rmax = p->maxrmargin; - if (MDOC_Literal == type || MDOC_Unfilled == type) + if (DISP_literal == n->data.Bd.type || + DISP_unfilled == n->data.Bd.type) p->rmargin = p->maxrmargin = TERM_MAXMARGIN; p->flags |= TERMP_NOSPACE; Index: src/external/bsd/mdocml/dist/mdoc_action.c diff -u src/external/bsd/mdocml/dist/mdoc_action.c:1.9 src/external/bsd/mdocml/dist/mdoc_action.c:1.10 --- src/external/bsd/mdocml/dist/mdoc_action.c:1.9 Wed Jun 16 18:13:41 2010 +++ src/external/bsd/mdocml/dist/mdoc_action.c Thu Jun 24 17:19:58 2010 @@ -1,6 +1,6 @@ -/* $Vendor-Id: mdoc_action.c,v 1.65 2010/06/03 13:44:36 kristaps Exp $ */ +/* $Vendor-Id: mdoc_action.c,v 1.71 2010/06/19 20:46:28 kristaps Exp $ */ /* - * Copyright (c) 2008, 2009 Kristaps Dzonsons <krist...@kth.se> + * Copyright (c) 2008, 2009 Kristaps Dzonsons <krist...@bsd.lv> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -68,9 +68,7 @@ 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 */ @@ -84,7 +82,7 @@ { 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 */ @@ -633,33 +631,34 @@ 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; /* XXX: make this a macro value. */ + sz = 10; 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); /* @@ -667,19 +666,21 @@ * We're guaranteed that a MDOC_Width doesn't already exist. */ - nn = n; - assert(nn->args); - i = (int)(nn->args->argc)++; + assert(n->args); + i = (int)(n->args->argc)++; + + n->args->argv = mandoc_realloc(n->args->argv, + n->args->argc * sizeof(struct mdoc_argv)); - nn->args->argv = mandoc_realloc(nn->args->argv, - nn->args->argc * sizeof(struct mdoc_argv)); + n->args->argv[i].arg = MDOC_Width; + n->args->argv[i].line = n->line; + n->args->argv[i].pos = n->pos; + n->args->argv[i].sz = 1; + n->args->argv[i].value = mandoc_malloc(sizeof(char *)); + n->args->argv[i].value[0] = mandoc_strdup(buf); - nn->args->argv[i].arg = MDOC_Width; - nn->args->argv[i].line = n->line; - nn->args->argv[i].pos = n->pos; - nn->args->argv[i].sz = 1; - nn->args->argv[i].value = mandoc_malloc(sizeof(char *)); - nn->args->argv[i].value[0] = mandoc_strdup(buf); + /* Set our width! */ + n->data.Bl.width = n->args->argv[i].value[0]; return(1); } @@ -696,36 +697,35 @@ int i; enum mdoct tok; char buf[NUMSIZ]; - char *p; - - if (NULL == n->args) - return(1); - - 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. */ - if (0 == strcmp(p, "Ds")) + if (0 == strcmp(n->data.Bl.width, "Ds")) width = 6; - else if (MDOC_MAX == (tok = mdoc_hash_find(p))) + else if (MDOC_MAX == (tok = mdoc_hash_find(n->data.Bl.width))) return(1); else if (0 == (width = mdoc_macro2len(tok))) return(mdoc_nmsg(m, n, MANDOCERR_BADWIDTH)); /* The value already exists: free and reallocate it. */ + assert(n->args); + + for (i = 0; i < (int)n->args->argc; i++) + if (MDOC_Width == n->args->argv[i].arg) + break; + + assert(i < (int)n->args->argc); + snprintf(buf, NUMSIZ, "%zun", width); free(n->args->argv[i].value[0]); n->args->argv[i].value[0] = mandoc_strdup(buf); + + /* Set our width! */ + n->data.Bl.width = n->args->argv[i].value[0]; return(1); } @@ -741,7 +741,9 @@ 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; @@ -751,8 +753,7 @@ 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); /* @@ -782,7 +783,8 @@ static int post_bl(POST_ARGS) { - int i, r, len; + struct mdoc_node *nn; + const char *ww; if (MDOC_HEAD == n->type) return(post_bl_head(m, n)); @@ -797,21 +799,27 @@ * rewritten into real lengths). */ - len = (int)(n->args ? n->args->argc : 0); + ww = n->data.Bl.width; - 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) - r |= 1 << 1; - } - - if (r & (1 << 0) && ! (r & (1 << 1))) { + if (LIST_tag == n->data.Bl.type && NULL == n->data.Bl.width) { if ( ! post_bl_tagwidth(m, n)) return(0); - } else if (r & (1 << 1)) + } else if (NULL != n->data.Bl.width) { if ( ! post_bl_width(m, n)) return(0); + } else + return(1); + + assert(n->data.Bl.width); + + /* If it has changed, propogate new width to children. */ + + if (ww == n->data.Bl.width) + return(1); + + for (nn = n->child; nn; nn = nn->next) + if (MDOC_Bl == nn->tok) + nn->data.Bl.width = n->data.Bl.width; return(1); } @@ -831,7 +839,6 @@ np = n; m->next = MDOC_NEXT_CHILD; - /* XXX: make into macro value. */ if ( ! mdoc_word_alloc(m, n->line, n->pos, "~")) return(0); m->last = np; @@ -937,61 +944,17 @@ } -/* 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. - */ - - for (i = 0; n->args && 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 <string>. */ - 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) -{ - - if (MDOC_BLOCK == n->type) - return(pre_offset(m, n)); - return(1); -} - - 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); }