Line 58... |
Line 58... |
{
|
{
|
|
|
FILE *fd;
|
FILE *fd;
|
int c;
|
int c;
|
int i = 0;
|
int i = 0;
|
|
int line = 0;
|
int filename_index=1;
|
int filename_index=1;
|
int bytes_per_line=1;
|
int bytes_per_line=1;
|
int bytes_per_line_index=2;
|
int bytes_per_line_index=2;
|
|
int min_num_bytes_index=3;
|
|
int min_num_bytes = 0;
|
|
|
|
|
if(argc < 3) {
|
if(argc < 3) {
|
fprintf(stderr,"\n\tInsufficient options.\n");
|
fprintf(stderr,"\n\tInsufficient options.\n");
|
fprintf(stderr,"\tPlease specify, in this order: a binary file to\n");
|
fprintf(stderr,"\tPlease specify, in this order: a binary file to\n");
|
Line 73... |
Line 76... |
exit(1);
|
exit(1);
|
}
|
}
|
|
|
fd = fopen( argv[filename_index], "r" );
|
fd = fopen( argv[filename_index], "r" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bytes_per_line = atoi(argv[bytes_per_line_index]);
|
bytes_per_line = atoi(argv[bytes_per_line_index]);
|
|
|
|
|
|
|
|
|
|
if(argc > 3) {
|
|
min_num_bytes = atoi(argv[min_num_bytes_index]);
|
|
}
|
|
|
|
|
|
|
|
|
if ((bytes_per_line == 0) || (bytes_per_line > 8))
|
if ((bytes_per_line == 0) || (bytes_per_line > 8))
|
{
|
{
|
fprintf(stderr,"bytes per line incorrect or missing: %s\n",argv[bytes_per_line_index]);
|
fprintf(stderr,"bytes per line incorrect or missing: %s\n",argv[bytes_per_line_index]);
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fd == NULL) {
|
if (fd == NULL) {
|
fprintf(stderr,"failed to open input file: %s\n",argv[1]);
|
fprintf(stderr,"failed to open input file: %s\n",argv[1]);
|
exit(1);
|
exit(1);
|
}
|
}
|
|
|
i=0;
|
i=0;
|
|
line=0;
|
|
|
// Now write out the binary data to hex format
|
// Now write out the binary data to hex format
|
while ((c = fgetc(fd)) != EOF) {
|
while ((c = fgetc(fd)) != EOF) {
|
printf("%.2x", (unsigned int) c);
|
printf("%.2x", (unsigned int) c);
|
if (++i == bytes_per_line) {
|
if (++i == bytes_per_line) {
|
printf("\n");
|
printf("\n");
|
|
line++;
|
|
i = 0;
|
|
}
|
|
}
|
|
|
|
|
|
while (i) {
|
|
printf("00");
|
|
if (++i == bytes_per_line) {
|
|
printf("\n");
|
|
line++;
|
i = 0;
|
i = 0;
|
}
|
}
|
}
|
}
|
|
|
|
|
|
|
|
while (line < min_num_bytes) {
|
|
printf("00000000\n");
|
|
line++;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
return 0;
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|