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

Diff for /mandoc/Attic/macro.c between version 1.48 and 1.49

version 1.48, 2009/01/20 20:56:21 version 1.49, 2009/01/22 14:56:21
Line 80 
Line 80 
 #define REWIND_REWIND   (1 << 0)  #define REWIND_REWIND   (1 << 0)
 #define REWIND_NOHALT   (1 << 1)  #define REWIND_NOHALT   (1 << 1)
 #define REWIND_HALT     (1 << 2)  #define REWIND_HALT     (1 << 2)
   
 static  int       rewind_dohalt(int, enum mdoc_type,  static  int       rewind_dohalt(int, enum mdoc_type,
                         const struct mdoc_node *);                          const struct mdoc_node *);
 static  int       rewind_alt(int);  static  int       rewind_alt(int);
Line 92  static int   rewind_subblock(enum mdoc_type, 
Line 93  static int   rewind_subblock(enum mdoc_type, 
 static  int       rewind_last(struct mdoc *, struct mdoc_node *);  static  int       rewind_last(struct mdoc *, struct mdoc_node *);
 static  int       append_delims(struct mdoc *, int, int *, char *);  static  int       append_delims(struct mdoc *, int, int *, char *);
 static  int       lookup(struct mdoc *, int, int, int, const char *);  static  int       lookup(struct mdoc *, int, int, int, const char *);
   static  int       pwarn(struct mdoc *, int, int, int);
   static  int       perr(struct mdoc *, int, int, int);
   
   #define WMACPARM        (1)
   #define WOBS            (2)
   
   #define ENOCTX          (1)
   #define ENOPARMS        (2)
   #define EARGVLIM        (3)
   
   
 static int  static int
   perr(struct mdoc *mdoc, int line, int pos, int type)
   {
           int              c;
   
           switch (type) {
           case (ENOCTX):
                   c = mdoc_perr(mdoc, line, pos,
                                   "closing macro has prior context");
                   break;
           case (ENOPARMS):
                   c = mdoc_perr(mdoc, line, pos,
                                   "macro doesn't expect parameters");
                   break;
           case (EARGVLIM):
                   c = mdoc_perr(mdoc, line, pos,
                                   "argument hard-limit %d reached",
                                   MDOC_LINEARG_MAX);
                   break;
           default:
                   abort();
                   /* NOTREACHED */
           }
           return(c);
   }
   
   static int
   pwarn(struct mdoc *mdoc, int line, int pos, int type)
   {
           int              c;
   
           switch (type) {
           case (WMACPARM):
                   c = mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX,
                                   "macro-like parameter");
                   break;
           case (WOBS):
                   c = mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX,
                                   "macro is marked obsolete");
                   break;
           default:
                   abort();
                   /* NOTREACHED */
           }
           return(c);
   }
   
   
   static int
 lookup(struct mdoc *mdoc, int line, int pos, int from, const char *p)  lookup(struct mdoc *mdoc, int line, int pos, int from, const char *p)
 {  {
         int              res;          int              res;
Line 104  lookup(struct mdoc *mdoc, int line, int pos, int from,
Line 162  lookup(struct mdoc *mdoc, int line, int pos, int from,
                 return(res);                  return(res);
         if (MDOC_MAX == res)          if (MDOC_MAX == res)
                 return(res);                  return(res);
         if ( ! mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX, "macro-like parameter"))          if ( ! pwarn(mdoc, line, pos, WMACPARM))
                 return(-1);                  return(-1);
         return(MDOC_MAX);          return(MDOC_MAX);
 }  }
Line 117  rewind_last(struct mdoc *mdoc, struct mdoc_node *to)
Line 175  rewind_last(struct mdoc *mdoc, struct mdoc_node *to)
         assert(to);          assert(to);
         mdoc->next = MDOC_NEXT_SIBLING;          mdoc->next = MDOC_NEXT_SIBLING;
   
           /* LINTED */
         while (mdoc->last != to) {          while (mdoc->last != to) {
                 if ( ! mdoc_valid_post(mdoc))                  if ( ! mdoc_valid_post(mdoc))
                         return(0);                          return(0);
Line 396  rewind_expblock(struct mdoc *mdoc, int tok, int line, 
Line 455  rewind_expblock(struct mdoc *mdoc, int tok, int line, 
         for (n = mdoc->last; n; n = n->parent) {          for (n = mdoc->last; n; n = n->parent) {
                 c = rewind_dohalt(tok, MDOC_BLOCK, n);                  c = rewind_dohalt(tok, MDOC_BLOCK, n);
                 if (REWIND_HALT == c)                  if (REWIND_HALT == c)
                         return(mdoc_perr(mdoc, line, ppos, "closing macro has no context"));                          return(perr(mdoc, line, ppos, ENOCTX));
                 if (REWIND_REWIND == c)                  if (REWIND_REWIND == c)
                         break;                          break;
                 else if (rewind_dobreak(tok, n))                  else if (rewind_dobreak(tok, n))
Line 444  append_delims(struct mdoc *mdoc, int line, int *pos, c
Line 503  append_delims(struct mdoc *mdoc, int line, int *pos, c
         for (;;) {          for (;;) {
                 lastarg = *pos;                  lastarg = *pos;
                 c = mdoc_args(mdoc, line, pos, buf, 0, &p);                  c = mdoc_args(mdoc, line, pos, buf, 0, &p);
                   assert(ARGS_PHRASE != c);
   
                 if (ARGS_ERROR == c)                  if (ARGS_ERROR == c)
                         return(0);                          return(0);
                 else if (ARGS_EOLN == c)                  else if (ARGS_EOLN == c)
Line 488  macro_scoped_close(MACRO_PROT_ARGS)
Line 549  macro_scoped_close(MACRO_PROT_ARGS)
                                 return(0);                                  return(0);
                         return(rewind_expblock(mdoc, tok, line, ppos));                          return(rewind_expblock(mdoc, tok, line, ppos));
                 }                  }
                 return(mdoc_perr(mdoc, line, ppos, "macro expects no parameters"));                  return(perr(mdoc, line, ppos, ENOPARMS));
         }          }
   
         if ( ! rewind_subblock(MDOC_BODY, mdoc, tok, line, ppos))          if ( ! rewind_subblock(MDOC_BODY, mdoc, tok, line, ppos))
Line 513  macro_scoped_close(MACRO_PROT_ARGS)
Line 574  macro_scoped_close(MACRO_PROT_ARGS)
                 }                  }
   
                 c = mdoc_args(mdoc, line, pos, buf, tok, &p);                  c = mdoc_args(mdoc, line, pos, buf, tok, &p);
                   assert(ARGS_PHRASE != c);
   
                 if (ARGS_ERROR == c)                  if (ARGS_ERROR == c)
                         return(0);                          return(0);
                 if (ARGS_PUNCT == c)                  if (ARGS_PUNCT == c)
Line 598  macro_text(MACRO_PROT_ARGS)
Line 661  macro_text(MACRO_PROT_ARGS)
   
         if (MDOC_LINEARG_MAX == argc) {          if (MDOC_LINEARG_MAX == argc) {
                 mdoc_argv_free(argc - 1, argv);                  mdoc_argv_free(argc - 1, argv);
                 return(mdoc_perr(mdoc, line, ppos, "parameter hard-limit exceeded"));                  return(perr(mdoc, line, ppos, EARGVLIM));
         }          }
   
         c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);          c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);
Line 614  macro_text(MACRO_PROT_ARGS)
Line 677  macro_text(MACRO_PROT_ARGS)
         for (;;) {          for (;;) {
                 la = *pos;                  la = *pos;
                 w = mdoc_args(mdoc, line, pos, buf, tok, &p);                  w = mdoc_args(mdoc, line, pos, buf, tok, &p);
                   assert(ARGS_PHRASE != c);
   
                 if (ARGS_ERROR == w) {                  if (ARGS_ERROR == w) {
                         mdoc_argv_free(argc, argv);                          mdoc_argv_free(argc, argv);
                         return(0);                          return(0);
Line 736  macro_scoped(MACRO_PROT_ARGS)
Line 801  macro_scoped(MACRO_PROT_ARGS)
   
         if (MDOC_LINEARG_MAX == argc) {          if (MDOC_LINEARG_MAX == argc) {
                 mdoc_argv_free(argc - 1, argv);                  mdoc_argv_free(argc - 1, argv);
                 return(mdoc_perr(mdoc, line, ppos, "parameter hard-limit exceeded"));                  return(perr(mdoc, line, ppos, EARGVLIM));
         }          }
   
         c = mdoc_block_alloc(mdoc, line, ppos,          c = mdoc_block_alloc(mdoc, line, ppos,
Line 766  macro_scoped(MACRO_PROT_ARGS)
Line 831  macro_scoped(MACRO_PROT_ARGS)
         for (;;) {          for (;;) {
                 lastarg = *pos;                  lastarg = *pos;
                 c = mdoc_args(mdoc, line, pos, buf, tok, &p);                  c = mdoc_args(mdoc, line, pos, buf, tok, &p);
   
                 if (ARGS_ERROR == c)                  if (ARGS_ERROR == c)
                         return(0);                          return(0);
                 if (ARGS_PUNCT == c)                  if (ARGS_PUNCT == c)
Line 774  macro_scoped(MACRO_PROT_ARGS)
Line 839  macro_scoped(MACRO_PROT_ARGS)
                 if (ARGS_EOLN == c)                  if (ARGS_EOLN == c)
                         break;                          break;
   
                   if (ARGS_PHRASE == c) {
                           /*
                           if ( ! mdoc_phrase(mdoc, line, lastarg, buf))
                                   return(0);
                           */
                           continue;
                   }
   
                 /* FIXME: if .It -column, the lookup must be for a                  /* FIXME: if .It -column, the lookup must be for a
                  * sub-line component.  BLAH. */                   * sub-line component.  BLAH. */
   
Line 847  macro_scoped_line(MACRO_PROT_ARGS)
Line 920  macro_scoped_line(MACRO_PROT_ARGS)
         for (;;) {          for (;;) {
                 lastarg = *pos;                  lastarg = *pos;
                 c = mdoc_args(mdoc, line, pos, buf, tok, &p);                  c = mdoc_args(mdoc, line, pos, buf, tok, &p);
                   assert(ARGS_PHRASE != c);
   
                 if (ARGS_ERROR == c)                  if (ARGS_ERROR == c)
                         return(0);                          return(0);
Line 943  macro_constant_scoped(MACRO_PROT_ARGS)
Line 1017  macro_constant_scoped(MACRO_PROT_ARGS)
                 }                  }
   
                 c = mdoc_args(mdoc, line, pos, buf, tok, &p);                  c = mdoc_args(mdoc, line, pos, buf, tok, &p);
                   assert(ARGS_PHRASE != c);
   
                 if (ARGS_ERROR == c)                  if (ARGS_ERROR == c)
                         return(0);                          return(0);
                 if (ARGS_PUNCT == c)                  if (ARGS_PUNCT == c)
Line 1050  macro_constant_delimited(MACRO_PROT_ARGS)
Line 1126  macro_constant_delimited(MACRO_PROT_ARGS)
   
         if (MDOC_LINEARG_MAX == argc) {          if (MDOC_LINEARG_MAX == argc) {
                 mdoc_argv_free(argc - 1, argv);                  mdoc_argv_free(argc - 1, argv);
                 return(mdoc_perr(mdoc, line, ppos, "parameter hard-limit exceeded"));                  return(perr(mdoc, line, ppos, EARGVLIM));
         }          }
   
         c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);          c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);
Line 1071  macro_constant_delimited(MACRO_PROT_ARGS)
Line 1147  macro_constant_delimited(MACRO_PROT_ARGS)
                 }                  }
   
                 c = mdoc_args(mdoc, line, pos, buf, tok, &p);                  c = mdoc_args(mdoc, line, pos, buf, tok, &p);
                   assert(ARGS_PHRASE != c);
   
                 if (ARGS_ERROR == c)                  if (ARGS_ERROR == c)
                         return(0);                          return(0);
                 if (ARGS_PUNCT == c)                  if (ARGS_PUNCT == c)
Line 1139  macro_constant(MACRO_PROT_ARGS)
Line 1217  macro_constant(MACRO_PROT_ARGS)
   
         if (MDOC_LINEARG_MAX == argc) {          if (MDOC_LINEARG_MAX == argc) {
                 mdoc_argv_free(argc - 1, argv);                  mdoc_argv_free(argc - 1, argv);
                 return(mdoc_perr(mdoc, line, ppos, "parameter hard-limit exceeded"));                  return(perr(mdoc, line, ppos, EARGVLIM));
         }          }
   
         c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);          c = mdoc_elem_alloc(mdoc, line, ppos, tok, argc, argv);
Line 1153  macro_constant(MACRO_PROT_ARGS)
Line 1231  macro_constant(MACRO_PROT_ARGS)
         for (;;) {          for (;;) {
                 la = *pos;                  la = *pos;
                 w = mdoc_args(mdoc, line, pos, buf, tok, &p);                  w = mdoc_args(mdoc, line, pos, buf, tok, &p);
                   assert(ARGS_PHRASE != c);
   
                 if (ARGS_ERROR == w)                  if (ARGS_ERROR == w)
                         return(0);                          return(0);
                 if (ARGS_EOLN == w)                  if (ARGS_EOLN == w)
Line 1182  int
Line 1262  int
 macro_obsolete(MACRO_PROT_ARGS)  macro_obsolete(MACRO_PROT_ARGS)
 {  {
   
         return(mdoc_pwarn(mdoc, line, ppos, WARN_SYNTAX, "macro is obsolete"));          return(pwarn(mdoc, line, ppos, WOBS));
 }  }
   
   

Legend:
Removed from v.1.48  
changed lines
  Added in v.1.49

CVSweb