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

Diff for /mandoc/Attic/validate.c between version 1.53 and 1.54

version 1.53, 2009/02/23 22:51:10 version 1.54, 2009/02/24 11:43:13
Line 35  typedef int (*v_post)(struct mdoc *);
Line 35  typedef int (*v_post)(struct mdoc *);
 /* FIXME: some sections should only occur in specific msecs. */  /* FIXME: some sections should only occur in specific msecs. */
 /* FIXME: ignoring Pp. */  /* FIXME: ignoring Pp. */
 /* FIXME: math symbols. */  /* FIXME: math symbols. */
 /* FIXME: valid character-escape checks. */  
 /* FIXME: .Fd only in synopsis section. */  /* FIXME: .Fd only in synopsis section. */
   
 struct  valids {  struct  valids {
Line 109  static int post_xr(struct mdoc *);
Line 108  static int post_xr(struct mdoc *);
 static  int     post_nm(struct mdoc *);  static  int     post_nm(struct mdoc *);
 static  int     post_bf(struct mdoc *);  static  int     post_bf(struct mdoc *);
 static  int     post_root(struct mdoc *);  static  int     post_root(struct mdoc *);
   static  int     pre_text(struct mdoc *, const struct mdoc_node *);
   
 /* Collections of pre-child-parse routines. */  /* Collections of pre-child-parse routines. */
   
Line 386  check_msec(struct mdoc *mdoc, struct mdoc_node *node, 
Line 386  check_msec(struct mdoc *mdoc, struct mdoc_node *node, 
   
   
 static int  static int
   check_parent(struct mdoc *mdoc, struct mdoc_node *n,
                   int tok, enum mdoc_type t)
   {
   
           assert(n->parent);
           if ((MDOC_ROOT == t || tok == n->parent->tok) &&
                           (t == n->parent->type))
                   return(1);
   
           return(mdoc_nerr(mdoc, n, "require parent %s",
                   MDOC_ROOT == t ? "<root>" : mdoc_macronames[tok]));
   }
   
   
   
   static int
 pre_display(struct mdoc *mdoc, struct mdoc_node *node)  pre_display(struct mdoc *mdoc, struct mdoc_node *node)
 {  {
         struct mdoc_node *n;          struct mdoc_node *n;
Line 922  ebool(struct mdoc *mdoc)
Line 938  ebool(struct mdoc *mdoc)
   
   
 static int  static int
   pre_text(struct mdoc *mdoc, const struct mdoc_node *n)
   {
           size_t           c;
           const char      *p;
   
           for (p = n->data.text.string; *p; p++) {
                   if ('\\' != *p)
                           continue;
                   if ((c = mdoc_isescape(p))) {
                           p += (c - 1);
                           continue;
                   }
                   return(mdoc_nerr(mdoc, n, "bad escape sequence"));
           }
   
           return(1);
   }
   
   
   static int
 post_root(struct mdoc *mdoc)  post_root(struct mdoc *mdoc)
 {  {
   
Line 931  post_root(struct mdoc *mdoc)
Line 967  post_root(struct mdoc *mdoc)
                 return(mdoc_err(mdoc, "document lacks prologue"));                  return(mdoc_err(mdoc, "document lacks prologue"));
   
         if (MDOC_BLOCK != mdoc->first->child->type)          if (MDOC_BLOCK != mdoc->first->child->type)
                 return(mdoc_err(mdoc, "lacking post-prologue `%s'",                  return(mdoc_err(mdoc, "lacking post-prologue %s",
                                         mdoc_macronames[MDOC_Sh]));                                          mdoc_macronames[MDOC_Sh]));
         if (MDOC_Sh != mdoc->first->child->tok)          if (MDOC_Sh != mdoc->first->child->tok)
                 return(mdoc_err(mdoc, "lacking post-prologue `%s'",                  return(mdoc_err(mdoc, "lacking post-prologue %s",
                                         mdoc_macronames[MDOC_Sh]));                                          mdoc_macronames[MDOC_Sh]));
   
         return(1);          return(1);
Line 969  post_sh_body(struct mdoc *mdoc)
Line 1005  post_sh_body(struct mdoc *mdoc)
          */           */
   
         if (NULL == (n = mdoc->last->child))          if (NULL == (n = mdoc->last->child))
                 return(mdoc_warn(mdoc, WARN_COMPAT, "section NAME "                  return(mdoc_warn(mdoc, WARN_SYNTAX,
                                         "should contain %s and %s",                                          "section should have %s and %s",
                                         mdoc_macronames[MDOC_Nm],                                          mdoc_macronames[MDOC_Nm],
                                         mdoc_macronames[MDOC_Nd]));                                          mdoc_macronames[MDOC_Nd]));
   
Line 979  post_sh_body(struct mdoc *mdoc)
Line 1015  post_sh_body(struct mdoc *mdoc)
                         continue;                          continue;
                 if (MDOC_TEXT == n->type)                  if (MDOC_TEXT == n->type)
                         continue;                          continue;
                 if ( ! (mdoc_nwarn(mdoc, n, WARN_COMPAT, "section "                  if ( ! (mdoc_nwarn(mdoc, n, WARN_SYNTAX,
                                         "NAME should contain %s as "                                          "section should have %s first",
                                         "initial body child",  
                                         mdoc_macronames[MDOC_Nm])))                                          mdoc_macronames[MDOC_Nm])))
                         return(0);                          return(0);
         }          }
Line 989  post_sh_body(struct mdoc *mdoc)
Line 1024  post_sh_body(struct mdoc *mdoc)
         if (MDOC_ELEM == n->type && MDOC_Nd == n->tok)          if (MDOC_ELEM == n->type && MDOC_Nd == n->tok)
                 return(1);                  return(1);
   
         return(mdoc_warn(mdoc, WARN_COMPAT, "section NAME should "          return(mdoc_warn(mdoc, WARN_SYNTAX,
                                 "contain %s as the last child",                                  "section should have %s last",
                                 mdoc_macronames[MDOC_Nd]));                                  mdoc_macronames[MDOC_Nd]));
 }  }
   
Line 1003  post_sh_head(struct mdoc *mdoc)
Line 1038  post_sh_head(struct mdoc *mdoc)
   
         assert(MDOC_Sh == mdoc->last->tok);          assert(MDOC_Sh == mdoc->last->tok);
   
         if ( ! xstrlcats(buf, mdoc->last->child, 64))          if ( ! xstrlcats(buf, mdoc->last->child, sizeof(buf)))
                 return(mdoc_err(mdoc, "macro parameters too long"));                  return(mdoc_err(mdoc, "argument too long"));
   
         sec = mdoc_atosec(buf);          sec = mdoc_atosec(buf);
   
         if (SEC_BODY == mdoc->lastnamed && SEC_NAME != sec)          if (SEC_BODY == mdoc->lastnamed && SEC_NAME != sec)
                 return(mdoc_err(mdoc, "section NAME must be first"));                  return(mdoc_warn(mdoc, WARN_SYNTAX,
                                   "section NAME should be first"));
         if (SEC_CUSTOM == sec)          if (SEC_CUSTOM == sec)
                 return(1);                  return(1);
         if (sec == mdoc->lastnamed)          if (sec == mdoc->lastnamed)
                 return(mdoc_warn(mdoc, WARN_SYNTAX, "section repeated"));                  return(mdoc_warn(mdoc, WARN_SYNTAX,
                                   "section repeated"));
         if (sec < mdoc->lastnamed)          if (sec < mdoc->lastnamed)
                 return(mdoc_warn(mdoc, WARN_SYNTAX, "section out of conventional order"));                  return(mdoc_warn(mdoc, WARN_SYNTAX,
                                   "section out of order"));
   
         return(1);          return(1);
 }  }
Line 1027  mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *no
Line 1065  mdoc_valid_pre(struct mdoc *mdoc, struct mdoc_node *no
         v_pre           *p;          v_pre           *p;
   
         if (MDOC_TEXT == node->type)          if (MDOC_TEXT == node->type)
                 return(1);                  return(pre_text(mdoc, node));
         assert(MDOC_ROOT != node->type);          assert(MDOC_ROOT != node->type);
   
         if (NULL == mdoc_valids[node->tok].pre)          if (NULL == mdoc_valids[node->tok].pre)
Line 1043  int
Line 1081  int
 mdoc_valid_post(struct mdoc *mdoc)  mdoc_valid_post(struct mdoc *mdoc)
 {  {
         v_post          *p;          v_post          *p;
   
           /*
            * This check occurs after the macro's children have been filled
            * in: postfix validation.  Since this happens when we're
            * rewinding the scope tree, it's possible to have multiple
            * invocations (as by design, for now), we set bit MDOC_VALID to
            * indicate that we've validated.
            */
   
         if (MDOC_VALID & mdoc->last->flags)          if (MDOC_VALID & mdoc->last->flags)
                 return(1);                  return(1);

Legend:
Removed from v.1.53  
changed lines
  Added in v.1.54

CVSweb