[Scummvm-cvs-logs] CVS: scummvm debugrl.cpp,NONE,1.1 debugrl.h,NONE,1.1 Makefile,1.12,1.13 debug.cpp,1.8,1.9

Claudio Matsuoka cmatsuoka at users.sourceforge.net
Sun Nov 18 16:05:02 CET 2001


Update of /cvsroot/scummvm/scummvm
In directory usw-pr-cvs1:/tmp/cvs-serv14169

Modified Files:
	Makefile debug.cpp 
Added Files:
	debugrl.cpp debugrl.h 
Log Message:
Merged Tom Dunstan's debugger readline patch. Define
HAVE_READLINE to enable it.


--- NEW FILE: debugrl.cpp ---
#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 */

--- NEW FILE: debugrl.h ---
#include <stdio.h>
#include <readline/readline.h>
#include <readline/history.h>
// initializes readline with our own completer
void initialize_readline ();

Index: Makefile
===================================================================
RCS file: /cvsroot/scummvm/scummvm/Makefile,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** Makefile	2001/11/14 18:40:39	1.12
--- Makefile	2001/11/19 00:04:34	1.13
***************
*** 3,11 ****
  CC	= gcc
  CFLAGS	= -g -Wno-multichar
! DEFINES	= -DUNIX
  LDFLAGS := 
  INCLUDES:= `sdl-config --cflags`
  CPPFLAGS= $(DEFINES) $(INCLUDES)
! LIBS	= `sdl-config --libs`
  ZIPFILE := scummvm-`date '+%Y-%m-%d'`.zip
  
--- 3,11 ----
  CC	= gcc
  CFLAGS	= -g -Wno-multichar
! DEFINES	= -DUNIX -DHAVE_READLINE
  LDFLAGS := 
  INCLUDES:= `sdl-config --cflags`
  CPPFLAGS= $(DEFINES) $(INCLUDES)
! LIBS	= `sdl-config --libs` -lreadline -lncurses -lhistory
  ZIPFILE := scummvm-`date '+%Y-%m-%d'`.zip
  
***************
*** 15,25 ****
  	  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
  
! 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 
  
  .cpp.o:
--- 15,23 ----
  	  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 debugrl.o
  
! 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:

Index: debug.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/debug.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** debug.cpp	2001/11/12 20:50:36	1.8
--- debug.cpp	2001/11/19 00:04:34	1.9
***************
*** 6,15 ****
   * 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
--- 6,15 ----
   * 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
***************
*** 17,26 ****
   *
   * $Header$
-  *
   */
  
  #include "stdafx.h"
  #include "scumm.h"
  
  
  enum {
--- 17,33 ----
   *
   * $Header$
   */
  
+ /*
+  * Readline and command completion support by Tom Dunstan <tommyd at senet.com.au>
+  */
+ 
+ 
  #include "stdafx.h"
  #include "scumm.h"
  
+ #ifdef HAVE_READLINE
+ #include "debugrl.h"
+ #endif
  
  enum {
***************
*** 43,46 ****
--- 50,56 ----
  
  	_go_amount = 1;
+ #ifdef HAVE_READLINE
+ 	initialize_readline();
+ #endif
  }
  
***************
*** 129,134 ****
--- 139,147 ----
  	char *s;
  	int i;
+ 	static char *buf;
  
  	do {
+ #ifndef HAVE_READLINE
+ 		buf = _cmd_buffer;
  		printf("debug> ");
  		if (!fgets(_cmd_buffer, sizeof(_cmd_buffer), stdin))
***************
*** 141,149 ****
  		if (i==0)
  			continue;
! 						
  		dc = debugger_commands;
  		do {
! 			if (!strncmp(_cmd_buffer, dc->text, dc->len)) {
! 				for(s=_cmd_buffer;*s;s++) {
  					if (*s==32) { s++; break; }
  				}
--- 154,177 ----
  		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(buf, dc->text, dc->len)) {
! 				for(s=buf;*s;s++) {
  					if (*s==32) { s++; break; }
  				}
***************
*** 153,159 ****
  		} while ((++dc)->text[0]);
  		
! 		for(s=_cmd_buffer;*s;s++)
  			if (*s==32) { *s=0; break; }
! 		printf("Invalid command '%s'. Type 'help' for a list of available commands.\n", _cmd_buffer);
  	} while (1);
  }
--- 181,187 ----
  		} while ((++dc)->text[0]);
  		
! 		for(s=buf;*s;s++)
  			if (*s==32) { *s=0; break; }
! 		printf("Invalid command '%s'. Type 'help' for a list of available commands.\n", buf);
  	} while (1);
  }
***************
*** 192,194 ****
  	}
  	printf("+---------------------------------+\n");
! }
\ No newline at end of file
--- 220,222 ----
  	}
  	printf("+---------------------------------+\n");
! }





More information about the Scummvm-git-logs mailing list