-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathathena.c
61 lines (46 loc) · 1.7 KB
/
athena.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
61
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int AthenaPortals()
{
DIR *d;
struct dirent *r;
FILE *f, *o;
char line[128], *from, *from_x, *from_y, *to, *to_x, *to_y;
int i;
printf("*** Parsing Athena Portal Scripts ***\n\n");
d = opendir(".");
if (!d) {
printf("Error: could not open directory");
return 1;
}
o = fopen("../portals-new.txt", "w");
while ((r = readdir(d))) {
if (!strcmp(r->d_name, ".") || !strcmp(r->d_name, "..")) continue;
printf("%s...", r->d_name);
f = fopen(r->d_name, "r");
if (f != NULL) {
printf("OK. Parsing...");
while (fgets(line, sizeof line, f) != NULL) {
if (strstr(line,"//") != NULL || strlen(line) < 5) continue; // Skip blank lines/comments
from = strtok(line, "\t,"); // Source map
from_x = strtok(NULL, "\t,"); // Source X coordinate
from_y = strtok(NULL, "\t,"); // Source Y coordinate
for (i=0;i<=4;i++) strtok(NULL, "\t,"); // Skip unneeded data
to = strtok(NULL, "\t,"); // Destination map
to_x = strtok(NULL, "\t,"); // Destination X coordinate
to_y = strtok(NULL, "\t,"); // Destination Y coordinate
fprintf(o, "%s %s %s %s %s %s", from, from_x, from_y, to, to_x, to_y);
}
printf("done.\n");
} else {
printf("ERROR\n");
continue;
}
fclose(f);
}
fclose(o);
closedir(d);
return 0;
}