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

Diff for /mandoc/roff.c between version 1.159 and 1.162

version 1.159, 2011/07/27 14:19:26 version 1.162, 2011/07/27 17:25:30
Line 82  struct reg {
Line 82  struct reg {
 };  };
   
 struct  roffstr {  struct  roffstr {
         char            *name; /* key of symbol */          char            *key; /* key of symbol */
         char            *string; /* current value */          size_t           keysz;
           char            *val; /* current value */
           size_t           valsz;
         struct roffstr  *next; /* next in list */          struct roffstr  *next; /* next in list */
 };  };
   
Line 496  again:
Line 498  again:
   
                 /* Replace the escape sequence by the string. */                  /* Replace the escape sequence by the string. */
   
                 pos += (stesc - *bufp);                  pos = stesc - *bufp;
   
                 nsz = *szp + strlen(res) + 1;                  nsz = *szp + strlen(res) + 1;
                 n = mandoc_malloc(nsz);                  n = mandoc_malloc(nsz);
Line 1465  roff_setstr(struct roff *r, const char *name, const ch
Line 1467  roff_setstr(struct roff *r, const char *name, const ch
   
         /* Search for an existing string with the same name. */          /* Search for an existing string with the same name. */
         n = r->first_string;          n = r->first_string;
         while (n && strcmp(name, n->name))          while (n && strcmp(name, n->key))
                 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 roffstr));
                 n->name = mandoc_strdup(name);                  n->key = mandoc_strdup(name);
                 n->string = NULL;                  n->keysz = strlen(name);
                   n->val = NULL;
                   n->valsz = 0;
                 n->next = r->first_string;                  n->next = r->first_string;
                 r->first_string = n;                  r->first_string = n;
         } else if (0 == multiline) {          } else if (0 == multiline) {
                 /* In multiline mode, append; else replace. */                  /* In multiline mode, append; else replace. */
                 free(n->string);                  free(n->val);
                 n->string = NULL;                  n->val = NULL;
                   n->valsz = 0;
         }          }
   
         if (NULL == string)          if (NULL == string)
Line 1489  roff_setstr(struct roff *r, const char *name, const ch
Line 1494  roff_setstr(struct roff *r, const char *name, const ch
          * and one for the terminating '\0'.           * and one for the terminating '\0'.
          */           */
         newch = strlen(string) + (multiline ? 2u : 1u);          newch = strlen(string) + (multiline ? 2u : 1u);
         if (NULL == n->string) {          if (NULL == n->val) {
                 n->string = mandoc_malloc(newch);                  n->val = mandoc_malloc(newch);
                 *n->string = '\0';                  *n->val = '\0';
                   n->valsz = newch - 1;
                 oldch = 0;                  oldch = 0;
         } else {          } else {
                 oldch = strlen(n->string);                  oldch = n->valsz;
                 n->string = mandoc_realloc(n->string, oldch + newch);                  n->val = mandoc_realloc(n->val, n->valsz + newch);
                   n->valsz += newch - 1;
         }          }
   
         /* Skip existing content in the destination buffer. */          /* Skip existing content in the destination buffer. */
         c = n->string + (int)oldch;          c = n->val + (int)oldch;
   
         /* Append new content to the destination buffer. */          /* Append new content to the destination buffer. */
         while (*string) {          while (*string) {
Line 1524  roff_getstrn(const struct roff *r, const char *name, s
Line 1531  roff_getstrn(const struct roff *r, const char *name, s
         const struct roffstr *n;          const struct roffstr *n;
   
         for (n = r->first_string; n; n = n->next)          for (n = r->first_string; n; n = n->next)
                 if (0 == strncmp(name, n->name, len) &&                  if (0 == strncmp(name, n->key, len) &&
                                 '\0' == n->name[(int)len])                                  '\0' == n->key[(int)len])
                         return(n->string);                          return(n->val);
   
         return(NULL);          return(NULL);
 }  }
Line 1537  roff_freestr(struct roff *r)
Line 1544  roff_freestr(struct roff *r)
         struct roffstr   *n, *nn;          struct roffstr   *n, *nn;
   
         for (n = r->first_string; n; n = nn) {          for (n = r->first_string; n; n = nn) {
                 free(n->name);                  free(n->key);
                 free(n->string);                  free(n->val);
                 nn = n->next;                  nn = n->next;
                 free(n);                  free(n);
         }          }

Legend:
Removed from v.1.159  
changed lines
  Added in v.1.162

CVSweb