text input: fix problem with autoindenting and ^^D
[nvi.git] / ex / ex_display.c
blob299aab09d8339c0215ab4ca6042b905e922a1b4c
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 is_prefix __P((ARGS *, CHAR_T *));
29 static int bdisplay __P((SCR *));
30 static void db __P((SCR *, CB *, u_char *));
33 * ex_display -- :display b[uffers] | c[onnections] | s[creens] | t[ags]
35 * Display cscope connections, buffers, tags or screens.
37 * PUBLIC: int ex_display __P((SCR *, EXCMD *));
39 int
40 ex_display(SCR *sp, EXCMD *cmdp)
42 ARGS *arg;
44 arg = cmdp->argv[0];
46 switch (arg->bp[0]) {
47 case L('b'):
48 if (!is_prefix(arg, L("buffers")))
49 break;
50 return (bdisplay(sp));
51 case L('c'):
52 if (!is_prefix(arg, L("connections")))
53 break;
54 return (cscope_display(sp));
55 case L('s'):
56 if (!is_prefix(arg, L("screens")))
57 break;
58 return (ex_sdisplay(sp));
59 case L('t'):
60 if (!is_prefix(arg, L("tags")))
61 break;
62 return (ex_tag_display(sp));
64 ex_emsg(sp, cmdp->cmd->usage, EXM_USAGE);
65 return (1);
69 * is_prefix --
71 * Check that a command argument matches a prefix of a given string.
73 static int
74 is_prefix(ARGS *arg, CHAR_T *str)
76 return arg->len <= STRLEN(str) && !MEMCMP(arg->bp, str, arg->len);
80 * bdisplay --
82 * Display buffers.
84 static int
85 bdisplay(SCR *sp)
87 CB *cbp;
89 if (sp->wp->cutq.lh_first == NULL && sp->wp->dcbp == NULL) {
90 msgq(sp, M_INFO, "123|No cut buffers to display");
91 return (0);
94 /* Display regular cut buffers. */
95 for (cbp = sp->wp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) {
96 if (isdigit(cbp->name))
97 continue;
98 if (cbp->textq.cqh_first != (void *)&cbp->textq)
99 db(sp, cbp, NULL);
100 if (INTERRUPTED(sp))
101 return (0);
103 /* Display numbered buffers. */
104 for (cbp = sp->wp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) {
105 if (!isdigit(cbp->name))
106 continue;
107 if (cbp->textq.cqh_first != (void *)&cbp->textq)
108 db(sp, cbp, NULL);
109 if (INTERRUPTED(sp))
110 return (0);
112 /* Display default buffer. */
113 if ((cbp = sp->wp->dcbp) != NULL)
114 db(sp, cbp, "default buffer");
115 return (0);
119 * db --
120 * Display a buffer.
122 static void
123 db(SCR *sp, CB *cbp, u_char *name)
125 CHAR_T *p;
126 GS *gp;
127 TEXT *tp;
128 size_t len;
130 gp = sp->gp;
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 for (tp = cbp->textq.cqh_first;
135 tp != (void *)&cbp->textq; tp = tp->q.cqe_next) {
136 for (len = tp->len, p = tp->lb; len--; ++p) {
137 (void)ex_puts(sp, KEY_NAME(sp, *p));
138 if (INTERRUPTED(sp))
139 return;
141 (void)ex_puts(sp, "\n");