]> git.armaanb.net Git - bin.git/blob - crontab-argh.c
git-mirror: update for loop style
[bin.git] / crontab-argh.c
1 // stops you from accidentally running crontab -r
2 // alias this to crontab
3
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7
8 int main(int argc, char *argv[]) {
9         char arg[255] = "crontab ";
10
11         for (int i = 1; i < argc; i++) {
12                 strcat(arg, strcat(argv[i], " "));
13         }
14
15         if (strstr(arg, "-r") != NULL) {
16                 printf("%s", "Delete user's crontab? [yes/no]: ");
17                 char inp[255];
18                 int ret;
19                 while (1) {
20                         ret = scanf("%s", inp);
21                         if (ret == EOF) continue;
22                         else if (strcmp(inp, "no") == 0) exit(0);
23                         else if (strcmp(inp, "yes") == 0) break;
24                         else printf("%s", "Please answer yes or no. [yes/no]: ");
25                 }
26         }
27         system(arg);
28 }