Commit | Line | Data |
---|---|---|
18ae9d6b AS |
1 | /*- |
2 | * Copyright (c) 1992, 1993 | |
3 | * The Regents of the University of California. All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #ifndef lint | |
35 | static char sccsid[] = "@(#)ex_display.c 8.14 (Berkeley) 1/9/94"; | |
36 | #endif /* not lint */ | |
37 | ||
38 | #include <sys/types.h> | |
39 | ||
40 | #include <ctype.h> | |
41 | #include <string.h> | |
42 | ||
43 | #include "vi.h" | |
44 | #include "tag.h" | |
45 | #include "excmd.h" | |
46 | ||
47 | static int bdisplay __P((SCR *, EXF *)); | |
48 | static void db __P((SCR *, CB *, char *)); | |
49 | ||
50 | /* | |
51 | * ex_display -- :display b[uffers] | s[creens] | t[ags] | |
52 | * | |
53 | * Display buffers, tags or screens. | |
54 | */ | |
55 | int | |
56 | ex_display(sp, ep, cmdp) | |
57 | SCR *sp; | |
58 | EXF *ep; | |
59 | EXCMDARG *cmdp; | |
60 | { | |
61 | switch (cmdp->argv[0]->bp[0]) { | |
62 | case 'b': | |
63 | return (bdisplay(sp, ep)); | |
64 | case 's': | |
65 | return (ex_sdisplay(sp, ep)); | |
66 | case 't': | |
67 | return (ex_tagdisplay(sp, ep)); | |
68 | } | |
69 | msgq(sp, M_ERR, | |
70 | "Unknown display argument %s, use b[uffers], s[creens], or t[ags].", | |
71 | cmdp->argv[0]); | |
72 | return (1); | |
73 | } | |
74 | ||
75 | /* | |
76 | * bdisplay -- | |
77 | * | |
78 | * Display buffers. | |
79 | */ | |
80 | static int | |
81 | bdisplay(sp, ep) | |
82 | SCR *sp; | |
83 | EXF *ep; | |
84 | { | |
85 | CB *cbp; | |
86 | ||
87 | if (sp->gp->cutq.lh_first == NULL && sp->gp->dcbp == NULL) { | |
88 | (void)ex_printf(EXCOOKIE, "No cut buffers to display."); | |
89 | return (0); | |
90 | } | |
91 | ||
92 | /* Buffers can be infinitely long, make it interruptible. */ | |
93 | F_SET(sp, S_INTERRUPTIBLE); | |
94 | ||
95 | /* Display regular cut buffers. */ | |
96 | for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) { | |
97 | if (isdigit(cbp->name)) | |
98 | continue; | |
99 | if (cbp->textq.cqh_first != (void *)&cbp->textq) | |
100 | db(sp, cbp, NULL); | |
101 | if (F_ISSET(sp, S_INTERRUPTED)) | |
102 | return (0); | |
103 | } | |
104 | /* Display numbered buffers. */ | |
105 | for (cbp = sp->gp->cutq.lh_first; cbp != NULL; cbp = cbp->q.le_next) { | |
106 | if (!isdigit(cbp->name)) | |
107 | continue; | |
108 | if (cbp->textq.cqh_first != (void *)&cbp->textq) | |
109 | db(sp, cbp, NULL); | |
110 | if (F_ISSET(sp, S_INTERRUPTED)) | |
111 | return (0); | |
112 | } | |
113 | /* Display default buffer. */ | |
114 | if ((cbp = sp->gp->dcbp) != NULL) | |
115 | db(sp, cbp, "default buffer"); | |
116 | return (0); | |
117 | } | |
118 | ||
119 | /* | |
120 | * db -- | |
121 | * Display a buffer. | |
122 | */ | |
123 | static void | |
124 | db(sp, cbp, name) | |
125 | SCR *sp; | |
126 | CB *cbp; | |
127 | char *name; | |
128 | { | |
129 | TEXT *tp; | |
130 | size_t len; | |
131 | char *p; | |
132 | ||
133 | (void)ex_printf(EXCOOKIE, "********** %s%s\n", | |
134 | name == NULL ? charname(sp, cbp->name) : name, | |
135 | F_ISSET(cbp, CB_LMODE) ? " (line mode)" : ""); | |
136 | for (tp = cbp->textq.cqh_first; | |
137 | tp != (void *)&cbp->textq; tp = tp->q.cqe_next) { | |
138 | for (len = tp->len, p = tp->lb; len--;) { | |
139 | (void)ex_printf(EXCOOKIE, "%s", charname(sp, *p++)); | |
140 | if (F_ISSET(sp, S_INTERRUPTED)) | |
141 | return; | |
142 | } | |
143 | (void)ex_printf(EXCOOKIE, "\n"); | |
144 | } | |
145 | } |