home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / DESKUTIL.ZIP / pausboot.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  91 lines

  1. /*------------------------------------------------------------------*/
  2. /*           Copyright (c) 1992, Blue Bird Computing, Inc.          */
  3. /*             This is free software (NOT public domain).           */
  4. /*                                                                  */
  5. /*  You can use, redistribute, or modify this software provided no  */
  6. /*  fee is charged and this message is not removed.                 */
  7. /*------------------------------------------------------------------*/
  8. /*  Revision History:                                               */
  9. /*  1.00 12Apr92  M.A. Stern      New                               */
  10. /*  1.01 06May92  M.A. Stern      Changed time counter to tenths.   */
  11. /*                                Allow cancel of countdown.        */
  12. /*------------------------------------------------------------------*/
  13.  
  14. /*------------------------------------------------------------------*/
  15. /*  Pause the OS/2 2.0 boot up process and go to a command          */
  16. /*  prompt if spacebar pressed within some number of seconds.       */
  17. /*                                                                  */
  18. /*  Usage (In config.sys):   CALL=PAUSBOOT.EXE <seconds>            */
  19. /*                                                                  */
  20. /*  <seconds> defaults to 5 if no value given.                      */
  21. /*------------------------------------------------------------------*/
  22.  
  23. #include <stdlib.h>
  24. #include <stdio.h>
  25. #include <conio.h>
  26. #include <time.h>
  27.  
  28. #define INCL_VIO
  29. #define INCL_DOSPROCESS
  30.  
  31. #include <os2.h>
  32.  
  33. #define PROMPT " /K PROMPT=Type EXIT to continue boot-up.$_$_$i[$p]"
  34.  
  35. int main( int argc, char **argv ) {
  36.  
  37.    int     i,fPause = 0;
  38.    int     cSecs, cTenths, cDiff = 0;
  39.    char    szMessage[80];
  40.    char    szSysCmd[200];
  41.    char    c;
  42.    char    cCell[2];
  43.  
  44.    if ( argc > 1 ) cDiff = atoi( argv[1] );
  45.    if ( cDiff == 0 ) cDiff = 5;
  46.  
  47.    cTenths = cDiff * 10;
  48.  
  49.    /* Clear screen */
  50.    cCell[0] = 0x20;
  51.    cCell[1] = 0x1f;
  52.    VioScrollUp(0, 0, 0xFFFF, 0xFFFF, 0xFFFF, cCell, 0);
  53.    VioSetCurPos( 0, 0, 0);
  54.  
  55.    strcpy( szMessage, "Press ESCAPE to cancel countdown "
  56.                            "and continue boot." );
  57.    VioWrtCharStr( szMessage, strlen( szMessage ), 9, 14, 0 );
  58.  
  59.    while ( cTenths && !fPause ) {
  60.  
  61.        cSecs = (cTenths+9) / 10;
  62.        cTenths--;
  63.  
  64.        sprintf( szMessage, "Press SPACEBAR within %d seconds for "
  65.                            "command prompt. ", cSecs );
  66.                            /* Extra space above is deliberate! */
  67.  
  68.        VioWrtCharStr( szMessage, strlen( szMessage ), 12, 14, 0 );
  69.  
  70.        DosSleep( 100L );
  71.        if ( kbhit() ) {
  72.            c = getch();
  73.            if ( c == 0 || c == 0xe0 ) c = getch();
  74.            if ( c == 27 ) break;
  75.            if ( c == 32 ) fPause = 1;
  76.            }
  77.        }
  78.  
  79.    /* Clear screen again */
  80.    cCell[1] = 0x07;
  81.    VioScrollUp(0, 0, 0xFFFF, 0xFFFF, 0xFFFF, cCell, 0);
  82.    VioSetCurPos( 0, 0, 0);
  83.  
  84.    if ( fPause ) {
  85.        strcpy( szSysCmd, getenv("COMSPEC") );
  86.        strcat( szSysCmd, PROMPT );
  87.        system( szSysCmd );
  88.        }
  89.    return 0;
  90.    }
  91.