mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-07-30 23:30:11 -07:00
feat: use m4 when parsing pcv files
This commit is contained in:
@@ -108,6 +108,14 @@ def run_proverif(file, log_file, extra_args=[]):
|
||||
exit(return_code)
|
||||
|
||||
|
||||
def m4(input_file, output_file):
|
||||
logger.debug(f"m4: {input_file}, {output_file}")
|
||||
input_file_path = pkgs.pathlib.Path(input_file)
|
||||
|
||||
params = ["m4", "-D", "ProVerif", pkgs.os.path.basename(input_file)]
|
||||
return exc(params, stderr=pkgs.sys.stderr, cwd=input_file_path.parent, stdout=output_file)
|
||||
|
||||
|
||||
def cpp(file, cpp_prep):
|
||||
logger.debug(f"_cpp: {file}, {cpp_prep}")
|
||||
file_path = pkgs.pathlib.Path(file)
|
||||
@@ -302,11 +310,28 @@ def metaverif(repo_path, tmpdir, file):
|
||||
@main.command()
|
||||
@click.argument("file_path")
|
||||
def parse(file_path):
|
||||
try:
|
||||
parse_main(file_path)
|
||||
except pkgs.lark.exceptions.UnexpectedCharacters as e:
|
||||
logger.error(f"Error {type(e).__name__} parsing {file_path}: {e}")
|
||||
if not pkgs.os.path.isfile(file_path):
|
||||
logger.error(f"{file_path} is not a file or does not exist.")
|
||||
exit(1)
|
||||
|
||||
if file_path.lower().endswith(".pv"):
|
||||
logger.info(f"Parsing ProVerif .pv file {file_path}")
|
||||
try:
|
||||
parse_main(file_path)
|
||||
except pkgs.lark.exceptions.UnexpectedCharacters as e:
|
||||
logger.error(f"Error {type(e).__name__} parsing {file_path}: {e}")
|
||||
|
||||
elif file_path.lower().endswith(".pcv"):
|
||||
with pkgs.tempfile.NamedTemporaryFile(suffix=".pv", delete_on_close=False) as f:
|
||||
m4(file_path, f)
|
||||
try:
|
||||
parse_main(f.name)
|
||||
except pkgs.lark.exceptions.UnexpectedCharacters as e:
|
||||
logger.error(f"Error {type(e).__name__} parsing {file_path}: {e}")
|
||||
|
||||
else:
|
||||
logger.error(f"Unsupported file extension for file {file_path}")
|
||||
exit(2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user