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