[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[not a bug] hooking an AI into libncurses
From: |
Johnicholas Hines |
Subject: |
[not a bug] hooking an AI into libncurses |
Date: |
Thu, 25 Feb 2010 13:33:23 -0500 |
Hi.
I'm trying to create a modified libncurses so that an AI can "see"
what is on the screen, and "type" commands. Then I inject the modified
libncurses into arbitrary curses-using binaries via LD_PRELOAD. The
goal is to replicate Rog-o-matic -
http://www.cs.princeton.edu/~appel/papers/rogomatic.html - a 1984
expert system that played Rogue.
The only way that I've found to hook the AI's "eyes" into libncurses
is via _tracedmp "newscr". However, that means turning on tracing,
which puts lots of information out into the trace file, and it seems a
little clumsy.
Is there a better place to modify to see each new screen?
Johnicholas
diff -Naur a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c
--- a/ncurses/trace/lib_tracedmp.c 2008-08-16 15:30:56.000000000 -0400
+++ b/ncurses/trace/lib_tracedmp.c 2010-02-23 12:36:54.000000000 -0500
@@ -38,6 +38,7 @@
#include <curses.priv.h>
#include <ctype.h>
+#include "soar-curses-link.h"
MODULE_ID("$Id: lib_tracedmp.c,v 1.31 2008/08/16 19:30:56 tom Exp $")
@@ -92,6 +93,11 @@
? '.'
: UChar(test))
: '?');
+
+ if (strcmp(name, "newscr") == 0) {
+ set(ep[j], n, j);
+ }
+
}
ep[j] = '\0';
_tracef("%s[%2d] %3ld%3ld ='%s'",
diff -Naur a/ncurses/base/lib_initscr.c b/ncurses/base/lib_initscr.c
--- a/ncurses/base/lib_initscr.c 2008-08-16 17:20:48.000000000 -0400
+++ b/ncurses/base/lib_initscr.c 2010-02-23 09:34:26.000000000 -0500
@@ -45,6 +45,8 @@
#include <sys/termio.h> /* needed for ISC */
#endif
+#include "soar-curses-link.h"
+
MODULE_ID("$Id: lib_initscr.c,v 1.38 2008/08/16 21:20:48 Werner.Fink Exp $")
NCURSES_EXPORT(WINDOW *)
@@ -95,5 +97,10 @@
result = stdscr;
_nc_unlock_global(curses);
+ // Turns on tracing.
+ trace(TRACE_ORDINARY);
+ // Initialize Soar.
+ create_link();
+
returnWin(result);
}
diff -Naur a/ncurses/base/lib_getch.c b/ncurses/base/lib_getch.c
--- a/ncurses/base/lib_getch.c 2008-09-20 15:46:13.000000000 -0400
+++ b/ncurses/base/lib_getch.c 2010-02-23 11:51:28.000000000 -0500
@@ -44,6 +44,7 @@
MODULE_ID("$Id: lib_getch.c,v 1.99 2008/09/20 19:46:13 tom Exp $")
#include <fifo_defs.h>
+#include "soar-curses-link.h"
#if USE_REENTRANT
#define GetEscdelay(sp) (sp)->_ESCDELAY
@@ -553,13 +554,15 @@
unsigned long value;
T((T_CALLED("wgetch(%p)"), win));
- code = _nc_wgetch(win,
+ /*
+ code = _nc_wgetch(win,
&value,
_nc_use_meta(win)
EVENTLIST_2nd((_nc_eventlist *) 0));
if (code != ERR)
code = value;
- returnCode(code);
+ */
+ returnCode(get());
}
/*
diff -Naur a/ncurses/base/lib_endwin.c b/ncurses/base/lib_endwin.c
--- a/ncurses/base/lib_endwin.c 2000-12-09 21:43:27.000000000 -0500
+++ b/ncurses/base/lib_endwin.c 2010-02-23 09:49:22.000000000 -0500
@@ -40,6 +40,7 @@
#include <curses.priv.h>
#include <term.h>
+#include "soar-curses-link.h"
MODULE_ID("$Id: lib_endwin.c,v 1.19 2000/12/10 02:43:27 tom Exp $")
@@ -53,6 +54,7 @@
SP->_mouse_wrap(SP);
_nc_screen_wrap();
_nc_mvcur_wrap(); /* wrap up cursor addressing */
+ destroy_link();
returnCode(reset_shell_mode());
}
diff -Naur a/ncurses/Makefile.in b/ncurses/Makefile.in
--- a/ncurses/Makefile.in 2008-10-18 10:11:54.000000000 -0400
+++ b/ncurses/Makefile.in 2010-02-21 19:08:05.000000000 -0500
@@ -88,7 +88,7 @@
CFLAGS = @CFLAGS@
INCDIR = $(srcdir)/../include
-CPPFLAGS = -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) @CPPFLAGS@
+CPPFLAGS = -DHAVE_CONFIG_H -I../ncurses -I$(srcdir) -I../../ @CPPFLAGS@
CCFLAGS = $(CPPFLAGS) $(CFLAGS)
@@ -113,7 +113,21 @@
CFLAGS_DEFAULT = $(address@hidden@)
LINK = $(LIBTOOL)
-LDFLAGS = @LDFLAGS@ @LD_MODEL@ @LIBS@
+
+SOAR_LIBS += ../../soar-curses-link.o
+SOAR_LIBS += -L../../SoarSuite/out/lib
+SOAR_LIBS += -lClientSML
+SOAR_LIBS += -lConnectionSML
+SOAR_LIBS += -lElementXML
+SOAR_LIBS += -lSoarKernelSML
+SOAR_LIBS += -lSoarKernel
+SOAR_LIBS += -lCommandLineInterface
+SOAR_LIBS += -ldl
+SOAR_LIBS += -lpthread
+SOAR_LIBS += -lsqlite3
+SOAR_LIBS += -lstdc++
+
+LDFLAGS = @LDFLAGS@ @LD_MODEL@ @LIBS@ $(SOAR_LIBS)
SHLIB_DIRS = -L../lib
SHLIB_LIST = $(SHLIB_DIRS) @SHLIB_LIST@
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [not a bug] hooking an AI into libncurses,
Johnicholas Hines <=