delete command
authorLaurent Mazet <mazet@softndesign.org>
Fri, 13 Jan 2023 23:03:49 +0000 (00:03 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 13 Jan 2023 23:03:49 +0000 (00:03 +0100)
hexdump.c

index b168c0f5ea4ba5148ff586ecd3c2265ded82c040..cc278231aee0940521c7caf3de26726b9c5b0b63 100644 (file)
--- a/hexdump.c
+++ b/hexdump.c
@@ -357,9 +357,10 @@ int main (int argc, char *argv[])
     char *input = NULL;
     char *output = NULL;
     char *commands = NULL;
-    int printlen = -1;
+    int length = -1;
     sequence_t seq = {0};
     unsigned long int addr = 0;
+    char c;
 
     /* get basename */
     char *pt = progname = argv[0];
@@ -454,7 +455,7 @@ int main (int argc, char *argv[])
     } else {
         VERBOSE (DEBUG, printf ("commands: %s\n", commands));
         while ((*commands != '\0') && (rc == 0)) {
-            switch (*commands++) {
+            switch (c = *commands++) {
             case ' ':
             case '\t':
                 break;
@@ -551,28 +552,35 @@ int main (int argc, char *argv[])
                 break;
 
             case 'd': /* delete mode */
-                break;
+                /* fall through */
 
             case 'p': /* print mode */
-                printlen = -1;
+                length = -1;
                 while (*commands != '\0') {
                     if ((*commands == ' ') || (*commands == '\t')) {
                         commands++;
                     } else if ((*commands >= '0') && (*commands <= '9')) {
-                        printlen = strtol (commands, &commands, 10);
+                        length = strtol (commands, &commands, 10);
                         break;
                     } else if (*commands == '-') {
-                        printlen = -1;
+                        length = -1;
                         commands++;
                         break;
                     } else {
-                        VERBOSE (ERROR, fprintf (stderr, "unknown print length (%s)\n", commands));
+                        VERBOSE (ERROR, fprintf (stderr, "unknown length (%s)\n", commands));
                         rc = 1;
                         break;
                     }
                 }
                 if (rc == 0) {
-                    hexdump (printlen);
+                    switch (c) {
+                    case 'd':
+                        fseek (fin, length, SEEK_CUR);
+                        break;
+                    case 'p':
+                        hexdump (length);
+                        break;
+                    }
                 }
                 break;
 
@@ -624,7 +632,7 @@ int main (int argc, char *argv[])
 // test: cmp hexdump.c test.c; x=$?; rm test.c; test x$x = x0
 // test: hexdump.exe -i hexdump.c -v 3 -e " /\'/" -e ' /\"/' -e ' /\\/' -e ' /\x2a/' -e ' s/\x3A/' | grep l: | wc -l | xargs test 5 =
 // test: hexdump.exe -i hexdump.c -e ' /\n\/* vim:/ p -' | grep -q ': 74 3a 20 2a 2f 0a *t: \*\/\.'
-// test: hexdump.exe -i hexdump.c -e 'p go_to_end' 2>&1 | grep -q 'unknown print length'
+// test: hexdump.exe -i hexdump.c -e 'p go_to_end' 2>&1 | grep -q 'unknown length'
 // test: hexdump.exe -i hexdump.c -e ' //' 2>&1 | grep -q 'incorrect sequence'
 // test: hexdump.exe -i hexdump.c -e 'foo' 2>&1 | grep -q 'unknown command'
 // test: hexdump.exe -i hexdump.c -e '0x20 p 8 64 p 8 0200 p 16' | grep -q '0x0080:'
@@ -632,5 +640,7 @@ int main (int argc, char *argv[])
 // test: hexdump.exe -i hexdump.c -o test.c -e ' /cflags/ a 414e5a /link/ i 2F333B'
 // test: grep -q ANZcflags test.c && grep -q 'link/3;er' test.c; x=$?; rm test.c; test x$x = x0
 // 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
 
 /* vim: set ts=4 sw=4 et: */