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

Diff for /mandoc/roff.c between version 1.165 and 1.166

version 1.165, 2011/07/28 14:53:22 version 1.166, 2011/07/29 09:19:48
Line 77  enum roffrule {
Line 77  enum roffrule {
  * Registers are assumed to be unsigned ints for now.   * Registers are assumed to be unsigned ints for now.
  */   */
 struct  reg {  struct  reg {
         int               set; /* whether set or not */          int              set; /* whether set or not */
         unsigned int      u; /* unsigned integer */          unsigned int     u; /* unsigned integer */
 };  };
   
 struct  roffstr {  struct  roffstr {
         char            *key; /* key of symbol */          char            *p;
         size_t           keysz;          size_t           sz;
         char            *val; /* current value */  
         size_t           valsz;  
         struct roffstr  *next; /* next in list */  
 };  };
   
   /*
    * A key-value string pair with lengths.
    */
   struct  roffkv {
           struct roffstr   key;
           struct roffstr   val;
           struct roffkv   *next; /* next in list */
   };
   
 struct  roff {  struct  roff {
         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 */
         int              rstackpos; /* position in rstack */          int              rstackpos; /* position in rstack */
         struct reg       regs[REG__MAX];          struct reg       regs[REG__MAX];
         struct roffstr  *strtab; /* user-defined strings & macros */          struct roffkv   *strtab; /* user-defined strings & macros */
         struct roffstr  *chrtab; /* user-defined characters */          struct roffkv   *chrtab; /* user-defined characters */
         const char      *current_string; /* value of last called user macro */          const char      *current_string; /* value of last called user macro */
         struct tbl_node *first_tbl; /* first table parsed */          struct tbl_node *first_tbl; /* first table parsed */
         struct tbl_node *last_tbl; /* last table parsed */          struct tbl_node *last_tbl; /* last table parsed */
Line 163  static enum rofferr  roff_cond_sub(ROFF_ARGS);
Line 169  static enum rofferr  roff_cond_sub(ROFF_ARGS);
 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_freestr(struct roffstr **);  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  const char      *roff_getstrn(const struct roff *,  static  const char      *roff_getstrn(const struct roff *,
                                 const char *, size_t);                                  const char *, size_t);
Line 178  static void   roff_res(struct roff *, 
Line 184  static void   roff_res(struct roff *, 
 static  enum rofferr     roff_rm(ROFF_ARGS);  static  enum rofferr     roff_rm(ROFF_ARGS);
 static  void             roff_setstr(struct roff *,  static  void             roff_setstr(struct roff *,
                                 const char *, const char *, int);                                  const char *, const char *, int);
 static  void             roff_setstrn(struct roffstr **, const char *,  static  void             roff_setstrn(struct roffkv **, const char *,
                                 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);
Line 1525  roff_setstr(struct roff *r, const char *name, const ch
Line 1531  roff_setstr(struct roff *r, const char *name, const ch
 }  }
   
 static void  static void
 roff_setstrn(struct roffstr **r, const char *name, size_t namesz,  roff_setstrn(struct roffkv **r, const char *name, size_t namesz,
                 const char *string, size_t stringsz, int multiline)                  const char *string, size_t stringsz, int multiline)
 {  {
         struct roffstr  *n;          struct roffkv   *n;
         char            *c;          char            *c;
         int              i;          int              i;
         size_t           oldch, newch;          size_t           oldch, newch;
Line 1536  roff_setstrn(struct roffstr **r, const char *name, siz
Line 1542  roff_setstrn(struct roffstr **r, const char *name, siz
         /* Search for an existing string with the same name. */          /* Search for an existing string with the same name. */
         n = *r;          n = *r;
   
         while (n && strcmp(name, n->key))          while (n && strcmp(name, n->key.p))
                 n = n->next;                  n = n->next;
   
         if (NULL == n) {          if (NULL == n) {
                 /* Create a new string table entry. */                  /* Create a new string table entry. */
                 n = mandoc_malloc(sizeof(struct roffstr));                  n = mandoc_malloc(sizeof(struct roffkv));
                 n->key = mandoc_strndup(name, namesz);                  n->key.p = mandoc_strndup(name, namesz);
                 n->keysz = namesz;                  n->key.sz = namesz;
                 n->val = NULL;                  n->val.p = NULL;
                 n->valsz = 0;                  n->val.sz = 0;
                 n->next = *r;                  n->next = *r;
                 *r = n;                  *r = n;
         } else if (0 == multiline) {          } else if (0 == multiline) {
                 /* In multiline mode, append; else replace. */                  /* In multiline mode, append; else replace. */
                 free(n->val);                  free(n->val.p);
                 n->val = NULL;                  n->val.p = NULL;
                 n->valsz = 0;                  n->val.sz = 0;
         }          }
   
         if (NULL == string)          if (NULL == string)
Line 1564  roff_setstrn(struct roffstr **r, const char *name, siz
Line 1570  roff_setstrn(struct roffstr **r, const char *name, siz
          */           */
         newch = stringsz + (multiline ? 2u : 1u);          newch = stringsz + (multiline ? 2u : 1u);
   
         if (NULL == n->val) {          if (NULL == n->val.p) {
                 n->val = mandoc_malloc(newch);                  n->val.p = mandoc_malloc(newch);
                 *n->val = '\0';                  *n->val.p = '\0';
                 oldch = 0;                  oldch = 0;
         } else {          } else {
                 oldch = n->valsz;                  oldch = n->val.sz;
                 n->val = mandoc_realloc(n->val, oldch + newch);                  n->val.p = mandoc_realloc(n->val.p, oldch + newch);
         }          }
   
         /* Skip existing content in the destination buffer. */          /* Skip existing content in the destination buffer. */
         c = n->val + (int)oldch;          c = n->val.p + (int)oldch;
   
         /* Append new content to the destination buffer. */          /* Append new content to the destination buffer. */
         i = 0;          i = 0;
Line 1593  roff_setstrn(struct roffstr **r, const char *name, siz
Line 1599  roff_setstrn(struct roffstr **r, const char *name, siz
                 *c++ = '\n';                  *c++ = '\n';
   
         *c = '\0';          *c = '\0';
         n->valsz = (int)(c - n->val);          n->val.sz = (int)(c - n->val.p);
 }  }
   
 static const char *  static const char *
 roff_getstrn(const struct roff *r, const char *name, size_t len)  roff_getstrn(const struct roff *r, const char *name, size_t len)
 {  {
         const struct roffstr *n;          const struct roffkv *n;
   
         for (n = r->strtab; n; n = n->next)          for (n = r->strtab; n; n = n->next)
                 if (0 == strncmp(name, n->key, len) &&                  if (0 == strncmp(name, n->key.p, len) &&
                                 '\0' == n->key[(int)len])                                  '\0' == n->key.p[(int)len])
                         return(n->val);                          return(n->val.p);
   
         return(NULL);          return(NULL);
 }  }
   
 static void  static void
 roff_freestr(struct roffstr **r)  roff_freestr(struct roffkv **r)
 {  {
         struct roffstr   *n, *nn;          struct roffkv    *n, *nn;
   
         for (n = *r; n; n = nn) {          for (n = *r; n; n = nn) {
                 free(n->key);                  free(n->key.p);
                 free(n->val);                  free(n->val.p);
                 nn = n->next;                  nn = n->next;
                 free(n);                  free(n);
         }          }
Line 1653  roff_eqndelim(const struct roff *r)
Line 1659  roff_eqndelim(const struct roff *r)
 char *  char *
 roff_strdup(const struct roff *r, const char *p)  roff_strdup(const struct roff *r, const char *p)
 {  {
         const struct roffstr *cp;          const struct roffkv *cp;
         char            *res;          char            *res;
         const char      *pp;          const char      *pp;
         size_t           ssz, sz;          size_t           ssz, sz;
Line 1678  roff_strdup(const struct roff *r, const char *p)
Line 1684  roff_strdup(const struct roff *r, const char *p)
         while ('\0' != *p) {          while ('\0' != *p) {
                 /* Search for term matches. */                  /* Search for term matches. */
                 for (cp = r->chrtab; cp; cp = cp->next)                  for (cp = r->chrtab; cp; cp = cp->next)
                         if (0 == strncmp(p, cp->key, cp->keysz))                          if (0 == strncmp(p, cp->key.p, cp->key.sz))
                                 break;                                  break;
   
                 if (NULL != cp) {                  if (NULL != cp) {
Line 1687  roff_strdup(const struct roff *r, const char *p)
Line 1693  roff_strdup(const struct roff *r, const char *p)
                          * Append the match to the array and move                           * Append the match to the array and move
                          * forward by its keysize.                           * forward by its keysize.
                          */                           */
                         res = mandoc_realloc(res, ssz + cp->valsz + 1);                          res = mandoc_realloc
                         memcpy(res + ssz, cp->val, cp->valsz);                                  (res, ssz + cp->val.sz + 1);
                         ssz += cp->valsz;                          memcpy(res + ssz, cp->val.p, cp->val.sz);
                         p += (int)cp->keysz;                          ssz += cp->val.sz;
                           p += (int)cp->key.sz;
                         continue;                          continue;
                 }                  }
   

Legend:
Removed from v.1.165  
changed lines
  Added in v.1.166

CVSweb