lastselwin, and restructured some code
[unix-history] / usr / src / usr.bin / window / cmd3.c
CommitLineData
57f965d5 1#ifndef lint
7c0483b9 2static char *sccsid = "@(#)cmd3.c 3.5 83/11/30";
57f965d5
EW
3#endif
4
5#include "defs.h"
b2618f9d 6#include "string.h"
57f965d5 7
85af59e4 8c_close(w)
c417b691 9register struct ww *w;
57f965d5 10{
c417b691 11 char didit = 0;
85af59e4 12 register i;
57f965d5 13
c0893e4e 14 if (w != 0) {
85af59e4 15 closewin(w);
c417b691 16 didit++;
c0893e4e 17 } else {
85af59e4
EW
18 for (i = 0; i < NWINDOW; i++) {
19 if ((w = window[i]) == 0)
c0893e4e 20 continue;
a4c3bba5 21 closewin(w);
85af59e4 22 didit++;
57f965d5 23 }
57f965d5
EW
24 }
25 if (selwin == 0) {
7c0483b9
EW
26 if (lastselwin != 0)
27 setselwin(lastselwin);
28 else {
29 for (i = 0; i < NWINDOW && window[i] == 0; i++)
30 ;
31 if (i < NWINDOW)
32 setselwin(window[i]);
33 }
57f965d5 34 }
c417b691
EW
35 if (didit)
36 reframe();
57f965d5 37}
0de7ca29 38
85af59e4
EW
39closewin(w)
40register struct ww *w;
0de7ca29 41{
85af59e4 42 if (w == selwin)
7c0483b9
EW
43 selwin = 0;
44 if (w == lastselwin)
45 lastselwin = 0;
85af59e4
EW
46 if (w->ww_id >= 0 && w->ww_id < NWINDOW)
47 window[w->ww_id] = 0;
48 if (w->ww_label)
49 free(w->ww_label);
50 wwdelete(w);
51 wwclose(w);
0de7ca29
EW
52}
53
54setescape(esc)
55register char *esc;
56{
57 if (*esc == '^') {
58 if (esc[1] != 0)
59 escapec = esc[1] & 0x1f;
60 else
61 escapec = '^';
62 } else
63 escapec = *esc;
64}
c0893e4e 65
c0893e4e
EW
66setlabel(w, label)
67register struct ww *w;
68char *label;
69{
70 if (w->ww_label != 0)
b2618f9d
EW
71 str_free(w->ww_label);
72 if ((w->ww_label = str_cpy(label)) == 0)
85af59e4 73 return -1;
85af59e4 74 return 0;
c0893e4e 75}