39 lines
642 B
C
39 lines
642 B
C
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <unistd.h>
|
||
|
|
||
|
int main(const int argc, const char **argv) {
|
||
|
if (argc == 1) {
|
||
|
printf("sleep [num[m - minute / h - hour / d - days].. ] / [inf (infinity)]\n");
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
if (!strcmp(argv[1], "inf"))
|
||
|
for (;;)
|
||
|
sleep(1);
|
||
|
|
||
|
unsigned int sec = 0;
|
||
|
for (int i = 1; i < argc; i++) {
|
||
|
switch (argv[i][strlen(argv[i]) - 1]) {
|
||
|
case 'd':
|
||
|
sec += atoi(argv[i]) * 86400;
|
||
|
break;
|
||
|
|
||
|
case 'h':
|
||
|
sec += atoi(argv[i]) * 3600;
|
||
|
break;
|
||
|
|
||
|
case 'm':
|
||
|
sec += atoi(argv[i]) * 60;
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
sec += atoi(argv[i]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sleep(sec);
|
||
|
return 0;
|
||
|
}
|