/* linker: debug.o */
#include <assert.h>
+#include <limits.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
char buffer[BUFFERSIZE] = {0};
FILE *fin = NULL;
-unsigned long int addrfile = 0;
+long int addrfile = 0;
FILE *fout = NULL;
char *progname = NULL;
fprintf (fd, " -o: output file\n");
fprintf (fd, " -v: verbose level (%d)\n", verbose);
fprintf (fd, "\n");
- fprintf (fd, "commands: [/hstr/|addr] [a hstr] [d nb|-] [i hstr] [p nb|-] [s/h1/h2/[g]]\n");
+ fprintf (fd, "commands: [/hstr/|addr|+nb] [a hstr] [d nb|-] [i hstr] [p nb|-] [s/h1/h2/[g]]\n");
fprintf (fd, " addr: move to address (0... octal, [1-9]... deci, 0x... hexa)\n");
+ fprintf (fd, " +nb: move to offset (0... octal, [1-9]... deci, 0x... hexa)\n");
fprintf (fd, " //: move to hexa stringi hstr\n");
fprintf (fd, " a : append hexa string hstr to current address\n");
fprintf (fd, " d : delete nb bytes (- until end file)\n");
/* go to address function */
-int gotoaddr (unsigned long int addr) {
+int gotoaddr (long int addr) {
char buffer[BUFFERSIZE] = {0};
- if (addrfile > addr) {
+ if (addr == -1) {
+ addr = LONG_MAX;
+ } else if (addrfile > addr) {
return 1;
}
char *input = NULL;
char *output = NULL;
char *commands = NULL;
- int length = -1;
+ long int length = -1;
sequence_t seq = {0};
- unsigned long int addr = 0;
+ long int addr = 0;
char c;
/* get basename */
VERBOSE (ERROR, fprintf (stderr, "erroneous address\n"));
rc = 1;
}
+ offset = 0;
break;
case '1':
commands--;
addr = strtol (commands, &commands, 10);
rc = gotoaddr (addr);
+ offset = 0;
break;
case 'a': /* append mode */
VERBOSE (ERROR, fprintf (stderr, "erroneous sequence '%s'\n", seq.sequence));
rc = 1;
}
+ offset = 0;
break;
+ case '+': /* relative move */
+ /* fall through */
+
case 'd': /* delete mode */
/* fall through */
}
if (rc == 0) {
switch (c) {
+ case '+':
+ rc = gotoaddr ((length > 0) ? addrfile + length : -1);
+ break;
+
case 'd':
fseek (fin, length, SEEK_CUR);
break;
+
case 'p':
hexdump (length);
break;
}
}
+ offset = 0;
break;
case 's': /* substitute mode */
+ offset = 0;
break;
default:
// test: hexdump.exe -i hexdump.c -e ' /cflags/ a 414e5' 2>&1 | grep 'erroneous sequence'
// test: hexdump.exe -i hexdump.c -o test.c -e ' /lags/ d 2'
// test: grep -q cfgs test.c; x=$?; rm test.c; test x$x = x0
+// test: hexdump.exe -i hexdump.c -o test.c -e ' /lags/ +2 i 2041'
+// test: grep -q 'cf Ags' test.c; x=$?; rm test.c; test x$x = x0
/* vim: set ts=4 sw=4 et: */