diff options
author | B. Watson <urchlay@slackware.uk> | 2024-07-20 18:03:34 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-07-20 18:03:34 -0400 |
commit | 4d71b6df11f8849095cb5a6c7b6e8678843b2a7e (patch) | |
tree | 656081567353e90e65cc815f507d3858c3ee304d /listbas.c | |
parent | 224afb63a2739d536c853ccba84091c66974f84d (diff) | |
download | bw-atari8-tools-4d71b6df11f8849095cb5a6c7b6e8678843b2a7e.tar.gz |
listbas: add -r option, tweak doc.
Diffstat (limited to 'listbas.c')
-rw-r--r-- | listbas.c | 40 |
1 files changed, 37 insertions, 3 deletions
@@ -79,6 +79,8 @@ int dump_tables = 0; /* 1 with -D */ int autodetect = 1; /* 0 with -b */ int mixed_case = 1; /* 0 with -k, or if input is B_ATARI or B_APLUS */ int indent = 1; /* 0 with -t, or if input is B_ATARI */ +int startline = 0; /* -r */ +int endline = 32767; /* -r */ /* change these with -c */ int color_cmd = C_YELLOW; @@ -151,8 +153,37 @@ int get_bas_type(char *arg) { exit(1); } +void get_line_range(const char *arg) { + int val = 0, comma = 0; + const char *p = arg; + + while(*p) { + if(*p >= '0' && *p <= '9') { + val *= 10; + val += *p - '0'; + if(val > 32768) die("Invalid line number for -r (range is 0-32768)."); + } else if(*p == ',' || *p == '-') { + if(comma) die("Invalid argument for -r (too many commas)."); + comma++; + startline = val; + val = 0; + } else { + if(comma) die("Invalid argument for -r (only digits and comma allowed)."); + } + p++; + } + + if(comma) + endline = val ? val : 32767; + else + startline = endline = val; + + if(endline < startline) + die("Invalid argument for -r (end > start)."); +} + void print_help(void) { - printf("Usage: %s [-a|-d|-m|-x|-U] [-B] [-i] [-l] [-u] [-n|-C] [-v] [-c *colors*] [-k] [-t] <inputfile>\n", self); + printf("Usage: %s [-a|-d|-m|-x|-U] [-B] [-i] [-l] [-u] [-n|-C] [-v] [-c *colors*] [-r *start,end* ] [-k] [-t] <inputfile>\n", self); printf(" -b <XX>: set BASIC type. XX is: a = atari, t = turbo, xl, xe, a+.\n"); printf(" -U: output ATASCII as Unicode/UTF-8 (this is the default).\n"); printf(" -a: output raw ATASCII.\n"); @@ -168,6 +199,7 @@ void print_help(void) { printf(" -c: use custom colors (see man page).\n"); printf(" -k: disable mixed case keywords for BXL/BXE (e.g. Print).\n"); printf(" -t: disable Turbo/BXL/BXE indentation.\n"); + printf(" -r: only list lines numbered from *start* to *end*.\n"); printf(" -v: verbose.\n"); } @@ -176,7 +208,7 @@ void parse_args(int argc, char **argv, int from_env) { optind = 1; - while( (opt = getopt(argc, argv, "Db:UCviamnBdhxulc:kt")) != -1) { + while( (opt = getopt(argc, argv, "r:Db:UCviamnBdhxulc:kt")) != -1) { switch(opt) { case 'U': output_mode = M_UTF8; break; case 'a': output_mode = M_ATASCII; color = 0; break; @@ -194,6 +226,7 @@ void parse_args(int argc, char **argv, int from_env) { case 'k': mixed_case = 0; break; case 't': indent = 0; break; case 'b': autodetect = 0; bas_type = get_bas_type(optarg); break; + case 'r': get_line_range(optarg); break; case 'c': parse_color_scheme(optarg); break; case 'h': print_help(); exit(0); default: @@ -960,7 +993,8 @@ void init_callbacks(void) { void list(void) { init_callbacks(); - walk_code(0, 32767 + immediate); + if(endline == 32767 && immediate) endline++; + walk_code(startline, endline); } void init_bas_tables() { |