-
Notifications
You must be signed in to change notification settings - Fork 0
/
replay.c
39 lines (37 loc) · 1003 Bytes
/
replay.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "headers.h"
void replay(char *command)
{
char buf[MAX_SIZE];
strcpy(buf,command);
char *saveptr;
char *arg = strtok_r(buf," ",&saveptr);
arg = strtok_r(NULL," ",&saveptr);
char commandexec[MAX_SIZE];
commandexec[0] = '\0';
if(strcmp(arg,"-command") == 0)
{
arg = strtok_r(NULL," ",&saveptr);
while(strcmp(arg,"-interval") != 0)
{
strcat(commandexec,arg);
strcat(commandexec," ");
arg = strtok_r(NULL," ",&saveptr);
}
arg = strtok_r(NULL," ",&saveptr);
int interval = atoi(arg);
arg = strtok_r(NULL," ",&saveptr);
arg = strtok_r(NULL," ",&saveptr);
int period = atoi(arg);
int t= interval;
while(t <= period)
{
sleep(interval);
processcommands(commandexec);
t += interval;
}
t -= interval;
if(period - t > 0)
sleep(period-t);
}
return;
}