version 1.94, 2011/07/28 17:33:39 |
version 1.95, 2011/07/28 20:50:55 |
Line 261 rl_set_prompt(const char *prompt) |
|
Line 261 rl_set_prompt(const char *prompt) |
|
if (rl_prompt != NULL && strcmp(rl_prompt, prompt) == 0) |
if (rl_prompt != NULL && strcmp(rl_prompt, prompt) == 0) |
return 0; |
return 0; |
if (rl_prompt) |
if (rl_prompt) |
free(rl_prompt); |
el_free(rl_prompt); |
rl_prompt = strdup(prompt); |
rl_prompt = strdup(prompt); |
if (rl_prompt == NULL) |
if (rl_prompt == NULL) |
return -1; |
return -1; |
Line 475 _rl_compat_sub(const char *str, const ch |
|
Line 475 _rl_compat_sub(const char *str, const ch |
|
} else |
} else |
s++; |
s++; |
} |
} |
r = result = malloc(len + 1); |
r = result = el_malloc((len + 1) * sizeof(*r)); |
if (result == NULL) |
if (result == NULL) |
return NULL; |
return NULL; |
s = str; |
s = str; |
Line 565 get_history_event(const char *cmd, int * |
|
Line 565 get_history_event(const char *cmd, int * |
|
else if (len == 0) |
else if (len == 0) |
return(NULL); |
return(NULL); |
else { |
else { |
if ((pat = malloc(len + 1)) == NULL) |
if ((pat = el_malloc((len + 1) * sizeof(*pat))) == NULL) |
return NULL; |
return NULL; |
(void)strncpy(pat, cmd + begin, len); |
(void)strncpy(pat, cmd + begin, len); |
pat[len] = '\0'; |
pat[len] = '\0'; |
Line 573 get_history_event(const char *cmd, int * |
|
Line 573 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) |
free(pat); |
el_free(pat); |
return (NULL); |
return (NULL); |
} |
} |
num = ev.num; |
num = ev.num; |
Line 581 get_history_event(const char *cmd, int * |
|
Line 581 get_history_event(const char *cmd, int * |
|
if (sub) { |
if (sub) { |
if (pat != last_search_pat) { |
if (pat != last_search_pat) { |
if (last_search_pat) |
if (last_search_pat) |
free(last_search_pat); |
el_free(last_search_pat); |
last_search_pat = pat; |
last_search_pat = pat; |
} |
} |
ret = history_search(pat, -1); |
ret = history_search(pat, -1); |
Line 593 get_history_event(const char *cmd, int * |
|
Line 593 get_history_event(const char *cmd, int * |
|
history(h, &ev, H_FIRST); |
history(h, &ev, H_FIRST); |
(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) |
free(pat); |
el_free(pat); |
return(NULL); |
return(NULL); |
} |
} |
|
|
if (sub && len) { |
if (sub && len) { |
if (last_search_match && last_search_match != pat) |
if (last_search_match && last_search_match != pat) |
free(last_search_match); |
el_free(last_search_match); |
last_search_match = pat; |
last_search_match = pat; |
} |
} |
|
|
if (pat != last_search_pat) |
if (pat != last_search_pat) |
free(pat); |
el_free(pat); |
|
|
if (history(h, &ev, H_CURR) != 0) |
if (history(h, &ev, H_CURR) != 0) |
return(NULL); |
return(NULL); |
Line 659 _history_expand_command(const char *comm |
|
Line 659 _history_expand_command(const char *comm |
|
} else { |
} else { |
if (command[offs + 1] == '#') { |
if (command[offs + 1] == '#') { |
/* use command so far */ |
/* use command so far */ |
if ((aptr = malloc(offs + 1)) == NULL) |
if ((aptr = el_malloc((offs + 1) * sizeof(*aptr))) |
|
== NULL) |
return -1; |
return -1; |
(void)strncpy(aptr, command, offs); |
(void)strncpy(aptr, command, offs); |
aptr[offs] = '\0'; |
aptr[offs] = '\0'; |
Line 679 _history_expand_command(const char *comm |
|
Line 680 _history_expand_command(const char *comm |
|
if (!has_mods) { |
if (!has_mods) { |
*result = strdup(aptr ? aptr : ptr); |
*result = strdup(aptr ? aptr : ptr); |
if (aptr) |
if (aptr) |
free(aptr); |
el_free(aptr); |
if (*result == NULL) |
if (*result == NULL) |
return -1; |
return -1; |
return(1); |
return(1); |
Line 727 _history_expand_command(const char *comm |
|
Line 728 _history_expand_command(const char *comm |
|
(void)fprintf(rl_outstream, "%s: Bad word specifier", |
(void)fprintf(rl_outstream, "%s: Bad word specifier", |
command + offs + idx); |
command + offs + idx); |
if (aptr) |
if (aptr) |
free(aptr); |
el_free(aptr); |
return(-1); |
return(-1); |
} |
} |
} else |
} else |
tmp = strdup(aptr? aptr:ptr); |
tmp = strdup(aptr? aptr:ptr); |
|
|
if (aptr) |
if (aptr) |
free(aptr); |
el_free(aptr); |
|
|
if (*cmd == '\0' || ((size_t)(cmd - (command + offs)) >= cmdlen)) { |
if (*cmd == '\0' || ((size_t)(cmd - (command + offs)) >= cmdlen)) { |
*result = tmp; |
*result = tmp; |
Line 750 _history_expand_command(const char *comm |
|
Line 751 _history_expand_command(const char *comm |
|
} else if (*cmd == 't') { /* remove leading path */ |
} else if (*cmd == 't') { /* remove leading path */ |
if ((aptr = strrchr(tmp, '/')) != NULL) { |
if ((aptr = strrchr(tmp, '/')) != NULL) { |
aptr = strdup(aptr + 1); |
aptr = strdup(aptr + 1); |
free(tmp); |
el_free(tmp); |
tmp = aptr; |
tmp = aptr; |
} |
} |
} else if (*cmd == 'r') { /* remove trailing suffix */ |
} else if (*cmd == 'r') { /* remove trailing suffix */ |
Line 759 _history_expand_command(const char *comm |
|
Line 760 _history_expand_command(const char *comm |
|
} else if (*cmd == 'e') { /* remove all but suffix */ |
} else if (*cmd == 'e') { /* remove all but suffix */ |
if ((aptr = strrchr(tmp, '.')) != NULL) { |
if ((aptr = strrchr(tmp, '.')) != NULL) { |
aptr = strdup(aptr); |
aptr = strdup(aptr); |
free(tmp); |
el_free(tmp); |
tmp = aptr; |
tmp = aptr; |
} |
} |
} else if (*cmd == 'p') /* print only */ |
} else if (*cmd == 'p') /* print only */ |
Line 776 _history_expand_command(const char *comm |
|
Line 777 _history_expand_command(const char *comm |
|
else if (*cmd == 's') { |
else if (*cmd == 's') { |
delim = *(++cmd), cmd++; |
delim = *(++cmd), cmd++; |
size = 16; |
size = 16; |
what = realloc(from, size); |
what = el_realloc(from, size * sizeof(*what)); |
if (what == NULL) { |
if (what == NULL) { |
free(from); |
el_free(from); |
free(tmp); |
el_free(tmp); |
return 0; |
return 0; |
} |
} |
len = 0; |
len = 0; |
Line 788 _history_expand_command(const char *comm |
|
Line 789 _history_expand_command(const char *comm |
|
cmd++; |
cmd++; |
if (len >= size) { |
if (len >= size) { |
char *nwhat; |
char *nwhat; |
nwhat = realloc(what, |
nwhat = el_realloc(what, |
(size <<= 1)); |
(size <<= 1) * |
|
sizeof(*nwhat)); |
if (nwhat == NULL) { |
if (nwhat == NULL) { |
free(what); |
el_free(what); |
free(tmp); |
el_free(tmp); |
return 0; |
return 0; |
} |
} |
what = nwhat; |
what = nwhat; |
Line 802 _history_expand_command(const char *comm |
|
Line 804 _history_expand_command(const char *comm |
|
what[len] = '\0'; |
what[len] = '\0'; |
from = what; |
from = what; |
if (*what == '\0') { |
if (*what == '\0') { |
free(what); |
el_free(what); |
if (search) { |
if (search) { |
from = strdup(search); |
from = strdup(search); |
if (from == NULL) { |
if (from == NULL) { |
free(tmp); |
el_free(tmp); |
return 0; |
return 0; |
} |
} |
} else { |
} else { |
from = NULL; |
from = NULL; |
free(tmp); |
el_free(tmp); |
return (-1); |
return (-1); |
} |
} |
} |
} |
Line 820 _history_expand_command(const char *comm |
|
Line 822 _history_expand_command(const char *comm |
|
continue; |
continue; |
|
|
size = 16; |
size = 16; |
with = realloc(to, size); |
with = el_realloc(to, size * sizeof(*with)); |
if (with == NULL) { |
if (with == NULL) { |
free(to); |
el_free(to); |
free(tmp); |
el_free(tmp); |
return -1; |
return -1; |
} |
} |
len = 0; |
len = 0; |
Line 832 _history_expand_command(const char *comm |
|
Line 834 _history_expand_command(const char *comm |
|
if (len + from_len + 1 >= size) { |
if (len + from_len + 1 >= size) { |
char *nwith; |
char *nwith; |
size += from_len + 1; |
size += from_len + 1; |
nwith = realloc(with, size); |
nwith = el_realloc(with, |
|
size * sizeof(*nwith)); |
if (nwith == NULL) { |
if (nwith == NULL) { |
free(with); |
el_free(with); |
free(tmp); |
el_free(tmp); |
return -1; |
return -1; |
} |
} |
with = nwith; |
with = nwith; |
Line 858 _history_expand_command(const char *comm |
|
Line 861 _history_expand_command(const char *comm |
|
|
|
aptr = _rl_compat_sub(tmp, from, to, g_on); |
aptr = _rl_compat_sub(tmp, from, to, g_on); |
if (aptr) { |
if (aptr) { |
free(tmp); |
el_free(tmp); |
tmp = aptr; |
tmp = aptr; |
} |
} |
g_on = 0; |
g_on = 0; |
Line 890 history_expand(char *str, char **output) |
|
Line 893 history_expand(char *str, char **output) |
|
*output = NULL; |
*output = NULL; |
if (str[0] == history_subst_char) { |
if (str[0] == history_subst_char) { |
/* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */ |
/* ^foo^foo2^ is equivalent to !!:s^foo^foo2^ */ |
*output = malloc(strlen(str) + 4 + 1); |
*output = el_malloc((strlen(str) + 4 + 1) * sizeof(*output)); |
if (*output == NULL) |
if (*output == NULL) |
return 0; |
return 0; |
(*output)[0] = (*output)[1] = history_expansion_char; |
(*output)[0] = (*output)[1] = history_expansion_char; |
Line 907 history_expand(char *str, char **output) |
|
Line 910 history_expand(char *str, char **output) |
|
#define ADD_STRING(what, len, fr) \ |
#define ADD_STRING(what, len, fr) \ |
{ \ |
{ \ |
if (idx + len + 1 > size) { \ |
if (idx + len + 1 > size) { \ |
char *nresult = realloc(result, (size += len + 1));\ |
char *nresult = el_realloc(result, \ |
|
(size += len + 1) * sizeof(*nresult)); \ |
if (nresult == NULL) { \ |
if (nresult == NULL) { \ |
free(*output); \ |
el_free(*output); \ |
if (/*CONSTCOND*/fr) \ |
if (/*CONSTCOND*/fr) \ |
free(tmp); \ |
el_free(tmp); \ |
return 0; \ |
return 0; \ |
} \ |
} \ |
result = nresult; \ |
result = nresult; \ |
|
|
ADD_STRING(tmp, len, 1); |
ADD_STRING(tmp, len, 1); |
} |
} |
if (tmp) { |
if (tmp) { |
free(tmp); |
el_free(tmp); |
tmp = NULL; |
tmp = NULL; |
} |
} |
i = j; |
i = j; |
|
|
ret = -1; |
ret = -1; |
#endif |
#endif |
} |
} |
free(*output); |
el_free(*output); |
*output = result; |
*output = result; |
|
|
return (ret); |
return (ret); |
Line 1036 history_arg_extract(int start, int end, |
|
Line 1040 history_arg_extract(int start, int end, |
|
for (i = start, len = 0; i <= (size_t)end; i++) |
for (i = start, len = 0; i <= (size_t)end; i++) |
len += strlen(arr[i]) + 1; |
len += strlen(arr[i]) + 1; |
len++; |
len++; |
result = malloc(len); |
result = el_malloc(len * sizeof(*result)); |
if (result == NULL) |
if (result == NULL) |
goto out; |
goto out; |
|
|
Line 1050 history_arg_extract(int start, int end, |
|
Line 1054 history_arg_extract(int start, int end, |
|
|
|
out: |
out: |
for (i = 0; arr[i]; i++) |
for (i = 0; arr[i]; i++) |
free(arr[i]); |
el_free(arr[i]); |
free(arr); |
el_free(arr); |
|
|
return result; |
return result; |
} |
} |
Line 1090 history_tokenize(const char *str) |
|
Line 1094 history_tokenize(const char *str) |
|
if (idx + 2 >= size) { |
if (idx + 2 >= size) { |
char **nresult; |
char **nresult; |
size <<= 1; |
size <<= 1; |
nresult = realloc(result, size * sizeof(char *)); |
nresult = el_realloc(result, size * sizeof(*nresult)); |
if (nresult == NULL) { |
if (nresult == NULL) { |
free(result); |
el_free(result); |
return NULL; |
return NULL; |
} |
} |
result = nresult; |
result = nresult; |
} |
} |
len = i - start; |
len = i - start; |
temp = malloc(len + 1); |
temp = el_malloc((len + 1) * sizeof(*temp)); |
if (temp == NULL) { |
if (temp == NULL) { |
for (i = 0; i < idx; i++) |
for (i = 0; i < idx; i++) |
free(result[i]); |
el_free(result[i]); |
free(result); |
el_free(result); |
return NULL; |
return NULL; |
} |
} |
(void)strncpy(temp, &str[start], len); |
(void)strncpy(temp, &str[start], len); |
Line 1395 remove_history(int num) |
|
Line 1399 remove_history(int num) |
|
if (h == NULL || e == NULL) |
if (h == NULL || e == NULL) |
rl_initialize(); |
rl_initialize(); |
|
|
if ((he = malloc(sizeof(*he))) == NULL) |
if ((he = el_malloc(sizeof(*he))) == NULL) |
return NULL; |
return NULL; |
|
|
if (history(h, &ev, H_DELDATA, num, &he->data) != 0) { |
if (history(h, &ev, H_DELDATA, num, &he->data) != 0) { |
free(he); |
el_free(he); |
return NULL; |
return NULL; |
} |
} |
|
|
Line 1433 replace_history_entry(int num, const cha |
|
Line 1437 replace_history_entry(int num, const cha |
|
if (history(h, &ev, H_LAST) != 0) |
if (history(h, &ev, H_LAST) != 0) |
return NULL; /* error */ |
return NULL; /* error */ |
|
|
if ((he = malloc(sizeof(*he))) == NULL) |
if ((he = el_malloc(sizeof(*he))) == NULL) |
return NULL; |
return NULL; |
|
|
/* look forwards for event matching specified offset */ |
/* look forwards for event matching specified offset */ |
Line 1453 replace_history_entry(int num, const cha |
|
Line 1457 replace_history_entry(int num, const cha |
|
|
|
return he; |
return he; |
out: |
out: |
free(he); |
el_free(he); |
return NULL; |
return NULL; |
} |
} |
|
|
Line 2117 rl_completion_matches(const char *str, r |
|
Line 2121 rl_completion_matches(const char *str, r |
|
|
|
len = 1; |
len = 1; |
max = 10; |
max = 10; |
if ((list = malloc(max * sizeof(*list))) == NULL) |
if ((list = el_malloc(max * sizeof(*list))) == NULL) |
return NULL; |
return NULL; |
|
|
while ((match = (*fun)(str, (int)(len - 1))) != NULL) { |
while ((match = (*fun)(str, (int)(len - 1))) != NULL) { |
Line 2125 rl_completion_matches(const char *str, r |
|
Line 2129 rl_completion_matches(const char *str, r |
|
if (len == max) { |
if (len == max) { |
char **nl; |
char **nl; |
max += 10; |
max += 10; |
if ((nl = realloc(list, max * sizeof(*nl))) == NULL) |
if ((nl = el_realloc(list, max * sizeof(*nl))) == NULL) |
goto out; |
goto out; |
list = nl; |
list = nl; |
} |
} |
Line 2152 rl_completion_matches(const char *str, r |
|
Line 2156 rl_completion_matches(const char *str, r |
|
if ((list[0] = strdup(str)) == NULL) |
if ((list[0] = strdup(str)) == NULL) |
goto out; |
goto out; |
} else { |
} else { |
if ((list[0] = malloc(min + 1)) == NULL) |
if ((list[0] = el_malloc((min + 1) * sizeof(*list[0]))) == NULL) |
goto out; |
goto out; |
(void)memcpy(list[0], list[1], min); |
(void)memcpy(list[0], list[1], min); |
list[0][min] = '\0'; |
list[0][min] = '\0'; |
Line 2160 rl_completion_matches(const char *str, r |
|
Line 2164 rl_completion_matches(const char *str, r |
|
return list; |
return list; |
|
|
out: |
out: |
free(list); |
el_free(list); |
return NULL; |
return NULL; |
} |
} |
|
|
Line 2195 history_get_history_state(void) |
|
Line 2199 history_get_history_state(void) |
|
{ |
{ |
HISTORY_STATE *hs; |
HISTORY_STATE *hs; |
|
|
if ((hs = malloc(sizeof(HISTORY_STATE))) == NULL) |
if ((hs = el_malloc(sizeof(*hs))) == NULL) |
return (NULL); |
return (NULL); |
hs->length = history_length; |
hs->length = history_length; |
return (hs); |
return (hs); |