diff options
author | crupest <crupest@outlook.com> | 2018-11-11 22:56:41 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2018-11-11 22:56:41 +0800 |
commit | 651106c12769751a87b1175c2c27dd664e31acb3 (patch) | |
tree | 1b1a0e0bdca0c6c1106d49313be15b2418e02a97 | |
parent | 92bec65a76b62bbbee56b44c3020171606bb8bbb (diff) | |
download | cru-651106c12769751a87b1175c2c27dd664e31acb3.tar.gz cru-651106c12769751a87b1175c2c27dd664e31acb3.tar.bz2 cru-651106c12769751a87b1175c2c27dd664e31acb3.zip |
Develop scan files.
-rw-r--r-- | tools/cppmerge/main.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tools/cppmerge/main.py b/tools/cppmerge/main.py new file mode 100644 index 00000000..ed7d113a --- /dev/null +++ b/tools/cppmerge/main.py @@ -0,0 +1,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() + |