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,489 @@
1
+ // Librairie Sound
2
+
3
+ #include<windows.h>
4
+ #include<winsock.h>
5
+ #include<stdio.h>
6
+ #include"simunet.h"
7
+ #include"vmem.h"
8
+ #include"vloader.h"
9
+ #include"vinterp.h"
10
+
11
+ extern HWND mainwin;
12
+
13
+ #define TCPMAX 128
14
+ #define UDPMAX 128
15
+
16
+ #define SOCKETWOULDBLOCK (WSAGetLastError()==WSAEWOULDBLOCK)
17
+
18
+ SOCKET tcp_sock[TCPMAX]; // =INVALID_SOCKET -> disponible
19
+ int tcp_enable[TCPMAX];
20
+ SOCKET udp_sock[UDPMAX];
21
+ int udp_port[UDPMAX]; // port=0 -> disponible
22
+
23
+ int inet_addr_bin(char *ip)
24
+ {
25
+ return *(int*)ip;
26
+ }
27
+
28
+ int simunetinit()
29
+ {
30
+ int i;
31
+ WORD wVersionRequested;
32
+ WSADATA wsaData;
33
+
34
+ wVersionRequested = MAKEWORD( 1, 1 );
35
+ if (WSAStartup( wVersionRequested, &wsaData ))
36
+ {
37
+ return -1;
38
+ }
39
+ for(i=0; i<TCPMAX; i++)
40
+ {
41
+ tcp_sock[i]=INVALID_SOCKET;
42
+ }
43
+ for(i=0; i<UDPMAX; i++)
44
+ {
45
+ udp_port[i]=0;
46
+ }
47
+ return 0;
48
+ }
49
+
50
+ int tcpgetfree()
51
+ {
52
+ int i;
53
+ for(i=0; i<TCPMAX; i++) if (tcp_sock[i]==INVALID_SOCKET)
54
+ {
55
+ tcp_enable[i]=1;
56
+ return i;
57
+ }
58
+ return -1;
59
+ }
60
+ int tcpbysock(SOCKET s)
61
+ {
62
+ int i;
63
+ for(i=0; i<TCPMAX; i++) if (tcp_sock[i]==s)
64
+ {
65
+ return i;
66
+ }
67
+ return -1;
68
+ }
69
+ int tcpservercreate(int port)
70
+ {
71
+ int opt=1;
72
+ SOCKADDR_IN ina;
73
+ SOCKET socksrv;
74
+ int i=tcpgetfree();
75
+ if (i<0)
76
+ {
77
+ return i;
78
+ }
79
+
80
+ socksrv=socket(PF_INET,SOCK_STREAM,0);
81
+ if (socksrv==INVALID_SOCKET)
82
+ {
83
+ return -1;
84
+ }
85
+ setsockopt (socksrv, SOL_SOCKET, SO_REUSEADDR,(char*) &opt, sizeof (opt));
86
+ if (WSAAsyncSelect(socksrv,mainwin,TCPEVENT,(FD_ACCEPT))==SOCKET_ERROR)
87
+ {
88
+ closesocket(socksrv);
89
+ return -1;
90
+ }
91
+ ina.sin_family = PF_INET;
92
+ ina.sin_port = htons((unsigned short)port);
93
+ ina.sin_addr.s_addr = INADDR_ANY;
94
+
95
+ if (bind(socksrv,(struct sockaddr*)&ina,sizeof(ina))!=0)
96
+ {
97
+ printf("Sockets : Tcp port %d busy\n",port);
98
+ closesocket(socksrv);
99
+ return -1;
100
+ }
101
+ if (listen(socksrv,3)!=0)
102
+ {
103
+ printf("Sockets : Tcp port %d listen error\n",port);
104
+ closesocket(socksrv);
105
+ return -1;
106
+ }
107
+ printf("Sockets : create Tcp server :%d (socket=%d)\n",port,socksrv);
108
+ tcp_sock[i]=socksrv;
109
+
110
+ return 0;
111
+ }
112
+
113
+
114
+ int tcpopen(char* dstip,int dstport)
115
+ {
116
+ SOCKET socktcp;
117
+ SOCKADDR_IN ina;
118
+ int opt=1;
119
+
120
+ int i=tcpgetfree();
121
+ if (i<0)
122
+ {
123
+ return i;
124
+ }
125
+
126
+ socktcp=socket(PF_INET,SOCK_STREAM,0);
127
+ if (socktcp==INVALID_SOCKET)
128
+ {
129
+ return -1;
130
+ }
131
+
132
+ if (WSAAsyncSelect(socktcp,mainwin,TCPEVENT,(FD_CONNECT|FD_READ|FD_WRITE|FD_CLOSE))==SOCKET_ERROR)
133
+ {
134
+ closesocket(socktcp);
135
+ return -1;
136
+ }
137
+ ina.sin_family = PF_INET;
138
+ ina.sin_port = htons((unsigned short)dstport);
139
+ ina.sin_addr.s_addr = inet_addr_bin(dstip);
140
+
141
+ if ( (connect(socktcp,(struct sockaddr *)&ina,sizeof(ina))!=0)
142
+ &&(!SOCKETWOULDBLOCK))
143
+ {
144
+ printf("Sockets : Tcp connect failed\n");
145
+ closesocket(socktcp);
146
+ return -1;
147
+ }
148
+ printf("Sockets : create Tcp %s:%d (socket=%d)\n",dstip,dstport,socktcp);
149
+
150
+ tcp_sock[i]=socktcp;
151
+ return i;
152
+ }
153
+ int tcpclose(int i)
154
+ {
155
+ if ((i>=0)&&(i<TCPMAX)&&(tcp_sock[i]!=INVALID_SOCKET))
156
+ {
157
+ printf("Sockets : Tcp close %d\n",tcp_sock[i]);
158
+ closesocket(tcp_sock[i]);
159
+ tcp_sock[i]=INVALID_SOCKET;
160
+ }
161
+ return i;
162
+ }
163
+
164
+ void tcpenable(int i,int enable)
165
+ {
166
+ if ((i>=0)&&(i<TCPMAX)&&(tcp_sock[i]!=INVALID_SOCKET))
167
+ {
168
+ char buf[16];
169
+ if (enable!=tcp_enable[i])
170
+ {
171
+ tcp_enable[i]=enable;
172
+ if (enable)
173
+ {
174
+ recv(tcp_sock[i],buf,0,0);
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ int tcpsend(int i,char* msg, int len)
181
+ {
182
+ if ((i>=0)&&(i<TCPMAX)&&(tcp_sock[i]!=INVALID_SOCKET))
183
+ {
184
+ int res=send(tcp_sock[i],msg,len,0);
185
+ if (res<0)
186
+ {
187
+ if (SOCKETWOULDBLOCK)
188
+ {
189
+ res=0;
190
+ }
191
+ else
192
+ {
193
+ res=-1;
194
+ }
195
+ }
196
+ return res;
197
+ }
198
+ return -1;
199
+ }
200
+ int tcpevent(int eventId, int wParam, int lParam)
201
+ {
202
+ int NetEvent,NetError;
203
+ SOCKET sock=(SOCKET)wParam;
204
+ int i=tcpbysock(sock);
205
+ // printf("tcpevent\n");
206
+ if (i<0)
207
+ {
208
+ return 0;
209
+ }
210
+ NetEvent=WSAGETSELECTEVENT(lParam);
211
+ NetError=WSAGETSELECTERROR(lParam);
212
+ if (NetError)
213
+ {
214
+ printf("Sockets : NetError %d on %d\n",NetError,i);
215
+ VPUSH(INTTOVAL(i));
216
+ VPUSH(INTTOVAL(-1));
217
+ VPUSH(NIL);
218
+ VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP));
219
+ interpGo();
220
+ VPULL();
221
+ return 1;
222
+ }
223
+ if (NetEvent==FD_ACCEPT)
224
+ {
225
+ SOCKADDR_IN cor;
226
+ SOCKET ns;
227
+ int sizecor;
228
+ int ni,ip,port;
229
+ char buf[16];
230
+
231
+ sizecor=sizeof(cor);
232
+ ns=accept(sock,(struct sockaddr*)&cor,&sizecor);
233
+ if (ns==INVALID_SOCKET)
234
+ {
235
+ return 1;
236
+ }
237
+
238
+ ni=tcpgetfree();
239
+ if (ni<0)
240
+ {
241
+ closesocket(ns);
242
+ return 1;
243
+ }
244
+
245
+ ip=cor.sin_addr.s_addr;
246
+ port=ntohs(cor.sin_port);
247
+
248
+ if (WSAAsyncSelect(ns,mainwin,TCPEVENT,
249
+ (FD_CONNECT|FD_READ|FD_WRITE|FD_CLOSE))==SOCKET_ERROR)
250
+ {
251
+ closesocket(ns);
252
+ return 1;
253
+ }
254
+ tcp_sock[ni]=ns;
255
+
256
+ printf("Sockets : accept Tcp from %x:%d (socket=%d)\n",ip,port,ns);
257
+ VPUSH(INTTOVAL(ni));
258
+ VPUSH(INTTOVAL(2));
259
+ sprintf(buf,"%d",i);
260
+ VPUSH(PNTTOVAL(VMALLOCSTR(buf,strlen(buf))));
261
+ VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP));
262
+ if (VSTACKGET(0)!=NIL)
263
+ {
264
+ interpGo();
265
+ }
266
+ else
267
+ {
268
+ VPULL();
269
+ VPULL();
270
+ VPULL();
271
+ }
272
+ VPULL();
273
+ return 1;
274
+ }
275
+
276
+ if (NetEvent==FD_WRITE)
277
+ {
278
+ printf("Sockets : Write event on %d\n",i);
279
+ VPUSH(INTTOVAL(i));
280
+ VPUSH(INTTOVAL(0));
281
+ VPUSH(NIL);
282
+ VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP));
283
+ if (VSTACKGET(0)!=NIL)
284
+ {
285
+ interpGo();
286
+ }
287
+ else
288
+ {
289
+ VPULL();
290
+ VPULL();
291
+ VPULL();
292
+ }
293
+ VPULL();
294
+ return 1;
295
+ }
296
+ if ((NetEvent==FD_READ)||(NetEvent==FD_CLOSE))
297
+ {
298
+ char buf[1024];
299
+ int res;
300
+ if (!tcp_enable[i])
301
+ {
302
+ // Sleep(10);
303
+ // recv(sock,buf,0,0);
304
+ // printf("disabled\n");
305
+ return 1;
306
+ }
307
+
308
+ printf("Sockets : Read event on %d\n",sock);
309
+ res=recv(sock,buf,1024,0);
310
+
311
+ VPUSH(INTTOVAL(i));
312
+ if (res>0)
313
+ {
314
+ VPUSH(INTTOVAL(1));
315
+ VPUSH(PNTTOVAL(VMALLOCSTR(buf,res)));
316
+ }
317
+ else
318
+ {
319
+ VPUSH(INTTOVAL(-1));
320
+ VPUSH(NIL);
321
+ }
322
+ VPUSH(VCALLSTACKGET(sys_start,SYS_CBTCP));
323
+ if (VSTACKGET(0)!=NIL)
324
+ {
325
+ interpGo();
326
+ }
327
+ else
328
+ {
329
+ VPULL();
330
+ VPULL();
331
+ VPULL();
332
+ }
333
+ VPULL();
334
+ return 1;
335
+ }
336
+ return 0;
337
+ }
338
+
339
+ int udpbyport(int p)
340
+ {
341
+ int i;
342
+ for(i=0; i<UDPMAX; i++) if (udp_port[i]==p)
343
+ {
344
+ return i;
345
+ }
346
+ return -1;
347
+ }
348
+ int udpgetfree()
349
+ {
350
+ return udpbyport(0);
351
+ }
352
+ int udpbysock(SOCKET s)
353
+ {
354
+ int i;
355
+ for(i=0; i<UDPMAX; i++) if ((udp_port[i])&&(udp_sock[i]==s))
356
+ {
357
+ return i;
358
+ }
359
+ return -1;
360
+ }
361
+
362
+ int udpcreate(int port)
363
+ {
364
+ SOCKET sockudp;
365
+ SOCKADDR_IN ina;
366
+ int opt=1;
367
+ int i;
368
+
369
+ udpclose(port);
370
+
371
+ i=udpgetfree();
372
+ if (i<0)
373
+ {
374
+ return i;
375
+ }
376
+
377
+ sockudp=socket(PF_INET,SOCK_DGRAM,0);
378
+ if (sockudp==INVALID_SOCKET)
379
+ {
380
+ return -1;
381
+ }
382
+
383
+ if (WSAAsyncSelect(sockudp,mainwin,UDPEVENT,(FD_READ))==SOCKET_ERROR)
384
+ {
385
+ closesocket(sockudp);
386
+ return -1;
387
+ }
388
+ ina.sin_family = PF_INET;
389
+ ina.sin_port = htons((unsigned short)port);
390
+ ina.sin_addr.s_addr = INADDR_ANY;
391
+ if (bind(sockudp,(struct sockaddr*)&ina,sizeof(ina))!=0)
392
+ {
393
+ printf("Sockets : Udp port %d busy\n",port);
394
+ closesocket(sockudp);
395
+ return -1;
396
+ }
397
+ setsockopt(sockudp, SOL_SOCKET, SO_REUSEADDR, (char*)&opt, sizeof (opt));
398
+ setsockopt(sockudp, SOL_SOCKET, SO_BROADCAST, (char*)&opt, sizeof (opt));
399
+ printf("Sockets : create Udp :%d (socket=%d)\n",port,sockudp);
400
+
401
+ udp_port[i]=port;
402
+ udp_sock[i]=sockudp;
403
+ return i;
404
+ }
405
+
406
+ int udpclose(int port)
407
+ {
408
+ int i=udpbyport(port);
409
+ if (i>=0)
410
+ {
411
+ closesocket(udp_sock[i]);
412
+ udp_port[i]=0;
413
+ }
414
+ return i;
415
+ }
416
+
417
+ int udpsend(int localport,char* dstip,int dstport,char* msg, int len)
418
+ {
419
+ SOCKADDR_IN ina;
420
+ int i;
421
+
422
+ i=udpbyport(localport);
423
+ if (i<0)
424
+ {
425
+ i=udpcreate(localport);
426
+ }
427
+ if (i>=0)
428
+ {
429
+ ina.sin_family = PF_INET;
430
+ ina.sin_port = htons((unsigned short)dstport);
431
+ ina.sin_addr.s_addr = inet_addr_bin(dstip);
432
+ printf("send %d bytes on chn %d\n",len,i);
433
+ sendto(udp_sock[i],msg,len,0,(struct sockaddr *)&ina,sizeof(ina));
434
+ return 0;
435
+ }
436
+ return -1;
437
+ }
438
+
439
+ int udpevent(int eventId, int wParam, int lParam)
440
+ {
441
+ int NetEvent,NetError;
442
+ SOCKET sock=(SOCKET)wParam;
443
+ int i=udpbysock(sock);
444
+ printf("Sockets : UDP event\n");
445
+
446
+ if (i<0)
447
+ {
448
+ return 0;
449
+ }
450
+
451
+ NetEvent=WSAGETSELECTEVENT(lParam);
452
+ NetError=WSAGETSELECTERROR(lParam);
453
+ if (NetError)
454
+ {
455
+ return 1;
456
+ }
457
+ if (NetEvent==FD_READ)
458
+ {
459
+ char buf[4096];
460
+ char *ip;
461
+ SOCKADDR_IN add;
462
+ int l=sizeof(add);
463
+ int res=recvfrom(sock,buf,4096,0,(struct sockaddr *)&add,&l);
464
+ if (res<0)
465
+ {
466
+ return 1;
467
+ }
468
+
469
+ ip=inet_ntoa(add.sin_addr);
470
+ printf("Sockets : UDP Read %d bytes on :%d from %s:%d\n",res,udp_port[i],ip,ntohs(add.sin_port));
471
+ VPUSH(INTTOVAL(i));
472
+ VPUSH(PNTTOVAL(VMALLOCSTR(buf,res)));
473
+ VPUSH(PNTTOVAL(VMALLOCSTR((char*)&add.sin_addr.s_addr,4)));
474
+ VPUSH(VCALLSTACKGET(sys_start,SYS_CBUDP));
475
+ if (VSTACKGET(0)!=NIL)
476
+ {
477
+ interpGo();
478
+ }
479
+ else
480
+ {
481
+ VPULL();
482
+ VPULL();
483
+ VPULL();
484
+ }
485
+ VPULL();
486
+ return 1;
487
+ }
488
+ return 0;
489
+ }
@@ -0,0 +1,95 @@
1
+ //-------------------
2
+ // MV
3
+ // version WIN32 et POCKETPC
4
+ // Sylvain Huet
5
+ // Derniere mise a jour : 07/01/2003
6
+ //
7
+
8
+
9
+ //#include <windows.h>
10
+ //#include <windowsx.h>
11
+ //#include <wingdi.h>
12
+ //#include <commctrl.h>
13
+ //#include <commdlg.h>
14
+ //#include <string.h>
15
+ #include "param.h"
16
+
17
+ #include <stdio.h>
18
+ #include <stdint.h>
19
+
20
+ #include "param.h"
21
+ #include "prodbuffer.h"
22
+ #include "filesystem.h"
23
+ #include "file.h"
24
+ #include "terminal.h"
25
+
26
+ #include "memory.h"
27
+ #include "util.h"
28
+ #include "parser.h"
29
+ #include "compiler.h"
30
+ #include "interpreter.h"
31
+
32
+
33
+
34
+ void AbortMetal(Memory* m,int donotstop)
35
+ {
36
+ if (m->abort)
37
+ {
38
+ return;
39
+ }
40
+ PRINTF(m)(LOG_RUNTIME,"\n---------- end of execution\n");
41
+ m->stop();
42
+ }
43
+
44
+
45
+
46
+ int StartMetal(const char *starter, const char* output, bool inSign)
47
+ {
48
+ int k;
49
+
50
+ // passe dans le r�pertoire de l'executable, en retenant le r�pertoire courant
51
+
52
+ Terminal* t=new Terminal();
53
+ Memory* m=new Memory(32*1024,t,NULL);
54
+ t->m=m;
55
+
56
+ if (k=m->start())
57
+ {
58
+ t->printf(LOG_RUNTIME,"Launcher : erreur d'initialisation Memory\n");
59
+ return -1;
60
+ }
61
+ STRPUSH(m, (char*) starter);
62
+ if (!(k=m->util->compiler->gocompile(COMPILE_FROMFILE)))
63
+ {
64
+ t->printf(LOG_RUNTIME,"\nCompiler : done !\n");
65
+ File* f=new File(NULL);
66
+ f->openwrite((char*) output);
67
+ if (inSign)
68
+ {
69
+ f->write("amber", 5);
70
+ char sizeStr[9];
71
+ sprintf(sizeStr, "%.8x", m->util->compiler->brelease->getsize());
72
+ f->write(sizeStr, 8);
73
+ }
74
+ f->write(m->util->compiler->brelease->getstart(),m->util->compiler->brelease->getsize());
75
+ if (inSign)
76
+ {
77
+ f->write("Mind", 4);
78
+ }
79
+ f->close();
80
+ return 0;
81
+ }
82
+ else
83
+ {
84
+ t->printf(LOG_RUNTIME,"Launcher : %s\n\n",m->errorname(k));
85
+ return -1;
86
+ }
87
+ }
88
+
89
+
90
+ int vcompDoit(char *starter)
91
+ {
92
+ int k=StartMetal(starter, "foo.bin", false);
93
+ getchar();
94
+ return k;
95
+ }