docs/*/Makefile: create html subdir if needed
[nvi.git] / ex / ex_display.c
blob154b71cd7be230729c7523ae6fdd55cb98e08b94
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: ex_display.c,v 10.15 2001/06/25 15:19:15 skimo Exp $ (Berkeley) $Date: 2001/06/25 15:19:15 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
20 #include <ctype.h>
21 #include <limits.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "../common/common.h"
26 #include "tag.h"
28 static int bdisplay __P((SCR *));
29 static void db __P((SCR *, CB *, u_char *));
32 * ex_display -- :display b[uffers] | c[onnections] | s[creens] | t[ags]
34 * Display cscope connections, buffers, tags or screens.
36 * PUBLIC: int ex_display __P((SCR *, EXCMD *));
38 int
39 ex_display(SCR *sp, EXCMD *cmdp)
41 switch (cmdp->argv[0]->bp[0]) {
42 case 'b':
43 #undef ARG
44 #define ARG "buffers"
45 if (cmdp->argv[0]->len >= sizeof(ARG) ||
46 memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len))
47 break;
48 return (bdisplay(sp));
49 case 'c':
50 #undef ARG
51 #define ARG "connections"
52 if (cmdp->argv[0]->len >= sizeof(ARG) ||
53 memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len))
54 break;
55 return (cscope_display(sp));
56 case 's':
57 #undef ARG
58 #define ARG "screens"
59 if (cmdp->argv[0]->len >= sizeof(ARG) ||
60 memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len))
61 break;
62 return (ex_sdisplay(sp));
63 case 't':
64 #undef ARG
65 #define ARG "tags"
66 if (cmdp->argv[0]->len >= sizeof(ARG) ||
67 memcmp(cmdp->argv[0]->bp, ARG, cmdp->argv[0]->len))
68 break;
69 return (ex_tag_display(sp));
71 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
72 return (1);
76 * bdisplay --
78 * Display buffers.
80 static int
81 bdisplay(SCR *sp)
83 CB *cbp;
85 if (sp->wp->cutq.lh_first == NULL && sp->wp->dcbp == NULL) {
86 msgq(sp, M_INFO, "123|No cut buffers to display");
87 return (0);
90 /* Display regular cut buffers. */
91 for (cbp = sp->wp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) {
92 if (isdigit(cbp->name))
93 continue;
94 if (cbp->textq.cqh_first != (void *)&cbp->textq)
95 db(sp, cbp, NULL);
96 if (INTERRUPTED(sp))
97 return (0);
99 /* Display numbered buffers. */
100 for (cbp = sp->wp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) {
101 if (!isdigit(cbp->name))
102 continue;
103 if (cbp->textq.cqh_first != (void *)&cbp->textq)
104 db(sp, cbp, NULL);
105 if (INTERRUPTED(sp))
106 return (0);
108 /* Display default buffer. */
109 if ((cbp = sp->wp->dcbp) != NULL)
110 db(sp, cbp, "default buffer");
111 return (0);
115 * db --
116 * Display a buffer.
118 static void
119 db(SCR *sp, CB *cbp, u_char *name)
121 CHAR_T *p;
122 GS *gp;
123 TEXT *tp;
124 size_t len;
126 gp = sp->gp;
127 (void)ex_printf(sp, "********** %s%s\n",
128 name == NULL ? KEY_NAME(sp, cbp->name) : name,
129 F_ISSET(cbp, CB_LMODE) ? " (line mode)" : " (character mode)");
130 for (tp = cbp->textq.cqh_first;
131 tp != (void *)&cbp->textq; tp = tp->q.cqe_next) {
132 for (len = tp->len, p = tp->lb; len--; ++p) {
133 (void)ex_puts(sp, KEY_NAME(sp, *p));
134 if (INTERRUPTED(sp))
135 return;
137 (void)ex_puts(sp, "\n");