diff options
-rw-r--r-- | renumbas.1 | 11 | ||||
-rw-r--r-- | renumbas.c | 19 | ||||
-rw-r--r-- | renumbas.rst | 9 |
3 files changed, 33 insertions, 6 deletions
@@ -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 @@ -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] <inputfile> <outputfile>\n", self); @@ -20,6 +21,7 @@ void print_help(void) { printf(" -s <num>: Starting line number (default: 10).\n"); printf(" -i <num>: Increment (default: 10).\n"); printf(" -f <num>: Don't renumber lines less than <num> (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 |