This repository has been archived by the owner on Aug 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathc2rst
executable file
·48 lines (44 loc) · 1.65 KB
/
c2rst
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
#!/usr/bin/env python
import codecs
import os
import sys
_state = 0
_func = []
class State(object):
RST = 0
CFUNC = 1
for file_ in sys.argv[1:]:
outfile = "%s.rst" % file_
with codecs.open(file_, encoding="UTF-8") as in_:
with codecs.open(outfile, mode="w", encoding="UTF-8") as out:
try:
line = next(in_)
while True:
if _state == State.CFUNC:
line = "\\*".join(line.split("*"))
if _state == State.RST:
if line.startswith("// .. c:function::"):
_func = []
_state = State.CFUNC
elif line.startswith("// "):
out.write(line[3:])
elif line.startswith("//"):
out.write(line[2:])
else:
out.write(" %s" % line)
line = next(in_)
else:
if line.startswith("//"):
func = " ".join(_func)
out.write(os.linesep)
out.write(os.linesep)
out.write(".. c:function:: %s" % func)
out.write(os.linesep)
_state = State.RST
else:
line2 = line.strip()
line2 = line2.strip(";")
_func.append(line2)
line = next(in_)
except StopIteration:
pass