995
|
1 /*
|
|
2 * Buffer management.
|
|
3 * Some of the functions are internal,
|
|
4 * and some are actually attached to user
|
|
5 * keys. Like everyone else, they set hints
|
|
6 * for the display system.
|
|
7 */
|
|
8 #include <stdio.h>
|
|
9 #include "ueed.h"
|
|
10
|
|
11 #ifndef OS9
|
|
12 /*
|
|
13 * Attach a buffer to a window. The
|
|
14 * values of dot and mark come from the buffer
|
|
15 * if the use count is 0. Otherwise, they come
|
|
16 * from some other window.
|
|
17 */
|
|
18 usebuffer(f, n)
|
|
19 {
|
|
20 register BUFFER *bp;
|
|
21 register WINDOW *wp;
|
|
22 register int s;
|
|
23 char bufn[NBUFN];
|
|
24
|
|
25 if ((s=mlreply("Use buffer: ", bufn, NBUFN)) != TRUE)
|
|
26 return (s);
|
|
27 if ((bp=bfind(bufn, TRUE, 0)) == NULL)
|
|
28 return (FALSE);
|
|
29 if (--curbp->b_nwnd == 0) { /* Last use. */
|
|
30 curbp->b_dotp = curwp->w_dotp;
|
|
31 curbp->b_doto = curwp->w_doto;
|
|
32 curbp->b_markp = curwp->w_markp;
|
|
33 curbp->b_marko = curwp->w_marko;
|
|
34 }
|
|
35 curbp = bp; /* Switch. */
|
|
36 curwp->w_bufp = bp;
|
|
37 curwp->w_linep = bp->b_linep; /* For macros, ignored. */
|
|
38 curwp->w_flag |= WFMODE|WFFORCE|WFHARD; /* Quite nasty. */
|
|
39 if (bp->b_nwnd++ == 0) { /* First use. */
|
|
40 curwp->w_dotp = bp->b_dotp;
|
|
41 curwp->w_doto = bp->b_doto;
|
|
42 curwp->w_markp = bp->b_markp;
|
|
43 curwp->w_marko = bp->b_marko;
|
|
44 return (TRUE);
|
|
45 }
|
|
46 wp = wheadp; /* Look for old. */
|
|
47 while (wp != NULL) {
|
|
48 if (wp!=curwp && wp->w_bufp==bp) {
|
|
49 curwp->w_dotp = wp->w_dotp;
|
|
50 curwp->w_doto = wp->w_doto;
|
|
51 curwp->w_markp = wp->w_markp;
|
|
52 curwp->w_marko = wp->w_marko;
|
|
53 break;
|
|
54 }
|
|
55 wp = wp->w_wndp;
|
|
56 }
|
|
57 return (TRUE);
|
|
58 }
|
|
59
|
|
60 /*
|
|
61 * Dispose of a buffer, by name.
|
|
62 * Ask for the name. Look it up (don't get too
|
|
63 * upset if it isn't there at all!). Get quite upset
|
|
64 * if the buffer is being displayed. Clear the buffer (ask
|
|
65 * if the buffer has been changed). Then free the header
|
|
66 * line and the buffer header. Bound to "C-X K".
|
|
67 */
|
|
68 killbuffer(f, n)
|
|
69 {
|
|
70 register BUFFER *bp;
|
|
71 register BUFFER *bp1;
|
|
72 register BUFFER *bp2;
|
|
73 register int s;
|
|
74 char bufn[NBUFN];
|
|
75
|
|
76 if ((s=mlreply("Kill buffer: ", bufn, NBUFN)) != TRUE)
|
|
77 return (s);
|
|
78 if ((bp=bfind(bufn, FALSE, 0)) == NULL) /* Easy if unknown. */
|
|
79 return (TRUE);
|
|
80 if (bp->b_nwnd != 0) { /* Error if on screen. */
|
|
81 mlwrite("Buffer is being displayed");
|
|
82 return (FALSE);
|
|
83 }
|
|
84 if ((s=bclear(bp)) != TRUE) /* Blow text away. */
|
|
85 return (s);
|
|
86 free((char *) bp->b_linep); /* Release header line. */
|
|
87 bp1 = NULL; /* Find the header. */
|
|
88 bp2 = bheadp;
|
|
89 while (bp2 != bp) {
|
|
90 bp1 = bp2;
|
|
91 bp2 = bp2->b_bufp;
|
|
92 }
|
|
93 bp2 = bp2->b_bufp; /* Next one in chain. */
|
|
94 if (bp1 == NULL) /* Unlink it. */
|
|
95 bheadp = bp2;
|
|
96 else
|
|
97 bp1->b_bufp = bp2;
|
|
98 free((char *) bp); /* Release buffer block */
|
|
99 return (TRUE);
|
|
100 }
|
|
101
|
|
102 /*
|
|
103 * List all of the active
|
|
104 * buffers. First update the special
|
|
105 * buffer that holds the list. Next make
|
|
106 * sure at least 1 window is displaying the
|
|
107 * buffer list, splitting the screen if this
|
|
108 * is what it takes. Lastly, repaint all of
|
|
109 * the windows that are displaying the
|
|
110 * list. Bound to "C-X C-B".
|
|
111 */
|
|
112 listbuffers(f, n)
|
|
113 {
|
|
114 register WINDOW *wp;
|
|
115 register BUFFER *bp;
|
|
116 register int s;
|
|
117
|
|
118 if ((s=makelist()) != TRUE)
|
|
119 return (s);
|
|
120 if (blistp->b_nwnd == 0) { /* Not on screen yet. */
|
|
121 if ((wp=wpopup()) == NULL)
|
|
122 return (FALSE);
|
|
123 bp = wp->w_bufp;
|
|
124 if (--bp->b_nwnd == 0) {
|
|
125 bp->b_dotp = wp->w_dotp;
|
|
126 bp->b_doto = wp->w_doto;
|
|
127 bp->b_markp = wp->w_markp;
|
|
128 bp->b_marko = wp->w_marko;
|
|
129 }
|
|
130 wp->w_bufp = blistp;
|
|
131 ++blistp->b_nwnd;
|
|
132 }
|
|
133 wp = wheadp;
|
|
134 while (wp != NULL) {
|
|
135 if (wp->w_bufp == blistp) {
|
|
136 wp->w_linep = lforw(blistp->b_linep);
|
|
137 wp->w_dotp = lforw(blistp->b_linep);
|
|
138 wp->w_doto = 0;
|
|
139 wp->w_markp = NULL;
|
|
140 wp->w_marko = 0;
|
|
141 wp->w_flag |= WFMODE|WFHARD;
|
|
142 }
|
|
143 wp = wp->w_wndp;
|
|
144 }
|
|
145 return (TRUE);
|
|
146 }
|
|
147
|
|
148 /*
|
|
149 * This routine rebuilds the
|
|
150 * text in the special secret buffer
|
|
151 * that holds the buffer list. It is called
|
|
152 * by the list buffers command. Return TRUE
|
|
153 * if everything works. Return FALSE if there
|
|
154 * is an error (if there is no memory).
|
|
155 */
|
|
156 makelist()
|
|
157 {
|
|
158 register char *cp1;
|
|
159 register char *cp2;
|
|
160 register int c;
|
|
161 register BUFFER *bp;
|
|
162 register LINE *lp;
|
|
163 register int nbytes;
|
|
164 register int s;
|
|
165 register int type;
|
|
166 char b[6+1];
|
|
167 char line[128];
|
|
168
|
|
169 blistp->b_flag &= ~BFCHG; /* Don't complain! */
|
|
170 if ((s=bclear(blistp)) != TRUE) /* Blow old text away */
|
|
171 return (s);
|
|
172 strcpy(blistp->b_fname, "");
|
|
173 if (addline("C Size Buffer File") == FALSE
|
|
174 || addline("- ---- ------ ----") == FALSE)
|
|
175 return (FALSE);
|
|
176 bp = bheadp; /* For all buffers */
|
|
177 while (bp != NULL) {
|
|
178 if ((bp->b_flag&BFTEMP) != 0) { /* Skip magic ones. */
|
|
179 bp = bp->b_bufp;
|
|
180 continue;
|
|
181 }
|
|
182 cp1 = &line[0]; /* Start at left edge */
|
|
183 if ((bp->b_flag&BFCHG) != 0) /* "*" if changed */
|
|
184 *cp1++ = '*';
|
|
185 else
|
|
186 *cp1++ = ' ';
|
|
187 *cp1++ = ' '; /* Gap. */
|
|
188 nbytes = 0; /* Count bytes in buf. */
|
|
189 lp = lforw(bp->b_linep);
|
|
190 while (lp != bp->b_linep) {
|
|
191 nbytes += llength(lp)+1;
|
|
192 lp = lforw(lp);
|
|
193 }
|
|
194 itoa(b, 6, nbytes); /* 6 digit buffer size. */
|
|
195 cp2 = &b[0];
|
|
196 while ((c = *cp2++) != 0)
|
|
197 *cp1++ = c;
|
|
198 *cp1++ = ' '; /* Gap. */
|
|
199 cp2 = &bp->b_bname[0]; /* Buffer name */
|
|
200 while ((c = *cp2++) != 0)
|
|
201 *cp1++ = c;
|
|
202 cp2 = &bp->b_fname[0]; /* File name */
|
|
203 if (*cp2 != 0) {
|
|
204 while (cp1 < &line[1+1+6+1+NBUFN+1])
|
|
205 *cp1++ = ' ';
|
|
206 while ((c = *cp2++) != 0) {
|
|
207 if (cp1 < &line[128-1])
|
|
208 *cp1++ = c;
|
|
209 }
|
|
210 }
|
|
211 *cp1 = 0; /* Add to the buffer. */
|
|
212 if (addline(line) == FALSE)
|
|
213 return (FALSE);
|
|
214 bp = bp->b_bufp;
|
|
215 }
|
|
216 return (TRUE); /* All done */
|
|
217 }
|
|
218 #endif
|
|
219
|