Remove building with NOCRYPTO option
[minix.git] / external / bsd / nvi / dist / ex / ex_display.c
blob711a9314c82bbcb006f860801cf2c0f826354bd7
1 /* $NetBSD: ex_display.c,v 1.4 2014/01/26 21:43:45 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 #include <sys/cdefs.h>
14 #if 0
15 #ifndef lint
16 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 ";
17 #endif /* not lint */
18 #else
19 __RCSID("$NetBSD: ex_display.c,v 1.4 2014/01/26 21:43:45 christos Exp $");
20 #endif
22 #include <sys/types.h>
23 #include <sys/queue.h>
25 #include <bitstring.h>
26 #include <ctype.h>
27 #include <limits.h>
28 #include <stdio.h>
29 #include <string.h>
31 #include "../common/common.h"
32 #include "tag.h"
34 static int is_prefix __P((ARGS *, const CHAR_T *));
35 static int bdisplay __P((SCR *));
36 static void db __P((SCR *, CB *, const char *));
39 * ex_display -- :display b[uffers] | c[onnections] | s[creens] | t[ags]
41 * Display cscope connections, buffers, tags or screens.
43 * PUBLIC: int ex_display __P((SCR *, EXCMD *));
45 int
46 ex_display(SCR *sp, EXCMD *cmdp)
48 ARGS *arg;
50 arg = cmdp->argv[0];
52 switch (arg->bp[0]) {
53 case L('b'):
54 if (!is_prefix(arg, L("buffers")))
55 break;
56 return (bdisplay(sp));
57 case L('c'):
58 if (!is_prefix(arg, L("connections")))
59 break;
60 return (cscope_display(sp));
61 case L('s'):
62 if (!is_prefix(arg, L("screens")))
63 break;
64 return (ex_sdisplay(sp));
65 case L('t'):
66 if (!is_prefix(arg, L("tags")))
67 break;
68 return (ex_tag_display(sp));
70 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
71 return (1);
75 * is_prefix --
77 * Check that a command argument matches a prefix of a given string.
79 static int
80 is_prefix(ARGS *arg, const CHAR_T *str)
82 return arg->len <= STRLEN(str) && !MEMCMP(arg->bp, str, arg->len);
86 * bdisplay --
88 * Display buffers.
90 static int
91 bdisplay(SCR *sp)
93 CB *cbp;
95 if (LIST_EMPTY(&sp->wp->cutq) && sp->wp->dcbp == NULL) {
96 msgq(sp, M_INFO, "123|No cut buffers to display");
97 return (0);
100 /* Display regular cut buffers. */
101 LIST_FOREACH(cbp, &sp->wp->cutq, q) {
102 if (ISDIGIT(cbp->name))
103 continue;
104 if (!TAILQ_EMPTY(&cbp->textq))
105 db(sp, cbp, NULL);
106 if (INTERRUPTED(sp))
107 return (0);
109 /* Display numbered buffers. */
110 LIST_FOREACH(cbp, &sp->wp->cutq, q) {
111 if (!ISDIGIT(cbp->name))
112 continue;
113 if (!TAILQ_EMPTY(&cbp->textq))
114 db(sp, cbp, NULL);
115 if (INTERRUPTED(sp))
116 return (0);
118 /* Display default buffer. */
119 if ((cbp = sp->wp->dcbp) != NULL)
120 db(sp, cbp, "default buffer");
121 return (0);
125 * db --
126 * Display a buffer.
128 static void
129 db(SCR *sp, CB *cbp, const char *np)
131 CHAR_T *p;
132 TEXT *tp;
133 size_t len;
134 const unsigned char *name = (const void *)np;
136 (void)ex_printf(sp, "********** %s%s\n",
137 name == NULL ? KEY_NAME(sp, cbp->name) : name,
138 F_ISSET(cbp, CB_LMODE) ? " (line mode)" : " (character mode)");
139 TAILQ_FOREACH(tp, &cbp->textq, q) {
140 for (len = tp->len, p = tp->lb; len--; ++p) {
141 (void)ex_puts(sp, (char *)KEY_NAME(sp, *p));
142 if (INTERRUPTED(sp))
143 return;
145 (void)ex_puts(sp, "\n");