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

Diff for /mandoc/mdoc.c between version 1.203 and 1.211

version 1.203, 2012/11/17 00:26:33 version 1.211, 2014/03/23 12:44:56
Line 1 
Line 1 
 /*      $Id$ */  /*      $Id$ */
 /*  /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2012 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
  *   *
  * Permission to use, copy, modify, and distribute this software for any   * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above   * purpose with or without fee is hereby granted, provided that the above
Line 22 
Line 22 
 #include <sys/types.h>  #include <sys/types.h>
   
 #include <assert.h>  #include <assert.h>
   #include <ctype.h>
 #include <stdarg.h>  #include <stdarg.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
Line 30 
Line 31 
   
 #include "mdoc.h"  #include "mdoc.h"
 #include "mandoc.h"  #include "mandoc.h"
   #include "mandoc_aux.h"
 #include "libmdoc.h"  #include "libmdoc.h"
 #include "libmandoc.h"  #include "libmandoc.h"
   
Line 197  mdoc_free(struct mdoc *mdoc)
Line 199  mdoc_free(struct mdoc *mdoc)
  * Allocate volatile and non-volatile parse resources.   * Allocate volatile and non-volatile parse resources.
  */   */
 struct mdoc *  struct mdoc *
 mdoc_alloc(struct roff *roff, struct mparse *parse, char *defos)  mdoc_alloc(struct roff *roff, struct mparse *parse,
           char *defos, int quick)
 {  {
         struct mdoc     *p;          struct mdoc     *p;
   
Line 205  mdoc_alloc(struct roff *roff, struct mparse *parse, ch
Line 208  mdoc_alloc(struct roff *roff, struct mparse *parse, ch
   
         p->parse = parse;          p->parse = parse;
         p->defos = defos;          p->defos = defos;
           p->quick = quick;
         p->roff = roff;          p->roff = roff;
   
         mdoc_hash_init();          mdoc_hash_init();
Line 295  mdoc_parseln(struct mdoc *mdoc, int ln, char *buf, int
Line 299  mdoc_parseln(struct mdoc *mdoc, int ln, char *buf, int
          * whether this mode is on or off.           * whether this mode is on or off.
          * Note that this mode is also switched by the Sh macro.           * Note that this mode is also switched by the Sh macro.
          */           */
         if (roff_regisset(mdoc->roff, REG_nS)) {          if (roff_getreg(mdoc->roff, "nS"))
                 if (roff_regget(mdoc->roff, REG_nS))                  mdoc->flags |= MDOC_SYNOPSIS;
                         mdoc->flags |= MDOC_SYNOPSIS;          else
                 else                  mdoc->flags &= ~MDOC_SYNOPSIS;
                         mdoc->flags &= ~MDOC_SYNOPSIS;  
         }  
   
         return(roff_getcontrol(mdoc->roff, buf, &offs) ?          return(roff_getcontrol(mdoc->roff, buf, &offs) ?
                         mdoc_pmacro(mdoc, ln, buf, offs) :                          mdoc_pmacro(mdoc, ln, buf, offs) :
Line 436  node_alloc(struct mdoc *mdoc, int line, int pos, 
Line 438  node_alloc(struct mdoc *mdoc, int line, int pos, 
         p->sec = mdoc->lastsec;          p->sec = mdoc->lastsec;
         p->line = line;          p->line = line;
         p->pos = pos;          p->pos = pos;
           p->lastline = line;
         p->tok = tok;          p->tok = tok;
         p->type = type;          p->type = type;
   
Line 584  mdoc_word_alloc(struct mdoc *mdoc, int line, int pos, 
Line 587  mdoc_word_alloc(struct mdoc *mdoc, int line, int pos, 
         return(1);          return(1);
 }  }
   
   void
   mdoc_word_append(struct mdoc *mdoc, const char *p)
   {
           struct mdoc_node        *n;
           char                    *addstr, *newstr;
   
           n = mdoc->last;
           addstr = roff_strdup(mdoc->roff, p);
           mandoc_asprintf(&newstr, "%s %s", n->string, addstr);
           free(addstr);
           free(n->string);
           n->string = newstr;
           mdoc->next = MDOC_NEXT_SIBLING;
   }
   
 static void  static void
 mdoc_node_free(struct mdoc_node *p)  mdoc_node_free(struct mdoc_node *p)
 {  {
Line 830  mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int
Line 847  mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int
   
         assert(buf < end);          assert(buf < end);
   
         if (mandoc_eos(buf+offs, (size_t)(end-buf-offs), 0))          if (mandoc_eos(buf+offs, (size_t)(end-buf-offs)))
                 mdoc->last->flags |= MDOC_EOS;                  mdoc->last->flags |= MDOC_EOS;
   
         return(1);          return(1);
Line 945  mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int 
Line 962  mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int 
         if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf))          if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf))
                 goto err;                  goto err;
   
           /* In quick mode (for mandocdb), abort after the NAME section. */
   
           if (mdoc->quick && MDOC_Sh == tok &&
               SEC_NAME != mdoc->last->sec)
                   return(2);
   
         return(1);          return(1);
   
 err:    /* Error out. */  err:    /* Error out. */
Line 997  mdoc_isdelim(const char *p)
Line 1020  mdoc_isdelim(const char *p)
                 return(DELIM_MIDDLE);                  return(DELIM_MIDDLE);
   
         return(DELIM_NONE);          return(DELIM_NONE);
   }
   
   void
   mdoc_deroff(char **dest, const struct mdoc_node *n)
   {
           char    *cp;
           size_t   sz;
   
           if (MDOC_TEXT != n->type) {
                   for (n = n->child; n; n = n->next)
                           mdoc_deroff(dest, n);
                   return;
           }
   
           /* Skip leading whitespace. */
   
           for (cp = n->string; '\0' != *cp; cp++)
                   if (0 == isspace((unsigned char)*cp))
                           break;
   
           /* Skip trailing whitespace. */
   
           for (sz = strlen(cp); sz; sz--)
                   if (0 == isspace((unsigned char)cp[sz-1]))
                           break;
   
           /* Skip empty strings. */
   
           if (0 == sz)
                   return;
   
           if (NULL == *dest) {
                   *dest = mandoc_strndup(cp, sz);
                   return;
           }
   
           mandoc_asprintf(&cp, "%s %*s", *dest, (int)sz, cp);
           free(*dest);
           *dest = cp;
 }  }

Legend:
Removed from v.1.203  
changed lines
  Added in v.1.211

CVSweb