summaryrefslogtreecommitdiffstats
path: root/sh
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2010-06-02 08:13:29 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2010-06-02 08:13:29 -0700
commit5dc0f5db7152a604377af30f7d2139a84fd7b30c (patch)
tree09bb7372cb3811176303038fc2c92373439ba618 /sh
parentc57a22c8561cc571d23cd7f321103b2b4d2c7cde (diff)
parent7fe202f160ca1926bc0277e3c276ad7b3f9b9aeb (diff)
downloadsystem_core-5dc0f5db7152a604377af30f7d2139a84fd7b30c.zip
system_core-5dc0f5db7152a604377af30f7d2139a84fd7b30c.tar.gz
system_core-5dc0f5db7152a604377af30f7d2139a84fd7b30c.tar.bz2
merge from open-source master
Change-Id: I9e7ebc99f0de12ed3ae38a3882481485a96f9680
Diffstat (limited to 'sh')
-rw-r--r--sh/Android.mk6
-rw-r--r--sh/input.c43
-rw-r--r--sh/parser.c3
3 files changed, 51 insertions, 1 deletions
diff --git a/sh/Android.mk b/sh/Android.mk
index 09bb6ac..b5e5c38 100644
--- a/sh/Android.mk
+++ b/sh/Android.mk
@@ -31,7 +31,11 @@ LOCAL_SRC_FILES:= \
LOCAL_MODULE:= sh
-LOCAL_CFLAGS += -DSHELL
+LOCAL_CFLAGS += -DSHELL -DWITH_LINENOISE
+
+LOCAL_STATIC_LIBRARIES := liblinenoise
+
+LOCAL_C_INCLUDES += system/core/liblinenoise
make_ash_files: PRIVATE_SRC_FILES := $(SRC_FILES)
make_ash_files: PRIVATE_CFLAGS := $(LOCAL_CFLAGS)
diff --git a/sh/input.c b/sh/input.c
index a81fd7b..9377bd0 100644
--- a/sh/input.c
+++ b/sh/input.c
@@ -64,6 +64,10 @@ __RCSID("$NetBSD: input.c,v 1.39 2003/08/07 09:05:32 agc Exp $");
#include "parser.h"
#include "myhistedit.h"
+#ifdef WITH_LINENOISE
+#include "linenoise.h"
+#endif
+
#define EOF_NLEFT -99 /* value of parsenleft when EOF pushed back */
MKINIT
@@ -203,6 +207,45 @@ retry:
} else
#endif
+#ifdef WITH_LINENOISE
+ if (parsefile->fd == 0) {
+ static char *rl_start;
+ static const char *rl_cp;
+ static int el_len;
+
+ if (rl_cp == NULL) {
+ rl_cp = rl_start = linenoise(getprompt(""));
+ if (rl_cp != NULL) {
+ el_len = strlen(rl_start);
+ if (el_len != 0) {
+ /* Add non-blank lines to history. */
+ linenoiseHistoryAdd(rl_start);
+ }
+ out2str("\r\n");
+ /* Client expects a newline at end of input, doesn't expect null */
+ rl_start[el_len++] = '\n';
+ }
+ }
+ if (rl_cp == NULL)
+ nr = 0;
+ else {
+ nr = el_len;
+ if (nr > BUFSIZ - 8)
+ nr = BUFSIZ - 8;
+ memcpy(buf, rl_cp, nr);
+ if (nr != el_len) {
+ el_len -= nr;
+ rl_cp += nr;
+ } else {
+ rl_cp = 0;
+ if (rl_start != NULL) {
+ free(rl_start);
+ rl_start = NULL;
+ }
+ }
+ }
+ } else
+#endif
nr = read(parsefile->fd, buf, BUFSIZ - 8);
diff --git a/sh/parser.c b/sh/parser.c
index 67de58e..d956375 100644
--- a/sh/parser.c
+++ b/sh/parser.c
@@ -1628,7 +1628,10 @@ setprompt(int which)
#ifdef WITH_HISTORY
if (!el)
#endif
+#ifdef WITH_LINENOISE
+#else
out2str(getprompt(NULL));
+#endif
}
/*