Merge branch 'ical'
[alpine.git] / pico / osdep / shell.c
blob52cce652a09d1d27ec8ebbdcafa10f9838397bf8
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: shell.c 807 2007-11-09 01:21:33Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2006-2007 University of Washington
8 * Copyright 2013-2017 Eduardo Chappa
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
20 #include <system.h>
21 #include <general.h>
23 #include "../estruct.h"
24 #include "../mode.h"
25 #include "../pico.h"
26 #include "../edef.h"
27 #include "../efunc.h"
28 #include "../keydefs.h"
30 #include "tty.h"
31 #include "signals.h"
33 #ifdef _WINDOWS
34 #include "mswin.h"
35 #endif
37 #include "shell.h"
41 /* internal prototypes */
42 #ifdef SIGCONT
43 RETSIGTYPE rtfrmshell(int);
44 #endif
48 #ifdef SIGTSTP
50 * bktoshell - suspend and wait to be woken up
52 int
53 bktoshell(int f, int n)
55 UCS z = CTRL | 'Z';
57 if(!(gmode&MDSSPD)){
58 unknown_command(z);
59 return(FALSE);
62 if(Pmaster){
63 if(!Pmaster->suspend){
64 unknown_command(z);
65 return(FALSE);
68 if((*Pmaster->suspend)() == NO_OP_COMMAND){
69 int rv;
71 if(km_popped){
72 term.t_mrow = 2;
73 curwp->w_ntrows -= 2;
76 clearcursor();
77 mlerase();
78 rv = (*Pmaster->showmsg)('x');
79 ttresize();
80 picosigs();
81 if(rv) /* Did showmsg corrupt the display? */
82 pico_refresh(0, 1); /* Yes, repaint */
84 mpresf = 1;
85 if(km_popped){
86 term.t_mrow = 0;
87 curwp->w_ntrows += 2;
90 else{
91 ttresize();
92 pclear(0, term.t_nrow);
93 pico_refresh(0, 1);
96 return(TRUE);
99 if(gmode&MDSPWN){
100 char *shell;
101 int dummy;
103 vttidy();
104 movecursor(0, 0);
105 (*term.t_eeop)();
106 printf("\n\n\nUse \"exit\" to return to Pi%s\n",
107 (gmode & MDBRONLY) ? "lot" : "co");
108 system((shell = (char *)getenv("SHELL")) ? shell : "/bin/csh");
109 rtfrmshell(dummy); /* fixup tty */
111 else {
112 movecursor(term.t_nrow-1, 0);
113 peeol();
114 movecursor(term.t_nrow, 0);
115 peeol();
116 movecursor(term.t_nrow, 0);
117 printf("\n\n\nUse \"fg\" to return to Pi%s\n",
118 (gmode & MDBRONLY) ? "lot" : "co");
119 ttclose();
120 movecursor(term.t_nrow, 0);
121 peeol();
122 (*term.t_flush)();
124 signal(SIGCONT, rtfrmshell); /* prepare to restart */
125 signal(SIGTSTP, SIG_DFL); /* prepare to stop */
126 kill(0, SIGTSTP);
129 return(TRUE);
131 #else
132 #ifdef _WINDOWS
134 bktoshell(int f, int n)
136 UCS z = CTRL | 'Z';
138 if(!(gmode&MDSSPD)){
139 unknown_command(z);
140 return(FALSE);
142 if(Pmaster){
143 if(!Pmaster->suspend){
144 unknown_command(z);
145 return(FALSE);
147 (*Pmaster->suspend)();
148 return(TRUE);
151 mswin_minimize();
152 return(TRUE);
154 #endif /* _WINDOWS */
156 #endif /* SIGTSTP */
158 #ifdef SIGCONT
160 * rtfrmshell - back from shell, fix modes and return
162 RETSIGTYPE
163 rtfrmshell(int sig)
165 signal(SIGCONT, SIG_DFL);
166 ttopen();
167 ttresize();
168 pclear(0, term.t_nrow);
169 pico_refresh(0, 1);
171 #endif /* SIGCONT */