#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#include <intuition/intuition.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct Screen* APP_pubscreen = NULL;
struct Window* APP_window = NULL;
LONG APP_signals;
int main(int argc, char **argv)
{
if (argc <= 1)
{
printf("To use msSimpleCron you must give two parameters:\n");
printf("- first: the command to execute ex. 'execute sys:tools/my.scrip't or 'sys:tools/calculator' etc.\n");
printf("- second: is the time of delay in miliseconds, ex. 5000 for 5 seconds etc.\n");
printf("for example: msSimpleCron 'execute my.script' 10000 <-- will run my.scipt every 10 seconds.");
return 0;
}
LONG curr_time = clock();
LONG start_time = curr_time;
LONG elapsed_time = 0;
LONG time_total = 0;
LONG delay = argv[2];
if (!(APP_pubscreen = LockPubScreen(NULL)))
return 20;
// --- create window ---
APP_window = OpenWindowTags( NULL,
WA_Left, 0,
WA_Top, 0,
WA_Width, 0,
WA_Height, 0,
WA_Flags, WFLG_ACTIVATE,
WA_PubScreen, (ULONG)APP_pubscreen,
TAG_END);
if (!APP_window)
return 20;
// enter main loop
BOOL is_loop = TRUE;
while(is_loop)
{
curr_time = clock();
time_total = (curr_time - start_time);
if (time_total - elapsed_time >= delay)
{
elapsed_time = clock();
system(argv[1]);
}
if(SetSignal(0L, APP_signals) & APP_signals)
{
struct IntuiMessage *imsg;
while( imsg=(struct IntuiMessage *)GetMsg(APP_window->UserPort) )
{
ReplyMsg((struct Message *)imsg);
}
}
}
} @mateusz_s, post #1
LONG delay = argv[2];
@snajper, post #2
@asman, post #6