Mercurial > vim
comparison src/regexp.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 | 417bf10a756d |
children | bd12ace1bab2 |
comparison
equal
deleted
inserted
replaced
15469:bc9b5261ed01 | 15470:55ccc2d353bd |
---|---|
332 */ | 332 */ |
333 #define UCHARAT(p) ((int)*(char_u *)(p)) | 333 #define UCHARAT(p) ((int)*(char_u *)(p)) |
334 | 334 |
335 /* Used for an error (down from) vim_regcomp(): give the error message, set | 335 /* Used for an error (down from) vim_regcomp(): give the error message, set |
336 * rc_did_emsg and return NULL */ | 336 * rc_did_emsg and return NULL */ |
337 #define EMSG_RET_NULL(m) return (EMSG(m), rc_did_emsg = TRUE, (void *)NULL) | 337 #define EMSG_RET_NULL(m) return (emsg((m)), rc_did_emsg = TRUE, (void *)NULL) |
338 #define IEMSG_RET_NULL(m) return (IEMSG(m), rc_did_emsg = TRUE, (void *)NULL) | 338 #define IEMSG_RET_NULL(m) return (iemsg((m)), rc_did_emsg = TRUE, (void *)NULL) |
339 #define EMSG_RET_FAIL(m) return (EMSG(m), rc_did_emsg = TRUE, FAIL) | 339 #define EMSG_RET_FAIL(m) return (emsg((m)), rc_did_emsg = TRUE, FAIL) |
340 #define EMSG2_RET_NULL(m, c) return (EMSG2((m), (c) ? "" : "\\"), rc_did_emsg = TRUE, (void *)NULL) | 340 #define EMSG2_RET_NULL(m, c) return (semsg((const char *)(m), (c) ? "" : "\\"), rc_did_emsg = TRUE, (void *)NULL) |
341 #define EMSG2_RET_FAIL(m, c) return (EMSG2((m), (c) ? "" : "\\"), rc_did_emsg = TRUE, FAIL) | 341 #define EMSG2_RET_FAIL(m, c) return (semsg((const char *)(m), (c) ? "" : "\\"), rc_did_emsg = TRUE, FAIL) |
342 #define EMSG_ONE_RET_NULL EMSG2_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL) | 342 #define EMSG_ONE_RET_NULL EMSG2_RET_NULL(_("E369: invalid item in %s%%[]"), reg_magic == MAGIC_ALL) |
343 | 343 |
344 | 344 |
345 #define MAX_LIMIT (32767L << 16L) | 345 #define MAX_LIMIT (32767L << 16L) |
346 | 346 |
1302 for (p = regparse; *p != NUL; ++p) | 1302 for (p = regparse; *p != NUL; ++p) |
1303 if (p[0] == '@' && p[1] == '<' && (p[2] == '!' || p[2] == '=')) | 1303 if (p[0] == '@' && p[1] == '<' && (p[2] == '!' || p[2] == '=')) |
1304 break; | 1304 break; |
1305 if (*p == NUL) | 1305 if (*p == NUL) |
1306 { | 1306 { |
1307 EMSG(_("E65: Illegal back reference")); | 1307 emsg(_("E65: Illegal back reference")); |
1308 rc_did_emsg = TRUE; | 1308 rc_did_emsg = TRUE; |
1309 return FALSE; | 1309 return FALSE; |
1310 } | 1310 } |
1311 } | 1311 } |
1312 return TRUE; | 1312 return TRUE; |
1900 sprintf((char *)IObuff, _("E61: Nested %s*"), | 1900 sprintf((char *)IObuff, _("E61: Nested %s*"), |
1901 reg_magic >= MAGIC_ON ? "" : "\\"); | 1901 reg_magic >= MAGIC_ON ? "" : "\\"); |
1902 else | 1902 else |
1903 sprintf((char *)IObuff, _("E62: Nested %s%c"), | 1903 sprintf((char *)IObuff, _("E62: Nested %s%c"), |
1904 reg_magic == MAGIC_ALL ? "" : "\\", no_Magic(peekchr())); | 1904 reg_magic == MAGIC_ALL ? "" : "\\", no_Magic(peekchr())); |
1905 EMSG_RET_NULL(IObuff); | 1905 EMSG_RET_NULL((char *)IObuff); |
1906 } | 1906 } |
1907 | 1907 |
1908 return ret; | 1908 return ret; |
1909 } | 1909 } |
1910 | 1910 |
2076 case Magic('*'): | 2076 case Magic('*'): |
2077 c = no_Magic(c); | 2077 c = no_Magic(c); |
2078 sprintf((char *)IObuff, _("E64: %s%c follows nothing"), | 2078 sprintf((char *)IObuff, _("E64: %s%c follows nothing"), |
2079 (c == '*' ? reg_magic >= MAGIC_ON : reg_magic == MAGIC_ALL) | 2079 (c == '*' ? reg_magic >= MAGIC_ON : reg_magic == MAGIC_ALL) |
2080 ? "" : "\\", c); | 2080 ? "" : "\\", c); |
2081 EMSG_RET_NULL(IObuff); | 2081 EMSG_RET_NULL((char *)IObuff); |
2082 /* NOTREACHED */ | 2082 /* NOTREACHED */ |
2083 | 2083 |
2084 case Magic('~'): /* previous substitute pattern */ | 2084 case Magic('~'): /* previous substitute pattern */ |
2085 if (reg_prev_sub != NULL) | 2085 if (reg_prev_sub != NULL) |
2086 { | 2086 { |
3404 regparse++; /* Allow either \{...} or \{...\} */ | 3404 regparse++; /* Allow either \{...} or \{...\} */ |
3405 if (*regparse != '}') | 3405 if (*regparse != '}') |
3406 { | 3406 { |
3407 sprintf((char *)IObuff, _("E554: Syntax error in %s{...}"), | 3407 sprintf((char *)IObuff, _("E554: Syntax error in %s{...}"), |
3408 reg_magic == MAGIC_ALL ? "" : "\\"); | 3408 reg_magic == MAGIC_ALL ? "" : "\\"); |
3409 EMSG_RET_FAIL(IObuff); | 3409 EMSG_RET_FAIL((char *)IObuff); |
3410 } | 3410 } |
3411 | 3411 |
3412 /* | 3412 /* |
3413 * Reverse the range if there was a '-', or make sure it is in the right | 3413 * Reverse the range if there was a '-', or make sure it is in the right |
3414 * order otherwise. | 3414 * order otherwise. |
3824 } | 3824 } |
3825 | 3825 |
3826 /* Be paranoid... */ | 3826 /* Be paranoid... */ |
3827 if (prog == NULL || line == NULL) | 3827 if (prog == NULL || line == NULL) |
3828 { | 3828 { |
3829 EMSG(_(e_null)); | 3829 emsg(_(e_null)); |
3830 goto theend; | 3830 goto theend; |
3831 } | 3831 } |
3832 | 3832 |
3833 /* Check validity of program. */ | 3833 /* Check validity of program. */ |
3834 if (prog_magic_wrong()) | 3834 if (prog_magic_wrong()) |
5239 /* It could match. Prepare for trying to match what | 5239 /* It could match. Prepare for trying to match what |
5240 * follows. The code is below. Parameters are stored in | 5240 * follows. The code is below. Parameters are stored in |
5241 * a regstar_T on the regstack. */ | 5241 * a regstar_T on the regstack. */ |
5242 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) | 5242 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) |
5243 { | 5243 { |
5244 EMSG(_(e_maxmempat)); | 5244 emsg(_(e_maxmempat)); |
5245 status = RA_FAIL; | 5245 status = RA_FAIL; |
5246 } | 5246 } |
5247 else if (ga_grow(®stack, sizeof(regstar_T)) == FAIL) | 5247 else if (ga_grow(®stack, sizeof(regstar_T)) == FAIL) |
5248 status = RA_FAIL; | 5248 status = RA_FAIL; |
5249 else | 5249 else |
5284 case BEHIND: | 5284 case BEHIND: |
5285 case NOBEHIND: | 5285 case NOBEHIND: |
5286 /* Need a bit of room to store extra positions. */ | 5286 /* Need a bit of room to store extra positions. */ |
5287 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) | 5287 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) |
5288 { | 5288 { |
5289 EMSG(_(e_maxmempat)); | 5289 emsg(_(e_maxmempat)); |
5290 status = RA_FAIL; | 5290 status = RA_FAIL; |
5291 } | 5291 } |
5292 else if (ga_grow(®stack, sizeof(regbehind_T)) == FAIL) | 5292 else if (ga_grow(®stack, sizeof(regbehind_T)) == FAIL) |
5293 status = RA_FAIL; | 5293 status = RA_FAIL; |
5294 else | 5294 else |
5336 case END: | 5336 case END: |
5337 status = RA_MATCH; /* Success! */ | 5337 status = RA_MATCH; /* Success! */ |
5338 break; | 5338 break; |
5339 | 5339 |
5340 default: | 5340 default: |
5341 EMSG(_(e_re_corr)); | 5341 emsg(_(e_re_corr)); |
5342 #ifdef DEBUG | 5342 #ifdef DEBUG |
5343 printf("Illegal op code %d\n", op); | 5343 printf("Illegal op code %d\n", op); |
5344 #endif | 5344 #endif |
5345 status = RA_FAIL; | 5345 status = RA_FAIL; |
5346 break; | 5346 break; |
5746 { | 5746 { |
5747 /* | 5747 /* |
5748 * We get here only if there's trouble -- normally "case END" is | 5748 * We get here only if there's trouble -- normally "case END" is |
5749 * the terminating point. | 5749 * the terminating point. |
5750 */ | 5750 */ |
5751 EMSG(_(e_re_corr)); | 5751 emsg(_(e_re_corr)); |
5752 #ifdef DEBUG | 5752 #ifdef DEBUG |
5753 printf("Premature EOL\n"); | 5753 printf("Premature EOL\n"); |
5754 #endif | 5754 #endif |
5755 } | 5755 } |
5756 return (status == RA_MATCH); | 5756 return (status == RA_MATCH); |
5770 { | 5770 { |
5771 regitem_T *rp; | 5771 regitem_T *rp; |
5772 | 5772 |
5773 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) | 5773 if ((long)((unsigned)regstack.ga_len >> 10) >= p_mmp) |
5774 { | 5774 { |
5775 EMSG(_(e_maxmempat)); | 5775 emsg(_(e_maxmempat)); |
5776 return NULL; | 5776 return NULL; |
5777 } | 5777 } |
5778 if (ga_grow(®stack, sizeof(regitem_T)) == FAIL) | 5778 if (ga_grow(®stack, sizeof(regitem_T)) == FAIL) |
5779 return NULL; | 5779 return NULL; |
5780 | 5780 |
6183 break; | 6183 break; |
6184 } | 6184 } |
6185 break; | 6185 break; |
6186 | 6186 |
6187 default: /* Oh dear. Called inappropriately. */ | 6187 default: /* Oh dear. Called inappropriately. */ |
6188 EMSG(_(e_re_corr)); | 6188 emsg(_(e_re_corr)); |
6189 #ifdef DEBUG | 6189 #ifdef DEBUG |
6190 printf("Called regrepeat with op code %d\n", OP(p)); | 6190 printf("Called regrepeat with op code %d\n", OP(p)); |
6191 #endif | 6191 #endif |
6192 break; | 6192 break; |
6193 } | 6193 } |
6234 /* For NFA matcher we don't check the magic */ | 6234 /* For NFA matcher we don't check the magic */ |
6235 return FALSE; | 6235 return FALSE; |
6236 | 6236 |
6237 if (UCHARAT(((bt_regprog_T *)prog)->program) != REGMAGIC) | 6237 if (UCHARAT(((bt_regprog_T *)prog)->program) != REGMAGIC) |
6238 { | 6238 { |
6239 EMSG(_(e_re_corr)); | 6239 emsg(_(e_re_corr)); |
6240 return TRUE; | 6240 return TRUE; |
6241 } | 6241 } |
6242 return FALSE; | 6242 return FALSE; |
6243 } | 6243 } |
6244 | 6244 |
7485 #endif | 7485 #endif |
7486 | 7486 |
7487 /* Be paranoid... */ | 7487 /* Be paranoid... */ |
7488 if ((source == NULL && expr == NULL) || dest == NULL) | 7488 if ((source == NULL && expr == NULL) || dest == NULL) |
7489 { | 7489 { |
7490 EMSG(_(e_null)); | 7490 emsg(_(e_null)); |
7491 return 0; | 7491 return 0; |
7492 } | 7492 } |
7493 if (prog_magic_wrong()) | 7493 if (prog_magic_wrong()) |
7494 return 0; | 7494 return 0; |
7495 src = source; | 7495 src = source; |
7788 break; | 7788 break; |
7789 } | 7789 } |
7790 else if (*s == NUL) /* we hit NUL. */ | 7790 else if (*s == NUL) /* we hit NUL. */ |
7791 { | 7791 { |
7792 if (copy) | 7792 if (copy) |
7793 EMSG(_(e_re_damg)); | 7793 emsg(_(e_re_damg)); |
7794 goto exit; | 7794 goto exit; |
7795 } | 7795 } |
7796 else | 7796 else |
7797 { | 7797 { |
7798 if (backslash && (*s == CAR || *s == '\\')) | 7798 if (backslash && (*s == CAR || *s == '\\')) |
8118 || newengine == NFA_ENGINE) | 8118 || newengine == NFA_ENGINE) |
8119 { | 8119 { |
8120 regexp_engine = expr[4] - '0'; | 8120 regexp_engine = expr[4] - '0'; |
8121 expr += 5; | 8121 expr += 5; |
8122 #ifdef DEBUG | 8122 #ifdef DEBUG |
8123 smsg((char_u *)"New regexp mode selected (%d): %s", | 8123 smsg("New regexp mode selected (%d): %s", |
8124 regexp_engine, regname[newengine]); | 8124 regexp_engine, regname[newengine]); |
8125 #endif | 8125 #endif |
8126 } | 8126 } |
8127 else | 8127 else |
8128 { | 8128 { |
8129 EMSG(_("E864: \\%#= can only be followed by 0, 1, or 2. The automatic engine will be used ")); | 8129 emsg(_("E864: \\%#= can only be followed by 0, 1, or 2. The automatic engine will be used ")); |
8130 regexp_engine = AUTOMATIC_ENGINE; | 8130 regexp_engine = AUTOMATIC_ENGINE; |
8131 } | 8131 } |
8132 } | 8132 } |
8133 #ifdef DEBUG | 8133 #ifdef DEBUG |
8134 bt_regengine.expr = expr; | 8134 bt_regengine.expr = expr; |
8156 { | 8156 { |
8157 fprintf(f, "Syntax error in \"%s\"\n", expr); | 8157 fprintf(f, "Syntax error in \"%s\"\n", expr); |
8158 fclose(f); | 8158 fclose(f); |
8159 } | 8159 } |
8160 else | 8160 else |
8161 EMSG2("(NFA) Could not open \"%s\" to write !!!", | 8161 semsg("(NFA) Could not open \"%s\" to write !!!", |
8162 BT_REGEXP_DEBUG_LOG_NAME); | 8162 BT_REGEXP_DEBUG_LOG_NAME); |
8163 } | 8163 } |
8164 #endif | 8164 #endif |
8165 /* | 8165 /* |
8166 * If the NFA engine failed, try the backtracking engine. | 8166 * If the NFA engine failed, try the backtracking engine. |
8239 int rex_in_use_save = rex_in_use; | 8239 int rex_in_use_save = rex_in_use; |
8240 | 8240 |
8241 // Cannot use the same prog recursively, it contains state. | 8241 // Cannot use the same prog recursively, it contains state. |
8242 if (rmp->regprog->re_in_use) | 8242 if (rmp->regprog->re_in_use) |
8243 { | 8243 { |
8244 EMSG(_(e_recursive)); | 8244 emsg(_(e_recursive)); |
8245 return FALSE; | 8245 return FALSE; |
8246 } | 8246 } |
8247 rmp->regprog->re_in_use = TRUE; | 8247 rmp->regprog->re_in_use = TRUE; |
8248 | 8248 |
8249 if (rex_in_use) | 8249 if (rex_in_use) |
8363 int rex_in_use_save = rex_in_use; | 8363 int rex_in_use_save = rex_in_use; |
8364 | 8364 |
8365 // Cannot use the same prog recursively, it contains state. | 8365 // Cannot use the same prog recursively, it contains state. |
8366 if (rmp->regprog->re_in_use) | 8366 if (rmp->regprog->re_in_use) |
8367 { | 8367 { |
8368 EMSG(_(e_recursive)); | 8368 emsg(_(e_recursive)); |
8369 return FALSE; | 8369 return FALSE; |
8370 } | 8370 } |
8371 rmp->regprog->re_in_use = TRUE; | 8371 rmp->regprog->re_in_use = TRUE; |
8372 | 8372 |
8373 if (rex_in_use) | 8373 if (rex_in_use) |