22
33#include <stdbool.h>
44#include <stdio.h>
5+ #include <stdlib.h>
6+ #include <string.h>
57
68#include "util.h"
9+ #include "commands/debugger.h"
710
811static const char * quit_matches [] = {"quit" , "q" };
912static const char * help_matches [] = {"help" , "?" };
1013
14+ /* Debugger commands */
15+ static const char * debug_info_matches [] = {"info" };
16+
1117static void print_commands_help () {
1218 puts (" Commands available:\n" );
13- puts (" :quit, :q \tExit laco" );
14- puts (" :help, :? \tDisplay this list of commands" );
19+ puts (" :quit, :q \tExit laco" );
20+ puts (" :help, :? \tDisplay this list of commands" );
21+ puts (" :info <name> \tShow information on given function" );
1522}
1623
1724static inline bool is_quit (const char * command ) {
@@ -22,17 +29,31 @@ static inline bool is_help(const char* command) {
2229 return laco_is_match (help_matches , command );
2330}
2431
32+ static inline bool is_debug_info (const char * command ) {
33+ return laco_is_match (debug_info_matches , command );
34+ }
35+
2536void laco_handle_command (struct LacoState * laco , char * line ) {
2637 if (laco != NULL && line != NULL ) {
27- const char * command = line + 1 ;
38+ char * command_line = strdup (line + 1 );
39+ char * * command_words = laco_line_to_words (command_line );
40+
41+ /* Alias for */
42+ const char * command = command_words [0 ];
43+ const char * * arguments = (const char * * ) command_words + 1 ;
2844
2945 if (is_quit (command )) {
3046 laco_kill (laco , 0 , "Exiting laco..." );
3147 } else if (is_help (command )) {
3248 print_commands_help ();
49+ } else if (is_debug_info (command )) {
50+ laco_print_debug_info (laco , arguments [0 ]);
3351 }
3452
35- /* Make it seem like this was an empty line */
53+ free (command_line );
54+ free (command_words );
55+
56+ /* Make it seems like this was an empty line */
3657 line [0 ] = '\0' ;
3758 }
3859}
0 commit comments