struct source {
source *prev;
char *upcoming;
+ int processedlen;
char *prefix;
char *suffix;
int fd;
txt->src = mymalloc(sizeof(source));
txt->src->prev = NULL;
txt->src->upcoming = NULL;
+ txt->src->processedlen = 0;
txt->src->prefix = NULL;
txt->src->suffix = NULL;
txt->src->transparent = 0;
while (*pos != '\0' && *pos != '\r' && *pos != '\n') pos++;
if (*pos == '\r') pos++;
if (*pos == '\n') pos++;
- if (*pos != '\0') txt->src->upcoming = mystrdup(pos);
+ if (*pos != '\0') {
+ txt->src->upcoming = mystrdup(pos);
+ txt->src->processedlen = 0;
+ }
fd = open(filename, O_RDONLY);
if (fd < 0) {
while (*pos != '\0' && *pos != '\r' && *pos != '\n') pos++;
if (*pos == '\r') pos++;
if (*pos == '\n') pos++;
- if (*pos != '\0') txt->src->upcoming = mystrdup(pos);
+ if (*pos != '\0') {
+ txt->src->upcoming = mystrdup(pos);
+ txt->src->processedlen = 0;
+ }
(*fmt->rew)(fmt->state);
char *tmp;
char *prev = NULL;
int len, i;
+ int processedlen;
int incision, linebreak;
int directive, inhibitbreak;
int peeking = 0; /* for a failed conditional without an else */
line = txt->src->upcoming;
}
txt->src->upcoming = NULL;
+ processedlen = strlen(txt->src->prefix) +
+ txt->src->processedlen;
break;
}
if (txt->src->limit != 0) {
txt->src->upcoming = NULL;
} else if (txt->src->transparent) {
txt->src->upcoming = tmp;
+ txt->src->processedlen = 0;
} else {
txt->src->upcoming =
unistr_escaped_to_utf8(tmp);
+ txt->src->processedlen = 0;
myfree(tmp);
}
} else {
}
if (prev != NULL) {
- /* Wrapping */
+ /* Wrapping; join and start processing at the new bit,
+ * which is always unprocessed. */
len = strlen(prev);
pos = prev + len - 1;
if (txt->wrapmode == WRAP_WORD) {
line for later. */
txt->wrapwidth = 0;
txt->src->upcoming = line;
+ txt->src->processedlen = 0;
line = prev;
pos = line + len;
skipwhite = 0;
linebreak = len;
prev = NULL;
} else {
- len = 0;
- pos = line;
+ /* Not wrapping; start processing where we left off;
+ * there can't be any break opportunities in the
+ * processed part, and if it looks like there are, they
+ * must have been inhibited so aren't really. */
+ pos = line + processedlen;
+ len = processedlen;
linebreak = 0;
skipwhite = 0;
}
if (*pos == '\n') pos++;
if (*pos == '\0') break;
txt->src->upcoming = mystrdup(pos);
+ txt->src->processedlen = 0;
break;
} else if (*pos == '\n') {
*pos = '\0';
pos++;
if (*pos == '\0') break;
txt->src->upcoming = mystrdup(pos);
+ txt->src->processedlen = 0;
break;
} else if (*pos == ' ') {
if (txt->skip == NULL &&
if (line[linebreak] == '\0') linebreak = 0;
}
if (linebreak != 0) {
+ txt->src->processedlen = len - linebreak;
len = strlen(line + linebreak);
if (txt->src->upcoming == NULL) {
tmp = mymalloc((len + txt->wrapindent + 1) *
strlen(txt->src->upcoming)) *
sizeof(char));
}
+ txt->src->processedlen += txt->wrapindent;
pos = tmp;
for (i = txt->wrapindent; i > 0; i--)
*pos++ = ' ';
* line */
if (txt->src->upcoming == NULL) {
txt->src->upcoming = line;
+ txt->src->processedlen = len;
} else {
tmp = txt->src->upcoming;
txt->src->upcoming = concatstr(3,
line, "\n",
txt->src->upcoming);
+ txt->src->processedlen = len;
myfree(line);
myfree(tmp);
}