source: golgotha/src/i4/string/resource_save.cc @ 608

Last change on this file since 608 was 80, checked in by Sam Hocevar, 15 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 3.6 KB
Line 
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
9#include "string/string.hh"
10#include "error/alert.hh"
11#ifdef _MANGLE_INC
12#include "../../golg/DRIVE~RO.HH"
13#else
14#include "../../golg/drive_map.hh"
15#endif
16
17FILE *out;
18
19struct hack_str
20{
21  char *s;
22  w16 len; 
23};
24
25void print_token(char *s)
26{
27  char *s2;
28  i4_bool need_quote=i4_F;
29  for (s2=s; *s2; s2++)
30    if (*s2==' ')
31      need_quote=i4_T;
32
33  if (need_quote)
34    fprintf(out,"\"");
35  for (; *s; s++)
36  {
37    if (*s=='\n')
38      fprintf(out,"\\n");
39    else if (*s=='\r')
40      fprintf(out,"\\r");
41    else if (*s=='\"')
42      fprintf(out,"\\\"");
43    else if (*s=='\t')
44      fprintf(out,"\\t");
45    else if (*s=='\\')
46      fprintf(out,"\\\\");
47    else if (*s=='$')
48      fprintf(out,"\\$");
49    else if (*s=='/' && s[1]=='/')
50      fprintf(out,"\\/");
51
52    else fprintf(out,"%c",*s);
53  }
54
55  if (need_quote)
56    fprintf(out,"\"");
57}
58
59void print_atoken(char **s)
60{
61  fprintf(out,"{");
62  while (*s)
63  {
64    print_token(*s);
65    s++;
66    if (*s)         
67      fprintf(out," ");
68
69  }
70  fprintf(out,"}");
71}
72
73class i4_string_manager_saver_class
74{
75public:
76  void dump_node(i4_string_manager_class::node *p)
77  {
78    if (p)
79    {
80      print_token(p->str_token);
81      fprintf(out," ");
82      print_token(((hack_str *)&p->value)->s);
83      fprintf(out,"\n");
84
85      dump_node(p->left);
86      dump_node(p->right);
87    }
88  }
89
90  void dump_array_node(i4_string_manager_class::array_node *p)
91  {
92    if (p)
93    {
94      print_token(p->str_token);
95      fprintf(out," ");
96      print_atoken(p->value);
97      fprintf(out,"\n");
98
99      dump_array_node(p->left);
100      dump_array_node(p->right);
101    }
102  }
103
104  i4_string_manager_saver_class(i4_string_manager_class *str_man)
105  {
106    dump_node(str_man->root);
107    dump_array_node(str_man->array_root);
108  }
109
110};
111
112i4_string_manager_class lx_s;
113
114void i4_main(w32 argc, i4_const_str *argv)
115{
116  i4_init(0,0);
117  if (argc!=3)
118    i4_error("bad # of argurments, ussage file_name symbol_name");
119
120#ifdef __linux
121  char *drive_map_resource =
122    "f:/ f:/ "
123    "F:/ F:/ "
124    "/u/ /u/ "
125    "c:/ c:/ "
126    "C:/ C:/ "
127    "/tmp/ /tmp/ "
128    "res_name c:/3dsmax/plugins/resource/ "
129    "res_loc /u/oliy/src/crack/maxtool/res/ "
130    "alpha1 \\//alpha1/ "
131    "/ / "
132    ;
133
134
135
136  lx_s.load_buffer(0,drive_map_resource,"drive_map_resource");
137  i4_file_man.mount_dir(lx_s.get("f:/"),new g1_drive_map(lx_s.get("/u/")));
138  i4_file_man.mount_dir(lx_s.get("F:/"),new g1_drive_map(lx_s.get("/u/")));
139  i4_file_man.mount_dir(lx_s.get("c:/"),new g1_drive_map(lx_s.get("/tmp/"))); 
140#endif
141
142
143  i4_string_man.load(0,argv[1]);
144  out=fopen("/tmp/parse.out","wb");
145  if (!out)
146    i4_error("unable to open tmp file");
147
148  i4_string_manager_saver_class d(&i4_string_man);
149  fclose(out);
150
151
152  out=fopen("/tmp/parse.out","rb");
153  printf("char %s[]={\n  ",((hack_str *)&argv[2])->s);
154  int c,x=0;
155
156  while (!feof(out))
157  {
158    c=fgetc(out);
159    if (!feof(out))
160    {
161      if (x!=0)
162        printf(",");
163      if (((x+1)%15)==0)
164      {
165        printf("\n  ");
166      }
167
168      printf("0x%x",c);
169
170
171    }
172    x++;
173
174  }
175  printf("};\n");
176
177  fflush(stdout);
178
179
180  i4_uninit();
181}
Note: See TracBrowser for help on using the repository browser.