-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
60 lines (54 loc) · 1.68 KB
/
main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "hazmat.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
hhelp();
return 0;
}
if (strcmp(argv[1], "help") == 0) {
hhelp();
} else if (strcmp(argv[1], "init") == 0) {
hinit();
}
else if (strcmp(argv[1], "gen") == 0) {
if (argc != 3) {
fprintf(stderr, "Error: 'gen' command requires length argument\n");
fprintf(stderr, "Usage: %s gen <length>\n", argv[0]);
return 1;
}
// Convert string argument to integer
int len = atoi(argv[2]);
if (len < 8 || len > 64) {
fprintf(stderr, "Error: length must be between 8 and 64\n");
return 1;
}
if (len <= 0) {
fprintf(stderr, "Error: length must be a positive number\n");
return 1;
}
char* random_string = genrand(len);
if (random_string == NULL) {
fprintf(stderr, "Error: Failed to generate random number string\n");
return 1;
}
printf("%s\n", random_string);
free(random_string); // im not leaking bud
}
else if (strcmp(argv[1], "shred") == 0) {
hshred();
} else if (strcmp(argv[1], "add") == 0 && argc == 3) {
// Implement add functionality with argv[2] as the file
} else if (strcmp(argv[1], "delete") == 0 && argc == 3) {
// Implement delete functionality with argv[2] as the file
} else if (strcmp(argv[1], "show") == 0 && argc == 3) {
// Implement show functionality with argv[2] as the file
} else if (strcmp(argv[1], "import") == 0 && argc == 3) {
// Implement import functionality with argv[2] as the file
} else if (strcmp(argv[1], "export") == 0 && argc == 3) {
// Implement export functionality with argv[2] as the file
} else {
fprintf(stderr, "Error: Unrecognized or incomplete command.\n");
hhelp();
return 1;
}
return 0;
}