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

Diff for /mandoc/roff.c between version 1.44 and 1.50

version 1.44, 2008/12/06 13:18:44 version 1.50, 2008/12/07 22:40:18
Line 92  static int     roffparse(struct rofftree *, char *);
Line 92  static int     roffparse(struct rofftree *, char *);
 static  int               textparse(struct rofftree *, char *);  static  int               textparse(struct rofftree *, char *);
 static  int               roffdata(struct rofftree *, int, char *);  static  int               roffdata(struct rofftree *, int, char *);
 static  int               roffspecial(struct rofftree *, int,  static  int               roffspecial(struct rofftree *, int,
                                 const char *, size_t, char **);                                  const char *, const int *,
                                   const char **, size_t, char **);
 static  int               roffsetname(struct rofftree *, char **);  static  int               roffsetname(struct rofftree *, char **);
   
 #ifdef __linux__  #ifdef __linux__
Line 618  roffnode_free(struct rofftree *tree)
Line 619  roffnode_free(struct rofftree *tree)
   
   
 static int  static int
 roffspecial(struct rofftree *tree, int tok,  roffspecial(struct rofftree *tree, int tok, const char *start,
                 const char *start, size_t sz, char **ordp)                  const int *argc, const char **argv,
                   size_t sz, char **ordp)
 {  {
   
         switch (tok) {          switch (tok) {
           case (ROFF_At):
                   if (0 == sz)
                           break;
                   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, start, "invalid `At' arg");
                   return(0);
   
           case (ROFF_Xr):
                   /* FALLTHROUGH */
           case (ROFF_Fn):
                   if (0 != sz)
                           break;
                   roff_err(tree, start, "`%s' expects at least "
                                   "one arg", toknames[tok]);
                   return(0);
   
         case (ROFF_Nm):          case (ROFF_Nm):
                 if (0 == sz) {                  if (0 == sz) {
                         if (0 == tree->name[0]) {                          if (0 == tree->name[0]) {
Line 635  roffspecial(struct rofftree *tree, int tok, 
Line 662  roffspecial(struct rofftree *tree, int tok, 
                         return(0);                          return(0);
                 break;                  break;
   
           case (ROFF_Rv):
                   /* FALLTHROUGH*/
           case (ROFF_Sx):
                   /* FALLTHROUGH*/
         case (ROFF_Ex):          case (ROFF_Ex):
                 if (0 == sz) {                  if (1 == sz)
                         roff_err(tree, start, "`Ex' expects an arg");                          break;
                         return(0);                  roff_err(tree, start, "`%s' expects one arg",
                 } else if (1 != sz) {                                  toknames[tok]);
                         roff_err(tree, start, "`Ex' expects one arg");                  return(0);
                         return(0);  
                 }  
                 break;  
   
         case (ROFF_Sm):          case (ROFF_Sm):
                 if (0 == sz) {                  if (1 != sz) {
                         roff_err(tree, start, "`Sm' expects an arg");  
                         return(0);  
                 } else if (1 != sz) {  
                         roff_err(tree, start, "`Sm' expects one arg");                          roff_err(tree, start, "`Sm' expects one arg");
                         return(0);                          return(0);
                 }                  }
Line 660  roffspecial(struct rofftree *tree, int tok, 
Line 685  roffspecial(struct rofftree *tree, int tok, 
                         return(0);                          return(0);
                 }                  }
                 break;                  break;
   
           case (ROFF_Ud):
                   /* FALLTHROUGH */
           case (ROFF_Ux):
                   /* FALLTHROUGH */
           case (ROFF_Bt):
                   if (0 != sz) {
                           roff_err(tree, start, "`%s' expects no args",
                                           toknames[tok]);
                           return(0);
                   }
                   break;
         default:          default:
                 break;                  break;
         }          }
   
         return((*tree->cb.roffspecial)          return((*tree->cb.roffspecial)(tree->arg, tok, tree->cur,
                         (tree->arg, tok, tree->cur, ordp));                                  argc, argv, (const char **)ordp));
 }  }
   
   
Line 953  roffsetname(struct rofftree *tree, char **ordp)
Line 990  roffsetname(struct rofftree *tree, char **ordp)
   
   
 /* ARGSUSED */  /* ARGSUSED */
 static int  
 roff_Sm(ROFFCALL_ARGS)  
 {  
         char            *ordp[1], *p;  
   
         p = *argv++;  
         *ordp = *argv;  
   
         return(roffspecial(tree, tok, p, *ordp ? 1 : 0, ordp));  
 }  
   
   
 /* ARGSUSED */  
 static  int  static  int
 roff_Ns(ROFFCALL_ARGS)  roff_Ns(ROFFCALL_ARGS)
 {  {
Line 975  roff_Ns(ROFFCALL_ARGS)
Line 999  roff_Ns(ROFFCALL_ARGS)
         first = (*argv++ == tree->cur);          first = (*argv++ == tree->cur);
         morep[0] = NULL;          morep[0] = NULL;
   
         if ( ! roffspecial(tree, tok, *argv, 0, morep))          if ( ! roffspecial(tree, tok, *argv, NULL, NULL, 0, morep))
                 return(0);                  return(0);
   
         while (*argv) {          while (*argv) {
Line 1094  roff_layout(ROFFCALL_ARGS) 
Line 1118  roff_layout(ROFFCALL_ARGS) 
          * the layout body is everything following until termination.           * the layout body is everything following until termination.
          */           */
   
         if ( ! (*tree->cb.roffblkin)(tree->arg, tok, argcp, argvp))          if ( ! (*tree->cb.roffblkin)(tree->arg, tok, argcp,
                                   (const char **)argvp))
                 return(0);                  return(0);
         if (NULL == *argv)          if (NULL == *argv)
                 return((*tree->cb.roffblkbodyin)                  return((*tree->cb.roffblkbodyin)
                                 (tree->arg, tok, argcp, argvp));                                  (tree->arg, tok, argcp,
                                    (const char **)argvp));
   
         if ( ! (*tree->cb.roffblkheadin)(tree->arg, tok, argcp, argvp))          if ( ! (*tree->cb.roffblkheadin)(tree->arg, tok, argcp,
                                   (const char **)argvp))
                 return(0);                  return(0);
   
         /*          /*
Line 1117  roff_layout(ROFFCALL_ARGS) 
Line 1144  roff_layout(ROFFCALL_ARGS) 
                 if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok))                  if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok))
                         return(0);                          return(0);
                 return((*tree->cb.roffblkbodyin)                  return((*tree->cb.roffblkbodyin)
                                 (tree->arg, tok, argcp, argvp));                                  (tree->arg, tok, argcp,
                                    (const char **)argvp));
         }          }
   
         /*          /*
Line 1148  roff_layout(ROFFCALL_ARGS) 
Line 1176  roff_layout(ROFFCALL_ARGS) 
                 if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok))                  if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok))
                         return(0);                          return(0);
                 return((*tree->cb.roffblkbodyin)                  return((*tree->cb.roffblkbodyin)
                                 (tree->arg, tok, argcp, argvp));                                  (tree->arg, tok, argcp,
                                    (const char **)argvp));
         }          }
   
         /*          /*
Line 1162  roff_layout(ROFFCALL_ARGS) 
Line 1191  roff_layout(ROFFCALL_ARGS) 
         if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok))          if ( ! (*tree->cb.roffblkheadout)(tree->arg, tok))
                 return(0);                  return(0);
         return((*tree->cb.roffblkbodyin)          return((*tree->cb.roffblkbodyin)
                         (tree->arg, tok, argcp, argvp));                          (tree->arg, tok, argcp,
                            (const char **)argvp));
 }  }
   
   
Line 1170  roff_layout(ROFFCALL_ARGS) 
Line 1200  roff_layout(ROFFCALL_ARGS) 
 static int  static int
 roff_ordered(ROFFCALL_ARGS)  roff_ordered(ROFFCALL_ARGS)
 {  {
         /* FIXME: the tail-switch statement is in two different places:  
          * consolidate. */  
         int              i, first, c, argcp[ROFF_MAXLINEARG];          int              i, first, c, argcp[ROFF_MAXLINEARG];
         char            *ordp[ROFF_MAXLINEARG], *p,          char            *ordp[ROFF_MAXLINEARG], *p,
                         *argvp[ROFF_MAXLINEARG];                          *argvp[ROFF_MAXLINEARG];
Line 1188  roff_ordered(ROFFCALL_ARGS) 
Line 1216  roff_ordered(ROFFCALL_ARGS) 
         if ( ! roffparseopts(tree, tok, &argv, argcp, argvp))          if ( ! roffparseopts(tree, tok, &argv, argcp, argvp))
                 return(0);                  return(0);
   
         if (NULL == *argv)          if (NULL == *argv) {
                 return(roffspecial(tree, tok, p, 0, ordp));                  ordp[0] = NULL;
                   return(roffspecial(tree, tok, p, argcp,
                                           (const char **)argvp, 0, ordp));
           }
   
         i = 0;          i = 0;
         while (*argv && i < ROFF_MAXLINEARG) {          while (*argv && i < ROFF_MAXLINEARG) {
                 c = rofffindcallable(*argv);                  c = ROFF_PARSED & tokens[tok].flags ?
                           rofffindcallable(*argv) : ROFF_MAX;
   
                 if (ROFF_MAX == c && ! roffispunct(*argv)) {                  if (ROFF_MAX == c && ! roffispunct(*argv)) {
                         ordp[i++] = *argv++;                          ordp[i++] = *argv++;
Line 1204  roff_ordered(ROFFCALL_ARGS) 
Line 1236  roff_ordered(ROFFCALL_ARGS) 
                 if (ROFF_MAX == c)                  if (ROFF_MAX == c)
                         break;                          break;
   
                 if ( ! roffspecial(tree, tok, p, (size_t)i, ordp))                  if ( ! roffspecial(tree, tok, p, argcp,
                                           (const char **)argvp,
                                           (size_t)i, ordp))
                         return(0);                          return(0);
   
                 return(roffcall(tree, c, ordp));                  return(roffcall(tree, c, argv));
         }          }
   
         assert(i != ROFF_MAXLINEARG);          assert(i != ROFF_MAXLINEARG);
         ordp[i] = NULL;          ordp[i] = NULL;
   
         if ( ! roffspecial(tree, tok, p, (size_t)i, ordp))          if ( ! roffspecial(tree, tok, p, argcp,
                                   (const char**)argvp,
                                   (size_t)i, ordp))
                 return(0);                  return(0);
   
         /* FIXME: error if there's stuff after the punctuation. */          /* FIXME: error if there's stuff after the punctuation. */
Line 1243  roff_text(ROFFCALL_ARGS) 
Line 1279  roff_text(ROFFCALL_ARGS) 
   
         if ( ! roffparseopts(tree, tok, &argv, argcp, argvp))          if ( ! roffparseopts(tree, tok, &argv, argcp, argvp))
                 return(0);                  return(0);
         if ( ! (*tree->cb.roffin)(tree->arg, tok, argcp, argvp))          if ( ! (*tree->cb.roffin)(tree->arg, tok, argcp,
                                   (const char **)argvp))
                 return(0);                  return(0);
         if (NULL == *argv)          if (NULL == *argv)
                 return((*tree->cb.roffout)(tree->arg, tok));                  return((*tree->cb.roffout)(tree->arg, tok));
Line 1262  roff_text(ROFFCALL_ARGS) 
Line 1299  roff_text(ROFFCALL_ARGS) 
          * terminating punctuation.  If we encounter it and all           * terminating punctuation.  If we encounter it and all
          * subsequent tokens are punctuation, then stop processing (the           * subsequent tokens are punctuation, then stop processing (the
          * line-dominant macro will print these tokens after closure).           * line-dominant macro will print these tokens after closure).
            * If the punctuation is followed by non-punctuation, then close
            * and re-open our scope, then continue.
          */           */
   
         i = 0;          i = 0;
Line 1293  roff_text(ROFFCALL_ARGS) 
Line 1332  roff_text(ROFFCALL_ARGS) 
                                 break;                                  break;
   
                 if (argv[j]) {                  if (argv[j]) {
                           if (ROFF_LSCOPE & tokens[tok].flags) {
                                   if ( ! roffdata(tree, 0, *argv++))
                                           return(0);
                                   continue;
                           }
                           if ( ! (*tree->cb.roffout)(tree->arg, tok))
                                   return(0);
                         if ( ! roffdata(tree, 0, *argv++))                          if ( ! roffdata(tree, 0, *argv++))
                                 return(0);                                  return(0);
                           if ( ! (*tree->cb.roffin)(tree->arg, tok,
                                                   argcp,
                                                   (const char **)argvp))
                                   return(0);
   
                           i = 0;
                         continue;                          continue;
                 }                  }
   

Legend:
Removed from v.1.44  
changed lines
  Added in v.1.50

CVSweb