aboutsummaryrefslogtreecommitdiff
path: root/unprotbas.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-05-29 14:18:15 -0400
committerB. Watson <urchlay@slackware.uk>2024-05-29 14:20:36 -0400
commitc84cedb3337c2cdabb5f3ff91aa44810d9661091 (patch)
treeb36d5d2e7aeac3b06b4014b880bcaa5370c0f14f /unprotbas.c
parent377fd0927ce1daf97dcefea0b17ec5cbaf2f02b2 (diff)
downloadbw-atari8-tools-c84cedb3337c2cdabb5f3ff91aa44810d9661091.tar.gz
unprotbas: don't allow -x without -p or -pv, group options in doc.
Diffstat (limited to 'unprotbas.c')
-rw-r--r--unprotbas.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/unprotbas.c b/unprotbas.c
index 37013cf..b2b3d98 100644
--- a/unprotbas.c
+++ b/unprotbas.c
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <time.h>
/* attempt to fix a "list-protected" Atari 8-bit BASIC program.
we don't fully detokenize, so this won't fix truly corrupted
@@ -54,6 +55,9 @@ unsigned char badcode[] = {
0x16, /* end-of-line token */
};
+/* for -p/-pv */
+int varname_char = 0x9b;
+
/* for the -r option */
#define MAP_FILE "varnames.txt"
unsigned char varnames[BUFSIZE];
@@ -630,8 +634,13 @@ void scramble_vars(void) {
exit(2);
}
+ if(varname_char == -1) srand(time(NULL));
+
for(i = vnstart; i < vvstart - 1; i++)
- data[i] = '\x9b';
+ if(varname_char == -1)
+ data[i] = (rand() >> 8) & 0xff;
+ else
+ data[i] = varname_char & 0xff;
if(verbose) {
i -= vnstart;
@@ -652,6 +661,8 @@ void print_help(void) {
fprintf(stderr, "-w: write variable names to varnames.txt\n");
fprintf(stderr, "-r: read variable names from varnames.txt\n");
fprintf(stderr, "-pc/-pv/-p: protect code/variables/both\n");
+ fprintf(stderr, "-xXX: hex code XX for variable names, with -p/-pc\n");
+ fprintf(stderr, "-xr: random variable names, with -p/-pc\n");
fprintf(stderr, "Use - as a filename to read from stdin and/or write to stdout\n");
}
@@ -706,6 +717,7 @@ void open_output(const char *name) {
void parse_args(int argc, char **argv) {
char *p;
+ int xopt_used = 0;
self = *argv;
p = strrchr(self, '/');
@@ -749,6 +761,23 @@ void parse_args(int argc, char **argv) {
}
}
break;
+ case 'x': {
+ xopt_used++;
+ switch((*argv)[2]) {
+ case 'r':
+ varname_char = -1; break;
+ case 0:
+ die("-x option requires a hex number or 'r' (e.g. -x20, not -x 20)"); break;
+ default:
+ {
+ char *e;
+ varname_char = (int)strtol(&(*argv)[2], &e, 16);
+ if(*e != 0 || varname_char > 0xff)
+ die("invalid hex character for -x option (range is 0 to ff)");
+ }
+ }
+ }
+ break;
case 0:
if(!input_file)
open_input(NULL);
@@ -776,8 +805,10 @@ void parse_args(int argc, char **argv) {
if(readmap && keepvars) die("-r and -n are mutually exclusive (maybe you want -w?)");
if(protect_code || protect_vars) {
if(checkonly || keepvars || forcevars || readmap || writemap || !keepgarbage)
- die("-p, -pc, -pv options can't be combined with other options except -v");
+ die("-p, -pc, -pv options can't be combined with other options except -x, -v");
}
+ if(xopt_used && !protect_vars)
+ die("-x option requires -p or -pv");
}
int main(int argc, char **argv) {