@@ -18,6 +18,7 @@ create_instruction_data(majom, "majom fuggveny leirasa, jaaaa :)");
18
18
create_instruction_data (eger , "eger fuggveny leirasa, gyoooo :)" );
19
19
create_instruction_data (okor , "eger fuggveny leirasa, gyaaa :)" );
20
20
create_instruction_data (csiga , "eger fuggveny leirasa, dikk :)" );
21
+ create_instruction_data (v , "Vagod csotany, hihihiiii ;)" );
21
22
22
23
#define add_instruction (name , func ) add_interpreter_instruction(&name##_API_NAME, &name##_API_DESC, func);
23
24
@@ -46,6 +47,7 @@ void init_interpreter(void)
46
47
add_instruction (eger , kutya_func );
47
48
add_instruction (okor , kutya_func );
48
49
add_instruction (csiga , kutya_func );
50
+ add_instruction (v , kutya_func );
49
51
50
52
// Index eache element to find their place in alphabetic order
51
53
index_apis_in_order ( & API_tree [0 ] );
@@ -97,7 +99,7 @@ void add_interpreter_instruction(const char **name, const char **desc, void (*fu
97
99
// if it is ot the first command we have to find it's place in the tree
98
100
else
99
101
{
100
- prev = & API_tree [0 ]; // get the address of the root element
102
+ prev = & API_tree [0 ]; // get the address of the root element
101
103
comp_res = strcmp ( (char * )* (prev -> name ), (char * )* name ); // compare the names and save the result to 'comp_res'
102
104
103
105
// compare( ABC order ) the root element name and the new element name
@@ -274,3 +276,66 @@ void recursive_optimiser( int32_t start_index, int32_t stop_index ){
274
276
275
277
276
278
}
279
+
280
+ void execute ( char * cmd , char * response ){
281
+
282
+ API_t * next ;
283
+ API_t * prev ;
284
+ int8_t comp_res ;
285
+ char * arg ;
286
+ uint32_t cmd_name_cntr ;
287
+
288
+ arg = cmd ; // 'arg' variable will hold the start address of the argument list
289
+ cmd_name_cntr = 0 ;
290
+
291
+ // find the first space character or a string-end character.
292
+ // At this time count how long is the command name( in characters )
293
+ while ( ( * arg != '\0' ) && ( * arg != ' ' ) ){
294
+
295
+ cmd_name_cntr ++ ;
296
+ arg ++ ;
297
+
298
+ }
299
+
300
+ // If space character found increment the 'arg'.
301
+ // It is important to do unless the arg list will contain
302
+ // a space character at the beginning.
303
+ if ( * arg == ' ' ){
304
+
305
+ * arg = '\0' ;
306
+ arg ++ ;
307
+
308
+ }
309
+
310
+
311
+ prev = & API_tree [0 ];
312
+
313
+ //comp_res = strncmp( (char*)*(prev->name), cmd, cmd_name_cntr );
314
+
315
+ comp_res = strncmp ( (char * )* (prev -> name ), cmd , strlen ( (char * )* (prev -> name ) ) );
316
+
317
+ (comp_res > 0 ) ? (next = (prev -> left )) : ( next = (prev -> right ));
318
+
319
+ while ( ( comp_res != 0 ) && ( next != NULL ) ){
320
+
321
+ prev = next ;
322
+ //comp_res = strncmp( (char*)*(prev->name), cmd, cmd_name_cntr );
323
+ comp_res = strncmp ( (char * )* (prev -> name ), cmd , strlen ( (char * )* (prev -> name ) ) );
324
+
325
+ (comp_res > 0 ) ? (next = (prev -> left )) : ( next = (prev -> right ));
326
+
327
+ }
328
+
329
+ if ( comp_res == 0 ){
330
+
331
+ (prev -> func )( arg , response );
332
+
333
+ }
334
+
335
+ else {
336
+
337
+ printf ( "Command \'%s\' not found!!!\r\n" , cmd );
338
+
339
+ }
340
+
341
+ }
0 commit comments