diff src/userfunc.c @ 15470:55ccc2d353bd v8.1.0743

patch 8.1.0743: giving error messages is not flexible commit https://github.com/vim/vim/commit/f9e3e09fdc93be9f0d47afbc6c7df1188c2a5a0d Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jan 13 23:38:42 2019 +0100 patch 8.1.0743: giving error messages is not flexible Problem: Giving error messages is not flexible. Solution: Add semsg(). Change argument from "char_u *" to "char *", also for msg() and get rid of most MSG macros. (Ozaki Kiichi, closes #3302) Also make emsg() accept a "char *" argument. Get rid of an enormous number of type casts.
author Bram Moolenaar <Bram@vim.org>
date Sun, 13 Jan 2019 23:45:08 +0100
parents 9df130fd5e0d
children dd725a8ab112
line wrap: on
line diff
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -119,7 +119,7 @@ get_function_args(
 		    || (p - arg == 8 && STRNCMP(arg, "lastline", 8) == 0))
 	    {
 		if (!skip)
-		    EMSG2(_("E125: Illegal argument: %s"), arg);
+		    semsg(_("E125: Illegal argument: %s"), arg);
 		break;
 	    }
 	    if (newargs != NULL && ga_grow(newargs, 1) == FAIL)
@@ -139,7 +139,7 @@ get_function_args(
 		for (i = 0; i < newargs->ga_len; ++i)
 		    if (STRCMP(((char_u **)(newargs->ga_data))[i], arg) == 0)
 		    {
-			EMSG2(_("E853: Duplicate argument name: %s"), arg);
+			semsg(_("E853: Duplicate argument name: %s"), arg);
 			vim_free(arg);
 			goto err_ret;
 		    }
@@ -157,7 +157,7 @@ get_function_args(
 	if (mustend && *p != endchar)
 	{
 	    if (!skip)
-		EMSG2(_(e_invarg2), *argp);
+		semsg(_(e_invarg2), *argp);
 	    break;
 	}
     }
@@ -386,7 +386,7 @@ emsg_funcname(char *ermsg, char_u *name)
 	p = concat_str((char_u *)"<SNR>", name + 3);
     else
 	p = name;
-    EMSG2(_(ermsg), p);
+    semsg(_(ermsg), p);
     if (p != name)
 	vim_free(p);
 }
@@ -713,7 +713,7 @@ call_user_func(
     /* If depth of calling is getting too high, don't execute the function */
     if (depth >= p_mfd)
     {
-	EMSG(_("E132: Function call depth is higher than 'maxfuncdepth'"));
+	emsg(_("E132: Function call depth is higher than 'maxfuncdepth'"));
 	rettv->v_type = VAR_NUMBER;
 	rettv->vval.v_number = -1;
 	return;
@@ -885,7 +885,7 @@ call_user_func(
 	    ++no_wait_return;
 	    verbose_enter_scroll();
 
-	    smsg((char_u *)_("calling %s"), sourcing_name);
+	    smsg(_("calling %s"), sourcing_name);
 	    if (p_verbose >= 14)
 	    {
 		char_u	buf[MSG_BUF_LEN];
@@ -990,9 +990,9 @@ call_user_func(
 	verbose_enter_scroll();
 
 	if (aborting())
-	    smsg((char_u *)_("%s aborted"), sourcing_name);
+	    smsg(_("%s aborted"), sourcing_name);
 	else if (fc->rettv->v_type == VAR_NUMBER)
-	    smsg((char_u *)_("%s returning #%ld"), sourcing_name,
+	    smsg(_("%s returning #%ld"), sourcing_name,
 					       (long)fc->rettv->vval.v_number);
 	else
 	{
@@ -1014,7 +1014,7 @@ call_user_func(
 		    trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN);
 		    s = buf;
 		}
-		smsg((char_u *)_("%s returning %s"), sourcing_name, s);
+		smsg(_("%s returning %s"), sourcing_name, s);
 		vim_free(tofree);
 	    }
 	}
@@ -1040,7 +1040,7 @@ call_user_func(
 	++no_wait_return;
 	verbose_enter_scroll();
 
-	smsg((char_u *)_("continuing in %s"), sourcing_name);
+	smsg(_("continuing in %s"), sourcing_name);
 	msg_puts((char_u *)"\n");   /* don't overwrite this either */
 
 	verbose_leave_scroll();
@@ -1194,7 +1194,7 @@ save_funccal(funccal_entry_T *entry)
 restore_funccal(void)
 {
     if (funccal_stack == NULL)
-	IEMSG("INTERNAL: restore_funccal()");
+	iemsg("INTERNAL: restore_funccal()");
     else
     {
 	current_funccal = funccal_stack->top_funccal;
@@ -1312,7 +1312,7 @@ func_call(
     {
 	if (argc == MAX_FUNC_ARGS - (partial == NULL ? 0 : partial->pt_argc))
 	{
-	    EMSG(_("E699: Too many arguments"));
+	    emsg(_("E699: Too many arguments"));
 	    break;
 	}
 	/* Make a copy of each argument.  This is needed to be able to set
@@ -1660,7 +1660,7 @@ trans_function_name(
     if (end == start)
     {
 	if (!skip)
-	    EMSG(_("E129: Function name required"));
+	    emsg(_("E129: Function name required"));
 	goto theend;
     }
     if (end == NULL || (lv.ll_tv != NULL && (lead > 2 || lv.ll_range)))
@@ -1673,7 +1673,7 @@ trans_function_name(
 	if (!aborting())
 	{
 	    if (end != NULL)
-		EMSG2(_(e_invarg2), start);
+		semsg(_(e_invarg2), start);
 	}
 	else
 	    *pp = find_name_end(start, NULL, NULL, FNE_INCL_BR);
@@ -1706,7 +1706,7 @@ trans_function_name(
 	{
 	    if (!skip && !(flags & TFN_QUIET) && (fdp == NULL
 			     || lv.ll_dict == NULL || fdp->fd_newkey == NULL))
-		EMSG(_(e_funcref));
+		emsg(_(e_funcref));
 	    else
 		*pp = end;
 	    name = NULL;
@@ -1789,7 +1789,7 @@ trans_function_name(
 	    /* It's "s:" or "<SID>" */
 	    if (current_sctx.sc_sid <= 0)
 	    {
-		EMSG(_(e_usingsid));
+		emsg(_(e_usingsid));
 		goto theend;
 	    }
 	    sprintf((char *)sid_buf, "%ld_", (long)current_sctx.sc_sid);
@@ -1798,7 +1798,7 @@ trans_function_name(
     }
     else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, len))
     {
-	EMSG2(_("E128: Function name must start with a capital or \"s:\": %s"),
+	semsg(_("E128: Function name must start with a capital or \"s:\": %s"),
 								       start);
 	goto theend;
     }
@@ -1808,7 +1808,7 @@ trans_function_name(
 
 	if (cp != NULL && cp < end)
 	{
-	    EMSG2(_("E884: Function name cannot contain a colon: %s"), start);
+	    semsg(_("E884: Function name cannot contain a colon: %s"), start);
 	    goto theend;
 	}
     }
@@ -1961,7 +1961,7 @@ ex_function(exarg_T *eap)
 	if (!aborting())
 	{
 	    if (!eap->skip && fudi.fd_newkey != NULL)
-		EMSG2(_(e_dictkey), fudi.fd_newkey);
+		semsg(_(e_dictkey), fudi.fd_newkey);
 	    vim_free(fudi.fd_newkey);
 	    return;
 	}
@@ -1981,7 +1981,7 @@ ex_function(exarg_T *eap)
     {
 	if (!ends_excmd(*skipwhite(p)))
 	{
-	    EMSG(_(e_trailing));
+	    emsg(_(e_trailing));
 	    goto ret_free;
 	}
 	eap->nextcmd = check_nextcmd(p);
@@ -2027,7 +2027,7 @@ ex_function(exarg_T *eap)
     {
 	if (!eap->skip)
 	{
-	    EMSG2(_("E124: Missing '(': %s"), eap->arg);
+	    semsg(_("E124: Missing '(': %s"), eap->arg);
 	    goto ret_free;
 	}
 	/* attempt to continue by skipping some text */
@@ -2062,7 +2062,7 @@ ex_function(exarg_T *eap)
 	}
 	/* Disallow using the g: dict. */
 	if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE)
-	    EMSG(_("E862: Cannot use g: here"));
+	    emsg(_("E862: Cannot use g: here"));
     }
 
     if (get_function_args(&p, ')', &newargs, &varargs, eap->skip) == FAIL)
@@ -2107,7 +2107,7 @@ ex_function(exarg_T *eap)
     if (*p == '\n')
 	line_arg = p + 1;
     else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg)
-	EMSG(_(e_trailing));
+	emsg(_(e_trailing));
 
     /*
      * Read the body of the function, until ":endfunction" is found.
@@ -2120,7 +2120,7 @@ ex_function(exarg_T *eap)
 	if (!eap->skip && !eap->forceit)
 	{
 	    if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL)
-		EMSG(_(e_funcdict));
+		emsg(_(e_funcdict));
 	    else if (name != NULL && find_func(name) != NULL)
 		emsg_funcname(e_funcexts, name);
 	}
@@ -2170,7 +2170,7 @@ ex_function(exarg_T *eap)
 	    lines_left = Rows - 1;
 	if (theline == NULL)
 	{
-	    EMSG(_("E126: Missing :endfunction"));
+	    emsg(_("E126: Missing :endfunction"));
 	    goto erret;
 	}
 
@@ -2374,7 +2374,7 @@ ex_function(exarg_T *eap)
 	fp = NULL;
 	if (fudi.fd_newkey == NULL && !eap->forceit)
 	{
-	    EMSG(_(e_funcdict));
+	    emsg(_(e_funcdict));
 	    goto erret;
 	}
 	if (fudi.fd_di == NULL)
@@ -2421,7 +2421,7 @@ ex_function(exarg_T *eap)
 	    }
 	    if (j == FAIL)
 	    {
-		EMSG2(_("E746: Function name does not match script file name: %s"), name);
+		semsg(_("E746: Function name does not match script file name: %s"), name);
 		goto erret;
 	    }
 	}
@@ -2876,13 +2876,13 @@ ex_delfunction(exarg_T *eap)
     if (name == NULL)
     {
 	if (fudi.fd_dict != NULL && !eap->skip)
-	    EMSG(_(e_funcref));
+	    emsg(_(e_funcref));
 	return;
     }
     if (!ends_excmd(*skipwhite(p)))
     {
 	vim_free(name);
-	EMSG(_(e_trailing));
+	emsg(_(e_trailing));
 	return;
     }
     eap->nextcmd = check_nextcmd(p);
@@ -2898,12 +2898,12 @@ ex_delfunction(exarg_T *eap)
 	if (fp == NULL)
 	{
 	    if (!eap->forceit)
-		EMSG2(_(e_nofunc), eap->arg);
+		semsg(_(e_nofunc), eap->arg);
 	    return;
 	}
 	if (fp->uf_calls > 0)
 	{
-	    EMSG2(_("E131: Cannot delete function %s: It is in use"), eap->arg);
+	    semsg(_("E131: Cannot delete function %s: It is in use"), eap->arg);
 	    return;
 	}
 
@@ -3032,7 +3032,7 @@ ex_return(exarg_T *eap)
 
     if (current_funccal == NULL)
     {
-	EMSG(_("E133: :return not inside a function"));
+	emsg(_("E133: :return not inside a function"));
 	return;
     }
 
@@ -3108,7 +3108,7 @@ ex_call(exarg_T *eap)
     if (fudi.fd_newkey != NULL)
     {
 	/* Still need to give an error message for missing key. */
-	EMSG2(_(e_dictkey), fudi.fd_newkey);
+	semsg(_(e_dictkey), fudi.fd_newkey);
 	vim_free(fudi.fd_newkey);
     }
     if (tofree == NULL)
@@ -3133,7 +3133,7 @@ ex_call(exarg_T *eap)
 
     if (*startarg != '(')
     {
-	EMSG2(_("E107: Missing parentheses: %s"), eap->arg);
+	semsg(_("E107: Missing parentheses: %s"), eap->arg);
 	goto end;
     }
 
@@ -3158,7 +3158,7 @@ ex_call(exarg_T *eap)
 	    {
 		// If the function deleted lines or switched to another buffer
 		// the line number may become invalid.
-		EMSG(_(e_invrange));
+		emsg(_(e_invrange));
 		break;
 	    }
 	    curwin->w_cursor.lnum = lnum;
@@ -3205,7 +3205,7 @@ ex_call(exarg_T *eap)
 	if (!ends_excmd(*arg))
 	{
 	    emsg_severe = TRUE;
-	    EMSG(_(e_trailing));
+	    emsg(_(e_trailing));
 	}
 	else
 	    eap->nextcmd = check_nextcmd(arg);
@@ -3267,7 +3267,7 @@ do_return(
 		if ((cstack->cs_rettv[idx] = alloc_tv()) != NULL)
 		    *(typval_T *)cstack->cs_rettv[idx] = *(typval_T *)rettv;
 		else
-		    EMSG(_(e_outofmem));
+		    emsg(_(e_outofmem));
 	    }
 	    else
 		cstack->cs_rettv[idx] = NULL;