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.
14 #if defined(FEAT_CSCOPE) || defined(PROTO)
19 #include <sys/types.h>
22 # include <sys/wait.h>
24 /* not UNIX, must be WIN32 */
28 #include "if_cscope.h"
30 static void cs_usage_msg
__ARGS((csid_e x
));
31 static int cs_add
__ARGS((exarg_T
*eap
));
32 static void cs_stat_emsg
__ARGS((char *fname
));
33 static int cs_add_common
__ARGS((char *, char *, char *));
34 static int cs_check_for_connections
__ARGS((void));
35 static int cs_check_for_tags
__ARGS((void));
36 static int cs_cnt_connections
__ARGS((void));
37 static void cs_reading_emsg
__ARGS((int idx
));
38 static int cs_cnt_matches
__ARGS((int idx
));
39 static char * cs_create_cmd
__ARGS((char *csoption
, char *pattern
));
40 static int cs_create_connection
__ARGS((int i
));
41 static void do_cscope_general
__ARGS((exarg_T
*eap
, int make_split
));
43 static void cs_file_results
__ARGS((FILE *, int *));
45 static void cs_fill_results
__ARGS((char *, int , int *, char ***,
47 static int cs_find
__ARGS((exarg_T
*eap
));
48 static int cs_find_common
__ARGS((char *opt
, char *pat
, int, int, int));
49 static int cs_help
__ARGS((exarg_T
*eap
));
50 static void cs_init
__ARGS((void));
51 static void clear_csinfo
__ARGS((int i
));
52 static int cs_insert_filelist
__ARGS((char *, char *, char *,
54 static int cs_kill
__ARGS((exarg_T
*eap
));
55 static void cs_kill_execute
__ARGS((int, char *));
56 static cscmd_T
* cs_lookup_cmd
__ARGS((exarg_T
*eap
));
57 static char * cs_make_vim_style_matches
__ARGS((char *, char *,
59 static char * cs_manage_matches
__ARGS((char **, char **, int, mcmd_e
));
60 static char * cs_parse_results
__ARGS((int cnumber
, char *buf
, int bufsize
, char **context
, char **linenumber
, char **search
));
61 static char * cs_pathcomponents
__ARGS((char *path
));
62 static void cs_print_tags_priv
__ARGS((char **, char **, int));
63 static int cs_read_prompt
__ARGS((int));
64 static void cs_release_csp
__ARGS((int, int freefnpp
));
65 static int cs_reset
__ARGS((exarg_T
*eap
));
66 static char * cs_resolve_file
__ARGS((int, char *));
67 static int cs_show
__ARGS((exarg_T
*eap
));
70 static csinfo_T csinfo
[CSCOPE_MAX_CONNECTIONS
];
71 static int eap_arg_len
; /* length of eap->arg, set in
73 static cscmd_T cs_cmds
[] =
76 N_("Add a new database"), "add file|dir [pre-path] [flags]", 0 },
78 N_("Query for a pattern"), FIND_USAGE
, 1 },
80 N_("Show this message"), "help", 0 },
82 N_("Kill a connection"), "kill #", 0 },
84 N_("Reinit all connections"), "reset", 0 },
86 N_("Show connections"), "show", 0 },
94 (void)EMSG2(_("E560: Usage: cs[cope] %s"), cs_cmds
[(int)x
].usage
);
98 * PRIVATE: do_cscope_general
100 * find the command, print help if invalid, and the then call the
101 * corresponding command function,
102 * called from do_cscope and do_scscope
105 do_cscope_general(eap
, make_split
)
107 int make_split
; /* whether to split window */
112 if ((cmdp
= cs_lookup_cmd(eap
)) == NULL
)
123 (void)MSG_PUTS(_("This cscope command does not support splitting the window.\n"));
126 postponed_split
= -1;
127 postponed_split_flags
= cmdmod
.split
;
128 postponed_split_tab
= cmdmod
.tab
;
135 postponed_split_flags
= 0;
136 postponed_split_tab
= 0;
147 do_cscope_general(eap
, FALSE
);
153 * same as do_cscope, but splits window, too.
159 do_cscope_general(eap
, TRUE
);
174 if (eap
->arg
== NULL
|| strlen((const char *)(eap
->arg
)) == 0)
176 (void)EMSG(_("E562: Usage: cstag <ident>"));
183 if (cs_check_for_connections())
185 ret
= cs_find_common("g", (char *)(eap
->arg
), eap
->forceit
, FALSE
,
193 if (cs_check_for_tags())
194 ret
= do_tag(eap
->arg
, DT_JUMP
, 0, eap
->forceit
, FALSE
);
197 else if (cs_check_for_tags())
199 ret
= do_tag(eap
->arg
, DT_JUMP
, 0, eap
->forceit
, FALSE
);
203 if (cs_check_for_tags())
205 ret
= do_tag(eap
->arg
, DT_JUMP
, 0, eap
->forceit
, FALSE
);
211 if (cs_check_for_connections())
213 ret
= cs_find_common("g", (char *)(eap
->arg
), eap
->forceit
,
220 else if (cs_check_for_connections())
222 ret
= cs_find_common("g", (char *)(eap
->arg
), eap
->forceit
, FALSE
,
234 (void)EMSG(_("E257: cstag: tag not found"));
235 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
246 * this simulates a vim_fgets(), but for cscope, returns the next line
247 * from the cscope output. should only be called from find_tags()
249 * returns TRUE if eof, FALSE otherwise
258 if ((p
= cs_manage_matches(NULL
, NULL
, -1, Get
)) == NULL
)
260 vim_strncpy(buf
, (char_u
*)p
, size
- 1);
267 * PUBLIC: cs_free_tags
269 * called only from do_tag(), when popping the tag stack
274 cs_manage_matches(NULL
, NULL
, -1, Free
);
279 * PUBLIC: cs_print_tags
281 * called from do_tag()
286 cs_manage_matches(NULL
, NULL
, -1, Print
);
291 * "cscope_connection([{num} , {dbpath} [, {prepend}]])" function
293 * Checks for the existence of a |cscope| connection. If no
294 * parameters are specified, then the function returns:
296 * 0, if cscope was not available (not compiled in), or if there
297 * are no cscope connections; or
298 * 1, if there is at least one cscope connection.
300 * If parameters are specified, then the value of {num}
301 * determines how existence of a cscope connection is checked:
303 * {num} Description of existence check
304 * ----- ------------------------------
305 * 0 Same as no parameters (e.g., "cscope_connection()").
306 * 1 Ignore {prepend}, and use partial string matches for
308 * 2 Ignore {prepend}, and use exact string matches for
310 * 3 Use {prepend}, use partial string matches for both
311 * {dbpath} and {prepend}.
312 * 4 Use {prepend}, use exact string matches for both
313 * {dbpath} and {prepend}.
315 * Note: All string comparisons are case sensitive!
317 #if defined(FEAT_EVAL) || defined(PROTO)
319 cs_connection(num
, dbpath
, ppath
)
326 if (num
< 0 || num
> 4 || (num
> 0 && !dbpath
))
329 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
331 if (!csinfo
[i
].fname
)
340 if (strstr(csinfo
[i
].fname
, (char *)dbpath
))
344 if (strcmp(csinfo
[i
].fname
, (char *)dbpath
) == 0)
348 if (strstr(csinfo
[i
].fname
, (char *)dbpath
)
349 && ((!ppath
&& !csinfo
[i
].ppath
)
352 && strstr(csinfo
[i
].ppath
, (char *)ppath
))))
356 if ((strcmp(csinfo
[i
].fname
, (char *)dbpath
) == 0)
357 && ((!ppath
&& !csinfo
[i
].ppath
)
360 && (strcmp(csinfo
[i
].ppath
, (char *)ppath
) == 0))))
367 } /* cs_connection */
373 ****************************************************************************/
378 * add cscope database or a directory name (to look for cscope.out)
379 * to the cscope connection list
388 char *fname
, *ppath
, *flags
= NULL
;
390 if ((fname
= strtok((char *)NULL
, (const char *)" ")) == NULL
)
393 return CSCOPE_FAILURE
;
395 if ((ppath
= strtok((char *)NULL
, (const char *)" ")) != NULL
)
396 flags
= strtok((char *)NULL
, (const char *)" ");
398 return cs_add_common(fname
, ppath
, flags
);
405 char *stat_emsg
= _("E563: stat(%s) error: %d");
406 char *buf
= (char *)alloc((unsigned)strlen(stat_emsg
) + MAXPATHL
+ 10);
410 (void)sprintf(buf
, stat_emsg
, fname
, errno
);
415 (void)EMSG(_("E563: stat error"));
420 * PRIVATE: cs_add_common
422 * the common routine to add a new cscope connection. called by
423 * cs_add() and cs_reset(). i really don't like to do this, but this
424 * routine uses a number of goto statements.
427 cs_add_common(arg1
, arg2
, flags
)
428 char *arg1
; /* filename - may contain environment variables */
429 char *arg2
; /* prepend path - may contain environment variables */
439 /* get the filename (arg1), expand it, and try to stat it */
440 if ((fname
= (char *)alloc(MAXPATHL
+ 1)) == NULL
)
443 expand_env((char_u
*)arg1
, (char_u
*)fname
, MAXPATHL
);
444 ret
= stat(fname
, &statbuf
);
453 /* get the prepend path (arg2), expand it, and try to stat it */
456 struct stat statbuf2
;
458 if ((ppath
= (char *)alloc(MAXPATHL
+ 1)) == NULL
)
461 expand_env((char_u
*)arg2
, (char_u
*)ppath
, MAXPATHL
);
462 ret
= stat(ppath
, &statbuf2
);
467 /* if filename is a directory, append the cscope database name to it */
468 if ((statbuf
.st_mode
& S_IFMT
) == S_IFDIR
)
470 fname2
= (char *)alloc((unsigned)(strlen(CSCOPE_DBFILE
) + strlen(fname
) + 2));
474 while (fname
[strlen(fname
)-1] == '/'
476 || fname
[strlen(fname
)-1] == '\\'
480 fname
[strlen(fname
)-1] = '\0';
481 if (strlen(fname
) == 0)
484 if (fname
[0] == '\0')
485 (void)sprintf(fname2
, "/%s", CSCOPE_DBFILE
);
487 (void)sprintf(fname2
, "%s/%s", fname
, CSCOPE_DBFILE
);
489 ret
= stat(fname2
, &statbuf
);
493 cs_stat_emsg(fname2
);
497 i
= cs_insert_filelist(fname2
, ppath
, flags
, &statbuf
);
500 else if (S_ISREG(statbuf
.st_mode
) || S_ISLNK(statbuf
.st_mode
))
502 /* WIN32 - substitute define S_ISREG from os_unix.h */
503 else if (((statbuf
.st_mode
) & S_IFMT
) == S_IFREG
)
506 i
= cs_insert_filelist(fname
, ppath
, flags
, &statbuf
);
512 _("E564: %s is not a directory or a valid cscope database"),
519 if (cs_create_connection(i
) == CSCOPE_FAILURE
520 || cs_read_prompt(i
) == CSCOPE_FAILURE
)
522 cs_release_csp(i
, TRUE
);
529 (void)smsg_attr(hl_attr(HLF_R
),
530 (char_u
*)_("Added cscope database %s"),
538 return CSCOPE_SUCCESS
;
544 return CSCOPE_FAILURE
;
545 } /* cs_add_common */
549 cs_check_for_connections()
551 return (cs_cnt_connections() > 0);
552 } /* cs_check_for_connections */
558 return (p_tags
[0] != NUL
&& curbuf
->b_p_tags
!= NULL
);
559 } /* cs_check_for_tags */
563 * PRIVATE: cs_cnt_connections
565 * count the number of cscope connections
573 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
575 if (csinfo
[i
].fname
!= NULL
)
579 } /* cs_cnt_connections */
583 int idx
; /* connection index */
585 EMSGN(_("E262: error reading cscope connection %ld"), idx
);
588 #define CSREAD_BUFSIZE 2048
590 * PRIVATE: cs_cnt_matches
592 * count the number of matches for a given cscope connection.
602 buf
= (char *)alloc(CSREAD_BUFSIZE
);
607 if (!fgets(buf
, CSREAD_BUFSIZE
, csinfo
[idx
].fr_fp
))
609 if (feof(csinfo
[idx
].fr_fp
))
612 cs_reading_emsg(idx
);
619 * If the database is out of date, or there's some other problem,
620 * cscope will output error messages before the number-of-lines output.
621 * Display/discard any output that doesn't match what we want.
622 * Accept "\S*cscope: X lines", also matches "mlcscope".
624 if ((stok
= strtok(buf
, (const char *)" ")) == NULL
)
626 if (strstr((const char *)stok
, "cscope:") == NULL
)
629 if ((stok
= strtok(NULL
, (const char *)" ")) == NULL
)
638 if ((stok
= strtok(NULL
, (const char *)" ")) == NULL
)
640 if (strncmp((const char *)stok
, "lines", 5))
648 } /* cs_cnt_matches */
652 * PRIVATE: cs_create_cmd
654 * Creates the actual cscope command query from what the user entered.
657 cs_create_cmd(csoption
, pattern
)
666 case '0' : case 's' :
669 case '1' : case 'g' :
672 case '2' : case 'd' :
675 case '3' : case 'c' :
678 case '4' : case 't' :
681 case '6' : case 'e' :
684 case '7' : case 'f' :
687 case '8' : case 'i' :
691 (void)EMSG(_("E561: unknown cscope search type"));
696 if ((cmd
= (char *)alloc((unsigned)(strlen(pattern
) + 2))) == NULL
)
699 (void)sprintf(cmd
, "%d%s", search
, pattern
);
702 } /* cs_create_cmd */
706 * PRIVATE: cs_create_connection
708 * This piece of code was taken/adapted from nvi. do we need to add
709 * the BSD license notice?
712 cs_create_connection(i
)
716 int to_cs
[2], from_cs
[2];
719 char *prog
, *cmd
, *ppath
= NULL
;
722 SECURITY_ATTRIBUTES sa
;
723 PROCESS_INFORMATION pi
;
725 BOOL pipe_stdin
= FALSE
, pipe_stdout
= FALSE
;
726 HANDLE stdin_rd
, stdout_rd
;
727 HANDLE stdout_wr
, stdin_wr
;
730 # define OPEN_OH_ARGTYPE long
732 # if (_MSC_VER >= 1300)
733 # define OPEN_OH_ARGTYPE intptr_t
735 # define OPEN_OH_ARGTYPE long
742 * Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from
743 * from_cs[0] and writes to to_cs[1].
745 to_cs
[0] = to_cs
[1] = from_cs
[0] = from_cs
[1] = -1;
746 if (pipe(to_cs
) < 0 || pipe(from_cs
) < 0)
748 (void)EMSG(_("E566: Could not create cscope pipes"));
751 (void)close(to_cs
[0]);
753 (void)close(to_cs
[1]);
754 if (from_cs
[0] != -1)
755 (void)close(from_cs
[0]);
756 if (from_cs
[1] != -1)
757 (void)close(from_cs
[1]);
758 return CSCOPE_FAILURE
;
761 switch (csinfo
[i
].pid
= fork())
764 (void)EMSG(_("E622: Could not fork for cscope"));
766 case 0: /* child: run cscope. */
767 if (dup2(to_cs
[0], STDIN_FILENO
) == -1)
768 PERROR("cs_create_connection 1");
769 if (dup2(from_cs
[1], STDOUT_FILENO
) == -1)
770 PERROR("cs_create_connection 2");
771 if (dup2(from_cs
[1], STDERR_FILENO
) == -1)
772 PERROR("cs_create_connection 3");
775 (void)close(to_cs
[1]);
776 (void)close(from_cs
[0]);
779 /* Create pipes to communicate with cscope */
780 sa
.nLength
= sizeof(SECURITY_ATTRIBUTES
);
781 sa
.bInheritHandle
= TRUE
;
782 sa
.lpSecurityDescriptor
= NULL
;
784 if (!(pipe_stdin
= CreatePipe(&stdin_rd
, &stdin_wr
, &sa
, 0))
785 || !(pipe_stdout
= CreatePipe(&stdout_rd
, &stdout_wr
, &sa
, 0)))
787 (void)EMSG(_("E566: Could not create cscope pipes"));
791 CloseHandle(stdin_rd
);
792 CloseHandle(stdin_wr
);
796 CloseHandle(stdout_rd
);
797 CloseHandle(stdout_wr
);
799 return CSCOPE_FAILURE
;
802 /* expand the cscope exec for env var's */
803 if ((prog
= (char *)alloc(MAXPATHL
+ 1)) == NULL
)
806 return CSCOPE_FAILURE
;
812 expand_env((char_u
*)p_csprg
, (char_u
*)prog
, MAXPATHL
);
814 /* alloc space to hold the cscope command */
815 len
= (int)(strlen(prog
) + strlen(csinfo
[i
].fname
) + 32);
818 /* expand the prepend path for env var's */
819 if ((ppath
= (char *)alloc(MAXPATHL
+ 1)) == NULL
)
823 return CSCOPE_FAILURE
;
829 expand_env((char_u
*)csinfo
[i
].ppath
, (char_u
*)ppath
, MAXPATHL
);
831 len
+= (int)strlen(ppath
);
835 len
+= (int)strlen(csinfo
[i
].flags
);
837 if ((cmd
= (char *)alloc(len
)) == NULL
)
842 return CSCOPE_FAILURE
;
849 /* run the cscope command; is there execl for non-unix systems? */
851 (void)sprintf(cmd
, "exec %s -dl -f %s", prog
, csinfo
[i
].fname
);
854 (void)sprintf(cmd
, "%s -dl -f %s", prog
, csinfo
[i
].fname
);
856 if (csinfo
[i
].ppath
!= NULL
)
858 (void)strcat(cmd
, " -P");
859 (void)strcat(cmd
, csinfo
[i
].ppath
);
861 if (csinfo
[i
].flags
!= NULL
)
863 (void)strcat(cmd
, " ");
864 (void)strcat(cmd
, csinfo
[i
].flags
);
867 /* on Win32 we still need prog */
873 if (execl("/bin/sh", "sh", "-c", cmd
, NULL
) == -1)
874 PERROR(_("cs_create_connection exec failed"));
878 default: /* parent. */
880 * Save the file descriptors for later duplication, and
883 if ((csinfo
[i
].to_fp
= fdopen(to_cs
[1], "w")) == NULL
)
884 PERROR(_("cs_create_connection: fdopen for to_fp failed"));
885 if ((csinfo
[i
].fr_fp
= fdopen(from_cs
[0], "r")) == NULL
)
886 PERROR(_("cs_create_connection: fdopen for fr_fp failed"));
889 (void)close(to_cs
[0]);
890 (void)close(from_cs
[1]);
897 /* Create a new process to run cscope and use pipes to talk with it */
899 si
.dwFlags
= STARTF_USESTDHANDLES
| STARTF_USESHOWWINDOW
;
900 si
.wShowWindow
= SW_HIDE
; /* Hide child application window */
901 si
.hStdOutput
= stdout_wr
;
902 si
.hStdError
= stdout_wr
;
903 si
.hStdInput
= stdin_rd
;
904 created
= CreateProcess(NULL
, cmd
, NULL
, NULL
, TRUE
, CREATE_NEW_CONSOLE
,
905 NULL
, NULL
, &si
, &pi
);
911 PERROR(_("cs_create_connection exec failed"));
912 (void)EMSG(_("E623: Could not spawn cscope process"));
916 csinfo
[i
].pid
= pi
.dwProcessId
;
917 csinfo
[i
].hProc
= pi
.hProcess
;
918 CloseHandle(pi
.hThread
);
920 /* TODO - tidy up after failure to create files on pipe handles. */
921 if (((fd
= _open_osfhandle((OPEN_OH_ARGTYPE
)stdin_wr
,
922 _O_TEXT
|_O_APPEND
)) < 0)
923 || ((csinfo
[i
].to_fp
= _fdopen(fd
, "w")) == NULL
))
924 PERROR(_("cs_create_connection: fdopen for to_fp failed"));
925 if (((fd
= _open_osfhandle((OPEN_OH_ARGTYPE
)stdout_rd
,
926 _O_TEXT
|_O_RDONLY
)) < 0)
927 || ((csinfo
[i
].fr_fp
= _fdopen(fd
, "r")) == NULL
))
928 PERROR(_("cs_create_connection: fdopen for fr_fp failed"));
930 /* Close handles for file descriptors inherited by the cscope process */
931 CloseHandle(stdin_rd
);
932 CloseHandle(stdout_wr
);
936 return CSCOPE_SUCCESS
;
937 } /* cs_create_connection */
943 * query cscope using command line interface. parse the output and use tselect
944 * to allow choices. like Nvi, creates a pipe to send to/from query/cscope.
946 * returns TRUE if we jump to a tag or abort, FALSE if not.
954 if (cs_check_for_connections() == FALSE
)
956 (void)EMSG(_("E567: no cscope connections"));
960 if ((opt
= strtok((char *)NULL
, (const char *)" ")) == NULL
)
966 pat
= opt
+ strlen(opt
) + 1;
967 if (pat
>= (char *)eap
->arg
+ eap_arg_len
)
973 return cs_find_common(opt
, pat
, eap
->forceit
, TRUE
,
974 eap
->cmdidx
== CMD_lcscope
);
979 * PRIVATE: cs_find_common
981 * common code for cscope find, shared by cs_find() and do_cstag()
984 cs_find_common(opt
, pat
, forceit
, verbose
, use_ll
)
993 int nummatches
[CSCOPE_MAX_CONNECTIONS
], totmatches
;
999 /* create the actual command to send to cscope */
1000 cmd
= cs_create_cmd(opt
, pat
);
1004 /* send query to all open connections, then count the total number
1005 * of matches so we can alloc matchesp all in one swell foop
1007 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
1010 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
1012 if (csinfo
[i
].fname
== NULL
|| csinfo
[i
].to_fp
== NULL
)
1015 /* send cmd to cscope */
1016 (void)fprintf(csinfo
[i
].to_fp
, "%s\n", cmd
);
1017 (void)fflush(csinfo
[i
].to_fp
);
1019 nummatches
[i
] = cs_cnt_matches(i
);
1021 if (nummatches
[i
] > -1)
1022 totmatches
+= nummatches
[i
];
1024 if (nummatches
[i
] == 0)
1025 (void)cs_read_prompt(i
);
1029 if (totmatches
== 0)
1031 char *nf
= _("E259: no matches found for cscope query %s of %s");
1037 buf
= (char *)alloc((unsigned)(strlen(opt
) + strlen(pat
) + strlen(nf
)));
1042 sprintf(buf
, nf
, opt
, pat
);
1049 #ifdef FEAT_QUICKFIX
1050 /* get cmd letter */
1081 qfpos
= (char *)vim_strchr(p_csqf
, cmdletter
);
1085 /* next symbol must be + or - */
1086 if (strchr(CSQF_FLAGS
, *qfpos
) == NULL
)
1088 char *nf
= _("E469: invalid cscopequickfix flag %c for %c");
1089 char *buf
= (char *)alloc((unsigned)strlen(nf
));
1091 /* strlen will be enough because we use chars */
1094 sprintf(buf
, nf
, *qfpos
, *(qfpos
-1));
1101 if (qfpos
!= NULL
&& *qfpos
!= '0' && totmatches
> 0)
1103 /* fill error list */
1105 char_u
*tmp
= vim_tempname('c');
1106 qf_info_T
*qi
= NULL
;
1109 f
= mch_fopen((char *)tmp
, "w");
1111 EMSG2(_(e_notopen
), tmp
);
1114 cs_file_results(f
, nummatches
);
1116 if (use_ll
) /* Use location list */
1118 /* '-' starts a new error list */
1119 if (qf_init(wp
, tmp
, (char_u
*)"%f%*\\t%l%*\\t%m",
1122 # ifdef FEAT_WINDOWS
1123 if (postponed_split
!= 0)
1125 win_split(postponed_split
> 0 ? postponed_split
: 0,
1126 postponed_split_flags
);
1127 # ifdef FEAT_SCROLLBIND
1128 curwin
->w_p_scb
= FALSE
;
1130 postponed_split
= 0;
1135 * In the location list window, use the displayed location
1136 * list. Otherwise, use the location list for the window.
1138 qi
= (bt_quickfix(wp
->w_buffer
) && wp
->w_llist_ref
!= NULL
)
1139 ? wp
->w_llist_ref
: wp
->w_llist
;
1140 qf_jump(qi
, 0, 0, forceit
);
1148 #endif /* FEAT_QUICKFIX */
1150 char **matches
= NULL
, **contexts
= NULL
;
1154 cs_fill_results((char *)pat
, totmatches
, nummatches
, &matches
,
1155 &contexts
, &matched
);
1156 if (matches
== NULL
)
1159 (void)cs_manage_matches(matches
, contexts
, matched
, Store
);
1161 return do_tag((char_u
*)pat
, DT_CSCOPE
, 0, forceit
, verbose
);
1164 } /* cs_find_common */
1176 cscmd_T
*cmdp
= cs_cmds
;
1178 (void)MSG_PUTS(_("cscope commands:\n"));
1179 while (cmdp
->name
!= NULL
)
1181 (void)smsg((char_u
*)_("%-5s: %-30s (Usage: %s)"),
1182 cmdp
->name
, _(cmdp
->help
), cmdp
->usage
);
1183 if (strcmp(cmdp
->name
, "find") == 0)
1184 MSG_PUTS(FIND_HELP
);
1196 * initialize cscope structure if not already
1202 static int init_already
= FALSE
;
1207 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
1210 init_already
= TRUE
;
1217 csinfo
[i
].fname
= NULL
;
1218 csinfo
[i
].ppath
= NULL
;
1219 csinfo
[i
].flags
= NULL
;
1221 csinfo
[i
].st_dev
= (dev_t
)0;
1222 csinfo
[i
].st_ino
= (ino_t
)0;
1224 csinfo
[i
].nVolume
= 0;
1225 csinfo
[i
].nIndexHigh
= 0;
1226 csinfo
[i
].nIndexLow
= 0;
1229 csinfo
[i
].fr_fp
= NULL
;
1230 csinfo
[i
].to_fp
= NULL
;
1232 csinfo
[i
].hProc
= NULL
;
1237 static char *GetWin32Error
__ARGS((void));
1243 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_FROM_SYSTEM
,
1244 NULL
, GetLastError(), 0, (LPSTR
)&msg
, 0, NULL
);
1247 /* remove trailing \r\n */
1248 char *pcrlf
= strstr(msg
, "\r\n");
1257 * PRIVATE: cs_insert_filelist
1259 * insert a new cscope database filename into the filelist
1263 cs_insert_filelist(fname
, ppath
, flags
, sb
)
1272 BY_HANDLE_FILE_INFORMATION bhfi
;
1274 vim_memset(&bhfi
, 0, sizeof(bhfi
));
1275 /* On windows 9x GetFileInformationByHandle doesn't work, so skip it */
1276 if (!mch_windows95())
1278 hFile
= CreateFile(fname
, FILE_READ_ATTRIBUTES
, 0, NULL
, OPEN_EXISTING
,
1279 FILE_ATTRIBUTE_NORMAL
, NULL
);
1280 if (hFile
== INVALID_HANDLE_VALUE
)
1284 char *cant_msg
= _("E625: cannot open cscope database: %s");
1285 char *winmsg
= GetWin32Error();
1289 (void)EMSG2(cant_msg
, winmsg
);
1293 /* subst filename if can't get error text */
1294 (void)EMSG2(cant_msg
, fname
);
1298 if (!GetFileInformationByHandle(hFile
, &bhfi
))
1302 (void)EMSG(_("E626: cannot get cscope database information"));
1309 i
= -1; /* can be set to the index of an empty item in csinfo */
1310 for (j
= 0; j
< CSCOPE_MAX_CONNECTIONS
; j
++)
1312 if (csinfo
[j
].fname
!= NULL
1314 && csinfo
[j
].st_dev
== sb
->st_dev
&& csinfo
[j
].st_ino
== sb
->st_ino
1316 /* compare pathnames first */
1317 && ((fullpathcmp(csinfo
[j
].fname
, fname
, FALSE
) & FPC_SAME
)
1318 /* if not Windows 9x, test index file attributes too */
1319 || (!mch_windows95()
1320 && csinfo
[j
].nVolume
== bhfi
.dwVolumeSerialNumber
1321 && csinfo
[j
].nIndexHigh
== bhfi
.nFileIndexHigh
1322 && csinfo
[j
].nIndexLow
== bhfi
.nFileIndexLow
))
1327 (void)EMSG(_("E568: duplicate cscope database not added"));
1331 if (csinfo
[j
].fname
== NULL
&& i
== -1)
1332 i
= j
; /* remember first empty entry */
1338 (void)EMSG(_("E569: maximum number of cscope connections reached"));
1342 if ((csinfo
[i
].fname
= (char *)alloc((unsigned)strlen(fname
)+1)) == NULL
)
1345 (void)strcpy(csinfo
[i
].fname
, (const char *)fname
);
1349 if ((csinfo
[i
].ppath
= (char *)alloc((unsigned)strlen(ppath
) + 1)) == NULL
)
1351 vim_free(csinfo
[i
].fname
);
1352 csinfo
[i
].fname
= NULL
;
1355 (void)strcpy(csinfo
[i
].ppath
, (const char *)ppath
);
1357 csinfo
[i
].ppath
= NULL
;
1361 if ((csinfo
[i
].flags
= (char *)alloc((unsigned)strlen(flags
) + 1)) == NULL
)
1363 vim_free(csinfo
[i
].fname
);
1364 vim_free(csinfo
[i
].ppath
);
1365 csinfo
[i
].fname
= NULL
;
1366 csinfo
[i
].ppath
= NULL
;
1369 (void)strcpy(csinfo
[i
].flags
, (const char *)flags
);
1371 csinfo
[i
].flags
= NULL
;
1374 csinfo
[i
].st_dev
= sb
->st_dev
;
1375 csinfo
[i
].st_ino
= sb
->st_ino
;
1378 csinfo
[i
].nVolume
= bhfi
.dwVolumeSerialNumber
;
1379 csinfo
[i
].nIndexLow
= bhfi
.nFileIndexLow
;
1380 csinfo
[i
].nIndexHigh
= bhfi
.nFileIndexHigh
;
1383 } /* cs_insert_filelist */
1387 * PRIVATE: cs_lookup_cmd
1389 * find cscope command in command table
1399 if (eap
->arg
== NULL
)
1402 /* Store length of eap->arg before it gets modified by strtok(). */
1403 eap_arg_len
= STRLEN(eap
->arg
);
1405 if ((stok
= strtok((char *)(eap
->arg
), (const char *)" ")) == NULL
)
1409 for (cmdp
= cs_cmds
; cmdp
->name
!= NULL
; ++cmdp
)
1411 if (strncmp((const char *)(stok
), cmdp
->name
, len
) == 0)
1415 } /* cs_lookup_cmd */
1431 if ((stok
= strtok((char *)NULL
, (const char *)" ")) == NULL
)
1434 return CSCOPE_FAILURE
;
1437 /* only single digit positive and negative integers are allowed */
1438 if ((strlen(stok
) < 2 && VIM_ISDIGIT((int)(stok
[0])))
1439 || (strlen(stok
) < 3 && stok
[0] == '-'
1440 && VIM_ISDIGIT((int)(stok
[1]))))
1444 /* It must be part of a name. We will try to find a match
1445 * within all the names in the csinfo data structure
1447 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
1449 if (csinfo
[i
].fname
!= NULL
&& strstr(csinfo
[i
].fname
, stok
))
1454 if ((i
>= CSCOPE_MAX_CONNECTIONS
|| i
< -1 || csinfo
[i
].fname
== NULL
)
1458 (void)EMSG2(_("E261: cscope connection %s not found"), stok
);
1464 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
1466 if (csinfo
[i
].fname
)
1467 cs_kill_execute(i
, csinfo
[i
].fname
);
1471 cs_kill_execute(i
, stok
);
1479 * PRIVATE: cs_kill_execute
1481 * Actually kills a specific cscope connection.
1484 cs_kill_execute(i
, cname
)
1485 int i
; /* cscope table index */
1486 char *cname
; /* cscope database name */
1491 (void)smsg_attr(hl_attr(HLF_R
) | MSG_HIST
,
1492 (char_u
*)_("cscope connection %s closed"), cname
);
1494 cs_release_csp(i
, TRUE
);
1499 * PRIVATE: cs_make_vim_style_matches
1501 * convert the cscope output into into a ctags style entry (as might be found
1502 * in a ctags tags file). there's one catch though: cscope doesn't tell you
1503 * the type of the tag you are looking for. for example, in Darren Hiebert's
1504 * ctags (the one that comes with vim), #define's use a line number to find the
1505 * tag in a file while function definitions use a regexp search pattern.
1507 * i'm going to always use the line number because cscope does something
1508 * quirky (and probably other things i don't know about):
1510 * if you have "# define" in your source file, which is
1511 * perfectly legal, cscope thinks you have "#define". this
1512 * will result in a failed regexp search. :(
1514 * besides, even if this particular case didn't happen, the search pattern
1515 * would still have to be modified to escape all the special regular expression
1516 * characters to comply with ctags formatting.
1519 cs_make_vim_style_matches(fname
, slno
, search
, tagstr
)
1525 /* vim style is ctags:
1527 * <tagstr>\t<filename>\t<linenum_or_search>"\t<extra>
1529 * but as mentioned above, we'll always use the line number and
1530 * put the search pattern (if one exists) as "extra"
1532 * buf is used as part of vim's method of handling tags, and
1533 * (i think) vim frees it when you pop your tags and get replaced
1534 * by new ones on the tag stack.
1541 amt
= (int)(strlen(fname
) + strlen(slno
) + strlen(tagstr
) + strlen(search
)+6);
1542 if ((buf
= (char *)alloc(amt
)) == NULL
)
1545 (void)sprintf(buf
, "%s\t%s\t%s;\"\t%s", tagstr
, fname
, slno
, search
);
1549 amt
= (int)(strlen(fname
) + strlen(slno
) + strlen(tagstr
) + 5);
1550 if ((buf
= (char *)alloc(amt
)) == NULL
)
1553 (void)sprintf(buf
, "%s\t%s\t%s;\"", tagstr
, fname
, slno
);
1557 } /* cs_make_vim_style_matches */
1561 * PRIVATE: cs_manage_matches
1563 * this is kind of hokey, but i don't see an easy way round this..
1565 * Store: keep a ptr to the (malloc'd) memory of matches originally
1566 * generated from cs_find(). the matches are originally lines directly
1567 * from cscope output, but transformed to look like something out of a
1568 * ctags. see cs_make_vim_style_matches for more details.
1570 * Get: used only from cs_fgets(), this simulates a vim_fgets() to return
1571 * the next line from the cscope output. it basically keeps track of which
1572 * lines have been "used" and returns the next one.
1574 * Free: frees up everything and resets
1576 * Print: prints the tags
1579 cs_manage_matches(matches
, contexts
, totmatches
, cmd
)
1585 static char **mp
= NULL
;
1586 static char **cp
= NULL
;
1587 static int cnt
= -1;
1588 static int next
= -1;
1594 assert(matches
!= NULL
);
1595 assert(totmatches
> 0);
1596 if (mp
!= NULL
|| cp
!= NULL
)
1597 (void)cs_manage_matches(NULL
, NULL
, -1, Free
);
1629 cs_print_tags_priv(mp
, cp
, cnt
);
1631 default: /* should not reach here */
1632 (void)EMSG(_("E570: fatal error in cs_manage_matches"));
1637 } /* cs_manage_matches */
1641 * PRIVATE: cs_parse_results
1643 * parse cscope output
1646 cs_parse_results(cnumber
, buf
, bufsize
, context
, linenumber
, search
)
1658 if (fgets(buf
, bufsize
, csinfo
[cnumber
].fr_fp
) == NULL
)
1660 if (feof(csinfo
[cnumber
].fr_fp
))
1663 cs_reading_emsg(cnumber
);
1668 /* If the line's too long for the buffer, discard it. */
1669 if ((p
= strchr(buf
, '\n')) == NULL
)
1671 while ((ch
= getc(csinfo
[cnumber
].fr_fp
)) != EOF
&& ch
!= '\n')
1678 * cscope output is in the following format:
1680 * <filename> <context> <line number> <pattern>
1682 if ((name
= strtok((char *)buf
, (const char *)" ")) == NULL
)
1684 if ((*context
= strtok(NULL
, (const char *)" ")) == NULL
)
1686 if ((*linenumber
= strtok(NULL
, (const char *)" ")) == NULL
)
1688 *search
= *linenumber
+ strlen(*linenumber
) + 1; /* +1 to skip \0 */
1691 * If the file is older than the cscope database, that is,
1692 * the database was built since the file was last modified,
1693 * or there wasn't a search string, use the line number.
1695 if (strcmp(*search
, "<unknown>") == 0)
1698 name
= cs_resolve_file(cnumber
, name
);
1702 #ifdef FEAT_QUICKFIX
1704 * PRIVATE: cs_file_results
1706 * write cscope find results to file
1709 cs_file_results(f
, nummatches_a
)
1715 char *search
, *slno
;
1720 buf
= (char *)alloc(CSREAD_BUFSIZE
);
1724 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
1726 if (nummatches_a
[i
] < 1)
1729 for (j
= 0; j
< nummatches_a
[i
]; j
++)
1731 if ((fullname
= cs_parse_results(i
, buf
, CSREAD_BUFSIZE
, &cntx
,
1732 &slno
, &search
)) == NULL
)
1735 context
= (char *)alloc((unsigned)strlen(cntx
)+5);
1736 if (context
== NULL
)
1739 if (strcmp(cntx
, "<global>")==0)
1740 strcpy(context
, "<<global>>");
1742 sprintf(context
, "<<%s>>", cntx
);
1745 fprintf(f
, "%s\t%s\t%s\n", fullname
, slno
, context
);
1747 fprintf(f
, "%s\t%s\t%s %s\n", fullname
, slno
, context
, search
);
1751 } /* for all matches */
1753 (void)cs_read_prompt(i
);
1755 } /* for all cscope connections */
1761 * PRIVATE: cs_fill_results
1763 * get parsed cscope output and calls cs_make_vim_style_matches to convert
1765 * When there are no matches sets "*matches_p" to NULL.
1768 cs_fill_results(tagstr
, totmatches
, nummatches_a
, matches_p
, cntxts_p
, matched
)
1778 char *search
, *slno
;
1780 char **matches
= NULL
;
1781 char **cntxts
= NULL
;
1785 assert(totmatches
> 0);
1787 buf
= (char *)alloc(CSREAD_BUFSIZE
);
1791 if ((matches
= (char **)alloc(sizeof(char *) * totmatches
)) == NULL
)
1793 if ((cntxts
= (char **)alloc(sizeof(char *) * totmatches
)) == NULL
)
1796 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
1798 if (nummatches_a
[i
] < 1)
1801 for (j
= 0; j
< nummatches_a
[i
]; j
++)
1803 if ((fullname
= cs_parse_results(i
, buf
, CSREAD_BUFSIZE
, &cntx
,
1804 &slno
, &search
)) == NULL
)
1807 matches
[totsofar
] = cs_make_vim_style_matches(fullname
, slno
,
1812 if (strcmp(cntx
, "<global>") == 0)
1813 cntxts
[totsofar
] = NULL
;
1815 /* note: if vim_strsave returns NULL, then the context
1816 * will be "<global>", which is misleading.
1818 cntxts
[totsofar
] = (char *)vim_strsave((char_u
*)cntx
);
1820 if (matches
[totsofar
] != NULL
)
1823 } /* for all matches */
1825 (void)cs_read_prompt(i
);
1827 } /* for all cscope connections */
1832 /* No matches, free the arrays and return NULL in "*matches_p". */
1838 *matched
= totsofar
;
1839 *matches_p
= matches
;
1843 } /* cs_fill_results */
1846 /* get the requested path components */
1848 cs_pathcomponents(path
)
1857 s
= path
+ strlen(path
) - 1;
1858 for (i
= 0; i
< p_cspc
; ++i
)
1859 while (s
> path
&& *--s
!= '/'
1865 if ((s
> path
&& *s
== '/')
1867 || (s
> path
&& *s
== '\\')
1875 * PRIVATE: cs_print_tags_priv
1877 * called from cs_manage_matches()
1880 cs_print_tags_priv(matches
, cntxts
, num_matches
)
1886 int bufsize
= 0; /* Track available bufsize */
1889 char *fname
, *lno
, *extra
, *tbuf
;
1891 char *globalcntx
= "GLOBAL";
1892 char *cntxformat
= " <<%s>>";
1894 char *cstag_msg
= _("Cscope tag: %s");
1895 char *csfmt_str
= "%4d %6s ";
1897 assert (num_matches
> 0);
1899 if ((tbuf
= (char *)alloc((unsigned)strlen(matches
[0]) + 1)) == NULL
)
1902 strcpy(tbuf
, matches
[0]);
1903 ptag
= strtok(tbuf
, "\t");
1905 newsize
= (int)(strlen(cstag_msg
) + strlen(ptag
));
1906 buf
= (char *)alloc(newsize
);
1910 (void)sprintf(buf
, cstag_msg
, ptag
);
1911 MSG_PUTS_ATTR(buf
, hl_attr(HLF_T
));
1916 MSG_PUTS_ATTR(_("\n # line"), hl_attr(HLF_T
)); /* strlen is 7 */
1917 msg_advance(msg_col
+ 2);
1918 MSG_PUTS_ATTR(_("filename / context / line\n"), hl_attr(HLF_T
));
1921 for (i
= 0; i
< num_matches
; i
++)
1925 /* if we really wanted to, we could avoid this malloc and strcpy
1926 * by parsing matches[i] on the fly and placing stuff into buf
1927 * directly, but that's too much of a hassle
1929 if ((tbuf
= (char *)alloc((unsigned)strlen(matches
[idx
]) + 1)) == NULL
)
1931 (void)strcpy(tbuf
, matches
[idx
]);
1933 if ((fname
= strtok(tbuf
, (const char *)"\t")) == NULL
)
1935 if ((fname
= strtok(NULL
, (const char *)"\t")) == NULL
)
1937 if ((lno
= strtok(NULL
, (const char *)"\t")) == NULL
)
1939 extra
= strtok(NULL
, (const char *)"\t");
1941 lno
[strlen(lno
)-2] = '\0'; /* ignore ;" at the end */
1943 /* hopefully 'num' (num of matches) will be less than 10^16 */
1944 newsize
= (int)(strlen(csfmt_str
) + 16 + strlen(lno
));
1945 if (bufsize
< newsize
)
1947 buf
= (char *)vim_realloc(buf
, newsize
);
1955 /* csfmt_str = "%4d %6s "; */
1956 (void)sprintf(buf
, csfmt_str
, num
, lno
);
1957 MSG_PUTS_ATTR(buf
, hl_attr(HLF_CM
));
1959 MSG_PUTS_LONG_ATTR(cs_pathcomponents(fname
), hl_attr(HLF_CM
));
1961 /* compute the required space for the context */
1962 if (cntxts
[idx
] != NULL
)
1963 context
= cntxts
[idx
];
1965 context
= globalcntx
;
1966 newsize
= (int)(strlen(context
) + strlen(cntxformat
));
1968 if (bufsize
< newsize
)
1970 buf
= (char *)vim_realloc(buf
, newsize
);
1978 (void)sprintf(buf
, cntxformat
, context
);
1980 /* print the context only if it fits on the same line */
1981 if (msg_col
+ (int)strlen(buf
) >= (int)Columns
)
1990 MSG_PUTS_LONG(extra
);
1993 vim_free(tbuf
); /* only after printing extra due to strtok use */
2001 got_int
= FALSE
; /* don't print any more matches */
2006 } /* for all matches */
2009 } /* cs_print_tags_priv */
2013 * PRIVATE: cs_read_prompt
2015 * read a cscope prompt (basically, skip over the ">> ")
2022 char *buf
= NULL
; /* buffer for possible error message from cscope */
2026 static char *eprompt
= "Press the RETURN key to continue:";
2027 int epromptlen
= (int)strlen(eprompt
);
2030 cs_emsg
= _("E609: Cscope error: %s");
2031 /* compute maximum allowed len for Cscope error message */
2032 maxlen
= (int)(IOSIZE
- strlen(cs_emsg
));
2036 while ((ch
= getc(csinfo
[i
].fr_fp
)) != EOF
&& ch
!= CSCOPE_PROMPT
[0])
2037 /* if there is room and char is printable */
2038 if (bufpos
< maxlen
- 1 && vim_isprintc(ch
))
2040 if (buf
== NULL
) /* lazy buffer allocation */
2041 buf
= (char *)alloc(maxlen
);
2044 /* append character to the message */
2047 if (bufpos
>= epromptlen
2048 && strcmp(&buf
[bufpos
- epromptlen
], eprompt
) == 0)
2050 /* remove eprompt from buf */
2051 buf
[bufpos
- epromptlen
] = NUL
;
2053 /* print message to user */
2054 (void)EMSG2(cs_emsg
, buf
);
2056 /* send RETURN to cscope */
2057 (void)putc('\n', csinfo
[i
].to_fp
);
2058 (void)fflush(csinfo
[i
].to_fp
);
2067 for (n
= 0; n
< (int)strlen(CSCOPE_PROMPT
); ++n
)
2070 ch
= getc(csinfo
[i
].fr_fp
);
2073 PERROR("cs_read_prompt EOF");
2074 if (buf
!= NULL
&& buf
[0] != NUL
)
2075 (void)EMSG2(cs_emsg
, buf
);
2076 else if (p_csverbose
)
2077 cs_reading_emsg(i
); /* don't have additional information */
2078 cs_release_csp(i
, TRUE
);
2080 return CSCOPE_FAILURE
;
2083 if (ch
!= CSCOPE_PROMPT
[n
])
2091 continue; /* didn't find the prompt */
2092 break; /* did find the prompt */
2096 return CSCOPE_SUCCESS
;
2101 * PRIVATE: cs_release_csp
2103 * Does the actual free'ing for the cs ptr with an optional flag of whether
2104 * or not to free the filename. Called by cs_kill and cs_reset.
2107 cs_release_csp(i
, freefnpp
)
2115 * Trying to exit normally (not sure whether it is fit to UNIX cscope
2117 if (csinfo
[i
].to_fp
!= NULL
)
2119 (void)fputs("q\n", csinfo
[i
].to_fp
);
2120 (void)fflush(csinfo
[i
].to_fp
);
2122 if (csinfo
[i
].hProc
!= NULL
)
2124 /* Give cscope a chance to exit normally */
2125 if (WaitForSingleObject(csinfo
[i
].hProc
, 1000) == WAIT_TIMEOUT
)
2126 TerminateProcess(csinfo
[i
].hProc
, 0);
2127 CloseHandle(csinfo
[i
].hProc
);
2131 if (csinfo
[i
].fr_fp
!= NULL
)
2132 (void)fclose(csinfo
[i
].fr_fp
);
2133 if (csinfo
[i
].to_fp
!= NULL
)
2134 (void)fclose(csinfo
[i
].to_fp
);
2137 * Safety check: If the PID would be zero here, the entire X session would
2138 * be killed. -1 and 1 are dangerous as well.
2141 if (csinfo
[i
].pid
> 1)
2143 kill(csinfo
[i
].pid
, SIGTERM
);
2144 (void)waitpid(csinfo
[i
].pid
, &pstat
, 0);
2150 vim_free(csinfo
[i
].fname
);
2151 vim_free(csinfo
[i
].ppath
);
2152 vim_free(csinfo
[i
].flags
);
2156 } /* cs_release_csp */
2162 * calls cs_kill on all cscope connections then reinits
2169 char **dblist
= NULL
, **pplist
= NULL
, **fllist
= NULL
;
2171 char buf
[20]; /* for sprintf " (#%d)" */
2173 /* malloc our db and ppath list */
2174 dblist
= (char **)alloc(CSCOPE_MAX_CONNECTIONS
* sizeof(char *));
2175 pplist
= (char **)alloc(CSCOPE_MAX_CONNECTIONS
* sizeof(char *));
2176 fllist
= (char **)alloc(CSCOPE_MAX_CONNECTIONS
* sizeof(char *));
2177 if (dblist
== NULL
|| pplist
== NULL
|| fllist
== NULL
)
2182 return CSCOPE_FAILURE
;
2185 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
2187 dblist
[i
] = csinfo
[i
].fname
;
2188 pplist
[i
] = csinfo
[i
].ppath
;
2189 fllist
[i
] = csinfo
[i
].flags
;
2190 if (csinfo
[i
].fname
!= NULL
)
2191 cs_release_csp(i
, FALSE
);
2194 /* rebuild the cscope connection list */
2195 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
2197 if (dblist
[i
] != NULL
)
2199 cs_add_common(dblist
[i
], pplist
[i
], fllist
[i
]);
2202 /* don't use smsg_attr() because we want to display the
2203 * connection number in the same line as
2204 * "Added cscope database..."
2206 sprintf(buf
, " (#%d)", i
);
2207 MSG_PUTS_ATTR(buf
, hl_attr(HLF_R
));
2210 vim_free(dblist
[i
]);
2211 vim_free(pplist
[i
]);
2212 vim_free(fllist
[i
]);
2219 MSG_ATTR(_("All cscope databases reset"), hl_attr(HLF_R
) | MSG_HIST
);
2220 return CSCOPE_SUCCESS
;
2225 * PRIVATE: cs_resolve_file
2227 * construct the full pathname to a file found in the cscope database.
2228 * (Prepends ppath, if there is one and if it's not already prepended,
2229 * otherwise just uses the name found.)
2231 * we need to prepend the prefix because on some cscope's (e.g., the one that
2232 * ships with Solaris 2.6), the output never has the prefix prepended.
2233 * contrast this with my development system (Digital Unix), which does.
2236 cs_resolve_file(i
, name
)
2244 * ppath is freed when we destroy the cscope connection.
2245 * fullname is freed after cs_make_vim_style_matches, after it's been
2246 * copied into the tag buffer used by vim
2248 len
= (int)(strlen(name
) + 2);
2249 if (csinfo
[i
].ppath
!= NULL
)
2250 len
+= (int)strlen(csinfo
[i
].ppath
);
2252 if ((fullname
= (char *)alloc(len
)) == NULL
)
2256 * note/example: this won't work if the cscope output already starts
2257 * "../.." and the prefix path is also "../..". if something like this
2258 * happens, you are screwed up and need to fix how you're using cscope.
2260 if (csinfo
[i
].ppath
!= NULL
&&
2261 (strncmp(name
, csinfo
[i
].ppath
, strlen(csinfo
[i
].ppath
)) != 0) &&
2264 && name
[0] != '\\' && name
[1] != ':'
2267 (void)sprintf(fullname
, "%s/%s", csinfo
[i
].ppath
, name
);
2269 (void)sprintf(fullname
, "%s", name
);
2272 } /* cs_resolve_file */
2278 * show all cscope connections
2286 if (cs_cnt_connections() == 0)
2287 MSG_PUTS(_("no cscope connections\n"));
2291 _(" # pid database name prepend path\n"),
2293 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
2295 if (csinfo
[i
].fname
== NULL
)
2298 if (csinfo
[i
].ppath
!= NULL
)
2299 (void)smsg((char_u
*)"%2d %-5ld %-34s %-32s",
2300 i
, (long)csinfo
[i
].pid
, csinfo
[i
].fname
, csinfo
[i
].ppath
);
2302 (void)smsg((char_u
*)"%2d %-5ld %-34s <none>",
2303 i
, (long)csinfo
[i
].pid
, csinfo
[i
].fname
);
2308 return CSCOPE_SUCCESS
;
2315 * Only called when VIM exits to quit any cscope sessions.
2322 for (i
= 0; i
< CSCOPE_MAX_CONNECTIONS
; i
++)
2323 cs_release_csp(i
, TRUE
);
2326 #endif /* FEAT_CSCOPE */