From a4d7098b3ccfe3994906608071be16ee164ffa55 Mon Sep 17 00:00:00 2001 From: CismonX Date: Sun, 17 May 2020 00:39:29 +0800 Subject: [PATCH] change suffix of default output file name when dumping mnemonics --- man/u6ac.1 | 2 +- src/u6ac.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/man/u6ac.1 b/man/u6ac.1 index 54c2762..8d811ed 100644 --- a/man/u6ac.1 +++ b/man/u6ac.1 @@ -12,7 +12,7 @@ Read and compile Unlambda code from the given \fIsource\-file\fR, or \fBSTDIN\fR .SH OPTIONS .TP \fB\-o\fR, \fB\-\-output\fR=\fIout\-file\fR -Save compiled bytecode to \fIout\-file\fR, defaults to \fIsource\-file\fR name with ".bc" suffix, or \fBSTDOUT\fR if the source file is read from \fBSTDIN\fR. +Save compiled bytecode to \fIout\-file\fR, defaults to \fIsource\-file\fR name with ".bc" (".bc.dump" if \fB\-S\fR option is enabled) suffix, or \fBSTDOUT\fR if the source file is read from \fBSTDIN\fR. .TP \fB\-\-add\-prefix\fR[=\fIprefix\-string\fR] Add \fIprefix\-string\fR to the beginning of \fIout\-file\fR. Defaults to "#!/usr/bin/env u6a\\n". diff --git a/src/u6ac.c b/src/u6ac.c index c58c354..1fb1575 100644 --- a/src/u6ac.c +++ b/src/u6ac.c @@ -153,13 +153,13 @@ process_options(struct arg_options* options, int argc, char** argv) { if (options->input_file == stdin) { goto write_to_stdout; } else { - if (UNLIKELY(file_name_size + 3 > PATH_MAX - 1)) { - u6a_err_path_too_long(err_toplevel, PATH_MAX - 1, file_name_size + 3); + if (UNLIKELY(file_name_size + 8 > PATH_MAX - 1)) { + u6a_err_path_too_long(err_toplevel, PATH_MAX - 1, file_name_size + 8); return false; } - options->output_file_name = malloc((file_name_size + 4) * sizeof(char)); + options->output_file_name = malloc((file_name_size + 9) * sizeof(char)); strcpy(options->output_file_name, options->input_file_name); - strcpy(options->output_file_name + file_name_size, ".bc\0"); + strcpy(options->output_file_name + file_name_size, options->dump_mnemonics ? ".bc.dump\0" : ".bc\0"); } } else if (strlen(options->output_file_name) == 1 && options->output_file_name[0] == '-') { write_to_stdout: