nabaztag_hack_kit 0.1.0.beta3 → 0.1.0.beta8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -2
  3. data/.gitmodules +3 -0
  4. data/.travis.yml +2 -2
  5. data/CHANGELOG.md +17 -2
  6. data/LICENSE +21 -0
  7. data/README.md +115 -44
  8. data/Rakefile +2 -6
  9. data/bytecode/{Commands.md → _docs/commands.md} +0 -0
  10. data/bytecode/{Docs.md → _docs/grammar.md} +0 -0
  11. data/bytecode/_docs/grammar.pdf +0 -0
  12. data/bytecode/{src → _original}/README.md +0 -0
  13. data/bytecode/{src → _original}/lib/arp.mtl +0 -0
  14. data/bytecode/{src → _original}/lib/cfg.mtl +0 -0
  15. data/bytecode/{src → _original}/lib/choreos.mtl +0 -0
  16. data/bytecode/{src → _original}/lib/dhcp.mtl +0 -0
  17. data/bytecode/{src → _original}/lib/dns.mtl +0 -0
  18. data/bytecode/{src → _original}/lib/http.mtl +0 -0
  19. data/bytecode/{src → _original}/lib/tcp.mtl +0 -0
  20. data/bytecode/{src → _original}/lib/udp.mtl +0 -0
  21. data/bytecode/{src → _original}/lib/util.mtl +0 -0
  22. data/bytecode/{src → _original}/lib/var.mtl +0 -0
  23. data/bytecode/{src → _original}/lib/wav.mtl +0 -0
  24. data/bytecode/{src → _original}/lib/wifi.mtl +0 -0
  25. data/bytecode/{src → _original}/nominal-ping.mtl +0 -0
  26. data/bytecode/main.mtl +11 -11
  27. data/bytecode/test/test.mtl +8 -8
  28. data/examples/basic/Gemfile +1 -3
  29. data/examples/basic/config.ru +14 -4
  30. data/examples/record/Gemfile +0 -5
  31. data/examples/record/{config.ru.example → config.ru} +2 -2
  32. data/examples/record/server.rb +0 -2
  33. data/ext/Makefile +10 -0
  34. data/ext/bin/mtl_comp +29 -0
  35. data/{bytecode → ext}/bin/mtl_merge +0 -0
  36. data/ext/bin/mtl_simu +29 -0
  37. data/{bytecode/src/mtl → ext}/extconf.rb +0 -0
  38. data/ext/mtl_linux/.gitignore +7 -0
  39. data/ext/mtl_linux/LICENSE +21 -0
  40. data/ext/mtl_linux/Makefile +116 -0
  41. data/ext/mtl_linux/MetalC.project +196 -0
  42. data/ext/mtl_linux/conf.bin +0 -0
  43. data/{bytecode/src/mtl → ext/mtl_linux}/conf.bin.sans_password +0 -0
  44. data/{bytecode/src/mtl → ext/mtl_linux}/config.txt +0 -0
  45. data/ext/mtl_linux/inc/log.h +21 -0
  46. data/{bytecode/src/mtl → ext/mtl_linux/inc}/properties.h +0 -0
  47. data/{bytecode/src/mtl/linux_simuaudio.h → ext/mtl_linux/inc/simu/linux/simuaudio.h} +0 -0
  48. data/{bytecode/src/mtl/linux_simunet.h → ext/mtl_linux/inc/simu/linux/simunet.h} +0 -0
  49. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simuaudio.h +18 -18
  50. data/{bytecode/src/mtl → ext/mtl_linux/inc/simu/win}/simunet.h +0 -0
  51. data/ext/mtl_linux/inc/vcomp/compiler.h +200 -0
  52. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/file.h +11 -11
  53. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/filesystem.h +0 -0
  54. data/ext/mtl_linux/inc/vcomp/interpreter.h +121 -0
  55. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/memory.h +120 -92
  56. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/param.h +0 -0
  57. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/parser.h +27 -27
  58. data/ext/mtl_linux/inc/vcomp/prodbuffer.h +42 -0
  59. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/resource.h +1 -1
  60. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/terminal.h +8 -8
  61. data/{bytecode/src/mtl → ext/mtl_linux/inc}/vcomp/util.h +7 -7
  62. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vaudio.h +0 -0
  63. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vbc.h +1 -1
  64. data/ext/mtl_linux/inc/vm/vbc_str.h +167 -0
  65. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vinterp.h +0 -0
  66. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vloader.h +0 -0
  67. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vlog.h +0 -0
  68. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vmem.h +0 -0
  69. data/{bytecode/src/mtl → ext/mtl_linux/inc/vm}/vnet.h +0 -0
  70. data/ext/mtl_linux/nominal.mtl +3959 -0
  71. data/ext/mtl_linux/src/comp/main.cpp +123 -0
  72. data/ext/mtl_linux/src/simu/dumpbc.c +2566 -0
  73. data/ext/mtl_linux/src/simu/linux/main.cpp +288 -0
  74. data/ext/mtl_linux/src/simu/linux/simu.c +309 -0
  75. data/ext/mtl_linux/src/simu/linux/simuaudio.c +44 -0
  76. data/ext/mtl_linux/src/simu/linux/simunet.c +707 -0
  77. data/ext/mtl_linux/src/simu/log.c +340 -0
  78. data/ext/mtl_linux/src/simu/properties.c +368 -0
  79. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/GTKANAL.H +0 -0
  80. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/LAYER3.C +0 -0
  81. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/TABINIT.C +0 -0
  82. data/ext/mtl_linux/src/simu/win/mp3/common.c +302 -0
  83. data/ext/mtl_linux/src/simu/win/mp3/dct64_i386.c +316 -0
  84. data/ext/mtl_linux/src/simu/win/mp3/decode_i386.c +160 -0
  85. data/ext/mtl_linux/src/simu/win/mp3/huffman.h +332 -0
  86. data/ext/mtl_linux/src/simu/win/mp3/interface.c +276 -0
  87. data/{bytecode/src/mtl → ext/mtl_linux/src/simu/win}/mp3/mpg123.h +34 -30
  88. data/ext/mtl_linux/src/simu/win/mp3/mpglib.h +47 -0
  89. data/ext/mtl_linux/src/simu/win/simu.c +819 -0
  90. data/ext/mtl_linux/src/simu/win/simuaudio.c +787 -0
  91. data/ext/mtl_linux/src/simu/win/simunet.c +489 -0
  92. data/ext/mtl_linux/src/vcomp/bootstrap.cpp +95 -0
  93. data/ext/mtl_linux/src/vcomp/compiler.cpp +587 -0
  94. data/ext/mtl_linux/src/vcomp/compiler_file.cpp +1253 -0
  95. data/ext/mtl_linux/src/vcomp/compiler_prog.cpp +437 -0
  96. data/ext/mtl_linux/src/vcomp/compiler_term.cpp +1500 -0
  97. data/ext/mtl_linux/src/vcomp/compiler_type.cpp +1238 -0
  98. data/ext/mtl_linux/src/vcomp/compiler_var.cpp +502 -0
  99. data/ext/mtl_linux/src/vcomp/file.cpp +100 -0
  100. data/ext/mtl_linux/src/vcomp/interpreter.cpp +93 -0
  101. data/ext/mtl_linux/src/vcomp/memory.cpp +313 -0
  102. data/ext/mtl_linux/src/vcomp/parser.cpp +584 -0
  103. data/ext/mtl_linux/src/vcomp/parser_xml.cpp +137 -0
  104. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/prodbuffer.cpp +57 -36
  105. data/ext/mtl_linux/src/vcomp/stdlib_core.cpp +130 -0
  106. data/ext/mtl_linux/src/vcomp/terminal.cpp +80 -0
  107. data/{bytecode/src/mtl → ext/mtl_linux/src}/vcomp/util.cpp +18 -11
  108. data/ext/mtl_linux/src/vm/vaudio.c +830 -0
  109. data/ext/mtl_linux/src/vm/vinterp.c +1780 -0
  110. data/ext/mtl_linux/src/vm/vloader.c +139 -0
  111. data/ext/mtl_linux/src/vm/vlog.c +782 -0
  112. data/ext/mtl_linux/src/vm/vmem.c +461 -0
  113. data/ext/mtl_linux/src/vm/vnet.c +298 -0
  114. data/{bytecode/src/mtl → ext/mtl_linux}/utils/correct_const.sh +0 -0
  115. data/lib/nabaztag_hack_kit/server.rb +4 -7
  116. data/lib/nabaztag_hack_kit/version.rb +1 -1
  117. data/lib/nabaztag_hack_kit.rb +2 -2
  118. data/nabaztag_hack_kit.gemspec +10 -11
  119. data/spec/integration/server_spec.rb +3 -3
  120. data/spec/spec_helper.rb +2 -0
  121. data/spec/unit/message_spec.rb +12 -18
  122. data/spec/unit/server_spec.rb +13 -10
  123. metadata +145 -137
  124. data/bytecode/bin/mtl_comp +0 -50
  125. data/bytecode/bin/mtl_simu +0 -49
  126. data/bytecode/src/mtl/Makefile +0 -42
  127. data/bytecode/src/mtl/README.md +0 -13
  128. data/bytecode/src/mtl/bc.cpp +0 -1891
  129. data/bytecode/src/mtl/dumpbc.c +0 -2566
  130. data/bytecode/src/mtl/linux_simu.c +0 -271
  131. data/bytecode/src/mtl/linux_simuaudio.c +0 -16
  132. data/bytecode/src/mtl/linux_simunet.c +0 -620
  133. data/bytecode/src/mtl/log.c +0 -297
  134. data/bytecode/src/mtl/log.h +0 -20
  135. data/bytecode/src/mtl/main_compiler.cpp +0 -104
  136. data/bytecode/src/mtl/main_simu.cpp +0 -221
  137. data/bytecode/src/mtl/mp3/common.c +0 -265
  138. data/bytecode/src/mtl/mp3/dct64_i386.c +0 -316
  139. data/bytecode/src/mtl/mp3/decode_i386.c +0 -155
  140. data/bytecode/src/mtl/mp3/huffman.h +0 -332
  141. data/bytecode/src/mtl/mp3/interface.c +0 -258
  142. data/bytecode/src/mtl/mp3/mpglib.h +0 -44
  143. data/bytecode/src/mtl/properties.c +0 -293
  144. data/bytecode/src/mtl/simu.c +0 -750
  145. data/bytecode/src/mtl/simuaudio.c +0 -662
  146. data/bytecode/src/mtl/simunet.c +0 -400
  147. data/bytecode/src/mtl/vaudio.c +0 -677
  148. data/bytecode/src/mtl/vbc_str.h +0 -166
  149. data/bytecode/src/mtl/vcomp/Makefile +0 -29
  150. data/bytecode/src/mtl/vcomp/bootstrap.cpp +0 -89
  151. data/bytecode/src/mtl/vcomp/compiler.cpp +0 -470
  152. data/bytecode/src/mtl/vcomp/compiler.h +0 -200
  153. data/bytecode/src/mtl/vcomp/compiler_file.cpp +0 -929
  154. data/bytecode/src/mtl/vcomp/compiler_prog.cpp +0 -250
  155. data/bytecode/src/mtl/vcomp/compiler_term.cpp +0 -1053
  156. data/bytecode/src/mtl/vcomp/compiler_type.cpp +0 -872
  157. data/bytecode/src/mtl/vcomp/compiler_var.cpp +0 -289
  158. data/bytecode/src/mtl/vcomp/file.cpp +0 -79
  159. data/bytecode/src/mtl/vcomp/interpreter.cpp +0 -85
  160. data/bytecode/src/mtl/vcomp/interpreter.h +0 -121
  161. data/bytecode/src/mtl/vcomp/memory.cpp +0 -241
  162. data/bytecode/src/mtl/vcomp/parser.cpp +0 -427
  163. data/bytecode/src/mtl/vcomp/parser_xml.cpp +0 -124
  164. data/bytecode/src/mtl/vcomp/prodbuffer.h +0 -42
  165. data/bytecode/src/mtl/vcomp/stdlib_core.cpp +0 -122
  166. data/bytecode/src/mtl/vcomp/terminal.cpp +0 -73
  167. data/bytecode/src/mtl/vinterp.c +0 -1349
  168. data/bytecode/src/mtl/vloader.c +0 -127
  169. data/bytecode/src/mtl/vlog.c +0 -589
  170. data/bytecode/src/mtl/vmem.c +0 -424
  171. data/bytecode/src/mtl/vnet.c +0 -255
  172. data/examples/basic/Procfile +0 -2
  173. data/examples/basic/server.rb +0 -14
@@ -0,0 +1,584 @@
1
+ //-------------------
2
+ // Moteur 3d
3
+ // version WIN32 et POCKETPC
4
+ // Sylvain Huet
5
+ // Premiere version : 03/09/2002
6
+ // Derniere mise a jour : 05/10/2002
7
+ //
8
+
9
+
10
+
11
+ #include <stdio.h>
12
+ #include <string.h>
13
+ #include <stdint.h>
14
+
15
+ #include "param.h"
16
+ #include "filesystem.h"
17
+ #include "file.h"
18
+ #include "parser.h"
19
+ #include "terminal.h"
20
+ #include "memory.h"
21
+
22
+ // test de lettre
23
+ int isletter(int c)
24
+ {
25
+ if ((c>='A')&&(c<='Z'))
26
+ {
27
+ return 1;
28
+ }
29
+ if ((c>='a')&&(c<='z'))
30
+ {
31
+ return 1;
32
+ }
33
+ if (c=='_')
34
+ {
35
+ return 1;
36
+ }
37
+ return 0;
38
+ }
39
+ // test de chiffre decimal
40
+ int isnum(int c)
41
+ {
42
+ if ((c>='0')&&(c<='9'))
43
+ {
44
+ return 1;
45
+ }
46
+ return 0;
47
+ }
48
+ // test de lettre
49
+ int ishex(int c)
50
+ {
51
+ if ((c>='0')&&(c<='9'))
52
+ {
53
+ return 1;
54
+ }
55
+ if ((c>='A')&&(c<='F'))
56
+ {
57
+ return 1;
58
+ }
59
+ if ((c>='a')&&(c<='f'))
60
+ {
61
+ return 1;
62
+ }
63
+ return 0;
64
+ }
65
+
66
+ // test de lettre ou de chiffre
67
+ int isletnum(int c)
68
+ {
69
+ if ((c>='A')&&(c<='Z'))
70
+ {
71
+ return 1;
72
+ }
73
+ if ((c>='a')&&(c<='z'))
74
+ {
75
+ return 1;
76
+ }
77
+ if ((c>='0')&&(c<='9'))
78
+ {
79
+ return 1;
80
+ }
81
+ if (c=='_')
82
+ {
83
+ return 1;
84
+ }
85
+ return 0;
86
+ }
87
+
88
+ // test si un mot est un label (une lettre puis des lettres ou des chiffres)
89
+ int islabel(char* src)
90
+ {
91
+ if (!isletter(*src++))
92
+ {
93
+ return 0;
94
+ }
95
+ while(*src)
96
+ {
97
+ if (!isletnum(*src++))
98
+ {
99
+ return 0;
100
+ }
101
+ }
102
+ return 1;
103
+ }
104
+
105
+ // test si un mot est un nombre d�cimal (que des chiffres)
106
+ int isdecimal(char* src)
107
+ {
108
+ while(*src)
109
+ {
110
+ if (!isnum(*src++))
111
+ {
112
+ return 0;
113
+ }
114
+ }
115
+ return 1;
116
+ }
117
+
118
+ // test si un mot est un nombre hexad�cimal (que des chiffres)
119
+ int ishexadecimal(char* src)
120
+ {
121
+ while(*src)
122
+ {
123
+ if (!ishex(*src++))
124
+ {
125
+ return 0;
126
+ }
127
+ }
128
+ return 1;
129
+ }
130
+
131
+ // test si un mot est un nombre flottant (que des chiffres avec un point)
132
+ int isfloat(char* src)
133
+ {
134
+ int debut=1;
135
+ int point=0;
136
+ while(*src)
137
+ {
138
+ if ((*src=='.')&&(!debut)&&(!point))
139
+ {
140
+ point=1;
141
+ }
142
+ else if (!isnum(*src))
143
+ {
144
+ return 0;
145
+ }
146
+ src++;
147
+ debut=0;
148
+ }
149
+ return point;
150
+ }
151
+
152
+ // retourne le code ascii correspondant � un chiffre hexad�cimal
153
+ int ctoh(int c)
154
+ {
155
+ c&=15;
156
+ if (c<10)
157
+ {
158
+ return '0'+c;
159
+ }
160
+ return 'a'+c-10;
161
+ }
162
+
163
+ // retourne le chiffre correspondant � un code ascii hexad�cimal
164
+ int htoc(int c)
165
+ {
166
+ if ((c>='0')&&(c<='9'))
167
+ {
168
+ return c-'0';
169
+ }
170
+ else if ((c>='A')&&(c<='F'))
171
+ {
172
+ return c-'A'+10;
173
+ }
174
+ else if ((c>='a')&&(c<='f'))
175
+ {
176
+ return c-'a'+10;
177
+ }
178
+ return 0;
179
+ }
180
+
181
+ // lecture d'une cha�ne d�cimale (s'arr�te au premier caract�re incorrect)
182
+ int mtl_atoi(char* src)
183
+ {
184
+ int x,c,s;
185
+ x=s=0;
186
+ if ((*src)=='-')
187
+ {
188
+ s=1;
189
+ src++;
190
+ }
191
+ while(c=*src++)
192
+ {
193
+ if ((c>='0')&&(c<='9'))
194
+ {
195
+ x=(x*10)+c-'0';
196
+ }
197
+ else
198
+ {
199
+ return (s?(-x):x);
200
+ }
201
+ }
202
+ return (s?(-x):x);
203
+ }
204
+
205
+ // lecture d'une cha�ne hexad�cimale (s'arr�te au premier caract�re incorrect)
206
+ int mtl_htoi(char* src)
207
+ {
208
+ int x,c;
209
+ x=0;
210
+ while(c=*src++)
211
+ {
212
+ if ((c>='0')&&(c<='9'))
213
+ {
214
+ x=(x<<4)+c-'0';
215
+ }
216
+ else if ((c>='A')&&(c<='F'))
217
+ {
218
+ x=(x<<4)+c-'A'+10;
219
+ }
220
+ else if ((c>='a')&&(c<='f'))
221
+ {
222
+ x=(x<<4)+c-'a'+10;
223
+ }
224
+ else
225
+ {
226
+ return x;
227
+ }
228
+ }
229
+ return x;
230
+ }
231
+
232
+ // lecture d'une cha�ne flottante (s'arr�te au premier caract�re incorrect)
233
+ mtl_float mtl_atof(char* src)
234
+ {
235
+ int c;
236
+ mtl_float f=0;
237
+ mtl_float div=1;
238
+ int point=0;
239
+ while(c=*src++)
240
+ {
241
+ if ((c=='.')&&(!point))
242
+ {
243
+ point=1;
244
+ }
245
+ else if ((c>='0')&&(c<='9'))
246
+ {
247
+ f=(f*10)+c-'0';
248
+ if (point)
249
+ {
250
+ div*=10;
251
+ }
252
+ }
253
+ else
254
+ {
255
+ return f/div;
256
+ }
257
+ }
258
+ return f/div;
259
+ }
260
+
261
+ Parser::Parser(Terminal* t,FileSystem* fs,char *filename)
262
+ {
263
+ term=t;
264
+
265
+ srcname=new char[strlen(filename)+1];
266
+ strcpy(srcname,filename);
267
+
268
+ File* file=new File(fs);
269
+ int size;
270
+
271
+ src=NULL;
272
+ if (!file->openread(filename))
273
+ {
274
+ src=file->getcontent(&size);
275
+ }
276
+ delete file;
277
+ if (!src)
278
+ {
279
+ t->printf(LOG_WARNING,"Parser : cannot open file %s\n",filename);
280
+ src=new char[1];
281
+ src[0]=0;
282
+ }
283
+ index=0;
284
+
285
+ indexsavedchar=-1;
286
+
287
+ again=0;
288
+
289
+ lign=offligne=0;
290
+ lign0=offligne0=offchar0=0;
291
+
292
+ token=NULL;
293
+ }
294
+
295
+ Parser::Parser(Terminal* t,const char *buf)
296
+ {
297
+ srcname=NULL;
298
+ term=t;
299
+ src=new char[strlen(buf)+1];
300
+ strcpy(src,buf);
301
+ index=0;
302
+
303
+ indexsavedchar=-1;
304
+
305
+ again=0;
306
+
307
+ lign=offligne=0;
308
+ lign0=offligne0=offchar0=0;
309
+
310
+ token=NULL;
311
+ }
312
+
313
+
314
+ Parser::~Parser()
315
+ {
316
+ delete src;
317
+ if (srcname)
318
+ {
319
+ delete srcname;
320
+ }
321
+ }
322
+
323
+ void Parser::giveback()
324
+ {
325
+ again=1;
326
+ }
327
+
328
+ char* Parser::next(int filter)
329
+ {
330
+ if (again)
331
+ {
332
+ again=0;
333
+ return token;
334
+ }
335
+
336
+ int i;
337
+ while(1)
338
+ {
339
+ int k;
340
+ do
341
+ {
342
+ k=gettoken(filter);
343
+ }
344
+ while (k==-2);
345
+ if (k)
346
+ {
347
+ token=NULL;
348
+ return NULL;
349
+ }
350
+ //~ term->printf(0,"token=%s\n",token);
351
+ //~ asm volatile ("int3;");
352
+ if (strcmp(token,"/*"))
353
+ {
354
+ return token; // ok
355
+ }
356
+ i=1; // gestion des commentaires
357
+ while(i)
358
+ {
359
+ if (gettoken(filter)==-1)
360
+ {
361
+ term->printf(LOG_COMPILER,"unbalanced comment reaches EOF\n");
362
+ token=NULL;
363
+ return NULL;
364
+ }
365
+ if (!strcmp(token,"/*"))
366
+ {
367
+ i++;
368
+ }
369
+ if (!strcmp(token,"*/"))
370
+ {
371
+ i--;
372
+ }
373
+ }
374
+ }
375
+ }
376
+
377
+ void Parser::savechar(int i)
378
+ {
379
+ indexsavedchar=i;
380
+ savedchar=src[i];
381
+ src[i]=0;
382
+ }
383
+
384
+ // demande de relire le dernier caract�re
385
+ void Parser::againchar()
386
+ {
387
+ index--;
388
+ if (src[index]==10)
389
+ {
390
+ lign--;
391
+ }
392
+ }
393
+
394
+ // lit le prochain caract�re
395
+ int Parser::nextchar()
396
+ {
397
+ int c;
398
+
399
+ c=src[index];
400
+ if (c)
401
+ {
402
+ index++;
403
+ if (c==10)
404
+ {
405
+ offligne=index;
406
+ lign++;
407
+ }
408
+ }
409
+ return c;
410
+ }
411
+
412
+
413
+ void Parser::restorechar()
414
+ {
415
+ // on restaure le caract�re escamot� � la fin du token pr�c�dent
416
+ if (indexsavedchar!=-1)
417
+ {
418
+ src[indexsavedchar]=savedchar;
419
+ indexsavedchar=-1;
420
+ }
421
+ }
422
+
423
+ int Parser::gettoken(int filter)
424
+ {
425
+ int c,d,f;
426
+
427
+ restorechar();
428
+
429
+ do
430
+ {
431
+ // recherche le d�but du token
432
+ // on sauvegarde la position dans le source
433
+ lign0=lign;
434
+ offligne0=offligne;
435
+ offchar0=index;
436
+ c=nextchar();
437
+ if (!c)
438
+ {
439
+ return -1; // fin du fichier, pas de nouveau token
440
+ }
441
+ }
442
+ while(c<=32);
443
+
444
+ token=&src[offchar0];
445
+
446
+ f=0;
447
+ if (c=='\"') // token cha�ne de caract�res
448
+ while(1)
449
+ {
450
+ c=nextchar();
451
+ if (!c)
452
+ {
453
+ term->printf(LOG_COMPILER,"uncomplete string reaches EOF\n");
454
+ return -1;
455
+ }
456
+ if ((c=='\"')&&(f==0))
457
+ {
458
+ savechar(index);
459
+ return 0;
460
+ }
461
+ if (c=='\\')
462
+ {
463
+ f=1-f;
464
+ }
465
+ else
466
+ {
467
+ f=0;
468
+ }
469
+ }
470
+ if (isletnum(c)) // token nombre ou label
471
+ {
472
+ int onlynum=1;
473
+ while(1)
474
+ {
475
+ if (!isnum(c))
476
+ {
477
+ onlynum=0;
478
+ }
479
+ c=nextchar();
480
+ if (!c)
481
+ {
482
+ return 0;
483
+ }
484
+ if ((c=='.')&&(onlynum)) // nombre flottant
485
+ {
486
+ while(1)
487
+ {
488
+ c=nextchar();
489
+ if (!c)
490
+ {
491
+ return 0;
492
+ }
493
+ if (!isnum(c))
494
+ {
495
+ againchar();
496
+ savechar(index);
497
+ return 0;
498
+ }
499
+ }
500
+ }
501
+ if (!isletnum(c))
502
+ {
503
+ againchar();
504
+ savechar(index);
505
+ return 0;
506
+ }
507
+ }
508
+ }
509
+ d=nextchar();
510
+ if (!d)
511
+ {
512
+ return 0; // fin du fichier sur un caract�re sp�cial
513
+ }
514
+
515
+ if ( ((c=='&')&&(d=='&'))
516
+ ||((c=='|')&&(d=='|'))
517
+ ||((c==':')&&(d==':'))
518
+ ||((c=='^')&&(d=='^'))
519
+ ||((c==';')&&(d==';'))
520
+ ||((c=='-')&&(d=='>'))
521
+ ||((c=='<')&&((d=='<')||(d=='/')))
522
+ ||((c=='>')&&(d=='>'))
523
+ ||((c=='=')&&(d=='='))
524
+ ||((c=='/')&&((d=='*')||(d=='>')))
525
+ ||((c=='*')&&(d=='/'))
526
+ )
527
+ {
528
+ // caract�re double reconnu
529
+ }
530
+ else if ((c=='/')&&(d=='/'))
531
+ {
532
+ do // cas du commentaire //
533
+ {
534
+ c=nextchar();
535
+ if (c==10)
536
+ {
537
+ return -2;
538
+ }
539
+ }
540
+ while (c);
541
+ return -1; // fin de fichier, pas de nouveau token
542
+ }
543
+ else if (((c=='!')||(c=='>')||(c=='<'))&&(d=='='))
544
+ {
545
+ /* d=nextchar();
546
+ if (!d) return 0; // fin du fichier sur un caract�re sp�cial compos�
547
+ if (d!='.') againchar();
548
+ */
549
+ }
550
+ else
551
+ {
552
+ againchar();
553
+ }
554
+ savechar(index);
555
+ return 0;
556
+ }
557
+
558
+
559
+ void Parser::echoposition()
560
+ {
561
+ restorechar();
562
+ if (srcname)
563
+ {
564
+ term->printf(LOG_COMPILER,">line %d in '%s' :\n>",lign0+1,srcname);
565
+ }
566
+ else
567
+ {
568
+ term->printf(LOG_COMPILER,">line %d :\n>",lign0+1);
569
+ }
570
+ char* p=&src[offligne0];
571
+ int i=0;
572
+ while((p[i])&&(p[i]!='\n'))
573
+ {
574
+ i++;
575
+ }
576
+ term->echo(LOG_COMPILER,p,i);
577
+ term->printf(LOG_COMPILER,"\n>");
578
+ for(i=0; i<offchar0-offligne0; i++)
579
+ {
580
+ term->printf(LOG_COMPILER, "%c", (p[i]!='\t') ? ' ' : '\t');
581
+ }
582
+ term->printf(LOG_COMPILER,"^\n");
583
+ }
584
+
@@ -0,0 +1,137 @@
1
+ //-------------------
2
+ // MV
3
+ // version WIN32 et POCKETPC
4
+ // Sylvain Huet
5
+ // Premiere version : 07/01/2003
6
+ // Derniere mise a jour : 07/01/2003
7
+ //
8
+
9
+ #include <stdio.h>
10
+ #include <string.h>
11
+ #include <stdint.h>
12
+
13
+ #include "param.h"
14
+ #include "filesystem.h"
15
+ #include "file.h"
16
+ #include "parser.h"
17
+ #include "terminal.h"
18
+ #include "memory.h"
19
+ #include "util.h"
20
+ #include "interpreter.h"
21
+ #include "prodbuffer.h"
22
+
23
+ // lit un keyword impos�
24
+ int Parser::parsekeyword(const char* keyword)
25
+ {
26
+ if (!next(0))
27
+ {
28
+ term->printf(LOG_COMPILER,"Parser : '%s' expected (found EOF)\n");
29
+ return MTLERR_SN;
30
+ }
31
+ if (strcmp(token,keyword))
32
+ {
33
+ term->printf(LOG_COMPILER,"Parser : '%s' expected (found '%s')\n",keyword,token);
34
+ return MTLERR_SN;
35
+ }
36
+ return 0;
37
+ }
38
+
39
+ // lit un keyword impos�
40
+ int Parser::parsekeyword(const char* keyword,int filter)
41
+ {
42
+ if (!next(filter))
43
+ {
44
+ term->printf(LOG_COMPILER,"Parser : '%s' expected (found EOF)\n");
45
+ return MTLERR_SN;
46
+ }
47
+ if (strcmp(token,keyword))
48
+ {
49
+ term->printf(LOG_COMPILER,"Parser : '%s' expected (found '%s')\n",keyword,token);
50
+ return MTLERR_SN;
51
+ }
52
+ return 0;
53
+ }
54
+
55
+
56
+ // parsing d'une cha�ne de caract�res
57
+ int Parser::getstring(Memory* m,char separator)
58
+ {
59
+ int c,n,i;
60
+
61
+ char* name=token;
62
+ name++;
63
+
64
+ Prodbuffer* output=m->util->interpreter->output;
65
+ output->reinit();
66
+
67
+ n=0;
68
+ while(1)
69
+ {
70
+ c=*(name++);
71
+ if (c=='\\')
72
+ {
73
+ c=(*(name++))&255;
74
+ if (c<32)
75
+ {
76
+ while(((*name)&255)<32)
77
+ {
78
+ name++;
79
+ }
80
+ }
81
+ else
82
+ {
83
+ if (c=='n')
84
+ {
85
+ c=10;
86
+ }
87
+ else if (c=='z')
88
+ {
89
+ c=0;
90
+ }
91
+ else if (c=='$')
92
+ {
93
+ i=0;
94
+ c=*name;
95
+ if (ishex(c))
96
+ {
97
+ name++;
98
+ i=htoc(c);
99
+ c=*name;
100
+ if (ishex(c))
101
+ {
102
+ name++;
103
+ i=(i<<4)+htoc(c);
104
+ }
105
+ }
106
+ c=i;
107
+ }
108
+ else if ((c>='0')&&(c<='9'))
109
+ {
110
+ i=c-'0';
111
+ c=*name;
112
+ if ((c>='0')&&(c<='9'))
113
+ {
114
+ name++;
115
+ i=(i*10)+c-'0';
116
+ c=*name;
117
+ if ((c>='0')&&(c<='9'))
118
+ {
119
+ name++;
120
+ i=(i*10)+c-'0';
121
+ }
122
+ }
123
+ c=i;
124
+ }
125
+ output->addchar(c);
126
+ }
127
+ }
128
+ else if (c==separator)
129
+ {
130
+ return STRPUSHBINARY(m,output->getstart(),output->getsize());
131
+ }
132
+ else
133
+ {
134
+ output->addchar(c);
135
+ }
136
+ }
137
+ }