#include "strgen.h"
#include "chomp.h"
#include "log_error.h"
-#include "mygetline.h"
#include "wrappers.h"
#include "getlistaddr.h"
#include "mlmmj.h"
int prefixlen;
int prefixwidth;
char *suffix;
- int fd;
+ FILE *fp;
struct formatted *fmt;
int transparent;
int limit;
+ char *line;
+ size_t linecap;
};
txt->src->limit = -1;
txt->wrapmode = WRAP_WORD;
txt->widthreckoning = WIDTH_THIN;
- txt->src->fd = fd;
+ txt->src->fp = fdopen(fd, "r");
return (txt);
}
void close_source(text *txt)
{
source *tmp;
- if (txt->src->fd != -1) close(txt->src->fd);
+ if (txt->src->fp) fclose(txt->src->fp);
if (txt->src->prefix != NULL) free(txt->src->prefix);
if (txt->src->suffix != NULL) free(txt->src->suffix);
+ free(txt->src->line);
tmp = txt->src;
txt->src = txt->src->prev;
free(tmp);
return;
}
- src = xmalloc(sizeof(source));
+ src = xcalloc(1, sizeof(source));
src->prev = txt->src;
- src->upcoming = NULL;
src->prefixlen = strlen(line);
src->prefixwidth = *width_p;
src->prefix = xmalloc((*width_p + 1) * sizeof(char));
for (tmp = src->prefix, i = 0; i < *width_p; tmp++, i++) *tmp = ' ';
*tmp = '\0';
- src->suffix = NULL;
- src->fd = fd;
- src->fmt = NULL;
+ src->fp = fdopen(fd, "r");
src->transparent = transparent;
src->limit = -1;
txt->src = src;
- tmp = mygetline(fd);
- if (tmp == NULL) {
+ if (getline(&txt->src->line, &txt->src->linecap, txt->src->fp) <= 0) {
close_source(txt);
**pos_p = '\0';
return;
}
+ tmp = txt->src->line;
if (!transparent) {
esc = unistr_escaped_to_utf8(tmp);
- free(tmp);
tmp = esc;
}
- line = concatstr(2, line, tmp);
+ line = concatstr(2, line, txt->src->line);
*pos_p = line + (*pos_p - *line_p);
free(*line_p);
*line_p = line;
- free(tmp);
}
} else {
src->suffix = xstrdup(suffix);
}
- src->fd = -1;
+ src->fp = NULL;
src->fmt = fmt;
src->transparent = transparent;
src->limit = -1;
break;
}
if (txt->src->limit != 0) {
- if (txt->src->fd != -1) {
- tmp = mygetline(txt->src->fd);
+ tmp = NULL;
+ if (txt->src->fp != NULL) {
+ tmp = NULL;
+ if (getline(&txt->src->line, &txt->src->linecap, txt->src->fp) > 0)
+ tmp = xstrdup(txt->src->line);
} else if (txt->src->fmt != NULL) {
item = (*txt->src->fmt->get)(
txt->src->fmt->state);
if (item==NULL) tmp = NULL;
else tmp = xstrdup(item);
- } else {
- tmp = NULL;
}
if (txt->src->limit > 0) txt->src->limit--;
if (tmp == NULL) {