[BACK]Return to roff.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / external / bsd / mdocml / dist

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/external/bsd/mdocml/dist/roff.c between version 1.7.6.1 and 1.7.6.2

version 1.7.6.1, 2013/06/23 06:28:25 version 1.7.6.2, 2014/08/19 23:51:32
Line 1 
Line 1 
 /*      $Vendor-Id: roff.c,v 1.172 2011/10/24 21:41:45 schwarze Exp $ */  /*      Id: roff.c,v 1.189 2013/12/30 18:44:06 schwarze Exp  */
 /*  /*
  * Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>   * Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>   * Copyright (c) 2010, 2011, 2012, 2013 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 24 
Line 24 
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
 #include <stdint.h>  
   
 #include "mandoc.h"  #include "mandoc.h"
 #include "libroff.h"  #include "libroff.h"
Line 41  enum rofft {
Line 40  enum rofft {
         ROFF_am,          ROFF_am,
         ROFF_ami,          ROFF_ami,
         ROFF_am1,          ROFF_am1,
           ROFF_cc,
         ROFF_de,          ROFF_de,
         ROFF_dei,          ROFF_dei,
         ROFF_de1,          ROFF_de1,
         ROFF_ds,          ROFF_ds,
         ROFF_el,          ROFF_el,
           ROFF_fam,
           ROFF_hw,
         ROFF_hy,          ROFF_hy,
         ROFF_ie,          ROFF_ie,
         ROFF_if,          ROFF_if,
Line 60  enum rofft {
Line 62  enum rofft {
         ROFF_so,          ROFF_so,
         ROFF_ta,          ROFF_ta,
         ROFF_tr,          ROFF_tr,
           ROFF_Dd,
           ROFF_TH,
         ROFF_TS,          ROFF_TS,
         ROFF_TE,          ROFF_TE,
         ROFF_T_,          ROFF_T_,
Line 77  enum roffrule {
Line 81  enum roffrule {
 };  };
   
 /*  /*
  * A single register entity.  If "set" is zero, the value of the  
  * register should be the default one, which is per-register.  
  * Registers are assumed to be unsigned ints for now.  
  */  
 struct  reg {  
         int              set; /* whether set or not */  
         unsigned int     u; /* unsigned integer */  
 };  
   
 /*  
  * An incredibly-simple string buffer.   * An incredibly-simple string buffer.
  */   */
 struct  roffstr {  struct  roffstr {
Line 103  struct roffkv {
Line 97  struct roffkv {
         struct roffkv   *next; /* next in list */          struct roffkv   *next; /* next in list */
 };  };
   
   /*
    * A single number register as part of a singly-linked list.
    */
   struct  roffreg {
           struct roffstr   key;
           int              val;
           struct roffreg  *next;
   };
   
 struct  roff {  struct  roff {
           enum mparset     parsetype; /* requested parse type */
         struct mparse   *parse; /* parse point */          struct mparse   *parse; /* parse point */
         struct roffnode *last; /* leaf of stack */          struct roffnode *last; /* leaf of stack */
         enum roffrule    rstack[RSTACK_MAX]; /* stack of !`ie' rules */          enum roffrule    rstack[RSTACK_MAX]; /* stack of !`ie' rules */
           char             control; /* control character */
         int              rstackpos; /* position in rstack */          int              rstackpos; /* position in rstack */
         struct reg       regs[REG__MAX];          struct roffreg  *regtab; /* number registers */
         struct roffkv   *strtab; /* user-defined strings & macros */          struct roffkv   *strtab; /* user-defined strings & macros */
         struct roffkv   *xmbtab; /* multi-byte trans table (`tr') */          struct roffkv   *xmbtab; /* multi-byte trans table (`tr') */
         struct roffstr  *xtab; /* single-byte trans table (`tr') */          struct roffstr  *xtab; /* single-byte trans table (`tr') */
Line 119  struct roff {
Line 124  struct roff {
         struct eqn_node *last_eqn; /* last equation parsed */          struct eqn_node *last_eqn; /* last equation parsed */
         struct eqn_node *first_eqn; /* first equation parsed */          struct eqn_node *first_eqn; /* first equation parsed */
         struct eqn_node *eqn; /* current equation being parsed */          struct eqn_node *eqn; /* current equation being parsed */
         struct roff_nr  *nr[64];        /* numbered register set */  
 };  };
   
 struct  roffnode {  struct  roffnode {
Line 172  static enum rofferr  roff_block(ROFF_ARG
Line 176  static enum rofferr  roff_block(ROFF_ARG
 static  enum rofferr     roff_block_text(ROFF_ARGS);  static  enum rofferr     roff_block_text(ROFF_ARGS);
 static  enum rofferr     roff_block_sub(ROFF_ARGS);  static  enum rofferr     roff_block_sub(ROFF_ARGS);
 static  enum rofferr     roff_cblock(ROFF_ARGS);  static  enum rofferr     roff_cblock(ROFF_ARGS);
   static  enum rofferr     roff_cc(ROFF_ARGS);
 static  enum rofferr     roff_ccond(ROFF_ARGS);  static  enum rofferr     roff_ccond(ROFF_ARGS);
 static  enum rofferr     roff_cond(ROFF_ARGS);  static  enum rofferr     roff_cond(ROFF_ARGS);
 static  enum rofferr     roff_cond_text(ROFF_ARGS);  static  enum rofferr     roff_cond_text(ROFF_ARGS);
Line 179  static enum rofferr  roff_cond_sub(ROFF_
Line 184  static enum rofferr  roff_cond_sub(ROFF_
 static  enum rofferr     roff_ds(ROFF_ARGS);  static  enum rofferr     roff_ds(ROFF_ARGS);
 static  enum roffrule    roff_evalcond(const char *, int *);  static  enum roffrule    roff_evalcond(const char *, int *);
 static  void             roff_free1(struct roff *);  static  void             roff_free1(struct roff *);
   static  void             roff_freereg(struct roffreg *);
 static  void             roff_freestr(struct roffkv *);  static  void             roff_freestr(struct roffkv *);
 static  char            *roff_getname(struct roff *, char **, int, int);  static  char            *roff_getname(struct roff *, char **, int, int);
   static  int              roff_getnum(const char *, int *, int *);
   static  int              roff_getop(const char *, int *, char *);
   static  int              roff_getregn(const struct roff *,
                                   const char *, size_t);
 static  const char      *roff_getstrn(const struct roff *,  static  const char      *roff_getstrn(const struct roff *,
                                 const char *, size_t);                                  const char *, size_t);
   static  enum rofferr     roff_it(ROFF_ARGS);
 static  enum rofferr     roff_line_ignore(ROFF_ARGS);  static  enum rofferr     roff_line_ignore(ROFF_ARGS);
 static  enum rofferr     roff_nr(ROFF_ARGS);  static  enum rofferr     roff_nr(ROFF_ARGS);
 static  void             roff_openeqn(struct roff *, const char *,  static  void             roff_openeqn(struct roff *, const char *,
                                 int, int, const char *);                                  int, int, const char *);
 static  enum rofft       roff_parse(struct roff *, const char *, int *);  static  enum rofft       roff_parse(struct roff *, const char *, int *);
 static  enum rofferr     roff_parsetext(char *);  static  enum rofferr     roff_parsetext(char **, size_t *, int, int *);
 static  enum rofferr     roff_res(struct roff *,  static  enum rofferr     roff_res(struct roff *,
                                 char **, size_t *, int, int);                                  char **, size_t *, int, int);
 static  enum rofferr     roff_rm(ROFF_ARGS);  static  enum rofferr     roff_rm(ROFF_ARGS);
Line 198  static void   roff_setstrn(struct roffkv
Line 209  static void   roff_setstrn(struct roffkv
                                 size_t, const char *, size_t, int);                                  size_t, const char *, size_t, int);
 static  enum rofferr     roff_so(ROFF_ARGS);  static  enum rofferr     roff_so(ROFF_ARGS);
 static  enum rofferr     roff_tr(ROFF_ARGS);  static  enum rofferr     roff_tr(ROFF_ARGS);
   static  enum rofferr     roff_Dd(ROFF_ARGS);
   static  enum rofferr     roff_TH(ROFF_ARGS);
 static  enum rofferr     roff_TE(ROFF_ARGS);  static  enum rofferr     roff_TE(ROFF_ARGS);
 static  enum rofferr     roff_TS(ROFF_ARGS);  static  enum rofferr     roff_TS(ROFF_ARGS);
 static  enum rofferr     roff_EQ(ROFF_ARGS);  static  enum rofferr     roff_EQ(ROFF_ARGS);
Line 218  static struct roffmac  roffs[ROFF_MAX] =
Line 231  static struct roffmac  roffs[ROFF_MAX] =
         { "am", roff_block, roff_block_text, roff_block_sub, 0, NULL },          { "am", roff_block, roff_block_text, roff_block_sub, 0, NULL },
         { "ami", roff_block, roff_block_text, roff_block_sub, 0, NULL },          { "ami", roff_block, roff_block_text, roff_block_sub, 0, NULL },
         { "am1", roff_block, roff_block_text, roff_block_sub, 0, NULL },          { "am1", roff_block, roff_block_text, roff_block_sub, 0, NULL },
           { "cc", roff_cc, NULL, NULL, 0, NULL },
         { "de", roff_block, roff_block_text, roff_block_sub, 0, NULL },          { "de", roff_block, roff_block_text, roff_block_sub, 0, NULL },
         { "dei", roff_block, roff_block_text, roff_block_sub, 0, NULL },          { "dei", roff_block, roff_block_text, roff_block_sub, 0, NULL },
         { "de1", roff_block, roff_block_text, roff_block_sub, 0, NULL },          { "de1", roff_block, roff_block_text, roff_block_sub, 0, NULL },
         { "ds", roff_ds, NULL, NULL, 0, NULL },          { "ds", roff_ds, NULL, NULL, 0, NULL },
         { "el", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },          { "el", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
           { "fam", roff_line_ignore, NULL, NULL, 0, NULL },
           { "hw", roff_line_ignore, NULL, NULL, 0, NULL },
         { "hy", roff_line_ignore, NULL, NULL, 0, NULL },          { "hy", roff_line_ignore, NULL, NULL, 0, NULL },
         { "ie", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },          { "ie", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
         { "if", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },          { "if", roff_cond, roff_cond_text, roff_cond_sub, ROFFMAC_STRUCT, NULL },
         { "ig", roff_block, roff_block_text, roff_block_sub, 0, NULL },          { "ig", roff_block, roff_block_text, roff_block_sub, 0, NULL },
         { "it", roff_line_ignore, NULL, NULL, 0, NULL },          { "it", roff_it, NULL, NULL, 0, NULL },
         { "ne", roff_line_ignore, NULL, NULL, 0, NULL },          { "ne", roff_line_ignore, NULL, NULL, 0, NULL },
         { "nh", roff_line_ignore, NULL, NULL, 0, NULL },          { "nh", roff_line_ignore, NULL, NULL, 0, NULL },
         { "nr", roff_nr, NULL, NULL, 0, NULL },          { "nr", roff_nr, NULL, NULL, 0, NULL },
Line 237  static struct roffmac  roffs[ROFF_MAX] =
Line 253  static struct roffmac  roffs[ROFF_MAX] =
         { "so", roff_so, NULL, NULL, 0, NULL },          { "so", roff_so, NULL, NULL, 0, NULL },
         { "ta", roff_line_ignore, NULL, NULL, 0, NULL },          { "ta", roff_line_ignore, NULL, NULL, 0, NULL },
         { "tr", roff_tr, NULL, NULL, 0, NULL },          { "tr", roff_tr, NULL, NULL, 0, NULL },
           { "Dd", roff_Dd, NULL, NULL, 0, NULL },
           { "TH", roff_TH, NULL, NULL, 0, NULL },
         { "TS", roff_TS, NULL, NULL, 0, NULL },          { "TS", roff_TS, NULL, NULL, 0, NULL },
         { "TE", roff_TE, NULL, NULL, 0, NULL },          { "TE", roff_TE, NULL, NULL, 0, NULL },
         { "T&", roff_T_, NULL, NULL, 0, NULL },          { "T&", roff_T_, NULL, NULL, 0, NULL },
Line 247  static struct roffmac  roffs[ROFF_MAX] =
Line 265  static struct roffmac  roffs[ROFF_MAX] =
         { NULL, roff_userdef, NULL, NULL, 0, NULL },          { NULL, roff_userdef, NULL, NULL, 0, NULL },
 };  };
   
   const   char *const __mdoc_reserved[] = {
           "Ac", "Ad", "An", "Ao", "Ap", "Aq", "Ar", "At",
           "Bc", "Bd", "Bf", "Bk", "Bl", "Bo", "Bq",
           "Brc", "Bro", "Brq", "Bsx", "Bt", "Bx",
           "Cd", "Cm", "Db", "Dc", "Dd", "Dl", "Do", "Dq",
           "Ds", "Dt", "Dv", "Dx", "D1",
           "Ec", "Ed", "Ef", "Ek", "El", "Em", "em",
           "En", "Eo", "Eq", "Er", "Es", "Ev", "Ex",
           "Fa", "Fc", "Fd", "Fl", "Fn", "Fo", "Fr", "Ft", "Fx",
           "Hf", "Ic", "In", "It", "Lb", "Li", "Lk", "Lp", "LP",
           "Me", "Ms", "Mt", "Nd", "Nm", "No", "Ns", "Nx",
           "Oc", "Oo", "Op", "Os", "Ot", "Ox",
           "Pa", "Pc", "Pf", "Po", "Pp", "PP", "pp", "Pq",
           "Qc", "Ql", "Qo", "Qq", "Or", "Rd", "Re", "Rs", "Rv",
           "Sc", "Sf", "Sh", "SH", "Sm", "So", "Sq",
           "Ss", "St", "Sx", "Sy",
           "Ta", "Tn", "Ud", "Ux", "Va", "Vt", "Xc", "Xo", "Xr",
           "%A", "%B", "%D", "%I", "%J", "%N", "%O",
           "%P", "%Q", "%R", "%T", "%U", "%V",
           NULL
   };
   
   const   char *const __man_reserved[] = {
           "AT", "B", "BI", "BR", "BT", "DE", "DS", "DT",
           "EE", "EN", "EQ", "EX", "HF", "HP", "I", "IB", "IP", "IR",
           "LP", "ME", "MT", "OP", "P", "PD", "PP", "PT",
           "R", "RB", "RE", "RI", "RS", "SB", "SH", "SM", "SS", "SY",
           "TE", "TH", "TP", "TQ", "TS", "T&", "UC", "UE", "UR", "YS",
           NULL
   };
   
 /* Array of injected predefined strings. */  /* Array of injected predefined strings. */
 #define PREDEFS_MAX      38  #define PREDEFS_MAX      38
 static  const struct predef predefs[PREDEFS_MAX] = {  static  const struct predef predefs[PREDEFS_MAX] = {
Line 256  static const struct predef predefs[PREDE
Line 305  static const struct predef predefs[PREDE
 /* See roffhash_find() */  /* See roffhash_find() */
 #define ROFF_HASH(p)    (p[0] - ASCII_LO)  #define ROFF_HASH(p)    (p[0] - ASCII_LO)
   
   static  int      roffit_lines;  /* number of lines to delay */
   static  char    *roffit_macro;  /* nil-terminated macro line */
   
 static void  static void
 roffhash_init(void)  roffhash_init(void)
 {  {
Line 354  roffnode_push(struct roff *r, enum rofft
Line 406  roffnode_push(struct roff *r, enum rofft
 static void  static void
 roff_free1(struct roff *r)  roff_free1(struct roff *r)
 {  {
         struct tbl_node *t;          struct tbl_node *tbl;
         struct eqn_node *e;          struct eqn_node *e;
         int              i;          int              i;
   
         while (NULL != (t = r->first_tbl)) {          while (NULL != (tbl = r->first_tbl)) {
                 r->first_tbl = t->next;                  r->first_tbl = tbl->next;
                 tbl_free(t);                  tbl_free(tbl);
         }          }
   
         r->first_tbl = r->last_tbl = r->tbl = NULL;          r->first_tbl = r->last_tbl = r->tbl = NULL;
Line 380  roff_free1(struct roff *r)
Line 432  roff_free1(struct roff *r)
   
         r->strtab = r->xmbtab = NULL;          r->strtab = r->xmbtab = NULL;
   
           roff_freereg(r->regtab);
   
           r->regtab = NULL;
   
         if (r->xtab)          if (r->xtab)
                 for (i = 0; i < 128; i++)                  for (i = 0; i < 128; i++)
                         free(r->xtab[i].p);                          free(r->xtab[i].p);
Line 395  roff_reset(struct roff *r)
Line 451  roff_reset(struct roff *r)
   
         roff_free1(r);          roff_free1(r);
   
         memset(&r->regs, 0, sizeof(r->regs));          r->control = 0;
         memset(&r->nr, 0, sizeof(r->nr));  
   
         for (i = 0; i < PREDEFS_MAX; i++)          for (i = 0; i < PREDEFS_MAX; i++)
                 roff_setstr(r, predefs[i].name, predefs[i].str, 0);                  roff_setstr(r, predefs[i].name, predefs[i].str, 0);
Line 413  roff_free(struct roff *r)
Line 468  roff_free(struct roff *r)
   
   
 struct roff *  struct roff *
 roff_alloc(struct mparse *parse)  roff_alloc(enum mparset type, struct mparse *parse)
 {  {
         struct roff     *r;          struct roff     *r;
         int              i;          int              i;
   
         r = mandoc_calloc(1, sizeof(struct roff));          r = mandoc_calloc(1, sizeof(struct roff));
           r->parsetype = type;
         r->parse = parse;          r->parse = parse;
         r->rstackpos = -1;          r->rstackpos = -1;
   
Line 431  roff_alloc(struct mparse *parse)
Line 487  roff_alloc(struct mparse *parse)
 }  }
   
 /*  /*
  * Pre-filter each and every line for reserved words (one beginning with   * In the current line, expand user-defined strings ("\*")
  * `\*', e.g., `\*(ab').  These must be handled before the actual line   * and references to number registers ("\n").
  * is processed.   * Also check the syntax of other escape sequences.
  * This also checks the syntax of regular escapes.  
  */   */
 static enum rofferr  static enum rofferr
 roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos)  roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos)
 {  {
         enum mandoc_esc  esc;          char             ubuf[12]; /* buffer to print the number */
         const char      *stesc; /* start of an escape sequence ('\\') */          const char      *stesc; /* start of an escape sequence ('\\') */
         const char      *stnam; /* start of the name, after "[(*" */          const char      *stnam; /* start of the name, after "[(*" */
         const char      *cp;    /* end of the name, e.g. before ']' */          const char      *cp;    /* end of the name, e.g. before ']' */
         const char      *res;   /* the string to be substituted */          const char      *res;   /* the string to be substituted */
         int              i, maxl, expand_count;          char            *nbuf;  /* new buffer to copy bufp to */
         size_t           nsz;          size_t           nsz;   /* size of the new buffer */
         char            *n;          size_t           maxl;  /* expected length of the escape name */
           size_t           naml;  /* actual length of the escape name */
           int              expand_count;  /* to avoid infinite loops */
   
         expand_count = 0;          expand_count = 0;
   
Line 456  again:
Line 513  again:
                 stesc = cp++;                  stesc = cp++;
   
                 /*                  /*
                  * The second character must be an asterisk.                   * The second character must be an asterisk or an n.
                  * If it isn't, skip it anyway:  It is escaped,                   * If it isn't, skip it anyway:  It is escaped,
                  * so it can't start another escape sequence.                   * so it can't start another escape sequence.
                  */                   */
Line 464  again:
Line 521  again:
                 if ('\0' == *cp)                  if ('\0' == *cp)
                         return(ROFF_CONT);                          return(ROFF_CONT);
   
                 if ('*' != *cp) {                  switch (*cp) {
                         res = cp;                  case ('*'):
                         esc = mandoc_escape(&cp, NULL, NULL);                          res = NULL;
                         if (ESCAPE_ERROR != esc)                          break;
                   case ('n'):
                           res = ubuf;
                           break;
                   default:
                           if (ESCAPE_ERROR != mandoc_escape(&cp, NULL, NULL))
                                 continue;                                  continue;
                         cp = res;  
                         mandoc_msg                          mandoc_msg
                                 (MANDOCERR_BADESCAPE, r->parse,                                  (MANDOCERR_BADESCAPE, r->parse,
                                  ln, (int)(stesc - *bufp), NULL);                                   ln, (int)(stesc - *bufp), NULL);
Line 480  again:
Line 541  again:
   
                 /*                  /*
                  * The third character decides the length                   * The third character decides the length
                  * of the name of the string.                   * of the name of the string or register.
                  * Save a pointer to the name.                   * Save a pointer to the name.
                  */                   */
   
Line 503  again:
Line 564  again:
   
                 /* Advance to the end of the name. */                  /* Advance to the end of the name. */
   
                 for (i = 0; 0 == maxl || i < maxl; i++, cp++) {                  for (naml = 0; 0 == maxl || naml < maxl; naml++, cp++) {
                         if ('\0' == *cp) {                          if ('\0' == *cp) {
                                 mandoc_msg                                  mandoc_msg
                                         (MANDOCERR_BADESCAPE,                                          (MANDOCERR_BADESCAPE,
Line 520  again:
Line 581  again:
                  * undefined, resume searching for escapes.                   * undefined, resume searching for escapes.
                  */                   */
   
                 res = roff_getstrn(r, stnam, (size_t)i);                  if (NULL == res)
                           res = roff_getstrn(r, stnam, naml);
                   else
                           snprintf(ubuf, sizeof(ubuf), "%d",
                               roff_getregn(r, stnam, naml));
   
                 if (NULL == res) {                  if (NULL == res) {
                         mandoc_msg                          mandoc_msg
Line 534  again:
Line 599  again:
                 pos = stesc - *bufp;                  pos = stesc - *bufp;
   
                 nsz = *szp + strlen(res) + 1;                  nsz = *szp + strlen(res) + 1;
                 n = mandoc_malloc(nsz);                  nbuf = mandoc_malloc(nsz);
   
                 strlcpy(n, *bufp, (size_t)(stesc - *bufp + 1));                  strlcpy(nbuf, *bufp, (size_t)(stesc - *bufp + 1));
                 strlcat(n, res, nsz);                  strlcat(nbuf, res, nsz);
                 strlcat(n, cp + (maxl ? 0 : 1), nsz);                  strlcat(nbuf, cp + (maxl ? 0 : 1), nsz);
   
                 free(*bufp);                  free(*bufp);
   
                 *bufp = n;                  *bufp = nbuf;
                 *szp = nsz;                  *szp = nsz;
   
                 if (EXPAND_LIMIT >= ++expand_count)                  if (EXPAND_LIMIT >= ++expand_count)
Line 556  again:
Line 621  again:
 }  }
   
 /*  /*
  * Process text streams: convert all breakable hyphens into ASCII_HYPH.   * Process text streams:
    * Convert all breakable hyphens into ASCII_HYPH.
    * Decrement and spring input line trap.
  */   */
 static enum rofferr  static enum rofferr
 roff_parsetext(char *p)  roff_parsetext(char **bufp, size_t *szp, int pos, int *offs)
 {  {
         size_t           sz;          size_t           sz;
         const char      *start;          const char      *start;
           char            *p;
           int              isz;
         enum mandoc_esc  esc;          enum mandoc_esc  esc;
   
         start = p;          start = p = *bufp + pos;
   
         while ('\0' != *p) {          while ('\0' != *p) {
                 sz = strcspn(p, "-\\");                  sz = strcspn(p, "-\\");
Line 577  roff_parsetext(char *p)
Line 646  roff_parsetext(char *p)
                 if ('\\' == *p) {                  if ('\\' == *p) {
                         /* Skip over escapes. */                          /* Skip over escapes. */
                         p++;                          p++;
                         esc = mandoc_escape                          esc = mandoc_escape((const char **)(void *)&p, NULL, NULL);
                                 ((const char **)/*XXX*/(void *)&p, NULL, NULL);  
                         if (ESCAPE_ERROR == esc)                          if (ESCAPE_ERROR == esc)
                                 break;                                  break;
                         continue;                          continue;
Line 593  roff_parsetext(char *p)
Line 661  roff_parsetext(char *p)
                 p++;                  p++;
         }          }
   
           /* Spring the input line trap. */
           if (1 == roffit_lines) {
                   isz = asprintf(&p, "%s\n.%s", *bufp, roffit_macro);
                   if (-1 == isz) {
                           perror(NULL);
                           exit((int)MANDOCLEVEL_SYSERR);
                   }
                   free(*bufp);
                   *bufp = p;
                   *szp = isz + 1;
                   *offs = 0;
                   free(roffit_macro);
                   roffit_lines = 0;
                   return(ROFF_REPARSE);
           } else if (1 < roffit_lines)
                   --roffit_lines;
         return(ROFF_CONT);          return(ROFF_CONT);
 }  }
   
Line 615  roff_parseln(struct roff *r, int ln, cha
Line 699  roff_parseln(struct roff *r, int ln, cha
         assert(ROFF_CONT == e);          assert(ROFF_CONT == e);
   
         ppos = pos;          ppos = pos;
         ctl = mandoc_getcontrol(*bufp, &pos);          ctl = roff_getcontrol(r, *bufp, &pos);
   
         /*          /*
          * First, if a scope is open and we're not a macro, pass the           * First, if a scope is open and we're not a macro, pass the
Line 625  roff_parseln(struct roff *r, int ln, cha
Line 709  roff_parseln(struct roff *r, int ln, cha
          * no matter our state.           * no matter our state.
          */           */
   
         if (!ctl) {          if (r->last && ! ctl) {
                 if (r->last) {                  t = r->last->tok;
                         t = r->last->tok;                  assert(roffs[t].text);
                         assert(roffs[t].text);                  e = (*roffs[t].text)
                         e = (*roffs[t].text)                          (r, t, bufp, szp, ln, pos, pos, offs);
                             (r, t, bufp, szp, ln, pos, pos, offs);                  assert(ROFF_IGN == e || ROFF_CONT == e);
                         assert(ROFF_IGN == e || ROFF_CONT == e);                  if (ROFF_CONT != e)
                         if (ROFF_CONT != e)                          return(e);
                                 return(e);          }
                 }          if (r->eqn)
                 if (r->eqn)                  return(eqn_read(&r->eqn, ln, *bufp, ppos, offs));
                         return(eqn_read(&r->eqn, ln, *bufp, pos, offs));          if ( ! ctl) {
                 if (r->tbl)                  if (r->tbl)
                         return(tbl_read(r->tbl, ln, *bufp, pos));                          return(tbl_read(r->tbl, ln, *bufp, pos));
                 return(roff_parsetext(*bufp + pos));                  return(roff_parsetext(bufp, szp, pos, offs));
         } else if (r->eqn)          }
                 return(eqn_read(&r->eqn, ln, *bufp, ppos, offs));  
   
         /*          /*
          * If a scope is open, go to the child handler for that macro,           * If a scope is open, go to the child handler for that macro,
Line 778  roffnode_cleanscope(struct roff *r)
Line 861  roffnode_cleanscope(struct roff *r)
 {  {
   
         while (r->last) {          while (r->last) {
                 if (--r->last->endspan < 0)                  if (--r->last->endspan != 0)
                         break;                          break;
                 roffnode_pop(r);                  roffnode_pop(r);
         }          }
Line 984  roff_cond_sub(ROFF_ARGS)
Line 1067  roff_cond_sub(ROFF_ARGS)
   
         rr = r->last->rule;          rr = r->last->rule;
         roffnode_cleanscope(r);          roffnode_cleanscope(r);
           t = roff_parse(r, *bufp, &pos);
   
         /*          /*
          * If the macro is unknown, first check if it contains a closing           * Fully handle known macros when they are structurally
          * delimiter `\}'.  If it does, close out our scope and return           * required or when the conditional evaluated to true.
          * the currently-scoped rule (ignore or continue).  Else, drop  
          * into the currently-scoped rule.  
          */           */
   
         if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos))) {          if ((ROFF_MAX != t) &&
                 ep = &(*bufp)[pos];              (ROFF_ccond == t || ROFFRULE_ALLOW == rr ||
                 for ( ; NULL != (ep = strchr(ep, '\\')); ep++) {               ROFFMAC_STRUCT & roffs[t].flags)) {
                         ep++;                  assert(roffs[t].proc);
                         if ('}' != *ep)                  return((*roffs[t].proc)(r, t, bufp, szp,
                                 continue;                                          ln, ppos, pos, offs));
           }
                         /*  
                          * Make the \} go away.  
                          * This is a little haphazard, as it's not quite  
                          * clear how nroff does this.  
                          * If we're at the end of line, then just chop  
                          * off the \} and resize the buffer.  
                          * If we aren't, then conver it to spaces.  
                          */  
   
                         if ('\0' == *(ep + 1)) {          /* Always check for the closing delimiter `\}'. */
                                 *--ep = '\0';  
                                 *szp -= 2;  
                         } else  
                                 *(ep - 1) = *ep = ' ';  
   
                         roff_ccond(r, ROFF_ccond, bufp, szp,          ep = &(*bufp)[pos];
                                         ln, pos, pos + 2, offs);          while (NULL != (ep = strchr(ep, '\\'))) {
                         break;                  if ('}' != *(++ep))
                 }                          continue;
                 return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);  
         }  
   
         /*                  /*
          * A denied conditional must evaluate its children if and only                   * If we're at the end of line, then just chop
          * if they're either structurally required (such as loops and                   * off the \} and resize the buffer.
          * conditionals) or a closing macro.                   * If we aren't, then convert it to spaces.
          */                   */
   
         if (ROFFRULE_DENY == rr)                  if ('\0' == *(ep + 1)) {
                 if ( ! (ROFFMAC_STRUCT & roffs[t].flags))                          *--ep = '\0';
                         if (ROFF_ccond != t)                          *szp -= 2;
                                 return(ROFF_IGN);                  } else
                           *(ep - 1) = *ep = ' ';
   
         assert(roffs[t].proc);                  roff_ccond(r, ROFF_ccond, bufp, szp,
         return((*roffs[t].proc)(r, t, bufp, szp,                                  ln, pos, pos + 2, offs);
                                 ln, ppos, pos, offs));                  break;
           }
           return(ROFFRULE_DENY == rr ? ROFF_IGN : ROFF_CONT);
 }  }
   
 /* ARGSUSED */  /* ARGSUSED */
Line 1064  roff_getnum(const char *v, int *pos, int
Line 1135  roff_getnum(const char *v, int *pos, int
 {  {
         int p, n;          int p, n;
   
         if ((n = (v[*pos] == '-')) != 0)  
                 (*pos)++;  
   
         p = *pos;          p = *pos;
           n = v[p] == '-';
           if (n)
                   p++;
   
         for (*res = 0; isdigit((unsigned char)v[p]); p++)          for (*res = 0; isdigit((unsigned char)v[p]); p++)
                 *res += 10 * *res + v[p] - '0';                  *res += 10 * *res + v[p] - '0';
         if (p == *pos)          if (p == *pos + n)
                 return 0;                  return 0;
   
         if (n)          if (n)
Line 1081  roff_getnum(const char *v, int *pos, int
Line 1153  roff_getnum(const char *v, int *pos, int
 }  }
   
 static int  static int
 roff_getop(const char *v, int *pos)  roff_getop(const char *v, int *pos, char *res)
 {  {
         int c;          int e;
         switch (c = v[*pos]) {  
           *res = v[*pos];
           e = v[*pos + 1] == '=';
   
           switch (*res) {
         case '=':          case '=':
         case '!':                  break;
         case '>':          case '>':
                   if (e)
                           *res = 'g';
                   break;
         case '<':          case '<':
                 (*pos)++;                  if (e)
                 if (v[*pos] == '=')  {                          *res = 'l';
                         (*pos)++;                  break;
                         return c;  
                 }  
                 switch (c) {  
                 case '=':  
                         return '=';  
                 case '>':  
                         return 'g';  
                 case '<':  
                         return 'l';  
                 default:  
                         return -1;  
                 }  
         default:          default:
                 return -1;                  return(0);
         }          }
   
           *pos += 1 + e;
   
           return(*res);
 }  }
   
 static enum roffrule  static enum roffrule
 roff_evalcond(const char *v, int *pos)  roff_evalcond(const char *v, int *pos)
 {  {
         int not = 0;          int      not, lh, rh;
         int lh, rh, op;          char     op;
   
         switch (v[*pos]) {          switch (v[*pos]) {
         case ('n'):          case ('n'):
                 (*pos)++;                  (*pos)++;
Line 1126  roff_evalcond(const char *v, int *pos)
Line 1198  roff_evalcond(const char *v, int *pos)
                 (*pos)++;                  (*pos)++;
                 return(ROFFRULE_DENY);                  return(ROFFRULE_DENY);
         case ('!'):          case ('!'):
                 not++;  
                 (*pos)++;                  (*pos)++;
                   not = 1;
                 break;                  break;
         default:          default:
                   not = 0;
                 break;                  break;
         }          }
   
         if (!roff_getnum(v, pos, &lh))          if (!roff_getnum(v, pos, &lh))
                 return ROFFRULE_DENY;                  return ROFFRULE_DENY;
         if ((op = roff_getop(v, pos)) == -1)          if (!roff_getop(v, pos, &op)) {
                   if (lh < 0)
                           lh = 0;
                 goto out;                  goto out;
           }
         if (!roff_getnum(v, pos, &rh))          if (!roff_getnum(v, pos, &rh))
                 return ROFFRULE_DENY;                  return ROFFRULE_DENY;
         switch (op) {          switch (op) {
         case '>':          case 'g':
                 lh = lh >= rh;                  lh = lh >= rh;
                 break;                  break;
         case '<':          case 'l':
                 lh = lh <= rh;                  lh = lh <= rh;
                 break;                  break;
         case '=':          case '=':
                 lh = lh == rh;                  lh = lh == rh;
                 break;                  break;
         case '!':          case '>':
                 lh = lh != rh;  
                 break;  
         case 'g':  
                 lh = lh > rh;                  lh = lh > rh;
                 break;                  break;
         case 'l':          case '<':
                 lh = lh < rh;                  lh = lh < rh;
                 break;                  break;
         default:          default:
Line 1171  static enum rofferr
Line 1245  static enum rofferr
 roff_line_ignore(ROFF_ARGS)  roff_line_ignore(ROFF_ARGS)
 {  {
   
         if (ROFF_it == tok)  
                 mandoc_msg(MANDOCERR_REQUEST, r->parse, ln, ppos, "it");  
   
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
Line 1181  roff_line_ignore(ROFF_ARGS)
Line 1252  roff_line_ignore(ROFF_ARGS)
 static enum rofferr  static enum rofferr
 roff_cond(ROFF_ARGS)  roff_cond(ROFF_ARGS)
 {  {
         int              sv;  
         enum roffrule    rule;          roffnode_push(r, tok, NULL, ln, ppos);
   
         /*          /*
          * An `.el' has no conditional body: it will consume the value           * An `.el' has no conditional body: it will consume the value
Line 1192  roff_cond(ROFF_ARGS)
Line 1263  roff_cond(ROFF_ARGS)
          * If we're not an `el', however, then evaluate the conditional.           * If we're not an `el', however, then evaluate the conditional.
          */           */
   
         rule = ROFF_el == tok ?          r->last->rule = ROFF_el == tok ?
                 (r->rstackpos < 0 ?                  (r->rstackpos < 0 ?
                  ROFFRULE_DENY : r->rstack[r->rstackpos--]) :                   ROFFRULE_DENY : r->rstack[r->rstackpos--]) :
                 roff_evalcond(*bufp, &pos);                  roff_evalcond(*bufp, &pos);
   
         sv = pos;  
         while (' ' == (*bufp)[pos])  
                 pos++;  
   
         /*  
          * Roff is weird.  If we have just white-space after the  
          * conditional, it's considered the BODY and we exit without  
          * really doing anything.  Warn about this.  It's probably  
          * wrong.  
          */  
   
         if ('\0' == (*bufp)[pos] && sv != pos) {  
                 mandoc_msg(MANDOCERR_NOARGS, r->parse, ln, ppos, NULL);  
                 return(ROFF_IGN);  
         }  
   
         roffnode_push(r, tok, NULL, ln, ppos);  
   
         r->last->rule = rule;  
   
         /*          /*
          * An if-else will put the NEGATION of the current evaluated           * An if-else will put the NEGATION of the current evaluated
          * conditional into the stack of rules.           * conditional into the stack of rules.
Line 1239  roff_cond(ROFF_ARGS)
Line 1290  roff_cond(ROFF_ARGS)
                 r->last->rule = ROFFRULE_DENY;                  r->last->rule = ROFFRULE_DENY;
   
         /*          /*
          * Determine scope.  If we're invoked with "\{" trailing the           * Determine scope.
          * conditional, then we're in a multiline scope.  Else our scope           * If there is nothing on the line after the conditional,
          * expires on the next line.           * not even whitespace, use next-line scope.
          */           */
   
         r->last->endspan = 1;          if ('\0' == (*bufp)[pos]) {
                   r->last->endspan = 2;
                   goto out;
           }
   
           while (' ' == (*bufp)[pos])
                   pos++;
   
           /* An opening brace requests multiline scope. */
   
         if ('\\' == (*bufp)[pos] && '{' == (*bufp)[pos + 1]) {          if ('\\' == (*bufp)[pos] && '{' == (*bufp)[pos + 1]) {
                 r->last->endspan = -1;                  r->last->endspan = -1;
                 pos += 2;                  pos += 2;
                   goto out;
         }          }
   
         /*          /*
          * If there are no arguments on the line, the next-line scope is           * Anything else following the conditional causes
          * assumed.           * single-line scope.  Warn if the scope contains
            * nothing but trailing whitespace.
          */           */
   
         if ('\0' == (*bufp)[pos])          if ('\0' == (*bufp)[pos])
                 return(ROFF_IGN);                  mandoc_msg(MANDOCERR_NOARGS, r->parse, ln, ppos, NULL);
   
         /* Otherwise re-run the roff parser after recalculating. */          r->last->endspan = 1;
   
   out:
         *offs = pos;          *offs = pos;
         return(ROFF_RERUN);          return(ROFF_RERUN);
 }  }
Line 1296  roff_ds(ROFF_ARGS)
Line 1358  roff_ds(ROFF_ARGS)
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 int  void
 roff_regisset(const struct roff *r, enum regs reg)  roff_setreg(struct roff *r, const char *name, int val, char sign)
 {  {
           struct roffreg  *reg;
   
         return(r->regs[(int)reg].set);          /* Search for an existing register with the same name. */
 }          reg = r->regtab;
   
 unsigned int  
 roff_regget(const struct roff *r, enum regs reg)  
 {  
   
         return(r->regs[(int)reg].u);          while (reg && strcmp(name, reg->key.p))
                   reg = reg->next;
   
           if (NULL == reg) {
                   /* Create a new register. */
                   reg = mandoc_malloc(sizeof(struct roffreg));
                   reg->key.p = mandoc_strdup(name);
                   reg->key.sz = strlen(name);
                   reg->val = 0;
                   reg->next = r->regtab;
                   r->regtab = reg;
           }
   
           if ('+' == sign)
                   reg->val += val;
           else if ('-' == sign)
                   reg->val -= val;
           else
                   reg->val = val;
 }  }
   
 void  int
 roff_regunset(struct roff *r, enum regs reg)  roff_getreg(const struct roff *r, const char *name)
 {  {
           struct roffreg  *reg;
   
         r->regs[(int)reg].set = 0;          for (reg = r->regtab; reg; reg = reg->next)
 }                  if (0 == strcmp(name, reg->key.p))
                           return(reg->val);
 struct roff_nr {  
         char *str;  
         uint32_t hash;  
         intmax_t val;  
         struct roff_nr *next;  
 };  
   
 static uint32_t          return(0);
 hash_str(const char *str)  
 {  
         const uint8_t *s = (const uint8_t *)str;  
         uint8_t c;  
         uint32_t hv = 0;  
         while ((c = *s++) != '\0')  
                 hv = hv * 33 + c;           /* "perl": k=33, r=r+r/32 */  
         return hv + (hv >> 5);  
 }  }
   
 static struct roff_nr *  static int
 hash_find(struct roff *r, const char *str, uint32_t *h)  roff_getregn(const struct roff *r, const char *name, size_t len)
 {  {
         struct roff_nr *e;          struct roffreg  *reg;
         *h = hash_str(str) % (sizeof(r->nr) / sizeof(r->nr[0]));  
   
         for (e = r->nr[*h]; e; e = e->next)          for (reg = r->regtab; reg; reg = reg->next)
                 if (e->hash == *h && strcmp(e->str, str) == 0)                  if (len == reg->key.sz &&
                         return e;                      0 == strncmp(name, reg->key.p, len))
         return NULL;                          return(reg->val);
   
           return(0);
 }  }
   
 static struct roff_nr *  static void
 hash_insert(struct roff *r, const char *str, uint32_t h)  roff_freereg(struct roffreg *reg)
 {  {
         struct roff_nr *e;          struct roffreg  *old_reg;
   
         e = mandoc_malloc(sizeof(*e));          while (NULL != reg) {
         e->str = mandoc_strdup(str);                  free(reg->key.p);
         e->hash = h;                  old_reg = reg;
         e->next = r->nr[h];                  reg = reg->next;
         r->nr[h] = e;                  free(old_reg);
         return e;          }
 }  }
   
 /* ARGSUSED */  /* ARGSUSED */
Line 1366  roff_nr(ROFF_ARGS)
Line 1431  roff_nr(ROFF_ARGS)
 {  {
         const char      *key;          const char      *key;
         char            *val;          char            *val;
         uint32_t         hv;          size_t           sz;
         struct roff_nr  *h;          int              iv;
           char             sign;
   
         val = *bufp + pos;          val = *bufp + pos;
         key = roff_getname(r, &val, ln, pos);          key = roff_getname(r, &val, ln, pos);
   
         if ((h = hash_find(r, key, &hv)) == NULL)          sign = *val;
                 h = hash_insert(r, key, hv);          if ('+' == sign || '-' == sign)
                   val++;
   
         h->val = mandoc_strntoi(val, strlen(val), 10);          sz = strspn(val, "0123456789");
           iv = sz ? mandoc_strntoi(val, sz, 10) : 0;
   
         if (0 == strcmp(key, "nS")) {          roff_setreg(r, key, iv, sign);
                 r->regs[(int)REG_nS].set = 1;  
                 if (h->val >= 0)  
                         r->regs[(int)REG_nS].u = (unsigned)h->val;  
                 else  
                         r->regs[(int)REG_nS].u = 0u;  
         }  
   
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
 void  
 roff_expand_nr(struct roff *r, const char *src, int *sp, size_t slen,  
     char **dst, int *dp, size_t *dlenp)  
 {  
         uint32_t         hv;  
         struct roff_nr  *h;  
         int              l, s, d;  
         char             e, *key;  
   
         s = *sp + 2;    /* skip \\\n */  
         d = *dp;  
   
         if ('[' == src[s]) {            /* XXX: Support builtins */  
                 s++;  
                 e = ']';  
         } else  
                 e = '\0';  
   
         for (l = s; src[l] && l < (int)slen; l++) {  
                 if (e) {  
                         if (src[l] == e)  
                                 break;  
                 } else {  
                         if (!isalnum((unsigned char)src[l]))  
                                 break;  
                 }  
         }  
         *sp = l;  
         l -= s;  
         key = mandoc_malloc(l + 1);  
         memcpy(key, src + s, l);  
         key[l] = '\0';  
   
         if ((h = hash_find(r, key, &hv)) == NULL) {  
                 free(key);  
                 return;  
         }  
         if (*dst == NULL || *dlenp - *dp < 256)  
                 *dst = mandoc_realloc(*dst, *dlenp += 256);  
   
         /* XXX: support .af */  
         *dp += snprintf(*dst + *dp, *dlenp - *dp, "%jd", h->val);  
 }  
   
 /* ARGSUSED */  /* ARGSUSED */
 static enum rofferr  static enum rofferr
 roff_rm(ROFF_ARGS)  roff_rm(ROFF_ARGS)
Line 1450  roff_rm(ROFF_ARGS)
Line 1468  roff_rm(ROFF_ARGS)
   
 /* ARGSUSED */  /* ARGSUSED */
 static enum rofferr  static enum rofferr
   roff_it(ROFF_ARGS)
   {
           char            *cp;
           size_t           len;
           int              iv;
   
           /* Parse the number of lines. */
           cp = *bufp + pos;
           len = strcspn(cp, " \t");
           cp[len] = '\0';
           if ((iv = mandoc_strntoi(cp, len, 10)) <= 0) {
                   mandoc_msg(MANDOCERR_NUMERIC, r->parse,
                                   ln, ppos, *bufp + 1);
                   return(ROFF_IGN);
           }
           cp += len + 1;
   
           /* Arm the input line trap. */
           roffit_lines = iv;
           roffit_macro = mandoc_strdup(cp);
           return(ROFF_IGN);
   }
   
   /* ARGSUSED */
   static enum rofferr
   roff_Dd(ROFF_ARGS)
   {
           const char *const       *cp;
   
           if (MPARSE_MDOC != r->parsetype)
                   for (cp = __mdoc_reserved; *cp; cp++)
                           roff_setstr(r, *cp, NULL, 0);
   
           return(ROFF_CONT);
   }
   
   /* ARGSUSED */
   static enum rofferr
   roff_TH(ROFF_ARGS)
   {
           const char *const       *cp;
   
           if (MPARSE_MDOC != r->parsetype)
                   for (cp = __man_reserved; *cp; cp++)
                           roff_setstr(r, *cp, NULL, 0);
   
           return(ROFF_CONT);
   }
   
   /* ARGSUSED */
   static enum rofferr
 roff_TE(ROFF_ARGS)  roff_TE(ROFF_ARGS)
 {  {
   
Line 1528  roff_EN(ROFF_ARGS)
Line 1597  roff_EN(ROFF_ARGS)
 static enum rofferr  static enum rofferr
 roff_TS(ROFF_ARGS)  roff_TS(ROFF_ARGS)
 {  {
         struct tbl_node *t;          struct tbl_node *tbl;
   
         if (r->tbl) {          if (r->tbl) {
                 mandoc_msg(MANDOCERR_SCOPEBROKEN, r->parse, ln, ppos, NULL);                  mandoc_msg(MANDOCERR_SCOPEBROKEN, r->parse, ln, ppos, NULL);
                 tbl_end(&r->tbl);                  tbl_end(&r->tbl);
         }          }
   
         t = tbl_alloc(ppos, ln, r->parse);          tbl = tbl_alloc(ppos, ln, r->parse);
   
         if (r->last_tbl)          if (r->last_tbl)
                 r->last_tbl->next = t;                  r->last_tbl->next = tbl;
         else          else
                 r->first_tbl = r->last_tbl = t;                  r->first_tbl = r->last_tbl = tbl;
   
           r->tbl = r->last_tbl = tbl;
           return(ROFF_IGN);
   }
   
   /* ARGSUSED */
   static enum rofferr
   roff_cc(ROFF_ARGS)
   {
           const char      *p;
   
           p = *bufp + pos;
   
           if ('\0' == *p || '.' == (r->control = *p++))
                   r->control = 0;
   
           if ('\0' != *p)
                   mandoc_msg(MANDOCERR_ARGCOUNT, r->parse, ln, ppos, NULL);
   
         r->tbl = r->last_tbl = t;  
         return(ROFF_IGN);          return(ROFF_IGN);
 }  }
   
Line 1646  roff_userdef(ROFF_ARGS)
Line 1732  roff_userdef(ROFF_ARGS)
   
         /*          /*
          * Collect pointers to macro argument strings           * Collect pointers to macro argument strings
          * and null-terminate them.           * and NUL-terminate them.
          */           */
         cp = *bufp + pos;          cp = *bufp + pos;
         for (i = 0; i < 9; i++)          for (i = 0; i < 9; i++)
Line 1942  roff_strdup(const struct roff *r, const 
Line 2028  roff_strdup(const struct roff *r, const 
         res[(int)ssz] = '\0';          res[(int)ssz] = '\0';
         return(res);          return(res);
 }  }
   
   /*
    * Find out whether a line is a macro line or not.
    * If it is, adjust the current position and return one; if it isn't,
    * return zero and don't change the current position.
    * If the control character has been set with `.cc', then let that grain
    * precedence.
    * This is slighly contrary to groff, where using the non-breaking
    * control character when `cc' has been invoked will cause the
    * non-breaking macro contents to be printed verbatim.
    */
   int
   roff_getcontrol(const struct roff *r, const char *cp, int *ppos)
   {
           int             pos;
   
           pos = *ppos;
   
           if (0 != r->control && cp[pos] == r->control)
                   pos++;
           else if (0 != r->control)
                   return(0);
           else if ('\\' == cp[pos] && '.' == cp[pos + 1])
                   pos += 2;
           else if ('.' == cp[pos] || '\'' == cp[pos])
                   pos++;
           else
                   return(0);
   
           while (' ' == cp[pos] || '\t' == cp[pos])
                   pos++;
   
           *ppos = pos;
           return(1);
   }

Legend:
Removed from v.1.7.6.1  
changed lines
  Added in v.1.7.6.2

CVSweb <webmaster@jp.NetBSD.org>