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

Diff for /mandoc/Attic/validate.c between version 1.23 and 1.24

version 1.23, 2009/01/09 15:15:31 version 1.24, 2009/01/12 10:31:53
Line 27  typedef int (*v_post)(struct mdoc *);
Line 27  typedef int (*v_post)(struct mdoc *);
   
   
 struct  valids {  struct  valids {
         v_pre    pre;          v_pre   *pre;
         v_post  *post;          v_post  *post;
 };  };
   
   
 static  int     pre_display(struct mdoc *, struct mdoc_node *);  static  int     pre_display(struct mdoc *, struct mdoc_node *);
   static  int     pre_bd(struct mdoc *, struct mdoc_node *);
   static  int     pre_bl(struct mdoc *, struct mdoc_node *);
 static  int     pre_prologue(struct mdoc *, struct mdoc_node *);  static  int     pre_prologue(struct mdoc *, struct mdoc_node *);
 static  int     pre_prologue(struct mdoc *, struct mdoc_node *);  static  int     pre_prologue(struct mdoc *, struct mdoc_node *);
 static  int     pre_prologue(struct mdoc *, struct mdoc_node *);  static  int     pre_prologue(struct mdoc *, struct mdoc_node *);
 static  int     post_headchild_err_ge1(struct mdoc *);  
 static  int     post_elemchild_err_ge1(struct mdoc *);  static  int     headchild_err_ge1(struct mdoc *);
 static  int     post_elemchild_warn_eq0(struct mdoc *);  static  int     headchild_err_eq0(struct mdoc *);
 static  int     post_bodychild_warn_ge1(struct mdoc *);  static  int     elemchild_err_ge1(struct mdoc *);
   static  int     elemchild_warn_eq0(struct mdoc *);
   static  int     bodychild_warn_ge1(struct mdoc *);
 static  int     post_sh(struct mdoc *);  static  int     post_sh(struct mdoc *);
   static  int     post_bl(struct mdoc *);
   
 static  v_post  posts_sh[] = { post_headchild_err_ge1,  static  v_pre   pres_prologue[] = { pre_prologue, NULL };
                         post_bodychild_warn_ge1, post_sh, NULL };  static  v_pre   pres_d1[] = { pre_display, NULL };
 static  v_post  posts_ss[] = { post_headchild_err_ge1, NULL };  static  v_pre   pres_bd[] = { pre_display, pre_bd, NULL };
 static  v_post  posts_pp[] = { post_elemchild_warn_eq0, NULL };  static  v_pre   pres_bl[] = { pre_bl, NULL };
 static  v_post  posts_dd[] = { post_elemchild_err_ge1, NULL };  static  v_post  posts_bd[] = { headchild_err_eq0,
 static  v_post  posts_display[] = { post_headchild_err_ge1, NULL };                          bodychild_warn_ge1, NULL };
   
   static  v_post  posts_sh[] = { headchild_err_ge1,
                           bodychild_warn_ge1, post_sh, NULL };
   static  v_post  posts_bl[] = { headchild_err_eq0,
                           bodychild_warn_ge1, post_bl, NULL };
   static  v_post  posts_ss[] = { headchild_err_ge1, NULL };
   static  v_post  posts_pp[] = { elemchild_warn_eq0, NULL };
   static  v_post  posts_dd[] = { elemchild_err_ge1, NULL };
   static  v_post  posts_d1[] = { headchild_err_ge1, NULL };
   
   
 const   struct valids mdoc_valids[MDOC_MAX] = {  const   struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, NULL }, /* \" */          { NULL, NULL }, /* \" */
         { pre_prologue, posts_dd }, /* Dd */          { pres_prologue, posts_dd }, /* Dd */
         { pre_prologue, NULL }, /* Dt */          { pres_prologue, NULL }, /* Dt */
         { pre_prologue, NULL }, /* Os */          { pres_prologue, NULL }, /* Os */
         { NULL, posts_sh }, /* Sh */ /* FIXME: preceding Pp. */          { NULL, posts_sh }, /* Sh */ /* FIXME: preceding Pp. */
         { NULL, posts_ss }, /* Ss */ /* FIXME: preceding Pp. */          { NULL, posts_ss }, /* Ss */ /* FIXME: preceding Pp. */
         { NULL, posts_pp }, /* Pp */ /* FIXME: proceeding... */          { NULL, posts_pp }, /* Pp */ /* FIXME: proceeding... */
         { pre_display, posts_display }, /* D1 */          { pres_d1, posts_d1 }, /* D1 */
         { pre_display, posts_display }, /* Dl */          { pres_d1, posts_d1 }, /* Dl */
         { pre_display, NULL }, /* Bd */ /* FIXME: preceding Pp. */          { pres_bd, posts_bd }, /* Bd */ /* FIXME: preceding Pp. */
         { NULL, NULL }, /* Ed */          { NULL, NULL }, /* Ed */
         { NULL, NULL }, /* Bl */ /* FIXME: preceding Pp. */          { pres_bl, posts_bl }, /* Bl */ /* FIXME: preceding Pp. */
         { NULL, NULL }, /* El */          { NULL, NULL }, /* El */
         { NULL, NULL }, /* It */          { NULL, NULL }, /* It */
         { NULL, NULL }, /* Ad */          { NULL, NULL }, /* Ad */
Line 161  const struct valids mdoc_valids[MDOC_MAX] = {
Line 175  const struct valids mdoc_valids[MDOC_MAX] = {
   
   
 static int  static int
 post_bodychild_warn_ge1(struct mdoc *mdoc)  bodychild_warn_ge1(struct mdoc *mdoc)
 {  {
   
         if (MDOC_BODY != mdoc->last->type)          if (MDOC_BODY != mdoc->last->type)
                 return(1);                  return(1);
         if (mdoc->last->child)          if (mdoc->last->child)
                 return(1);                  return(1);
   
         return(mdoc_warn(mdoc, WARN_ARGS_GE1));          return(mdoc_warn(mdoc, WARN_ARGS_GE1));
 }  }
   
   
 static int  static int
 post_elemchild_warn_eq0(struct mdoc *mdoc)  elemchild_warn_eq0(struct mdoc *mdoc)
 {  {
   
         assert(MDOC_ELEM == mdoc->last->type);          assert(MDOC_ELEM == mdoc->last->type);
         if (NULL == mdoc->last->child)          if (NULL == mdoc->last->child)
                 return(1);                  return(1);
         return(mdoc_warn(mdoc, WARN_ARGS_EQ0));          return(mdoc_pwarn(mdoc, mdoc->last->child->line,
                           mdoc->last->child->pos, WARN_ARGS_EQ0));
 }  }
   
   
 static int  static int
 post_elemchild_err_ge1(struct mdoc *mdoc)  elemchild_err_ge1(struct mdoc *mdoc)
 {  {
   
         assert(MDOC_ELEM == mdoc->last->type);          assert(MDOC_ELEM == mdoc->last->type);
Line 196  post_elemchild_err_ge1(struct mdoc *mdoc)
Line 210  post_elemchild_err_ge1(struct mdoc *mdoc)
   
   
 static int  static int
 post_headchild_err_ge1(struct mdoc *mdoc)  headchild_err_eq0(struct mdoc *mdoc)
 {  {
   
         if (MDOC_HEAD != mdoc->last->type)          if (MDOC_HEAD != mdoc->last->type)
                 return(1);                  return(1);
           if (NULL == mdoc->last->child)
                   return(1);
           return(mdoc_perr(mdoc, mdoc->last->child->line,
                           mdoc->last->child->pos, ERR_ARGS_EQ0));
   }
   
   
   static int
   headchild_err_ge1(struct mdoc *mdoc)
   {
   
           if (MDOC_HEAD != mdoc->last->type)
                   return(1);
         if (mdoc->last->child)          if (mdoc->last->child)
                 return(1);                  return(1);
         return(mdoc_err(mdoc, ERR_ARGS_GE1));          return(mdoc_err(mdoc, ERR_ARGS_GE1));
Line 212  pre_display(struct mdoc *mdoc, struct mdoc_node *node)
Line 239  pre_display(struct mdoc *mdoc, struct mdoc_node *node)
 {  {
         struct mdoc_node *n;          struct mdoc_node *n;
   
           if (MDOC_BLOCK != node->type)
                   return(1);
   
         for (n = mdoc->last; n; n = n->parent)          for (n = mdoc->last; n; n = n->parent)
                 if (MDOC_BLOCK == n->type)                  if (MDOC_BLOCK == n->type)
                         if (MDOC_Bd == n->data.block.tok)                          if (MDOC_Bd == n->data.block.tok)
Line 223  pre_display(struct mdoc *mdoc, struct mdoc_node *node)
Line 253  pre_display(struct mdoc *mdoc, struct mdoc_node *node)
   
   
 static int  static int
   pre_bl(struct mdoc *mdoc, struct mdoc_node *node)
   {
           int              type, err;
           struct mdoc_arg *argv;
           size_t           i, argc;
   
           if (MDOC_BLOCK != node->type)
                   return(1);
           assert(MDOC_Bl == node->data.block.tok);
   
           argv = NULL;
           argc = node->data.block.argc;
   
           for (i = type = err = 0; i < argc; i++) {
                   argv = &node->data.block.argv[(int)i];
                   assert(argv);
                   switch (argv->arg) {
                   case (MDOC_Bullet):
                           /* FALLTHROUGH */
                   case (MDOC_Dash):
                           /* FALLTHROUGH */
                   case (MDOC_Enum):
                           /* FALLTHROUGH */
                   case (MDOC_Hyphen):
                           /* FALLTHROUGH */
                   case (MDOC_Item):
                           /* FALLTHROUGH */
                   case (MDOC_Tag):
                           /* FALLTHROUGH */
                   case (MDOC_Diag):
                           /* FALLTHROUGH */
                   case (MDOC_Hang):
                           /* FALLTHROUGH */
                   case (MDOC_Ohang):
                           /* FALLTHROUGH */
                   case (MDOC_Inset):
                           if (type)
                                   err++;
                           type++;
                           break;
                   default:
                           break;
                   }
           }
           if (0 == type)
                   return(mdoc_err(mdoc, ERR_SYNTAX_ARGMISS));
           if (0 == err)
                   return(1);
           assert(argv);
           return(mdoc_perr(mdoc, argv->line,
                           argv->pos, ERR_SYNTAX_ARGBAD));
   }
   
   
   static int
   pre_bd(struct mdoc *mdoc, struct mdoc_node *node)
   {
           int              type, err;
           struct mdoc_arg *argv;
           size_t           i, argc;
   
           if (MDOC_BLOCK != node->type)
                   return(1);
           assert(MDOC_Bd == node->data.block.tok);
   
           argv = NULL;
           argc = node->data.block.argc;
   
           for (err = i = type = 0; 0 == err && i < argc; i++) {
                   argv = &node->data.block.argv[(int)i];
                   assert(argv);
                   switch (argv->arg) {
                   case (MDOC_Ragged):
                           /* FALLTHROUGH */
                   case (MDOC_Unfilled):
                           /* FALLTHROUGH */
                   case (MDOC_Literal):
                           /* FALLTHROUGH */
                   case (MDOC_File):
                           if (type)
                                   err++;
                           type++;
                           break;
                   default:
                           break;
                   }
           }
           if (0 == type)
                   return(mdoc_err(mdoc, ERR_SYNTAX_ARGMISS));
           if (0 == err)
                   return(1);
           assert(argv);
           return(mdoc_perr(mdoc, argv->line,
                           argv->pos, ERR_SYNTAX_ARGBAD));
   }
   
   
   static int
 pre_prologue(struct mdoc *mdoc, struct mdoc_node *node)  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node)
 {  {
   
Line 274  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node
Line 402  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node
 }  }
   
   
   static int
   post_bl(struct mdoc *mdoc)
   {
           struct mdoc_node *n;
   
           if (MDOC_BODY != mdoc->last->type)
                   return(1);
           assert(MDOC_Bl == mdoc->last->data.body.tok);
   
           for (n = mdoc->last->child; n; n = n->next) {
                   if (MDOC_BLOCK == n->type)
                           if (MDOC_It == n->data.block.tok)
                                   continue;
                   break;
           }
           if (NULL == n)
                   return(1);
           return(mdoc_verr(mdoc, n, ERR_SYNTAX_CHILDBAD));
   }
   
   
 /*  /*
  * Warn if sections (those that are with a known title, such as NAME,   * Warn if sections (those that are with a known title, such as NAME,
  * DESCRIPTION, and so forth) are out of the conventional order.   * DESCRIPTION, and so forth) are out of the conventional order.
Line 316  post_sh(struct mdoc *mdoc)
Line 465  post_sh(struct mdoc *mdoc)
 int  int
 mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *node)  mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *node)
 {  {
           v_pre           *p;
         int              t;          int              t;
   
         switch (node->type) {          switch (node->type) {
Line 337  mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *no
Line 487  mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *no
   
         if (NULL == mdoc_valids[t].pre)          if (NULL == mdoc_valids[t].pre)
                 return(1);                  return(1);
         return((*mdoc_valids[t].pre)(mdoc, node));          for (p = mdoc_valids[t].pre; *p; p++)
                   if ( ! (*p)(mdoc, node))
                           return(0);
           return(1);
 }  }
   
   
Line 366  mdoc_valid_post(struct mdoc *mdoc)
Line 519  mdoc_valid_post(struct mdoc *mdoc)
   
         if (NULL == mdoc_valids[t].post)          if (NULL == mdoc_valids[t].post)
                 return(1);                  return(1);
   
         for (p = mdoc_valids[t].post; *p; p++)          for (p = mdoc_valids[t].post; *p; p++)
                 if ( ! (*p)(mdoc))                  if ( ! (*p)(mdoc))
                         return(0);                          return(0);

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.24

CVSweb