From 158a8368ec67046bf32ca7a4871fc922b0ff58a1 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Tue, 31 May 2022 10:41:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=93=E4=BA=86=E4=B8=80=E4=B8=AApython?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=EF=BC=8C=E7=94=A8=E6=9D=A5=E6=8A=8A=E5=A4=B4?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=92=8C=E6=BA=90=E6=96=87=E4=BB=B6=E5=90=88?= =?UTF-8?q?=E6=88=90=E4=B8=80=E4=B8=AA=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 ++++- main.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 main.py diff --git a/.gitignore b/.gitignore index eaac8ba..78f9a6b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,7 @@ build/ .idea/ # draw.io的缓存文件 -*.bkp \ No newline at end of file +*.bkp + +# 合成的全部代码文件 +all.c \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..0c9a6f5 --- /dev/null +++ b/main.py @@ -0,0 +1,66 @@ +import os + +input_file = open("all.c", "w", encoding="utf-8") +include_path: str = "./include/" +src_path: str = "./src/" + +# 写入需要用到的头文件 +input_file.write( + """#include +#include +#include +#define BUS_CLOCK_WISE 0 // 顺时针 +#define BUS_COUNTER_CLOCK_WISE 1 // 逆时针 +#define BUS_TARGET 2 // 目标 +#define BUS_STOP 2 // 停止 +#define BUS_TRUE 1 // 真 +#define BUS_FAlSE 0 // 假 +#define IO_CLOCK 0 // 读取时钟指令 +#define IO_READING 1 // 读取请求指令 +#define IO_END 2 // 读取结束指令 +#define BUS_FCFS 0 // 先来先服务 +#define BUS_SSTF 1 // 最短寻找时间优先 +#define BUS_SCAN 2 // 顺便服务 + """ +) + +# 读取include, src两个文件夹 +# include文件的顺序需要手动指定 +include_list: list = ["rail.h", "bus.h", "query.h", "bus_io.h", "controller.h", "define.h"] +src_list: list = os.listdir(src_path) + +for file_name in include_list: + file_name = include_path + file_name + with open(file_name, "r", encoding="utf-8") as include_file: + while True: + line: str = include_file.readline() + if not line: + break + elif line[0] == "#": + continue + else: + input_file.write(line) + +for file_name in src_list: + file_name = src_path + file_name + with open(file_name, "r", encoding="utf-8") as src_file: + while True: + line: str = src_file.readline() + if not line: + break + elif line[0] == "#": + continue + else: + input_file.write(line) + +with open("main.c", "r", encoding="utf-8") as main_file: + while True: + line: str = main_file.readline() + if not line: + break + elif line[0] == "#": + continue + else: + input_file.write(line) + +input_file.close()