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

Diff for /mandoc/Attic/macro.c between version 1.51 and 1.57

version 1.51, 2009/02/23 12:45:19 version 1.57, 2009/03/06 14:13:47
Line 31 
Line 31 
  * macro.   * macro.
  */   */
   
   /*
    * FIXME: don't use static mdoc_argv values, as they require us to do a
    * complicated copy-over when actually assigning them to dynamic memory.
    */
   
 #include "private.h"  #include "private.h"
   
 static int        macro_obsolete(MACRO_PROT_ARGS);  static int        macro_obsolete(MACRO_PROT_ARGS);
Line 170  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
Line 175  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
         { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Xo */          { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Xo */
         /* XXX - .Fo supposed to be (but isn't) callable. */          /* XXX - .Fo supposed to be (but isn't) callable. */
         { macro_scoped, MDOC_EXPLICIT }, /* Fo */          { macro_scoped, MDOC_EXPLICIT }, /* Fo */
         /* XXX - .Fc supposed to be (but isn't) callable. */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Fc */
         { macro_scoped_close, MDOC_EXPLICIT }, /* Fc */  
         { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Oo */          { macro_constant_scoped, MDOC_CALLABLE | MDOC_PARSED | MDOC_EXPLICIT }, /* Oo */
         { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Oc */          { macro_scoped_close, MDOC_EXPLICIT | MDOC_CALLABLE | MDOC_PARSED }, /* Oc */
         { macro_scoped, MDOC_EXPLICIT }, /* Bk */          { macro_scoped, MDOC_EXPLICIT }, /* Bk */
Line 180  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
Line 184  const struct mdoc_macro __mdoc_macros[MDOC_MAX] = {
         { macro_constant, 0 }, /* Hf */          { macro_constant, 0 }, /* Hf */
         { macro_obsolete, 0 }, /* Fr */          { macro_obsolete, 0 }, /* Fr */
         { macro_constant, 0 }, /* Ud */          { macro_constant, 0 }, /* Ud */
           { macro_constant, 0 }, /* Lb */
 };  };
   
 const   struct mdoc_macro * const mdoc_macros = __mdoc_macros;  const   struct mdoc_macro * const mdoc_macros = __mdoc_macros;
Line 518  rewind_subblock(enum mdoc_type type, struct mdoc *mdoc
Line 523  rewind_subblock(enum mdoc_type type, struct mdoc *mdoc
                         break;                          break;
                 else if (rewind_dobreak(tok, n))                  else if (rewind_dobreak(tok, n))
                         continue;                          continue;
                 return(mdoc_perr(mdoc, line, ppos, "scope breaks prior %s", mdoc_node2a(n)));                  return(mdoc_perr(mdoc, line, ppos,
                           "scope breaks %s", MDOC_ROOT == n->type ?
                           "<root>" : mdoc_macronames[n->tok]));
         }          }
   
         assert(n);          assert(n);
Line 542  rewind_expblock(struct mdoc *mdoc, int tok, int line, 
Line 549  rewind_expblock(struct mdoc *mdoc, int tok, int line, 
                 else if (rewind_dobreak(tok, n))                  else if (rewind_dobreak(tok, n))
                         continue;                          continue;
                 return(mdoc_perr(mdoc, line, ppos,                  return(mdoc_perr(mdoc, line, ppos,
                                         "scope breaks prior %s",                          "scope breaks %s", MDOC_ROOT == n->type ?
                                         mdoc_node2a(n)));                          "<root>" : mdoc_macronames[n->tok]));
         }          }
   
         assert(n);          assert(n);
Line 567  rewind_impblock(struct mdoc *mdoc, int tok, int line, 
Line 574  rewind_impblock(struct mdoc *mdoc, int tok, int line, 
                 else if (rewind_dobreak(tok, n))                  else if (rewind_dobreak(tok, n))
                         continue;                          continue;
                 return(mdoc_perr(mdoc, line, ppos,                  return(mdoc_perr(mdoc, line, ppos,
                                         "scope breaks prior %s",                          "scope breaks %s", MDOC_ROOT == n->type ?
                                         mdoc_node2a(n)));                          "<root>" : mdoc_macronames[n->tok]));
         }          }
   
         assert(n);          assert(n);
Line 751  macro_text(MACRO_PROT_ARGS)
Line 758  macro_text(MACRO_PROT_ARGS)
                 return(perr(mdoc, line, ppos, EARGVLIM));                  return(perr(mdoc, line, ppos, EARGVLIM));
         }          }
   
         c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);          c = mdoc_elem_alloc(mdoc, line, ppos,
                           tok, (size_t)argc, argv);
   
         if (0 == c) {          if (0 == c) {
                 mdoc_argv_free(argc, argv);                  mdoc_argv_free(argc, argv);
Line 796  macro_text(MACRO_PROT_ARGS)
Line 804  macro_text(MACRO_PROT_ARGS)
                         return(0);                          return(0);
                 }                  }
   
                   /* FIXME: .Fl and .Ar handling of `|'. */
   
                 if (ARGS_QWORD != w && mdoc_isdelim(p)) {                  if (ARGS_QWORD != w && mdoc_isdelim(p)) {
                         if (0 == lastpunct && ! rewind_elem(mdoc, tok)) {                          if (0 == lastpunct && ! rewind_elem(mdoc, tok)) {
                                 mdoc_argv_free(argc, argv);                                  mdoc_argv_free(argc, argv);
Line 803  macro_text(MACRO_PROT_ARGS)
Line 813  macro_text(MACRO_PROT_ARGS)
                         }                          }
                         lastpunct = 1;                          lastpunct = 1;
                 } else if (lastpunct) {                  } else if (lastpunct) {
                         c = mdoc_elem_alloc(mdoc, line,                          c = mdoc_elem_alloc(mdoc, line, ppos,
                                         ppos, tok, argc, argv);                                          tok, (size_t)argc, argv);
                         if (0 == c) {                          if (0 == c) {
                                 mdoc_argv_free(argc, argv);                                  mdoc_argv_free(argc, argv);
                                 return(0);                                  return(0);
Line 922  macro_scoped(MACRO_PROT_ARGS)
Line 932  macro_scoped(MACRO_PROT_ARGS)
   
                 if (ARGS_ERROR == c)                  if (ARGS_ERROR == c)
                         return(0);                          return(0);
                 if (ARGS_PUNCT == c)  
                         break;  
                 if (ARGS_EOLN == c)                  if (ARGS_EOLN == c)
                         break;                          break;
   
                 if (ARGS_PHRASE == c) {                  if (ARGS_PHRASE == c) {
                         /*                          /*
                         if ( ! mdoc_phrase(mdoc, line, lastarg, buf))                          if ( ! mdoc_phrase(mdoc, line, lastarg, buf))
Line 953  macro_scoped(MACRO_PROT_ARGS)
Line 960  macro_scoped(MACRO_PROT_ARGS)
                 break;                  break;
         }          }
   
         if ( ! rewind_subblock(MDOC_HEAD, mdoc, tok, line, ppos))  
                 return(0);  
         if (1 == ppos && ! append_delims(mdoc, line, pos, buf))          if (1 == ppos && ! append_delims(mdoc, line, pos, buf))
                 return(0);                  return(0);
           if ( ! rewind_subblock(MDOC_HEAD, mdoc, tok, line, ppos))
                   return(0);
   
         if ( ! mdoc_body_alloc(mdoc, line, ppos, tok))          if ( ! mdoc_body_alloc(mdoc, line, ppos, tok))
                 return(0);                  return(0);
Line 1179  static int
Line 1186  static int
 macro_constant_delimited(MACRO_PROT_ARGS)  macro_constant_delimited(MACRO_PROT_ARGS)
 {  {
         int               lastarg, flushed, j, c, maxargs, argc,          int               lastarg, flushed, j, c, maxargs, argc,
                           igndelim;                            igndelim, ignargs;
         struct mdoc_arg   argv[MDOC_LINEARG_MAX];          struct mdoc_arg   argv[MDOC_LINEARG_MAX];
         char             *p;          char             *p;
   
         lastarg = ppos;          lastarg = ppos;
         flushed = 0;          flushed = 0;
   
   
           /*
            * Maximum arguments per macro.  Some of these have none and
            * exit as soon as they're parsed.
            */
   
         switch (tok) {          switch (tok) {
         case (MDOC_No):          case (MDOC_No):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (MDOC_Ns):          case (MDOC_Ns):
                 /* FALLTHROUGH */                  /* FALLTHROUGH */
         case (MDOC_Ux):          case (MDOC_Ux):
                 /* FALLTHROUGH */  
         case (MDOC_St):  
                 maxargs = 0;                  maxargs = 0;
                 break;                  break;
         default:          default:
Line 1201  macro_constant_delimited(MACRO_PROT_ARGS)
Line 1212  macro_constant_delimited(MACRO_PROT_ARGS)
                 break;                  break;
         }          }
   
           /*
            * Whether to ignore delimiter characters.  `Pf' accepts its
            * first token as a parameter no matter what it looks like (if
            * it's text).
            */
   
         switch (tok) {          switch (tok) {
         case (MDOC_Pf):          case (MDOC_Pf):
                 igndelim = 1;                  igndelim = 1;
Line 1210  macro_constant_delimited(MACRO_PROT_ARGS)
Line 1227  macro_constant_delimited(MACRO_PROT_ARGS)
                 break;                  break;
         }          }
   
         for (argc = 0; argc < MDOC_LINEARG_MAX; argc++) {          /*
                 lastarg = *pos;           * Whether to ignore arguments: `St', for example, handles its
                 c = mdoc_argv(mdoc, line, tok, &argv[argc], pos, buf);           * argument-like parameters as regular parameters.
                 if (ARGV_EOLN == c)           */
                         break;  
                 if (ARGV_WORD == c) {          switch (tok) {
                         *pos = lastarg;          case (MDOC_St):
                         break;                  ignargs = 1;
                 } else if (ARGV_ARG == c)                  break;
                         continue;          default:
                 mdoc_argv_free(argc, argv);                  ignargs = 0;
                 return(0);                  break;
         }          }
   
           argc = 0;
   
           if ( ! ignargs)
                   for ( ; argc < MDOC_LINEARG_MAX; argc++) {
                           lastarg = *pos;
                           c = mdoc_argv(mdoc, line, tok,
                                           &argv[argc], pos, buf);
                           if (ARGV_EOLN == c)
                                   break;
                           if (ARGV_WORD == c) {
                                   *pos = lastarg;
                                   break;
                           } else if (ARGV_ARG == c)
                                   continue;
                           mdoc_argv_free(argc, argv);
                           return(0);
                   }
   
         if (MDOC_LINEARG_MAX == argc) {          if (MDOC_LINEARG_MAX == argc) {
                 mdoc_argv_free(argc - 1, argv);                  mdoc_argv_free(argc - 1, argv);
                 return(perr(mdoc, line, ppos, EARGVLIM));                  return(perr(mdoc, line, ppos, EARGVLIM));
         }          }
   
         c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);          c = mdoc_elem_alloc(mdoc, line, ppos,
                           tok, (size_t)argc, argv);
   
         mdoc_argv_free(argc, argv);          mdoc_argv_free(argc, argv);
   
         if (0 == c)          if (0 == c)
Line 1320  macro_constant(MACRO_PROT_ARGS)
Line 1357  macro_constant(MACRO_PROT_ARGS)
                 return(perr(mdoc, line, ppos, EARGVLIM));                  return(perr(mdoc, line, ppos, EARGVLIM));
         }          }
   
         c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);          c = mdoc_elem_alloc(mdoc, line, ppos,
                           tok, (size_t)argc, argv);
   
         mdoc_argv_free(argc, argv);          mdoc_argv_free(argc, argv);
   
         if (0 == c)          if (0 == c)

Legend:
Removed from v.1.51  
changed lines
  Added in v.1.57

CVSweb