Subversion Repositories Kolibri OS

Rev

Rev 9050 | Rev 9073 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9050 Rev 9060
1
(*
1
(*
2
    Copyright 2021 Anton Krotov
2
    Copyright 2021 Anton Krotov
3
 
3
 
4
    This file is part of CEdit.
4
    This file is part of CEdit.
5
 
5
 
6
    CEdit is free software: you can redistribute it and/or modify
6
    CEdit is free software: you can redistribute it and/or modify
7
    it under the terms of the GNU General Public License as published by
7
    it under the terms of the GNU General Public License as published by
8
    the Free Software Foundation, either version 3 of the License, or
8
    the Free Software Foundation, either version 3 of the License, or
9
    (at your option) any later version.
9
    (at your option) any later version.
10
 
10
 
11
    CEdit is distributed in the hope that it will be useful,
11
    CEdit is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
    GNU General Public License for more details.
14
    GNU General Public License for more details.
15
 
15
 
16
    You should have received a copy of the GNU General Public License
16
    You should have received a copy of the GNU General Public License
17
    along with CEdit. If not, see .
17
    along with CEdit. If not, see .
18
*)
18
*)
19
 
19
 
20
MODULE Lines;
20
MODULE Lines;
21
 
21
 
22
IMPORT
22
IMPORT
23
    List, SYSTEM, API, Utils;
23
    List, SYSTEM, API, Utils;
24
 
24
 
25
CONST
25
CONST
26
    WCHAR_SIZE = 2;
26
    WCHAR_SIZE = 2;
27
    SPACE = 20X;
27
    SPACE = 20X;
28
 
28
 
29
TYPE
29
TYPE
30
 
30
 
31
    tLine* = POINTER TO RECORD (List.tItem)
31
    tLine* = POINTER TO RECORD (List.tItem)
32
        ptr: INTEGER;
32
        ptr: INTEGER;
33
        length*: INTEGER;
33
        length*: INTEGER;
34
        modified*, saved*, temp: BOOLEAN;
34
        modified*, saved*, temp, label*: BOOLEAN;
35
        cin*, cout*, pos*: INTEGER
35
        cin*, cout*, pos*: INTEGER
36
    END;
36
    END;
37
 
37
 
38
    PmovInt = PROCEDURE (VAR v: INTEGER; x: INTEGER);
38
    PmovInt = PROCEDURE (VAR v: INTEGER; x: INTEGER);
39
    PmovBool = PROCEDURE (VAR v: BOOLEAN; x: BOOLEAN);
39
    PmovBool = PROCEDURE (VAR v: BOOLEAN; x: BOOLEAN);
40
    PmovPtr = PROCEDURE (VAR v: List.tItem; x: List.tItem);
40
    PmovPtr = PROCEDURE (VAR v: List.tItem; x: List.tItem);
41
(*
41
(*
42
    PTypedPtr = PROCEDURE (p: List.tItem);
42
    PTypedPtr = PROCEDURE (p: List.tItem);
43
    PUntypedPtr = PROCEDURE (p: INTEGER);
43
    PUntypedPtr = PROCEDURE (p: INTEGER);
44
*)
44
*)
45
 
45
 
46
VAR
46
VAR
47
 
47
 
48
    _movInt: PmovInt;
48
    _movInt: PmovInt;
49
    _movBool: PmovBool;
49
    _movBool: PmovBool;
50
    _movPtr: PmovPtr;
50
    _movPtr: PmovPtr;
51
(*    _typedPtr: PTypedPtr;
51
(*    _typedPtr: PTypedPtr;
52
    _untypedPtr: PUntypedPtr;*)
52
    _untypedPtr: PUntypedPtr;*)
53
 
53
 
54
    pMaxLength: INTEGER;
54
    pMaxLength: INTEGER;
55
 
55
 
56
 
56
 
57
PROCEDURE movInt (VAR v: INTEGER; x: INTEGER);
57
PROCEDURE movInt (VAR v: INTEGER; x: INTEGER);
58
BEGIN
58
BEGIN
59
    _movInt(v, x)
59
    _movInt(v, x)
60
END movInt;
60
END movInt;
61
 
61
 
62
 
62
 
63
PROCEDURE movBool (VAR v: BOOLEAN; x: BOOLEAN);
63
PROCEDURE movBool (VAR v: BOOLEAN; x: BOOLEAN);
64
BEGIN
64
BEGIN
65
    _movBool(v, x)
65
    _movBool(v, x)
66
END movBool;
66
END movBool;
67
 
67
 
68
 
68
 
69
PROCEDURE movPtr (VAR v: List.tItem; x: List.tItem);
69
PROCEDURE movPtr (VAR v: List.tItem; x: List.tItem);
70
BEGIN
70
BEGIN
71
    _movPtr(v, x)
71
    _movPtr(v, x)
72
END movPtr;
72
END movPtr;
73
 
73
 
74
 
74
 
75
PROCEDURE malloc (size: INTEGER): INTEGER;
75
PROCEDURE malloc (size: INTEGER): INTEGER;
76
VAR
76
VAR
77
    ptr: INTEGER;
77
    ptr: INTEGER;
78
    maxLength: INTEGER;
78
    maxLength: INTEGER;
79
BEGIN
79
BEGIN
80
    ASSERT(pMaxLength # 0);
80
    ASSERT(pMaxLength # 0);
81
    SYSTEM.GET(pMaxLength, maxLength);
81
    SYSTEM.GET(pMaxLength, maxLength);
82
    IF size > maxLength THEN
82
    IF size > maxLength THEN
83
        SYSTEM.PUT(pMaxLength, size)
83
        SYSTEM.PUT(pMaxLength, size)
84
    END;
84
    END;
85
    size := size*WCHAR_SIZE + 4;
85
    size := size*WCHAR_SIZE + 4;
86
    INC(size, (-size) MOD 32);
86
    INC(size, (-size) MOD 32);
87
    ptr := API._NEW(size)
87
    ptr := API._NEW(size)
88
    RETURN ptr
88
    RETURN ptr
89
END malloc;
89
END malloc;
90
 
90
 
91
 
91
 
92
PROCEDURE free (line: tLine; newPtr: INTEGER);
92
PROCEDURE free (line: tLine; newPtr: INTEGER);
93
BEGIN
93
BEGIN
94
    IF line.ptr # 0 THEN
94
    IF line.ptr # 0 THEN
95
        IF line.temp THEN
95
        IF line.temp THEN
96
            line.ptr := API._DISPOSE(line.ptr)
96
            line.ptr := API._DISPOSE(line.ptr)
97
        ELSE
97
        ELSE
98
            line.ptr := 0
98
            line.ptr := 0
99
        END
99
        END
100
    END;
100
    END;
101
    IF ~line.temp THEN
101
    IF ~line.temp THEN
102
        movInt(line.ptr, newPtr);
102
        movInt(line.ptr, newPtr);
103
(*        IF newPtr # 0 THEN
103
(*        IF newPtr # 0 THEN
104
            _untypedPtr(newPtr)
104
            _untypedPtr(newPtr)
105
        END*)
105
        END*)
106
    END;
106
    END;
107
    line.ptr := newPtr
107
    line.ptr := newPtr
108
END free;
108
END free;
109
 
109
 
110
 
110
 
111
PROCEDURE create* (temp: BOOLEAN): tLine;
111
PROCEDURE create* (temp: BOOLEAN): tLine;
112
VAR
112
VAR
113
    line: tLine;
113
    line: tLine;
114
BEGIN
114
BEGIN
115
    NEW(line);
115
    NEW(line);
-
 
116
    line.label := FALSE;
116
    ASSERT(line # NIL);
117
    ASSERT(line # NIL);
117
(*    IF ~temp THEN
118
(*    IF ~temp THEN
118
        _typedPtr(line)
119
        _typedPtr(line)
119
    END;*)
120
    END;*)
120
    line.next := NIL;
121
    line.next := NIL;
121
    line.prev := NIL;
122
    line.prev := NIL;
122
    IF ~temp THEN
123
    IF ~temp THEN
123
        movPtr(line.next, NIL);
124
        movPtr(line.next, NIL);
124
        movPtr(line.prev, NIL)
125
        movPtr(line.prev, NIL)
125
    END;
126
    END;
126
    line.ptr := malloc(1);
127
    line.ptr := malloc(1);
127
    ASSERT(line.ptr # 0);
128
    ASSERT(line.ptr # 0);
128
    IF ~temp THEN
129
    IF ~temp THEN
129
        (*_untypedPtr(line.ptr);*)
130
        (*_untypedPtr(line.ptr);*)
130
        movInt(line.ptr, line.ptr)
131
        movInt(line.ptr, line.ptr)
131
    END;
132
    END;
132
    SYSTEM.PUT16(line.ptr, 0);
133
    SYSTEM.PUT16(line.ptr, 0);
133
    line.length := 0;
134
    line.length := 0;
134
    IF ~temp THEN
135
    IF ~temp THEN
135
        movInt(line.length, 0)
136
        movInt(line.length, 0)
136
    END;
137
    END;
137
    line.temp := temp;
138
    line.temp := temp;
138
    line.modified := FALSE;
139
    line.modified := FALSE;
139
    line.saved := FALSE;
140
    line.saved := FALSE;
140
    IF ~temp THEN
141
    IF ~temp THEN
141
        movBool(line.modified, FALSE);
142
        movBool(line.modified, FALSE);
142
        movBool(line.saved, FALSE)
143
        movBool(line.saved, FALSE)
143
    END;
144
    END;
144
    line.cin := 0;
145
    line.cin := 0;
145
    line.cout := 0;
146
    line.cout := 0;
146
    line.pos := 0
147
    line.pos := 0
147
    RETURN line
148
    RETURN line
148
END create;
149
END create;
149
 
150
 
150
 
151
 
151
PROCEDURE destroy* (VAR line: tLine);
152
PROCEDURE destroy* (VAR line: tLine);
152
BEGIN
153
BEGIN
153
    IF line.temp THEN
154
    IF line.temp THEN
154
        free(line, 0);
155
        free(line, 0);
155
        DISPOSE(line)
156
        DISPOSE(line)
156
    ELSE
157
    ELSE
157
        line := NIL
158
        line := NIL
158
    END
159
    END
159
END destroy;
160
END destroy;
160
 
161
 
161
 
162
 
162
PROCEDURE modify* (line: tLine);
163
PROCEDURE modify* (line: tLine);
163
BEGIN
164
BEGIN
164
    IF ~line.temp THEN
165
    IF ~line.temp THEN
165
        movBool(line.modified, TRUE);
166
        movBool(line.modified, TRUE);
166
        movBool(line.saved, FALSE)
167
        movBool(line.saved, FALSE)
167
    END;
168
    END;
168
    line.modified := TRUE;
169
    line.modified := TRUE;
169
    line.saved := FALSE
170
    line.saved := FALSE
170
END modify;
171
END modify;
171
 
172
 
172
 
173
 
173
PROCEDURE save* (line: tLine);
174
PROCEDURE save* (line: tLine);
174
BEGIN
175
BEGIN
175
    IF ~line.temp THEN
176
    IF ~line.temp THEN
176
        movBool(line.saved, TRUE);
177
        movBool(line.saved, TRUE);
177
        movBool(line.modified, FALSE)
178
        movBool(line.modified, FALSE)
178
    END;
179
    END;
179
    line.modified := FALSE;
180
    line.modified := FALSE;
180
    line.saved := TRUE
181
    line.saved := TRUE
181
END save;
182
END save;
182
 
183
 
183
 
184
 
184
PROCEDURE getChar* (line: tLine; i: INTEGER): WCHAR;
185
PROCEDURE getChar* (line: tLine; i: INTEGER): WCHAR;
185
VAR
186
VAR
186
    c: WCHAR;
187
    c: WCHAR;
187
BEGIN
188
BEGIN
188
    SYSTEM.GET(line.ptr + i*WCHAR_SIZE, c)
189
    SYSTEM.GET(line.ptr + i*WCHAR_SIZE, c)
189
    RETURN c
190
    RETURN c
190
END getChar;
191
END getChar;
191
 
192
 
192
 
193
 
193
PROCEDURE trimLength* (line: tLine): INTEGER;
194
PROCEDURE trimLength* (line: tLine): INTEGER;
194
VAR
195
VAR
195
    i: INTEGER;
196
    i: INTEGER;
196
BEGIN
197
BEGIN
197
    i := line.length - 1;
198
    i := line.length - 1;
198
    WHILE (i >= 0) & (getChar(line, i) = SPACE) DO
199
    WHILE (i >= 0) & (getChar(line, i) = SPACE) DO
199
        DEC(i)
200
        DEC(i)
200
    END
201
    END
201
    RETURN i + 1
202
    RETURN i + 1
202
END trimLength;
203
END trimLength;
203
 
204
 
204
 
205
 
205
PROCEDURE getPChar* (line: tLine; i: INTEGER): INTEGER;
206
PROCEDURE getPChar* (line: tLine; i: INTEGER): INTEGER;
206
    RETURN line.ptr + i*WCHAR_SIZE
207
    RETURN line.ptr + i*WCHAR_SIZE
207
END getPChar;
208
END getPChar;
208
 
209
 
209
 
210
 
210
PROCEDURE setChar* (line: tLine; i: INTEGER; c: WCHAR);
211
PROCEDURE setChar* (line: tLine; i: INTEGER; c: WCHAR);
211
BEGIN
212
BEGIN
212
    SYSTEM.PUT(line.ptr + i*WCHAR_SIZE, c)
213
    SYSTEM.PUT(line.ptr + i*WCHAR_SIZE, c)
213
END setChar;
214
END setChar;
214
 
215
 
215
 
216
 
216
PROCEDURE move* (src, dst: tLine);
217
PROCEDURE move* (src, dst: tLine);
217
BEGIN
218
BEGIN
218
    SYSTEM.MOVE(src.ptr, dst.ptr, (MIN(src.length, dst.length) + 1)*WCHAR_SIZE)
219
    SYSTEM.MOVE(src.ptr, dst.ptr, (MIN(src.length, dst.length) + 1)*WCHAR_SIZE)
219
END move;
220
END move;
220
 
221
 
221
 
222
 
222
PROCEDURE concat* (line: tLine; s: ARRAY OF WCHAR);
223
PROCEDURE concat* (line: tLine; s: ARRAY OF WCHAR);
223
VAR
224
VAR
224
    Len: INTEGER;
225
    Len: INTEGER;
225
    ptr: INTEGER;
226
    ptr: INTEGER;
226
BEGIN
227
BEGIN
227
    Len := LENGTH(s);
228
    Len := LENGTH(s);
228
    ptr := malloc(line.length + Len + 1);
229
    ptr := malloc(line.length + Len + 1);
229
    ASSERT(ptr # 0);
230
    ASSERT(ptr # 0);
230
    SYSTEM.MOVE(line.ptr, ptr, line.length*WCHAR_SIZE);
231
    SYSTEM.MOVE(line.ptr, ptr, line.length*WCHAR_SIZE);
231
    SYSTEM.MOVE(SYSTEM.ADR(s[0]), ptr + line.length*WCHAR_SIZE, Len*WCHAR_SIZE);
232
    SYSTEM.MOVE(SYSTEM.ADR(s[0]), ptr + line.length*WCHAR_SIZE, Len*WCHAR_SIZE);
232
    SYSTEM.PUT16(ptr + (line.length + Len)*WCHAR_SIZE, 0);
233
    SYSTEM.PUT16(ptr + (line.length + Len)*WCHAR_SIZE, 0);
233
    IF ~line.temp THEN
234
    IF ~line.temp THEN
234
        movInt(line.length, line.length + Len)
235
        movInt(line.length, line.length + Len)
235
    END;
236
    END;
236
    INC(line.length, Len);
237
    INC(line.length, Len);
237
    free(line, ptr)
238
    free(line, ptr)
238
END concat;
239
END concat;
239
 
240
 
240
 
241
 
241
PROCEDURE delChar* (line: tLine; pos: INTEGER);
242
PROCEDURE delChar* (line: tLine; pos: INTEGER);
242
VAR
243
VAR
243
    ptr: INTEGER;
244
    ptr: INTEGER;
244
BEGIN
245
BEGIN
245
    IF pos < line.length THEN
246
    IF pos < line.length THEN
246
        ptr := malloc(line.length);
247
        ptr := malloc(line.length);
247
        ASSERT(ptr # 0);
248
        ASSERT(ptr # 0);
248
        IF ~line.temp THEN
249
        IF ~line.temp THEN
249
            movInt(line.length, line.length - 1)
250
            movInt(line.length, line.length - 1)
250
        END;
251
        END;
251
        DEC(line.length);
252
        DEC(line.length);
252
        SYSTEM.MOVE(line.ptr, ptr, pos*WCHAR_SIZE);
253
        SYSTEM.MOVE(line.ptr, ptr, pos*WCHAR_SIZE);
253
        SYSTEM.MOVE(line.ptr + pos*WCHAR_SIZE + WCHAR_SIZE, ptr + pos*WCHAR_SIZE, (line.length - pos)*WCHAR_SIZE);
254
        SYSTEM.MOVE(line.ptr + pos*WCHAR_SIZE + WCHAR_SIZE, ptr + pos*WCHAR_SIZE, (line.length - pos)*WCHAR_SIZE);
254
        SYSTEM.PUT16(ptr + line.length*WCHAR_SIZE, 0);
255
        SYSTEM.PUT16(ptr + line.length*WCHAR_SIZE, 0);
255
        free(line, ptr)
256
        free(line, ptr)
256
    END
257
    END
257
END delChar;
258
END delChar;
258
 
259
 
259
 
260
 
260
PROCEDURE insert* (line: tLine; pos: INTEGER; c: WCHAR);
261
PROCEDURE insert* (line: tLine; pos: INTEGER; c: WCHAR);
261
VAR
262
VAR
262
    ptr: INTEGER;
263
    ptr: INTEGER;
263
BEGIN
264
BEGIN
264
    ptr := malloc(line.length + 2);
265
    ptr := malloc(line.length + 2);
265
    ASSERT(ptr # 0);
266
    ASSERT(ptr # 0);
266
    SYSTEM.MOVE(line.ptr, ptr, pos*WCHAR_SIZE);
267
    SYSTEM.MOVE(line.ptr, ptr, pos*WCHAR_SIZE);
267
    SYSTEM.PUT(ptr + pos*WCHAR_SIZE, c);
268
    SYSTEM.PUT(ptr + pos*WCHAR_SIZE, c);
268
    SYSTEM.MOVE(line.ptr + pos*WCHAR_SIZE, ptr + pos*WCHAR_SIZE + WCHAR_SIZE, (line.length - pos)*WCHAR_SIZE);
269
    SYSTEM.MOVE(line.ptr + pos*WCHAR_SIZE, ptr + pos*WCHAR_SIZE + WCHAR_SIZE, (line.length - pos)*WCHAR_SIZE);
269
    IF ~line.temp THEN
270
    IF ~line.temp THEN
270
        movInt(line.length, line.length + 1)
271
        movInt(line.length, line.length + 1)
271
    END;
272
    END;
272
    INC(line.length);
273
    INC(line.length);
273
    SYSTEM.PUT16(ptr + line.length*WCHAR_SIZE, 0);
274
    SYSTEM.PUT16(ptr + line.length*WCHAR_SIZE, 0);
274
    free(line, ptr)
275
    free(line, ptr)
275
END insert;
276
END insert;
276
 
277
 
277
 
278
 
278
PROCEDURE insert2* (line1: tLine; pos: INTEGER; line2: tLine);
279
PROCEDURE insert2* (line1: tLine; pos: INTEGER; line2: tLine);
279
VAR
280
VAR
280
    ptr: INTEGER;
281
    ptr: INTEGER;
281
BEGIN
282
BEGIN
282
    IF line2.length > 0 THEN
283
    IF line2.length > 0 THEN
283
        ptr := malloc(line1.length + line2.length + 1);
284
        ptr := malloc(line1.length + line2.length + 1);
284
        ASSERT(ptr # 0);
285
        ASSERT(ptr # 0);
285
        SYSTEM.MOVE(line1.ptr, ptr, pos*WCHAR_SIZE);
286
        SYSTEM.MOVE(line1.ptr, ptr, pos*WCHAR_SIZE);
286
        SYSTEM.MOVE(line2.ptr, ptr + pos*WCHAR_SIZE, line2.length*WCHAR_SIZE);
287
        SYSTEM.MOVE(line2.ptr, ptr + pos*WCHAR_SIZE, line2.length*WCHAR_SIZE);
287
        SYSTEM.MOVE(line1.ptr + pos*WCHAR_SIZE, ptr + (pos + line2.length)*WCHAR_SIZE, (line1.length - pos)*WCHAR_SIZE);
288
        SYSTEM.MOVE(line1.ptr + pos*WCHAR_SIZE, ptr + (pos + line2.length)*WCHAR_SIZE, (line1.length - pos)*WCHAR_SIZE);
288
        SYSTEM.PUT16(ptr + (line1.length + line2.length)*WCHAR_SIZE, 0);
289
        SYSTEM.PUT16(ptr + (line1.length + line2.length)*WCHAR_SIZE, 0);
289
        IF ~line1.temp THEN
290
        IF ~line1.temp THEN
290
            movInt(line1.length, line1.length + line2.length)
291
            movInt(line1.length, line1.length + line2.length)
291
        END;
292
        END;
292
        IF ~line2.temp THEN
293
        IF ~line2.temp THEN
293
            movInt(line2.length, 0)
294
            movInt(line2.length, 0)
294
        END;
295
        END;
295
        INC(line1.length, line2.length);
296
        INC(line1.length, line2.length);
296
        line2.length := 0;
297
        line2.length := 0;
297
        free(line1, ptr);
298
        free(line1, ptr);
298
        free(line2, 0)
299
        free(line2, 0)
299
    END
300
    END
300
END insert2;
301
END insert2;
301
 
302
 
302
 
303
 
303
PROCEDURE insert3* (line: tLine; pos, n: INTEGER);
304
PROCEDURE insert3* (line: tLine; pos, n: INTEGER);
304
VAR
305
VAR
305
    ptr: INTEGER;
306
    ptr: INTEGER;
306
BEGIN
307
BEGIN
307
    IF n > 0 THEN
308
    IF n > 0 THEN
308
        ptr := malloc(line.length + n + 1);
309
        ptr := malloc(line.length + n + 1);
309
        ASSERT(ptr # 0);
310
        ASSERT(ptr # 0);
310
        SYSTEM.MOVE(line.ptr, ptr, pos*WCHAR_SIZE);
311
        SYSTEM.MOVE(line.ptr, ptr, pos*WCHAR_SIZE);
311
        SYSTEM.MOVE(line.ptr + pos*WCHAR_SIZE, ptr + (pos + n)*WCHAR_SIZE, (line.length - pos)*WCHAR_SIZE);
312
        SYSTEM.MOVE(line.ptr + pos*WCHAR_SIZE, ptr + (pos + n)*WCHAR_SIZE, (line.length - pos)*WCHAR_SIZE);
312
        SYSTEM.PUT16(ptr + (line.length + n)*WCHAR_SIZE, 0);
313
        SYSTEM.PUT16(ptr + (line.length + n)*WCHAR_SIZE, 0);
313
        IF ~line.temp THEN
314
        IF ~line.temp THEN
314
            movInt(line.length, line.length + n)
315
            movInt(line.length, line.length + n)
315
        END;
316
        END;
316
        INC(line.length, n);
317
        INC(line.length, n);
317
        free(line, ptr)
318
        free(line, ptr)
318
    END
319
    END
319
END insert3;
320
END insert3;
320
 
321
 
321
 
322
 
322
PROCEDURE delCharN* (line: tLine; pos, n: INTEGER);
323
PROCEDURE delCharN* (line: tLine; pos, n: INTEGER);
323
VAR
324
VAR
324
    ptr: INTEGER;
325
    ptr: INTEGER;
325
BEGIN
326
BEGIN
326
    IF n > 0 THEN
327
    IF n > 0 THEN
327
        ptr := malloc(line.length - n + 1);
328
        ptr := malloc(line.length - n + 1);
328
        ASSERT(ptr # 0);
329
        ASSERT(ptr # 0);
329
        SYSTEM.MOVE(line.ptr, ptr, pos*WCHAR_SIZE);
330
        SYSTEM.MOVE(line.ptr, ptr, pos*WCHAR_SIZE);
330
        SYSTEM.MOVE(line.ptr + (pos + n)*WCHAR_SIZE, ptr + pos*WCHAR_SIZE, (line.length - pos - n)*WCHAR_SIZE);
331
        SYSTEM.MOVE(line.ptr + (pos + n)*WCHAR_SIZE, ptr + pos*WCHAR_SIZE, (line.length - pos - n)*WCHAR_SIZE);
331
        SYSTEM.PUT16(ptr + (line.length - n)*WCHAR_SIZE, 0);
332
        SYSTEM.PUT16(ptr + (line.length - n)*WCHAR_SIZE, 0);
332
        IF ~line.temp THEN
333
        IF ~line.temp THEN
333
            movInt(line.length, line.length - n)
334
            movInt(line.length, line.length - n)
334
        END;
335
        END;
335
        DEC(line.length, n);
336
        DEC(line.length, n);
336
        free(line, ptr)
337
        free(line, ptr)
337
    END
338
    END
338
END delCharN;
339
END delCharN;
339
 
340
 
340
 
341
 
341
PROCEDURE wrap* (line, nextLine: tLine; pos: INTEGER);
342
PROCEDURE wrap* (line, nextLine: tLine; pos: INTEGER);
342
VAR
343
VAR
343
    ptr1, ptr2: INTEGER;
344
    ptr1, ptr2: INTEGER;
344
    n: INTEGER;
345
    n: INTEGER;
345
BEGIN
346
BEGIN
346
    ptr1 := malloc(pos + 1);
347
    ptr1 := malloc(pos + 1);
347
    ASSERT(ptr1 # 0);
348
    ASSERT(ptr1 # 0);
348
    n := line.length - pos;
349
    n := line.length - pos;
349
    ptr2 := malloc(n + 1);
350
    ptr2 := malloc(n + 1);
350
    ASSERT(ptr2 # 0);
351
    ASSERT(ptr2 # 0);
351
    SYSTEM.MOVE(line.ptr, ptr1, pos*WCHAR_SIZE);
352
    SYSTEM.MOVE(line.ptr, ptr1, pos*WCHAR_SIZE);
352
    SYSTEM.PUT16(ptr1 + pos*WCHAR_SIZE, 0);
353
    SYSTEM.PUT16(ptr1 + pos*WCHAR_SIZE, 0);
353
    SYSTEM.MOVE(line.ptr + pos*WCHAR_SIZE, ptr2, n*WCHAR_SIZE);
354
    SYSTEM.MOVE(line.ptr + pos*WCHAR_SIZE, ptr2, n*WCHAR_SIZE);
354
    SYSTEM.PUT16(ptr2 + n*WCHAR_SIZE, 0);
355
    SYSTEM.PUT16(ptr2 + n*WCHAR_SIZE, 0);
355
    IF ~line.temp THEN
356
    IF ~line.temp THEN
356
        movInt(line.length, pos)
357
        movInt(line.length, pos)
357
    END;
358
    END;
358
    IF ~nextLine.temp THEN
359
    IF ~nextLine.temp THEN
359
        movInt(nextLine.length, n)
360
        movInt(nextLine.length, n)
360
    END;
361
    END;
361
    line.length := pos;
362
    line.length := pos;
362
    nextLine.length := n;
363
    nextLine.length := n;
363
    free(line, ptr1);
364
    free(line, ptr1);
364
    free(nextLine, ptr2)
365
    free(nextLine, ptr2)
365
END wrap;
366
END wrap;
366
 
367
 
367
 
368
 
368
PROCEDURE copy* (line: tLine);
369
PROCEDURE copy* (line: tLine);
369
VAR
370
VAR
370
    ptr: INTEGER;
371
    ptr: INTEGER;
371
BEGIN
372
BEGIN
372
    ptr := malloc(line.length + 1);
373
    ptr := malloc(line.length + 1);
373
    ASSERT(ptr # 0);
374
    ASSERT(ptr # 0);
374
    SYSTEM.MOVE(line.ptr, ptr, line.length*WCHAR_SIZE);
375
    SYSTEM.MOVE(line.ptr, ptr, line.length*WCHAR_SIZE);
375
    SYSTEM.PUT16(ptr + line.length*WCHAR_SIZE, 0);
376
    SYSTEM.PUT16(ptr + line.length*WCHAR_SIZE, 0);
376
    free(line, ptr)
377
    free(line, ptr)
377
END copy;
378
END copy;
378
 
379
 
379
 
380
 
380
PROCEDURE chCase* (line: tLine; pos1, pos2: INTEGER; upper: BOOLEAN): BOOLEAN;
381
PROCEDURE chCase* (line: tLine; pos1, pos2: INTEGER; upper: BOOLEAN): BOOLEAN;
381
VAR
382
VAR
382
    i: INTEGER;
383
    i: INTEGER;
383
    modified: BOOLEAN;
384
    modified: BOOLEAN;
384
    c: WCHAR;
385
    c: WCHAR;
385
    func: PROCEDURE (VAR c: WCHAR): BOOLEAN;
386
    func: PROCEDURE (VAR c: WCHAR): BOOLEAN;
386
BEGIN
387
BEGIN
387
    modified := FALSE;
388
    modified := FALSE;
388
    IF upper THEN
389
    IF upper THEN
389
        func := Utils.cap
390
        func := Utils.cap
390
    ELSE
391
    ELSE
391
        func := Utils.low
392
        func := Utils.low
392
    END;
393
    END;
393
    i := pos2;
394
    i := pos2;
394
    WHILE i >= pos1 DO
395
    WHILE i >= pos1 DO
395
        c := getChar(line, i);
396
        c := getChar(line, i);
396
        IF func(c) THEN
397
        IF func(c) THEN
397
            modified := TRUE
398
            modified := TRUE
398
        END;
399
        END;
399
        DEC(i)
400
        DEC(i)
400
    END;
401
    END;
401
 
402
 
402
    IF modified THEN
403
    IF modified THEN
403
        copy(line);
404
        copy(line);
404
        i := pos2;
405
        i := pos2;
405
        WHILE i >= pos1 DO
406
        WHILE i >= pos1 DO
406
            c := getChar(line, i);
407
            c := getChar(line, i);
407
            IF func(c) THEN
408
            IF func(c) THEN
408
                setChar(line, i, c)
409
                setChar(line, i, c)
409
            END;
410
            END;
410
            DEC(i)
411
            DEC(i)
411
        END;
412
        END;
412
        modify(line)
413
        modify(line)
413
    END
414
    END
414
    RETURN modified
415
    RETURN modified
415
END chCase;
416
END chCase;
416
 
417
 
417
 
418
 
418
PROCEDURE init* (movInt: PmovInt; movPtr: PmovPtr; movBool: PmovBool(*; typedPtr: PTypedPtr; untypedPtr: PUntypedPtr*));
419
PROCEDURE init* (movInt: PmovInt; movPtr: PmovPtr; movBool: PmovBool(*; typedPtr: PTypedPtr; untypedPtr: PUntypedPtr*));
419
BEGIN
420
BEGIN
420
    _movInt := movInt;
421
    _movInt := movInt;
421
    _movPtr := movPtr;
422
    _movPtr := movPtr;
422
    _movBool := movBool;
423
    _movBool := movBool;
423
(*    _typedPtr := typedPtr;
424
(*    _typedPtr := typedPtr;
424
    _untypedPtr := untypedPtr;*)
425
    _untypedPtr := untypedPtr;*)
425
END init;
426
END init;
426
 
427
 
427
 
428
 
428
PROCEDURE setMaxLength* (VAR maxLength: INTEGER);
429
PROCEDURE setMaxLength* (VAR maxLength: INTEGER);
429
BEGIN
430
BEGIN
430
    pMaxLength := SYSTEM.ADR(maxLength)
431
    pMaxLength := SYSTEM.ADR(maxLength)
431
END setMaxLength;
432
END setMaxLength;
432
 
433
 
433
 
434
 
434
BEGIN
435
BEGIN
435
    pMaxLength := 0
436
    pMaxLength := 0
436
END Lines.
437
END Lines.