mittens 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/Gemfile +7 -0
  4. data/LICENSE.txt +30 -0
  5. data/README.md +62 -0
  6. data/Rakefile +21 -0
  7. data/ext/mittens/ext.c +96 -0
  8. data/ext/mittens/extconf.rb +12 -0
  9. data/lib/mittens/version.rb +3 -0
  10. data/lib/mittens.rb +7 -0
  11. data/mittens.gemspec +22 -0
  12. data/vendor/snowball/.gitignore +26 -0
  13. data/vendor/snowball/.travis.yml +112 -0
  14. data/vendor/snowball/AUTHORS +27 -0
  15. data/vendor/snowball/CONTRIBUTING.rst +216 -0
  16. data/vendor/snowball/COPYING +29 -0
  17. data/vendor/snowball/GNUmakefile +742 -0
  18. data/vendor/snowball/NEWS +754 -0
  19. data/vendor/snowball/README.rst +37 -0
  20. data/vendor/snowball/ada/README.md +74 -0
  21. data/vendor/snowball/ada/generate/generate.adb +83 -0
  22. data/vendor/snowball/ada/generate.gpr +21 -0
  23. data/vendor/snowball/ada/src/stemmer.adb +620 -0
  24. data/vendor/snowball/ada/src/stemmer.ads +219 -0
  25. data/vendor/snowball/ada/src/stemwords.adb +70 -0
  26. data/vendor/snowball/ada/stemmer_config.gpr +83 -0
  27. data/vendor/snowball/ada/stemwords.gpr +21 -0
  28. data/vendor/snowball/algorithms/arabic.sbl +558 -0
  29. data/vendor/snowball/algorithms/armenian.sbl +301 -0
  30. data/vendor/snowball/algorithms/basque.sbl +149 -0
  31. data/vendor/snowball/algorithms/catalan.sbl +202 -0
  32. data/vendor/snowball/algorithms/danish.sbl +93 -0
  33. data/vendor/snowball/algorithms/dutch.sbl +164 -0
  34. data/vendor/snowball/algorithms/english.sbl +229 -0
  35. data/vendor/snowball/algorithms/finnish.sbl +197 -0
  36. data/vendor/snowball/algorithms/french.sbl +254 -0
  37. data/vendor/snowball/algorithms/german.sbl +139 -0
  38. data/vendor/snowball/algorithms/german2.sbl +145 -0
  39. data/vendor/snowball/algorithms/greek.sbl +701 -0
  40. data/vendor/snowball/algorithms/hindi.sbl +323 -0
  41. data/vendor/snowball/algorithms/hungarian.sbl +241 -0
  42. data/vendor/snowball/algorithms/indonesian.sbl +192 -0
  43. data/vendor/snowball/algorithms/irish.sbl +149 -0
  44. data/vendor/snowball/algorithms/italian.sbl +202 -0
  45. data/vendor/snowball/algorithms/kraaij_pohlmann.sbl +240 -0
  46. data/vendor/snowball/algorithms/lithuanian.sbl +373 -0
  47. data/vendor/snowball/algorithms/lovins.sbl +208 -0
  48. data/vendor/snowball/algorithms/nepali.sbl +92 -0
  49. data/vendor/snowball/algorithms/norwegian.sbl +80 -0
  50. data/vendor/snowball/algorithms/porter.sbl +139 -0
  51. data/vendor/snowball/algorithms/portuguese.sbl +218 -0
  52. data/vendor/snowball/algorithms/romanian.sbl +236 -0
  53. data/vendor/snowball/algorithms/russian.sbl +221 -0
  54. data/vendor/snowball/algorithms/serbian.sbl +2379 -0
  55. data/vendor/snowball/algorithms/spanish.sbl +230 -0
  56. data/vendor/snowball/algorithms/swedish.sbl +72 -0
  57. data/vendor/snowball/algorithms/tamil.sbl +405 -0
  58. data/vendor/snowball/algorithms/turkish.sbl +470 -0
  59. data/vendor/snowball/algorithms/yiddish.sbl +460 -0
  60. data/vendor/snowball/charsets/ISO-8859-2.sbl +98 -0
  61. data/vendor/snowball/charsets/KOI8-R.sbl +74 -0
  62. data/vendor/snowball/charsets/cp850.sbl +130 -0
  63. data/vendor/snowball/compiler/analyser.c +1547 -0
  64. data/vendor/snowball/compiler/driver.c +615 -0
  65. data/vendor/snowball/compiler/generator.c +1748 -0
  66. data/vendor/snowball/compiler/generator_ada.c +1702 -0
  67. data/vendor/snowball/compiler/generator_csharp.c +1322 -0
  68. data/vendor/snowball/compiler/generator_go.c +1278 -0
  69. data/vendor/snowball/compiler/generator_java.c +1313 -0
  70. data/vendor/snowball/compiler/generator_js.c +1316 -0
  71. data/vendor/snowball/compiler/generator_pascal.c +1387 -0
  72. data/vendor/snowball/compiler/generator_python.c +1337 -0
  73. data/vendor/snowball/compiler/generator_rust.c +1295 -0
  74. data/vendor/snowball/compiler/header.h +418 -0
  75. data/vendor/snowball/compiler/space.c +286 -0
  76. data/vendor/snowball/compiler/syswords.h +86 -0
  77. data/vendor/snowball/compiler/syswords2.h +13 -0
  78. data/vendor/snowball/compiler/tokeniser.c +567 -0
  79. data/vendor/snowball/csharp/.gitignore +8 -0
  80. data/vendor/snowball/csharp/Snowball/Algorithms/.gitignore +1 -0
  81. data/vendor/snowball/csharp/Snowball/Among.cs +108 -0
  82. data/vendor/snowball/csharp/Snowball/AssemblyInfo.cs +36 -0
  83. data/vendor/snowball/csharp/Snowball/Stemmer.cs +660 -0
  84. data/vendor/snowball/csharp/Stemwords/App.config +6 -0
  85. data/vendor/snowball/csharp/Stemwords/Program.cs +114 -0
  86. data/vendor/snowball/doc/TODO +12 -0
  87. data/vendor/snowball/doc/libstemmer_c_README +148 -0
  88. data/vendor/snowball/doc/libstemmer_csharp_README +53 -0
  89. data/vendor/snowball/doc/libstemmer_java_README +67 -0
  90. data/vendor/snowball/doc/libstemmer_js_README +48 -0
  91. data/vendor/snowball/doc/libstemmer_python_README +113 -0
  92. data/vendor/snowball/examples/stemwords.c +204 -0
  93. data/vendor/snowball/go/README.md +55 -0
  94. data/vendor/snowball/go/among.go +16 -0
  95. data/vendor/snowball/go/env.go +403 -0
  96. data/vendor/snowball/go/stemwords/generate.go +68 -0
  97. data/vendor/snowball/go/stemwords/main.go +68 -0
  98. data/vendor/snowball/go/util.go +34 -0
  99. data/vendor/snowball/iconv.py +50 -0
  100. data/vendor/snowball/include/libstemmer.h +78 -0
  101. data/vendor/snowball/java/org/tartarus/snowball/Among.java +29 -0
  102. data/vendor/snowball/java/org/tartarus/snowball/SnowballProgram.java +381 -0
  103. data/vendor/snowball/java/org/tartarus/snowball/SnowballStemmer.java +8 -0
  104. data/vendor/snowball/java/org/tartarus/snowball/TestApp.java +75 -0
  105. data/vendor/snowball/javascript/base-stemmer.js +294 -0
  106. data/vendor/snowball/javascript/stemwords.js +106 -0
  107. data/vendor/snowball/libstemmer/libstemmer_c.in +96 -0
  108. data/vendor/snowball/libstemmer/mkalgorithms.pl +90 -0
  109. data/vendor/snowball/libstemmer/mkmodules.pl +267 -0
  110. data/vendor/snowball/libstemmer/modules.txt +63 -0
  111. data/vendor/snowball/libstemmer/test.c +34 -0
  112. data/vendor/snowball/pascal/.gitignore +4 -0
  113. data/vendor/snowball/pascal/SnowballProgram.pas +430 -0
  114. data/vendor/snowball/pascal/generate.pl +23 -0
  115. data/vendor/snowball/pascal/stemwords-template.dpr +78 -0
  116. data/vendor/snowball/python/MANIFEST.in +7 -0
  117. data/vendor/snowball/python/create_init.py +54 -0
  118. data/vendor/snowball/python/setup.cfg +6 -0
  119. data/vendor/snowball/python/setup.py +81 -0
  120. data/vendor/snowball/python/snowballstemmer/among.py +13 -0
  121. data/vendor/snowball/python/snowballstemmer/basestemmer.py +323 -0
  122. data/vendor/snowball/python/stemwords.py +101 -0
  123. data/vendor/snowball/python/testapp.py +28 -0
  124. data/vendor/snowball/runtime/api.c +58 -0
  125. data/vendor/snowball/runtime/api.h +32 -0
  126. data/vendor/snowball/runtime/header.h +61 -0
  127. data/vendor/snowball/runtime/utilities.c +513 -0
  128. data/vendor/snowball/rust/Cargo.toml +7 -0
  129. data/vendor/snowball/rust/build.rs +55 -0
  130. data/vendor/snowball/rust/rust-pre-1.27-compat.patch +30 -0
  131. data/vendor/snowball/rust/src/main.rs +102 -0
  132. data/vendor/snowball/rust/src/snowball/algorithms/mod.rs +2 -0
  133. data/vendor/snowball/rust/src/snowball/among.rs +6 -0
  134. data/vendor/snowball/rust/src/snowball/mod.rs +6 -0
  135. data/vendor/snowball/rust/src/snowball/snowball_env.rs +421 -0
  136. data/vendor/snowball/tests/stemtest.c +95 -0
  137. metadata +178 -0
@@ -0,0 +1,615 @@
1
+ #include <ctype.h> /* for toupper etc */
2
+ #include <stdio.h> /* for fprintf etc */
3
+ #include <stdlib.h> /* for free etc */
4
+ #include <string.h> /* for strcmp */
5
+ #include "header.h"
6
+
7
+ #define DEFAULT_JAVA_PACKAGE "org.tartarus.snowball.ext"
8
+ #define DEFAULT_JAVA_BASE_CLASS "org.tartarus.snowball.SnowballProgram"
9
+ #define DEFAULT_JAVA_AMONG_CLASS "org.tartarus.snowball.Among"
10
+ #define DEFAULT_JAVA_STRING_CLASS "java.lang.StringBuilder"
11
+
12
+ #define DEFAULT_GO_PACKAGE "snowball"
13
+ #define DEFAULT_GO_SNOWBALL_RUNTIME "github.com/snowballstem/snowball/go"
14
+
15
+ #define DEFAULT_ADA_PACKAGE "Snowball"
16
+ #define DEFAULT_ADA_SNOWBALL_RUNTIME "github.com/snowballstem/snowball/ada"
17
+
18
+ #define DEFAULT_CS_NAMESPACE "Snowball"
19
+ #define DEFAULT_CS_BASE_CLASS "Stemmer"
20
+ #define DEFAULT_CS_AMONG_CLASS "Among"
21
+ #define DEFAULT_CS_STRING_CLASS "StringBuilder"
22
+
23
+ #define DEFAULT_JS_BASE_CLASS "BaseStemmer"
24
+
25
+ #define DEFAULT_PYTHON_BASE_CLASS "BaseStemmer"
26
+
27
+ static int eq(const char * s1, const char * s2) {
28
+ return strcmp(s1, s2) == 0;
29
+ }
30
+
31
+ static void print_arglist(int exit_code) {
32
+ FILE * f = exit_code ? stderr : stdout;
33
+ fprintf(f, "Usage: snowball SOURCE_FILE... [OPTIONS]\n\n"
34
+ "Supported options:\n"
35
+ " -o[utput] file\n"
36
+ " -s[yntax]\n"
37
+ " -comments\n"
38
+ #ifndef DISABLE_JAVA
39
+ " -j[ava]\n"
40
+ #endif
41
+ #ifndef DISABLE_CSHARP
42
+ " -cs[harp]\n"
43
+ #endif
44
+ " -c++\n"
45
+ #ifndef DISABLE_PASCAL
46
+ " -pascal\n"
47
+ #endif
48
+ #ifndef DISABLE_PYTHON
49
+ " -py[thon]\n"
50
+ #endif
51
+ #ifndef DISABLE_JS
52
+ " -js\n"
53
+ #endif
54
+ #ifndef DISABLE_RUST
55
+ " -rust\n"
56
+ #endif
57
+ #ifndef DISABLE_GO
58
+ " -go\n"
59
+ #endif
60
+ #ifndef DISABLE_ADA
61
+ " -ada\n"
62
+ #endif
63
+ " -w[idechars]\n"
64
+ " -u[tf8]\n"
65
+ " -n[ame] class name\n"
66
+ " -ep[refix] string\n"
67
+ " -vp[refix] string\n"
68
+ " -i[nclude] directory\n"
69
+ " -r[untime] path to runtime headers\n"
70
+ " -p[arentclassname] fully qualified parent class name\n"
71
+ #if !defined(DISABLE_JAVA) || !defined(DISABLE_CSHARP)
72
+ " -P[ackage] package name for stemmers\n"
73
+ " -S[tringclass] StringBuffer-compatible class\n"
74
+ " -a[mongclass] fully qualified name of the Among class\n"
75
+ #endif
76
+ #ifndef DISABLE_GO
77
+ " -gop[ackage] Go package name for stemmers\n"
78
+ " -gor[untime] Go snowball runtime package\n"
79
+ #endif
80
+ " --help display this help and exit\n"
81
+ " --version output version information and exit\n"
82
+ );
83
+ exit(exit_code);
84
+ }
85
+
86
+ static void check_lim(int i, int argc) {
87
+ if (i >= argc) {
88
+ fprintf(stderr, "argument list is one short\n");
89
+ print_arglist(1);
90
+ }
91
+ }
92
+
93
+ static FILE * get_output(symbol * b) {
94
+ char * s = b_to_s(b);
95
+ FILE * output = fopen(s, "w");
96
+ if (output == 0) {
97
+ fprintf(stderr, "Can't open output %s\n", s);
98
+ exit(1);
99
+ }
100
+ free(s);
101
+ return output;
102
+ }
103
+
104
+ static int read_options(struct options * o, int argc, char * argv[]) {
105
+ char * s;
106
+ int i = 1;
107
+ int new_argc = 1;
108
+ /* Note down the last option used to specify an explicit encoding so
109
+ * we can warn we ignored it for languages with a fixed encoding.
110
+ */
111
+ const char * encoding_opt = NULL;
112
+
113
+ /* set defaults: */
114
+
115
+ o->output_file = 0;
116
+ o->syntax_tree = false;
117
+ o->comments = false;
118
+ o->externals_prefix = NULL;
119
+ o->variables_prefix = 0;
120
+ o->runtime_path = 0;
121
+ o->parent_class_name = NULL;
122
+ o->string_class = NULL;
123
+ o->among_class = NULL;
124
+ o->package = NULL;
125
+ o->go_snowball_runtime = DEFAULT_GO_SNOWBALL_RUNTIME;
126
+ o->name = NULL;
127
+ o->make_lang = LANG_C;
128
+ o->includes = 0;
129
+ o->includes_end = 0;
130
+ o->encoding = ENC_SINGLEBYTE;
131
+
132
+ /* read options: */
133
+
134
+ while (i < argc) {
135
+ s = argv[i++];
136
+ if (s[0] != '-') {
137
+ /* Non-option argument - shuffle down. */
138
+ argv[new_argc++] = s;
139
+ continue;
140
+ }
141
+
142
+ {
143
+ if (eq(s, "-o") || eq(s, "-output")) {
144
+ check_lim(i, argc);
145
+ o->output_file = argv[i++];
146
+ continue;
147
+ }
148
+ if (eq(s, "-n") || eq(s, "-name")) {
149
+ char * new_name;
150
+ size_t len;
151
+
152
+ check_lim(i, argc);
153
+ /* Take a copy of the argument here, because
154
+ * later we will free o->name */
155
+ len = strlen(argv[i]);
156
+ new_name = malloc(len + 1);
157
+ memcpy(new_name, argv[i++], len);
158
+ new_name[len] = '\0';
159
+ o->name = new_name;
160
+ continue;
161
+ }
162
+ #ifndef DISABLE_JS
163
+ if (eq(s, "-js")) {
164
+ o->make_lang = LANG_JAVASCRIPT;
165
+ continue;
166
+ }
167
+ #endif
168
+ #ifndef DISABLE_RUST
169
+ if (eq(s, "-rust")) {
170
+ o->make_lang = LANG_RUST;
171
+ continue;
172
+ }
173
+ #endif
174
+ #ifndef DISABLE_GO
175
+ if (eq(s, "-go")) {
176
+ o->make_lang = LANG_GO;
177
+ continue;
178
+ }
179
+ #endif
180
+ #ifndef DISABLE_JAVA
181
+ if (eq(s, "-j") || eq(s, "-java")) {
182
+ o->make_lang = LANG_JAVA;
183
+ continue;
184
+ }
185
+ #endif
186
+ #ifndef DISABLE_CSHARP
187
+ if (eq(s, "-cs") || eq(s, "-csharp")) {
188
+ o->make_lang = LANG_CSHARP;
189
+ continue;
190
+ }
191
+ #endif
192
+ if (eq(s, "-c++")) {
193
+ o->make_lang = LANG_CPLUSPLUS;
194
+ continue;
195
+ }
196
+ #ifndef DISABLE_PASCAL
197
+ if (eq(s, "-pascal")) {
198
+ o->make_lang = LANG_PASCAL;
199
+ continue;
200
+ }
201
+ #endif
202
+ #ifndef DISABLE_PYTHON
203
+ if (eq(s, "-py") || eq(s, "-python")) {
204
+ o->make_lang = LANG_PYTHON;
205
+ continue;
206
+ }
207
+ #endif
208
+ #ifndef DISABLE_ADA
209
+ if (eq(s, "-ada")) {
210
+ o->make_lang = LANG_ADA;
211
+ continue;
212
+ }
213
+ #endif
214
+ if (eq(s, "-w") || eq(s, "-widechars")) {
215
+ encoding_opt = s;
216
+ o->encoding = ENC_WIDECHARS;
217
+ continue;
218
+ }
219
+ if (eq(s, "-s") || eq(s, "-syntax")) {
220
+ o->syntax_tree = true;
221
+ continue;
222
+ }
223
+ if (eq(s, "-comments")) {
224
+ o->comments = true;
225
+ continue;
226
+ }
227
+ if (eq(s, "-ep") || eq(s, "-eprefix")) {
228
+ check_lim(i, argc);
229
+ o->externals_prefix = argv[i++];
230
+ continue;
231
+ }
232
+ if (eq(s, "-vp") || eq(s, "-vprefix")) {
233
+ check_lim(i, argc);
234
+ o->variables_prefix = argv[i++];
235
+ continue;
236
+ }
237
+ if (eq(s, "-i") || eq(s, "-include")) {
238
+ check_lim(i, argc);
239
+
240
+ {
241
+ NEW(include, p);
242
+ symbol * b = add_s_to_b(0, argv[i++]);
243
+ b = add_s_to_b(b, "/");
244
+ p->next = 0; p->b = b;
245
+
246
+ if (o->includes == 0) o->includes = p; else
247
+ o->includes_end->next = p;
248
+ o->includes_end = p;
249
+ }
250
+ continue;
251
+ }
252
+ if (eq(s, "-r") || eq(s, "-runtime")) {
253
+ check_lim(i, argc);
254
+ o->runtime_path = argv[i++];
255
+ continue;
256
+ }
257
+ if (eq(s, "-u") || eq(s, "-utf8")) {
258
+ encoding_opt = s;
259
+ o->encoding = ENC_UTF8;
260
+ continue;
261
+ }
262
+ if (eq(s, "-p") || eq(s, "-parentclassname")) {
263
+ check_lim(i, argc);
264
+ o->parent_class_name = argv[i++];
265
+ continue;
266
+ }
267
+ #if !defined(DISABLE_JAVA) || !defined(DISABLE_CSHARP)
268
+ if (eq(s, "-P") || eq(s, "-Package")) {
269
+ check_lim(i, argc);
270
+ o->package = argv[i++];
271
+ continue;
272
+ }
273
+ if (eq(s, "-S") || eq(s, "-stringclass")) {
274
+ check_lim(i, argc);
275
+ o->string_class = argv[i++];
276
+ continue;
277
+ }
278
+ if (eq(s, "-a") || eq(s, "-amongclass")) {
279
+ check_lim(i, argc);
280
+ o->among_class = argv[i++];
281
+ continue;
282
+ }
283
+ #endif
284
+ #ifndef DISABLE_GO
285
+ if (eq(s, "-gop") || eq(s, "-gopackage")) {
286
+ check_lim(i, argc);
287
+ o->package = argv[i++];
288
+ continue;
289
+ }
290
+ if (eq(s, "-gor") || eq(s, "-goruntime")) {
291
+ check_lim(i, argc);
292
+ o->go_snowball_runtime = argv[i++];
293
+ continue;
294
+ }
295
+ #endif
296
+ if (eq(s, "--help")) {
297
+ print_arglist(0);
298
+ }
299
+
300
+ if (eq(s, "--version")) {
301
+ printf("Snowball compiler version " SNOWBALL_VERSION "\n");
302
+ exit(0);
303
+ }
304
+
305
+ fprintf(stderr, "'%s' misplaced\n", s);
306
+ print_arglist(1);
307
+ }
308
+ }
309
+ if (new_argc == 1) {
310
+ fprintf(stderr, "no source files specified\n");
311
+ print_arglist(1);
312
+ }
313
+ argv[new_argc] = NULL;
314
+
315
+ /* Set language-dependent defaults. */
316
+ switch (o->make_lang) {
317
+ case LANG_C:
318
+ case LANG_CPLUSPLUS:
319
+ encoding_opt = NULL;
320
+ break;
321
+ case LANG_CSHARP:
322
+ o->encoding = ENC_WIDECHARS;
323
+ if (!o->parent_class_name)
324
+ o->parent_class_name = DEFAULT_CS_BASE_CLASS;
325
+ if (!o->string_class)
326
+ o->string_class = DEFAULT_CS_STRING_CLASS;
327
+ if (!o->among_class)
328
+ o->among_class = DEFAULT_CS_AMONG_CLASS;
329
+ if (!o->package)
330
+ o->package = DEFAULT_CS_NAMESPACE;
331
+ break;
332
+ case LANG_GO:
333
+ o->encoding = ENC_UTF8;
334
+ if (!o->package)
335
+ o->package = DEFAULT_GO_PACKAGE;
336
+ break;
337
+ case LANG_ADA:
338
+ o->encoding = ENC_UTF8;
339
+ if (!o->package)
340
+ o->package = DEFAULT_ADA_PACKAGE;
341
+ break;
342
+ case LANG_JAVA:
343
+ o->encoding = ENC_WIDECHARS;
344
+ if (!o->parent_class_name)
345
+ o->parent_class_name = DEFAULT_JAVA_BASE_CLASS;
346
+ if (!o->string_class)
347
+ o->string_class = DEFAULT_JAVA_STRING_CLASS;
348
+ if (!o->among_class)
349
+ o->among_class = DEFAULT_JAVA_AMONG_CLASS;
350
+ if (!o->package)
351
+ o->package = DEFAULT_JAVA_PACKAGE;
352
+ break;
353
+ case LANG_JAVASCRIPT:
354
+ o->encoding = ENC_WIDECHARS;
355
+ if (!o->parent_class_name)
356
+ o->parent_class_name = DEFAULT_JS_BASE_CLASS;
357
+ break;
358
+ case LANG_PYTHON:
359
+ o->encoding = ENC_WIDECHARS;
360
+ if (!o->parent_class_name)
361
+ o->parent_class_name = DEFAULT_PYTHON_BASE_CLASS;
362
+ break;
363
+ case LANG_RUST:
364
+ o->encoding = ENC_UTF8;
365
+ break;
366
+ default:
367
+ break;
368
+ }
369
+
370
+ if (encoding_opt) {
371
+ fprintf(stderr, "warning: %s only meaningful for C and C++\n",
372
+ encoding_opt);
373
+ }
374
+
375
+ if (o->make_lang != LANG_C && o->make_lang != LANG_CPLUSPLUS) {
376
+ if (o->runtime_path) {
377
+ fprintf(stderr, "warning: -r/-runtime only meaningful for C and C++\n");
378
+ }
379
+ if (o->externals_prefix) {
380
+ fprintf(stderr, "warning: -ep/-eprefix only meaningful for C and C++\n");
381
+ }
382
+ }
383
+ if (!o->externals_prefix) o->externals_prefix = "";
384
+
385
+ if (!o->name && o->output_file) {
386
+ /* Default class name to basename of output_file - this is the standard
387
+ * convention for at least Java and C#.
388
+ */
389
+ const char * slash = strrchr(o->output_file, '/');
390
+ size_t len;
391
+ const char * leaf = (slash == NULL) ? o->output_file : slash + 1;
392
+
393
+ slash = strrchr(leaf, '\\');
394
+ if (slash != NULL) leaf = slash + 1;
395
+
396
+ {
397
+ const char * dot = strchr(leaf, '.');
398
+ len = (dot == NULL) ? strlen(leaf) : (size_t)(dot - leaf);
399
+ }
400
+
401
+ {
402
+ char * new_name = malloc(len + 1);
403
+ switch (o->make_lang) {
404
+ case LANG_CSHARP:
405
+ case LANG_PASCAL:
406
+ /* Upper case initial letter. */
407
+ memcpy(new_name, leaf, len);
408
+ new_name[0] = toupper(new_name[0]);
409
+ break;
410
+ case LANG_JAVASCRIPT:
411
+ case LANG_PYTHON: {
412
+ /* Upper case initial letter and change each
413
+ * underscore+letter or hyphen+letter to an upper case
414
+ * letter.
415
+ */
416
+ size_t i, j = 0;
417
+ int uc_next = true;
418
+ for (i = 0; i != len; ++i) {
419
+ unsigned char ch = leaf[i];
420
+ if (ch == '_' || ch == '-') {
421
+ uc_next = true;
422
+ } else {
423
+ if (uc_next) {
424
+ new_name[j] = toupper(ch);
425
+ uc_next = false;
426
+ } else {
427
+ new_name[j] = ch;
428
+ }
429
+ ++j;
430
+ }
431
+ }
432
+ len = j;
433
+ break;
434
+ }
435
+ default:
436
+ /* Just copy. */
437
+ memcpy(new_name, leaf, len);
438
+ break;
439
+ }
440
+ new_name[len] = '\0';
441
+ o->name = new_name;
442
+ }
443
+ }
444
+
445
+ return new_argc;
446
+ }
447
+
448
+ extern int main(int argc, char * argv[]) {
449
+
450
+ int i;
451
+ NEW(options, o);
452
+ argc = read_options(o, argc, argv);
453
+ {
454
+ char * file = argv[1];
455
+ symbol * u = get_input(file);
456
+ if (u == 0) {
457
+ fprintf(stderr, "Can't open input %s\n", file);
458
+ exit(1);
459
+ }
460
+ {
461
+ struct tokeniser * t = create_tokeniser(u, file);
462
+ struct analyser * a = create_analyser(t);
463
+ struct input ** next_input_ptr = &(t->next);
464
+ a->encoding = t->encoding = o->encoding;
465
+ t->includes = o->includes;
466
+ /* If multiple source files are specified, set up the others to be
467
+ * read after the first in order, using the same mechanism as
468
+ * 'get' uses. */
469
+ for (i = 2; i != argc; ++i) {
470
+ NEW(input, q);
471
+ file = argv[i];
472
+ u = get_input(file);
473
+ if (u == 0) {
474
+ fprintf(stderr, "Can't open input %s\n", file);
475
+ exit(1);
476
+ }
477
+ q->p = u;
478
+ q->c = 0;
479
+ q->file = file;
480
+ q->file_needs_freeing = false;
481
+ q->line_number = 1;
482
+ *next_input_ptr = q;
483
+ next_input_ptr = &(q->next);
484
+ }
485
+ *next_input_ptr = NULL;
486
+ read_program(a);
487
+ if (t->error_count > 0) exit(1);
488
+ if (o->syntax_tree) print_program(a);
489
+ close_tokeniser(t);
490
+ if (!o->syntax_tree) {
491
+ struct generator * g;
492
+
493
+ const char * s = o->output_file;
494
+ if (!s) {
495
+ fprintf(stderr, "Please include the -o option\n");
496
+ print_arglist(1);
497
+ }
498
+ g = create_generator(a, o);
499
+ if (o->make_lang == LANG_C || o->make_lang == LANG_CPLUSPLUS) {
500
+ symbol * b = add_s_to_b(0, s);
501
+ b = add_s_to_b(b, ".h");
502
+ o->output_h = get_output(b);
503
+ b[SIZE(b) - 1] = 'c';
504
+ if (o->make_lang == LANG_CPLUSPLUS) {
505
+ b = add_s_to_b(b, "c");
506
+ }
507
+ o->output_src = get_output(b);
508
+ lose_b(b);
509
+
510
+ generate_program_c(g);
511
+ fclose(o->output_src);
512
+ fclose(o->output_h);
513
+ }
514
+ #ifndef DISABLE_JAVA
515
+ if (o->make_lang == LANG_JAVA) {
516
+ symbol * b = add_s_to_b(0, s);
517
+ b = add_s_to_b(b, ".java");
518
+ o->output_src = get_output(b);
519
+ lose_b(b);
520
+ generate_program_java(g);
521
+ fclose(o->output_src);
522
+ }
523
+ #endif
524
+ #ifndef DISABLE_PASCAL
525
+ if (o->make_lang == LANG_PASCAL) {
526
+ symbol *b = add_s_to_b(0, s);
527
+ b = add_s_to_b(b, ".pas");
528
+ o->output_src = get_output(b);
529
+ lose_b(b);
530
+ generate_program_pascal(g);
531
+ fclose(o->output_src);
532
+ }
533
+ #endif
534
+ #ifndef DISABLE_PYTHON
535
+ if (o->make_lang == LANG_PYTHON) {
536
+ symbol * b = add_s_to_b(0, s);
537
+ b = add_s_to_b(b, ".py");
538
+ o->output_src = get_output(b);
539
+ lose_b(b);
540
+ generate_program_python(g);
541
+ fclose(o->output_src);
542
+ }
543
+ #endif
544
+ #ifndef DISABLE_JS
545
+ if (o->make_lang == LANG_JAVASCRIPT) {
546
+ symbol * b = add_s_to_b(0, s);
547
+ b = add_s_to_b(b, ".js");
548
+ o->output_src = get_output(b);
549
+ lose_b(b);
550
+ generate_program_js(g);
551
+ fclose(o->output_src);
552
+ }
553
+ #endif
554
+ #ifndef DISABLE_CSHARP
555
+ if (o->make_lang == LANG_CSHARP) {
556
+ symbol * b = add_s_to_b(0, s);
557
+ b = add_s_to_b(b, ".cs");
558
+ o->output_src = get_output(b);
559
+ lose_b(b);
560
+ generate_program_csharp(g);
561
+ fclose(o->output_src);
562
+ }
563
+ #endif
564
+ #ifndef DISABLE_RUST
565
+ if (o->make_lang == LANG_RUST) {
566
+ symbol * b = add_s_to_b(0, s);
567
+ b = add_s_to_b(b, ".rs");
568
+ o->output_src = get_output(b);
569
+ lose_b(b);
570
+ generate_program_rust(g);
571
+ fclose(o->output_src);
572
+ }
573
+ #endif
574
+ #ifndef DISABLE_GO
575
+ if (o->make_lang == LANG_GO) {
576
+ symbol * b = add_s_to_b(0, s);
577
+ b = add_s_to_b(b, ".go");
578
+ o->output_src = get_output(b);
579
+ lose_b(b);
580
+ generate_program_go(g);
581
+ fclose(o->output_src);
582
+ }
583
+ #endif
584
+ #ifndef DISABLE_ADA
585
+ if (o->make_lang == LANG_ADA) {
586
+ symbol * b = add_s_to_b(0, s);
587
+ b = add_s_to_b(b, ".ads");
588
+ o->output_h = get_output(b);
589
+ b[SIZE(b) - 1] = 'b';
590
+ o->output_src = get_output(b);
591
+ lose_b(b);
592
+
593
+ generate_program_ada(g);
594
+ fclose(o->output_src);
595
+ fclose(o->output_h);
596
+
597
+ }
598
+ #endif
599
+ close_generator(g);
600
+ }
601
+ close_analyser(a);
602
+ }
603
+ lose_b(u);
604
+ }
605
+ { struct include * p = o->includes;
606
+ while (p) {
607
+ struct include * q = p->next;
608
+ lose_b(p->b); FREE(p); p = q;
609
+ }
610
+ }
611
+ FREE(o->name);
612
+ FREE(o);
613
+ if (space_count) fprintf(stderr, "%d blocks unfreed\n", space_count);
614
+ return 0;
615
+ }