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.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'renumbas.c') 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) { -- cgit v1.2.3