1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 */ 17 18 #ifndef lint 19 static char sccsid[] = "@(#)cmd1.c 3.34 (Berkeley) 08/04/88"; 20 #endif /* not lint */ 21 22 #include "defs.h" 23 #include "char.h" 24 25 c_window() 26 { 27 int col, row, xcol, xrow; 28 int id; 29 30 if ((id = findid()) < 0) 31 return; 32 if (!terse) 33 wwputs("New window (upper left corner): ", cmdwin); 34 col = 0; 35 row = 1; 36 wwadd(boxwin, framewin->ww_back); 37 for (;;) { 38 wwbox(boxwin, row - 1, col - 1, 3, 3); 39 wwsetcursor(row, col); 40 while (wwpeekc() < 0) 41 wwiomux(); 42 switch (getpos(&row, &col, row > 1, 0, 43 wwnrow - 1, wwncol - 1)) { 44 case 3: 45 wwunbox(boxwin); 46 wwdelete(boxwin); 47 return; 48 case 2: 49 wwunbox(boxwin); 50 break; 51 case 1: 52 wwunbox(boxwin); 53 case 0: 54 continue; 55 } 56 break; 57 } 58 if (!terse) 59 wwputs("\nNew window (lower right corner): ", cmdwin); 60 xcol = col; 61 xrow = row; 62 for (;;) { 63 wwbox(boxwin, row - 1, col - 1, 64 xrow - row + 3, xcol - col + 3); 65 wwsetcursor(xrow, xcol); 66 while (wwpeekc() < 0) 67 wwiomux(); 68 switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1)) 69 { 70 case 3: 71 wwunbox(boxwin); 72 wwdelete(boxwin); 73 return; 74 case 2: 75 wwunbox(boxwin); 76 break; 77 case 1: 78 wwunbox(boxwin); 79 case 0: 80 continue; 81 } 82 break; 83 } 84 wwdelete(boxwin); 85 if (!terse) 86 wwputc('\n', cmdwin); 87 wwcurtowin(cmdwin); 88 (void) openwin(id, row, col, xrow-row+1, xcol-col+1, default_nline, 89 (char *) 0, 1, 1, default_shellfile, default_shell); 90 } 91 92 getpos(row, col, minrow, mincol, maxrow, maxcol) 93 register int *row, *col; 94 int minrow, mincol; 95 int maxrow, maxcol; 96 { 97 static int scount; 98 int count; 99 char c; 100 int oldrow = *row, oldcol = *col; 101 102 while ((c = wwgetc()) >= 0) { 103 switch (c) { 104 case '0': case '1': case '2': case '3': case '4': 105 case '5': case '6': case '7': case '8': case '9': 106 scount = scount * 10 + c - '0'; 107 continue; 108 } 109 count = scount ? scount : 1; 110 scount = 0; 111 switch (c) { 112 case 'h': 113 if ((*col -= count) < mincol) 114 *col = mincol; 115 break; 116 case 'H': 117 *col = mincol; 118 break; 119 case 'l': 120 if ((*col += count) > maxcol) 121 *col = maxcol; 122 break; 123 case 'L': 124 *col = maxcol; 125 break; 126 case 'j': 127 if ((*row += count) > maxrow) 128 *row = maxrow; 129 break; 130 case 'J': 131 *row = maxrow; 132 break; 133 case 'k': 134 if ((*row -= count) < minrow) 135 *row = minrow; 136 break; 137 case 'K': 138 *row = minrow; 139 break; 140 case ctrl('['): 141 if (!terse) 142 wwputs("\nCancelled. ", cmdwin); 143 return 3; 144 case '\r': 145 return 2; 146 default: 147 if (!terse) 148 wwputs("\nType [hjklHJKL] to move, return to enter position, escape to cancel.", cmdwin); 149 wwbell(); 150 } 151 } 152 return oldrow != *row || oldcol != *col; 153 } 154