* New version 2.26
[alpine.git] / pico / osdep / shell.c
blob3deb8af1050c8e503a46dfb0c0afded63702a1ec
1 /*
2 * ========================================================================
3 * Copyright 2006-2007 University of Washington
4 * Copyright 2013-2022 Eduardo Chappa
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
16 #include <system.h>
17 #include <general.h>
19 #include "../estruct.h"
20 #include "../mode.h"
21 #include "../pico.h"
22 #include "../edef.h"
23 #include "../efunc.h"
24 #include "../keydefs.h"
26 #include "tty.h"
27 #include "signals.h"
29 #ifdef _WINDOWS
30 #include "mswin.h"
31 #endif
33 #include "shell.h"
37 /* internal prototypes */
38 #ifdef SIGCONT
39 RETSIGTYPE rtfrmshell(int);
40 #endif
44 #ifdef SIGTSTP
46 * bktoshell - suspend and wait to be woken up
48 int
49 bktoshell(int f, int n)
51 UCS z = CTRL | 'Z';
53 if(!(gmode&MDSSPD)){
54 unknown_command(z);
55 return(FALSE);
58 if(Pmaster){
59 if(!Pmaster->suspend){
60 unknown_command(z);
61 return(FALSE);
64 if((*Pmaster->suspend)() == NO_OP_COMMAND){
65 int rv;
67 if(km_popped){
68 term.t_mrow = 2;
69 curwp->w_ntrows -= 2;
72 clearcursor();
73 mlerase();
74 rv = (*Pmaster->showmsg)('x');
75 ttresize();
76 picosigs();
77 if(rv) /* Did showmsg corrupt the display? */
78 pico_refresh(0, 1); /* Yes, repaint */
80 mpresf = 1;
81 if(km_popped){
82 term.t_mrow = 0;
83 curwp->w_ntrows += 2;
86 else{
87 ttresize();
88 pclear(0, term.t_nrow);
89 pico_refresh(0, 1);
92 return(TRUE);
95 if(gmode&MDSPWN){
96 char *shell;
97 int dummy = 1;
99 vttidy();
100 movecursor(0, 0);
101 (*term.t_eeop)();
102 printf("\n\n\nUse \"exit\" to return to Pi%s\n",
103 (gmode & MDBRONLY) ? "lot" : "co");
104 system((shell = (char *)getenv("SHELL")) ? shell : "/bin/csh");
105 rtfrmshell(dummy); /* fixup tty */
107 else {
108 movecursor(term.t_nrow-1, 0);
109 peeol();
110 movecursor(term.t_nrow, 0);
111 peeol();
112 movecursor(term.t_nrow, 0);
113 printf("\n\n\nUse \"fg\" to return to Pi%s\n",
114 (gmode & MDBRONLY) ? "lot" : "co");
115 ttclose();
116 movecursor(term.t_nrow, 0);
117 peeol();
118 (*term.t_flush)();
120 signal(SIGCONT, rtfrmshell); /* prepare to restart */
121 signal(SIGTSTP, SIG_DFL); /* prepare to stop */
122 kill(0, SIGTSTP);
125 return(TRUE);
127 #else
128 #ifdef _WINDOWS
130 bktoshell(int f, int n)
132 UCS z = CTRL | 'Z';
134 if(!(gmode&MDSSPD)){
135 unknown_command(z);
136 return(FALSE);
138 if(Pmaster){
139 if(!Pmaster->suspend){
140 unknown_command(z);
141 return(FALSE);
143 (*Pmaster->suspend)();
144 return(TRUE);
147 mswin_minimize();
148 return(TRUE);
150 #endif /* _WINDOWS */
152 #endif /* SIGTSTP */
154 #ifdef SIGCONT
156 * rtfrmshell - back from shell, fix modes and return
158 RETSIGTYPE
159 rtfrmshell(int sig)
161 signal(SIGCONT, SIG_DFL);
162 ttopen();
163 ttresize();
164 pclear(0, term.t_nrow);
165 pico_refresh(0, 1);
167 #endif /* SIGCONT */