xref: /original-bsd/usr.bin/window/cmd3.c (revision c43e4352)
1 #ifndef lint
2 static	char *sccsid = "@(#)cmd3.c	2.1 83/07/30";
3 #endif
4 
5 #include "defs.h"
6 
7 struct ww *getwin();
8 struct ww *openwin();
9 char *strtime();
10 
11 doclose(w)
12 register struct ww *w;
13 {
14 	char didit = 0;
15 	struct ww *w1;
16 
17 	if (w != 0) {
18 		if (w == selwin)
19 			setselwin(0);
20 		wwclose(w);
21 		didit++;
22 	} else {
23 		for (w = wwhead; w;) {
24 			if (w == cmdwin) {
25 				w = w->ww_next;
26 				continue;
27 			}
28 			w = (w1 = w)->ww_next;
29 			if (w1 == selwin)
30 				setselwin(0);
31 			if (w->ww_state == WW_HASPROC && w->ww_pid == 0) {
32 				wwprintf(cmdwin, "%d: pid == 0.  ",
33 					w->ww_ident);
34 			} else {
35 				wwclose(w1);
36 				didit++;
37 			}
38 		}
39 	}
40 	if (selwin == 0) {
41 		for (w = wwhead; w && w == cmdwin; w = w->ww_next)
42 			;
43 		setselwin(w);
44 	}
45 	if (didit)
46 		reframe();
47 }
48 
49 /*
50 doescape()
51 {
52 	char buf[2];
53 
54 	wwputs("New escape character? ", cmdwin);
55 	wwsetcursor(WCurRow(cmdwin->ww_win), WCurCol(cmdwin->ww_win));
56 	while ((*buf = bgetc()) < 0)
57 		bread();
58 	buf[1] = 0;
59 	setescape(buf);
60 	wwputs("\r\n", cmdwin);
61 }
62 */
63 
64 setescape(esc)
65 register char *esc;
66 {
67 	if (*esc == '^') {
68 		if (esc[1] != 0)
69 			escapec = esc[1] & 0x1f;
70 		else
71 			escapec = '^';
72 	} else
73 		escapec = *esc;
74 }
75 
76 /*
77 dolabel()
78 {
79 	register struct ww *w;
80 	char buf[30];
81 	char *malloc();
82 
83 	if ((w = getwin()) == 0)
84 		return;
85 	wwprintf(cmdwin, "Label for window %d? ", w->ww_ident);
86 	bgets(buf, sizeof buf, cmdwin);
87 	setlabel(w, buf);
88 	wwputs("\r\n", cmdwin);
89 }
90 */
91 
92 setlabel(w, label)
93 register struct ww *w;
94 char *label;
95 {
96 	char *malloc();
97 
98 	if (w->ww_label != 0)
99 		free(w->ww_label);
100 	w->ww_label = malloc(strlen(label) + 1);
101 	strcpy(w->ww_label, label);
102 	wwunframe(w);		/* cover up the old label */
103 	wwframe(w);
104 	labelwin(w);
105 }
106