Snapshot 44
[MacVim.git] / src / if_cscope.c
blob2407ad03e34ed1760aea35b55d90f8f8b2efd709
1 /* vi:set ts=8 sts=4 sw=4:
3 * CSCOPE support for Vim added by Andy Kahn <kahn@zk3.dec.com>
4 * Ported to Win32 by Sergey Khorev <sergey.khorev@gmail.com>
6 * The basic idea/structure of cscope for Vim was borrowed from Nvi. There
7 * might be a few lines of code that look similar to what Nvi has.
9 * See README.txt for an overview of the Vim source code.
12 #include "vim.h"
14 #if defined(FEAT_CSCOPE) || defined(PROTO)
16 #include <string.h>
17 #include <errno.h>
18 #include <assert.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #if defined(UNIX)
22 # include <sys/wait.h>
23 #else
24 /* not UNIX, must be WIN32 */
25 # include "vimio.h"
26 #endif
27 #include "if_cscope.h"
29 static void cs_usage_msg __ARGS((csid_e x));
30 static int cs_add __ARGS((exarg_T *eap));
31 static void cs_stat_emsg __ARGS((char *fname));
32 static int cs_add_common __ARGS((char *, char *, char *));
33 static int cs_check_for_connections __ARGS((void));
34 static int cs_check_for_tags __ARGS((void));
35 static int cs_cnt_connections __ARGS((void));
36 static void cs_reading_emsg __ARGS((int idx));
37 static int cs_cnt_matches __ARGS((int idx));
38 static char * cs_create_cmd __ARGS((char *csoption, char *pattern));
39 static int cs_create_connection __ARGS((int i));
40 static void do_cscope_general __ARGS((exarg_T *eap, int make_split));
41 #ifdef FEAT_QUICKFIX
42 static void cs_file_results __ARGS((FILE *, int *));
43 #endif
44 static void cs_fill_results __ARGS((char *, int , int *, char ***,
45 char ***, int *));
46 static int cs_find __ARGS((exarg_T *eap));
47 static int cs_find_common __ARGS((char *opt, char *pat, int, int, int));
48 static int cs_help __ARGS((exarg_T *eap));
49 static void cs_init __ARGS((void));
50 static void clear_csinfo __ARGS((int i));
51 static int cs_insert_filelist __ARGS((char *, char *, char *,
52 struct stat *));
53 static int cs_kill __ARGS((exarg_T *eap));
54 static void cs_kill_execute __ARGS((int, char *));
55 static cscmd_T * cs_lookup_cmd __ARGS((exarg_T *eap));
56 static char * cs_make_vim_style_matches __ARGS((char *, char *,
57 char *, char *));
58 static char * cs_manage_matches __ARGS((char **, char **, int, mcmd_e));
59 static char * cs_parse_results __ARGS((int cnumber, char *buf, int bufsize, char **context, char **linenumber, char **search));
60 static char * cs_pathcomponents __ARGS((char *path));
61 static void cs_print_tags_priv __ARGS((char **, char **, int));
62 static int cs_read_prompt __ARGS((int));
63 static void cs_release_csp __ARGS((int, int freefnpp));
64 static int cs_reset __ARGS((exarg_T *eap));
65 static char * cs_resolve_file __ARGS((int, char *));
66 static int cs_show __ARGS((exarg_T *eap));
69 static csinfo_T csinfo[CSCOPE_MAX_CONNECTIONS];
70 static int eap_arg_len; /* length of eap->arg, set in
71 cs_lookup_cmd() */
72 static cscmd_T cs_cmds[] =
74 { "add", cs_add,
75 N_("Add a new database"), "add file|dir [pre-path] [flags]", 0 },
76 { "find", cs_find,
77 N_("Query for a pattern"), "find c|d|e|f|g|i|s|t name", 1 },
78 { "help", cs_help,
79 N_("Show this message"), "help", 0 },
80 { "kill", cs_kill,
81 N_("Kill a connection"), "kill #", 0 },
82 { "reset", cs_reset,
83 N_("Reinit all connections"), "reset", 0 },
84 { "show", cs_show,
85 N_("Show connections"), "show", 0 },
86 { NULL }
89 static void
90 cs_usage_msg(x)
91 csid_e x;
93 (void)EMSG2(_("E560: Usage: cs[cope] %s"), cs_cmds[(int)x].usage);
96 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
98 static enum
100 EXP_CSCOPE_SUBCMD, /* expand ":cscope" sub-commands */
101 EXP_CSCOPE_FIND, /* expand ":cscope find" arguments */
102 EXP_CSCOPE_KILL /* expand ":cscope kill" arguments */
103 } expand_what;
106 * Function given to ExpandGeneric() to obtain the cscope command
107 * expansion.
109 /*ARGSUSED*/
110 char_u *
111 get_cscope_name(xp, idx)
112 expand_T *xp;
113 int idx;
115 switch (expand_what)
117 case EXP_CSCOPE_SUBCMD:
118 /* Complete with sub-commands of ":cscope":
119 * add, find, help, kill, reset, show */
120 return (char_u *)cs_cmds[idx].name;
121 case EXP_CSCOPE_FIND:
123 const char *query_type[] =
125 "c", "d", "e", "f", "g", "i", "s", "t", NULL
128 /* Complete with query type of ":cscope find {query_type}".
129 * {query_type} can be letters (c, d, ... t) or numbers (0, 1,
130 * ..., 8) but only complete with letters, since numbers are
131 * redundant. */
132 return (char_u *)query_type[idx];
134 case EXP_CSCOPE_KILL:
136 int i;
137 int current_idx = 0;
138 static char_u connection[2];
140 /* ":cscope kill" accepts connection numbers or partial names of
141 * the pathname of the cscope database as argument. Only complete
142 * with connection numbers. -1 can also be used to kill all
143 * connections. */
144 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
146 if (csinfo[i].fname == NULL)
147 continue;
148 if (current_idx++ == idx)
150 /* Connection number fits in one character since
151 * CSCOPE_MAX_CONNECTIONS is < 10 */
152 connection[0] = i + '0';
153 connection[1] = NUL;
154 return connection;
157 return (current_idx == idx && idx > 0) ? (char_u *)"-1" : NULL;
159 default:
160 return NULL;
165 * Handle command line completion for :cscope command.
167 void
168 set_context_in_cscope_cmd(xp, arg)
169 expand_T *xp;
170 char_u *arg;
172 char_u *p;
174 /* Default: expand subcommands */
175 xp->xp_context = EXPAND_CSCOPE;
176 expand_what = EXP_CSCOPE_SUBCMD;
177 xp->xp_pattern = arg;
179 /* (part of) subcommand already typed */
180 if (*arg != NUL)
182 p = skiptowhite(arg);
183 if (*p != NUL) /* past first word */
185 xp->xp_pattern = skipwhite(p);
186 if (*skiptowhite(xp->xp_pattern) != NUL)
187 xp->xp_context = EXPAND_NOTHING;
188 else if (STRNICMP(arg, "add", p - arg) == 0)
189 xp->xp_context = EXPAND_FILES;
190 else if (STRNICMP(arg, "kill", p - arg) == 0)
191 expand_what = EXP_CSCOPE_KILL;
192 else if (STRNICMP(arg, "find", p - arg) == 0)
193 expand_what = EXP_CSCOPE_FIND;
194 else
195 xp->xp_context = EXPAND_NOTHING;
200 #endif /* FEAT_CMDL_COMPL */
203 * PRIVATE: do_cscope_general
205 * Find the command, print help if invalid, and then call the corresponding
206 * command function.
208 static void
209 do_cscope_general(eap, make_split)
210 exarg_T *eap;
211 int make_split; /* whether to split window */
213 cscmd_T *cmdp;
215 cs_init();
216 if ((cmdp = cs_lookup_cmd(eap)) == NULL)
218 cs_help(eap);
219 return;
222 #ifdef FEAT_WINDOWS
223 if (make_split)
225 if (!cmdp->cansplit)
227 (void)MSG_PUTS(_("This cscope command does not support splitting the window.\n"));
228 return;
230 postponed_split = -1;
231 postponed_split_flags = cmdmod.split;
232 postponed_split_tab = cmdmod.tab;
234 #endif
236 cmdp->func(eap);
238 #ifdef FEAT_WINDOWS
239 postponed_split_flags = 0;
240 postponed_split_tab = 0;
241 #endif
245 * PUBLIC: do_cscope
247 void
248 do_cscope(eap)
249 exarg_T *eap;
251 do_cscope_general(eap, FALSE);
255 * PUBLIC: do_scscope
257 * same as do_cscope, but splits window, too.
259 void
260 do_scscope(eap)
261 exarg_T *eap;
263 do_cscope_general(eap, TRUE);
267 * PUBLIC: do_cstag
270 void
271 do_cstag(eap)
272 exarg_T *eap;
274 int ret = FALSE;
276 cs_init();
278 if (*eap->arg == NUL)
280 (void)EMSG(_("E562: Usage: cstag <ident>"));
281 return;
284 switch (p_csto)
286 case 0 :
287 if (cs_check_for_connections())
289 ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE,
290 FALSE);
291 if (ret == FALSE)
293 cs_free_tags();
294 if (msg_col)
295 msg_putchar('\n');
297 if (cs_check_for_tags())
298 ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
301 else if (cs_check_for_tags())
303 ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
305 break;
306 case 1 :
307 if (cs_check_for_tags())
309 ret = do_tag(eap->arg, DT_JUMP, 0, eap->forceit, FALSE);
310 if (ret == FALSE)
312 if (msg_col)
313 msg_putchar('\n');
315 if (cs_check_for_connections())
317 ret = cs_find_common("g", (char *)(eap->arg), eap->forceit,
318 FALSE, FALSE);
319 if (ret == FALSE)
320 cs_free_tags();
324 else if (cs_check_for_connections())
326 ret = cs_find_common("g", (char *)(eap->arg), eap->forceit, FALSE,
327 FALSE);
328 if (ret == FALSE)
329 cs_free_tags();
331 break;
332 default :
333 break;
336 if (!ret)
338 (void)EMSG(_("E257: cstag: tag not found"));
339 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
340 g_do_tagpreview = 0;
341 #endif
344 } /* do_cscope */
348 * PUBLIC: cs_find
350 * this simulates a vim_fgets(), but for cscope, returns the next line
351 * from the cscope output. should only be called from find_tags()
353 * returns TRUE if eof, FALSE otherwise
356 cs_fgets(buf, size)
357 char_u *buf;
358 int size;
360 char *p;
362 if ((p = cs_manage_matches(NULL, NULL, -1, Get)) == NULL)
363 return TRUE;
364 vim_strncpy(buf, (char_u *)p, size - 1);
366 return FALSE;
367 } /* cs_fgets */
371 * PUBLIC: cs_free_tags
373 * called only from do_tag(), when popping the tag stack
375 void
376 cs_free_tags()
378 cs_manage_matches(NULL, NULL, -1, Free);
383 * PUBLIC: cs_print_tags
385 * called from do_tag()
387 void
388 cs_print_tags()
390 cs_manage_matches(NULL, NULL, -1, Print);
395 * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function
397 * Checks for the existence of a |cscope| connection. If no
398 * parameters are specified, then the function returns:
400 * 0, if cscope was not available (not compiled in), or if there
401 * are no cscope connections; or
402 * 1, if there is at least one cscope connection.
404 * If parameters are specified, then the value of {num}
405 * determines how existence of a cscope connection is checked:
407 * {num} Description of existence check
408 * ----- ------------------------------
409 * 0 Same as no parameters (e.g., "cscope_connection()").
410 * 1 Ignore {prepend}, and use partial string matches for
411 * {dbpath}.
412 * 2 Ignore {prepend}, and use exact string matches for
413 * {dbpath}.
414 * 3 Use {prepend}, use partial string matches for both
415 * {dbpath} and {prepend}.
416 * 4 Use {prepend}, use exact string matches for both
417 * {dbpath} and {prepend}.
419 * Note: All string comparisons are case sensitive!
421 #if defined(FEAT_EVAL) || defined(PROTO)
423 cs_connection(num, dbpath, ppath)
424 int num;
425 char_u *dbpath;
426 char_u *ppath;
428 int i;
430 if (num < 0 || num > 4 || (num > 0 && !dbpath))
431 return FALSE;
433 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
435 if (!csinfo[i].fname)
436 continue;
438 if (num == 0)
439 return TRUE;
441 switch (num)
443 case 1:
444 if (strstr(csinfo[i].fname, (char *)dbpath))
445 return TRUE;
446 break;
447 case 2:
448 if (strcmp(csinfo[i].fname, (char *)dbpath) == 0)
449 return TRUE;
450 break;
451 case 3:
452 if (strstr(csinfo[i].fname, (char *)dbpath)
453 && ((!ppath && !csinfo[i].ppath)
454 || (ppath
455 && csinfo[i].ppath
456 && strstr(csinfo[i].ppath, (char *)ppath))))
457 return TRUE;
458 break;
459 case 4:
460 if ((strcmp(csinfo[i].fname, (char *)dbpath) == 0)
461 && ((!ppath && !csinfo[i].ppath)
462 || (ppath
463 && csinfo[i].ppath
464 && (strcmp(csinfo[i].ppath, (char *)ppath) == 0))))
465 return TRUE;
466 break;
470 return FALSE;
471 } /* cs_connection */
472 #endif
476 * PRIVATE functions
477 ****************************************************************************/
480 * PRIVATE: cs_add
482 * add cscope database or a directory name (to look for cscope.out)
483 * to the cscope connection list
485 * MAXPATHL 256
487 /* ARGSUSED */
488 static int
489 cs_add(eap)
490 exarg_T *eap;
492 char *fname, *ppath, *flags = NULL;
494 if ((fname = strtok((char *)NULL, (const char *)" ")) == NULL)
496 cs_usage_msg(Add);
497 return CSCOPE_FAILURE;
499 if ((ppath = strtok((char *)NULL, (const char *)" ")) != NULL)
500 flags = strtok((char *)NULL, (const char *)" ");
502 return cs_add_common(fname, ppath, flags);
505 static void
506 cs_stat_emsg(fname)
507 char *fname;
509 char *stat_emsg = _("E563: stat(%s) error: %d");
510 char *buf = (char *)alloc((unsigned)strlen(stat_emsg) + MAXPATHL + 10);
512 if (buf != NULL)
514 (void)sprintf(buf, stat_emsg, fname, errno);
515 (void)EMSG(buf);
516 vim_free(buf);
518 else
519 (void)EMSG(_("E563: stat error"));
524 * PRIVATE: cs_add_common
526 * the common routine to add a new cscope connection. called by
527 * cs_add() and cs_reset(). i really don't like to do this, but this
528 * routine uses a number of goto statements.
530 static int
531 cs_add_common(arg1, arg2, flags)
532 char *arg1; /* filename - may contain environment variables */
533 char *arg2; /* prepend path - may contain environment variables */
534 char *flags;
536 struct stat statbuf;
537 int ret;
538 char *fname = NULL;
539 char *fname2 = NULL;
540 char *ppath = NULL;
541 int i;
543 /* get the filename (arg1), expand it, and try to stat it */
544 if ((fname = (char *)alloc(MAXPATHL + 1)) == NULL)
545 goto add_err;
547 expand_env((char_u *)arg1, (char_u *)fname, MAXPATHL);
548 ret = stat(fname, &statbuf);
549 if (ret < 0)
551 staterr:
552 if (p_csverbose)
553 cs_stat_emsg(fname);
554 goto add_err;
557 /* get the prepend path (arg2), expand it, and try to stat it */
558 if (arg2 != NULL)
560 struct stat statbuf2;
562 if ((ppath = (char *)alloc(MAXPATHL + 1)) == NULL)
563 goto add_err;
565 expand_env((char_u *)arg2, (char_u *)ppath, MAXPATHL);
566 ret = stat(ppath, &statbuf2);
567 if (ret < 0)
568 goto staterr;
571 /* if filename is a directory, append the cscope database name to it */
572 if ((statbuf.st_mode & S_IFMT) == S_IFDIR)
574 fname2 = (char *)alloc((unsigned)(strlen(CSCOPE_DBFILE) + strlen(fname) + 2));
575 if (fname2 == NULL)
576 goto add_err;
578 while (fname[strlen(fname)-1] == '/'
579 #ifdef WIN32
580 || fname[strlen(fname)-1] == '\\'
581 #endif
584 fname[strlen(fname)-1] = '\0';
585 if (strlen(fname) == 0)
586 break;
588 if (fname[0] == '\0')
589 (void)sprintf(fname2, "/%s", CSCOPE_DBFILE);
590 else
591 (void)sprintf(fname2, "%s/%s", fname, CSCOPE_DBFILE);
593 ret = stat(fname2, &statbuf);
594 if (ret < 0)
596 if (p_csverbose)
597 cs_stat_emsg(fname2);
598 goto add_err;
601 i = cs_insert_filelist(fname2, ppath, flags, &statbuf);
603 #if defined(UNIX)
604 else if (S_ISREG(statbuf.st_mode) || S_ISLNK(statbuf.st_mode))
605 #else
606 /* WIN32 - substitute define S_ISREG from os_unix.h */
607 else if (((statbuf.st_mode) & S_IFMT) == S_IFREG)
608 #endif
610 i = cs_insert_filelist(fname, ppath, flags, &statbuf);
612 else
614 if (p_csverbose)
615 (void)EMSG2(
616 _("E564: %s is not a directory or a valid cscope database"),
617 fname);
618 goto add_err;
621 if (i != -1)
623 if (cs_create_connection(i) == CSCOPE_FAILURE
624 || cs_read_prompt(i) == CSCOPE_FAILURE)
626 cs_release_csp(i, TRUE);
627 goto add_err;
630 if (p_csverbose)
632 msg_clr_eos();
633 (void)smsg_attr(hl_attr(HLF_R),
634 (char_u *)_("Added cscope database %s"),
635 csinfo[i].fname);
639 vim_free(fname);
640 vim_free(fname2);
641 vim_free(ppath);
642 return CSCOPE_SUCCESS;
644 add_err:
645 vim_free(fname2);
646 vim_free(fname);
647 vim_free(ppath);
648 return CSCOPE_FAILURE;
649 } /* cs_add_common */
652 static int
653 cs_check_for_connections()
655 return (cs_cnt_connections() > 0);
656 } /* cs_check_for_connections */
659 static int
660 cs_check_for_tags()
662 return (p_tags[0] != NUL && curbuf->b_p_tags != NULL);
663 } /* cs_check_for_tags */
667 * PRIVATE: cs_cnt_connections
669 * count the number of cscope connections
671 static int
672 cs_cnt_connections()
674 short i;
675 short cnt = 0;
677 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
679 if (csinfo[i].fname != NULL)
680 cnt++;
682 return cnt;
683 } /* cs_cnt_connections */
685 static void
686 cs_reading_emsg(idx)
687 int idx; /* connection index */
689 EMSGN(_("E262: error reading cscope connection %ld"), idx);
692 #define CSREAD_BUFSIZE 2048
694 * PRIVATE: cs_cnt_matches
696 * count the number of matches for a given cscope connection.
698 static int
699 cs_cnt_matches(idx)
700 int idx;
702 char *stok;
703 char *buf;
704 int nlines;
706 buf = (char *)alloc(CSREAD_BUFSIZE);
707 if (buf == NULL)
708 return 0;
709 for (;;)
711 if (!fgets(buf, CSREAD_BUFSIZE, csinfo[idx].fr_fp))
713 if (feof(csinfo[idx].fr_fp))
714 errno = EIO;
716 cs_reading_emsg(idx);
718 vim_free(buf);
719 return -1;
723 * If the database is out of date, or there's some other problem,
724 * cscope will output error messages before the number-of-lines output.
725 * Display/discard any output that doesn't match what we want.
726 * Accept "\S*cscope: X lines", also matches "mlcscope".
728 if ((stok = strtok(buf, (const char *)" ")) == NULL)
729 continue;
730 if (strstr((const char *)stok, "cscope:") == NULL)
731 continue;
733 if ((stok = strtok(NULL, (const char *)" ")) == NULL)
734 continue;
735 nlines = atoi(stok);
736 if (nlines < 0)
738 nlines = 0;
739 break;
742 if ((stok = strtok(NULL, (const char *)" ")) == NULL)
743 continue;
744 if (strncmp((const char *)stok, "lines", 5))
745 continue;
747 break;
750 vim_free(buf);
751 return nlines;
752 } /* cs_cnt_matches */
756 * PRIVATE: cs_create_cmd
758 * Creates the actual cscope command query from what the user entered.
760 static char *
761 cs_create_cmd(csoption, pattern)
762 char *csoption;
763 char *pattern;
765 char *cmd;
766 short search;
767 char *pat;
769 switch (csoption[0])
771 case '0' : case 's' :
772 search = 0;
773 break;
774 case '1' : case 'g' :
775 search = 1;
776 break;
777 case '2' : case 'd' :
778 search = 2;
779 break;
780 case '3' : case 'c' :
781 search = 3;
782 break;
783 case '4' : case 't' :
784 search = 4;
785 break;
786 case '6' : case 'e' :
787 search = 6;
788 break;
789 case '7' : case 'f' :
790 search = 7;
791 break;
792 case '8' : case 'i' :
793 search = 8;
794 break;
795 default :
796 (void)EMSG(_("E561: unknown cscope search type"));
797 cs_usage_msg(Find);
798 return NULL;
801 /* Skip white space before the patter, except for text and pattern search,
802 * they may want to use the leading white space. */
803 pat = pattern;
804 if (search != 4 && search != 6)
805 while vim_iswhite(*pat)
806 ++pat;
808 if ((cmd = (char *)alloc((unsigned)(strlen(pat) + 2))) == NULL)
809 return NULL;
811 (void)sprintf(cmd, "%d%s", search, pat);
813 return cmd;
814 } /* cs_create_cmd */
818 * PRIVATE: cs_create_connection
820 * This piece of code was taken/adapted from nvi. do we need to add
821 * the BSD license notice?
823 static int
824 cs_create_connection(i)
825 int i;
827 #ifdef UNIX
828 int to_cs[2], from_cs[2];
829 #endif
830 int len;
831 char *prog, *cmd, *ppath = NULL;
832 #ifdef WIN32
833 int fd;
834 SECURITY_ATTRIBUTES sa;
835 PROCESS_INFORMATION pi;
836 STARTUPINFO si;
837 BOOL pipe_stdin = FALSE, pipe_stdout = FALSE;
838 HANDLE stdin_rd, stdout_rd;
839 HANDLE stdout_wr, stdin_wr;
840 BOOL created;
841 # ifdef __BORLANDC__
842 # define OPEN_OH_ARGTYPE long
843 # else
844 # if (_MSC_VER >= 1300)
845 # define OPEN_OH_ARGTYPE intptr_t
846 # else
847 # define OPEN_OH_ARGTYPE long
848 # endif
849 # endif
850 #endif
852 #if defined(UNIX)
854 * Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from
855 * from_cs[0] and writes to to_cs[1].
857 to_cs[0] = to_cs[1] = from_cs[0] = from_cs[1] = -1;
858 if (pipe(to_cs) < 0 || pipe(from_cs) < 0)
860 (void)EMSG(_("E566: Could not create cscope pipes"));
861 err_closing:
862 if (to_cs[0] != -1)
863 (void)close(to_cs[0]);
864 if (to_cs[1] != -1)
865 (void)close(to_cs[1]);
866 if (from_cs[0] != -1)
867 (void)close(from_cs[0]);
868 if (from_cs[1] != -1)
869 (void)close(from_cs[1]);
870 return CSCOPE_FAILURE;
873 switch (csinfo[i].pid = fork())
875 case -1:
876 (void)EMSG(_("E622: Could not fork for cscope"));
877 goto err_closing;
878 case 0: /* child: run cscope. */
879 if (dup2(to_cs[0], STDIN_FILENO) == -1)
880 PERROR("cs_create_connection 1");
881 if (dup2(from_cs[1], STDOUT_FILENO) == -1)
882 PERROR("cs_create_connection 2");
883 if (dup2(from_cs[1], STDERR_FILENO) == -1)
884 PERROR("cs_create_connection 3");
886 /* close unused */
887 (void)close(to_cs[1]);
888 (void)close(from_cs[0]);
889 #else
890 /* WIN32 */
891 /* Create pipes to communicate with cscope */
892 sa.nLength = sizeof(SECURITY_ATTRIBUTES);
893 sa.bInheritHandle = TRUE;
894 sa.lpSecurityDescriptor = NULL;
896 if (!(pipe_stdin = CreatePipe(&stdin_rd, &stdin_wr, &sa, 0))
897 || !(pipe_stdout = CreatePipe(&stdout_rd, &stdout_wr, &sa, 0)))
899 (void)EMSG(_("E566: Could not create cscope pipes"));
900 err_closing:
901 if (pipe_stdin)
903 CloseHandle(stdin_rd);
904 CloseHandle(stdin_wr);
906 if (pipe_stdout)
908 CloseHandle(stdout_rd);
909 CloseHandle(stdout_wr);
911 return CSCOPE_FAILURE;
913 #endif
914 /* expand the cscope exec for env var's */
915 if ((prog = (char *)alloc(MAXPATHL + 1)) == NULL)
917 #ifdef UNIX
918 return CSCOPE_FAILURE;
919 #else
920 /* WIN32 */
921 goto err_closing;
922 #endif
924 expand_env((char_u *)p_csprg, (char_u *)prog, MAXPATHL);
926 /* alloc space to hold the cscope command */
927 len = (int)(strlen(prog) + strlen(csinfo[i].fname) + 32);
928 if (csinfo[i].ppath)
930 /* expand the prepend path for env var's */
931 if ((ppath = (char *)alloc(MAXPATHL + 1)) == NULL)
933 vim_free(prog);
934 #ifdef UNIX
935 return CSCOPE_FAILURE;
936 #else
937 /* WIN32 */
938 goto err_closing;
939 #endif
941 expand_env((char_u *)csinfo[i].ppath, (char_u *)ppath, MAXPATHL);
943 len += (int)strlen(ppath);
946 if (csinfo[i].flags)
947 len += (int)strlen(csinfo[i].flags);
949 if ((cmd = (char *)alloc(len)) == NULL)
951 vim_free(prog);
952 vim_free(ppath);
953 #ifdef UNIX
954 return CSCOPE_FAILURE;
955 #else
956 /* WIN32 */
957 goto err_closing;
958 #endif
961 /* run the cscope command; is there execl for non-unix systems? */
962 #if defined(UNIX)
963 (void)sprintf(cmd, "exec %s -dl -f %s", prog, csinfo[i].fname);
964 #else
965 /* WIN32 */
966 (void)sprintf(cmd, "%s -dl -f %s", prog, csinfo[i].fname);
967 #endif
968 if (csinfo[i].ppath != NULL)
970 (void)strcat(cmd, " -P");
971 (void)strcat(cmd, csinfo[i].ppath);
973 if (csinfo[i].flags != NULL)
975 (void)strcat(cmd, " ");
976 (void)strcat(cmd, csinfo[i].flags);
978 # ifdef UNIX
979 /* on Win32 we still need prog */
980 vim_free(prog);
981 # endif
982 vim_free(ppath);
984 #if defined(UNIX)
985 if (execl("/bin/sh", "sh", "-c", cmd, NULL) == -1)
986 PERROR(_("cs_create_connection exec failed"));
988 exit(127);
989 /* NOTREACHED */
990 default: /* parent. */
992 * Save the file descriptors for later duplication, and
993 * reopen as streams.
995 if ((csinfo[i].to_fp = fdopen(to_cs[1], "w")) == NULL)
996 PERROR(_("cs_create_connection: fdopen for to_fp failed"));
997 if ((csinfo[i].fr_fp = fdopen(from_cs[0], "r")) == NULL)
998 PERROR(_("cs_create_connection: fdopen for fr_fp failed"));
1000 /* close unused */
1001 (void)close(to_cs[0]);
1002 (void)close(from_cs[1]);
1004 break;
1007 #else
1008 /* WIN32 */
1009 /* Create a new process to run cscope and use pipes to talk with it */
1010 GetStartupInfo(&si);
1011 si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
1012 si.wShowWindow = SW_HIDE; /* Hide child application window */
1013 si.hStdOutput = stdout_wr;
1014 si.hStdError = stdout_wr;
1015 si.hStdInput = stdin_rd;
1016 created = CreateProcess(NULL, cmd, NULL, NULL, TRUE, CREATE_NEW_CONSOLE,
1017 NULL, NULL, &si, &pi);
1018 vim_free(prog);
1019 vim_free(cmd);
1021 if (!created)
1023 PERROR(_("cs_create_connection exec failed"));
1024 (void)EMSG(_("E623: Could not spawn cscope process"));
1025 goto err_closing;
1027 /* else */
1028 csinfo[i].pid = pi.dwProcessId;
1029 csinfo[i].hProc = pi.hProcess;
1030 CloseHandle(pi.hThread);
1032 /* TODO - tidy up after failure to create files on pipe handles. */
1033 if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdin_wr,
1034 _O_TEXT|_O_APPEND)) < 0)
1035 || ((csinfo[i].to_fp = _fdopen(fd, "w")) == NULL))
1036 PERROR(_("cs_create_connection: fdopen for to_fp failed"));
1037 if (((fd = _open_osfhandle((OPEN_OH_ARGTYPE)stdout_rd,
1038 _O_TEXT|_O_RDONLY)) < 0)
1039 || ((csinfo[i].fr_fp = _fdopen(fd, "r")) == NULL))
1040 PERROR(_("cs_create_connection: fdopen for fr_fp failed"));
1042 /* Close handles for file descriptors inherited by the cscope process */
1043 CloseHandle(stdin_rd);
1044 CloseHandle(stdout_wr);
1046 #endif /* !UNIX */
1048 return CSCOPE_SUCCESS;
1049 } /* cs_create_connection */
1053 * PRIVATE: cs_find
1055 * query cscope using command line interface. parse the output and use tselect
1056 * to allow choices. like Nvi, creates a pipe to send to/from query/cscope.
1058 * returns TRUE if we jump to a tag or abort, FALSE if not.
1060 static int
1061 cs_find(eap)
1062 exarg_T *eap;
1064 char *opt, *pat;
1066 if (cs_check_for_connections() == FALSE)
1068 (void)EMSG(_("E567: no cscope connections"));
1069 return FALSE;
1072 if ((opt = strtok((char *)NULL, (const char *)" ")) == NULL)
1074 cs_usage_msg(Find);
1075 return FALSE;
1078 pat = opt + strlen(opt) + 1;
1079 if (pat >= (char *)eap->arg + eap_arg_len)
1081 cs_usage_msg(Find);
1082 return FALSE;
1085 return cs_find_common(opt, pat, eap->forceit, TRUE,
1086 eap->cmdidx == CMD_lcscope);
1087 } /* cs_find */
1091 * PRIVATE: cs_find_common
1093 * common code for cscope find, shared by cs_find() and do_cstag()
1095 static int
1096 cs_find_common(opt, pat, forceit, verbose, use_ll)
1097 char *opt;
1098 char *pat;
1099 int forceit;
1100 int verbose;
1101 int use_ll;
1103 int i;
1104 char *cmd;
1105 int nummatches[CSCOPE_MAX_CONNECTIONS], totmatches;
1106 #ifdef FEAT_QUICKFIX
1107 char cmdletter;
1108 char *qfpos;
1109 #endif
1111 /* create the actual command to send to cscope */
1112 cmd = cs_create_cmd(opt, pat);
1113 if (cmd == NULL)
1114 return FALSE;
1116 /* send query to all open connections, then count the total number
1117 * of matches so we can alloc matchesp all in one swell foop
1119 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
1120 nummatches[i] = 0;
1121 totmatches = 0;
1122 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
1124 if (csinfo[i].fname == NULL || csinfo[i].to_fp == NULL)
1125 continue;
1127 /* send cmd to cscope */
1128 (void)fprintf(csinfo[i].to_fp, "%s\n", cmd);
1129 (void)fflush(csinfo[i].to_fp);
1131 nummatches[i] = cs_cnt_matches(i);
1133 if (nummatches[i] > -1)
1134 totmatches += nummatches[i];
1136 if (nummatches[i] == 0)
1137 (void)cs_read_prompt(i);
1139 vim_free(cmd);
1141 if (totmatches == 0)
1143 char *nf = _("E259: no matches found for cscope query %s of %s");
1144 char *buf;
1146 if (!verbose)
1147 return FALSE;
1149 buf = (char *)alloc((unsigned)(strlen(opt) + strlen(pat) + strlen(nf)));
1150 if (buf == NULL)
1151 (void)EMSG(nf);
1152 else
1154 sprintf(buf, nf, opt, pat);
1155 (void)EMSG(buf);
1156 vim_free(buf);
1158 return FALSE;
1161 #ifdef FEAT_QUICKFIX
1162 /* get cmd letter */
1163 switch (opt[0])
1165 case '0' :
1166 cmdletter = 's';
1167 break;
1168 case '1' :
1169 cmdletter = 'g';
1170 break;
1171 case '2' :
1172 cmdletter = 'd';
1173 break;
1174 case '3' :
1175 cmdletter = 'c';
1176 break;
1177 case '4' :
1178 cmdletter = 't';
1179 break;
1180 case '6' :
1181 cmdletter = 'e';
1182 break;
1183 case '7' :
1184 cmdletter = 'f';
1185 break;
1186 case '8' :
1187 cmdletter = 'i';
1188 break;
1189 default :
1190 cmdletter = opt[0];
1193 qfpos = (char *)vim_strchr(p_csqf, cmdletter);
1194 if (qfpos != NULL)
1196 qfpos++;
1197 /* next symbol must be + or - */
1198 if (strchr(CSQF_FLAGS, *qfpos) == NULL)
1200 char *nf = _("E469: invalid cscopequickfix flag %c for %c");
1201 char *buf = (char *)alloc((unsigned)strlen(nf));
1203 /* strlen will be enough because we use chars */
1204 if (buf != NULL)
1206 sprintf(buf, nf, *qfpos, *(qfpos-1));
1207 (void)EMSG(buf);
1208 vim_free(buf);
1210 return FALSE;
1213 if (qfpos != NULL && *qfpos != '0' && totmatches > 0)
1215 /* fill error list */
1216 FILE *f;
1217 char_u *tmp = vim_tempname('c');
1218 qf_info_T *qi = NULL;
1219 win_T *wp = NULL;
1221 f = mch_fopen((char *)tmp, "w");
1222 if (f == NULL)
1223 EMSG2(_(e_notopen), tmp);
1224 else
1226 cs_file_results(f, nummatches);
1227 fclose(f);
1228 if (use_ll) /* Use location list */
1229 wp = curwin;
1230 /* '-' starts a new error list */
1231 if (qf_init(wp, tmp, (char_u *)"%f%*\\t%l%*\\t%m",
1232 *qfpos == '-') > 0)
1234 # ifdef FEAT_WINDOWS
1235 if (postponed_split != 0)
1237 win_split(postponed_split > 0 ? postponed_split : 0,
1238 postponed_split_flags);
1239 # ifdef FEAT_SCROLLBIND
1240 curwin->w_p_scb = FALSE;
1241 # endif
1242 postponed_split = 0;
1244 # endif
1245 if (use_ll)
1247 * In the location list window, use the displayed location
1248 * list. Otherwise, use the location list for the window.
1250 qi = (bt_quickfix(wp->w_buffer) && wp->w_llist_ref != NULL)
1251 ? wp->w_llist_ref : wp->w_llist;
1252 qf_jump(qi, 0, 0, forceit);
1255 mch_remove(tmp);
1256 vim_free(tmp);
1257 return TRUE;
1259 else
1260 #endif /* FEAT_QUICKFIX */
1262 char **matches = NULL, **contexts = NULL;
1263 int matched = 0;
1265 /* read output */
1266 cs_fill_results((char *)pat, totmatches, nummatches, &matches,
1267 &contexts, &matched);
1268 if (matches == NULL)
1269 return FALSE;
1271 (void)cs_manage_matches(matches, contexts, matched, Store);
1273 return do_tag((char_u *)pat, DT_CSCOPE, 0, forceit, verbose);
1276 } /* cs_find_common */
1279 * PRIVATE: cs_help
1281 * print help
1283 /* ARGSUSED */
1284 static int
1285 cs_help(eap)
1286 exarg_T *eap;
1288 cscmd_T *cmdp = cs_cmds;
1290 (void)MSG_PUTS(_("cscope commands:\n"));
1291 while (cmdp->name != NULL)
1293 char *help = _(cmdp->help);
1294 int space_cnt = 30 - vim_strsize((char_u *)help);
1296 /* Use %*s rather than %30s to ensure proper alignment in utf-8 */
1297 if (space_cnt < 0)
1298 space_cnt = 0;
1299 (void)smsg((char_u *)_("%-5s: %s%*s (Usage: %s)"),
1300 cmdp->name,
1301 help, space_cnt, " ",
1302 cmdp->usage);
1303 if (strcmp(cmdp->name, "find") == 0)
1304 MSG_PUTS(_("\n"
1305 " c: Find functions calling this function\n"
1306 " d: Find functions called by this function\n"
1307 " e: Find this egrep pattern\n"
1308 " f: Find this file\n"
1309 " g: Find this definition\n"
1310 " i: Find files #including this file\n"
1311 " s: Find this C symbol\n"
1312 " t: Find assignments to\n"));
1314 cmdp++;
1317 wait_return(TRUE);
1318 return 0;
1319 } /* cs_help */
1323 * PRIVATE: cs_init
1325 * initialize cscope structure if not already
1327 static void
1328 cs_init()
1330 short i;
1331 static int init_already = FALSE;
1333 if (init_already)
1334 return;
1336 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
1337 clear_csinfo(i);
1339 init_already = TRUE;
1340 } /* cs_init */
1342 static void
1343 clear_csinfo(i)
1344 int i;
1346 csinfo[i].fname = NULL;
1347 csinfo[i].ppath = NULL;
1348 csinfo[i].flags = NULL;
1349 #if defined(UNIX)
1350 csinfo[i].st_dev = (dev_t)0;
1351 csinfo[i].st_ino = (ino_t)0;
1352 #else
1353 csinfo[i].nVolume = 0;
1354 csinfo[i].nIndexHigh = 0;
1355 csinfo[i].nIndexLow = 0;
1356 #endif
1357 csinfo[i].pid = 0;
1358 csinfo[i].fr_fp = NULL;
1359 csinfo[i].to_fp = NULL;
1360 #if defined(WIN32)
1361 csinfo[i].hProc = NULL;
1362 #endif
1365 #ifndef UNIX
1366 static char *GetWin32Error __ARGS((void));
1368 static char *
1369 GetWin32Error()
1371 char *msg = NULL;
1372 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,
1373 NULL, GetLastError(), 0, (LPSTR)&msg, 0, NULL);
1374 if (msg != NULL)
1376 /* remove trailing \r\n */
1377 char *pcrlf = strstr(msg, "\r\n");
1378 if (pcrlf != NULL)
1379 *pcrlf = '\0';
1381 return msg;
1383 #endif
1386 * PRIVATE: cs_insert_filelist
1388 * insert a new cscope database filename into the filelist
1390 /*ARGSUSED*/
1391 static int
1392 cs_insert_filelist(fname, ppath, flags, sb)
1393 char *fname;
1394 char *ppath;
1395 char *flags;
1396 struct stat *sb;
1398 short i, j;
1399 #ifndef UNIX
1400 HANDLE hFile;
1401 BY_HANDLE_FILE_INFORMATION bhfi;
1403 vim_memset(&bhfi, 0, sizeof(bhfi));
1404 /* On windows 9x GetFileInformationByHandle doesn't work, so skip it */
1405 if (!mch_windows95())
1407 hFile = CreateFile(fname, FILE_READ_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
1408 FILE_ATTRIBUTE_NORMAL, NULL);
1409 if (hFile == INVALID_HANDLE_VALUE)
1411 if (p_csverbose)
1413 char *cant_msg = _("E625: cannot open cscope database: %s");
1414 char *winmsg = GetWin32Error();
1416 if (winmsg != NULL)
1418 (void)EMSG2(cant_msg, winmsg);
1419 LocalFree(winmsg);
1421 else
1422 /* subst filename if can't get error text */
1423 (void)EMSG2(cant_msg, fname);
1425 return -1;
1427 if (!GetFileInformationByHandle(hFile, &bhfi))
1429 CloseHandle(hFile);
1430 if (p_csverbose)
1431 (void)EMSG(_("E626: cannot get cscope database information"));
1432 return -1;
1434 CloseHandle(hFile);
1436 #endif
1438 i = -1; /* can be set to the index of an empty item in csinfo */
1439 for (j = 0; j < CSCOPE_MAX_CONNECTIONS; j++)
1441 if (csinfo[j].fname != NULL
1442 #if defined(UNIX)
1443 && csinfo[j].st_dev == sb->st_dev && csinfo[j].st_ino == sb->st_ino
1444 #else
1445 /* compare pathnames first */
1446 && ((fullpathcmp(csinfo[j].fname, fname, FALSE) & FPC_SAME)
1447 /* if not Windows 9x, test index file attributes too */
1448 || (!mch_windows95()
1449 && csinfo[j].nVolume == bhfi.dwVolumeSerialNumber
1450 && csinfo[j].nIndexHigh == bhfi.nFileIndexHigh
1451 && csinfo[j].nIndexLow == bhfi.nFileIndexLow))
1452 #endif
1455 if (p_csverbose)
1456 (void)EMSG(_("E568: duplicate cscope database not added"));
1457 return -1;
1460 if (csinfo[j].fname == NULL && i == -1)
1461 i = j; /* remember first empty entry */
1464 if (i == -1)
1466 if (p_csverbose)
1467 (void)EMSG(_("E569: maximum number of cscope connections reached"));
1468 return -1;
1471 if ((csinfo[i].fname = (char *)alloc((unsigned)strlen(fname)+1)) == NULL)
1472 return -1;
1474 (void)strcpy(csinfo[i].fname, (const char *)fname);
1476 if (ppath != NULL)
1478 if ((csinfo[i].ppath = (char *)alloc((unsigned)strlen(ppath) + 1)) == NULL)
1480 vim_free(csinfo[i].fname);
1481 csinfo[i].fname = NULL;
1482 return -1;
1484 (void)strcpy(csinfo[i].ppath, (const char *)ppath);
1485 } else
1486 csinfo[i].ppath = NULL;
1488 if (flags != NULL)
1490 if ((csinfo[i].flags = (char *)alloc((unsigned)strlen(flags) + 1)) == NULL)
1492 vim_free(csinfo[i].fname);
1493 vim_free(csinfo[i].ppath);
1494 csinfo[i].fname = NULL;
1495 csinfo[i].ppath = NULL;
1496 return -1;
1498 (void)strcpy(csinfo[i].flags, (const char *)flags);
1499 } else
1500 csinfo[i].flags = NULL;
1502 #if defined(UNIX)
1503 csinfo[i].st_dev = sb->st_dev;
1504 csinfo[i].st_ino = sb->st_ino;
1506 #else
1507 csinfo[i].nVolume = bhfi.dwVolumeSerialNumber;
1508 csinfo[i].nIndexLow = bhfi.nFileIndexLow;
1509 csinfo[i].nIndexHigh = bhfi.nFileIndexHigh;
1510 #endif
1511 return i;
1512 } /* cs_insert_filelist */
1516 * PRIVATE: cs_lookup_cmd
1518 * find cscope command in command table
1520 static cscmd_T *
1521 cs_lookup_cmd(eap)
1522 exarg_T *eap;
1524 cscmd_T *cmdp;
1525 char *stok;
1526 size_t len;
1528 if (eap->arg == NULL)
1529 return NULL;
1531 /* Store length of eap->arg before it gets modified by strtok(). */
1532 eap_arg_len = (int)STRLEN(eap->arg);
1534 if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL)
1535 return NULL;
1537 len = strlen(stok);
1538 for (cmdp = cs_cmds; cmdp->name != NULL; ++cmdp)
1540 if (strncmp((const char *)(stok), cmdp->name, len) == 0)
1541 return (cmdp);
1543 return NULL;
1544 } /* cs_lookup_cmd */
1548 * PRIVATE: cs_kill
1550 * nuke em
1552 /* ARGSUSED */
1553 static int
1554 cs_kill(eap)
1555 exarg_T *eap;
1557 char *stok;
1558 short i;
1560 if ((stok = strtok((char *)NULL, (const char *)" ")) == NULL)
1562 cs_usage_msg(Kill);
1563 return CSCOPE_FAILURE;
1566 /* only single digit positive and negative integers are allowed */
1567 if ((strlen(stok) < 2 && VIM_ISDIGIT((int)(stok[0])))
1568 || (strlen(stok) < 3 && stok[0] == '-'
1569 && VIM_ISDIGIT((int)(stok[1]))))
1570 i = atoi(stok);
1571 else
1573 /* It must be part of a name. We will try to find a match
1574 * within all the names in the csinfo data structure
1576 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
1578 if (csinfo[i].fname != NULL && strstr(csinfo[i].fname, stok))
1579 break;
1583 if ((i >= CSCOPE_MAX_CONNECTIONS || i < -1 || csinfo[i].fname == NULL)
1584 && i != -1)
1586 if (p_csverbose)
1587 (void)EMSG2(_("E261: cscope connection %s not found"), stok);
1589 else
1591 if (i == -1)
1593 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
1595 if (csinfo[i].fname)
1596 cs_kill_execute(i, csinfo[i].fname);
1599 else
1600 cs_kill_execute(i, stok);
1603 return 0;
1604 } /* cs_kill */
1608 * PRIVATE: cs_kill_execute
1610 * Actually kills a specific cscope connection.
1612 static void
1613 cs_kill_execute(i, cname)
1614 int i; /* cscope table index */
1615 char *cname; /* cscope database name */
1617 if (p_csverbose)
1619 msg_clr_eos();
1620 (void)smsg_attr(hl_attr(HLF_R) | MSG_HIST,
1621 (char_u *)_("cscope connection %s closed"), cname);
1623 cs_release_csp(i, TRUE);
1628 * PRIVATE: cs_make_vim_style_matches
1630 * convert the cscope output into into a ctags style entry (as might be found
1631 * in a ctags tags file). there's one catch though: cscope doesn't tell you
1632 * the type of the tag you are looking for. for example, in Darren Hiebert's
1633 * ctags (the one that comes with vim), #define's use a line number to find the
1634 * tag in a file while function definitions use a regexp search pattern.
1636 * i'm going to always use the line number because cscope does something
1637 * quirky (and probably other things i don't know about):
1639 * if you have "# define" in your source file, which is
1640 * perfectly legal, cscope thinks you have "#define". this
1641 * will result in a failed regexp search. :(
1643 * besides, even if this particular case didn't happen, the search pattern
1644 * would still have to be modified to escape all the special regular expression
1645 * characters to comply with ctags formatting.
1647 static char *
1648 cs_make_vim_style_matches(fname, slno, search, tagstr)
1649 char *fname;
1650 char *slno;
1651 char *search;
1652 char *tagstr;
1654 /* vim style is ctags:
1656 * <tagstr>\t<filename>\t<linenum_or_search>"\t<extra>
1658 * but as mentioned above, we'll always use the line number and
1659 * put the search pattern (if one exists) as "extra"
1661 * buf is used as part of vim's method of handling tags, and
1662 * (i think) vim frees it when you pop your tags and get replaced
1663 * by new ones on the tag stack.
1665 char *buf;
1666 int amt;
1668 if (search != NULL)
1670 amt = (int)(strlen(fname) + strlen(slno) + strlen(tagstr) + strlen(search)+6);
1671 if ((buf = (char *)alloc(amt)) == NULL)
1672 return NULL;
1674 (void)sprintf(buf, "%s\t%s\t%s;\"\t%s", tagstr, fname, slno, search);
1676 else
1678 amt = (int)(strlen(fname) + strlen(slno) + strlen(tagstr) + 5);
1679 if ((buf = (char *)alloc(amt)) == NULL)
1680 return NULL;
1682 (void)sprintf(buf, "%s\t%s\t%s;\"", tagstr, fname, slno);
1685 return buf;
1686 } /* cs_make_vim_style_matches */
1690 * PRIVATE: cs_manage_matches
1692 * this is kind of hokey, but i don't see an easy way round this..
1694 * Store: keep a ptr to the (malloc'd) memory of matches originally
1695 * generated from cs_find(). the matches are originally lines directly
1696 * from cscope output, but transformed to look like something out of a
1697 * ctags. see cs_make_vim_style_matches for more details.
1699 * Get: used only from cs_fgets(), this simulates a vim_fgets() to return
1700 * the next line from the cscope output. it basically keeps track of which
1701 * lines have been "used" and returns the next one.
1703 * Free: frees up everything and resets
1705 * Print: prints the tags
1707 static char *
1708 cs_manage_matches(matches, contexts, totmatches, cmd)
1709 char **matches;
1710 char **contexts;
1711 int totmatches;
1712 mcmd_e cmd;
1714 static char **mp = NULL;
1715 static char **cp = NULL;
1716 static int cnt = -1;
1717 static int next = -1;
1718 char *p = NULL;
1720 switch (cmd)
1722 case Store:
1723 assert(matches != NULL);
1724 assert(totmatches > 0);
1725 if (mp != NULL || cp != NULL)
1726 (void)cs_manage_matches(NULL, NULL, -1, Free);
1727 mp = matches;
1728 cp = contexts;
1729 cnt = totmatches;
1730 next = 0;
1731 break;
1732 case Get:
1733 if (next >= cnt)
1734 return NULL;
1736 p = mp[next];
1737 next++;
1738 break;
1739 case Free:
1740 if (mp != NULL)
1742 if (cnt > 0)
1743 while (cnt--)
1745 vim_free(mp[cnt]);
1746 if (cp != NULL)
1747 vim_free(cp[cnt]);
1749 vim_free(mp);
1750 vim_free(cp);
1752 mp = NULL;
1753 cp = NULL;
1754 cnt = 0;
1755 next = 0;
1756 break;
1757 case Print:
1758 cs_print_tags_priv(mp, cp, cnt);
1759 break;
1760 default: /* should not reach here */
1761 (void)EMSG(_("E570: fatal error in cs_manage_matches"));
1762 return NULL;
1765 return p;
1766 } /* cs_manage_matches */
1770 * PRIVATE: cs_parse_results
1772 * parse cscope output
1774 static char *
1775 cs_parse_results(cnumber, buf, bufsize, context, linenumber, search)
1776 int cnumber;
1777 char *buf;
1778 int bufsize;
1779 char **context;
1780 char **linenumber;
1781 char **search;
1783 int ch;
1784 char *p;
1785 char *name;
1787 if (fgets(buf, bufsize, csinfo[cnumber].fr_fp) == NULL)
1789 if (feof(csinfo[cnumber].fr_fp))
1790 errno = EIO;
1792 cs_reading_emsg(cnumber);
1794 return NULL;
1797 /* If the line's too long for the buffer, discard it. */
1798 if ((p = strchr(buf, '\n')) == NULL)
1800 while ((ch = getc(csinfo[cnumber].fr_fp)) != EOF && ch != '\n')
1802 return NULL;
1804 *p = '\0';
1807 * cscope output is in the following format:
1809 * <filename> <context> <line number> <pattern>
1811 if ((name = strtok((char *)buf, (const char *)" ")) == NULL)
1812 return NULL;
1813 if ((*context = strtok(NULL, (const char *)" ")) == NULL)
1814 return NULL;
1815 if ((*linenumber = strtok(NULL, (const char *)" ")) == NULL)
1816 return NULL;
1817 *search = *linenumber + strlen(*linenumber) + 1; /* +1 to skip \0 */
1819 /* --- nvi ---
1820 * If the file is older than the cscope database, that is,
1821 * the database was built since the file was last modified,
1822 * or there wasn't a search string, use the line number.
1824 if (strcmp(*search, "<unknown>") == 0)
1825 *search = NULL;
1827 name = cs_resolve_file(cnumber, name);
1828 return name;
1831 #ifdef FEAT_QUICKFIX
1833 * PRIVATE: cs_file_results
1835 * write cscope find results to file
1837 static void
1838 cs_file_results(f, nummatches_a)
1839 FILE *f;
1840 int *nummatches_a;
1842 int i, j;
1843 char *buf;
1844 char *search, *slno;
1845 char *fullname;
1846 char *cntx;
1847 char *context;
1849 buf = (char *)alloc(CSREAD_BUFSIZE);
1850 if (buf == NULL)
1851 return;
1853 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
1855 if (nummatches_a[i] < 1)
1856 continue;
1858 for (j = 0; j < nummatches_a[i]; j++)
1860 if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx,
1861 &slno, &search)) == NULL)
1862 continue;
1864 context = (char *)alloc((unsigned)strlen(cntx)+5);
1865 if (context == NULL)
1866 continue;
1868 if (strcmp(cntx, "<global>")==0)
1869 strcpy(context, "<<global>>");
1870 else
1871 sprintf(context, "<<%s>>", cntx);
1873 if (search == NULL)
1874 fprintf(f, "%s\t%s\t%s\n", fullname, slno, context);
1875 else
1876 fprintf(f, "%s\t%s\t%s %s\n", fullname, slno, context, search);
1878 vim_free(context);
1879 vim_free(fullname);
1880 } /* for all matches */
1882 (void)cs_read_prompt(i);
1884 } /* for all cscope connections */
1885 vim_free(buf);
1887 #endif
1890 * PRIVATE: cs_fill_results
1892 * get parsed cscope output and calls cs_make_vim_style_matches to convert
1893 * into ctags format
1894 * When there are no matches sets "*matches_p" to NULL.
1896 static void
1897 cs_fill_results(tagstr, totmatches, nummatches_a, matches_p, cntxts_p, matched)
1898 char *tagstr;
1899 int totmatches;
1900 int *nummatches_a;
1901 char ***matches_p;
1902 char ***cntxts_p;
1903 int *matched;
1905 int i, j;
1906 char *buf;
1907 char *search, *slno;
1908 int totsofar = 0;
1909 char **matches = NULL;
1910 char **cntxts = NULL;
1911 char *fullname;
1912 char *cntx;
1914 assert(totmatches > 0);
1916 buf = (char *)alloc(CSREAD_BUFSIZE);
1917 if (buf == NULL)
1918 return;
1920 if ((matches = (char **)alloc(sizeof(char *) * totmatches)) == NULL)
1921 goto parse_out;
1922 if ((cntxts = (char **)alloc(sizeof(char *) * totmatches)) == NULL)
1923 goto parse_out;
1925 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
1927 if (nummatches_a[i] < 1)
1928 continue;
1930 for (j = 0; j < nummatches_a[i]; j++)
1932 if ((fullname = cs_parse_results(i, buf, CSREAD_BUFSIZE, &cntx,
1933 &slno, &search)) == NULL)
1934 continue;
1936 matches[totsofar] = cs_make_vim_style_matches(fullname, slno,
1937 search, tagstr);
1939 vim_free(fullname);
1941 if (strcmp(cntx, "<global>") == 0)
1942 cntxts[totsofar] = NULL;
1943 else
1944 /* note: if vim_strsave returns NULL, then the context
1945 * will be "<global>", which is misleading.
1947 cntxts[totsofar] = (char *)vim_strsave((char_u *)cntx);
1949 if (matches[totsofar] != NULL)
1950 totsofar++;
1952 } /* for all matches */
1954 (void)cs_read_prompt(i);
1956 } /* for all cscope connections */
1958 parse_out:
1959 if (totsofar == 0)
1961 /* No matches, free the arrays and return NULL in "*matches_p". */
1962 vim_free(matches);
1963 matches = NULL;
1964 vim_free(cntxts);
1965 cntxts = NULL;
1967 *matched = totsofar;
1968 *matches_p = matches;
1969 *cntxts_p = cntxts;
1971 vim_free(buf);
1972 } /* cs_fill_results */
1975 /* get the requested path components */
1976 static char *
1977 cs_pathcomponents(path)
1978 char *path;
1980 int i;
1981 char *s;
1983 if (p_cspc == 0)
1984 return path;
1986 s = path + strlen(path) - 1;
1987 for (i = 0; i < p_cspc; ++i)
1988 while (s > path && *--s != '/'
1989 #ifdef WIN32
1990 && *--s != '\\'
1991 #endif
1994 if ((s > path && *s == '/')
1995 #ifdef WIN32
1996 || (s > path && *s == '\\')
1997 #endif
1999 ++s;
2000 return s;
2004 * PRIVATE: cs_print_tags_priv
2006 * called from cs_manage_matches()
2008 static void
2009 cs_print_tags_priv(matches, cntxts, num_matches)
2010 char **matches;
2011 char **cntxts;
2012 int num_matches;
2014 char *buf = NULL;
2015 int bufsize = 0; /* Track available bufsize */
2016 int newsize = 0;
2017 char *ptag;
2018 char *fname, *lno, *extra, *tbuf;
2019 int i, idx, num;
2020 char *globalcntx = "GLOBAL";
2021 char *cntxformat = " <<%s>>";
2022 char *context;
2023 char *cstag_msg = _("Cscope tag: %s");
2024 char *csfmt_str = "%4d %6s ";
2026 assert (num_matches > 0);
2028 if ((tbuf = (char *)alloc((unsigned)strlen(matches[0]) + 1)) == NULL)
2029 return;
2031 strcpy(tbuf, matches[0]);
2032 ptag = strtok(tbuf, "\t");
2034 newsize = (int)(strlen(cstag_msg) + strlen(ptag));
2035 buf = (char *)alloc(newsize);
2036 if (buf != NULL)
2038 bufsize = newsize;
2039 (void)sprintf(buf, cstag_msg, ptag);
2040 MSG_PUTS_ATTR(buf, hl_attr(HLF_T));
2043 vim_free(tbuf);
2045 MSG_PUTS_ATTR(_("\n # line"), hl_attr(HLF_T)); /* strlen is 7 */
2046 msg_advance(msg_col + 2);
2047 MSG_PUTS_ATTR(_("filename / context / line\n"), hl_attr(HLF_T));
2049 num = 1;
2050 for (i = 0; i < num_matches; i++)
2052 idx = i;
2054 /* if we really wanted to, we could avoid this malloc and strcpy
2055 * by parsing matches[i] on the fly and placing stuff into buf
2056 * directly, but that's too much of a hassle
2058 if ((tbuf = (char *)alloc((unsigned)strlen(matches[idx]) + 1)) == NULL)
2059 continue;
2060 (void)strcpy(tbuf, matches[idx]);
2062 if ((fname = strtok(tbuf, (const char *)"\t")) == NULL)
2063 continue;
2064 if ((fname = strtok(NULL, (const char *)"\t")) == NULL)
2065 continue;
2066 if ((lno = strtok(NULL, (const char *)"\t")) == NULL)
2067 continue;
2068 extra = strtok(NULL, (const char *)"\t");
2070 lno[strlen(lno)-2] = '\0'; /* ignore ;" at the end */
2072 /* hopefully 'num' (num of matches) will be less than 10^16 */
2073 newsize = (int)(strlen(csfmt_str) + 16 + strlen(lno));
2074 if (bufsize < newsize)
2076 buf = (char *)vim_realloc(buf, newsize);
2077 if (buf == NULL)
2078 bufsize = 0;
2079 else
2080 bufsize = newsize;
2082 if (buf != NULL)
2084 /* csfmt_str = "%4d %6s "; */
2085 (void)sprintf(buf, csfmt_str, num, lno);
2086 MSG_PUTS_ATTR(buf, hl_attr(HLF_CM));
2088 MSG_PUTS_LONG_ATTR(cs_pathcomponents(fname), hl_attr(HLF_CM));
2090 /* compute the required space for the context */
2091 if (cntxts[idx] != NULL)
2092 context = cntxts[idx];
2093 else
2094 context = globalcntx;
2095 newsize = (int)(strlen(context) + strlen(cntxformat));
2097 if (bufsize < newsize)
2099 buf = (char *)vim_realloc(buf, newsize);
2100 if (buf == NULL)
2101 bufsize = 0;
2102 else
2103 bufsize = newsize;
2105 if (buf != NULL)
2107 (void)sprintf(buf, cntxformat, context);
2109 /* print the context only if it fits on the same line */
2110 if (msg_col + (int)strlen(buf) >= (int)Columns)
2111 msg_putchar('\n');
2112 msg_advance(12);
2113 MSG_PUTS_LONG(buf);
2114 msg_putchar('\n');
2116 if (extra != NULL)
2118 msg_advance(13);
2119 MSG_PUTS_LONG(extra);
2122 vim_free(tbuf); /* only after printing extra due to strtok use */
2124 if (msg_col)
2125 msg_putchar('\n');
2127 ui_breakcheck();
2128 if (got_int)
2130 got_int = FALSE; /* don't print any more matches */
2131 break;
2134 num++;
2135 } /* for all matches */
2137 vim_free(buf);
2138 } /* cs_print_tags_priv */
2142 * PRIVATE: cs_read_prompt
2144 * read a cscope prompt (basically, skip over the ">> ")
2146 static int
2147 cs_read_prompt(i)
2148 int i;
2150 int ch;
2151 char *buf = NULL; /* buffer for possible error message from cscope */
2152 int bufpos = 0;
2153 char *cs_emsg;
2154 int maxlen;
2155 static char *eprompt = "Press the RETURN key to continue:";
2156 int epromptlen = (int)strlen(eprompt);
2157 int n;
2159 cs_emsg = _("E609: Cscope error: %s");
2160 /* compute maximum allowed len for Cscope error message */
2161 maxlen = (int)(IOSIZE - strlen(cs_emsg));
2163 for (;;)
2165 while ((ch = getc(csinfo[i].fr_fp)) != EOF && ch != CSCOPE_PROMPT[0])
2166 /* if there is room and char is printable */
2167 if (bufpos < maxlen - 1 && vim_isprintc(ch))
2169 if (buf == NULL) /* lazy buffer allocation */
2170 buf = (char *)alloc(maxlen);
2171 if (buf != NULL)
2173 /* append character to the message */
2174 buf[bufpos++] = ch;
2175 buf[bufpos] = NUL;
2176 if (bufpos >= epromptlen
2177 && strcmp(&buf[bufpos - epromptlen], eprompt) == 0)
2179 /* remove eprompt from buf */
2180 buf[bufpos - epromptlen] = NUL;
2182 /* print message to user */
2183 (void)EMSG2(cs_emsg, buf);
2185 /* send RETURN to cscope */
2186 (void)putc('\n', csinfo[i].to_fp);
2187 (void)fflush(csinfo[i].to_fp);
2189 /* clear buf */
2190 bufpos = 0;
2191 buf[bufpos] = NUL;
2196 for (n = 0; n < (int)strlen(CSCOPE_PROMPT); ++n)
2198 if (n > 0)
2199 ch = getc(csinfo[i].fr_fp);
2200 if (ch == EOF)
2202 PERROR("cs_read_prompt EOF");
2203 if (buf != NULL && buf[0] != NUL)
2204 (void)EMSG2(cs_emsg, buf);
2205 else if (p_csverbose)
2206 cs_reading_emsg(i); /* don't have additional information */
2207 cs_release_csp(i, TRUE);
2208 vim_free(buf);
2209 return CSCOPE_FAILURE;
2212 if (ch != CSCOPE_PROMPT[n])
2214 ch = EOF;
2215 break;
2219 if (ch == EOF)
2220 continue; /* didn't find the prompt */
2221 break; /* did find the prompt */
2224 vim_free(buf);
2225 return CSCOPE_SUCCESS;
2228 #if defined(UNIX) && defined(SIGALRM)
2230 * Used to catch and ignore SIGALRM below.
2232 /* ARGSUSED */
2233 static RETSIGTYPE
2234 sig_handler SIGDEFARG(sigarg)
2236 /* do nothing */
2237 SIGRETURN;
2239 #endif
2242 * PRIVATE: cs_release_csp
2244 * Does the actual free'ing for the cs ptr with an optional flag of whether
2245 * or not to free the filename. Called by cs_kill and cs_reset.
2247 static void
2248 cs_release_csp(i, freefnpp)
2249 int i;
2250 int freefnpp;
2253 * Trying to exit normally (not sure whether it is fit to UNIX cscope
2255 if (csinfo[i].to_fp != NULL)
2257 (void)fputs("q\n", csinfo[i].to_fp);
2258 (void)fflush(csinfo[i].to_fp);
2260 #if defined(UNIX)
2262 int waitpid_errno;
2263 int pstat;
2264 pid_t pid;
2266 # if defined(HAVE_SIGACTION)
2267 struct sigaction sa, old;
2269 /* Use sigaction() to limit the waiting time to two seconds. */
2270 sigemptyset(&sa.sa_mask);
2271 sa.sa_handler = sig_handler;
2272 sa.sa_flags = SA_NODEFER;
2273 sigaction(SIGALRM, &sa, &old);
2274 alarm(2); /* 2 sec timeout */
2276 /* Block until cscope exits or until timer expires */
2277 pid = waitpid(csinfo[i].pid, &pstat, 0);
2278 waitpid_errno = errno;
2280 /* cancel pending alarm if still there and restore signal */
2281 alarm(0);
2282 sigaction(SIGALRM, &old, NULL);
2283 # else
2284 int waited;
2286 /* Can't use sigaction(), loop for two seconds. First yield the CPU
2287 * to give cscope a chance to exit quickly. */
2288 sleep(0);
2289 for (waited = 0; waited < 40; ++waited)
2291 pid = waitpid(csinfo[i].pid, &pstat, WNOHANG);
2292 waitpid_errno = errno;
2293 if (pid != 0)
2294 break; /* break unless the process is still running */
2295 mch_delay(50L, FALSE); /* sleep 50 ms */
2297 # endif
2299 * If the cscope process is still running: kill it.
2300 * Safety check: If the PID would be zero here, the entire X session
2301 * would be killed. -1 and 1 are dangerous as well.
2303 if (pid < 0 && csinfo[i].pid > 1)
2305 # ifdef ECHILD
2306 int alive = TRUE;
2308 if (waitpid_errno == ECHILD)
2311 * When using 'vim -g', vim is forked and cscope process is
2312 * no longer a child process but a sibling. So waitpid()
2313 * fails with errno being ECHILD (No child processes).
2314 * Don't send SIGKILL to cscope immediately but wait
2315 * (polling) for it to exit normally as result of sending
2316 * the "q" command, hence giving it a chance to clean up
2317 * its temporary files.
2319 int waited;
2321 sleep(0);
2322 for (waited = 0; waited < 40; ++waited)
2324 /* Check whether cscope process is still alive */
2325 if (kill(csinfo[i].pid, 0) != 0)
2327 alive = FALSE; /* cscope process no longer exists */
2328 break;
2330 mch_delay(50L, FALSE); /* sleep 50ms */
2333 if (alive)
2334 # endif
2336 kill(csinfo[i].pid, SIGKILL);
2337 (void)waitpid(csinfo[i].pid, &pstat, 0);
2341 #else /* !UNIX */
2342 if (csinfo[i].hProc != NULL)
2344 /* Give cscope a chance to exit normally */
2345 if (WaitForSingleObject(csinfo[i].hProc, 1000) == WAIT_TIMEOUT)
2346 TerminateProcess(csinfo[i].hProc, 0);
2347 CloseHandle(csinfo[i].hProc);
2349 #endif
2351 if (csinfo[i].fr_fp != NULL)
2352 (void)fclose(csinfo[i].fr_fp);
2353 if (csinfo[i].to_fp != NULL)
2354 (void)fclose(csinfo[i].to_fp);
2356 if (freefnpp)
2358 vim_free(csinfo[i].fname);
2359 vim_free(csinfo[i].ppath);
2360 vim_free(csinfo[i].flags);
2363 clear_csinfo(i);
2364 } /* cs_release_csp */
2368 * PRIVATE: cs_reset
2370 * calls cs_kill on all cscope connections then reinits
2372 /* ARGSUSED */
2373 static int
2374 cs_reset(eap)
2375 exarg_T *eap;
2377 char **dblist = NULL, **pplist = NULL, **fllist = NULL;
2378 int i;
2379 char buf[20]; /* for sprintf " (#%d)" */
2381 /* malloc our db and ppath list */
2382 dblist = (char **)alloc(CSCOPE_MAX_CONNECTIONS * sizeof(char *));
2383 pplist = (char **)alloc(CSCOPE_MAX_CONNECTIONS * sizeof(char *));
2384 fllist = (char **)alloc(CSCOPE_MAX_CONNECTIONS * sizeof(char *));
2385 if (dblist == NULL || pplist == NULL || fllist == NULL)
2387 vim_free(dblist);
2388 vim_free(pplist);
2389 vim_free(fllist);
2390 return CSCOPE_FAILURE;
2393 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
2395 dblist[i] = csinfo[i].fname;
2396 pplist[i] = csinfo[i].ppath;
2397 fllist[i] = csinfo[i].flags;
2398 if (csinfo[i].fname != NULL)
2399 cs_release_csp(i, FALSE);
2402 /* rebuild the cscope connection list */
2403 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
2405 if (dblist[i] != NULL)
2407 cs_add_common(dblist[i], pplist[i], fllist[i]);
2408 if (p_csverbose)
2410 /* don't use smsg_attr() because we want to display the
2411 * connection number in the same line as
2412 * "Added cscope database..."
2414 sprintf(buf, " (#%d)", i);
2415 MSG_PUTS_ATTR(buf, hl_attr(HLF_R));
2418 vim_free(dblist[i]);
2419 vim_free(pplist[i]);
2420 vim_free(fllist[i]);
2422 vim_free(dblist);
2423 vim_free(pplist);
2424 vim_free(fllist);
2426 if (p_csverbose)
2427 MSG_ATTR(_("All cscope databases reset"), hl_attr(HLF_R) | MSG_HIST);
2428 return CSCOPE_SUCCESS;
2429 } /* cs_reset */
2433 * PRIVATE: cs_resolve_file
2435 * construct the full pathname to a file found in the cscope database.
2436 * (Prepends ppath, if there is one and if it's not already prepended,
2437 * otherwise just uses the name found.)
2439 * we need to prepend the prefix because on some cscope's (e.g., the one that
2440 * ships with Solaris 2.6), the output never has the prefix prepended.
2441 * contrast this with my development system (Digital Unix), which does.
2443 static char *
2444 cs_resolve_file(i, name)
2445 int i;
2446 char *name;
2448 char *fullname;
2449 int len;
2452 * ppath is freed when we destroy the cscope connection.
2453 * fullname is freed after cs_make_vim_style_matches, after it's been
2454 * copied into the tag buffer used by vim
2456 len = (int)(strlen(name) + 2);
2457 if (csinfo[i].ppath != NULL)
2458 len += (int)strlen(csinfo[i].ppath);
2460 if ((fullname = (char *)alloc(len)) == NULL)
2461 return NULL;
2464 * note/example: this won't work if the cscope output already starts
2465 * "../.." and the prefix path is also "../..". if something like this
2466 * happens, you are screwed up and need to fix how you're using cscope.
2468 if (csinfo[i].ppath != NULL &&
2469 (strncmp(name, csinfo[i].ppath, strlen(csinfo[i].ppath)) != 0) &&
2470 (name[0] != '/')
2471 #ifdef WIN32
2472 && name[0] != '\\' && name[1] != ':'
2473 #endif
2475 (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name);
2476 else
2477 (void)sprintf(fullname, "%s", name);
2479 return fullname;
2480 } /* cs_resolve_file */
2484 * PRIVATE: cs_show
2486 * show all cscope connections
2488 /* ARGSUSED */
2489 static int
2490 cs_show(eap)
2491 exarg_T *eap;
2493 short i;
2494 if (cs_cnt_connections() == 0)
2495 MSG_PUTS(_("no cscope connections\n"));
2496 else
2498 MSG_PUTS_ATTR(
2499 _(" # pid database name prepend path\n"),
2500 hl_attr(HLF_T));
2501 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
2503 if (csinfo[i].fname == NULL)
2504 continue;
2506 if (csinfo[i].ppath != NULL)
2507 (void)smsg((char_u *)"%2d %-5ld %-34s %-32s",
2508 i, (long)csinfo[i].pid, csinfo[i].fname, csinfo[i].ppath);
2509 else
2510 (void)smsg((char_u *)"%2d %-5ld %-34s <none>",
2511 i, (long)csinfo[i].pid, csinfo[i].fname);
2515 wait_return(TRUE);
2516 return CSCOPE_SUCCESS;
2517 } /* cs_show */
2521 * PUBLIC: cs_end
2523 * Only called when VIM exits to quit any cscope sessions.
2525 void
2526 cs_end()
2528 int i;
2530 for (i = 0; i < CSCOPE_MAX_CONNECTIONS; i++)
2531 cs_release_csp(i, TRUE);
2534 #endif /* FEAT_CSCOPE */
2536 /* the end */