home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / CENVIW9.ZIP / RUNTIME.CMM < prev    next >
Text File  |  1994-03-08  |  2KB  |  60 lines

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