[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.107 and 1.116

version 1.107, 2010/07/02 15:03:14 version 1.116, 2010/08/29 10:30:58
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
  *   *
  * 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 above   * purpose with or without fee is hereby granted, provided that the above
Line 32 
Line 32 
 #include "libmandoc.h"  #include "libmandoc.h"
   
 /* FIXME: .Bl -diag can't have non-text children in HEAD. */  /* FIXME: .Bl -diag can't have non-text children in HEAD. */
 /* TODO: ignoring Pp (it's superfluous in some invocations). */  
   
 #define PRE_ARGS  struct mdoc *mdoc, struct mdoc_node *n  #define PRE_ARGS  struct mdoc *mdoc, struct mdoc_node *n
 #define POST_ARGS struct mdoc *mdoc  #define POST_ARGS struct mdoc *mdoc
Line 65  static int  err_count(struct mdoc *, const char *, 
Line 64  static int  err_count(struct mdoc *, const char *, 
 static  int      berr_ge1(POST_ARGS);  static  int      berr_ge1(POST_ARGS);
 static  int      bwarn_ge1(POST_ARGS);  static  int      bwarn_ge1(POST_ARGS);
 static  int      ebool(POST_ARGS);  static  int      ebool(POST_ARGS);
 static  int      eerr_eq0(POST_ARGS);  
 static  int      eerr_eq1(POST_ARGS);  static  int      eerr_eq1(POST_ARGS);
 static  int      eerr_ge1(POST_ARGS);  static  int      eerr_ge1(POST_ARGS);
 static  int      eerr_le1(POST_ARGS);  static  int      eerr_le1(POST_ARGS);
   static  int      ewarn_eq0(POST_ARGS);
 static  int      ewarn_ge1(POST_ARGS);  static  int      ewarn_ge1(POST_ARGS);
 static  int      herr_eq0(POST_ARGS);  static  int      herr_eq0(POST_ARGS);
 static  int      herr_ge1(POST_ARGS);  static  int      herr_ge1(POST_ARGS);
Line 118  static v_post  posts_it[] = { post_it, NULL };
Line 117  static v_post  posts_it[] = { post_it, NULL };
 static  v_post   posts_lb[] = { eerr_eq1, post_lb, NULL };  static  v_post   posts_lb[] = { eerr_eq1, post_lb, NULL };
 static  v_post   posts_nd[] = { berr_ge1, NULL };  static  v_post   posts_nd[] = { berr_ge1, NULL };
 static  v_post   posts_nm[] = { post_nm, NULL };  static  v_post   posts_nm[] = { post_nm, NULL };
 static  v_post   posts_notext[] = { eerr_eq0, NULL };  static  v_post   posts_notext[] = { ewarn_eq0, NULL };
 static  v_post   posts_rs[] = { berr_ge1, herr_eq0, post_rs, NULL };  static  v_post   posts_rs[] = { berr_ge1, herr_eq0, post_rs, NULL };
 static  v_post   posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL };  static  v_post   posts_sh[] = { herr_ge1, bwarn_ge1, post_sh, NULL };
 static  v_post   posts_sp[] = { eerr_le1, NULL };  static  v_post   posts_sp[] = { eerr_le1, NULL };
Line 146  static v_pre  pres_ss[] = { pre_ss, NULL };
Line 145  static v_pre  pres_ss[] = { pre_ss, NULL };
   
 const   struct valids mdoc_valids[MDOC_MAX] = {  const   struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, NULL },                         /* Ap */          { NULL, NULL },                         /* Ap */
         { pres_dd, posts_text },                /* Dd */          { pres_dd, posts_wtext },               /* Dd */
         { pres_dt, posts_dt },                  /* Dt */          { pres_dt, posts_dt },                  /* Dt */
         { pres_os, NULL },                      /* Os */          { pres_os, NULL },                      /* Os */
         { pres_sh, posts_sh },                  /* Sh */          { pres_sh, posts_sh },                  /* Sh */
Line 393  CHECK_CHILD_DEFN(err, lt, <)   /* err_child_lt() */
Line 392  CHECK_CHILD_DEFN(err, lt, <)   /* err_child_lt() */
 CHECK_CHILD_DEFN(warn, lt, <)                   /* warn_child_lt() */  CHECK_CHILD_DEFN(warn, lt, <)                   /* warn_child_lt() */
 CHECK_BODY_DEFN(ge1, warn, warn_child_gt, 0)    /* bwarn_ge1() */  CHECK_BODY_DEFN(ge1, warn, warn_child_gt, 0)    /* bwarn_ge1() */
 CHECK_BODY_DEFN(ge1, err, err_child_gt, 0)      /* berr_ge1() */  CHECK_BODY_DEFN(ge1, err, err_child_gt, 0)      /* berr_ge1() */
   CHECK_ELEM_DEFN(eq0, warn, warn_child_eq, 0)    /* ewarn_eq0() */
 CHECK_ELEM_DEFN(ge1, warn, warn_child_gt, 0)    /* ewarn_ge1() */  CHECK_ELEM_DEFN(ge1, warn, warn_child_gt, 0)    /* ewarn_ge1() */
 CHECK_ELEM_DEFN(eq1, err, err_child_eq, 1)      /* eerr_eq1() */  CHECK_ELEM_DEFN(eq1, err, err_child_eq, 1)      /* eerr_eq1() */
 CHECK_ELEM_DEFN(le1, err, err_child_lt, 2)      /* eerr_le1() */  CHECK_ELEM_DEFN(le1, err, err_child_lt, 2)      /* eerr_le1() */
 CHECK_ELEM_DEFN(eq0, err, err_child_eq, 0)      /* eerr_eq0() */  
 CHECK_ELEM_DEFN(ge1, err, err_child_gt, 0)      /* eerr_ge1() */  CHECK_ELEM_DEFN(ge1, err, err_child_gt, 0)      /* eerr_ge1() */
 CHECK_HEAD_DEFN(eq0, err, err_child_eq, 0)      /* herr_eq0() */  CHECK_HEAD_DEFN(eq0, err, err_child_eq, 0)      /* herr_eq0() */
 CHECK_HEAD_DEFN(le1, warn, warn_child_lt, 2)    /* hwarn_le1() */  CHECK_HEAD_DEFN(le1, warn, warn_child_lt, 2)    /* hwarn_le1() */
Line 454  check_argv(struct mdoc *m, struct mdoc_node *n, struct
Line 453  check_argv(struct mdoc *m, struct mdoc_node *n, struct
   
   
 static int  static int
 check_text(struct mdoc *mdoc, int line, int pos, char *p)  check_text(struct mdoc *m, int ln, int pos, char *p)
 {  {
         int              c;          int              c;
           size_t           sz;
   
         /*  
          * FIXME: we absolutely cannot let \b get through or it will  
          * destroy some assumptions in terms of format.  
          */  
   
         for ( ; *p; p++, pos++) {          for ( ; *p; p++, pos++) {
                   sz = strcspn(p, "\t\\");
                   p += (int)sz;
   
                   if ('\0' == *p)
                           break;
   
                   pos += (int)sz;
   
                 if ('\t' == *p) {                  if ('\t' == *p) {
                         if ( ! (MDOC_LITERAL & mdoc->flags))                          if (MDOC_LITERAL & m->flags)
                                 if ( ! mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADCHAR))                                  continue;
                                         return(0);                          if (mdoc_pmsg(m, ln, pos, MANDOCERR_BADTAB))
                 } else if ( ! isprint((u_char)*p) && ASCII_HYPH != *p)                                  continue;
                         if ( ! mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADCHAR))                          return(0);
                                 return(0);                  }
   
                 if ('\\' != *p)                  /* Check the special character. */
                         continue;  
   
                 c = mandoc_special(p);                  c = mandoc_special(p);
                 if (c) {                  if (c) {
                         p += c - 1;                          p += c - 1;
                         pos += c - 1;                          pos += c - 1;
                         continue;                  } else
                 }                          mdoc_pmsg(m, ln, pos, MANDOCERR_BADESCAPE);
   
                 c = mdoc_pmsg(mdoc, line, pos, MANDOCERR_BADESCAPE);  
                 if ( ! (MDOC_IGN_ESCAPE & mdoc->pflags) && ! c)  
                         return(c);  
         }          }
   
         return(1);          return(1);
 }  }
   
   
   
   
 static int  static int
 check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type t)  check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type t)
 {  {
Line 510  check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type 
Line 506  check_parent(PRE_ARGS, enum mdoct tok, enum mdoc_type 
 }  }
   
   
   
 static int  static int
 pre_display(PRE_ARGS)  pre_display(PRE_ARGS)
 {  {
Line 625  pre_bl(PRE_ARGS)
Line 620  pre_bl(PRE_ARGS)
                         if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV))                          if ( ! mdoc_nmsg(mdoc, n, MANDOCERR_IGNARGV))
                                 return(0);                                  return(0);
                         break;                          break;
                   default:
                           continue;
                 }                  }
   
                 /* Check: duplicate auxiliary arguments. */                  /* Check: duplicate auxiliary arguments. */
Line 647  pre_bl(PRE_ARGS)
Line 644  pre_bl(PRE_ARGS)
   
                 /* Assign list type. */                  /* Assign list type. */
   
                 if (LIST__NONE != lt && n->data.Bl->type == LIST__NONE)                  if (LIST__NONE != lt && n->data.Bl->type == LIST__NONE) {
                         n->data.Bl->type = lt;                          n->data.Bl->type = lt;
                           /* Set column information, too. */
                           if (LIST_column == lt) {
                                   n->data.Bl->ncols =
                                           n->args->argv[i].sz;
                                   n->data.Bl->cols = (const char **)
                                           n->args->argv[i].value;
                           }
                   }
   
                 /* The list type should come first. */                  /* The list type should come first. */
   
Line 939  static int
Line 944  static int
 post_bf(POST_ARGS)  post_bf(POST_ARGS)
 {  {
         struct mdoc_node *np;          struct mdoc_node *np;
         int               arg;          enum mdocargt     arg;
   
         /*          /*
          * Unlike other data pointers, these are "housed" by the HEAD           * Unlike other data pointers, these are "housed" by the HEAD
Line 1132  post_it(POST_ARGS)
Line 1137  post_it(POST_ARGS)
                 if (NULL == mdoc->last->head->child)                  if (NULL == mdoc->last->head->child)
                         if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS))                          if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOARGS))
                                 return(0);                                  return(0);
                 if (NULL == mdoc->last->body->child)  
                         if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))  
                                 return(0);  
                 break;                  break;
         case (LIST_bullet):          case (LIST_bullet):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
Line 1143  post_it(POST_ARGS)
Line 1145  post_it(POST_ARGS)
         case (LIST_enum):          case (LIST_enum):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (LIST_hyphen):          case (LIST_hyphen):
                   if (NULL == mdoc->last->body->child)
                           if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))
                                   return(0);
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (LIST_item):          case (LIST_item):
                 if (mdoc->last->head->child)                  if (mdoc->last->head->child)
                         if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST))                          if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_ARGSLOST))
                                 return(0);                                  return(0);
                 if (NULL == mdoc->last->body->child)  
                         if ( ! mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NOBODY))  
                                 return(0);  
                 break;                  break;
         case (LIST_column):          case (LIST_column):
                 cols = -1;                  cols = (int)n->data.Bl->ncols;
                 for (i = 0; i < (int)n->args->argc; i++)  
                         if (MDOC_Column == n->args->argv[i].arg) {  
                                 cols = (int)n->args->argv[i].sz;  
                                 break;  
                         }  
   
                 assert(-1 != cols);  
                 assert(NULL == mdoc->last->head->child);                  assert(NULL == mdoc->last->head->child);
   
                 if (NULL == mdoc->last->body->child)                  if (NULL == mdoc->last->body->child)
Line 1200  post_bl_head(POST_ARGS) 
Line 1196  post_bl_head(POST_ARGS) 
         n = mdoc->last->parent;          n = mdoc->last->parent;
   
         if (LIST_column == n->data.Bl->type) {          if (LIST_column == n->data.Bl->type) {
                 for (i = 0; i < (int)n->args->argc; i++)                  if (n->data.Bl->ncols && mdoc->last->nchild) {
                         if (MDOC_Column == n->args->argv[i].arg)  
                                 break;  
                 assert(i < (int)n->args->argc);  
   
                 if (n->args->argv[i].sz && mdoc->last->nchild) {  
                         mdoc_nmsg(mdoc, n, MANDOCERR_COLUMNS);                          mdoc_nmsg(mdoc, n, MANDOCERR_COLUMNS);
                         return(0);                          return(0);
                 }                  }

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

CVSweb