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

Diff for /mandoc/man_macro.c between version 1.1 and 1.6

version 1.1, 2009/03/23 14:22:11 version 1.6, 2009/03/25 15:36:05
Line 18 
Line 18 
  */   */
 #include <assert.h>  #include <assert.h>
 #include <ctype.h>  #include <ctype.h>
   #include <err.h> /* XXX */
 #include <stdlib.h>  #include <stdlib.h>
 #include <stdio.h>  #include <stdio.h>
 #include <string.h>  #include <string.h>
   
 #include "libman.h"  #include "libman.h"
   
 static  int       in_line_eoln(MACRO_PROT_ARGS);  static  int              man_args(struct man *, int,
                                   int *, char *, char **);
   
 const   struct man_macro __man_macros[MAN_MAX] = {  
         { in_line_eoln, NULL }, /* MAN___ */  
         { in_line_eoln, NULL }, /* MAN_TH */  
         { in_line_eoln, NULL }, /* MAN_SH */  
         { in_line_eoln, NULL }, /* MAN_SS */  
         { in_line_eoln, NULL }, /* MAN_TP */  
         { in_line_eoln, NULL }, /* MAN_LP */  
         { in_line_eoln, NULL }, /* MAN_PP */  
         { in_line_eoln, NULL }, /* MAN_P */  
         { in_line_eoln, NULL }, /* MAN_IP */  
         { in_line_eoln, NULL }, /* MAN_HP */  
         { in_line_eoln, NULL }, /* MAN_SM */  
         { in_line_eoln, NULL }, /* MAN_SB */  
         { in_line_eoln, NULL }, /* MAN_BI */  
         { in_line_eoln, NULL }, /* MAN_IB */  
         { in_line_eoln, NULL }, /* MAN_BR */  
         { in_line_eoln, NULL }, /* MAN_RB */  
         { in_line_eoln, NULL }, /* MAN_R */  
         { in_line_eoln, NULL }, /* MAN_B */  
         { in_line_eoln, NULL }, /* MAN_I */  
 };  
   
 const   struct man_macro * const man_macros = __man_macros;  int
   man_macro(struct man *man, int tok, int line,
                   int ppos, int *pos, char *buf)
 /*  
  * In-line macro that spans an entire line.  May be callable, but has no  
  * subsequent parsed arguments.  
  */  
 static int  
 in_line_eoln(MACRO_PROT_ARGS)  
 {  {
 #if 0          int              w, la;
         int               c, w, la;          char            *p;
         char             *p;          struct man_node *n;
   
         if ( ! man_elem_alloc(man, line, ppos, tok, arg))          if ( ! man_elem_alloc(man, line, ppos, tok))
                 return(0);                  return(0);
         man->next = MDOC_NEXT_SIBLING;          n = man->last;
           man->next = MAN_NEXT_CHILD;
   
         for (;;) {          for (;;) {
                 la = *pos;                  la = *pos;
                 w = man_args(man, line, pos, buf, tok, &p);                  w = man_args(man, line, pos, buf, &p);
   
                 if (ARGS_ERROR == w)                  if (-1 == w)
                         return(0);                          return(0);
                 if (ARGS_EOLN == w)                  if (0 == w)
                         break;                          break;
   
                 c = ARGS_QWORD == w ? MAN_MAX :                  if ( ! man_word_alloc(man, line, la, p))
                         lookup(man, line, la, tok, p);                          return(0);
                   man->next = MAN_NEXT_SIBLING;
           }
   
                 if (MDOC_MAX != c && -1 != c) {          for ( ; man->last && man->last != n;
                         if ( ! rew_elem(mdoc, tok))                          man->last = man->last->parent) {
                                 return(0);                  if ( ! man_valid_post(man))
                         return(mdoc_macro(mdoc, c, line, la, pos, buf));  
                 } else if (-1 == c)  
                         return(0);                          return(0);
                   if ( ! man_action_post(man))
                           return(0);
           }
   
                 if ( ! mdoc_word_alloc(mdoc, line, la, p))          assert(man->last);
   
           if ( ! man_valid_post(man))
                   return(0);
           if ( ! man_action_post(man))
                   return(0);
   
           man->next = MAN_NEXT_SIBLING;
   
           return(1);
   }
   
   
   int
   man_macroend(struct man *m)
   {
   
           for ( ; m->last && m->last != m->first;
                           m->last = m->last->parent) {
                   if ( ! man_valid_post(m))
                         return(0);                          return(0);
                   if ( ! man_action_post(m))
                           return(0);
         }          }
   
         return(rew_elem(mdoc, tok));          if ( ! man_valid_post(m))
 #endif                  return(0);
           if ( ! man_action_post(m))
                   return(0);
   
         return(1);          return(1);
 }  }
   
   
   /* ARGSUSED */
   static int
   man_args(struct man *man, int line,
                   int *pos, char *buf, char **v)
   {
   
           if (0 == buf[*pos])
                   return(0);
   
           /* First parse non-quoted strings. */
   
           if ('\"' != buf[*pos]) {
                   *v = &buf[*pos];
   
                   while (buf[*pos]) {
                           if (' ' == buf[*pos])
                                   if ('\\' != buf[*pos - 1])
                                           break;
                           (*pos)++;
                   }
   
                   if (0 == buf[*pos])
                           return(1);
   
                   buf[(*pos)++] = 0;
   
                   if (0 == buf[*pos])
                           return(1);
   
                   while (buf[*pos] && ' ' == buf[*pos])
                           (*pos)++;
   
                   if (buf[*pos])
                           return(1);
   
                   warnx("tail whitespace");
                   return(-1);
           }
   
           /*
            * If we're a quoted string (and quoted strings are allowed),
            * then parse ahead to the next quote.  If none's found, it's an
            * error.  After, parse to the next word.
            */
   
           *v = &buf[++(*pos)];
   
           while (buf[*pos] && '\"' != buf[*pos])
                   (*pos)++;
   
           if (0 == buf[*pos]) {
                   warnx("unterminated quotation");
                   return(-1);
           }
   
           buf[(*pos)++] = 0;
           if (0 == buf[*pos])
                   return(1);
   
           while (buf[*pos] && ' ' == buf[*pos])
                   (*pos)++;
   
           if (buf[*pos])
                   return(1);
   
           warnx("tail whitespace");
           return(-1);
   }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.6

CVSweb