forked from zuberfowler/zedit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LNECMD1.C
271 lines (263 loc) · 8.42 KB
/
LNECMD1.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include <stdlib.h>
#include "zedit.h"
struct bufline *lnecmd1(
union both_scr *posptr,
int nfield,
int rowcol[] [5],
unsigned int cmd[],
int maxlrecl,
register struct bufline *curr,
register struct lineptrs *place,
char *pos,
char ccnt[8],
int *line_no,
int *dschanged)
/**********************************************************************/
/* */
/* Process line commands from edit screen. Anything < f. */
/* */
/**********************************************************************/
/* */
/* This is ZEDIT source material. */
/* */
/* ZEDIT Source Materials are intellectual property */
/* (c) Copyright 1987,2001 by Clyde Thomas Zuber. */
/* */
/**********************************************************************/
{
struct bufline *hold;
struct bufline *top;
register int n;
register int cnt;
switch(*pos)
{
case '#': /* already processed */
break;
case '(':
if (lcinval(posptr, lc_any, curr))
break;
if (ckplace(posptr, sl_cmd, place))
break;
if (ccnt[0] == '(')
{
if (place -> slst)
{
if (cmpline(place -> slst, curr) > 0)
{
place -> slfn = place -> slst;
place -> slst = curr;
} /* end then */
else
place -> slfn = curr;
if (place -> slst -> status == ST_XBLK)
place -> slst = place -> slst -> bblk;
} /* end then */
else
place -> slst = curr;
/* check for number following shift */
ccnt[0] = '0';
} /* end then */
if (!(cnt = vrepcnt(posptr, ccnt)))
break;
if (cnt >= maxlrecl)
{
dispmsg(posptr, LNECMD1_MSG1);
cnt = 1;
} /* end then */
place -> count = cnt;
if (place -> slst)
{
if (place -> slfn)
{
shiftlf(posptr, place, maxlrecl);
*dschanged = YES;
} /* end then */
break;
} /* end then */
if (curr -> status == ST_XBLK)
place -> slst = curr -> bblk;
else
place -> slst = curr;
place -> slfn = curr;
shiftlf(posptr, place, maxlrecl);
*dschanged = YES;
break;
case ')':
if (lcinval(posptr, lc_any, curr))
break;
if (ckplace(posptr, sr_cmd, place))
break;
if (ccnt[0] == ')')
{
if (place -> srst)
{
if (cmpline(place -> srst, curr) > 0)
{
place -> srfn = place -> srst;
place -> srst = curr;
} /* end then */
else
place -> srfn = curr;
if (place -> srst -> status == ST_XBLK)
place -> srst = place -> srst -> bblk;
} /* end then */
else
place -> srst = curr;
/* check for number following shift */
ccnt[0] = '0';
} /* end then */
if (!(cnt = vrepcnt(posptr, ccnt)))
break;
place -> count = cnt;
if (place -> srst)
{
if (place -> srfn)
{
shiftrt(posptr, place, maxlrecl);
*dschanged = YES;
} /* end then */
break;
} /* end then */
if (curr -> status == ST_XBLK)
place -> srst = curr -> bblk;
else
place -> srst = curr;
place -> srfn = curr;
shiftrt(posptr, place, maxlrecl);
*dschanged = YES;
break;
case 'a':
if (lcinval(posptr, lc_bottom, curr))
break;
if (ccnt[0])
{
dispmsg(posptr, LNECMD1_MSG2);
break;
} /* end then */
place -> after = curr;
curr = curr -> next;
movecpy(posptr, place, maxlrecl);
curr = curr -> prev;
/* dschanged set by companion command */
break;
case 'b':
if (lcinval(posptr, lc_top, curr))
break;
if (ccnt[0])
{
dispmsg(posptr, LNECMD1_MSG2);
break;
} /* end then */
if (curr -> status == ST_XBLK)
place -> after = curr -> bblk -> prev;
else
place -> after = curr -> prev;
movecpy(posptr, place, maxlrecl);
/* dschanged set by companion command */
break;
case 'c':
if (lcinval(posptr, lc_both, curr))
break;
if (ccnt[0] == 'o') /* COLS */
{
place -> colsb = curr;
pshstck(cmd, COLMS);
if (cmd[0] == NEXTINPT)
cmd[0] = NOP;
break;
} /* end then, else */
if (ckplace(posptr, copy_cmd, place))
break;
if (ccnt[0] == 'c')
{
if (place -> copyst)
{
if (cmpline(place -> copyst, curr) > 0)
{
place -> copyfn = place -> copyst;
place -> copyst = curr;
} /* end then */
else
place -> copyfn = curr;
if (place -> copyst -> status == ST_XBLK)
place -> copyst = place -> copyst -> bblk;
movecpy(posptr, place, maxlrecl);
*dschanged = YES;
} /* end then */
else
place -> copyst = curr;
break;
} /* end then */
if (!(cnt = vrepcnt(posptr, ccnt)))
break;
--cnt;
if (curr -> status == ST_XBLK)
place -> copyst = curr -> bblk;
else
place -> copyst = curr;
hold = curr;
n = 0;
while (n < cnt && hold -> next -> next)
{
hold = hold -> next;
if (!(hold -> status & ST_EXCL))
++n;
} /* end while */
place -> copyfn = hold;
movecpy(posptr, place, maxlrecl);
*dschanged = YES;
break;
case 'd':
if (lcinval(posptr, lc_both, curr))
break;
if (ckplace(posptr, del_cmd, place))
break;
if (ccnt[0] == 'd')
{
if (place -> delst)
{
if (cmpline(place -> delst, curr) > 0)
{
place -> delfn = place -> delst;
place -> delst = curr;
} /* end then */
else
place -> delfn = curr;
curr = place -> delfn -> next;
if (place -> delst -> status == ST_XBLK)
place -> delst = place -> delst -> bblk;
ddelblk(posptr, place, maxlrecl);
curr = curr -> prev;
*dschanged = YES;
} /* end then */
else
place -> delst = curr;
break;
} /* end then */
if (!(cnt = vrepcnt(posptr, ccnt)))
break;
if (*line_no == rowcol[nfield - 1] [TOP_MAR])
place -> newcurr = curr -> prev;
if (curr -> status == ST_XBLK)
curr = curr -> bblk;
top = curr -> prev;
n = 0;
while (curr -> next && n < cnt)
{
if (!(curr -> status & ST_EXCL))
++n;
hold = curr;
curr = curr -> next;
free(hold);
} /* end for */
*dschanged = YES;
*line_no += cnt - 1;
top -> next = curr;
curr -> prev = top;
srpbufr(posptr, maxlrecl, curr);
renbufr(top);
curr = top;
break;
} /* end switch */
return(curr);
} /* end lnecmd1 */