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

Diff for /mandoc/mdoc_validate.c between version 1.2 and 1.9

version 1.2, 2009/03/31 13:50:19 version 1.9, 2009/06/12 09:18:00
Line 1 
Line 1 
 /* $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@openbsd.org>   * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the   * purpose with or without fee is hereby granted, provided that the above
  * above copyright notice and this permission notice appear in all   * copyright notice and this permission notice appear in all copies.
  * copies.  
  *   *
  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  * PERFORMANCE OF THIS SOFTWARE.  
  */   */
 #include <sys/types.h>  #include <sys/types.h>
   
Line 51  enum merr {
Line 49  enum merr {
 };  };
   
 enum    mwarn {  enum    mwarn {
           WPRINT,
           WNOWIDTH,
           WMISSWIDTH,
         WESCAPE,          WESCAPE,
           WDEPCOL,
         WWRONGMSEC,          WWRONGMSEC,
         WSECOOO,          WSECOOO,
         WSECREP,          WSECREP,
Line 95  static int warn_child_gt(struct mdoc *, const char *, 
Line 97  static int warn_child_gt(struct mdoc *, const char *, 
 static  int     err_child_eq(struct mdoc *, const char *, int);  static  int     err_child_eq(struct mdoc *, const char *, int);
 static  int     warn_child_eq(struct mdoc *, const char *, int);  static  int     warn_child_eq(struct mdoc *, const char *, int);
 static  int     count_child(struct mdoc *);  static  int     count_child(struct mdoc *);
   static  int     warn_print(struct mdoc *, int, int);
 static  int     warn_count(struct mdoc *, const char *,  static  int     warn_count(struct mdoc *, const char *,
                         int, const char *, int);                          int, const char *, int);
 static  int     err_count(struct mdoc *, const char *,  static  int     err_count(struct mdoc *, const char *,
Line 297  const struct valids mdoc_valids[MDOC_MAX] = {
Line 300  const struct valids mdoc_valids[MDOC_MAX] = {
         { pres_lb, posts_lb },                  /* Lb */          { pres_lb, posts_lb },                  /* Lb */
         { NULL, NULL },                         /* Ap */          { NULL, NULL },                         /* Ap */
         { NULL, posts_pp },                     /* Lp */          { NULL, posts_pp },                     /* Lp */
         { NULL, posts_text },                   /* Lk */          { NULL, NULL },                         /* Lk */
         { NULL, posts_text },                   /* Mt */          { NULL, posts_text },                   /* Mt */
         { NULL, posts_wline },                  /* Brq */          { NULL, posts_wline },                  /* Brq */
         { NULL, NULL },                         /* Bro */          { NULL, NULL },                         /* Bro */
Line 311  const struct valids mdoc_valids[MDOC_MAX] = {
Line 314  const struct valids mdoc_valids[MDOC_MAX] = {
   
   
 #ifdef __linux__  #ifdef __linux__
 extern  size_t  strlcpy(char *, const char *, size_t);  
 extern  size_t  strlcat(char *, const char *, size_t);  extern  size_t  strlcat(char *, const char *, size_t);
 #endif  #endif
   
Line 461  pwarn(struct mdoc *m, int line, int pos, enum mwarn ty
Line 463  pwarn(struct mdoc *m, int line, int pos, enum mwarn ty
                 p = "prologue macros out-of-order";                  p = "prologue macros out-of-order";
                 c = WARN_COMPAT;                  c = WARN_COMPAT;
                 break;                  break;
           case (WDEPCOL):
                   p = "deprecated column argument syntax";
                   c = WARN_COMPAT;
                   break;
           case (WNOWIDTH):
                   p = "superfluous width argument";
                   break;
           case (WMISSWIDTH):
                   p = "missing width argument";
                   break;
           case (WPRINT):
                   p = "invalid character";
                   break;
         case (WESCAPE):          case (WESCAPE):
                 p = "invalid escape sequence";                  p = "invalid escape sequence";
                 break;                  break;
Line 498  pwarn(struct mdoc *m, int line, int pos, enum mwarn ty
Line 513  pwarn(struct mdoc *m, int line, int pos, enum mwarn ty
 }  }
   
   
   static int
   warn_print(struct mdoc *m, int ln, int pos)
   {
           if (MDOC_IGN_CHARS & m->pflags)
                   return(pwarn(m, ln, pos, WPRINT));
           return(perr(m, ln, pos, EPRINT));
   }
   
   
 static inline int  static inline int
 warn_count(struct mdoc *m, const char *k,  warn_count(struct mdoc *m, const char *k,
                 int want, const char *v, int has)                  int want, const char *v, int has)
Line 700  check_text(struct mdoc *mdoc, int line, int pos, const
Line 723  check_text(struct mdoc *mdoc, int line, int pos, const
         for ( ; *p; p++) {          for ( ; *p; p++) {
                 if ('\t' == *p) {                  if ('\t' == *p) {
                         if ( ! (MDOC_LITERAL & mdoc->flags))                          if ( ! (MDOC_LITERAL & mdoc->flags))
                                 return(perr(mdoc, line, pos, EPRINT));                                  if ( ! warn_print(mdoc, line, pos))
                                           return(0);
                 } else if ( ! isprint((u_char)*p))                  } else if ( ! isprint((u_char)*p))
                         return(perr(mdoc, line, pos, EPRINT));                          if ( ! warn_print(mdoc, line, pos))
                                   return(0);
   
                 if ('\\' != *p)                  if ('\\' != *p)
                         continue;                          continue;
Line 764  pre_display(PRE_ARGS)
Line 789  pre_display(PRE_ARGS)
 static int  static int
 pre_bl(PRE_ARGS)  pre_bl(PRE_ARGS)
 {  {
         int              i, type, width, offset;          int              pos, col, type, width, offset;
   
         if (MDOC_BLOCK != n->type)          if (MDOC_BLOCK != n->type)
                 return(1);                  return(1);
Line 773  pre_bl(PRE_ARGS)
Line 798  pre_bl(PRE_ARGS)
   
         /* Make sure that only one type of list is specified.  */          /* Make sure that only one type of list is specified.  */
   
         type = offset = width = -1;          type = offset = width = col = -1;
   
         /* LINTED */          /* LINTED */
         for (i = 0; i < (int)n->args->argc; i++)          for (pos = 0; pos < (int)n->args->argc; pos++)
                 switch (n->args->argv[i].arg) {                  switch (n->args->argv[pos].arg) {
                 case (MDOC_Bullet):                  case (MDOC_Bullet):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (MDOC_Dash):                  case (MDOC_Dash):
Line 799  pre_bl(PRE_ARGS)
Line 824  pre_bl(PRE_ARGS)
                 case (MDOC_Inset):                  case (MDOC_Inset):
                         /* FALLTHROUGH */                          /* FALLTHROUGH */
                 case (MDOC_Column):                  case (MDOC_Column):
                         if (-1 == type) {                          if (-1 != type)
                                 type = n->args->argv[i].arg;                                  return(nerr(mdoc, n, EMULTILIST));
                                 break;                          type = n->args->argv[pos].arg;
                         }                          col = pos;
                         return(nerr(mdoc, n, EMULTILIST));                          break;
                 case (MDOC_Width):                  case (MDOC_Width):
                         if (-1 == width) {                          if (-1 != width)
                                 width = n->args->argv[i].arg;                                  return(nerr(mdoc, n, EARGREP));
                                 break;                          width = n->args->argv[pos].arg;
                         }                          break;
                         return(nerr(mdoc, n, EARGREP));  
                 case (MDOC_Offset):                  case (MDOC_Offset):
                         if (-1 == offset) {                          if (-1 != offset)
                                 offset = n->args->argv[i].arg;                                  return(nerr(mdoc, n, EARGREP));
                                 break;                          offset = n->args->argv[pos].arg;
                         }                          break;
                         return(nerr(mdoc, n, EARGREP));  
                 default:                  default:
                         break;                          break;
                 }                  }
Line 823  pre_bl(PRE_ARGS)
Line 846  pre_bl(PRE_ARGS)
         if (-1 == type)          if (-1 == type)
                 return(nerr(mdoc, n, ELISTTYPE));                  return(nerr(mdoc, n, ELISTTYPE));
   
           /*
            * Validate the width field.  Some list types don't need width
            * types and should be warned about them.  Others should have it
            * and must also be warned.
            */
   
         switch (type) {          switch (type) {
           case (MDOC_Tag):
                   if (-1 == width && ! nwarn(mdoc, n, WMISSWIDTH))
                           return(0);
                   break;
         case (MDOC_Column):          case (MDOC_Column):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (MDOC_Diag):          case (MDOC_Diag):
Line 831  pre_bl(PRE_ARGS)
Line 864  pre_bl(PRE_ARGS)
         case (MDOC_Inset):          case (MDOC_Inset):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (MDOC_Item):          case (MDOC_Item):
                 if (-1 == width)                  if (-1 != width && ! nwarn(mdoc, n, WNOWIDTH))
                           return(0);
                   break;
           default:
                   break;
           }
   
           /*
            * General validation of fields.
            */
   
           switch (type) {
           case (MDOC_Column):
                   assert(col >= 0);
                   if (0 == n->args->argv[col].sz)
                         break;                          break;
                 return(mdoc_nwarn(mdoc, n, WARN_SYNTAX,                  if ( ! nwarn(mdoc, n, WDEPCOL))
                                 "superfluous %s argument",                          return(0);
                                 mdoc_argnames[MDOC_Width]));                  break;
         case (MDOC_Tag):  
                 if (-1 != width)  
                         break;  
                 return(mdoc_nwarn(mdoc, n, WARN_SYNTAX,  
                                 "suggest %s argument",  
                                 mdoc_argnames[MDOC_Width]));  
         default:          default:
                 break;                  break;
         }          }
Line 960  static int
Line 1001  static int
 pre_er(PRE_ARGS)  pre_er(PRE_ARGS)
 {  {
   
         return(check_msec(mdoc, n, 2, 0));          return(check_msec(mdoc, n, 2, 3, 9, 0));
 }  }
   
   
Line 1352  post_sh_head(POST_ARGS)
Line 1393  post_sh_head(POST_ARGS)
   
         /* This is just concat() inlined, which is irritating. */          /* This is just concat() inlined, which is irritating. */
   
           buf[0] = 0;
         for (n = mdoc->last->child; n; n = n->next) {          for (n = mdoc->last->child; n; n = n->next) {
                 assert(MDOC_TEXT == n->type);                  assert(MDOC_TEXT == n->type);
                 if (strlcat(buf, n->string, 64) >= 64)                  if (strlcat(buf, n->string, 64) >= 64)

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.9

CVSweb