[BACK]Return to mdoc.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/mdoc.c between version 1.25 and 1.29

version 1.25, 2009/01/09 14:45:44 version 1.29, 2009/01/14 11:58:24
Line 94  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
Line 94  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
         { macro_scoped_line, MDOC_PARSED }, /* D1 */          { macro_scoped_line, MDOC_PARSED }, /* D1 */
         { macro_scoped_line, MDOC_PARSED }, /* Dl */          { macro_scoped_line, MDOC_PARSED }, /* Dl */
         { macro_scoped, MDOC_EXPLICIT }, /* Bd */          { macro_scoped, MDOC_EXPLICIT }, /* Bd */
         { macro_close_explicit, 0 }, /* Ed */          { macro_scoped_close, MDOC_EXPLICIT }, /* Ed */
         { macro_scoped, MDOC_EXPLICIT }, /* Bl */          { macro_scoped, MDOC_EXPLICIT }, /* Bl */
         { macro_close_explicit, 0 }, /* El */          { macro_scoped_close, MDOC_EXPLICIT }, /* El */
         { macro_scoped, MDOC_NESTED | MDOC_PARSED }, /* It */          { macro_scoped, MDOC_PARSED | MDOC_TABSEP}, /* It */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ad */
         { macro_constant, MDOC_PARSED }, /* An */          { macro_constant, MDOC_PARSED }, /* An */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */
Line 137  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
Line 137  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
         { macro_constant, MDOC_QUOTABLE }, /* %R */          { macro_constant, MDOC_QUOTABLE }, /* %R */
         { macro_constant, MDOC_QUOTABLE }, /* %T */          { macro_constant, MDOC_QUOTABLE }, /* %T */
         { macro_constant, MDOC_QUOTABLE }, /* %V */          { macro_constant, MDOC_QUOTABLE }, /* %V */
         { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Ac */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ac */
         { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Ao */          { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Ao */
         { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Aq */          { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Aq */
         { macro_constant, 0 }, /* At */          { 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_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_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Bq */
         { macro_constant_delimited, MDOC_PARSED }, /* Bsx */          { macro_constant_delimited, MDOC_PARSED }, /* Bsx */
         { macro_constant_delimited, MDOC_PARSED }, /* Bx */          { macro_constant_delimited, MDOC_PARSED }, /* Bx */
         { macro_constant, 0 }, /* Db */          { macro_constant, 0 }, /* Db */
         { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Dc */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Dc */
         { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Do */          { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Do */
         { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Dq */          { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Dq */
         { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Ec */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ec */
         { macro_close_explicit, 0 }, /* Ef */          { macro_scoped_close, MDOC_EXPLICIT }, /* Ef */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Em */          { 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_constant_delimited, MDOC_PARSED }, /* Fx */
         { macro_text, MDOC_PARSED }, /* Ms */          { macro_text, MDOC_PARSED }, /* Ms */
         { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* No */          { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* No */
         { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* Ns */          { macro_constant_delimited, MDOC_CALLABLE | MDOC_PARSED }, /* Ns */
         { macro_constant_delimited, MDOC_PARSED }, /* Nx */          { macro_constant_delimited, MDOC_PARSED }, /* Nx */
         { macro_constant_delimited, MDOC_PARSED }, /* Ox */          { 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, 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_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_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_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Qq */
         { macro_close_explicit, 0 }, /* Re */          { macro_scoped_close, MDOC_EXPLICIT }, /* Re */
         { macro_scoped, MDOC_EXPLICIT }, /* Rs */          { macro_scoped, MDOC_EXPLICIT }, /* Rs */
         { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Sc */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Sc */
         { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* So */          { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* So */
         { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Sq */          { macro_scoped_line, MDOC_CALLABLE | MDOC_PARSED }, /* Sq */
         { macro_constant, 0 }, /* Sm */          { macro_constant, 0 }, /* Sm */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sx */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sx */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sy */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Sy */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Tn */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Tn */
         { macro_constant_delimited, MDOC_PARSED }, /* Ux */          { macro_constant_delimited, MDOC_PARSED }, /* Ux */
         { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Xc */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Xc */
         { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Xo */          { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Xo */
         /* XXX - .Fo supposed to be (but isn't) callable. */          /* XXX - .Fo supposed to be (but isn't) callable. */
         { macro_scoped, MDOC_EXPLICIT | MDOC_PARSED }, /* Fo */          { macro_scoped, MDOC_EXPLICIT | MDOC_PARSED }, /* Fo */
         /* XXX - .Fc supposed to be (but isn't) callable. */          /* XXX - .Fc supposed to be (but isn't) callable. */
         { macro_close_explicit, MDOC_PARSED }, /* Fc */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_PARSED }, /* Fc */
         { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED }, /* Oo */          { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Oo */
         { macro_close_explicit, MDOC_CALLABLE | MDOC_PARSED }, /* Oc */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Oc */
         { macro_scoped, MDOC_EXPLICIT }, /* Bk */          { macro_scoped, MDOC_EXPLICIT }, /* Bk */
         { macro_close_explicit, 0 }, /* Ek */          { macro_scoped_close, MDOC_EXPLICIT }, /* Ek */
         { macro_constant, 0 }, /* Bt */          { macro_constant, 0 }, /* Bt */
         { macro_constant, 0 }, /* Hf */          { macro_constant, 0 }, /* Hf */
         { macro_obsolete, 0 }, /* Fr */          { macro_obsolete, 0 }, /* Fr */
Line 283  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
Line 283  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
   
         if ('.' != *buf) {          if ('.' != *buf) {
                 if (SEC_PROLOGUE != mdoc->sec_lastn) {                  if (SEC_PROLOGUE != mdoc->sec_lastn) {
                         mdoc_word_alloc(mdoc, line, 0, buf);                          if ( ! mdoc_word_alloc(mdoc, line, 0, buf))
                                   return(0);
                         mdoc->next = MDOC_NEXT_SIBLING;                          mdoc->next = MDOC_NEXT_SIBLING;
                         return(1);                          return(1);
                 }                  }
Line 392  mdoc_macro(struct mdoc *mdoc, int tok, 
Line 393  mdoc_macro(struct mdoc *mdoc, int tok, 
 static int  static int
 mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p)  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *p)
 {  {
         const char       *nn, *on, *nt, *ot, *act;          const char       *on, *ot, *act;
   
         switch (p->type) {  
         case (MDOC_TEXT):  
                 nn = p->data.text.string;  
                 nt = "text";  
                 break;  
         case (MDOC_BODY):  
                 nn = mdoc_macronames[p->data.body.tok];  
                 nt = "body";  
                 break;  
         case (MDOC_ELEM):  
                 nn = mdoc_macronames[p->data.elem.tok];  
                 nt = "elem";  
                 break;  
         case (MDOC_HEAD):  
                 nn = mdoc_macronames[p->data.head.tok];  
                 nt = "head";  
                 break;  
         case (MDOC_TAIL):  
                 nn = mdoc_macronames[p->data.tail.tok];  
                 nt = "tail";  
                 break;  
         case (MDOC_BLOCK):  
                 nn = mdoc_macronames[p->data.block.tok];  
                 nt = "block";  
                 break;  
         default:  
                 abort();  
                 /* NOTREACHED */  
         }  
   
         assert(mdoc->last);          assert(mdoc->last);
         assert(mdoc->first);          assert(mdoc->first);
         assert(MDOC_ROOT != p->type);          assert(MDOC_ROOT != p->type);
   
           if (MDOC_TEXT == mdoc->last->type)
                   on = "<text>";
           else if (MDOC_ROOT == mdoc->last->type)
                   on = "<root>";
           else
                   on = mdoc_macronames[mdoc->last->tok];
   
           /* FIXME: put this into util.c. */
         switch (mdoc->last->type) {          switch (mdoc->last->type) {
         case (MDOC_TEXT):          case (MDOC_TEXT):
                 on = "<text>";  
                 ot = "text";                  ot = "text";
                 break;                  break;
         case (MDOC_BODY):          case (MDOC_BODY):
                 on = mdoc_macronames[mdoc->last->data.body.tok];  
                 ot = "body";                  ot = "body";
                 break;                  break;
         case (MDOC_ELEM):          case (MDOC_ELEM):
                 on = mdoc_macronames[mdoc->last->data.elem.tok];  
                 ot = "elem";                  ot = "elem";
                 break;                  break;
         case (MDOC_HEAD):          case (MDOC_HEAD):
                 on = mdoc_macronames[mdoc->last->data.head.tok];  
                 ot = "head";                  ot = "head";
                 break;                  break;
         case (MDOC_TAIL):          case (MDOC_TAIL):
                 on = mdoc_macronames[mdoc->last->data.tail.tok];  
                 ot = "tail";                  ot = "tail";
                 break;                  break;
         case (MDOC_BLOCK):          case (MDOC_BLOCK):
                 on = mdoc_macronames[mdoc->last->data.block.tok];  
                 ot = "block";                  ot = "block";
                 break;                  break;
         case (MDOC_ROOT):          case (MDOC_ROOT):
                 on = "root";  
                 ot = "root";                  ot = "root";
                 break;                  break;
         default:          default:
Line 483  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
Line 455  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
                 return(0);                  return(0);
         if ( ! mdoc_action_pre(mdoc, p))          if ( ! mdoc_action_pre(mdoc, p))
                 return(0);                  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->last = p;
         mdoc_msg(mdoc, "parse: %s of %s `%s'", act, ot, on);          mdoc_msg(mdoc, "parse: %s of %s `%s'", act, ot, on);
         return(1);          return(1);
Line 502  mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, 
Line 492  mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, 
         p->line = line;          p->line = line;
         p->pos = pos;          p->pos = pos;
         p->type = MDOC_TAIL;          p->type = MDOC_TAIL;
         p->data.tail.tok = tok;          p->tok = tok;
   
         return(mdoc_node_append(mdoc, p));          return(mdoc_node_append(mdoc, p));
 }  }
Line 521  mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, 
Line 511  mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, 
         p->line = line;          p->line = line;
         p->pos = pos;          p->pos = pos;
         p->type = MDOC_HEAD;          p->type = MDOC_HEAD;
         p->data.head.tok = tok;          p->tok = tok;
   
         return(mdoc_node_append(mdoc, p));          return(mdoc_node_append(mdoc, p));
 }  }
Line 540  mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, 
Line 530  mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, 
         p->line = line;          p->line = line;
         p->pos = pos;          p->pos = pos;
         p->type = MDOC_BODY;          p->type = MDOC_BODY;
         p->data.body.tok = tok;          p->tok = tok;
   
         return(mdoc_node_append(mdoc, p));          return(mdoc_node_append(mdoc, p));
 }  }
Line 570  mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,
Line 560  mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,
         p->pos = pos;          p->pos = pos;
         p->line = line;          p->line = line;
         p->type = MDOC_BLOCK;          p->type = MDOC_BLOCK;
         p->data.block.tok = tok;          p->tok = tok;
         p->data.block.argc = argsz;          p->data.block.argc = argsz;
         p->data.block.argv = argdup(argsz, args);          p->data.block.argv = argdup(argsz, args);
   
Line 589  mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, 
Line 579  mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos, 
         p->line = line;          p->line = line;
         p->pos = pos;          p->pos = pos;
         p->type = MDOC_ELEM;          p->type = MDOC_ELEM;
         p->data.elem.tok = tok;          p->tok = tok;
         p->data.elem.argc = argsz;          p->data.elem.argc = argsz;
         p->data.elem.argv = argdup(argsz, args);          p->data.elem.argv = argdup(argsz, args);
   
Line 708  argcpy(struct mdoc_arg *dst, const struct mdoc_arg *sr
Line 698  argcpy(struct mdoc_arg *dst, const struct mdoc_arg *sr
 {  {
         int              i;          int              i;
   
           dst->line = src->line;
           dst->pos = src->pos;
         dst->arg = src->arg;          dst->arg = src->arg;
         if (0 == (dst->sz = src->sz))          if (0 == (dst->sz = src->sz))
                 return;                  return;

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.29

CVSweb