home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / npwait.zip / NPWAIT.C next >
C/C++ Source or Header  |  1993-08-19  |  2KB  |  98 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <dos.h>
  5. #include <string.h>
  6.  
  7. /*********************************************************
  8.  
  9. Usage: put in CONFIG.SYS
  10.  
  11. CALL=[path]NPWAIT.EXE [-cCOMMAND] [-wWAIT_TIME] [-r]
  12.  
  13. optional switches:
  14.  
  15.   -cCOMMAND Tells NPWAIT what command to run if a key is hit.
  16.         Usually, you would want it to run CMD.EXE, but you
  17.         can use this switch to tell it the right drive and path.
  18.         If you use something other than CMD.EXE, do not
  19.         attempt to pass arguments to the program you run.
  20.        default value = C:\OS2\CMD.EXE
  21.        example:  -cE:\OS2CMDS\CMD.EXE
  22.  
  23.   -wWAIT_TIME Tells NPWAIT how long to count down, in seconds.
  24.        default value = 10
  25.        example:  -w20
  26.  
  27.   -r        Tells NPWAIT to resume countdown when you exit the
  28.         COMMAND shell CMD.EXE.
  29.        default value = Do not resume countdown, exit NPWAIT immediately.
  30.  
  31. EXAMPLE:
  32.  
  33. The following command will run wait 20 seconds, and run
  34. the program D:\OS2\CMD.EXE if a key is pressed. When the user
  35. types EXIT at the command line, it will continue on with its
  36. countdown until it reaches 0.  Then it will continue with
  37. CONFIG.SYS.
  38.  
  39. CALL=C:\OS2UTIL\NPWAIT.EXE -cD:\OS2\CMD.EXE -w20 -r
  40.  
  41. **********************************************************/
  42.  
  43. int main(int argn, char *argc[])
  44. {
  45.   int i;
  46.   unsigned wait_duration = 10;
  47.   char command_string[240] = "c:\\os2\\cmd.exe";
  48.   char wait_string[40];
  49.   int return_flag = 0;
  50.   char *waiting = "Waiting...%d";
  51.   char *instructions = "Press any key to exit to command line";
  52.  
  53.   if (argn > 1) {
  54.     for(i=1;i<argn;i++) {
  55.       if ((argc[i][0] == '-') || (argc[i][0] == '/')) {
  56.     switch(argc[i][1]) {
  57.       case 'w':
  58.       case 'W':
  59.         strcpy(wait_string,&argc[i][2]);
  60.         wait_duration = atoi(wait_string);
  61.         break;
  62.       case 'c':
  63.       case 'C':
  64.         strcpy(command_string,&argc[i][2]);
  65.         break;
  66.       case 'r':
  67.       case 'R':
  68.         return_flag = 1;
  69.         break;
  70.     }
  71.       }
  72.     }
  73.   }
  74.  
  75.   clrscr();
  76.   gotoxy(40-strlen(instructions)/2,2);
  77.   printf(instructions);
  78.   for (i=wait_duration;i>0;i--) {
  79.     gotoxy(40-strlen(waiting)/2,10);
  80.     clreol();
  81.     printf(waiting,i);
  82.     sleep(1);
  83.     if (kbhit()) {
  84.       clrscr();
  85.       getch();
  86.       system(command_string);
  87.       clrscr();
  88.       if (! return_flag)
  89.     return(0);
  90.       gotoxy(40-strlen(instructions)/2,2);
  91.       printf(instructions);
  92.     }
  93.   }
  94.   clrscr();
  95.   return(0);
  96. }
  97.  
  98.