aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile14
-rw-r--r--debug.cpp46
-rw-r--r--debugrl.cpp86
-rw-r--r--debugrl.h5
4 files changed, 134 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index e63a7f084f..f114c5bdbf 100644
--- a/Makefile
+++ b/Makefile
@@ -2,11 +2,11 @@
CC = gcc
CFLAGS = -g -Wno-multichar
-DEFINES = -DUNIX
+DEFINES = -DUNIX -DHAVE_READLINE
LDFLAGS :=
INCLUDES:= `sdl-config --cflags`
CPPFLAGS= $(DEFINES) $(INCLUDES)
-LIBS = `sdl-config --libs`
+LIBS = `sdl-config --libs` -lreadline -lncurses -lhistory
ZIPFILE := scummvm-`date '+%Y-%m-%d'`.zip
INCS = scumm.h scummsys.h stdafx.h
@@ -14,13 +14,11 @@ INCS = scumm.h scummsys.h stdafx.h
OBJS = actor.o boxes.o costume.o gfx.o object.o resource.o \
saveload.o script.o scummvm.o sound.o string.o \
sys.o verbs.o sdl.o script_v1.o script_v2.o debug.o gui.o \
- imuse.o
+ imuse.o debugrl.o
-DISTFILES=actor.cpp boxes.cpp costume.cpp gfx.cpp object.cpp resource.cpp \
- saveload.cpp script.cpp scummvm.cpp sound.cpp string.cpp \
- sys.cpp verbs.cpp sdl.cpp script_v1.cpp script_v2.cpp debug.cpp \
- Makefile scumm.h scummsys.h stdafx.h stdafx.cpp windows.cpp \
- whatsnew.txt readme.txt copying.txt scummvm.dsp scummvm.dsw
+DISTFILES=$(OBJS:.o=.cpp) Makefile scumm.h scummsys.h stdafx.h stdafx.cpp \
+ windows.cpp debugrl.h whatsnew.txt readme.txt copying.txt \
+ scummvm.dsp scummvm.dsw
.cpp.o:
$(CC) $(CFLAGS) $(CPPFLAGS) -c $(<)
diff --git a/debug.cpp b/debug.cpp
index fa2166131c..fd18dcaf4b 100644
--- a/debug.cpp
+++ b/debug.cpp
@@ -5,23 +5,30 @@
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
-
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
-
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Header$
- *
*/
+/*
+ * Readline and command completion support by Tom Dunstan <tommyd@senet.com.au>
+ */
+
+
#include "stdafx.h"
#include "scumm.h"
+#ifdef HAVE_READLINE
+#include "debugrl.h"
+#endif
enum {
CMD_INVALID,
@@ -42,6 +49,9 @@ void ScummDebugger::attach(Scumm *s) {
s->_debugger = this;
_go_amount = 1;
+#ifdef HAVE_READLINE
+ initialize_readline();
+#endif
}
bool ScummDebugger::do_command() {
@@ -128,8 +138,11 @@ int ScummDebugger::get_command() {
const DebuggerCommands *dc;
char *s;
int i;
+ static char *buf;
do {
+#ifndef HAVE_READLINE
+ buf = _cmd_buffer;
printf("debug> ");
if (!fgets(_cmd_buffer, sizeof(_cmd_buffer), stdin))
return CMD_QUIT;
@@ -140,11 +153,26 @@ int ScummDebugger::get_command() {
if (i==0)
continue;
-
+
+#else // yes we do have readline
+ if(buf) {
+ free(buf);
+ }
+ buf = readline("debug> ");
+ if(!buf) {
+ printf("\n");
+ return CMD_QUIT;
+ }
+ if(strlen(buf) == 0) {
+ continue;
+ }
+ add_history(buf);
+#endif
+
dc = debugger_commands;
do {
- if (!strncmp(_cmd_buffer, dc->text, dc->len)) {
- for(s=_cmd_buffer;*s;s++) {
+ if (!strncmp(buf, dc->text, dc->len)) {
+ for(s=buf;*s;s++) {
if (*s==32) { s++; break; }
}
_parameters = s;
@@ -152,9 +180,9 @@ int ScummDebugger::get_command() {
}
} while ((++dc)->text[0]);
- for(s=_cmd_buffer;*s;s++)
+ for(s=buf;*s;s++)
if (*s==32) { *s=0; break; }
- printf("Invalid command '%s'. Type 'help' for a list of available commands.\n", _cmd_buffer);
+ printf("Invalid command '%s'. Type 'help' for a list of available commands.\n", buf);
} while (1);
}
@@ -191,4 +219,4 @@ void ScummDebugger::printScripts() {
}
}
printf("+---------------------------------+\n");
-} \ No newline at end of file
+}
diff --git a/debugrl.cpp b/debugrl.cpp
new file mode 100644
index 0000000000..86d72327a0
--- /dev/null
+++ b/debugrl.cpp
@@ -0,0 +1,86 @@
+#ifdef HAVE_READLINE
+
+#include "debugrl.h"
+
+// A lot of this was ripped straight from the readline fileman.c example.
+
+char* _debugger_commands[] = {
+ "help",
+ "quit",
+ "go",
+ "actor",
+ "scripts",
+ "exit",
+ (char *)NULL
+};
+
+
+// forwards decls
+char ** scumm_debugger_completion (const char *text, int start, int end);
+char * scumm_debugger_command_generator (const char *text, int state);
+
+void initialize_readline () {
+ /* Allow conditional parsing of the ~/.inputrc file. */
+ rl_readline_name = "scummvm";
+
+ /* Tell the completer that we want a crack first. */
+ rl_attempted_completion_function = scumm_debugger_completion;
+}
+
+char ** scumm_debugger_completion (const char *text, int start, int end) {
+
+ char **matches;
+
+ matches = (char **)NULL;
+
+ // If this word is at the start of the line, then it is a command
+ // to complete.
+ if (start == 0) {
+ matches = rl_completion_matches (text, scumm_debugger_command_generator);
+ } else {
+ // At some stage it'd be nice to have symbolic actor name completion
+ // or something similarly groovy. Not right now though.
+ }
+
+ // This just makes sure that readline doesn't try to use its default
+ // completer, which uses filenames in the current dir, if we can't find
+ // a match, since filenames don't have much use in the debuger :)
+ // There's probably a nice way to do this once, rather than every time.
+ rl_attempted_completion_over = 1;
+
+ return (matches);
+}
+
+
+/* Generator function for command completion. STATE lets us know whether
+ to start from scratch; without any state (i.e. STATE == 0), then we
+ start at the top of the list. */
+char * scumm_debugger_command_generator (const char *text, int state) {
+
+ static int list_index, len;
+ char *name;
+
+ /* If this is a new word to complete, initialize now. This includes
+ saving the length of TEXT for efficiency, and initializing the index
+ variable to 0. */
+ if (!state)
+ {
+ list_index = 0;
+ len = strlen (text);
+ }
+
+ /* Return the next name which partially matches from the command list. */
+ while (name = _debugger_commands[list_index])
+ {
+ list_index++;
+
+ if (strncmp (name, text, len) == 0)
+ //return (dupstr(name));
+ return strdup(name);
+ }
+
+ /* If no names matched, then return NULL. */
+ return ((char *)NULL);
+}
+
+#endif /* HAVE_READLINE */
diff --git a/debugrl.h b/debugrl.h
new file mode 100644
index 0000000000..c309ec96d8
--- /dev/null
+++ b/debugrl.h
@@ -0,0 +1,5 @@
+#include <stdio.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+// initializes readline with our own completer
+void initialize_readline ();