-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
56 lines (42 loc) · 1 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
#include "FileSystem.h"
#include "Hamcore.h"
int main(const int argc, const char *argv[])
{
printf("hamcore.se2 builder\n\n");
if (argc < 3)
{
printf("Usage: hamcorebuilder <dest_file> <src_dir>\n\n");
return 0;
}
const char *dst = argv[1];
const char *src = argv[2];
printf("Destination: \"%s\"\n", dst);
printf("Source: \"%s\"\n\n", src);
ENTRIES *entries = EnumEntriesRecursively(src, true);
if (!entries)
{
return 1;
}
const size_t num = entries->Num;
char **paths = malloc(sizeof(char *) * num);
for (size_t i = 0; i < num; ++i)
{
const ENTRY *entry = &entries->List[i];
const size_t path_len = strlen(entry->Path);
paths[i] = malloc(path_len + 1);
memcpy(paths[i], entry->Path, path_len + 1);
}
FreeEntries(entries);
const bool ok = HamcoreBuild(dst, src, (const char **)paths, num);
for (size_t i = 0; i < num; ++i)
{
free(paths[i]);
}
free(paths);
if (!ok)
{
return 2;
}
printf("Done!\n");
return 0;
}