|
|
1.1 ! root 1: // ! 2: // Copyright (C) 2012-2016 [email protected] ! 3: // ! 4: // cgrom.dat を C ソースに変換する ! 5: // ! 6: // 書式 ! 7: // gencgrom <cgrom.dat> <cgrom.cpp> ! 8: // ! 9: ! 10: #include <cstdint> ! 11: #include <cstdio> ! 12: #include <cstdlib> ! 13: #include <cstring> ! 14: ! 15: int ! 16: main(int ac, char *av[]) ! 17: { ! 18: char buf[4096]; ! 19: const char *infile; ! 20: const char *outfile; ! 21: FILE *in; ! 22: FILE *out; ! 23: int n; ! 24: int i; ! 25: ! 26: if (ac < 3) { ! 27: fprintf(stderr, "usage: %s <infile> <outfile>\n", av[0]); ! 28: exit(1); ! 29: } ! 30: ! 31: infile = av[1]; ! 32: outfile = av[2]; ! 33: ! 34: in = fopen(infile, "rb"); ! 35: if (in == NULL) { ! 36: fprintf(stderr, "cannot open %s\n", infile); ! 37: exit(1); ! 38: } ! 39: ! 40: out = fopen(outfile, "wb"); ! 41: if (out == NULL) { ! 42: fprintf(stderr, "cannot open %s\n", outfile); ! 43: exit(1); ! 44: } ! 45: ! 46: fprintf(out, "// This file is auto-generated by %s\n", av[0]); ! 47: fprintf(out, "#include \"cgrom.h\"\n"); ! 48: fprintf(out, "uint8 builtin_cgrom[] = {"); ! 49: ! 50: for (;;) { ! 51: n = fread(buf, 1, sizeof(buf), in); ! 52: if (n == 0) { ! 53: break; ! 54: } ! 55: ! 56: for (i = 0; i < n; i++) { ! 57: if (i % 8 == 0) { ! 58: fprintf(out, "\n\t"); ! 59: } ! 60: fprintf(out, "0x%02x,", (unsigned char)buf[i]); ! 61: } ! 62: } ! 63: fprintf(out, "\n};\n"); ! 64: ! 65: fclose(in); ! 66: fclose(out); ! 67: exit(0); ! 68: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.