nabaztag_hack_kit 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +3 -0
  3. data/CHANGELOG.md +11 -0
  4. data/Gemfile +4 -0
  5. data/README.md +119 -0
  6. data/Rakefile +21 -0
  7. data/bin/mtl_comp +41 -0
  8. data/bin/mtl_merge +22 -0
  9. data/bin/mtl_simu +40 -0
  10. data/bytecode/lib/buffer.mtl +109 -0
  11. data/bytecode/lib/button.mtl +27 -0
  12. data/bytecode/lib/data_helper.mtl +88 -0
  13. data/bytecode/lib/ear.mtl +90 -0
  14. data/bytecode/lib/led.mtl +33 -0
  15. data/bytecode/lib/rfid.mtl +50 -0
  16. data/bytecode/main.mtl +129 -0
  17. data/config.ru +6 -0
  18. data/ext/bytecode/Commands.md +172 -0
  19. data/ext/bytecode/Docs.md +488 -0
  20. data/ext/bytecode/README.md +5 -0
  21. data/ext/bytecode/lib/arp.mtl +159 -0
  22. data/ext/bytecode/lib/cfg.mtl +74 -0
  23. data/ext/bytecode/lib/choreos.mtl +1487 -0
  24. data/ext/bytecode/lib/dhcp.mtl +152 -0
  25. data/ext/bytecode/lib/dns.mtl +89 -0
  26. data/ext/bytecode/lib/http.mtl +84 -0
  27. data/ext/bytecode/lib/tcp.mtl +340 -0
  28. data/ext/bytecode/lib/udp.mtl +49 -0
  29. data/ext/bytecode/lib/util.mtl +74 -0
  30. data/ext/bytecode/lib/var.mtl +15 -0
  31. data/ext/bytecode/lib/wifi.mtl +243 -0
  32. data/ext/bytecode/nominal-ping.mtl +5828 -0
  33. data/ext/mtl/Makefile +42 -0
  34. data/ext/mtl/README.md +13 -0
  35. data/ext/mtl/bc.cpp +1891 -0
  36. data/ext/mtl/conf.bin.sans_password +0 -0
  37. data/ext/mtl/config.txt +5 -0
  38. data/ext/mtl/dumpbc.c +2566 -0
  39. data/ext/mtl/extconf.rb +1 -0
  40. data/ext/mtl/linux_simu.c +271 -0
  41. data/ext/mtl/linux_simuaudio.c +16 -0
  42. data/ext/mtl/linux_simuaudio.h +18 -0
  43. data/ext/mtl/linux_simunet.c +620 -0
  44. data/ext/mtl/linux_simunet.h +7 -0
  45. data/ext/mtl/log.c +297 -0
  46. data/ext/mtl/log.h +20 -0
  47. data/ext/mtl/main_compiler.cpp +104 -0
  48. data/ext/mtl/main_simu.cpp +221 -0
  49. data/ext/mtl/mp3/GTKANAL.H +97 -0
  50. data/ext/mtl/mp3/LAYER3.C +2090 -0
  51. data/ext/mtl/mp3/TABINIT.C +82 -0
  52. data/ext/mtl/mp3/common.c +265 -0
  53. data/ext/mtl/mp3/dct64_i386.c +316 -0
  54. data/ext/mtl/mp3/decode_i386.c +155 -0
  55. data/ext/mtl/mp3/huffman.h +332 -0
  56. data/ext/mtl/mp3/interface.c +258 -0
  57. data/ext/mtl/mp3/mpg123.h +182 -0
  58. data/ext/mtl/mp3/mpglib.h +44 -0
  59. data/ext/mtl/properties.c +293 -0
  60. data/ext/mtl/properties.h +10 -0
  61. data/ext/mtl/simu.c +750 -0
  62. data/ext/mtl/simuaudio.c +662 -0
  63. data/ext/mtl/simuaudio.h +74 -0
  64. data/ext/mtl/simunet.c +400 -0
  65. data/ext/mtl/simunet.h +30 -0
  66. data/ext/mtl/utils/correct_const.sh +34 -0
  67. data/ext/mtl/vaudio.c +677 -0
  68. data/ext/mtl/vaudio.h +46 -0
  69. data/ext/mtl/vbc.h +160 -0
  70. data/ext/mtl/vbc_str.h +166 -0
  71. data/ext/mtl/vcomp/Makefile +29 -0
  72. data/ext/mtl/vcomp/bootstrap.cpp +89 -0
  73. data/ext/mtl/vcomp/compiler.cpp +470 -0
  74. data/ext/mtl/vcomp/compiler.h +200 -0
  75. data/ext/mtl/vcomp/compiler_file.cpp +929 -0
  76. data/ext/mtl/vcomp/compiler_prog.cpp +250 -0
  77. data/ext/mtl/vcomp/compiler_term.cpp +1053 -0
  78. data/ext/mtl/vcomp/compiler_type.cpp +872 -0
  79. data/ext/mtl/vcomp/compiler_var.cpp +289 -0
  80. data/ext/mtl/vcomp/file.cpp +79 -0
  81. data/ext/mtl/vcomp/file.h +39 -0
  82. data/ext/mtl/vcomp/filesystem.h +14 -0
  83. data/ext/mtl/vcomp/interpreter.cpp +85 -0
  84. data/ext/mtl/vcomp/interpreter.h +121 -0
  85. data/ext/mtl/vcomp/memory.cpp +241 -0
  86. data/ext/mtl/vcomp/memory.h +326 -0
  87. data/ext/mtl/vcomp/param.h +95 -0
  88. data/ext/mtl/vcomp/parser.cpp +427 -0
  89. data/ext/mtl/vcomp/parser.h +97 -0
  90. data/ext/mtl/vcomp/parser_xml.cpp +124 -0
  91. data/ext/mtl/vcomp/prodbuffer.cpp +125 -0
  92. data/ext/mtl/vcomp/prodbuffer.h +42 -0
  93. data/ext/mtl/vcomp/resource.h +17 -0
  94. data/ext/mtl/vcomp/stdlib_core.cpp +122 -0
  95. data/ext/mtl/vcomp/terminal.cpp +73 -0
  96. data/ext/mtl/vcomp/terminal.h +30 -0
  97. data/ext/mtl/vcomp/util.cpp +48 -0
  98. data/ext/mtl/vcomp/util.h +31 -0
  99. data/ext/mtl/vinterp.c +1349 -0
  100. data/ext/mtl/vinterp.h +11 -0
  101. data/ext/mtl/vloader.c +127 -0
  102. data/ext/mtl/vloader.h +31 -0
  103. data/ext/mtl/vlog.c +589 -0
  104. data/ext/mtl/vlog.h +69 -0
  105. data/ext/mtl/vmem.c +424 -0
  106. data/ext/mtl/vmem.h +107 -0
  107. data/ext/mtl/vnet.c +255 -0
  108. data/ext/mtl/vnet.h +19 -0
  109. data/lib/nabaztag_hack_kit/message/api.rb +39 -0
  110. data/lib/nabaztag_hack_kit/message/helper.rb +39 -0
  111. data/lib/nabaztag_hack_kit/message.rb +36 -0
  112. data/lib/nabaztag_hack_kit/server.rb +50 -0
  113. data/lib/nabaztag_hack_kit/version.rb +3 -0
  114. data/lib/nabaztag_hack_kit.rb +4 -0
  115. data/nabaztag_hack_kit.gemspec +29 -0
  116. data/public/bytecode.bin +0 -0
  117. data/test/bytecode/helper.mtl +60 -0
  118. data/test/bytecode/native.mtl +28 -0
  119. data/test/bytecode/test.mtl +221 -0
  120. data/test/spec_helper.rb +5 -0
  121. data/test/unit/message_spec.rb +56 -0
  122. metadata +209 -0
@@ -0,0 +1,293 @@
1
+ // VLISP Virtual Machine - 2006 - by Sylvain Huet
2
+ // Lowcost IS Powerfull
3
+
4
+ //#include"vlow.h"
5
+ #include <stdlib.h>
6
+ #include <string.h>
7
+ #include<stdio.h>
8
+ #include"vmem.h"
9
+ #include"properties.h"
10
+ #include "log.h"
11
+
12
+ struct Prop
13
+ {
14
+ char* name;
15
+ char* val;
16
+ struct Prop* nxt;
17
+ };
18
+ typedef struct Prop* prop;
19
+
20
+ char* emptystring="";
21
+ struct Prop *Properties;
22
+
23
+ // retourne le contenu d'un fichier dans un buffer
24
+ // il ne faudra pas oublier de d�sallou� le buffer, par un appel � fileReleaseBuffer
25
+ char* fileLoadL(const char *filename,int *length)
26
+ {
27
+ FILE* file;
28
+ int size;
29
+ char *buffer;
30
+
31
+ file=fopen(filename,"rb");
32
+ if (!file) return NULL;
33
+
34
+ fseek(file,0,SEEK_END);
35
+ size=ftell(file);
36
+ fseek(file,0,SEEK_SET);
37
+
38
+ buffer=(char*)malloc(size+1);
39
+ size=fread((void*)buffer,1,size,file);
40
+ buffer[size]=0;
41
+ fclose(file);
42
+ if (length) *length=size;
43
+ return buffer;
44
+ }
45
+
46
+ char* fileLoad(const char *filename)
47
+ {
48
+ return fileLoadL(filename,NULL);
49
+ }
50
+
51
+ // lib�re le buffer retourn� par fileLoad
52
+ void fileReleaseBuffer(char* buffer)
53
+ {
54
+ if (buffer) free((void*)buffer);
55
+ }
56
+
57
+ // lecture d'une cha�ne hexad�cimale (s'arr�te au premier caract�re incorrect)
58
+ int htoi(const char* src)
59
+ {
60
+ int x,c;
61
+ x=0;
62
+ while(c=*src++)
63
+ {
64
+ if ((c>='0')&&(c<='9')) x=(x<<4)+c-'0';
65
+ else if ((c>='A')&&(c<='F')) x=(x<<4)+c-'A'+10;
66
+ else if ((c>='a')&&(c<='f')) x=(x<<4)+c-'a'+10;
67
+ else return x;
68
+ }
69
+ return x;
70
+ }
71
+
72
+
73
+ // alloue une cha�ne
74
+ char* stringStore(const char *src,int len)
75
+ {
76
+ char* s=(char*)malloc(len+1);
77
+ memcpy(s,src,len);
78
+ s[len]=0;
79
+ return s;
80
+ }
81
+
82
+ // d�salloue une cha�ne
83
+ void stringRelease(char *src)
84
+ {
85
+ if (src) free((void*)src);
86
+ }
87
+
88
+
89
+ // fonction d'identification du premier mot d'une cha�ne
90
+ // ignore les espaces initiaux, et s'arr�te au premier espace ou caract�re sp�cial rencontr�
91
+ void suppspace(char* begin,int len, char **wordbegin, int *wordlen)
92
+ {
93
+ int i=0;
94
+ int j;
95
+
96
+ while((i<len)&&(begin[i]>0)&&(begin[i]<=32)) i++; // suppression des espaces
97
+ *wordbegin=begin+i;
98
+
99
+ j=i;
100
+ while((j<len)&&((begin[j]>32)||(begin[j]<0))) j++; // aller jusqu'au bout du tag
101
+ *wordlen=j-i;
102
+ }
103
+
104
+
105
+ // allocation de m�moire pour la structure prop
106
+ prop propAlloc()
107
+ {
108
+ prop pnt=(prop)malloc(sizeof(struct Prop));
109
+ return pnt;
110
+ }
111
+
112
+ // d�sallocation de m�moire pour la structure prop
113
+ void propFree(prop pnt)
114
+ {
115
+ if (pnt) free((void*)pnt);
116
+ }
117
+
118
+ // d�truit une prop, avec tous ses champs
119
+ void propRelease(prop pnt)
120
+ {
121
+ if (pnt)
122
+ {
123
+ propRelease(pnt->nxt);
124
+ stringRelease(pnt->name);
125
+ stringRelease(pnt->val);
126
+ propFree(pnt);
127
+ }
128
+ }
129
+
130
+ // ajout d'un champ � une structure prop 'nxt'
131
+ prop propAdd(const char *name,int namelen,const char *val,int vallen,prop nxt)
132
+ {
133
+ char *sname,*sval;
134
+
135
+ if (name[0] == ';')
136
+ return nxt;
137
+
138
+ prop pnt=propAlloc();
139
+ sname=stringStore(name,namelen);
140
+ sval=stringStore(val,vallen);
141
+
142
+ pnt->name=sname;
143
+ pnt->val=sval;
144
+ pnt->nxt=nxt;
145
+ return pnt;
146
+ }
147
+
148
+ // inverse la liste de propri�t�s
149
+ prop propReverse(prop pnt)
150
+ {
151
+ prop last=NULL;
152
+ prop nxt=NULL;
153
+ while(pnt)
154
+ {
155
+ nxt=pnt->nxt;
156
+ pnt->nxt=last;
157
+ if (!nxt) return pnt;
158
+ last=pnt;
159
+ pnt=nxt;
160
+ }
161
+ return NULL;
162
+ }
163
+
164
+ // parsing d'un buffer rempli avec le contenu d'un fichier de prop
165
+ prop propParseInv(char *src)
166
+ {
167
+ prop pnt=NULL; // pointeur vers la property en construction
168
+ int i,name_b,name_e,val_b,val_e;
169
+
170
+ i=0;
171
+ while(src[i])
172
+ {
173
+ while((src[i])&&(src[i]>0)&&(src[i]<=32)) i++;
174
+ if (!src[i]) return pnt;
175
+ name_b=i;
176
+ while(src[i]>32) i++;
177
+ if (!src[i]) return pnt;
178
+ name_e=i;
179
+ while((src[i])&&((src[i]==32)||(src[i]==9))) i++;
180
+ if (!src[i]) return pnt;
181
+ if (src[i]>32) // il y a bien un argument
182
+ {
183
+ val_b=i;
184
+ while((src[i]>=32)||(src[i]<0)) i++;
185
+ val_e=i;
186
+ pnt=propAdd(src+name_b,name_e-name_b,src+val_b,val_e-val_b,pnt);
187
+ }
188
+ else pnt=propAdd(src+name_b,name_e-name_b,src,0,pnt);
189
+ }
190
+ return pnt;
191
+ }
192
+
193
+ // parsing d'un buffer rempli avec le contenu d'un fichier de prop
194
+ prop propParse(char *src)
195
+ {
196
+ return propReverse(propParseInv(src));
197
+ }
198
+
199
+ // retourne le premier �l�ment
200
+ prop propFirst(prop pnt)
201
+ {
202
+ return pnt;
203
+ }
204
+
205
+ // retourne l'�l�ment suivant
206
+ prop propNext(prop pnt)
207
+ {
208
+ return pnt->nxt;
209
+ }
210
+
211
+ // charge un fichier de prop
212
+ // retourne un pointeur vers la structure prop du dernier champ
213
+ prop propLoad(const char *file)
214
+ {
215
+ prop pnt=NULL; // pointeur vers la property en construction
216
+ char* src=fileLoad(file);
217
+
218
+ if (!src) return NULL;
219
+ pnt=propParse(src);
220
+ fileReleaseBuffer(src);
221
+ return pnt;
222
+ }
223
+
224
+
225
+ // dump d'une prop sur la sortie standard
226
+ void propDump(prop pnt)
227
+ {
228
+ while(pnt)
229
+ {
230
+ my_printf(LOG_INIT, "%s := %s\n",pnt->name,pnt->val);
231
+ pnt=pnt->nxt;
232
+ }
233
+ }
234
+
235
+
236
+ // retourne la valeur d'un champ
237
+ char* propGet(prop pnt,const char *field)
238
+ {
239
+ while(pnt)
240
+ {
241
+ if (!strcmp(pnt->name,field)) return pnt->val;
242
+ pnt=pnt->nxt;
243
+ }
244
+ return emptystring;
245
+ }
246
+
247
+ // retourne la valeur enti�re d'un champ
248
+ int propGetInt(prop pnt,const char *field)
249
+ {
250
+ char *p=propGet(pnt,field);
251
+ if ((p[0]=='0')&&((p[1]=='x')||(p[1]=='X'))) return htoi(p+2);
252
+ return atoi(p);
253
+ }
254
+
255
+ int PropLoad(const char* file)
256
+ {
257
+ Properties=propLoad(file);
258
+ return 0;
259
+ }
260
+
261
+ // retourne la valeur d'un champ
262
+ char* PropGet(const char *field)
263
+ {
264
+ return propGet(Properties,field);
265
+ }
266
+
267
+ // retourne la valeur enti�re d'un champ
268
+ int PropGetInt(const char *field)
269
+ {
270
+ return propGetInt(Properties,field);
271
+ }
272
+
273
+ // efface la valeur d'un champ s'il est pr�sent, chaine
274
+ void PropSet(const char *field, const char *val)
275
+ {
276
+ prop tmp = Properties;
277
+
278
+ while (tmp && strcmp(tmp->name, field))
279
+ tmp = tmp->nxt;
280
+ if (!tmp)
281
+ Properties = propAdd(field,strlen(field),val,strlen(val),Properties);
282
+ else
283
+ {
284
+ stringRelease(tmp->val);
285
+ tmp->val = stringStore(val, strlen(val));
286
+ }
287
+ }
288
+
289
+ // affiche toutes les prop sur la sortie standard
290
+ void PropDump()
291
+ {
292
+ propDump(Properties);
293
+ }
@@ -0,0 +1,10 @@
1
+ #ifndef PROPERTIES_H_
2
+ # define PROPERTIES_H_
3
+
4
+ int PropLoad(const char* file);
5
+ char* PropGet(const char *field);
6
+ int PropGetInt(const char *field);
7
+ void PropSet(const char *field, const char *val);
8
+ void PropDump();
9
+
10
+ #endif // ! PROPERTIES_H_