[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.274 and 1.278

version 1.274, 2015/02/06 03:38:45 version 1.278, 2015/02/12 12:24:33
Line 56  struct valids {
Line 56  struct valids {
         v_post   post;          v_post   post;
 };  };
   
 static  void     check_count(struct mdoc *, enum mdoc_type,  
                         enum check_ineq, int);  
 static  void     check_text(struct mdoc *, int, int, char *);  static  void     check_text(struct mdoc *, int, int, char *);
 static  void     check_argv(struct mdoc *,  static  void     check_argv(struct mdoc *,
                         struct mdoc_node *, struct mdoc_argv *);                          struct mdoc_node *, struct mdoc_argv *);
Line 67  static enum mdoc_sec a2sec(const char *);
Line 65  static enum mdoc_sec a2sec(const char *);
 static  size_t          macro2len(enum mdoct);  static  size_t          macro2len(enum mdoct);
 static  void     rewrite_macro2len(char **);  static  void     rewrite_macro2len(char **);
   
 static  void     ewarn_eq1(POST_ARGS);  
 static  void     ewarn_ge1(POST_ARGS);  
   
 static  void     post_an(POST_ARGS);  static  void     post_an(POST_ARGS);
 static  void     post_at(POST_ARGS);  static  void     post_at(POST_ARGS);
 static  void     post_bf(POST_ARGS);  static  void     post_bf(POST_ARGS);
Line 92  static void  post_fn(POST_ARGS);
Line 87  static void  post_fn(POST_ARGS);
 static  void     post_fname(POST_ARGS);  static  void     post_fname(POST_ARGS);
 static  void     post_fo(POST_ARGS);  static  void     post_fo(POST_ARGS);
 static  void     post_hyph(POST_ARGS);  static  void     post_hyph(POST_ARGS);
 static  void     post_hyphtext(POST_ARGS);  
 static  void     post_ignpar(POST_ARGS);  static  void     post_ignpar(POST_ARGS);
 static  void     post_it(POST_ARGS);  static  void     post_it(POST_ARGS);
 static  void     post_lb(POST_ARGS);  static  void     post_lb(POST_ARGS);
Line 167  static const struct valids mdoc_valids[MDOC_MAX] = {
Line 161  static const struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, NULL },                         /* Va */          { NULL, NULL },                         /* Va */
         { NULL, post_vt },                      /* Vt */          { NULL, post_vt },                      /* Vt */
         { NULL, NULL },                         /* Xr */          { NULL, NULL },                         /* Xr */
         { NULL, ewarn_ge1 },                    /* %A */          { NULL, NULL },                         /* %A */
         { NULL, post_hyphtext },                /* %B */ /* FIXME: can be used outside Rs/Re. */          { NULL, post_hyph },                    /* %B */ /* FIXME: can be used outside Rs/Re. */
         { NULL, ewarn_ge1 },                    /* %D */          { NULL, NULL },                         /* %D */
         { NULL, ewarn_ge1 },                    /* %I */          { NULL, NULL },                         /* %I */
         { NULL, ewarn_ge1 },                    /* %J */          { NULL, NULL },                         /* %J */
         { NULL, post_hyphtext },                /* %N */          { NULL, post_hyph },                    /* %N */
         { NULL, post_hyphtext },                /* %O */          { NULL, post_hyph },                    /* %O */
         { NULL, ewarn_ge1 },                    /* %P */          { NULL, NULL },                         /* %P */
         { NULL, post_hyphtext },                /* %R */          { NULL, post_hyph },                    /* %R */
         { NULL, post_hyphtext },                /* %T */ /* FIXME: can be used outside Rs/Re. */          { NULL, post_hyph },                    /* %T */ /* FIXME: can be used outside Rs/Re. */
         { NULL, ewarn_ge1 },                    /* %V */          { NULL, NULL },                         /* %V */
         { NULL, NULL },                         /* Ac */          { NULL, NULL },                         /* Ac */
         { NULL, NULL },                         /* Ao */          { NULL, NULL },                         /* Ao */
         { NULL, NULL },                         /* Aq */          { NULL, NULL },                         /* Aq */
Line 239  static const struct valids mdoc_valids[MDOC_MAX] = {
Line 233  static const struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, NULL },                         /* Brq */          { NULL, NULL },                         /* Brq */
         { NULL, NULL },                         /* Bro */          { NULL, NULL },                         /* Bro */
         { NULL, NULL },                         /* Brc */          { NULL, NULL },                         /* Brc */
         { NULL, ewarn_ge1 },                    /* %C */          { NULL, NULL },                         /* %C */
         { pre_obsolete, post_es },              /* Es */          { pre_obsolete, post_es },              /* Es */
         { pre_obsolete, post_en },              /* En */          { pre_obsolete, post_en },              /* En */
         { NULL, NULL },                         /* Dx */          { NULL, NULL },                         /* Dx */
         { NULL, ewarn_ge1 },                    /* %Q */          { NULL, NULL },                         /* %Q */
         { NULL, post_par },                     /* br */          { NULL, post_par },                     /* br */
         { NULL, post_par },                     /* sp */          { NULL, post_par },                     /* sp */
         { NULL, ewarn_eq1 },                    /* %U */          { NULL, NULL },                         /* %U */
         { NULL, NULL },                         /* Ta */          { NULL, NULL },                         /* Ta */
         { NULL, NULL },                         /* ll */          { NULL, NULL },                         /* ll */
 };  };
Line 331  mdoc_valid_post(struct mdoc *mdoc)
Line 325  mdoc_valid_post(struct mdoc *mdoc)
         n = mdoc->last;          n = mdoc->last;
         if (n->flags & MDOC_VALID)          if (n->flags & MDOC_VALID)
                 return;                  return;
         n->flags |= MDOC_VALID;          n->flags |= MDOC_VALID | MDOC_ENDED;
   
         switch (n->type) {          switch (n->type) {
         case MDOC_TEXT:          case MDOC_TEXT:
Line 366  mdoc_valid_post(struct mdoc *mdoc)
Line 360  mdoc_valid_post(struct mdoc *mdoc)
 }  }
   
 static void  static void
 check_count(struct mdoc *mdoc, enum mdoc_type type,  
         enum check_ineq ineq, int val)  
 {  
         const char      *p;  
   
         if (mdoc->last->type != type)  
                 return;  
   
         switch (ineq) {  
         case CHECK_LT:  
                 p = "less than ";  
                 if (mdoc->last->nchild < val)  
                         return;  
                 break;  
         case CHECK_GT:  
                 p = "more than ";  
                 if (mdoc->last->nchild > val)  
                         return;  
                 break;  
         case CHECK_EQ:  
                 p = "";  
                 if (val == mdoc->last->nchild)  
                         return;  
                 break;  
         default:  
                 abort();  
                 /* NOTREACHED */  
         }  
   
         mandoc_vmsg(MANDOCERR_ARGCWARN, mdoc->parse, mdoc->last->line,  
             mdoc->last->pos, "want %s%d children (have %d)",  
             p, val, mdoc->last->nchild);  
 }  
   
 static void  
 ewarn_eq1(POST_ARGS)  
 {  
         check_count(mdoc, MDOC_ELEM, CHECK_EQ, 1);  
 }  
   
 static void  
 ewarn_ge1(POST_ARGS)  
 {  
         check_count(mdoc, MDOC_ELEM, CHECK_GT, 0);  
 }  
   
 static void  
 check_args(struct mdoc *mdoc, struct mdoc_node *n)  check_args(struct mdoc *mdoc, struct mdoc_node *n)
 {  {
         int              i;          int              i;
Line 469  pre_display(PRE_ARGS)
Line 416  pre_display(PRE_ARGS)
 static void  static void
 pre_bl(PRE_ARGS)  pre_bl(PRE_ARGS)
 {  {
         struct mdoc_node *np;  
         struct mdoc_argv *argv, *wa;          struct mdoc_argv *argv, *wa;
         int               i;          int               i;
         enum mdocargt     mdoclt;          enum mdocargt     mdoclt;
         enum mdoc_list    lt;          enum mdoc_list    lt;
   
         if (MDOC_BLOCK != n->type) {          if (n->type != MDOC_BLOCK)
                 if (ENDBODY_NOT != n->end) {  
                         assert(n->pending);  
                         np = n->pending->parent;  
                 } else  
                         np = n->parent;  
   
                 assert(np);  
                 assert(MDOC_BLOCK == np->type);  
                 assert(MDOC_Bl == np->tok);  
                 return;                  return;
         }  
   
         /*          /*
          * First figure out which kind of list to use: bind ourselves to           * First figure out which kind of list to use: bind ourselves to
Line 662  pre_bl(PRE_ARGS)
Line 598  pre_bl(PRE_ARGS)
 static void  static void
 pre_bd(PRE_ARGS)  pre_bd(PRE_ARGS)
 {  {
         struct mdoc_node *np;  
         struct mdoc_argv *argv;          struct mdoc_argv *argv;
         int               i;          int               i;
         enum mdoc_disp    dt;          enum mdoc_disp    dt;
   
         pre_literal(mdoc, n);          pre_literal(mdoc, n);
   
         if (MDOC_BLOCK != n->type) {          if (n->type != MDOC_BLOCK)
                 if (ENDBODY_NOT != n->end) {  
                         assert(n->pending);  
                         np = n->pending->parent;  
                 } else  
                         np = n->parent;  
   
                 assert(np);  
                 assert(MDOC_BLOCK == np->type);  
                 assert(MDOC_Bd == np->tok);  
                 return;                  return;
         }  
   
         for (i = 0; n->args && i < (int)n->args->argc; i++) {          for (i = 0; n->args && i < (int)n->args->argc; i++) {
                 argv = n->args->argv + i;                  argv = n->args->argv + i;
Line 850  post_bf(POST_ARGS)
Line 775  post_bf(POST_ARGS)
          * element, which contains the goods.           * element, which contains the goods.
          */           */
   
         if (MDOC_HEAD != mdoc->last->type) {          np = mdoc->last;
                 if (ENDBODY_NOT != mdoc->last->end) {          if (MDOC_HEAD != np->type)
                         assert(mdoc->last->pending);  
                         np = mdoc->last->pending->parent->head;  
                 } else if (MDOC_BLOCK != mdoc->last->type) {  
                         np = mdoc->last->parent->head;  
                 } else  
                         np = mdoc->last->head;  
   
                 assert(np);  
                 assert(MDOC_HEAD == np->type);  
                 assert(MDOC_Bf == np->tok);  
                 return;                  return;
         }  
   
         np = mdoc->last;  
         assert(MDOC_BLOCK == np->parent->type);          assert(MDOC_BLOCK == np->parent->type);
         assert(MDOC_Bf == np->parent->tok);          assert(MDOC_Bf == np->parent->tok);
   
Line 920  post_lb(POST_ARGS)
Line 833  post_lb(POST_ARGS)
         const char              *stdlibname;          const char              *stdlibname;
         char                    *libname;          char                    *libname;
   
         check_count(mdoc, MDOC_ELEM, CHECK_EQ, 1);  
         n = mdoc->last->child;          n = mdoc->last->child;
         assert(MDOC_TEXT == n->type);          assert(MDOC_TEXT == n->type);
   
Line 1089  post_d1(POST_ARGS)
Line 1001  post_d1(POST_ARGS)
                 return;                  return;
   
         if (n->child == NULL)          if (n->child == NULL)
                 mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,                  mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse,
                     n->line, n->pos, "D1");                      n->line, n->pos, "D1");
   
         post_hyph(mdoc);          post_hyph(mdoc);
Line 1106  post_literal(POST_ARGS)
Line 1018  post_literal(POST_ARGS)
                 return;                  return;
   
         if (n->child == NULL)          if (n->child == NULL)
                 mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,                  mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse,
                     n->line, n->pos, mdoc_macronames[n->tok]);                      n->line, n->pos, mdoc_macronames[n->tok]);
   
         if (n->tok == MDOC_Bd &&          if (n->tok == MDOC_Bd &&
Line 1275  post_it(POST_ARGS)
Line 1187  post_it(POST_ARGS)
                                 i++;                                  i++;
   
                 if (i < cols || i > cols + 1)                  if (i < cols || i > cols + 1)
                         mandoc_vmsg(MANDOCERR_ARGCOUNT,                          mandoc_vmsg(MANDOCERR_BL_COL,
                             mdoc->parse, nit->line, nit->pos,                              mdoc->parse, nit->line, nit->pos,
                             "columns == %d (have %d)", cols, i);                              "%d columns, %d cells", cols, i);
                 break;                  break;
         default:          default:
                 abort();                  abort();
Line 1513  post_bl(POST_ARGS)
Line 1425  post_bl(POST_ARGS)
   
         nchild = nbody->child;          nchild = nbody->child;
         if (nchild == NULL) {          if (nchild == NULL) {
                 mandoc_msg(MANDOCERR_MACRO_EMPTY, mdoc->parse,                  mandoc_msg(MANDOCERR_BLK_EMPTY, mdoc->parse,
                     nbody->line, nbody->pos, "Bl");                      nbody->line, nbody->pos, "Bl");
                 return;                  return;
         }          }
Line 1581  post_bk(POST_ARGS)
Line 1493  post_bk(POST_ARGS)
         n = mdoc->last;          n = mdoc->last;
   
         if (n->type == MDOC_BLOCK && n->body->child == NULL) {          if (n->type == MDOC_BLOCK && n->body->child == NULL) {
                 mandoc_msg(MANDOCERR_MACRO_EMPTY,                  mandoc_msg(MANDOCERR_BLK_EMPTY,
                     mdoc->parse, n->line, n->pos, "Bk");                      mdoc->parse, n->line, n->pos, "Bk");
                 mdoc_node_delete(mdoc, n);                  mdoc_node_delete(mdoc, n);
         }          }
Line 1793  post_hyph(POST_ARGS)
Line 1705  post_hyph(POST_ARGS)
 }  }
   
 static void  static void
 post_hyphtext(POST_ARGS)  
 {  
   
         ewarn_ge1(mdoc);  
         post_hyph(mdoc);  
 }  
   
 static void  
 post_ns(POST_ARGS)  post_ns(POST_ARGS)
 {  {
   
Line 1877  static void
Line 1781  static void
 post_sh_see_also(POST_ARGS)  post_sh_see_also(POST_ARGS)
 {  {
         const struct mdoc_node  *n;          const struct mdoc_node  *n;
         const char              *name, *sec;          const char              *name, *sec;
         const char              *lastname, *lastsec, *lastpunct;          const char              *lastname, *lastsec, *lastpunct;
         int                      cmp;          int                      cmp;
   

Legend:
Removed from v.1.274  
changed lines
  Added in v.1.278

CVSweb