Mercurial > vim
comparison src/quickfix.c @ 14633:462087b5c415 v8.1.0330
patch 8.1.0330: the qf_add_entries() function is too long
commit https://github.com/vim/vim/commit/6f6ef7c1951b080843f3da049d3f5d0679de7348
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 28 22:07:44 2018 +0200
patch 8.1.0330: the qf_add_entries() function is too long
Problem: The qf_add_entries() function is too long.
Solution: Split in two parts. (Yegappan Lakshmanan)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 28 Aug 2018 22:15:08 +0200 |
parents | d1b69129db99 |
children | 8770189c3e22 |
comparison
equal
deleted
inserted
replaced
14632:868225825bad | 14633:462087b5c415 |
---|---|
5995 | 5995 |
5996 return status; | 5996 return status; |
5997 } | 5997 } |
5998 | 5998 |
5999 /* | 5999 /* |
6000 * Add a new quickfix entry to list at 'qf_idx' in the stack 'qi' from the | |
6001 * items in the dict 'd'. | |
6002 */ | |
6003 static int | |
6004 qf_add_entry_from_dict( | |
6005 qf_info_T *qi, | |
6006 int qf_idx, | |
6007 dict_T *d, | |
6008 int first_entry) | |
6009 { | |
6010 static int did_bufnr_emsg; | |
6011 char_u *filename, *module, *pattern, *text, *type; | |
6012 int bufnum, valid, status, col, vcol, nr; | |
6013 long lnum; | |
6014 | |
6015 if (first_entry) | |
6016 did_bufnr_emsg = FALSE; | |
6017 | |
6018 filename = get_dict_string(d, (char_u *)"filename", TRUE); | |
6019 module = get_dict_string(d, (char_u *)"module", TRUE); | |
6020 bufnum = (int)get_dict_number(d, (char_u *)"bufnr"); | |
6021 lnum = (int)get_dict_number(d, (char_u *)"lnum"); | |
6022 col = (int)get_dict_number(d, (char_u *)"col"); | |
6023 vcol = (int)get_dict_number(d, (char_u *)"vcol"); | |
6024 nr = (int)get_dict_number(d, (char_u *)"nr"); | |
6025 type = get_dict_string(d, (char_u *)"type", TRUE); | |
6026 pattern = get_dict_string(d, (char_u *)"pattern", TRUE); | |
6027 text = get_dict_string(d, (char_u *)"text", TRUE); | |
6028 if (text == NULL) | |
6029 text = vim_strsave((char_u *)""); | |
6030 | |
6031 valid = TRUE; | |
6032 if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) | |
6033 valid = FALSE; | |
6034 | |
6035 // Mark entries with non-existing buffer number as not valid. Give the | |
6036 // error message only once. | |
6037 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
6038 { | |
6039 if (!did_bufnr_emsg) | |
6040 { | |
6041 did_bufnr_emsg = TRUE; | |
6042 EMSGN(_("E92: Buffer %ld not found"), bufnum); | |
6043 } | |
6044 valid = FALSE; | |
6045 bufnum = 0; | |
6046 } | |
6047 | |
6048 // If the 'valid' field is present it overrules the detected value. | |
6049 if ((dict_find(d, (char_u *)"valid", -1)) != NULL) | |
6050 valid = (int)get_dict_number(d, (char_u *)"valid"); | |
6051 | |
6052 status = qf_add_entry(qi, | |
6053 qf_idx, | |
6054 NULL, // dir | |
6055 filename, | |
6056 module, | |
6057 bufnum, | |
6058 text, | |
6059 lnum, | |
6060 col, | |
6061 vcol, // vis_col | |
6062 pattern, // search pattern | |
6063 nr, | |
6064 type == NULL ? NUL : *type, | |
6065 valid); | |
6066 | |
6067 vim_free(filename); | |
6068 vim_free(module); | |
6069 vim_free(pattern); | |
6070 vim_free(text); | |
6071 vim_free(type); | |
6072 | |
6073 return status; | |
6074 } | |
6075 | |
6076 /* | |
6000 * Add list of entries to quickfix/location list. Each list entry is | 6077 * Add list of entries to quickfix/location list. Each list entry is |
6001 * a dictionary with item information. | 6078 * a dictionary with item information. |
6002 */ | 6079 */ |
6003 static int | 6080 static int |
6004 qf_add_entries( | 6081 qf_add_entries( |
6008 char_u *title, | 6085 char_u *title, |
6009 int action) | 6086 int action) |
6010 { | 6087 { |
6011 listitem_T *li; | 6088 listitem_T *li; |
6012 dict_T *d; | 6089 dict_T *d; |
6013 char_u *filename, *module, *pattern, *text, *type; | |
6014 int bufnum; | |
6015 long lnum; | |
6016 int col, nr; | |
6017 int vcol; | |
6018 qfline_T *old_last = NULL; | 6090 qfline_T *old_last = NULL; |
6019 int valid, status; | |
6020 int retval = OK; | 6091 int retval = OK; |
6021 int did_bufnr_emsg = FALSE; | |
6022 | 6092 |
6023 if (action == ' ' || qf_idx == qi->qf_listcount) | 6093 if (action == ' ' || qf_idx == qi->qf_listcount) |
6024 { | 6094 { |
6025 /* make place for a new list */ | 6095 /* make place for a new list */ |
6026 qf_new_list(qi, title); | 6096 qf_new_list(qi, title); |
6042 | 6112 |
6043 d = li->li_tv.vval.v_dict; | 6113 d = li->li_tv.vval.v_dict; |
6044 if (d == NULL) | 6114 if (d == NULL) |
6045 continue; | 6115 continue; |
6046 | 6116 |
6047 filename = get_dict_string(d, (char_u *)"filename", TRUE); | 6117 retval = qf_add_entry_from_dict(qi, qf_idx, d, li == list->lv_first); |
6048 module = get_dict_string(d, (char_u *)"module", TRUE); | 6118 if (retval == FAIL) |
6049 bufnum = (int)get_dict_number(d, (char_u *)"bufnr"); | |
6050 lnum = (int)get_dict_number(d, (char_u *)"lnum"); | |
6051 col = (int)get_dict_number(d, (char_u *)"col"); | |
6052 vcol = (int)get_dict_number(d, (char_u *)"vcol"); | |
6053 nr = (int)get_dict_number(d, (char_u *)"nr"); | |
6054 type = get_dict_string(d, (char_u *)"type", TRUE); | |
6055 pattern = get_dict_string(d, (char_u *)"pattern", TRUE); | |
6056 text = get_dict_string(d, (char_u *)"text", TRUE); | |
6057 if (text == NULL) | |
6058 text = vim_strsave((char_u *)""); | |
6059 | |
6060 valid = TRUE; | |
6061 if ((filename == NULL && bufnum == 0) || (lnum == 0 && pattern == NULL)) | |
6062 valid = FALSE; | |
6063 | |
6064 /* Mark entries with non-existing buffer number as not valid. Give the | |
6065 * error message only once. */ | |
6066 if (bufnum != 0 && (buflist_findnr(bufnum) == NULL)) | |
6067 { | |
6068 if (!did_bufnr_emsg) | |
6069 { | |
6070 did_bufnr_emsg = TRUE; | |
6071 EMSGN(_("E92: Buffer %ld not found"), bufnum); | |
6072 } | |
6073 valid = FALSE; | |
6074 bufnum = 0; | |
6075 } | |
6076 | |
6077 /* If the 'valid' field is present it overrules the detected value. */ | |
6078 if ((dict_find(d, (char_u *)"valid", -1)) != NULL) | |
6079 valid = (int)get_dict_number(d, (char_u *)"valid"); | |
6080 | |
6081 status = qf_add_entry(qi, | |
6082 qf_idx, | |
6083 NULL, /* dir */ | |
6084 filename, | |
6085 module, | |
6086 bufnum, | |
6087 text, | |
6088 lnum, | |
6089 col, | |
6090 vcol, /* vis_col */ | |
6091 pattern, /* search pattern */ | |
6092 nr, | |
6093 type == NULL ? NUL : *type, | |
6094 valid); | |
6095 | |
6096 vim_free(filename); | |
6097 vim_free(module); | |
6098 vim_free(pattern); | |
6099 vim_free(text); | |
6100 vim_free(type); | |
6101 | |
6102 if (status == FAIL) | |
6103 { | |
6104 retval = FAIL; | |
6105 break; | 6119 break; |
6106 } | |
6107 } | 6120 } |
6108 | 6121 |
6109 if (qi->qf_lists[qf_idx].qf_index == 0) | 6122 if (qi->qf_lists[qf_idx].qf_index == 0) |
6110 /* no valid entry */ | 6123 /* no valid entry */ |
6111 qi->qf_lists[qf_idx].qf_nonevalid = TRUE; | 6124 qi->qf_lists[qf_idx].qf_nonevalid = TRUE; |