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

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

version 1.29, 2009/01/14 11:58:24 version 1.35, 2009/01/17 20:10:36
Line 99  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
Line 99  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
         { macro_scoped_close, MDOC_EXPLICIT }, /* El */          { macro_scoped_close, MDOC_EXPLICIT }, /* El */
         { macro_scoped, MDOC_PARSED | MDOC_TABSEP}, /* 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_text, MDOC_PARSED }, /* An */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ar */
         { macro_constant, MDOC_QUOTABLE }, /* Cd */          { macro_constant, MDOC_QUOTABLE }, /* Cd */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Cm */
Line 111  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
Line 111  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
         { macro_constant, 0 }, /* Fd */          { macro_constant, 0 }, /* Fd */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Fl */
         { macro_text, MDOC_CALLABLE | MDOC_QUOTABLE | MDOC_PARSED }, /* Fn */          { macro_text, MDOC_CALLABLE | MDOC_QUOTABLE | MDOC_PARSED }, /* Fn */
         { macro_text, MDOC_PARSED }, /* Ft */          { macro_text, MDOC_PARSED | MDOC_QUOTABLE }, /* Ft */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ic */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Ic */
         { macro_constant, 0 }, /* In */          { macro_constant, 0 }, /* In */
         { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Li */          { macro_text, MDOC_CALLABLE | MDOC_PARSED }, /* Li */
Line 140  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
Line 140  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
         { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ac */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Ac */
         { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* 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_delimited, 0 }, /* At */
         { macro_scoped_close, MDOC_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 | MDOC_EXPLICIT }, /* Bo */          { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Bo */
Line 162  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
Line 162  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
         { 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_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Pc */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Pc */
         { macro_constant, MDOC_PARSED }, /* Pf */          { macro_constant_delimited, MDOC_PARSED }, /* Pf */
         { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* 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_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Qc */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Qc */
Line 221  mdoc_result(struct mdoc *mdoc)
Line 221  mdoc_result(struct mdoc *mdoc)
   
   
 void  void
   mdoc_meta_free(struct mdoc *mdoc)
   {
   
           if (mdoc->meta.title)
                   free(mdoc->meta.title);
           if (mdoc->meta.os)
                   free(mdoc->meta.os);
           if (mdoc->meta.name)
                   free(mdoc->meta.name);
   }
   
   
   void
 mdoc_free(struct mdoc *mdoc)  mdoc_free(struct mdoc *mdoc)
 {  {
   
Line 241  mdoc_alloc(void *data, const struct mdoc_cb *cb)
Line 254  mdoc_alloc(void *data, const struct mdoc_cb *cb)
         p = xcalloc(1, sizeof(struct mdoc));          p = xcalloc(1, sizeof(struct mdoc));
   
         p->data = data;          p->data = data;
         (void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb));          if (cb)
                   (void)memcpy(&p->cb, cb, sizeof(struct mdoc_cb));
   
         p->last = xcalloc(1, sizeof(struct mdoc_node));          p->last = xcalloc(1, sizeof(struct mdoc_node));
         p->last->type = MDOC_ROOT;          p->last->type = MDOC_ROOT;
Line 288  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
Line 302  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
                         mdoc->next = MDOC_NEXT_SIBLING;                          mdoc->next = MDOC_NEXT_SIBLING;
                         return(1);                          return(1);
                 }                  }
                 return(mdoc_perr(mdoc, line, 0, ERR_SYNTAX_NOTEXT));                  return(mdoc_perr(mdoc, line, 0, "text disallowed"));
         }          }
   
         if (buf[1] && '\\' == buf[1])          if (buf[1] && '\\' == buf[1])
Line 301  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
Line 315  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
   
         if (i == (int)sizeof(tmp)) {          if (i == (int)sizeof(tmp)) {
                 mdoc->flags |= MDOC_HALT;                  mdoc->flags |= MDOC_HALT;
                 return(mdoc_perr(mdoc, line, 1, ERR_MACRO_NOTSUP));                  return(mdoc_perr(mdoc, line, 1, "unknown macro"));
         } else if (i <= 2) {          } else if (i <= 2) {
                 mdoc->flags |= MDOC_HALT;                  mdoc->flags |= MDOC_HALT;
                 return(mdoc_perr(mdoc, line, 1, ERR_MACRO_NOTSUP));                  return(mdoc_perr(mdoc, line, 1, "unknown macro"));
         }          }
   
         i--;          i--;
Line 314  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
Line 328  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
   
         if (MDOC_MAX == (c = mdoc_find(mdoc, tmp))) {          if (MDOC_MAX == (c = mdoc_find(mdoc, tmp))) {
                 mdoc->flags |= MDOC_HALT;                  mdoc->flags |= MDOC_HALT;
                 return(mdoc_perr(mdoc, line, 1, ERR_MACRO_NOTSUP));                  return(mdoc_perr(mdoc, line, 1, "unknown macro"));
         }          }
   
         while (buf[i] && isspace(buf[i]))          while (buf[i] && isspace(buf[i]))
Line 329  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
Line 343  mdoc_parseln(struct mdoc *mdoc, int line, char *buf)
   
   
 void  void
 mdoc_msg(struct mdoc *mdoc, const char *fmt, ...)  mdoc_vmsg(struct mdoc *mdoc, int ln, int pos, const char *fmt, ...)
 {  {
         struct mdoc_node *n;  
         va_list           ap;  
         char              buf[256];          char              buf[256];
           va_list           ap;
   
         if (NULL == mdoc->cb.mdoc_msg)          if (NULL == mdoc->cb.mdoc_msg)
                 return;                  return;
   
         n = mdoc->last;  
         assert(n);  
   
         va_start(ap, fmt);          va_start(ap, fmt);
         (void)vsnprintf(buf, sizeof(buf), fmt, ap);          (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
         va_end(ap);          va_end(ap);
           (*mdoc->cb.mdoc_msg)(mdoc->data, ln, pos, buf);
         (*mdoc->cb.mdoc_msg)(mdoc->data, n->line, n->pos, buf);  
 }  }
   
   
 int  int
 mdoc_perr(struct mdoc *mdoc,  mdoc_verr(struct mdoc *mdoc, int ln, int pos,
                 int line, int pos, enum mdoc_err type)                  const char *fmt, ...)
 {  {
           char             buf[256];
           va_list          ap;
   
         if (NULL == mdoc->cb.mdoc_err)          if (NULL == mdoc->cb.mdoc_err)
                 return(0);                  return(0);
         return((*mdoc->cb.mdoc_err)(mdoc->data, line, pos, type));  
           va_start(ap, fmt);
           (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
           va_end(ap);
           return((*mdoc->cb.mdoc_err)(mdoc->data, ln, pos, buf));
 }  }
   
   
 int  int
 mdoc_pwarn(struct mdoc *mdoc,  mdoc_vwarn(struct mdoc *mdoc, int ln, int pos,
                 int line, int pos, enum mdoc_warn type)                  enum mdoc_warn type, const char *fmt, ...)
 {  {
           char             buf[256];
           va_list          ap;
   
         if (NULL == mdoc->cb.mdoc_warn)          if (NULL == mdoc->cb.mdoc_warn)
                 return(0);                  return(0);
         return((*mdoc->cb.mdoc_warn)(mdoc->data, line, pos, type));  
           va_start(ap, fmt);
           (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
           va_end(ap);
           return((*mdoc->cb.mdoc_warn)(mdoc->data, ln, pos, type, buf));
 }  }
   
   
Line 376  mdoc_macro(struct mdoc *mdoc, int tok, 
Line 397  mdoc_macro(struct mdoc *mdoc, int tok, 
                 int ln, int ppos, int *pos, char *buf)                  int ln, int ppos, int *pos, char *buf)
 {  {
   
           assert(mdoc_macros[tok].fp);
   
         if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&          if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
                         SEC_PROLOGUE == mdoc->sec_lastn)                          SEC_PROLOGUE == mdoc->sec_lastn)
                 return(mdoc_perr(mdoc, ln, ppos, ERR_SEC_PROLOGUE));                  return(mdoc_perr(mdoc, ln, ppos, "macro disallowed in document prologue"));
   
         if (NULL == (mdoc_macros[tok].fp))  
                 return(mdoc_perr(mdoc, ln, ppos, ERR_MACRO_NOTSUP));  
   
         if (1 != ppos && ! (MDOC_CALLABLE & mdoc_macros[tok].flags))          if (1 != ppos && ! (MDOC_CALLABLE & mdoc_macros[tok].flags))
                 return(mdoc_perr(mdoc, ln, ppos, ERR_MACRO_NOTCALL));                  return(mdoc_perr(mdoc, ln, ppos, "macro not callable"));
   
         return((*mdoc_macros[tok].fp)(mdoc, tok, ln, ppos, pos, buf));          return((*mdoc_macros[tok].fp)(mdoc, tok, ln, ppos, pos, buf));
 }  }
   
Line 393  mdoc_macro(struct mdoc *mdoc, int tok, 
Line 411  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       *on, *ot, *act;          const char       *nn, *nt, *on, *ot, *act;
   
         assert(mdoc->last);          assert(mdoc->last);
         assert(mdoc->first);          assert(mdoc->first);
Line 406  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
Line 424  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
         else          else
                 on = mdoc_macronames[mdoc->last->tok];                  on = mdoc_macronames[mdoc->last->tok];
   
         /* FIXME: put this into util.c. */          if (MDOC_TEXT == p->type)
         switch (mdoc->last->type) {                  nn = "<text>";
         case (MDOC_TEXT):          else if (MDOC_ROOT == p->type)
                 ot = "text";                  nn = "<root>";
                 break;          else
         case (MDOC_BODY):                  nn = mdoc_macronames[p->tok];
                 ot = "body";  
                 break;  
         case (MDOC_ELEM):  
                 ot = "elem";  
                 break;  
         case (MDOC_HEAD):  
                 ot = "head";  
                 break;  
         case (MDOC_TAIL):  
                 ot = "tail";  
                 break;  
         case (MDOC_BLOCK):  
                 ot = "block";  
                 break;  
         case (MDOC_ROOT):  
                 ot = "root";  
                 break;  
         default:  
                 abort();  
                 /* NOTREACHED */  
         }  
   
           ot = mdoc_type2a(mdoc->last->type);
           nt = mdoc_type2a(p->type);
   
         switch (mdoc->next) {          switch (mdoc->next) {
         case (MDOC_NEXT_SIBLING):          case (MDOC_NEXT_SIBLING):
                 mdoc->last->next = p;                  mdoc->last->next = p;
Line 453  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
Line 453  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
   
         if ( ! mdoc_valid_pre(mdoc, p))          if ( ! mdoc_valid_pre(mdoc, p))
                 return(0);                  return(0);
         if ( ! mdoc_action_pre(mdoc, p))  
                 return(0);  
   
         switch (p->type) {          switch (p->type) {
         case (MDOC_HEAD):          case (MDOC_HEAD):
Line 474  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
Line 472  mdoc_node_append(struct mdoc *mdoc, struct mdoc_node *
         }          }
   
         mdoc->last = p;          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);          return(1);
 }  }
   
Line 724  argdup(size_t argsz, const struct mdoc_arg *args)
Line 723  argdup(size_t argsz, const struct mdoc_arg *args)
   
         return(pp);          return(pp);
 }  }
   
   
   char *
   mdoc_node2a(struct mdoc_node *node)
   {
           static char      buf[64];
   
           assert(node);
   
           buf[0] = 0;
           (void)xstrlcat(buf, mdoc_type2a(node->type), 64);
           if (MDOC_ROOT == node->type)
                   return(buf);
           (void)xstrlcat(buf, " `", 64);
           if (MDOC_TEXT == node->type)
                   (void)xstrlcat(buf, node->data.text.string, 64);
           else
                   (void)xstrlcat(buf, mdoc_macronames[node->tok], 64);
   
           return(buf);
   }
   
   

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

CVSweb