diff --git a/README.md b/README.md index 9394d47..0bb9057 100644 --- a/README.md +++ b/README.md @@ -75,17 +75,21 @@ The "-x" option treats values as hex. cbcbcb -### skip: discard initial octets +### drop: discard octets -Throws away some initial octets from stdin, +Throws away some octets from stdin, and sends the rest to stdout. You could use `dd` for the same purpose. - $ echo abcdefgh | dd skip=5 bs=1 status=none - fgh - $ echo abcdefgh | skip 5 - fgh + $ echo 01234567 | drop 0 3 + 34567 + $ echo 01234567 | drop 4 7 + 01237 + $ echo 01234567 | drop 4 6 + 012367 + $ echo 01234567 | drop 3 9999 + 012 ### pcat: print text representation of pcap file diff --git a/drop.c b/drop.c new file mode 100644 index 0000000..b0a156a --- /dev/null +++ b/drop.c @@ -0,0 +1,43 @@ +/* + * drop octets -- 2017 Neale Pickett + * + * This file is in the public domain. I make no promises about the functionality + * of this program. + */ + +#include +#include + +int +main(int argc, char *argv[]) +{ + unsigned long int start; + unsigned long int end; + unsigned long int pos; + + if (3 == argc) { + start = strtoul(argv[1], NULL, 0); + end = strtoul(argv[2], NULL, 0); + } else { + fprintf(stderr, "Usage: %s start end\n", argv[0]); + fprintf(stderr, "\n"); + fprintf(stderr, "Drops octets from input\n"); + return 1; + } + + for (pos = 0; ; pos += 1) { + int c = getchar(); + + if (EOF == c) { + break; + } + + if ((start <= pos) && (pos < end)) { + /* drop */ + } else { + putchar(c); + } + } + + return 0; +} diff --git a/skip.c b/skip.c deleted file mode 100644 index c466c8d..0000000 --- a/skip.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * skip octets -- 2017 Neale Pickett - * - * This file is in the public domain. I make no promises about the functionality - * of this program. - */ - -#include -#include - -int -main(int argc, char *argv[]) -{ - long int count; - - if (argc != 2) { - fprintf(stderr, "Usage: %s count\n", argv[0]); - return 1; - } - - count = strtol(argv[1], NULL, 0); - /* Throw away count octets */ - for (; count > 0; count -= 1) { - int c = getchar(); - - if (EOF == c) { - break; - } - } - - /* Spit out the rest */ - while (1) { - int c = getchar(); - - if (EOF == c) { - break; - } - putchar(c); - } - - return 0; -}