URL
https://opencores.org/ocsvn/eco32/eco32/trunk
Only display areas with differences |
Details |
Blame |
View Log
Rev 18 |
Rev 270 |
/*
|
/*
|
* dump.c -- dump a binary file as contents of a C array
|
* dump.c -- dump a binary file as contents of a C array
|
*/
|
*/
|
|
|
|
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <string.h>
|
#include <string.h>
|
|
|
|
|
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
FILE *infile, *outfile;
|
FILE *infile, *outfile;
|
int c, n;
|
int c, n;
|
|
|
if (argc != 3) {
|
if (argc != 3) {
|
printf("Usage: %s <infile> <outfile>\n", argv[0]);
|
printf("Usage: %s <infile> <outfile>\n", argv[0]);
|
return 1;
|
return 1;
|
}
|
}
|
infile = fopen(argv[1], "rb");
|
infile = fopen(argv[1], "rb");
|
if (infile == NULL) {
|
if (infile == NULL) {
|
printf("Error: cannot open file '%s' for input\n", argv[1]);
|
printf("Error: cannot open file '%s' for input\n", argv[1]);
|
return 1;
|
return 1;
|
}
|
}
|
outfile = fopen(argv[2], "wt");
|
outfile = fopen(argv[2], "wt");
|
if (outfile == NULL) {
|
if (outfile == NULL) {
|
printf("Error: cannot open file '%s' for output\n", argv[2]);
|
printf("Error: cannot open file '%s' for output\n", argv[2]);
|
return 1;
|
return 1;
|
}
|
}
|
n = 0;
|
n = 0;
|
while (1) {
|
while (1) {
|
c = getc(infile);
|
c = getc(infile);
|
if (c == EOF) {
|
if (c == EOF) {
|
break;
|
break;
|
}
|
}
|
fprintf(outfile, "0x%02X, ", c);
|
fprintf(outfile, "0x%02X, ", c);
|
n++;
|
n++;
|
if (n == 8) {
|
if (n == 8) {
|
n = 0;
|
n = 0;
|
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
}
|
}
|
}
|
}
|
if (n != 0) {
|
if (n != 0) {
|
fprintf(outfile, "\n");
|
fprintf(outfile, "\n");
|
}
|
}
|
fclose(infile);
|
fclose(infile);
|
fclose(outfile);
|
fclose(outfile);
|
return 0;
|
return 0;
|
}
|
}
|
|
|
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.