Skip to content

Commit

Permalink
Support multi file run at same time
Browse files Browse the repository at this point in the history
  • Loading branch information
iewnfod committed Sep 18, 2023
1 parent 633f1e7 commit 69daadd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CAIE Pseudocode Interpreter

### Usage
```
cpc [file_path] [options]
cpc [file_paths] [options]
```

### Options
Expand Down
25 changes: 12 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def wrong_argument(msg):
# 主函数
def main():
# 解析参数
file_path = ''
file_paths = set()
i = 1
while i < len(argv):
arg = argv[i]
Expand All @@ -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')


# 程序入口
Expand Down
1 change: 1 addition & 0 deletions man/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pandoc man/cpc.md -s -t man -o man/cpc.1
5 changes: 4 additions & 1 deletion man/cpc.1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
5 changes: 4 additions & 1 deletion man/cpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/iewnfod/CAIE_Code>.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 69daadd

Please sign in to comment.