| #include <stdio.h> |
| #include <string.h> |
| |
| int main(int argc, char *argv[]) |
| { |
| |
| int c; |
| int comment = 0; |
| int linebreak = 1; |
| const char *msg = |
| "/* do not modify !! (automatically generated by initcode) */\n\n"; |
| char buf[32]; |
| int cnt; |
| char *point; |
| |
| FILE *infp, *outfp; |
| |
| if (argc != 3) { |
| printf("usage: %s infile outfile\n", argv[0]); |
| return (1); |
| } |
| |
| infp = fopen(argv[1], "r"); |
| |
| if (!infp) { |
| printf("could not open input file %s\n", argv[1]); |
| return (1); |
| } |
| |
| outfp = fopen(argv[2], "w"); |
| |
| if (!outfp) { |
| printf("could not open output file %s\n", argv[2]); |
| fclose(infp); |
| return (1); |
| } |
| |
| fwrite(msg, strlen(msg), 1, outfp); |
| |
| fwrite("char ", 5, 1, outfp); |
| |
| if (argc == 4) { |
| fwrite(argv[3], strlen(argv[3]), 1, outfp); |
| } |
| else { |
| while ((point = strchr(argv[2], '.')) != NULL) { |
| *point = '_'; |
| } |
| fwrite(argv[2], strlen(argv[2]), 1, outfp); |
| } |
| |
| fwrite("[] = {", 6, 1, outfp); |
| |
| cnt = 0; |
| |
| while ((c = getc(infp)) != EOF) { |
| |
| if (linebreak && c == '#') |
| comment = 1; |
| |
| if (!comment) { |
| sprintf(buf, "0x%x,", c); |
| fwrite(buf, strlen(buf), 1, outfp); |
| cnt++; |
| |
| if ((cnt % 10) == 0) { |
| |
| sprintf(buf, "\n "); |
| fwrite(buf, strlen(buf), 1, outfp); |
| } |
| } |
| |
| linebreak = 0; |
| |
| if ((char) c == '\n') { |
| linebreak = 1; |
| comment = 0; |
| } |
| |
| } |
| |
| sprintf(buf, "0x0};\n"); |
| fwrite(buf, strlen(buf), 1, outfp); |
| |
| fclose(infp); |
| fclose(outfp); |
| |
| return (0); |
| } |