home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / timeutil.lzh / WAITUNTL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-10  |  2.2 KB  |  88 lines

  1. /*  WAITUNTL.C - A program to cause the computer to wait until a specified */
  2. /*time before terminating.  Useful in .BAT files for bulletin boards and   */
  3. /*similar situations where time may be a factor in when to run programs.   */
  4.  
  5. #include <stdio.h>
  6. #include <dos.h>
  7. #define        NUL        0x0000
  8.  
  9. main(argc, argv)
  10.  
  11. int argc;
  12. char *argv[];
  13.  
  14. {
  15.     struct time dostime;
  16.     int       wait_hour, wait_minute, oldsec, target_time, keyscan, new_time;
  17.     char   wait_time[6], temp[3], semi_colon;
  18.  
  19.     temp[2] = NULL;
  20.     keyscan = 0;
  21.  
  22. /*    check for right number of arguments    */
  23.     if (argc == 1)
  24.         {
  25.             printf("\nUsage:  WAITUNTL xx:xx\n");
  26.             exit(1);
  27.         }
  28.  
  29. /*    get wait_time from command line */
  30.     strcpy( wait_time, argv[1]);
  31.  
  32. /*    convert wait_hour to int and check  */
  33.     strncpy( temp, wait_time, 2);
  34.     wait_hour = atoi( temp );
  35.     if ( (wait_hour < 0) || (wait_hour > 23) )
  36.         {
  37.             printf("\nBad hour.  Must be between 0 and 23.  Aborting...\n");
  38.             exit(1);
  39.         }
  40.  
  41. /*    check argv[1][2] for ":"  */
  42.     semi_colon = argv[1][2];
  43.     if ( semi_colon != ':' )
  44.         {
  45.             printf("\nUsage:  WAITUNTL xx:xx\n");
  46.             exit(1);
  47.         }
  48.  
  49. /*    get & test minute value     */
  50.     strncpy( temp, &argv[1][3], 3);
  51.     wait_minute = atoi( temp );
  52.     if ( (wait_minute < 0) || (wait_minute > 59) )
  53.         {
  54.             printf("\nBad minute.  Must be between 0 and 59.  Aborting...\n");
  55.             exit(1);
  56.         }
  57.  
  58.     target_time = wait_hour * 100 + wait_minute; /*    set target time */
  59.  
  60.     gettime(&dostime);
  61.     oldsec = dostime.ti_sec;
  62.  
  63.     printf("\n   Waiting until %s:00\n\n", wait_time);
  64.     printf("Starting time is %02d:%02d:%02d\n", dostime.ti_hour,
  65.                     dostime.ti_min, dostime.ti_sec);
  66.     printf(" Current time is %02d:%02d:%02d", dostime.ti_hour,
  67.                     dostime.ti_min, dostime.ti_sec);
  68.  
  69.     do
  70.         {
  71.             do
  72.                 { gettime(&dostime);
  73.                     if ( kbhit() != 0)
  74.                         {
  75.                             keyscan = getch();
  76.                             if ( keyscan == 03 ) exit(1);
  77.                         }
  78.                     new_time = (dostime.ti_hour * 100) + dostime.ti_min;
  79.                     if (oldsec != dostime.ti_sec)
  80.                         { printf("\b\b\b\b\b\b\b\b%02d:%02d:%02d",
  81.                             dostime.ti_hour, dostime.ti_min, dostime.ti_sec);
  82.                             oldsec = dostime.ti_sec;
  83.                         }
  84.                 } while (dostime.ti_sec > 0);
  85.         } while (new_time != target_time);
  86.     printf("\n");
  87. }
  88.