-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_docs.py
208 lines (193 loc) · 4.88 KB
/
build_docs.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#!/usr/bin/python3
import os
def error(e):
print("Something went wrong building!\nError:",e)
quit()
def inttohex(n):
h="0123456789ABCDEF"
l=[]
for x in range(6):
l.insert(0,h[n%16])
n//=16
return "".join(l)
def fwalk(d):
for root, dirs, files in os.walk(d):
for file in files:
yield root.replace("\\","/")+"/"+file
def FindTextInFiles(dirlist, df):
for fname in dirlist:
if fname.endswith(".asm"):
try:
with open(fname) as fp:
dt=fp.read().split("\n")
except FileNotFoundError:
print("failed to read file",fname)
continue
for ix in range(len(dt)):
if dt[ix].startswith(df):
return dt,ix
return [],0
def build_docs():
try:
with open("src/table.asm") as f:
data=f.read().split("\n")
except Exception as e:
error(e)
try:
with open("src/include/defines.inc") as f:
defines=f.read().split("\n")
except Exception as e:
error(e)
SrcDirListing = [fname for fname in fwalk("src")]
# for fname in SrcDirListing:
# print(fname)
counter=0x020108
try:
os.makedirs("docs")
except:
pass
with open("docs/style.css","w") as f:
f.write("""
html {
background-color: #000500;
}
body {
margin: 0 auto;
width: 90%;
font-size: 100%;
line-height: 1.5;
color: white;
background-color: #142;
text-align: center;
}
h1 {
color: #ded;
}
h3 {
color: #cdc;
}
ul {
text-align: left;
}
th, tr, td {
border-left: 1px solid #eef;
border-top: 1px solid #dde;
}
th {
color: #ddd;
width: 20%;
}
td {
color: #eee;
width: 20%;
}
table {
border-right: 1px solid white;
border-bottom: 1px solid white;
position: relative;
left: 2%;
width: 96%;
}
a {
color: #aaa;
}
a:visited {
color: #aae;
}
a:hover {
color: #22e;
}
.no_op {
color: #C22;
}
.assembly {
color: #4F1;
background-color: #111;
border: 1px dotted black;
padding-left: 45%;
text-align: left;
}
.stupid_tabs {
color: #111;
font-size: 2.5;
}
""")
print("Generating syscalls.html")
with open("docs/syscalls.html","w") as f:
f.write("<html><head><title>bos.inc docs</title>\
<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"></head>\
<body>\
<h1>\"bos.inc\" documentation</h1>\
<b>\"bos.DONOTHING\" is a no-op and does nothing,</b><br>As the name implies.\
<table><th>syscall name</th><th>syscall adress</th>\
")
with open("docs/tmp.html","w") as f2:
for lx in range(len(data)):
line = data[lx]
# print(line)
if line.startswith(";$=$"):
counter = int(line[4:], 16)
elif "jp " in line or "call " in line:
if "jp " in line:
line=line[line.find("jp ")+3:]
else:
line=line[line.find("call ")+5:]
e=[]
if ";" in line:
line=line[:line.find(";")]
if "DONOTHING" in line:
f.write("<tr class=\"no_op\"></tr>")
else:
f.write("<tr>")
f2.write("<div id=\""+line+"\"><h1>"+line+"</h1>\
<h3>syscall Adress "+inttohex(counter)+"</h3>\n")
f2.write("<table><th>What it does</th><th>Inputs</th><th>Outputs</th><th>Destroys</th><th>Notes</th>\n")
a=[]; b=[]; c=[]; d=[]
dt,ix=FindTextInFiles(SrcDirListing,line+":")
if ix>0:
while not dt[ix].startswith(";@DOES"):
ix-=1
if not ix: break
while not dt[ix].startswith(line):
if len(dt[ix])>1:
t=dt[ix][1:]
if t.startswith("@DOES "):
a.append(t.replace("@DOES ","").replace("\\n","<br>\n"))
elif t.startswith("@INPUT "):
b.append(t.replace("@INPUT ","").replace("\\n","<br>\n"))
elif t.startswith("@OUTPUT "):
c.append(t.replace("@OUTPUT ","").replace("\\n","<br>\n"))
# elif t.startswith("@DESTROYS "):
# d.append(t.replace("@DESTROYS ","").replace("\\n","<br>\n"))
elif t.startswith("@NOTE "):
e.append(t.replace("@NOTE ","").replace("\\n","<br>\n"))
ix+=1
f2.write("<tr><td>"+("<br>\n".join(a))+"</td><td>"+("<br>\n".join(b))+"</td><td>"+("<br>\n".join(c))+\
"</td><td>"+("<br>\n".join(d))+"</td><td>\n"+("<br>\n".join(e))+"</td></tr>\n")
f2.write("</table></div>")
# if ix and ":" not in dt[ix]:
# f2.write("<div class=\"assembly\">\n")
# while len(dt[ix]):
# f2.write(dt[ix].replace("\t","<a class=\"stupid_tabs\">am I a tab to you?</a>",1)+"<br>\n")
# ix+=1
# if ix>=len(dt):
# break
# f2.write("</div>")
f.write("<td><a href=\"#"+line+"\">bos."+line+"</a></td><td><a href=\"#"+line+"\">"+inttohex(counter)+"</a></td></tr>\n")
counter+=4
f.write("</table>")
print("Writing to syscalls.html")
with open("docs/tmp.html") as f2:
f.write(f2.read())
os.remove("docs/tmp.html")
f.write("</body></html>")
# print("Archiving \"src\" directory")
# with zipfile.ZipFile("./docs/sources.zip",'w') as zf:
# for fname in fwalk("./src"):
# zf.write(fname)
# for fname in ["build.py","bos.inc","build_bos_inc.py","build_docs.py","LICENSE","README.md"]:
# zf.write(fname)
#
# print("Done.")
if __name__=='__main__':
build_docs()