version 1.41, 2003/11/01 23:39:22 |
version 1.47, 2004/09/08 18:15:57 |
Line 61 __RCSID("$NetBSD$"); |
|
Line 61 __RCSID("$NetBSD$"); |
|
#ifdef HAVE_ALLOCA_H |
#ifdef HAVE_ALLOCA_H |
#include <alloca.h> |
#include <alloca.h> |
#endif |
#endif |
#include "histedit.h" |
|
#include "readline/readline.h" |
|
#include "el.h" |
#include "el.h" |
#include "tokenizer.h" |
|
#include "fcns.h" /* for EL_NUM_FCNS */ |
#include "fcns.h" /* for EL_NUM_FCNS */ |
|
#include "histedit.h" |
|
#include "readline/readline.h" |
|
|
/* for rl_complete() */ |
/* for rl_complete() */ |
#define TAB '\r' |
#define TAB '\r' |
Line 162 static int el_rl_complete_cmdnum = 0; |
|
Line 161 static int el_rl_complete_cmdnum = 0; |
|
|
|
/* internal functions */ |
/* internal functions */ |
static unsigned char _el_rl_complete(EditLine *, int); |
static unsigned char _el_rl_complete(EditLine *, int); |
|
static unsigned char _el_rl_tstp(EditLine *, int); |
static char *_get_prompt(EditLine *); |
static char *_get_prompt(EditLine *); |
static HIST_ENTRY *_move_history(int); |
static HIST_ENTRY *_move_history(int); |
static int _history_expand_command(const char *, size_t, size_t, |
static int _history_expand_command(const char *, size_t, size_t, |
Line 273 rl_initialize(void) |
|
Line 273 rl_initialize(void) |
|
"ReadLine compatible completion function", |
"ReadLine compatible completion function", |
_el_rl_complete); |
_el_rl_complete); |
el_set(e, EL_BIND, "^I", "rl_complete", NULL); |
el_set(e, EL_BIND, "^I", "rl_complete", NULL); |
|
|
|
/* |
|
* Send TSTP when ^Z is pressed. |
|
*/ |
|
el_set(e, EL_ADDFN, "rl_tstp", |
|
"ReadLine compatible suspend function", |
|
_el_rl_tstp); |
|
el_set(e, EL_BIND, "^Z", "rl_tstp", NULL); |
|
|
/* |
/* |
* Find out where the rl_complete function was added; this is |
* Find out where the rl_complete function was added; this is |
* used later to detect that lastcmd was also rl_complete. |
* used later to detect that lastcmd was also rl_complete. |
Line 1445 filename_completion_function(const char |
|
Line 1454 filename_completion_function(const char |
|
(void)strncpy(dirname, text, len); |
(void)strncpy(dirname, text, len); |
dirname[len] = '\0'; |
dirname[len] = '\0'; |
} else { |
} else { |
filename = strdup(text); |
if (*text == 0) |
if (filename == NULL) |
filename = NULL; |
return NULL; |
else { |
|
filename = strdup(text); |
|
if (filename == NULL) |
|
return NULL; |
|
} |
dirname = NULL; |
dirname = NULL; |
} |
} |
|
|
Line 1467 filename_completion_function(const char |
|
Line 1480 filename_completion_function(const char |
|
free(temp); /* no longer needed */ |
free(temp); /* no longer needed */ |
} |
} |
/* will be used in cycle */ |
/* will be used in cycle */ |
filename_len = strlen(filename); |
filename_len = filename ? strlen(filename) : 0; |
if (filename_len == 0) |
|
return (NULL); /* no expansion possible */ |
|
|
|
if (dir != NULL) { |
if (dir != NULL) { |
(void)closedir(dir); |
(void)closedir(dir); |
Line 1481 filename_completion_function(const char |
|
Line 1492 filename_completion_function(const char |
|
} |
} |
/* find the match */ |
/* find the match */ |
while ((entry = readdir(dir)) != NULL) { |
while ((entry = readdir(dir)) != NULL) { |
|
/* skip . and .. */ |
|
if (entry->d_name[0] == '.' && (!entry->d_name[1] |
|
|| (entry->d_name[1] == '.' && !entry->d_name[2]))) |
|
continue; |
|
if (filename_len == 0) |
|
break; |
/* otherwise, get first entry where first */ |
/* otherwise, get first entry where first */ |
/* filename_len characters are equal */ |
/* filename_len characters are equal */ |
if (entry->d_name[0] == filename[0] |
if (entry->d_name[0] == filename[0] |
Line 1564 _el_rl_complete(EditLine *el __attribute |
|
Line 1581 _el_rl_complete(EditLine *el __attribute |
|
return (unsigned char) rl_complete(0, ch); |
return (unsigned char) rl_complete(0, ch); |
} |
} |
|
|
|
/* |
|
* el-compatible wrapper to send TSTP on ^Z |
|
*/ |
|
/* ARGSUSED */ |
|
static unsigned char |
|
_el_rl_tstp(EditLine *el __attribute__((__unused__)), int ch __attribute__((__unused__))) |
|
{ |
|
(void)kill(0, SIGTSTP); |
|
return CC_NORM; |
|
} |
|
|
/* |
/* |
* returns list of completions for text given |
* returns list of completions for text given |
Line 1727 rl_complete_internal(int what_to_do) |
|
Line 1754 rl_complete_internal(int what_to_do) |
|
rl_point = li->cursor - li->buffer; |
rl_point = li->cursor - li->buffer; |
rl_end = li->lastchar - li->buffer; |
rl_end = li->lastchar - li->buffer; |
|
|
if (!rl_attempted_completion_function) |
if (rl_attempted_completion_function) { |
matches = completion_matches(temp, (CPFunction *)complet_func); |
|
else { |
|
int end = li->cursor - li->buffer; |
int end = li->cursor - li->buffer; |
matches = (*rl_attempted_completion_function) (temp, (int) |
matches = (*rl_attempted_completion_function) (temp, (int) |
(end - len), end); |
(end - len), end); |
} |
} else |
|
matches = 0; |
|
if (!rl_attempted_completion_function || !matches) |
|
matches = completion_matches(temp, (CPFunction *)complet_func); |
|
|
if (matches) { |
if (matches) { |
int i, retval = CC_REFRESH; |
int i, retval = CC_REFRESH; |
Line 1837 rl_complete(int ignore, int invoking_key |
|
Line 1865 rl_complete(int ignore, int invoking_key |
|
rl_initialize(); |
rl_initialize(); |
|
|
if (rl_inhibit_completion) { |
if (rl_inhibit_completion) { |
rl_insert(ignore, invoking_key); |
char arr[2]; |
|
arr[0] = (char)invoking_key; |
|
arr[1] = '\0'; |
|
el_insertstr(e, arr); |
return (CC_REFRESH); |
return (CC_REFRESH); |
} else if (e->el_state.lastcmd == el_rl_complete_cmdnum) |
} else if (e->el_state.lastcmd == el_rl_complete_cmdnum) |
return rl_complete_internal('?'); |
return rl_complete_internal('?'); |
Line 2052 rl_parse_and_bind(const char *line) |
|
Line 2083 rl_parse_and_bind(const char *line) |
|
Tokenizer *tok; |
Tokenizer *tok; |
|
|
tok = tok_init(NULL); |
tok = tok_init(NULL); |
tok_line(tok, line, &argc, &argv); |
tok_str(tok, line, &argc, &argv); |
argc = el_parse(e, argc, argv); |
argc = el_parse(e, argc, argv); |
tok_end(tok); |
tok_end(tok); |
return (argc ? 1 : 0); |
return (argc ? 1 : 0); |
Line 2071 rl_stuff_char(int c) |
|
Line 2102 rl_stuff_char(int c) |
|
static int |
static int |
_rl_event_read_char(EditLine *el, char *cp) |
_rl_event_read_char(EditLine *el, char *cp) |
{ |
{ |
int n, num_read; |
int n, num_read = 0; |
|
|
*cp = 0; |
*cp = 0; |
while (rl_event_hook) { |
while (rl_event_hook) { |