Several fixes.
-Erik
This commit is contained in:
parent
161220c498
commit
6273f655c8
@ -4,10 +4,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifndef BB_INIT
|
|
||||||
#undef BB_FEATURE_LINUXRC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int been_there_done_that = 0;
|
static int been_there_done_that = 0;
|
||||||
|
|
||||||
/* It has been alledged that doing such things can
|
/* It has been alledged that doing such things can
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
DF="busybox.def.h"
|
DF="busybox.def.h"
|
||||||
MF="busybox.c"
|
MF="busybox.c"
|
||||||
|
|
||||||
LIST="$(sed -n '/^#define/{s/^#define BB_FEATURE_.*//g;s/^#define //p;}' $DF)"
|
#LIST="$(sed -n '/^#define/{s/^#define BB_FEATURE_.*//g;s/^#define //p;}' $DF)"
|
||||||
|
LIST="$(cpp $DF -dM | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1/gp;' | sort)"
|
||||||
|
|
||||||
for def in ${LIST}; do
|
for def in ${LIST}; do
|
||||||
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
sed -n -e 's/^#define.*BB_FEATURE.*$//g;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;' \
|
|
||||||
-e '/^#define/{s/.*bb_//;s/$/.o/p;}' busybox.def.h
|
# I added in the extra "ls" so only source files that
|
||||||
|
# actually exist will show up in the compile list.
|
||||||
|
ls -1 ` \
|
||||||
|
cpp busybox.def.h -dM | \
|
||||||
|
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||||
|
| tr [:upper:] [:lower:] | sort
|
||||||
|
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||||
|
|
||||||
|
@ -4,10 +4,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#ifndef BB_INIT
|
|
||||||
#undef BB_FEATURE_LINUXRC
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int been_there_done_that = 0;
|
static int been_there_done_that = 0;
|
||||||
|
|
||||||
/* It has been alledged that doing such things can
|
/* It has been alledged that doing such things can
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
// Don't bother turning BB_INSMOD on. It doesn't work.
|
// Don't bother turning BB_INSMOD on. It doesn't work.
|
||||||
//#define BB_INSMOD
|
//#define BB_INSMOD
|
||||||
#define BB_KILL
|
#define BB_KILL
|
||||||
|
#define BB_KILLALL
|
||||||
#define BB_KLOGD
|
#define BB_KLOGD
|
||||||
//#define BB_LENGTH
|
//#define BB_LENGTH
|
||||||
#define BB_LN
|
#define BB_LN
|
||||||
@ -198,11 +199,23 @@
|
|||||||
#define BB_MTAB
|
#define BB_MTAB
|
||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
#ifdef BB_FEATURE_FULL_REGULAR_EXPRESSIONS
|
#if defined BB_FEATURE_FULL_REGULAR_EXPRESSIONS && (defined BB_SED || defined BB_GREP )
|
||||||
#define BB_REGEXP
|
#define BB_REGEXP
|
||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
#if defined BB_FEATURE_SH_COMMAND_EDITING && defined BB_SH
|
||||||
#define BB_CMDEDIT
|
#define BB_CMDEDIT
|
||||||
#endif
|
#endif
|
||||||
//
|
//
|
||||||
|
#ifdef BB_KILLALL
|
||||||
|
#ifndef BB_KILL
|
||||||
|
#define BB_KILL
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
//
|
||||||
|
#ifdef BB_FEATURE_LINUXRC
|
||||||
|
#ifndef BB_INIT
|
||||||
|
#define BB_INIT
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
//
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
DF="busybox.def.h"
|
DF="busybox.def.h"
|
||||||
MF="busybox.c"
|
MF="busybox.c"
|
||||||
|
|
||||||
LIST="$(sed -n '/^#define/{s/^#define BB_FEATURE_.*//g;s/^#define //p;}' $DF)"
|
#LIST="$(sed -n '/^#define/{s/^#define BB_FEATURE_.*//g;s/^#define //p;}' $DF)"
|
||||||
|
LIST="$(cpp $DF -dM | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1/gp;' | sort)"
|
||||||
|
|
||||||
for def in ${LIST}; do
|
for def in ${LIST}; do
|
||||||
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
||||||
|
11
busybox.sh
11
busybox.sh
@ -1,3 +1,10 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
sed -n -e 's/^#define.*BB_FEATURE.*$//g;y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/;' \
|
|
||||||
-e '/^#define/{s/.*bb_//;s/$/.o/p;}' busybox.def.h
|
# I added in the extra "ls" so only source files that
|
||||||
|
# actually exist will show up in the compile list.
|
||||||
|
ls -1 ` \
|
||||||
|
cpp busybox.def.h -dM | \
|
||||||
|
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||||
|
| tr [:upper:] [:lower:] | sort
|
||||||
|
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||||
|
|
||||||
|
260
cmdedit.c
260
cmdedit.c
@ -47,6 +47,8 @@
|
|||||||
|
|
||||||
#define ESC 27
|
#define ESC 27
|
||||||
#define DEL 127
|
#define DEL 127
|
||||||
|
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
|
||||||
|
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
|
||||||
|
|
||||||
static struct history *his_front = NULL; /* First element in command line list */
|
static struct history *his_front = NULL; /* First element in command line list */
|
||||||
static struct history *his_end = NULL; /* Last element in command line list */
|
static struct history *his_end = NULL; /* Last element in command line list */
|
||||||
@ -104,7 +106,7 @@ void cmdedit_reset_term(void)
|
|||||||
xioctl(fileno(stdin), TCSETA, (void *) &old_term);
|
xioctl(fileno(stdin), TCSETA, (void *) &old_term);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gotaSignal(int sig)
|
void prepareToDie(int sig)
|
||||||
{
|
{
|
||||||
cmdedit_reset_term();
|
cmdedit_reset_term();
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
@ -175,6 +177,40 @@ void input_backspace(int outputFd, int *cursor, int *len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char **username_completion_matches( char* matchBuf)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "\nin username_completion_matches\n");
|
||||||
|
return ( (char**) NULL);
|
||||||
|
}
|
||||||
|
char **command_completion_matches( char* matchBuf)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "\nin command_completion_matches\n");
|
||||||
|
return ( (char**) NULL);
|
||||||
|
}
|
||||||
|
char **directory_completion_matches( char* matchBuf)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "\nin directory_completion_matches\n");
|
||||||
|
return ( (char**) NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function is used to grab a character buffer
|
||||||
|
* from the input file descriptor and allows you to
|
||||||
|
* a string with full command editing (sortof like
|
||||||
|
* a mini readline).
|
||||||
|
*
|
||||||
|
* The following standard commands are not implemented:
|
||||||
|
* ESC-b -- Move back one word
|
||||||
|
* ESC-f -- Move forward one word
|
||||||
|
* ESC-d -- Delete back one word
|
||||||
|
* ESC-h -- Delete forward one word
|
||||||
|
* CTL-t -- Transpose two characters
|
||||||
|
*
|
||||||
|
* Furthermore, the "vi" command editing keys are not implemented.
|
||||||
|
*
|
||||||
|
* TODO: implement TAB command completion. :)
|
||||||
|
*
|
||||||
|
*/
|
||||||
extern int cmdedit_read_input(int inputFd, int outputFd,
|
extern int cmdedit_read_input(int inputFd, int outputFd,
|
||||||
char command[BUFSIZ])
|
char command[BUFSIZ])
|
||||||
{
|
{
|
||||||
@ -185,6 +221,8 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
int cursor = 0;
|
int cursor = 0;
|
||||||
int break_out = 0;
|
int break_out = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int lastWasTab = FALSE;
|
||||||
|
char **matches = (char **)NULL;
|
||||||
char c = 0;
|
char c = 0;
|
||||||
struct history *hp = his_end;
|
struct history *hp = his_end;
|
||||||
|
|
||||||
@ -209,90 +247,233 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
|
|
||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* Control-A Beginning of line */
|
case 1:
|
||||||
|
/* Control-a -- Beginning of line */
|
||||||
input_home(outputFd, &cursor);
|
input_home(outputFd, &cursor);
|
||||||
break;
|
case 5:
|
||||||
case 5: /* Control-E EOL */
|
/* Control-e -- End of line */
|
||||||
input_end(outputFd, &cursor, len);
|
input_end(outputFd, &cursor, len);
|
||||||
break;
|
break;
|
||||||
case 4: /* Control-D */
|
case 2:
|
||||||
|
/* Control-b -- Move back one character */
|
||||||
|
if (cursor > 0) {
|
||||||
|
xwrite(outputFd, "\033[D", 3);
|
||||||
|
cursor--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
/* Control-f -- Move forward one character */
|
||||||
|
if (cursor < len) {
|
||||||
|
xwrite(outputFd, "\033[C", 3);
|
||||||
|
cursor++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
/* Control-d -- Delete one character */
|
||||||
if (cursor != len) {
|
if (cursor != len) {
|
||||||
input_delete(outputFd, cursor);
|
input_delete(outputFd, cursor);
|
||||||
len--;
|
len--;
|
||||||
|
} else if (len == 0) {
|
||||||
|
prepareToDie(0);
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\b': /* Backspace */
|
case 14:
|
||||||
|
/* Control-n -- Get next command */
|
||||||
|
if (hp && hp->n && hp->n->s) {
|
||||||
|
free( hp->s);
|
||||||
|
hp->s = strdup(parsenextc);
|
||||||
|
hp = hp->n;
|
||||||
|
goto hop;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
/* Control-p -- Get previous command */
|
||||||
|
if (hp && hp->p) {
|
||||||
|
free( hp->s);
|
||||||
|
hp->s = strdup(parsenextc);
|
||||||
|
hp = hp->p;
|
||||||
|
goto hop;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
{
|
||||||
|
/* Do TAB completion */
|
||||||
|
int in_command_position=0, ti=len-1;
|
||||||
|
|
||||||
|
if (lastWasTab == FALSE) {
|
||||||
|
char *tmp;
|
||||||
|
char *matchBuf;
|
||||||
|
|
||||||
|
if (matches) {
|
||||||
|
free(matches);
|
||||||
|
matches = (char **)NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
|
||||||
|
|
||||||
|
/* Make a local copy of the string -- up
|
||||||
|
* to the the position of the cursor */
|
||||||
|
strcpy( matchBuf, parsenextc);
|
||||||
|
matchBuf[cursor+1] = '\0';
|
||||||
|
|
||||||
|
/* skip leading white space */
|
||||||
|
tmp = matchBuf;
|
||||||
|
while (*tmp && isspace(*tmp)) {
|
||||||
|
(tmp)++;
|
||||||
|
ti++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Determine if this is a command word or not */
|
||||||
|
//while ((ti > -1) && (whitespace (matchBuf[ti]))) {
|
||||||
|
//printf("\nti=%d\n", ti);
|
||||||
|
// ti--;
|
||||||
|
// }
|
||||||
|
printf("\nti=%d\n", ti);
|
||||||
|
|
||||||
|
if (ti < 0) {
|
||||||
|
in_command_position++;
|
||||||
|
} else if (member(matchBuf[ti], ";|&{(`")) {
|
||||||
|
int this_char, prev_char;
|
||||||
|
in_command_position++;
|
||||||
|
/* Handle the two character tokens `>&', `<&', and `>|'.
|
||||||
|
We are not in a command position after one of these. */
|
||||||
|
this_char = matchBuf[ti];
|
||||||
|
prev_char = matchBuf[ti - 1];
|
||||||
|
|
||||||
|
if ((this_char == '&' && (prev_char == '<' || prev_char == '>')) ||
|
||||||
|
(this_char == '|' && prev_char == '>')) {
|
||||||
|
in_command_position = 0;
|
||||||
|
}
|
||||||
|
/* For now, do not bother with catching quoted
|
||||||
|
* expressions and marking them as not in command
|
||||||
|
* positions. Some other day. Or not.
|
||||||
|
*/
|
||||||
|
//else if (char_is_quoted (matchBuf, ti)) {
|
||||||
|
// in_command_position = 0;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
printf("\nin_command_position=%d\n", in_command_position);
|
||||||
|
/* If the word starts in `~', and there is no slash in the word,
|
||||||
|
* then try completing this word as a username. */
|
||||||
|
if (*matchBuf == '~' && !strchr (matchBuf, '/'))
|
||||||
|
matches = username_completion_matches(matchBuf);
|
||||||
|
|
||||||
|
/* If this word is in a command position, then complete over possible
|
||||||
|
* command names, including aliases, built-ins, and executables. */
|
||||||
|
if (!matches && in_command_position) {
|
||||||
|
matches = command_completion_matches(matchBuf);
|
||||||
|
|
||||||
|
/* If we are attempting command completion and nothing matches,
|
||||||
|
* then try and match directories as a last resort... */
|
||||||
|
if (!matches)
|
||||||
|
matches = directory_completion_matches(matchBuf);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("\nprinting match list\n");
|
||||||
|
}
|
||||||
|
/* Rewrite the whole line (for debugging) */
|
||||||
|
for (; cursor > 0; cursor--)
|
||||||
|
xwrite(outputFd, "\b", 1);
|
||||||
|
len = strlen(parsenextc);
|
||||||
|
xwrite(outputFd, parsenextc, len);
|
||||||
|
cursor = len;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '\b':
|
||||||
case DEL:
|
case DEL:
|
||||||
|
/* Backspace */
|
||||||
input_backspace(outputFd, &cursor, &len);
|
input_backspace(outputFd, &cursor, &len);
|
||||||
break;
|
break;
|
||||||
case '\n': /* Enter */
|
case '\n':
|
||||||
|
/* Enter */
|
||||||
*(parsenextc + len++ + 1) = c;
|
*(parsenextc + len++ + 1) = c;
|
||||||
xwrite(outputFd, &c, 1);
|
xwrite(outputFd, &c, 1);
|
||||||
break_out = 1;
|
break_out = 1;
|
||||||
break;
|
break;
|
||||||
case ESC: /* escape sequence follows */
|
case ESC: {
|
||||||
|
/* escape sequence follows */
|
||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (c == '[') { /* 91 */
|
if (c == '[') { /* 91 */
|
||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'A':
|
case 'A':
|
||||||
if (hp && hp->p) { /* Up */
|
/* Up Arrow -- Get previous command */
|
||||||
|
if (hp && hp->p) {
|
||||||
|
free( hp->s);
|
||||||
|
hp->s = strdup(parsenextc);
|
||||||
hp = hp->p;
|
hp = hp->p;
|
||||||
goto hop;
|
goto hop;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
if (hp && hp->n && hp->n->s) { /* Down */
|
/* Down Arrow -- Get next command */
|
||||||
|
if (hp && hp->n && hp->n->s) {
|
||||||
|
free( hp->s);
|
||||||
|
hp->s = strdup(parsenextc);
|
||||||
hp = hp->n;
|
hp = hp->n;
|
||||||
goto hop;
|
goto hop;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
hop: /* hop */
|
/* This is where we rewrite the line
|
||||||
|
* using the selected history item */
|
||||||
|
hop:
|
||||||
len = strlen(parsenextc);
|
len = strlen(parsenextc);
|
||||||
|
|
||||||
for (; cursor > 0; cursor--) /* return to begining of line */
|
/* return to begining of line */
|
||||||
|
for (; cursor > 0; cursor--)
|
||||||
xwrite(outputFd, "\b", 1);
|
xwrite(outputFd, "\b", 1);
|
||||||
|
xwrite(outputFd, parsenextc, len);
|
||||||
|
|
||||||
for (j = 0; j < len; j++) /* erase old command */
|
/* erase old command */
|
||||||
|
for (j = 0; j < len; j++)
|
||||||
xwrite(outputFd, " ", 1);
|
xwrite(outputFd, " ", 1);
|
||||||
|
|
||||||
for (j = len; j > 0; j--) /* return to begining of line */
|
/* return to begining of line */
|
||||||
|
for (j = len; j > 0; j--)
|
||||||
xwrite(outputFd, "\b", 1);
|
xwrite(outputFd, "\b", 1);
|
||||||
|
|
||||||
strcpy(parsenextc, hp->s); /* write new command */
|
memset(parsenextc, 0, BUFSIZ);
|
||||||
|
/* write new command */
|
||||||
|
strcpy(parsenextc, hp->s);
|
||||||
len = strlen(hp->s);
|
len = strlen(hp->s);
|
||||||
xwrite(outputFd, parsenextc, len);
|
xwrite(outputFd, parsenextc, len);
|
||||||
cursor = len;
|
cursor = len;
|
||||||
break;
|
break;
|
||||||
case 'C': /* Right */
|
case 'C':
|
||||||
|
/* Right Arrow -- Move forward one character */
|
||||||
if (cursor < len) {
|
if (cursor < len) {
|
||||||
xwrite(outputFd, "\033[C", 3);
|
xwrite(outputFd, "\033[C", 3);
|
||||||
cursor++;
|
cursor++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'D': /* Left */
|
case 'D':
|
||||||
|
/* Left Arrow -- Move back one character */
|
||||||
if (cursor > 0) {
|
if (cursor > 0) {
|
||||||
xwrite(outputFd, "\033[D", 3);
|
xwrite(outputFd, "\033[D", 3);
|
||||||
cursor--;
|
cursor--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '3': /* Delete */
|
case '3':
|
||||||
|
/* Delete */
|
||||||
if (cursor != len) {
|
if (cursor != len) {
|
||||||
input_delete(outputFd, cursor);
|
input_delete(outputFd, cursor);
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '1': /* Home (Ctrl-A) */
|
case '1':
|
||||||
|
/* Home (Ctrl-A) */
|
||||||
input_home(outputFd, &cursor);
|
input_home(outputFd, &cursor);
|
||||||
break;
|
break;
|
||||||
case '4': /* End (Ctrl-E) */
|
case '4':
|
||||||
|
/* End (Ctrl-E) */
|
||||||
input_end(outputFd, &cursor, len);
|
input_end(outputFd, &cursor, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -300,20 +481,24 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret; /* read 126 (~) */
|
return ret; /* read 126 (~) */
|
||||||
}
|
}
|
||||||
if (c == 'O') { /* 79 */
|
if (c == 'O') {
|
||||||
|
/* 79 */
|
||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret;
|
return ret;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'H': /* Home (xterm) */
|
case 'H':
|
||||||
|
/* Home (xterm) */
|
||||||
input_home(outputFd, &cursor);
|
input_home(outputFd, &cursor);
|
||||||
break;
|
break;
|
||||||
case 'F': /* End (xterm) */
|
case 'F':
|
||||||
|
/* End (xterm) */
|
||||||
input_end(outputFd, &cursor, len);
|
input_end(outputFd, &cursor, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c = 0;
|
c = 0;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: /* If it's regular input, do the normal thing */
|
default: /* If it's regular input, do the normal thing */
|
||||||
|
|
||||||
@ -343,6 +528,10 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
xwrite(outputFd, &c, 1);
|
xwrite(outputFd, &c, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (c=='\t')
|
||||||
|
lastWasTab = TRUE;
|
||||||
|
else
|
||||||
|
lastWasTab = FALSE;
|
||||||
|
|
||||||
if (break_out) /* Enter is the command terminator, no more input. */
|
if (break_out) /* Enter is the command terminator, no more input. */
|
||||||
break;
|
break;
|
||||||
@ -353,32 +542,33 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
reset_term = 0;
|
reset_term = 0;
|
||||||
|
|
||||||
|
|
||||||
if (*(parsenextc)) { /* Handle command history log */
|
/* Handle command history log */
|
||||||
|
if (*(parsenextc)) {
|
||||||
|
|
||||||
struct history *h = his_end;
|
struct history *h = his_end;
|
||||||
|
|
||||||
if (!h) { /* No previous history */
|
if (!h) {
|
||||||
|
/* No previous history */
|
||||||
h = his_front = malloc(sizeof(struct history));
|
h = his_front = malloc(sizeof(struct history));
|
||||||
h->n = malloc(sizeof(struct history));
|
h->n = malloc(sizeof(struct history));
|
||||||
h->p = NULL;
|
h->p = NULL;
|
||||||
h->s = strdup(parsenextc);
|
h->s = strdup(parsenextc);
|
||||||
|
|
||||||
h->n->p = h;
|
h->n->p = h;
|
||||||
h->n->n = NULL;
|
h->n->n = NULL;
|
||||||
h->n->s = NULL;
|
h->n->s = NULL;
|
||||||
his_end = h->n;
|
his_end = h->n;
|
||||||
history_counter++;
|
history_counter++;
|
||||||
} else { /* Add a new history command */
|
} else {
|
||||||
|
/* Add a new history command */
|
||||||
h->n = malloc(sizeof(struct history));
|
h->n = malloc(sizeof(struct history));
|
||||||
|
|
||||||
h->n->p = h;
|
h->n->p = h;
|
||||||
h->n->n = NULL;
|
h->n->n = NULL;
|
||||||
h->n->s = NULL;
|
h->n->s = NULL;
|
||||||
h->s = strdup(parsenextc);
|
h->s = strdup(parsenextc);
|
||||||
his_end = h->n;
|
his_end = h->n;
|
||||||
|
|
||||||
if (history_counter >= MAX_HISTORY) { /* After max history, remove the last known command */
|
/* After max history, remove the oldest command */
|
||||||
|
if (history_counter >= MAX_HISTORY) {
|
||||||
|
|
||||||
struct history *p = his_front->n;
|
struct history *p = his_front->n;
|
||||||
|
|
||||||
@ -398,8 +588,8 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
extern void cmdedit_init(void)
|
extern void cmdedit_init(void)
|
||||||
{
|
{
|
||||||
atexit(cmdedit_reset_term);
|
atexit(cmdedit_reset_term);
|
||||||
signal(SIGINT, gotaSignal);
|
signal(SIGINT, prepareToDie);
|
||||||
signal(SIGQUIT, gotaSignal);
|
signal(SIGQUIT, prepareToDie);
|
||||||
signal(SIGTERM, gotaSignal);
|
signal(SIGTERM, prepareToDie);
|
||||||
}
|
}
|
||||||
#endif /* BB_FEATURE_SH_COMMAND_EDITING */
|
#endif /* BB_FEATURE_SH_COMMAND_EDITING */
|
||||||
|
13
kill.c
13
kill.c
@ -36,11 +36,12 @@ static const char *kill_usage =
|
|||||||
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
||||||
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
||||||
|
|
||||||
|
#ifdef BB_KILLALL
|
||||||
static const char *killall_usage =
|
static const char *killall_usage =
|
||||||
"killall [-signal] process-name [process-name ...]\n\n"
|
"killall [-signal] process-name [process-name ...]\n\n"
|
||||||
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
||||||
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
#define KILL 0
|
#define KILL 0
|
||||||
#define KILLALL 1
|
#define KILLALL 1
|
||||||
@ -132,10 +133,15 @@ extern int kill_main(int argc, char **argv)
|
|||||||
int whichApp, sig = SIGTERM;
|
int whichApp, sig = SIGTERM;
|
||||||
const char *appUsage;
|
const char *appUsage;
|
||||||
|
|
||||||
|
#ifdef BB_KILLALL
|
||||||
/* Figure out what we are trying to do here */
|
/* Figure out what we are trying to do here */
|
||||||
whichApp = (strcmp(*argv, "killall") == 0)?
|
whichApp = (strcmp(*argv, "killall") == 0)?
|
||||||
KILLALL : KILL;
|
KILLALL : KILL;
|
||||||
appUsage = (whichApp == KILLALL)? killall_usage : kill_usage;
|
appUsage = (whichApp == KILLALL)? killall_usage : kill_usage;
|
||||||
|
#else
|
||||||
|
whichApp = KILL;
|
||||||
|
appUsage = kill_usage;
|
||||||
|
#endif
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
@ -213,7 +219,9 @@ extern int kill_main(int argc, char **argv)
|
|||||||
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
|
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
#ifdef BB_KILLALL
|
||||||
|
else {
|
||||||
/* Looks like they want to do a killall. Do that */
|
/* Looks like they want to do a killall. Do that */
|
||||||
while (--argc >= 0) {
|
while (--argc >= 0) {
|
||||||
int pid;
|
int pid;
|
||||||
@ -225,6 +233,7 @@ extern int kill_main(int argc, char **argv)
|
|||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
exit(TRUE);
|
exit(TRUE);
|
||||||
|
|
||||||
|
12
lash.c
12
lash.c
@ -98,7 +98,7 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList);
|
|||||||
static int shell_help(struct job *cmd, struct jobSet *junk);
|
static int shell_help(struct job *cmd, struct jobSet *junk);
|
||||||
static int shell_jobs(struct job *dummy, struct jobSet *jobList);
|
static int shell_jobs(struct job *dummy, struct jobSet *jobList);
|
||||||
static int shell_pwd(struct job *dummy, struct jobSet *junk);
|
static int shell_pwd(struct job *dummy, struct jobSet *junk);
|
||||||
static int shell_set(struct job *cmd, struct jobSet *junk);
|
static int shell_export(struct job *cmd, struct jobSet *junk);
|
||||||
static int shell_source(struct job *cmd, struct jobSet *jobList);
|
static int shell_source(struct job *cmd, struct jobSet *jobList);
|
||||||
static int shell_unset(struct job *cmd, struct jobSet *junk);
|
static int shell_unset(struct job *cmd, struct jobSet *junk);
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ static struct builtInCommand bltins[] = {
|
|||||||
{"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
|
{"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
|
||||||
{"jobs", "Lists the active jobs", "jobs", shell_jobs},
|
{"jobs", "Lists the active jobs", "jobs", shell_jobs},
|
||||||
{"pwd", "Print current directory", "pwd", shell_pwd},
|
{"pwd", "Print current directory", "pwd", shell_pwd},
|
||||||
{"set", "Set environment variable", "set [VAR=value]", shell_set},
|
{"export", "Set environment variable", "export [VAR=value]", shell_export},
|
||||||
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
||||||
|
|
||||||
{".", "Source-in and run commands in a file", ". filename",
|
{".", "Source-in and run commands in a file", ". filename",
|
||||||
@ -182,7 +182,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
|
|||||||
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||||
{
|
{
|
||||||
int i, jobNum;
|
int i, jobNum;
|
||||||
struct job *job;
|
struct job *job=NULL;
|
||||||
|
|
||||||
if (!jobList->head) {
|
if (!jobList->head) {
|
||||||
if (!cmd->progs[0].argv[1] || cmd->progs[0].argv[2]) {
|
if (!cmd->progs[0].argv[1] || cmd->progs[0].argv[2]) {
|
||||||
@ -268,8 +268,8 @@ static int shell_pwd(struct job *dummy, struct jobSet *junk)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* built-in 'set VAR=value' handler */
|
/* built-in 'export VAR=value' handler */
|
||||||
static int shell_set(struct job *cmd, struct jobSet *junk)
|
static int shell_export(struct job *cmd, struct jobSet *junk)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ static int shell_set(struct job *cmd, struct jobSet *junk)
|
|||||||
}
|
}
|
||||||
res = putenv(cmd->progs[0].argv[1]);
|
res = putenv(cmd->progs[0].argv[1]);
|
||||||
if (res)
|
if (res)
|
||||||
fprintf(stdout, "set: %s\n", strerror(errno));
|
fprintf(stdout, "export: %s\n", strerror(errno));
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,11 +36,12 @@ static const char *kill_usage =
|
|||||||
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
||||||
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
||||||
|
|
||||||
|
#ifdef BB_KILLALL
|
||||||
static const char *killall_usage =
|
static const char *killall_usage =
|
||||||
"killall [-signal] process-name [process-name ...]\n\n"
|
"killall [-signal] process-name [process-name ...]\n\n"
|
||||||
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
||||||
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
"Options:\n" "\t-l\tList all signal names and numbers.\n\n";
|
||||||
|
#endif
|
||||||
|
|
||||||
#define KILL 0
|
#define KILL 0
|
||||||
#define KILLALL 1
|
#define KILLALL 1
|
||||||
@ -132,10 +133,15 @@ extern int kill_main(int argc, char **argv)
|
|||||||
int whichApp, sig = SIGTERM;
|
int whichApp, sig = SIGTERM;
|
||||||
const char *appUsage;
|
const char *appUsage;
|
||||||
|
|
||||||
|
#ifdef BB_KILLALL
|
||||||
/* Figure out what we are trying to do here */
|
/* Figure out what we are trying to do here */
|
||||||
whichApp = (strcmp(*argv, "killall") == 0)?
|
whichApp = (strcmp(*argv, "killall") == 0)?
|
||||||
KILLALL : KILL;
|
KILLALL : KILL;
|
||||||
appUsage = (whichApp == KILLALL)? killall_usage : kill_usage;
|
appUsage = (whichApp == KILLALL)? killall_usage : kill_usage;
|
||||||
|
#else
|
||||||
|
whichApp = KILL;
|
||||||
|
appUsage = kill_usage;
|
||||||
|
#endif
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
@ -213,7 +219,9 @@ extern int kill_main(int argc, char **argv)
|
|||||||
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
|
fatalError( "Could not kill pid '%d': %s\n", pid, strerror(errno));
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
#ifdef BB_KILLALL
|
||||||
|
else {
|
||||||
/* Looks like they want to do a killall. Do that */
|
/* Looks like they want to do a killall. Do that */
|
||||||
while (--argc >= 0) {
|
while (--argc >= 0) {
|
||||||
int pid;
|
int pid;
|
||||||
@ -225,6 +233,7 @@ extern int kill_main(int argc, char **argv)
|
|||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
exit(TRUE);
|
exit(TRUE);
|
||||||
|
|
||||||
|
12
sh.c
12
sh.c
@ -98,7 +98,7 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList);
|
|||||||
static int shell_help(struct job *cmd, struct jobSet *junk);
|
static int shell_help(struct job *cmd, struct jobSet *junk);
|
||||||
static int shell_jobs(struct job *dummy, struct jobSet *jobList);
|
static int shell_jobs(struct job *dummy, struct jobSet *jobList);
|
||||||
static int shell_pwd(struct job *dummy, struct jobSet *junk);
|
static int shell_pwd(struct job *dummy, struct jobSet *junk);
|
||||||
static int shell_set(struct job *cmd, struct jobSet *junk);
|
static int shell_export(struct job *cmd, struct jobSet *junk);
|
||||||
static int shell_source(struct job *cmd, struct jobSet *jobList);
|
static int shell_source(struct job *cmd, struct jobSet *jobList);
|
||||||
static int shell_unset(struct job *cmd, struct jobSet *junk);
|
static int shell_unset(struct job *cmd, struct jobSet *junk);
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ static struct builtInCommand bltins[] = {
|
|||||||
{"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
|
{"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
|
||||||
{"jobs", "Lists the active jobs", "jobs", shell_jobs},
|
{"jobs", "Lists the active jobs", "jobs", shell_jobs},
|
||||||
{"pwd", "Print current directory", "pwd", shell_pwd},
|
{"pwd", "Print current directory", "pwd", shell_pwd},
|
||||||
{"set", "Set environment variable", "set [VAR=value]", shell_set},
|
{"export", "Set environment variable", "export [VAR=value]", shell_export},
|
||||||
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
||||||
|
|
||||||
{".", "Source-in and run commands in a file", ". filename",
|
{".", "Source-in and run commands in a file", ". filename",
|
||||||
@ -182,7 +182,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
|
|||||||
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||||
{
|
{
|
||||||
int i, jobNum;
|
int i, jobNum;
|
||||||
struct job *job;
|
struct job *job=NULL;
|
||||||
|
|
||||||
if (!jobList->head) {
|
if (!jobList->head) {
|
||||||
if (!cmd->progs[0].argv[1] || cmd->progs[0].argv[2]) {
|
if (!cmd->progs[0].argv[1] || cmd->progs[0].argv[2]) {
|
||||||
@ -268,8 +268,8 @@ static int shell_pwd(struct job *dummy, struct jobSet *junk)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* built-in 'set VAR=value' handler */
|
/* built-in 'export VAR=value' handler */
|
||||||
static int shell_set(struct job *cmd, struct jobSet *junk)
|
static int shell_export(struct job *cmd, struct jobSet *junk)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ static int shell_set(struct job *cmd, struct jobSet *junk)
|
|||||||
}
|
}
|
||||||
res = putenv(cmd->progs[0].argv[1]);
|
res = putenv(cmd->progs[0].argv[1]);
|
||||||
if (res)
|
if (res)
|
||||||
fprintf(stdout, "set: %s\n", strerror(errno));
|
fprintf(stdout, "export: %s\n", strerror(errno));
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
260
shell/cmdedit.c
260
shell/cmdedit.c
@ -47,6 +47,8 @@
|
|||||||
|
|
||||||
#define ESC 27
|
#define ESC 27
|
||||||
#define DEL 127
|
#define DEL 127
|
||||||
|
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
|
||||||
|
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
|
||||||
|
|
||||||
static struct history *his_front = NULL; /* First element in command line list */
|
static struct history *his_front = NULL; /* First element in command line list */
|
||||||
static struct history *his_end = NULL; /* Last element in command line list */
|
static struct history *his_end = NULL; /* Last element in command line list */
|
||||||
@ -104,7 +106,7 @@ void cmdedit_reset_term(void)
|
|||||||
xioctl(fileno(stdin), TCSETA, (void *) &old_term);
|
xioctl(fileno(stdin), TCSETA, (void *) &old_term);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gotaSignal(int sig)
|
void prepareToDie(int sig)
|
||||||
{
|
{
|
||||||
cmdedit_reset_term();
|
cmdedit_reset_term();
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
@ -175,6 +177,40 @@ void input_backspace(int outputFd, int *cursor, int *len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char **username_completion_matches( char* matchBuf)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "\nin username_completion_matches\n");
|
||||||
|
return ( (char**) NULL);
|
||||||
|
}
|
||||||
|
char **command_completion_matches( char* matchBuf)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "\nin command_completion_matches\n");
|
||||||
|
return ( (char**) NULL);
|
||||||
|
}
|
||||||
|
char **directory_completion_matches( char* matchBuf)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "\nin directory_completion_matches\n");
|
||||||
|
return ( (char**) NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function is used to grab a character buffer
|
||||||
|
* from the input file descriptor and allows you to
|
||||||
|
* a string with full command editing (sortof like
|
||||||
|
* a mini readline).
|
||||||
|
*
|
||||||
|
* The following standard commands are not implemented:
|
||||||
|
* ESC-b -- Move back one word
|
||||||
|
* ESC-f -- Move forward one word
|
||||||
|
* ESC-d -- Delete back one word
|
||||||
|
* ESC-h -- Delete forward one word
|
||||||
|
* CTL-t -- Transpose two characters
|
||||||
|
*
|
||||||
|
* Furthermore, the "vi" command editing keys are not implemented.
|
||||||
|
*
|
||||||
|
* TODO: implement TAB command completion. :)
|
||||||
|
*
|
||||||
|
*/
|
||||||
extern int cmdedit_read_input(int inputFd, int outputFd,
|
extern int cmdedit_read_input(int inputFd, int outputFd,
|
||||||
char command[BUFSIZ])
|
char command[BUFSIZ])
|
||||||
{
|
{
|
||||||
@ -185,6 +221,8 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
int cursor = 0;
|
int cursor = 0;
|
||||||
int break_out = 0;
|
int break_out = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int lastWasTab = FALSE;
|
||||||
|
char **matches = (char **)NULL;
|
||||||
char c = 0;
|
char c = 0;
|
||||||
struct history *hp = his_end;
|
struct history *hp = his_end;
|
||||||
|
|
||||||
@ -209,90 +247,233 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
|
|
||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1: /* Control-A Beginning of line */
|
case 1:
|
||||||
|
/* Control-a -- Beginning of line */
|
||||||
input_home(outputFd, &cursor);
|
input_home(outputFd, &cursor);
|
||||||
break;
|
case 5:
|
||||||
case 5: /* Control-E EOL */
|
/* Control-e -- End of line */
|
||||||
input_end(outputFd, &cursor, len);
|
input_end(outputFd, &cursor, len);
|
||||||
break;
|
break;
|
||||||
case 4: /* Control-D */
|
case 2:
|
||||||
|
/* Control-b -- Move back one character */
|
||||||
|
if (cursor > 0) {
|
||||||
|
xwrite(outputFd, "\033[D", 3);
|
||||||
|
cursor--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
/* Control-f -- Move forward one character */
|
||||||
|
if (cursor < len) {
|
||||||
|
xwrite(outputFd, "\033[C", 3);
|
||||||
|
cursor++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
/* Control-d -- Delete one character */
|
||||||
if (cursor != len) {
|
if (cursor != len) {
|
||||||
input_delete(outputFd, cursor);
|
input_delete(outputFd, cursor);
|
||||||
len--;
|
len--;
|
||||||
|
} else if (len == 0) {
|
||||||
|
prepareToDie(0);
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '\b': /* Backspace */
|
case 14:
|
||||||
|
/* Control-n -- Get next command */
|
||||||
|
if (hp && hp->n && hp->n->s) {
|
||||||
|
free( hp->s);
|
||||||
|
hp->s = strdup(parsenextc);
|
||||||
|
hp = hp->n;
|
||||||
|
goto hop;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
/* Control-p -- Get previous command */
|
||||||
|
if (hp && hp->p) {
|
||||||
|
free( hp->s);
|
||||||
|
hp->s = strdup(parsenextc);
|
||||||
|
hp = hp->p;
|
||||||
|
goto hop;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '\t':
|
||||||
|
{
|
||||||
|
/* Do TAB completion */
|
||||||
|
int in_command_position=0, ti=len-1;
|
||||||
|
|
||||||
|
if (lastWasTab == FALSE) {
|
||||||
|
char *tmp;
|
||||||
|
char *matchBuf;
|
||||||
|
|
||||||
|
if (matches) {
|
||||||
|
free(matches);
|
||||||
|
matches = (char **)NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
|
||||||
|
|
||||||
|
/* Make a local copy of the string -- up
|
||||||
|
* to the the position of the cursor */
|
||||||
|
strcpy( matchBuf, parsenextc);
|
||||||
|
matchBuf[cursor+1] = '\0';
|
||||||
|
|
||||||
|
/* skip leading white space */
|
||||||
|
tmp = matchBuf;
|
||||||
|
while (*tmp && isspace(*tmp)) {
|
||||||
|
(tmp)++;
|
||||||
|
ti++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Determine if this is a command word or not */
|
||||||
|
//while ((ti > -1) && (whitespace (matchBuf[ti]))) {
|
||||||
|
//printf("\nti=%d\n", ti);
|
||||||
|
// ti--;
|
||||||
|
// }
|
||||||
|
printf("\nti=%d\n", ti);
|
||||||
|
|
||||||
|
if (ti < 0) {
|
||||||
|
in_command_position++;
|
||||||
|
} else if (member(matchBuf[ti], ";|&{(`")) {
|
||||||
|
int this_char, prev_char;
|
||||||
|
in_command_position++;
|
||||||
|
/* Handle the two character tokens `>&', `<&', and `>|'.
|
||||||
|
We are not in a command position after one of these. */
|
||||||
|
this_char = matchBuf[ti];
|
||||||
|
prev_char = matchBuf[ti - 1];
|
||||||
|
|
||||||
|
if ((this_char == '&' && (prev_char == '<' || prev_char == '>')) ||
|
||||||
|
(this_char == '|' && prev_char == '>')) {
|
||||||
|
in_command_position = 0;
|
||||||
|
}
|
||||||
|
/* For now, do not bother with catching quoted
|
||||||
|
* expressions and marking them as not in command
|
||||||
|
* positions. Some other day. Or not.
|
||||||
|
*/
|
||||||
|
//else if (char_is_quoted (matchBuf, ti)) {
|
||||||
|
// in_command_position = 0;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
printf("\nin_command_position=%d\n", in_command_position);
|
||||||
|
/* If the word starts in `~', and there is no slash in the word,
|
||||||
|
* then try completing this word as a username. */
|
||||||
|
if (*matchBuf == '~' && !strchr (matchBuf, '/'))
|
||||||
|
matches = username_completion_matches(matchBuf);
|
||||||
|
|
||||||
|
/* If this word is in a command position, then complete over possible
|
||||||
|
* command names, including aliases, built-ins, and executables. */
|
||||||
|
if (!matches && in_command_position) {
|
||||||
|
matches = command_completion_matches(matchBuf);
|
||||||
|
|
||||||
|
/* If we are attempting command completion and nothing matches,
|
||||||
|
* then try and match directories as a last resort... */
|
||||||
|
if (!matches)
|
||||||
|
matches = directory_completion_matches(matchBuf);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf("\nprinting match list\n");
|
||||||
|
}
|
||||||
|
/* Rewrite the whole line (for debugging) */
|
||||||
|
for (; cursor > 0; cursor--)
|
||||||
|
xwrite(outputFd, "\b", 1);
|
||||||
|
len = strlen(parsenextc);
|
||||||
|
xwrite(outputFd, parsenextc, len);
|
||||||
|
cursor = len;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case '\b':
|
||||||
case DEL:
|
case DEL:
|
||||||
|
/* Backspace */
|
||||||
input_backspace(outputFd, &cursor, &len);
|
input_backspace(outputFd, &cursor, &len);
|
||||||
break;
|
break;
|
||||||
case '\n': /* Enter */
|
case '\n':
|
||||||
|
/* Enter */
|
||||||
*(parsenextc + len++ + 1) = c;
|
*(parsenextc + len++ + 1) = c;
|
||||||
xwrite(outputFd, &c, 1);
|
xwrite(outputFd, &c, 1);
|
||||||
break_out = 1;
|
break_out = 1;
|
||||||
break;
|
break;
|
||||||
case ESC: /* escape sequence follows */
|
case ESC: {
|
||||||
|
/* escape sequence follows */
|
||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (c == '[') { /* 91 */
|
if (c == '[') { /* 91 */
|
||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'A':
|
case 'A':
|
||||||
if (hp && hp->p) { /* Up */
|
/* Up Arrow -- Get previous command */
|
||||||
|
if (hp && hp->p) {
|
||||||
|
free( hp->s);
|
||||||
|
hp->s = strdup(parsenextc);
|
||||||
hp = hp->p;
|
hp = hp->p;
|
||||||
goto hop;
|
goto hop;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'B':
|
case 'B':
|
||||||
if (hp && hp->n && hp->n->s) { /* Down */
|
/* Down Arrow -- Get next command */
|
||||||
|
if (hp && hp->n && hp->n->s) {
|
||||||
|
free( hp->s);
|
||||||
|
hp->s = strdup(parsenextc);
|
||||||
hp = hp->n;
|
hp = hp->n;
|
||||||
goto hop;
|
goto hop;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
hop: /* hop */
|
/* This is where we rewrite the line
|
||||||
|
* using the selected history item */
|
||||||
|
hop:
|
||||||
len = strlen(parsenextc);
|
len = strlen(parsenextc);
|
||||||
|
|
||||||
for (; cursor > 0; cursor--) /* return to begining of line */
|
/* return to begining of line */
|
||||||
|
for (; cursor > 0; cursor--)
|
||||||
xwrite(outputFd, "\b", 1);
|
xwrite(outputFd, "\b", 1);
|
||||||
|
xwrite(outputFd, parsenextc, len);
|
||||||
|
|
||||||
for (j = 0; j < len; j++) /* erase old command */
|
/* erase old command */
|
||||||
|
for (j = 0; j < len; j++)
|
||||||
xwrite(outputFd, " ", 1);
|
xwrite(outputFd, " ", 1);
|
||||||
|
|
||||||
for (j = len; j > 0; j--) /* return to begining of line */
|
/* return to begining of line */
|
||||||
|
for (j = len; j > 0; j--)
|
||||||
xwrite(outputFd, "\b", 1);
|
xwrite(outputFd, "\b", 1);
|
||||||
|
|
||||||
strcpy(parsenextc, hp->s); /* write new command */
|
memset(parsenextc, 0, BUFSIZ);
|
||||||
|
/* write new command */
|
||||||
|
strcpy(parsenextc, hp->s);
|
||||||
len = strlen(hp->s);
|
len = strlen(hp->s);
|
||||||
xwrite(outputFd, parsenextc, len);
|
xwrite(outputFd, parsenextc, len);
|
||||||
cursor = len;
|
cursor = len;
|
||||||
break;
|
break;
|
||||||
case 'C': /* Right */
|
case 'C':
|
||||||
|
/* Right Arrow -- Move forward one character */
|
||||||
if (cursor < len) {
|
if (cursor < len) {
|
||||||
xwrite(outputFd, "\033[C", 3);
|
xwrite(outputFd, "\033[C", 3);
|
||||||
cursor++;
|
cursor++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'D': /* Left */
|
case 'D':
|
||||||
|
/* Left Arrow -- Move back one character */
|
||||||
if (cursor > 0) {
|
if (cursor > 0) {
|
||||||
xwrite(outputFd, "\033[D", 3);
|
xwrite(outputFd, "\033[D", 3);
|
||||||
cursor--;
|
cursor--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '3': /* Delete */
|
case '3':
|
||||||
|
/* Delete */
|
||||||
if (cursor != len) {
|
if (cursor != len) {
|
||||||
input_delete(outputFd, cursor);
|
input_delete(outputFd, cursor);
|
||||||
len--;
|
len--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '1': /* Home (Ctrl-A) */
|
case '1':
|
||||||
|
/* Home (Ctrl-A) */
|
||||||
input_home(outputFd, &cursor);
|
input_home(outputFd, &cursor);
|
||||||
break;
|
break;
|
||||||
case '4': /* End (Ctrl-E) */
|
case '4':
|
||||||
|
/* End (Ctrl-E) */
|
||||||
input_end(outputFd, &cursor, len);
|
input_end(outputFd, &cursor, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -300,20 +481,24 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret; /* read 126 (~) */
|
return ret; /* read 126 (~) */
|
||||||
}
|
}
|
||||||
if (c == 'O') { /* 79 */
|
if (c == 'O') {
|
||||||
|
/* 79 */
|
||||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||||
return ret;
|
return ret;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'H': /* Home (xterm) */
|
case 'H':
|
||||||
|
/* Home (xterm) */
|
||||||
input_home(outputFd, &cursor);
|
input_home(outputFd, &cursor);
|
||||||
break;
|
break;
|
||||||
case 'F': /* End (xterm) */
|
case 'F':
|
||||||
|
/* End (xterm) */
|
||||||
input_end(outputFd, &cursor, len);
|
input_end(outputFd, &cursor, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c = 0;
|
c = 0;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default: /* If it's regular input, do the normal thing */
|
default: /* If it's regular input, do the normal thing */
|
||||||
|
|
||||||
@ -343,6 +528,10 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
xwrite(outputFd, &c, 1);
|
xwrite(outputFd, &c, 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (c=='\t')
|
||||||
|
lastWasTab = TRUE;
|
||||||
|
else
|
||||||
|
lastWasTab = FALSE;
|
||||||
|
|
||||||
if (break_out) /* Enter is the command terminator, no more input. */
|
if (break_out) /* Enter is the command terminator, no more input. */
|
||||||
break;
|
break;
|
||||||
@ -353,32 +542,33 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
reset_term = 0;
|
reset_term = 0;
|
||||||
|
|
||||||
|
|
||||||
if (*(parsenextc)) { /* Handle command history log */
|
/* Handle command history log */
|
||||||
|
if (*(parsenextc)) {
|
||||||
|
|
||||||
struct history *h = his_end;
|
struct history *h = his_end;
|
||||||
|
|
||||||
if (!h) { /* No previous history */
|
if (!h) {
|
||||||
|
/* No previous history */
|
||||||
h = his_front = malloc(sizeof(struct history));
|
h = his_front = malloc(sizeof(struct history));
|
||||||
h->n = malloc(sizeof(struct history));
|
h->n = malloc(sizeof(struct history));
|
||||||
h->p = NULL;
|
h->p = NULL;
|
||||||
h->s = strdup(parsenextc);
|
h->s = strdup(parsenextc);
|
||||||
|
|
||||||
h->n->p = h;
|
h->n->p = h;
|
||||||
h->n->n = NULL;
|
h->n->n = NULL;
|
||||||
h->n->s = NULL;
|
h->n->s = NULL;
|
||||||
his_end = h->n;
|
his_end = h->n;
|
||||||
history_counter++;
|
history_counter++;
|
||||||
} else { /* Add a new history command */
|
} else {
|
||||||
|
/* Add a new history command */
|
||||||
h->n = malloc(sizeof(struct history));
|
h->n = malloc(sizeof(struct history));
|
||||||
|
|
||||||
h->n->p = h;
|
h->n->p = h;
|
||||||
h->n->n = NULL;
|
h->n->n = NULL;
|
||||||
h->n->s = NULL;
|
h->n->s = NULL;
|
||||||
h->s = strdup(parsenextc);
|
h->s = strdup(parsenextc);
|
||||||
his_end = h->n;
|
his_end = h->n;
|
||||||
|
|
||||||
if (history_counter >= MAX_HISTORY) { /* After max history, remove the last known command */
|
/* After max history, remove the oldest command */
|
||||||
|
if (history_counter >= MAX_HISTORY) {
|
||||||
|
|
||||||
struct history *p = his_front->n;
|
struct history *p = his_front->n;
|
||||||
|
|
||||||
@ -398,8 +588,8 @@ extern int cmdedit_read_input(int inputFd, int outputFd,
|
|||||||
extern void cmdedit_init(void)
|
extern void cmdedit_init(void)
|
||||||
{
|
{
|
||||||
atexit(cmdedit_reset_term);
|
atexit(cmdedit_reset_term);
|
||||||
signal(SIGINT, gotaSignal);
|
signal(SIGINT, prepareToDie);
|
||||||
signal(SIGQUIT, gotaSignal);
|
signal(SIGQUIT, prepareToDie);
|
||||||
signal(SIGTERM, gotaSignal);
|
signal(SIGTERM, prepareToDie);
|
||||||
}
|
}
|
||||||
#endif /* BB_FEATURE_SH_COMMAND_EDITING */
|
#endif /* BB_FEATURE_SH_COMMAND_EDITING */
|
||||||
|
12
shell/lash.c
12
shell/lash.c
@ -98,7 +98,7 @@ static int shell_fg_bg(struct job *cmd, struct jobSet *jobList);
|
|||||||
static int shell_help(struct job *cmd, struct jobSet *junk);
|
static int shell_help(struct job *cmd, struct jobSet *junk);
|
||||||
static int shell_jobs(struct job *dummy, struct jobSet *jobList);
|
static int shell_jobs(struct job *dummy, struct jobSet *jobList);
|
||||||
static int shell_pwd(struct job *dummy, struct jobSet *junk);
|
static int shell_pwd(struct job *dummy, struct jobSet *junk);
|
||||||
static int shell_set(struct job *cmd, struct jobSet *junk);
|
static int shell_export(struct job *cmd, struct jobSet *junk);
|
||||||
static int shell_source(struct job *cmd, struct jobSet *jobList);
|
static int shell_source(struct job *cmd, struct jobSet *jobList);
|
||||||
static int shell_unset(struct job *cmd, struct jobSet *junk);
|
static int shell_unset(struct job *cmd, struct jobSet *junk);
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ static struct builtInCommand bltins[] = {
|
|||||||
{"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
|
{"fg", "Bring job into the foreground", "fg [%%job]", shell_fg_bg},
|
||||||
{"jobs", "Lists the active jobs", "jobs", shell_jobs},
|
{"jobs", "Lists the active jobs", "jobs", shell_jobs},
|
||||||
{"pwd", "Print current directory", "pwd", shell_pwd},
|
{"pwd", "Print current directory", "pwd", shell_pwd},
|
||||||
{"set", "Set environment variable", "set [VAR=value]", shell_set},
|
{"export", "Set environment variable", "export [VAR=value]", shell_export},
|
||||||
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
{"unset", "Unset environment variable", "unset VAR", shell_unset},
|
||||||
|
|
||||||
{".", "Source-in and run commands in a file", ". filename",
|
{".", "Source-in and run commands in a file", ". filename",
|
||||||
@ -182,7 +182,7 @@ static int shell_exit(struct job *cmd, struct jobSet *junk)
|
|||||||
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
static int shell_fg_bg(struct job *cmd, struct jobSet *jobList)
|
||||||
{
|
{
|
||||||
int i, jobNum;
|
int i, jobNum;
|
||||||
struct job *job;
|
struct job *job=NULL;
|
||||||
|
|
||||||
if (!jobList->head) {
|
if (!jobList->head) {
|
||||||
if (!cmd->progs[0].argv[1] || cmd->progs[0].argv[2]) {
|
if (!cmd->progs[0].argv[1] || cmd->progs[0].argv[2]) {
|
||||||
@ -268,8 +268,8 @@ static int shell_pwd(struct job *dummy, struct jobSet *junk)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* built-in 'set VAR=value' handler */
|
/* built-in 'export VAR=value' handler */
|
||||||
static int shell_set(struct job *cmd, struct jobSet *junk)
|
static int shell_export(struct job *cmd, struct jobSet *junk)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@ -278,7 +278,7 @@ static int shell_set(struct job *cmd, struct jobSet *junk)
|
|||||||
}
|
}
|
||||||
res = putenv(cmd->progs[0].argv[1]);
|
res = putenv(cmd->progs[0].argv[1]);
|
||||||
if (res)
|
if (res)
|
||||||
fprintf(stdout, "set: %s\n", strerror(errno));
|
fprintf(stdout, "export: %s\n", strerror(errno));
|
||||||
return (res);
|
return (res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1247,8 +1247,7 @@ extern int device_open(char *device, int mode)
|
|||||||
#endif /* BB_INIT BB_SYSLOGD */
|
#endif /* BB_INIT BB_SYSLOGD */
|
||||||
|
|
||||||
|
|
||||||
#if defined BB_FEATURE_LINUXRC && ( defined BB_HALT || defined BB_REBOOT || defined BB_POWEROFF )
|
#if defined BB_KILLALL || ( defined BB_FEATURE_LINUXRC && ( defined BB_HALT || defined BB_REBOOT || defined BB_POWEROFF ))
|
||||||
|
|
||||||
#ifdef BB_FEATURE_USE_DEVPS_PATCH
|
#ifdef BB_FEATURE_USE_DEVPS_PATCH
|
||||||
#include <linux/devps.h>
|
#include <linux/devps.h>
|
||||||
#endif
|
#endif
|
||||||
@ -1363,7 +1362,7 @@ extern pid_t findPidByName( char* pidName)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
|
#endif /* BB_FEATURE_USE_DEVPS_PATCH */
|
||||||
#endif /* BB_INIT || BB_HALT || BB_REBOOT || BB_POWEROFF */
|
#endif /* BB_KILLALL || ( BB_FEATURE_LINUXRC && ( BB_HALT || BB_REBOOT || BB_POWEROFF )) */
|
||||||
|
|
||||||
#if defined BB_GUNZIP \
|
#if defined BB_GUNZIP \
|
||||||
|| defined BB_GZIP \
|
|| defined BB_GZIP \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user