tools/llvm: Do not build with symbols
[minix3.git] / external / bsd / nvi / dist / ex / ex_display.c
blob19e70f0fe5366c4c7728cfded97e8e9aba693e64
1 /* $NetBSD: ex_display.c,v 1.3 2013/11/25 22:43:46 christos Exp $ */
2 /*-
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
9 */
11 #include "config.h"
13 #ifndef lint
14 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 ";
15 #endif /* not lint */
17 #include <sys/types.h>
18 #include <sys/queue.h>
20 #include <bitstring.h>
21 #include <ctype.h>
22 #include <limits.h>
23 #include <stdio.h>
24 #include <string.h>
26 #include "../common/common.h"
27 #include "tag.h"
29 static int is_prefix __P((ARGS *, const CHAR_T *));
30 static int bdisplay __P((SCR *));
31 static void db __P((SCR *, CB *, const char *));
34 * ex_display -- :display b[uffers] | c[onnections] | s[creens] | t[ags]
36 * Display cscope connections, buffers, tags or screens.
38 * PUBLIC: int ex_display __P((SCR *, EXCMD *));
40 int
41 ex_display(SCR *sp, EXCMD *cmdp)
43 ARGS *arg;
45 arg = cmdp->argv[0];
47 switch (arg->bp[0]) {
48 case L('b'):
49 if (!is_prefix(arg, L("buffers")))
50 break;
51 return (bdisplay(sp));
52 case L('c'):
53 if (!is_prefix(arg, L("connections")))
54 break;
55 return (cscope_display(sp));
56 case L('s'):
57 if (!is_prefix(arg, L("screens")))
58 break;
59 return (ex_sdisplay(sp));
60 case L('t'):
61 if (!is_prefix(arg, L("tags")))
62 break;
63 return (ex_tag_display(sp));
65 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
66 return (1);
70 * is_prefix --
72 * Check that a command argument matches a prefix of a given string.
74 static int
75 is_prefix(ARGS *arg, const CHAR_T *str)
77 return arg->len <= STRLEN(str) && !MEMCMP(arg->bp, str, arg->len);
81 * bdisplay --
83 * Display buffers.
85 static int
86 bdisplay(SCR *sp)
88 CB *cbp;
90 if (LIST_EMPTY(&sp->wp->cutq) && sp->wp->dcbp == NULL) {
91 msgq(sp, M_INFO, "123|No cut buffers to display");
92 return (0);
95 /* Display regular cut buffers. */
96 LIST_FOREACH(cbp, &sp->wp->cutq, q) {
97 if (ISDIGIT(cbp->name))
98 continue;
99 if (!TAILQ_EMPTY(&cbp->textq))
100 db(sp, cbp, NULL);
101 if (INTERRUPTED(sp))
102 return (0);
104 /* Display numbered buffers. */
105 LIST_FOREACH(cbp, &sp->wp->cutq, q) {
106 if (!ISDIGIT(cbp->name))
107 continue;
108 if (!TAILQ_EMPTY(&cbp->textq))
109 db(sp, cbp, NULL);
110 if (INTERRUPTED(sp))
111 return (0);
113 /* Display default buffer. */
114 if ((cbp = sp->wp->dcbp) != NULL)
115 db(sp, cbp, "default buffer");
116 return (0);
120 * db --
121 * Display a buffer.
123 static void
124 db(SCR *sp, CB *cbp, const char *np)
126 CHAR_T *p;
127 TEXT *tp;
128 size_t len;
129 const unsigned char *name = (const void *)np;
131 (void)ex_printf(sp, "********** %s%s\n",
132 name == NULL ? KEY_NAME(sp, cbp->name) : name,
133 F_ISSET(cbp, CB_LMODE) ? " (line mode)" : " (character mode)");
134 TAILQ_FOREACH(tp, &cbp->textq, q) {
135 for (len = tp->len, p = tp->lb; len--; ++p) {
136 (void)ex_puts(sp, (char *)KEY_NAME(sp, *p));
137 if (INTERRUPTED(sp))
138 return;
140 (void)ex_puts(sp, "\n");