-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
50 lines (45 loc) · 960 Bytes
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<stdio.h>
#include "include/filedump.h"
int main( int argc,char *argv[])
{
UtilConfig config;
char isDone=0;
int address=0;
int len=0;
int r=0;
int spaces=0;
char printFormat[15];
unsigned char stream[MAX_COLS];
//validate arguments
if(validateArg(argc,argv,&config)==0)
{
return 0;
}
sprintf(printFormat,"%%0%dx ",config.addressSize*2);
while(!isDone)
{
len = (config.fileSize-address) >MAX_COLS?MAX_COLS:(config.fileSize-address);
fread(stream,len,1,config.fPtr);
//display address
printf(printFormat,address);
//printf("%02x\t",address);
printStream(stream,len,config.format," ");
if(config.format==HEXASCII)
{
spaces=len<MAX_COLS?(MAX_COLS-len)*3+3:3;
printf("%*c",spaces,' ');
printf("| ");
printStream(stream,len,ASCII," ");
if(len==MAX_COLS)
printf("%*c|",spaces,' ');
}
printf("\n");
address +=len;
r++;
if(address>=config.fileSize)
{
isDone=1;
}
}
return 0;
}