home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource1 / cenvew / runtime.cmm < prev    next >
Encoding:
Text File  |  1993-11-17  |  2.0 KB  |  59 lines

  1. /*******************************************************
  2.  *** RunTime.cmm - Execute commands at supplied time ***
  3.  *******************************************************/
  4.  
  5. #include <Message.lib>
  6.  
  7. // define TIME_CHECK_DELAY for how long to delay in between each time
  8. // checking if the RunTime has come yet.  This time is in milliseconds so
  9. // 1000 is 1 second. This time is not exact so setting to 60000 (60 seconds)
  10. // might miss an entire minute. Less then 100 would probably take up more
  11. // processor time than you want, but still not very much
  12.    #define  TIME_CHECK_DELAY  5000  // check every 5 seconds
  13.  
  14.  
  15. // Get time of day to run command
  16.    do {
  17.       GetCurrentTime(hour,minute,second);
  18.       printf("\nTime is %02d:%02d",hour,minute);
  19.       printf("\nEnter time to run command (0:00 -> 23:59) ");
  20.       TimeString = gets();
  21.    } while ( 2 != sscanf(TimeString,"%d:%d",RunHour,RunMinute)
  22.           || RunHour < 0  ||  23 < RunHour
  23.           || RunMinute < 0  ||  59 < RunMinute );
  24.  
  25. // Get Command to run
  26.    printf("\nCommand to run: ");
  27.    RunCommand = gets();
  28.  
  29. // Show message for what will happen
  30.    ScreenClear();
  31.    printf("Command: %s\n",RunCommand);
  32.    printf("Scheduled time: %02d:%02d:00\n",RunHour,RunMinute);
  33.  
  34. // Minimize this window so it's not in the way for so long
  35.    PostMessage(ScreenHandle(),WM_SYSCOMMAND,SC_MINIMIZE,0);
  36.  
  37. // Wait until the specified time
  38.    DisplayedSecond = -1; // force current time to print
  39.    do {
  40.       GetCurrentTime(CurrentHour,CurrentMinute,CurrentSecond);
  41.       if ( CurrentSecond != DisplayedSecond )
  42.          printf("\rCurrent Time:   %02d:%02d:%02d",
  43.                 CurrentHour,CurrentMinute,DisplayedSecond=CurrentSecond);
  44.       suspend(TIME_CHECK_DELAY);
  45.    } while ( CurrentHour != RunHour  ||  CurrentMinute != RunMinute );
  46.    printf("\n");
  47.  
  48. // Execute the command
  49.    spawn(P_NOWAIT,RunCommand);
  50.  
  51. GetCurrentTime(hour,minute,second)
  52. {
  53.    now = localtime(time());
  54.    hour = now.tm_hour;
  55.    minute = now.tm_min;
  56.    second = now.tm_sec;
  57. }
  58.  
  59.