From a095768910dde7a8581aa018eceef5f2f899d1fa Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 24 May 2024 14:54:23 -0400 Subject: unprotbas: fix exit status. --- unprotbas.1 | 4 ++++ unprotbas.c | 14 +++++++------- unprotbas.rst | 4 ++++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/unprotbas.1 b/unprotbas.1 index 4d381b2..6c82dc0 100644 --- a/unprotbas.1 +++ b/unprotbas.1 @@ -98,12 +98,16 @@ can be used with these. .TP .B 0 \fBinput\-file\fP was protected, unprotection was successful. +With \fB\-p\fP, \fB\-pc\fP, \fB\-pv\fP: \fBinput\-file\fP was not +protected, protection was successful. .TP .B 1 I/O error, or \fBinput\-file\fP isn\(aqt a valid BASIC program. .TP .B 2 \fBinput\-file\fP is already an unprotected BASIC program. +With \fB\-p\fP, \fB\-pc\fP, \fB\-pv\fP: \fBinput\-file\fP is already a +protected BASIC program. .UNINDENT .SH DETAILS .sp diff --git a/unprotbas.c b/unprotbas.c index 686b8c3..cfdcf75 100644 --- a/unprotbas.c +++ b/unprotbas.c @@ -231,8 +231,10 @@ void breakcode(void) { break; } else { offset = data[pos + 2]; - if(!offset) - die("program already was code-protected"); + if(!offset) { + fprintf(stderr, "%s: program already was code-protected.\n", self); + exit(2); + } oldpos = pos; pos += offset; } @@ -732,6 +734,7 @@ int main(int argc, char **argv) { } if(protect_vars) scramble_vars(); if(protect_code) breakcode(); + was_protected = 1; /* opposite sense for this one */ } else { if(readmap) { was_protected = !vntable_ok(); @@ -764,10 +767,7 @@ int main(int argc, char **argv) { if(checkonly) { if(verbose) fprintf(stderr, "Check-only mode; no output written.\n"); - if(was_protected) - return 0; - else - return 2; + return was_protected ? 0 : 2; } } @@ -777,5 +777,5 @@ int main(int argc, char **argv) { if(writemap) write_var_map(); - return 0; + return was_protected ? 0 : 2; } diff --git a/unprotbas.rst b/unprotbas.rst index 138b228..13c16a6 100644 --- a/unprotbas.rst +++ b/unprotbas.rst @@ -80,12 +80,16 @@ EXIT STATUS 0 **input-file** was protected, unprotection was successful. + With **-p**, **-pc**, **-pv**: **input-file** was not + protected, protection was successful. 1 I/O error, or **input-file** isn't a valid BASIC program. 2 **input-file** is already an unprotected BASIC program. + With **-p**, **-pc**, **-pv**: **input-file** is already a + protected BASIC program. DETAILS ======= -- cgit v1.2.3