ansi-to-src.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include <ctype.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #define ZF_LOGD(...)
  5. #include "utils.h"
  6. int read_file(const char *filename) {
  7. FILE *fp;
  8. char buffer[10240];
  9. int read;
  10. fp = fopen(filename, "rb");
  11. if (fp == NULL) {
  12. ZF_LOGD("Failed to open %s", filename);
  13. return 0;
  14. }
  15. strcpy(buffer, filename);
  16. char *cp;
  17. if ((cp = strchr(buffer, '.')) != NULL) {
  18. *cp = 0;
  19. }
  20. cp = buffer;
  21. while (*cp != 0) {
  22. if (!isalpha(*cp))
  23. memmove(cp, cp + 1, strlen(cp));
  24. cp++;
  25. }
  26. printf("char * %s[] = {\n", buffer);
  27. if ((read = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
  28. char *nl;
  29. buffer[read] = 0;
  30. cp = repr(buffer);
  31. int first = 1;
  32. while ((nl = strstr(cp, "\\r\\n")) != NULL) {
  33. strcpy(nl, "\"");
  34. if (!first) {
  35. printf(",\n");
  36. };
  37. first = 0;
  38. printf(" \"%s", cp);
  39. cp = nl + 4;
  40. }
  41. if (strlen(cp) > 0)
  42. printf(",\n \"%s\"\n", cp);
  43. else
  44. printf("\n");
  45. printf("};\n");
  46. };
  47. fclose(fp);
  48. return 1;
  49. }
  50. int main(int argc, char *argv[]) {
  51. read_file(argv[1]);
  52. return 0;
  53. }