2 * Copyright (c) 1994, 1996
3 * Rob Mayoff. All rights reserved.
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid
[] = "$Id: ex_cscope.c,v 10.25 2012/10/04 09:23:03 zy Exp $";
16 #include <sys/types.h>
17 #include <sys/queue.h>
21 #include <bitstring.h>
34 #include "../common/common.h"
35 #include "pathnames.h"
38 #define CSCOPE_DBFILE "cscope.out"
39 #define CSCOPE_PATHS "cscope.tpath"
42 * 0name find all uses of name
43 * 1name find definition of name
44 * 2name find all function calls made from name
45 * 3name find callers of name
46 * 4string find text string (cscope 12.9)
47 * 4name find assignments to name (cscope 13.3)
48 * 5pattern change pattern -- NOT USED
49 * 6pattern find pattern
50 * 7name find files with name as substring
51 * 8name find files #including name
54 find c|d|e|f|g|i|s|t buffer|pattern\n\
55 c: find callers of name\n\
56 d: find all function calls made from name\n\
58 f: find files with name as substring\n\
59 g: find definition of name\n\
60 i: find files #including name\n\
61 s: find all uses of name\n\
62 t: find assignments to name"
64 static int cscope_add(SCR
*, EXCMD
*, CHAR_T
*);
65 static int cscope_find(SCR
*, EXCMD
*, CHAR_T
*);
66 static int cscope_help(SCR
*, EXCMD
*, CHAR_T
*);
67 static int cscope_kill(SCR
*, EXCMD
*, CHAR_T
*);
68 static int cscope_reset(SCR
*, EXCMD
*, CHAR_T
*);
72 int (*function
)(SCR
*, EXCMD
*, CHAR_T
*);
77 static CC
const cscope_cmds
[] = {
79 "Add a new cscope database", "add file | directory" },
80 { "find", cscope_find
,
81 "Query the databases for a pattern", FINDHELP
},
82 { "help", cscope_help
,
83 "Show help for cscope commands", "help [command]" },
84 { "kill", cscope_kill
,
85 "Kill a cscope connection", "kill number" },
86 { "reset", cscope_reset
,
87 "Discard all current cscope connections", "reset" },
91 static TAGQ
*create_cs_cmd(SCR
*, char *, size_t *);
92 static int csc_help(SCR
*, char *);
93 static void csc_file(SCR
*,
94 CSC
*, char *, char **, size_t *, int *);
95 static int get_paths(SCR
*, CSC
*);
96 static CC
const *lookup_ccmd(char *);
97 static int parse(SCR
*, CSC
*, TAGQ
*, int *);
98 static int read_prompt(SCR
*, CSC
*);
99 static int run_cscope(SCR
*, CSC
*, char *);
100 static int start_cscopes(SCR
*, EXCMD
*);
101 static int terminate(SCR
*, CSC
*, int);
105 * Perform an ex cscope.
107 * PUBLIC: int ex_cscope(SCR *, EXCMD *);
110 ex_cscope(SCR
*sp
, EXCMD
*cmdp
)
120 /* Initialize the default cscope directories. */
122 if (!F_ISSET(exp
, EXP_CSCINIT
) && start_cscopes(sp
, cmdp
))
124 F_SET(exp
, EXP_CSCINIT
);
126 /* Skip leading whitespace. */
127 for (p
= cmdp
->argv
[0]->bp
, i
= cmdp
->argv
[0]->len
; i
> 0; --i
, ++p
)
133 /* Skip the command to any arguments. */
134 for (cmd
= p
; i
> 0; --i
, ++p
)
139 for (; *p
&& isspace(*p
); ++p
);
142 INT2CHAR(sp
, cmd
, STRLEN(cmd
) + 1, np
, nlen
);
143 if ((ccp
= lookup_ccmd(np
)) == NULL
) {
144 usage
: msgq(sp
, M_ERR
, "309|Use \"cscope help\" for help");
148 /* Call the underlying function. */
149 return (ccp
->function(sp
, cmdp
, p
));
154 * Initialize the cscope package.
157 start_cscopes(SCR
*sp
, EXCMD
*cmdp
)
160 char *bp
, *cscopes
, *p
, *t
;
167 * If the CSCOPE_DIRS environment variable is set, we treat it as a
168 * list of cscope directories that we're using, similar to the tags
172 * This should probably be an edit option, although that implies that
173 * we start/stop cscope processes periodically, instead of once when
176 if ((cscopes
= getenv("CSCOPE_DIRS")) == NULL
)
178 len
= strlen(cscopes
);
179 GET_SPACE_RETC(sp
, bp
, blen
, len
);
180 memcpy(bp
, cscopes
, len
+ 1);
182 for (cscopes
= t
= bp
; (p
= strsep(&t
, "\t :")) != NULL
;)
184 CHAR2INT(sp
, p
, strlen(p
) + 1, wp
, wlen
);
185 (void)cscope_add(sp
, cmdp
, wp
);
188 FREE_SPACE(sp
, bp
, blen
);
194 * The cscope add command.
197 cscope_add(SCR
*sp
, EXCMD
*cmdp
, CHAR_T
*dname
)
211 * 0 additional args: usage.
212 * 1 additional args: matched a file.
213 * >1 additional args: object, too many args.
215 cur_argc
= cmdp
->argc
;
216 if (argv_exp2(sp
, cmdp
, dname
, STRLEN(dname
))) {
219 if (cmdp
->argc
== cur_argc
) {
220 (void)csc_help(sp
, "add");
223 if (cmdp
->argc
== cur_argc
+ 1)
224 dname
= cmdp
->argv
[cur_argc
]->bp
;
226 ex_emsg(sp
, np
, EXM_FILECOUNT
);
230 INT2CHAR(sp
, dname
, STRLEN(dname
)+1, np
, nlen
);
233 * The user can specify a specific file (so they can have multiple
234 * Cscope databases in a single directory) or a directory. If the
235 * file doesn't exist, we're done. If it's a directory, append the
236 * standard database file name and try again. Store the directory
237 * name regardless so that we can use it as a base for searches.
240 msgq(sp
, M_SYSERR
, "%s", np
);
243 if (S_ISDIR(sb
.st_mode
)) {
244 if ((path
= join(np
, CSCOPE_DBFILE
)) == NULL
) {
245 msgq(sp
, M_SYSERR
, NULL
);
248 if (stat(path
, &sb
)) {
249 msgq(sp
, M_SYSERR
, "%s", path
);
254 dbname
= CSCOPE_DBFILE
;
255 } else if ((dbname
= strrchr(np
, '/')) != NULL
)
262 /* Allocate a cscope connection structure and initialize its fields. */
264 CALLOC_RET(sp
, csc
, CSC
*, 1, sizeof(CSC
) + len
);
265 csc
->dname
= csc
->buf
;
267 memcpy(csc
->dname
, np
, len
);
268 csc
->mtim
= sb
.st_mtimespec
;
270 /* Get the search paths for the cscope. */
271 if (get_paths(sp
, csc
))
274 /* Start the cscope process. */
275 if (run_cscope(sp
, csc
, dbname
))
279 * Add the cscope connection to the screen's list. From now on,
280 * on error, we have to call terminate, which expects the csc to
283 SLIST_INSERT_HEAD(exp
->cscq
, csc
, q
);
285 /* Read the initial prompt from the cscope to make sure it's okay. */
286 return read_prompt(sp
, csc
);
294 * Get the directories to search for the files associated with this
298 get_paths(SCR
*sp
, CSC
*csc
)
303 char *p
, **pathp
, *buf
;
308 * If there's a cscope directory with a file named CSCOPE_PATHS, it
309 * contains a colon-separated list of paths in which to search for
310 * files returned by cscope.
313 * These paths are absolute paths, and not relative to the cscope
314 * directory. To fix this, rewrite the each path using the cscope
315 * directory as a prefix.
317 if ((buf
= join(csc
->dname
, CSCOPE_PATHS
)) == NULL
) {
318 msgq(sp
, M_SYSERR
, NULL
);
321 if (stat(buf
, &sb
) == 0) {
322 /* Read in the CSCOPE_PATHS file. */
324 MALLOC_RET(sp
, csc
->pbuf
, char *, len
+ 1);
325 if ((fd
= open(buf
, O_RDONLY
, 0)) < 0 ||
326 read(fd
, csc
->pbuf
, len
) != len
) {
327 msgq_str(sp
, M_SYSERR
, buf
, "%s");
335 csc
->pbuf
[len
] = '\0';
337 /* Count up the entries. */
338 for (nentries
= 0, p
= csc
->pbuf
; *p
!= '\0'; ++p
)
339 if (p
[0] == ':' && p
[1] != '\0')
342 /* Build an array of pointers to the paths. */
344 csc
->paths
, char **, nentries
+ 1, sizeof(char **));
345 for (pathp
= csc
->paths
, p
= strtok(csc
->pbuf
, ":");
346 p
!= NULL
; p
= strtok(NULL
, ":"))
353 * If the CSCOPE_PATHS file doesn't exist, we look for files
354 * relative to the cscope directory.
356 if ((csc
->pbuf
= strdup(csc
->dname
)) == NULL
) {
357 msgq(sp
, M_SYSERR
, NULL
);
360 CALLOC_GOTO(sp
, csc
->paths
, char **, 2, sizeof(char *));
361 csc
->paths
[0] = csc
->pbuf
;
365 if (csc
->pbuf
!= NULL
) {
374 * Fork off the cscope process.
377 run_cscope(SCR
*sp
, CSC
*csc
, char *dbname
)
379 int to_cs
[2], from_cs
[2];
383 * Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from
384 * from_cs[0] and writes to to_cs[1].
386 to_cs
[0] = to_cs
[1] = from_cs
[0] = from_cs
[1] = -1;
387 if (pipe(to_cs
) < 0 || pipe(from_cs
) < 0) {
388 msgq(sp
, M_SYSERR
, "pipe");
391 switch (csc
->pid
= vfork()) {
394 msgq(sp
, M_SYSERR
, "vfork");
395 err
: if (to_cs
[0] != -1)
396 (void)close(to_cs
[0]);
398 (void)close(to_cs
[1]);
399 if (from_cs
[0] != -1)
400 (void)close(from_cs
[0]);
401 if (from_cs
[1] != -1)
402 (void)close(from_cs
[1]);
404 case 0: /* child: run cscope. */
405 (void)dup2(to_cs
[0], STDIN_FILENO
);
406 (void)dup2(from_cs
[1], STDOUT_FILENO
);
407 (void)dup2(from_cs
[1], STDERR_FILENO
);
409 /* Close unused file descriptors. */
410 (void)close(to_cs
[1]);
411 (void)close(from_cs
[0]);
413 /* Run the cscope command. */
414 #define CSCOPE_CMD_FMT "cd %s && exec cscope -dl -f %s"
415 if ((dn
= quote(csc
->dname
)) == NULL
)
417 if ((dbn
= quote(dbname
)) == NULL
) {
421 (void)asprintf(&cmd
, CSCOPE_CMD_FMT
, dn
, dbn
);
425 nomem
: msgq(sp
, M_SYSERR
, NULL
);
428 (void)execl(_PATH_BSHELL
, "sh", "-c", cmd
, (char *)NULL
);
429 msgq_str(sp
, M_SYSERR
, cmd
, "execl: %s");
433 default: /* parent. */
434 /* Close unused file descriptors. */
435 (void)close(to_cs
[0]);
436 (void)close(from_cs
[1]);
439 * Save the file descriptors for later duplication, and
442 csc
->to_fd
= to_cs
[1];
443 csc
->to_fp
= fdopen(to_cs
[1], "w");
444 csc
->from_fd
= from_cs
[0];
445 csc
->from_fp
= fdopen(from_cs
[0], "r");
453 * The cscope find command.
456 cscope_find(SCR
*sp
, EXCMD
*cmdp
, CHAR_T
*pattern
)
465 int force
, istmp
, matches
;
471 /* Check for connections. */
472 if (SLIST_EMPTY(exp
->cscq
)) {
473 msgq(sp
, M_ERR
, "310|No cscope connections running");
478 * Allocate all necessary memory before doing anything hard. If the
479 * tags stack is empty, we'll need the `local context' TAGQ structure
484 if (TAILQ_EMPTY(exp
->tq
)) {
485 /* Initialize the `local context' tag queue structure. */
486 CALLOC_GOTO(sp
, rtqp
, TAGQ
*, 1, sizeof(TAGQ
));
487 TAILQ_INIT(rtqp
->tagq
);
489 /* Initialize and link in its tag structure. */
490 CALLOC_GOTO(sp
, rtp
, TAG
*, 1, sizeof(TAG
));
491 TAILQ_INSERT_HEAD(rtqp
->tagq
, rtp
, q
);
495 /* Create the cscope command. */
496 INT2CHAR(sp
, pattern
, STRLEN(pattern
) + 1, np
, nlen
);
498 if ((tqp
= create_cs_cmd(sp
, np
, &search
)) == NULL
)
504 * Stick the current context in a convenient place, we'll lose it
505 * when we switch files.
510 istmp
= F_ISSET(sp
->frp
, FR_TMPFILE
) && !F_ISSET(cmdp
, E_NEWSCREEN
);
512 /* Search all open connections for a match. */
514 /* Copy next connect here in case csc is killed. */
515 SLIST_FOREACH_MUTABLE(csc
, exp
->cscq
, q
, csc_next
) {
517 * Send the command to the cscope program. (We skip the
518 * first two bytes of the command, because we stored the
519 * search cscope command character and a leading space
522 (void)fprintf(csc
->to_fp
, "%lu%s\n", search
, tqp
->tag
+ 2);
523 (void)fflush(csc
->to_fp
);
525 /* Read the output. */
526 if (parse(sp
, csc
, tqp
, &matches
))
531 msgq(sp
, M_INFO
, "278|No matches for query");
532 nomatch
: if (rtp
!= NULL
)
540 /* Try to switch to the first tag. */
541 force
= FL_ISSET(cmdp
->iflags
, E_C_FORCE
);
542 if (F_ISSET(cmdp
, E_NEWSCREEN
)) {
543 if (ex_tag_Nswitch(sp
, tqp
->current
, force
))
546 /* Everything else gets done in the new screen. */
550 if (ex_tag_nswitch(sp
, tqp
->current
, force
))
554 * If this is the first tag, put a `current location' queue entry
555 * in place, so we can pop all the way back to the current mark.
556 * Note, it doesn't point to much of anything, it's a placeholder.
558 if (TAILQ_EMPTY(exp
->tq
)) {
559 TAILQ_INSERT_HEAD(exp
->tq
, rtqp
, q
);
561 rtqp
= TAILQ_FIRST(exp
->tq
);
563 /* Link the current TAGQ structure into place. */
564 TAILQ_INSERT_HEAD(exp
->tq
, tqp
, q
);
566 (void)cscope_search(sp
, tqp
, tqp
->current
);
569 * Move the current context from the temporary save area into the
572 * If we were in a temporary file, we don't have a context to which
573 * we can return, so just make it be the same as what we're moving
574 * to. It will be a little odd that ^T doesn't change anything, but
575 * I don't think it's a big deal.
578 rtqp
->current
->frp
= sp
->frp
;
579 rtqp
->current
->lno
= sp
->lno
;
580 rtqp
->current
->cno
= sp
->cno
;
582 rtqp
->current
->frp
= frp
;
583 rtqp
->current
->lno
= lno
;
584 rtqp
->current
->cno
= cno
;
602 * Build a cscope command, creating and initializing the base TAGQ.
605 create_cs_cmd(SCR
*sp
, char *pattern
, size_t *searchp
)
613 * Cscope supports a "change pattern" command which we never use,
614 * cscope command 5. Set CSCOPE_QUERIES[5] to " " since the user
615 * can't pass " " as the first character of pattern. That way the
616 * user can't ask for pattern 5 so we don't need any special-case
619 #define CSCOPE_QUERIES "sgdct efi"
624 /* Skip leading blanks, check for command character. */
625 for (; cmdskip(pattern
[0]); ++pattern
);
626 if (pattern
[0] == '\0' || !cmdskip(pattern
[1]))
628 for (*searchp
= 0, p
= CSCOPE_QUERIES
;
629 *p
!= '\0' && *p
!= pattern
[0]; ++*searchp
, ++p
);
632 "311|%s: unknown search type: use one of %s",
633 KEY_NAME(sp
, pattern
[0]), CSCOPE_QUERIES
);
637 /* Skip <blank> characters to the pattern. */
638 for (p
= pattern
+ 1; *p
!= '\0' && cmdskip(*p
); ++p
);
640 usage
: (void)csc_help(sp
, "find");
644 /* The user can specify the contents of a buffer as the pattern. */
646 if (p
[0] == '"' && p
[1] != '\0' && p
[2] == '\0')
647 CBNAME(sp
, cbp
, p
[1]);
649 INT2CHAR(sp
, TAILQ_FIRST(cbp
->textq
)->lb
,
650 TAILQ_FIRST(cbp
->textq
)->len
, p
, tlen
);
654 /* Allocate and initialize the TAGQ structure. */
655 CALLOC(sp
, tqp
, TAGQ
*, 1, sizeof(TAGQ
) + tlen
+ 3);
658 TAILQ_INIT(tqp
->tagq
);
660 tqp
->tag
[0] = pattern
[0];
662 tqp
->tlen
= tlen
+ 2;
663 memcpy(tqp
->tag
+ 2, p
, tlen
);
664 tqp
->tag
[tlen
+ 2] = '\0';
665 F_SET(tqp
, TAG_CSCOPE
);
672 * Parse the cscope output.
675 parse(SCR
*sp
, CSC
*csc
, TAGQ
*tqp
, int *matchesp
)
679 size_t dlen
, nlen
= 0, slen
= 0;
680 int ch
, i
, isolder
= 0, nlines
;
681 char *dname
= NULL
, *name
= NULL
, *search
, *p
, *t
, dummy
[2], buf
[2048];
686 if (!fgets(buf
, sizeof(buf
), csc
->from_fp
))
690 * If the database is out of date, or there's some other
691 * problem, cscope will output error messages before the
692 * number-of-lines output. Display/discard any output
693 * that doesn't match what we want.
695 #define CSCOPE_NLINES_FMT "cscope: %d lines%1[\n]"
696 if (sscanf(buf
, CSCOPE_NLINES_FMT
, &nlines
, dummy
) == 2)
698 if ((p
= strchr(buf
, '\n')) != NULL
)
700 msgq(sp
, M_ERR
, "%s: \"%s\"", csc
->dname
, buf
);
704 if (fgets(buf
, sizeof(buf
), csc
->from_fp
) == NULL
)
707 /* If the line's too long for the buffer, discard it. */
708 if ((p
= strchr(buf
, '\n')) == NULL
) {
709 while ((ch
= getc(csc
->from_fp
)) != EOF
&& ch
!= '\n');
715 * The cscope output is in the following format:
717 * <filename> <context> <line number> <pattern>
719 * Figure out how long everything is so we can allocate in one
720 * swell foop, but discard anything that looks wrong.
723 i
< 3 && (t
= strsep(&p
, "\t ")) != NULL
; ++i
)
725 case 0: /* Filename. */
729 case 1: /* Context. */
731 case 2: /* Line number. */
732 slno
= (recno_t
)atol(t
);
735 if (i
!= 3 || p
== NULL
|| t
== NULL
)
738 /* The rest of the string is the search pattern. */
742 /* Resolve the file name. */
743 csc_file(sp
, csc
, name
, &dname
, &dlen
, &isolder
);
746 * If the file is older than the cscope database, that is,
747 * the database was built since the file was last modified,
748 * or there wasn't a search string, use the line number.
750 if (isolder
|| strcmp(search
, "<unknown>") == 0) {
756 * Allocate and initialize a tag structure plus the variable
757 * length cscope information that follows it.
760 TAG
*, 1, sizeof(TAG
) + dlen
+ 2 + nlen
+ 1 +
761 (slen
+ 1) * sizeof(CHAR_T
));
762 tp
->fname
= (char *)tp
->buf
;
763 if (dlen
== 1 && *dname
== '.')
765 else if (dlen
!= 0) {
766 memcpy(tp
->fname
, dname
, dlen
);
767 tp
->fname
[dlen
] = '/';
770 memcpy(tp
->fname
+ dlen
, name
, nlen
+ 1);
771 tp
->fnlen
= dlen
+ nlen
;
773 tp
->search
= (CHAR_T
*)(tp
->fname
+ tp
->fnlen
+ 1);
774 CHAR2INT(sp
, search
, slen
+ 1, wp
, wlen
);
775 MEMCPY(tp
->search
, wp
, (tp
->slen
= slen
) + 1);
776 TAILQ_INSERT_TAIL(tqp
->tagq
, tp
, q
);
778 /* Try to preset the tag within the current file. */
779 if (sp
->frp
!= NULL
&& sp
->frp
->name
!= NULL
&&
780 tqp
->current
== NULL
&& !strcmp(tp
->fname
, sp
->frp
->name
))
786 if (tqp
->current
== NULL
)
787 tqp
->current
= TAILQ_FIRST(tqp
->tagq
);
789 return read_prompt(sp
, csc
);
791 io_err
: if (feof(csc
->from_fp
))
793 msgq_str(sp
, M_SYSERR
, "%s", csc
->dname
);
794 terminate(sp
, csc
, 0);
800 * Search for the right path to this file.
803 csc_file(SCR
*sp
, CSC
*csc
, char *name
, char **dirp
, size_t *dlenp
, int *isolderp
)
809 * Check for the file in all of the listed paths. If we don't
810 * find it, we simply return it unchanged. We have to do this
811 * now, even though it's expensive, because if the user changes
812 * directories, we can't change our minds as to where the file
815 for (pp
= csc
->paths
; *pp
!= NULL
; ++pp
) {
816 if ((buf
= join(*pp
, name
)) == NULL
) {
817 msgq(sp
, M_SYSERR
, NULL
);
821 if (stat(buf
, &sb
) == 0) {
824 *dlenp
= strlen(*pp
);
825 *isolderp
= timespeccmp(
826 &sb
.st_mtimespec
, &csc
->mtim
, <);
836 * The cscope help command.
839 cscope_help(SCR
*sp
, EXCMD
*cmdp
, CHAR_T
*subcmd
)
844 INT2CHAR(sp
, subcmd
, STRLEN(subcmd
) + 1, np
, nlen
);
845 return (csc_help(sp
, np
));
850 * Display help/usage messages.
853 csc_help(SCR
*sp
, char *cmd
)
857 if (cmd
!= NULL
&& *cmd
!= '\0')
858 if ((ccp
= lookup_ccmd(cmd
)) == NULL
) {
860 "%s doesn't match any cscope command\n", cmd
);
864 "Command: %s (%s)\n", ccp
->name
, ccp
->help_msg
);
865 ex_printf(sp
, " Usage: %s\n", ccp
->usage_msg
);
869 ex_printf(sp
, "cscope commands:\n");
870 for (ccp
= cscope_cmds
; ccp
->name
!= NULL
; ++ccp
)
871 ex_printf(sp
, " %*s: %s\n", 5, ccp
->name
, ccp
->help_msg
);
877 * The cscope kill command.
880 cscope_kill(SCR
*sp
, EXCMD
*cmdp
, CHAR_T
*cn
)
887 INT2CHAR(sp
, cn
, STRLEN(cn
) + 1, np
, nlen
);
890 return (terminate(sp
, NULL
, n
));
895 * Detach from a cscope process.
898 terminate(SCR
*sp
, CSC
*csc
, int n
)
902 CSC
*cp
, *pre_cp
= NULL
;
907 * We either get a csc structure or a number. Locate and remove
908 * the candidate which matches the structure or the number.
910 if (csc
== NULL
&& n
< 1)
912 SLIST_FOREACH(cp
, exp
->cscq
, q
) {
914 if (csc
== NULL
? i
!= n
: cp
!= csc
) {
918 if (cp
== SLIST_FIRST(exp
->cscq
))
919 SLIST_REMOVE_HEAD(exp
->cscq
, q
);
921 SLIST_REMOVE_AFTER(pre_cp
, q
);
926 badno
: msgq(sp
, M_ERR
, "312|%d: no such cscope session", n
);
932 * Theoretically, we have the only file descriptors to the process,
933 * so closing them should let it exit gracefully, deleting temporary
934 * files, etc. However, the earlier created cscope processes seems
935 * to refuse to quit unless we send a SIGTERM signal.
937 if (csc
->from_fp
!= NULL
)
938 (void)fclose(csc
->from_fp
);
939 if (csc
->to_fp
!= NULL
)
940 (void)fclose(csc
->to_fp
);
942 (void)kill(csc
->pid
, SIGTERM
);
943 (void)waitpid(csc
->pid
, &pstat
, 0);
945 /* Discard cscope connection information. */
946 if (csc
->pbuf
!= NULL
)
948 if (csc
->paths
!= NULL
)
956 * The cscope reset command.
959 cscope_reset(SCR
*sp
, EXCMD
*cmdp
, CHAR_T
*notusedp
)
961 return cscope_end(sp
);
966 * End all cscope connections.
968 * PUBLIC: int cscope_end(SCR *);
975 for (exp
= EXP(sp
); !SLIST_EMPTY(exp
->cscq
);)
976 if (terminate(sp
, NULL
, 1))
983 * Display current connections.
985 * PUBLIC: int cscope_display(SCR *);
988 cscope_display(SCR
*sp
)
995 if (SLIST_EMPTY(exp
->cscq
)) {
996 ex_printf(sp
, "No cscope connections.\n");
999 SLIST_FOREACH(csc
, exp
->cscq
, q
)
1000 ex_printf(sp
, "%2d %s (process %lu)\n",
1001 ++i
, csc
->dname
, (u_long
)csc
->pid
);
1007 * Search a file for a cscope entry.
1009 * PUBLIC: int cscope_search(SCR *, TAGQ *, TAG *);
1012 cscope_search(SCR
*sp
, TAGQ
*tqp
, TAG
*tp
)
1016 /* If we don't have a search pattern, use the line number. */
1017 if (tp
->search
== NULL
) {
1018 if (!db_exist(sp
, tp
->slno
)) {
1019 tag_msg(sp
, TAG_BADLNO
, tqp
->tag
);
1025 * Search for the tag; cheap fallback for C functions
1026 * if the name is the same but the arguments have changed.
1030 if (f_search(sp
, &m
, &m
,
1031 tp
->search
, tp
->slen
, NULL
, SEARCH_CSCOPE
| SEARCH_FILE
)) {
1032 tag_msg(sp
, TAG_SEARCH
, tqp
->tag
);
1038 * Historically, tags set the search direction if it wasn't
1041 if (sp
->searchdir
== NOTSET
)
1042 sp
->searchdir
= FORWARD
;
1047 * Tags move to the first non-blank, NOT the search pattern start.
1051 (void)nonblank(sp
, sp
->lno
, &sp
->cno
);
1058 * Return a pointer to the command structure.
1061 lookup_ccmd(char *name
)
1067 for (ccp
= cscope_cmds
; ccp
->name
!= NULL
; ++ccp
)
1068 if (strncmp(name
, ccp
->name
, len
) == 0)
1075 * Read a prompt from cscope.
1078 read_prompt(SCR
*sp
, CSC
*csc
)
1082 #define CSCOPE_PROMPT ">> "
1085 getc(csc
->from_fp
)) != EOF
&& ch
!= CSCOPE_PROMPT
[0]);
1087 terminate(sp
, csc
, 0);
1090 if (getc(csc
->from_fp
) != CSCOPE_PROMPT
[1])
1092 if (getc(csc
->from_fp
) != CSCOPE_PROMPT
[2])