Merge branch 'master' of git.dcc.fc.up.pt:yap-6.3

This commit is contained in:
U-vsc-PC\vsc 2014-02-26 22:16:54 +00:00
commit 50eb140deb
13 changed files with 558 additions and 340 deletions

View File

@ -1,4 +1,4 @@
/* $Id$ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -20,7 +20,7 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define WINDOWS_LEAN_AND_MEAN 1 #define WINDOWS_LEAN_AND_MEAN 1
@ -43,6 +43,10 @@ typedef enum
CMD_ANSI CMD_ANSI
} astate; } astate;
typedef enum
{ HDL_CONSOLE = 0,
HDL_FILE
} htype;
typedef struct typedef struct
{ int magic; { int magic;
@ -57,6 +61,7 @@ typedef struct
int argstat; int argstat;
astate cmdstat; /* State for sequence processing */ astate cmdstat; /* State for sequence processing */
WORD def_attr; /* Default attributes */ WORD def_attr; /* Default attributes */
htype handletype; /* Type of stream handle */
} ansi_stream; } ansi_stream;
@ -85,11 +90,19 @@ flush_ansi(ansi_stream *as)
{ BOOL rc; { BOOL rc;
DWORD done; DWORD done;
rc = WriteConsoleW(as->hConsole, if (as->handletype == HDL_CONSOLE)
&as->buffer[written], { rc = WriteConsoleW(as->hConsole,
(DWORD)(as->buffered-written), &as->buffer[written],
&done, (DWORD)(as->buffered-written),
NULL); &done,
NULL);
} else
{ rc = WriteFile(as->hConsole,
&as->buffer[written],
(DWORD)(as->buffered-written),
&done,
NULL);
}
if ( rc ) if ( rc )
{ written += done; { written += done;
@ -347,7 +360,20 @@ control_ansi(void *handle, int op, void *data)
case SIO_SETENCODING: case SIO_SETENCODING:
return -1; /* We cannot change the encoding! */ return -1; /* We cannot change the encoding! */
case SIO_LASTERROR: case SIO_LASTERROR:
return 0; /* TBD */ { const char *s;
if ( (s = WinError()) );
{ const char **sp = data;
*sp = s;
return 0;
}
return -1;
}
case SIO_GETFILENO:
{ int *fp = data;
*fp = (int)(intptr_t)as->saved_handle; /* is one of 0,1,2 */
return 0;
}
default: default:
return -1; return -1;
} }
@ -402,10 +428,16 @@ error:
static int static int
wrap_console(HANDLE h, IOSTREAM *s, IOFUNCTIONS *funcs) wrap_console(HANDLE h, IOSTREAM *s, IOFUNCTIONS *funcs)
{ ansi_stream *as; { ansi_stream *as;
DWORD mode;
as = PL_malloc(sizeof(*as)); as = PL_malloc(sizeof(*as));
memset(as, 0, sizeof(*as)); memset(as, 0, sizeof(*as));
if (GetConsoleMode(h, &mode))
as->handletype = HDL_CONSOLE;
else
as->handletype = HDL_FILE;
as->hConsole = h; as->hConsole = h;
as->pStream = s; as->pStream = s;
as->saved_handle = s->handle; as->saved_handle = s->handle;
@ -413,6 +445,7 @@ wrap_console(HANDLE h, IOSTREAM *s, IOFUNCTIONS *funcs)
s->handle = as; s->handle = as;
s->encoding = ENC_WCHAR; s->encoding = ENC_WCHAR;
s->functions = funcs; s->functions = funcs;
s->flags &= ~SIO_FILE;
return TRUE; return TRUE;
} }

View File

@ -1,75 +1,53 @@
# ################################################################
# default base directory for YAP installation # Makefile for the SWI-Prolog console window.
# (EROOT for architecture-dependent files) ################################################################
#
prefix = @prefix@
exec_prefix = @exec_prefix@
ROOTDIR = $(prefix)
EROOTDIR = @exec_prefix@
#
# where YAP should look for libraries
#
LIBDIR=@libdir@/Yap
#
#
CC=@CC@ -municode -DUNICODE -D_UNICODE
CPPFLAGS=@CPPFLAGS@
CFLAGS= @CFLAGS@ $(DEFS) $(CPPFLAGS) -I$(srcdir) -DRLC_VENDOR="\"YAP\""
#
#
# You shouldn't need to change what follows.
#
INSTALL=@INSTALL@
INSTALL_DATA=@INSTALL_DATA@
INSTALL_PROGRAM=@INSTALL_PROGRAM@
RANLIB=@RANLIB@
AR=@AR@
srcdir=@srcdir@ srcdir=@srcdir@
@VPATH@ @srcdir@
SOURCES= \ CC=@CC@
$(srcdir)/complete.c $(srcdir)/console.c \ LDEXE=@LDEXE@
$(srcdir)/edit.c $(srcdir)/history.c \ PLARCH=@PLARCH@
$(srcdir)/menu.c XLIBS=@XLIBS@
HEADERS= \ SOEXT=@SO_EXT@
$(srcdir)/common.h $(srcdir)/console.h \
$(srcdir)/console_i.h $(srcdir)/history.h \
$(srcdir)/menu.h
OBJECTS= complete.o console.o edit.o history.o menu.o COFLAGS=@COFLAGS@
CWFLAGS=@CWFLAGS@
CIFLAGS=@CIFLAGS@
CMFLAGS=@CMFLAGS@ -DUNICODE -D_UNICODE
CPFLAGS=
CFLAGS= $(CWFLAGS) $(COFLAGS) $(CIFLAGS) $(CMFLAGS) $(CPFLAGS)
LDFLAGS=@LDFLAGS@ $(CPFLAGS)
LIBS=-lgdi32 -lcomdlg32 PLHOME=../../..
all: ../../plterm.dll include $(srcdir)/../../common.mk
../../plterm.dll: libplterm.a OBJ= complete.o console.o edit.o history.o menu.o
$(CC) $(CFLAGS) -shared -o ../../plterm.dll \ OUT= $(PLHOME)/lib/$(PLARCH)/plterm.$(SOEXT)
-Wl,--export-all-symbols \ INCLDIR=$(PLHOME)/include
-Wl,--enable-auto-import \ HDR= $(INCLDIR)/console.h
-Wl,--whole-archive libplterm.a \
-Wl,--no-whole-archive $(LIBS) $(LDFLAGS)
libplterm.a: $(OBJECTS) $(SOURCES) $(HEADERS) all: $(OUT) $(HDR)
-rm -f libplterm.a
$(AR) rc libplterm.a $(OBJECTS)
$(RANLIB) libplterm.a
install: $(OUT): $(OBJ)
$(CC) -shared $(COFLAGS) -o $@ -Wl,--out-implib,$@.a $(OBJ) $(XLIBS)
$(HDR): $(INCLDIR)
$(INCLDIR):
mkdir -p $@
$(PLHOME)/include/console.h: $(srcdir)/console.h
cp -f $< $@
console.o: $(srcdir)/console_i.h $(srcdir)/console.h
clean: clean:
rm -f *.o *~ *.dll rm -f *.o
rm -f *~
complete.o: $(srcdir)/complete.c
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/complete.c -o complete.o
console.o: $(srcdir)/console.c
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/console.c -o console.o
history.o: $(srcdir)/history.c
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/history.c -o history.o
menu.o: $(srcdir)/menu.c
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/menu.c -o menu.o
edit.o: $(srcdir)/edit.c
$(CC) -c $(CFLAGS) $(SHLIB_CFLAGS) $(srcdir)/edit.c -o edit.o
distclean: clean
rm -f $(PLHOME)/lib/$(PLARCH)/plterm.$(SOEXT)
rm -f $(PLHOME)/lib/$(PLARCH)/plterm.$(SOEXT).a
rm -f $(INCLDIR)/console.h

View File

@ -1,4 +1,4 @@
/* $Id: common.h,v 1.1 2008-04-01 08:50:48 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,7 +19,7 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define IMODE_SWITCH_CHAR -2 #define IMODE_SWITCH_CHAR -2

View File

@ -1,4 +1,4 @@
/* $Id: complete.c,v 1.1 2008-03-27 00:41:33 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,21 +19,21 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
#include "console.h" #include "console.h"
#ifndef __TCHAR_DEFINED
typedef wint_t _TINT;
#endif
#ifndef EOS #ifndef EOS
#define EOS 0 #define EOS 0
#endif #endif
#ifndef _TINT
typedef wint_t _TINT;
#endif
static TCHAR *completion_chars = TEXT("~:\\/-."); static TCHAR *completion_chars = TEXT("~:\\/-.");
static size_t static size_t
@ -77,7 +77,7 @@ rlc_complete_file_function(RlcCompleteData data)
for( ; n < ln->point; n++) for( ; n < ln->point; n++)
{ int c = ln->data[n]; { int c = ln->data[n];
if ( c == '/' ) if ( c == '/' )
c = '\\'; c = '\\';
if ( c == '\\' ) if ( c == '\\' )
@ -108,7 +108,7 @@ rlc_complete_file_function(RlcCompleteData data)
{ _tcscpy(data->candidate, fdata.cFileName); { _tcscpy(data->candidate, fdata.cFileName);
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $Id: console.h,v 1.1 2008-04-01 08:45:42 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,7 +19,7 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#ifndef _CONSOLE_H_INCLUDED #ifndef _CONSOLE_H_INCLUDED
@ -41,21 +41,21 @@
#include <signal.h> #include <signal.h>
#include <stddef.h> #include <stddef.h>
#if __GNUC__ #ifdef _MSC_VER
#include <stdint.h>
#else
#if (_MSC_VER < 1300) #if (_MSC_VER < 1300)
typedef long intptr_t; typedef long intptr_t;
typedef unsigned long uintptr_t; typedef unsigned long uintptr_t;
#endif #endif
#else
#include <stdint.h>
#endif #endif
#define RLC_APPTIMER_ID 100 /* >=100: application timer */ #define RLC_APPTIMER_ID 100 /* >=100: application timer */
typedef struct typedef struct
{ int first; { int first;
int last; int last;
int size; /* size of the buffer */ int size; /* size of the buffer */
TCHAR *buffer; /* character buffer */ TCHAR *buffer; /* character buffer */
int flags; /* flags for the queue */ int flags; /* flags for the queue */
} rlc_queue, *RlcQueue; } rlc_queue, *RlcQueue;
@ -75,7 +75,7 @@ typedef struct
int x; /* # pixels (0: default) */ int x; /* # pixels (0: default) */
int y; /* # pixels (0: default) */ int y; /* # pixels (0: default) */
int savelines; /* # lines to save (0: default) */ int savelines; /* # lines to save (0: default) */
TCHAR face_name[32]; /* font name */ TCHAR face_name[32]; /* font name */
int font_family; /* family id */ int font_family; /* family id */
int font_size; int font_size;
int font_weight; int font_weight;
@ -94,7 +94,7 @@ typedef void (*RlcResizeHook)(int, int); /* Hook for window change */
typedef void (*RlcMenuHook)(rlc_console, const TCHAR *id); /* Hook for menu-selection */ typedef void (*RlcMenuHook)(rlc_console, const TCHAR *id); /* Hook for menu-selection */
typedef void (*RlcFreeDataHook)(uintptr_t data); /* release data */ typedef void (*RlcFreeDataHook)(uintptr_t data); /* release data */
#if defined(_WINDOWS_) || defined(_WINDOWS_H) /* <windows.h> is included */ #ifdef __WINDOWS__ /* <windows.h> is included */
/* rlc_color(which, ...) */ /* rlc_color(which, ...) */
#define RLC_WINDOW (0) /* window background */ #define RLC_WINDOW (0) /* window background */
#define RLC_TEXT (1) /* text color */ #define RLC_TEXT (1) /* text color */
@ -116,7 +116,7 @@ typedef LRESULT (*RlcMessageHook)(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam); WPARAM wParam, LPARAM lParam);
_export RlcMessageHook rlc_message_hook(RlcMessageHook hook); _export RlcMessageHook rlc_message_hook(RlcMessageHook hook);
#endif /*_WINDOWS_*/ #endif /*__WINDOWS__*/
_export RlcUpdateHook rlc_update_hook(RlcUpdateHook updatehook); _export RlcUpdateHook rlc_update_hook(RlcUpdateHook updatehook);
_export RlcTimerHook rlc_timer_hook(RlcTimerHook timerhook); _export RlcTimerHook rlc_timer_hook(RlcTimerHook timerhook);
@ -182,9 +182,9 @@ _export int rlc_set(rlc_console c, int what,
typedef struct _line typedef struct _line
{ rlc_mark origin; /* origin of edit */ { rlc_mark origin; /* origin of edit */
size_t point; /* location of the caret */ size_t point; /* location of the caret */
size_t size; /* # characters in buffer */ size_t size; /* # characters in buffer */
size_t allocated; /* # characters allocated */ size_t allocated; /* # characters allocated */
size_t change_start; /* start of change */ size_t change_start; /* start of change */
int complete; /* line is completed */ int complete; /* line is completed */
int reprompt; /* repeat the prompt */ int reprompt; /* repeat the prompt */
@ -199,6 +199,8 @@ typedef struct _line
#define COMPLETE_ENUMERATE 1 #define COMPLETE_ENUMERATE 1
#define COMPLETE_CLOSE 2 #define COMPLETE_CLOSE 2
struct _complete_data;
typedef int (*RlcCompleteFunc)(struct _complete_data *); typedef int (*RlcCompleteFunc)(struct _complete_data *);
typedef struct _complete_data typedef struct _complete_data
@ -221,5 +223,9 @@ _export int rlc_complete_file_function(RlcCompleteData data);
_export void rlc_init_history(rlc_console c, int size); _export void rlc_init_history(rlc_console c, int size);
_export void rlc_add_history(rlc_console c, const TCHAR *line); _export void rlc_add_history(rlc_console c, const TCHAR *line);
_export int rlc_bind(int chr, const char *fname); _export int rlc_bind(int chr, const char *fname);
_export int rlc_for_history(
rlc_console b,
int (*handler)(void *ctx, int no, const TCHAR *line),
void *ctx);
#endif /* _CONSOLE_H_INCLUDED */ #endif /* _CONSOLE_H_INCLUDED */

View File

@ -1,4 +1,4 @@
/* $Id: console_i.h,v 1.1 2008-04-01 08:50:44 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,7 +19,7 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -45,7 +45,7 @@ typedef struct _history
#define ANSI_MAX_ARGC 10 /* Ansi-escape sequence argv */ #define ANSI_MAX_ARGC 10 /* Ansi-escape sequence argv */
#define MAXPROMPT 80 /* max size of prompt */ #define MAXPROMPT 80 /* max size of prompt */
#define OQSIZE 4096 /* output queue size */ #define OQSIZE 4096 /* output queue size */
#define MAX_USER_VALUES 10 /* max user data-handles */ #define MAX_USER_VALUES 10 /* max user data-handles */
typedef struct lqueued typedef struct lqueued
@ -53,8 +53,29 @@ typedef struct lqueued
struct lqueued* next; /* Next in queue */ struct lqueued* next; /* Next in queue */
} lqueued, *LQueued; } lqueued, *LQueued;
typedef unsigned short text_flags;
#define ANSI_COLOR_DEFAULT 31
#define TF_FG(f) ((f)&0x1f) /* foreground */
#define TF_BG(f) (((f)>>5)&0x1f) /* background */
#define TF_BOLD(f) ((f)&(1<<10)) /* bold */
#define TF_UNDERLINE(f) ((f)&(1<<11)) /* underline */
#define TF_DEFAULT (ANSI_COLOR_DEFAULT | ANSI_COLOR_DEFAULT<<5)
#define TF_SET_FG(f,c) (((f)&~0x1f)|(c))
#define TF_SET_BG(f,c) (((f)&~(0x1f<<5))|((c)<<5))
#define TF_SET_BOLD(f,v) (((f)&~(1<<10))|((v)<<10))
#define TF_SET_UNDERLINE(f,v) (((f)&~(1<<11))|((v)<<11))
typedef struct typedef struct
{ TCHAR * text; /* the storage */ { TCHAR code; /* character code */
text_flags flags; /* flags for the text */
} text_char;
typedef struct
{ text_char *text; /* the storage */
unsigned short size; /* #characters in line */ unsigned short size; /* #characters in line */
unsigned adjusted : 1; /* line has been adjusted? */ unsigned adjusted : 1; /* line has been adjusted? */
unsigned changed : 1; /* line needs redraw */ unsigned changed : 1; /* line needs redraw */
@ -78,7 +99,7 @@ typedef struct
int caret_y; /* its line */ int caret_y; /* its line */
int window_start; /* start line of the window */ int window_start; /* start line of the window */
int window_size; /* #lines on the window */ int window_size; /* #lines on the window */
TextLine lines; /* the actual lines */ TextLine lines; /* the actual lines */
int sel_unit; /* SEL_CHAR, SEL_WORD, SEL_LINE */ int sel_unit; /* SEL_CHAR, SEL_WORD, SEL_LINE */
int sel_org_line; /* line origin of the selection */ int sel_org_line; /* line origin of the selection */
int sel_org_char; /* char origin of the selection */ int sel_org_char; /* char origin of the selection */
@ -100,6 +121,8 @@ typedef struct
COLORREF background; /* Background color */ COLORREF background; /* Background color */
COLORREF sel_foreground; /* Selection foreground */ COLORREF sel_foreground; /* Selection foreground */
COLORREF sel_background; /* Selection background */ COLORREF sel_background; /* Selection background */
COLORREF ansi_color[16]; /* ANSI colors (8 normal + 8 bright) */
text_flags sgr_flags; /* Current SGR flags */
int cw; /* character width */ int cw; /* character width */
int ch; /* character height */ int ch; /* character height */
int cb; /* baseline */ int cb; /* baseline */
@ -139,7 +162,7 @@ typedef struct
DWORD console_thread_id; /* I/O thread id */ DWORD console_thread_id; /* I/O thread id */
DWORD application_thread_id; DWORD application_thread_id;
HWND kill_window; /* window in app thread for destroy */ HWND kill_window; /* window in app thread for destroy */
user_data values[MAX_USER_VALUES]; /* associated user data */ user_data values[MAX_USER_VALUES]; /* associated user data */
} rlc_data, *RlcData; } rlc_data, *RlcData;

View File

@ -1,4 +1,4 @@
/* $Id: edit.c,v 1.1 2008-03-27 00:41:33 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,13 +19,13 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define _MAKE_DLL 1
#undef _export
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
#define _MAKE_DLL 1
#undef _export
#include "console.h" #include "console.h"
#include "console_i.h" #include "console_i.h"
#include "common.h" #include "common.h"
@ -127,7 +127,7 @@ delete(Line ln, size_t from, size_t len)
_tcsncpy(&ln->data[from], &ln->data[from+len], ln->size - (from+len)); _tcsncpy(&ln->data[from], &ln->data[from+len], ln->size - (from+len));
ln->size -= len; ln->size -= len;
} }
/******************************* /*******************************
@ -232,7 +232,7 @@ forward_word(Line ln, int chr)
static void static void
backward_delete_word(Line ln, int chr) backward_delete_word(Line ln, int chr)
{ size_t from = back_word(ln, ln->point); { size_t from = back_word(ln, ln->point);
memmove(&ln->data[from], &ln->data[ln->point], memmove(&ln->data[from], &ln->data[ln->point],
(ln->size - ln->point)*sizeof(TCHAR)); (ln->size - ln->point)*sizeof(TCHAR));
ln->size -= ln->point - from; ln->size -= ln->point - from;
@ -244,7 +244,7 @@ backward_delete_word(Line ln, int chr)
static void static void
forward_delete_word(Line ln, int chr) forward_delete_word(Line ln, int chr)
{ size_t to = forw_word(ln, ln->point); { size_t to = forw_word(ln, ln->point);
memmove(&ln->data[ln->point], &ln->data[to], (ln->size - to)*sizeof(TCHAR)); memmove(&ln->data[ln->point], &ln->data[to], (ln->size - to)*sizeof(TCHAR));
ln->size -= to - ln->point; ln->size -= to - ln->point;
changed(ln, ln->point); changed(ln, ln->point);
@ -258,7 +258,7 @@ transpose_chars(Line ln, int chr)
ln->data[ln->point-1] = ln->data[ln->point]; ln->data[ln->point-1] = ln->data[ln->point];
ln->data[ln->point] = c0; ln->data[ln->point] = c0;
changed(ln, ln->point-1); changed(ln, ln->point-1);
} }
} }
@ -291,7 +291,7 @@ empty_line(Line ln, int chr)
static void static void
enter(Line ln, int chr) enter(Line ln, int chr)
{ ln->point = ln->size; { ln->point = ln->size;
#ifdef DOS_CRNL #ifdef DOS_CRNL
make_room(ln, 2); make_room(ln, 2);
ln->data[ln->point++] = '\r'; ln->data[ln->point++] = '\r';
ln->data[ln->point++] = '\n'; ln->data[ln->point++] = '\n';
@ -325,7 +325,7 @@ delete_character_or_eof(Line ln, int chr)
static void static void
undefined(Line ln, int chr) undefined(Line ln, int chr)
{ {
} }
@ -442,7 +442,7 @@ complete(Line ln, int chr)
} }
data->call_type = COMPLETE_CLOSE; data->call_type = COMPLETE_CLOSE;
(*data->function)(data); (*data->function)(data);
delete(ln, data->replace_from, patlen); delete(ln, data->replace_from, patlen);
ln->point = data->replace_from; ln->point = data->replace_from;
make_room(ln, ncommon); make_room(ln, ncommon);
@ -487,7 +487,7 @@ list_completions(Line ln, int chr)
if ( nmatches > COMPLETE_MAX_MATCHES ) if ( nmatches > COMPLETE_MAX_MATCHES )
{ TCHAR *msg = _T("\r\n! Too many matches\r\n"); { TCHAR *msg = _T("\r\n! Too many matches\r\n");
while(*msg) while(*msg)
rlc_putchar(ln->console, *msg++); rlc_putchar(ln->console, *msg++);
ln->reprompt = TRUE; ln->reprompt = TRUE;
@ -511,7 +511,7 @@ list_completions(Line ln, int chr)
{ len++; { len++;
rlc_putchar(ln->console, *s++); rlc_putchar(ln->console, *s++);
} }
rlc_free(buf[n++]); rlc_free(buf[n++]);
if ( n % cols == 0 ) if ( n % cols == 0 )
@ -552,7 +552,7 @@ update_display(Line ln)
{ if ( ln->reprompt ) { if ( ln->reprompt )
{ const TCHAR *prompt = rlc_prompt(ln->console, NULL); { const TCHAR *prompt = rlc_prompt(ln->console, NULL);
const TCHAR *s = prompt; const TCHAR *s = prompt;
rlc_putchar(ln->console, '\r'); rlc_putchar(ln->console, '\r');
while(*s) while(*s)
rlc_putchar(ln->console, *s++); rlc_putchar(ln->console, *s++);
@ -646,7 +646,7 @@ init_dispatch_table()
dispatch_table[n] = insert_self; dispatch_table[n] = insert_self;
for(n=0; n<256; n++) for(n=0; n<256; n++)
dispatch_meta[n] = undefined; dispatch_meta[n] = undefined;
bind_actions(); bind_actions();
done = TRUE; done = TRUE;
@ -704,7 +704,7 @@ int
rlc_bind(int chr, const char *fname) rlc_bind(int chr, const char *fname)
{ if ( chr >= 0 && chr <= 256 ) { if ( chr >= 0 && chr <= 256 )
{ Action a = actions; { Action a = actions;
for( ; a->name; a++ ) for( ; a->name; a++ )
{ if ( strcmp(a->name, fname) == 0 ) { if ( strcmp(a->name, fname) == 0 )
{ if ( chr > META_OFFSET ) { if ( chr > META_OFFSET )

View File

@ -1,4 +1,4 @@
/* $Id: history.c,v 1.1 2008-03-27 00:41:33 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,13 +19,13 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define _MAKE_DLL 1
#undef _export
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
#define _MAKE_DLL 1
#undef _export
#include "console.h" /* public stuff */ #include "console.h" /* public stuff */
#include "console_i.h" /* internal stuff */ #include "console_i.h" /* internal stuff */
#include <string.h> #include <string.h>
@ -100,7 +100,7 @@ rlc_add_history(rlc_console c, const TCHAR *line)
{ b->history.current = -1; { b->history.current = -1;
return; /* same as last line added */ return; /* same as last line added */
} }
if ( i == b->history.tail ) /* this one is lost */ if ( i == b->history.tail ) /* this one is lost */
b->history.tail = next(b, b->history.tail); b->history.tail = next(b, b->history.tail);
b->history.head = i; b->history.head = i;
@ -120,6 +120,25 @@ rlc_add_history(rlc_console c, const TCHAR *line)
} }
int
rlc_for_history(rlc_console c,
int (*handler)(void *ctx, int no, const TCHAR *line),
void *ctx)
{ RlcData b = rlc_get_data(c);
int here = b->history.head;
int no = 1;
for( ; here != b->history.tail; here = prev(b, here))
{ int rc;
if ( (rc=(*handler)(ctx, no++, b->history.lines[here])) != 0 )
return rc;
}
return 0;
}
int int
rlc_at_head_history(RlcData b) rlc_at_head_history(RlcData b)
{ return b->history.current == -1 ? TRUE : FALSE; { return b->history.current == -1 ? TRUE : FALSE;

View File

@ -1,4 +1,4 @@
/* $Id: history.h,v 1.1 2008-04-01 08:52:50 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,7 +19,7 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/* history.c */ /* history.c */

View File

@ -1,4 +1,4 @@
/* $Id: menu.c,v 1.1 2008-03-27 00:41:33 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,12 +19,13 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <windows.h> #include <windows.h>
#include <tchar.h> #include <tchar.h>
#define _MAKE_DLL #define _MAKE_DLL 1
#undef _export
#include "console.h" #include "console.h"
#include "console_i.h" #include "console_i.h"
#include "menu.h" #include "menu.h"
@ -83,7 +84,7 @@ lookupMenuLabel(const TCHAR *label)
llen = _tcslen(label); llen = _tcslen(label);
menuids[nmenus] = rlc_malloc((llen+1)*sizeof(TCHAR)); menuids[nmenus] = rlc_malloc((llen+1)*sizeof(TCHAR));
_tcsncpy(menuids[nmenus], label, llen+1); _tcsncpy(menuids[nmenus], label, llen+1);
return nmenus++ + IDM_USER; return nmenus++ + IDM_USER;
} }
@ -109,7 +110,7 @@ insertMenu(HMENU in, const TCHAR *label, const TCHAR *before)
AppendMenu(in, MF_SEPARATOR, 0, NULL); AppendMenu(in, MF_SEPARATOR, 0, NULL);
else else
{ UINT id = lookupMenuLabel(label); { UINT id = lookupMenuLabel(label);
AppendMenu(in, MF_STRING, id, label); AppendMenu(in, MF_STRING, id, label);
} }
} else } else
@ -199,15 +200,15 @@ rlc_add_menu_bar(HWND cwin)
/*append_builtin(edit, IDM_CUT);*/ /*append_builtin(edit, IDM_CUT);*/
append_builtin(edit, IDM_COPY); append_builtin(edit, IDM_COPY);
append_builtin(edit, IDM_PASTE); append_builtin(edit, IDM_PASTE);
append_builtin(settings, IDM_FONT); append_builtin(settings, IDM_FONT);
append_builtin(run, IDM_BREAK); append_builtin(run, IDM_BREAK);
AppendMenu(menu, MF_POPUP, (UINT)file, _T("&File")); AppendMenu(menu, MF_POPUP, (UINT_PTR)file, _T("&File"));
AppendMenu(menu, MF_POPUP, (UINT)edit, _T("&Edit")); AppendMenu(menu, MF_POPUP, (UINT_PTR)edit, _T("&Edit"));
AppendMenu(menu, MF_POPUP, (UINT)settings, _T("&Settings")); AppendMenu(menu, MF_POPUP, (UINT_PTR)settings, _T("&Settings"));
AppendMenu(menu, MF_POPUP, (UINT)run, _T("&Run")); AppendMenu(menu, MF_POPUP, (UINT_PTR)run, _T("&Run"));
SetMenu(cwin, menu); SetMenu(cwin, menu);
} }
@ -218,13 +219,22 @@ rlc_add_menu_bar(HWND cwin)
#define MEN_MAGIC 0x6c4a58e0 #define MEN_MAGIC 0x6c4a58e0
typedef struct menu_data
{ intptr_t magic; /* safety */
const TCHAR *menu; /* menu to operate on */
const TCHAR *label; /* new label */
const TCHAR *before; /* add before this one */
int rc; /* result */
} menu_data;
void void
rlc_menu_action(rlc_console c, menu_data *data) rlc_menu_action(rlc_console c, menu_data *data)
{ RlcData b = rlc_get_data(c); { RlcData b = rlc_get_data(c);
if ( !data || !data->magic == MEN_MAGIC ) if ( !data || !data->magic == MEN_MAGIC )
return; return;
if ( data->menu ) /* rlc_insert_menu_item() */ if ( data->menu ) /* rlc_insert_menu_item() */
{ HMENU popup; { HMENU popup;
@ -255,7 +265,7 @@ rlc_menu_action(rlc_console c, menu_data *data)
info.hSubMenu = CreatePopupMenu(); info.hSubMenu = CreatePopupMenu();
info.dwTypeData = (TCHAR *)data->label; info.dwTypeData = (TCHAR *)data->label;
info.cch = (int)_tcslen(data->label); info.cch = (int)_tcslen(data->label);
InsertMenuItem(mb, bid, TRUE, &info); InsertMenuItem(mb, bid, TRUE, &info);
/* force redraw; not automatic! */ /* force redraw; not automatic! */
DrawMenuBar(hwnd); DrawMenuBar(hwnd);

View File

@ -1,4 +1,4 @@
/* $Id: menu.h,v 1.1 2008-04-01 08:50:44 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,7 +19,7 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
/* see also console.c */ /* see also console.c */
@ -35,14 +35,7 @@
#define IDM_BREAK 14 #define IDM_BREAK 14
#define IDM_FONT 15 #define IDM_FONT 15
typedef struct menu_data struct menu_data;
{ intptr_t magic; /* safety */
const TCHAR *menu; /* menu to operate on */
const TCHAR *label; /* new label */
const TCHAR *before; /* add before this one */
int rc; /* result */
} menu_data;
const TCHAR *lookupMenuId(UINT id); const TCHAR *lookupMenuId(UINT id);
void rlc_add_menu_bar(HWND win); void rlc_add_menu_bar(HWND win);

View File

@ -1,4 +1,4 @@
/* $Id: registry.c,v 1.1 2008-03-27 00:41:33 vsc Exp $ /* $Id$
Part of SWI-Prolog Part of SWI-Prolog
@ -19,7 +19,7 @@
You should have received a copy of the GNU Lesser General Public You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <windows.h> #include <windows.h>