make cut buffer displays interruptible
[nvi.git] / ex / ex_display.c
blobcad9e3b897c8b58919a4810ef4880c4d9489d4d4
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_display.c,v 8.13 1993/12/28 11:47:50 bostic Exp $ (Berkeley) $Date: 1993/12/28 11:47:50 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include <ctype.h>
15 #include <string.h>
17 #include "vi.h"
18 #include "tag.h"
19 #include "excmd.h"
21 static int bdisplay __P((SCR *, EXF *));
22 static void db __P((SCR *, CB *));
25 * ex_display -- :display b[uffers] | s[creens] | t[ags]
27 * Display buffers, tags or screens.
29 int
30 ex_display(sp, ep, cmdp)
31 SCR *sp;
32 EXF *ep;
33 EXCMDARG *cmdp;
35 switch (cmdp->argv[0]->bp[0]) {
36 case 'b':
37 return (bdisplay(sp, ep));
38 case 's':
39 return (ex_sdisplay(sp, ep));
40 case 't':
41 return (ex_tagdisplay(sp, ep));
43 msgq(sp, M_ERR,
44 "Unknown display argument %s, use b[uffers], s[creens], or t[ags].",
45 cmdp->argv[0]);
46 return (1);
50 * bdisplay --
52 * Display buffers.
54 static int
55 bdisplay(sp, ep)
56 SCR *sp;
57 EXF *ep;
59 CB *cbp;
61 if (sp->gp->cutq.lh_first == NULL) {
62 (void)ex_printf(EXCOOKIE, "No cut buffers to display.");
63 return (0);
66 /* Buffers can be infinitely long, make it interruptible. */
67 F_SET(sp, S_INTERRUPTIBLE);
69 /* Display regular cut buffers. */
70 for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) {
71 if (isdigit(cbp->name))
72 continue;
73 if (cbp->textq.cqh_first != (void *)&cbp->textq)
74 db(sp, cbp);
75 if (F_ISSET(sp, S_INTERRUPTED))
76 return (0);
78 /* Display numbered buffers. */
79 for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) {
80 if (!isdigit(cbp->name))
81 continue;
82 if (cbp->textq.cqh_first != (void *)&cbp->textq)
83 db(sp, cbp);
84 if (F_ISSET(sp, S_INTERRUPTED))
85 return (0);
87 return (0);
91 * db --
92 * Display a buffer.
94 static void
95 db(sp, cbp)
96 SCR *sp;
97 CB *cbp;
99 TEXT *tp;
100 size_t len;
101 char *p;
103 (void)ex_printf(EXCOOKIE, "********** %s%s\n", charname(sp, cbp->name),
104 F_ISSET(cbp, CB_LMODE) ? " (line mode)" : "");
105 for (tp = cbp->textq.cqh_first;
106 tp != (void *)&cbp->textq; tp = tp->q.cqe_next) {
107 for (len = tp->len, p = tp->lb; len--;) {
108 (void)ex_printf(EXCOOKIE, "%s", charname(sp, *p++));
109 if (F_ISSET(sp, S_INTERRUPTED))
110 return;
112 (void)ex_printf(EXCOOKIE, "\n");