Skip to content
Snippets Groups Projects
Commit 05ac5124 authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

readline module

Rev: src/modules/readlinemod/Makefile.src:1.1
Rev: src/modules/readlinemod/configure.in:1.1
Rev: src/modules/readlinemod/readline_machine.h.in:1.1
Rev: src/modules/readlinemod/readlinemod.c:1.1
parent e43b7a64
No related merge requests found
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)
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 )
#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
/*\
||| 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) { }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment