source: trunk/txlib/txcon.c@ 11

Last change on this file since 11 was 11, checked in by Jan van Wijk, 19 years ago

DFSee 8.01 level; fix crash on huge PATH; History-popup improved (4OS2 compatible)

File size: 28.0 KB
Line 
1//
2// TxWin, Textmode Windowing Library
3//
4// Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk
5//
6// ==========================================================================
7//
8// This file contains Original Code and/or Modifications of Original Code as
9// defined in and that are subject to the GNU Lesser General Public License.
10// You may not use this file except in compliance with the License.
11// BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE.
12// A copy of the License is provided with the Original Code and Modifications,
13// and is also available at http://www.dfsee.com/txwin/lgpl.htm
14//
15// This library is free software; you can redistribute it and/or modify
16// it under the terms of the GNU Lesser General Public License as published
17// by the Free Software Foundation; either version 2.1 of the License,
18// or (at your option) any later version.
19//
20// This library is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23// See the GNU Lesser General Public License for more details.
24//
25// You should have received a copy of the GNU Lesser General Public License
26// along with this library; (lgpl.htm) if not, write to the Free Software
27// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28//
29// Questions on TxWin licensing can be directed to: txwin@fsys.nl
30//
31// ==========================================================================
32//
33// Screen output using ANSI X3.64 terminal escape definitions and
34// file-logging facilities
35//
36// Author: J. van Wijk
37//
38// JvW 24-01-2003 Removed thread-id from default hex-dump display
39// JvW 01-02-2002 Added 7 bit ASCII filtering using switch '-7'
40// JvW 10-12-2001 Added TxStrListAdd
41// JvW 29-08-2001 Rename to TXCON
42// JvW 17-01-2000 Added UNICODE modus to FormatMixedStr function
43// JvW 08-03-1998 Added WIN32 ANSI expansion function (JvD)
44// JvW 20-04-1997 Ported to WIN32
45// JvW 27-01-1996 Made more generic, for LPTIO tests
46// JvW 15-02-1996 Added ddl global debugging variable
47// JvW 09-03-1996 Added trace macro's and implementation
48// JvW 26-12-1996 Added RetBool support for 64 threads
49// JvW 17-06-1995 Initial version, split off from DHPFS.C
50
51#include <txlib.h>
52#include <txwpriv.h> // private window interface
53#include <txtpriv.h> // private text interface
54
55static DEVICE_STATE screen_act = DEVICE_ON;
56static DEVICE_STATE logfile_act = DEVICE_ON;
57
58#if defined (USEWINDOWING)
59static char txConfirmTitle[] = " Confirmation request ";
60static char txMsgWarnTitle[] = " Notification or warning message ";
61#endif
62
63 // Hook control structures
64 TXH_INFO *txh_clean = NULL; // clean TxPrint handler
65 TXH_INFO *txh_raw = NULL; // raw ansi TxPrint handler
66
67static char *txm_buff = NULL; // temporary buffer for TxPrint
68
69static BOOL txk_Abort = FALSE; // TX KB-system abort notify
70static ULONG txkThread = 0; // TX KB-system owning thread
71
72#define ANSI_S_TIMEOUT 10000 // 10 seconds timeout on claim
73
74static BOOL txc_ascii7 = FALSE; // ASCII filtering off
75static char txc_ansi = A_ON;
76
77
78//- Note: 256 color strings sorted in default PC order
79ANSIDEFS ansi =
80{
81 "[0;40;30m",
82 "[0;40;34m",
83 "[0;40;32m",
84 "[0;40;36m",
85 "[0;40;31m",
86 "[0;40;35m",
87 "[0;40;33m",
88 "[0;40;37m",
89 "[1;40;30m",
90 "[1;40;34m",
91 "[1;40;32m",
92 "[1;40;36m",
93 "[1;40;31m",
94 "[1;40;35m",
95 "[1;40;33m",
96 "[1;40;37m",
97 "[0;44;30m",
98 "[0;44;34m",
99 "[0;44;32m",
100 "[0;44;36m",
101 "[0;44;31m",
102 "[0;44;35m",
103 "[0;44;33m",
104 "[0;44;37m",
105 "[1;44;30m",
106 "[1;44;34m",
107 "[1;44;32m",
108 "[1;44;36m",
109 "[1;44;31m",
110 "[1;44;35m",
111 "[1;44;33m",
112 "[1;44;37m",
113 "[0;42;30m",
114 "[0;42;34m",
115 "[0;42;32m",
116 "[0;42;36m",
117 "[0;42;31m",
118 "[0;42;35m",
119 "[0;42;33m",
120 "[0;42;37m",
121 "[1;42;30m",
122 "[1;42;34m",
123 "[1;42;32m",
124 "[1;42;36m",
125 "[1;42;31m",
126 "[1;42;35m",
127 "[1;42;33m",
128 "[1;42;37m",
129 "[0;46;30m",
130 "[0;46;34m",
131 "[0;46;32m",
132 "[0;46;36m",
133 "[0;46;31m",
134 "[0;46;35m",
135 "[0;46;33m",
136 "[0;46;37m",
137 "[1;46;30m",
138 "[1;46;34m",
139 "[1;46;32m",
140 "[1;46;36m",
141 "[1;46;31m",
142 "[1;46;35m",
143 "[1;46;33m",
144 "[1;46;37m",
145 "[0;41;30m",
146 "[0;41;34m",
147 "[0;41;32m",
148 "[0;41;36m",
149 "[0;41;31m",
150 "[0;41;35m",
151 "[0;41;33m",
152 "[0;41;37m",
153 "[1;41;30m",
154 "[1;41;34m",
155 "[1;41;32m",
156 "[1;41;36m",
157 "[1;41;31m",
158 "[1;41;35m",
159 "[1;41;33m",
160 "[1;41;37m",
161 "[0;45;30m",
162 "[0;45;34m",
163 "[0;45;32m",
164 "[0;45;36m",
165 "[0;45;31m",
166 "[0;45;35m",
167 "[0;45;33m",
168 "[0;45;37m",
169 "[1;45;30m",
170 "[1;45;34m",
171 "[1;45;32m",
172 "[1;45;36m",
173 "[1;45;31m",
174 "[1;45;35m",
175 "[1;45;33m",
176 "[1;45;37m",
177 "[0;43;30m",
178 "[0;43;34m",
179 "[0;43;32m",
180 "[0;43;36m",
181 "[0;43;31m",
182 "[0;43;35m",
183 "[0;43;33m",
184 "[0;43;37m",
185 "[1;43;30m",
186 "[1;43;34m",
187 "[1;43;32m",
188 "[1;43;36m",
189 "[1;43;31m",
190 "[1;43;35m",
191 "[1;43;33m",
192 "[1;43;37m",
193 "[0;47;30m",
194 "[0;47;34m",
195 "[0;47;32m",
196 "[0;47;36m",
197 "[0;47;31m",
198 "[0;47;35m",
199 "[0;47;33m",
200 "[0;47;37m",
201 "[1;47;30m",
202 "[1;47;34m",
203 "[1;47;32m",
204 "[1;47;36m",
205 "[1;47;31m",
206 "[1;47;35m",
207 "[1;47;33m",
208 "[1;47;37m",
209
210 "[5;40;30m",
211 "[5;40;34m",
212 "[5;40;32m",
213 "[5;40;36m",
214 "[5;40;31m",
215 "[5;40;35m",
216 "[5;40;33m",
217 "[5;40;37m",
218 "[5;40;1;30m",
219 "[5;40;1;34m",
220 "[5;40;1;32m",
221 "[5;40;1;36m",
222 "[5;40;1;31m",
223 "[5;40;1;35m",
224 "[5;40;1;33m",
225 "[5;40;1;37m",
226 "[5;44;30m",
227 "[5;44;34m",
228 "[5;44;32m",
229 "[5;44;36m",
230 "[5;44;31m",
231 "[5;44;35m",
232 "[5;44;33m",
233 "[5;44;37m",
234 "[5;44;1;30m",
235 "[5;44;1;34m",
236 "[5;44;1;32m",
237 "[5;44;1;36m",
238 "[5;44;1;31m",
239 "[5;44;1;35m",
240 "[5;44;1;33m",
241 "[5;44;1;37m",
242 "[5;42;30m",
243 "[5;42;34m",
244 "[5;42;32m",
245 "[5;42;36m",
246 "[5;42;31m",
247 "[5;42;35m",
248 "[5;42;33m",
249 "[5;42;37m",
250 "[5;42;1;30m",
251 "[5;42;1;34m",
252 "[5;42;1;32m",
253 "[5;42;1;36m",
254 "[5;42;1;31m",
255 "[5;42;1;35m",
256 "[5;42;1;33m",
257 "[5;42;1;37m",
258 "[5;46;30m",
259 "[5;46;34m",
260 "[5;46;32m",
261 "[5;46;36m",
262 "[5;46;31m",
263 "[5;46;35m",
264 "[5;46;33m",
265 "[5;46;37m",
266 "[5;46;1;30m",
267 "[5;46;1;34m",
268 "[5;46;1;32m",
269 "[5;46;1;36m",
270 "[5;46;1;31m",
271 "[5;46;1;35m",
272 "[5;46;1;33m",
273 "[5;46;1;37m",
274 "[5;41;30m",
275 "[5;41;34m",
276 "[5;41;32m",
277 "[5;41;36m",
278 "[5;41;31m",
279 "[5;41;35m",
280 "[5;41;33m",
281 "[5;41;37m",
282 "[5;41;1;30m",
283 "[5;41;1;34m",
284 "[5;41;1;32m",
285 "[5;41;1;36m",
286 "[5;41;1;31m",
287 "[5;41;1;35m",
288 "[5;41;1;33m",
289 "[5;41;1;37m",
290 "[5;45;30m",
291 "[5;45;34m",
292 "[5;45;32m",
293 "[5;45;36m",
294 "[5;45;31m",
295 "[5;45;35m",
296 "[5;45;33m",
297 "[5;45;37m",
298 "[5;45;1;30m",
299 "[5;45;1;34m",
300 "[5;45;1;32m",
301 "[5;45;1;36m",
302 "[5;45;1;31m",
303 "[5;45;1;35m",
304 "[5;45;1;33m",
305 "[5;45;1;37m",
306 "[5;43;30m",
307 "[5;43;34m",
308 "[5;43;32m",
309 "[5;43;36m",
310 "[5;43;31m",
311 "[5;43;35m",
312 "[5;43;33m",
313 "[5;43;37m",
314 "[5;43;1;30m",
315 "[5;43;1;34m",
316 "[5;43;1;32m",
317 "[5;43;1;36m",
318 "[5;43;1;31m",
319 "[5;43;1;35m",
320 "[5;43;1;33m",
321 "[5;43;1;37m",
322 "[5;47;30m",
323 "[5;47;34m",
324 "[5;47;32m",
325 "[5;47;36m",
326 "[5;47;31m",
327 "[5;47;35m",
328 "[5;47;33m",
329 "[5;47;37m",
330 "[5;47;1;30m",
331 "[5;47;1;34m",
332 "[5;47;1;32m",
333 "[5;47;1;36m",
334 "[5;47;1;31m",
335 "[5;47;1;35m",
336 "[5;47;1;33m",
337 "[5;47;1;37m",
338
339 "[0m", // NORMAL
340 "[1A", // CURSOR_UP1
341 "[2A", // CURSOR_UP2
342 "[4A", // CURSOR_UP4
343 "[8A", // CURSOR_UP8
344 "[1B", // CURSOR_DOWN1
345 "[2B", // CURSOR_DOWN2
346 "[4B", // CURSOR_DOWN4
347 "[8B", // CURSOR_DOWN8
348 "[1C", // CURSOR_RIGHT1
349 "[2C", // CURSOR_RIGHT2
350 "[4C", // CURSOR_RIGHT4
351 "[8C", // CURSOR_RIGHT8
352 "[1D", // CURSOR_LEFT1
353 "[2D", // CURSOR_LEFT2
354 "[4D", // CURSOR_LEFT4
355 "[8D", // CURSOR_LEFT8
356 "[s", // CURSOR_SAVEP
357 "[u", // CURSOR_RESTP
358 "[K", // CLEAR_TO_EOL
359 "[1;70H", // CURS_GO_1_70
360 "[1;75H", // CURS_GO_1_75
361 "[1;1H", // CURS_GO_1_01
362 "[2;1H", // CURS_GO_2_01
363 "[23;1H", // CURS_GO23_01
364 "[24;1H" // CURS_GO24_01
365};
366
367
368/*****************************************************************************/
369// Set 7-bit ASCII mode
370/*****************************************************************************/
371void TxSetAscii7Mode
372(
373 BOOL mode // IN ASCII 7-bit mode
374)
375{
376 TRACES(( "ASCII7 set 1: %s\n", (mode) ? "TRUE" : "FALSE"));
377 txc_ascii7 = mode;
378} // end 'TxSetAscii7Mode'
379/*---------------------------------------------------------------------------*/
380
381
382/*****************************************************************************/
383// Get ASCII mode, 7-bit or full
384/*****************************************************************************/
385BOOL TxGetAscii7Mode // RET ASCII 7-bit in use
386(
387 void
388)
389{
390 return( txc_ascii7);
391} // end 'TxGetAscii7Mode'
392/*---------------------------------------------------------------------------*/
393
394
395/*****************************************************************************/
396// Set ansi string definitions active or inactive
397/*****************************************************************************/
398void TxSetAnsiMode
399(
400 char mode // IN ansi mode
401)
402{
403 int i;
404
405 txc_ansi = mode;
406 for (i = 0; i < NUMBER_ANSIS; i++)
407 {
408 ansi[i][0] = mode;
409 }
410} // end 'TxSetAnsiMode'
411/*---------------------------------------------------------------------------*/
412
413
414/*****************************************************************************/
415// Get ansi string definitions active or inactive
416/*****************************************************************************/
417char TxGetAnsiMode // RET ansi mode
418(
419 void
420)
421{
422 return( txc_ansi);
423} // end 'TxGetAnsiMode'
424/*---------------------------------------------------------------------------*/
425
426
427/*****************************************************************************/
428// Test and set TxScreenState
429/*****************************************************************************/
430DEVICE_STATE TxScreenState // RET screen active
431(
432 DEVICE_STATE action // IN screen action
433)
434{
435 if (action != DEVICE_TEST)
436 {
437 screen_act = action;
438 }
439 return (screen_act);
440} // end 'TxScreenState'
441/*---------------------------------------------------------------------------*/
442
443
444/*****************************************************************************/
445// Test and set TxLogfileState, logging when state = ON and file opened
446/*****************************************************************************/
447DEVICE_STATE TxLogfileState // RET logfile active
448(
449 DEVICE_STATE action // IN screen action
450)
451{
452 if (action != DEVICE_TEST)
453 {
454 logfile_act = action;
455 }
456 return (logfile_act);
457} // end 'TxLogfileState'
458/*---------------------------------------------------------------------------*/
459
460
461/*****************************************************************************/
462// printf-like print on stdout, LOG filehandle and raw/clean copy hooks
463/*****************************************************************************/
464void TxPrint
465(
466 char *fmt, // IN format string (printf)
467 ... // IN variable arguments
468)
469{
470 va_list varargs;
471 ULONG size = 0;
472 BOOL log7bit;
473 BOOL logreopen;
474 FILE *log_handle = TxQueryLogFile( &log7bit, &logreopen);
475 TXH_INFO *hinfo; // current hook info
476
477 va_start(varargs, fmt);
478 if (txm_buff == NULL)
479 {
480 txm_buff = calloc( 1, TXMAX4K);
481 }
482 if (txm_buff != NULL)
483 {
484 size = vsprintf( txm_buff, fmt, varargs); // expanded string in buffer
485
486 if (txc_ascii7) // filter to 7-bit ASCII
487 {
488 TxAscii827( txm_buff, TXASCII827_TRANS);
489 }
490
491 if ((screen_act == DEVICE_ON) && // screen output ON
492 (txh_raw == NULL)) // and not redirected to a RAW
493 { // stream (like scrollbuffer)
494 #if defined (WIN32)
495 txNtConsoleDisplay( txm_buff); // ANSI expand and print
496 #else
497 printf( "%s", txm_buff); // just print formatted buffer
498 #endif
499 fflush(stdout);
500 }
501 for (hinfo = txh_raw; hinfo != NULL; hinfo = hinfo->next)
502 {
503 if ((size < hinfo->size) && (hinfo->active) &&
504 ((screen_act == DEVICE_ON) ||
505 (hinfo->follow_screen_toggle == FALSE)))
506 {
507 strcpy( hinfo->cbuf, txm_buff);
508 (hinfo->copy) (hinfo->cbuf, hinfo->user);
509 }
510 }
511 if ((log_handle != 0) || (txh_clean != NULL))
512 {
513 TxStripAnsiCodes( txm_buff);
514 for (hinfo = txh_clean; hinfo != NULL; hinfo = hinfo->next)
515 {
516 if ((size < hinfo->size) && (hinfo->active) &&
517 ((screen_act == DEVICE_ON) ||
518 (hinfo->follow_screen_toggle == FALSE)))
519 {
520 strcpy( hinfo->cbuf, txm_buff);
521 (hinfo->copy) (hinfo->cbuf, hinfo->user);
522 }
523 }
524 if ((log_handle != 0) && (logfile_act == DEVICE_ON))
525 {
526 if (!txc_ascii7 && log7bit) // 7-bit ASCII for log only ?
527 {
528 TxAscii827( txm_buff, TXASCII827_TRANS);
529 }
530 fprintf( log_handle, "%s", txm_buff);
531 if (logreopen)
532 {
533 TxCloseReopenLogFile(); // close/reopen (force flush)
534 }
535 else
536 {
537 fflush( log_handle); // soft flush
538 }
539 }
540 }
541 }
542 va_end(varargs);
543} // end 'TxPrint'
544/*---------------------------------------------------------------------------*/
545
546
547/*****************************************************************************/
548// Remove ANSI control code from a text-string (in place conversion)
549/*****************************************************************************/
550char *TxStripAnsiCodes // RET stripped string
551(
552 char *text // INOUT ANSI text to strip
553)
554{
555 char *rd = text; // read-pointer in string
556 char *wr = text; // write pointer
557
558 while (*rd)
559 {
560 if ((*rd == TXK_ESCAPE) && (*(rd+1) == '['))
561 {
562 rd += 2;
563 while ((isdigit(*rd)) || (*rd == ';'))
564 {
565 rd++;
566 }
567 }
568 else
569 {
570 *(wr++) = *rd; // copy the character
571 }
572 rd++;
573 }
574 *wr = '\0'; // terminate stripped string
575 return( text);
576} // end 'TxStripAnsiCodes'
577/*---------------------------------------------------------------------------*/
578
579
580/*****************************************************************************/
581// Claim TX keyboard access-functions for current thread (TxAbort etc)
582/*****************************************************************************/
583ULONG TxClaimKeyboard // RET previous owner
584(
585 void
586)
587{
588 ULONG rc = txkThread; // function return
589
590 ENTER();
591
592 txkThread = TXCURTHREAD;
593
594 RETURN (rc);
595} // end 'TxClaimKeyboard'
596/*---------------------------------------------------------------------------*/
597
598
599/*****************************************************************************/
600// Cancel any pending abort status (as returned by TxAbort)
601/*****************************************************************************/
602void TxCancelAbort
603(
604 void
605)
606{
607 ENTER();
608
609 txk_Abort = FALSE;
610
611 VRETURN ();
612} // end 'TxCancelAbort'
613/*---------------------------------------------------------------------------*/
614
615/*****************************************************************************/
616// Set abort status to pending, for other threads (as returned by TxAbort)
617/*****************************************************************************/
618void TxSetPendingAbort
619(
620 void
621)
622{
623 ENTER();
624
625 txk_Abort = TRUE;
626
627 VRETURN ();
628} // end 'TxSetPendingAbort'
629/*---------------------------------------------------------------------------*/
630
631
632/*****************************************************************************/
633// Return kbhit status and latest More ... reply, read away the hit
634/*****************************************************************************/
635BOOL TxAbort // RET TRUE when abort wanted
636(
637 void
638)
639{
640 BOOL aborting = FALSE;
641 ULONG key;
642
643 if ((txk_Abort) || // already aborting
644 (txkThread != TXCURTHREAD)) // or not KB owning thread
645 {
646 aborting = txk_Abort;
647 }
648 else
649 {
650 if (kbhit())
651 {
652 #if defined (USEWINDOWING)
653 key = txwGetInputEvent( NULL);
654 #else
655 key = getch();
656 #endif
657 switch (key)
658 {
659 case TXK_ESCAPE:
660 aborting = TRUE; // abort if <Esc>
661 txk_Abort = TRUE; // remember abort status
662 break;
663
664#if defined (DUMP)
665 case TXa_SLASH: // toggle trace value
666 switch (TxTrLevel)
667 {
668 case 0: TxTrLevel = 1; break;
669 case 1: TxTrLevel = 100; break;
670 default: TxTrLevel = 0; break;
671 }
672 break;
673#endif
674 default: // route some keys to focus-win
675 #if defined (USEWINDOWING)
676 if (txwa->desktop != NULL) // if windowing is active
677 {
678 switch (key) // do not send critical keys
679 {
680 case TXk_ENTER:
681 break;
682
683 default:
684 txwSendMsg((TXWHANDLE) txwa->focus, TXWM_CHAR, 0, key);
685 break;
686 }
687 }
688 #endif // USEWINDOWING
689 break;
690 }
691 }
692 }
693 return( aborting);
694} // end 'TxAbort'
695/*---------------------------------------------------------------------------*/
696
697
698/*****************************************************************************/
699// Display a message using format string and ask confirmation
700/*****************************************************************************/
701BOOL TxConfirm // RET Confirmed
702(
703 ULONG helpid, // IN helpid confirmation
704 char *fmt, // IN format string (printf)
705 ... // IN variable arguments
706)
707{
708 BOOL cf = TRUE; // return value
709 TX1K text;
710 int reply = 'n';
711 va_list varargs;
712 char **mText; // formatted text for display
713 int ll; // real max line length
714 int lines; // nr of lines
715 DEVICE_STATE sa = screen_act;
716
717 if ((ll = TxScreenCols() -12) < 20) // ScreenCols will be 0 if
718 { // output is redirected!
719 ll = 20;
720 }
721 if ((txwa->desktop != NULL) && (!TxaExeSwitch('p')))
722 {
723 screen_act = DEVICE_OFF; // no regular text if windowed
724 } // and not 'pedantic mode'
725 else
726 {
727 screen_act = DEVICE_ON; // force screen for confirm
728 }
729 va_start(varargs, fmt);
730 vsprintf( text, fmt, varargs); // format the message
731
732 mText = txString2Text( text, &ll, &lines); // convert to multi-line
733 TxPrint( "\n"); // force empty line before
734 TxShowTxt( mText); // display in scrollbuffer
735 txFreeText( mText); // free the text memory
736
737 screen_act = sa; // restore screen state
738 // to allow sbView output while
739 // MsgBox is up (other threads!)
740 #if defined (USEWINDOWING)
741 if (txwa->desktop != NULL) // there is a desktop
742 {
743 char *yn;
744
745 TxStripAnsiCodes( text); // remove colors for popup
746 if ((yn = strstr( text, "[Y/N]")) != NULL)
747 {
748 *yn = '\0'; // remove [y/n] part
749 }
750 switch (txwMessageBox( TXHWND_DESKTOP, TXHWND_DESKTOP,
751 text, txConfirmTitle, helpid,
752 TXMB_YESNOCANCEL | TXMB_MOVEABLE |
753 TXMB_HCENTER | TXMB_VCENTER) )
754 {
755 case TXMBID_OK: // F4=OK
756 case TXMBID_YES:
757 reply = 'y'; // for logging only
758 break;
759
760 case TXMBID_CANCEL:
761 TxSetPendingAbort();
762 TxPrint( "Abort");
763 reply = '!';
764 default:
765 cf = FALSE; // not confirmed
766 break;
767 }
768 }
769 else // use non-windowed interface
770 #endif // USEWINDOWING
771 {
772 if (TxAbort())
773 {
774 reply = TXK_ESCAPE;
775 }
776 else
777 {
778 reply = getch(); // wait for next keystroke
779 }
780 switch (reply)
781 {
782 case 'y': case 'Y':
783 case 'j': case 'J':
784 break;
785
786 case TXK_ESCAPE:
787 TxSetPendingAbort();
788 TxPrint( "Abort");
789 reply = '!';
790 default:
791 cf = FALSE; // not confirmed
792 break;
793 }
794 }
795 TxPrint("%c\n", reply);
796
797 return (cf);
798} // end 'TxConfirm'
799/*---------------------------------------------------------------------------*/
800
801
802/*****************************************************************************/
803// Display a message or warning using format string and wait for OK (or ESC)
804/*****************************************************************************/
805BOOL TxMessage // RET OK, not escaped
806(
807 BOOL acknowledge, // IN wait for acknowledge
808 ULONG helpid, // IN helpid confirmation
809 char *fmt, // IN format string (printf)
810 ... // IN variable arguments
811)
812{
813 BOOL rc = TRUE; // return value
814 TX1K text;
815 va_list varargs;
816 char **mText; // formatted text for display
817 int ll; // real max line length
818 int lines; // nr of lines
819 DEVICE_STATE sa = screen_act;
820
821 if ((ll = TxScreenCols() -4) < 20) // ScreenCols will be 0 if
822 { // output is redirected!
823 ll = 20;
824 }
825 if ((txwa->desktop != NULL) && (acknowledge) && (!TxaExeSwitch('p')))
826 {
827 screen_act = DEVICE_OFF; // no regular text if windowed
828 } // and not 'pedantic mode'
829 else if (acknowledge)
830 {
831 screen_act = DEVICE_ON; // force screen on for confirm
832 }
833 va_start(varargs, fmt);
834 vsprintf( text, fmt, varargs); // format the message
835
836 mText = txString2Text( text, &ll, &lines); // convert to multi-line
837 TxPrint( "\n"); // force empty line before
838 TxShowTxt( mText); // display in scrollbuffer
839 txFreeText( mText); // free the text memory
840 TxPrint("\n");
841
842 screen_act = sa; // restore screen state
843 // to allow sbView output while
844 // MsgBox is up (other threads!)
845 if (acknowledge)
846 {
847 #if defined (USEWINDOWING)
848 if (txwa->desktop != NULL) // there is a desktop
849 {
850 TxStripAnsiCodes( text); // remove colors for popup
851 if (txwMessageBox( TXHWND_DESKTOP, TXHWND_DESKTOP,
852 text, txMsgWarnTitle, helpid,
853 TXMB_OK | TXMB_MOVEABLE |
854 TXMB_VCENTER | TXMB_HCENTER) != TXMBID_OK)
855 {
856 rc = FALSE;
857 }
858 TxCancelAbort(); // avoid aborting on Escape ...
859 }
860 else // use non-windowed interface
861 #endif
862 {
863 TxPrint( "Press [Space-bar] to continue ...\n");
864 if (getch() == TXK_ESCAPE) // wait for next keystroke
865 {
866 rc = FALSE;
867 }
868 }
869 }
870 return (rc);
871} // end 'TxMessage'
872/*---------------------------------------------------------------------------*/
873
Note: See TracBrowser for help on using the repository browser.