1 /* ********************************************
  2    *                                          *
  3    * Copyright, (C) Honeywell Bull Inc., 1988 *
  4    *                                          *
  5    ******************************************** */
  6 
  7 /* HISTORY COMMENTS:
  8   1) change(87-05-04,Wallman), approve(87-05-04,MCR7586),
  9      audit(87-07-16,Flegel), install(87-08-07,MR12.1-1072):
 10      First release.
 11   2) change(88-04-28,Lee), approve(88-05-16,MCR7897),
 12      audit(88-09-19,Flegel), install(88-10-12,MR12.2-1160):
 13      Created. The previous WSTBKGND.C has been rewritten to
 14      handle background messages using a background screen
 15      instead of a 1 line minibuffer.
 16   3) change(88-05-31,Lee), approve(88-05-16,MCR7897),
 17      audit(88-09-19,Flegel), install(88-10-12,MR12.2-1160):
 18      Added file and printer auditing support.
 19   4) change(88-07-25,Lee), approve(88-05-16,MCR7897),
 20      audit(88-09-19,Flegel), install(88-10-12,MR12.2-1160):
 21      Documentation additions only. Added header comments to all routines.
 22   5) change(88-08-09,Lee), approve(88-05-16,MCR7897),
 23      audit(88-09-19,Flegel), install(88-10-12,MR12.2-1160):
 24      Fix references to include files; "wstdefs.h" was split into
 25      "wstdefs.h" and "wsttype.h" to avoid declaration clash; also,
 26      various constants defined to descriptive names.
 27                                                    END HISTORY COMMENTS */
 28 
 29 /* WSTBKGND - handles processing of background messages using a
 30               background screen. Replaces previous modules which
 31               used 25th line to display background messages.
 32 */
 33 
 34 #include    <stdio.h>
 35 #include    <dos.h>
 36 #include    <ws.h>
 37 #include    <ws_mcb.h>
 38 #include    <ws_error.h>
 39 #include    "wstdefs.h"
 40 #include    "wstglob.h"
 41 
 42 
 43 /*^L
 44 **********************************************************************
 45 
 46   Routine:            SHOW_BKMSG
 47 
 48   Function:
 49       This routine signals the arrival of a background message
 50 
 51   Parameters:         NONE
 52 
 53   Returns:            NONE
 54 
 55 **********************************************************************/
 56 
 57 show_bkmsg ()
 58 {
 59     signal_bg(ON);
 60     bk_msg_showing = ON;
 61 }                                       /* End of show_bkmsg */
 62 
 63 
 64 
 65 /*^L
 66 **********************************************************************
 67 
 68   Routine:            DISPLAY_BKMSG
 69 
 70   Function:
 71       This routine saves the foreground screen and enters the
 72   background screen. While in the background screen, the user may
 73   display the next background message, quit, invoke the help screen
 74   or invoke the background polling screen.
 75 
 76   Parameters:         NONE
 77 
 78   Returns:            NONE
 79 
 80 **********************************************************************/
 81 
 82 display_bkmsg ()
 83 {
 84     char    message [MAX_BG_MESS_LENGTH+1];  /* A background message */
 85     int     msg_type,       /* WSINFO or WSQUERY */
 86             sender;         /* Sender's majcap */
 87     int     bg_msg_pending;          /* count of pending background messages */
 88     char    statline[SCREEN_COLS+1]; /* string to display in status line */
 89     int     ch;             /* the key hit when waiting for input */
 90     char    *msg_ptr;
 91 
 92     /* get number of background messages pending */
 93     bg_msg_pending = tdata_arg.background_pending_flag;
 94 
 95     /* turn background messages off for now, will be reset in wsterm main */
 96     bk_msg_showing = OFF;
 97 
 98     /* save foreground screen and swap to background screen */
 99     save_wst_screen(&wst_fg_screen);
100     restore_wst_screen(&wst_bg_screen);
101 
102     /* Loop here until getbkmes says there aren't any. */
103     while (ON) {
104 
105         /* if background messages in queue */
106         if (bg_msg_pending > 0) {
107 
108             /* display number of background messages in queue on status line */
109             sprintf(statline,"Background Screen: %d message(s). <ALT-H>-help  [<q>,<p>,<ALT-M>,<ALT-D>]",
110                 bg_msg_pending);
111             status_line(statline);
112 
113             /* hide cursor */
114             cursor_move(HIDE_CURSOR_ROW,HIDE_CURSOR_COL);
115 
116             /* wait for user to hit a valid key */
117             while (TRUE) {
118                 ch = getkey(BLOCK);
119 
120                 /* if key to quit hit */
121                 if (uppercase(ch) == 'Q') {
122                     bg_msg_pending = 0;
123                     cursor_move(wst_bg_screen.cursor_row,
124                         wst_bg_screen.cursor_col);
125                     exit_bg_screen();
126                     return;
127                 }
128 
129                 /* if key to display next background message */
130                 else if (ch == ALT_M || ch == ALT_D)
131                     break;
132 
133                 /* if key to enter poll loop */
134                 else if (uppercase(ch) == 'P') {
135                     poll_bg_msg();
136                     cursor_move(wst_bg_screen.cursor_row,
137                         wst_bg_screen.cursor_col);
138                     exit_bg_screen();
139                     return;
140                 }
141 
142                 /* enter help screen, giving background screen info */
143                 else if (ch == ALT_H) {
144                     help(BG_HELP);
145 
146                     /* restore status line message when done */
147                     status_line(statline);
148                 }
149 
150                 else
151                     beep();
152             }
153 
154             /* get and display the next background message */
155             if (getbgmes (message, &msg_type, &sender) == WSNOMESS) {
156                 /* if couldn't get it, continue at top of loop to */
157                 /* exit gracefully */
158                 bg_msg_pending = 0;
159                 continue;
160             }
161 
162             /* tally background message and display it */
163             bg_msg_pending--;
164             msg_ptr = message;
165 
166             cursor_move(wst_bg_screen.cursor_row,
167                 wst_bg_screen.cursor_col);
168 
169             while (*msg_ptr)
170                 put_wst_screen(&wst_bg_screen,*msg_ptr++);
171             put_wst_screen(&wst_bg_screen,'\n');
172 
173             /* hide cursor */
174             cursor_move(HIDE_CURSOR_ROW,HIDE_CURSOR_COL);
175 
176             /* perform auditing if auditing enabled */
177             if (wst_f_audit) {
178                 f_audit_msg("==BG==> ",8);
179                 f_audit_msg(message,strlen(message));
180                 f_audit_msg("\n",1);
181             }
182 
183             if (wst_p_audit) {
184                 p_audit_msg("==BG==> ",8,statline);
185                 p_audit_msg(message,strlen(message),statline);
186                 p_audit_msg("\n",1,statline);
187             }
188 
189             /* If this is a query, contruct and send the reply */
190             if (msg_type == WSQUERY) {
191                 /* prompt user for input on status line */
192                 strcpy(statline,"Background Screen: Enter reply     <ALT-H>-help");
193                 status_line(statline);
194 
195                 /* restore cursor */
196                 cursor_move(wst_bg_screen.cursor_row,
197                     wst_bg_screen.cursor_col);
198 
199                 /* read message from keyboard */
200                 wst_getline(&wst_bg_screen,message,statline);
201 
202                 /* hide cursor */
203                 cursor_move(HIDE_CURSOR_ROW,HIDE_CURSOR_COL);
204 
205                 /* send reply to sender of background message */
206                 sendqrep (message, sender);
207 
208                 /* perform auditing if auditing enabled */
209                 if (wst_f_audit) {
210                     f_audit_msg("==BGR=> ",8);
211                     f_audit_msg(message,strlen(message));
212                     f_audit_msg("\n",1);
213                 }
214 
215                 if (wst_p_audit) {
216                     p_audit_msg("==BGR=> ",8,statline);
217                     p_audit_msg(message,strlen(message),statline);
218                     p_audit_msg("\n",1,statline);
219                 }
220 
221             }
222         }
223 
224         /* no messages */
225         else {
226             strcpy(statline,"Background Screen: No more messages. <ALT-H>-help  [<p>,<q>]");
227             status_line(statline);
228 
229             /* hide cursor */
230             cursor_move(HIDE_CURSOR_ROW,HIDE_CURSOR_COL);
231 
232             /* allow user to enter poll loop or to quit */
233             while (TRUE) {
234                 ch = getkey(BLOCK);
235                 if (ch == ALT_H) {
236                     help(BG_HELP);
237                     status_line(statline);
238                 }
239                 else if (uppercase(ch) == 'P' || uppercase(ch) == 'Q')
240                     break;
241                 else
242                     beep();
243             }
244 
245             /* background polling requested? */
246             if (uppercase(ch) == 'P')
247                 poll_bg_msg();
248 
249             cursor_move(wst_bg_screen.cursor_row,
250                 wst_bg_screen.cursor_col);
251 
252             exit_bg_screen();
253 
254             return;
255         }
256     }
257 }
258 
259 
260 
261 /*^L
262 **********************************************************************
263 
264   Routine:            EXIT_BG_SCREEN
265 
266   Function:
267       This routine saves the contents of the background screen and
268   restores the contents of the foreground screen.
269 
270   Parameters:         NONE
271 
272   Returns:            NONE
273 
274 **********************************************************************/
275 
276 exit_bg_screen()
277 {
278     save_wst_screen(&wst_bg_screen);
279     restore_wst_screen(&wst_fg_screen);
280     update_status();
281 }
282 
283 
284 
285 /*^L
286 **********************************************************************
287 
288   Routine:            POLL_BG_MSG
289 
290   Function:
291       This routine puts the user into the background polling screen.
292   Any background messages are immediately displayed upon arrival.
293   Keyboard input allows the user to quit the background screen,
294   invoke the help screen or toggle between scroll and no scroll.
295 
296   Parameters:         NONE
297 
298   Returns:            NONE
299 
300 **********************************************************************/
301 
302 poll_bg_msg()
303 {
304     int msg_type;        /* holds background message type */
305     int sender;          /* holds sender of background message */
306     char message[MAX_BG_MESS_LENGTH+1]; /* holds background message */
307     int scroll;          /* scroll switching to control local scrolling */
308     int ch;              /* holds key hit */
309     char *bgp_stat_ns;   /* points to status line message in no-scroll */
310     char *bgp_stat_s;    /* points to status line message in scroll */
311     char *bgp_stat_q;    /* points to status line message replying to query */
312     char *msg_ptr;       /* scratch message ptr */
313 
314     scroll = 1;
315     bgp_stat_ns = "Background Screen(Poll): [NO-SCROLL] <ALT-H>-help  [<q>,<other>]";
316     bgp_stat_s = "Background Screen(Poll):             <ALT-H>-help  [<q>,<other>]";
317     bgp_stat_q = "Background Screen(Poll): Enter reply     <ALT-H>-help";
318 
319     /* update the status line */
320     status_line(bgp_stat_s);
321 
322     /* poll until the user hits 'q' to quit */
323     while (TRUE) {
324         if (scroll && getbgmes (message, &msg_type, &sender) != WSNOMESS) {
325 
326             /* restore cursor */
327             cursor_move(wst_bg_screen.cursor_row,
328                 wst_bg_screen.cursor_col);
329 
330             /* display the background message */
331             msg_ptr = message;
332             while (*msg_ptr)
333                 put_wst_screen(&wst_bg_screen,*msg_ptr++);
334             put_wst_screen(&wst_bg_screen,'\n');
335 
336             /* perform auditing if enabled */
337             if (wst_f_audit) {
338                 f_audit_msg("==BG==> ",8);
339                 f_audit_msg(message,strlen(message));
340                 f_audit_msg("\n",1);
341             }
342 
343             if (wst_p_audit) {
344                 p_audit_msg("==BG==> ",8,bgp_stat_s);
345                 p_audit_msg(message,strlen(message),bgp_stat_s);
346                 p_audit_msg("\n",1,bgp_stat_s);
347             }
348 
349             /* hide cursor */
350             cursor_move(HIDE_CURSOR_ROW,HIDE_CURSOR_COL);
351 
352             /* If this is a query, contruct and send the reply */
353             if (msg_type == WSQUERY) {
354 
355                 /* restore cursor position */
356                 cursor_move(wst_bg_screen.cursor_row,
357                     wst_bg_screen.cursor_col);
358 
359                 /* update status line to indicate input state */
360                 status_line(bgp_stat_q);
361 
362                 /* get the user input (reply) */
363                 wst_getline(&wst_bg_screen,message,bgp_stat_q);
364 
365                 cursor_pos(&wst_bg_screen.cursor_row,
366                     &wst_bg_screen.cursor_col);
367 
368                 /* hide cursor */
369                 cursor_move(HIDE_CURSOR_ROW,HIDE_CURSOR_COL);
370 
371                 /* send reply message back to sender of background message */
372                 sendqrep (message, sender);
373 
374                 /* audit if auditing enabled */
375                 if (wst_f_audit) {
376                     f_audit_msg("==BGR=> ",8);
377                     f_audit_msg(message,strlen(message));
378                     f_audit_msg("\n",1);
379                 }
380 
381                 if (wst_p_audit) {
382                     p_audit_msg("==BGR=> ",8,bgp_stat_q);
383                     p_audit_msg(message,strlen(message),bgp_stat_q);
384                     p_audit_msg("\n",1,bgp_stat_q);
385                 }
386 
387                 /* update the status line to indicate polling state */
388                 status_line(bgp_stat_s);
389             }
390         }
391 
392         /* if a key has been hit */
393         if (checkkey() >= 0) {
394 
395             /* get the key */
396             ch = getkey(BLOCK);
397 
398             /* check if key hit was 'q' to quit */
399             if (uppercase(ch) == 'Q')
400                 return;
401 
402             /* check if help requested */
403             else if (ch == ALT_H) {
404                 help(BG_HELP);
405                 if (scroll)
406                     status_line(bgp_stat_s);
407                 else
408                     status_line(bgp_stat_ns);
409             }
410 
411             /* any other key hit toggles scroll/no_scroll */
412             else {
413 
414                 /* toggle scroll value and update the status line */
415                 scroll = !scroll;
416                 if (scroll)
417                     status_line(bgp_stat_s);
418                 else
419                     status_line(bgp_stat_ns);
420             }
421         }
422     }
423 }
424