Mercurial > vim
comparison src/if_cscope.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 | 27b9a84395b5 |
children | 98c35d312987 |
comparison
equal
deleted
inserted
replaced
15469:bc9b5261ed01 | 15470:55ccc2d353bd |
---|---|
74 }; | 74 }; |
75 | 75 |
76 static void | 76 static void |
77 cs_usage_msg(csid_e x) | 77 cs_usage_msg(csid_e x) |
78 { | 78 { |
79 (void)EMSG2(_("E560: Usage: cs[cope] %s"), cs_cmds[(int)x].usage); | 79 (void)semsg(_("E560: Usage: cs[cope] %s"), cs_cmds[(int)x].usage); |
80 } | 80 } |
81 | 81 |
82 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | 82 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
83 | 83 |
84 static enum | 84 static enum |
252 { | 252 { |
253 int ret = FALSE; | 253 int ret = FALSE; |
254 | 254 |
255 if (*eap->arg == NUL) | 255 if (*eap->arg == NUL) |
256 { | 256 { |
257 (void)EMSG(_("E562: Usage: cstag <ident>")); | 257 (void)emsg(_("E562: Usage: cstag <ident>")); |
258 return; | 258 return; |
259 } | 259 } |
260 | 260 |
261 switch (p_csto) | 261 switch (p_csto) |
262 { | 262 { |
310 break; | 310 break; |
311 } | 311 } |
312 | 312 |
313 if (!ret) | 313 if (!ret) |
314 { | 314 { |
315 (void)EMSG(_("E257: cstag: tag not found")); | 315 (void)emsg(_("E257: cstag: tag not found")); |
316 #if defined(FEAT_QUICKFIX) | 316 #if defined(FEAT_QUICKFIX) |
317 g_do_tagpreview = 0; | 317 g_do_tagpreview = 0; |
318 #endif | 318 #endif |
319 } | 319 } |
320 | 320 |
469 char *buf = (char *)alloc((unsigned)strlen(stat_emsg) + MAXPATHL + 10); | 469 char *buf = (char *)alloc((unsigned)strlen(stat_emsg) + MAXPATHL + 10); |
470 | 470 |
471 if (buf != NULL) | 471 if (buf != NULL) |
472 { | 472 { |
473 (void)sprintf(buf, stat_emsg, fname, errno); | 473 (void)sprintf(buf, stat_emsg, fname, errno); |
474 (void)EMSG(buf); | 474 (void)emsg(buf); |
475 vim_free(buf); | 475 vim_free(buf); |
476 } | 476 } |
477 else | 477 else |
478 (void)EMSG(_("E563: stat error")); | 478 (void)emsg(_("E563: stat error")); |
479 } | 479 } |
480 | 480 |
481 | 481 |
482 /* | 482 /* |
483 * The common routine to add a new cscope connection. Called by | 483 * The common routine to add a new cscope connection. Called by |
577 i = cs_insert_filelist(fname, ppath, flags, &statbuf); | 577 i = cs_insert_filelist(fname, ppath, flags, &statbuf); |
578 } | 578 } |
579 else | 579 else |
580 { | 580 { |
581 if (p_csverbose) | 581 if (p_csverbose) |
582 (void)EMSG2( | 582 (void)semsg( |
583 _("E564: %s is not a directory or a valid cscope database"), | 583 _("E564: %s is not a directory or a valid cscope database"), |
584 fname); | 584 fname); |
585 goto add_err; | 585 goto add_err; |
586 } | 586 } |
587 | 587 |
596 | 596 |
597 if (p_csverbose) | 597 if (p_csverbose) |
598 { | 598 { |
599 msg_clr_eos(); | 599 msg_clr_eos(); |
600 (void)smsg_attr(HL_ATTR(HLF_R), | 600 (void)smsg_attr(HL_ATTR(HLF_R), |
601 (char_u *)_("Added cscope database %s"), | 601 _("Added cscope database %s"), |
602 csinfo[i].fname); | 602 csinfo[i].fname); |
603 } | 603 } |
604 } | 604 } |
605 | 605 |
606 vim_free(fname); | 606 vim_free(fname); |
649 | 649 |
650 static void | 650 static void |
651 cs_reading_emsg( | 651 cs_reading_emsg( |
652 int idx) /* connection index */ | 652 int idx) /* connection index */ |
653 { | 653 { |
654 EMSGN(_("E262: error reading cscope connection %ld"), idx); | 654 semsg(_("E262: error reading cscope connection %ld"), idx); |
655 } | 655 } |
656 | 656 |
657 #define CSREAD_BUFSIZE 2048 | 657 #define CSREAD_BUFSIZE 2048 |
658 /* | 658 /* |
659 * Count the number of matches for a given cscope connection. | 659 * Count the number of matches for a given cscope connection. |
755 break; | 755 break; |
756 case '9' : case 'a' : | 756 case '9' : case 'a' : |
757 search = 9; | 757 search = 9; |
758 break; | 758 break; |
759 default : | 759 default : |
760 (void)EMSG(_("E561: unknown cscope search type")); | 760 (void)emsg(_("E561: unknown cscope search type")); |
761 cs_usage_msg(Find); | 761 cs_usage_msg(Find); |
762 return NULL; | 762 return NULL; |
763 } | 763 } |
764 | 764 |
765 /* Skip white space before the patter, except for text and pattern search, | 765 /* Skip white space before the patter, except for text and pattern search, |
812 * from_cs[0] and writes to to_cs[1]. | 812 * from_cs[0] and writes to to_cs[1]. |
813 */ | 813 */ |
814 to_cs[0] = to_cs[1] = from_cs[0] = from_cs[1] = -1; | 814 to_cs[0] = to_cs[1] = from_cs[0] = from_cs[1] = -1; |
815 if (pipe(to_cs) < 0 || pipe(from_cs) < 0) | 815 if (pipe(to_cs) < 0 || pipe(from_cs) < 0) |
816 { | 816 { |
817 (void)EMSG(_("E566: Could not create cscope pipes")); | 817 (void)emsg(_("E566: Could not create cscope pipes")); |
818 err_closing: | 818 err_closing: |
819 if (to_cs[0] != -1) | 819 if (to_cs[0] != -1) |
820 (void)close(to_cs[0]); | 820 (void)close(to_cs[0]); |
821 if (to_cs[1] != -1) | 821 if (to_cs[1] != -1) |
822 (void)close(to_cs[1]); | 822 (void)close(to_cs[1]); |
828 } | 828 } |
829 | 829 |
830 switch (csinfo[i].pid = fork()) | 830 switch (csinfo[i].pid = fork()) |
831 { | 831 { |
832 case -1: | 832 case -1: |
833 (void)EMSG(_("E622: Could not fork for cscope")); | 833 (void)emsg(_("E622: Could not fork for cscope")); |
834 goto err_closing; | 834 goto err_closing; |
835 case 0: /* child: run cscope. */ | 835 case 0: /* child: run cscope. */ |
836 if (dup2(to_cs[0], STDIN_FILENO) == -1) | 836 if (dup2(to_cs[0], STDIN_FILENO) == -1) |
837 PERROR("cs_create_connection 1"); | 837 PERROR("cs_create_connection 1"); |
838 if (dup2(from_cs[1], STDOUT_FILENO) == -1) | 838 if (dup2(from_cs[1], STDOUT_FILENO) == -1) |
851 sa.lpSecurityDescriptor = NULL; | 851 sa.lpSecurityDescriptor = NULL; |
852 | 852 |
853 if (!(pipe_stdin = CreatePipe(&stdin_rd, &stdin_wr, &sa, 0)) | 853 if (!(pipe_stdin = CreatePipe(&stdin_rd, &stdin_wr, &sa, 0)) |
854 || !(pipe_stdout = CreatePipe(&stdout_rd, &stdout_wr, &sa, 0))) | 854 || !(pipe_stdout = CreatePipe(&stdout_rd, &stdout_wr, &sa, 0))) |
855 { | 855 { |
856 (void)EMSG(_("E566: Could not create cscope pipes")); | 856 (void)emsg(_("E566: Could not create cscope pipes")); |
857 err_closing: | 857 err_closing: |
858 if (pipe_stdin) | 858 if (pipe_stdin) |
859 { | 859 { |
860 CloseHandle(stdin_rd); | 860 CloseHandle(stdin_rd); |
861 CloseHandle(stdin_wr); | 861 CloseHandle(stdin_wr); |
985 vim_free(cmd); | 985 vim_free(cmd); |
986 | 986 |
987 if (!created) | 987 if (!created) |
988 { | 988 { |
989 PERROR(_("cs_create_connection exec failed")); | 989 PERROR(_("cs_create_connection exec failed")); |
990 (void)EMSG(_("E623: Could not spawn cscope process")); | 990 (void)emsg(_("E623: Could not spawn cscope process")); |
991 goto err_closing; | 991 goto err_closing; |
992 } | 992 } |
993 /* else */ | 993 /* else */ |
994 csinfo[i].pid = pi.dwProcessId; | 994 csinfo[i].pid = pi.dwProcessId; |
995 csinfo[i].hProc = pi.hProcess; | 995 csinfo[i].hProc = pi.hProcess; |
1027 char *opt, *pat; | 1027 char *opt, *pat; |
1028 int i; | 1028 int i; |
1029 | 1029 |
1030 if (cs_check_for_connections() == FALSE) | 1030 if (cs_check_for_connections() == FALSE) |
1031 { | 1031 { |
1032 (void)EMSG(_("E567: no cscope connections")); | 1032 (void)emsg(_("E567: no cscope connections")); |
1033 return FALSE; | 1033 return FALSE; |
1034 } | 1034 } |
1035 | 1035 |
1036 if ((opt = strtok((char *)NULL, (const char *)" ")) == NULL) | 1036 if ((opt = strtok((char *)NULL, (const char *)" ")) == NULL) |
1037 { | 1037 { |
1125 | 1125 |
1126 /* strlen will be enough because we use chars */ | 1126 /* strlen will be enough because we use chars */ |
1127 if (buf != NULL) | 1127 if (buf != NULL) |
1128 { | 1128 { |
1129 sprintf(buf, nf, *qfpos, *(qfpos-1)); | 1129 sprintf(buf, nf, *qfpos, *(qfpos-1)); |
1130 (void)EMSG(buf); | 1130 (void)emsg(buf); |
1131 vim_free(buf); | 1131 vim_free(buf); |
1132 } | 1132 } |
1133 return FALSE; | 1133 return FALSE; |
1134 } | 1134 } |
1135 | 1135 |
1192 return FALSE; | 1192 return FALSE; |
1193 } | 1193 } |
1194 | 1194 |
1195 buf = (char *)alloc((unsigned)(strlen(opt) + strlen(pat) + strlen(nf))); | 1195 buf = (char *)alloc((unsigned)(strlen(opt) + strlen(pat) + strlen(nf))); |
1196 if (buf == NULL) | 1196 if (buf == NULL) |
1197 (void)EMSG(nf); | 1197 (void)emsg(nf); |
1198 else | 1198 else |
1199 { | 1199 { |
1200 sprintf(buf, nf, opt, pat); | 1200 sprintf(buf, nf, opt, pat); |
1201 (void)EMSG(buf); | 1201 (void)emsg(buf); |
1202 vim_free(buf); | 1202 vim_free(buf); |
1203 } | 1203 } |
1204 vim_free(nummatches); | 1204 vim_free(nummatches); |
1205 return FALSE; | 1205 return FALSE; |
1206 } | 1206 } |
1214 qf_info_T *qi = NULL; | 1214 qf_info_T *qi = NULL; |
1215 win_T *wp = NULL; | 1215 win_T *wp = NULL; |
1216 | 1216 |
1217 f = mch_fopen((char *)tmp, "w"); | 1217 f = mch_fopen((char *)tmp, "w"); |
1218 if (f == NULL) | 1218 if (f == NULL) |
1219 EMSG2(_(e_notopen), tmp); | 1219 semsg(_(e_notopen), tmp); |
1220 else | 1220 else |
1221 { | 1221 { |
1222 cs_file_results(f, nummatches); | 1222 cs_file_results(f, nummatches); |
1223 fclose(f); | 1223 fclose(f); |
1224 if (use_ll) /* Use location list */ | 1224 if (use_ll) /* Use location list */ |
1287 int space_cnt = 30 - vim_strsize((char_u *)help); | 1287 int space_cnt = 30 - vim_strsize((char_u *)help); |
1288 | 1288 |
1289 /* Use %*s rather than %30s to ensure proper alignment in utf-8 */ | 1289 /* Use %*s rather than %30s to ensure proper alignment in utf-8 */ |
1290 if (space_cnt < 0) | 1290 if (space_cnt < 0) |
1291 space_cnt = 0; | 1291 space_cnt = 0; |
1292 (void)smsg((char_u *)_("%-5s: %s%*s (Usage: %s)"), | 1292 (void)smsg(_("%-5s: %s%*s (Usage: %s)"), |
1293 cmdp->name, | 1293 cmdp->name, |
1294 help, space_cnt, " ", | 1294 help, space_cnt, " ", |
1295 cmdp->usage); | 1295 cmdp->usage); |
1296 if (strcmp(cmdp->name, "find") == 0) | 1296 if (strcmp(cmdp->name, "find") == 0) |
1297 MSG_PUTS(_("\n" | 1297 MSG_PUTS(_("\n" |
1376 char *cant_msg = _("E625: cannot open cscope database: %s"); | 1376 char *cant_msg = _("E625: cannot open cscope database: %s"); |
1377 char *winmsg = GetWin32Error(); | 1377 char *winmsg = GetWin32Error(); |
1378 | 1378 |
1379 if (winmsg != NULL) | 1379 if (winmsg != NULL) |
1380 { | 1380 { |
1381 (void)EMSG2(cant_msg, winmsg); | 1381 (void)semsg(cant_msg, winmsg); |
1382 LocalFree(winmsg); | 1382 LocalFree(winmsg); |
1383 } | 1383 } |
1384 else | 1384 else |
1385 /* subst filename if can't get error text */ | 1385 /* subst filename if can't get error text */ |
1386 (void)EMSG2(cant_msg, fname); | 1386 (void)semsg(cant_msg, fname); |
1387 } | 1387 } |
1388 return -1; | 1388 return -1; |
1389 | 1389 |
1390 case FILEINFO_INFO_FAIL: /* GetFileInformationByHandle() failed */ | 1390 case FILEINFO_INFO_FAIL: /* GetFileInformationByHandle() failed */ |
1391 if (p_csverbose) | 1391 if (p_csverbose) |
1392 (void)EMSG(_("E626: cannot get cscope database information")); | 1392 (void)emsg(_("E626: cannot get cscope database information")); |
1393 return -1; | 1393 return -1; |
1394 } | 1394 } |
1395 #endif | 1395 #endif |
1396 | 1396 |
1397 i = -1; /* can be set to the index of an empty item in csinfo */ | 1397 i = -1; /* can be set to the index of an empty item in csinfo */ |
1410 && csinfo[j].nIndexLow == bhfi.nFileIndexLow)) | 1410 && csinfo[j].nIndexLow == bhfi.nFileIndexLow)) |
1411 #endif | 1411 #endif |
1412 ) | 1412 ) |
1413 { | 1413 { |
1414 if (p_csverbose) | 1414 if (p_csverbose) |
1415 (void)EMSG(_("E568: duplicate cscope database not added")); | 1415 (void)emsg(_("E568: duplicate cscope database not added")); |
1416 return -1; | 1416 return -1; |
1417 } | 1417 } |
1418 | 1418 |
1419 if (csinfo[j].fname == NULL && i == -1) | 1419 if (csinfo[j].fname == NULL && i == -1) |
1420 i = j; /* remember first empty entry */ | 1420 i = j; /* remember first empty entry */ |
1553 } | 1553 } |
1554 | 1554 |
1555 if ((i != -1) && (i >= csinfo_size || i < -1 || csinfo[i].fname == NULL)) | 1555 if ((i != -1) && (i >= csinfo_size || i < -1 || csinfo[i].fname == NULL)) |
1556 { | 1556 { |
1557 if (p_csverbose) | 1557 if (p_csverbose) |
1558 (void)EMSG2(_("E261: cscope connection %s not found"), stok); | 1558 (void)semsg(_("E261: cscope connection %s not found"), stok); |
1559 } | 1559 } |
1560 else | 1560 else |
1561 { | 1561 { |
1562 if (i == -1) | 1562 if (i == -1) |
1563 { | 1563 { |
1585 { | 1585 { |
1586 if (p_csverbose) | 1586 if (p_csverbose) |
1587 { | 1587 { |
1588 msg_clr_eos(); | 1588 msg_clr_eos(); |
1589 (void)smsg_attr(HL_ATTR(HLF_R) | MSG_HIST, | 1589 (void)smsg_attr(HL_ATTR(HLF_R) | MSG_HIST, |
1590 (char_u *)_("cscope connection %s closed"), cname); | 1590 _("cscope connection %s closed"), cname); |
1591 } | 1591 } |
1592 cs_release_csp(i, TRUE); | 1592 cs_release_csp(i, TRUE); |
1593 } | 1593 } |
1594 | 1594 |
1595 | 1595 |
1721 break; | 1721 break; |
1722 case Print: | 1722 case Print: |
1723 cs_print_tags_priv(mp, cp, cnt); | 1723 cs_print_tags_priv(mp, cp, cnt); |
1724 break; | 1724 break; |
1725 default: /* should not reach here */ | 1725 default: /* should not reach here */ |
1726 IEMSG(_("E570: fatal error in cs_manage_matches")); | 1726 iemsg(_("E570: fatal error in cs_manage_matches")); |
1727 return NULL; | 1727 return NULL; |
1728 } | 1728 } |
1729 | 1729 |
1730 return p; | 1730 return p; |
1731 } /* cs_manage_matches */ | 1731 } /* cs_manage_matches */ |
2139 { | 2139 { |
2140 /* remove eprompt from buf */ | 2140 /* remove eprompt from buf */ |
2141 buf[bufpos - epromptlen] = NUL; | 2141 buf[bufpos - epromptlen] = NUL; |
2142 | 2142 |
2143 /* print message to user */ | 2143 /* print message to user */ |
2144 (void)EMSG2(cs_emsg, buf); | 2144 (void)semsg(cs_emsg, buf); |
2145 | 2145 |
2146 /* send RETURN to cscope */ | 2146 /* send RETURN to cscope */ |
2147 (void)putc('\n', csinfo[i].to_fp); | 2147 (void)putc('\n', csinfo[i].to_fp); |
2148 (void)fflush(csinfo[i].to_fp); | 2148 (void)fflush(csinfo[i].to_fp); |
2149 | 2149 |
2160 ch = getc(csinfo[i].fr_fp); | 2160 ch = getc(csinfo[i].fr_fp); |
2161 if (ch == EOF) | 2161 if (ch == EOF) |
2162 { | 2162 { |
2163 PERROR("cs_read_prompt EOF"); | 2163 PERROR("cs_read_prompt EOF"); |
2164 if (buf != NULL && buf[0] != NUL) | 2164 if (buf != NULL && buf[0] != NUL) |
2165 (void)EMSG2(cs_emsg, buf); | 2165 (void)semsg(cs_emsg, buf); |
2166 else if (p_csverbose) | 2166 else if (p_csverbose) |
2167 cs_reading_emsg(i); /* don't have additional information */ | 2167 cs_reading_emsg(i); /* don't have additional information */ |
2168 cs_release_csp(i, TRUE); | 2168 cs_release_csp(i, TRUE); |
2169 vim_free(buf); | 2169 vim_free(buf); |
2170 return CSCOPE_FAILURE; | 2170 return CSCOPE_FAILURE; |
2474 { | 2474 { |
2475 if (csinfo[i].fname == NULL) | 2475 if (csinfo[i].fname == NULL) |
2476 continue; | 2476 continue; |
2477 | 2477 |
2478 if (csinfo[i].ppath != NULL) | 2478 if (csinfo[i].ppath != NULL) |
2479 (void)smsg((char_u *)"%2d %-5ld %-34s %-32s", | 2479 (void)smsg("%2d %-5ld %-34s %-32s", |
2480 i, (long)csinfo[i].pid, csinfo[i].fname, csinfo[i].ppath); | 2480 i, (long)csinfo[i].pid, csinfo[i].fname, csinfo[i].ppath); |
2481 else | 2481 else |
2482 (void)smsg((char_u *)"%2d %-5ld %-34s <none>", | 2482 (void)smsg("%2d %-5ld %-34s <none>", |
2483 i, (long)csinfo[i].pid, csinfo[i].fname); | 2483 i, (long)csinfo[i].pid, csinfo[i].fname); |
2484 } | 2484 } |
2485 } | 2485 } |
2486 | 2486 |
2487 wait_return(TRUE); | 2487 wait_return(TRUE); |