Skip to content

Commit

Permalink
mpy-cross: When reading from stdin, write output to stdout.
Browse files Browse the repository at this point in the history
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 <armin.brauns@embedded-solutions.at>
  • Loading branch information
arbrauns authored and dpgeorge committed Jul 24, 2023
1 parent 6a61e4e commit 3164749
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions mpy-cross/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -121,7 +122,7 @@ STATIC int usage(char **argv) {
"usage: %s [<opts>] [-X <implopt>] [--] <input filename>\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"
Expand Down

0 comments on commit 3164749

Please sign in to comment.