Rename addchar_() to addchar()

All the ocurrences of addchar() were moved to addchar_(),
so we can rename addchar_() and remove the old definition.
This commit is contained in:
Roberto E. Vargas Caballero 2018-03-04 15:15:54 +01:00 committed by sin
parent 3ce26f33c6
commit d849e6d4aa

63
ed.c
View File

@ -119,7 +119,7 @@ prevln(int line)
} }
static char * static char *
addchar_(char c, String *s) addchar(char c, String *s)
{ {
size_t cap = s->cap, siz = s->siz; size_t cap = s->cap, siz = s->siz;
char *t = s->str; char *t = s->str;
@ -135,21 +135,6 @@ addchar_(char c, String *s)
return t; return t;
} }
static char *
addchar(char c, char *t, size_t *capacity, size_t *size)
{
size_t cap = *capacity, siz = *size;
if (siz >= cap &&
(cap > SIZE_MAX - LINESIZE ||
(t = realloc(t, cap += LINESIZE)) == NULL))
error("out of memory");
t[siz++] = c;
*size = siz;
*capacity = cap;
return t;
}
static int static int
input(void) input(void)
{ {
@ -159,7 +144,7 @@ input(void)
return ocmdline[repidx++]; return ocmdline[repidx++];
if ((c = getchar()) != EOF) if ((c = getchar()) != EOF)
addchar_(c, &cmdline); addchar(c, &cmdline);
return c; return c;
} }
@ -239,7 +224,7 @@ gettxt(int line)
off = lp->seek; off = lp->seek;
if (off == (off_t) -1) if (off == (off_t) -1)
return addchar_('\0', &text); return addchar('\0', &text);
repeat: repeat:
if (!csize || off < lasto || off - lasto >= csize) { if (!csize || off < lasto || off - lasto >= csize) {
@ -253,13 +238,13 @@ 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;
addchar_(*p, &text); addchar(*p, &text);
} }
if (csize && p == buf + csize) if (csize && p == buf + csize)
goto repeat; goto repeat;
addchar_('\n', &text); addchar('\n', &text);
addchar_('\0', &text); addchar('\0', &text);
return text.str; return text.str;
} }
@ -402,21 +387,21 @@ compile(int delim)
} }
if (c == '\\') { if (c == '\\') {
addchar_(c, &lastre); addchar(c, &lastre);
c = input(); c = input();
} else if (c == '[') { } else if (c == '[') {
bracket = 1; bracket = 1;
} else if (c == ']') { } else if (c == ']') {
bracket = 0; bracket = 0;
} }
addchar_(c, &lastre); addchar(c, &lastre);
} }
if (n == 0) { if (n == 0) {
if (!pattern) if (!pattern)
error("no previous pattern"); error("no previous pattern");
return; return;
} }
addchar_('\0', &lastre); addchar('\0', &lastre);
if (pattern) if (pattern)
regfree(pattern); regfree(pattern);
@ -839,13 +824,13 @@ join(void)
s.siz = s.cap = 0; s.siz = s.cap = 0;
for (i = line1;; i = nextln(i)) { for (i = line1;; i = nextln(i)) {
for (t = gettxt(i); (c = *t) != '\n'; ++t) for (t = gettxt(i); (c = *t) != '\n'; ++t)
addchar_(*t, &s); addchar(*t, &s);
if (i == line2) if (i == line2)
break; break;
} }
addchar_('\n', &s); addchar('\n', &s);
addchar_('\0', &s); addchar('\0', &s);
delete(line1, line2); delete(line1, line2);
inject(s.str, 1); inject(s.str, 1);
free(s.str); free(s.str);
@ -908,12 +893,12 @@ execsh(void)
error("no current filename"); error("no current filename");
repl = 1; repl = 1;
for (p = savfname; *p; ++p) for (p = savfname; *p; ++p)
addchar_(*p, &cmd); addchar(*p, &cmd);
} else { } else {
addchar_(c, &cmd); addchar(c, &cmd);
} }
} }
addchar_('\0', &cmd); addchar('\0', &cmd);
if (repl) if (repl)
puts(cmd.str); puts(cmd.str);
@ -932,8 +917,8 @@ getrhs(int delim)
s.str = NULL; s.str = NULL;
s.siz = s.cap = 0; s.siz = s.cap = 0;
while ((c = input()) != '\n' && c != EOF && c != delim) while ((c = input()) != '\n' && c != EOF && c != delim)
addchar_(c, &s); addchar(c, &s);
addchar_('\0', &s); addchar('\0', &s);
if (c == EOF) if (c == EOF)
error("invalid pattern delimiter"); error("invalid pattern delimiter");
if (c == '\n') { if (c == '\n') {
@ -975,7 +960,7 @@ addpre(String *s)
char *p; char *p;
for (p = lastmatch; p < lastmatch + matchs[0].rm_so; ++p) for (p = lastmatch; p < lastmatch + matchs[0].rm_so; ++p)
addchar_(*p, s); addchar(*p, s);
} }
static void static void
@ -984,8 +969,8 @@ addpost(String *s)
char c, *p; char c, *p;
for (p = lastmatch + matchs[0].rm_eo; (c = *p); ++p) for (p = lastmatch + matchs[0].rm_eo; (c = *p); ++p)
addchar_(c, s); addchar(c, s);
addchar_('\0', s); addchar('\0', s);
} }
static int static int
@ -998,7 +983,7 @@ addsub(String *s, int nth, int nmatch)
q = lastmatch + matchs[0].rm_so; q = lastmatch + matchs[0].rm_so;
end = lastmatch + matchs[0].rm_eo; end = lastmatch + matchs[0].rm_eo;
while (q < end) while (q < end)
addchar_(*q++, s); addchar(*q++, s);
return 0; return 0;
} }
@ -1017,11 +1002,11 @@ addsub(String *s, int nth, int nmatch)
q = lastmatch + matchs[sub].rm_so; q = lastmatch + matchs[sub].rm_so;
end = lastmatch + matchs[sub].rm_eo; end = lastmatch + matchs[sub].rm_eo;
while (q < end) while (q < end)
addchar_(*q++, s); addchar(*q++, s);
break; break;
default: default:
copy_char: copy_char:
addchar_(c, s); addchar(c, s);
break; break;
} }
} }
@ -1278,7 +1263,7 @@ save_last_cmd:
if (rep) if (rep)
return; return;
free(ocmdline); free(ocmdline);
addchar_('\0', &cmdline); addchar('\0', &cmdline);
if ((ocmdline = strdup(cmdline.str)) == NULL) if ((ocmdline = strdup(cmdline.str)) == NULL)
error("out of memory"); error("out of memory");
} }