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