diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-01-13 23:38:42 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-01-13 23:38:42 +0100 |
commit | f9e3e09fdc93be9f0d47afbc6c7df1188c2a5a0d (patch) | |
tree | a6b07005c19279a4f5d01be14f14861c2657fa95 /src/quickfix.c | |
parent | 05500ece6282407f9f7227aaf564e24147326863 (diff) | |
download | vim-git-f9e3e09fdc93be9f0d47afbc6c7df1188c2a5a0d.tar.gz |
patch 8.1.0743: giving error messages is not flexiblev8.1.0743
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.
Diffstat (limited to 'src/quickfix.c')
-rw-r--r-- | src/quickfix.c | 124 |
1 files changed, 51 insertions, 73 deletions
diff --git a/src/quickfix.c b/src/quickfix.c index 899b63689..c533a28d3 100644 --- a/src/quickfix.c +++ b/src/quickfix.c @@ -239,17 +239,14 @@ efmpat_to_regpat( char_u *regpat, efm_T *efminfo, int idx, - int round, - char_u *errmsg) + int round) { char_u *srcptr; if (efminfo->addr[idx]) { // Each errorformat pattern can occur only once - sprintf((char *)errmsg, - _("E372: Too many %%%c in format string"), *efmpat); - EMSG(errmsg); + semsg(_("E372: Too many %%%c in format string"), *efmpat); return NULL; } if ((idx && idx < 6 @@ -257,9 +254,7 @@ efmpat_to_regpat( || (idx == 6 && vim_strchr((char_u *)"OPQ", efminfo->prefix) == NULL)) { - sprintf((char *)errmsg, - _("E373: Unexpected %%%c in format string"), *efmpat); - EMSG(errmsg); + semsg(_("E373: Unexpected %%%c in format string"), *efmpat); return NULL; } efminfo->addr[idx] = (char_u)++round; @@ -316,8 +311,7 @@ scanf_fmt_to_regpat( char_u **pefmp, char_u *efm, int len, - char_u *regpat, - char_u *errmsg) + char_u *regpat) { char_u *efmp = *pefmp; @@ -335,7 +329,7 @@ scanf_fmt_to_regpat( // skip ; if (efmp == efm + len) { - EMSG(_("E374: Missing ] in format string")); + emsg(_("E374: Missing ] in format string")); return NULL; } } @@ -348,9 +342,7 @@ scanf_fmt_to_regpat( else { // TODO: scanf()-like: %*ud, %*3c, %*f, ... ? - sprintf((char *)errmsg, - _("E375: Unsupported %%%c in format string"), *efmp); - EMSG(errmsg); + semsg(_("E375: Unsupported %%%c in format string"), *efmp); return NULL; } @@ -363,7 +355,7 @@ scanf_fmt_to_regpat( * Analyze/parse an errorformat prefix. */ static char_u * -efm_analyze_prefix(char_u *efmp, efm_T *efminfo, char_u *errmsg) +efm_analyze_prefix(char_u *efmp, efm_T *efminfo) { if (vim_strchr((char_u *)"+-", *efmp) != NULL) efminfo->flags = *efmp++; @@ -371,9 +363,7 @@ efm_analyze_prefix(char_u *efmp, efm_T *efminfo, char_u *errmsg) efminfo->prefix = *efmp; else { - sprintf((char *)errmsg, - _("E376: Invalid %%%c in format string prefix"), *efmp); - EMSG(errmsg); + semsg(_("E376: Invalid %%%c in format string prefix"), *efmp); return NULL; } @@ -391,8 +381,7 @@ efm_to_regpat( char_u *efm, int len, efm_T *fmt_ptr, - char_u *regpat, - char_u *errmsg) + char_u *regpat) { char_u *ptr; char_u *efmp; @@ -413,8 +402,7 @@ efm_to_regpat( break; if (idx < FMT_PATTERNS) { - ptr = efmpat_to_regpat(efmp, ptr, fmt_ptr, idx, round, - errmsg); + ptr = efmpat_to_regpat(efmp, ptr, fmt_ptr, idx, round); if (ptr == NULL) return FAIL; round++; @@ -422,7 +410,7 @@ efm_to_regpat( else if (*efmp == '*') { ++efmp; - ptr = scanf_fmt_to_regpat(&efmp, efm, len, ptr, errmsg); + ptr = scanf_fmt_to_regpat(&efmp, efm, len, ptr); if (ptr == NULL) return FAIL; } @@ -436,15 +424,13 @@ efm_to_regpat( { // prefix is allowed only at the beginning of the errorformat // option part - efmp = efm_analyze_prefix(efmp, fmt_ptr, errmsg); + efmp = efm_analyze_prefix(efmp, fmt_ptr); if (efmp == NULL) return FAIL; } else { - sprintf((char *)errmsg, - _("E377: Invalid %%%c in format string"), *efmp); - EMSG(errmsg); + semsg(_("E377: Invalid %%%c in format string"), *efmp); return FAIL; } } @@ -526,8 +512,6 @@ efm_option_part_len(char_u *efm) static efm_T * parse_efm_option(char_u *efm) { - char_u *errmsg = NULL; - int errmsglen; efm_T *fmt_ptr = NULL; efm_T *fmt_first = NULL; efm_T *fmt_last = NULL; @@ -535,11 +519,6 @@ parse_efm_option(char_u *efm) int len; int sz; - errmsglen = CMDBUFFSIZE + 1; - errmsg = alloc_id(errmsglen, aid_qf_errmsg); - if (errmsg == NULL) - goto parse_efm_end; - // Each part of the format string is copied and modified from errorformat // to regex prog. Only a few % characters are allowed. @@ -563,7 +542,7 @@ parse_efm_option(char_u *efm) // Isolate one part in the 'errorformat' option len = efm_option_part_len(efm); - if (efm_to_regpat(efm, len, fmt_ptr, fmtstr, errmsg) == FAIL) + if (efm_to_regpat(efm, len, fmt_ptr, fmtstr) == FAIL) goto parse_efm_error; if ((fmt_ptr->prog = vim_regcomp(fmtstr, RE_MAGIC + RE_STRING)) == NULL) goto parse_efm_error; @@ -572,7 +551,7 @@ parse_efm_option(char_u *efm) } if (fmt_first == NULL) // nothing found - EMSG(_("E378: 'errorformat' contains no pattern")); + emsg(_("E378: 'errorformat' contains no pattern")); goto parse_efm_end; @@ -581,7 +560,6 @@ parse_efm_error: parse_efm_end: vim_free(fmtstr); - vim_free(errmsg); return fmt_first; } @@ -1271,7 +1249,7 @@ qf_parse_dir_pfx(int idx, qffields_T *fields, qf_list_T *qfl) { if (*fields->namebuf == NUL) { - EMSG(_("E379: Missing or empty directory name")); + emsg(_("E379: Missing or empty directory name")); return QF_FAIL; } qfl->qf_directory = @@ -1568,7 +1546,7 @@ qf_setup_state( if (efile != NULL && (pstate->fd = mch_fopen((char *)efile, "r")) == NULL) { - EMSG2(_(e_openerrf), efile); + semsg(_(e_openerrf), efile); return FAIL; } @@ -1751,7 +1729,7 @@ qf_init_ext( retval = qfl->qf_count; goto qf_init_end; } - EMSG(_(e_readerrf)); + emsg(_(e_readerrf)); error2: if (!adding) { @@ -1968,7 +1946,7 @@ decr_quickfix_busy(void) #ifdef ABORT_ON_INTERNAL_ERROR if (quickfix_busy < 0) { - EMSG("quickfix_busy has become negative"); + emsg("quickfix_busy has become negative"); abort(); } #endif @@ -1980,7 +1958,7 @@ check_quickfix_busy(void) { if (quickfix_busy != 0) { - EMSGN("quickfix_busy not zero on exit: %ld", (long)quickfix_busy); + semsg("quickfix_busy not zero on exit: %ld", (long)quickfix_busy); # ifdef ABORT_ON_INTERNAL_ERROR abort(); # endif @@ -2635,7 +2613,7 @@ get_nth_valid_entry( qf_idx = prev_index; if (err != NULL) { - EMSG(_(err)); + emsg(_(err)); return NULL; } break; @@ -3041,14 +3019,14 @@ qf_jump_edit_buffer( // present. if (qfl_type == QFLT_LOCATION && !win_valid_any_tab(oldwin)) { - EMSG(_("E924: Current window was closed")); + emsg(_("E924: Current window was closed")); *opened_window = FALSE; return NOTDONE; } if (qfl_type == QFLT_QUICKFIX && !qflist_valid(NULL, save_qfid)) { - EMSG(_("E925: Current quickfix was changed")); + emsg(_("E925: Current quickfix was changed")); return NOTDONE; } @@ -3056,9 +3034,9 @@ qf_jump_edit_buffer( || !is_qf_entry_present(qfl, qf_ptr)) { if (qfl_type == QFLT_QUICKFIX) - EMSG(_("E925: Current quickfix was changed")); + emsg(_("E925: Current quickfix was changed")); else - EMSG(_(e_loc_list_changed)); + emsg(_(e_loc_list_changed)); return NOTDONE; } @@ -3315,7 +3293,7 @@ qf_jump_newwin(qf_info_T *qi, if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) { - EMSG(_(e_quickfix)); + emsg(_(e_quickfix)); return; } @@ -3497,14 +3475,14 @@ qf_list(exarg_T *eap) qi = GET_LOC_LIST(curwin); if (qi == NULL) { - EMSG(_(e_loclist)); + emsg(_(e_loclist)); return; } } if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) { - EMSG(_(e_quickfix)); + emsg(_(e_quickfix)); return; } if (*arg == '+') @@ -3514,7 +3492,7 @@ qf_list(exarg_T *eap) } if (!get_list_range(&arg, &idx1, &idx2) || *arg != NUL) { - EMSG(_(e_trailing)); + emsg(_(e_trailing)); return; } qfl = &qi->qf_lists[qi->qf_curlist]; @@ -3643,7 +3621,7 @@ qf_age(exarg_T *eap) qi = GET_LOC_LIST(curwin); if (qi == NULL) { - EMSG(_(e_loclist)); + emsg(_(e_loclist)); return; } } @@ -3658,7 +3636,7 @@ qf_age(exarg_T *eap) { if (qi->qf_curlist == 0) { - EMSG(_("E380: At bottom of quickfix stack")); + emsg(_("E380: At bottom of quickfix stack")); break; } --qi->qf_curlist; @@ -3667,7 +3645,7 @@ qf_age(exarg_T *eap) { if (qi->qf_curlist >= qi->qf_listcount - 1) { - EMSG(_("E381: At top of quickfix stack")); + emsg(_("E381: At top of quickfix stack")); break; } ++qi->qf_curlist; @@ -3870,7 +3848,7 @@ qf_view_result(int split) if (qf_list_empty(qi, qi->qf_curlist)) { - EMSG(_(e_quickfix)); + emsg(_(e_quickfix)); return; } @@ -4081,7 +4059,7 @@ ex_copen(exarg_T *eap) qi = GET_LOC_LIST(curwin); if (qi == NULL) { - EMSG(_(e_loclist)); + emsg(_(e_loclist)); return; } } @@ -4163,7 +4141,7 @@ ex_cbottom(exarg_T *eap) qi = GET_LOC_LIST(curwin); if (qi == NULL) { - EMSG(_(e_loclist)); + emsg(_(e_loclist)); return; } } @@ -4609,7 +4587,7 @@ get_mef_name(void) { name = vim_tempname('e', FALSE); if (name == NULL) - EMSG(_(e_notmp)); + emsg(_(e_notmp)); return name; } @@ -4941,7 +4919,7 @@ ex_cc(exarg_T *eap) qi = GET_LOC_LIST(curwin); if (qi == NULL) { - EMSG(_(e_loclist)); + emsg(_(e_loclist)); return; } } @@ -4992,7 +4970,7 @@ ex_cnext(exarg_T *eap) qi = GET_LOC_LIST(curwin); if (qi == NULL) { - EMSG(_(e_loclist)); + emsg(_(e_loclist)); return; } } @@ -5148,7 +5126,7 @@ vgr_init_regmatch(regmmatch_T *regmatch, char_u *s) // Pattern is empty, use last search pattern. if (last_search_pat() == NULL) { - EMSG(_(e_noprevre)); + emsg(_(e_noprevre)); return; } regmatch->regprog = vim_regcomp(last_search_pat(), RE_MAGIC); @@ -5238,7 +5216,7 @@ vgr_qflist_valid( if (wp != NULL) { // An autocmd has freed the location list. - EMSG(_(e_loc_list_changed)); + emsg(_(e_loc_list_changed)); return FALSE; } else @@ -5417,7 +5395,7 @@ ex_vimgrep(exarg_T *eap) p = skip_vimgrep_pat(eap->arg, &s, &flags); if (p == NULL) { - EMSG(_(e_invalpat)); + emsg(_(e_invalpat)); goto theend; } @@ -5428,7 +5406,7 @@ ex_vimgrep(exarg_T *eap) p = skipwhite(p); if (*p == NUL) { - EMSG(_("E683: File name missing or invalid pattern")); + emsg(_("E683: File name missing or invalid pattern")); goto theend; } @@ -5444,7 +5422,7 @@ ex_vimgrep(exarg_T *eap) goto theend; if (fcount == 0) { - EMSG(_(e_nomatch)); + emsg(_(e_nomatch)); goto theend; } @@ -5505,7 +5483,7 @@ ex_vimgrep(exarg_T *eap) if (buf == NULL) { if (!got_int) - smsg((char_u *)_("Cannot open file \"%s\""), fname); + smsg(_("Cannot open file \"%s\""), fname); } else { @@ -5608,7 +5586,7 @@ ex_vimgrep(exarg_T *eap) first_match_buf, target_dir); } else - EMSG2(_(e_nomatch2), s); + semsg(_(e_nomatch2), s); decr_quickfix_busy(); @@ -6285,7 +6263,7 @@ qf_add_entry_from_dict( if (!did_bufnr_emsg) { did_bufnr_emsg = TRUE; - EMSGN(_("E92: Buffer %ld not found"), bufnum); + semsg(_("E92: Buffer %ld not found"), bufnum); } valid = FALSE; bufnum = 0; @@ -6864,9 +6842,9 @@ ex_cbuffer(exarg_T *eap) else if (*skipwhite(skipdigits(eap->arg)) == NUL) buf = buflist_findnr(atoi((char *)eap->arg)); if (buf == NULL) - EMSG(_(e_invarg)); + emsg(_(e_invarg)); else if (buf->b_ml.ml_mfp == NULL) - EMSG(_("E681: Buffer is not loaded")); + emsg(_("E681: Buffer is not loaded")); else { if (eap->addr_count == 0) @@ -6876,7 +6854,7 @@ ex_cbuffer(exarg_T *eap) } if (eap->line1 < 1 || eap->line1 > buf->b_ml.ml_line_count || eap->line2 < 1 || eap->line2 > buf->b_ml.ml_line_count) - EMSG(_(e_invrange)); + emsg(_(e_invrange)); else { char_u *qf_title = qf_cmdtitle(*eap->cmdlinep); @@ -7011,7 +6989,7 @@ ex_cexpr(exarg_T *eap) decr_quickfix_busy(); } else - EMSG(_("E777: String or List expected")); + emsg(_("E777: String or List expected")); cleanup: free_tv(tv); } @@ -7310,7 +7288,7 @@ ex_helpgrep(exarg_T *eap) if (!qf_list_empty(qi, qi->qf_curlist)) qf_jump(qi, 0, 0, FALSE); else - EMSG2(_(e_nomatch2), eap->arg); + semsg(_(e_nomatch2), eap->arg); decr_quickfix_busy(); |