=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.26 retrieving revision 1.30 diff -u -p -r1.26 -r1.30 --- mandoc/mdoc.c 2009/01/12 10:31:53 1.26 +++ mandoc/mdoc.c 2009/01/15 15:46:45 1.30 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.26 2009/01/12 10:31:53 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.30 2009/01/15 15:46:45 kristaps Exp $ */ /* * Copyright (c) 2008 Kristaps Dzonsons * @@ -94,10 +94,10 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { macro_scoped_line, MDOC_PARSED }, /* D1 */ { macro_scoped_line, MDOC_PARSED }, /* Dl */ { macro_scoped, MDOC_EXPLICIT }, /* Bd */ - { macro_close_explicit, 0 }, /* Ed */ + { macro_scoped_close, MDOC_EXPLICIT }, /* Ed */ { macro_scoped, MDOC_EXPLICIT }, /* Bl */ - { macro_close_explicit, 0 }, /* El */ - { macro_scoped, MDOC_NESTED | MDOC_PARSED }, /* It */ + { macro_scoped_close, MDOC_EXPLICIT }, /* El */ + { macro_scoped, MDOC_PARSED | MDOC_TABSEP}, /* It */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */ { macro_constant, MDOC_PARSED }, /* An */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */ @@ -137,58 +137,58 @@ const struct mdoc_macro __mdoc_macros[MDOC_MAX] = { { macro_constant, MDOC_QUOTABLE }, /* %R */ { macro_constant, MDOC_QUOTABLE }, /* %T */ { macro_constant, MDOC_QUOTABLE }, /* %V */ - { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Ac */ - { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Ao */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ac */ + { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Ao */ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Aq */ { macro_constant, 0 }, /* At */ - { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Bc */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Bc */ { macro_scoped, MDOC_EXPLICIT }, /* Bf */ - { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Bo */ + { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Bo */ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Bq */ { macro_constant_delimited, MDOC_PARSED }, /* Bsx */ { macro_constant_delimited, MDOC_PARSED }, /* Bx */ { macro_constant, 0 }, /* Db */ - { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Dc */ - { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Do */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Dc */ + { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Do */ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Dq */ - { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Ec */ - { macro_close_explicit, 0 }, /* Ef */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ec */ + { macro_scoped_close, MDOC_EXPLICIT }, /* Ef */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Em */ - { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Eo */ + { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Eo */ { macro_constant_delimited, MDOC_PARSED }, /* Fx */ { macro_text, MDOC_PARSED }, /* Ms */ { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* No */ { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* Ns */ { macro_constant_delimited, MDOC_PARSED }, /* Nx */ { macro_constant_delimited, MDOC_PARSED }, /* Ox */ - { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Pc */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Pc */ { macro_constant, MDOC_PARSED }, /* Pf */ - { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Po */ + { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Po */ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Pq */ - { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Qc */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Qc */ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Ql */ - { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Qo */ + { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Qo */ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Qq */ - { macro_close_explicit, 0 }, /* Re */ + { macro_scoped_close, MDOC_EXPLICIT }, /* Re */ { macro_scoped, MDOC_EXPLICIT }, /* Rs */ - { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Sc */ - { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* So */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Sc */ + { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* So */ { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Sq */ { macro_constant, 0 }, /* Sm */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sx */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sy */ { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Tn */ { macro_constant_delimited, MDOC_PARSED }, /* Ux */ - { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Xc */ - { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Xo */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Xc */ + { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Xo */ /* XXX - .Fo supposed to be (but isn't) callable. */ { macro_scoped, MDOC_EXPLICIT | MDOC_PARSED }, /* Fo */ /* XXX - .Fc supposed to be (but isn't) callable. */ - { macro_close_explicit, MDOC_PARSED }, /* Fc */ - { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Oo */ - { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Oc */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_PARSED }, /* Fc */ + { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Oo */ + { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Oc */ { macro_scoped, MDOC_EXPLICIT }, /* Bk */ - { macro_close_explicit, 0 }, /* Ek */ + { macro_scoped_close, MDOC_EXPLICIT }, /* Ek */ { macro_constant, 0 }, /* Bt */ { macro_constant, 0 }, /* Hf */ { macro_obsolete, 0 }, /* Fr */ @@ -393,46 +393,29 @@ mdoc_macro(struct mdoc *mdoc, int tok, static int mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p) { - const char *on, *ot, *act; + const char *nn, *nt, *on, *ot, *act; assert(mdoc->last); assert(mdoc->first); assert(MDOC_ROOT != p->type); - switch (mdoc->last->type) { - case (MDOC_TEXT): + if (MDOC_TEXT == mdoc->last->type) on = ""; - ot = "text"; - break; - case (MDOC_BODY): - on = mdoc_macronames[mdoc->last->data.body.tok]; - ot = "body"; - break; - case (MDOC_ELEM): - on = mdoc_macronames[mdoc->last->data.elem.tok]; - ot = "elem"; - break; - case (MDOC_HEAD): - on = mdoc_macronames[mdoc->last->data.head.tok]; - ot = "head"; - break; - case (MDOC_TAIL): - on = mdoc_macronames[mdoc->last->data.tail.tok]; - ot = "tail"; - break; - case (MDOC_BLOCK): - on = mdoc_macronames[mdoc->last->data.block.tok]; - ot = "block"; - break; - case (MDOC_ROOT): - on = "root"; - ot = "root"; - break; - default: - abort(); - /* NOTREACHED */ - } + else if (MDOC_ROOT == mdoc->last->type) + on = ""; + else + on = mdoc_macronames[mdoc->last->tok]; + if (MDOC_TEXT == p->type) + nn = ""; + else if (MDOC_ROOT == p->type) + nn = ""; + else + nn = mdoc_macronames[p->tok]; + + ot = mdoc_type2a(mdoc->last->type); + nt = mdoc_type2a(p->type); + switch (mdoc->next) { case (MDOC_NEXT_SIBLING): mdoc->last->next = p; @@ -454,8 +437,27 @@ mdoc_node_append(struct mdoc *mdoc, struct mdoc_node * return(0); if ( ! mdoc_action_pre(mdoc, p)) return(0); + + switch (p->type) { + case (MDOC_HEAD): + assert(MDOC_BLOCK == p->parent->type); + p->parent->data.block.head = p; + break; + case (MDOC_TAIL): + assert(MDOC_BLOCK == p->parent->type); + p->parent->data.block.tail = p; + break; + case (MDOC_BODY): + assert(MDOC_BLOCK == p->parent->type); + p->parent->data.block.body = p; + break; + default: + break; + } + mdoc->last = p; - mdoc_msg(mdoc, "parse: %s of %s `%s'", act, ot, on); + mdoc_msg(mdoc, "parse: %s `%s' %s of %s `%s'", + nt, nn, act, ot, on); return(1); } @@ -473,7 +475,7 @@ mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, p->line = line; p->pos = pos; p->type = MDOC_TAIL; - p->data.tail.tok = tok; + p->tok = tok; return(mdoc_node_append(mdoc, p)); } @@ -492,7 +494,7 @@ mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, p->line = line; p->pos = pos; p->type = MDOC_HEAD; - p->data.head.tok = tok; + p->tok = tok; return(mdoc_node_append(mdoc, p)); } @@ -511,7 +513,7 @@ mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, p->line = line; p->pos = pos; p->type = MDOC_BODY; - p->data.body.tok = tok; + p->tok = tok; return(mdoc_node_append(mdoc, p)); } @@ -541,7 +543,7 @@ mdoc_block_alloc(struct mdoc *mdoc, int line, int pos, p->pos = pos; p->line = line; p->type = MDOC_BLOCK; - p->data.block.tok = tok; + p->tok = tok; p->data.block.argc = argsz; p->data.block.argv = argdup(argsz, args); @@ -560,7 +562,7 @@ mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, p->line = line; p->pos = pos; p->type = MDOC_ELEM; - p->data.elem.tok = tok; + p->tok = tok; p->data.elem.argc = argsz; p->data.elem.argv = argdup(argsz, args);