diff --git a/src/Makefile b/src/Makefile index bf8a082..9c0ae3d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,4 +8,4 @@ main: $(OBJFILES) $(CC) hexdump.c -o hexdump test: main - ./hexdump + ./hexdump ../tests/test2.bin diff --git a/src/hexdump.c b/src/hexdump.c index 85baed1..919e14c 100644 --- a/src/hexdump.c +++ b/src/hexdump.c @@ -50,7 +50,6 @@ int hexdump(char *data) { } if (dumpgroup == 2) { dumpgroup = 0; - cur_start_of_line = 0; chardump(data, cur_start_of_line, i); hexnum = 0; cur_start_of_line = i; @@ -58,14 +57,18 @@ int hexdump(char *data) { } } -int main() { - FILE *infile = fopen("../tests/test2.bin", "r");//fopen("test.bin", "r"); +int main(int argc, char *argv[]) { + if (argc < 2) { + printf("%s: not enought arguments\n", argv[0]); + return 1; + } + FILE *infile = fopen(argv[1], "r"); char data[10000]; // FIXME char ch; int byte = 0; // FIXME if (infile == NULL) { printf("Cannot find file: \n"); - return 0; + return 1; } while ((ch = fgetc(infile)) != EOF) { diff --git a/tests/test4.bin b/tests/test4.bin new file mode 100644 index 0000000..9982bf7 --- /dev/null +++ b/tests/test4.bin @@ -0,0 +1,22 @@ +LONG file +LONG file +LONG file +LONG file +LONG file +LONG file +LONG file +LONG file +LONG file +LONG file +LONG file +123 +456 +123 +123 +123 +123 +456 +456 +456 +456 +