blob: ed7d113a694b3046e95a20dd821d3f4d804c7ec4 (
plain)
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
|
import argparse
import os
import os.path
import re
import sys
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--output", required=True, help="The name of output header and source files excluding extension.")
parser.add_argument("input", nargs="+", help="The input source files or folders to scan.")
args = parser.parse_args()
input_dirs = []
header_file_list = []
source_file_list = []
def add_source_file(path):
print("find source file: {}".format(path))
source_file_list.append(path)
def add_header_file(path):
print("find header file: {}".format(path))
header_file_list.append(path)
cpp_header_file_regex = re.compile(r".*\.(h|hpp)")
cpp_source_file_regex = re.compile(r".*\.(cpp|cc|cxx)")
for path in args.input:
if os.path.isdir(path):
input_dirs.append(path)
elif os.path.isfile(path):
file_name = os.path.basename(path)
if cpp_source_file_regex.match(file_name):
add_source_file(path)
elif cpp_header_file_regex.match(file_name):
add_header_file(path)
else:
sys.exit("{} is a file but it is neither c++ source nor header.".format(path))
else:
sys.exit("{} is neither a file nor a directory.".format(path))
for input_dir in input_dirs:
for root, subdirs, files in os.walk(input_dir):
for f in files:
if cpp_source_file_regex.match(f):
path = os.path.join(root, f)
add_source_file(path)
elif cpp_header_file_regex.match(f):
path = os.path.join(root, f)
add_header_file(path)
print()
print("total find {} header file(s)".format(len(header_file_list)))
print("total find {} source file(s)".format(len(source_file_list)))
print()
|