diff --git a/hex.c b/hex.c index ad7b46b..c7e06e1 100644 --- a/hex.c +++ b/hex.c @@ -1,35 +1,40 @@ #include #include -// TODO: ASCII/Position printing +// TODO: Position printing // TODO: Stop appending garbage at file end -// TODO: Simplify/clean some code (useless condition/loop guard brackets) +// TODO: Skip repeating lines +// TODO: Coloring printable ASCII characters in output +// TODO: Stop scanning always for cmd & loc (for q and s commands) #define BYTES 1024 #define BYTES_PER_LINE 20 -void print_hex(unsigned char* buf, int byteno) -{ +void print_hex(unsigned char* buf, int byteno, int pos) +{ for (int i=0; i\n", argv[0]); + printf("Usage: %s \nInline commands:\n\tpX - print position X\n\teX - edit position X\n\ts - save modified buffer\n\tq - quit\n", argv[0]); return -1; } FILE* f = fopen(argv[1], "r"); unsigned char buf[BYTES]; int byteno = fread(buf, 1, BYTES, f); - print_hex(buf, byteno); + print_hex(buf, byteno, 0); for (;;) { char cmd; - int loc = 0; + int loc; + scanf("%c%d", &cmd, &loc); switch(cmd) { case 'p': case 'P': - print_hex(buf + loc, BYTES_PER_LINE); + print_hex(buf + loc, BYTES_PER_LINE, loc); break; case 'e': case 'E': @@ -99,7 +102,6 @@ int main(int argc, char** argv) case 'q': case 'Q': return 0; - break; } } } diff --git a/minihex b/minihex index 3940a6a..7751565 100755 Binary files a/minihex and b/minihex differ diff --git a/test.txt b/test.txt index 09ce57f..a546446 100644 --- a/test.txt +++ b/test.txt @@ -1,3 +1,3 @@ -=ello, from a text file. +?ello, from a text file. This is a public service announcement brought to you in part by Slim Shady lol