1 /* *********************************************************** 2 * * 3 * Copyright, (C) Honeywell Bull Inc., 1987 * 4 * * 5 * Copyright, (C) Honeywell Information Systems Inc., 1986 * 6 * * 7 *********************************************************** */ 8 9 /* HISTORY COMMENTS: 10 1) change(86-07-23,Lee), approve(87-07-13,MCR7580), audit(87-07-13,Leskiw), 11 install(87-08-07,MR12.1-1072): 12 Created. 13 2) change(86-07-24,Lee), approve(87-07-13,MCR7580), audit(87-07-13,Leskiw), 14 install(87-08-07,MR12.1-1072): 15 Added function key handling. 16 3) change(86-08-22,Lee), approve(87-07-13,MCR7580), audit(87-07-13,Leskiw), 17 install(87-08-07,MR12.1-1072): 18 Passed all function key handling to call routine; 19 a -1 is returned if a function key was pressed and the parameter 'option' 20 will contain the key pressed for the special function. 21 4) change(86-09-07,Lee), approve(87-07-13,MCR7580), audit(87-07-13,Leskiw), 22 install(87-08-07,MR12.1-1072): 23 Added local editing 24 END HISTORY COMMENTS */ 25 26 /* : PROCEDURE FUNCTION (get_kb_line) 27 28 If data exists in the keyboard buffer, this routine will echo 29 the data and wait for additional data until a carriage return is 30 entered; the line entered will be passed back and the length of 31 the line is returned. If nothing exists in the keyboard buffer, 32 this routine just returns 0. If a function key press was detected, 33 a -1 is returned and the value of the function key press is put in 34 the parameter 'option'. While in this routine, the user may use 35 the backspace key to erase the previous character entered. If the 36 entire line is erased, the routine will return immediately with the 37 value 0. (This allows the emulator in the main loop to poll for 38 foreground data again.) The local_edit flag determines whether 39 the \, @, # and ESC keys have special editing functions. If 40 local_edit is TRUE, ESC and @ will kill the entire line, # will also 41 serve as a backspace and the \ serves to escape all four keys. 42 If the local_edit key is FALSE, all characters will be passed back 43 unchanged. Note that tabs will expand when the tab key is pressed 44 (according to the size in em_tab_size) but the tab character is passed 45 back to the caller unaltered. 46 47 */ 48 49 #include <ctype.h> 50 #include <ws.h> 51 #include <keydefs.h> 52 #include <emulator.h> 53 54 #if EM_DEBUG /* Do NOT compile if !EM_DEBUG */ 55 56 extern int bg_sender_stack[NUMBER_OF_CAT_ENTRIES]; 57 extern int packetize_flag; 58 extern int em_print_mode; 59 extern int em_tab_size; 60 extern int local_edit; 61 62 63 db_get_kb_line(kb_buffer,kb_stack,option) 64 65 /* INPUT */ 66 char kb_buffer[]; 67 char kb_stack[]; 68 69 /* OUTPUT */ 70 int *option; 71 { 72 73 /* MISC */ 74 int done; 75 int ch; 76 int buff_char; 77 int i; 78 int counter; 79 int kb_index; 80 int kb_posit; 81 int kb_tstptr; 82 int hidden_pos; 83 84 /* INITIALIZATION */ 85 86 done = 0; 87 kb_index = 0; 88 kb_posit = 0; 89 kb_tstptr = 0; 90 hidden_pos = 0; 91 92 /* : initialize function key value and buffer */ 93 94 *option = -1; 95 *kb_buffer = '\0'; 96 97 /* : loop unconditionally */ 98 99 while (1) { 100 101 /* : - if a key was pressed, process that character 102 -- filter special characters if in local edit mode */ 103 104 if (get_kb_key(&ch)) { 105 if (local_edit) { 106 switch (ch) { 107 case '#': ch = BS; break; 108 case '@': ch = DEL_LINE; break; 109 case ESC: ch = DEL_LINE; break; 110 111 /* : -- handle escaping of special characters 112 --- '\' pressed, wait for another key 113 --- if not function key or special character put '\' in buffer and pass 114 new key on otherwise discard '\' and pass new key on */ 115 116 case '\\': 117 while(!get_kb_key(&ch)); 118 119 if (ch < 256 && ch != '#' && ch != '@' && ch != ESC && ch != '\\') { 120 if (kb_index < KB_BUFFERSIZE) { 121 kb_buffer[kb_index++] = '\\'; 122 kb_posit++; 123 putch('\\'); 124 } 125 else 126 beep(); 127 } 128 break; 129 } 130 } 131 132 /* : -- check for extended ascii code */ 133 134 if (ch > 255 && ch < 512) { 135 if (kb_index == 0) { 136 *option = ch; 137 return(-1); 138 } 139 } 140 141 /* : -- process normal keyboard data */ 142 143 else { 144 switch (ch) { 145 146 /* : --- handle carriage return pressed 147 ---- terminate line with a linefeed 148 ---- return the length of keyboard input */ 149 150 case CR: 151 kb_buffer[kb_index++] = LF; 152 putch(LF); 153 putch(CR); 154 return(kb_index); 155 156 /* : --- handle backspace 157 ---- if something in keyboard buffer 158 ---- else nothing in keyboard buffer, return to allow scanning of 159 incoming data */ 160 161 case BS: 162 if (kb_index > 0) { 163 buff_char = kb_buffer[--kb_index]; 164 if (buff_char == TAB) { 165 counter = Pop (&kb_tstptr,kb_stack); 166 for (i = 0; i < counter; i++) 167 Screen_Erase_Char(); 168 } 169 else 170 Screen_Erase_Char(); 171 } 172 else 173 return(0); 174 break; 175 176 /* : --- wipe out entire line and return(0) 177 ---- for each character entered */ 178 179 case DEL_LINE: 180 while (kb_index > 0) { 181 buff_char = kb_buffer[--kb_index]; 182 183 if (buff_char == TAB) { 184 counter = Pop (&kb_tstptr,kb_stack); 185 for (i = 0; i < counter; i++) 186 Screen_Erase_Char(); 187 } 188 else 189 Screen_Erase_Char(); 190 } 191 return(0); 192 193 194 /* : --- handle tabs */ 195 196 case TAB: 197 if (kb_index < KB_BUFFERSIZE) { 198 kb_buffer[kb_index++] = TAB; 199 counter = em_tab_size - (kb_posit % em_tab_size); 200 kb_posit += counter; 201 Push (counter,&kb_tstptr,kb_stack); 202 for (i = 0; i < counter; i++) 203 putch(' '); 204 } 205 else 206 beep(); 207 break; 208 209 /* : --- handle normal keyboard character */ 210 default: 211 if (kb_index < KB_BUFFERSIZE) { 212 kb_buffer[kb_index++] = ch; 213 kb_posit++; 214 putch(ch); 215 } 216 else 217 beep(); 218 } 219 } 220 } 221 222 /* : -- if keyboard buffer empty, return to allow scanning of incoming data */ 223 224 else if (kb_index <= 0) return(0); 225 } 226 } 227 228 #else 229 db_get_kb_line () 230 {} 231 #endif 232 ^Z