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

Diff for /mandoc/Attic/validate.c between version 1.9 and 1.18

version 1.9, 2008/12/30 18:15:26 version 1.18, 2009/01/08 14:55:59
Line 22 
Line 22 
 #include "private.h"  #include "private.h"
   
   
 typedef int     (*v_sz)(struct mdoc *, int, int, int);  typedef int     (*v_pre)(struct mdoc *, struct mdoc_node *);
 typedef int     (*v_extra)(struct mdoc *, int, int, int,  typedef int     (*v_post)(struct mdoc *);
                         const char *[], int, const struct mdoc_arg *);  
   
 static int        assert_eq0(struct mdoc *, int, int, int);  
 static int        assert_le1(struct mdoc *, int, int, int);  
 static int        need_eq0(struct mdoc *, int, int, int);  
 static int        need_eq1(struct mdoc *, int, int, int);  
 static int        need_ge1(struct mdoc *, int, int, int);  
 static int        need_le2(struct mdoc *, int, int, int);  
 static int        want_eq0(struct mdoc *, int, int, int);  
 static int        want_ge1(struct mdoc *, int, int, int);  
 static int        v_Sh(struct mdoc *, int, int, int,  
                         const char *[], int, const struct mdoc_arg *);  
 static int        v_Bd(struct mdoc *, int, int, int,  
                         const char *[], int, const struct mdoc_arg *);  
 static int        v_At(struct mdoc *, int, int, int,  
                         const char *[], int, const struct mdoc_arg *);  
   
 struct  valids {  struct  valids {
         v_sz      sz;          v_pre    pre;
         v_extra   extra;          v_post  *post;
 };  };
   
   
   static  int     pre_sh(struct mdoc *, struct mdoc_node *);
   static  int     post_headchild_err_ge1(struct mdoc *);
   static  int     post_headchild_err_le8(struct mdoc *);
   static  int     post_bodychild_warn_ge1(struct mdoc *);
   
   static v_post   posts_sh[] = { post_headchild_err_ge1,
                           post_bodychild_warn_ge1,
                           post_headchild_err_le8, NULL };
   
   
 const   struct valids mdoc_valids[MDOC_MAX] = {  const   struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, NULL }, /* \" */          { NULL, NULL }, /* \" */
         { NULL, NULL }, /* Dd */          { NULL, NULL }, /* Dd */ /* TODO */
         { NULL, NULL }, /* Dt */          { NULL, NULL }, /* Dt */ /* TODO */
         { NULL, NULL }, /* Os */          { NULL, NULL }, /* Os */ /* TODO */
         { need_ge1, v_Sh }, /* Sh */          { pre_sh, posts_sh }, /* Sh */ /* FIXME: preceding Pp. */
         { need_ge1, NULL }, /* Ss */          { NULL, NULL }, /* Ss */ /* FIXME: preceding Pp. */
         { want_eq0, NULL }, /* Pp */          { NULL, NULL }, /* Pp */
         { NULL, NULL }, /* D1 */          { NULL, NULL }, /* D1 */
         { NULL, NULL }, /* Dl */          { NULL, NULL }, /* Dl */
         { NULL, v_Bd }, /* Bd */          { NULL, NULL }, /* Bd */ /* FIXME: preceding Pp. */
         { NULL, NULL }, /* Ed */          { NULL, NULL }, /* Ed */
         { NULL, NULL }, /* Bl */          { NULL, NULL }, /* Bl */ /* FIXME: preceding Pp. */
         { NULL, NULL }, /* El */          { NULL, NULL }, /* El */
         { NULL, NULL }, /* It */          { NULL, NULL }, /* It */
         { need_ge1, NULL }, /* Ad */          { NULL, NULL }, /* Ad */
         { NULL, NULL }, /* An */          { NULL, NULL }, /* An */
         { NULL, NULL }, /* Ar */          { NULL, NULL }, /* Ar */
         { NULL, NULL }, /* Cd */          { NULL, NULL }, /* Cd */
         { NULL, NULL }, /* Cm */          { NULL, NULL }, /* Cm */
         { need_ge1, NULL }, /* Dv */          { NULL, NULL }, /* Dv */
         { need_ge1, NULL }, /* Er */          { NULL, NULL }, /* Er */
         { need_ge1, NULL }, /* Ev */          { NULL, NULL }, /* Ev */
         { NULL, NULL }, /* Ex */          { NULL, NULL }, /* Ex */
         { need_ge1, NULL }, /* Fa */          { NULL, NULL }, /* Fa */
         { NULL, NULL }, /* Fd */          { NULL, NULL }, /* Fd */
         { NULL, NULL }, /* Fl */          { NULL, NULL }, /* Fl */
         { NULL, NULL }, /* Fn */          { NULL, NULL }, /* Fn */
         { want_ge1, NULL }, /* Ft */          { NULL, NULL }, /* Ft */
         { need_ge1, NULL }, /* Ic */          { NULL, NULL }, /* Ic */
         { NULL, NULL }, /* In */          { NULL, NULL }, /* In */
         { want_ge1, NULL }, /* Li */          { NULL, NULL }, /* Li */
         { want_ge1, NULL }, /* Nd */          { NULL, NULL }, /* Nd */
         { NULL, NULL }, /* Nm */          { NULL, NULL }, /* Nm */
         { NULL, NULL }, /* Op */          { NULL, NULL }, /* Op */
         { NULL, NULL }, /* Ot */          { NULL, NULL }, /* Ot */
         { want_ge1, NULL }, /* Pa */          { NULL, NULL }, /* Pa */
         { NULL, NULL }, /* Rv */          { NULL, NULL }, /* Rv */
         { NULL, NULL }, /* St */          { NULL, NULL }, /* St */
         { need_ge1, NULL }, /* Va */          { NULL, NULL }, /* Va */
         { need_ge1, NULL }, /* Vt */          { NULL, NULL }, /* Vt */
         { NULL, NULL }, /* Xr */          { NULL, NULL }, /* Xr */
         { NULL, NULL }, /* %A */          { NULL, NULL }, /* %A */
         { NULL, NULL }, /* %B */          { NULL, NULL }, /* %B */
Line 103  const struct valids mdoc_valids[MDOC_MAX] = {
Line 98  const struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, NULL }, /* Ac */          { NULL, NULL }, /* Ac */
         { NULL, NULL }, /* Ao */          { NULL, NULL }, /* Ao */
         { NULL, NULL }, /* Aq */          { NULL, NULL }, /* Aq */
         { need_le2, v_At }, /* At */          { NULL, NULL }, /* At */ /* FIXME */
         { NULL, NULL }, /* Bc */          { NULL, NULL }, /* Bc */
         { NULL, NULL }, /* Bf */          { NULL, NULL }, /* Bf */
         { NULL, NULL }, /* Bo */          { NULL, NULL }, /* Bo */
         { NULL, NULL }, /* Bq */          { NULL, NULL }, /* Bq */
         { assert_le1, NULL }, /* Bsx */          { NULL, NULL }, /* Bsx */
         { assert_le1, NULL }, /* Bx */          { NULL, NULL }, /* Bx */
         { NULL, NULL }, /* Db */          { NULL, NULL }, /* Db */
         { NULL, NULL }, /* Dc */          { NULL, NULL }, /* Dc */
         { NULL, NULL }, /* Do */          { NULL, NULL }, /* Do */
         { NULL, NULL }, /* Dq */          { NULL, NULL }, /* Dq */
         { NULL, NULL }, /* Ec */          { NULL, NULL }, /* Ec */
         { NULL, NULL }, /* Ef */          { NULL, NULL }, /* Ef */ /* -symbolic, etc. */
         { need_ge1, NULL }, /* Em */          { NULL, NULL }, /* Em */
         { NULL, NULL }, /* Eo */          { NULL, NULL }, /* Eo */
         { assert_le1, NULL }, /* Fx */          { NULL, NULL }, /* Fx */
         { want_ge1, NULL }, /* Ms */          { NULL, NULL }, /* Ms */
         { NULL, NULL }, /* No */          { NULL, NULL }, /* No */
         { NULL, NULL }, /* Ns */          { NULL, NULL }, /* Ns */
         { assert_le1, NULL }, /* Nx */          { NULL, NULL }, /* Nx */
         { assert_le1, NULL }, /* Ox */          { NULL, NULL }, /* Ox */
         { NULL, NULL }, /* Pc */          { NULL, NULL }, /* Pc */
         { NULL, NULL }, /* Pf */          { NULL, NULL }, /* Pf */ /* 2 or more arguments */
         { NULL, NULL }, /* Po */          { NULL, NULL }, /* Po */
         { NULL, NULL }, /* Pq */          { NULL, NULL }, /* Pq */ /* FIXME: ignore following Sh/Ss */
         { NULL, NULL }, /* Qc */          { NULL, NULL }, /* Qc */
         { NULL, NULL }, /* Ql */          { NULL, NULL }, /* Ql */
         { NULL, NULL }, /* Qo */          { NULL, NULL }, /* Qo */
Line 138  const struct valids mdoc_valids[MDOC_MAX] = {
Line 133  const struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, NULL }, /* So */          { NULL, NULL }, /* So */
         { NULL, NULL }, /* Sq */          { NULL, NULL }, /* Sq */
         { NULL, NULL }, /* Sm */          { NULL, NULL }, /* Sm */
         { need_ge1, NULL }, /* Sx */          { NULL, NULL }, /* Sx */
         { need_ge1, NULL }, /* Sy */          { NULL, NULL }, /* Sy */
         { want_ge1, NULL }, /* Tn */          { NULL, NULL }, /* Tn */
         { assert_eq0, NULL }, /* Ux */          { NULL, NULL }, /* Ux */
         { NULL, NULL }, /* Xc */          { NULL, NULL }, /* Xc */
         { NULL, NULL }, /* Xo */          { NULL, NULL }, /* Xo */
         { NULL, NULL }, /* Fo */          { NULL, NULL }, /* Fo */
Line 150  const struct valids mdoc_valids[MDOC_MAX] = {
Line 145  const struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, NULL }, /* Oc */          { NULL, NULL }, /* Oc */
         { NULL, NULL }, /* Bk */          { NULL, NULL }, /* Bk */
         { NULL, NULL }, /* Ek */          { NULL, NULL }, /* Ek */
         { need_eq0, NULL }, /* Bt */          { NULL, NULL }, /* Bt */
         { need_eq1, NULL }, /* Hf */          { NULL, NULL }, /* Hf */
         { NULL, NULL }, /* Fr */          { NULL, NULL }, /* Fr */
         { need_eq0, NULL }, /* Ud */          { NULL, NULL }, /* Ud */
 };  };
   
   
 static int  static int
 need_le2(struct mdoc *mdoc, int tok, int pos, int sz)  post_bodychild_warn_ge1(struct mdoc *mdoc)
 {  {
         if (sz > 2)  
                 return(1);  
         return(mdoc_err(mdoc, tok, pos, ERR_ARGS_LE2));  
 }  
   
           if (MDOC_BODY != mdoc->last->type)
 static int  
 want_ge1(struct mdoc *mdoc, int tok, int pos, int sz)  
 {  
         if (sz > 0)  
                 return(1);                  return(1);
         return(mdoc_warn(mdoc, tok, pos, WARN_ARGS_GE1));          if (mdoc->last->child)
 }  
   
   
 static int  
 want_eq0(struct mdoc *mdoc, int tok, int pos, int sz)  
 {  
         if (sz == 0)  
                 return(1);                  return(1);
         return(mdoc_warn(mdoc, tok, pos, WARN_ARGS_EQ0));  
 }  
   
           return(mdoc_warn(mdoc, WARN_ARGS_GE1));
 static int  
 need_eq0(struct mdoc *mdoc, int tok, int pos, int sz)  
 {  
         if (sz == 0)  
                 return(1);  
         return(mdoc_err(mdoc, tok, pos, ERR_ARGS_EQ0));  
 }  }
   
   
 static int  static int
 assert_le1(struct mdoc *mdoc, int tok, int pos, int sz)  post_headchild_err_ge1(struct mdoc *mdoc)
 {  {
   
         assert(sz <= 1);          if (MDOC_HEAD != mdoc->last->type)
         return(1);                  return(1);
           if (mdoc->last->child)
                   return(1);
           return(mdoc_err(mdoc, ERR_ARGS_GE1));
 }  }
   
   
 static int  static int
 assert_eq0(struct mdoc *mdoc, int tok, int pos, int sz)  post_headchild_err_le8(struct mdoc *mdoc)
 {  {
           int               i;
           struct mdoc_node *n;
   
         assert(sz == 0);          if (MDOC_HEAD != mdoc->last->type)
         return(1);  
 }  
   
   
 static int  
 need_eq1(struct mdoc *mdoc, int tok, int pos, int sz)  
 {  
         if (sz == 1)  
                 return(1);                  return(1);
         return(mdoc_err(mdoc, tok, pos, ERR_ARGS_EQ1));          for (i = 0, n = mdoc->last->child; n; n = n->next, i++)
 }                  /* Do nothing. */ ;
           if (i <= 8)
   
 static int  
 need_ge1(struct mdoc *mdoc, int tok, int pos, int sz)  
 {  
         if (sz > 0)  
                 return(1);                  return(1);
         return(mdoc_err(mdoc, tok, pos, ERR_ARGS_GE1));          return(mdoc_err(mdoc, ERR_ARGS_LE8));
 }  }
   
   
 static int  static int
 v_Sh(struct mdoc *mdoc, int tok, int pos,  pre_sh(struct mdoc *mdoc, struct mdoc_node *node)
                 int sz, const char *args[],  
                 int argc, const struct mdoc_arg *argv)  
 {  {
         enum mdoc_sec    sec;  
   
         sec = mdoc_atosec((size_t)sz, args);  
         if (SEC_CUSTOM != sec && sec < mdoc->sec_lastn)  
                 if ( ! mdoc_warn(mdoc, tok, pos, WARN_SEC_OO))  
                         return(0);  
         if (SEC_BODY == mdoc->sec_last && SEC_NAME != sec)  
                 return(mdoc_err(mdoc, tok, pos, ERR_SEC_NAME));  
   
         return(1);          return(1);
 }  }
   
   
 static int  int
 v_At(struct mdoc *mdoc, int tok, int pos,  mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *node)
                 int sz, const char *args[],  
                 int argc, const struct mdoc_arg *argv)  
 {  {
         int              i;          int              t;
   
         if (0 == sz)          switch (node->type) {
           case (MDOC_BODY):
                   t = mdoc->last->data.body.tok;
                   break;
           case (MDOC_ELEM):
                   t = mdoc->last->data.elem.tok;
                   break;
           case (MDOC_BLOCK):
                   t = mdoc->last->data.block.tok;
                   break;
           case (MDOC_HEAD):
                   t = mdoc->last->data.head.tok;
                   break;
           default:
                 return(1);                  return(1);
   
         i = 0;  
         if (ATT_DEFAULT == mdoc_atoatt(args[i]))  
                 i++;  
   
         for ( ; i < sz; i++) {  
                 if ( ! mdoc_isdelim(args[i]))  
                         continue;  
                 return(mdoc_err(mdoc, tok, pos, ERR_SYNTAX_NOPUNCT));  
         }          }
         return(1);  
           if (NULL == mdoc_valids[t].pre)
                   return(1);
           return((*mdoc_valids[t].pre)(mdoc, node));
 }  }
   
   
 static int  int
 v_Bd(struct mdoc *mdoc, int tok, int pos,  mdoc_valid_post(struct mdoc *mdoc)
                 int sz, const char *args[],  
                 int argc, const struct mdoc_arg *argv)  
 {  {
         struct mdoc_node *node;          v_post          *p;
           int              t;
   
         /*          switch (mdoc->last->type) {
          * We can't be nested within any other block displays (or really          case (MDOC_BODY):
          * any other kind of display, although Bd is the only multi-line                  t = mdoc->last->data.body.tok;
          * one that will show up).  
          */  
         assert(mdoc->last);  
   
         /* LINTED */  
         for (node = mdoc->last->parent ; node; node = node->parent) {  
                 if (node->type != MDOC_BLOCK)  
                         continue;  
                 if (node->data.block.tok != MDOC_Bd)  
                         continue;  
                 break;                  break;
           case (MDOC_ELEM):
                   t = mdoc->last->data.elem.tok;
                   break;
           case (MDOC_BLOCK):
                   t = mdoc->last->data.block.tok;
                   break;
           case (MDOC_HEAD):
                   t = mdoc->last->data.head.tok;
                   break;
           default:
                   return(1);
         }          }
         if (NULL == node)  
           if (NULL == mdoc_valids[t].post)
                 return(1);                  return(1);
         return(mdoc_err(mdoc, tok, pos, ERR_SCOPE_NONEST));  
 }  
   
           for (p = mdoc_valids[t].post; *p; p++)
 int                  if ( ! (*p)(mdoc))
 mdoc_valid(struct mdoc *mdoc, int tok, int pos,  
                 int sz, const char *args[],  
                 int argc, const struct mdoc_arg *argv)  
 {  
   
         assert(tok < MDOC_MAX);  
         if (mdoc_valids[tok].sz)  
                 if ( ! (*mdoc_valids[tok].sz)(mdoc, tok, pos, sz))  
                         return(0);                          return(0);
   
         if (NULL == mdoc_valids[tok].extra)          return(1);
                 return(1);  
         return(*mdoc_valids[tok].extra)(mdoc,  
                         tok, pos, sz, args, argc, argv);  
 }  }
   

Legend:
Removed from v.1.9  
changed lines
  Added in v.1.18

CVSweb