ref: efed3e9037a152731d9f2ef9d51e4e9a8aa20edd
parent: 2da706eb682dd4906578d99521bc3e58467c10b1
author: Ali Gholami Rudi <[email protected]>
date: Fri May 8 08:59:15 EDT 2015
char: assign to escread()'s second argument a static buffer This removes the need for a few buffers with length ILNLEN.
--- a/char.c
+++ b/char.c
@@ -224,35 +224,40 @@
* s. The return value is the name of the troff request (the
* argument is copied into d) or zero for glyph names (it is
* copied into d). Returns -1 when the end of s is reached.
+ * Note that to d, a pointer to a static array is assigned.
*/
-int escread(char **s, char *d)
+int escread(char **s, char **d)
{
- char *r = d;
+ static char buf[1 << 12];
+ char *r;
if (!**s)
return -1;
- utf8read(s, d);
- if (d[0] == c_ec) {
- utf8read(s, d + 1);
- if (d[1] == '(') {
- utf8read(s, d);
- utf8read(s, d + strlen(d));
- } else if (!n_cp && d[1] == '[') {
+ r = buf;
+ *d = buf;
+ utf8read(s, r);
+ if (r[0] == c_ec) {
+ utf8read(s, r + 1);
+ if (r[1] == '(') {
+ utf8read(s, r);
+ utf8read(s, r + strlen(r));
+ } else if (!n_cp && r[1] == '[') {
while (**s && **s != ']')
*r++ = *(*s)++;
+ *r = '\0';
if (**s == ']')
(*s)++;
- } else if (strchr("CDfhmsvXx", d[1])) {
- int c = d[1];
- d[0] = '\0';
+ } else if (strchr("CDfhmsvXx", r[1])) {
+ int c = r[1];
+ r[0] = '\0';
if (strchr(ESC_P, c))
- unquotedread(s, d);
+ unquotedread(s, r);
if (strchr(ESC_Q, c))
- quotedread(s, d);
+ quotedread(s, r);
return c == 'C' ? 0 : c;
}
+ } else if (r[0] == c_ni) {
+ utf8read(s, r + 1);
}
- if (d[0] == c_ni)
- utf8read(s, d + 1);
return 0;
}
--- a/fmt.c
+++ b/fmt.c
@@ -279,14 +279,14 @@
/* find explicit hyphenation positions: dashes, \: and \% */
static int fmt_hyphmarks(char *word, int *hyidx, int *hyins)
{
- char d[ILNLEN];
char *s = word;
+ char *d = NULL;
int c, n = 0;
- while ((c = escread(&s, d)) > 0)
+ while ((c = escread(&s, &d)) > 0)
;
if (c < 0 || !strcmp(c_hc, d))
return -1;
- while ((c = escread(&s, d)) >= 0 && n < NHYPHSWORD) {
+ while ((c = escread(&s, &d)) >= 0 && n < NHYPHSWORD) {
if (!c && !strcmp(c_hc, d)) {
hyins[n] = 1;
hyidx[n++] = s - word;
--- a/hyph.c
+++ b/hyph.c
@@ -104,13 +104,13 @@
void tr_hw(char **args)
{
- char c[ILNLEN];
char word[WORDLEN];
+ char *c;
int i;
for (i = 1; i < NARGS && args[i]; i++) {
char *s = args[i];
char *d = word;
- while (d - word < WORDLEN - GNLEN && !escread(&s, c)) {
+ while (d - word < WORDLEN - GNLEN && !escread(&s, &c)) {
if (strcmp("-", c))
hcode_mapchar(c);
d += hy_cput(d, c);
--- a/out.c
+++ b/out.c
@@ -151,9 +151,9 @@
void out_line(char *s)
{
- char c[ILNLEN + GNLEN * 4];
+ char *c;
int t;
- while ((t = escread(&s, c)) >= 0) {
+ while ((t = escread(&s, &c)) >= 0) {
if (!t) {
if (c[0] == c_ni || (c[0] == '\\' && c[1] == '\\')) {
c[0] = c[1];
--- a/roff.h
+++ b/roff.h
@@ -399,7 +399,7 @@
void charnext_str(char *d, char *c);
void quotednext(char *d, int (*next)(void), void (*back)(int));
void unquotednext(char *d, int cmd, int (*next)(void), void (*back)(int));
-int escread(char **s, char *d);
+int escread(char **s, char **d);
/* string streams; nested next()/back() interface for string buffers */
void sstr_push(char *s);
char *sstr_pop(void);
--- a/wb.c
+++ b/wb.c
@@ -402,8 +402,7 @@
void wb_cat(struct wb *wb, struct wb *src)
{
- char *s;
- char d[ILNLEN];
+ char *s, *d;
int c, part;
int collect;
wb_flushsub(src);
@@ -410,7 +409,7 @@
wb_flushsub(wb);
collect = wb_collect(wb, 0);
s = sbuf_buf(&src->sbuf);
- while ((c = escread(&s, d)) >= 0)
+ while ((c = escread(&s, &d)) >= 0)
wb_putc(wb, c, d);
part = src->part;
wb->r_s = -1;
@@ -501,11 +500,11 @@
void wb_catstr(struct wb *wb, char *s, char *end)
{
- char d[ILNLEN];
int collect, c;
+ char *d;
wb_flushsub(wb);
collect = wb_collect(wb, 0);
- while (s < end && (c = escread(&s, d)) >= 0)
+ while (s < end && (c = escread(&s, &d)) >= 0)
wb_putc(wb, c, d);
wb_collect(wb, collect);
}