Skip to content

Commit 033da4b

Browse files
committed
Add handling of :info command
1 parent 4a63eaf commit 033da4b

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/commands.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
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

811
static const char* quit_matches[] = {"quit", "q"};
912
static const char* help_matches[] = {"help", "?"};
1013

14+
/* Debugger commands */
15+
static const char* debug_info_matches[] = {"info"};
16+
1117
static 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

1724
static 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+
2536
void 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

Comments
 (0)