=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.155 retrieving revision 1.161 diff -u -p -r1.155 -r1.161 --- mandoc/roff.c 2011/07/27 07:32:26 1.155 +++ mandoc/roff.c 2011/07/27 14:58:28 1.161 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.155 2011/07/27 07:32:26 kristaps Exp $ */ +/* $Id: roff.c,v 1.161 2011/07/27 14:58:28 kristaps Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -82,8 +82,8 @@ struct reg { }; struct roffstr { - char *name; /* key of symbol */ - char *string; /* current value */ + char *key; /* key of symbol */ + char *val; /* current value */ struct roffstr *next; /* next in list */ }; @@ -166,6 +166,8 @@ static const char *roff_getstrn(const struct roff *, const char *, size_t); static enum rofferr roff_line_ignore(ROFF_ARGS); static enum rofferr roff_nr(ROFF_ARGS); +static void roff_openeqn(struct roff *, const char *, + int, int, const char *); static enum rofft roff_parse(struct roff *, const char *, int *); static enum rofferr roff_parsetext(char *); static void roff_res(struct roff *, @@ -494,7 +496,7 @@ again: /* Replace the escape sequence by the string. */ - pos += (stesc - *bufp); + pos = stesc - *bufp; nsz = *szp + strlen(res) + 1; n = mandoc_malloc(nsz); @@ -528,6 +530,9 @@ roff_parsetext(char *p) sz = strcspn(p, "-\\"); p += sz; + if ('\0' == *p) + break; + if ('\\' == *p) { /* Skip over escapes. */ p++; @@ -536,18 +541,19 @@ roff_parsetext(char *p) if (ESCAPE_ERROR == esc) break; continue; - } else if ('-' != *p || p == start) + } else if (p == start) { + p++; continue; + } l = *(p - 1); r = *(p + 1); - if ('\\' != l && '\t' != r && '\t' != l && ' ' != r && ' ' != l && '-' != r && '-' != l && ! isdigit((unsigned char)l) && - ! isdigit((unsigned char)r)) + ! isdigit((unsigned char)r)) *p = ASCII_HYPH; p++; } @@ -1258,14 +1264,16 @@ roff_T_(ROFF_ARGS) return(ROFF_IGN); } -int +#if 0 +static int roff_closeeqn(struct roff *r) { return(r->eqn && ROFF_EQN == eqn_end(&r->eqn) ? 1 : 0); } +#endif -void +static void roff_openeqn(struct roff *r, const char *name, int line, int offs, const char *buf) { @@ -1457,20 +1465,20 @@ roff_setstr(struct roff *r, const char *name, const ch /* Search for an existing string with the same name. */ n = r->first_string; - while (n && strcmp(name, n->name)) + while (n && strcmp(name, n->key)) n = n->next; if (NULL == n) { /* Create a new string table entry. */ n = mandoc_malloc(sizeof(struct roffstr)); - n->name = mandoc_strdup(name); - n->string = NULL; + n->key = mandoc_strdup(name); + n->val = NULL; n->next = r->first_string; r->first_string = n; } else if (0 == multiline) { /* In multiline mode, append; else replace. */ - free(n->string); - n->string = NULL; + free(n->val); + n->val = NULL; } if (NULL == string) @@ -1481,17 +1489,17 @@ roff_setstr(struct roff *r, const char *name, const ch * and one for the terminating '\0'. */ newch = strlen(string) + (multiline ? 2u : 1u); - if (NULL == n->string) { - n->string = mandoc_malloc(newch); - *n->string = '\0'; + if (NULL == n->val) { + n->val = mandoc_malloc(newch); + *n->val = '\0'; oldch = 0; } else { - oldch = strlen(n->string); - n->string = mandoc_realloc(n->string, oldch + newch); + oldch = strlen(n->val); + n->val = mandoc_realloc(n->val, oldch + newch); } /* Skip existing content in the destination buffer. */ - c = n->string + (int)oldch; + c = n->val + (int)oldch; /* Append new content to the destination buffer. */ while (*string) { @@ -1515,11 +1523,12 @@ roff_getstrn(const struct roff *r, const char *name, s { const struct roffstr *n; - n = r->first_string; - while (n && (strncmp(name, n->name, len) || '\0' != n->name[(int)len])) - n = n->next; + for (n = r->first_string; n; n = n->next) + if (0 == strncmp(name, n->key, len) && + '\0' == n->key[(int)len]) + return(n->val); - return(n ? n->string : NULL); + return(NULL); } static void @@ -1528,8 +1537,8 @@ roff_freestr(struct roff *r) struct roffstr *n, *nn; for (n = r->first_string; n; n = nn) { - free(n->name); - free(n->string); + free(n->key); + free(n->val); nn = n->next; free(n); }