File: make_help.py

package info (click to toggle)
horizon-eda 2.6.0-2.3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 33,416 kB
  • sloc: cpp: 270,162; ansic: 3,817; python: 2,098; xml: 402; sql: 219; sh: 190; ruby: 61; makefile: 19
file content (34 lines) | stat: -rw-r--r-- 891 bytes parent folder | download | duplicates (2)
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
import sys
infile = sys.argv[1]
h_file = sys.argv[2]
c_file = sys.argv[3]

texts = {}
text_current = None
for line in open(infile, "r", encoding="UTF-8") :
	line = line.strip()
	if line.startswith("#") :
		text_current = line[1:]
		texts[text_current] = ""
	elif text_current is not None :
		texts[text_current] += line+"\n"

texts = {k:v.strip() for k,v in texts.items()}

with open(h_file, "w") as fi:
	print("#pragma once", file=fi)
	print("namespace horizon {", file=fi)
	print("class HelpTexts {", file=fi)
	print("public:", file=fi)
	for k in texts.keys() :
		print("    static const char* %s;"%k, file=fi)
	print("};", file=fi)
	print("}", file=fi)

with open(c_file, "w") as fi:
	print('#include "help_texts.hpp"', file=fi)
	print("namespace horizon {", file=fi)
	
	for k,v in texts.items() :
		print('const char* HelpTexts::%s = R"EOF(%s)EOF";'%(k,v), file=fi)
	print("}", file=fi)