File: gentrans.cpp

package info (click to toggle)
hyperrogue 12.1q-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 73,972 kB
  • sloc: cpp: 166,609; makefile: 145; sh: 10
file content (227 lines) | stat: -rw-r--r-- 7,137 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#include "../hyper.h"
#include <iostream>
#include <thread>

namespace hr {

char buf[10000000];
int bufpos;

bool chk(const char *s) {
  char *t = buf+bufpos;
  while(*s == *t) s++, t++;
  return *s == 0;
  }

bool eat(const char *s) {
  bool ret = chk(s);
  if(ret) bufpos += strlen(s);
  return ret;
  }

char eatchar() {
  return buf[bufpos++];
  }

set<string> seen;

void check_ex(string s, string help) {
  if(seen.count(s)) return;
  seen.insert(s);
  if(!translation_exists(s)) println(hlog, "S(", as_nice_cstring(s), ", ", help, ")");
  }

void check_nonliteral(string s, string fname, int line) {
  if(seen.count(s)) return;
  seen.insert(s);
  string thu = "", end = "";
  for(char c: s) if(c == '[') break; else thu += c;
  for(char c: s) if(c == ']') end = ""; else end += c;
  
  if(s == "s") ;
  else if(thu == "minetexts")
    for(string m: minetexts) check_ex(m, s);
  else if(thu == "dfnames")
    for(string m: dfnames) check_ex(m, s);
  else if(thu == "ncnames")
    for(string m: ncnames) check_ex(m, s);
  else if(thu == "slides" && end == ".help") ;
    // for(auto sl: tour::slides) check_ex(sl.help);
  else if(thu == "slides" && end == ".name") ;
    // for(auto sl: tour::slides) check_ex(sl.name);
  else if(end == ".menu_displayed_name") ;
    // for(auto g: ginf) check_ex(g.menu_displayed_name);
  else if(end == ".tiling_name") ;
    // for(auto g: ginf) check_ex(g.tiling_name);
  else if(end == ".name_hyperbolic")
    for(auto md: mdinf) check_ex(md.name_hyperbolic, s);
  else if(end == ".name_spherical")
    for(auto md: mdinf) { if(md.name_spherical != md.name_hyperbolic) check_ex(md.name_spherical, s); }
  else if(end == ".name_euclidean")
    for(auto md: mdinf) { if(md.name_euclidean != md.name_hyperbolic && md.name_euclidean != md.name_hyperbolic) check_ex(md.name_euclidean, s); }
  else if(thu == "olrdesc") ;
  else if(thu == "wdmodes") 
    for(string m: wdmodes) check_ex(m, s);
  else if(thu == "axemodes") 
    for(string m: multi::axemodes) check_ex(m, s);
  else if(thu == "axmodes") 
    for(string m: multi::axmodes) check_ex(m, s);
  else if(thu == "mpnames") 
    for(string m: texture::mpnames) check_ex(m, s);
  else if(thu == "axemodes3") 
    for(string m: multi::axemodes3) check_ex(m, s);
  else if(thu == "mdmodes") 
    for(string m: mdmodes) check_ex(m, s);
  else if(thu == "hlmodes") 
    for(string m: hlmodes) check_ex(m, s);
  else if(thu == "current_filter->name") 
    for(auto f: available_filters) check_ex(f->name, s);
  else if(thu == "olrDescriptions")
    for(string m: olrDescriptions) check_ex(m, s);
  else if(thu == "shmupcmdtable") ;
  else if(thu == "stringx") ;
  else if(thu == "lv.msg") ; /* trust */
  else if(thu == "opt") ; /* todo */
  else if(thu == "menu_item_name") ; /* todo */
  else if(s == "winf[w].help") ;
  else if(s == "linf[l].help") ;
  else if(s == "iinf[it].help") ;
  else if(s == "minf[m].help") ;
  else if(among(s, "mapeditorhelp", "patthelp", "drawhelp", "warpdesc", "hyperstone_optional", "irrhelp", "helptext", "inv::helptext", "power_help", "trollhelp2")) ; /* trust */
  else
    println(hlog, "// unrecognized nonliteral: ", s, " in ", fname, ":", line);
  }

void check_xlat_content(string s, string fname, int line) {
  // println(hlog, "// xlat content found: ", s);
  string literal = "";
  string nonliteral = "";
  bool in_quote = false;
  int i = 0;
  while(i < isize(s)) {
    auto chk = [&] (string mname, string mvalue) {
      if(in_quote) return false;
      for(int k=0; k<isize(mname); k++) if(s[i+k] != mname[k]) return false;
      literal += mvalue; i += isize(mname);
      return true;
      };
    if(chk("LEADERFULL", "Steam Leaderboards")) continue;
    if(chk("LEADER", "Steam")) continue;
    if(chk("IMAGEEXT", IMAGEEXT)) continue;
    if(chk("SHMUPTITLE", SHMUPTITLE)) continue;
    if(s[i] == '"') in_quote = !in_quote;
    else if(s[i] == '\\') {
      i++;
      if(s[i] == '"' || s[i] == '\'' || s[i] == '\\')  literal += s[i];
      else if(s[i] == 'n') literal += "\n";
      else println(hlog, "unknown escape: ", s0+s[i]);
      }
    else if(in_quote) literal += s[i];
    else if(among(s[i], ' ', '\n', '\r')) ;
    else nonliteral += s[i];
    i++;
    }
  if(literal != "" && nonliteral != "") {
    println(hlog, "// confused about: ", s, " ", fname, ":", line);
    println(hlog, "literal = ", literal);
    println(hlog, "nonliteral = ", nonliteral);
    }
  else if(nonliteral != "")
    check_nonliteral(nonliteral, fname, line);
  else {
    if(seen.count(literal)) return;
    seen.insert(literal);
    if(!translation_exists(literal)) 
      println(hlog, "S(", s, ", literal in ", fname, ":", line, ")");
    }
  }

void check_file(string s) {
  FILE *f = fopen(s.c_str(), "rt");
  int qty = fread(buf, 1, 10000000, f);
  buf[qty] = 0;
  fclose(f);
  // println(hlog, "// checking file ", s, ", ", qty, " B");
  
  bufpos = 0;
  
  bool in_xlat = false;
  bool in_quote = false;
  string xlat_content;
  
  int linenum = 0;
  
  while(true) {
    if(bufpos == qty) break;
    if(buf[bufpos] == '\n') linenum++;
    if(!in_xlat) {
      if(eat("XLAT(")) {
        in_xlat = true;
        xlat_content = "";
        }
      else 
        eatchar();
      }
    else {
      if(eat("\"")) {
        xlat_content += "\"";
        in_quote = !in_quote;
        }
      else if(in_quote && eat("\\")) {
        xlat_content += "\\";
        xlat_content += eatchar();
        }
      else if(!in_quote && eat("(")) {
        println(hlog, "// found parenthesis inside XLAT: ", xlat_content, " at ", s, ":", linenum);
        }
      else if(!in_quote && eat("?")) {
        println(hlog, "// found '?' inside XLAT: ", xlat_content, " at ", s, ":", linenum);
        }
      else if(!in_quote && (eat(")") || eat(","))) {
        check_xlat_content(xlat_content, s, linenum);
        in_xlat = false;
        }
      else
        xlat_content += eatchar();
      }
    }
  }

void gentrans() {
  DIR           *d;
  struct dirent *dir;
  
  println(hlog, "// checking all the files");

  d = opendir(".");

  if(d) {
    while ((dir = readdir(d)) != NULL) {
      string s = dir->d_name;
      if(s.size() > 4 && s.substr(s.size()-4) == ".cpp")
        check_file(s);
      }
    closedir(d);
    }

  println(hlog, "// checking configurables");
  
  for(auto& fs: params) {
    auto& sett = fs.second;
    if(sett->menu_item_name != sett->config_name)
      check_ex(sett->menu_item_name, "menu_item_name for " + sett->parameter_name);
    check_ex(sett->help_text, "help_text for " + sett->parameter_name);
    auto ls = dynamic_cast<list_setting*> ( (setting*) &*sett);
    if(ls)
      for(auto opt: ls->options) {
        check_ex(opt.first, "option first for " + sett->parameter_name);
        check_ex(opt.second, "option second for " + sett->parameter_name);
        }
    }
  
  exit(0);
  }

auto ar = arg::add3("-gentrans", gentrans);

}