-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmantags
executable file
·109 lines (92 loc) · 3.13 KB
/
mantags
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
#!/usr/bin/env python3
import sys
import os
configFooPath = ".mantags"
def countIdent(s):
ident = 0
for c in s:
if c == " ":
ident += 1
else:
return ident
return ident
def genManFile(f):
try:
os.mkdir(configFooPath)
except FileExistsError:
pass
os.system("man " + f + " > " + configFooPath + "/" + f)
def write(d, file):
f = open("tags", "w")
f.write("!_TAG_FILE_FORMAT\t2\t/extended format; --format=1 will not append ;\" to lines/\n")
f.write("!_TAG_FILE_SORTED\t0\t/0=unsorted, 1=sorted, 2=foldcase/\n")
f.write("!_TAG_OUTPUT_MODE\tu-ctags /u-ctags or e-ctags/\n")
f.write("!_TAG_PROGRAM_AUTHOR\tConfig foo Team\t//\n")
f.write("!_TAG_PROGRAM_NAME\tmantags\n")
for x in d:
f.write(x[2] + "\t" + file + "\t/" + x[3] + "/\n") # "\ts\ttitle:" + file + "\n")
def main():
if len(sys.argv) != 2:
print("not enough arguments")
sys.exit(1)
manFile = sys.argv[1]
genManFile(manFile)
previos = ""
previosText = ""
optionSection = False
list = []
# list.append((0, "p", ""))
listCounter = 0
counter = 0
default_indent = 0
last_key_word = 0
with open(configFooPath + "/" + manFile) as f:
for line in f:
counter += 1
if default_indent == 0:
if countIdent(line) == 0 and line.startswith("NAME"):
last_key_word = 1
if last_key_word == 1:
default_indent = countIdent(line)
continue
if line in ('\n', '\r\n'):
continue
if countIdent(line) == 0:
print("section")
optionSection = False
continue
indent = (countIdent(line) / default_indent)
if indent < 1:
print("half indent")
continue
if indent == 1:
previosText = line.strip()
# if optionSection == True:
# if list[-1][2].startswith(line.strip()):
# print("double")
# list.append((counter, "o", line.strip()))
continue
if indent > 1:
if previosText == "":
continue
# if list[-1][2].startswith(line.strip()):
# print("double")
if '=,' in previosText:
options = previosText.split(",")
if len(options) > 3:
print("larger than 3??")
continue
for x in options:
list.append((counter - 1, "o", x.strip().strip("="), ""))
previosText = ""
continue
insert_text = previosText.strip().split(" ")[0]
comment_text = previosText.strip()
list.append((counter - 1, "o", insert_text.strip("="), comment_text))
optionSection = True
previosText = ""
write(list, configFooPath + "/" + manFile)
if __name__ == "__main__":
main()
# lastKeyWord
# 1 = NAME