Merge branch 'master' of https://bitbucket.com/slorquet/apps into ieee
This commit is contained in:
commit
a371f09d85
@ -1366,8 +1366,10 @@
|
|||||||
* apps/examples/ostest: Add a test for the sporadic scheduler. This
|
* apps/examples/ostest: Add a test for the sporadic scheduler. This
|
||||||
test is failing as of this commit (2015-07-24).
|
test is failing as of this commit (2015-07-24).
|
||||||
* apps/system/readline: Add support for Unix-style tab complete toi
|
* apps/system/readline: Add support for Unix-style tab complete toi
|
||||||
readline. This currently works only for built-in functions.i
|
readline. This currently works only for built-in functions.
|
||||||
Contributed by Nghia (2015-07-28).
|
Contributed by Nghia Ho (2015-07-28).
|
||||||
* apps/system/readline and apps/nshlib: Extended the tab-completion
|
* apps/system/readline and apps/nshlib: Extended the tab-completion
|
||||||
support to also expand NSH command names (2015-07-30).
|
support to also expand NSH command names (2015-07-30).
|
||||||
|
* apps/system/readline and apps/nshlib: Add support for an in-memory
|
||||||
|
command line history that can be retrieved using the up and down
|
||||||
|
arrows. Contributed by Nghia Ho (2015-08-09).
|
||||||
|
@ -75,6 +75,12 @@ PROGNAME = $(CONFIG_XYZ_PROGNAME)
|
|||||||
|
|
||||||
ROOTDEPPATH = --dep-path .
|
ROOTDEPPATH = --dep-path .
|
||||||
|
|
||||||
|
# Webserver built-in application info
|
||||||
|
|
||||||
|
APPNAME = webserver
|
||||||
|
PRIORITY = SCHED_PRIORITY_DEFAULT
|
||||||
|
STACKSIZE = 2048
|
||||||
|
|
||||||
# Common build
|
# Common build
|
||||||
|
|
||||||
VPATH =
|
VPATH =
|
||||||
@ -108,7 +114,14 @@ install:
|
|||||||
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||||
|
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
|
||||||
|
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
|
||||||
|
|
||||||
|
context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
|
||||||
|
else
|
||||||
context:
|
context:
|
||||||
|
endif
|
||||||
|
|
||||||
.depend: Makefile $(SRCS)
|
.depend: Makefile $(SRCS)
|
||||||
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
@$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
config NETUTILS_THTTPD
|
config NETUTILS_THTTPD
|
||||||
bool "THTTPD webserver"
|
bool "THTTPD webserver"
|
||||||
default n
|
default n
|
||||||
depends on NXFLAT || FS_BINFS
|
depends on (NXFLAT || FS_BINFS) && !DISABLE_POLL
|
||||||
---help---
|
---help---
|
||||||
Enable support for the THTTPD webservert.
|
Enable support for the THTTPD webservert.
|
||||||
|
|
||||||
|
@ -32,26 +32,68 @@ config READLINE_TABCOMPLETION
|
|||||||
depends on (BUILD_FLAT && BUILTIN) || READLINE_HAVE_EXTMATCH
|
depends on (BUILD_FLAT && BUILTIN) || READLINE_HAVE_EXTMATCH
|
||||||
---help---
|
---help---
|
||||||
Build in support for Unix-style tab completion. This feature was
|
Build in support for Unix-style tab completion. This feature was
|
||||||
originally provided by Nghia.
|
originally provided by Nghia Ho.
|
||||||
|
|
||||||
if READLINE_TABCOMPLETION
|
if READLINE_TABCOMPLETION
|
||||||
|
|
||||||
config READLINE_MAX_BUILTINS
|
config READLINE_MAX_BUILTINS
|
||||||
int "Maximum built-in matches"
|
int "Maximum built-in matches"
|
||||||
default 64
|
default 64
|
||||||
depends on BUILTIN
|
depends on BUILTIN
|
||||||
---help---
|
---help---
|
||||||
This the maximum number of matching names of builtin commands that
|
This the maximum number of matching names of builtin commands that
|
||||||
will be displayed.
|
will be displayed.
|
||||||
|
|
||||||
config READLINE_MAX_EXTCMDS
|
config READLINE_MAX_EXTCMDS
|
||||||
int "Maximum external command matches"
|
int "Maximum external command matches"
|
||||||
default 64
|
default 64
|
||||||
depends on READLINE_HAVE_EXTMATCH
|
depends on READLINE_HAVE_EXTMATCH
|
||||||
---help---
|
---help---
|
||||||
This the maximum number of matching names of builtin commands that
|
This the maximum number of matching names of builtin commands that
|
||||||
will be displayed.
|
will be displayed.
|
||||||
|
|
||||||
endif # READLINE_TABCOMPLETION
|
endif # READLINE_TABCOMPLETION
|
||||||
|
|
||||||
|
config READLINE_CMD_HISTORY
|
||||||
|
bool "Command line history"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Build in support for Unix-style command history using up and down
|
||||||
|
arrow keys. This feature was originally provided by Nghia Ho.
|
||||||
|
|
||||||
|
NOTE: Command line history is kept in an in-memory array and is
|
||||||
|
shared. In the FLAT or PROTECTED builds, this history is shared by
|
||||||
|
all threads; in the KERNEL build, the command line history is shared
|
||||||
|
by all threads in the process. This means that in a FLAT build, for
|
||||||
|
example, a built-in application started from NSH will have the same
|
||||||
|
history as does NSH if it also uses readline(). This also means
|
||||||
|
that different NSH sessions on serial, USB, or Telnet will also
|
||||||
|
share the same history array.
|
||||||
|
|
||||||
|
In a KERNEL build, each process will have a separately allocated
|
||||||
|
history array so the issue is lessened.
|
||||||
|
|
||||||
|
if READLINE_CMD_HISTORY
|
||||||
|
|
||||||
|
config READLINE_CMD_HISTORY_LINELEN
|
||||||
|
int "Command line history length"
|
||||||
|
default 64 if DEFAULT_SMALL
|
||||||
|
default 80 if !DEFAULT_SMALL
|
||||||
|
---help---
|
||||||
|
The maximum length of one command line in the in-memory array. The
|
||||||
|
total memory usage for the command line array will be
|
||||||
|
READLINE_CMD_HISTORY_LINELEN x READLINE_CMD_HISTORY_LEN. Default: 64/80
|
||||||
|
|
||||||
|
config READLINE_CMD_HISTORY_LEN
|
||||||
|
int "Command line history records"
|
||||||
|
default 4 if DEFAULT_SMALL
|
||||||
|
default 16 if !DEFAULT_SMALL
|
||||||
|
---help---
|
||||||
|
The number of lines of history that will be buffered in the in-
|
||||||
|
memory array. The total memory usage for the command line array
|
||||||
|
will be READLINE_CMD_HISTORY_LINELEN x READLINE_CMD_HISTORY_LEN.
|
||||||
|
Default: 16
|
||||||
|
|
||||||
|
endif # READLINE_CMD_HISTORY
|
||||||
endif # READLINE_ECHO
|
endif # READLINE_ECHO
|
||||||
endif # SYSTEM_READLINE
|
endif # SYSTEM_READLINE
|
||||||
|
@ -68,7 +68,22 @@ static FAR const char *g_readline_prompt = NULL;
|
|||||||
#ifdef CONFIG_READLINE_HAVE_EXTMATCH
|
#ifdef CONFIG_READLINE_HAVE_EXTMATCH
|
||||||
static FAR const struct extmatch_vtable_s *g_extmatch_vtbl = NULL;
|
static FAR const struct extmatch_vtable_s *g_extmatch_vtbl = NULL;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif /* CONFIG_READLINE_TABCOMPLETION */
|
||||||
|
|
||||||
|
#ifdef CONFIG_READLINE_CMD_HISTORY
|
||||||
|
/* Nghia Ho: command history
|
||||||
|
*
|
||||||
|
* g_cmd_history[][] Circular buffer
|
||||||
|
* g_cmd_history_head Head of the circular buffer, most recent command
|
||||||
|
* g_cmd_history_steps_from_head Offset from head
|
||||||
|
* g_cmd_history_len Number of elements in the circular buffer
|
||||||
|
*/
|
||||||
|
|
||||||
|
static char g_cmd_history[CONFIG_READLINE_CMD_HISTORY_LEN][CONFIG_READLINE_CMD_HISTORY_LINELEN];
|
||||||
|
static int g_cmd_history_head = -1;
|
||||||
|
static int g_cmd_history_steps_from_head = 1;
|
||||||
|
static int g_cmd_history_len = 0;
|
||||||
|
#endif /* CONFIG_READLINE_CMD_HISTORY */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
@ -341,7 +356,7 @@ FAR const char *readline_prompt(FAR const char *prompt)
|
|||||||
* Assumptions:
|
* Assumptions:
|
||||||
* The vtbl string is statically allocated a global. readline() will
|
* The vtbl string is statically allocated a global. readline() will
|
||||||
* simply remember the pointer to the structure. The structure must stay
|
* simply remember the pointer to the structure. The structure must stay
|
||||||
* allocated and available. Only one instance of such a structure is
|
* allocated and available. Only one instance of such a structure is
|
||||||
* supported. If there are multiple clients of readline(), they must all
|
* supported. If there are multiple clients of readline(), they must all
|
||||||
* share the same tab-completion logic (with exceptions in the case of
|
* share the same tab-completion logic (with exceptions in the case of
|
||||||
* the kernel build).
|
* the kernel build).
|
||||||
@ -389,8 +404,11 @@ FAR const struct extmatch_vtable_s *
|
|||||||
|
|
||||||
ssize_t readline_common(FAR struct rl_common_s *vtbl, FAR char *buf, int buflen)
|
ssize_t readline_common(FAR struct rl_common_s *vtbl, FAR char *buf, int buflen)
|
||||||
{
|
{
|
||||||
int escape;
|
int escape;
|
||||||
int nch;
|
int nch;
|
||||||
|
#ifdef CONFIG_READLINE_CMD_HISTORY
|
||||||
|
int i;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
|
|
||||||
@ -454,6 +472,70 @@ ssize_t readline_common(FAR struct rl_common_s *vtbl, FAR char *buf, int buflen)
|
|||||||
{
|
{
|
||||||
/* We are finished with the escape sequence */
|
/* We are finished with the escape sequence */
|
||||||
|
|
||||||
|
#ifdef CONFIG_READLINE_CMD_HISTORY
|
||||||
|
/* Nghia Ho: intercept up and down arrow keys */
|
||||||
|
|
||||||
|
if (g_cmd_history_len > 0)
|
||||||
|
{
|
||||||
|
if (ch == 'A') /* up arrow */
|
||||||
|
{
|
||||||
|
/* Go to the past command in history */
|
||||||
|
|
||||||
|
g_cmd_history_steps_from_head--;
|
||||||
|
|
||||||
|
if (-g_cmd_history_steps_from_head >= g_cmd_history_len)
|
||||||
|
{
|
||||||
|
g_cmd_history_steps_from_head = -(g_cmd_history_len - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (ch == 'B') /* down arrow */
|
||||||
|
{
|
||||||
|
/* Go to the recent command in history */
|
||||||
|
|
||||||
|
g_cmd_history_steps_from_head++;
|
||||||
|
|
||||||
|
if (g_cmd_history_steps_from_head > 1)
|
||||||
|
{
|
||||||
|
g_cmd_history_steps_from_head = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear out current command from the prompt */
|
||||||
|
|
||||||
|
while (nch > 0)
|
||||||
|
{
|
||||||
|
nch--;
|
||||||
|
|
||||||
|
#ifdef CONFIG_READLINE_ECHO
|
||||||
|
RL_PUTC(vtbl, ASCII_BS);
|
||||||
|
RL_WRITE(vtbl, g_erasetoeol, sizeof(g_erasetoeol));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g_cmd_history_steps_from_head != 1)
|
||||||
|
{
|
||||||
|
int idx = g_cmd_history_head + g_cmd_history_steps_from_head;
|
||||||
|
|
||||||
|
/* Circular buffer wrap around */
|
||||||
|
|
||||||
|
if (idx < 0)
|
||||||
|
{
|
||||||
|
idx = idx + CONFIG_READLINE_CMD_HISTORY_LEN;
|
||||||
|
}
|
||||||
|
else if (idx >= CONFIG_READLINE_CMD_HISTORY_LEN)
|
||||||
|
{
|
||||||
|
idx = idx - CONFIG_READLINE_CMD_HISTORY_LEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; g_cmd_history[idx][i] != '\0'; i++)
|
||||||
|
{
|
||||||
|
buf[nch++] = g_cmd_history[idx][i];
|
||||||
|
RL_PUTC(vtbl, g_cmd_history[idx][i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_READLINE_CMD_HISTORY */
|
||||||
|
|
||||||
escape = 0;
|
escape = 0;
|
||||||
ch = 'a';
|
ch = 'a';
|
||||||
}
|
}
|
||||||
@ -520,6 +602,30 @@ ssize_t readline_common(FAR struct rl_common_s *vtbl, FAR char *buf, int buflen)
|
|||||||
else if (ch == '\n' || ch == '\r')
|
else if (ch == '\n' || ch == '\r')
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_READLINE_CMD_HISTORY
|
||||||
|
/* Nghia Ho: save history of command, only if there was something
|
||||||
|
* typed besides return character.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (nch >= 1)
|
||||||
|
{
|
||||||
|
g_cmd_history_head = (g_cmd_history_head + 1) % CONFIG_READLINE_CMD_HISTORY_LEN;
|
||||||
|
|
||||||
|
for (i = 0; (i < nch) && i < (CONFIG_READLINE_CMD_HISTORY_LINELEN - 1); i++)
|
||||||
|
{
|
||||||
|
g_cmd_history[g_cmd_history_head][i] = buf[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
g_cmd_history[g_cmd_history_head][i] = '\0';
|
||||||
|
g_cmd_history_steps_from_head = 1;
|
||||||
|
|
||||||
|
if (g_cmd_history_len < CONFIG_READLINE_CMD_HISTORY_LEN)
|
||||||
|
{
|
||||||
|
g_cmd_history_len++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_READLINE_CMD_HISTORY */
|
||||||
|
|
||||||
/* The newline is stored in the buffer along with the null
|
/* The newline is stored in the buffer along with the null
|
||||||
* terminator.
|
* terminator.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user