ed: add init()
These funcction initializes the scratch buffer, and in case of having a file name parameter it loads the file in the scratch. It also fixes a problem before this version, where the saved filename was not set when the file didn't exist.
This commit is contained in:
parent
03d27b7806
commit
b19d708923
32
ed.c
32
ed.c
@ -629,12 +629,6 @@ doread(char *fname)
|
|||||||
fp = NULL;
|
fp = NULL;
|
||||||
if (fclose(aux))
|
if (fclose(aux))
|
||||||
error("input/output error");
|
error("input/output error");
|
||||||
|
|
||||||
if (savfname[0] == '\0') {
|
|
||||||
modflag = 0;
|
|
||||||
clearundo();
|
|
||||||
strcpy(savfname, fname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1359,6 +1353,23 @@ edit(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
init(char *fname)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (setjmp(savesp))
|
||||||
|
return;
|
||||||
|
setscratch();
|
||||||
|
if (!fname)
|
||||||
|
return;
|
||||||
|
if ((len = strlen(fname)) >= FILENAME_MAX || len == 0)
|
||||||
|
error("incorrect filename");
|
||||||
|
memcpy(savfname, fname, len);
|
||||||
|
doread(fname);
|
||||||
|
clearundo();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -1380,15 +1391,8 @@ main(int argc, char *argv[])
|
|||||||
signal(SIGINT, sigintr);
|
signal(SIGINT, sigintr);
|
||||||
signal(SIGHUP, sighup);
|
signal(SIGHUP, sighup);
|
||||||
signal(SIGQUIT, SIG_IGN);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
if (!setjmp(savesp)) {
|
|
||||||
setscratch();
|
|
||||||
if (*argv) {
|
|
||||||
if (strlen(*argv) >= FILENAME_MAX)
|
|
||||||
error("file name too long");
|
|
||||||
doread(*argv);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
init(*argv);
|
||||||
edit();
|
edit();
|
||||||
|
|
||||||
/* not reached */
|
/* not reached */
|
||||||
|
Loading…
Reference in New Issue
Block a user