-
Notifications
You must be signed in to change notification settings - Fork 1
/
visutils.h
73 lines (63 loc) · 1.45 KB
/
visutils.h
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
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
using std::string;
int digits;
inline string its(int i) {
char buf[16];
sprintf(buf, "%*d", digits, i);
return buf;
}
inline string sts(string s0) {
char buf[16];
sprintf(buf, "%*s", digits, s0.c_str());
return buf;
}
string s0 = "";
inline string maymark(string s, bool marked) {
if(!marked) return s;
return "<font color='red'><b>" + s + "</b></font>";
}
#ifdef EMSCRIPTEN
void set_value(string name, string s) {
EM_ASM_({
var name = UTF8ToString($0, $1);
var value = UTF8ToString($2, $3);
document.getElementById(name).innerHTML = value;
}, name.c_str(), int(name.size()),
s.c_str(), int(s.size())
);
}
#else
void set_value(string name, string s) {
printf("output on %s:\n%s\n", name.c_str(), s.c_str());
}
#endif
#ifdef EMSCRIPTEN
void set_edit_value(string name, string s) {
EM_ASM_({
var name = UTF8ToString($0, $1);
var value = UTF8ToString($2, $3);
document.getElementById(name).value = value;
}, name.c_str(), int(name.size()),
s.c_str(), int(s.size())
);
}
#else
void set_edit_value(string name, string s) {
printf("value on %s:\n%s\n", name.c_str(), s.c_str());
}
#endif
inline void outputHTML(string s) {
#ifdef EMSCRIPTEN
set_value("result", s);
#else
ofstream of("output.html");
of << s;
printf("Output written to 'output.html'\n");
#endif
}