annotate 3rdparty/packages/uemacs/ueline2.c @ 995:48c646212b1c

'microEMACS' for OS-9. Posted to USENET net.micro.6809, 4-May-86. Picked up from Google groups
author roug
date Sun, 23 Feb 2003 21:26:32 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
995
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
1 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
2 * The functions in this file are a general set of line management utilities.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
3 * They are the only routines that touch the text. They also touch the buffer
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
4 * and window structures, to make sure that the necessary updating gets done.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
5 * There are routines in this file that handle the kill buffer too. It i
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
6 sn't
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
7 * here for any good reason.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
8 *
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
9 * Note that this code only updates the dot and mark values in the window list.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
10 * Since all the code acts on the current window, the buffer that we are
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
11 * editing must be being displayed, which means that "b_nwnd" is non zero,
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
12 * which means that the dot and mark values in the buffer headers are nonsense.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
13 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
14
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
15 #include <stdio.h>
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
16 #include "ueed.h"
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
17
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
18 #define NBLOCK 16 /* Line block chunk size */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
19 #define KBLOCK 256 /* Kill buffer block size */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
20
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
21 extern char *kbufp; /* Kill buffer data */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
22 extern int kused; /* # of bytes used in KB */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
23 extern int ksize; /* # of bytes allocated in KB */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
24
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
25 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
26 * Insert a newline into the buffer at the current location of dot in the
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
27 * current window. The funny ass-backwards way it does things is not a botch;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
28 * it just makes the last line in the file not a special case. Return TRUE if
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
29 * everything works out and FALSE on error (memory allocation failure). The
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
30 * update of dot and mark is a bit easier then in the above case, because the
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
31 * split forces more updating.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
32 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
33 lnewline()
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
34 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
35 register char *cp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
36 register char *cp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
37 register LINE *lp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
38 register LINE *lp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
39 register int doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
40 register WINDOW *wp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
41
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
42 lchange(WFHARD);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
43 lp1 = curwp->w_dotp; /* Get the address and */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
44 doto = curwp->w_doto; /* offset of "." */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
45 if ((lp2=lalloc(doto)) == NULL) /* New first half line */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
46 return (FALSE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
47 cp1 = &lp1->l_text[0]; /* Shuffle text around */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
48 cp2 = &lp2->l_text[0];
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
49 while (cp1 != &lp1->l_text[doto])
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
50 *cp2++ = *cp1++;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
51 cp2 = &lp1->l_text[0];
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
52 while (cp1 != &lp1->l_text[lp1->l_used])
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
53 *cp2++ = *cp1++;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
54 lp1->l_used -= doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
55 lp2->l_bp = lp1->l_bp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
56 lp1->l_bp = lp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
57 lp2->l_bp->l_fp = lp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
58 lp2->l_fp = lp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
59 wp = wheadp; /* Windows */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
60 while (wp != NULL) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
61 if (wp->w_linep == lp1)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
62 wp->w_linep = lp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
63 if (wp->w_dotp == lp1) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
64 if (wp->w_doto < doto)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
65 wp->w_dotp = lp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
66 else
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
67 wp->w_doto -= doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
68 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
69 if (wp->w_markp == lp1) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
70 if (wp->w_marko < doto)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
71 wp->w_markp = lp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
72 else
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
73 wp->w_marko -= doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
74 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
75 wp = wp->w_wndp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
76 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
77 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
78 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
79
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
80 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
81 * This function deletes "n" bytes, starting at dot. It understands how do deal
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
82 * with end of lines, etc. It returns TRUE if all of the characters were
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
83 * deleted, and FALSE if they were not (because dot ran into the end of the
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
84 * buffer. The "kflag" is TRUE if the text should be put in the kill buffer.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
85 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
86 ldelete(n, kflag)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
87 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
88 register char *cp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
89 register char *cp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
90 register LINE *dotp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
91 register int doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
92 register int chunk;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
93 register WINDOW *wp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
94
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
95 while (n != 0) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
96 dotp = curwp->w_dotp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
97 doto = curwp->w_doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
98 if (dotp == curbp->b_linep) /* Hit end of buffer. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
99 return (FALSE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
100 chunk = dotp->l_used-doto; /* Size of chunk. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
101 if (chunk > n)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
102 chunk = n;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
103 if (chunk == 0) { /* End of line, merge. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
104 lchange(WFHARD);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
105 if (ldelnewline() == FALSE
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
106 || (kflag!=FALSE && kinsert('\n')==FALSE))
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
107 return (FALSE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
108 --n;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
109 continue;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
110 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
111 lchange(WFEDIT);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
112 cp1 = &dotp->l_text[doto]; /* Scrunch text. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
113 cp2 = cp1 + chunk;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
114 if (kflag != FALSE) { /* Kill? */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
115 while (cp1 != cp2) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
116 if (kinsert(*cp1) == FALSE)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
117 return (FALSE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
118 ++cp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
119 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
120 cp1 = &dotp->l_text[doto];
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
121 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
122 while (cp2 != &dotp->l_text[dotp->l_used])
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
123 *cp1++ = *cp2++;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
124 dotp->l_used -= chunk;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
125 wp = wheadp; /* Fix windows */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
126 while (wp != NULL) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
127 if (wp->w_dotp==dotp && wp->w_doto>=doto) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
128 wp->w_doto -= chunk;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
129 if (wp->w_doto < doto)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
130 wp->w_doto = doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
131 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
132 if (wp->w_markp==dotp && wp->w_marko>=doto) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
133 wp->w_marko -= chunk;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
134 if (wp->w_marko < doto)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
135 wp->w_marko = doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
136 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
137 wp = wp->w_wndp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
138 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
139 n -= chunk;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
140 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
141 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
142 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
143
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
144 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
145 * Delete a newline. Join the current line with the next line. If the next line
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
146 * is the magic header line always return TRUE; merging the last line with the
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
147 * header line can be thought of as always being a successful operation, even
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
148 * if nothing is done, and this makes the kill buffer work "right". Easy cases
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
149 * can be done by shuffling data around. Hard cases require that lines be moved
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
150 * about in memory. Return FALSE on error and TRUE if all looks ok. Called by
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
151 * "ldelete" only.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
152 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
153 ldelnewline()
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
154 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
155 register char *cp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
156 register char *cp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
157 register LINE *lp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
158 register LINE *lp2;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
159 register LINE *lp3;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
160 register WINDOW *wp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
161
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
162 lp1 = curwp->w_dotp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
163 lp2 = lp1->l_fp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
164 if (lp2 == curbp->b_linep) { /* At the buffer end. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
165 if (lp1->l_used == 0) /* Blank line. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
166 lfree(lp1);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
167 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
168 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
169 if (lp2->l_used <= lp1->l_size-lp1->l_used) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
170 cp1 = &lp1->l_text[lp1->l_used];
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
171 cp2 = &lp2->l_text[0];
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
172 while (cp2 != &lp2->l_text[lp2->l_used])
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
173 *cp1++ = *cp2++;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
174 wp = wheadp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
175 while (wp != NULL) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
176 if (wp->w_linep == lp2)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
177 wp->w_linep = lp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
178 if (wp->w_dotp == lp2) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
179 wp->w_dotp = lp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
180 wp->w_doto += lp1->l_used;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
181 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
182 if (wp->w_markp == lp2) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
183 wp->w_markp = lp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
184 wp->w_marko += lp1->l_used;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
185 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
186 wp = wp->w_wndp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
187 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
188 lp1->l_used += lp2->l_used;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
189 lp1->l_fp = lp2->l_fp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
190 lp2->l_fp->l_bp = lp1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
191 free((char *) lp2);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
192 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
193 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
194 if ((lp3=lalloc(lp1->l_used+lp2->l_used)) == NULL)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
195 return (FALSE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
196 cp1 = &lp1->l_text[0];
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
197 cp2 = &lp3->l_text[0];
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
198 while (cp1 != &lp1->l_text[lp1->l_used])
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
199 *cp2++ = *cp1++;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
200 cp1 = &lp2->l_text[0];
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
201 while (cp1 != &lp2->l_text[lp2->l_used])
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
202 *cp2++ = *cp1++;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
203 lp1->l_bp->l_fp = lp3;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
204 lp3->l_fp = lp2->l_fp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
205 lp2->l_fp->l_bp = lp3;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
206 lp3->l_bp = lp1->l_bp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
207 wp = wheadp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
208 while (wp != NULL) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
209 if (wp->w_linep==lp1 || wp->w_linep==lp2)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
210 wp->w_linep = lp3;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
211 if (wp->w_dotp == lp1)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
212 wp->w_dotp = lp3;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
213 else if (wp->w_dotp == lp2) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
214 wp->w_dotp = lp3;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
215 wp->w_doto += lp1->l_used;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
216 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
217 if (wp->w_markp == lp1)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
218 wp->w_markp = lp3;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
219 else if (wp->w_markp == lp2) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
220 wp->w_markp = lp3;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
221 wp->w_marko += lp1->l_used;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
222 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
223 wp = wp->w_wndp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
224 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
225 free((char *) lp1);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
226 free((char *) lp2);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
227 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
228 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
229
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
230 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
231 * Delete all of the text saved in the kill buffer. Called by commands when a
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
232 * new kill context is being created. The kill buffer array is released, just
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
233 * in case the buffer has grown to immense size. No errors.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
234 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
235 kdelete()
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
236 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
237 if (kbufp != NULL) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
238 free((char *) kbufp);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
239 kbufp = NULL;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
240 kused = 0;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
241 ksize = 0;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
242 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
243 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
244
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
245 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
246 * Insert a character to the kill buffer, enlarging the buffer if there isn't
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
247 * any room. Always grow the buffer in chunks, on the assumption that if you
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
248 * put something in the kill buffer you are going to put more stuff there too
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
249 * later. Return TRUE if all is well, and FALSE on errors.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
250 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
251 kinsert(c)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
252 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
253 register char *nbufp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
254 register int i;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
255
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
256 if (kused == ksize) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
257 if ((nbufp=malloc(ksize+KBLOCK)) == NULL)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
258 return (FALSE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
259 for (i=0; i<ksize; ++i)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
260 nbufp[i] = kbufp[i];
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
261 if (kbufp != NULL)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
262 free((char *) kbufp);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
263 kbufp = nbufp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
264 ksize += KBLOCK;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
265 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
266 kbufp[kused++] = c;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
267 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
268 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
269
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
270 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
271 * This function gets characters from the kill buffer. If the character index
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
272 * "n" is off the end, it returns "-1". This lets the caller just scan along
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
273 * until it gets a "-1" back.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
274 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
275 kremove(n)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
276 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
277 if (n >= kused)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
278 return (-1);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
279 else
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
280 return (kbufp[n] & 0xFF);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
281 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
282
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
283
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
284