This repository was archived by the owner on Mar 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap2html.c
More file actions
58 lines (49 loc) · 1.88 KB
/
map2html.c
File metadata and controls
58 lines (49 loc) · 1.88 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
//Save map as HTML file, and delay for delayTime miniseconds (so the html get time to render it)
/* NOTE:
* The gui.html will constantly pull new map from the map file to display it.
* Due to new CORS pilicy on local HTML file, JS can no longer read XHR content.
* To work around, the C program need to generate a HTML file as map file, then the gui.html will load this map file using iframe.
*/
#define MAP_OUTPUT_FILE "./map.html"
void saveMap(Map map, unsigned long int delayTime, char* signal) {
FILE* fp = fopen(MAP_OUTPUT_FILE,"w");
fputs("<!DOCTYPE html><html>",fp);
fputs("<style>",fp);
fputs("td{border:solid #000000 1px;width:20px;height:20px;text-align:center;vertical-align:middle;}",fp);
fputs(".map_free{background-color:#EEEEEE;}",fp);
fputs(".map_wave{background-color:#9999F0;}",fp);
fputs(".map_obstruction{background-color:#000000;}",fp);
fputs(".map_net{background-color:#99F099;}",fp);
fputs(".map_Unknown{background-color:#FF0000;}",fp);
fputs("</style>",fp);
fputs("<table>",fp);
for (mapaddr_t y = 0; y < map.height; y++) {
fputs("<tr>",fp);
for (mapaddr_t x = 0; x < map.width; x++) {
switch (getMapSlotType(map,x,y)) {
case mapslot_free:
fputs("<td class=\"map_free\"></td>",fp);
break;
case mapslot_wave:
fprintf(fp,"<td class=\"map_wave\">%llu</td>",(unsigned long long int)getMapSlotValue(map,x,y));
break;
case mapslot_obstruction:
fputs("<td class=\"map_obstruction\"></td>",fp);
break;
case mapslot_net:
fprintf(fp,"<td class=\"map_net\">%llu</td>",(unsigned long long int)getMapSlotValue(map,x,y));
break;
default:
fputs("<td class=\"map_Unknown\">X</td>",fp);
}
}
fputs("</tr>",fp);
}
fputs("</table>",fp);
fprintf(fp,"<div>%s</div>",signal);
fputs("</html>",fp);
fclose(fp);
// puts("--> Map exported.");
struct timespec t = {0, delayTime*1000000};
nanosleep(&t,NULL);
}