]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/window/cmd.c
This commit was generated by cvs2svn to compensate for changes in r75264,
[FreeBSD/FreeBSD.git] / usr.bin / window / cmd.c
1 /*
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Edward Wang at The University of California, Berkeley.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by the University of
19  *      California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36
37 #ifndef lint
38 static char sccsid[] = "@(#)cmd.c       8.1 (Berkeley) 6/6/93";
39 static char rcsid[] = "@(#)$FreeBSD$";
40 #endif /* not lint */
41
42 #include "defs.h"
43 #include "char.h"
44
45 docmd()
46 {
47         register c;
48         register struct ww *w;
49         char out = 0;
50
51         while (!out && !quit) {
52                 if ((c = wwgetc()) < 0) {
53                         if (terse)
54                                 wwsetcursor(0, 0);
55                         else {
56                                 wwputs("Command: ", cmdwin);
57                                 wwcurtowin(cmdwin);
58                         }
59                         do
60                                 wwiomux();
61                         while ((c = wwgetc()) < 0);
62                 }
63                 if (!terse)
64                         wwputc('\n', cmdwin);
65                 switch (c) {
66                 default:
67                         if (c != escapec)
68                                 break;
69                 case 'h': case 'j': case 'k': case 'l':
70                 case 'y': case 'p':
71                 case ctrl('y'):
72                 case ctrl('e'):
73                 case ctrl('u'):
74                 case ctrl('d'):
75                 case ctrl('b'):
76                 case ctrl('f'):
77                 case ctrl('s'):
78                 case ctrl('q'):
79                 case ctrl('['):
80                         if (selwin == 0) {
81                                 error("No window.");
82                                 continue;
83                         }
84                 }
85                 switch (c) {
86                 case '1': case '2': case '3': case '4': case '5':
87                 case '6': case '7': case '8': case '9':
88                         if ((w = window[c - '1']) == 0) {
89                                 error("%c: No such window.", c);
90                                 break;
91                         }
92                         setselwin(w);
93                         if (checkproc(selwin) >= 0)
94                                  out = 1;
95                         break;
96                 case '%':
97                         if ((w = getwin()) != 0)
98                                 setselwin(w);
99                         break;
100                 case ctrl('^'):
101                         if (lastselwin != 0) {
102                                 setselwin(lastselwin);
103                                 if (checkproc(selwin) >= 0)
104                                         out = 1;
105                         } else
106                                 error("No previous window.");
107                         break;
108                 case 'c':
109                         if ((w = getwin()) != 0)
110                                 closewin(w);
111                         break;
112                 case 'w':
113                         c_window();
114                         break;
115                 case 'm':
116                         if ((w = getwin()) != 0)
117                                 c_move(w);
118                         break;
119                 case 'M':
120                         if ((w = getwin()) != 0)
121                                 movewin(w, w->ww_alt.t, w->ww_alt.l);
122                         break;
123                 case 's':
124                         if ((w = getwin()) != 0)
125                                 c_size(w);
126                         break;
127                 case 'S':
128                         if ((w = getwin()) != 0)
129                                 sizewin(w, w->ww_alt.nr, w->ww_alt.nc);
130                         break;
131                 case 'y':
132                         c_yank();
133                         break;
134                 case 'p':
135                         c_put();
136                         break;
137                 case ':':
138                         c_colon();
139                         break;
140                 case 'h':
141                         (void) wwwrite(selwin, "\b", 1);
142                         break;
143                 case 'j':
144                         (void) wwwrite(selwin, "\n", 1);
145                         break;
146                 case 'k':
147                         (void) wwwrite(selwin, "\033A", 2);
148                         break;
149                 case 'l':
150                         (void) wwwrite(selwin, "\033C", 2);
151                         break;
152                 case ctrl('e'):
153                         wwscroll(selwin, 1);
154                         break;
155                 case ctrl('y'):
156                         wwscroll(selwin, -1);
157                         break;
158                 case ctrl('d'):
159                         wwscroll(selwin, selwin->ww_w.nr / 2);
160                         break;
161                 case ctrl('u'):
162                         wwscroll(selwin, - selwin->ww_w.nr / 2);
163                         break;
164                 case ctrl('f'):
165                         wwscroll(selwin, selwin->ww_w.nr);
166                         break;
167                 case ctrl('b'):
168                         wwscroll(selwin, - selwin->ww_w.nr);
169                         break;
170                 case ctrl('s'):
171                         stopwin(selwin);
172                         break;
173                 case ctrl('q'):
174                         startwin(selwin);
175                         break;
176                 case ctrl('l'):
177                         wwredraw();
178                         break;
179                 case '?':
180                         c_help();
181                         break;
182                 case ctrl('['):
183                         if (checkproc(selwin) >= 0)
184                                 out = 1;
185                         break;
186                 case ctrl('z'):
187                         wwsuspend();
188                         break;
189                 case 'q':
190                         c_quit();
191                         break;
192                 /* debugging stuff */
193                 case '&':
194                         if (debug) {
195                                 c_debug();
196                                 break;
197                         }
198                 default:
199                         if (c == escapec) {
200                                 if (checkproc(selwin) >= 0) {
201                                         (void) write(selwin->ww_pty,
202                                                 &escapec, 1);
203                                         out = 1;
204                                 }
205                         } else {
206                                 if (!terse)
207                                         wwbell();
208                                 error("Type ? for help.");
209                         }
210                 }
211         }
212         if (!quit)
213                 setcmd(0);
214 }
215
216 struct ww *
217 getwin()
218 {
219         register int c;
220         struct ww *w = 0;
221
222         if (!terse)
223                 wwputs("Which window? ", cmdwin);
224         wwcurtowin(cmdwin);
225         while ((c = wwgetc()) < 0)
226                 wwiomux();
227         if (debug && c == 'c')
228                 w = cmdwin;
229         else if (debug && c == 'f')
230                 w = framewin;
231         else if (debug && c == 'b')
232                 w = boxwin;
233         else if (c >= '1' && c < NWINDOW + '1')
234                 w = window[c - '1'];
235         else if (c == '+')
236                 w = selwin;
237         else if (c == '-')
238                 w = lastselwin;
239         if (w == 0)
240                 wwbell();
241         if (!terse)
242                 wwputc('\n', cmdwin);
243         return w;
244 }
245
246 checkproc(w)
247 struct ww *w;
248 {
249         if (w->ww_state != WWS_HASPROC) {
250                 error("No process in window.");
251                 return -1;
252         }
253         return 0;
254 }
255
256 setcmd(new)
257 char new;
258 {
259         if (new && !incmd) {
260                 if (!terse)
261                         wwadd(cmdwin, &wwhead);
262                 if (selwin != 0)
263                         wwcursor(selwin, 1);
264                 wwcurwin = 0;
265         } else if (!new && incmd) {
266                 if (!terse) {
267                         wwdelete(cmdwin);
268                         reframe();
269                 }
270                 if (selwin != 0)
271                         wwcursor(selwin, 0);
272                 wwcurwin = selwin;
273         }
274         incmd = new;
275 }
276
277 setterse(new)
278 char new;
279 {
280         if (incmd)
281                 if (new && !terse) {
282                         wwdelete(cmdwin);
283                         reframe();
284                 } else if (!new && terse)
285                         wwadd(cmdwin, &wwhead);
286         terse = new;
287 }
288
289 /*
290  * Set the current window.
291  */
292 setselwin(w)
293 struct ww *w;
294 {
295         if (selwin == w)
296                 return;
297         if (selwin != 0)
298                 lastselwin = selwin;
299         if ((selwin = w) != 0)
300                 front(selwin, 1);
301 }