1 /* ***********************************************************
  2    *                                                         *
  3    * Copyright, (C) Honeywell Bull Inc., 1988                *
  4    *                                                         *
  5    * Copyright, (C) Honeywell Information Systems Inc., 1987 *
  6    *                                                         *
  7    *********************************************************** */
  8 
  9 
 10 /* HISTORY COMMENTS:
 11   1) change(87-03-21,Wallman), approve(87-03-21,MCR7586),
 12      audit(87-08-10,Flegel), install(87-08-07,MR12.1-1072):
 13      First release.
 14   2) change(87-09-02,Wallman), approve(87-09-02,MCR7586),
 15      audit(87-08-17,Flegel), install(87-09-10,MR12.1-1103):
 16      PBF to support the ABT order by flushing keyboard input.
 17   3) change(88-02-24,Lee), approve(88-05-16,MCR7897), audit(88-09-19,Flegel),
 18      install(88-10-12,MR12.2-1160):
 19      Removed debugging code and unused variables, re-formatting.
 20   4) change(88-05-17,Lee), approve(88-05-16,MCR7897), audit(88-09-19,Flegel),
 21      install(88-10-12,MR12.2-1160):
 22      Removed code for accessing the mini-buffer on the 25th line
 23      which is now used as a status line.
 24   5) change(88-07-25,Lee), approve(88-05-16,MCR7897), audit(88-09-19,Flegel),
 25      install(88-10-12,MR12.2-1160):
 26      Documentation only, added header comments.
 27   6) change(88-08-09,Lee), approve(88-05-16,MCR7897), audit(88-09-19,Flegel),
 28      install(88-10-12,MR12.2-1160):
 29      Fix references to include files; "wstdefs.h" was split into
 30      "wstdefs.h" and "wsttype.h" to avoid declaration clash; also,
 31      various constants defined to descriptive names.
 32   7) change(89-01-30,Lee), approve(89-01-02,MCR8043), audit(89-03-14,Flegel),
 33      install(89-04-24,MR12.3-1033):
 34      phx21233 - Initialize edit-mode screen size and line length variables from
 35      incoming mowse_io control (STM) message.
 36                                                    END HISTORY COMMENTS */
 37 
 38 /* WSTFRGND - WSTERM module to process incoming foreground messages */
 39 
 40 /* This modules holds the functions needed to process foreground messages. */
 41 
 42 #include    <stdio.h>
 43 #include    <dos.h>
 44 #include    <ws.h>
 45 #include    <ws_mcb.h>
 46 #include    <wsmincap.h>
 47 #include    "wstdefs.h"
 48 #include    "wstglob.h"
 49 
 50 /*^L
 51 **********************************************************************
 52 
 53   Routine:            ASYNC_MSG
 54 
 55   Function:
 56       This routine is called to handle an async message from the
 57   host.
 58 
 59   Parameters:
 60      (input)          force_sw - if TRUE, specifies that terminal
 61                           messages are forced to be displayed;
 62                           terminal messages are usually not displayed
 63                           while handling partial keyboard input
 64 
 65   Returns:            NONE
 66 
 67 **********************************************************************/
 68 
 69 async_msg (force_sw)
 70 int force_sw;       /* Force the message */
 71 
 72 {
 73     /* If there's typeahead in kb.klin, the fg_msg signal is showing,
 74        and the force_sw is off, just return */
 75 
 76     if (fg_msg_showing && strlen (kb.klin) > 0 && ~force_sw)
 77         return;
 78 
 79     /* Is this a control message? */
 80 
 81     if (tdata_arg.minor_capability == FG_CONTROL_MESSAGE) {
 82         ctrl_msg ();
 83         fg_msg_len = 0;
 84         return;
 85     }
 86 
 87     /* Its a display message */
 88 
 89     /* Discard message while waiting for FG_BREAK */
 90 
 91     if (break_sent)
 92         fg_msg_len = 0;
 93 
 94     else {
 95 
 96         /* Display the message if there's no typeahead or it is to be forced */
 97         if ((strlen (kb.klin) == 0 && edlin.length < 1) || force_sw) {
 98 
 99             /* audit the message to file if file audit enabled */
100             if (wst_f_audit)
101                 f_audit_msg(fg_msg.text,fg_msg_len);
102 
103             /* audit the message to printer if printer audit enabled */
104             if (wst_p_audit)
105                 p_audit_msg(fg_msg.text,fg_msg_len,NULL);
106 
107             /* display the terminal message */
108             emit_msg (fg_msg.text, fg_msg_len, ~PSTR);
109             fg_msg_len = 0;
110 
111             if (fg_msg_showing) {    /* Erase fg_msg signal */
112                 signal_fg(OFF);
113                 fg_msg_showing = OFF;
114             }
115         }
116 
117         /* Otherwise, show the fg_msg signal */
118 
119         else if (~fg_msg_showing) {
120             signal_fg(ON);
121             fg_msg_showing = ON;
122         }
123     }
124 }               /* End of async_msg */
125 
126 
127 
128 /*^L
129 **********************************************************************
130 
131   Routine:            SYNC_MSG
132 
133   Function:
134       This routine is called to handle a sync message from the host.
135 
136   Parameters:         NONE
137 
138   Returns:            NONE
139 
140 **********************************************************************/
141 
142 sync_msg ()
143 {
144 
145     /* Send any typeahead */
146 
147     if (read_active && kb.cndx > 0)
148         extract_msg (~NO_BLOCK, ~TRO, TXMT_MSG, ~HIDE);
149 
150     /* Is this a control message? */
151 
152     if (tdata_arg.minor_capability == FG_CONTROL_MESSAGE)
153         ctrl_msg ();
154 
155         /* Its a display message */
156 
157     else {
158         if (~break_sent) {
159             emit_msg (fg_msg.text, fg_msg_len, ~PSTR);
160 
161             /* audit to file if file audit enabled */
162             if (wst_f_audit)
163                 f_audit_msg(fg_msg.text,fg_msg_len);
164 
165             fg_msg_len = 0;
166         }
167     }
168 
169     fg_msg_len = 0;         /* Message is procesed */
170 }               /* End of sync_msg */
171 
172 
173 
174 /*^L
175 **********************************************************************
176 
177   Routine:            CTRL_MSG
178 
179   Function:
180       This routine is called to handle control messages from the
181   host.
182 
183   Parameters:         NONE
184 
185   Returns:            NONE
186 
187 **********************************************************************/
188 
189 ctrl_msg ()
190 {
191     char    msg_id [4]; /* Message ID */
192     int no_blk_sw;      /* For no-block reads */
193 
194     strncpy (msg_id, fg_msg.ctl.hdr.id, 3);
195     msg_id[3] = 0;
196 
197     /* ABORT */
198 
199     if (strcmp (msg_id, "ABT") == 0) {
200         kb.cndx = 0;
201         kb.endx = 0;
202         setmem (kb.pos, sizeof (kb.pos), NUL);
203         setmem (kb.klin, sizeof (kb.klin), NUL);
204         edlin.length = 0;           /* phx21233 R.L. - flush edit mode input */
205         edlin.escape_flag = 0;
206         edlin.escape_arg = -1;
207         edlin.index = 0;
208     }  /* PRINTER ON/OFF */
209 
210     else if (strcmp (msg_id, "PON") == 0 || strcmp (msg_id, "POF") ==
211         0) {
212         kb.echo = -(strcmp (msg_id, "PON") == 0);
213 
214     }  /* SET TTY MODES */
215 
216     else if (strcmp (msg_id, "STM") == 0) {
217         line_kill = fg_msg.ctl.data.stm.kill;
218         char_erase = fg_msg.ctl.data.stm.erase;
219         lnc = fg_msg.ctl.data.stm.lnc;
220         strncpy (erkl_chars, &fg_msg.ctl.data.stm.kill, 3);
221 
222         /* phx21233 RL - remove restriction of page and line size to screen size */
223         screen.maxcol = fg_msg.ctl.data.stm.maxcol;
224         screen.maxlin = fg_msg.ctl.data.stm.maxlin;
225 
226         /* Mode switches */
227         sync = -((fg_msg.ctl.data.stm.modes & 1) != 0); /* Sync mode */
228         crecho = -((fg_msg.ctl.data.stm.modes & 2) != 0);   /* CRECHO mode */
229         lfecho = -((fg_msg.ctl.data.stm.modes & 4) != 0);   /* LFECHO mode */
230 
231 
232     }  /* SET BREAK TABLE */
233 
234     else if (strcmp (msg_id, "SBT") == 0) {
235         strcpy (brk_table, fg_msg.ctl.data.break_table);
236 
237     }  /* ENTER SYNC MODE */
238 
239     else if (strcmp (msg_id, "ESM") == 0) {
240         strcpy (brk_table, fg_msg.ctl.data.break_table);
241         sync = ON;
242         kb.cndx = 0;
243         kb.endx = 0;
244         setmem (kb.pos, sizeof (kb.pos), NUL);
245         setmem (kb.klin, sizeof (kb.klin), NUL);
246 
247         puttdata (FG_CONTROL_MESSAGE, "SME", 3);
248     }  /* EXIT SYNC MODE */
249 
250     else if (strcmp (msg_id, "XSM") == 0) {
251 
252         sync = OFF;
253         kb.echo = ON;
254         kb.cndx = 0;
255         kb.endx = 0;
256         setmem (kb.klin, sizeof (kb.klin), NUL);
257 
258         puttdata (FG_CONTROL_MESSAGE, "SMX", 3);
259         clear_screen ();
260 
261     }  /* READ ... */
262 
263     else if (strcmp (msg_id, "RNE") == 0 || strcmp (msg_id, "RWE") ==
264         0) {
265 
266         /* Terminate any active read */
267 
268         if (read_active) {
269             term_read = ON;
270             if (kb.cndx > 0)
271                 extract_msg (~NO_BLOCK, ~TRO, TXMT_MSG,
272                      ~HIDE);
273 
274             else
275                 send_msg (nul_str, 0);
276         }
277 
278         read_count =  HI_BYTE_VALUE * fg_msg.ctl.data.rd_ct [0] +
279             fg_msg.ctl.data.rd_ct [1];
280         no_blk_sw = -(fg_msg.ctl.hdr.msb_size && NO_BLOCK_MASK);
281 
282         /* Set up the new read */
283 
284         read_active = ON;
285         kb.echo = -(strcmp (msg_id, "RWE") == 0);
286 
287         /* Terminate again for a no-block read */
288 
289         if (no_blk_sw) {
290             term_read = ON;
291             if (kb.cndx > 0)        /* Send typeahead */
292                 extract_msg (~NO_BLOCK, ~TRO, TXMT_MSG,
293                      ~HIDE);
294 
295             else
296                 send_msg (nul_str, 0);
297         }
298     }  else /* Unsupported control order */  {
299 
300     }
301 }               /* End of ctrl_msg */
302 
303 
304 /* End of WSTFRGND */