void grabedit(struct header* hp, unsigned long type) { register char* s; register const struct lab* lp; int r; sig_t saveint; sig_t savequit; char buf[LINESIZE]; fflush(stdout); if ((saveint = signal(SIGINT, SIG_IGN)) == SIG_DFL) signal(SIGINT, SIG_DFL); if ((savequit = signal(SIGQUIT, SIG_IGN)) == SIG_DFL) signal(SIGQUIT, SIG_DFL); r = 0; for (lp = state.hdrtab; lp->name; lp++) if (type & lp->type) { if (!(s = detract(hp, lp->type))) s = ""; if (strlen(s) >= sizeof(buf)) { note(0, "%sfield too long to edit", lp->name); continue; } strcpy(buf, s); if ((r = ttyedit(0, 1, lp->name, buf, sizeof(buf))) < 0) break; headclear(hp, lp->type); extract(hp, lp->type, buf); } if (saveint != SIG_DFL) signal(SIGINT, saveint); if (savequit != SIG_DFL) signal(SIGQUIT, savequit); if (r < -1) kill(0, -(r + 1)); }
int main (int argc, char *argv[]) { #ifdef SIGINT void (*old_int) (int); #endif /* SIGINT */ #ifdef SIGQUIT void (*old_quit) (int); #endif /* SIGQUIT */ /* catch quit and hangup signals */ /* * In the terminal driver munging routines, we set Control-P * to generate an interrupt, and turn off generating Quits from * the terminal. Now we just ignore them if sent from elsewhere. */ #ifdef SIGHUP signal (SIGHUP, hup_hdlr); #endif /* SIGHUP */ #ifdef SIGINT old_int = signal (SIGINT, int_hdlr); #endif /* SIGINT */ #ifdef SIGQUIT old_quit = signal (SIGQUIT, SIG_IGN); #endif /* SIGQUIT */ if ( #ifdef SIGINT old_int == SIG_IGN || #endif /* SIGINT */ #ifdef SIGQUIT old_quit == SIG_IGN || #endif /* SIGQUIT */ 0 ) { /* fired off into the background, refuse to run */ if (isatty (fileno (stdin))) { fprintf (stderr, "%s: I refuse to run in the background.\n", basename (argv[0])); exit (2); } /* else assume input is a script */ } /* set terminal to no echo, no output processing, break enabled */ ttyedit (); initialize (argc, argv); edit (argc, argv); /* reset the terminal mode */ ttynormal (); t_exit (); return 0; }