From 3164749b3d19a35bc3d0064da18ce0e55c4d7f20 Mon Sep 17 00:00:00 2001 From: Armin Brauns Date: Fri, 14 Jul 2023 10:31:33 +0000 Subject: [PATCH] mpy-cross: When reading from stdin, write output to stdout. Unless -o is given, output defaults to stdout unless a source file is given (in which case the source file name is used to derive an output file name). Signed-off-by: Armin Brauns --- mpy-cross/main.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mpy-cross/main.c b/mpy-cross/main.c index 20f3f85db..87e44e379 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -90,7 +90,8 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha cm.context = m_new_obj(mp_module_context_t); mp_compile_to_raw_code(&parse_tree, source_name, false, &cm); - if (output_file != NULL && strcmp(output_file, "-") == 0) { + if ((output_file != NULL && strcmp(output_file, "-") == 0) || + (output_file == NULL && strcmp(file, "-") == 0)) { mp_raw_code_save(&cm, (mp_print_t *)&mp_stdout_print); } else { vstr_t vstr; @@ -121,7 +122,7 @@ STATIC int usage(char **argv) { "usage: %s [] [-X ] [--] \n" "Options:\n" "--version : show version information\n" - "-o : output file for compiled bytecode (defaults to input with .mpy extension)\n" + "-o : output file for compiled bytecode (defaults to input filename with .mpy extension, or stdout if input is stdin)\n" "-s : source filename to embed in the compiled bytecode (defaults to input file)\n" "-v : verbose (trace various operations); can be multiple\n" "-O[N] : apply bytecode optimizations of level N\n"