hexdump: add cli arguments

This commit is contained in:
g1n 2021-08-24 13:38:58 +03:00
parent 1359b66b21
commit 104fdea113
3 changed files with 30 additions and 5 deletions

View File

@ -8,4 +8,4 @@ main: $(OBJFILES)
$(CC) hexdump.c -o hexdump
test: main
./hexdump
./hexdump ../tests/test2.bin

View File

@ -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)
{

22
tests/test4.bin Normal file
View File

@ -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