Repository navigation
Expand file tree
/
Copy pathmain.c
More file actions
94 lines (84 loc) · 2.76 KB
/
Copy pathmain.c
File metadata and controls
94 lines (84 loc) · 2.76 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <forge.h>
#include <strings.h>
#include <time.h>
#include <stdlib.h>
#include <refine.h>
#include <data_manager.h>
#include <stats.h>
#include <colour.h>
#include <archive.h>
void show_options(void) {
printf("Wordforge v1.0 - Created by Marcus Cornes\n");
printf("Usage: wordforge [subcommand]\n\n");
printf("forge - Write something.\n");
printf("refine - Improve one of your archived texts.\n");
printf("archive - View texts in your archive.\n");
printf("stats - View your statistics.\n");
return;
}
void show_archive_options(void) {
printf("Wordforge v1.0 - Created by Marcus Cornes\n");
printf("Archive Options:\n\n");
printf("archive list - List all memoirs in the archive.\n");
printf("archive revisions [number] - List the revisions of a text.\n");
printf("archive refine [number] - Refines a text (from the latest revision).\n");
printf("archive open [number] [version] - Opens a text at a specified revision in read-only mode.\n");
return;
}
// Routes subcommands to the appropriate files.
int main(int argc, char *argv[]) {
if (argc < 2) {
show_options();
return 1;
}
srand(time(NULL));
if (strcasecmp(argv[1], "forge") == 0) {
forge();
} else if (strcasecmp(argv[1], "refine") == 0)
{
refine();
} else if (strcasecmp(argv[1], "stats") == 0) {
stats();
} else if (strcasecmp(argv[1], "archive") == 0) {
if (argc <= 2) {
show_archive_options();
return 1;
}
if (strcasecmp(argv[2], "list") == 0) {
archive_list();
} else if (strcasecmp(argv[2], "revisions") == 0) {
if (argc <= 3) {
fprintf(stderr, "Usage: archive revisions [number]\n");
return 1;
}
int index = atoi(argv[3]) - 1;
archive_revisions(index);
} else if (strcasecmp(argv[2], "refine") == 0) {
if (argc <= 3) {
fprintf(stderr, "Usage: archive refine [number]\n");
return 1;
}
int index = atoi(argv[3]) - 1;
archive_refine(index);
} else if (strcasecmp(argv[2], "open") == 0) {
if (argc <= 4) {
fprintf(stderr, "Usage: archive open [number] [version]\n");
return 1;
}
int index = atoi(argv[3]) - 1;
int version = atoi(argv[4]) - 1;
archive_open(index, version);
} else {
fprintf(stderr, "Unknown archive command: %s\n", argv[2]);
show_archive_options();
return 1;
}
}
else {
printf(RED "ERROR: Unknown command.\n\n" RESET);
show_options();
return 1;
}
return 0;
}