| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <ctype.h> |
| |
| typedef unsigned char UINT8; |
| typedef unsigned short UINT16; |
| typedef unsigned long UINT32; |
| |
| char *changeExt(const char *inName, const char *ext) |
| { |
| char *outName = (char *)malloc(strlen(inName) + strlen(ext) + 1 + 1); //+ext+'.'+\0 |
| int i, exti; |
| if (outName) { |
| for (i = 0, exti = -1; inName[i]; i++) { |
| if ((outName[i] = inName[i]) == '.') |
| exti = i; |
| } |
| |
| if (exti < 0) //no dot |
| { |
| exti = i; |
| outName[exti] = '.'; |
| } |
| strcpy(&outName[exti + 1], ext); |
| } |
| return outName; |
| } |
| |
| void main(int argc, char *argv[]) |
| { |
| FILE *fin; |
| FILE *fout; |
| char *outName; |
| UINT32 buffer[2]; |
| int i; |
| |
| int success = false; |
| |
| if (argc != 2 && argc != 3) { |
| fprintf(stderr, "USAGE: %s input-file-name <output-file-name>\n", argv[0]); |
| exit(1); |
| } |
| |
| if (!(fin = fopen(argv[1], "rb"))) { |
| fprintf(stderr, "Cannot open input file \"%s\"\n", argv[1]); |
| exit(1); |
| } |
| |
| if (argc < 3) { |
| outName = changeExt(argv[1], "txt"); |
| } else |
| outName = argv[2]; |
| |
| if (!(fout = fopen(outName, "wt+"))) { |
| fprintf(stderr, "Cannot open output file \"%s\"\n", outName); |
| fclose(fin); |
| if (outName != argv[2]) |
| free(outName); |
| exit(1); |
| } |
| // Write output heading (18 lines required for Excel spread-sheet to import the data starting at 19) |
| for (i = 0; i < 18; i++) { |
| fprintf(fout, "--- mipsram-out header ---\n"); |
| } |
| |
| // Read/convert/write data |
| while (fread((void *)buffer, sizeof(buffer), 1, fin) > 0) { |
| fprintf(fout, "XXXXXX 00000000 : *%.8X %.8X* xxxxxxxxxx\n", buffer[0], buffer[1]); |
| } |
| success = true; |
| |
| fclose(fin); |
| if (fout != stdout) { |
| fclose(fout); |
| if (!success) |
| unlink(outName); |
| } |
| |
| if (outName != argv[2]) |
| free(outName); |
| |
| if (success) { |
| fprintf(stderr, "Done\n"); |
| exit(0); |
| } else { |
| fprintf(stderr, "Conversion failed, no output generated\n"); |
| exit(0); |
| } |
| } |