aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--unprotbas.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/unprotbas.c b/unprotbas.c
index 4ed831f..bf8fc76 100644
--- a/unprotbas.c
+++ b/unprotbas.c
@@ -67,6 +67,7 @@ int protect_code = 0;
/* file handles */
FILE *input_file = NULL;
FILE *output_file = NULL;
+char *output_filename = NULL;
void die(const char *msg) {
fprintf(stderr, "%s: %s\n", self, msg);
@@ -649,7 +650,7 @@ void open_input(const char *name) {
}
void open_output(const char *name) {
- if(!name) {
+ if(!name || (strcmp(name, "-") == 0)) {
if(isatty(fileno(stdout))) {
die("refusing to write binary data to the terminal");
}
@@ -713,8 +714,8 @@ void parse_args(int argc, char **argv) {
case 0:
if(!input_file)
open_input(NULL);
- else if(!output_file)
- open_output(NULL);
+ else if(!output_filename)
+ output_filename = *argv;
else
invalid_args(*argv);
break;
@@ -724,14 +725,14 @@ void parse_args(int argc, char **argv) {
if(!input_file)
open_input(*argv);
else if(!checkonly && !output_file)
- open_output(*argv);
+ output_filename = *argv;
else
invalid_args(*argv);
}
}
if(!input_file) die("no input file given (use - for stdin)");
- if(!checkonly && !output_file) die("no output file given (use - for stdout)");
+ if(!checkonly && !output_filename) die("no output file given (use - for stdout)");
if(keepvars && forcevars) die("-f and -n are mutually exclusive");
if(readmap && writemap) die("-r and -w are mutually exclusive");
if(readmap && keepvars) die("-r and -n are mutually exclusive (maybe you want -w?)");
@@ -742,6 +743,7 @@ void parse_args(int argc, char **argv) {
}
int main(int argc, char **argv) {
+ int outbytes;
parse_args(argc, argv);
filelen = readfile();
@@ -798,9 +800,10 @@ int main(int argc, char **argv) {
}
}
- int got = fwrite(data, 1, filelen, output_file);
+ open_output(output_filename);
+ outbytes = fwrite(data, 1, filelen, output_file);
fclose(output_file);
- if(verbose) fprintf(stderr, "wrote %d bytes\n", got);
+ if(verbose) fprintf(stderr, "wrote %d bytes\n", outbytes);
if(writemap) write_var_map();