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

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

version 1.24, 2009/01/12 10:31:53 version 1.25, 2009/01/12 12:52:21
Line 35  struct valids {
Line 35  struct valids {
 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_bd(struct mdoc *, struct mdoc_node *);
 static  int     pre_bl(struct mdoc *, struct mdoc_node *);  static  int     pre_bl(struct mdoc *, struct mdoc_node *);
   static  int     pre_it(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 *);
Line 46  static int elemchild_warn_eq0(struct mdoc *);
Line 47  static int elemchild_warn_eq0(struct mdoc *);
 static  int     bodychild_warn_ge1(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  int     post_bl(struct mdoc *);
   static  int     post_it(struct mdoc *);
   
 static  v_pre   pres_prologue[] = { pre_prologue, NULL };  static  v_pre   pres_prologue[] = { pre_prologue, NULL };
 static  v_pre   pres_d1[] = { pre_display, NULL };  static  v_pre   pres_d1[] = { pre_display, NULL };
 static  v_pre   pres_bd[] = { pre_display, pre_bd, NULL };  static  v_pre   pres_bd[] = { pre_display, pre_bd, NULL };
 static  v_pre   pres_bl[] = { pre_bl, NULL };  static  v_pre   pres_bl[] = { pre_bl, NULL };
   static  v_pre   pres_it[] = { pre_it, NULL };
 static  v_post  posts_bd[] = { headchild_err_eq0,  static  v_post  posts_bd[] = { headchild_err_eq0,
                         bodychild_warn_ge1, NULL };                          bodychild_warn_ge1, NULL };
   
Line 58  static v_post posts_sh[] = { headchild_err_ge1, 
Line 61  static v_post posts_sh[] = { headchild_err_ge1, 
                         bodychild_warn_ge1, post_sh, NULL };                          bodychild_warn_ge1, post_sh, NULL };
 static  v_post  posts_bl[] = { headchild_err_eq0,  static  v_post  posts_bl[] = { headchild_err_eq0,
                         bodychild_warn_ge1, post_bl, NULL };                          bodychild_warn_ge1, post_bl, NULL };
   static  v_post  posts_it[] = { post_it, NULL };
 static  v_post  posts_ss[] = { headchild_err_ge1, NULL };  static  v_post  posts_ss[] = { headchild_err_ge1, NULL };
 static  v_post  posts_pp[] = { elemchild_warn_eq0, NULL };  static  v_post  posts_pp[] = { elemchild_warn_eq0, NULL };
 static  v_post  posts_dd[] = { elemchild_err_ge1, NULL };  static  v_post  posts_dd[] = { elemchild_err_ge1, NULL };
Line 78  const struct valids mdoc_valids[MDOC_MAX] = {
Line 82  const struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, NULL }, /* Ed */          { NULL, NULL }, /* Ed */
         { pres_bl, posts_bl }, /* Bl */ /* FIXME: preceding Pp. */          { pres_bl, posts_bl }, /* Bl */ /* FIXME: preceding Pp. */
         { NULL, NULL }, /* El */          { NULL, NULL }, /* El */
         { NULL, NULL }, /* It */          { pres_it, posts_it }, /* It */
         { NULL, NULL }, /* Ad */          { NULL, NULL }, /* Ad */
         { NULL, NULL }, /* An */          { NULL, NULL }, /* An */
         { NULL, NULL }, /* Ar */          { NULL, NULL }, /* Ar */
Line 244  pre_display(struct mdoc *mdoc, struct mdoc_node *node)
Line 248  pre_display(struct mdoc *mdoc, struct mdoc_node *node)
   
         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->tok)
                                 break;                                  break;
         if (NULL == n)          if (NULL == n)
                 return(1);                  return(1);
Line 261  pre_bl(struct mdoc *mdoc, struct mdoc_node *node)
Line 265  pre_bl(struct mdoc *mdoc, struct mdoc_node *node)
   
         if (MDOC_BLOCK != node->type)          if (MDOC_BLOCK != node->type)
                 return(1);                  return(1);
         assert(MDOC_Bl == node->data.block.tok);          assert(MDOC_Bl == node->tok);
   
         argv = NULL;          argv = NULL;
         argc = node->data.block.argc;          argc = node->data.block.argc;
Line 316  pre_bd(struct mdoc *mdoc, struct mdoc_node *node)
Line 320  pre_bd(struct mdoc *mdoc, struct mdoc_node *node)
   
         if (MDOC_BLOCK != node->type)          if (MDOC_BLOCK != node->type)
                 return(1);                  return(1);
         assert(MDOC_Bd == node->data.block.tok);          assert(MDOC_Bd == node->tok);
   
         argv = NULL;          argv = NULL;
         argc = node->data.block.argc;          argc = node->data.block.argc;
Line 351  pre_bd(struct mdoc *mdoc, struct mdoc_node *node)
Line 355  pre_bd(struct mdoc *mdoc, struct mdoc_node *node)
   
   
 static int  static int
   pre_it(struct mdoc *mdoc, struct mdoc_node *node)
   {
   
           if (MDOC_BLOCK != mdoc->last->type)
                   return(1);
           assert(MDOC_It == mdoc->last->tok);
   
           if (MDOC_BODY != mdoc->last->parent->type)
                   return(mdoc_verr(mdoc, node, ERR_SYNTAX_PARENTBAD));
           if (MDOC_Bl != mdoc->last->parent->tok)
                   return(mdoc_verr(mdoc, node, ERR_SYNTAX_PARENTBAD));
   
           return(1);
   }
   
   
   static int
 pre_prologue(struct mdoc *mdoc, struct mdoc_node *node)  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node)
 {  {
   
Line 360  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node
Line 381  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node
   
         /* Check for ordering. */          /* Check for ordering. */
   
         switch (node->data.elem.tok) {          switch (node->tok) {
         case (MDOC_Os):          case (MDOC_Os):
                 if (mdoc->meta.title[0] && mdoc->meta.date)                  if (mdoc->meta.title[0] && mdoc->meta.date)
                         break;                          break;
Line 380  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node
Line 401  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node
   
         /* Check for repetition. */          /* Check for repetition. */
   
         switch (node->data.elem.tok) {          switch (node->tok) {
         case (MDOC_Os):          case (MDOC_Os):
                 if (0 == mdoc->meta.os[0])                  if (0 == mdoc->meta.os[0])
                         return(1);                          return(1);
Line 402  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node
Line 423  pre_prologue(struct mdoc *mdoc, struct mdoc_node *node
 }  }
   
   
   /* Warn if `Bl' type-specific syntax isn't reflected in items. */
 static int  static int
   post_it(struct mdoc *mdoc)
   {
           int               type, sv;
   #define TYPE_NONE        (0)
   #define TYPE_BODY        (1)
   #define TYPE_HEAD        (2)
           size_t            i, argc;
           struct mdoc_node *n;
   
           if (MDOC_BLOCK != mdoc->last->type)
                   return(1);
   
           assert(MDOC_It == mdoc->last->tok);
   
           n = mdoc->last->parent;
           assert(n);
           assert(MDOC_Bl == n->tok);
   
           n = n->parent;
           assert(MDOC_BLOCK == n->type);
           assert(MDOC_Bl == n->tok);
   
           argc = n->data.block.argc;
           type = TYPE_NONE;
   
           for (i = 0; TYPE_NONE == type && i < argc; i++)
                   switch (n->data.block.argv[(int)i].arg) {
                   case (MDOC_Tag):
                           /* FALLTHROUGH */
                   case (MDOC_Diag):
                           /* FALLTHROUGH */
                   case (MDOC_Hang):
                           /* FALLTHROUGH */
                   case (MDOC_Ohang):
                           /* FALLTHROUGH */
                   case (MDOC_Inset):
                           type = TYPE_HEAD;
                           sv = n->data.block.argv[(int)i].arg;
                           break;
                   case (MDOC_Bullet):
                           /* FALLTHROUGH */
                   case (MDOC_Dash):
                           /* FALLTHROUGH */
                   case (MDOC_Enum):
                           /* FALLTHROUGH */
                   case (MDOC_Hyphen):
                           /* FALLTHROUGH */
                   case (MDOC_Item):
                           /* FALLTHROUGH */
                   case (MDOC_Column):
                           type = TYPE_BODY;
                           sv = n->data.block.argv[(int)i].arg;
                           break;
                   default:
                           break;
                   }
   
           assert(TYPE_NONE != type);
   
           if (TYPE_HEAD == type) {
                   if (NULL == (n = mdoc->last->data.block.head)) {
                           if ( ! mdoc_warn(mdoc, WARN_SYNTAX_EMPTYHEAD))
                                   return(0);
                   } else if (NULL == n->child)
                           if ( ! mdoc_warn(mdoc, WARN_SYNTAX_EMPTYHEAD))
                                   return(0);
   
                   if (NULL == (n = mdoc->last->data.block.body)) {
                           if ( ! mdoc_warn(mdoc, WARN_SYNTAX_EMPTYBODY))
                                   return(0);
                   } else if (NULL == n->child)
                           if ( ! mdoc_warn(mdoc, WARN_SYNTAX_EMPTYBODY))
                                   return(0);
   
                   return(1);
           }
   
           if (NULL == (n = mdoc->last->data.block.head)) {
                   if ( ! mdoc_warn(mdoc, WARN_SYNTAX_EMPTYHEAD))
                           return(0);
           } else if (NULL == n->child)
                   if ( ! mdoc_warn(mdoc, WARN_SYNTAX_EMPTYHEAD))
                           return(0);
   
           if ((n = mdoc->last->data.block.body) && n->child)
                   if ( ! mdoc_warn(mdoc, WARN_SYNTAX_NOBODY))
                           return(0);
   
           /* TODO: make sure columns are aligned. */
           assert(MDOC_Column != sv);
   
           return(1);
   
   #undef  TYPE_NONE
   #undef  TYPE_BODY
   #undef  TYPE_HEAD
   }
   
   
   /* Make sure that only `It' macros are our body-children. */
   static int
 post_bl(struct mdoc *mdoc)  post_bl(struct mdoc *mdoc)
 {  {
         struct mdoc_node *n;          struct mdoc_node *n;
   
         if (MDOC_BODY != mdoc->last->type)          if (MDOC_BODY != mdoc->last->type)
                 return(1);                  return(1);
         assert(MDOC_Bl == mdoc->last->data.body.tok);          assert(MDOC_Bl == mdoc->last->tok);
   
         for (n = mdoc->last->child; n; n = n->next) {          for (n = mdoc->last->child; n; n = n->next) {
                 if (MDOC_BLOCK == n->type)                  if (MDOC_BLOCK == n->type)
                         if (MDOC_It == n->data.block.tok)                          if (MDOC_It == n->tok)
                                 continue;                                  continue;
                 break;                  break;
         }          }
Line 423  post_bl(struct mdoc *mdoc)
Line 546  post_bl(struct mdoc *mdoc)
 }  }
   
   
 /*  /* Warn if conventional sections are out of order. */
  * Warn if sections (those that are with a known title, such as NAME,  
  * DESCRIPTION, and so forth) are out of the conventional order.  
  */  
 static int  static int
 post_sh(struct mdoc *mdoc)  post_sh(struct mdoc *mdoc)
 {  {
Line 438  post_sh(struct mdoc *mdoc)
Line 558  post_sh(struct mdoc *mdoc)
         if (MDOC_HEAD != mdoc->last->type)          if (MDOC_HEAD != mdoc->last->type)
                 return(1);                  return(1);
   
         assert(MDOC_Sh == mdoc->last->data.head.tok);          assert(MDOC_Sh == mdoc->last->tok);
   
         n = mdoc->last->child;          n = mdoc->last->child;
         assert(n);          assert(n);
Line 466  int
Line 586  int
 mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *node)  mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *node)
 {  {
         v_pre           *p;          v_pre           *p;
         int              t;  
   
         switch (node->type) {          /* TODO: character-escape checks. */
         case (MDOC_BODY):  
                 t = node->data.body.tok;          if (MDOC_TEXT == node->type)
                 break;  
         case (MDOC_ELEM):  
                 t = node->data.elem.tok;  
                 break;  
         case (MDOC_BLOCK):  
                 t = node->data.block.tok;  
                 break;  
         case (MDOC_HEAD):  
                 t = node->data.head.tok;  
                 break;  
         default:  
                 return(1);                  return(1);
         }          assert(MDOC_ROOT != node->type);
   
         if (NULL == mdoc_valids[t].pre)          if (NULL == mdoc_valids[node->tok].pre)
                 return(1);                  return(1);
         for (p = mdoc_valids[t].pre; *p; p++)          for (p = mdoc_valids[node->tok].pre; *p; p++)
                 if ( ! (*p)(mdoc, node))                  if ( ! (*p)(mdoc, node))
                         return(0);                          return(0);
         return(1);          return(1);
Line 498  int
Line 606  int
 mdoc_valid_post(struct mdoc *mdoc)  mdoc_valid_post(struct mdoc *mdoc)
 {  {
         v_post          *p;          v_post          *p;
         int              t;  
   
         switch (mdoc->last->type) {          if (MDOC_TEXT == mdoc->last->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);
         }          if (MDOC_ROOT == mdoc->last->type)
                   return(1);
   
         if (NULL == mdoc_valids[t].post)          if (NULL == mdoc_valids[mdoc->last->tok].post)
                 return(1);                  return(1);
         for (p = mdoc_valids[t].post; *p; p++)          for (p = mdoc_valids[mdoc->last->tok].post; *p; p++)
                 if ( ! (*p)(mdoc))                  if ( ! (*p)(mdoc))
                         return(0);                          return(0);
   

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

CVSweb