]>
Commit | Line | Data |
---|---|---|
39a54fe5 AG |
1 | To: vim-dev@vim.org |
2 | Subject: Patch 7.2.228 | |
3 | Fcc: outbox | |
4 | From: Bram Moolenaar <Bram@moolenaar.net> | |
5 | Mime-Version: 1.0 | |
6 | Content-Type: text/plain; charset=UTF-8 | |
7 | Content-Transfer-Encoding: 8bit | |
8 | ------------ | |
9 | ||
10 | Patch 7.2.228 | |
11 | Problem: Cscope is limited to 8 connections. | |
12 | Solution: Allocated the connection array to handle any number of | |
13 | connections. (Dominique Pelle) | |
14 | Files: runtime/doc/if_cscop.txt, src/if_cscope.h, src/if_cscope.c | |
15 | ||
16 | ||
17 | *** ../vim-7.2.227/runtime/doc/if_cscop.txt 2009-03-18 14:30:46.000000000 +0100 | |
18 | --- runtime/doc/if_cscop.txt 2009-07-09 15:40:48.000000000 +0200 | |
19 | *************** | |
20 | *** 355,367 **** | |
21 | The DJGPP-built version from http://cscope.sourceforge.net is known to not | |
22 | work with Vim. | |
23 | ||
24 | ! There are a couple of hard-coded limitations: | |
25 | ! | |
26 | ! 1. The maximum number of cscope connections allowed is 8. Do you | |
27 | ! really need more? | |
28 | ! | |
29 | ! 2. Doing a |:tjump| when |:cstag| searches the tag files is not | |
30 | ! configurable (e.g., you can't do a tselect instead). | |
31 | ||
32 | ============================================================================== | |
33 | 6. Suggested usage *cscope-suggestions* | |
34 | --- 355,362 ---- | |
35 | The DJGPP-built version from http://cscope.sourceforge.net is known to not | |
36 | work with Vim. | |
37 | ||
38 | ! Hard-coded limitation: doing a |:tjump| when |:cstag| searches the tag files | |
39 | ! is not configurable (e.g., you can't do a tselect instead). | |
40 | ||
41 | ============================================================================== | |
42 | 6. Suggested usage *cscope-suggestions* | |
43 | *** ../vim-7.2.227/src/if_cscope.h 2008-08-25 04:35:13.000000000 +0200 | |
44 | --- src/if_cscope.h 2009-07-09 15:39:32.000000000 +0200 | |
45 | *************** | |
46 | *** 25,31 **** | |
47 | ||
48 | #define CSCOPE_SUCCESS 0 | |
49 | #define CSCOPE_FAILURE -1 | |
50 | - #define CSCOPE_MAX_CONNECTIONS 8 /* you actually need more? */ | |
51 | ||
52 | #define CSCOPE_DBFILE "cscope.out" | |
53 | #define CSCOPE_PROMPT ">> " | |
54 | --- 25,30 ---- | |
55 | *** ../vim-7.2.227/src/if_cscope.c 2009-05-16 17:29:37.000000000 +0200 | |
56 | --- src/if_cscope.c 2009-07-09 15:39:32.000000000 +0200 | |
57 | *************** | |
58 | *** 46,52 **** | |
59 | static int cs_find __ARGS((exarg_T *eap)); | |
60 | static int cs_find_common __ARGS((char *opt, char *pat, int, int, int)); | |
61 | static int cs_help __ARGS((exarg_T *eap)); | |
62 | - static void cs_init __ARGS((void)); | |
63 | static void clear_csinfo __ARGS((int i)); | |
64 | static int cs_insert_filelist __ARGS((char *, char *, char *, | |
65 | struct stat *)); | |
66 | --- 46,51 ---- | |
67 | *************** | |
68 | *** 66,72 **** | |
69 | static int cs_show __ARGS((exarg_T *eap)); | |
70 | ||
71 | ||
72 | ! static csinfo_T csinfo[CSCOPE_MAX_CONNECTIONS]; | |
73 | static int eap_arg_len; /* length of eap->arg, set in | |
74 | cs_lookup_cmd() */ | |
75 | static cscmd_T cs_cmds[] = | |
76 | --- 65,74 ---- | |
77 | static int cs_show __ARGS((exarg_T *eap)); | |
78 | ||
79 | ||
80 | ! static csinfo_T * csinfo = NULL; | |
81 | ! static int csinfo_size = 0; /* number of items allocated in | |
82 | ! csinfo[] */ | |
83 | ! | |
84 | static int eap_arg_len; /* length of eap->arg, set in | |
85 | cs_lookup_cmd() */ | |
86 | static cscmd_T cs_cmds[] = | |
87 | *************** | |
88 | *** 144,166 **** | |
89 | } | |
90 | case EXP_CSCOPE_KILL: | |
91 | { | |
92 | ! static char_u connection[2]; | |
93 | ||
94 | /* ":cscope kill" accepts connection numbers or partial names of | |
95 | * the pathname of the cscope database as argument. Only complete | |
96 | * with connection numbers. -1 can also be used to kill all | |
97 | * connections. */ | |
98 | ! for (i = 0, current_idx = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
99 | { | |
100 | if (csinfo[i].fname == NULL) | |
101 | continue; | |
102 | if (current_idx++ == idx) | |
103 | { | |
104 | ! /* Connection number fits in one character since | |
105 | ! * CSCOPE_MAX_CONNECTIONS is < 10 */ | |
106 | ! connection[0] = i + '0'; | |
107 | ! connection[1] = NUL; | |
108 | ! return connection; | |
109 | } | |
110 | } | |
111 | return (current_idx == idx && idx > 0) ? (char_u *)"-1" : NULL; | |
112 | --- 146,165 ---- | |
113 | } | |
114 | case EXP_CSCOPE_KILL: | |
115 | { | |
116 | ! static char connection[5]; | |
117 | ||
118 | /* ":cscope kill" accepts connection numbers or partial names of | |
119 | * the pathname of the cscope database as argument. Only complete | |
120 | * with connection numbers. -1 can also be used to kill all | |
121 | * connections. */ | |
122 | ! for (i = 0, current_idx = 0; i < csinfo_size; i++) | |
123 | { | |
124 | if (csinfo[i].fname == NULL) | |
125 | continue; | |
126 | if (current_idx++ == idx) | |
127 | { | |
128 | ! vim_snprintf(connection, sizeof(connection), "%d", i); | |
129 | ! return (char_u *)connection; | |
130 | } | |
131 | } | |
132 | return (current_idx == idx && idx > 0) ? (char_u *)"-1" : NULL; | |
133 | *************** | |
134 | *** 223,229 **** | |
135 | { | |
136 | cscmd_T *cmdp; | |
137 | ||
138 | - cs_init(); | |
139 | if ((cmdp = cs_lookup_cmd(eap)) == NULL) | |
140 | { | |
141 | cs_help(eap); | |
142 | --- 222,227 ---- | |
143 | *************** | |
144 | *** 284,291 **** | |
145 | { | |
146 | int ret = FALSE; | |
147 | ||
148 | - cs_init(); | |
149 | - | |
150 | if (*eap->arg == NUL) | |
151 | { | |
152 | (void)EMSG(_("E562: Usage: cstag <ident>")); | |
153 | --- 282,287 ---- | |
154 | *************** | |
155 | *** 441,447 **** | |
156 | if (num < 0 || num > 4 || (num > 0 && !dbpath)) | |
157 | return FALSE; | |
158 | ||
159 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
160 | { | |
161 | if (!csinfo[i].fname) | |
162 | continue; | |
163 | --- 437,443 ---- | |
164 | if (num < 0 || num > 4 || (num > 0 && !dbpath)) | |
165 | return FALSE; | |
166 | ||
167 | ! for (i = 0; i < csinfo_size; i++) | |
168 | { | |
169 | if (!csinfo[i].fname) | |
170 | continue; | |
171 | *************** | |
172 | *** 684,690 **** | |
173 | short i; | |
174 | short cnt = 0; | |
175 | ||
176 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
177 | { | |
178 | if (csinfo[i].fname != NULL) | |
179 | cnt++; | |
180 | --- 680,686 ---- | |
181 | short i; | |
182 | short cnt = 0; | |
183 | ||
184 | ! for (i = 0; i < csinfo_size; i++) | |
185 | { | |
186 | if (csinfo[i].fname != NULL) | |
187 | cnt++; | |
188 | *************** | |
189 | *** 1112,1118 **** | |
190 | { | |
191 | int i; | |
192 | char *cmd; | |
193 | ! int nummatches[CSCOPE_MAX_CONNECTIONS], totmatches; | |
194 | #ifdef FEAT_QUICKFIX | |
195 | char cmdletter; | |
196 | char *qfpos; | |
197 | --- 1108,1115 ---- | |
198 | { | |
199 | int i; | |
200 | char *cmd; | |
201 | ! int *nummatches; | |
202 | ! int totmatches; | |
203 | #ifdef FEAT_QUICKFIX | |
204 | char cmdletter; | |
205 | char *qfpos; | |
206 | *************** | |
207 | *** 1123,1135 **** | |
208 | if (cmd == NULL) | |
209 | return FALSE; | |
210 | ||
211 | /* send query to all open connections, then count the total number | |
212 | * of matches so we can alloc matchesp all in one swell foop | |
213 | */ | |
214 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
215 | nummatches[i] = 0; | |
216 | totmatches = 0; | |
217 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
218 | { | |
219 | if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL) | |
220 | continue; | |
221 | --- 1120,1136 ---- | |
222 | if (cmd == NULL) | |
223 | return FALSE; | |
224 | ||
225 | + nummatches = (int *)alloc(sizeof(int)*csinfo_size); | |
226 | + if (nummatches == NULL) | |
227 | + return FALSE; | |
228 | + | |
229 | /* send query to all open connections, then count the total number | |
230 | * of matches so we can alloc matchesp all in one swell foop | |
231 | */ | |
232 | ! for (i = 0; i < csinfo_size; i++) | |
233 | nummatches[i] = 0; | |
234 | totmatches = 0; | |
235 | ! for (i = 0; i < csinfo_size; i++) | |
236 | { | |
237 | if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL) | |
238 | continue; | |
239 | *************** | |
240 | *** 1154,1160 **** | |
241 | --- 1155,1164 ---- | |
242 | char *buf; | |
243 | ||
244 | if (!verbose) | |
245 | + { | |
246 | + vim_free(nummatches); | |
247 | return FALSE; | |
248 | + } | |
249 | ||
250 | buf = (char *)alloc((unsigned)(strlen(opt) + strlen(pat) + strlen(nf))); | |
251 | if (buf == NULL) | |
252 | *************** | |
253 | *** 1165,1170 **** | |
254 | --- 1169,1175 ---- | |
255 | (void)EMSG(buf); | |
256 | vim_free(buf); | |
257 | } | |
258 | + vim_free(nummatches); | |
259 | return FALSE; | |
260 | } | |
261 | ||
262 | *************** | |
263 | *** 1217,1222 **** | |
264 | --- 1222,1228 ---- | |
265 | (void)EMSG(buf); | |
266 | vim_free(buf); | |
267 | } | |
268 | + vim_free(nummatches); | |
269 | return FALSE; | |
270 | } | |
271 | } | |
272 | *************** | |
273 | *** 1264,1269 **** | |
274 | --- 1270,1276 ---- | |
275 | } | |
276 | mch_remove(tmp); | |
277 | vim_free(tmp); | |
278 | + vim_free(nummatches); | |
279 | return TRUE; | |
280 | } | |
281 | else | |
282 | *************** | |
283 | *** 1275,1280 **** | |
284 | --- 1282,1288 ---- | |
285 | /* read output */ | |
286 | cs_fill_results((char *)pat, totmatches, nummatches, &matches, | |
287 | &contexts, &matched); | |
288 | + vim_free(nummatches); | |
289 | if (matches == NULL) | |
290 | return FALSE; | |
291 | ||
292 | *************** | |
293 | *** 1328,1353 **** | |
294 | } /* cs_help */ | |
295 | ||
296 | ||
297 | - /* | |
298 | - * PRIVATE: cs_init | |
299 | - * | |
300 | - * initialize cscope structure if not already | |
301 | - */ | |
302 | - static void | |
303 | - cs_init() | |
304 | - { | |
305 | - short i; | |
306 | - static int init_already = FALSE; | |
307 | - | |
308 | - if (init_already) | |
309 | - return; | |
310 | - | |
311 | - for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
312 | - clear_csinfo(i); | |
313 | - | |
314 | - init_already = TRUE; | |
315 | - } /* cs_init */ | |
316 | - | |
317 | static void | |
318 | clear_csinfo(i) | |
319 | int i; | |
320 | --- 1336,1341 ---- | |
321 | *************** | |
322 | *** 1444,1450 **** | |
323 | #endif | |
324 | ||
325 | i = -1; /* can be set to the index of an empty item in csinfo */ | |
326 | ! for (j = 0; j < CSCOPE_MAX_CONNECTIONS; j++) | |
327 | { | |
328 | if (csinfo[j].fname != NULL | |
329 | #if defined(UNIX) | |
330 | --- 1432,1438 ---- | |
331 | #endif | |
332 | ||
333 | i = -1; /* can be set to the index of an empty item in csinfo */ | |
334 | ! for (j = 0; j < csinfo_size; j++) | |
335 | { | |
336 | if (csinfo[j].fname != NULL | |
337 | #if defined(UNIX) | |
338 | *************** | |
339 | *** 1471,1479 **** | |
340 | ||
341 | if (i == -1) | |
342 | { | |
343 | ! if (p_csverbose) | |
344 | ! (void)EMSG(_("E569: maximum number of cscope connections reached")); | |
345 | ! return -1; | |
346 | } | |
347 | ||
348 | if ((csinfo[i].fname = (char *)alloc((unsigned)strlen(fname)+1)) == NULL) | |
349 | --- 1459,1483 ---- | |
350 | ||
351 | if (i == -1) | |
352 | { | |
353 | ! i = csinfo_size; | |
354 | ! if (csinfo_size == 0) | |
355 | ! { | |
356 | ! /* First time allocation: allocate only 1 connection. It should | |
357 | ! * be enough for most users. If more is needed, csinfo will be | |
358 | ! * reallocated. */ | |
359 | ! csinfo_size = 1; | |
360 | ! csinfo = (csinfo_T *)alloc_clear(sizeof(csinfo_T)); | |
361 | ! } | |
362 | ! else | |
363 | ! { | |
364 | ! /* Reallocate space for more connections. */ | |
365 | ! csinfo_size *= 2; | |
366 | ! csinfo = vim_realloc(csinfo, sizeof(csinfo_T)*csinfo_size); | |
367 | ! } | |
368 | ! if (csinfo == NULL) | |
369 | ! return -1; | |
370 | ! for (j = csinfo_size/2; j < csinfo_size; j++) | |
371 | ! clear_csinfo(j); | |
372 | } | |
373 | ||
374 | if ((csinfo[i].fname = (char *)alloc((unsigned)strlen(fname)+1)) == NULL) | |
375 | *************** | |
376 | *** 1580,1594 **** | |
377 | /* It must be part of a name. We will try to find a match | |
378 | * within all the names in the csinfo data structure | |
379 | */ | |
380 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
381 | { | |
382 | if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok)) | |
383 | break; | |
384 | } | |
385 | } | |
386 | ||
387 | ! if ((i >= CSCOPE_MAX_CONNECTIONS || i < -1 || csinfo[i].fname == NULL) | |
388 | ! && i != -1) | |
389 | { | |
390 | if (p_csverbose) | |
391 | (void)EMSG2(_("E261: cscope connection %s not found"), stok); | |
392 | --- 1584,1597 ---- | |
393 | /* It must be part of a name. We will try to find a match | |
394 | * within all the names in the csinfo data structure | |
395 | */ | |
396 | ! for (i = 0; i < csinfo_size; i++) | |
397 | { | |
398 | if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok)) | |
399 | break; | |
400 | } | |
401 | } | |
402 | ||
403 | ! if ((i != -1) && (i >= csinfo_size || i < -1 || csinfo[i].fname == NULL)) | |
404 | { | |
405 | if (p_csverbose) | |
406 | (void)EMSG2(_("E261: cscope connection %s not found"), stok); | |
407 | *************** | |
408 | *** 1597,1603 **** | |
409 | { | |
410 | if (i == -1) | |
411 | { | |
412 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
413 | { | |
414 | if (csinfo[i].fname) | |
415 | cs_kill_execute(i, csinfo[i].fname); | |
416 | --- 1600,1606 ---- | |
417 | { | |
418 | if (i == -1) | |
419 | { | |
420 | ! for (i = 0; i < csinfo_size; i++) | |
421 | { | |
422 | if (csinfo[i].fname) | |
423 | cs_kill_execute(i, csinfo[i].fname); | |
424 | *************** | |
425 | *** 1857,1863 **** | |
426 | if (buf == NULL) | |
427 | return; | |
428 | ||
429 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
430 | { | |
431 | if (nummatches_a[i] < 1) | |
432 | continue; | |
433 | --- 1860,1866 ---- | |
434 | if (buf == NULL) | |
435 | return; | |
436 | ||
437 | ! for (i = 0; i < csinfo_size; i++) | |
438 | { | |
439 | if (nummatches_a[i] < 1) | |
440 | continue; | |
441 | *************** | |
442 | *** 1929,1935 **** | |
443 | if ((cntxts = (char **)alloc(sizeof(char *) * totmatches)) == NULL) | |
444 | goto parse_out; | |
445 | ||
446 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
447 | { | |
448 | if (nummatches_a[i] < 1) | |
449 | continue; | |
450 | --- 1932,1938 ---- | |
451 | if ((cntxts = (char **)alloc(sizeof(char *) * totmatches)) == NULL) | |
452 | goto parse_out; | |
453 | ||
454 | ! for (i = 0; i < csinfo_size; i++) | |
455 | { | |
456 | if (nummatches_a[i] < 1) | |
457 | continue; | |
458 | *************** | |
459 | *** 2383,2392 **** | |
460 | int i; | |
461 | char buf[20]; /* for sprintf " (#%d)" */ | |
462 | ||
463 | /* malloc our db and ppath list */ | |
464 | ! dblist = (char **)alloc(CSCOPE_MAX_CONNECTIONS * sizeof(char *)); | |
465 | ! pplist = (char **)alloc(CSCOPE_MAX_CONNECTIONS * sizeof(char *)); | |
466 | ! fllist = (char **)alloc(CSCOPE_MAX_CONNECTIONS * sizeof(char *)); | |
467 | if (dblist == NULL || pplist == NULL || fllist == NULL) | |
468 | { | |
469 | vim_free(dblist); | |
470 | --- 2386,2398 ---- | |
471 | int i; | |
472 | char buf[20]; /* for sprintf " (#%d)" */ | |
473 | ||
474 | + if (csinfo_size == 0) | |
475 | + return CSCOPE_SUCCESS; | |
476 | + | |
477 | /* malloc our db and ppath list */ | |
478 | ! dblist = (char **)alloc(csinfo_size * sizeof(char *)); | |
479 | ! pplist = (char **)alloc(csinfo_size * sizeof(char *)); | |
480 | ! fllist = (char **)alloc(csinfo_size * sizeof(char *)); | |
481 | if (dblist == NULL || pplist == NULL || fllist == NULL) | |
482 | { | |
483 | vim_free(dblist); | |
484 | *************** | |
485 | *** 2395,2401 **** | |
486 | return CSCOPE_FAILURE; | |
487 | } | |
488 | ||
489 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
490 | { | |
491 | dblist[i] = csinfo[i].fname; | |
492 | pplist[i] = csinfo[i].ppath; | |
493 | --- 2401,2407 ---- | |
494 | return CSCOPE_FAILURE; | |
495 | } | |
496 | ||
497 | ! for (i = 0; i < csinfo_size; i++) | |
498 | { | |
499 | dblist[i] = csinfo[i].fname; | |
500 | pplist[i] = csinfo[i].ppath; | |
501 | *************** | |
502 | *** 2405,2411 **** | |
503 | } | |
504 | ||
505 | /* rebuild the cscope connection list */ | |
506 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
507 | { | |
508 | if (dblist[i] != NULL) | |
509 | { | |
510 | --- 2411,2417 ---- | |
511 | } | |
512 | ||
513 | /* rebuild the cscope connection list */ | |
514 | ! for (i = 0; i < csinfo_size; i++) | |
515 | { | |
516 | if (dblist[i] != NULL) | |
517 | { | |
518 | *************** | |
519 | *** 2502,2508 **** | |
520 | MSG_PUTS_ATTR( | |
521 | _(" # pid database name prepend path\n"), | |
522 | hl_attr(HLF_T)); | |
523 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
524 | { | |
525 | if (csinfo[i].fname == NULL) | |
526 | continue; | |
527 | --- 2508,2514 ---- | |
528 | MSG_PUTS_ATTR( | |
529 | _(" # pid database name prepend path\n"), | |
530 | hl_attr(HLF_T)); | |
531 | ! for (i = 0; i < csinfo_size; i++) | |
532 | { | |
533 | if (csinfo[i].fname == NULL) | |
534 | continue; | |
535 | *************** | |
536 | *** 2531,2538 **** | |
537 | { | |
538 | int i; | |
539 | ||
540 | ! for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++) | |
541 | cs_release_csp(i, TRUE); | |
542 | } | |
543 | ||
544 | #endif /* FEAT_CSCOPE */ | |
545 | --- 2537,2546 ---- | |
546 | { | |
547 | int i; | |
548 | ||
549 | ! for (i = 0; i < csinfo_size; i++) | |
550 | cs_release_csp(i, TRUE); | |
551 | + vim_free(csinfo); | |
552 | + csinfo_size = 0; | |
553 | } | |
554 | ||
555 | #endif /* FEAT_CSCOPE */ | |
556 | *** ../vim-7.2.227/src/version.c 2009-07-09 20:13:59.000000000 +0200 | |
557 | --- src/version.c 2009-07-09 21:21:48.000000000 +0200 | |
558 | *************** | |
559 | *** 678,679 **** | |
560 | --- 678,681 ---- | |
561 | { /* Add new patch number below this line */ | |
562 | + /**/ | |
563 | + 228, | |
564 | /**/ | |
565 | ||
566 | -- | |
567 | hundred-and-one symptoms of being an internet addict: | |
568 | 84. Books in your bookcase bear the names Bongo, WinSock and Inside OLE | |
569 | ||
570 | /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ | |
571 | /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ | |
572 | \\\ download, build and distribute -- http://www.A-A-P.org /// | |
573 | \\\ help me help AIDS victims -- http://ICCF-Holland.org /// |