ops: refactor get_spec_reg()

Return value is bool.
errmsg (param) is bool in here and in getaltfname().
allocated (param) is bool.
This commit is contained in:
Jan Edmund Lazo 2018-08-16 22:32:06 -04:00
parent 015df9c66e
commit 58ad7fc578
3 changed files with 35 additions and 37 deletions

View File

@ -2659,9 +2659,8 @@ buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum)
* Get alternate file name for current window.
* Return NULL if there isn't any, and give error message if requested.
*/
char_u *
getaltfname (
int errmsg /* give error message */
char_u * getaltfname(
bool errmsg // give error message
)
{
char_u *fname;

View File

@ -3286,10 +3286,9 @@ void restore_cmdline_alloc(char_u *p)
/// @returns FAIL for failure, OK otherwise
static bool cmdline_paste(int regname, bool literally, bool remcr)
{
long i;
char_u *arg;
char_u *p;
int allocated;
bool allocated;
struct cmdline_info save_ccline;
/* check for valid regname; also accept special characters for CTRL-R in
@ -3311,7 +3310,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
* things like going to another buffer when evaluating an expression. */
save_cmdline(&save_ccline);
++textlock;
i = get_spec_reg(regname, &arg, &allocated, TRUE);
const bool i = get_spec_reg(regname, &arg, &allocated, true);
--textlock;
restore_cmdline(&save_ccline);

View File

@ -1110,7 +1110,7 @@ int insert_reg(
)
{
int retval = OK;
int allocated;
bool allocated;
/*
* It is possible to get into an endless loop by having CTRL-R a in
@ -1187,75 +1187,75 @@ static void stuffescaped(const char *arg, int literally)
}
}
/*
* If "regname" is a special register, return TRUE and store a pointer to its
* value in "argp".
*/
int get_spec_reg(
// If "regname" is a special register, return true and store a pointer to its
// value in "argp".
bool get_spec_reg(
int regname,
char_u **argp,
int *allocated, /* return: TRUE when value was allocated */
int errmsg /* give error message when failing */
bool *allocated, // return: true when value was allocated
bool errmsg // give error message when failing
)
{
size_t cnt;
*argp = NULL;
*allocated = FALSE;
*allocated = false;
switch (regname) {
case '%': /* file name */
if (errmsg)
check_fname(); /* will give emsg if not set */
*argp = curbuf->b_fname;
return TRUE;
return true;
case '#': /* alternate file name */
*argp = getaltfname(errmsg); /* may give emsg if not set */
return TRUE;
return true;
case '=': /* result of expression */
*argp = get_expr_line();
*allocated = TRUE;
return TRUE;
*allocated = true;
return true;
case ':': /* last command line */
if (last_cmdline == NULL && errmsg)
EMSG(_(e_nolastcmd));
*argp = last_cmdline;
return TRUE;
return true;
case '/': /* last search-pattern */
if (last_search_pat() == NULL && errmsg)
EMSG(_(e_noprevre));
*argp = last_search_pat();
return TRUE;
return true;
case '.': /* last inserted text */
*argp = get_last_insert_save();
*allocated = TRUE;
*allocated = true;
if (*argp == NULL && errmsg)
EMSG(_(e_noinstext));
return TRUE;
return true;
case Ctrl_F: /* Filename under cursor */
case Ctrl_P: /* Path under cursor, expand via "path" */
if (!errmsg)
return FALSE;
if (!errmsg) {
return false;
}
*argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP
| (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL);
*allocated = TRUE;
return TRUE;
*allocated = true;
return true;
case Ctrl_W: /* word under cursor */
case Ctrl_A: /* WORD (mnemonic All) under cursor */
if (!errmsg)
return FALSE;
if (!errmsg) {
return false;
}
cnt = find_ident_under_cursor(argp, (regname == Ctrl_W
? (FIND_IDENT|FIND_STRING)
: FIND_STRING));
*argp = cnt ? vim_strnsave(*argp, cnt) : NULL;
*allocated = TRUE;
return TRUE;
*allocated = true;
return true;
case Ctrl_L: // Line under cursor
if (!errmsg) {
@ -1267,10 +1267,10 @@ int get_spec_reg(
case '_': /* black hole: always empty */
*argp = (char_u *)"";
return TRUE;
return true;
}
return FALSE;
return false;
}
/// Paste a yank register into the command line.
@ -2660,7 +2660,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
int lendiff = 0;
pos_T old_pos;
char_u *insert_string = NULL;
int allocated = FALSE;
bool allocated = false;
long cnt;
if (flags & PUT_FIXINDENT)
@ -2756,7 +2756,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
* For special registers '%' (file name), '#' (alternate file name) and
* ':' (last command line), etc. we have to create a fake yank register.
*/
if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) {
if (get_spec_reg(regname, &insert_string, &allocated, true)) {
if (insert_string == NULL)
return;
}
@ -4915,8 +4915,8 @@ void *get_reg_contents(int regname, int flags)
return NULL;
char_u *retval;
int allocated;
if (get_spec_reg(regname, &retval, &allocated, FALSE)) {
bool allocated;
if (get_spec_reg(regname, &retval, &allocated, false)) {
if (retval == NULL)
return NULL;
if (allocated) {