diff options
Diffstat (limited to 'renumbas.c')
-rw-r--r-- | renumbas.c | 29 |
1 files changed, 21 insertions, 8 deletions
@@ -13,13 +13,15 @@ unsigned short startlineno = 10; unsigned short increment = 10; unsigned short limit = 0; unsigned short newno; +int backwards = 0; void print_help(void) { - fprintf(stderr, "Usage: %s [-v] [-s start-lineno] [-i increment] [-f first-lineno] <inputfile> <outputfile>\n", self); - fprintf(stderr, " -v: Verbose.\n"); - fprintf(stderr, " -s <num>: Starting line number (default: 10).\n"); - fprintf(stderr, " -i <num>: Increment (default: 10).\n"); - fprintf(stderr, " -f <num>: Don't renumber lines less than <num> (default: 0).\n"); + printf("Usage: %s [-v] [-s start-lineno] [-i increment] [-f first-lineno] <inputfile> <outputfile>\n", self); + printf(" -v: Verbose.\n"); + 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) { |