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