Move cmdline to String type
This commit is contained in:
parent
20794b570e
commit
f5cb020f06
32
ed.c
32
ed.c
@ -61,9 +61,8 @@ 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;
|
||||||
static char *cmdline;
|
static String cmdline;
|
||||||
static char *ocmdline;
|
static char *ocmdline;
|
||||||
static size_t cmdsiz, cmdcap;
|
|
||||||
static int repidx;
|
static int repidx;
|
||||||
static char *rhs;
|
static char *rhs;
|
||||||
static char *lastmatch;
|
static char *lastmatch;
|
||||||
@ -76,12 +75,15 @@ discard(void)
|
|||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
/* discard until end of line */
|
if (repidx >= 0)
|
||||||
if (repidx < 0 &&
|
return;
|
||||||
((cmdsiz > 0 && cmdline[cmdsiz-1] != '\n') || cmdsiz == 0)) {
|
|
||||||
while ((c = getchar()) != '\n' && c != EOF)
|
/* discard until the end of the line */
|
||||||
/* nothing */;
|
if (cmdline.siz > 0 && cmdline.str[cmdline.siz-1] == '\n')
|
||||||
}
|
return;
|
||||||
|
|
||||||
|
while ((c = getchar()) != '\n' && c != EOF)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void undo(void);
|
static void undo(void);
|
||||||
@ -158,7 +160,7 @@ input(void)
|
|||||||
return ocmdline[repidx++];
|
return ocmdline[repidx++];
|
||||||
|
|
||||||
if ((c = getchar()) != EOF)
|
if ((c = getchar()) != EOF)
|
||||||
cmdline = addchar(c, cmdline, &cmdcap, &cmdsiz);
|
addchar_(c, &cmdline);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +172,7 @@ back(int c)
|
|||||||
} else {
|
} else {
|
||||||
ungetc(c, stdin);
|
ungetc(c, stdin);
|
||||||
if (c != EOF)
|
if (c != EOF)
|
||||||
--cmdsiz;
|
--cmdline.siz;
|
||||||
}
|
}
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
@ -1085,7 +1087,7 @@ repeat:
|
|||||||
execsh();
|
execsh();
|
||||||
break;
|
break;
|
||||||
case EOF:
|
case EOF:
|
||||||
if (cmdsiz == 0)
|
if (cmdline.siz == 0)
|
||||||
quit();
|
quit();
|
||||||
case '\n':
|
case '\n':
|
||||||
if (gflag && uflag)
|
if (gflag && uflag)
|
||||||
@ -1281,8 +1283,8 @@ save_last_cmd:
|
|||||||
if (rep)
|
if (rep)
|
||||||
return;
|
return;
|
||||||
free(ocmdline);
|
free(ocmdline);
|
||||||
cmdline = addchar('\0', cmdline, &cmdcap, &cmdsiz);
|
addchar_('\0', &cmdline);
|
||||||
if ((ocmdline = strdup(cmdline)) == NULL)
|
if ((ocmdline = strdup(cmdline.str)) == NULL)
|
||||||
error("out of memory");
|
error("out of memory");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1332,7 +1334,7 @@ doglobal(void)
|
|||||||
int i, k;
|
int i, k;
|
||||||
|
|
||||||
skipblank();
|
skipblank();
|
||||||
cmdsiz = 0;
|
cmdline.siz = 0;
|
||||||
gflag = 1;
|
gflag = 1;
|
||||||
if (uflag)
|
if (uflag)
|
||||||
chkprint(0);
|
chkprint(0);
|
||||||
@ -1394,7 +1396,7 @@ edit(void)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
newcmd = 1;
|
newcmd = 1;
|
||||||
ocurln = curln;
|
ocurln = curln;
|
||||||
cmdsiz = 0;
|
cmdline.siz = 0;
|
||||||
repidx = -1;
|
repidx = -1;
|
||||||
if (optprompt) {
|
if (optprompt) {
|
||||||
fputs(prompt, stdout);
|
fputs(prompt, stdout);
|
||||||
|
Loading…
Reference in New Issue
Block a user