ed

simple ed
git clone git://git.2f30.org/ed.git
Log | Files | Refs

commit 158cf998967695f2eeefd2550354cc9994568a88
parent f52bd35eb9f0aeccfe3d00a1ceefe64dca087fcc
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu Dec  3 12:34:29 +0100

Handle SIGHUP

If the buffer is not empty and has changed since the
last write, the ed utility shall attempt to write a copy of
the buffer in a file. First, the file named ed.hup in the current
directory shall be used; if that fails, the file named
ed.hup in the directory named by the HOME environment
variable shall beused. In any case, the ed utility
shall exit without returning to command mode.

Diffstat:
ed.c | 22++++++++++++++++++++++
1 file changed, 22 insertions(+), 0 deletions(-)
diff --git a/ed.c b/ed.c @@ -981,6 +981,27 @@ sigintr(int n) error("interrupt"); } +static void +sighup(int dummy) +{ + char *home = getenv("HOME"), fname[FILENAME_MAX]; + + if (modflag) { + line1 = nextln(0); + line2 = lastln; + if (!setjmp(savesp)) { + dowrite("ed.hup", 1); + } else if (home && !setjmp(savesp)) { + size_t len = strlen(home) + sizeof("ed.hup") + 1; + if (len < FILENAME_MAX) { + sprintf(fname, "%s/%s", home, "ed.hup"); + dowrite(fname, 1); + } + } + } + exit(1); +} + int main(int argc, char *argv[]) { @@ -1006,6 +1027,7 @@ main(int argc, char *argv[]) } signal(SIGINT, sigintr); + signal(SIGHUP, sighup); signal(SIGQUIT, SIG_IGN); if (!setjmp(savesp)) { setscratch();