[uim-commit] r1182 - in trunk: . scm uim
omote at freedesktop.org
omote at freedesktop.org
Thu Aug 11 05:53:50 EST 2005
Author: omote
Date: 2005-08-10 12:53:47 -0700 (Wed, 10 Aug 2005)
New Revision: 1182
Added:
trunk/uim/editline.c
trunk/uim/editline.h
Modified:
trunk/configure.ac
trunk/scm/uim-sh.scm
trunk/uim/Makefile.am
trunk/uim/uim-sh.c
Log:
* This commit enables line editing and history in uim-sh. You can use them
by 'uim-sh -r editline'.
* configure.ac: Merge from r5rs branch which support libedit.
* uim/Makefile.am: Add editline.[ch] entry.
* uim/editline.[ch]: New file for supporting libedit history and line editing.
* uim/uim-sh.c: Add support of libedit.
* scm/uim-sh.scm: Ditto.
Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac 2005-08-10 19:47:22 UTC (rev 1181)
+++ trunk/configure.ac 2005-08-10 19:53:47 UTC (rev 1182)
@@ -485,7 +485,36 @@
AC_SUBST(EBLIB_LIBS)
+# Check whether user wants libedit support
+# This code was based on openssh-4.1p1
+AC_ARG_WITH(libedit,
+AC_HELP_STRING([--with-libedit[=DIR], Enable libedit support]),
+ [
+ if test "x$with_libedit" != "xno"; then
+ use_libedit="yes"
+ libedit_path="$withval"
+ fi
+ ],
+ [use_libedit="yes"])
+
+ if test "x$use_libedit" != "xno"; then
+ saved_CPPFLAGS=$CPPFLAGS
+ saved_LDFLAGS=$LDFLAGS
+ CPPFLAGS="${CPPFLAGS} -I$libedit_path/include"
+ LDFLAGS="${LDFLAGS} -L$libedit_path/lib"
+ AC_CHECK_LIB(edit, el_init,
+ [
+ LIBEDIT_LIBS="-ledit -lcurses -l$libedit_path/lib"
+ AC_SUBST(LIBEDIT_LIBS)
+ ], [
+ AC_MSG_WARN("libedit not found. Disabled...")
+ use_libedit="no"
+ ])
+ CPPFLAGS=$saved_CPPFLAGS
+ LDFLAGS=$saved_LDFLAGS
+fi
+
AM_CONDITIONAL(M17NLIB, test x$use_m17nlib = xyes)
AM_CONDITIONAL(SCIM, test x$use_scim = xyes)
AM_CONDITIONAL(ANTHY, test x$use_anthy = xyes)
@@ -502,6 +531,7 @@
AM_CONDITIONAL(XIM, test x$use_xim = xyes)
AM_CONDITIONAL(DICT, test x$use_dict = xyes)
AM_CONDITIONAL(EB, test x$use_eb = xyes)
+AM_CONDITIONAL(LIBEDIT, test x$use_libedit = xyes)
AM_CONDITIONAL(DEBUG, test x$enable_debug = xyes)
AM_CONDITIONAL(COMPAT_SCM, test x$enable_compat_scm = xyes)
AM_CONDITIONAL(COMPAT_TABLE, test x$enable_compat_table = xyes)
@@ -766,6 +796,7 @@
XIM : ${use_xim}
DICT : ${use_dict}
EB : ${use_eb}
+ libedit : ${use_libedit}
Default toolkit : ${default_toolkit}
])
Modified: trunk/scm/uim-sh.scm
===================================================================
--- trunk/scm/uim-sh.scm 2005-08-10 19:47:22 UTC (rev 1181)
+++ trunk/scm/uim-sh.scm 2005-08-10 19:53:47 UTC (rev 1182)
@@ -35,6 +35,8 @@
(define uim-sh-opt-strict-batch #f)
(define uim-sh-opt-help #f)
+(define uim-editline-enabled #f)
+
(define uim-sh-loop
(lambda ()
(if (not uim-sh-opt-batch)
@@ -60,23 +62,55 @@
strict-batch?))
(set! uim-sh-opt-strict-batch strict-batch?)
(set! uim-sh-opt-help (or (member "-h" args)
- (member "--help" args))))))
+ (member "--help" args)))
+ (if (symbol-bound? 'uim-editline-readline)
+ (set! uim-editline-enabled (or (and (member "-r" args)
+ (member "editline" args))
+ (member "--editline" args)))))))
(define uim-sh-usage
(lambda ()
(puts "Usage: uim-sh [options]
-b batch mode. suppress shell prompts
-B strict batch mode, implies -b. suppress shell prompts and
- evaluated results
- -h show this help
-")))
+ evaluated results\n")
+ (if (symbol-bound? 'uim-editline-readline)
+ (puts " -r [module] Load and import module.\n"))
+ (puts " -h show this help\n")))
(define uim-sh
(lambda (args)
(uim-sh-parse-args args)
(if uim-sh-opt-help
(uim-sh-usage)
- (if (*catch
- 'all
- (uim-sh-loop))
- (uim-sh args)))))
+ (begin
+ (if (and uim-editline-enabled
+ (symbol-bound? 'uim-editline-readline))
+ (activate-editline))
+ (if (*catch
+ 'all
+ (uim-sh-loop))
+ (uim-sh args))))))
+
+(if (symbol-bound? 'uim-editline-readline)
+ (begin
+ (define uim-sh-loop-orig ())
+ (define activate-editline
+ (lambda ()
+ (set! uim-sh-loop-orig uim-sh-loop)
+ (set! uim-sh-loop
+ (lambda ()
+ (if uim-sh-opt-batch
+ (uim-sh-loop-orig)
+ (let* ((line (uim-editline-readline))
+ (expr (read-from-string line))
+ (eof (eq? (eof-val) expr)))
+ (if (not eof)
+ (begin
+ ((if uim-sh-opt-strict-batch
+ (lambda () #f)
+ print)
+ (eval expr))
+ (uim-sh-loop))
+ #f)))))
+ #t))))
Modified: trunk/uim/Makefile.am
===================================================================
--- trunk/uim/Makefile.am 2005-08-10 19:47:22 UTC (rev 1181)
+++ trunk/uim/Makefile.am 2005-08-10 19:53:47 UTC (rev 1182)
@@ -117,6 +117,11 @@
uim_sh_CFLAGS =
uim_sh_LDADD = libuim.la
uim_sh_SOURCES = uim-sh.c
+if LIBEDIT
+ uim_sh_CFLAGS += -DLIBEDIT
+ uim_sh_SOURCES += editline.c
+ uim_sh_LDADD += -ledit -lcurses
+endif
uim_module_manager_LIBS =
uim_module_manager_CPPFLAGS = $(uim_defs) -I$(top_srcdir) -DUIM_DATADIR=\""$(datadir)/uim"\"
Added: trunk/uim/editline.c
===================================================================
--- trunk/uim/editline.c 2005-08-10 19:47:22 UTC (rev 1181)
+++ trunk/uim/editline.c 2005-08-10 19:53:47 UTC (rev 1182)
@@ -0,0 +1,99 @@
+/*
+
+ Copyright (c) 2003-2005 uim Project http://uim.freedesktop.org/
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of authors nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+#include <uim/uim.h>
+#include <uim/uim-scm.h>
+#include <uim/plugin.h>
+
+#include <histedit.h>
+
+static EditLine *el;
+static History *hist;
+static HistEvent hev;
+static uim_lisp uim_editline_readline(void);
+static char *prompt(EditLine *e);
+
+void
+editline_init(void)
+{
+ el = el_init("uim", stdin, stdout, stderr);
+ el_set(el, EL_PROMPT, &prompt);
+ el_set(el, EL_EDITOR, "emacs");
+
+ hist = history_init();
+ history(hist, &hev, H_SETSIZE, 100);
+ el_set(el, EL_HIST, history, hist);
+ el_source(el, NULL);
+
+ uim_scm_init_subr_0("uim-editline-readline", uim_editline_readline);
+}
+
+void
+editline_quit(void)
+{
+ history_end(hist);
+ el_end(el);
+}
+
+static uim_lisp
+uim_editline_readline(void)
+{
+ const char *line;
+ int count = 0;
+ uim_lisp ret, stack_start;
+
+ uim_scm_gc_protect_stack(&stack_start);
+
+ line = el_gets(el, &count);
+
+ if(count > 0 && line) {
+ history(hist, &hev, H_ENTER, line);
+ ret = uim_scm_make_str(line);
+ } else {
+ ret = uim_scm_make_str("");
+ }
+
+ uim_scm_gc_unprotect_stack(&stack_start);
+
+ return ret;
+}
+
+static char *prompt(EditLine *e) {
+ char *p;
+
+ p = uim_scm_symbol_value_str("uim-sh-prompt"); /* XXX */
+
+ if(!p)
+ return "uim-sh> ";
+ else
+ return p;
+}
Added: trunk/uim/editline.h
===================================================================
--- trunk/uim/editline.h 2005-08-10 19:47:22 UTC (rev 1181)
+++ trunk/uim/editline.h 2005-08-10 19:53:47 UTC (rev 1182)
@@ -0,0 +1,39 @@
+/*
+
+ Copyright (c) 2003-2005 uim Project http://uim.freedesktop.org/
+
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ 3. Neither the name of authors nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+*/
+
+#ifndef __HAVE_EDITLINE_H__
+#define __HAVE_EDITLINE_H__
+
+void editline_init(void);
+void editline_quit(void);
+
+#endif /* __HAVE_EDITLINE_H__ */
Modified: trunk/uim/uim-sh.c
===================================================================
--- trunk/uim/uim-sh.c 2005-08-10 19:47:22 UTC (rev 1181)
+++ trunk/uim/uim-sh.c 2005-08-10 19:53:47 UTC (rev 1182)
@@ -37,6 +37,10 @@
#include "uim-scm.h"
#include "uim-compat-scm.h"
+#ifdef LIBEDIT
+#include "editline.h"
+#endif
+
#ifdef UIM_SH_USE_EXIT_HOOK
extern int uim_siod_fatal;
#endif
@@ -51,6 +55,10 @@
/* TODO: be able to suppress ordinary initialization process */
uim_init();
+#ifdef LIBEDIT
+ editline_init();
+#endif
+
verbose = uim_scm_get_verbose_level();
uim_scm_set_verbose_level(1);
uim_scm_require_file("uim-sh.scm");
@@ -83,6 +91,8 @@
return 1;
#endif
+ editline_quit();
+
uim_quit();
return 0;
More information about the uim-commit
mailing list