From 69daaddc9f30c0539e7f5faec8ee9dad6a86cdc9 Mon Sep 17 00:00:00 2001 From: Iewnfod Date: Mon, 18 Sep 2023 10:59:45 +0800 Subject: [PATCH] Support multi file run at same time --- README.md | 2 +- main.py | 25 ++++++++++++------------- man/build.sh | 1 + man/cpc.1 | 5 ++++- man/cpc.md | 5 ++++- src/options.py | 4 ++-- 6 files changed, 24 insertions(+), 18 deletions(-) create mode 100755 man/build.sh diff --git a/README.md b/README.md index 2c6f42a..e909a29 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ CAIE Pseudocode Interpreter ### Usage ``` -cpc [file_path] [options] +cpc [file_paths] [options] ``` ### Options diff --git a/main.py b/main.py index e9f8bce..e99d588 100644 --- a/main.py +++ b/main.py @@ -154,7 +154,7 @@ def wrong_argument(msg): # 主函数 def main(): # 解析参数 - file_path = '' + file_paths = set() i = 1 while i < len(argv): arg = argv[i] @@ -167,27 +167,26 @@ def main(): if arg[0] == '-': wrong_argument(f'Unknown option `{arg}`') else: - if file_path == '': - file_path = arg - else: - wrong_argument(f'There should only be one file path, but found `{file_path}` and `{arg}`') + file_paths.add(arg) i += 1 # 预加载文件 preload_scripts() - lexer.lineno = 1 # 选择模式运行 - if not file_path: + if not file_paths: with_line() else: - if os.path.exists(file_path): - if os.path.isfile(file_path): - with_file(file_path) + for file_path in file_paths: + lexer.lineno = 1 + # 选择模式运行 + if os.path.exists(file_path): + if os.path.isfile(file_path): + with_file(file_path) + else: + wrong_argument(f'`{file_path}` is not a file') else: - wrong_argument(f'`{file_path}` is not a file') - else: - wrong_argument(f'File `{file_path}` does not exist') + wrong_argument(f'File `{file_path}` does not exist') # 程序入口 diff --git a/man/build.sh b/man/build.sh new file mode 100755 index 0000000..f095905 --- /dev/null +++ b/man/build.sh @@ -0,0 +1 @@ +pandoc man/cpc.md -s -t man -o man/cpc.1 diff --git a/man/cpc.1 b/man/cpc.1 index 4d6c99e..af8bab5 100644 --- a/man/cpc.1 +++ b/man/cpc.1 @@ -21,7 +21,7 @@ cpc - An interpreter for CAIE Pseudocode. .SH SYNOPSIS .PP -\f[B]cpc\f[R] [\f[I]FILE_PATH\f[R]] [\f[I]OPTIONS\f[R]] +\f[B]cpc\f[R] [\f[I]FILE_PATHS\f[R]] [\f[I]OPTIONS\f[R]] .SH DESCRIPTION .PP \f[B]cpc\f[R] is a simple interpreter for CAIE Pseudocode written in @@ -69,6 +69,9 @@ git) \f[B]-v\f[R] \f[B]\[en]version\f[R] To show the version of installed \f[I]cpc\f[R] +.SS EXAMPLE +.PP +\f[I]cpc test/test.cpc test/recursive_test.cpc -r 10000 -t -gt\f[R] .SH PLAYGROUND OPTIONS .TP \f[B]clear\f[R] diff --git a/man/cpc.md b/man/cpc.md index 3d5e08e..ead0e3c 100644 --- a/man/cpc.md +++ b/man/cpc.md @@ -10,7 +10,7 @@ date: September 8, 2023 cpc - An interpreter for CAIE Pseudocode. # SYNOPSIS -**cpc** [*FILE_PATH*] [*OPTIONS*] +**cpc** [*FILE_PATHS*] [*OPTIONS*] # DESCRIPTION **cpc** is a simple interpreter for CAIE Pseudocode written in Python3. The language regulated by CAIE has a really retro grammar and even some grammar is not good for both developers and the interpreter. Thus, some unimportant grammars are changed in this interpreter. For more detailed information about this, you may look at README or . @@ -52,6 +52,9 @@ cpc - An interpreter for CAIE Pseudocode. : **--version** : To show the version of installed *cpc* +## EXAMPLE +*cpc test/test.cpc test/recursive_test.cpc -r 10000 -t -gt* + # PLAYGROUND OPTIONS **clear** : To remove all commands before in the playground diff --git a/src/options.py b/src/options.py index 47e0ab6..c816b34 100644 --- a/src/options.py +++ b/src/options.py @@ -34,10 +34,10 @@ def help(): print() - print('Usage: \033[1mcpc\033[0m [file_path] [options]') + print('Usage: \033[1mcpc\033[0m [file_paths] [options]') # 提示 - print('\033[2mThere should not be any space in a file path. \nOr, you need to add double quotation marks around the path. \033[0m') + print('\033[2mThere should not be any space in a single file path. \nOr, you need to add double quotation marks around the path. \033[0m') print()