home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / oswait01.zip / SOURCE.ZIP / DOSWAIT!.C next >
C/C++ Source or Header  |  1994-04-09  |  3KB  |  122 lines

  1. /*
  2.  DOSWAIT! (c) 1994, ITECH-CIS
  3.  
  4.  
  5.   Compile as DOS EXE application.
  6.  
  7.   Description : DOS program to pause a batch/command file for
  8.         a user specified number of seconds.  If the user
  9.         presses "Q" the program will terminate with an errorlevel
  10.         value of 1.  If the timer runs out, or the user presses
  11.         the ENTER key, OSWAIT! will terminate with an errorlevel
  12.         of 0.
  13.  
  14.  
  15.   Disclaimer
  16.  
  17.   This program is provided for educational purposes only and may not be
  18.   duplicated without the writtent consent of the author, John M. Warren.
  19.  
  20.   The author claims no responsibility for the use of this product.
  21.  
  22. */
  23.  
  24.  
  25. #include <conio.h>
  26. #include <dos.h>
  27. #include <stdio.h>
  28. #include <signal.h>
  29. #include <stdlib.h>
  30.  
  31. #define  no 0
  32. #define  yes 1
  33. #define  return_key 0xD
  34. #define  default_delay 5
  35.  
  36.  
  37. /* prints a string in the current foreground color, with RETURNS number
  38.    of carriage returns following the string
  39.    cprintf() will not interprate \n formatting codes if your wondering.
  40. */
  41. void cprintf_return(char *text, unsigned char returns, unsigned char whatcolor);
  42.  
  43.  
  44. main(int numparams, char *params[]){
  45.     int elapsed_seconds;
  46.     int cursor_pos_x, cursor_pos_y;
  47.     int seconds = 0;
  48.     int stop;
  49.     int c;
  50.     int extended = 0;
  51.     if(numparams != 1) {                   /* if a command line paramater was specified */
  52.                        /* then convert the string params[1] to an */
  53.        seconds = atoi(params[1]);          /* integer value */
  54.  
  55.     }
  56.  
  57.     if(seconds == 0)  seconds = default_delay;   /* delay default number of seconds */
  58.  
  59.  
  60.     _setcursortype(_NOCURSOR);
  61.     cprintf_return("DOSWAIT! v1 (c) 1994, ITECH-CIS",1,LIGHTGREEN);
  62.     cprintf_return("Syntax :  DOSWAIT! [seconds].   Default = 5 Seconds.",2,GREEN);
  63.     cprintf_return("Press [Q] to halt program, or press [ENTER] to continue..",2,YELLOW);
  64.  
  65.  
  66.     textcolor(WHITE);
  67.     cursor_pos_x = wherex();
  68.     cursor_pos_y = wherey();   /* cursor location saved for gotoxy() moves */
  69.  
  70.  
  71.  
  72.  
  73.     elapsed_seconds = 0;
  74.     stop = no;
  75.  
  76.     do {                       /* keep going till the timer runs out or a key is pressed */
  77.  
  78.        sleep(1);
  79.         if(kbhit()){
  80.       c = getch();
  81.       if (!c)
  82.        extended = getch();
  83.       if (!extended)
  84.     switch(c){
  85.      case return_key : stop = yes; break;  /* on carriage return continue */
  86.      case 'q' :
  87.      case 'Q' :                            /* terminate with errorlevel */
  88.            printf("\n");                   /* remember the last cprinf() does not print a carriage return */
  89.            printf("**** User Break ****\n");
  90.            _setcursortype(_NORMALCURSOR);  /* turn the cursor back on */
  91.            exit(1);    }
  92.      }
  93.  
  94.        gotoxy(cursor_pos_x, cursor_pos_y);
  95.        cprintf("Seconds Remaining %i                 ",seconds - elapsed_seconds);
  96.        elapsed_seconds++;
  97.    }
  98.    while( stop == no && (elapsed_seconds != seconds+1));
  99.  
  100. printf("\n");                   /* remember the last cprinf() does not print a carriage return */
  101. _setcursortype(_NORMALCURSOR);  /* turn the cursor back on */
  102. return(0);
  103. }
  104.  
  105. /* user defined functions follow */
  106.  
  107. void cprintf_return(char *text, unsigned char returns, unsigned char whatcolor){
  108.   int counter = 0;
  109.   textcolor(whatcolor);
  110.   cprintf("%s",text);
  111.   for(counter = 0; counter < returns; counter++)  printf("\n");
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.