annotate 3rdparty/packages/uemacs/ueregion.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 routines in this file
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
3 * deal with the region, that magic space
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
4 * between "." and mark. Some functions are
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
5 * commands. Some functions are just for
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
6 * internal use.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
7 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
8 #include <stdio.h>
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
9 #include "ueed.h"
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
10
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
11 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
12 * Kill the region. Ask "getregion"
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
13 * to figure out the bounds of the region.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
14 * Move "." to the start, and kill the characters.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
15 * Bound to "C-W".
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
16 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
17 killregion(f, n)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
18 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
19 register int s;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
20 REGION region;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
21
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
22 if ((s=getregion(&region)) != TRUE)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
23 return (s);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
24 if ((lastflag&CFKILL) == 0) /* This is a kill type */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
25 kdelete(); /* command, so do magic */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
26 thisflag |= CFKILL; /* kill buffer stuff. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
27 curwp->w_dotp = region.r_linep;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
28 curwp->w_doto = region.r_offset;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
29 return (ldelete(region.r_size, TRUE));
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
30 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
31
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
32 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
33 * Copy all of the characters in the
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
34 * region to the kill buffer. Don't move dot
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
35 * at all. This is a bit like a kill region followed
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
36 * by a yank. Bound to "M-W".
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
37 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
38 copyregion(f, n)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
39 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
40 register LINE *linep;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
41 register int loffs;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
42 register int s;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
43 REGION region;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
44
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
45 if ((s=getregion(&region)) != TRUE)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
46 return (s);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
47 if ((lastflag&CFKILL) == 0) /* Kill type command. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
48 kdelete();
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
49 thisflag |= CFKILL;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
50 linep = region.r_linep; /* Current line. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
51 loffs = region.r_offset; /* Current offset. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
52 while (region.r_size--) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
53 if (loffs == llength(linep)) { /* End of line. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
54 if ((s=kinsert('\n')) != TRUE)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
55 return (s);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
56 linep = lforw(linep);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
57 loffs = 0;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
58 } else { /* Middle of line. */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
59 if ((s=kinsert(lgetc(linep, loffs))) != TRUE)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
60 return (s);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
61 ++loffs;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
62 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
63 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
64 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
65 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
66
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
67 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
68 * Lower case region. Zap all of the upper
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
69 * case characters in the region to lower case. Use
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
70 * the region code to set the limits. Scan the buffer,
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
71 * doing the changes. Call "lchange" to ensure that
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
72 * redisplay is done in all buffers. Bound to
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
73 * "C-X C-L".
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
74 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
75 lowerregion(f, n)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
76 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
77 register LINE *linep;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
78 register int loffs;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
79 register int c;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
80 register int s;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
81 REGION region;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
82
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
83 if ((s=getregion(&region)) != TRUE)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
84 return (s);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
85 lchange(WFHARD);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
86 linep = region.r_linep;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
87 loffs = region.r_offset;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
88 while (region.r_size--) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
89 if (loffs == llength(linep)) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
90 linep = lforw(linep);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
91 loffs = 0;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
92 } else {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
93 c = lgetc(linep, loffs);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
94 if (c>='A' && c<='Z')
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
95 lputc(linep, loffs, c+'a'-'A');
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
96 ++loffs;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
97 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
98 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
99 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
100 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
101
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
102 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
103 * Upper case region. Zap all of the lower
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
104 * case characters in the region to upper case. Use
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
105 * the region code to set the limits. Scan the buffer,
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
106 * doing the changes. Call "lchange" to ensure that
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
107 * redisplay is done in all buffers. Bound to
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
108 * "C-X C-L".
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
109 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
110 upperregion(f, n)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
111 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
112 register LINE *linep;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
113 register int loffs;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
114 register int c;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
115 register int s;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
116 REGION region;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
117
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
118 if ((s=getregion(&region)) != TRUE)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
119 return (s);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
120 lchange(WFHARD);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
121 linep = region.r_linep;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
122 loffs = region.r_offset;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
123 while (region.r_size--) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
124 if (loffs == llength(linep)) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
125 linep = lforw(linep);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
126 loffs = 0;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
127 } else {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
128 c = lgetc(linep, loffs);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
129 if (c>='a' && c<='z')
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
130 lputc(linep, loffs, c-'a'+'A');
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
131 ++loffs;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
132 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
133 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
134 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
135 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
136
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
137 /*
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
138 * This routine figures out the
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
139 * bounds of the region in the current window, and
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
140 * fills in the fields of the "REGION" structure pointed
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
141 * to by "rp". Because the dot and mark are usually very
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
142 * close together, we scan outward from dot looking for
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
143 * mark. This should save time. Return a standard code.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
144 * Callers of this routine should be prepared to get
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
145 * an "ABORT" status; we might make this have the
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
146 * conform thing later.
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
147 */
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
148 getregion(rp)
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
149 register REGION *rp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
150 {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
151 register LINE *flp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
152 register LINE *blp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
153 register int fsize;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
154 register int bsize;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
155
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
156 if (curwp->w_markp == NULL) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
157 mlwrite("No mark set in this window");
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
158 return (FALSE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
159 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
160 if (curwp->w_dotp == curwp->w_markp) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
161 rp->r_linep = curwp->w_dotp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
162 if (curwp->w_doto < curwp->w_marko) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
163 rp->r_offset = curwp->w_doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
164 rp->r_size = curwp->w_marko-curwp->w_doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
165 } else {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
166 rp->r_offset = curwp->w_marko;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
167 rp->r_size = curwp->w_doto-curwp->w_marko;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
168 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
169 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
170 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
171 blp = curwp->w_dotp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
172 bsize = curwp->w_doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
173 flp = curwp->w_dotp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
174 fsize = llength(flp)-curwp->w_doto+1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
175 while (flp!=curbp->b_linep || lback(blp)!=curbp->b_linep) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
176 if (flp != curbp->b_linep) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
177 flp = lforw(flp);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
178 if (flp == curwp->w_markp) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
179 rp->r_linep = curwp->w_dotp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
180 rp->r_offset = curwp->w_doto;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
181 rp->r_size = fsize+curwp->w_marko;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
182 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
183 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
184 fsize += llength(flp)+1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
185 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
186 if (lback(blp) != curbp->b_linep) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
187 blp = lback(blp);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
188 bsize += llength(blp)+1;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
189 if (blp == curwp->w_markp) {
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
190 rp->r_linep = blp;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
191 rp->r_offset = curwp->w_marko;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
192 rp->r_size = bsize - curwp->w_marko;
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
193 return (TRUE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
194 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
195 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
196 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
197 mlwrite("Bug: lost mark");
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
198 return (FALSE);
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
199 }
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
200
48c646212b1c 'microEMACS' for OS-9.
roug
parents:
diff changeset
201