From 1185226bef2131f4216676d298e7c4e724e8a9bd Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 22 Jun 2024 15:02:49 -0400 Subject: renumbas: add *useless* -b option (just for shiggles). --- renumbas.1 | 11 +++++++++-- renumbas.c | 19 ++++++++++++++++--- renumbas.rst | 9 ++++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/renumbas.1 b/renumbas.1 index 3252fab..495b204 100644 --- a/renumbas.1 +++ b/renumbas.1 @@ -27,12 +27,12 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. -.TH "RENUMBAS" 1 "2024-06-18" "0.2.1" "Urchlay's Atari 8-bit Tools" +.TH "RENUMBAS" 1 "2024-06-22" "0.2.1" "Urchlay's Atari 8-bit Tools" .SH NAME renumbas \- Renumber Atari 8-bit BASIC programs .SH SYNOPSIS .sp -renumbas [\fB\-v\fP] [\fB\-s\fP \fIstart\-lineno\fP] [\fB\-i\fP \fIincrement\fP] [\fB\-f\fP \fIfirst\-lineno\fP] \fIinput\-file\fP \fIoutput\-file\fP +renumbas [\fB\-v\fP] [\fB\-s\fP \fIstart\-lineno\fP] [\fB\-i\fP \fIincrement\fP] [\fB\-f\fP \fIfirst\-lineno\fP] [\fB\-b\fP] \fIinput\-file\fP \fIoutput\-file\fP .SH DESCRIPTION .sp \fBrenumbas\fP reads a tokenized Atari 8\-bit BASIC program and writes a @@ -86,6 +86,13 @@ Line number increment between successive lines. Default: 10. .B \fB\-f\fP \fIfirst\-lineno\fP Line number in original program where renumbering will start. Lines numbered lower that this will not be renumbered. Default: 0. +.TP +.B \fB\-b\fP +Renumber program backwards (line numbers in descending +order). This option is completely useless, but exists for testing +purposes. Programs renumbered this way won\(aqt \fIRUN\fP correctly, +although they will \fILOAD\fP and \fILIST\fP\&. When using this option, set +\fB\-s\fP to a higher number than the default. .UNINDENT .SS General Options .INDENT 0.0 diff --git a/renumbas.c b/renumbas.c index 62a4f07..6f4f51e 100644 --- a/renumbas.c +++ b/renumbas.c @@ -13,6 +13,7 @@ unsigned short startlineno = 10; unsigned short increment = 10; unsigned short limit = 0; unsigned short newno; +int backwards = 0; void print_help(void) { printf("Usage: %s [-v] [-s start-lineno] [-i increment] [-f first-lineno] \n", self); @@ -20,6 +21,7 @@ void print_help(void) { printf(" -s : Starting line number (default: 10).\n"); printf(" -i : Increment (default: 10).\n"); printf(" -f : Don't renumber lines less than (default: 0).\n"); + printf(" -b: Number backwards (creates invalid program).\n"); } unsigned short getlineno(char opt, const char *arg) { @@ -46,9 +48,10 @@ unsigned short getlineno(char opt, const char *arg) { void parse_args(int argc, char **argv) { int opt; - while( (opt = getopt(argc, argv, "vs:i:f:")) != -1) { + while( (opt = getopt(argc, argv, "vbs:i:f:")) != -1) { switch(opt) { - case 'v': verbose = 1; break; + case 'v': verbose = 1; break; + case 'b': backwards = 1; break; case 's': startlineno = getlineno(opt, optarg); break; case 'i': increment = getlineno(opt, optarg); break; case 'f': limit = getlineno(opt, optarg); break; @@ -86,7 +89,17 @@ CALLBACK(renumber_line) { for(i = 0; i < refcounts[lineno]; i++) memmove(program + linerefs[lineno][i].pos, fpnewno, 6); setword(pos, newno); - newno += increment; + + if(backwards) { + if(newno < increment) { + fprintf(stderr, "%s: Fatal: New line number %d would be <0.\n", self, newno); + exit(1); + } else { + newno -= increment; + } + } else { + newno += increment; + } } void check_refs(void) { diff --git a/renumbas.rst b/renumbas.rst index f71bf01..a442ccb 100644 --- a/renumbas.rst +++ b/renumbas.rst @@ -10,7 +10,7 @@ Renumber Atari 8-bit BASIC programs SYNOPSIS ======== -renumbas [**-v**] [**-s** *start-lineno*] [**-i** *increment*] [**-f** *first-lineno*] *input-file* *output-file* +renumbas [**-v**] [**-s** *start-lineno*] [**-i** *increment*] [**-f** *first-lineno*] [**-b**] *input-file* *output-file* DESCRIPTION =========== @@ -68,6 +68,13 @@ Renumber Options Line number in original program where renumbering will start. Lines numbered lower that this will not be renumbered. Default: 0. +**-b** + Renumber program backwards (line numbers in descending + order). This option is completely useless, but exists for testing + purposes. Programs renumbered this way won't *RUN* correctly, + although they will *LOAD* and *LIST*. When using this option, set + **-s** to a higher number than the default. + .. include:: genopts.rst DIAGNOSTICS -- cgit v1.2.3