-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c2
90 lines (81 loc) · 2.22 KB
/
main.c2
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
module pagegen;
import stdio as io local;
import stdlib local;
import c2vector as vctr local;
import utils local;
import string local;
import unistd local;
vector files;
public bool debug = 1;
public func int32 main()
{
vctr.init(&files);
char[1024] buffer;
while(strcmp(buffer, "/") != 0)
{
tputs(getcwd(buffer, 1024));
if(access("pagelist.txt", R_OK) == 0)
{
tputs("found");
tprintf("%s\n", loadfile("pagelist.txt"));
char* pagelist;
pagelist = loadfile("pagelist.txt");
tputs("successfully loaded pagelist");
parse(pagelist);
break;
}
chdir("../");
}
if(access("template.txt", R_OK) == 0)
{
tputs("template found");
char* template = loadfile("template.txt");
tputs("template loaded");
tprintf("amount of stuff in the vector: %d\n", cast<void*>(vctr.total(&files)));
for(int32 i = 0; i < vctr.total(&files); i++)
{
char* name = vctr.get(&files, i);
char* noext = strdup(name);
char* trunc;
if ( (trunc = strstr( noext, ".half" )) != nil )
{
*trunc = '\0';
}
tprintf("building %s\n", name);
char* content = loadfile(name);
char* complete = malloc(sizeof(template) + sizeof(content));
sprintf(complete, template, content);
char[80] fullname;
sprintf(fullname, "%s.html", noext);
FILE* fp = fopen(fullname, "w");
if (fp != nil)
{
fprintf(fp, complete);
fclose(fp);
tputs("file written");
}
}
}
return 0;
}
public func int32 parse(char* pagelist)
{
tputs("parsing");
char* buffer = strdup(pagelist);
tputs("copied pagelist");
char* token = strsep(&buffer, "\n");
tputs("started strsep");
tputs(token);
while(token != nil)
{
if(strcmp(token, "") == 0)
{
token = strsep(&buffer, '\n');
continue;
}
vctr.add(&files, token);
token = strsep(&buffer, '\n');
}
tputs("parsing complete");
return 0;
}