[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.104 and 1.108

version 1.104, 2014/08/01 21:24:17 version 1.108, 2014/12/28 14:42:27
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 15 
Line 15 
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
 #ifdef HAVE_CONFIG_H  
 #include "config.h"  #include "config.h"
 #endif  
   
 #include <sys/types.h>  #include <sys/types.h>
   
Line 38 
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_ge2(CHKARGS);  static  void      check_le5(CHKARGS);
 static  int       check_le5(CHKARGS);  static  void      check_par(CHKARGS);
 static  int       check_par(CHKARGS);  static  void      check_part(CHKARGS);
 static  int       check_part(CHKARGS);  static  void      check_root(CHKARGS);
 static  int       check_root(CHKARGS);  static  void      check_text(CHKARGS);
 static  int       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 103  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 111  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 142  check_root(CHKARGS)
Line 143  check_root(CHKARGS)
                 man->meta.hasbody = 1;                  man->meta.hasbody = 1;
   
         if (NULL == man->meta.title) {          if (NULL == man->meta.title) {
                 mandoc_msg(MANDOCERR_TH_MISSING, man->parse,                  mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse,
                     n->line, n->pos, NULL);                      n->line, n->pos, NULL);
   
                 /*                  /*
Line 150  check_root(CHKARGS)
Line 151  check_root(CHKARGS)
                  * implication, date and section also aren't set).                   * implication, date and section also aren't set).
                  */                   */
   
                 man->meta.title = mandoc_strdup("unknown");                  man->meta.title = mandoc_strdup("");
                 man->meta.msec = mandoc_strdup("1");                  man->meta.msec = mandoc_strdup("");
                 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)
 INEQ_DEFINE(2, ==, eq2)  INEQ_DEFINE(2, ==, eq2)
 INEQ_DEFINE(1, <=, le1)  INEQ_DEFINE(1, <=, le1)
 INEQ_DEFINE(2, >=, ge2)  
 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 252  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 293  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 315  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;
         const char      *p;          const char      *p;
   
         check_ge2(man, n);  
         check_le5(man, n);          check_le5(man, n);
   
         free(man->meta.title);          free(man->meta.title);
Line 354  post_TH(CHKARGS)
Line 341  post_TH(CHKARGS)
                         }                          }
                 }                  }
                 man->meta.title = mandoc_strdup(n->string);                  man->meta.title = mandoc_strdup(n->string);
         } else          } else {
                 man->meta.title = mandoc_strdup("");                  man->meta.title = mandoc_strdup("");
                   mandoc_msg(MANDOCERR_TH_NOTITLE, man->parse,
                       nb->line, nb->pos, "TH");
           }
   
         /* TITLE ->MSEC<- DATE SOURCE VOL */          /* TITLE ->MSEC<- DATE SOURCE VOL */
   
Line 363  post_TH(CHKARGS)
Line 353  post_TH(CHKARGS)
                 n = n->next;                  n = n->next;
         if (n && n->string)          if (n && n->string)
                 man->meta.msec = mandoc_strdup(n->string);                  man->meta.msec = mandoc_strdup(n->string);
         else          else {
                 man->meta.msec = mandoc_strdup("");                  man->meta.msec = mandoc_strdup("");
                   mandoc_vmsg(MANDOCERR_MSEC_MISSING, man->parse,
                       nb->line, nb->pos, "TH %s", man->meta.title);
           }
   
         /* TITLE MSEC ->DATE<- SOURCE VOL */          /* TITLE MSEC ->DATE<- SOURCE VOL */
   
Line 386  post_TH(CHKARGS)
Line 379  post_TH(CHKARGS)
   
         if (n && (n = n->next))          if (n && (n = n->next))
                 man->meta.source = mandoc_strdup(n->string);                  man->meta.source = mandoc_strdup(n->string);
           else if (man->defos != NULL)
                   man->meta.source = mandoc_strdup(man->defos);
   
         /* TITLE MSEC DATE SOURCE ->VOL<- */          /* TITLE MSEC DATE SOURCE ->VOL<- */
         /* If missing, use the default VOL name for MSEC. */          /* If missing, use the default VOL name for MSEC. */
Line 401  post_TH(CHKARGS)
Line 396  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 415  post_nf(CHKARGS)
Line 409  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 429  post_fi(CHKARGS)
Line 422  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 467  post_UC(CHKARGS)
Line 459  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 505  post_AT(CHKARGS)
Line 496  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 518  post_vs(CHKARGS)
Line 508  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 538  post_vs(CHKARGS)
Line 528  post_vs(CHKARGS)
         default:          default:
                 break;                  break;
         }          }
   
         return(1);  
 }  }

Legend:
Removed from v.1.104  
changed lines
  Added in v.1.108

CVSweb