version 1.14, 2001/01/01 11:03:16 |
version 1.21, 2002/03/18 16:20:36 |
|
|
* POSSIBILITY OF SUCH DAMAGE. |
* POSSIBILITY OF SUCH DAMAGE. |
*/ |
*/ |
|
|
#include <sys/cdefs.h> |
#include "config.h" |
#if !defined(lint) && !defined(SCCSID) |
#if !defined(lint) && !defined(SCCSID) |
__RCSID("$NetBSD$"); |
__RCSID("$NetBSD$"); |
#endif /* not lint && not SCCSID */ |
#endif /* not lint && not SCCSID */ |
Line 52 __RCSID("$NetBSD$"); |
|
Line 52 __RCSID("$NetBSD$"); |
|
#include <unistd.h> |
#include <unistd.h> |
#include <limits.h> |
#include <limits.h> |
#include "histedit.h" |
#include "histedit.h" |
#include "readline.h" |
#include "readline/readline.h" |
#include "sys.h" |
|
#include "el.h" |
#include "el.h" |
#include "fcns.h" /* for EL_NUM_FCNS */ |
#include "fcns.h" /* for EL_NUM_FCNS */ |
|
|
Line 66 __RCSID("$NetBSD$"); |
|
Line 65 __RCSID("$NetBSD$"); |
|
/* readline compatibility stuff - look at readline sources/documentation */ |
/* readline compatibility stuff - look at readline sources/documentation */ |
/* to see what these variables mean */ |
/* to see what these variables mean */ |
const char *rl_library_version = "EditLine wrapper"; |
const char *rl_library_version = "EditLine wrapper"; |
char *rl_readline_name = ""; |
static char empty[] = { '\0' }; |
|
static char expand_chars[] = { ' ', '\t', '\n', '=', '(', '\0' }; |
|
static char break_chars[] = { ' ', '\t', '\n', '"', '\\', '\'', '`', '@', '$', |
|
'>', '<', '=', ';', '|', '&', '{', '(', '\0' }; |
|
char *rl_readline_name = empty; |
FILE *rl_instream = NULL; |
FILE *rl_instream = NULL; |
FILE *rl_outstream = NULL; |
FILE *rl_outstream = NULL; |
int rl_point = 0; |
int rl_point = 0; |
Line 78 int history_length = 0; |
|
Line 81 int history_length = 0; |
|
int max_input_history = 0; |
int max_input_history = 0; |
char history_expansion_char = '!'; |
char history_expansion_char = '!'; |
char history_subst_char = '^'; |
char history_subst_char = '^'; |
char *history_no_expand_chars = " \t\n=("; |
char *history_no_expand_chars = expand_chars; |
Function *history_inhibit_expansion_function = NULL; |
Function *history_inhibit_expansion_function = NULL; |
|
|
int rl_inhibit_completion = 0; |
int rl_inhibit_completion = 0; |
int rl_attempted_completion_over = 0; |
int rl_attempted_completion_over = 0; |
char *rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{("; |
char *rl_basic_word_break_characters = break_chars; |
char *rl_completer_word_break_characters = NULL; |
char *rl_completer_word_break_characters = NULL; |
char *rl_completer_quote_characters = NULL; |
char *rl_completer_quote_characters = NULL; |
CPFunction *rl_completion_entry_function = NULL; |
CPFunction *rl_completion_entry_function = NULL; |
Line 103 int rl_completion_type = 0; |
|
Line 106 int rl_completion_type = 0; |
|
int rl_completion_query_items = 100; |
int rl_completion_query_items = 100; |
|
|
/* |
/* |
* If not zero, non-unique completions always show list of possible matches. |
* List of characters which are word break characters, but should be left |
|
* in the parsed text when it is passed to the completion function. |
|
* Shell uses this to help determine what kind of completing to do. |
*/ |
*/ |
|
char *rl_special_prefixes = (char *)NULL; |
|
|
|
/* |
|
* This is the character appended to the completed words if at the end of |
|
* the line. Default is ' ' (a space). |
|
*/ |
|
int rl_completion_append_character = ' '; |
|
|
|
/* stuff below is used internally by libedit for readline emulation */ |
|
|
|
/* if not zero, non-unique completions always show list of possible matches */ |
static int _rl_complete_show_all = 0; |
static int _rl_complete_show_all = 0; |
|
|
/* used for readline emulation */ |
|
static History *h = NULL; |
static History *h = NULL; |
static EditLine *e = NULL; |
static EditLine *e = NULL; |
static int el_rl_complete_cmdnum = 0; |
static int el_rl_complete_cmdnum = 0; |
Line 169 rl_initialize(void) |
|
Line 184 rl_initialize(void) |
|
HistEvent ev; |
HistEvent ev; |
const LineInfo *li; |
const LineInfo *li; |
int i; |
int i; |
|
int editmode = 1; |
|
struct termios t; |
|
|
if (e != NULL) |
if (e != NULL) |
el_end(e); |
el_end(e); |
Line 179 rl_initialize(void) |
|
Line 196 rl_initialize(void) |
|
rl_instream = stdin; |
rl_instream = stdin; |
if (!rl_outstream) |
if (!rl_outstream) |
rl_outstream = stdout; |
rl_outstream = stdout; |
|
|
|
/* |
|
* See if we don't really want to run the editor |
|
*/ |
|
if (tcgetattr(fileno(rl_instream), &t) != -1 && (t.c_lflag & ECHO) == 0) |
|
editmode = 0; |
|
|
e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr); |
e = el_init(rl_readline_name, rl_instream, rl_outstream, stderr); |
|
|
|
if (!editmode) |
|
el_set(e, EL_EDITMODE, 0); |
|
|
h = history_init(); |
h = history_init(); |
if (!e || !h) |
if (!e || !h) |
return (-1); |
return (-1); |
Line 227 rl_initialize(void) |
|
Line 254 rl_initialize(void) |
|
* and rl_line_buffer directly. |
* and rl_line_buffer directly. |
*/ |
*/ |
li = el_line(e); |
li = el_line(e); |
/* LINTED const cast */ |
/* a cheesy way to get rid of const cast. */ |
rl_line_buffer = (char *) li->buffer; |
rl_line_buffer = memchr(li->buffer, *li->buffer, 1); |
rl_point = rl_end = 0; |
rl_point = rl_end = 0; |
|
|
return (0); |
return (0); |
Line 245 readline(const char *prompt) |
|
Line 272 readline(const char *prompt) |
|
HistEvent ev; |
HistEvent ev; |
int count; |
int count; |
const char *ret; |
const char *ret; |
|
char *buf; |
|
|
if (e == NULL || h == NULL) |
if (e == NULL || h == NULL) |
rl_initialize(); |
rl_initialize(); |
Line 260 readline(const char *prompt) |
|
Line 288 readline(const char *prompt) |
|
ret = el_gets(e, &count); |
ret = el_gets(e, &count); |
|
|
if (ret && count > 0) { |
if (ret && count > 0) { |
char *foo; |
|
int lastidx; |
int lastidx; |
|
|
foo = strdup(ret); |
buf = strdup(ret); |
lastidx = count - 1; |
lastidx = count - 1; |
if (foo[lastidx] == '\n') |
if (buf[lastidx] == '\n') |
foo[lastidx] = '\0'; |
buf[lastidx] = '\0'; |
|
|
ret = foo; |
|
} else |
} else |
ret = NULL; |
buf = NULL; |
|
|
history(h, &ev, H_GETSIZE); |
history(h, &ev, H_GETSIZE); |
history_length = ev.num; |
history_length = ev.num; |
|
|
/* LINTED const cast */ |
return buf; |
return (char *) ret; |
|
} |
} |
|
|
/* |
/* |
|
|
_rl_qsort_string_compare(i1, i2) |
_rl_qsort_string_compare(i1, i2) |
const void *i1, *i2; |
const void *i1, *i2; |
{ |
{ |
|
/* LINTED const castaway */ |
const char *s1 = ((const char **)i1)[0]; |
const char *s1 = ((const char **)i1)[0]; |
|
/* LINTED const castaway */ |
const char *s2 = ((const char **)i2)[0]; |
const char *s2 = ((const char **)i2)[0]; |
|
|
return strcasecmp(s1, s2); |
return strcasecmp(s1, s2); |
Line 1383 rl_display_match_list (matches, len, max |
|
Line 1409 rl_display_match_list (matches, len, max |
|
count++; |
count++; |
|
|
/* Sort the items if they are not already sorted. */ |
/* Sort the items if they are not already sorted. */ |
qsort(&matches[1], len-1, sizeof(char *), _rl_qsort_string_compare); |
qsort(&matches[1], (size_t)(len - 1), sizeof(char *), |
|
_rl_qsort_string_compare); |
|
|
idx = 1; |
idx = 1; |
for(; count > 0; count--) { |
for(; count > 0; count--) { |
Line 1422 rl_complete_internal(int what_to_do) |
|
Line 1449 rl_complete_internal(int what_to_do) |
|
if (!complet_func) |
if (!complet_func) |
complet_func = filename_completion_function; |
complet_func = filename_completion_function; |
|
|
|
/* We now look backwards for the start of a filename/variable word */ |
li = el_line(e); |
li = el_line(e); |
ctemp = (char *) li->cursor; |
ctemp = (const char *) li->cursor; |
while (ctemp > li->buffer && |
while (ctemp > li->buffer |
!strchr(rl_basic_word_break_characters, *(ctemp - 1))) |
&& !strchr(rl_basic_word_break_characters, ctemp[-1]) |
|
&& (!rl_special_prefixes |
|
|| !strchr(rl_special_prefixes, ctemp[-1]) ) ) |
ctemp--; |
ctemp--; |
|
|
len = li->cursor - ctemp; |
len = li->cursor - ctemp; |
Line 1469 rl_complete_internal(int what_to_do) |
|
Line 1499 rl_complete_internal(int what_to_do) |
|
* object is a directory. |
* object is a directory. |
*/ |
*/ |
size_t alen = strlen(matches[0]); |
size_t alen = strlen(matches[0]); |
if (complet_func != filename_completion_function |
if ((complet_func != filename_completion_function |
|| (alen > 0 && (matches[0])[alen - 1] != '/')) |
|| (alen > 0 && (matches[0])[alen - 1] != '/')) |
el_insertstr(e, " "); |
&& rl_completion_append_character) { |
|
char buf[2]; |
|
buf[0] = rl_completion_append_character; |
|
buf[1] = '\0'; |
|
el_insertstr(e, buf); |
|
} |
} else if (what_to_do == '!') { |
} else if (what_to_do == '!') { |
display_matches: |
display_matches: |
/* |
/* |
Line 1507 rl_complete_internal(int what_to_do) |
|
Line 1542 rl_complete_internal(int what_to_do) |
|
rl_display_match_list(matches, matches_num, |
rl_display_match_list(matches, matches_num, |
maxlen); |
maxlen); |
retval = CC_REDISPLAY; |
retval = CC_REDISPLAY; |
|
} else if (matches[0][0]) { |
|
/* |
|
* There was some common match, but the name was |
|
* not complete enough. Next tab will print possible |
|
* completions. |
|
*/ |
|
el_beep(e); |
} else { |
} else { |
/* lcd is not a valid object - further specification */ |
/* lcd is not a valid object - further specification */ |
/* is needed */ |
/* is needed */ |