[BACK]Return to roff.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / mandoc

Diff for /mandoc/roff.c between version 1.52 and 1.54

version 1.52, 2008/12/08 16:29:57 version 1.54, 2008/12/09 00:27:17
Line 84  static int    rofffindcallable(const char *);
Line 84  static int    rofffindcallable(const char *);
 static  int               roffismsec(const char *);  static  int               roffismsec(const char *);
 static  int               roffissec(const char **);  static  int               roffissec(const char **);
 static  int               roffispunct(const char *);  static  int               roffispunct(const char *);
   static  int               roffisatt(const char *);
 static  int               roffchecksec(struct rofftree *,  static  int               roffchecksec(struct rofftree *,
                                 const char *, int);                                  const char *, int);
 static  int               roffargs(const struct rofftree *,  static  int               roffargs(const struct rofftree *,
Line 126  roff_free(struct rofftree *tree, int flush)
Line 127  roff_free(struct rofftree *tree, int flush)
         error = 1;          error = 1;
   
         if (ROFF_PRELUDE & tree->state) {          if (ROFF_PRELUDE & tree->state) {
                 roff_err(tree, NULL, "prelude never finished");                  (void)roff_err(tree, NULL, "prelude never finished");
                 goto end;                  goto end;
         } else if ( ! (ROFFSec_NAME & tree->asec)) {          } else if ( ! (ROFFSec_NAME & tree->asec)) {
                 roff_err(tree, NULL, "missing `NAME' section");                  (void)roff_err(tree, NULL, "missing `NAME' section");
                 goto end;                  goto end;
         } else if ( ! (ROFFSec_NMASK & tree->asec))          } else if ( ! (ROFFSec_NMASK & tree->asec))
                 roff_warn(tree, NULL, "missing suggested `NAME', "                  roff_warn(tree, NULL, "missing suggested `NAME', "
Line 138  roff_free(struct rofftree *tree, int flush)
Line 139  roff_free(struct rofftree *tree, int flush)
         for (n = tree->last; n; n = n->parent) {          for (n = tree->last; n; n = n->parent) {
                 if (0 != tokens[n->tok].ctx)                  if (0 != tokens[n->tok].ctx)
                         continue;                          continue;
                 roff_err(tree, NULL, "closing explicit scope `%s'",                  (void)roff_err(tree, NULL, "closing explicit scope "
                                 toknames[n->tok]);                                  "`%s'", toknames[n->tok]);
                 goto end;                  goto end;
         }          }
   
Line 193  roff_engine(struct rofftree *tree, char *buf)
Line 194  roff_engine(struct rofftree *tree, char *buf)
         tree->cur = buf;          tree->cur = buf;
         assert(buf);          assert(buf);
   
         if (0 == *buf) {          if (0 == *buf)
                 roff_err(tree, buf, "blank line");                  return(roff_err(tree, buf, "blank line"));
                 return(0);          else if ('.' != *buf)
         } else if ('.' != *buf)  
                 return(textparse(tree, buf));                  return(textparse(tree, buf));
   
         return(roffparse(tree, buf));          return(roffparse(tree, buf));
Line 210  textparse(struct rofftree *tree, char *buf)
Line 210  textparse(struct rofftree *tree, char *buf)
   
         /* TODO: literal parsing. */          /* TODO: literal parsing. */
   
         if ( ! (ROFF_BODY & tree->state)) {          if ( ! (ROFF_BODY & tree->state))
                 roff_err(tree, buf, "data not in body");                  return(roff_err(tree, buf, "data not in body"));
                 return(0);  
         }  
   
         /* LINTED */          /* LINTED */
         while (*buf) {          while (*buf) {
Line 269  roffargs(const struct rofftree *tree, 
Line 267  roffargs(const struct rofftree *tree, 
                         argv[i] = ++buf;                          argv[i] = ++buf;
                         while (*buf && '\"' != *buf)                          while (*buf && '\"' != *buf)
                                 buf++;                                  buf++;
                         if (0 == *buf) {                          if (0 == *buf)
                                 roff_err(tree, argv[i], "unclosed "                                  return(roff_err(tree, argv[i],
                                                 "quote in argument "                                          "unclosed quote in arg list"));
                                                 "list for `%s'",  
                                                 toknames[tok]);  
                                 return(0);  
                         }  
                 } else {                  } else {
                         argv[i] = buf++;                          argv[i] = buf++;
                         while (*buf) {                          while (*buf) {
Line 298  roffargs(const struct rofftree *tree, 
Line 292  roffargs(const struct rofftree *tree, 
         }          }
   
         assert(i > 0);          assert(i > 0);
         if (ROFF_MAXLINEARG == i && *buf) {          if (ROFF_MAXLINEARG == i && *buf)
                 roff_err(tree, p, "too many arguments for `%s'", toknames                  return(roff_err(tree, p, "too many args"));
                                 [tok]);  
                 return(0);  
         }  
   
         argv[i] = NULL;          argv[i] = NULL;
         return(1);          return(1);
Line 336  roffparse(struct rofftree *tree, char *buf)
Line 327  roffparse(struct rofftree *tree, char *buf)
                 if (0 == strncmp(buf, ".\\\"", 3))                  if (0 == strncmp(buf, ".\\\"", 3))
                         return(1);                          return(1);
   
         if (ROFF_MAX == (tok = rofffindtok(buf + 1))) {          if (ROFF_MAX == (tok = rofffindtok(buf + 1)))
                 roff_err(tree, buf, "bogus line macro");                  return(roff_err(tree, buf, "bogus line macro"));
           else if ( ! roffargs(tree, tok, buf, argv))
                 return(0);                  return(0);
         } else if ( ! roffargs(tree, tok, buf, argv))  
                 return(0);  
   
         argvp = (char **)argv;          argvp = (char **)argv;
   
Line 361  roffparse(struct rofftree *tree, char *buf)
Line 351  roffparse(struct rofftree *tree, char *buf)
          */           */
   
         if (tree->last && ! roffscan          if (tree->last && ! roffscan
                         (tree->last->tok, tokens[tok].parents)) {                          (tree->last->tok, tokens[tok].parents))
                 roff_err(tree, *argvp, "`%s' has invalid parent `%s'",                  return(roff_err(tree, *argvp, "`%s' has invalid "
                                 toknames[tok],                                          "parent `%s'", toknames[tok],
                                 toknames[tree->last->tok]);                                          toknames[tree->last->tok]));
                 return(0);  
         }  
   
         if (tree->last && ! roffscan          if (tree->last && ! roffscan
                         (tok, tokens[tree->last->tok].children)) {                          (tok, tokens[tree->last->tok].children))
                 roff_err(tree, *argvp, "`%s' is invalid child of `%s'",                  return(roff_err(tree, *argvp, "`%s' has invalid "
                                 toknames[tok],                                          "child `%s'", toknames[tok],
                                 toknames[tree->last->tok]);                                          toknames[tree->last->tok]));
                 return(0);  
         }  
   
         /*          /*
          * Branch if we're not a layout token.           * Branch if we're not a layout token.
Line 414  roffparse(struct rofftree *tree, char *buf)
Line 400  roffparse(struct rofftree *tree, char *buf)
                         }                          }
                         if (tokens[n->tok].ctx == n->tok)                          if (tokens[n->tok].ctx == n->tok)
                                 continue;                                  continue;
                         roff_err(tree, *argv, "`%s' breaks `%s' scope",                          return(roff_err(tree, *argv, "`%s' breaks "
                                         toknames[tok], toknames[n->tok]);                                                  "scope of prior`%s'",
                         return(0);                                                  toknames[tok],
                                                   toknames[n->tok]));
                 }                  }
   
                 /*                  /*
Line 457  roffparse(struct rofftree *tree, char *buf)
Line 444  roffparse(struct rofftree *tree, char *buf)
                 if (n->tok != tokens[tok].ctx) {                  if (n->tok != tokens[tok].ctx) {
                         if (n->tok == tokens[n->tok].ctx)                          if (n->tok == tokens[n->tok].ctx)
                                 continue;                                  continue;
                         roff_err(tree, *argv, "`%s' breaks `%s' scope",                          return(roff_err(tree, *argv, "`%s' breaks "
                                         toknames[tok], toknames[n->tok]);                                                  "scope of prior `%s'",
                         return(0);                                                  toknames[tok],
                                                   toknames[n->tok]));
                 } else                  } else
                         break;                          break;
   
           if (NULL == n)
                   return(roff_err(tree, *argv, "`%s' has no starting "
                                           "tag `%s'", toknames[tok],
                                           toknames[tokens[tok].ctx]));
   
         if (NULL == n) {  
                 roff_err(tree, *argv, "`%s' has no starting tag `%s'",  
                                 toknames[tok],  
                                 toknames[tokens[tok].ctx]);  
                 return(0);  
         }  
   
         /* LINTED */          /* LINTED */
         do {          do {
                 t = tree->last->tok;                  t = tree->last->tok;
Line 596  roffchecksec(struct rofftree *tree, const char *start,
Line 581  roffchecksec(struct rofftree *tree, const char *start,
 }  }
   
   
   /* FIXME: move this into literals.c. */
 static int  static int
 roffissec(const char **p)  roffissec(const char **p)
 {  {
Line 644  roffissec(const char **p)
Line 630  roffissec(const char **p)
 }  }
   
   
   /* FIXME: move this into literals.c. */
 static int  static int
 roffismsec(const char *p)  roffismsec(const char *p)
 {  {
Line 679  roffismsec(const char *p)
Line 666  roffismsec(const char *p)
 }  }
   
   
   /* FIXME: move this into literals.c. */
 static int  static int
   roffisatt(const char *p)
   {
   
           assert(p);
           if (0 == strcmp(p, "v1"))
                   return(1);
           else if (0 == strcmp(p, "v2"))
                   return(1);
           else if (0 == strcmp(p, "v3"))
                   return(1);
           else if (0 == strcmp(p, "v6"))
                   return(1);
           else if (0 == strcmp(p, "v7"))
                   return(1);
           else if (0 == strcmp(p, "32v"))
                   return(1);
           else if (0 == strcmp(p, "V.1"))
                   return(1);
           else if (0 == strcmp(p, "V.4"))
                   return(1);
   
           return(0);
   }
   
   
   /* FIXME: move this into literals.c (or similar). */
   static int
 roffispunct(const char *p)  roffispunct(const char *p)
 {  {
   
Line 788  roffspecial(struct rofftree *tree, int tok, const char
Line 803  roffspecial(struct rofftree *tree, int tok, const char
         case (ROFF_At):          case (ROFF_At):
                 if (0 == sz)                  if (0 == sz)
                         break;                          break;
                 if (0 == strcmp(*ordp, "v1"))                  if (roffisatt(*ordp))
                         break;                          break;
                 else if (0 == strcmp(*ordp, "v2"))                  return(roff_err(tree, *ordp, "invalid `At' arg"));
                         break;  
                 else if (0 == strcmp(*ordp, "v3"))  
                         break;  
                 else if (0 == strcmp(*ordp, "v6"))  
                         break;  
                 else if (0 == strcmp(*ordp, "v7"))  
                         break;  
                 else if (0 == strcmp(*ordp, "32v"))  
                         break;  
                 else if (0 == strcmp(*ordp, "V.1"))  
                         break;  
                 else if (0 == strcmp(*ordp, "V.4"))  
                         break;  
                 roff_err(tree, *ordp, "invalid `At' arg");  
                 return(0);  
   
         case (ROFF_Xr):          case (ROFF_Xr):
                 if (2 == sz) {                  if (2 == sz) {
Line 822  roffspecial(struct rofftree *tree, int tok, const char
Line 822  roffspecial(struct rofftree *tree, int tok, const char
         case (ROFF_Fn):          case (ROFF_Fn):
                 if (0 != sz)                  if (0 != sz)
                         break;                          break;
                 roff_err(tree, start, "`%s' expects at least "                  return(roff_err(tree, start, "`%s' expects at least "
                                 "one arg", toknames[tok]);                                          "one arg", toknames[tok]));
                 return(0);  
   
         case (ROFF_Nm):          case (ROFF_Nm):
                 if (0 == sz) {                  if (0 == sz) {
Line 1291  static int
Line 1290  static int
 roff_layout(ROFFCALL_ARGS)  roff_layout(ROFFCALL_ARGS)
 {  {
         int              i, c, argcp[ROFF_MAXLINEARG];          int              i, c, argcp[ROFF_MAXLINEARG];
         char            *argvp[ROFF_MAXLINEARG];          char            *argvp[ROFF_MAXLINEARG], *p;
   
         /*          /*
          * The roff_layout function is for multi-line macros.  A layout           * The roff_layout function is for multi-line macros.  A layout
Line 1320  roff_layout(ROFFCALL_ARGS) 
Line 1319  roff_layout(ROFFCALL_ARGS) 
   
         assert( ! (ROFF_CALLABLE & tokens[tok].flags));          assert( ! (ROFF_CALLABLE & tokens[tok].flags));
   
         ++argv;          p = *argv++;
   
         if ( ! roffparseopts(tree, tok, &argv, argcp, argvp))          if ( ! roffparseopts(tree, tok, &argv, argcp, argvp))
                 return(0);                  return(0);

Legend:
Removed from v.1.52  
changed lines
  Added in v.1.54

CVSweb