@@ -1183,7 +1183,8 @@ qf_init_ext(
1183
1183
fields .errmsglen = CMDBUFFSIZE + 1 ;
1184
1184
fields .errmsg = alloc_id (fields .errmsglen , aid_qf_errmsg );
1185
1185
fields .pattern = alloc_id (CMDBUFFSIZE + 1 , aid_qf_pattern );
1186
- if (fields .namebuf == NULL || fields .errmsg == NULL || fields .pattern == NULL )
1186
+ if (fields .namebuf == NULL || fields .errmsg == NULL
1187
+ || fields .pattern == NULL )
1187
1188
goto qf_init_end ;
1188
1189
1189
1190
if (efile != NULL && (state .fd = mch_fopen ((char * )efile , "r" )) == NULL )
@@ -1817,7 +1818,6 @@ qf_push_dir(char_u *dirbuf, struct dir_stack_T **stackptr, int is_file_stack)
1817
1818
}
1818
1819
}
1819
1820
1820
-
1821
1821
/*
1822
1822
* pop dirbuf from the directory stack and return previous directory or NULL if
1823
1823
* stack is empty
@@ -4948,7 +4948,8 @@ enum {
4948
4948
};
4949
4949
4950
4950
/*
4951
- * Parse text from 'di' and return the quickfix list items
4951
+ * Parse text from 'di' and return the quickfix list items.
4952
+ * Existing quickfix lists are not modified.
4952
4953
*/
4953
4954
static int
4954
4955
qf_get_list_from_lines (dict_T * what , dictitem_T * di , dict_T * retdict )
@@ -5017,25 +5018,13 @@ qf_winid(qf_info_T *qi)
5017
5018
}
5018
5019
5019
5020
/*
5020
- * Return quickfix/location list details (title) as a
5021
- * dictionary. 'what' contains the details to return. If 'list_idx' is -1,
5022
- * then current list is used. Otherwise the specified list is used.
5021
+ * Convert the keys in 'what' to quickfix list property flags.
5023
5022
*/
5024
- int
5025
- qf_get_properties ( win_T * wp , dict_T * what , dict_T * retdict )
5023
+ static int
5024
+ qf_getprop_keys2flags ( dict_T * what )
5026
5025
{
5027
- qf_info_T * qi = & ql_info ;
5028
- int status = OK ;
5029
- int qf_idx ;
5030
- dictitem_T * di ;
5031
5026
int flags = QF_GETLIST_NONE ;
5032
5027
5033
- if ((di = dict_find (what , (char_u * )"lines" , -1 )) != NULL )
5034
- return qf_get_list_from_lines (what , di , retdict );
5035
-
5036
- if (wp != NULL )
5037
- qi = GET_LOC_LIST (wp );
5038
-
5039
5028
if (dict_find (what , (char_u * )"all" , -1 ) != NULL )
5040
5029
flags |= QF_GETLIST_ALL ;
5041
5030
@@ -5066,140 +5055,223 @@ qf_get_properties(win_T *wp, dict_T *what, dict_T *retdict)
5066
5055
if (dict_find (what , (char_u * )"changedtick" , -1 ) != NULL )
5067
5056
flags |= QF_GETLIST_TICK ;
5068
5057
5069
- if (qi != NULL && qi -> qf_listcount != 0 )
5070
- {
5071
- qf_idx = qi -> qf_curlist ; /* default is the current list */
5072
- if ((di = dict_find (what , (char_u * )"nr" , -1 )) != NULL )
5073
- {
5074
- /* Use the specified quickfix/location list */
5075
- if (di -> di_tv .v_type == VAR_NUMBER )
5076
- {
5077
- /* for zero use the current list */
5078
- if (di -> di_tv .vval .v_number != 0 )
5079
- {
5080
- qf_idx = di -> di_tv .vval .v_number - 1 ;
5081
- if (qf_idx < 0 || qf_idx >= qi -> qf_listcount )
5082
- qf_idx = -1 ;
5083
- }
5084
- }
5085
- else if (di -> di_tv .v_type == VAR_STRING
5086
- && di -> di_tv .vval .v_string != NULL
5087
- && STRCMP (di -> di_tv .vval .v_string , "$" ) == 0 )
5088
- /* Get the last quickfix list number */
5089
- qf_idx = qi -> qf_listcount - 1 ;
5090
- else
5091
- qf_idx = -1 ;
5092
- flags |= QF_GETLIST_NR ;
5093
- }
5058
+ return flags ;
5059
+ }
5060
+
5061
+ /*
5062
+ * Return the quickfix list index based on 'nr' or 'id' in 'what'.
5063
+ * If 'nr' and 'id' are not present in 'what' then return the current
5064
+ * quickfix list index.
5065
+ * If 'nr' is zero then return the current quickfix list index.
5066
+ * If 'nr' is '$' then return the last quickfix list index.
5067
+ * If 'id' is present then return the index of the quickfix list with that id.
5068
+ * If 'id' is zero then return the quickfix list index specified by 'nr'.
5069
+ * Return -1, if quickfix list is not present or if the stack is empty.
5070
+ */
5071
+ static int
5072
+ qf_getprop_qfidx (qf_info_T * qi , dict_T * what )
5073
+ {
5074
+ int qf_idx ;
5075
+ dictitem_T * di ;
5094
5076
5095
- if ((di = dict_find (what , (char_u * )"id" , -1 )) != NULL )
5077
+ qf_idx = qi -> qf_curlist ; /* default is the current list */
5078
+ if ((di = dict_find (what , (char_u * )"nr" , -1 )) != NULL )
5079
+ {
5080
+ /* Use the specified quickfix/location list */
5081
+ if (di -> di_tv .v_type == VAR_NUMBER )
5096
5082
{
5097
- /* Look for a list with the specified id */
5098
- if (di -> di_tv .v_type == VAR_NUMBER )
5083
+ /* for zero use the current list */
5084
+ if (di -> di_tv .vval . v_number != 0 )
5099
5085
{
5100
- /*
5101
- * For zero, use the current list or the list specifed by 'nr'
5102
- */
5103
- if (di -> di_tv .vval .v_number != 0 )
5104
- qf_idx = qf_id2nr (qi , di -> di_tv .vval .v_number );
5105
- flags |= QF_GETLIST_ID ;
5086
+ qf_idx = di -> di_tv .vval .v_number - 1 ;
5087
+ if (qf_idx < 0 || qf_idx >= qi -> qf_listcount )
5088
+ qf_idx = -1 ;
5106
5089
}
5107
- else
5108
- qf_idx = -1 ;
5109
5090
}
5091
+ else if (di -> di_tv .v_type == VAR_STRING
5092
+ && di -> di_tv .vval .v_string != NULL
5093
+ && STRCMP (di -> di_tv .vval .v_string , "$" ) == 0 )
5094
+ /* Get the last quickfix list number */
5095
+ qf_idx = qi -> qf_listcount - 1 ;
5096
+ else
5097
+ qf_idx = -1 ;
5110
5098
}
5111
5099
5112
- /* List is not present or is empty */
5113
- if (qi == NULL || qi -> qf_listcount == 0 || qf_idx == -1 )
5100
+ if ((di = dict_find (what , (char_u * )"id" , -1 )) != NULL )
5114
5101
{
5115
- if (flags & QF_GETLIST_TITLE )
5116
- status = dict_add_nr_str (retdict , "title" , 0L , (char_u * )"" );
5117
- if ((status == OK ) && (flags & QF_GETLIST_ITEMS ))
5102
+ /* Look for a list with the specified id */
5103
+ if (di -> di_tv .v_type == VAR_NUMBER )
5118
5104
{
5119
- list_T * l = list_alloc ();
5120
- if ( l != NULL )
5121
- status = dict_add_list ( retdict , "items" , l );
5122
- else
5123
- status = FAIL ;
5105
+ /*
5106
+ * For zero, use the current list or the list specified by 'nr'
5107
+ */
5108
+ if ( di -> di_tv . vval . v_number != 0 )
5109
+ qf_idx = qf_id2nr ( qi , di -> di_tv . vval . v_number ) ;
5124
5110
}
5125
- if ((status == OK ) && (flags & QF_GETLIST_NR ))
5126
- status = dict_add_nr_str (retdict , "nr" , 0L , NULL );
5127
- if ((status == OK ) && (flags & QF_GETLIST_WINID ))
5128
- status = dict_add_nr_str (retdict , "winid" , qf_winid (qi ), NULL );
5129
- if ((status == OK ) && (flags & QF_GETLIST_CONTEXT ))
5130
- status = dict_add_nr_str (retdict , "context" , 0L , (char_u * )"" );
5131
- if ((status == OK ) && (flags & QF_GETLIST_ID ))
5132
- status = dict_add_nr_str (retdict , "id" , 0L , NULL );
5133
- if ((status == OK ) && (flags & QF_GETLIST_IDX ))
5134
- status = dict_add_nr_str (retdict , "idx" , 0L , NULL );
5135
- if ((status == OK ) && (flags & QF_GETLIST_SIZE ))
5136
- status = dict_add_nr_str (retdict , "size" , 0L , NULL );
5137
- if ((status == OK ) && (flags & QF_GETLIST_TICK ))
5138
- status = dict_add_nr_str (retdict , "changedtick" , 0L , NULL );
5139
-
5140
- return status ;
5111
+ else
5112
+ qf_idx = -1 ;
5141
5113
}
5142
5114
5115
+ return qf_idx ;
5116
+ }
5117
+
5118
+ /*
5119
+ * Return default values for quickfix list properties in retdict.
5120
+ */
5121
+ static int
5122
+ qf_getprop_defaults (qf_info_T * qi , int flags , dict_T * retdict )
5123
+ {
5124
+ int status = OK ;
5125
+
5143
5126
if (flags & QF_GETLIST_TITLE )
5144
- {
5145
- char_u * t ;
5146
- t = qi -> qf_lists [qf_idx ].qf_title ;
5147
- if (t == NULL )
5148
- t = (char_u * )"" ;
5149
- status = dict_add_nr_str (retdict , "title" , 0L , t );
5150
- }
5151
- if ((status == OK ) && (flags & QF_GETLIST_NR ))
5152
- status = dict_add_nr_str (retdict , "nr" , qf_idx + 1 , NULL );
5153
- if ((status == OK ) && (flags & QF_GETLIST_WINID ))
5154
- status = dict_add_nr_str (retdict , "winid" , qf_winid (qi ), NULL );
5127
+ status = dict_add_nr_str (retdict , "title" , 0L , (char_u * )"" );
5155
5128
if ((status == OK ) && (flags & QF_GETLIST_ITEMS ))
5156
5129
{
5157
5130
list_T * l = list_alloc ();
5158
5131
if (l != NULL )
5159
- {
5160
- (void )get_errorlist (qi , NULL , qf_idx , l );
5161
- dict_add_list (retdict , "items" , l );
5162
- }
5132
+ status = dict_add_list (retdict , "items" , l );
5163
5133
else
5164
5134
status = FAIL ;
5165
5135
}
5166
-
5136
+ if ((status == OK ) && (flags & QF_GETLIST_NR ))
5137
+ status = dict_add_nr_str (retdict , "nr" , 0L , NULL );
5138
+ if ((status == OK ) && (flags & QF_GETLIST_WINID ))
5139
+ status = dict_add_nr_str (retdict , "winid" , qf_winid (qi ), NULL );
5167
5140
if ((status == OK ) && (flags & QF_GETLIST_CONTEXT ))
5141
+ status = dict_add_nr_str (retdict , "context" , 0L , (char_u * )"" );
5142
+ if ((status == OK ) && (flags & QF_GETLIST_ID ))
5143
+ status = dict_add_nr_str (retdict , "id" , 0L , NULL );
5144
+ if ((status == OK ) && (flags & QF_GETLIST_IDX ))
5145
+ status = dict_add_nr_str (retdict , "idx" , 0L , NULL );
5146
+ if ((status == OK ) && (flags & QF_GETLIST_SIZE ))
5147
+ status = dict_add_nr_str (retdict , "size" , 0L , NULL );
5148
+ if ((status == OK ) && (flags & QF_GETLIST_TICK ))
5149
+ status = dict_add_nr_str (retdict , "changedtick" , 0L , NULL );
5150
+
5151
+ return status ;
5152
+ }
5153
+
5154
+ /*
5155
+ * Return the quickfix list title as 'title' in retdict
5156
+ */
5157
+ static int
5158
+ qf_getprop_title (qf_info_T * qi , int qf_idx , dict_T * retdict )
5159
+ {
5160
+ char_u * t ;
5161
+
5162
+ t = qi -> qf_lists [qf_idx ].qf_title ;
5163
+ if (t == NULL )
5164
+ t = (char_u * )"" ;
5165
+ return dict_add_nr_str (retdict , "title" , 0L , t );
5166
+ }
5167
+
5168
+ /*
5169
+ * Return the quickfix list items/entries as 'items' in retdict
5170
+ */
5171
+ static int
5172
+ qf_getprop_items (qf_info_T * qi , int qf_idx , dict_T * retdict )
5173
+ {
5174
+ int status = OK ;
5175
+ list_T * l = list_alloc ();
5176
+ if (l != NULL )
5168
5177
{
5169
- if (qi -> qf_lists [qf_idx ].qf_ctx != NULL )
5178
+ (void )get_errorlist (qi , NULL , qf_idx , l );
5179
+ dict_add_list (retdict , "items" , l );
5180
+ }
5181
+ else
5182
+ status = FAIL ;
5183
+
5184
+ return status ;
5185
+ }
5186
+
5187
+ /*
5188
+ * Return the quickfix list context (if any) as 'context' in retdict.
5189
+ */
5190
+ static int
5191
+ qf_getprop_ctx (qf_info_T * qi , int qf_idx , dict_T * retdict )
5192
+ {
5193
+ int status ;
5194
+ dictitem_T * di ;
5195
+
5196
+ if (qi -> qf_lists [qf_idx ].qf_ctx != NULL )
5197
+ {
5198
+ di = dictitem_alloc ((char_u * )"context" );
5199
+ if (di != NULL )
5170
5200
{
5171
- di = dictitem_alloc ((char_u * )"context" );
5172
- if (di != NULL )
5173
- {
5174
- copy_tv (qi -> qf_lists [qf_idx ].qf_ctx , & di -> di_tv );
5175
- status = dict_add (retdict , di );
5176
- if (status == FAIL )
5177
- dictitem_free (di );
5178
- }
5179
- else
5180
- status = FAIL ;
5201
+ copy_tv (qi -> qf_lists [qf_idx ].qf_ctx , & di -> di_tv );
5202
+ status = dict_add (retdict , di );
5203
+ if (status == FAIL )
5204
+ dictitem_free (di );
5181
5205
}
5182
5206
else
5183
- status = dict_add_nr_str ( retdict , "context" , 0L , ( char_u * ) "" ) ;
5207
+ status = FAIL ;
5184
5208
}
5209
+ else
5210
+ status = dict_add_nr_str (retdict , "context" , 0L , (char_u * )"" );
5211
+
5212
+ return status ;
5213
+ }
5214
+
5215
+ /*
5216
+ * Return the quickfix list index as 'idx' in retdict
5217
+ */
5218
+ static int
5219
+ qf_getprop_idx (qf_info_T * qi , int qf_idx , dict_T * retdict )
5220
+ {
5221
+ int idx = qi -> qf_lists [qf_idx ].qf_index ;
5222
+ if (qi -> qf_lists [qf_idx ].qf_count == 0 )
5223
+ /* For empty lists, qf_index is set to 1 */
5224
+ idx = 0 ;
5225
+ return dict_add_nr_str (retdict , "idx" , idx , NULL );
5226
+ }
5185
5227
5228
+ /*
5229
+ * Return quickfix/location list details (title) as a
5230
+ * dictionary. 'what' contains the details to return. If 'list_idx' is -1,
5231
+ * then current list is used. Otherwise the specified list is used.
5232
+ */
5233
+ int
5234
+ qf_get_properties (win_T * wp , dict_T * what , dict_T * retdict )
5235
+ {
5236
+ qf_info_T * qi = & ql_info ;
5237
+ int status = OK ;
5238
+ int qf_idx ;
5239
+ dictitem_T * di ;
5240
+ int flags = QF_GETLIST_NONE ;
5241
+
5242
+ if ((di = dict_find (what , (char_u * )"lines" , -1 )) != NULL )
5243
+ return qf_get_list_from_lines (what , di , retdict );
5244
+
5245
+ if (wp != NULL )
5246
+ qi = GET_LOC_LIST (wp );
5247
+
5248
+ flags = qf_getprop_keys2flags (what );
5249
+
5250
+ if (qi != NULL && qi -> qf_listcount != 0 )
5251
+ qf_idx = qf_getprop_qfidx (qi , what );
5252
+
5253
+ /* List is not present or is empty */
5254
+ if (qi == NULL || qi -> qf_listcount == 0 || qf_idx == -1 )
5255
+ return qf_getprop_defaults (qi , flags , retdict );
5256
+
5257
+ if (flags & QF_GETLIST_TITLE )
5258
+ status = qf_getprop_title (qi , qf_idx , retdict );
5259
+ if ((status == OK ) && (flags & QF_GETLIST_NR ))
5260
+ status = dict_add_nr_str (retdict , "nr" , qf_idx + 1 , NULL );
5261
+ if ((status == OK ) && (flags & QF_GETLIST_WINID ))
5262
+ status = dict_add_nr_str (retdict , "winid" , qf_winid (qi ), NULL );
5263
+ if ((status == OK ) && (flags & QF_GETLIST_ITEMS ))
5264
+ status = qf_getprop_items (qi , qf_idx , retdict );
5265
+ if ((status == OK ) && (flags & QF_GETLIST_CONTEXT ))
5266
+ status = qf_getprop_ctx (qi , qf_idx , retdict );
5186
5267
if ((status == OK ) && (flags & QF_GETLIST_ID ))
5187
5268
status = dict_add_nr_str (retdict , "id" , qi -> qf_lists [qf_idx ].qf_id ,
5188
5269
NULL );
5189
-
5190
5270
if ((status == OK ) && (flags & QF_GETLIST_IDX ))
5191
- {
5192
- int idx = qi -> qf_lists [qf_idx ].qf_index ;
5193
- if (qi -> qf_lists [qf_idx ].qf_count == 0 )
5194
- /* For empty lists, qf_index is set to 1 */
5195
- idx = 0 ;
5196
- status = dict_add_nr_str (retdict , "idx" , idx , NULL );
5197
- }
5198
-
5271
+ status = qf_getprop_idx (qi , qf_idx , retdict );
5199
5272
if ((status == OK ) && (flags & QF_GETLIST_SIZE ))
5200
5273
status = dict_add_nr_str (retdict , "size" ,
5201
5274
qi -> qf_lists [qf_idx ].qf_count , NULL );
5202
-
5203
5275
if ((status == OK ) && (flags & QF_GETLIST_TICK ))
5204
5276
status = dict_add_nr_str (retdict , "changedtick" ,
5205
5277
qi -> qf_lists [qf_idx ].qf_changedtick , NULL );
@@ -5609,7 +5681,7 @@ mark_quickfix_ctx(qf_info_T *qi, int copyID)
5609
5681
5610
5682
/*
5611
5683
* Mark the context of the quickfix list and the location lists (if present) as
5612
- * "in use". So that garabage collection doesn't free the context.
5684
+ * "in use". So that garbage collection doesn't free the context.
5613
5685
*/
5614
5686
int
5615
5687
set_ref_in_quickfix (int copyID )
0 commit comments