-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathmkfile
More file actions
executable file
·38 lines (28 loc) · 843 Bytes
/
mkfile
File metadata and controls
executable file
·38 lines (28 loc) · 843 Bytes
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
#!/usr/bin/python3
import sys
import os
if len(sys.argv) != 2:
print("bad number of arguments")
sys.exit(-1)
path = sys.argv[0][:-6]
fn = sys.argv[1]
if os.path.exists(fn):
print("file already exists.")
sys.exit(-1)
pathTemplates = os.path.join(path, "templates")
name, ext = os.path.splitext(fn)
if ext == ".h":
template = os.path.join(pathTemplates, "header.h")
elif ext == ".cpp":
template = os.path.join(pathTemplates, "source.cpp")
elif ext == ".c":
template = os.path.join(pathTemplates, "source.c")
else:
print("unknown file type")
sys.exit(-1)
with open(template, "r") as fid1:
text = fid1.read()
text = text.replace("CLASSNAME_H", name.upper() + "_H")
text = text.replace("CLASSNAME", name)
with open(fn, "w") as fid2:
fid2.write(text)