1 #ifndef lint 2 static char *sccsid = "@(#)cmd.c 3.4 83/08/19"; 3 #endif 4 5 #include "defs.h" 6 7 struct ww *getwin(); 8 9 docmd() 10 { 11 register char c; 12 register struct ww *w; 13 14 if (!terse) 15 wwadd(cmdwin, &wwhead); 16 if (selwin != 0) 17 wwcursor(selwin, 1); 18 top: 19 while ((c = bgetc()) >= 0) { 20 if (!terse) 21 (void) wwputs("\r\n", cmdwin); 22 switch (c) { 23 default: 24 if (c == escapec) 25 goto foo; 26 break; 27 case 'h': case 'j': case 'k': case 'l': 28 case CTRL(y): 29 case CTRL(e): 30 case CTRL(u): 31 case CTRL(d): 32 case CTRL(b): 33 case CTRL(f): 34 case CTRL(s): 35 case CTRL(q): 36 case CTRL([): 37 foo: 38 if (selwin == 0) { 39 error("No window."); 40 continue; 41 } 42 } 43 switch (c) { 44 case '1': case '2': case '3': case '4': case '5': 45 case '6': case '7': case '8': case '9': 46 if ((w = window[c - '1']) == 0) { 47 wwbell(); 48 break; 49 } 50 setselwin(w); 51 goto out; 52 case '%': 53 if ((w = getwin()) != 0) 54 setselwin(w); 55 break; 56 case 'c': 57 if ((w = getwin()) != 0) 58 c_close(w); 59 break; 60 case 'C': 61 c_close((struct ww *)0); 62 break; 63 case 'w': 64 c_window(); 65 break; 66 case 'S': 67 c_show(); 68 break; 69 case 'L': 70 c_list(); 71 break; 72 case 's': 73 c_stat(); 74 break; 75 case 'M': 76 wwdumpsmap(); 77 break; 78 case 'V': 79 if ((w = getwin()) != 0) 80 wwdumpnvis(w); 81 break; 82 case 'D': 83 if ((w = getwin()) != 0) 84 wwdumpcov(w); 85 break; 86 case 'W': 87 if ((w = getwin()) != 0) 88 wwdumpwin(w); 89 break; 90 case 't': 91 c_time(RUSAGE_SELF); 92 break; 93 case 'T': 94 c_time(RUSAGE_CHILDREN); 95 break; 96 case ':': 97 c_colon(); 98 break; 99 case 'h': 100 (void) wwwrite(selwin, "\b", 1); 101 break; 102 case 'j': 103 (void) wwwrite(selwin, "\n", 1); 104 break; 105 case 'k': 106 (void) wwwrite(selwin, "\033A", 2); 107 break; 108 case 'l': 109 (void) wwwrite(selwin, "\033C", 2); 110 break; 111 case CTRL(e): 112 wwscroll(selwin, 1); 113 break; 114 case CTRL(y): 115 wwscroll(selwin, -1); 116 break; 117 case CTRL(d): 118 wwscroll(selwin, selwin->ww_w.nr / 2); 119 break; 120 case CTRL(u): 121 wwscroll(selwin, - selwin->ww_w.nr / 2); 122 break; 123 case CTRL(f): 124 wwscroll(selwin, selwin->ww_w.nr); 125 break; 126 case CTRL(b): 127 wwscroll(selwin, - selwin->ww_w.nr); 128 break; 129 case CTRL(s): 130 (void) write(selwin->ww_pty, 131 &wwwintty.ww_tchars.t_stopc, 1); 132 break; 133 case CTRL(q): 134 (void) write(selwin->ww_pty, 135 &wwwintty.ww_tchars.t_startc, 1); 136 break; 137 case CTRL(l): 138 wwredraw(); 139 break; 140 case '?': 141 c_help(); 142 break; 143 case CTRL([): 144 goto out; 145 case CTRL(z): 146 wwsuspend(); 147 break; 148 case 'q': 149 c_quit(); 150 if (quit) 151 goto out; 152 break; 153 case '.': 154 error("Use q to quit."); 155 break; 156 default: 157 if (c == escapec) { 158 (void) write(selwin->ww_pty, &escapec, 1); 159 goto out; 160 } 161 if (!terse) 162 wwbell(); 163 error("Type ? for help."); 164 break; 165 } 166 } 167 if (terse) 168 wwsetcursor(0, 0); 169 else { 170 if (!terse) 171 (void) wwputs("Command: ", cmdwin); 172 wwsetcursor(wwcurrow(cmdwin), wwcurcol(cmdwin)); 173 } 174 while (bpeekc() < 0) 175 bread(); 176 goto top; 177 out: 178 if (!quit) { 179 curwin = selwin; 180 if (!terse) { 181 wwdelete(cmdwin); 182 reframe(); 183 } 184 } 185 if (selwin != 0) 186 wwcursor(selwin, 0); 187 } 188 189 struct ww * 190 getwin() 191 { 192 register int c; 193 struct ww *w = 0; 194 195 if (!terse) 196 (void) wwputs("Which window? ", cmdwin); 197 wwsetcursor(wwcurrow(cmdwin), wwcurcol(cmdwin)); 198 while ((c = bgetc()) < 0) 199 bread(); 200 if (debug && c == 'c') 201 w = cmdwin; 202 else if (debug && c == 'f') 203 w = framewin; 204 else if (c >= '1' && c < NWINDOW + '1') 205 w = window[c - '1']; 206 if (w == 0) 207 wwbell(); 208 if (!terse) 209 (void) wwputs("\r\n", cmdwin); 210 return w; 211 } 212 213 setselwin(w) 214 register struct ww *w; 215 { 216 register struct ww *oldselwin = selwin; 217 218 if (w == oldselwin) 219 return; 220 if (selwin = w) { 221 wwdelete(w); 222 /* 223 * Stick it in front of the old selected window, 224 * or behind everbody else. 225 */ 226 wwadd(w, (oldselwin ? oldselwin : &wwhead)->ww_back); 227 } 228 reframe(); 229 } 230 231 labelwin(w) 232 register struct ww *w; 233 { 234 int mode = w == selwin ? WWM_REV : 0; 235 236 if (w->ww_id >= 0) { 237 char buf[2]; 238 239 buf[0] = w->ww_id + '1'; 240 buf[1] = 0; 241 (void) wwlabel(w, framewin, 1, buf, mode); 242 } 243 if (w->ww_label) { 244 int col; 245 246 if (w->ww_center) { 247 col = (w->ww_w.nc - strlen(w->ww_label)) / 2; 248 col = MAX(3, col); 249 } else 250 col = 3; 251 (void) wwlabel(w, framewin, col, w->ww_label, mode); 252 } 253 } 254