Mercurial > vim
comparison src/ex_docmd.c @ 21459:a422bd80b434 v8.2.1280
patch 8.2.1280: Ex command error cannot contain an argument
Commit: https://github.com/vim/vim/commit/8930caaa1a283092aca81fdbc3fcf15c7eadb197
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jul 23 16:37:03 2020 +0200
patch 8.2.1280: Ex command error cannot contain an argument
Problem: Ex command error cannot contain an argument.
Solution: Add ex_errmsg() and translate earlier. Use e_trailing_arg where
possible.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 23 Jul 2020 16:45:03 +0200 |
parents | 8992d4f63761 |
children | 4dfd00f481fb |
comparison
equal
deleted
inserted
replaced
21458:5b12080761da | 21459:a422bd80b434 |
---|---|
2568 * Call the function to execute the builtin command. | 2568 * Call the function to execute the builtin command. |
2569 */ | 2569 */ |
2570 ea.errmsg = NULL; | 2570 ea.errmsg = NULL; |
2571 (cmdnames[ea.cmdidx].cmd_func)(&ea); | 2571 (cmdnames[ea.cmdidx].cmd_func)(&ea); |
2572 if (ea.errmsg != NULL) | 2572 if (ea.errmsg != NULL) |
2573 errormsg = _(ea.errmsg); | 2573 errormsg = ea.errmsg; |
2574 } | 2574 } |
2575 | 2575 |
2576 #ifdef FEAT_EVAL | 2576 #ifdef FEAT_EVAL |
2577 // Set flag that any command was executed, used by ex_vim9script(). | 2577 // Set flag that any command was executed, used by ex_vim9script(). |
2578 if (getline_equal(ea.getline, ea.cookie, getsourceline) | 2578 if (getline_equal(ea.getline, ea.cookie, getsourceline) |
2645 return ea.nextcmd; | 2645 return ea.nextcmd; |
2646 } | 2646 } |
2647 #if (_MSC_VER == 1200) | 2647 #if (_MSC_VER == 1200) |
2648 #pragma optimize( "", on ) | 2648 #pragma optimize( "", on ) |
2649 #endif | 2649 #endif |
2650 | |
2651 static char ex_error_buf[MSG_BUF_LEN]; | |
2652 | |
2653 /* | |
2654 * Return an error message with argument included. | |
2655 * Uses a static buffer, only the last error will be kept. | |
2656 * "msg" will be translated, caller should use N_(). | |
2657 */ | |
2658 char * | |
2659 ex_errmsg(char *msg, char_u *arg) | |
2660 { | |
2661 vim_snprintf(ex_error_buf, MSG_BUF_LEN, _(msg), arg); | |
2662 return ex_error_buf; | |
2663 } | |
2650 | 2664 |
2651 /* | 2665 /* |
2652 * Parse and skip over command modifiers: | 2666 * Parse and skip over command modifiers: |
2653 * - update eap->cmd | 2667 * - update eap->cmd |
2654 * - store flags in "cmdmod". | 2668 * - store flags in "cmdmod". |
3987 */ | 4001 */ |
3988 void | 4002 void |
3989 ex_ni(exarg_T *eap) | 4003 ex_ni(exarg_T *eap) |
3990 { | 4004 { |
3991 if (!eap->skip) | 4005 if (!eap->skip) |
3992 eap->errmsg = N_("E319: Sorry, the command is not available in this version"); | 4006 eap->errmsg = |
4007 _("E319: Sorry, the command is not available in this version"); | |
3993 } | 4008 } |
3994 | 4009 |
3995 #ifdef HAVE_EX_SCRIPT_NI | 4010 #ifdef HAVE_EX_SCRIPT_NI |
3996 /* | 4011 /* |
3997 * Function called for script command which is Not Implemented. NI! | 4012 * Function called for script command which is Not Implemented. NI! |
4745 * directory for security reasons. | 4760 * directory for security reasons. |
4746 */ | 4761 */ |
4747 if (secure) | 4762 if (secure) |
4748 { | 4763 { |
4749 secure = 2; | 4764 secure = 2; |
4750 eap->errmsg = e_curdir; | 4765 eap->errmsg = _(e_curdir); |
4751 } | 4766 } |
4752 else if (eap->cmdidx == CMD_autocmd) | 4767 else if (eap->cmdidx == CMD_autocmd) |
4753 do_autocmd(eap->arg, eap->forceit); | 4768 do_autocmd(eap->arg, eap->forceit); |
4754 else | 4769 else |
4755 do_augroup(eap->arg, eap->forceit); | 4770 do_augroup(eap->arg, eap->forceit); |
4796 ex_buffer(exarg_T *eap) | 4811 ex_buffer(exarg_T *eap) |
4797 { | 4812 { |
4798 if (ERROR_IF_ANY_POPUP_WINDOW) | 4813 if (ERROR_IF_ANY_POPUP_WINDOW) |
4799 return; | 4814 return; |
4800 if (*eap->arg) | 4815 if (*eap->arg) |
4801 eap->errmsg = e_trailing; | 4816 eap->errmsg = ex_errmsg(e_trailing_arg, eap->arg); |
4802 else | 4817 else |
4803 { | 4818 { |
4804 if (eap->addr_count == 0) // default is current buffer | 4819 if (eap->addr_count == 0) // default is current buffer |
4805 goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0); | 4820 goto_buffer(eap, DOBUF_CURRENT, FORWARD, 0); |
4806 else | 4821 else |
5363 tab_number = LAST_TAB_NR; | 5378 tab_number = LAST_TAB_NR; |
5364 else if (p == p_save || *p_save == '-' || *p != NUL | 5379 else if (p == p_save || *p_save == '-' || *p != NUL |
5365 || tab_number > LAST_TAB_NR) | 5380 || tab_number > LAST_TAB_NR) |
5366 { | 5381 { |
5367 // No numbers as argument. | 5382 // No numbers as argument. |
5368 eap->errmsg = e_invarg; | 5383 eap->errmsg = ex_errmsg(e_invarg2, eap->arg); |
5369 goto theend; | 5384 goto theend; |
5370 } | 5385 } |
5371 } | 5386 } |
5372 else | 5387 else |
5373 { | 5388 { |
5375 tab_number = 1; | 5390 tab_number = 1; |
5376 else if (p == p_save || *p_save == '-' || *p != NUL | 5391 else if (p == p_save || *p_save == '-' || *p != NUL |
5377 || tab_number == 0) | 5392 || tab_number == 0) |
5378 { | 5393 { |
5379 // No numbers as argument. | 5394 // No numbers as argument. |
5380 eap->errmsg = e_invarg; | 5395 eap->errmsg = ex_errmsg(e_invarg2, eap->arg); |
5381 goto theend; | 5396 goto theend; |
5382 } | 5397 } |
5383 tab_number = tab_number * relative + tabpage_index(curtab); | 5398 tab_number = tab_number * relative + tabpage_index(curtab); |
5384 if (!unaccept_arg0 && relative == -1) | 5399 if (!unaccept_arg0 && relative == -1) |
5385 --tab_number; | 5400 --tab_number; |
5386 } | 5401 } |
5387 if (tab_number < unaccept_arg0 || tab_number > LAST_TAB_NR) | 5402 if (tab_number < unaccept_arg0 || tab_number > LAST_TAB_NR) |
5388 eap->errmsg = e_invarg; | 5403 eap->errmsg = ex_errmsg(e_invarg2, eap->arg); |
5389 } | 5404 } |
5390 else if (eap->addr_count > 0) | 5405 else if (eap->addr_count > 0) |
5391 { | 5406 { |
5392 if (unaccept_arg0 && eap->line2 == 0) | 5407 if (unaccept_arg0 && eap->line2 == 0) |
5393 { | 5408 { |
5394 eap->errmsg = e_invrange; | 5409 eap->errmsg = _(e_invrange); |
5395 tab_number = 0; | 5410 tab_number = 0; |
5396 } | 5411 } |
5397 else | 5412 else |
5398 { | 5413 { |
5399 tab_number = eap->line2; | 5414 tab_number = eap->line2; |
5400 if (!unaccept_arg0 && *skipwhite(*eap->cmdlinep) == '-') | 5415 if (!unaccept_arg0 && *skipwhite(*eap->cmdlinep) == '-') |
5401 { | 5416 { |
5402 --tab_number; | 5417 --tab_number; |
5403 if (tab_number < unaccept_arg0) | 5418 if (tab_number < unaccept_arg0) |
5404 eap->errmsg = e_invarg; | 5419 eap->errmsg = _(e_invrange); |
5405 } | 5420 } |
5406 } | 5421 } |
5407 } | 5422 } |
5408 else | 5423 else |
5409 { | 5424 { |
5912 * Command modifier used in a wrong way. | 5927 * Command modifier used in a wrong way. |
5913 */ | 5928 */ |
5914 static void | 5929 static void |
5915 ex_wrongmodifier(exarg_T *eap) | 5930 ex_wrongmodifier(exarg_T *eap) |
5916 { | 5931 { |
5917 eap->errmsg = e_invcmd; | 5932 eap->errmsg = _(e_invcmd); |
5918 } | 5933 } |
5919 | 5934 |
5920 /* | 5935 /* |
5921 * :sview [+command] file split window with new file, read-only | 5936 * :sview [+command] file split window with new file, read-only |
5922 * :split [[+command] file] split window with current or new file | 5937 * :split [[+command] file] split window with current or new file |
6095 tab_number = getdigits(&p); | 6110 tab_number = getdigits(&p); |
6096 if (p == p_save || *p_save == '-' || *p != NUL | 6111 if (p == p_save || *p_save == '-' || *p != NUL |
6097 || tab_number == 0) | 6112 || tab_number == 0) |
6098 { | 6113 { |
6099 // No numbers as argument. | 6114 // No numbers as argument. |
6100 eap->errmsg = e_invarg; | 6115 eap->errmsg = ex_errmsg(e_invarg2, eap->arg); |
6101 return; | 6116 return; |
6102 } | 6117 } |
6103 } | 6118 } |
6104 else | 6119 else |
6105 { | 6120 { |
6108 else | 6123 else |
6109 { | 6124 { |
6110 tab_number = eap->line2; | 6125 tab_number = eap->line2; |
6111 if (tab_number < 1) | 6126 if (tab_number < 1) |
6112 { | 6127 { |
6113 eap->errmsg = e_invrange; | 6128 eap->errmsg = _(e_invrange); |
6114 return; | 6129 return; |
6115 } | 6130 } |
6116 } | 6131 } |
6117 } | 6132 } |
6118 goto_tabpage(-tab_number); | 6133 goto_tabpage(-tab_number); |
6496 * ":gui" and ":gvim" when there is no GUI. | 6511 * ":gui" and ":gvim" when there is no GUI. |
6497 */ | 6512 */ |
6498 static void | 6513 static void |
6499 ex_nogui(exarg_T *eap) | 6514 ex_nogui(exarg_T *eap) |
6500 { | 6515 { |
6501 eap->errmsg = e_nogvim; | 6516 eap->errmsg = _(e_nogvim); |
6502 } | 6517 } |
6503 #endif | 6518 #endif |
6504 | 6519 |
6505 #if defined(FEAT_GUI_MSWIN) && defined(FEAT_MENU) && defined(FEAT_TEAROFF) | 6520 #if defined(FEAT_GUI_MSWIN) && defined(FEAT_MENU) && defined(FEAT_TEAROFF) |
6506 static void | 6521 static void |
8072 *p++ = NUL; | 8087 *p++ = NUL; |
8073 p = skipwhite(p); | 8088 p = skipwhite(p); |
8074 | 8089 |
8075 // Check for trailing illegal characters | 8090 // Check for trailing illegal characters |
8076 if (!ends_excmd2(eap->arg, p)) | 8091 if (!ends_excmd2(eap->arg, p)) |
8077 eap->errmsg = e_trailing; | 8092 eap->errmsg = ex_errmsg(e_trailing_arg, p); |
8078 else | 8093 else |
8079 eap->nextcmd = check_nextcmd(p); | 8094 eap->nextcmd = check_nextcmd(p); |
8080 } | 8095 } |
8081 } | 8096 } |
8082 if (!eap->skip) | 8097 if (!eap->skip) |