forked from ogdenpm/aedit-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aedplm.c
228 lines (191 loc) · 5.9 KB
/
aedplm.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
/*********************************************************************
* INTEL CORPORATION PROPRIETARY INFORMATION *
* This software is supplied under the terms of a license agreement *
* or nondisclosure agreement with Intel Corporation and may not be *
* copied or disclosed except in accordance with the terms of that *
* agreement. *
*********************************************************************/
#include <stdbool.h>
#include "lit.h"
#include "type.h"
#include "data.h"
#include "proc.h"
/************************************************************
PLACE THE CURSOR SOMEWHERE IN THE TEXT. NO ERRORS ARE
POSSIBLE. IF FORCE COLUMN IS LESS THAN 80 THEN IT
SPECIFIES THE COLUMN THAT MUST BE MOVED TO. END THE
ROUTINE WITH A PUT_GOTO TO SET THE CURSOR.
************************************************************/
void Position_in_text() {
word row, tcol;
pointer addr;
/* CALCULATE ROW BY COMPARING ADDRESSES IN HAVE ARRAY WITH HIGH_S */
row = first_text_line;
while (have[row] < oa.high_s) {
if (++row > message_line) {
row = message_line;
force_column = 0;
goto ex_loop;
}
}
if (have[row] > oa.high_s)
row--;
ex_loop:
addr = have[row];
oa.bol = addr;
if (force_column >= 80) {
tcol = 0;
while (tcol < wrapping_column && addr < oa.low_e) {
if (*addr == TAB)
tcol += tab_to[tcol];
else
tcol++;
addr++;
}
virtual_col = (byte)tcol;
if (oa.left_column != 0) {
if (oa.left_column <= tcol) /* adjust for left column */
tcol = tcol - oa.left_column;
else
tcol = 0;
}
if (tcol > 79)
tcol = 79;
}
else
tcol = force_column;
force_column = 100; /* for next time */
Put_goto((byte)tcol, (byte)row);
cursor = oa.high_s;
} /* Position_in_text() */
/* Translated from ASM86 - IB */
pointer Unfold(pointer textp, pointer image_p) {
byte ch, count, image_index, actual_col, l_col;
low_e_byte = LF;
if (macro_suppress && !force_writing) {
image_p[0] = 0;
/* search_for_lf: */
for (;;) {
textp += findb(textp, LF, wrapping_column - 1);
if (textp == oa.low_e) {
textp = oa.high_s;
continue;
}
if (textp >= oa.high_e) {
if (Can_forward_file() != 0) {
Set_tag(ed_tagb, oa.high_s);
Forward_file();
textp = oa.high_s;
Jump_tag(ed_tagb);
continue;
}
return oa.high_e;
}
if (textp[0] == LF)
textp++;
if (textp == oa.low_e)
textp = oa.high_s;
return textp;
}
}
image_index = 0;
l_col = oa.left_column;
actual_col = 0;
if (oa.left_column != 0) {
image_index = 1;
image_p[1] = '!';
l_col++;
}
/* unfold_loop: */
for (;;) {
ch = Printable(*textp++);
if (ch != TAB && ch != LF) {
if (++actual_col == wrapping_column)
goto lf_case;
if (actual_col <= l_col)
continue;
if (++image_index > 80) {
image_index--;
ch = '!';
}
image_p[image_index] = ch;
continue;
}
if (ch == LF)
goto lf_case;
count = tab_to[actual_col];
ch = print_as[' '];
/* tab_loop: */
while (count != 0) {
count--;
if (++actual_col == wrapping_column)
goto lf_case;
if (actual_col <= l_col)
continue;
if (++image_index > 80) {
image_index--;
ch = '!';
}
image_p[image_index] = ch;
}
continue;
lf_case:
if (--textp == oa.low_e) {
textp = oa.high_s;
continue;
}
if (textp >= oa.high_e) {
if (Can_forward_file() != 0) {
Set_tag(ed_tagb, oa.high_s);
Forward_file();
textp = oa.high_s;
Jump_tag(ed_tagb);
continue;
}
if (actual_col == 0)
image_index = 0;
image_p[0] = image_index;
return oa.high_e;
}
if (ch != LF && actual_col == wrapping_column) {
if (++image_index >= 80)
image_index--;
image_p[image_index] = '+';
}
image_p[0] = image_index;
if (textp[0] == LF)
textp++;
if (textp == oa.low_e)
textp = oa.high_s;
return textp;
}
} /* Unfold */
/*
; NEXT_LINE GIVEN A POINTER, FIND THE NEXT
; LF AND RETURN POINTER TO FIRST
; CHARACTER PAST LF. DO NOT
; WORRY ABOUT WINDOW, END OF TEXT
; ETC.
*/
pointer Next_line(pointer str) {
word tmp;
tmp = findb(str, LF, wrapping_column);
if (tmp != 0xffff)
return str + (tmp & 0xff) + 1;
return str + wrapping_column;
} /* Next_line */
/*
; PRIOR_LINE GIVEN A POINTER, SUBTRACT 1 AND THEN
; FIND THE PRIOR LF AND RETURN POINTER
; TO LF. DO NOT WORRY ABOUT WINDOW,
; END OF TEXT ETC.
*/
pointer Prior_line(pointer str) {
word tmp;
str -= wrapping_column;
tmp = findrb(str, LF, wrapping_column);
if (tmp != 0xffff)
return str + (tmp & 0xff);
return str;
} /* Prior_line */
/* Cc_trap() is in separate module so we can get long calls */