Mercurial > vim
comparison src/regexp_nfa.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 | a7d02a56b5d5 |
children | 98c35d312987 |
comparison
equal
deleted
inserted
replaced
15469:bc9b5261ed01 | 15470:55ccc2d353bd |
---|---|
1301 p = vim_strchr(classchars, no_Magic(c)); | 1301 p = vim_strchr(classchars, no_Magic(c)); |
1302 if (p == NULL) | 1302 if (p == NULL) |
1303 { | 1303 { |
1304 if (extra == NFA_ADD_NL) | 1304 if (extra == NFA_ADD_NL) |
1305 { | 1305 { |
1306 EMSGN(_(e_ill_char_class), c); | 1306 semsg(_(e_ill_char_class), c); |
1307 rc_did_emsg = TRUE; | 1307 rc_did_emsg = TRUE; |
1308 return FAIL; | 1308 return FAIL; |
1309 } | 1309 } |
1310 IEMSGN("INTERNAL: Unknown character class char: %ld", c); | 1310 siemsg("INTERNAL: Unknown character class char: %ld", c); |
1311 return FAIL; | 1311 return FAIL; |
1312 } | 1312 } |
1313 #ifdef FEAT_MBYTE | 1313 #ifdef FEAT_MBYTE |
1314 /* When '.' is followed by a composing char ignore the dot, so that | 1314 /* When '.' is followed by a composing char ignore the dot, so that |
1315 * the composing char is matched here. */ | 1315 * the composing char is matched here. */ |
1347 break; | 1347 break; |
1348 | 1348 |
1349 case Magic('|'): | 1349 case Magic('|'): |
1350 case Magic('&'): | 1350 case Magic('&'): |
1351 case Magic(')'): | 1351 case Magic(')'): |
1352 EMSGN(_(e_misplaced), no_Magic(c)); | 1352 semsg(_(e_misplaced), no_Magic(c)); |
1353 return FAIL; | 1353 return FAIL; |
1354 | 1354 |
1355 case Magic('='): | 1355 case Magic('='): |
1356 case Magic('?'): | 1356 case Magic('?'): |
1357 case Magic('+'): | 1357 case Magic('+'): |
1358 case Magic('@'): | 1358 case Magic('@'): |
1359 case Magic('*'): | 1359 case Magic('*'): |
1360 case Magic('{'): | 1360 case Magic('{'): |
1361 /* these should follow an atom, not form an atom */ | 1361 /* these should follow an atom, not form an atom */ |
1362 EMSGN(_(e_misplaced), no_Magic(c)); | 1362 semsg(_(e_misplaced), no_Magic(c)); |
1363 return FAIL; | 1363 return FAIL; |
1364 | 1364 |
1365 case Magic('~'): | 1365 case Magic('~'): |
1366 { | 1366 { |
1367 char_u *lp; | 1367 char_u *lp; |
1368 | 1368 |
1369 /* Previous substitute pattern. | 1369 /* Previous substitute pattern. |
1370 * Generated as "\%(pattern\)". */ | 1370 * Generated as "\%(pattern\)". */ |
1371 if (reg_prev_sub == NULL) | 1371 if (reg_prev_sub == NULL) |
1372 { | 1372 { |
1373 EMSG(_(e_nopresub)); | 1373 emsg(_(e_nopresub)); |
1374 return FAIL; | 1374 return FAIL; |
1375 } | 1375 } |
1376 for (lp = reg_prev_sub; *lp != NUL; MB_CPTR_ADV(lp)) | 1376 for (lp = reg_prev_sub; *lp != NUL; MB_CPTR_ADV(lp)) |
1377 { | 1377 { |
1378 EMIT(PTR2CHAR(lp)); | 1378 EMIT(PTR2CHAR(lp)); |
1443 return FAIL; /* cascaded error */ | 1443 return FAIL; /* cascaded error */ |
1444 re_has_z = REX_SET; | 1444 re_has_z = REX_SET; |
1445 break; | 1445 break; |
1446 #endif | 1446 #endif |
1447 default: | 1447 default: |
1448 EMSGN(_("E867: (NFA) Unknown operator '\\z%c'"), | 1448 semsg(_("E867: (NFA) Unknown operator '\\z%c'"), |
1449 no_Magic(c)); | 1449 no_Magic(c)); |
1450 return FAIL; | 1450 return FAIL; |
1451 } | 1451 } |
1452 break; | 1452 break; |
1453 | 1453 |
1575 EMIT(cmp == '<' ? NFA_VCOL_LT : | 1575 EMIT(cmp == '<' ? NFA_VCOL_LT : |
1576 cmp == '>' ? NFA_VCOL_GT : NFA_VCOL); | 1576 cmp == '>' ? NFA_VCOL_GT : NFA_VCOL); |
1577 #if VIM_SIZEOF_INT < VIM_SIZEOF_LONG | 1577 #if VIM_SIZEOF_INT < VIM_SIZEOF_LONG |
1578 if (n > INT_MAX) | 1578 if (n > INT_MAX) |
1579 { | 1579 { |
1580 EMSG(_("E951: \\% value too large")); | 1580 emsg(_("E951: \\% value too large")); |
1581 return FAIL; | 1581 return FAIL; |
1582 } | 1582 } |
1583 #endif | 1583 #endif |
1584 EMIT((int)n); | 1584 EMIT((int)n); |
1585 break; | 1585 break; |
1591 cmp == '>' ? NFA_MARK_GT : NFA_MARK); | 1591 cmp == '>' ? NFA_MARK_GT : NFA_MARK); |
1592 EMIT(getchr()); | 1592 EMIT(getchr()); |
1593 break; | 1593 break; |
1594 } | 1594 } |
1595 } | 1595 } |
1596 EMSGN(_("E867: (NFA) Unknown operator '\\%%%c'"), | 1596 semsg(_("E867: (NFA) Unknown operator '\\%%%c'"), |
1597 no_Magic(c)); | 1597 no_Magic(c)); |
1598 return FAIL; | 1598 return FAIL; |
1599 } | 1599 } |
1600 break; | 1600 break; |
1601 | 1601 |
2069 i = NFA_PREV_ATOM_LIKE_PATTERN; | 2069 i = NFA_PREV_ATOM_LIKE_PATTERN; |
2070 break; | 2070 break; |
2071 } | 2071 } |
2072 if (i == 0) | 2072 if (i == 0) |
2073 { | 2073 { |
2074 EMSGN(_("E869: (NFA) Unknown operator '\\@%c'"), op); | 2074 semsg(_("E869: (NFA) Unknown operator '\\@%c'"), op); |
2075 return FAIL; | 2075 return FAIL; |
2076 } | 2076 } |
2077 EMIT(i); | 2077 EMIT(i); |
2078 if (i == NFA_PREV_ATOM_JUST_BEFORE | 2078 if (i == NFA_PREV_ATOM_JUST_BEFORE |
2079 || i == NFA_PREV_ATOM_JUST_BEFORE_NEG) | 2079 || i == NFA_PREV_ATOM_JUST_BEFORE_NEG) |
2926 # endif | 2926 # endif |
2927 fprintf(df, "\n--------------------------\n"); | 2927 fprintf(df, "\n--------------------------\n"); |
2928 fclose(df); | 2928 fclose(df); |
2929 } | 2929 } |
2930 #endif | 2930 #endif |
2931 EMSG(_("E874: (NFA) Could not pop the stack!")); | 2931 emsg(_("E874: (NFA) Could not pop the stack!")); |
2932 } | 2932 } |
2933 | 2933 |
2934 /* | 2934 /* |
2935 * Push an item onto the stack. | 2935 * Push an item onto the stack. |
2936 */ | 2936 */ |
4875 return OK; | 4875 return OK; |
4876 break; | 4876 break; |
4877 | 4877 |
4878 default: | 4878 default: |
4879 /* should not be here :P */ | 4879 /* should not be here :P */ |
4880 IEMSGN(_(e_ill_char_class), class); | 4880 siemsg(_(e_ill_char_class), class); |
4881 return FAIL; | 4881 return FAIL; |
4882 } | 4882 } |
4883 return FAIL; | 4883 return FAIL; |
4884 } | 4884 } |
4885 | 4885 |
5144 { | 5144 { |
5145 vim_free(*listids); | 5145 vim_free(*listids); |
5146 *listids = (int *)lalloc(sizeof(int) * prog->nstate, TRUE); | 5146 *listids = (int *)lalloc(sizeof(int) * prog->nstate, TRUE); |
5147 if (*listids == NULL) | 5147 if (*listids == NULL) |
5148 { | 5148 { |
5149 EMSG(_("E878: (NFA) Could not allocate memory for branch traversal!")); | 5149 emsg(_("E878: (NFA) Could not allocate memory for branch traversal!")); |
5150 return 0; | 5150 return 0; |
5151 } | 5151 } |
5152 *listids_len = prog->nstate; | 5152 *listids_len = prog->nstate; |
5153 } | 5153 } |
5154 nfa_save_listids(prog, *listids); | 5154 nfa_save_listids(prog, *listids); |
5199 fprintf(log_fd, "MATCH = %s\n", result == TRUE ? "OK" : "FALSE"); | 5199 fprintf(log_fd, "MATCH = %s\n", result == TRUE ? "OK" : "FALSE"); |
5200 fprintf(log_fd, "****************************\n"); | 5200 fprintf(log_fd, "****************************\n"); |
5201 } | 5201 } |
5202 else | 5202 else |
5203 { | 5203 { |
5204 EMSG(_(e_log_open_failed)); | 5204 emsg(_(e_log_open_failed)); |
5205 log_fd = stderr; | 5205 log_fd = stderr; |
5206 } | 5206 } |
5207 #endif | 5207 #endif |
5208 | 5208 |
5209 return result; | 5209 return result; |
5519 | 5519 |
5520 #ifdef NFA_REGEXP_DEBUG_LOG | 5520 #ifdef NFA_REGEXP_DEBUG_LOG |
5521 debug = fopen(NFA_REGEXP_DEBUG_LOG, "a"); | 5521 debug = fopen(NFA_REGEXP_DEBUG_LOG, "a"); |
5522 if (debug == NULL) | 5522 if (debug == NULL) |
5523 { | 5523 { |
5524 EMSG2("(NFA) COULD NOT OPEN %s!", NFA_REGEXP_DEBUG_LOG); | 5524 semsg("(NFA) COULD NOT OPEN %s!", NFA_REGEXP_DEBUG_LOG); |
5525 return FALSE; | 5525 return FALSE; |
5526 } | 5526 } |
5527 #endif | 5527 #endif |
5528 nfa_match = FALSE; | 5528 nfa_match = FALSE; |
5529 | 5529 |
5547 abs(start->id), code); | 5547 abs(start->id), code); |
5548 fprintf(log_fd, "**********************************\n"); | 5548 fprintf(log_fd, "**********************************\n"); |
5549 } | 5549 } |
5550 else | 5550 else |
5551 { | 5551 { |
5552 EMSG(_(e_log_open_failed)); | 5552 emsg(_(e_log_open_failed)); |
5553 log_fd = stderr; | 5553 log_fd = stderr; |
5554 } | 5554 } |
5555 #endif | 5555 #endif |
5556 | 5556 |
5557 thislist = &list[0]; | 5557 thislist = &list[0]; |
6668 { | 6668 { |
6669 int c = t->state->c; | 6669 int c = t->state->c; |
6670 | 6670 |
6671 #ifdef DEBUG | 6671 #ifdef DEBUG |
6672 if (c < 0) | 6672 if (c < 0) |
6673 IEMSGN("INTERNAL: Negative state char: %ld", c); | 6673 siemsg("INTERNAL: Negative state char: %ld", c); |
6674 #endif | 6674 #endif |
6675 result = (c == curc); | 6675 result = (c == curc); |
6676 | 6676 |
6677 if (!result && rex.reg_ic) | 6677 if (!result && rex.reg_ic) |
6678 result = MB_TOLOWER(c) == MB_TOLOWER(curc); | 6678 result = MB_TOLOWER(c) == MB_TOLOWER(curc); |
6959 nfa_print_state(f, start); | 6959 nfa_print_state(f, start); |
6960 fprintf(f, "\n\n"); | 6960 fprintf(f, "\n\n"); |
6961 fclose(f); | 6961 fclose(f); |
6962 } | 6962 } |
6963 else | 6963 else |
6964 EMSG("Could not open temporary log file for writing"); | 6964 emsg("Could not open temporary log file for writing"); |
6965 #endif | 6965 #endif |
6966 | 6966 |
6967 clear_sub(&subs.norm); | 6967 clear_sub(&subs.norm); |
6968 clear_sub(&m.norm); | 6968 clear_sub(&m.norm); |
6969 #ifdef FEAT_SYN_HL | 6969 #ifdef FEAT_SYN_HL |
7092 } | 7092 } |
7093 | 7093 |
7094 /* Be paranoid... */ | 7094 /* Be paranoid... */ |
7095 if (prog == NULL || line == NULL) | 7095 if (prog == NULL || line == NULL) |
7096 { | 7096 { |
7097 EMSG(_(e_null)); | 7097 emsg(_(e_null)); |
7098 goto theend; | 7098 goto theend; |
7099 } | 7099 } |
7100 | 7100 |
7101 /* If pattern contains "\c" or "\C": overrule value of rex.reg_ic */ | 7101 /* If pattern contains "\c" or "\C": overrule value of rex.reg_ic */ |
7102 if (prog->regflags & RF_ICASE) | 7102 if (prog->regflags & RF_ICASE) |
7210 postfix = re2post(); | 7210 postfix = re2post(); |
7211 if (postfix == NULL) | 7211 if (postfix == NULL) |
7212 { | 7212 { |
7213 /* TODO: only give this error for debugging? */ | 7213 /* TODO: only give this error for debugging? */ |
7214 if (post_ptr >= post_end) | 7214 if (post_ptr >= post_end) |
7215 IEMSGN("Internal error: estimated max number of states insufficient: %ld", post_end - post_start); | 7215 siemsg("Internal error: estimated max number of states insufficient: %ld", post_end - post_start); |
7216 goto fail; /* Cascaded (syntax?) error */ | 7216 goto fail; /* Cascaded (syntax?) error */ |
7217 } | 7217 } |
7218 | 7218 |
7219 /* | 7219 /* |
7220 * In order to build the NFA, we parse the input regexp twice: | 7220 * In order to build the NFA, we parse the input regexp twice: |