version 1.95, 2011/07/28 20:50:55 |
version 1.96, 2011/07/29 15:16:33 |
|
|
_get_prompt(EditLine *el __attribute__((__unused__))) |
_get_prompt(EditLine *el __attribute__((__unused__))) |
{ |
{ |
rl_already_prompted = 1; |
rl_already_prompted = 1; |
return (rl_prompt); |
return rl_prompt; |
} |
} |
|
|
|
|
Line 191 _move_history(int op) |
|
Line 191 _move_history(int op) |
|
static HIST_ENTRY rl_he; |
static HIST_ENTRY rl_he; |
|
|
if (history(h, &ev, op) != 0) |
if (history(h, &ev, op) != 0) |
return (HIST_ENTRY *) NULL; |
return NULL; |
|
|
rl_he.line = ev.str; |
rl_he.line = ev.str; |
rl_he.data = NULL; |
rl_he.data = NULL; |
|
|
return (&rl_he); |
return &rl_he; |
} |
} |
|
|
|
|
Line 305 rl_initialize(void) |
|
Line 305 rl_initialize(void) |
|
|
|
h = history_init(); |
h = history_init(); |
if (!e || !h) |
if (!e || !h) |
return (-1); |
return -1; |
|
|
history(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */ |
history(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */ |
history_length = 0; |
history_length = 0; |
Line 366 rl_initialize(void) |
|
Line 366 rl_initialize(void) |
|
if (rl_startup_hook) |
if (rl_startup_hook) |
(*rl_startup_hook)(NULL, 0); |
(*rl_startup_hook)(NULL, 0); |
|
|
return (0); |
return 0; |
} |
} |
|
|
|
|
Line 486 _rl_compat_sub(const char *str, const ch |
|
Line 486 _rl_compat_sub(const char *str, const ch |
|
s += what_len; |
s += what_len; |
if (!globally) { |
if (!globally) { |
(void)strcpy(r, s); |
(void)strcpy(r, s); |
return(result); |
return result; |
} |
} |
} else |
} else |
*r++ = *s++; |
*r++ = *s++; |
} |
} |
*r = '\0'; |
*r = '\0'; |
return(result); |
return result; |
} |
} |
|
|
static char *last_search_pat; /* last !?pat[?] search pattern */ |
static char *last_search_pat; /* last !?pat[?] search pattern */ |
Line 509 get_history_event(const char *cmd, int * |
|
Line 509 get_history_event(const char *cmd, int * |
|
|
|
idx = *cindex; |
idx = *cindex; |
if (cmd[idx++] != history_expansion_char) |
if (cmd[idx++] != history_expansion_char) |
return(NULL); |
return NULL; |
|
|
/* find out which event to take */ |
/* find out which event to take */ |
if (cmd[idx] == history_expansion_char || cmd[idx] == '\0') { |
if (cmd[idx] == history_expansion_char || cmd[idx] == '\0') { |
if (history(h, &ev, H_FIRST) != 0) |
if (history(h, &ev, H_FIRST) != 0) |
return(NULL); |
return NULL; |
*cindex = cmd[idx]? (idx + 1):idx; |
*cindex = cmd[idx]? (idx + 1):idx; |
return ev.str; |
return ev.str; |
} |
} |
Line 536 get_history_event(const char *cmd, int * |
|
Line 536 get_history_event(const char *cmd, int * |
|
num = history_length - num + 1; |
num = history_length - num + 1; |
|
|
if (!(rl_he = history_get(num))) |
if (!(rl_he = history_get(num))) |
return(NULL); |
return NULL; |
|
|
*cindex = idx; |
*cindex = idx; |
return(rl_he->line); |
return rl_he->line; |
} |
} |
sub = 0; |
sub = 0; |
if (cmd[idx] == '?') { |
if (cmd[idx] == '?') { |
Line 563 get_history_event(const char *cmd, int * |
|
Line 563 get_history_event(const char *cmd, int * |
|
if (sub && len == 0 && last_search_pat && *last_search_pat) |
if (sub && len == 0 && last_search_pat && *last_search_pat) |
pat = last_search_pat; |
pat = last_search_pat; |
else if (len == 0) |
else if (len == 0) |
return(NULL); |
return NULL; |
else { |
else { |
if ((pat = el_malloc((len + 1) * sizeof(*pat))) == NULL) |
if ((pat = el_malloc((len + 1) * sizeof(*pat))) == NULL) |
return NULL; |
return NULL; |
Line 574 get_history_event(const char *cmd, int * |
|
Line 574 get_history_event(const char *cmd, int * |
|
if (history(h, &ev, H_CURR) != 0) { |
if (history(h, &ev, H_CURR) != 0) { |
if (pat != last_search_pat) |
if (pat != last_search_pat) |
el_free(pat); |
el_free(pat); |
return (NULL); |
return NULL; |
} |
} |
num = ev.num; |
num = ev.num; |
|
|
Line 594 get_history_event(const char *cmd, int * |
|
Line 594 get_history_event(const char *cmd, int * |
|
(void)fprintf(rl_outstream, "%s: Event not found\n", pat); |
(void)fprintf(rl_outstream, "%s: Event not found\n", pat); |
if (pat != last_search_pat) |
if (pat != last_search_pat) |
el_free(pat); |
el_free(pat); |
return(NULL); |
return NULL; |
} |
} |
|
|
if (sub && len) { |
if (sub && len) { |
Line 607 get_history_event(const char *cmd, int * |
|
Line 607 get_history_event(const char *cmd, int * |
|
el_free(pat); |
el_free(pat); |
|
|
if (history(h, &ev, H_CURR) != 0) |
if (history(h, &ev, H_CURR) != 0) |
return(NULL); |
return NULL; |
*cindex = idx; |
*cindex = idx; |
rptr = ev.str; |
rptr = ev.str; |
|
|
Line 675 _history_expand_command(const char *comm |
|
Line 675 _history_expand_command(const char *comm |
|
} |
} |
|
|
if (ptr == NULL && aptr == NULL) |
if (ptr == NULL && aptr == NULL) |
return(-1); |
return -1; |
|
|
if (!has_mods) { |
if (!has_mods) { |
*result = strdup(aptr ? aptr : ptr); |
*result = strdup(aptr ? aptr : ptr); |
Line 683 _history_expand_command(const char *comm |
|
Line 683 _history_expand_command(const char *comm |
|
el_free(aptr); |
el_free(aptr); |
if (*result == NULL) |
if (*result == NULL) |
return -1; |
return -1; |
return(1); |
return 1; |
} |
} |
|
|
cmd = command + offs + idx + 1; |
cmd = command + offs + idx + 1; |
Line 729 _history_expand_command(const char *comm |
|
Line 729 _history_expand_command(const char *comm |
|
command + offs + idx); |
command + offs + idx); |
if (aptr) |
if (aptr) |
el_free(aptr); |
el_free(aptr); |
return(-1); |
return -1; |
} |
} |
} else |
} else |
tmp = strdup(aptr? aptr:ptr); |
tmp = strdup(aptr? aptr:ptr); |
Line 739 _history_expand_command(const char *comm |
|
Line 739 _history_expand_command(const char *comm |
|
|
|
if (*cmd == '\0' || ((size_t)(cmd - (command + offs)) >= cmdlen)) { |
if (*cmd == '\0' || ((size_t)(cmd - (command + offs)) >= cmdlen)) { |
*result = tmp; |
*result = tmp; |
return(1); |
return 1; |
} |
} |
|
|
for (; *cmd; cmd++) { |
for (; *cmd; cmd++) { |
Line 814 _history_expand_command(const char *comm |
|
Line 814 _history_expand_command(const char *comm |
|
} else { |
} else { |
from = NULL; |
from = NULL; |
el_free(tmp); |
el_free(tmp); |
return (-1); |
return -1; |
} |
} |
} |
} |
cmd++; /* shift after delim */ |
cmd++; /* shift after delim */ |
Line 868 _history_expand_command(const char *comm |
|
Line 868 _history_expand_command(const char *comm |
|
} |
} |
} |
} |
*result = tmp; |
*result = tmp; |
return (p_on? 2:1); |
return p_on? 2:1; |
} |
} |
|
|
|
|
Line 887 history_expand(char *str, char **output) |
|
Line 887 history_expand(char *str, char **output) |
|
|
|
if (history_expansion_char == 0) { |
if (history_expansion_char == 0) { |
*output = strdup(str); |
*output = strdup(str); |
return(0); |
return 0; |
} |
} |
|
|
*output = NULL; |
*output = NULL; |
|
|
el_free(*output); |
el_free(*output); |
*output = result; |
*output = result; |
|
|
return (ret); |
return ret; |
} |
} |
|
|
/* |
/* |
Line 1116 history_tokenize(const char *str) |
|
Line 1116 history_tokenize(const char *str) |
|
if (str[i]) |
if (str[i]) |
i++; |
i++; |
} |
} |
return (result); |
return result; |
} |
} |
|
|
|
|
Line 1148 unstifle_history(void) |
|
Line 1148 unstifle_history(void) |
|
history(h, &ev, H_SETSIZE, INT_MAX); |
history(h, &ev, H_SETSIZE, INT_MAX); |
omax = max_input_history; |
omax = max_input_history; |
max_input_history = INT_MAX; |
max_input_history = INT_MAX; |
return (omax); /* some value _must_ be returned */ |
return omax; /* some value _must_ be returned */ |
} |
} |
|
|
|
|
Line 1157 history_is_stifled(void) |
|
Line 1157 history_is_stifled(void) |
|
{ |
{ |
|
|
/* cannot return true answer */ |
/* cannot return true answer */ |
return (max_input_history != INT_MAX); |
return max_input_history != INT_MAX; |
} |
} |
|
|
static const char _history_tmp_template[] = "/tmp/.historyXXXXXX"; |
static const char _history_tmp_template[] = "/tmp/.historyXXXXXX"; |
Line 1309 read_history(const char *filename) |
|
Line 1309 read_history(const char *filename) |
|
rl_initialize(); |
rl_initialize(); |
if (filename == NULL && (filename = _default_history_file()) == NULL) |
if (filename == NULL && (filename = _default_history_file()) == NULL) |
return errno; |
return errno; |
return (history(h, &ev, H_LOAD, filename) == -1 ? |
return history(h, &ev, H_LOAD, filename) == -1 ? |
(errno ? errno : EINVAL) : 0); |
(errno ? errno : EINVAL) : 0; |
} |
} |
|
|
|
|
Line 1326 write_history(const char *filename) |
|
Line 1326 write_history(const char *filename) |
|
rl_initialize(); |
rl_initialize(); |
if (filename == NULL && (filename = _default_history_file()) == NULL) |
if (filename == NULL && (filename = _default_history_file()) == NULL) |
return errno; |
return errno; |
return (history(h, &ev, H_SAVE, filename) == -1 ? |
return history(h, &ev, H_SAVE, filename) == -1 ? |
(errno ? errno : EINVAL) : 0); |
(errno ? errno : EINVAL) : 0; |
} |
} |
|
|
|
|
Line 1348 history_get(int num) |
|
Line 1348 history_get(int num) |
|
|
|
/* save current position */ |
/* save current position */ |
if (history(h, &ev, H_CURR) != 0) |
if (history(h, &ev, H_CURR) != 0) |
return (NULL); |
return NULL; |
curr_num = ev.num; |
curr_num = ev.num; |
|
|
/* start from the oldest */ |
/* start from the oldest */ |
if (history(h, &ev, H_LAST) != 0) |
if (history(h, &ev, H_LAST) != 0) |
return (NULL); /* error */ |
return NULL; /* error */ |
|
|
/* look forwards for event matching specified offset */ |
/* look forwards for event matching specified offset */ |
if (history(h, &ev, H_NEXT_EVDATA, num, &she.data)) |
if (history(h, &ev, H_NEXT_EVDATA, num, &she.data)) |
return (NULL); |
return NULL; |
|
|
she.line = ev.str; |
she.line = ev.str; |
|
|
/* restore pointer to where it was */ |
/* restore pointer to where it was */ |
(void)history(h, &ev, H_SET, curr_num); |
(void)history(h, &ev, H_SET, curr_num); |
|
|
return (&she); |
return &she; |
} |
} |
|
|
|
|
Line 1383 add_history(const char *line) |
|
Line 1383 add_history(const char *line) |
|
if (history(h, &ev, H_GETSIZE) == 0) |
if (history(h, &ev, H_GETSIZE) == 0) |
history_length = ev.num; |
history_length = ev.num; |
|
|
return (!(history_length > 0)); /* return 0 if all is okay */ |
return !(history_length > 0); /* return 0 if all is okay */ |
} |
} |
|
|
|
|
Line 1484 where_history(void) |
|
Line 1484 where_history(void) |
|
int curr_num, off; |
int curr_num, off; |
|
|
if (history(h, &ev, H_CURR) != 0) |
if (history(h, &ev, H_CURR) != 0) |
return (0); |
return 0; |
curr_num = ev.num; |
curr_num = ev.num; |
|
|
(void)history(h, &ev, H_FIRST); |
(void)history(h, &ev, H_FIRST); |
Line 1492 where_history(void) |
|
Line 1492 where_history(void) |
|
while (ev.num != curr_num && history(h, &ev, H_NEXT) == 0) |
while (ev.num != curr_num && history(h, &ev, H_NEXT) == 0) |
off++; |
off++; |
|
|
return (off); |
return off; |
} |
} |
|
|
|
|
|
|
current_history(void) |
current_history(void) |
{ |
{ |
|
|
return (_move_history(H_CURR)); |
return _move_history(H_CURR); |
} |
} |
|
|
|
|
Line 1518 history_total_bytes(void) |
|
Line 1518 history_total_bytes(void) |
|
size_t size; |
size_t size; |
|
|
if (history(h, &ev, H_CURR) != 0) |
if (history(h, &ev, H_CURR) != 0) |
return (-1); |
return -1; |
curr_num = ev.num; |
curr_num = ev.num; |
|
|
(void)history(h, &ev, H_FIRST); |
(void)history(h, &ev, H_FIRST); |
Line 1530 history_total_bytes(void) |
|
Line 1530 history_total_bytes(void) |
|
/* get to the same position as before */ |
/* get to the same position as before */ |
history(h, &ev, H_PREV_EVENT, curr_num); |
history(h, &ev, H_PREV_EVENT, curr_num); |
|
|
return (int)(size); |
return (int)size; |
} |
} |
|
|
|
|
Line 1544 history_set_pos(int pos) |
|
Line 1544 history_set_pos(int pos) |
|
int curr_num; |
int curr_num; |
|
|
if (pos >= history_length || pos < 0) |
if (pos >= history_length || pos < 0) |
return (-1); |
return -1; |
|
|
(void)history(h, &ev, H_CURR); |
(void)history(h, &ev, H_CURR); |
curr_num = ev.num; |
curr_num = ev.num; |
Line 1555 history_set_pos(int pos) |
|
Line 1555 history_set_pos(int pos) |
|
*/ |
*/ |
if (history(h, &ev, H_DELDATA, pos, (void **)-1)) { |
if (history(h, &ev, H_DELDATA, pos, (void **)-1)) { |
(void)history(h, &ev, H_SET, curr_num); |
(void)history(h, &ev, H_SET, curr_num); |
return(-1); |
return -1; |
} |
} |
return (0); |
return 0; |
} |
} |
|
|
|
|
|
|
previous_history(void) |
previous_history(void) |
{ |
{ |
|
|
return (_move_history(H_PREV)); |
return _move_history(H_PREV); |
} |
} |
|
|
|
|
|
|
next_history(void) |
next_history(void) |
{ |
{ |
|
|
return (_move_history(H_NEXT)); |
return _move_history(H_NEXT); |
} |
} |
|
|
|
|
Line 1594 history_search(const char *str, int dire |
|
Line 1594 history_search(const char *str, int dire |
|
int curr_num; |
int curr_num; |
|
|
if (history(h, &ev, H_CURR) != 0) |
if (history(h, &ev, H_CURR) != 0) |
return (-1); |
return -1; |
curr_num = ev.num; |
curr_num = ev.num; |
|
|
for (;;) { |
for (;;) { |
if ((strp = strstr(ev.str, str)) != NULL) |
if ((strp = strstr(ev.str, str)) != NULL) |
return (int) (strp - ev.str); |
return (int)(strp - ev.str); |
if (history(h, &ev, direction < 0 ? H_NEXT:H_PREV) != 0) |
if (history(h, &ev, direction < 0 ? H_NEXT:H_PREV) != 0) |
break; |
break; |
} |
} |
(void)history(h, &ev, H_SET, curr_num); |
(void)history(h, &ev, H_SET, curr_num); |
return (-1); |
return -1; |
} |
} |
|
|
|
|
Line 1637 history_search_pos(const char *str, |
|
Line 1637 history_search_pos(const char *str, |
|
pos = (pos > 0) ? 1 : -1; |
pos = (pos > 0) ? 1 : -1; |
|
|
if (history(h, &ev, H_CURR) != 0) |
if (history(h, &ev, H_CURR) != 0) |
return (-1); |
return -1; |
curr_num = ev.num; |
curr_num = ev.num; |
|
|
if (history_set_pos(off) != 0 || history(h, &ev, H_CURR) != 0) |
if (history_set_pos(off) != 0 || history(h, &ev, H_CURR) != 0) |
return (-1); |
return -1; |
|
|
for (;;) { |
for (;;) { |
if (strstr(ev.str, str)) |
if (strstr(ev.str, str)) |
return (off); |
return off; |
if (history(h, &ev, (pos < 0) ? H_PREV : H_NEXT) != 0) |
if (history(h, &ev, (pos < 0) ? H_PREV : H_NEXT) != 0) |
break; |
break; |
} |
} |
Line 1654 history_search_pos(const char *str, |
|
Line 1654 history_search_pos(const char *str, |
|
(void)history(h, &ev, |
(void)history(h, &ev, |
pos < 0 ? H_NEXT_EVENT : H_PREV_EVENT, curr_num); |
pos < 0 ? H_NEXT_EVENT : H_PREV_EVENT, curr_num); |
|
|
return (-1); |
return -1; |
} |
} |
|
|
|
|
Line 1690 username_completion_function(const char |
|
Line 1690 username_completion_function(const char |
|
struct passwd *pass = NULL; |
struct passwd *pass = NULL; |
|
|
if (text[0] == '\0') |
if (text[0] == '\0') |
return (NULL); |
return NULL; |
|
|
if (*text == '~') |
if (*text == '~') |
text++; |
text++; |
Line 1770 rl_complete(int ignore __attribute__((__ |
|
Line 1770 rl_complete(int ignore __attribute__((__ |
|
arr[0] = (char)invoking_key; |
arr[0] = (char)invoking_key; |
arr[1] = '\0'; |
arr[1] = '\0'; |
el_insertstr(e, arr); |
el_insertstr(e, arr); |
return (CC_REFRESH); |
return CC_REFRESH; |
} |
} |
|
|
/* Just look at how many global variables modify this operation! */ |
/* Just look at how many global variables modify this operation! */ |
Line 1815 rl_bind_key(int c, rl_command_func_t *fu |
|
Line 1815 rl_bind_key(int c, rl_command_func_t *fu |
|
e->el_map.key[c] = ED_INSERT; |
e->el_map.key[c] = ED_INSERT; |
retval = 0; |
retval = 0; |
} |
} |
return (retval); |
return retval; |
} |
} |
|
|
|
|
Line 1831 rl_read_key(void) |
|
Line 1831 rl_read_key(void) |
|
if (e == NULL || h == NULL) |
if (e == NULL || h == NULL) |
rl_initialize(); |
rl_initialize(); |
|
|
return (el_getc(e, fooarr)); |
return el_getc(e, fooarr); |
} |
} |
|
|
|
|
Line 1867 rl_insert(int count, int c) |
|
Line 1867 rl_insert(int count, int c) |
|
for (; count > 0; count--) |
for (; count > 0; count--) |
el_push(e, arr); |
el_push(e, arr); |
|
|
return (0); |
return 0; |
} |
} |
|
|
int |
int |
rl_insert_text(const char *text) |
rl_insert_text(const char *text) |
{ |
{ |
if (!text || *text == 0) |
if (!text || *text == 0) |
return (0); |
return 0; |
|
|
if (h == NULL || e == NULL) |
if (h == NULL || e == NULL) |
rl_initialize(); |
rl_initialize(); |
|
|
if (el_insertstr(e, text) < 0) |
if (el_insertstr(e, text) < 0) |
return (0); |
return 0; |
return (int)strlen(text); |
return (int)strlen(text); |
} |
} |
|
|
Line 2005 rl_deprep_terminal(void) |
|
Line 2005 rl_deprep_terminal(void) |
|
int |
int |
rl_read_init_file(const char *s) |
rl_read_init_file(const char *s) |
{ |
{ |
return(el_source(e, s)); |
return el_source(e, s); |
} |
} |
|
|
int |
int |
Line 2019 rl_parse_and_bind(const char *line) |
|
Line 2019 rl_parse_and_bind(const char *line) |
|
tok_str(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; |
} |
} |
|
|
int |
int |
Line 2029 rl_variable_bind(const char *var, const |
|
Line 2029 rl_variable_bind(const char *var, const |
|
* The proper return value is undocument, but this is what the |
* The proper return value is undocument, but this is what the |
* readline source seems to do. |
* readline source seems to do. |
*/ |
*/ |
return ((el_set(e, EL_BIND, "", var, value) == -1) ? 1 : 0); |
return el_set(e, EL_BIND, "", var, value) == -1 ? 1 : 0; |
} |
} |
|
|
void |
void |
Line 2055 _rl_event_read_char(EditLine *el, char * |
|
Line 2055 _rl_event_read_char(EditLine *el, char * |
|
|
|
#if defined(FIONREAD) |
#if defined(FIONREAD) |
if (ioctl(el->el_infd, FIONREAD, &n) < 0) |
if (ioctl(el->el_infd, FIONREAD, &n) < 0) |
return(-1); |
return -1; |
if (n) |
if (n) |
num_read = read(el->el_infd, cp, 1); |
num_read = read(el->el_infd, cp, 1); |
else |
else |
num_read = 0; |
num_read = 0; |
#elif defined(F_SETFL) && defined(O_NDELAY) |
#elif defined(F_SETFL) && defined(O_NDELAY) |
if ((n = fcntl(el->el_infd, F_GETFL, 0)) < 0) |
if ((n = fcntl(el->el_infd, F_GETFL, 0)) < 0) |
return(-1); |
return -1; |
if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) < 0) |
if (fcntl(el->el_infd, F_SETFL, n|O_NDELAY) < 0) |
return(-1); |
return -1; |
num_read = read(el->el_infd, cp, 1); |
num_read = read(el->el_infd, cp, 1); |
if (fcntl(el->el_infd, F_SETFL, n)) |
if (fcntl(el->el_infd, F_SETFL, n)) |
return(-1); |
return -1; |
#else |
#else |
/* not non-blocking, but what you gonna do? */ |
/* not non-blocking, but what you gonna do? */ |
num_read = read(el->el_infd, cp, 1); |
num_read = read(el->el_infd, cp, 1); |
return(-1); |
return -1; |
#endif |
#endif |
|
|
if (num_read < 0 && errno == EAGAIN) |
if (num_read < 0 && errno == EAGAIN) |
Line 2200 history_get_history_state(void) |
|
Line 2200 history_get_history_state(void) |
|
HISTORY_STATE *hs; |
HISTORY_STATE *hs; |
|
|
if ((hs = el_malloc(sizeof(*hs))) == NULL) |
if ((hs = el_malloc(sizeof(*hs))) == NULL) |
return (NULL); |
return NULL; |
hs->length = history_length; |
hs->length = history_length; |
return (hs); |
return hs; |
} |
} |
|
|
int |
int |