From: millert Date: Fri, 3 Mar 2000 19:31:26 +0000 (+0000) Subject: Reverse rutgers change (attachtoparent vs. spawncli) X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=8dd1652bc04e7548b0953dde5df08a7447f36c04;p=openbsd Reverse rutgers change (attachtoparent vs. spawncli) New ttreinit function that enters application mode, enables the keypad and resets the tty size. New spawn module that calls tttidy() to exit application mode (and cleanup) then calls ttreinit() after resume to get back into application mode. Assumes we have job control. This takes advantage of the xterm 'alternate screen'. --- diff --git a/usr.bin/mg/keymap.c b/usr.bin/mg/keymap.c index d880bce016d..69c34e300e3 100644 --- a/usr.bin/mg/keymap.c +++ b/usr.bin/mg/keymap.c @@ -218,7 +218,9 @@ extern int queryrepl(); /* Query replace */ * Defined by "spawn.c". */ extern int spawncli(); /* Run CLI in a subjob. */ +#ifdef VMS extern int attachtoparent(); /* Attach to parent process */ +#endif /* defined by "version.c" */ @@ -584,7 +586,11 @@ static PF fund_CJ[] = { killregion, /* ^W */ prefix, /* ^X */ yank, /* ^Y */ +#ifndef VMS + spawncli, /* ^Z */ +#else attachtoparent, /* ^Z */ +#endif }; static PF fund_esc[] = { prefix, /* esc */ @@ -712,7 +718,11 @@ static PF diredcl[] = { prefix, /* ^X */ }; static PF diredcz[] = { +#ifndef VMS + spawncli, /* ^Z */ +#else attachtoparent, /* ^Z */ +#endif prefix, /* esc */ rescan, /* ^\ */ rescan, /* ^] */ @@ -1071,7 +1081,11 @@ FUNCTNAMES functnames[] = { #ifndef NO_MACRO {definemacro, "start-kbd-macro"}, #endif +#ifdef VMS {attachtoparent,"suspend-emacs"}, +#else + {spawncli, "suspend-emacs"}, +#endif {usebuffer, "switch-to-buffer"}, {poptobuffer, "switch-to-buffer-other-window"}, {twiddle, "transpose-chars"}, diff --git a/usr.bin/mg/spawn.c b/usr.bin/mg/spawn.c index f907d944a57..800592d68bc 100644 --- a/usr.bin/mg/spawn.c +++ b/usr.bin/mg/spawn.c @@ -1,116 +1,39 @@ /* - * Name: MicroGnuEmacs - * Spawn CLI for System V. - * - * Spawn for System V. + * Spawn. Actually just suspends Mg. + * Assumes POSIX job control. */ #include "def.h" #include - -char *shellp = NULL; /* Saved "SHELL" program. */ -char *shname = NULL; /* Saved shell name */ +#include /* - * On System V, we no gots job control, so always run - * a subshell using fork/exec. Bound to "C-C", and used - * as a subcommand by "C-Z". (daveb) - * - * Returns 0 if the shell executed OK, something else if - * we couldn't start shell or it exited badly. + * This causes mg to send itself a stop signal. + * Assumes the parent shell supports POSIX job control. + * If the terminal supports an alternate screen, we will sitch to it. */ +/* ARGSUSED */ spawncli(f, n) { - register int pid; - register int wpid; - register void (*oqsig)(); - register void (*oisig)(); - int status; - int errp = FALSE; - - if (shellp == NULL) { - shellp = getenv("SHELL"); - if (shellp == NULL) - shellp = getenv("shell"); - if (shellp == NULL) - shellp = "/bin/sh"; /* Safer. */ - shname = strrchr( shellp, '/' ); - shname = shname ? shname++ : shellp; - - } - ttcolor(CTEXT); - ttnowindow(); - ttmove(nrow-1, 0); - if (epresf != FALSE) { - tteeol(); - epresf = FALSE; - } - ttclose(); - sgarbf = TRUE; /* Force repaint. */ - oqsig = signal(SIGQUIT, SIG_IGN); - oisig = signal(SIGINT, SIG_IGN); - if ((pid=fork()) == 0) { - (void) signal(SIGINT, oisig); - (void) signal(SIGQUIT, oqsig); - execlp(shellp, shname, "-i", (char *)NULL); - _exit(1); /* Should do better! */ - } - else if (pid > 0) { - while ((wpid=wait(&status))>=0 && wpid!=pid) - ; - } - else errp = TRUE; - - signal(SIGINT, oisig); - signal(SIGQUIT, oqsig); - ttopen(); - setttysize(); - ttwindow(); - - if(errp) - ewprintf("Failed to create process"); - - return ( errp | status ); -} - -/* - * Put the tty in normal mode, so he can do a second ^Z. Then - * wait for a char. To use ^Z^Z to suspend and "fg %mg CR CR" - * to continue; - * - * Returns 0 if it works, which presumably it must. - */ -attachtoparent(f, n) -{ - register int pid; - register int wpid; - register int (*oqsig)(); - register int (*oisig)(); - int status; - int errp = FALSE; - int omask; - sigset_t newsig,oldsig; + sigset_t oset; + int ttputc __P((int)); /* XXX */ + /* Very similar to what vttidy() does. */ ttcolor(CTEXT); ttnowindow(); - ttmove(nrow-1, 0); + ttmove(nrow - 1, 0); if (epresf != FALSE) { tteeol(); epresf = FALSE; } - ttclose(); - sgarbf = TRUE; /* Force repaint. */ -#ifdef SIGTSTP - sigemptyset(&newsig); - sigprocmask(SIG_SETMASK, &newsig, &oldsig); + if (ttcooked() == FALSE) + return (FALSE); + tttidy(); /* Exit application mode and tidy. */ + ttflush(); + (void) sigprocmask(SIG_SETMASK, NULL, &oset); (void) kill(0, SIGTSTP); - sigprocmask(SIG_SETMASK, &oldsig, NULL); -#else - getchar(); -#endif - ttopen(); - setttysize(); - ttwindow(); - - return ( 0 ); + (void) sigprocmask(SIG_SETMASK, &oset, NULL); + ttreinit(); + sgarbf = TRUE; /* Force repaint. */ + return ttraw(); } diff --git a/usr.bin/mg/tty.c b/usr.bin/mg/tty.c index fadea1673c5..7cf082667bc 100644 --- a/usr.bin/mg/tty.c +++ b/usr.bin/mg/tty.c @@ -114,6 +114,19 @@ ttinit() { setttysize(); } +/* + * Re-initialize the terminal when the editor is resumed. + * The keypad_xmit doesn't really belong here but... + */ +ttreinit() { + if (enter_ca_mode) + putpad(enter_ca_mode, 1); /* enter application mode */ + if (keypad_xmit) + putpad(keypad_xmit, 1); /* turn on keypad */ + + setttysize(); +} + /* * Clean up the terminal, in anticipation of * a return to the command interpreter. This is a no-op