1 /* $NetBSD: ex_cscope.c,v 1.4 2009/01/18 03:45:50 lukem Exp $ */
4 * Copyright (c) 1994, 1996
5 * Rob Mayoff. All rights reserved.
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 static const char sccsid
[] = "Id: ex_cscope.c,v 10.21 2003/11/05 17:11:54 skimo Exp (Berkeley) Date: 2003/11/05 17:11:54";
18 #include <sys/param.h>
19 #include <sys/types.h> /* XXX: param.h may not have included types.h */
20 #include <sys/queue.h>
25 #include <bitstring.h>
37 #include "../common/common.h"
38 #include "pathnames.h"
41 #define CSCOPE_DBFILE "cscope.out"
42 #define CSCOPE_PATHS "cscope.tpath"
45 * 0name find all uses of name
46 * 1name find definition of name
47 * 2name find all function calls made from name
48 * 3name find callers of name
49 * 4string find text string (cscope 12.9)
50 * 4name find assignments to name (cscope 13.3)
51 * 5pattern change pattern -- NOT USED
52 * 6pattern find pattern
53 * 7name find files with name as substring
54 * 8name find files #including name
57 find c|d|e|f|g|i|s|t buffer|pattern\n\
58 c: find callers of name\n\
59 d: find all function calls made from name\n\
61 f: find files with name as substring\n\
62 g: find definition of name\n\
63 i: find files #including name\n\
64 s: find all uses of name\n\
65 t: find assignments to name"
67 static int cscope_add
__P((SCR
*, EXCMD
*, const CHAR_T
*));
68 static int cscope_find
__P((SCR
*, EXCMD
*, const CHAR_T
*));
69 static int cscope_help
__P((SCR
*, EXCMD
*, const CHAR_T
*));
70 static int cscope_kill
__P((SCR
*, EXCMD
*, const CHAR_T
*));
71 static int cscope_reset
__P((SCR
*, EXCMD
*, const CHAR_T
*));
75 int (*function
) __P((SCR
*, EXCMD
*, const CHAR_T
*));
77 const char *usage_msg
;
80 static CC
const cscope_cmds
[] = {
82 "Add a new cscope database", "add file | directory" },
83 { "find", cscope_find
,
84 "Query the databases for a pattern", FINDHELP
},
85 { "help", cscope_help
,
86 "Show help for cscope commands", "help [command]" },
87 { "kill", cscope_kill
,
88 "Kill a cscope connection", "kill number" },
89 { "reset", cscope_reset
,
90 "Discard all current cscope connections", "reset" },
91 { NULL
, NULL
, NULL
, NULL
}
94 static TAGQ
*create_cs_cmd
__P((SCR
*, const char *, size_t *));
95 static int csc_help
__P((SCR
*, const char *));
96 static void csc_file
__P((SCR
*,
97 CSC
*, char *, char **, size_t *, int *));
98 static int get_paths
__P((SCR
*, CSC
*));
99 static CC
const *lookup_ccmd
__P((const char *));
100 static int parse
__P((SCR
*, CSC
*, TAGQ
*, int *));
101 static int read_prompt
__P((SCR
*, CSC
*));
102 static int run_cscope
__P((SCR
*, CSC
*, const char *));
103 static int start_cscopes
__P((SCR
*, EXCMD
*));
104 static int terminate
__P((SCR
*, CSC
*, int));
108 * Perform an ex cscope.
110 * PUBLIC: int ex_cscope __P((SCR *, EXCMD *));
113 ex_cscope(SCR
*sp
, EXCMD
*cmdp
)
123 /* Initialize the default cscope directories. */
125 if (!F_ISSET(exp
, EXP_CSCINIT
) && start_cscopes(sp
, cmdp
))
127 F_SET(exp
, EXP_CSCINIT
);
129 /* Skip leading whitespace. */
130 for (p
= cmdp
->argv
[0]->bp
, i
= cmdp
->argv
[0]->len
; i
> 0; --i
, ++p
)
136 /* Skip the command to any arguments. */
137 for (cmd
= p
; i
> 0; --i
, ++p
)
142 for (; *p
&& isspace(*p
); ++p
);
145 INT2CHAR(sp
, cmd
, STRLEN(cmd
) + 1, np
, nlen
);
146 if ((ccp
= lookup_ccmd(np
)) == NULL
) {
147 usage
: msgq(sp
, M_ERR
, "309|Use \"cscope help\" for help");
151 /* Call the underlying function. */
152 return (ccp
->function(sp
, cmdp
, p
));
157 * Initialize the cscope package.
160 start_cscopes(SCR
*sp
, EXCMD
*cmdp
)
163 char *bp
, *cscopes
, *p
, *t
;
170 * If the CSCOPE_DIRS environment variable is set, we treat it as a
171 * list of cscope directories that we're using, similar to the tags
175 * This should probably be an edit option, although that implies that
176 * we start/stop cscope processes periodically, instead of once when
179 if ((cscopes
= getenv("CSCOPE_DIRS")) == NULL
)
181 len
= strlen(cscopes
);
182 GET_SPACE_RETC(sp
, bp
, blen
, len
);
183 memcpy(bp
, cscopes
, len
+ 1);
185 for (cscopes
= t
= bp
; (p
= strsep(&t
, "\t :")) != NULL
;)
187 CHAR2INT(sp
, p
, strlen(p
) + 1, wp
, wlen
);
188 (void)cscope_add(sp
, cmdp
, wp
);
191 FREE_SPACE(sp
, bp
, blen
);
197 * The cscope add command.
200 cscope_add(SCR
*sp
, EXCMD
*cmdp
, const CHAR_T
*dname
)
208 char path
[MAXPATHLEN
];
216 * 0 additional args: usage.
217 * 1 additional args: matched a file.
218 * >1 additional args: object, too many args.
220 cur_argc
= cmdp
->argc
;
221 if (argv_exp2(sp
, cmdp
, dname
, STRLEN(dname
))) {
224 if (cmdp
->argc
== cur_argc
) {
225 (void)csc_help(sp
, "add");
228 if (cmdp
->argc
== cur_argc
+ 1)
229 dname
= cmdp
->argv
[cur_argc
]->bp
;
231 ex_emsg(sp
, np
, EXM_FILECOUNT
);
235 INT2CHAR(sp
, dname
, STRLEN(dname
)+1, np
, nlen
);
238 * The user can specify a specific file (so they can have multiple
239 * Cscope databases in a single directory) or a directory. If the
240 * file doesn't exist, we're done. If it's a directory, append the
241 * standard database file name and try again. Store the directory
242 * name regardless so that we can use it as a base for searches.
245 msgq(sp
, M_SYSERR
, "%s", np
);
248 if (S_ISDIR(sb
.st_mode
)) {
249 (void)snprintf(path
, sizeof(path
),
250 "%s/%s", np
, CSCOPE_DBFILE
);
251 if (stat(path
, &sb
)) {
252 msgq(sp
, M_SYSERR
, "%s", path
);
255 dbname
= CSCOPE_DBFILE
;
256 } else if ((npp
= strrchr(np
, '/')) != NULL
) {
264 /* Allocate a cscope connection structure and initialize its fields. */
266 CALLOC_RET(sp
, csc
, CSC
*, 1, sizeof(CSC
) + len
);
267 csc
->dname
= csc
->buf
;
269 memcpy(csc
->dname
, np
, len
);
270 csc
->mtime
= sb
.st_mtime
;
272 /* Get the search paths for the cscope. */
273 if (get_paths(sp
, csc
))
276 /* Start the cscope process. */
277 if (run_cscope(sp
, csc
, dbname
))
281 * Add the cscope connection to the screen's list. From now on,
282 * on error, we have to call terminate, which expects the csc to
285 LIST_INSERT_HEAD(&exp
->cscq
, csc
, q
);
287 /* Read the initial prompt from the cscope to make sure it's okay. */
288 return read_prompt(sp
, csc
);
296 * Get the directories to search for the files associated with this
300 get_paths(SCR
*sp
, CSC
*csc
)
305 char *p
, **pathp
, buf
[MAXPATHLEN
* 2];
310 * If there's a cscope directory with a file named CSCOPE_PATHS, it
311 * contains a colon-separated list of paths in which to search for
312 * files returned by cscope.
315 * These paths are absolute paths, and not relative to the cscope
316 * directory. To fix this, rewrite the each path using the cscope
317 * directory as a prefix.
319 (void)snprintf(buf
, sizeof(buf
), "%s/%s", csc
->dname
, CSCOPE_PATHS
);
320 if (stat(buf
, &sb
) == 0) {
321 /* Read in the CSCOPE_PATHS file. */
323 MALLOC_RET(sp
, csc
->pbuf
, char *, len
+ 1);
324 if ((fd
= open(buf
, O_RDONLY
, 0)) < 0 ||
325 (size_t)read(fd
, csc
->pbuf
, len
) != len
) {
326 msgq_str(sp
, M_SYSERR
, buf
, "%s");
332 csc
->pbuf
[len
] = '\0';
334 /* Count up the entries. */
335 for (nentries
= 0, p
= csc
->pbuf
; *p
!= '\0'; ++p
)
336 if (p
[0] == ':' && p
[1] != '\0')
339 /* Build an array of pointers to the paths. */
341 csc
->paths
, char **, nentries
+ 1, sizeof(char **));
342 for (pathp
= csc
->paths
, p
= strtok(csc
->pbuf
, ":");
343 p
!= NULL
; p
= strtok(NULL
, ":"))
349 * If the CSCOPE_PATHS file doesn't exist, we look for files
350 * relative to the cscope directory.
352 if ((csc
->pbuf
= strdup(csc
->dname
)) == NULL
) {
353 msgq(sp
, M_SYSERR
, NULL
);
356 CALLOC_GOTO(sp
, csc
->paths
, char **, 2, sizeof(char *));
357 csc
->paths
[0] = csc
->pbuf
;
361 if (csc
->pbuf
!= NULL
) {
370 * Fork off the cscope process.
373 run_cscope(SCR
*sp
, CSC
*csc
, const char *dbname
)
375 int to_cs
[2], from_cs
[2];
376 char cmd
[MAXPATHLEN
* 2];
379 * Cscope reads from to_cs[0] and writes to from_cs[1]; vi reads from
380 * from_cs[0] and writes to to_cs[1].
382 to_cs
[0] = to_cs
[1] = from_cs
[0] = from_cs
[0] = -1;
383 if (pipe(to_cs
) < 0 || pipe(from_cs
) < 0) {
384 msgq(sp
, M_SYSERR
, "pipe");
387 switch (csc
->pid
= vfork()) {
389 msgq(sp
, M_SYSERR
, "vfork");
390 err
: if (to_cs
[0] != -1)
391 (void)close(to_cs
[0]);
393 (void)close(to_cs
[1]);
394 if (from_cs
[0] != -1)
395 (void)close(from_cs
[0]);
396 if (from_cs
[1] != -1)
397 (void)close(from_cs
[1]);
399 case 0: /* child: run cscope. */
400 (void)dup2(to_cs
[0], STDIN_FILENO
);
401 (void)dup2(from_cs
[1], STDOUT_FILENO
);
402 (void)dup2(from_cs
[1], STDERR_FILENO
);
404 /* Close unused file descriptors. */
405 (void)close(to_cs
[1]);
406 (void)close(from_cs
[0]);
408 /* Run the cscope command. */
409 #define CSCOPE_CMD_FMT "cd '%s' && exec cscope -dl -f %s"
410 (void)snprintf(cmd
, sizeof(cmd
),
411 CSCOPE_CMD_FMT
, csc
->dname
, dbname
);
412 (void)execl(_PATH_BSHELL
, "sh", "-c", cmd
, (char *)NULL
);
413 msgq_str(sp
, M_SYSERR
, cmd
, "execl: %s");
416 default: /* parent. */
417 /* Close unused file descriptors. */
418 (void)close(to_cs
[0]);
419 (void)close(from_cs
[1]);
422 * Save the file descriptors for later duplication, and
425 csc
->to_fd
= to_cs
[1];
426 csc
->to_fp
= fdopen(to_cs
[1], "w");
427 csc
->from_fd
= from_cs
[0];
428 csc
->from_fp
= fdopen(from_cs
[0], "r");
436 * The cscope find command.
439 cscope_find(SCR
*sp
, EXCMD
*cmdp
, const CHAR_T
*pattern
)
448 int force
, istmp
, matches
;
449 const char *np
= NULL
;
454 /* Check for connections. */
455 if (exp
->cscq
.lh_first
== NULL
) {
456 msgq(sp
, M_ERR
, "310|No cscope connections running");
461 * Allocate all necessary memory before doing anything hard. If the
462 * tags stack is empty, we'll need the `local context' TAGQ structure
467 if (exp
->tq
.cqh_first
== (void *)&exp
->tq
) {
468 /* Initialize the `local context' tag queue structure. */
469 CALLOC_GOTO(sp
, rtqp
, TAGQ
*, 1, sizeof(TAGQ
));
470 CIRCLEQ_INIT(&rtqp
->tagq
);
472 /* Initialize and link in its tag structure. */
473 CALLOC_GOTO(sp
, rtp
, TAG
*, 1, sizeof(TAG
));
474 CIRCLEQ_INSERT_HEAD(&rtqp
->tagq
, rtp
, q
);
478 /* Create the cscope command. */
479 INT2CHAR(sp
, pattern
, STRLEN(pattern
) + 1, np
, nlen
);
481 if ((tqp
= create_cs_cmd(sp
, np
, &search
)) == NULL
)
485 * Stick the current context in a convenient place, we'll lose it
486 * when we switch files.
491 istmp
= F_ISSET(sp
->frp
, FR_TMPFILE
) && !F_ISSET(cmdp
, E_NEWSCREEN
);
493 /* Search all open connections for a match. */
495 for (csc
= exp
->cscq
.lh_first
; csc
!= NULL
; csc
= csc_next
) {
496 /* Copy csc->q.lh_next here in case csc is killed. */
497 csc_next
= csc
->q
.le_next
;
500 * Send the command to the cscope program. (We skip the
501 * first two bytes of the command, because we stored the
502 * search cscope command character and a leading space
505 (void)fprintf(csc
->to_fp
, "%zu%s\n", search
, tqp
->tag
+ 2);
506 (void)fflush(csc
->to_fp
);
508 /* Read the output. */
509 if (parse(sp
, csc
, tqp
, &matches
)) {
518 msgq(sp
, M_INFO
, "278|No matches for query");
522 tqp
->current
= tqp
->tagq
.cqh_first
;
524 /* Try to switch to the first tag. */
525 force
= FL_ISSET(cmdp
->iflags
, E_C_FORCE
);
526 if (F_ISSET(cmdp
, E_NEWSCREEN
)) {
527 if (ex_tag_Nswitch(sp
, tqp
->current
, force
))
530 /* Everything else gets done in the new screen. */
534 if (ex_tag_nswitch(sp
, tqp
->current
, force
))
538 * If this is the first tag, put a `current location' queue entry
539 * in place, so we can pop all the way back to the current mark.
540 * Note, it doesn't point to much of anything, it's a placeholder.
542 if (exp
->tq
.cqh_first
== (void *)&exp
->tq
) {
543 CIRCLEQ_INSERT_HEAD(&exp
->tq
, rtqp
, q
);
545 rtqp
= exp
->tq
.cqh_first
;
547 /* Link the current TAGQ structure into place. */
548 CIRCLEQ_INSERT_HEAD(&exp
->tq
, tqp
, q
);
550 (void)cscope_search(sp
, tqp
, tqp
->current
);
553 * Move the current context from the temporary save area into the
556 * If we were in a temporary file, we don't have a context to which
557 * we can return, so just make it be the same as what we're moving
558 * to. It will be a little odd that ^T doesn't change anything, but
559 * I don't think it's a big deal.
562 rtqp
->current
->frp
= sp
->frp
;
563 rtqp
->current
->lno
= sp
->lno
;
564 rtqp
->current
->cno
= sp
->cno
;
566 rtqp
->current
->frp
= frp
;
567 rtqp
->current
->lno
= lno
;
568 rtqp
->current
->cno
= cno
;
586 * Build a cscope command, creating and initializing the base TAGQ.
589 create_cs_cmd(SCR
*sp
, const char *pattern
, size_t *searchp
)
597 * Cscope supports a "change pattern" command which we never use,
598 * cscope command 5. Set CSCOPE_QUERIES[5] to " " since the user
599 * can't pass " " as the first character of pattern. That way the
600 * user can't ask for pattern 5 so we don't need any special-case
603 #define CSCOPE_QUERIES "sgdct efi"
608 /* Skip leading blanks, check for command character. */
609 for (; isblank(pattern
[0]); ++pattern
);
610 if (pattern
[0] == '\0' || !isblank(pattern
[1]))
612 for (*searchp
= 0, p
= CSCOPE_QUERIES
;
613 *p
!= '\0' && *p
!= pattern
[0]; ++*searchp
, ++p
);
616 "311|%s: unknown search type: use one of %s",
617 KEY_NAME(sp
, pattern
[0]), CSCOPE_QUERIES
);
621 /* Skip <blank> characters to the pattern. */
622 for (p
= pattern
+ 1; *p
!= '\0' && isblank(*p
); ++p
);
624 usage
: (void)csc_help(sp
, "find");
628 /* The user can specify the contents of a buffer as the pattern. */
630 if (p
[0] == '"' && p
[1] != '\0' && p
[2] == '\0')
631 CBNAME(sp
, cbp
, p
[1]);
633 INT2CHAR(sp
, cbp
->textq
.cqh_first
->lb
,
634 cbp
->textq
.cqh_first
->len
, p
, tlen
);
638 /* Allocate and initialize the TAGQ structure. */
639 CALLOC(sp
, tqp
, TAGQ
*, 1, sizeof(TAGQ
) + tlen
+ 3);
642 CIRCLEQ_INIT(&tqp
->tagq
);
644 tqp
->tag
[0] = pattern
[0];
646 tqp
->tlen
= tlen
+ 2;
647 memcpy(tqp
->tag
+ 2, p
, tlen
);
648 tqp
->tag
[tlen
+ 2] = '\0';
649 F_SET(tqp
, TAG_CSCOPE
);
656 * Parse the cscope output.
659 parse(SCR
*sp
, CSC
*csc
, TAGQ
*tqp
, int *matchesp
)
663 size_t dlen
, nlen
= 0, slen
= 0;
664 int ch
, i
, isolder
= 0, nlines
;
665 char *dname
= NULL
, *name
= NULL
, *search
, *p
, *t
, dummy
[2], buf
[2048];
668 if (!fgets(buf
, sizeof(buf
), csc
->from_fp
))
672 * If the database is out of date, or there's some other
673 * problem, cscope will output error messages before the
674 * number-of-lines output. Display/discard any output
675 * that doesn't match what we want.
677 #define CSCOPE_NLINES_FMT "cscope: %d lines%1[\n]"
678 if (sscanf(buf
, CSCOPE_NLINES_FMT
, &nlines
, dummy
) == 2)
680 if ((p
= strchr(buf
, '\n')) != NULL
)
682 msgq(sp
, M_ERR
, "%s: \"%s\"", csc
->dname
, buf
);
686 if (fgets(buf
, sizeof(buf
), csc
->from_fp
) == NULL
)
689 /* If the line's too long for the buffer, discard it. */
690 if ((p
= strchr(buf
, '\n')) == NULL
) {
691 while ((ch
= getc(csc
->from_fp
)) != EOF
&& ch
!= '\n');
697 * The cscope output is in the following format:
699 * <filename> <context> <line number> <pattern>
701 * Figure out how long everything is so we can allocate in one
702 * swell foop, but discard anything that looks wrong.
705 i
< 3 && (t
= strsep(&p
, "\t ")) != NULL
; ++i
)
707 case 0: /* Filename. */
711 case 1: /* Context. */
713 case 2: /* Line number. */
714 slno
= (db_recno_t
)atol(t
);
717 if (i
!= 3 || p
== NULL
|| t
== NULL
)
720 /* The rest of the string is the search pattern. */
724 /* Resolve the file name. */
725 csc_file(sp
, csc
, name
, &dname
, &dlen
, &isolder
);
728 * If the file is older than the cscope database, that is,
729 * the database was built since the file was last modified,
730 * or there wasn't a search string, use the line number.
732 if (isolder
|| strcmp(search
, "<unknown>") == 0) {
738 * Allocate and initialize a tag structure plus the variable
739 * length cscope information that follows it.
742 TAG
*, 1, sizeof(TAG
) + dlen
+ 2 + nlen
+ 1 + slen
+ 1);
743 tp
->fname
= (char *)tp
->buf
;
745 memcpy(tp
->fname
, dname
, dlen
);
746 tp
->fname
[dlen
] = '/';
749 memcpy(tp
->fname
+ dlen
, name
, nlen
+ 1);
750 tp
->fnlen
= dlen
+ nlen
;
753 tp
->search
= (CHAR_T
*)(tp
->fname
+ tp
->fnlen
+ 1);
754 MEMCPYW(tp
->search
, search
, (tp
->slen
= slen
) + 1);
756 CIRCLEQ_INSERT_TAIL(&tqp
->tagq
, tp
, q
);
761 return read_prompt(sp
, csc
);
763 io_err
: if (feof(csc
->from_fp
))
765 msgq_str(sp
, M_SYSERR
, "%s", csc
->dname
);
766 terminate(sp
, csc
, 0);
772 * Search for the right path to this file.
775 csc_file(SCR
*sp
, CSC
*csc
, char *name
, char **dirp
, size_t *dlenp
, int *isolderp
)
778 char **pp
, buf
[MAXPATHLEN
];
781 * Check for the file in all of the listed paths. If we don't
782 * find it, we simply return it unchanged. We have to do this
783 * now, even though it's expensive, because if the user changes
784 * directories, we can't change our minds as to where the file
787 for (pp
= csc
->paths
; *pp
!= NULL
; ++pp
) {
788 (void)snprintf(buf
, sizeof(buf
), "%s/%s", *pp
, name
);
789 if (stat(buf
, &sb
) == 0) {
791 *dlenp
= strlen(*pp
);
792 *isolderp
= sb
.st_mtime
< csc
->mtime
;
801 * The cscope help command.
804 cscope_help(SCR
*sp
, EXCMD
*cmdp
, const CHAR_T
*subcmd
)
809 INT2CHAR(sp
, subcmd
, STRLEN(subcmd
) + 1, np
, nlen
);
810 return (csc_help(sp
, np
));
815 * Display help/usage messages.
818 csc_help(SCR
*sp
, const char *cmd
)
822 if (cmd
!= NULL
&& *cmd
!= '\0') {
823 if ((ccp
= lookup_ccmd(cmd
)) == NULL
) {
825 "%s doesn't match any cscope command\n", cmd
);
829 "Command: %s (%s)\n", ccp
->name
, ccp
->help_msg
);
830 ex_printf(sp
, " Usage: %s\n", ccp
->usage_msg
);
835 ex_printf(sp
, "cscope commands:\n");
836 for (ccp
= cscope_cmds
; ccp
->name
!= NULL
; ++ccp
)
837 ex_printf(sp
, " %*s: %s\n", 5, ccp
->name
, ccp
->help_msg
);
843 * The cscope kill command.
846 cscope_kill(SCR
*sp
, EXCMD
*cmdp
, const CHAR_T
*cn
)
851 INT2CHAR(sp
, cn
, STRLEN(cn
) + 1, np
, nlen
);
852 return (terminate(sp
, NULL
, atoi(np
)));
857 * Detach from a cscope process.
860 terminate(SCR
*sp
, CSC
*csc
, int n
)
868 * We either get a csc structure or a number. If not provided a
869 * csc structure, find the right one.
874 for (i
= 1, csc
= exp
->cscq
.lh_first
;
875 csc
!= NULL
; csc
= csc
->q
.le_next
, i
++)
879 badno
: msgq(sp
, M_ERR
, "312|%d: no such cscope session", n
);
886 * Theoretically, we have the only file descriptors to the process,
887 * so closing them should let it exit gracefully, deleting temporary
888 * files, etc. The original vi cscope integration sent the cscope
889 * connection a SIGTERM signal, so I'm not sure if closing the file
890 * descriptors is sufficient.
892 if (csc
->from_fp
!= NULL
)
893 (void)fclose(csc
->from_fp
);
894 if (csc
->to_fp
!= NULL
)
895 (void)fclose(csc
->to_fp
);
896 (void)waitpid(csc
->pid
, &pstat
, 0);
898 /* Discard cscope connection information. */
900 if (csc
->pbuf
!= NULL
)
902 if (csc
->paths
!= NULL
)
910 * The cscope reset command.
913 cscope_reset(SCR
*sp
, EXCMD
*cmdp
, const CHAR_T
*notusedp
)
917 for (exp
= EXP(sp
); exp
->cscq
.lh_first
!= NULL
;) {
918 static CHAR_T one
[] = {'1', 0};
919 if (cscope_kill(sp
, cmdp
, one
))
927 * Display current connections.
929 * PUBLIC: int cscope_display __P((SCR *));
932 cscope_display(SCR
*sp
)
939 if (exp
->cscq
.lh_first
== NULL
) {
940 ex_printf(sp
, "No cscope connections.\n");
944 csc
= exp
->cscq
.lh_first
; csc
!= NULL
; ++i
, csc
= csc
->q
.le_next
)
946 "%2d %s (process %lu)\n", i
, csc
->dname
, (u_long
)csc
->pid
);
952 * Search a file for a cscope entry.
954 * PUBLIC: int cscope_search __P((SCR *, TAGQ *, TAG *));
957 cscope_search(SCR
*sp
, TAGQ
*tqp
, TAG
*tp
)
961 /* If we don't have a search pattern, use the line number. */
962 if (tp
->search
== NULL
) {
963 if (!db_exist(sp
, tp
->slno
)) {
964 tag_msg(sp
, TAG_BADLNO
, tqp
->tag
);
970 * Search for the tag; cheap fallback for C functions
971 * if the name is the same but the arguments have changed.
975 if (f_search(sp
, &m
, &m
,
976 tp
->search
, tp
->slen
, NULL
, SEARCH_CSCOPE
| SEARCH_FIRST
)) {
977 tag_msg(sp
, TAG_SEARCH
, tqp
->tag
);
983 * Historically, tags set the search direction if it wasn't
986 if (sp
->searchdir
== NOTSET
)
987 sp
->searchdir
= FORWARD
;
992 * Tags move to the first non-blank, NOT the search pattern start.
996 (void)nonblank(sp
, sp
->lno
, &sp
->cno
);
1003 * Return a pointer to the command structure.
1006 lookup_ccmd(const char *name
)
1012 for (ccp
= cscope_cmds
; ccp
->name
!= NULL
; ++ccp
)
1013 if (strncmp(name
, ccp
->name
, len
) == 0)
1020 * Read a prompt from cscope.
1023 read_prompt(SCR
*sp
, CSC
*csc
)
1027 #define CSCOPE_PROMPT ">> "
1030 getc(csc
->from_fp
)) != EOF
&& ch
!= CSCOPE_PROMPT
[0]);
1032 terminate(sp
, csc
, 0);
1035 if (getc(csc
->from_fp
) != CSCOPE_PROMPT
[1])
1037 if (getc(csc
->from_fp
) != CSCOPE_PROMPT
[2])