resource_save.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "string/string.hh"
  9. #include "error/alert.hh"
  10. #ifdef _MANGLE_INC
  11. #include "../../golg/DRIVE~RO.HH"
  12. #else
  13. #include "../../golg/drive_map.hh"
  14. #endif
  15. FILE *out;
  16. struct hack_str
  17. {
  18. char *s;
  19. w16 len;
  20. };
  21. void print_token(char *s)
  22. {
  23. char *s2;
  24. i4_bool need_quote=i4_F;
  25. for (s2=s; *s2; s2++)
  26. if (*s2==' ')
  27. need_quote=i4_T;
  28. if (need_quote)
  29. fprintf(out,"\"");
  30. for (; *s; s++)
  31. {
  32. if (*s=='\n')
  33. fprintf(out,"\\n");
  34. else if (*s=='\r')
  35. fprintf(out,"\\r");
  36. else if (*s=='\"')
  37. fprintf(out,"\\\"");
  38. else if (*s=='\t')
  39. fprintf(out,"\\t");
  40. else if (*s=='\\')
  41. fprintf(out,"\\\\");
  42. else if (*s=='$')
  43. fprintf(out,"\\$");
  44. else if (*s=='/' && s[1]=='/')
  45. fprintf(out,"\\/");
  46. else fprintf(out,"%c",*s);
  47. }
  48. if (need_quote)
  49. fprintf(out,"\"");
  50. }
  51. void print_atoken(char **s)
  52. {
  53. fprintf(out,"{");
  54. while (*s)
  55. {
  56. print_token(*s);
  57. s++;
  58. if (*s)
  59. fprintf(out," ");
  60. }
  61. fprintf(out,"}");
  62. }
  63. class i4_string_manager_saver_class
  64. {
  65. public:
  66. void dump_node(i4_string_manager_class::node *p)
  67. {
  68. if (p)
  69. {
  70. print_token(p->str_token);
  71. fprintf(out," ");
  72. print_token(((hack_str *)&p->value)->s);
  73. fprintf(out,"\n");
  74. dump_node(p->left);
  75. dump_node(p->right);
  76. }
  77. }
  78. void dump_array_node(i4_string_manager_class::array_node *p)
  79. {
  80. if (p)
  81. {
  82. print_token(p->str_token);
  83. fprintf(out," ");
  84. print_atoken(p->value);
  85. fprintf(out,"\n");
  86. dump_array_node(p->left);
  87. dump_array_node(p->right);
  88. }
  89. }
  90. i4_string_manager_saver_class(i4_string_manager_class *str_man)
  91. {
  92. dump_node(str_man->root);
  93. dump_array_node(str_man->array_root);
  94. }
  95. };
  96. i4_string_manager_class lx_s;
  97. void i4_main(w32 argc, i4_const_str *argv)
  98. {
  99. i4_init(0,0);
  100. if (argc!=3)
  101. i4_error("bad # of argurments, ussage file_name symbol_name");
  102. #ifdef __linux
  103. char *drive_map_resource =
  104. "f:/ f:/ "
  105. "F:/ F:/ "
  106. "/u/ /u/ "
  107. "c:/ c:/ "
  108. "C:/ C:/ "
  109. "/tmp/ /tmp/ "
  110. "res_name c:/3dsmax/plugins/resource/ "
  111. "res_loc /u/oliy/src/crack/maxtool/res/ "
  112. "alpha1 \\//alpha1/ "
  113. "/ / "
  114. ;
  115. lx_s.load_buffer(0,drive_map_resource,"drive_map_resource");
  116. i4_file_man.mount_dir(lx_s.get("f:/"),new g1_drive_map(lx_s.get("/u/")));
  117. i4_file_man.mount_dir(lx_s.get("F:/"),new g1_drive_map(lx_s.get("/u/")));
  118. i4_file_man.mount_dir(lx_s.get("c:/"),new g1_drive_map(lx_s.get("/tmp/")));
  119. #endif
  120. i4_string_man.load(0,argv[1]);
  121. out=fopen("/tmp/parse.out","wb");
  122. if (!out)
  123. i4_error("unable to open tmp file");
  124. i4_string_manager_saver_class d(&i4_string_man);
  125. fclose(out);
  126. out=fopen("/tmp/parse.out","rb");
  127. printf("char %s[]={\n ",((hack_str *)&argv[2])->s);
  128. int c,x=0;
  129. while (!feof(out))
  130. {
  131. c=fgetc(out);
  132. if (!feof(out))
  133. {
  134. if (x!=0)
  135. printf(",");
  136. if (((x+1)%15)==0)
  137. {
  138. printf("\n ");
  139. }
  140. printf("0x%x",c);
  141. }
  142. x++;
  143. }
  144. printf("};\n");
  145. fflush(stdout);
  146. i4_uninit();
  147. }