[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.198 and 1.209

version 1.198, 2013/12/15 21:23:52 version 1.209, 2014/04/15 00:41:09
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org>
    * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.org>
  *   *
  * 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 35 
Line 36 
   
 #include "mdoc.h"  #include "mdoc.h"
 #include "mandoc.h"  #include "mandoc.h"
   #include "mandoc_aux.h"
 #include "libmdoc.h"  #include "libmdoc.h"
 #include "libmandoc.h"  #include "libmandoc.h"
   
Line 44 
Line 46 
 #define POST_ARGS struct mdoc *mdoc  #define POST_ARGS struct mdoc *mdoc
   
 #define NUMSIZ    32  #define NUMSIZ    32
 #define DATESIZE  32  
   
 enum    check_ineq {  enum    check_ineq {
         CHECK_LT,          CHECK_LT,
Line 72  static void  check_text(struct mdoc *, int, int, char 
Line 73  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 *);
 static  void     check_args(struct mdoc *, struct mdoc_node *);  static  void     check_args(struct mdoc *, struct mdoc_node *);
 static  int      concat(char *, const struct mdoc_node *, size_t);  
 static  enum mdoc_sec   a2sec(const char *);  static  enum mdoc_sec   a2sec(const char *);
 static  size_t          macro2len(enum mdoct);  static  size_t          macro2len(enum mdoct);
   
Line 304  static const struct valids mdoc_valids[MDOC_MAX] = {
Line 304  static const struct valids mdoc_valids[MDOC_MAX] = {
         { NULL, posts_sp },                     /* sp */          { NULL, posts_sp },                     /* sp */
         { NULL, posts_text1 },                  /* %U */          { NULL, posts_text1 },                  /* %U */
         { NULL, NULL },                         /* Ta */          { NULL, NULL },                         /* Ta */
           { NULL, NULL },                         /* ll */
 };  };
   
 #define RSORD_MAX 14 /* Number of `Rs' blocks. */  #define RSORD_MAX 14 /* Number of `Rs' blocks. */
Line 331  static const char * const secnames[SEC__MAX] = {
Line 332  static const char * const secnames[SEC__MAX] = {
         "LIBRARY",          "LIBRARY",
         "SYNOPSIS",          "SYNOPSIS",
         "DESCRIPTION",          "DESCRIPTION",
           "CONTEXT",
         "IMPLEMENTATION NOTES",          "IMPLEMENTATION NOTES",
         "RETURN VALUES",          "RETURN VALUES",
         "ENVIRONMENT",          "ENVIRONMENT",
Line 1121  post_vt(POST_ARGS)
Line 1123  post_vt(POST_ARGS)
 static int  static int
 post_nm(POST_ARGS)  post_nm(POST_ARGS)
 {  {
         char             buf[BUFSIZ];  
         int              c;  
   
         if (NULL != mdoc->meta.name)          if (NULL != mdoc->meta.name)
                 return(1);                  return(1);
   
         /* Try to use our children for setting the meta name. */          mdoc_deroff(&mdoc->meta.name, mdoc->last);
   
         if (NULL != mdoc->last->child) {          if (NULL == mdoc->meta.name) {
                 buf[0] = '\0';  
                 c = concat(buf, mdoc->last->child, BUFSIZ);  
         } else  
                 c = 0;  
   
         switch (c) {  
         case (-1):  
                 mdoc_nmsg(mdoc, mdoc->last->child, MANDOCERR_MEM);  
                 return(0);  
         case (0):  
                 mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME);                  mdoc_nmsg(mdoc, mdoc->last, MANDOCERR_NONAME);
                 mdoc->meta.name = mandoc_strdup("UNKNOWN");                  mdoc->meta.name = mandoc_strdup("UNKNOWN");
                 break;  
         default:  
                 mdoc->meta.name = mandoc_strdup(buf);  
                 break;  
         }          }
         return(1);          return(1);
 }  }
Line 1893  post_hyph(POST_ARGS)
Line 1879  post_hyph(POST_ARGS)
                 if (MDOC_TEXT != nch->type)                  if (MDOC_TEXT != nch->type)
                         continue;                          continue;
                 cp = nch->string;                  cp = nch->string;
                 if (3 > strnlen(cp, 3))                  if ('\0' == *cp)
                         continue;                          continue;
                 while ('\0' != *(++cp))                  while ('\0' != *(++cp))
                         if ('-' == *cp &&                          if ('-' == *cp &&
Line 1963  post_sh_body(POST_ARGS)
Line 1949  post_sh_body(POST_ARGS)
 static int  static int
 post_sh_head(POST_ARGS)  post_sh_head(POST_ARGS)
 {  {
         char             buf[BUFSIZ];  
         struct mdoc_node *n;          struct mdoc_node *n;
           char            *secname;
         enum mdoc_sec    sec;          enum mdoc_sec    sec;
         int              c;  
   
         /*          /*
          * Process a new section.  Sections are either "named" or           * Process a new section.  Sections are either "named" or
Line 1975  post_sh_head(POST_ARGS)
Line 1960  post_sh_head(POST_ARGS)
          * manual sections.           * manual sections.
          */           */
   
           secname = NULL;
         sec = SEC_CUSTOM;          sec = SEC_CUSTOM;
         buf[0] = '\0';          mdoc_deroff(&secname, mdoc->last);
         if (-1 == (c = concat(buf, mdoc->last->child, BUFSIZ))) {          sec = NULL == secname ? SEC_CUSTOM : a2sec(secname);
                 mdoc_nmsg(mdoc, mdoc->last->child, MANDOCERR_MEM);  
                 return(0);  
         } else if (1 == c)  
                 sec = a2sec(buf);  
   
         /* The NAME should be first. */          /* The NAME should be first. */
   
Line 2018  post_sh_head(POST_ARGS)
Line 2000  post_sh_head(POST_ARGS)
   
         /* We don't care about custom sections after this. */          /* We don't care about custom sections after this. */
   
         if (SEC_CUSTOM == sec)          if (SEC_CUSTOM == sec) {
                   free(secname);
                 return(1);                  return(1);
           }
   
         /*          /*
          * Check whether our non-custom section is being repeated or is           * Check whether our non-custom section is being repeated or is
Line 2041  post_sh_head(POST_ARGS)
Line 2025  post_sh_head(POST_ARGS)
         assert(mdoc->meta.msec);          assert(mdoc->meta.msec);
   
         switch (sec) {          switch (sec) {
         case (SEC_RETURN_VALUES):  
                 /* FALLTHROUGH */  
         case (SEC_ERRORS):          case (SEC_ERRORS):
                   if (*mdoc->meta.msec == '4')
                           break;
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
           case (SEC_RETURN_VALUES):
                   /* FALLTHROUGH */
         case (SEC_LIBRARY):          case (SEC_LIBRARY):
                 if (*mdoc->meta.msec == '2')                  if (*mdoc->meta.msec == '2')
                         break;                          break;
                 if (*mdoc->meta.msec == '3')                  if (*mdoc->meta.msec == '3')
                         break;                          break;
                   /* FALLTHROUGH */
           case (SEC_CONTEXT):
                 if (*mdoc->meta.msec == '9')                  if (*mdoc->meta.msec == '9')
                         break;                          break;
                 mandoc_msg(MANDOCERR_SECMSEC, mdoc->parse,                  mandoc_msg(MANDOCERR_SECMSEC, mdoc->parse,
                                 mdoc->last->line, mdoc->last->pos, buf);                      mdoc->last->line, mdoc->last->pos, secname);
                 break;                  break;
         default:          default:
                 break;                  break;
         }          }
   
           free(secname);
         return(1);          return(1);
 }  }
   
Line 2174  pre_literal(PRE_ARGS)
Line 2163  pre_literal(PRE_ARGS)
 static int  static int
 post_dd(POST_ARGS)  post_dd(POST_ARGS)
 {  {
         char              buf[DATESIZE];  
         struct mdoc_node *n;          struct mdoc_node *n;
         int               c;          char             *datestr;
   
         if (mdoc->meta.date)          if (mdoc->meta.date)
                 free(mdoc->meta.date);                  free(mdoc->meta.date);
   
         n = mdoc->last;          n = mdoc->last;
         if (NULL == n->child || '\0' == n->child->string[0]) {          if (NULL == n->child || '\0' == n->child->string[0]) {
                 mdoc->meta.date = mandoc_normdate                  mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :
                         (mdoc->parse, NULL, n->line, n->pos);                      mandoc_normdate(mdoc->parse, NULL, n->line, n->pos);
                 return(1);                  return(1);
         }          }
   
         buf[0] = '\0';          datestr = NULL;
         if (-1 == (c = concat(buf, n->child, DATESIZE))) {          mdoc_deroff(&datestr, n);
                 mdoc_nmsg(mdoc, n->child, MANDOCERR_MEM);          if (mdoc->quick)
                 return(0);                  mdoc->meta.date = datestr;
           else {
                   mdoc->meta.date = mandoc_normdate(mdoc->parse,
                       datestr, n->line, n->pos);
                   free(datestr);
         }          }
   
         assert(c);  
         mdoc->meta.date = mandoc_normdate  
                 (mdoc->parse, buf, n->line, n->pos);  
   
         return(1);          return(1);
 }  }
   
Line 2347  post_bx(POST_ARGS)
Line 2334  post_bx(POST_ARGS)
 static int  static int
 post_os(POST_ARGS)  post_os(POST_ARGS)
 {  {
         struct mdoc_node *n;  
         char              buf[BUFSIZ];  
         int               c;  
 #ifndef OSNAME  #ifndef OSNAME
         struct utsname    utsname;          struct utsname    utsname;
           static char      *defbuf;
 #endif  #endif
           struct mdoc_node *n;
   
         n = mdoc->last;          n = mdoc->last;
   
Line 2366  post_os(POST_ARGS)
Line 2352  post_os(POST_ARGS)
          */           */
   
         free(mdoc->meta.os);          free(mdoc->meta.os);
           mdoc->meta.os = NULL;
           mdoc_deroff(&mdoc->meta.os, n);
           if (mdoc->meta.os)
                   return(1);
   
         buf[0] = '\0';          if (mdoc->defos) {
         if (-1 == (c = concat(buf, n->child, BUFSIZ))) {                  mdoc->meta.os = mandoc_strdup(mdoc->defos);
                 mdoc_nmsg(mdoc, n->child, MANDOCERR_MEM);                  return(1);
                 return(0);  
         }          }
   
         assert(c);  
   
         if ('\0' == buf[0]) {  
                 if (mdoc->defos) {  
                         mdoc->meta.os = mandoc_strdup(mdoc->defos);  
                         return(1);  
                 }  
 #ifdef OSNAME  #ifdef OSNAME
                 if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) {          mdoc->meta.os = mandoc_strdup(OSNAME);
                         mdoc_nmsg(mdoc, n, MANDOCERR_MEM);  
                         return(0);  
                 }  
 #else /*!OSNAME */  #else /*!OSNAME */
           if (NULL == defbuf) {
                 if (-1 == uname(&utsname)) {                  if (-1 == uname(&utsname)) {
                         mdoc_nmsg(mdoc, n, MANDOCERR_UNAME);                          mdoc_nmsg(mdoc, n, MANDOCERR_UNAME);
                         mdoc->meta.os = mandoc_strdup("UNKNOWN");                          defbuf = mandoc_strdup("UNKNOWN");
                         return(post_prol(mdoc));                  } else
                 }                          mandoc_asprintf(&defbuf, "%s %s",
                               utsname.sysname, utsname.release);
                 if (strlcat(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) {  
                         mdoc_nmsg(mdoc, n, MANDOCERR_MEM);  
                         return(0);  
                 }  
                 if (strlcat(buf, " ", BUFSIZ) >= BUFSIZ) {  
                         mdoc_nmsg(mdoc, n, MANDOCERR_MEM);  
                         return(0);  
                 }  
                 if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) {  
                         mdoc_nmsg(mdoc, n, MANDOCERR_MEM);  
                         return(0);  
                 }  
 #endif /*!OSNAME*/  
         }          }
           mdoc->meta.os = mandoc_strdup(defbuf);
         mdoc->meta.os = mandoc_strdup(buf);  #endif /*!OSNAME*/
         return(1);          return(1);
 }  }
   
Line 2437  post_std(POST_ARGS)
Line 2404  post_std(POST_ARGS)
                 return(0);                  return(0);
   
         mdoc->last = nn;          mdoc->last = nn;
         return(1);  
 }  
   
 /*  
  * Concatenate a node, stopping at the first non-text.  
  * Concatenation is separated by a single whitespace.  
  * Returns -1 on fatal (string overrun) error, 0 if child nodes were  
  * encountered, 1 otherwise.  
  */  
 static int  
 concat(char *p, const struct mdoc_node *n, size_t sz)  
 {  
   
         for ( ; NULL != n; n = n->next) {  
                 if (MDOC_TEXT != n->type)  
                         return(0);  
                 if ('\0' != p[0] && strlcat(p, " ", sz) >= sz)  
                         return(-1);  
                 if (strlcat(p, n->string, sz) >= sz)  
                         return(-1);  
                 concat(p, n->child, sz);  
         }  
   
         return(1);          return(1);
 }  }
   

Legend:
Removed from v.1.198  
changed lines
  Added in v.1.209

CVSweb