[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.172 and 1.173

version 1.172, 2011/07/26 14:09:01 version 1.173, 2011/08/10 14:07:23
Line 72  static void  check_text(struct mdoc *, int, int, char 
Line 72  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  int      concat(struct mdoc *, 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 1107  static int
Line 1105  static int
 post_nm(POST_ARGS)  post_nm(POST_ARGS)
 {  {
         char             buf[BUFSIZ];          char             buf[BUFSIZ];
           int              c;
   
         /* If no child specified, make sure we have the meta name. */          /* If no child specified, make sure we have the meta name. */
   
Line 1118  post_nm(POST_ARGS)
Line 1117  post_nm(POST_ARGS)
   
         /* If no meta name, set it from the child. */          /* If no meta name, set it from the child. */
   
         if ( ! concat(mdoc, buf, mdoc->last->child, BUFSIZ))          buf[0] = '\0';
           if (-1 == (c = concat(buf, mdoc->last->child, BUFSIZ))) {
                   mdoc_nmsg(mdoc, mdoc->last->child, MANDOCERR_MEM);
                 return(0);                  return(0);
           }
   
           assert(c);
         mdoc->meta.name = mandoc_strdup(buf);          mdoc->meta.name = mandoc_strdup(buf);
   
         return(1);          return(1);
 }  }
   
Line 1818  post_sh_head(POST_ARGS)
Line 1820  post_sh_head(POST_ARGS)
 {  {
         char             buf[BUFSIZ];          char             buf[BUFSIZ];
         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 1826  post_sh_head(POST_ARGS)
Line 1829  post_sh_head(POST_ARGS)
          * manual sections.           * manual sections.
          */           */
   
         if ( ! concat(mdoc, buf, mdoc->last->child, BUFSIZ))          sec = SEC_CUSTOM;
           buf[0] = '\0';
           if (-1 == (c = concat(buf, mdoc->last->child, BUFSIZ))) {
                   mdoc_nmsg(mdoc, mdoc->last->child, MANDOCERR_MEM);
                 return(0);                  return(0);
           } else if (1 == c)
                   sec = a2sec(buf);
   
         sec = a2sec(buf);  
   
         /* The NAME should be first. */          /* The NAME should be first. */
   
         if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed)          if (SEC_NAME != sec && SEC_NONE == mdoc->lastnamed)
Line 1978  post_dd(POST_ARGS)
Line 1984  post_dd(POST_ARGS)
 {  {
         char              buf[DATESIZE];          char              buf[DATESIZE];
         struct mdoc_node *n;          struct mdoc_node *n;
           int               c;
   
         if (mdoc->meta.date)          if (mdoc->meta.date)
                 free(mdoc->meta.date);                  free(mdoc->meta.date);
Line 1989  post_dd(POST_ARGS)
Line 1996  post_dd(POST_ARGS)
                 return(1);                  return(1);
         }          }
   
         if ( ! concat(mdoc, buf, n->child, DATESIZE))          buf[0] = '\0';
           if (-1 == (c = concat(buf, n->child, DATESIZE))) {
                   mdoc_nmsg(mdoc, n->child, MANDOCERR_MEM);
                 return(0);                  return(0);
           }
   
           assert(c);
         mdoc->meta.date = mandoc_normdate          mdoc->meta.date = mandoc_normdate
                 (mdoc->parse, buf, n->line, n->pos);                  (mdoc->parse, buf, n->line, n->pos);
   
Line 2146  post_os(POST_ARGS)
Line 2157  post_os(POST_ARGS)
 {  {
         struct mdoc_node *n;          struct mdoc_node *n;
         char              buf[BUFSIZ];          char              buf[BUFSIZ];
           int               c;
 #ifndef OSNAME  #ifndef OSNAME
         struct utsname    utsname;          struct utsname    utsname;
 #endif  #endif
Line 2162  post_os(POST_ARGS)
Line 2174  post_os(POST_ARGS)
         if (mdoc->meta.os)          if (mdoc->meta.os)
                 free(mdoc->meta.os);                  free(mdoc->meta.os);
   
         if ( ! concat(mdoc, buf, n->child, BUFSIZ))          buf[0] = '\0';
           if (-1 == (c = concat(buf, n->child, BUFSIZ))) {
                   mdoc_nmsg(mdoc, n->child, MANDOCERR_MEM);
                 return(0);                  return(0);
           }
   
           assert(c);
   
         /* XXX: yes, these can all be dynamically-adjusted buffers, but          /* XXX: yes, these can all be dynamically-adjusted buffers, but
          * it's really not worth the extra hackery.           * it's really not worth the extra hackery.
          */           */
Line 2230  post_std(POST_ARGS)
Line 2247  post_std(POST_ARGS)
         return(1);          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  static int
 concat(struct mdoc *m, char *p, const struct mdoc_node *n, size_t sz)  concat(char *p, const struct mdoc_node *n, size_t sz)
 {  {
   
         p[0] = '\0';          for ( ; NULL != n; n = n->next) {
                   if (MDOC_TEXT != n->type)
         /*  
          * Concatenate sibling nodes together.  All siblings must be of  
          * type MDOC_TEXT or an assertion is raised.  Concatenation is  
          * separated by a single whitespace.  Returns 0 on fatal (string  
          * overrun) error.  
          */  
   
         for ( ; n; n = n->next) {  
                 assert(MDOC_TEXT == n->type);  
   
                 if (strlcat(p, n->string, sz) >= sz) {  
                         mdoc_nmsg(m, n, MANDOCERR_MEM);  
                         return(0);                          return(0);
                 }                  if ('\0' != p[0] && strlcat(p, " ", sz) >= sz)
                           return(-1);
                 if (NULL == n->next)                  if (strlcat(p, n->string, sz) >= sz)
                         continue;                          return(-1);
                   concat(p, n->child, sz);
                 if (strlcat(p, " ", sz) >= sz) {  
                         mdoc_nmsg(m, n, MANDOCERR_MEM);  
                         return(0);  
                 }  
         }          }
   
         return(1);          return(1);

Legend:
Removed from v.1.172  
changed lines
  Added in v.1.173

CVSweb