Subversion Repositories svn1

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
91 - 1
/*************************************************************************
2
*           Copyright (C) 1995 Embedded Solutions
3
*                       All rights reserved
4
*
5
* file:     src\vduW32.c
6
*
7
* purpose:  This module contains all the VDU interface routines
8
*
9
*           This instance of this file implements the functions
10
*           in a Win32 platform.
11
*
12
*           A small number of routines are provided. These can be emulated
13
*           on other machines to provide similar functions
14
*
15
*           A number of general purpose I/O routines are also provided
16
*
17
* functions
18
*       init_screen             - Initialize the screen
19
*       cur                     - Position the cursor on the screen
20
*       clearscreen             - Clears the vdu screen
21
*       beep                    - Generate a bell character
22
*       flush_out               - Flush terminal output
23
*       getinp                  - Get one character of input
24
*       getnum                  - Get a number from the operator
25
*       getstring               - Get and edit a string
26
*       getsex                  - Get a sex type from the operator
27
*       getclass                - Get a class descriptor
28
*       getcountry              - Get a country descriptor
29
*       getfnc                  - Get menu selector
30
*       getyes                  - Prompt for YES / NO
31
*       to_upper                - Convert character to upper case
32
*       to_lower                - Convert character to lower case
33
*       sleep                   - Wait a bit
34
*       printf                  - Text display routines
35
*       putchar                 - Text display routines
36
*       console_clreol          - Clear to end of the line
37
*       console_prompt          - Display a hightlighted prompt
38
*
39
* programmer: David Purdie
40
*
41
* revision  date        by      reason
42
*   00.0    17/09/2002  DDP     Created
43
*
44
**************************************************************************/
45
 
46
#include    <stdio.h>
47
#include    <ctype.h>
48
#include    <windows.h>
49
#include    <wincon.h>
50
 
51
#include    "consts.h"
52
#include    "structs.h"
53
#include    "proto.h"
54
#include "QApplication"
55
 
56
/* variables used by the routines */
57
 
58
int         n_lines;                             /* Number of lines on the screen */
59
int         n_cols;
60
 
61
int         rubout = '\010';                     /* users rubout character */
62
char        escape = '\033';                     /* Escape character */
63
int         abort_flag = FALSE;                  /* Abort character detected */
64
int         fnc_opr;                             /* Function key pushed */
65
char        *force_cmds = NULL;                  /* Initial commnads */
66
 
67
 
68
HANDLE      h_console;                          /* Output handle */
69
 
70
/*
71
**  Prototypes
72
*/
73
int get_kb_character( void );
74
 
75
/*----------------------------------------------------------------------------
76
** FUNCTION           : set_commands
77
**
78
** DESCRIPTION        :
79
**
80
**
81
** INPUTS             : cptr            - Address of commands to execute
82
**
83
** RETURNS            : Nothing
84
**
85
** PRECONDITION       : 
86
**
87
** EXCEPTIONS         :
88
**
89
** WARNING            :
90
**
91
** SEE ALSO           :
92
----------------------------------------------------------------------------*/
93
 
94
void set_commands ( char * cptr )
95
{
96
    force_cmds = cptr;
97
}
98
 
99
 
100
/*========================================================================
101
 *
102
 *  Initialize the screen
103
 *
104
 *  Purpose:
105
 *      This function is called to Initialize the screen
106
 *
107
 *  Parameters:
108
 *      None
109
 *
110
 *  Returns:
111
 *      Nothing
112
 *
113
 *========================================================================*/
114
 
115
void init_screen( void )
116
{
117
    /*
118
    **  Save a handle to the console
119
    */
120
    h_console = GetStdHandle(STD_OUTPUT_HANDLE);
121
 
122
    /*
123
    **  Operate within a virtual console area of 24 * 80
124
    **  Ignore the real console area
125
    */
126
    n_lines = 24;                                /* Fix number of lines for export */
127
    n_cols = 80;                                 /* Number of cols */
128
}
129
 
130
 
131
/*========================================================================
132
 *
133
 *  Restore screen to normal
134
 *
135
 *  Purpose:
136
 *      This function is called to Restore screen to normal
137
 *
138
 *  Parameters:
139
 *      None
140
 *
141
 *  Returns:
142
 *      Nothing
143
 *
144
 *========================================================================*/
145
 
146
void fix_screen( void )                          /* Restore screen to normal */
147
{
148
    flush_out();
149
}
150
 
151
/*========================================================================
152
 *
153
 *  Position the cursor on the screen
154
 *
155
 *  Purpose:
156
 *      This function is called to Position the cursor on the screen
157
 *
158
 *  Parameters:
159
 *      x               col number
160
 *      y               line number
161
 *
162
 *  Returns:
163
 *      Nothing
164
 *
165
 *========================================================================*/
166
 
167
void cur( int x, int y )
168
{
169
    COORD cursor;
170
 
171
    cursor.Y = y;
172
    cursor.X = x;
173
    SetConsoleCursorPosition ( h_console, cursor );
174
}
175
 
176
/*========================================================================
177
 *
178
 *  Position the cursor on the screen
179
 *
180
 *  Purpose:
181
 *      This function is called to save the current cursor location
182
 *      A single level save - for debug
183
 *
184
 *  Parameters:
185
 *      None
186
 *
187
 *  Returns:
188
 *      Nothing
189
 *
190
 *========================================================================*/
191
int save_x,save_y;
192
void save_cur(void)
193
{
194
 
195
    CONSOLE_SCREEN_BUFFER_INFO console_info;
196
 
197
    /*
198
    **  Determine the screen size and the current location of the
199
    **  cursor within the screen
200
    */
201
    GetConsoleScreenBufferInfo( h_console, &console_info );
202
    save_x = console_info.dwCursorPosition.X;
203
    save_y = console_info.dwCursorPosition.Y;
204
}
205
 
206
void restore_cur(void)
207
{
208
    cur( save_x, save_y);
209
}
210
 
211
 
212
/*========================================================================
213
 *
214
 *  Clears the vdu screen 
215
 *
216
 *  Purpose:
217
 *      This function is called to Clears the vdu screen
218
 *      From the Microsoft Web Site 
219
 *
220
 *  Parameters:
221
 *      None
222
 *
223
 *  Returns:
224
 *      Nothing
225
 *
226
 *========================================================================*/
227
 
228
void clearscreen( void )
229
{
230
    COORD coordScreen = { 0, 0 };        /* home for the cursor  */
231
    DWORD cCharsWritten;
232
    CONSOLE_SCREEN_BUFFER_INFO csbi;
233
    DWORD dwConSize;
234
 
235
    /*
236
    **   Get the number of character cells in the current buffer.
237
    */
238
 
239
    if( !GetConsoleScreenBufferInfo( h_console, &csbi ))
240
        return;
241
    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
242
 
243
    /*
244
    **   Fill the entire screen with blanks.
245
    */
246
    if( !FillConsoleOutputCharacter( h_console, (TCHAR) ' ',
247
                                dwConSize, coordScreen, &cCharsWritten ))
248
        return;
249
 
250
    /*
251
    **    Get the current text attribute.
252
    */
253
    if( !GetConsoleScreenBufferInfo( h_console, &csbi ))
254
        return;
255
 
256
    /*
257
    **  Set the buffer's attributes accordingly.
258
    */
259
    if( !FillConsoleOutputAttribute( h_console, csbi.wAttributes,
260
                                dwConSize, coordScreen, &cCharsWritten ))
261
        return;
262
 
263
    /*
264
    **   Put the cursor at its home coordinates.
265
    */
266
    SetConsoleCursorPosition( h_console, coordScreen );
267
}
268
 
269
/*========================================================================
270
 *
271
 *  Generate a bell character
272
 *
273
 *  Purpose:
274
 *      This function is called to Generate a bell character
275
 *
276
 *  Parameters:
277
 *      None
278
 *
279
 *  Returns:
280
 *      Nothing
281
 *
282
 *========================================================================*/
283
 
284
void beep( void )
285
{
286
    putchar( '\007' );
287
}
288
 
289
 
290
/*========================================================================
291
 *
292
 *  Flush terminal output
293
 *
294
 *  Purpose:
295
 *      This function is called to Flush terminal output
296
 *
297
 *  Parameters:
298
 *      None
299
 *
300
 *  Returns:
301
 *      Nothing
302
 *
303
 *========================================================================*/
304
 
305
void flush_out( void )
306
{
307
}
308
 
309
 
310
/*========================================================================
311
 *
312
 *  Get one character of input
313
 *
314
 *  Purpose:
315
 *      This function is called to Get one character of input
316
 *
317
 *  Parameters:
318
 *      None
319
 *
320
 *  Returns:
321
 *      Ascii code or internal control code which will be greater than
322
 *      a byte
323
 *
324
 *========================================================================*/
325
 
326
int getinp( void )
327
{
328
 
329
    /*
330
     * General input routine
331
     * Will intercept function keys and set flags
332
     */
333
 
334
    int         c;
335
 
336
    if ( force_cmds && *force_cmds )
337
    {
338
        c = *force_cmds++;
339
    }
340
    else
341
    {
342
        c = get_kb_character();
343
    }
344
    if( c & 0xff )
345
    {
346
        c = c & 0xff;
347
        if( c == '\r' )
348
            c = '\n';
349
        if( c == ABORT_CHAR || c == ABORT_CHAR_1 )
350
        {
351
            abort_flag = TRUE;
352
            c = ABORT_CHAR;
353
        }
354
        return ( c );                            /* Input is ascii char */
355
    }
356
    c >>= 8;                                     /* Upper byte */
357
    if( c >= 59 && c <= 68 )
358
    {
359
        fnc_opr = FNC1 + c - 59;
360
        return ( 0 );
361
    }
362
    switch ( c )
363
    {
364
    case 71:    return ( HOME_KEY );
365
    case 72:    return ( UPARROW );
366
    case 75:    return ( LEFTARROW );
367
    case 77:    return ( RIGHTARROW );
368
    case 80:    return ( DOWNARROW );
369
    case 73:    return ( PAGE_UP );
370
    case 81:    return ( PAGE_DOWN );
371
    case 79:    return ( END_KEY );
372
    case 82:    return ( INSERT_KEY );
373
    case 83:    return ( DELETE_KEY );
374
    case 15:    return ( BACKTAB );
375
    }
376
    return ( 0 );
377
}
378
 
379
 
380
/*========================================================================
381
 *
382
 *  Get a number from the operator
383
 *
384
 *  Purpose:
385
 *      This function is called to get a number from the operator
386
 *      
387
 *      This routine will accept numeric data entry from the operator
388
 *      the routine will limit the operator input to a limited number
389
 *      of characters. This allowes fixed format input
390
 *      
391
 *  Parameters:
392
 *      max_len         Max field width allowed
393
 *      final_buf       pointer to the final resting place of the number
394
 *
395
 *  Returns:
396
 *      This routine will return an indication of operator input
397
 *          0 - No valid entry
398
 *          1 - data entered and transfered to number.
399
 *
400
 *========================================================================*/
401
 
402
bool getnum( int max_len, int *final_buf )
403
{
404
    char        n_buf[30];                       /* Convert number here */
405
 
406
    n_buf[0] = '\0';
407
    if ( *final_buf )
408
        sprintf( n_buf, "%*.*d", max_len,max_len, *final_buf );
409
    if( getstring( max_len, n_buf, Digit ) )
410
    {
411
        sscanf( n_buf, "%d", final_buf );
412
        return ( TRUE );
413
    }
414
    else
415
        return ( FALSE );
416
}
417
 
418
/*========================================================================
419
 *
420
 *  Get and edit a string
421
 *
422
 *  Purpose:
423
 *      This function is called to Get and edit a string
424
 *
425
 *  Parameters:
426
 *      len                 Max length of the string
427
 *      str                 Address of the string
428
 *      limit               Types of chars allowed
429
 *
430
 *  Returns:
431
 *      Length of the input string
432
 *
433
 *========================================================================*/
434
 
435
int getstring( int len, const char *str, enum class_enum limit )
436
{
437
    char        buf[100];                        /* Internal edit buffer */
438
    int         i;                               /* Current index into buf */
439
    int         ii;                              /* Number of characters in buf */
440
    int         j;                               /* Loooopy variable */
441
    int         ch;                              /* Current input character */
442
 
443
    ( void ) memset( buf, 0, 100 );              /* Init the buffer */
444
    ( void ) strcpy( buf, str );                 /* Copy in the original string */
445
    ii = i = strlen( str );                      /* i is at the end of the string */
446
    printf( "%s", buf );                         /* Display the current string */
447
 
448
    /*
449
     * This routine assumes that the cursor is at the end of
450
     * the string as it is displayed on the screen
451
     */
452
 
453
    while( !abort_flag )
454
    {
455
        ch = getinp();                           /* Get the next character */
456
 
457
        if( ch == '\n' || ch == '\t' || fnc_opr || abort_flag )/* RETURN */
458
            break;                               /* Finish the edit */
459
 
460
        else if( ch == rubout && i )             /* Users rubout character */
461
        {
462
            i--;
463
            putchar( '\010' );
464
            for( j = i; j <= ii; j++ )
465
                buf[j] = buf[j + 1];
466
            printf( "%s ", &buf[i] );            /* Print remainder of the buffer */
467
            ii--;                                /* One less in the buffer */
468
            for( j = i; j <= ii; j++ )
469
                putchar( '\010' );
470
        }
471
 
472
        else if( ch == DELETE_KEY && i != ii )   /* Delete char under cursor */
473
        {
474
            for( j = i; j <= ii; j++ )
475
                buf[j] = buf[j + 1];
476
            printf( "%s ", &buf[i] );
477
            ii--;
478
            for( j = i; j <= ii; j++ )
479
                putchar( '\010' );
480
        }
481
 
482
        else if( ( ch == '\010' || ch == LEFTARROW ) && i ) /* Back-space */
483
        {
484
            i--;
485
            putchar( '\010' );
486
        }
487
 
488
        else if( ch == RIGHTARROW && i < ii )    /* forward */
489
            putchar( buf[i++] );
490
 
491
        else if( ( ii < len ) && ( ( ( limit == Alphanum  || limit == AlphnumUpper) && isprint( ch ) ) || ( ( limit == Digit ) && isascii( ch ) && isdigit( ch ) ) || ( ( limit == Alpha ) && isalpha( ch ) ) ) )    /* Insert the char */
492
        {
493
            if ( limit == AlphnumUpper )
494
                ch = toupper(ch);
495
 
496
            for( j = ii + 1; j > i; j-- )
497
                buf[j] = buf[j - 1];
498
            buf[i] = ch;
499
            ii++;
500
            printf( "%s", &buf[i++] );  /* Print remainder of the buffer */
501
            for( j = i; j < ii; j++ )
502
                putchar( '\010' );
503
        }
504
        else
505
        {
506
            beep();
507
        }
508
    }
509
 
510
    /*
511
     * Edit complete - transfer the data to the user 
512
     */
513
 
514
    printf( "%s", &buf[i] );            /* Cursor to end of the buffer */
515
    if( !abort_flag )
516
        strcpy( (char *)str, buf );             /* Copy buffer to the user */
517
    else
518
        ii = 0;
519
    return ( ii );                               /* Return length of input */
520
}
521
 
522
/*========================================================================
523
 *
524
 *  Get a sex type from the operator
525
 *
526
 *  Purpose:
527
 *      This function is called to Get a sex type from the operator
528
 *
529
 *  Parameters:
530
 *      None
531
 *
532
 *  Returns:
533
 *      A sex type
534
 *      The unknown sex type is used to signal no change in state
535
 *
536
 *========================================================================*/
537
 
538
sex_type getsex( void )
539
{
540
    sex_type    curr = unknown;                  /* current sex type in display */
541
    char        c;
542
 
543
    while( ( c = getinp() ) != ABORT_CHAR )
544
    {
545
        if( c == '\n' || c == '\t' )
546
        {
547
            return ( curr );
548
        }
549
        if( c == 'M' || c == 'm')
550
        {
551
            printf( "Male  \010\010\010\010\010\010" );
552
            curr = male;
553
        }
554
        else if( c == 'F' || c == 'f' )
555
        {
556
            printf( "Female\010\010\010\010\010\010" );
557
            curr = female;
558
        }
559
        else
560
        {
561
            beep();
562
        }
563
    }
564
    return ( unknown );
565
}
566
 
567
/*========================================================================
568
 *
569
 *  Get a class descriptor
570
 *
571
 *  Purpose:
572
 *      This function is called to Get a class descriptor
573
 *
574
 *  Parameters:
575
 *      None
576
 *
577
 *  Returns:
578
 *      An integer which is the index into the  config.team_class array
579
 *
580
 *========================================================================*/
581
 
582
int getclass( void )
583
{
584
    char        cc[3];                           /* Input character */
585
    int         i, j;                            /* One those loopy things */
586
 
587
 
588
    cc[0] = '\0';
589
    while( ( j = getstring( 2, cc, AlphnumUpper ) ) != 0 )
590
    {
591
        /*
592
        **  Is this a valid class
593
        */
594
        if ( (i = lookup_class(cc, NULL)) > 0 )
595
            return (i);
596
 
597
        /*
598
        **  Invalid
599
        **  Rubout and try again
600
        */
601
        beep();
602
        for( i = 0; i < j; i++ )
603
            putchar( '\010' );
604
    }
605
    return ( 0 );
606
}
607
 
608
/*========================================================================
609
 *
610
 *  Get a country descriptor
611
 *
612
 *  Purpose:
613
 *      This function is called to Get a country descriptor
614
 *
615
 *  Parameters:
616
 *      None
617
 *
618
 *  Returns:
619
 *      An integer which is the index into the config.country_name array.
620
 *
621
 *========================================================================*/
622
 
623
int getcountry( void )
624
{
625
    char        cc[5];                           /* Input character */
626
    int         i, j, k;                         /* One those loopy things */
627
 
628
    cc[0] = '\0';
629
    while( ( j = getstring( 4, cc, Alphanum ) ) != 0 )
630
    {
631
 
632
        /*
633
         * Attempt to locate the entered country in the list of defined countries
634
         */
635
 
636
        for( i = 0; i < MAX_COUNTRY; i++ )
637
        {
638
            for( k = 0; k <= j; k++ )
639
            {
640
                if( cc[k] == '\000' )
641
                    return ( ++i );              /* Found it */
642
 
643
                if( toupper( cc[k] ) !=
644
                    toupper( config.country_name[i].abr[k] ) )
645
                    break;
646
            }
647
        }
648
        beep();
649
        for( i = 0; i < j; i++ )
650
            putchar( '\010' );
651
    }
652
    return ( 0 );
653
}
654
 
655
/*========================================================================
656
 *
657
 *  Get menu selector
658
 *
659
 *  Purpose:
660
 *      This function is called to Get menu selector
661
 *
662
 *      This function will accept characters until one in
663
 *      "list" is encountered. This is returned to the user
664
 *      RETURN is valid if the first character of the list is not a "*"
665
 *      it will return the first charcater of the list;
666
 *      ABORT will return a zero
667
 *
668
 *  Parameters:
669
 *      List        A string of valid responses
670
 *
671
 *  Returns:
672
 *      Selected character
673
 *
674
 *========================================================================*/
675
 
676
char getfnc( const char *list )
677
{
678
    const char       *copylist;
679
    char        c;
680
    char        result = 0;
681
 
682
    copylist = ( *list == '*' ) ? list + 1 : list;
683
    while( ( c = getinp() ) != ABORT_CHAR )
684
    {
685
        c = toupper( c );                        /* Get a character */
686
        if( strchr( copylist, c ) )
687
        {
688
            result = c;
689
            break;
690
        }
691
 
692
        if( c == '\n' && *list != '*' )
693
        {
694
            result = *list;
695
            break;
696
        }
697
 
698
        beep();
699
    }
700
 
701
    /*
702
    **  Display the option selected
703
    **  Not ready for this yet. Looks a bit ugle in a few places
704
    */
705
    /*    if ( result )
706
    **    putchar(result);
707
    */
708
 
709
    return ( result );
710
}
711
 
712
/*========================================================================
713
 *
714
 *  Prompt for YES / NO
715
 *
716
 *  Purpose:
717
 *      This function is called to Prompt for YES / NO
718
 *
719
 *  Parameters:
720
 *      prompt      Prompt to display to the user
721
 *
722
 *  Returns:
723
 *      TRUE for Yes, FALSE for No
724
 *
725
 *========================================================================*/
726
 
727
bool getyes( const char *prompt )
728
{
729
    char        c;
730
 
731
    printf( "%s ? ", prompt );
732
    c = getfnc( "*YN" );
733
    putchar( '\n' );
734
    return ( c == 'Y' );
735
}
736
 
737
/*========================================================================
738
 *
739
 *  Convert character to upper case
740
 *
741
 *  Purpose:
742
 *      This function is called to convert character to upper case
743
 *
744
 *  Parameters:
745
 *      ch      Character to convert
746
 *
747
 *  Returns:
748
 *      Converted character
749
 *
750
 *========================================================================*/
751
 
752
char to_upper( char ch )
753
{
754
    if( islower( ch ) )
755
        return ( ch + 'A' - 'a' );
756
    return ( ch );
757
}
758
 
759
/*========================================================================
760
 *
761
 *  Convert character to lower case
762
 *
763
 *  Purpose:
764
 *      This function is called to convert character to lower case
765
 *
766
 *  Parameters:
767
 *      ch      Character to convert
768
 *
769
 *  Returns:
770
 *      Converted character
771
 *
772
 *========================================================================*/
773
 
774
char to_lower( char ch )
775
{
776
    if( isupper( ch ) )
777
        return ( ch + 'a' - 'A' );
778
    return ( ch );
779
}
780
 
781
 
782
/*========================================================================
783
 *
784
 *  Wait a bit
785
 *
786
 *  Purpose:
787
 *      This function is called to idle and to nothing for a while
788
 *
789
 *  Parameters:
790
 *      t           Time to wait
791
 *
792
 *  Returns:
793
 *      Nothing
794
 *
795
 *========================================================================*/
796
 
797
void sleep( int t )
798
{
799
    Sleep ( t * 1000 );
800
}
801
 
802
 
803
/*========================================================================
804
 *
805
 *  Clear to the end of the current display line
806
 *
807
 *  Purpose:
808
 *      Clears to the end of the line
809
 *
810
 *  Parameters:
811
 *      None
812
 *
813
 *  Returns:
814
 *      Nothing
815
 *
816
 *========================================================================*/
817
void console_clreol( void )
818
{
819
 
820
    CONSOLE_SCREEN_BUFFER_INFO console_info;
821
    DWORD                      rlen;
822
 
823
    int ii;
824
    int top;
825
 
826
 
827
    /*
828
    **  Determine the screen size and the current location of the
829
    **  cursor within the screen
830
    */
831
    GetConsoleScreenBufferInfo( h_console, &console_info );
832
 
833
    /*
834
    **  Clear all of it
835
    */
836
    top = console_info.dwSize.X - console_info.dwCursorPosition.X;
837
 
838
    for ( ii = 0; ii < top ; ii++ )
839
    {
840
        WriteConsole( h_console, " ", 1, &rlen, NULL );
841
    }
842
    cur ( console_info.dwCursorPosition.X, console_info.dwCursorPosition.Y );
843
}
844
 
845
/*========================================================================
846
 *
847
 *  printf - Text display routines
848
 *  putchar - Text display routines
849
 *
850
 *
851
 *  Purpose:
852
 *      Intercept standard output calls and direct output to the
853
 *      console.
854
 *
855
 *  Parameters: As per standard function definitions
856
 *      None
857
 *
858
 *  Returns:
859
 *      As per standard function definitions
860
 *
861
 *========================================================================*/
862
 
863
 
864
int putchar(int cc)
865
{
866
    printf( "aaa-%c", cc );
867
    return 1;
868
}
869
 
870
// void gross_error_message(void)
871
// {
872
//     LPVOID lpMsgBuf;
873
//
874
//     FormatMessage(
875
//         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
876
//         NULL,
877
//         GetLastError(),
878
//         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
879
//         (LPTSTR) &lpMsgBuf,
880
//         0,
881
//         NULL
882
//     );
883
//
884
//     // Display the string.
885
//     MessageBox( NULL, lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );
886
//
887
//     // Free the buffer.
888
//     LocalFree( lpMsgBuf );
889
// }
890
 
891
int printf( const char *format, ... )
892
{
893
    va_list     ap;
894
    char        pp[200];
895
    int         len;
896
    BOOL        result;
897
    HANDLE      h_console;
898
 
899
    DWORD       llen;
900
    DWORD       rlen;
901
 
902
 
903
    va_start( ap, format );
904
    len = vsprintf( pp, format, ap );
905
    va_end( ap );
906
qDebug("xx%s", pp);
907
    llen = len;
908
    h_console = GetStdHandle(STD_OUTPUT_HANDLE);
909
    result = WriteConsole( h_console, pp, llen, &rlen, NULL );
910
    return ( len );
911
}
912
 
913
/*========================================================================
914
 *
915
 *  Display a prompt character in a highlight
916
 *
917
 *  Purpose:
918
 *      USed to highlight menu entries
919
 *
920
 *  Parameters:
921
 *      None
922
 *
923
 *  Returns:
924
 *      Nothing
925
 *
926
 *========================================================================*/
927
void console_prompt( char prompt )
928
{
929
    SetConsoleTextAttribute( h_console, FOREGROUND_GREEN );
930
    putchar( prompt );
931
    SetConsoleTextAttribute( h_console, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );
932
}
933
 
934
/*------------------------------------------------------------------------------
935
Name:           get_kb_character
936
Description:    Extract a keyboard character - including cursor and function
937
                keys.
938
Parameters:     None
939
Global Refs:
940
Returns:        a 16 bit value that encodes ascii character and scan code
941
Side-effects:
942
------------------------------------------------------------------------------*/
943
 
944
int get_kb_character( void )
945
{
946
    HANDLE          hConsoleInput;
947
    INPUT_RECORD    Buffer;
948
    DWORD           NumberOfEventsRead;
949
 
950
    hConsoleInput = GetStdHandle(STD_INPUT_HANDLE);
951
 
952
    /*
953
    **  Process console events until we get a suitable keystroke event
954
    */
955
    FlushFileBuffers( h_console );
956
    for (;;)
957
    {
958
        if (ReadConsoleInput( hConsoleInput, &Buffer, 1, &NumberOfEventsRead ))
959
        {
960
            /*
961
            **  Only want keyboard depression - ignore other events
962
            */
963
            if (Buffer.EventType == KEY_EVENT && Buffer.Event.KeyEvent.bKeyDown)
964
            {
965
                /*
966
                **  Ignore several scan codes
967
                **  CNTRL, ALT, SHIFT, CAPLOCK
968
                */
969
                if (Buffer.Event.KeyEvent.wVirtualScanCode == 0x38 ||
970
                    Buffer.Event.KeyEvent.wVirtualScanCode == 0x1D ||
971
                    Buffer.Event.KeyEvent.wVirtualScanCode == 0x2A ||
972
                    Buffer.Event.KeyEvent.wVirtualScanCode == 0x3A)
973
                {
974
                    continue;
975
                }
976
 
977
                return ( (int) (Buffer.Event.KeyEvent.uChar.AsciiChar + (Buffer.Event.KeyEvent.wVirtualScanCode << 8)));
978
            }
979
        }
980
        else
981
        {
982
            sleep (1);
983
        }
984
    }
985
 
986
}
987
 
988
/********************************* EOF ***********************************/
989