summaryrefslogtreecommitdiffstats
path: root/lib/libedit/readline.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libedit/readline.c')
-rw-r--r--lib/libedit/readline.c144
1 files changed, 72 insertions, 72 deletions
diff --git a/lib/libedit/readline.c b/lib/libedit/readline.c
index 92c52cf9058..f39f2ca838a 100644
--- a/lib/libedit/readline.c
+++ b/lib/libedit/readline.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: readline.c,v 1.14 2015/02/06 23:21:58 millert Exp $ */
+/* $OpenBSD: readline.c,v 1.15 2016/01/30 12:22:20 schwarze Exp $ */
/* $NetBSD: readline.c,v 1.91 2010/08/28 15:44:59 christos Exp $ */
/*-
@@ -176,7 +176,7 @@ static char *
_get_prompt(EditLine *el __attribute__((__unused__)))
{
rl_already_prompted = 1;
- return (rl_prompt);
+ return rl_prompt;
}
@@ -190,12 +190,12 @@ _move_history(int op)
static HIST_ENTRY rl_he;
if (history(h, &ev, op) != 0)
- return (HIST_ENTRY *) NULL;
+ return NULL;
rl_he.line = ev.str;
rl_he.data = NULL;
- return (&rl_he);
+ return &rl_he;
}
@@ -304,7 +304,7 @@ rl_initialize(void)
h = history_init();
if (!e || !h)
- return (-1);
+ return -1;
history(h, &ev, H_SETSIZE, INT_MAX); /* unlimited */
history_length = 0;
@@ -365,7 +365,7 @@ rl_initialize(void)
if (rl_startup_hook)
(*rl_startup_hook)(NULL, 0);
- return (0);
+ return 0;
}
@@ -485,13 +485,13 @@ _rl_compat_sub(const char *str, const char *what, const char *with,
s += what_len;
if (!globally) {
(void)strlcpy(r, s, len);
- return(result);
+ return result;
}
} else
*r++ = *s++;
}
*r = '\0';
- return(result);
+ return result;
}
static char *last_search_pat; /* last !?pat[?] search pattern */
@@ -508,12 +508,12 @@ get_history_event(const char *cmd, int *cindex, int qchar)
idx = *cindex;
if (cmd[idx++] != history_expansion_char)
- return(NULL);
+ return NULL;
/* find out which event to take */
if (cmd[idx] == history_expansion_char || cmd[idx] == '\0') {
if (history(h, &ev, H_FIRST) != 0)
- return(NULL);
+ return NULL;
*cindex = cmd[idx]? (idx + 1):idx;
return ev.str;
}
@@ -535,10 +535,10 @@ get_history_event(const char *cmd, int *cindex, int qchar)
num = history_length - num + 1;
if (!(rl_he = history_get(num)))
- return(NULL);
+ return NULL;
*cindex = idx;
- return(rl_he->line);
+ return rl_he->line;
}
sub = 0;
if (cmd[idx] == '?') {
@@ -562,7 +562,7 @@ get_history_event(const char *cmd, int *cindex, int qchar)
if (sub && len == 0 && last_search_pat && *last_search_pat)
pat = last_search_pat;
else if (len == 0)
- return(NULL);
+ return NULL;
else {
if ((pat = malloc(len + 1)) == NULL)
return NULL;
@@ -573,7 +573,7 @@ get_history_event(const char *cmd, int *cindex, int qchar)
if (history(h, &ev, H_CURR) != 0) {
if (pat != last_search_pat)
free(pat);
- return (NULL);
+ return NULL;
}
num = ev.num;
@@ -593,7 +593,7 @@ get_history_event(const char *cmd, int *cindex, int qchar)
(void)fprintf(rl_outstream, "%s: Event not found\n", pat);
if (pat != last_search_pat)
free(pat);
- return(NULL);
+ return NULL;
}
if (sub && len) {
@@ -606,7 +606,7 @@ get_history_event(const char *cmd, int *cindex, int qchar)
free(pat);
if (history(h, &ev, H_CURR) != 0)
- return(NULL);
+ return NULL;
*cindex = idx;
rptr = ev.str;
@@ -624,7 +624,7 @@ get_history_event(const char *cmd, int *cindex, int qchar)
* returns 0 if data was not modified, 1 if it was and 2 if the string
* should be only printed and not executed; in case of error,
* returns -1 and *result points to NULL
- * it's callers responsibility to free() string returned in *result
+ * it's the caller's responsibility to free() the string returned in *result
*/
static int
_history_expand_command(const char *command, size_t offs, size_t cmdlen,
@@ -673,7 +673,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
}
if (ptr == NULL && aptr == NULL)
- return(-1);
+ return -1;
if (!has_mods) {
*result = strdup(aptr ? aptr : ptr);
@@ -681,7 +681,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
free(aptr);
if (*result == NULL)
return -1;
- return(1);
+ return 1;
}
cmd = command + offs + idx + 1;
@@ -727,7 +727,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
command + offs + idx);
if (aptr)
free(aptr);
- return(-1);
+ return -1;
}
} else
tmp = strdup(aptr? aptr:ptr);
@@ -737,7 +737,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
if (*cmd == '\0' || ((size_t)(cmd - (command + offs)) >= cmdlen)) {
*result = tmp;
- return(1);
+ return 1;
}
for (; *cmd; cmd++) {
@@ -812,7 +812,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
} else {
from = NULL;
free(tmp);
- return (-1);
+ return -1;
}
}
cmd++; /* shift after delim */
@@ -866,7 +866,7 @@ _history_expand_command(const char *command, size_t offs, size_t cmdlen,
}
}
*result = tmp;
- return (p_on? 2:1);
+ return p_on? 2:1;
}
@@ -885,7 +885,7 @@ history_expand(char *str, char **output)
if (history_expansion_char == 0) {
*output = strdup(str);
- return(0);
+ return 0;
}
*output = NULL;
@@ -1001,7 +1001,7 @@ loop:
free(*output);
*output = result;
- return (ret);
+ return ret;
}
/*
@@ -1117,7 +1117,7 @@ history_tokenize(const char *str)
if (str[i])
i++;
}
- return (result);
+ return result;
}
@@ -1149,7 +1149,7 @@ unstifle_history(void)
history(h, &ev, H_SETSIZE, INT_MAX);
omax = max_input_history;
max_input_history = INT_MAX;
- return (omax); /* some value _must_ be returned */
+ return omax; /* some value _must_ be returned */
}
@@ -1158,7 +1158,7 @@ history_is_stifled(void)
{
/* cannot return true answer */
- return (max_input_history != INT_MAX);
+ return max_input_history != INT_MAX;
}
static const char _history_tmp_template[] = "/tmp/.historyXXXXXX";
@@ -1310,8 +1310,8 @@ read_history(const char *filename)
rl_initialize();
if (filename == NULL && (filename = _default_history_file()) == NULL)
return errno;
- return (history(h, &ev, H_LOAD, filename) == -1 ?
- (errno ? errno : EINVAL) : 0);
+ return history(h, &ev, H_LOAD, filename) == -1 ?
+ (errno ? errno : EINVAL) : 0;
}
@@ -1327,8 +1327,8 @@ write_history(const char *filename)
rl_initialize();
if (filename == NULL && (filename = _default_history_file()) == NULL)
return errno;
- return (history(h, &ev, H_SAVE, filename) == -1 ?
- (errno ? errno : EINVAL) : 0);
+ return history(h, &ev, H_SAVE, filename) == -1 ?
+ (errno ? errno : EINVAL) : 0;
}
@@ -1349,23 +1349,23 @@ history_get(int num)
/* save current position */
if (history(h, &ev, H_CURR) != 0)
- return (NULL);
+ return NULL;
curr_num = ev.num;
/* start from the oldest */
if (history(h, &ev, H_LAST) != 0)
- return (NULL); /* error */
+ return NULL; /* error */
/* look forwards for event matching specified offset */
if (history(h, &ev, H_NEXT_EVDATA, num, &she.data))
- return (NULL);
+ return NULL;
she.line = ev.str;
/* restore pointer to where it was */
(void)history(h, &ev, H_SET, curr_num);
- return (&she);
+ return &she;
}
@@ -1384,7 +1384,7 @@ add_history(const char *line)
if (history(h, &ev, H_GETSIZE) == 0)
history_length = ev.num;
- return (!(history_length > 0)); /* return 0 if all is okay */
+ return !(history_length > 0); /* return 0 if all is okay */
}
@@ -1485,7 +1485,7 @@ where_history(void)
int curr_num, off;
if (history(h, &ev, H_CURR) != 0)
- return (0);
+ return 0;
curr_num = ev.num;
(void)history(h, &ev, H_FIRST);
@@ -1493,7 +1493,7 @@ where_history(void)
while (ev.num != curr_num && history(h, &ev, H_NEXT) == 0)
off++;
- return (off);
+ return off;
}
@@ -1504,7 +1504,7 @@ HIST_ENTRY *
current_history(void)
{
- return (_move_history(H_CURR));
+ return _move_history(H_CURR);
}
@@ -1519,7 +1519,7 @@ history_total_bytes(void)
size_t size;
if (history(h, &ev, H_CURR) != 0)
- return (-1);
+ return -1;
curr_num = ev.num;
(void)history(h, &ev, H_FIRST);
@@ -1531,7 +1531,7 @@ history_total_bytes(void)
/* get to the same position as before */
history(h, &ev, H_PREV_EVENT, curr_num);
- return (int)(size);
+ return (int)size;
}
@@ -1545,7 +1545,7 @@ history_set_pos(int pos)
int curr_num;
if (pos >= history_length || pos < 0)
- return (-1);
+ return -1;
(void)history(h, &ev, H_CURR);
curr_num = ev.num;
@@ -1556,9 +1556,9 @@ history_set_pos(int pos)
*/
if (history(h, &ev, H_DELDATA, pos, (void **)-1)) {
(void)history(h, &ev, H_SET, curr_num);
- return(-1);
+ return -1;
}
- return (0);
+ return 0;
}
@@ -1569,7 +1569,7 @@ HIST_ENTRY *
previous_history(void)
{
- return (_move_history(H_PREV));
+ return _move_history(H_PREV);
}
@@ -1580,7 +1580,7 @@ HIST_ENTRY *
next_history(void)
{
- return (_move_history(H_NEXT));
+ return _move_history(H_NEXT);
}
@@ -1595,17 +1595,17 @@ history_search(const char *str, int direction)
int curr_num;
if (history(h, &ev, H_CURR) != 0)
- return (-1);
+ return -1;
curr_num = ev.num;
for (;;) {
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)
break;
}
(void)history(h, &ev, H_SET, curr_num);
- return (-1);
+ return -1;
}
@@ -1638,15 +1638,15 @@ history_search_pos(const char *str,
pos = (pos > 0) ? 1 : -1;
if (history(h, &ev, H_CURR) != 0)
- return (-1);
+ return -1;
curr_num = ev.num;
if (history_set_pos(off) != 0 || history(h, &ev, H_CURR) != 0)
- return (-1);
+ return -1;
for (;;) {
if (strstr(ev.str, str))
- return (off);
+ return off;
if (history(h, &ev, (pos < 0) ? H_PREV : H_NEXT) != 0)
break;
}
@@ -1655,7 +1655,7 @@ history_search_pos(const char *str,
(void)history(h, &ev,
pos < 0 ? H_NEXT_EVENT : H_PREV_EVENT, curr_num);
- return (-1);
+ return -1;
}
@@ -1679,7 +1679,7 @@ filename_completion_function(const char *name, int state)
* which starts with supplied text
* text contains a partial username preceded by random character
* (usually '~'); state is ignored
- * it's callers responsibility to free returned value
+ * it's the caller's responsibility to free the returned value
*/
char *
username_completion_function(const char *text, int state)
@@ -1687,7 +1687,7 @@ username_completion_function(const char *text, int state)
struct passwd *pwd;
if (text[0] == '\0')
- return (NULL);
+ return NULL;
if (*text == '~')
text++;
@@ -1760,7 +1760,7 @@ rl_complete(int ignore __attribute__((__unused__)), int invoking_key)
arr[0] = (char)invoking_key;
arr[1] = '\0';
el_insertstr(e, arr);
- return (CC_REFRESH);
+ return CC_REFRESH;
}
/* Just look at how many global variables modify this operation! */
@@ -1805,7 +1805,7 @@ rl_bind_key(int c, rl_command_func_t *func)
e->el_map.key[c] = ED_INSERT;
retval = 0;
}
- return (retval);
+ return retval;
}
@@ -1821,7 +1821,7 @@ rl_read_key(void)
if (e == NULL || h == NULL)
rl_initialize();
- return (el_getc(e, fooarr));
+ return el_getc(e, fooarr);
}
@@ -1857,20 +1857,20 @@ rl_insert(int count, int c)
for (; count > 0; count--)
el_push(e, arr);
- return (0);
+ return 0;
}
int
rl_insert_text(const char *text)
{
if (!text || *text == 0)
- return (0);
+ return 0;
if (h == NULL || e == NULL)
rl_initialize();
if (el_insertstr(e, text) < 0)
- return (0);
+ return 0;
return (int)strlen(text);
}
@@ -1995,7 +1995,7 @@ rl_deprep_terminal(void)
int
rl_read_init_file(const char *s)
{
- return(el_source(e, s));
+ return el_source(e, s);
}
int
@@ -2009,7 +2009,7 @@ rl_parse_and_bind(const char *line)
tok_str(tok, line, &argc, &argv);
argc = el_parse(e, argc, argv);
tok_end(tok);
- return (argc ? 1 : 0);
+ return argc ? 1 : 0;
}
int
@@ -2019,7 +2019,7 @@ rl_variable_bind(const char *var, const char *value)
* The proper return value is undocument, but this is what the
* readline source seems to do.
*/
- return ((el_set(e, EL_BIND, "", var, value, NULL) == -1) ? 1 : 0);
+ return el_set(e, EL_BIND, "", var, value, NULL) == -1 ? 1 : 0;
}
void
@@ -2045,23 +2045,23 @@ _rl_event_read_char(EditLine *el, char *cp)
#if defined(FIONREAD)
if (ioctl(el->el_infd, FIONREAD, &n) < 0)
- return(-1);
+ return -1;
if (n)
num_read = read(el->el_infd, cp, 1);
else
num_read = 0;
#elif defined(F_SETFL) && defined(O_NDELAY)
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)
- return(-1);
+ return -1;
num_read = read(el->el_infd, cp, 1);
if (fcntl(el->el_infd, F_SETFL, n))
- return(-1);
+ return -1;
#else
/* not non-blocking, but what you gonna do? */
num_read = read(el->el_infd, cp, 1);
- return(-1);
+ return -1;
#endif
if (num_read < 0 && errno == EAGAIN)
@@ -2190,9 +2190,9 @@ history_get_history_state(void)
HISTORY_STATE *hs;
if ((hs = malloc(sizeof(HISTORY_STATE))) == NULL)
- return (NULL);
+ return NULL;
hs->length = history_length;
- return (hs);
+ return hs;
}
int