comparison src/sign.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 51b3c36b0523
children 882bbbdc9c76
comparison
equal deleted inserted replaced
15469:bc9b5261ed01 15470:55ccc2d353bd
750 if (next_sign_typenr == MAX_TYPENR) 750 if (next_sign_typenr == MAX_TYPENR)
751 next_sign_typenr = 1; 751 next_sign_typenr = 1;
752 if (next_sign_typenr == start) 752 if (next_sign_typenr == start)
753 { 753 {
754 vim_free(sp); 754 vim_free(sp);
755 EMSG(_("E612: Too many signs defined")); 755 emsg(_("E612: Too many signs defined"));
756 return FAIL; 756 return FAIL;
757 } 757 }
758 lp = first_sign; // start all over 758 lp = first_sign; // start all over
759 continue; 759 continue;
760 } 760 }
833 cells = (int)(s - text); 833 cells = (int)(s - text);
834 } 834 }
835 // Currently must be one or two display cells 835 // Currently must be one or two display cells
836 if (s != endp || cells < 1 || cells > 2) 836 if (s != endp || cells < 1 || cells > 2)
837 { 837 {
838 EMSG2(_("E239: Invalid sign text: %s"), text); 838 semsg(_("E239: Invalid sign text: %s"), text);
839 return FAIL; 839 return FAIL;
840 } 840 }
841 841
842 vim_free(sp->sn_text); 842 vim_free(sp->sn_text);
843 // Allocate one byte more if we need to pad up 843 // Allocate one byte more if we need to pad up
868 sign_T *sp; 868 sign_T *sp;
869 869
870 sp = sign_find(name, &sp_prev); 870 sp = sign_find(name, &sp_prev);
871 if (sp == NULL) 871 if (sp == NULL)
872 { 872 {
873 EMSG2(_("E155: Unknown sign: %s"), name); 873 semsg(_("E155: Unknown sign: %s"), name);
874 return FAIL; 874 return FAIL;
875 } 875 }
876 sign_undefine(sp, sp_prev); 876 sign_undefine(sp, sp_prev);
877 877
878 return OK; 878 return OK;
888 888
889 sp = sign_find(name, NULL); 889 sp = sign_find(name, NULL);
890 if (sp != NULL) 890 if (sp != NULL)
891 sign_list_defined(sp); 891 sign_list_defined(sp);
892 else 892 else
893 EMSG2(_("E155: Unknown sign: %s"), name); 893 semsg(_("E155: Unknown sign: %s"), name);
894 } 894 }
895 895
896 /* 896 /*
897 * Place a sign at the specifed file location or update a sign. 897 * Place a sign at the specifed file location or update a sign.
898 */ 898 */
914 for (sp = first_sign; sp != NULL; sp = sp->sn_next) 914 for (sp = first_sign; sp != NULL; sp = sp->sn_next)
915 if (STRCMP(sp->sn_name, sign_name) == 0) 915 if (STRCMP(sp->sn_name, sign_name) == 0)
916 break; 916 break;
917 if (sp == NULL) 917 if (sp == NULL)
918 { 918 {
919 EMSG2(_("E155: Unknown sign: %s"), sign_name); 919 semsg(_("E155: Unknown sign: %s"), sign_name);
920 return FAIL; 920 return FAIL;
921 } 921 }
922 if (*sign_id == 0) 922 if (*sign_id == 0)
923 *sign_id = sign_group_get_next_signid(buf, sign_group); 923 *sign_id = sign_group_get_next_signid(buf, sign_group);
924 924
931 lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr); 931 lnum = buf_change_sign_type(buf, *sign_id, sign_group, sp->sn_typenr);
932 if (lnum > 0) 932 if (lnum > 0)
933 redraw_buf_line_later(buf, lnum); 933 redraw_buf_line_later(buf, lnum);
934 else 934 else
935 { 935 {
936 EMSG2(_("E885: Not possible to change sign %s"), sign_name); 936 semsg(_("E885: Not possible to change sign %s"), sign_name);
937 return FAIL; 937 return FAIL;
938 } 938 }
939 939
940 return OK; 940 return OK;
941 } 941 }
978 978
979 id = buf_findsign_id(curwin->w_buffer, curwin->w_cursor.lnum, groupname); 979 id = buf_findsign_id(curwin->w_buffer, curwin->w_cursor.lnum, groupname);
980 if (id > 0) 980 if (id > 0)
981 sign_unplace(id, groupname, curwin->w_buffer, curwin->w_cursor.lnum); 981 sign_unplace(id, groupname, curwin->w_buffer, curwin->w_cursor.lnum);
982 else 982 else
983 EMSG(_("E159: Missing sign number")); 983 emsg(_("E159: Missing sign number"));
984 } 984 }
985 985
986 /* 986 /*
987 * Jump to a sign. 987 * Jump to a sign.
988 */ 988 */
991 { 991 {
992 linenr_T lnum; 992 linenr_T lnum;
993 993
994 if ((lnum = buf_findsign(buf, sign_id, sign_group)) <= 0) 994 if ((lnum = buf_findsign(buf, sign_id, sign_group)) <= 0)
995 { 995 {
996 EMSGN(_("E157: Invalid sign ID: %ld"), sign_id); 996 semsg(_("E157: Invalid sign ID: %ld"), sign_id);
997 return -1; 997 return -1;
998 } 998 }
999 999
1000 // goto a sign ... 1000 // goto a sign ...
1001 if (buf_jump_open_win(buf) != NULL) 1001 if (buf_jump_open_win(buf) != NULL)
1008 { // ... not currently in a window 1008 { // ... not currently in a window
1009 char_u *cmd; 1009 char_u *cmd;
1010 1010
1011 if (buf->b_fname == NULL) 1011 if (buf->b_fname == NULL)
1012 { 1012 {
1013 EMSG(_("E934: Cannot jump to a buffer that does not have a name")); 1013 emsg(_("E934: Cannot jump to a buffer that does not have a name"));
1014 return -1; 1014 return -1;
1015 } 1015 }
1016 cmd = alloc((unsigned)STRLEN(buf->b_fname) + 25); 1016 cmd = alloc((unsigned)STRLEN(buf->b_fname) + 25);
1017 if (cmd == NULL) 1017 if (cmd == NULL)
1018 return -1; 1018 return -1;
1068 arg += 7; 1068 arg += 7;
1069 texthl = vim_strnsave(arg, (int)(p - arg)); 1069 texthl = vim_strnsave(arg, (int)(p - arg));
1070 } 1070 }
1071 else 1071 else
1072 { 1072 {
1073 EMSG2(_(e_invarg2), arg); 1073 semsg(_(e_invarg2), arg);
1074 failed = TRUE; 1074 failed = TRUE;
1075 break; 1075 break;
1076 } 1076 }
1077 } 1077 }
1078 1078
1109 // :sign place 1109 // :sign place
1110 // :sign place group={group} 1110 // :sign place group={group}
1111 // :sign place group=* 1111 // :sign place group=*
1112 if (lnum >= 0 || sign_name != NULL 1112 if (lnum >= 0 || sign_name != NULL
1113 || (group != NULL && *group == '\0')) 1113 || (group != NULL && *group == '\0'))
1114 EMSG(_(e_invarg)); 1114 emsg(_(e_invarg));
1115 else 1115 else
1116 sign_list_placed(buf, group); 1116 sign_list_placed(buf, group);
1117 } 1117 }
1118 else 1118 else
1119 { 1119 {
1120 // Place a new sign 1120 // Place a new sign
1121 if (sign_name == NULL || buf == NULL 1121 if (sign_name == NULL || buf == NULL
1122 || (group != NULL && *group == '\0')) 1122 || (group != NULL && *group == '\0'))
1123 { 1123 {
1124 EMSG(_(e_invarg)); 1124 emsg(_(e_invarg));
1125 return; 1125 return;
1126 } 1126 }
1127 1127
1128 sign_place(&id, group, sign_name, buf, lnum, prio); 1128 sign_place(&id, group, sign_name, buf, lnum, prio);
1129 } 1129 }
1140 int id, 1140 int id,
1141 char_u *group) 1141 char_u *group)
1142 { 1142 {
1143 if (lnum >= 0 || sign_name != NULL || (group != NULL && *group == '\0')) 1143 if (lnum >= 0 || sign_name != NULL || (group != NULL && *group == '\0'))
1144 { 1144 {
1145 EMSG(_(e_invarg)); 1145 emsg(_(e_invarg));
1146 return; 1146 return;
1147 } 1147 }
1148 1148
1149 if (id == -2) 1149 if (id == -2)
1150 { 1150 {
1209 int id, 1209 int id,
1210 char_u *group) 1210 char_u *group)
1211 { 1211 {
1212 if (sign_name == NULL && group == NULL && id == -1) 1212 if (sign_name == NULL && group == NULL && id == -1)
1213 { 1213 {
1214 EMSG(_(e_argreq)); 1214 emsg(_(e_argreq));
1215 return; 1215 return;
1216 } 1216 }
1217 1217
1218 if (buf == NULL || (group != NULL && *group == '\0') 1218 if (buf == NULL || (group != NULL && *group == '\0')
1219 || lnum >= 0 || sign_name != NULL) 1219 || lnum >= 0 || sign_name != NULL)
1220 { 1220 {
1221 // File or buffer is not specified or an empty group is used 1221 // File or buffer is not specified or an empty group is used
1222 // or a line number or a sign name is specified. 1222 // or a line number or a sign name is specified.
1223 EMSG(_(e_invarg)); 1223 emsg(_(e_invarg));
1224 return; 1224 return;
1225 } 1225 }
1226 (void)sign_jump(id, group, buf); 1226 (void)sign_jump(id, group, buf);
1227 } 1227 }
1228 1228
1273 } 1273 }
1274 else if (STRNCMP(arg, "*", 1) == 0 && cmd == SIGNCMD_UNPLACE) 1274 else if (STRNCMP(arg, "*", 1) == 0 && cmd == SIGNCMD_UNPLACE)
1275 { 1275 {
1276 if (*signid != -1) 1276 if (*signid != -1)
1277 { 1277 {
1278 EMSG(_(e_invarg)); 1278 emsg(_(e_invarg));
1279 return FAIL; 1279 return FAIL;
1280 } 1280 }
1281 *signid = -2; 1281 *signid = -2;
1282 arg = skiptowhite(arg + 1); 1282 arg = skiptowhite(arg + 1);
1283 } 1283 }
1317 { 1317 {
1318 arg += 7; 1318 arg += 7;
1319 filename = arg; 1319 filename = arg;
1320 *buf = buflist_findnr((int)getdigits(&arg)); 1320 *buf = buflist_findnr((int)getdigits(&arg));
1321 if (*skipwhite(arg) != NUL) 1321 if (*skipwhite(arg) != NUL)
1322 EMSG(_(e_trailing)); 1322 emsg(_(e_trailing));
1323 break; 1323 break;
1324 } 1324 }
1325 else 1325 else
1326 { 1326 {
1327 EMSG(_(e_invarg)); 1327 emsg(_(e_invarg));
1328 return FAIL; 1328 return FAIL;
1329 } 1329 }
1330 arg = skipwhite(arg); 1330 arg = skipwhite(arg);
1331 } 1331 }
1332 1332
1333 if (filename != NULL && *buf == NULL) 1333 if (filename != NULL && *buf == NULL)
1334 { 1334 {
1335 EMSG2(_("E158: Invalid buffer name: %s"), filename); 1335 semsg(_("E158: Invalid buffer name: %s"), filename);
1336 return FAIL; 1336 return FAIL;
1337 } 1337 }
1338 1338
1339 // If the filename is not supplied for the sign place or the sign jump 1339 // If the filename is not supplied for the sign place or the sign jump
1340 // command, then use the current buffer. 1340 // command, then use the current buffer.
1360 // Parse the subcommand. 1360 // Parse the subcommand.
1361 p = skiptowhite(arg); 1361 p = skiptowhite(arg);
1362 idx = sign_cmd_idx(arg, p); 1362 idx = sign_cmd_idx(arg, p);
1363 if (idx == SIGNCMD_LAST) 1363 if (idx == SIGNCMD_LAST)
1364 { 1364 {
1365 EMSG2(_("E160: Unknown sign command: %s"), arg); 1365 semsg(_("E160: Unknown sign command: %s"), arg);
1366 return; 1366 return;
1367 } 1367 }
1368 arg = skipwhite(p); 1368 arg = skipwhite(p);
1369 1369
1370 if (idx <= SIGNCMD_LIST) 1370 if (idx <= SIGNCMD_LIST)
1375 // ":sign list": list all defined signs 1375 // ":sign list": list all defined signs
1376 for (sp = first_sign; sp != NULL && !got_int; sp = sp->sn_next) 1376 for (sp = first_sign; sp != NULL && !got_int; sp = sp->sn_next)
1377 sign_list_defined(sp); 1377 sign_list_defined(sp);
1378 } 1378 }
1379 else if (*arg == NUL) 1379 else if (*arg == NUL)
1380 EMSG(_("E156: Missing sign name")); 1380 emsg(_("E156: Missing sign name"));
1381 else 1381 else
1382 { 1382 {
1383 char_u *name; 1383 char_u *name;
1384 1384
1385 // Isolate the sign name. If it's a number skip leading zeroes, 1385 // Isolate the sign name. If it's a number skip leading zeroes,
1589 static void 1589 static void
1590 sign_list_defined(sign_T *sp) 1590 sign_list_defined(sign_T *sp)
1591 { 1591 {
1592 char_u *p; 1592 char_u *p;
1593 1593
1594 smsg((char_u *)"sign %s", sp->sn_name); 1594 smsg("sign %s", sp->sn_name);
1595 if (sp->sn_icon != NULL) 1595 if (sp->sn_icon != NULL)
1596 { 1596 {
1597 MSG_PUTS(" icon="); 1597 MSG_PUTS(" icon=");
1598 msg_outtrans(sp->sn_icon); 1598 msg_outtrans(sp->sn_icon);
1599 # ifdef FEAT_SIGN_ICONS 1599 # ifdef FEAT_SIGN_ICONS