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

Diff for /mandoc/man.c between version 1.133 and 1.143

version 1.133, 2014/07/07 21:36:20 version 1.143, 2014/11/19 03:08:17
Line 16 
Line 16 
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */   */
 #ifdef HAVE_CONFIG_H  
 #include "config.h"  #include "config.h"
 #endif  
   
 #include <sys/types.h>  #include <sys/types.h>
   
Line 68  const struct man_node *
Line 66  const struct man_node *
 man_node(const struct man *man)  man_node(const struct man *man)
 {  {
   
         assert( ! (MAN_HALT & man->flags));  
         return(man->first);          return(man->first);
 }  }
   
Line 76  const struct man_meta *
Line 73  const struct man_meta *
 man_meta(const struct man *man)  man_meta(const struct man *man)
 {  {
   
         assert( ! (MAN_HALT & man->flags));  
         return(&man->meta);          return(&man->meta);
 }  }
   
Line 116  int
Line 112  int
 man_endparse(struct man *man)  man_endparse(struct man *man)
 {  {
   
         assert( ! (MAN_HALT & man->flags));          return(man_macroend(man));
         if (man_macroend(man))  
                 return(1);  
         man->flags |= MAN_HALT;  
         return(0);  
 }  }
   
 int  int
 man_parseln(struct man *man, int ln, char *buf, int offs)  man_parseln(struct man *man, int ln, char *buf, int offs)
 {  {
   
         man->flags |= MAN_NEWLINE;          if (man->last->type != MAN_EQN || ln > man->last->line)
                   man->flags |= MAN_NEWLINE;
   
         assert( ! (MAN_HALT & man->flags));  
   
         return (roff_getcontrol(man->roff, buf, &offs) ?          return (roff_getcontrol(man->roff, buf, &offs) ?
             man_pmacro(man, ln, buf, offs) :              man_pmacro(man, ln, buf, offs) :
             man_ptext(man, ln, buf, offs));              man_ptext(man, ln, buf, offs));
Line 194  man_node_append(struct man *man, struct man_node *p)
Line 185  man_node_append(struct man *man, struct man_node *p)
         assert(p->parent);          assert(p->parent);
         p->parent->nchild++;          p->parent->nchild++;
   
         if ( ! man_valid_pre(man, p))  
                 return(0);  
   
         switch (p->type) {          switch (p->type) {
           case MAN_BLOCK:
                   if (p->tok == MAN_SH || p->tok == MAN_SS)
                           man->flags &= ~MAN_LITERAL;
                   break;
         case MAN_HEAD:          case MAN_HEAD:
                 assert(MAN_BLOCK == p->parent->type);                  assert(MAN_BLOCK == p->parent->type);
                 p->parent->head = p;                  p->parent->head = p;
Line 323  man_word_alloc(struct man *man, int line, int pos, con
Line 315  man_word_alloc(struct man *man, int line, int pos, con
         return(1);          return(1);
 }  }
   
   void
   man_word_append(struct man *man, const char *word)
   {
           struct man_node *n;
           char            *addstr, *newstr;
   
           n = man->last;
           addstr = roff_strdup(man->roff, word);
           mandoc_asprintf(&newstr, "%s %s", n->string, addstr);
           free(addstr);
           free(n->string);
           n->string = newstr;
           man->next = MAN_NEXT_SIBLING;
   }
   
 /*  /*
  * Free all of the resources held by a node.  This does NOT unlink a   * Free all of the resources held by a node.  This does NOT unlink a
  * node from its context; for that, see man_node_unlink().   * node from its context; for that, see man_node_unlink().
Line 352  man_addeqn(struct man *man, const struct eqn *ep)
Line 359  man_addeqn(struct man *man, const struct eqn *ep)
 {  {
         struct man_node *n;          struct man_node *n;
   
         assert( ! (MAN_HALT & man->flags));  
   
         n = man_node_alloc(man, ep->ln, ep->pos, MAN_EQN, MAN_MAX);          n = man_node_alloc(man, ep->ln, ep->pos, MAN_EQN, MAN_MAX);
         n->eqn = ep;          n->eqn = ep;
           if (ep->ln > man->last->line)
                   n->flags |= MAN_LINE;
   
         if ( ! man_node_append(man, n))          if ( ! man_node_append(man, n))
                 return(0);                  return(0);
Line 369  man_addspan(struct man *man, const struct tbl_span *sp
Line 376  man_addspan(struct man *man, const struct tbl_span *sp
 {  {
         struct man_node *n;          struct man_node *n;
   
         assert( ! (MAN_HALT & man->flags));  
   
         n = man_node_alloc(man, sp->line, 0, MAN_TBL, MAN_MAX);          n = man_node_alloc(man, sp->line, 0, MAN_TBL, MAN_MAX);
         n->span = sp;          n->span = sp;
   
Line 478  man_ptext(struct man *man, int line, char *buf, int of
Line 483  man_ptext(struct man *man, int line, char *buf, int of
 static int  static int
 man_pmacro(struct man *man, int ln, char *buf, int offs)  man_pmacro(struct man *man, int ln, char *buf, int offs)
 {  {
         int              i, ppos;          struct man_node *n;
           const char      *cp;
         enum mant        tok;          enum mant        tok;
           int              i, ppos;
           int              bline;
         char             mac[5];          char             mac[5];
         struct man_node *n;  
   
         if ('"' == buf[offs]) {  
                 mandoc_msg(MANDOCERR_COMMENT_BAD, man->parse,  
                     ln, offs, NULL);  
                 return(1);  
         } else if ('\0' == buf[offs])  
                 return(1);  
   
         ppos = offs;          ppos = offs;
   
         /*          /*
          * Copy the first word into a nil-terminated buffer.           * Copy the first word into a nil-terminated buffer.
          * Stop copying when a tab, space, or eoln is encountered.           * Stop when a space, tab, escape, or eoln is encountered.
          */           */
   
         i = 0;          i = 0;
         while (i < 4 && '\0' != buf[offs] && ' ' != buf[offs] &&          while (i < 4 && strchr(" \t\\", buf[offs]) == NULL)
             '\t' != buf[offs])  
                 mac[i++] = buf[offs++];                  mac[i++] = buf[offs++];
   
         mac[i] = '\0';          mac[i] = '\0';
   
         tok = (i > 0 && i < 4) ? man_hash_find(mac) : MAN_MAX;          tok = (i > 0 && i < 4) ? man_hash_find(mac) : MAN_MAX;
   
         if (MAN_MAX == tok) {          if (tok == MAN_MAX) {
                 mandoc_vmsg(MANDOCERR_MACRO, man->parse, ln, ppos,                  mandoc_msg(MANDOCERR_MACRO, man->parse,
                     "%s", buf + ppos - 1);                      ln, ppos, buf + ppos - 1);
                 return(1);                  return(1);
         }          }
   
         /* The macro is sane.  Jump to the next word. */          /* Skip a leading escape sequence or tab. */
   
           switch (buf[offs]) {
           case '\\':
                   cp = buf + offs + 1;
                   mandoc_escape(&cp, NULL, NULL);
                   offs = cp - buf;
                   break;
           case '\t':
                   offs++;
                   break;
           default:
                   break;
           }
   
           /* Jump to the next non-whitespace word. */
   
         while (buf[offs] && ' ' == buf[offs])          while (buf[offs] && ' ' == buf[offs])
                 offs++;                  offs++;
   
Line 581  man_pmacro(struct man *man, int ln, char *buf, int off
Line 595  man_pmacro(struct man *man, int ln, char *buf, int off
                 man->flags &= ~MAN_BLINE;                  man->flags &= ~MAN_BLINE;
         }          }
   
         /*          /* Remember whether we are in next-line scope for a block head. */
          * Save the fact that we're in the next-line for a block.  In  
          * this way, embedded roff instructions can "remember" state  
          * when they exit.  
          */  
   
         if (MAN_BLINE & man->flags)          bline = man->flags & MAN_BLINE;
                 man->flags |= MAN_BPLINE;  
   
         /* Call to handler... */          /* Call to handler... */
   
         assert(man_macros[tok].fp);          assert(man_macros[tok].fp);
         if ( ! (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf))          if ( ! (*man_macros[tok].fp)(man, tok, ln, ppos, &offs, buf))
                 goto err;                  return(0);
   
         /* In quick mode (for mandocdb), abort after the NAME section. */          /* In quick mode (for mandocdb), abort after the NAME section. */
   
Line 606  man_pmacro(struct man *man, int ln, char *buf, int off
Line 615  man_pmacro(struct man *man, int ln, char *buf, int off
         }          }
   
         /*          /*
          * We weren't in a block-line scope when entering the           * If we are in a next-line scope for a block head,
          * above-parsed macro, so return.           * close it out now and switch to the body,
            * unless the next-line scope is allowed to continue.
          */           */
   
         if ( ! (MAN_BPLINE & man->flags)) {          if ( ! bline || man->flags & MAN_ELINE ||
                 man->flags &= ~MAN_ILINE;              man_macros[tok].flags & MAN_NSCOPED)
                 return(1);                  return(1);
         }  
         man->flags &= ~MAN_BPLINE;  
   
         /*  
          * If we're in a block scope, then allow this macro to slip by  
          * without closing scope around it.  
          */  
   
         if (MAN_ILINE & man->flags) {  
                 man->flags &= ~MAN_ILINE;  
                 return(1);  
         }  
   
         /*  
          * If we've opened a new next-line element scope, then return  
          * now, as the next line will close out the block scope.  
          */  
   
         if (MAN_ELINE & man->flags)  
                 return(1);  
   
         /* Close out the block scope opened in the prior line.  */  
   
         assert(MAN_BLINE & man->flags);          assert(MAN_BLINE & man->flags);
         man->flags &= ~MAN_BLINE;          man->flags &= ~MAN_BLINE;
   
         if ( ! man_unscope(man, man->last->parent))          if ( ! man_unscope(man, man->last->parent))
                 return(0);                  return(0);
         return(man_body_alloc(man, ln, ppos, man->last->tok));          return(man_body_alloc(man, ln, ppos, man->last->tok));
   
 err:    /* Error out. */  
   
         man->flags |= MAN_HALT;  
         return(0);  
 }  }
   
 /*  /*

Legend:
Removed from v.1.133  
changed lines
  Added in v.1.143

CVSweb