[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.366 and 1.377

version 1.366, 2018/12/30 00:49:55 version 1.377, 2020/01/19 18:02:00
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-2018 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2010-2020 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2010 Joerg Sonnenberger <joerg@netbsd.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
Line 64  static size_t  macro2len(enum roff_tok);
Line 64  static size_t  macro2len(enum roff_tok);
 static  void     rewrite_macro2len(struct roff_man *, char **);  static  void     rewrite_macro2len(struct roff_man *, char **);
 static  int      similar(const char *, const char *);  static  int      similar(const char *, const char *);
   
 static  void     post_abort(POST_ARGS);  static  void     post_abort(POST_ARGS) __attribute__((__noreturn__));
 static  void     post_an(POST_ARGS);  static  void     post_an(POST_ARGS);
 static  void     post_an_norm(POST_ARGS);  static  void     post_an_norm(POST_ARGS);
 static  void     post_at(POST_ARGS);  static  void     post_at(POST_ARGS);
Line 113  static void  post_sm(POST_ARGS);
Line 113  static void  post_sm(POST_ARGS);
 static  void     post_st(POST_ARGS);  static  void     post_st(POST_ARGS);
 static  void     post_std(POST_ARGS);  static  void     post_std(POST_ARGS);
 static  void     post_sx(POST_ARGS);  static  void     post_sx(POST_ARGS);
   static  void     post_tg(POST_ARGS);
 static  void     post_useless(POST_ARGS);  static  void     post_useless(POST_ARGS);
 static  void     post_xr(POST_ARGS);  static  void     post_xr(POST_ARGS);
 static  void     post_xx(POST_ARGS);  static  void     post_xx(POST_ARGS);
Line 238  static const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = 
Line 239  static const v_post mdoc_valids[MDOC_MAX - MDOC_Dd] = 
         NULL,           /* %Q */          NULL,           /* %Q */
         NULL,           /* %U */          NULL,           /* %U */
         NULL,           /* Ta */          NULL,           /* Ta */
           post_tg,        /* Tg */
 };  };
   
 #define RSORD_MAX 14 /* Number of `Rs' blocks. */  #define RSORD_MAX 14 /* Number of `Rs' blocks. */
Line 288  static const char * const secnames[SEC__MAX] = {
Line 290  static const char * const secnames[SEC__MAX] = {
   
 /* Validate the subtree rooted at mdoc->last. */  /* Validate the subtree rooted at mdoc->last. */
 void  void
 mdoc_node_validate(struct roff_man *mdoc)  mdoc_validate(struct roff_man *mdoc)
 {  {
         struct roff_node *n, *np;          struct roff_node *n, *np;
         const v_post *p;          const v_post *p;
Line 319  mdoc_node_validate(struct roff_man *mdoc)
Line 321  mdoc_node_validate(struct roff_man *mdoc)
   
         mdoc->last = mdoc->last->child;          mdoc->last = mdoc->last->child;
         while (mdoc->last != NULL) {          while (mdoc->last != NULL) {
                 mdoc_node_validate(mdoc);                  mdoc_validate(mdoc);
                 if (mdoc->last == n)                  if (mdoc->last == n)
                         mdoc->last = mdoc->last->child;                          mdoc->last = mdoc->last->child;
                 else                  else
Line 336  mdoc_node_validate(struct roff_man *mdoc)
Line 338  mdoc_node_validate(struct roff_man *mdoc)
                 if (n->sec != SEC_SYNOPSIS ||                  if (n->sec != SEC_SYNOPSIS ||
                     (np->tok != MDOC_Cd && np->tok != MDOC_Fd))                      (np->tok != MDOC_Cd && np->tok != MDOC_Fd))
                         check_text(mdoc, n->line, n->pos, n->string);                          check_text(mdoc, n->line, n->pos, n->string);
                 if (np->tok != MDOC_Ql && np->tok != MDOC_Dl &&                  if ((n->flags & NODE_NOFILL) == 0 &&
                     (np->tok != MDOC_Bd ||  
                      (mdoc->flags & MDOC_LITERAL) == 0) &&  
                     (np->tok != MDOC_It || np->type != ROFFT_HEAD ||                      (np->tok != MDOC_It || np->type != ROFFT_HEAD ||
                      np->parent->parent->norm->Bl.type != LIST_diag))                       np->parent->parent->norm->Bl.type != LIST_diag))
                         check_text_em(mdoc, n->line, n->pos, n->string);                          check_text_em(mdoc, n->line, n->pos, n->string);
Line 411  check_text(struct roff_man *mdoc, int ln, int pos, cha
Line 411  check_text(struct roff_man *mdoc, int ln, int pos, cha
 {  {
         char            *cp;          char            *cp;
   
         if (MDOC_LITERAL & mdoc->flags)          if (mdoc->last->flags & NODE_NOFILL)
                 return;                  return;
   
         for (cp = p; NULL != (p = strchr(p, '\t')); p++)          for (cp = p; NULL != (p = strchr(p, '\t')); p++)
Line 1092  post_st(POST_ARGS)
Line 1092  post_st(POST_ARGS)
 }  }
   
 static void  static void
   post_tg(POST_ARGS)
   {
           struct roff_node        *n, *nch;
           size_t                  len;
   
           n = mdoc->last;
           nch = n->child;
           if (nch == NULL && n->next != NULL &&
               n->next->child->type == ROFFT_TEXT) {
                   mdoc->next = ROFF_NEXT_CHILD;
                   roff_word_alloc(mdoc, n->line, n->pos, n->next->child->string);
                   nch = mdoc->last;
                   nch->flags |= NODE_NOSRC;
                   mdoc->last = n;
           }
           if (nch == NULL || *nch->string == '\0') {
                   mandoc_msg(MANDOCERR_MACRO_EMPTY, n->line, n->pos, "Tg");
                   roff_node_delete(mdoc, n);
                   return;
           }
           len = strcspn(nch->string, " \t");
           if (nch->string[len] != '\0')
                   mandoc_msg(MANDOCERR_TG_SPC, nch->line, nch->pos + len + 1,
                       "Tg %s", nch->string);
           if (nch->next != NULL) {
                   mandoc_msg(MANDOCERR_ARG_EXCESS, nch->next->line,
                       nch->next->pos, "Tg ... %s", nch->next->string);
                   while (nch->next != NULL)
                           roff_node_delete(mdoc, nch->next);
           }
           if (nch->string[len] != '\0')
                   roff_node_delete(mdoc, n);
   }
   
   static void
 post_obsolete(POST_ARGS)  post_obsolete(POST_ARGS)
 {  {
         struct roff_node *n;          struct roff_node *n;
Line 1188  post_fname(POST_ARGS)
Line 1223  post_fname(POST_ARGS)
         size_t                   pos;          size_t                   pos;
   
         n = mdoc->last->child;          n = mdoc->last->child;
         pos = strcspn(n->string, "()");          cp = n->string;
         cp = n->string + pos;          if (*cp == '(') {
         if ( ! (cp[0] == '\0' || (cp[0] == '(' && cp[1] == '*')))                  if (cp[strlen(cp + 1)] == ')')
                 mandoc_msg(MANDOCERR_FN_PAREN, n->line, n->pos + pos,                          return;
                     "%s", n->string);                  pos = 0;
           } else {
                   pos = strcspn(cp, "()");
                   if (cp[pos] == '\0')
                           return;
           }
           mandoc_msg(MANDOCERR_FN_PAREN, n->line, n->pos + pos, "%s", cp);
 }  }
   
 static void  static void
Line 1583  post_it(POST_ARGS)
Line 1624  post_it(POST_ARGS)
                         mandoc_msg(MANDOCERR_BL_COL, nit->line, nit->pos,                          mandoc_msg(MANDOCERR_BL_COL, nit->line, nit->pos,
                             "%d columns, %d cells", cols, i);                              "%d columns, %d cells", cols, i);
                 else if (nit->head->next->child != NULL &&                  else if (nit->head->next->child != NULL &&
                     nit->head->next->child->line > nit->line)                      nit->head->next->child->flags & NODE_LINE)
                         mandoc_msg(MANDOCERR_IT_NOARG,                          mandoc_msg(MANDOCERR_IT_NOARG,
                             nit->line, nit->pos, "Bl -column It");                              nit->line, nit->pos, "Bl -column It");
                 break;                  break;
Line 1750  post_bl(POST_ARGS)
Line 1791  post_bl(POST_ARGS)
         while (nchild != NULL) {          while (nchild != NULL) {
                 nnext = nchild->next;                  nnext = nchild->next;
                 if (nchild->tok == MDOC_It ||                  if (nchild->tok == MDOC_It ||
                     (nchild->tok == MDOC_Sm &&                      ((nchild->tok == MDOC_Sm || nchild->tok == MDOC_Tg) &&
                      nnext != NULL && nnext->tok == MDOC_It)) {                       nnext != NULL && nnext->tok == MDOC_It)) {
                         nchild = nnext;                          nchild = nnext;
                         continue;                          continue;
Line 1900  post_sm(POST_ARGS)
Line 1941  post_sm(POST_ARGS)
 static void  static void
 post_root(POST_ARGS)  post_root(POST_ARGS)
 {  {
         const char *openbsd_arch[] = {  
                 "alpha", "amd64", "arm64", "armv7", "hppa", "i386",  
                 "landisk", "loongson", "luna88k", "macppc", "mips64",  
                 "octeon", "sgi", "socppc", "sparc64", NULL  
         };  
         const char *netbsd_arch[] = {  
                 "acorn26", "acorn32", "algor", "alpha", "amiga",  
                 "arc", "atari",  
                 "bebox", "cats", "cesfic", "cobalt", "dreamcast",  
                 "emips", "evbarm", "evbmips", "evbppc", "evbsh3", "evbsh5",  
                 "hp300", "hpcarm", "hpcmips", "hpcsh", "hppa",  
                 "i386", "ibmnws", "luna68k",  
                 "mac68k", "macppc", "mipsco", "mmeye", "mvme68k", "mvmeppc",  
                 "netwinder", "news68k", "newsmips", "next68k",  
                 "pc532", "playstation2", "pmax", "pmppc", "prep",  
                 "sandpoint", "sbmips", "sgimips", "shark",  
                 "sparc", "sparc64", "sun2", "sun3",  
                 "vax", "walnut", "x68k", "x86", "x86_64", "xen", NULL  
         };  
         const char **arches[] = { NULL, netbsd_arch, openbsd_arch };  
   
         struct roff_node *n;          struct roff_node *n;
         const char **arch;  
   
         /* Add missing prologue data. */          /* Add missing prologue data. */
   
         if (mdoc->meta.date == NULL)          if (mdoc->meta.date == NULL)
                 mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :                  mdoc->meta.date = mandoc_normdate(NULL, NULL);
                     mandoc_normdate(mdoc, NULL, 0, 0);  
   
         if (mdoc->meta.title == NULL) {          if (mdoc->meta.title == NULL) {
                 mandoc_msg(MANDOCERR_DT_NOTITLE, 0, 0, "EOF");                  mandoc_msg(MANDOCERR_DT_NOTITLE, 0, 0, "EOF");
Line 1948  post_root(POST_ARGS)
Line 1966  post_root(POST_ARGS)
                     "(OpenBSD)" : "(NetBSD)");                      "(OpenBSD)" : "(NetBSD)");
   
         if (mdoc->meta.arch != NULL &&          if (mdoc->meta.arch != NULL &&
             (arch = arches[mdoc->meta.os_e]) != NULL) {              arch_valid(mdoc->meta.arch, mdoc->meta.os_e) == 0) {
                 while (*arch != NULL && strcmp(*arch, mdoc->meta.arch))                  n = mdoc->meta.first->child;
                         arch++;                  while (n->tok != MDOC_Dt ||
                 if (*arch == NULL) {                      n->child == NULL ||
                         n = mdoc->meta.first->child;                      n->child->next == NULL ||
                         while (n->tok != MDOC_Dt ||                      n->child->next->next == NULL)
                             n->child == NULL ||                          n = n->next;
                             n->child->next == NULL ||                  n = n->child->next->next;
                             n->child->next->next == NULL)                  mandoc_msg(MANDOCERR_ARCH_BAD, n->line, n->pos,
                                 n = n->next;                      "Dt ... %s %s", mdoc->meta.arch,
                         n = n->child->next->next;                      mdoc->meta.os_e == MANDOC_OS_OPENBSD ?
                         mandoc_msg(MANDOCERR_ARCH_BAD, n->line, n->pos,                      "(OpenBSD)" : "(NetBSD)");
                             "Dt ... %s %s", mdoc->meta.arch,  
                             mdoc->meta.os_e == MANDOC_OS_OPENBSD ?  
                             "(OpenBSD)" : "(NetBSD)");  
                 }  
         }          }
   
         /* Check that we begin with a proper `Sh'. */          /* Check that we begin with a proper `Sh'. */
Line 2530  static void
Line 2544  static void
 post_dd(POST_ARGS)  post_dd(POST_ARGS)
 {  {
         struct roff_node *n;          struct roff_node *n;
         char             *datestr;  
   
         n = mdoc->last;          n = mdoc->last;
         n->flags |= NODE_NOPRT;          n->flags |= NODE_NOPRT;
Line 2547  post_dd(POST_ARGS)
Line 2560  post_dd(POST_ARGS)
                 mandoc_msg(MANDOCERR_PROLOG_ORDER,                  mandoc_msg(MANDOCERR_PROLOG_ORDER,
                     n->line, n->pos, "Dd after Os");                      n->line, n->pos, "Dd after Os");
   
         if (n->child == NULL || n->child->string[0] == '\0') {          if (mdoc->quick && n != NULL)
                 mdoc->meta.date = mdoc->quick ? mandoc_strdup("") :                  mdoc->meta.date = mandoc_strdup("");
                     mandoc_normdate(mdoc, NULL, n->line, n->pos);          else
                 return;                  mdoc->meta.date = mandoc_normdate(n->child, n);
         }  
   
         datestr = NULL;  
         deroff(&datestr, n);  
         if (mdoc->quick)  
                 mdoc->meta.date = datestr;  
         else {  
                 mdoc->meta.date = mandoc_normdate(mdoc,  
                     datestr, n->line, n->pos);  
                 free(datestr);  
         }  
 }  }
   
 static void  static void

Legend:
Removed from v.1.366  
changed lines
  Added in v.1.377

CVSweb