Move text to String type

This commit is contained in:
Roberto E. Vargas Caballero 2018-03-04 14:06:24 +01:00 committed by sin
parent f5cb020f06
commit 35cf3c79f2

15
ed.c
View File

@ -54,10 +54,9 @@ static jmp_buf savesp;
static char *lasterr; static char *lasterr;
static size_t idxsize, lastidx; static size_t idxsize, lastidx;
static struct hline *zero; static struct hline *zero;
static char *text; static String text;
static char savfname[FILENAME_MAX]; static char savfname[FILENAME_MAX];
static char tmpname[FILENAME_MAX]; static char tmpname[FILENAME_MAX];
static size_t sizetxt, memtxt;
static int scratch; static int scratch;
static int pflag, modflag, uflag, gflag; static int pflag, modflag, uflag, gflag;
static size_t csize; static size_t csize;
@ -236,11 +235,11 @@ gettxt(int line)
char *p; char *p;
lp = zero + getindex(line); lp = zero + getindex(line);
sizetxt = 0; text.siz = 0;
off = lp->seek; off = lp->seek;
if (off == (off_t) -1) if (off == (off_t) -1)
return text = addchar('\0', text, &memtxt, &sizetxt); return addchar_('\0', &text);
repeat: repeat:
if (!csize || off < lasto || off - lasto >= csize) { if (!csize || off < lasto || off - lasto >= csize) {
@ -254,14 +253,14 @@ repeat:
} }
for (p = buf + off - lasto; p < buf + csize && *p != '\n'; ++p) { for (p = buf + off - lasto; p < buf + csize && *p != '\n'; ++p) {
++off; ++off;
text = addchar(*p, text, &memtxt, &sizetxt); addchar_(*p, &text);
} }
if (csize && p == buf + csize) if (csize && p == buf + csize)
goto repeat; goto repeat;
text = addchar('\n', text, &memtxt, &sizetxt); addchar_('\n', &text);
text = addchar('\0', text, &memtxt, &sizetxt); addchar_('\0', &text);
return text; return text.str;
} }
static void static void