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

Diff for /mandoc/man_validate.c between version 1.106 and 1.107

version 1.106, 2014/08/10 23:54:41 version 1.107, 2014/11/28 05:51:32
Line 1 
Line 1 
 /*      $Id$ */  /*      $OpenBSD$ */
 /*  /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
Line 36 
Line 36 
   
 #define CHKARGS   struct man *man, struct man_node *n  #define CHKARGS   struct man *man, struct man_node *n
   
 typedef int     (*v_check)(CHKARGS);  typedef void    (*v_check)(CHKARGS);
   
 static  int       check_eq0(CHKARGS);  static  void      check_eq0(CHKARGS);
 static  int       check_eq2(CHKARGS);  static  void      check_eq2(CHKARGS);
 static  int       check_le1(CHKARGS);  static  void      check_le1(CHKARGS);
 static  int       check_le5(CHKARGS);  static  void      check_le5(CHKARGS);
 static  int       check_par(CHKARGS);  static  void      check_par(CHKARGS);
 static  int       check_part(CHKARGS);  static  void      check_part(CHKARGS);
 static  int       check_root(CHKARGS);  static  void      check_root(CHKARGS);
 static  int       check_text(CHKARGS);  static  void      check_text(CHKARGS);
   
 static  int       post_AT(CHKARGS);  static  void      post_AT(CHKARGS);
 static  int       post_IP(CHKARGS);  static  void      post_IP(CHKARGS);
 static  int       post_vs(CHKARGS);  static  void      post_vs(CHKARGS);
 static  int       post_fi(CHKARGS);  static  void      post_fi(CHKARGS);
 static  int       post_ft(CHKARGS);  static  void      post_ft(CHKARGS);
 static  int       post_nf(CHKARGS);  static  void      post_nf(CHKARGS);
 static  int       post_TH(CHKARGS);  static  void      post_TH(CHKARGS);
 static  int       post_UC(CHKARGS);  static  void      post_UC(CHKARGS);
 static  int       post_UR(CHKARGS);  static  void      post_UR(CHKARGS);
   
 static  v_check man_valids[MAN_MAX] = {  static  v_check man_valids[MAN_MAX] = {
         post_vs,    /* br */          post_vs,    /* br */
Line 100  static v_check man_valids[MAN_MAX] = {
Line 100  static v_check man_valids[MAN_MAX] = {
 };  };
   
   
 int  void
 man_valid_post(struct man *man)  man_valid_post(struct man *man)
 {  {
         struct man_node *n;          struct man_node *n;
Line 108  man_valid_post(struct man *man)
Line 108  man_valid_post(struct man *man)
   
         n = man->last;          n = man->last;
         if (n->flags & MAN_VALID)          if (n->flags & MAN_VALID)
                 return(1);                  return;
         n->flags |= MAN_VALID;          n->flags |= MAN_VALID;
   
         switch (n->type) {          switch (n->type) {
         case MAN_TEXT:          case MAN_TEXT:
                 return(check_text(man, n));                  check_text(man, n);
                   break;
         case MAN_ROOT:          case MAN_ROOT:
                 return(check_root(man, n));                  check_root(man, n);
                   break;
         case MAN_EQN:          case MAN_EQN:
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case MAN_TBL:          case MAN_TBL:
                 return(1);                  break;
         default:          default:
                 cp = man_valids + n->tok;                  cp = man_valids + n->tok;
                 return(*cp ? (*cp)(man, n) : 1);                  if (*cp)
                           (*cp)(man, n);
                   break;
         }          }
 }  }
   
 static int  static void
 check_root(CHKARGS)  check_root(CHKARGS)
 {  {
   
Line 152  check_root(CHKARGS)
Line 156  check_root(CHKARGS)
                 man->meta.date = man->quick ? mandoc_strdup("") :                  man->meta.date = man->quick ? mandoc_strdup("") :
                     mandoc_normdate(man->parse, NULL, n->line, n->pos);                      mandoc_normdate(man->parse, NULL, n->line, n->pos);
         }          }
   
         return(1);  
 }  }
   
 static int  static void
 check_text(CHKARGS)  check_text(CHKARGS)
 {  {
         char            *cp, *p;          char            *cp, *p;
   
         if (MAN_LITERAL & man->flags)          if (MAN_LITERAL & man->flags)
                 return(1);                  return;
   
         cp = n->string;          cp = n->string;
         for (p = cp; NULL != (p = strchr(p, '\t')); p++)          for (p = cp; NULL != (p = strchr(p, '\t')); p++)
                 mandoc_msg(MANDOCERR_FI_TAB, man->parse,                  mandoc_msg(MANDOCERR_FI_TAB, man->parse,
                     n->line, n->pos + (p - cp), NULL);                      n->line, n->pos + (p - cp), NULL);
         return(1);  
 }  }
   
 #define INEQ_DEFINE(x, ineq, name) \  #define INEQ_DEFINE(x, ineq, name) \
 static int \  static void \
 check_##name(CHKARGS) \  check_##name(CHKARGS) \
 { \  { \
         if (n->nchild ineq (x)) \          if (n->nchild ineq (x)) \
                 return(1); \                  return; \
         mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, n->pos, \          mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line, n->pos, \
             "line arguments %s %d (have %d)", \              "line arguments %s %d (have %d)", \
             #ineq, (x), n->nchild); \              #ineq, (x), n->nchild); \
         return(1); \  
 }  }
   
 INEQ_DEFINE(0, ==, eq0)  INEQ_DEFINE(0, ==, eq0)
Line 188  INEQ_DEFINE(2, ==, eq2)
Line 188  INEQ_DEFINE(2, ==, eq2)
 INEQ_DEFINE(1, <=, le1)  INEQ_DEFINE(1, <=, le1)
 INEQ_DEFINE(5, <=, le5)  INEQ_DEFINE(5, <=, le5)
   
 static int  static void
 post_UR(CHKARGS)  post_UR(CHKARGS)
 {  {
   
         if (MAN_HEAD == n->type && 1 != n->nchild)          if (MAN_HEAD == n->type && 1 != n->nchild)
                 mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line,                  mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line,
                     n->pos, "line arguments eq 1 (have %d)", n->nchild);                      n->pos, "line arguments eq 1 (have %d)", n->nchild);
           check_part(man, n);
         return(check_part(man, n));  
 }  }
   
 static int  static void
 post_ft(CHKARGS)  post_ft(CHKARGS)
 {  {
         char    *cp;          char    *cp;
         int      ok;          int      ok;
   
         if (0 == n->nchild)          if (0 == n->nchild)
                 return(1);                  return;
   
         ok = 0;          ok = 0;
         cp = n->child->string;          cp = n->child->string;
Line 248  post_ft(CHKARGS)
Line 247  post_ft(CHKARGS)
         if (1 < n->nchild)          if (1 < n->nchild)
                 mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line,                  mandoc_vmsg(MANDOCERR_ARGCOUNT, man->parse, n->line,
                     n->pos, "want one child (have %d)", n->nchild);                      n->pos, "want one child (have %d)", n->nchild);
   
         return(1);  
 }  }
   
 static int  static void
 check_part(CHKARGS)  check_part(CHKARGS)
 {  {
   
         if (MAN_BODY == n->type && 0 == n->nchild)          if (MAN_BODY == n->type && 0 == n->nchild)
                 mandoc_msg(MANDOCERR_ARGCWARN, man->parse, n->line,                  mandoc_msg(MANDOCERR_ARGCWARN, man->parse, n->line,
                     n->pos, "want children (have none)");                      n->pos, "want children (have none)");
   
         return(1);  
 }  }
   
 static int  static void
 check_par(CHKARGS)  check_par(CHKARGS)
 {  {
   
Line 289  check_par(CHKARGS)
Line 284  check_par(CHKARGS)
         default:          default:
                 break;                  break;
         }          }
   
         return(1);  
 }  }
   
 static int  static void
 post_IP(CHKARGS)  post_IP(CHKARGS)
 {  {
   
Line 311  post_IP(CHKARGS)
Line 304  post_IP(CHKARGS)
         default:          default:
                 break;                  break;
         }          }
         return(1);  
 }  }
   
 static int  static void
 post_TH(CHKARGS)  post_TH(CHKARGS)
 {  {
         struct man_node *nb;          struct man_node *nb;
Line 402  post_TH(CHKARGS)
Line 394  post_TH(CHKARGS)
          * meta-data.           * meta-data.
          */           */
         man_node_delete(man, man->last);          man_node_delete(man, man->last);
         return(1);  
 }  }
   
 static int  static void
 post_nf(CHKARGS)  post_nf(CHKARGS)
 {  {
   
Line 416  post_nf(CHKARGS)
Line 407  post_nf(CHKARGS)
                     n->line, n->pos, "nf");                      n->line, n->pos, "nf");
   
         man->flags |= MAN_LITERAL;          man->flags |= MAN_LITERAL;
         return(1);  
 }  }
   
 static int  static void
 post_fi(CHKARGS)  post_fi(CHKARGS)
 {  {
   
Line 430  post_fi(CHKARGS)
Line 420  post_fi(CHKARGS)
                     n->line, n->pos, "fi");                      n->line, n->pos, "fi");
   
         man->flags &= ~MAN_LITERAL;          man->flags &= ~MAN_LITERAL;
         return(1);  
 }  }
   
 static int  static void
 post_UC(CHKARGS)  post_UC(CHKARGS)
 {  {
         static const char * const bsd_versions[] = {          static const char * const bsd_versions[] = {
Line 468  post_UC(CHKARGS)
Line 457  post_UC(CHKARGS)
   
         free(man->meta.source);          free(man->meta.source);
         man->meta.source = mandoc_strdup(p);          man->meta.source = mandoc_strdup(p);
         return(1);  
 }  }
   
 static int  static void
 post_AT(CHKARGS)  post_AT(CHKARGS)
 {  {
         static const char * const unix_versions[] = {          static const char * const unix_versions[] = {
Line 506  post_AT(CHKARGS)
Line 494  post_AT(CHKARGS)
   
         free(man->meta.source);          free(man->meta.source);
         man->meta.source = mandoc_strdup(p);          man->meta.source = mandoc_strdup(p);
         return(1);  
 }  }
   
 static int  static void
 post_vs(CHKARGS)  post_vs(CHKARGS)
 {  {
   
Line 519  post_vs(CHKARGS)
Line 506  post_vs(CHKARGS)
                 check_le1(man, n);                  check_le1(man, n);
   
         if (NULL != n->prev)          if (NULL != n->prev)
                 return(1);                  return;
   
         switch (n->parent->tok) {          switch (n->parent->tok) {
         case MAN_SH:          case MAN_SH:
Line 539  post_vs(CHKARGS)
Line 526  post_vs(CHKARGS)
         default:          default:
                 break;                  break;
         }          }
   
         return(1);  
 }  }

Legend:
Removed from v.1.106  
changed lines
  Added in v.1.107

CVSweb