diff --git a/src/modules/readlinemod/Makefile.src b/src/modules/readlinemod/Makefile.src new file mode 100644 index 0000000000000000000000000000000000000000..46940d347237f433b766176f8936b2d3e964d638 --- /dev/null +++ b/src/modules/readlinemod/Makefile.src @@ -0,0 +1,19 @@ +SRCDIR=@srcdir@ +VPATH=@srcdir@:@srcdir@/../..:../.. +PREFLAGS=-I. -I$(SRCDIR) -I$(SRCDIR)/../.. -I../.. +CFLAGS=$(PREFLAGS) $(OTHERFLAGS) + +FILES=readlinemod.o +LIB=readlinemod.a + +$(LIB): $(FILES) + -rm -f $(LIB) + ar cq $(LIB) $(FILES) + -@RANLIB@ $(LIB) + echo >linker_options @LIBS@ + +clean: + -rm -f *.o *.a + +depend: + gcc -MM $(PREFLAGS) $(SRCDIR)/*.c | $(FIXDEP) $(SRCDIR) diff --git a/src/modules/readlinemod/configure.in b/src/modules/readlinemod/configure.in new file mode 100644 index 0000000000000000000000000000000000000000..64b90a5b5b19f9c8699b34aff6ecb86e4f6dd902 --- /dev/null +++ b/src/modules/readlinemod/configure.in @@ -0,0 +1,15 @@ +AC_INIT(readlinemod.c) +AC_CONFIG_HEADER(readline_machine.h) + +AC_PROG_CC +AC_PROG_RANLIB +AC_SUBST(RANLIB) + +AC_CHECK_HEADERS(readline.h) +AC_CHECK_HEADERS(history.h) +AC_CHECK_LIB(termcap, tputs) +AC_CHECK_LIB(readline, readline) + +AC_OUTPUT(Makefile,echo FOO >stamp-h ) + + diff --git a/src/modules/readlinemod/readline_machine.h.in b/src/modules/readlinemod/readline_machine.h.in new file mode 100644 index 0000000000000000000000000000000000000000..df03aee30d128790f662c98d4987327f0ff1d090 --- /dev/null +++ b/src/modules/readlinemod/readline_machine.h.in @@ -0,0 +1,16 @@ +#ifndef GDBM_MACHINE_H +#define GDBM_MACHINE_H + +/* Define this if you have <readline.h> */ +#undef HAVE_READLINE_H + +/* Define this if you have <history.h> */ +#undef HAVE_HISTORY_H + +/* Define this if you have -lreadline */ +#undef HAVE_LIBREADLINE + +/* Define this if you have -ltermcap */ +#undef HAVE_LIBTERMCAP + +#endif diff --git a/src/modules/readlinemod/readlinemod.c b/src/modules/readlinemod/readlinemod.c new file mode 100644 index 0000000000000000000000000000000000000000..a84802d7757b7d10c50993d7fbda8937722bafc4 --- /dev/null +++ b/src/modules/readlinemod/readlinemod.c @@ -0,0 +1,90 @@ +/*\ +||| This file a part of uLPC, and is copyright by Fredrik Hubinette +||| uLPC is distributed as GPL (General Public License) +||| See the files COPYING and DISCLAIMER for more information. +\*/ +#include "global.h" +#include "readline_machine.h" +#include "types.h" +#include "interpret.h" +#include "svalue.h" +#include "stralloc.h" +#include "array.h" +#include "object.h" +#include "macros.h" + +#if !defined(HAVE_READLINE_H) || !defined(HAVE_HISTORY_H) +#undef HAVE_LIBREADLINE +#endif + +#ifdef HAVE_LIBREADLINE + +#include <readline.h> +#include <history.h> + +static void f_readline(INT32 args) +{ + char *r; + if(args < 1) + error("Too few arguments to readline().\n"); + + if(sp[-args].type != T_STRING) + error("Bad argument 1 to readline()\n"); + + r=readline(sp[-args].u.string->str); + pop_n_elems(args); + if(r) + { + if(*r) add_history(r); + push_string(make_shared_string(r)); + free(r); + } else { + push_int(0); + } +} + +#else + +#include <stdio.h> + +#define BLOCK 16384 + +static void f_readline(INT32 args) +{ + char line[BLOCK]; + char *r; + if(args < 1) + error("Too few arguments to readline().\n"); + + if(sp[-args].type != T_STRING) + error("Bad argument 1 to readline()\n"); + + puts(sp[-args].u.string->str); + + pop_n_elems(args); + if(fgets(line,BLOCK,stdin)) + { + INT32 len; + if(len=strlen(line)) + { + if(line[len-1]=='\n') + { + push_string(make_shared_binary_string(line,len-1)); + return; + } + } + } + push_int(0); +} + +#endif + +void init_readlinemod_efuns(void) +{ + rl_bind_key('\t', rl_insert); + add_efun("readline",f_readline,"function(string:string)",OPT_SIDE_EFFECT); +} +void exit_readlinemod(void) {} +void init_readlinemod_programs(void) { } + +