=================================================================== RCS file: /cvs/mandoc/Attic/mdoc_action.c,v retrieving revision 1.51 retrieving revision 1.58 diff -u -p -r1.51 -r1.58 --- mandoc/Attic/mdoc_action.c 2010/03/31 07:13:53 1.51 +++ mandoc/Attic/mdoc_action.c 2010/05/15 16:24:38 1.58 @@ -1,4 +1,4 @@ -/* $Id: mdoc_action.c,v 1.51 2010/03/31 07:13:53 kristaps Exp $ */ +/* $Id: mdoc_action.c,v 1.58 2010/05/15 16:24:38 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -44,7 +44,7 @@ struct actions { static int concat(struct mdoc *, char *, const struct mdoc_node *, size_t); -static inline int order_rs(int); +static inline int order_rs(enum mdoct); static int post_ar(POST_ARGS); static int post_at(POST_ARGS); @@ -196,7 +196,7 @@ static const struct actions mdoc_actions[MDOC_MAX] = { #define RSORD_MAX 14 -static const int rsord[RSORD_MAX] = { +static const enum mdoct rsord[RSORD_MAX] = { MDOC__A, MDOC__T, MDOC__B, @@ -366,9 +366,10 @@ post_st(POST_ARGS) assert(MDOC_TEXT == n->child->type); p = mdoc_a2st(n->child->string); - assert(p); - free(n->child->string); - n->child->string = mandoc_strdup(p); + if (p != NULL) { + free(n->child->string); + n->child->string = mandoc_strdup(p); + } return(1); } @@ -381,15 +382,27 @@ post_st(POST_ARGS) static int post_at(POST_ARGS) { - struct mdoc_node *nn; - const char *p; + struct mdoc_node *nn; + const char *p, *q; + char *buf; + size_t sz; if (n->child) { assert(MDOC_TEXT == n->child->type); p = mdoc_a2att(n->child->string); - assert(p); - free(n->child->string); - n->child->string = mandoc_strdup(p); + if (p) { + free(n->child->string); + n->child->string = mandoc_strdup(p); + } else { + p = "AT&T UNIX "; + q = n->child->string; + sz = strlen(p) + strlen(q) + 1; + buf = mandoc_malloc(sz); + strlcpy(buf, p, sz); + strlcat(buf, q, sz); + free(n->child->string); + n->child->string = buf; + } return(1); } @@ -419,8 +432,12 @@ post_sh(POST_ARGS) if ( ! concat(m, buf, n->child, BUFSIZ)) return(0); - sec = mdoc_atosec(buf); - if (SEC_CUSTOM != sec) + sec = mdoc_str2sec(buf); + /* + * The first section should always make us move into a non-new + * state. + */ + if (SEC_NONE == m->lastnamed || SEC_CUSTOM != sec) m->lastnamed = sec; /* Some sections only live in certain manual sections. */ @@ -429,17 +446,14 @@ post_sh(POST_ARGS) case (SEC_RETURN_VALUES): /* FALLTHROUGH */ case (SEC_ERRORS): - switch (m->meta.msec) { - case (2): - /* FALLTHROUGH */ - case (3): - /* FALLTHROUGH */ - case (9): + assert(m->meta.msec); + if (*m->meta.msec == '2') break; - default: - return(mdoc_nwarn(m, n, EBADSEC)); - } - break; + if (*m->meta.msec == '3') + break; + if (*m->meta.msec == '9') + break; + return(mdoc_nwarn(m, n, EWRONGMSEC)); default: break; } @@ -456,8 +470,6 @@ post_dt(POST_ARGS) { struct mdoc_node *nn; const char *cp; - char *ep; - long lval; if (m->meta.title) free(m->meta.title); @@ -467,16 +479,16 @@ post_dt(POST_ARGS) free(m->meta.arch); m->meta.title = m->meta.vol = m->meta.arch = NULL; - m->meta.msec = 0; - /* Handles: `.Dt' * --> title = unknown, volume = local, msec = 0, arch = NULL */ 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.msec = mandoc_strdup("1"); return(post_prol(m, n)); } @@ -487,8 +499,10 @@ post_dt(POST_ARGS) m->meta.title = mandoc_strdup(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.msec = mandoc_strdup("1"); return(post_prol(m, n)); } @@ -501,13 +515,13 @@ post_dt(POST_ARGS) cp = mdoc_a2msec(nn->string); if (cp) { - /* FIXME: where is strtonum!? */ m->meta.vol = mandoc_strdup(cp); - lval = strtol(nn->string, &ep, 10); - if (nn->string[0] != '\0' && *ep == '\0') - m->meta.msec = (int)lval; - } else + m->meta.msec = mandoc_strdup(nn->string); + } else if (mdoc_nwarn(m, n, EBADMSEC)) { m->meta.vol = mandoc_strdup(nn->string); + m->meta.msec = mandoc_strdup(nn->string); + } else + return(0); if (NULL == (nn = nn->next)) return(post_prol(m, n)); @@ -524,6 +538,7 @@ post_dt(POST_ARGS) free(m->meta.vol); m->meta.vol = mandoc_strdup(cp); } else { + /* FIXME: warn about bad arch. */ cp = mdoc_a2arch(nn->string); if (NULL == cp) { free(m->meta.vol); @@ -725,7 +740,7 @@ post_bl_head(POST_ARGS) nn->string = NULL; nnp = nn; nn = nn->next; - mdoc_node_free(nnp); + mdoc_node_delete(NULL, nnp); } n->nchild = 0; @@ -850,29 +865,10 @@ post_dd(POST_ARGS) static int post_prol(POST_ARGS) { - struct mdoc_node *np; - if (n->parent->child == n) - n->parent->child = n->prev; - if (n->prev) - n->prev->next = NULL; - - np = n; - assert(NULL == n->next); - - if (n->prev) { - m->last = n->prev; - m->next = MDOC_NEXT_SIBLING; - } else { - m->last = n->parent; - m->next = MDOC_NEXT_CHILD; - } - - mdoc_node_freelist(np); - + mdoc_node_delete(m, n); if (m->meta.title && m->meta.date && m->meta.os) m->flags |= MDOC_PBODY; - return(1); } @@ -960,11 +956,11 @@ post_display(POST_ARGS) static inline int -order_rs(int t) +order_rs(enum mdoct t) { int i; - for (i = 0; i < RSORD_MAX; i++) + for (i = 0; i < (int)RSORD_MAX; i++) if (rsord[i] == t) return(i);