99
1010static const char * quit_matches [] = {"quit" , "q" , NULL };
1111static const char * help_matches [] = {"help" , "?" , NULL };
12-
13- /* Debugger commands */
1412static const char * debug_info_matches [] = {"info" , NULL };
1513
16- static void print_commands_help () {
14+ static void handle_quit (struct LacoState * laco , const char * * arguments ) {
15+ laco_kill (laco , 0 , "Exiting laco..." );
16+ }
17+
18+ static void handle_help (struct LacoState * laco , const char * * arguments ) {
1719 puts (" Commands available:\n" );
1820 puts (" :quit, :q \tExit laco" );
1921 puts (" :help, :? \tDisplay this list of commands" );
2022 puts (" :info <name> \tShow information on given function" );
2123}
2224
23- static inline bool is_quit (const char * command ) {
24- return laco_is_match (quit_matches , command );
25+ static void handle_debug_info (struct LacoState * laco ,
26+ const char * * arguments ) {
27+ laco_print_debug_info (laco , arguments [0 ]);
2528}
2629
27- static inline bool is_help ( const char * command ) {
28- return laco_is_match ( help_matches , command );
29- }
30+ static const struct LacoCommand line_commands [] = {
31+ { quit_matches , handle_quit },
32+ { help_matches , handle_help },
3033
31- static inline bool is_debug_info (const char * command ) {
32- return laco_is_match (debug_info_matches , command );
33- }
34+ /* Debugger commands */
35+ { debug_info_matches , handle_debug_info },
36+
37+ { NULL , NULL }
38+ };
3439
3540void laco_dispatch (const struct LacoCommand * commands ,
3641 struct LacoState * laco , const char * command_keyword ,
@@ -55,13 +60,7 @@ void laco_handle_command(struct LacoState* laco, char* line) {
5560 const char * command = command_words [0 ];
5661 const char * * arguments = (const char * * ) command_words + 1 ;
5762
58- if (is_quit (command )) {
59- laco_kill (laco , 0 , "Exiting laco..." );
60- } else if (is_help (command )) {
61- print_commands_help ();
62- } else if (is_debug_info (command )) {
63- laco_print_debug_info (laco , arguments [0 ]);
64- }
63+ laco_dispatch (line_commands , laco , command , arguments );
6564
6665 free (command_line );
6766 free (command_words );
0 commit comments