Mercurial > vim
comparison src/quickfix.c @ 14887:863bdbc8465b v8.1.0455
patch 8.1.0455: checking for empty quickfix stack is not consistent
commit https://github.com/vim/vim/commit/019dfe6855e011c02427bb922aafeae0245372c9
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Oct 7 14:38:49 2018 +0200
patch 8.1.0455: checking for empty quickfix stack is not consistent
Problem: Checking for empty quickfix stack is not consistent.
Solution: Use qf_stack_empty(). (Yegappan Lakshmanan)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 07 Oct 2018 14:45:05 +0200 |
parents | 3c8a4b25427c |
children | e35d98651e56 |
comparison
equal
deleted
inserted
replaced
14886:580739362915 | 14887:863bdbc8465b |
---|---|
1497 | 1497 |
1498 return QF_OK; | 1498 return QF_OK; |
1499 } | 1499 } |
1500 | 1500 |
1501 /* | 1501 /* |
1502 * Returns TRUE if the specified quickfix/location stack is empty | |
1503 */ | |
1504 static int | |
1505 qf_stack_empty(qf_info_T *qi) | |
1506 { | |
1507 return qi == NULL || qi->qf_listcount <= 0; | |
1508 } | |
1509 | |
1510 /* | |
1502 * Returns TRUE if the specified quickfix/location list is empty. | 1511 * Returns TRUE if the specified quickfix/location list is empty. |
1503 */ | 1512 */ |
1504 static int | 1513 static int |
1505 qf_list_empty(qf_info_T *qi, int qf_idx) | 1514 qf_list_empty(qf_info_T *qi, int qf_idx) |
1506 { | 1515 { |
3218 int retval = OK; | 3227 int retval = OK; |
3219 | 3228 |
3220 if (qi == NULL) | 3229 if (qi == NULL) |
3221 qi = &ql_info; | 3230 qi = &ql_info; |
3222 | 3231 |
3223 if (qi->qf_curlist >= qi->qf_listcount | 3232 if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) |
3224 || qf_list_empty(qi, qi->qf_curlist)) | |
3225 { | 3233 { |
3226 EMSG(_(e_quickfix)); | 3234 EMSG(_(e_quickfix)); |
3227 return; | 3235 return; |
3228 } | 3236 } |
3229 | 3237 |
3410 EMSG(_(e_loclist)); | 3418 EMSG(_(e_loclist)); |
3411 return; | 3419 return; |
3412 } | 3420 } |
3413 } | 3421 } |
3414 | 3422 |
3415 if (qi->qf_curlist >= qi->qf_listcount | 3423 if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) |
3416 || qf_list_empty(qi, qi->qf_curlist)) | |
3417 { | 3424 { |
3418 EMSG(_(e_quickfix)); | 3425 EMSG(_(e_quickfix)); |
3419 return; | 3426 return; |
3420 } | 3427 } |
3421 if (*arg == '+') | 3428 if (*arg == '+') |
3599 qf_info_T *qi = &ql_info; | 3606 qf_info_T *qi = &ql_info; |
3600 int i; | 3607 int i; |
3601 | 3608 |
3602 if (is_loclist_cmd(eap->cmdidx)) | 3609 if (is_loclist_cmd(eap->cmdidx)) |
3603 qi = GET_LOC_LIST(curwin); | 3610 qi = GET_LOC_LIST(curwin); |
3604 if (qi == NULL || (qi->qf_listcount == 0 | 3611 if (qf_stack_empty(qi) || qf_list_empty(qi, qi->qf_curlist)) |
3605 && qf_list_empty(qi, qi->qf_curlist))) | |
3606 MSG(_("No entries")); | 3612 MSG(_("No entries")); |
3607 else | 3613 else |
3608 for (i = 0; i < qi->qf_listcount; ++i) | 3614 for (i = 0; i < qi->qf_listcount; ++i) |
3609 qf_msg(qi, i, i == qi->qf_curlist ? "> " : " "); | 3615 qf_msg(qi, i, i == qi->qf_curlist ? "> " : " "); |
3610 } | 3616 } |
3828 /* | 3834 /* |
3829 * If a quickfix window is open but we have no errors to display, | 3835 * If a quickfix window is open but we have no errors to display, |
3830 * close the window. If a quickfix window is not open, then open | 3836 * close the window. If a quickfix window is not open, then open |
3831 * it if we have errors; otherwise, leave it closed. | 3837 * it if we have errors; otherwise, leave it closed. |
3832 */ | 3838 */ |
3833 if (qi->qf_lists[qi->qf_curlist].qf_nonevalid | 3839 if (qf_stack_empty(qi) |
3834 || qf_list_empty(qi, qi->qf_curlist) | 3840 || qi->qf_lists[qi->qf_curlist].qf_nonevalid |
3835 || qi->qf_curlist >= qi->qf_listcount) | 3841 || qf_list_empty(qi, qi->qf_curlist)) |
3836 { | 3842 { |
3837 if (win != NULL) | 3843 if (win != NULL) |
3838 ex_cclose(eap); | 3844 ex_cclose(eap); |
3839 } | 3845 } |
3840 else if (win == NULL) | 3846 else if (win == NULL) |
4340 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) | 4346 while ((curbuf->b_ml.ml_flags & ML_EMPTY) == 0) |
4341 (void)ml_delete((linenr_T)1, FALSE); | 4347 (void)ml_delete((linenr_T)1, FALSE); |
4342 } | 4348 } |
4343 | 4349 |
4344 /* Check if there is anything to display */ | 4350 /* Check if there is anything to display */ |
4345 if (qi->qf_curlist < qi->qf_listcount) | 4351 if (!qf_stack_empty(qi)) |
4346 { | 4352 { |
4347 char_u dirname[MAXPATHL]; | 4353 char_u dirname[MAXPATHL]; |
4348 | 4354 |
4349 *dirname = NUL; | 4355 *dirname = NUL; |
4350 | 4356 |
5331 } | 5337 } |
5332 | 5338 |
5333 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd | 5339 if ((eap->cmdidx != CMD_grepadd && eap->cmdidx != CMD_lgrepadd |
5334 && eap->cmdidx != CMD_vimgrepadd | 5340 && eap->cmdidx != CMD_vimgrepadd |
5335 && eap->cmdidx != CMD_lvimgrepadd) | 5341 && eap->cmdidx != CMD_lvimgrepadd) |
5336 || qi->qf_curlist == qi->qf_listcount) | 5342 || qf_stack_empty(qi)) |
5337 /* make place for a new list */ | 5343 /* make place for a new list */ |
5338 qf_new_list(qi, title != NULL ? title : qf_cmdtitle(*eap->cmdlinep)); | 5344 qf_new_list(qi, title != NULL ? title : qf_cmdtitle(*eap->cmdlinep)); |
5339 | 5345 |
5340 /* parse the list of arguments */ | 5346 /* parse the list of arguments */ |
5341 if (get_arglist_exp(p, &fcount, &fnames, TRUE) == FAIL) | 5347 if (get_arglist_exp(p, &fcount, &fnames, TRUE) == FAIL) |
6105 if (wp != NULL) | 6111 if (wp != NULL) |
6106 qi = GET_LOC_LIST(wp); | 6112 qi = GET_LOC_LIST(wp); |
6107 | 6113 |
6108 flags = qf_getprop_keys2flags(what, (wp != NULL)); | 6114 flags = qf_getprop_keys2flags(what, (wp != NULL)); |
6109 | 6115 |
6110 if (qi != NULL && qi->qf_listcount != 0) | 6116 if (!qf_stack_empty(qi)) |
6111 qf_idx = qf_getprop_qfidx(qi, what); | 6117 qf_idx = qf_getprop_qfidx(qi, what); |
6112 | 6118 |
6113 /* List is not present or is empty */ | 6119 /* List is not present or is empty */ |
6114 if (qi == NULL || qi->qf_listcount == 0 || qf_idx == INVALID_QFIDX) | 6120 if (qf_stack_empty(qi) || qf_idx == INVALID_QFIDX) |
6115 return qf_getprop_defaults(qi, flags, retdict); | 6121 return qf_getprop_defaults(qi, flags, retdict); |
6116 | 6122 |
6117 qfl = &qi->qf_lists[qf_idx]; | 6123 qfl = &qi->qf_lists[qf_idx]; |
6118 | 6124 |
6119 if (flags & QF_GETLIST_TITLE) | 6125 if (flags & QF_GETLIST_TITLE) |
6311 * When creating a new list, accept qf_idx pointing to the next | 6317 * When creating a new list, accept qf_idx pointing to the next |
6312 * non-available list and add the new list at the end of the | 6318 * non-available list and add the new list at the end of the |
6313 * stack. | 6319 * stack. |
6314 */ | 6320 */ |
6315 *newlist = TRUE; | 6321 *newlist = TRUE; |
6316 qf_idx = qi->qf_listcount > 0 ? qi->qf_listcount - 1 : 0; | 6322 qf_idx = qf_stack_empty(qi) ? 0 : qi->qf_listcount - 1; |
6317 } | 6323 } |
6318 else if (qf_idx < 0 || qf_idx >= qi->qf_listcount) | 6324 else if (qf_idx < 0 || qf_idx >= qi->qf_listcount) |
6319 return INVALID_QFIDX; | 6325 return INVALID_QFIDX; |
6320 else if (action != ' ') | 6326 else if (action != ' ') |
6321 *newlist = FALSE; /* use the specified list */ | 6327 *newlist = FALSE; /* use the specified list */ |
6322 } | 6328 } |
6323 else if (di->di_tv.v_type == VAR_STRING | 6329 else if (di->di_tv.v_type == VAR_STRING |
6324 && di->di_tv.vval.v_string != NULL | 6330 && di->di_tv.vval.v_string != NULL |
6325 && STRCMP(di->di_tv.vval.v_string, "$") == 0) | 6331 && STRCMP(di->di_tv.vval.v_string, "$") == 0) |
6326 { | 6332 { |
6327 if (qi->qf_listcount > 0) | 6333 if (!qf_stack_empty(qi)) |
6328 qf_idx = qi->qf_listcount - 1; | 6334 qf_idx = qi->qf_listcount - 1; |
6329 else if (*newlist) | 6335 else if (*newlist) |
6330 qf_idx = 0; | 6336 qf_idx = 0; |
6331 else | 6337 else |
6332 return INVALID_QFIDX; | 6338 return INVALID_QFIDX; |
6450 dictitem_T *di; | 6456 dictitem_T *di; |
6451 int retval = FAIL; | 6457 int retval = FAIL; |
6452 int qf_idx; | 6458 int qf_idx; |
6453 int newlist = FALSE; | 6459 int newlist = FALSE; |
6454 | 6460 |
6455 if (action == ' ' || qi->qf_curlist == qi->qf_listcount) | 6461 if (action == ' ' || qf_stack_empty(qi)) |
6456 newlist = TRUE; | 6462 newlist = TRUE; |
6457 | 6463 |
6458 qf_idx = qf_setprop_get_qfidx(qi, what, action, &newlist); | 6464 qf_idx = qf_setprop_get_qfidx(qi, what, action, &newlist); |
6459 if (qf_idx == INVALID_QFIDX) /* List not found */ | 6465 if (qf_idx == INVALID_QFIDX) /* List not found */ |
6460 return FAIL; | 6466 return FAIL; |