Subversion Repositories Kolibri OS

Rev

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

Rev 9891 Rev 9892
1
(*
1
(*
2
    Copyright 2021-2023 Anton Krotov
2
    Copyright 2021-2023 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 Text;
20
MODULE Text;
21
 
21
 
22
IMPORT
22
IMPORT
23
    List, Lines,
23
    List, Lines,
24
    G := Graph,
24
    G := Graph,
25
    U := Utils,
25
    U := Utils,
26
    RW, Search,
26
    RW, Search,
27
    E := Encodings,
27
    E := Encodings,
28
    CB := Clipboard,
28
    CB := Clipboard,
29
    ChangeLog, File,
29
    ChangeLog, File,
30
    Lang := Languages;
30
    Lang := Languages;
31
 
31
 
32
 
32
 
33
CONST
33
CONST
34
 
34
 
35
    SPACE = Lines.SPACE;
35
    SPACE = Lines.SPACE;
36
    TAB = Lines.TAB;
36
    TAB = Lines.TAB;
37
    TAB1 = Lines.TAB1;
37
    TAB1 = Lines.TAB1;
38
    lenEOL = CB.lenEOL;
38
    lenEOL = CB.lenEOL;
39
 
39
 
40
    mark_width = 2;
40
    mark_width = 2;
41
    pad_left = mark_width + 3;
41
    pad_left = mark_width + 3;
42
    pad_top = 0;
42
    pad_top = 1;
43
    inter = 2;
43
    inter = 2;
44
 
44
 
45
 
45
 
46
TYPE
46
TYPE
47
 
47
 
48
    tPoint* = RECORD
48
    tPoint* = RECORD
49
        X*, Y*: INTEGER
49
        X*, Y*: INTEGER
50
    END;
50
    END;
51
 
51
 
52
    pPoint = POINTER TO tPoint;
52
    pPoint = POINTER TO tPoint;
53
 
53
 
54
    tString* = ARRAY 1000 OF WCHAR;
54
    tString* = ARRAY 1000 OF WCHAR;
55
 
55
 
56
    tLine = Lines.tLine;
56
    tLine = Lines.tLine;
57
 
57
 
58
    tGuard = POINTER TO RECORD (ChangeLog.tGuard)
58
    tGuard = POINTER TO RECORD (ChangeLog.tGuard)
59
        selected: BOOLEAN;
59
        selected: BOOLEAN;
60
        cursor, select2, scroll: tPoint;
60
        cursor, select2, scroll: tPoint;
61
        CurX: INTEGER
61
        CurX: INTEGER
62
    END;
62
    END;
63
 
63
 
64
    tText* = POINTER TO RECORD (List.tList)
64
    tText* = POINTER TO RECORD (List.tList)
65
        cursor, select, select2: pPoint;
65
        cursor, select, select2: pPoint;
66
        scroll: tPoint;
66
        scroll: tPoint;
67
        CurX: INTEGER;
67
        CurX: INTEGER;
68
        smallChange: INTEGER;
68
        smallChange: INTEGER;
69
        modified*, smallMove,
69
        modified*, smallMove,
70
        comments, guard, fasm*,
70
        comments, guard, fasm*,
71
        search, cs, whole: BOOLEAN;
71
        search, cs, whole: BOOLEAN;
72
        edition*: tGuard;
72
        edition*: tGuard;
73
        curLine: tLine;
73
        curLine: tLine;
74
        lang*: INTEGER;
74
        lang*: INTEGER;
75
        enc, eol: INTEGER;
75
        enc, eol: INTEGER;
76
        foundList: List.tList;
76
        foundList: List.tList;
77
        foundSel: INTEGER;
77
        foundSel: INTEGER;
78
        searchText: tString;
78
        searchText: tString;
79
        LinesVector: Lines.tVector;
79
        LinesVector: Lines.tVector;
80
        chLog*: ChangeLog.tLog;
80
        chLog*: ChangeLog.tLog;
81
        maxLength*: INTEGER;
81
        maxLength*: INTEGER;
82
        fileName*: RW.tFileName
82
        fileName*: RW.tFileName
83
    END;
83
    END;
84
 
84
 
85
    tProcedure = PROCEDURE;
85
    tProcedure = PROCEDURE;
86
 
86
 
87
 
87
 
88
VAR
88
VAR
89
 
89
 
90
    pdelete: PROCEDURE (text: tText);
90
    pdelete: PROCEDURE (text: tText);
91
    ShowCursor: PROCEDURE;
91
    ShowCursor: PROCEDURE;
92
 
92
 
93
    colors: RECORD
93
    colors: RECORD
94
                text, back, seltext, selback, modified, saved, curline, numtext, numback: INTEGER;
94
                text, back, seltext, selback, modified, saved, curline, numtext, numback: INTEGER;
95
                comment, string, escape, num, delim, key1, key2, key3: INTEGER
95
                comment, string, escape, num, delim, key1, key2, key3: INTEGER
96
             END;
96
             END;
97
    canvas: G.tCanvas;
97
    canvas: G.tCanvas;
98
    drawCursor: BOOLEAN;
98
    drawCursor: BOOLEAN;
99
    padding: RECORD left, top: INTEGER END;
99
    padding: RECORD left, top: INTEGER END;
100
    size, textsize: tPoint;
100
    size, textsize: tPoint;
101
    charWidth, charHeight: INTEGER;
101
    charWidth, charHeight: INTEGER;
102
    autoIndents*, lineNumbers*, autoBrackets*, trimSpace*: BOOLEAN;
102
    autoIndents*, lineNumbers*, autoBrackets*, trimSpace*: BOOLEAN;
103
    idxTable: Search.IdxTable;
103
    idxTable: Search.IdxTable;
104
 
104
 
105
 
105
 
106
PROCEDURE setLang* (text: tText; lang: INTEGER);
106
PROCEDURE setLang* (text: tText; lang: INTEGER);
107
BEGIN
107
BEGIN
108
	IF text.lang # lang THEN
108
	IF text.lang # lang THEN
109
		text.fasm := lang = Lang.langFasm;
109
		text.fasm := lang = Lang.langFasm;
110
		text.lang := lang
110
		text.lang := lang
111
	END;
111
	END;
112
    text.comments := TRUE;
112
    text.comments := TRUE;
113
    Lang.setCurLang(text.lang)
113
    Lang.setCurLang(text.lang)
114
END setLang;
114
END setLang;
115
 
115
 
116
 
116
 
117
PROCEDURE setName* (text: tText; name: RW.tFileName);
117
PROCEDURE setName* (text: tText; name: RW.tFileName);
118
VAR
118
VAR
119
    ext: RW.tFileName;
119
    ext: RW.tFileName;
120
BEGIN
120
BEGIN
121
    text.fileName := name;
121
    text.fileName := name;
122
    U.getFileName(name, ext, ".");
122
    U.getFileName(name, ext, ".");
123
    U.upcase(ext);
123
    U.upcase(ext);
124
    setLang(text, Lang.getLang(ext))
124
    setLang(text, Lang.getLang(ext))
125
END setName;
125
END setName;
126
 
126
 
127
 
127
 
128
PROCEDURE getPos* (text: tText; VAR x, y: INTEGER);
128
PROCEDURE getPos* (text: tText; VAR x, y: INTEGER);
129
BEGIN
129
BEGIN
130
    x := text.cursor.X + 1;
130
    x := text.cursor.X + 1;
131
    y := text.cursor.Y + 1
131
    y := text.cursor.Y + 1
132
END getPos;
132
END getPos;
133
 
133
 
134
 
134
 
135
PROCEDURE getScroll* (text: tText; VAR x, y: INTEGER);
135
PROCEDURE getScroll* (text: tText; VAR x, y: INTEGER);
136
BEGIN
136
BEGIN
137
    x := text.scroll.X;
137
    x := text.scroll.X;
138
    y := text.scroll.Y
138
    y := text.scroll.Y
139
END getScroll;
139
END getScroll;
140
 
140
 
141
 
141
 
142
PROCEDURE getTextSize* (VAR x, y: INTEGER);
142
PROCEDURE getTextSize* (VAR x, y: INTEGER);
143
BEGIN
143
BEGIN
144
    x := textsize.X;
144
    x := textsize.X;
145
    y := textsize.Y
145
    y := textsize.Y
146
END getTextSize;
146
END getTextSize;
147
 
147
 
148
 
148
 
149
PROCEDURE getTextRect* (VAR left, top, rigth, bottom: INTEGER);
149
PROCEDURE getTextRect* (VAR left, top, rigth, bottom: INTEGER);
150
BEGIN
150
BEGIN
151
    left := padding.left - 1;
151
    left := padding.left - 1;
152
    top := padding.top - 1;
152
    top := padding.top - 1;
153
    rigth := size.X - 1;
153
    rigth := size.X - 1;
154
    bottom := top + size.Y - 1;
154
    bottom := top + size.Y - 1;
155
END getTextRect;
155
END getTextRect;
156
 
156
 
157
 
157
 
158
PROCEDURE toggleNumbers*;
158
PROCEDURE toggleNumbers*;
159
BEGIN
159
BEGIN
160
    lineNumbers := ~lineNumbers
160
    lineNumbers := ~lineNumbers
161
END toggleNumbers;
161
END toggleNumbers;
162
 
162
 
163
 
163
 
164
PROCEDURE toggleIndents*;
164
PROCEDURE toggleIndents*;
165
BEGIN
165
BEGIN
166
    autoIndents := ~autoIndents
166
    autoIndents := ~autoIndents
167
END toggleIndents;
167
END toggleIndents;
168
 
168
 
169
 
169
 
170
PROCEDURE toggleBrackets*;
170
PROCEDURE toggleBrackets*;
171
BEGIN
171
BEGIN
172
    autoBrackets := ~autoBrackets
172
    autoBrackets := ~autoBrackets
173
END toggleBrackets;
173
END toggleBrackets;
174
 
174
 
175
 
175
 
176
PROCEDURE toggleTrimSpace*;
176
PROCEDURE toggleTrimSpace*;
177
BEGIN
177
BEGIN
178
    trimSpace := ~trimSpace
178
    trimSpace := ~trimSpace
179
END toggleTrimSpace;
179
END toggleTrimSpace;
180
 
180
 
181
 
181
 
182
PROCEDURE showCursor*;
182
PROCEDURE showCursor*;
183
BEGIN
183
BEGIN
184
	drawCursor := TRUE
184
	drawCursor := TRUE
185
END showCursor;
185
END showCursor;
186
 
186
 
187
 
187
 
188
PROCEDURE hideCursor*;
188
PROCEDURE hideCursor*;
189
BEGIN
189
BEGIN
190
	drawCursor := FALSE
190
	drawCursor := FALSE
191
END hideCursor;
191
END hideCursor;
192
 
192
 
193
 
193
 
194
PROCEDURE getString (src: tLine; pos, cnt: INTEGER; VAR dst: ARRAY OF WCHAR): INTEGER;
194
PROCEDURE getString (src: tLine; pos, cnt: INTEGER; VAR dst: ARRAY OF WCHAR): INTEGER;
195
VAR
195
VAR
196
    i: INTEGER;
196
    i: INTEGER;
197
BEGIN
197
BEGIN
198
    i := 0;
198
    i := 0;
199
    WHILE (pos < src.length) & (cnt > 0) DO
199
    WHILE (pos < src.length) & (cnt > 0) DO
200
        IF i < LEN(dst) - 1 THEN
200
        IF i < LEN(dst) - 1 THEN
201
            dst[i] := Lines.getChar(src, pos);
201
            dst[i] := Lines.getChar(src, pos);
202
            INC(i)
202
            INC(i)
203
        END;
203
        END;
204
        INC(pos);
204
        INC(pos);
205
        DEC(cnt)
205
        DEC(cnt)
206
    END;
206
    END;
207
    dst[i] := 0X
207
    dst[i] := 0X
208
    RETURN i
208
    RETURN i
209
END getString;
209
END getString;
210
 
210
 
211
 
211
 
212
PROCEDURE NextLine (VAR line: tLine);
212
PROCEDURE NextLine (VAR line: tLine);
213
BEGIN
213
BEGIN
214
    line := line.next(tLine)
214
    line := line.next(tLine)
215
END NextLine;
215
END NextLine;
216
 
216
 
217
 
217
 
218
PROCEDURE PrevLine (VAR line: tLine);
218
PROCEDURE PrevLine (VAR line: tLine);
219
BEGIN
219
BEGIN
220
    line := line.prev(tLine)
220
    line := line.prev(tLine)
221
END PrevLine;
221
END PrevLine;
222
 
222
 
223
 
223
 
224
PROCEDURE SetColor (textColor, backColor: INTEGER);
224
PROCEDURE SetColor (textColor, backColor: INTEGER);
225
BEGIN
225
BEGIN
226
    G.SetTextColor(canvas, textColor);
226
    G.SetTextColor(canvas, textColor);
227
    G.SetBkColor(canvas, backColor)
227
    G.SetBkColor(canvas, backColor)
228
END SetColor;
228
END SetColor;
229
 
229
 
230
 
230
 
231
PROCEDURE ProcessComments (line: tLine; VAR depth, pos: INTEGER; minDepth, n: INTEGER; lang: INTEGER);
231
PROCEDURE ProcessComments (line: tLine; VAR depth, pos: INTEGER; minDepth, n: INTEGER; lang: INTEGER);
232
VAR
232
VAR
233
    cond: INTEGER;
233
    cond: INTEGER;
234
BEGIN
234
BEGIN
235
    cond := 0;
235
    cond := 0;
236
    WHILE (pos <= n) & (depth > minDepth) DO
236
    WHILE (pos <= n) & (depth > minDepth) DO
237
        Lang.comments(line, depth, cond, pos, n, lang);
237
        Lang.comments(line, depth, cond, pos, n, lang);
238
        INC(pos)
238
        INC(pos)
239
    END;
239
    END;
240
    DEC(pos)
240
    DEC(pos)
241
END ProcessComments;
241
END ProcessComments;
242
 
242
 
243
 
243
 
244
PROCEDURE getLine2 (text: tText; n: INTEGER): tLine;
244
PROCEDURE getLine2 (text: tText; n: INTEGER): tLine;
245
VAR
245
VAR
246
	item: tLine;
246
	item: tLine;
247
BEGIN
247
BEGIN
248
	IF (0 <= n) & (n < text.count) THEN
248
	IF (0 <= n) & (n < text.count) THEN
249
		item := Lines.getVectorItem(text.LinesVector, n)
249
		item := Lines.getVectorItem(text.LinesVector, n)
250
	ELSE
250
	ELSE
251
		item := NIL
251
		item := NIL
252
	END
252
	END
253
	RETURN item
253
	RETURN item
254
END getLine2;
254
END getLine2;
255
 
255
 
256
 
256
 
257
PROCEDURE Comments (text: tText);
257
PROCEDURE Comments (text: tText);
258
VAR
258
VAR
259
	line: tLine;
259
	line: tLine;
260
	i, k, cout: INTEGER;
260
	i, k, cout: INTEGER;
261
BEGIN
261
BEGIN
262
	IF text.smallChange = 1 THEN
262
	IF text.smallChange = 1 THEN
263
		line := getLine2(text, text.cursor.Y);
263
		line := getLine2(text, text.cursor.Y);
264
		IF line.prev # NIL THEN
264
		IF line.prev # NIL THEN
265
			line.cin := line.prev(tLine).cout
265
			line.cin := line.prev(tLine).cout
266
		ELSE
266
		ELSE
267
			line.cin := 0
267
			line.cin := 0
268
		END;
268
		END;
269
		cout := line.cout;
269
		cout := line.cout;
270
		line.cout := line.cin;
270
		line.cout := line.cin;
271
		i := 0;
271
		i := 0;
272
		ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang);
272
		ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang);
273
		IF line.cout # cout THEN
273
		IF line.cout # cout THEN
274
			text.smallChange := 0;
274
			text.smallChange := 0;
275
			Comments(text)
275
			Comments(text)
276
		END
276
		END
277
	ELSE
277
	ELSE
278
		Lines.destroyVector(text.LinesVector);
278
		Lines.destroyVector(text.LinesVector);
279
		text.LinesVector := Lines.createVector(text.count);
279
		text.LinesVector := Lines.createVector(text.count);
280
		k := 0;
280
		k := 0;
281
		line := text.first(tLine);
281
		line := text.first(tLine);
282
		Lines.setVectorItem(text.LinesVector, k, line);
282
		Lines.setVectorItem(text.LinesVector, k, line);
283
		INC(k);
283
		INC(k);
284
		line.cin := 0;
284
		line.cin := 0;
285
		line.cout := 0;
285
		line.cout := 0;
286
		i := 0;
286
		i := 0;
287
		ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang);
287
		ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang);
288
		NextLine(line);
288
		NextLine(line);
289
		WHILE line # NIL DO
289
		WHILE line # NIL DO
290
			Lines.setVectorItem(text.LinesVector, k, line);
290
			Lines.setVectorItem(text.LinesVector, k, line);
291
			INC(k);
291
			INC(k);
292
			line.cin := line.prev(tLine).cout;
292
			line.cin := line.prev(tLine).cout;
293
			line.cout := line.cin;
293
			line.cout := line.cin;
294
			i := 0;
294
			i := 0;
295
			ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang);
295
			ProcessComments(line, line.cout, i, -1, line.length - 1, text.lang);
296
			NextLine(line)
296
			NextLine(line)
297
		END
297
		END
298
	END;
298
	END;
299
	text.smallChange := 0;
299
	text.smallChange := 0;
300
	text.comments := FALSE
300
	text.comments := FALSE
301
END Comments;
301
END Comments;
302
 
302
 
303
 
303
 
304
PROCEDURE leadingSpaces (line: tLine): INTEGER;
304
PROCEDURE leadingSpaces (line: tLine): INTEGER;
305
VAR
305
VAR
306
    i: INTEGER;
306
    i: INTEGER;
307
BEGIN
307
BEGIN
308
    i := 0;
308
    i := 0;
309
    WHILE Lines.isSpace(Lines.getChar(line, i)) DO
309
    WHILE Lines.isSpace(Lines.getChar(line, i)) DO
310
        INC(i)
310
        INC(i)
311
    END
311
    END
312
    RETURN i
312
    RETURN i
313
END leadingSpaces;
313
END leadingSpaces;
314
 
314
 
315
 
315
 
316
PROCEDURE parse (text: tText; line: tLine; y: INTEGER; backColor: INTEGER; lang: INTEGER);
316
PROCEDURE parse (text: tText; line: tLine; y: INTEGER; backColor: INTEGER; lang: INTEGER);
317
VAR
317
VAR
318
    c: WCHAR;
318
    c: WCHAR;
319
    i, n, k: INTEGER;
319
    i, n, k: INTEGER;
320
    cond, depth: INTEGER;
320
    cond, depth: INTEGER;
321
    color: INTEGER;
321
    color: INTEGER;
322
    hex: BOOLEAN;
322
    hex: BOOLEAN;
323
    isDgt: PROCEDURE (c: WCHAR): BOOLEAN;
323
    isDgt: PROCEDURE (c: WCHAR): BOOLEAN;
324
 
324
 
325
 
325
 
326
    PROCEDURE PrintLex (text: tText; line: tLine; lexStart, lexEnd: INTEGER; y: INTEGER; color, backColor: INTEGER);
326
    PROCEDURE PrintLex (text: tText; line: tLine; lexStart, lexEnd: INTEGER; y: INTEGER; color, backColor: INTEGER);
327
    VAR
327
    VAR
328
        lexLen: INTEGER;
328
        lexLen: INTEGER;
329
    BEGIN
329
    BEGIN
330
        SetColor(color, backColor);
330
        SetColor(color, backColor);
331
        lexLen := MAX(MIN(line.length - lexStart, lexEnd - lexStart + 1), 0);
331
        lexLen := MAX(MIN(line.length - lexStart, lexEnd - lexStart + 1), 0);
332
        G.TextOut(canvas, padding.left + (lexStart - text.scroll.X) * charWidth, y, Lines.getPChar(line, lexStart), lexLen, color)
332
        G.TextOut(canvas, padding.left + (lexStart - text.scroll.X) * charWidth, y, Lines.getPChar(line, lexStart), lexLen, color)
333
    END PrintLex;
333
    END PrintLex;
334
 
334
 
335
 
335
 
336
    PROCEDURE PrintComment (text: tText; line: tLine; VAR depth, i: INTEGER; w, y: INTEGER; backColor: INTEGER);
336
    PROCEDURE PrintComment (text: tText; line: tLine; VAR depth, i: INTEGER; w, y: INTEGER; backColor: INTEGER);
337
    VAR
337
    VAR
338
        lexStart: INTEGER;
338
        lexStart: INTEGER;
339
        color: INTEGER;
339
        color: INTEGER;
340
    BEGIN
340
    BEGIN
341
        IF (text.lang = Lang.langLua) & ~ODD(depth) THEN
341
        IF (text.lang = Lang.langLua) & ~ODD(depth) THEN
342
            color := colors.string
342
            color := colors.string
343
        ELSIF (text.lang = Lang.langIni) & (depth = 1) THEN
343
        ELSIF (text.lang = Lang.langIni) & (depth = 1) THEN
344
            color := colors.key2
344
            color := colors.key2
345
        ELSIF (text.lang = Lang.langPascal) & (depth = 3) THEN
345
        ELSIF (text.lang = Lang.langPascal) & (depth = 3) THEN
346
            color := colors.key3
346
            color := colors.key3
347
        ELSE
347
        ELSE
348
            color := colors.comment
348
            color := colors.comment
349
        END;
349
        END;
350
        lexStart := MAX(i - w, 0);
350
        lexStart := MAX(i - w, 0);
351
        ProcessComments(line, depth, i, 0, line.length - 1, text.lang);
351
        ProcessComments(line, depth, i, 0, line.length - 1, text.lang);
352
        PrintLex(text, line, lexStart, i, y, color, backColor)
352
        PrintLex(text, line, lexStart, i, y, color, backColor)
353
    END PrintComment;
353
    END PrintComment;
354
 
354
 
355
 
355
 
356
    PROCEDURE cap (c: WCHAR): WCHAR;
356
    PROCEDURE cap (c: WCHAR): WCHAR;
357
    BEGIN
357
    BEGIN
358
        IF U.cap(c) THEN END
358
        IF U.cap(c) THEN END
359
        RETURN c
359
        RETURN c
360
    END cap;
360
    END cap;
361
 
361
 
362
 
362
 
363
    PROCEDURE UL (c: WCHAR): BOOLEAN;
363
    PROCEDURE UL (c: WCHAR): BOOLEAN;
364
        RETURN (cap(c) = "U") OR (cap(c) = "L")
364
        RETURN (cap(c) = "U") OR (cap(c) = "L")
365
    END UL;
365
    END UL;
366
 
366
 
367
 
367
 
368
    PROCEDURE FL (c: WCHAR): BOOLEAN;
368
    PROCEDURE FL (c: WCHAR): BOOLEAN;
369
        RETURN (cap(c) = "F") OR (cap(c) = "L")
369
        RETURN (cap(c) = "F") OR (cap(c) = "L")
370
    END FL;
370
    END FL;
371
 
371
 
372
 
372
 
373
    PROCEDURE ident (text: tText; VAR i: INTEGER; first, y: INTEGER; line: tLine; backColor: INTEGER; cs: BOOLEAN);
373
    PROCEDURE ident (text: tText; VAR i: INTEGER; first, y: INTEGER; line: tLine; backColor: INTEGER; cs: BOOLEAN);
374
    VAR
374
    VAR
375
        c: WCHAR;
375
        c: WCHAR;
376
        lexLen: INTEGER;
376
        lexLen: INTEGER;
377
        s: ARRAY 32 OF WCHAR;
377
        s: ARRAY 32 OF WCHAR;
378
        color: INTEGER;
378
        color: INTEGER;
379
    BEGIN
379
    BEGIN
380
        c := Lines.getChar(line, i);
380
        c := Lines.getChar(line, i);
381
        WHILE U.isLetter(c) OR (c = "_") OR U.isDigit(c) DO
381
        WHILE U.isLetter(c) OR (c = "_") OR U.isDigit(c) DO
382
            INC(i);
382
            INC(i);
383
            c := Lines.getChar(line, i);
383
            c := Lines.getChar(line, i);
384
        END;
384
        END;
385
        DEC(i);
385
        DEC(i);
386
        lexLen := getString(line, first, i - first + 1, s);
386
        lexLen := getString(line, first, i - first + 1, s);
387
        IF ~cs THEN
387
        IF ~cs THEN
388
            U.upcase16(s)
388
            U.upcase16(s)
389
        END;
389
        END;
390
        IF Lang.isKey(s, text.lang, 1) THEN
390
        IF Lang.isKey(s, text.lang, 1) THEN
391
            color := colors.key1
391
            color := colors.key1
392
        ELSIF Lang.isKey(s, text.lang, 2) THEN
392
        ELSIF Lang.isKey(s, text.lang, 2) THEN
393
            color := colors.key2
393
            color := colors.key2
394
        ELSIF Lang.isKey(s, text.lang, 3) THEN
394
        ELSIF Lang.isKey(s, text.lang, 3) THEN
395
            color := colors.key3
395
            color := colors.key3
396
        ELSE
396
        ELSE
397
            color := colors.text
397
            color := colors.text
398
        END;
398
        END;
399
        IF color # colors.text THEN
399
        IF color # colors.text THEN
400
            PrintLex(text, line, first, i, y, color, backColor)
400
            PrintLex(text, line, first, i, y, color, backColor)
401
        END
401
        END
402
    END ident;
402
    END ident;
403
 
403
 
404
 
404
 
405
    PROCEDURE String (text: tText; line: tLine; VAR i: INTEGER; y: INTEGER; backColor: INTEGER);
405
    PROCEDURE String (text: tText; line: tLine; VAR i: INTEGER; y: INTEGER; backColor: INTEGER);
406
    VAR
406
    VAR
407
        k, j, Start, End: INTEGER;
407
        k, j, Start, End: INTEGER;
408
        c: WCHAR;
408
        c: WCHAR;
409
    BEGIN
409
    BEGIN
410
        k := i;
410
        k := i;
411
        Lang.SkipString(line, i, line.length - 1, text.lang);
411
        Lang.SkipString(line, i, line.length - 1, text.lang);
412
        PrintLex(text, line, k, i, y, colors.string, backColor);
412
        PrintLex(text, line, k, i, y, colors.string, backColor);
413
        IF text.lang IN Lang.escLang THEN
413
        IF text.lang IN Lang.escLang THEN
414
	        Start := k + 1;
414
	        Start := k + 1;
415
	        End := i - 1;
415
	        End := i - 1;
416
	        k := Start;
416
	        k := Start;
417
	        WHILE k <= End DO
417
	        WHILE k <= End DO
418
	        	c := Lines.getChar(line, k);
418
	        	c := Lines.getChar(line, k);
419
	        	IF c = "\" THEN
419
	        	IF c = "\" THEN
420
	        		j := k;
420
	        		j := k;
421
	        		Lang.SkipEsc(line, k, line.length - 1, text.lang);
421
	        		Lang.SkipEsc(line, k, line.length - 1, text.lang);
422
	        		PrintLex(text, line, j, k, y, colors.escape, backColor)
422
	        		PrintLex(text, line, j, k, y, colors.escape, backColor)
423
	        	END;
423
	        	END;
424
	        	INC(k)
424
	        	INC(k)
425
	        END
425
	        END
426
        END
426
        END
427
    END String;
427
    END String;
428
 
428
 
429
 
429
 
430
BEGIN
430
BEGIN
431
    depth := line.cin;
431
    depth := line.cin;
432
    n := line.length - 1;
432
    n := line.length - 1;
433
    i := 0;
433
    i := 0;
434
    IF (depth > 0) & (n >= 0) THEN
434
    IF (depth > 0) & (n >= 0) THEN
435
        PrintComment(text, line, depth, i, 2, y, backColor)
435
        PrintComment(text, line, depth, i, 2, y, backColor)
436
    END;
436
    END;
437
    cond := 0;
437
    cond := 0;
438
    WHILE i <= n DO
438
    WHILE i <= n DO
439
        c := Lines.getChar(line, i);
439
        c := Lines.getChar(line, i);
440
 
440
 
441
        IF lang = Lang.langFasm THEN
441
        IF lang = Lang.langFasm THEN
442
 
442
 
443
            IF c = ";" THEN
443
            IF c = ";" THEN
444
                PrintLex(text, line, i, n, y, colors.comment, backColor);
444
                PrintLex(text, line, i, n, y, colors.comment, backColor);
445
                i := n
445
                i := n
446
            ELSIF (c = "'") OR (c = '"') THEN
446
            ELSIF (c = "'") OR (c = '"') THEN
447
                String(text, line, i, y, backColor)
447
                String(text, line, i, y, backColor)
448
            ELSIF (U.isLetter(c) OR (c = "_")) THEN
448
            ELSIF (U.isLetter(c) OR (c = "_")) THEN
449
                ident(text, i, i, y, line, backColor, Lang.isCS(lang))
449
                ident(text, i, i, y, line, backColor, Lang.isCS(lang))
450
            ELSIF U.isDigit(c) THEN
450
            ELSIF U.isDigit(c) THEN
451
                hex := FALSE;
451
                hex := FALSE;
452
                k := i;
452
                k := i;
453
                INC(i);
453
                INC(i);
454
                c := Lines.getChar(line, i);
454
                c := Lines.getChar(line, i);
455
                IF (cap(c) = "X") & (Lines.getChar(line, i - 1) = "0") THEN
455
                IF (cap(c) = "X") & (Lines.getChar(line, i - 1) = "0") THEN
456
                    INC(i);
456
                    INC(i);
457
                    hex := TRUE
457
                    hex := TRUE
458
                END;
458
                END;
459
 
459
 
460
                WHILE U.isHex(cap(Lines.getChar(line, i))) DO
460
                WHILE U.isHex(cap(Lines.getChar(line, i))) DO
461
                    INC(i)
461
                    INC(i)
462
                END;
462
                END;
463
 
463
 
464
                IF (cap(Lines.getChar(line, i)) = "H") & ~hex THEN
464
                IF (cap(Lines.getChar(line, i)) = "H") & ~hex THEN
465
                    INC(i)
465
                    INC(i)
466
                END;
466
                END;
467
 
467
 
468
                DEC(i);
468
                DEC(i);
469
                PrintLex(text, line, k, i, y, colors.num, backColor)
469
                PrintLex(text, line, k, i, y, colors.num, backColor)
470
            END
470
            END
471
 
471
 
472
        ELSIF (lang = Lang.langC) OR (lang = Lang.langJSON) THEN
472
        ELSIF (lang = Lang.langC) OR (lang = Lang.langJSON) THEN
473
 
473
 
474
	        IF depth = 0 THEN
474
	        IF depth = 0 THEN
475
	            IF c = "/" THEN
475
	            IF c = "/" THEN
476
	                IF cond = 0 THEN
476
	                IF cond = 0 THEN
477
	                    cond := 1
477
	                    cond := 1
478
	                ELSE
478
	                ELSE
479
	                    PrintLex(text, line, i - 1, n, y, colors.comment, backColor);
479
	                    PrintLex(text, line, i - 1, n, y, colors.comment, backColor);
480
	                    cond := 0;
480
	                    cond := 0;
481
	                    i := n
481
	                    i := n
482
	                END
482
	                END
483
	            ELSIF (c = "*") & (cond = 1) THEN
483
	            ELSIF (c = "*") & (cond = 1) THEN
484
	                depth := 1;
484
	                depth := 1;
485
	                INC(i);
485
	                INC(i);
486
	                PrintComment(text, line, depth, i, 2, y, backColor);
486
	                PrintComment(text, line, depth, i, 2, y, backColor);
487
	                cond := 0
487
	                cond := 0
488
	            ELSIF U.isLetter(c) OR (c = "_") OR (c = "'") OR (c = '"') THEN
488
	            ELSIF U.isLetter(c) OR (c = "_") OR (c = "'") OR (c = '"') THEN
489
	            	k := i;
489
	            	k := i;
490
	            	IF (c = "'") OR (c = '"') THEN
490
	            	IF (c = "'") OR (c = '"') THEN
491
	            		String(text, line, i, y, backColor);
491
	            		String(text, line, i, y, backColor);
492
	            	ELSE
492
	            	ELSE
493
	            		ident(text, i, i - ORD((lang = Lang.langC) & (i > 0) & (Lines.getChar(line, i - 1) = "#")), y, line, backColor, Lang.isCS(lang))
493
	            		ident(text, i, i - ORD((lang = Lang.langC) & (i > 0) & (Lines.getChar(line, i - 1) = "#")), y, line, backColor, Lang.isCS(lang))
494
	            	END;
494
	            	END;
495
	                IF lang = Lang.langJSON THEN
495
	                IF lang = Lang.langJSON THEN
496
		                WHILE Lines.isSpace(Lines.getChar(line, i + 1)) DO
496
		                WHILE Lines.isSpace(Lines.getChar(line, i + 1)) DO
497
		                	INC(i)
497
		                	INC(i)
498
		                END;
498
		                END;
499
		                IF Lines.getChar(line, i + 1) = ":" THEN
499
		                IF Lines.getChar(line, i + 1) = ":" THEN
500
		                	PrintLex(text, line, k, i, y, colors.key1, backColor)
500
		                	PrintLex(text, line, k, i, y, colors.key1, backColor)
501
		                END
501
		                END
502
	                END;
502
	                END;
503
	                cond := 0
503
	                cond := 0
504
	            ELSIF U.isDigit(c) THEN
504
	            ELSIF U.isDigit(c) THEN
505
	                k := i;
505
	                k := i;
506
	                INC(i);
506
	                INC(i);
507
	                c := Lines.getChar(line, i);
507
	                c := Lines.getChar(line, i);
508
	                IF c = "." THEN
508
	                IF c = "." THEN
509
	                    DEC(i);
509
	                    DEC(i);
510
	                    c := Lines.getChar(line, i)
510
	                    c := Lines.getChar(line, i)
511
	                END;
511
	                END;
512
	                IF (cap(c) = "X") & (Lines.getChar(line, i - 1) = "0") THEN
512
	                IF (cap(c) = "X") & (Lines.getChar(line, i - 1) = "0") THEN
513
	                    REPEAT
513
	                    REPEAT
514
	                        INC(i);
514
	                        INC(i);
515
	                        c := Lines.getChar(line, i)
515
	                        c := Lines.getChar(line, i)
516
	                    UNTIL ~U.isHex(cap(c));
516
	                    UNTIL ~U.isHex(cap(c));
517
	                    IF UL(c) THEN
517
	                    IF UL(c) THEN
518
	                        INC(i)
518
	                        INC(i)
519
	                    END
519
	                    END
520
	                ELSIF UL(c) THEN
520
	                ELSIF UL(c) THEN
521
	                    INC(i)
521
	                    INC(i)
522
	                ELSIF U.isDigit(c) THEN
522
	                ELSIF U.isDigit(c) THEN
523
	                    REPEAT
523
	                    REPEAT
524
	                        INC(i)
524
	                        INC(i)
525
	                    UNTIL ~U.isDigit(Lines.getChar(line, i));
525
	                    UNTIL ~U.isDigit(Lines.getChar(line, i));
526
	                    c := Lines.getChar(line, i);
526
	                    c := Lines.getChar(line, i);
527
	                    IF UL(c) THEN
527
	                    IF UL(c) THEN
528
	                        INC(i)
528
	                        INC(i)
529
	                    ELSIF c = "." THEN
529
	                    ELSIF c = "." THEN
530
	                        INC(i);
530
	                        INC(i);
531
	                        WHILE U.isDigit(Lines.getChar(line, i)) DO
531
	                        WHILE U.isDigit(Lines.getChar(line, i)) DO
532
	                            INC(i)
532
	                            INC(i)
533
	                        END;
533
	                        END;
534
	                        c := Lines.getChar(line, i);
534
	                        c := Lines.getChar(line, i);
535
	                        IF cap(c) = "E" THEN
535
	                        IF cap(c) = "E" THEN
536
	                            INC(i);
536
	                            INC(i);
537
	                            c := Lines.getChar(line, i);
537
	                            c := Lines.getChar(line, i);
538
	                            IF (c = "+") OR (c = "-") THEN
538
	                            IF (c = "+") OR (c = "-") THEN
539
	                                INC(i)
539
	                                INC(i)
540
	                            END;
540
	                            END;
541
	                            IF U.isDigit(Lines.getChar(line, i)) THEN
541
	                            IF U.isDigit(Lines.getChar(line, i)) THEN
542
	                                WHILE U.isDigit(Lines.getChar(line, i)) DO
542
	                                WHILE U.isDigit(Lines.getChar(line, i)) DO
543
	                                    INC(i)
543
	                                    INC(i)
544
	                                END;
544
	                                END;
545
	                                c := Lines.getChar(line, i);
545
	                                c := Lines.getChar(line, i);
546
	                                IF FL(c) THEN
546
	                                IF FL(c) THEN
547
	                                    INC(i)
547
	                                    INC(i)
548
	                                END
548
	                                END
549
	                            END
549
	                            END
550
	                        ELSIF FL(c) THEN
550
	                        ELSIF FL(c) THEN
551
	                            INC(i)
551
	                            INC(i)
552
	                        END
552
	                        END
553
	                    END
553
	                    END
554
	                END;
554
	                END;
555
	                DEC(i);
555
	                DEC(i);
556
	                PrintLex(text, line, k, i, y, colors.num, backColor);
556
	                PrintLex(text, line, k, i, y, colors.num, backColor);
557
	                cond := 0
557
	                cond := 0
558
	            ELSE
558
	            ELSE
559
	                cond := 0
559
	                cond := 0
560
	            END
560
	            END
561
	        ELSIF depth = 1 THEN
561
	        ELSIF depth = 1 THEN
562
	            IF c = "*" THEN
562
	            IF c = "*" THEN
563
	                cond := 1
563
	                cond := 1
564
	            ELSIF (c = "/") & (cond = 1) THEN
564
	            ELSIF (c = "/") & (cond = 1) THEN
565
	                cond := 0;
565
	                cond := 0;
566
	                depth := 0
566
	                depth := 0
567
	            ELSE
567
	            ELSE
568
	                cond := 0
568
	                cond := 0
569
	            END
569
	            END
570
	        END
570
	        END
571
 
571
 
572
        ELSIF lang = Lang.langOberon THEN
572
        ELSIF lang = Lang.langOberon THEN
573
 
573
 
574
	        IF (depth = 0) & (c = "/") THEN
574
	        IF (depth = 0) & (c = "/") THEN
575
	            IF cond = 3 THEN
575
	            IF cond = 3 THEN
576
	                PrintLex(text, line, i - 1, n, y, colors.comment, backColor);
576
	                PrintLex(text, line, i - 1, n, y, colors.comment, backColor);
577
	                cond := 0;
577
	                cond := 0;
578
	                i := n
578
	                i := n
579
	            ELSE
579
	            ELSE
580
	                cond := 3
580
	                cond := 3
581
	            END
581
	            END
582
	        ELSIF (depth = 0) & ((c = "'") OR (c = '"')) THEN
582
	        ELSIF (depth = 0) & ((c = "'") OR (c = '"')) THEN
583
	            String(text, line, i, y, backColor);
583
	            String(text, line, i, y, backColor);
584
	            cond := 0
584
	            cond := 0
585
	        ELSIF (depth = 0) & U.isDigit(c) THEN
585
	        ELSIF (depth = 0) & U.isDigit(c) THEN
586
	            color := colors.num;
586
	            color := colors.num;
587
	            k := i;
587
	            k := i;
588
	            INC(i);
588
	            INC(i);
589
	            WHILE U.isHex(Lines.getChar(line, i)) DO
589
	            WHILE U.isHex(Lines.getChar(line, i)) DO
590
	                INC(i)
590
	                INC(i)
591
	            END;
591
	            END;
592
	            IF i <= n THEN
592
	            IF i <= n THEN
593
	                IF Lines.getChar(line, i) = "." THEN
593
	                IF Lines.getChar(line, i) = "." THEN
594
	                    INC(i);
594
	                    INC(i);
595
	                    IF Lines.getChar(line, i) = "." THEN
595
	                    IF Lines.getChar(line, i) = "." THEN
596
	                        DEC(i)
596
	                        DEC(i)
597
	                    END;
597
	                    END;
598
	                    WHILE U.isDigit(Lines.getChar(line, i)) DO
598
	                    WHILE U.isDigit(Lines.getChar(line, i)) DO
599
	                        INC(i)
599
	                        INC(i)
600
	                    END;
600
	                    END;
601
	                    IF Lines.getChar(line, i) = "E" THEN
601
	                    IF Lines.getChar(line, i) = "E" THEN
602
	                        INC(i);
602
	                        INC(i);
603
	                        IF (Lines.getChar(line, i) = "+") OR (Lines.getChar(line, i) = "-") THEN
603
	                        IF (Lines.getChar(line, i) = "+") OR (Lines.getChar(line, i) = "-") THEN
604
	                            INC(i)
604
	                            INC(i)
605
	                        END;
605
	                        END;
606
	                        WHILE U.isDigit(Lines.getChar(line, i)) DO
606
	                        WHILE U.isDigit(Lines.getChar(line, i)) DO
607
	                            INC(i)
607
	                            INC(i)
608
	                        END
608
	                        END
609
	                    END
609
	                    END
610
	                ELSIF Lines.getChar(line, i) = "H" THEN
610
	                ELSIF Lines.getChar(line, i) = "H" THEN
611
	                    INC(i)
611
	                    INC(i)
612
	                ELSIF Lines.getChar(line, i) = "X" THEN
612
	                ELSIF Lines.getChar(line, i) = "X" THEN
613
	                    color := colors.string;
613
	                    color := colors.string;
614
	                    INC(i)
614
	                    INC(i)
615
	                END
615
	                END
616
	            END;
616
	            END;
617
	            DEC(i);
617
	            DEC(i);
618
	            PrintLex(text, line, k, i, y, color, backColor);
618
	            PrintLex(text, line, k, i, y, color, backColor);
619
	            cond := 0
619
	            cond := 0
620
	        ELSIF (depth = 0) & (U.isLetter(c) OR (c = "_")) THEN
620
	        ELSIF (depth = 0) & (U.isLetter(c) OR (c = "_")) THEN
621
	            ident(text, i, i, y, line, backColor, Lang.isCS(lang));
621
	            ident(text, i, i, y, line, backColor, Lang.isCS(lang));
622
	            cond := 0
622
	            cond := 0
623
	        ELSIF c = "(" THEN
623
	        ELSIF c = "(" THEN
624
	            cond := 1
624
	            cond := 1
625
	        ELSIF c = "*" THEN
625
	        ELSIF c = "*" THEN
626
	            IF cond = 1 THEN
626
	            IF cond = 1 THEN
627
	                INC(depth);
627
	                INC(depth);
628
	                INC(i);
628
	                INC(i);
629
	                PrintComment(text, line, depth, i, 2, y, backColor);
629
	                PrintComment(text, line, depth, i, 2, y, backColor);
630
	                cond := 0
630
	                cond := 0
631
	            ELSE
631
	            ELSE
632
	                cond := 2
632
	                cond := 2
633
	            END
633
	            END
634
	        ELSIF c = ")" THEN
634
	        ELSIF c = ")" THEN
635
	            IF cond = 2 THEN
635
	            IF cond = 2 THEN
636
	                IF depth > 0 THEN
636
	                IF depth > 0 THEN
637
	                    DEC(depth)
637
	                    DEC(depth)
638
	                END
638
	                END
639
	            END;
639
	            END;
640
	            cond := 0
640
	            cond := 0
641
	        ELSE
641
	        ELSE
642
	            cond := 0
642
	            cond := 0
643
	        END
643
	        END
644
 
644
 
645
        ELSIF lang = Lang.langLua THEN
645
        ELSIF lang = Lang.langLua THEN
646
 
646
 
647
	        IF depth = 0 THEN
647
	        IF depth = 0 THEN
648
	            IF c = "-" THEN
648
	            IF c = "-" THEN
649
	                IF cond = 1 THEN
649
	                IF cond = 1 THEN
650
	                    IF Lang.LuaLong(line, i + 1) >= 0 THEN
650
	                    IF Lang.LuaLong(line, i + 1) >= 0 THEN
651
	                        depth := Lang.LuaLong(line, i + 1)*2 + 1;
651
	                        depth := Lang.LuaLong(line, i + 1)*2 + 1;
652
	                        INC(i);
652
	                        INC(i);
653
	                        PrintComment(text, line, depth, i, 2, y, backColor)
653
	                        PrintComment(text, line, depth, i, 2, y, backColor)
654
	                    ELSE
654
	                    ELSE
655
	                        PrintLex(text, line, i - 1, n, y, colors.comment, backColor);
655
	                        PrintLex(text, line, i - 1, n, y, colors.comment, backColor);
656
	                        i := n
656
	                        i := n
657
	                    END;
657
	                    END;
658
	                    cond := 0
658
	                    cond := 0
659
	                ELSE
659
	                ELSE
660
	                    cond := 1
660
	                    cond := 1
661
	                END
661
	                END
662
	            ELSIF c = "[" THEN
662
	            ELSIF c = "[" THEN
663
	                cond := 0;
663
	                cond := 0;
664
	                k := Lang.LuaLong(line, i);
664
	                k := Lang.LuaLong(line, i);
665
	                IF k >= 0 THEN
665
	                IF k >= 0 THEN
666
	                    depth := (k + 1)*2;
666
	                    depth := (k + 1)*2;
667
	                    INC(i, 2);
667
	                    INC(i, 2);
668
	                    PrintComment(text, line, depth, i, 2, y, backColor);
668
	                    PrintComment(text, line, depth, i, 2, y, backColor);
669
	                    cond := 0
669
	                    cond := 0
670
	                END
670
	                END
671
	            ELSIF (c = "'") OR (c = '"') THEN
671
	            ELSIF (c = "'") OR (c = '"') THEN
672
	                String(text, line, i, y, backColor);
672
	                String(text, line, i, y, backColor);
673
	                cond := 0
673
	                cond := 0
674
	            ELSIF U.isDigit(c) THEN
674
	            ELSIF U.isDigit(c) THEN
675
	                k := i;
675
	                k := i;
676
	                IF (c = "0") & (cap(Lines.getChar(line, i + 1)) = "X") THEN
676
	                IF (c = "0") & (cap(Lines.getChar(line, i + 1)) = "X") THEN
677
	                    isDgt := U.isHex;
677
	                    isDgt := U.isHex;
678
	                    hex := TRUE;
678
	                    hex := TRUE;
679
	                    INC(i, 2)
679
	                    INC(i, 2)
680
	                ELSE
680
	                ELSE
681
	                    isDgt := U.isDigit;
681
	                    isDgt := U.isDigit;
682
	                    hex := FALSE
682
	                    hex := FALSE
683
	                END;
683
	                END;
684
	                WHILE isDgt(cap(Lines.getChar(line, i))) DO
684
	                WHILE isDgt(cap(Lines.getChar(line, i))) DO
685
	                    INC(i)
685
	                    INC(i)
686
	                END;
686
	                END;
687
	                IF Lines.getChar(line, i) = "." THEN
687
	                IF Lines.getChar(line, i) = "." THEN
688
	                    INC(i);
688
	                    INC(i);
689
	                    IF Lines.getChar(line, i) = "." THEN
689
	                    IF Lines.getChar(line, i) = "." THEN
690
	                        DEC(i)
690
	                        DEC(i)
691
	                    END;
691
	                    END;
692
	                    WHILE isDgt(cap(Lines.getChar(line, i))) DO
692
	                    WHILE isDgt(cap(Lines.getChar(line, i))) DO
693
	                        INC(i)
693
	                        INC(i)
694
	                    END
694
	                    END
695
	                END;
695
	                END;
696
	                IF (cap(Lines.getChar(line, i)) = "E") OR hex & (cap(Lines.getChar(line, i)) = "P") THEN
696
	                IF (cap(Lines.getChar(line, i)) = "E") OR hex & (cap(Lines.getChar(line, i)) = "P") THEN
697
	                    INC(i);
697
	                    INC(i);
698
	                    IF (Lines.getChar(line, i) = "-") OR (Lines.getChar(line, i) = "+") THEN
698
	                    IF (Lines.getChar(line, i) = "-") OR (Lines.getChar(line, i) = "+") THEN
699
	                        INC(i)
699
	                        INC(i)
700
	                    END;
700
	                    END;
701
	                    WHILE isDgt(cap(Lines.getChar(line, i))) DO
701
	                    WHILE isDgt(cap(Lines.getChar(line, i))) DO
702
	                        INC(i)
702
	                        INC(i)
703
	                    END
703
	                    END
704
	                END;
704
	                END;
705
	                DEC(i);
705
	                DEC(i);
706
	                PrintLex(text, line, k, i, y, colors.num, backColor);
706
	                PrintLex(text, line, k, i, y, colors.num, backColor);
707
	                cond := 0
707
	                cond := 0
708
	            ELSIF U.isLetter(c) OR (c = "_") THEN
708
	            ELSIF U.isLetter(c) OR (c = "_") THEN
709
	                ident(text, i, i, y, line, backColor, Lang.isCS(lang));
709
	                ident(text, i, i, y, line, backColor, Lang.isCS(lang));
710
	                cond := 0
710
	                cond := 0
711
	            ELSE
711
	            ELSE
712
	                cond := 0
712
	                cond := 0
713
	            END
713
	            END
714
 
714
 
715
	        ELSIF depth > 0 THEN
715
	        ELSIF depth > 0 THEN
716
	            IF (cond = 0) & (c = "]") THEN
716
	            IF (cond = 0) & (c = "]") THEN
717
	                cond := 1
717
	                cond := 1
718
	            ELSIF (cond >= 1) & (c = "=") THEN
718
	            ELSIF (cond >= 1) & (c = "=") THEN
719
	                INC(cond)
719
	                INC(cond)
720
	            ELSIF (cond >= 1) & (c = "]") & (cond * 2 - depth MOD 2 = depth) THEN
720
	            ELSIF (cond >= 1) & (c = "]") & (cond * 2 - depth MOD 2 = depth) THEN
721
	                depth := 0;
721
	                depth := 0;
722
	                cond := 0
722
	                cond := 0
723
	            ELSE
723
	            ELSE
724
	                cond := 0
724
	                cond := 0
725
	            END
725
	            END
726
	        END
726
	        END
727
 
727
 
728
        ELSIF lang = Lang.langPascal THEN
728
        ELSIF lang = Lang.langPascal THEN
729
 
729
 
730
	        IF depth = 0 THEN
730
	        IF depth = 0 THEN
731
	            IF c = "(" THEN
731
	            IF c = "(" THEN
732
	                cond := 1
732
	                cond := 1
733
	            ELSIF (c = "*") & (cond = 1) THEN
733
	            ELSIF (c = "*") & (cond = 1) THEN
734
	                depth := 2;
734
	                depth := 2;
735
	                INC(i);
735
	                INC(i);
736
	                PrintComment(text, line, depth, i, 2, y, backColor);
736
	                PrintComment(text, line, depth, i, 2, y, backColor);
737
	                cond := 0
737
	                cond := 0
738
	            ELSIF c = "/" THEN
738
	            ELSIF c = "/" THEN
739
	                IF cond = 2 THEN
739
	                IF cond = 2 THEN
740
	                    PrintLex(text, line, i - 1, n, y, colors.comment, backColor);
740
	                    PrintLex(text, line, i - 1, n, y, colors.comment, backColor);
741
	                    cond := 0;
741
	                    cond := 0;
742
	                    i := n
742
	                    i := n
743
	                ELSE
743
	                ELSE
744
	                    cond := 2
744
	                    cond := 2
745
	                END
745
	                END
746
	            ELSIF c = "'" THEN
746
	            ELSIF c = "'" THEN
747
	                String(text, line, i, y, backColor);
747
	                String(text, line, i, y, backColor);
748
	                cond := 0
748
	                cond := 0
749
	            ELSIF c = "{" THEN
749
	            ELSIF c = "{" THEN
750
	                IF Lines.getChar(line, i + 1) = "$" THEN
750
	                IF Lines.getChar(line, i + 1) = "$" THEN
751
	                    depth := 3
751
	                    depth := 3
752
	                ELSE
752
	                ELSE
753
	                    depth := 1
753
	                    depth := 1
754
	                END;
754
	                END;
755
	                INC(i);
755
	                INC(i);
756
	                PrintComment(text, line, depth, i, 1, y, backColor);
756
	                PrintComment(text, line, depth, i, 1, y, backColor);
757
	                cond := 0
757
	                cond := 0
758
	            ELSIF c = "#" THEN
758
	            ELSIF c = "#" THEN
759
	                k := i;
759
	                k := i;
760
	                INC(i);
760
	                INC(i);
761
	                WHILE U.isDigit(Lines.getChar(line, i)) DO
761
	                WHILE U.isDigit(Lines.getChar(line, i)) DO
762
	                    INC(i)
762
	                    INC(i)
763
	                END;
763
	                END;
764
	                DEC(i);
764
	                DEC(i);
765
	                PrintLex(text, line, k, i, y, colors.string, backColor);
765
	                PrintLex(text, line, k, i, y, colors.string, backColor);
766
	                cond := 0
766
	                cond := 0
767
	            ELSIF c = "$" THEN
767
	            ELSIF c = "$" THEN
768
	                IF (i > 0 ) & (Lines.getChar(line, i - 1) = "#") THEN
768
	                IF (i > 0 ) & (Lines.getChar(line, i - 1) = "#") THEN
769
	                    color := colors.string
769
	                    color := colors.string
770
	                ELSE
770
	                ELSE
771
	                    color := colors.num
771
	                    color := colors.num
772
	                END;
772
	                END;
773
	                k := i;
773
	                k := i;
774
	                INC(i);
774
	                INC(i);
775
	                WHILE U.isHex(cap(Lines.getChar(line, i))) DO
775
	                WHILE U.isHex(cap(Lines.getChar(line, i))) DO
776
	                    INC(i)
776
	                    INC(i)
777
	                END;
777
	                END;
778
	                DEC(i);
778
	                DEC(i);
779
	                PrintLex(text, line, k, i, y, color, backColor);
779
	                PrintLex(text, line, k, i, y, color, backColor);
780
	                cond := 0
780
	                cond := 0
781
	            ELSIF U.isDigit(c) THEN
781
	            ELSIF U.isDigit(c) THEN
782
	                k := i;
782
	                k := i;
783
	                WHILE U.isDigit(Lines.getChar(line, i)) DO
783
	                WHILE U.isDigit(Lines.getChar(line, i)) DO
784
	                    INC(i)
784
	                    INC(i)
785
	                END;
785
	                END;
786
	                IF Lines.getChar(line, i) = "." THEN
786
	                IF Lines.getChar(line, i) = "." THEN
787
	                    INC(i);
787
	                    INC(i);
788
	                    IF Lines.getChar(line, i) = "." THEN
788
	                    IF Lines.getChar(line, i) = "." THEN
789
	                        DEC(i)
789
	                        DEC(i)
790
	                    END;
790
	                    END;
791
	                    WHILE U.isDigit(Lines.getChar(line, i)) DO
791
	                    WHILE U.isDigit(Lines.getChar(line, i)) DO
792
	                        INC(i)
792
	                        INC(i)
793
	                    END;
793
	                    END;
794
	                    IF cap(Lines.getChar(line, i)) = "E" THEN
794
	                    IF cap(Lines.getChar(line, i)) = "E" THEN
795
	                        INC(i);
795
	                        INC(i);
796
	                        IF (Lines.getChar(line, i) = "-") OR (Lines.getChar(line, i) = "+") THEN
796
	                        IF (Lines.getChar(line, i) = "-") OR (Lines.getChar(line, i) = "+") THEN
797
	                            INC(i)
797
	                            INC(i)
798
	                        END;
798
	                        END;
799
	                        WHILE U.isDigit(Lines.getChar(line, i)) DO
799
	                        WHILE U.isDigit(Lines.getChar(line, i)) DO
800
	                            INC(i)
800
	                            INC(i)
801
	                        END
801
	                        END
802
	                    END
802
	                    END
803
	                END;
803
	                END;
804
	                DEC(i);
804
	                DEC(i);
805
	                PrintLex(text, line, k, i, y, colors.num, backColor);
805
	                PrintLex(text, line, k, i, y, colors.num, backColor);
806
	                cond := 0
806
	                cond := 0
807
	            ELSIF (U.isLetter(c) OR (c = "_")) THEN
807
	            ELSIF (U.isLetter(c) OR (c = "_")) THEN
808
	                ident(text, i, i, y, line, backColor, Lang.isCS(lang));
808
	                ident(text, i, i, y, line, backColor, Lang.isCS(lang));
809
	                cond := 0
809
	                cond := 0
810
	            ELSE
810
	            ELSE
811
	                cond := 0
811
	                cond := 0
812
	            END
812
	            END
813
	        ELSIF depth IN {1, 3} THEN
813
	        ELSIF depth IN {1, 3} THEN
814
	            IF c = "}" THEN
814
	            IF c = "}" THEN
815
	                depth := 0
815
	                depth := 0
816
	            END
816
	            END
817
	        ELSIF depth = 2 THEN
817
	        ELSIF depth = 2 THEN
818
	            IF c = "*" THEN
818
	            IF c = "*" THEN
819
	                cond := 1
819
	                cond := 1
820
	            ELSIF (c = ")") & (cond = 1) THEN
820
	            ELSIF (c = ")") & (cond = 1) THEN
821
	                depth := 0;
821
	                depth := 0;
822
	                cond := 0
822
	                cond := 0
823
	            ELSE
823
	            ELSE
824
	                cond := 0
824
	                cond := 0
825
	            END
825
	            END
826
	        END
826
	        END
827
 
827
 
828
        ELSIF lang = Lang.langIni THEN
828
        ELSIF lang = Lang.langIni THEN
829
 
829
 
830
	        IF depth = 0 THEN
830
	        IF depth = 0 THEN
831
	            IF ((c = ";") OR (c = "#")) & (leadingSpaces(line) = i) THEN
831
	            IF ((c = ";") OR (c = "#")) & (leadingSpaces(line) = i) THEN
832
	                PrintLex(text, line, i, n, y, colors.comment, backColor);
832
	                PrintLex(text, line, i, n, y, colors.comment, backColor);
833
	                i := n
833
	                i := n
834
	            ELSIF c = '"' THEN
834
	            ELSIF c = '"' THEN
835
	                String(text, line, i, y, backColor)
835
	                String(text, line, i, y, backColor)
836
	            ELSIF c = "[" THEN
836
	            ELSIF c = "[" THEN
837
	                depth := 1;
837
	                depth := 1;
838
	                INC(i);
838
	                INC(i);
839
	                PrintComment(text, line, depth, i, 1, y, backColor)
839
	                PrintComment(text, line, depth, i, 1, y, backColor)
840
	            ELSIF U.isDigit(c) THEN
840
	            ELSIF U.isDigit(c) THEN
841
	                k := i;
841
	                k := i;
842
	                WHILE U.isDigit(Lines.getChar(line, i)) DO
842
	                WHILE U.isDigit(Lines.getChar(line, i)) DO
843
	                    INC(i)
843
	                    INC(i)
844
	                END;
844
	                END;
845
	                DEC(i);
845
	                DEC(i);
846
	                PrintLex(text, line, k, i, y, colors.num, backColor)
846
	                PrintLex(text, line, k, i, y, colors.num, backColor)
847
	            ELSIF (U.isLetter(c) OR (c = "_")) THEN
847
	            ELSIF (U.isLetter(c) OR (c = "_")) THEN
848
	                ident(text, i, i, y, line, backColor, Lang.isCS(lang))
848
	                ident(text, i, i, y, line, backColor, Lang.isCS(lang))
849
	            END
849
	            END
850
	        ELSIF depth = 1 THEN
850
	        ELSIF depth = 1 THEN
851
	            IF c = "]" THEN
851
	            IF c = "]" THEN
852
	                depth := 0
852
	                depth := 0
853
	            END
853
	            END
854
	        END
854
	        END
855
 
855
 
856
        END;
856
        END;
857
        INC(i)
857
        INC(i)
858
    END
858
    END
859
END parse;
859
END parse;
860
 
860
 
861
 
861
 
862
PROCEDURE plain (text: tText): CB.tBuffer;
862
PROCEDURE plain (text: tText): CB.tBuffer;
863
VAR
863
VAR
864
    buf: CB.tBuffer;
864
    buf: CB.tBuffer;
865
    size: INTEGER;
865
    size: INTEGER;
866
    line: tLine;
866
    line: tLine;
867
BEGIN
867
BEGIN
868
    size := 0;
868
    size := 0;
869
    line := text.first(tLine);
869
    line := text.first(tLine);
870
    WHILE line # NIL DO
870
    WHILE line # NIL DO
871
        line.pos := size;
871
        line.pos := size;
872
        INC(size, line.length);
872
        INC(size, line.length);
873
        NextLine(line);
873
        NextLine(line);
874
        IF line # NIL THEN
874
        IF line # NIL THEN
875
            INC(size, CB.lenEOL)
875
            INC(size, CB.lenEOL)
876
        END
876
        END
877
    END;
877
    END;
878
    buf := CB.create(size + 2);
878
    buf := CB.create(size + 2);
879
    line := text.first(tLine);
879
    line := text.first(tLine);
880
    WHILE line # NIL DO
880
    WHILE line # NIL DO
881
        CB.append(buf, line, 0, line.length - 1);
881
        CB.append(buf, line, 0, line.length - 1);
882
        NextLine(line);
882
        NextLine(line);
883
        IF line # NIL THEN
883
        IF line # NIL THEN
884
            CB.eol(buf)
884
            CB.eol(buf)
885
        END
885
        END
886
    END;
886
    END;
887
    CB.appends(buf, 0X, 0, 0);
887
    CB.appends(buf, 0X, 0, 0);
888
    CB.appends(buf, 0X, 0, 0)
888
    CB.appends(buf, 0X, 0, 0)
889
    RETURN buf
889
    RETURN buf
890
END plain;
890
END plain;
891
 
891
 
892
 
892
 
893
PROCEDURE search* (text: tText; s: ARRAY OF WCHAR; cs, whole: BOOLEAN): BOOLEAN;
893
PROCEDURE search* (text: tText; s: ARRAY OF WCHAR; cs, whole: BOOLEAN): BOOLEAN;
894
VAR
894
VAR
895
	pos: List.tItem;
895
	pos: List.tItem;
896
	res: BOOLEAN;
896
	res: BOOLEAN;
897
	plainText, idxData: Search.tBuffer;
897
	plainText, idxData: Search.tBuffer;
898
BEGIN
898
BEGIN
899
	res := TRUE;
899
	res := TRUE;
900
	plainText := NIL;
900
	plainText := NIL;
901
	idxData := NIL;
901
	idxData := NIL;
902
	WHILE text.foundList.count # 0 DO
902
	WHILE text.foundList.count # 0 DO
903
		pos := List.pop(text.foundList);
903
		pos := List.pop(text.foundList);
904
		DISPOSE(pos)
904
		DISPOSE(pos)
905
	END;
905
	END;
906
	text.whole := whole;
906
	text.whole := whole;
907
	text.cs := cs;
907
	text.cs := cs;
908
	text.searchText := s;
908
	text.searchText := s;
909
	IF ~cs THEN
909
	IF ~cs THEN
910
		U.upcase16(text.searchText)
910
		U.upcase16(text.searchText)
911
	END;
911
	END;
912
	IF text.searchText # "" THEN
912
	IF text.searchText # "" THEN
913
		plainText := plain(text);
913
		plainText := plain(text);
914
		idxData := Search.index(plainText, idxTable, cs);
914
		idxData := Search.index(plainText, idxTable, cs);
915
		Search.find(plainText, idxTable, text.searchText, whole, text.foundList);
915
		Search.find(plainText, idxTable, text.searchText, whole, text.foundList);
916
		res := text.foundList.count > 0
916
		res := text.foundList.count > 0
917
	END;
917
	END;
918
	CB.destroy(plainText);
918
	CB.destroy(plainText);
919
	CB.destroy(idxData);
919
	CB.destroy(idxData);
920
	text.search := FALSE;
920
	text.search := FALSE;
921
	text.foundSel := 0
921
	text.foundSel := 0
922
	RETURN res
922
	RETURN res
923
END search;
923
END search;
924
 
924
 
925
 
925
 
926
PROCEDURE modify (text: tText);
926
PROCEDURE modify (text: tText);
927
BEGIN
927
BEGIN
928
    text.modified := TRUE;
928
    text.modified := TRUE;
929
    text.comments := TRUE;
929
    text.comments := TRUE;
930
    text.search := TRUE;
930
    text.search := TRUE;
931
    text.guard := TRUE
931
    text.guard := TRUE
932
END modify;
932
END modify;
933
 
933
 
934
 
934
 
935
PROCEDURE setEnc* (text: tText; enc: INTEGER);
935
PROCEDURE setEnc* (text: tText; enc: INTEGER);
936
BEGIN
936
BEGIN
937
	IF text.enc # enc THEN
937
	IF text.enc # enc THEN
938
		ChangeLog.changeInt(text.enc, enc);
938
		ChangeLog.changeInt(text.enc, enc);
939
		text.enc := enc;
939
		text.enc := enc;
940
		modify(text)
940
		modify(text)
941
	END
941
	END
942
END setEnc;
942
END setEnc;
943
 
943
 
944
 
944
 
945
PROCEDURE setEol* (text: tText; eol: INTEGER);
945
PROCEDURE setEol* (text: tText; eol: INTEGER);
946
BEGIN
946
BEGIN
947
	IF text.eol # eol THEN
947
	IF text.eol # eol THEN
948
		ChangeLog.changeInt(text.eol, eol);
948
		ChangeLog.changeInt(text.eol, eol);
949
		text.eol := eol;
949
		text.eol := eol;
950
		modify(text)
950
		modify(text)
951
	END
951
	END
952
END setEol;
952
END setEol;
953
 
953
 
954
 
954
 
955
PROCEDURE getEnc* (text: tText): INTEGER;
955
PROCEDURE getEnc* (text: tText): INTEGER;
956
	RETURN text.enc
956
	RETURN text.enc
957
END getEnc;
957
END getEnc;
958
 
958
 
959
 
959
 
960
PROCEDURE getEol* (text: tText): INTEGER;
960
PROCEDURE getEol* (text: tText): INTEGER;
961
	RETURN text.eol
961
	RETURN text.eol
962
END getEol;
962
END getEol;
963
 
963
 
964
 
964
 
965
PROCEDURE DelLine (text: tText; line: tLine);
965
PROCEDURE DelLine (text: tText; line: tLine);
966
BEGIN
966
BEGIN
967
    List._delete(text, line);
967
    List._delete(text, line);
968
    Lines.destroy(line);
968
    Lines.destroy(line);
969
    modify(text)
969
    modify(text)
970
END DelLine;
970
END DelLine;
971
 
971
 
972
 
972
 
973
PROCEDURE setSelect (text: tText);
973
PROCEDURE setSelect (text: tText);
974
BEGIN
974
BEGIN
975
    IF text.select = text.cursor THEN
975
    IF text.select = text.cursor THEN
976
        text.select2^ := text.cursor^;
976
        text.select2^ := text.cursor^;
977
        text.select := text.select2
977
        text.select := text.select2
978
    END
978
    END
979
END setSelect;
979
END setSelect;
980
 
980
 
981
 
981
 
982
PROCEDURE resetSelect* (text: tText);
982
PROCEDURE resetSelect* (text: tText);
983
BEGIN
983
BEGIN
984
    text.select := text.cursor
984
    text.select := text.cursor
985
END resetSelect;
985
END resetSelect;
986
 
986
 
987
 
987
 
988
PROCEDURE getLine (text: tText; n: INTEGER): tLine;
988
PROCEDURE getLine (text: tText; n: INTEGER): tLine;
989
VAR
989
VAR
990
	item: List.tItem;
990
	item: List.tItem;
991
BEGIN
991
BEGIN
992
	item := List.getItem(text, n)
992
	item := List.getItem(text, n)
993
	RETURN item(tLine)
993
	RETURN item(tLine)
994
END getLine;
994
END getLine;
995
 
995
 
996
 
996
 
997
PROCEDURE SetPos* (text: tText; x, y: INTEGER);
997
PROCEDURE SetPos* (text: tText; x, y: INTEGER);
998
VAR
998
VAR
999
    deltaY, n, L, R: INTEGER;
999
    deltaY, n, L, R: INTEGER;
1000
    cursor: pPoint;
1000
    cursor: pPoint;
1001
    c: WCHAR;
1001
    c: WCHAR;
1002
   (* trimLength: INTEGER; *)
1002
   (* trimLength: INTEGER; *)
1003
BEGIN
1003
BEGIN
1004
    cursor := text.cursor;
1004
    cursor := text.cursor;
1005
    y := MIN(MAX(y, 0), text.count - 1);
1005
    y := MIN(MAX(y, 0), text.count - 1);
1006
    deltaY := y - cursor.Y;
1006
    deltaY := y - cursor.Y;
1007
    IF deltaY # 0 THEN
1007
    IF deltaY # 0 THEN
1008
        cursor.Y := y;
1008
        cursor.Y := y;
1009
(*        trimLength := Lines.trimLength(text.curLine);
1009
(*        trimLength := Lines.trimLength(text.curLine);
1010
        IF text.curLine.length # trimLength THEN
1010
        IF text.curLine.length # trimLength THEN
1011
            Lines.setChar(text.curLine, trimLength, 0X);
1011
            Lines.setChar(text.curLine, trimLength, 0X);
1012
            text.curLine.length := trimLength
1012
            text.curLine.length := trimLength
1013
        END;*)
1013
        END;*)
1014
        IF deltaY = 1 THEN
1014
        IF deltaY = 1 THEN
1015
            NextLine(text.curLine)
1015
            NextLine(text.curLine)
1016
        ELSIF deltaY = -1 THEN
1016
        ELSIF deltaY = -1 THEN
1017
            PrevLine(text.curLine)
1017
            PrevLine(text.curLine)
1018
        ELSE
1018
        ELSE
1019
            text.curLine := getLine(text, y)
1019
            text.curLine := getLine(text, y)
1020
        END
1020
        END
1021
    END;
1021
    END;
1022
    cursor.X := MIN(MAX(x, 0), text.curLine.length);
1022
    cursor.X := MIN(MAX(x, 0), text.curLine.length);
1023
    c := Lines.getChar(text.curLine, cursor.X);
1023
    c := Lines.getChar(text.curLine, cursor.X);
1024
    IF c = TAB1 THEN
1024
    IF c = TAB1 THEN
1025
        n := cursor.X;
1025
        n := cursor.X;
1026
        WHILE Lines.getChar(text.curLine, n) = TAB1 DO
1026
        WHILE Lines.getChar(text.curLine, n) = TAB1 DO
1027
            INC(n)
1027
            INC(n)
1028
        END;
1028
        END;
1029
        R := n - cursor.X;
1029
        R := n - cursor.X;
1030
        n := cursor.X;
1030
        n := cursor.X;
1031
        WHILE Lines.getChar(text.curLine, n) # TAB DO
1031
        WHILE Lines.getChar(text.curLine, n) # TAB DO
1032
            DEC(n)
1032
            DEC(n)
1033
        END;
1033
        END;
1034
        L := cursor.X - n;
1034
        L := cursor.X - n;
1035
        IF L < R THEN
1035
        IF L < R THEN
1036
            DEC(cursor.X, L)
1036
            DEC(cursor.X, L)
1037
        ELSE
1037
        ELSE
1038
            INC(cursor.X, R)
1038
            INC(cursor.X, R)
1039
        END
1039
        END
1040
    END;
1040
    END;
1041
    IF text.scroll.Y > cursor.Y THEN
1041
    IF text.scroll.Y > cursor.Y THEN
1042
        text.scroll.Y := cursor.Y
1042
        text.scroll.Y := cursor.Y
1043
    ELSIF text.scroll.Y + textsize.Y <= cursor.Y THEN
1043
    ELSIF text.scroll.Y + textsize.Y <= cursor.Y THEN
1044
        text.scroll.Y := cursor.Y - textsize.Y + 1
1044
        text.scroll.Y := cursor.Y - textsize.Y + 1
1045
    END;
1045
    END;
1046
    IF text.scroll.X > cursor.X THEN
1046
    IF text.scroll.X > cursor.X THEN
1047
        text.scroll.X := cursor.X
1047
        text.scroll.X := cursor.X
1048
    ELSIF text.scroll.X + textsize.X <= cursor.X THEN
1048
    ELSIF text.scroll.X + textsize.X <= cursor.X THEN
1049
        text.scroll.X := cursor.X - textsize.X + 1
1049
        text.scroll.X := cursor.X - textsize.X + 1
1050
    END;
1050
    END;
1051
    IF (text.select.Y = cursor.Y) & (text.select.X > text.curLine.length) THEN
1051
    IF (text.select.Y = cursor.Y) & (text.select.X > text.curLine.length) THEN
1052
        text.select.X := text.curLine.length
1052
        text.select.X := text.curLine.length
1053
    END;
1053
    END;
1054
    setSelect(text);
1054
    setSelect(text);
1055
    text.foundSel := 0;
1055
    text.foundSel := 0;
1056
    ShowCursor;
1056
    ShowCursor;
1057
    text.CurX := -1
1057
    text.CurX := -1
1058
END SetPos;
1058
END SetPos;
1059
 
1059
 
1060
 
1060
 
1061
PROCEDURE getSelect (text: tText; VAR selBeg, selEnd: tPoint);
1061
PROCEDURE getSelect (text: tText; VAR selBeg, selEnd: tPoint);
1062
BEGIN
1062
BEGIN
1063
    selBeg := text.cursor^;
1063
    selBeg := text.cursor^;
1064
    selEnd := text.select^;
1064
    selEnd := text.select^;
1065
    IF (selBeg.Y > selEnd.Y) OR (selBeg.Y = selEnd.Y) & (selBeg.X > selEnd.X) THEN
1065
    IF (selBeg.Y > selEnd.Y) OR (selBeg.Y = selEnd.Y) & (selBeg.X > selEnd.X) THEN
1066
        selBeg := text.select^;
1066
        selBeg := text.select^;
1067
        selEnd := text.cursor^
1067
        selEnd := text.cursor^
1068
    END
1068
    END
1069
END getSelect;
1069
END getSelect;
1070
 
1070
 
1071
 
1071
 
1072
PROCEDURE selected* (text: tText): BOOLEAN;
1072
PROCEDURE selected* (text: tText): BOOLEAN;
1073
    RETURN (text.cursor.X # text.select.X) OR (text.cursor.Y # text.select.Y)
1073
    RETURN (text.cursor.X # text.select.X) OR (text.cursor.Y # text.select.Y)
1074
END selected;
1074
END selected;
1075
 
1075
 
1076
 
1076
 
1077
PROCEDURE delSelect (text: tText);
1077
PROCEDURE delSelect (text: tText);
1078
VAR
1078
VAR
1079
    selBeg, selEnd: tPoint;
1079
    selBeg, selEnd: tPoint;
1080
    line, last, cur: tLine;
1080
    line, last, cur: tLine;
1081
BEGIN
1081
BEGIN
1082
    getSelect(text, selBeg, selEnd);
1082
    getSelect(text, selBeg, selEnd);
1083
    IF (selBeg.Y = selEnd.Y) & (selBeg.X < selEnd.X) THEN
1083
    IF (selBeg.Y = selEnd.Y) & (selBeg.X < selEnd.X) THEN
1084
        line := text.curLine;
1084
        line := text.curLine;
1085
        Lines.delCharN(line, selBeg.X, selEnd.X - selBeg.X);
1085
        Lines.delCharN(line, selBeg.X, selEnd.X - selBeg.X);
1086
        Lines.modify(line);
1086
        Lines.modify(line);
1087
        text.cursor^ := selBeg;
1087
        text.cursor^ := selBeg;
1088
        resetSelect(text);
1088
        resetSelect(text);
1089
        SetPos(text, text.cursor.X, text.cursor.Y);
1089
        SetPos(text, text.cursor.X, text.cursor.Y);
1090
        modify(text)
1090
        modify(text)
1091
    ELSIF selBeg.Y < selEnd.Y THEN
1091
    ELSIF selBeg.Y < selEnd.Y THEN
1092
        SetPos(text, selBeg.X, selBeg.Y);
1092
        SetPos(text, selBeg.X, selBeg.Y);
1093
        line := text.curLine;
1093
        line := text.curLine;
1094
        Lines.delCharN(line, selBeg.X, line.length - selBeg.X);
1094
        Lines.delCharN(line, selBeg.X, line.length - selBeg.X);
1095
        last := getLine(text, selEnd.Y);
1095
        last := getLine(text, selEnd.Y);
1096
        Lines.delCharN(last, 0, selEnd.X);
1096
        Lines.delCharN(last, 0, selEnd.X);
1097
        cur := line.next(tLine);
1097
        cur := line.next(tLine);
1098
        WHILE cur # last DO
1098
        WHILE cur # last DO
1099
            DelLine(text, cur);
1099
            DelLine(text, cur);
1100
            cur := line.next(tLine)
1100
            cur := line.next(tLine)
1101
        END;
1101
        END;
1102
        resetSelect(text);
1102
        resetSelect(text);
1103
        SetPos(text, text.cursor.X, text.cursor.Y);
1103
        SetPos(text, text.cursor.X, text.cursor.Y);
1104
        pdelete(text);
1104
        pdelete(text);
1105
        modify(text)
1105
        modify(text)
1106
    END;
1106
    END;
1107
    resetSelect(text)
1107
    resetSelect(text)
1108
END delSelect;
1108
END delSelect;
1109
 
1109
 
1110
 
1110
 
1111
PROCEDURE delete (text: tText);
1111
PROCEDURE delete (text: tText);
1112
VAR
1112
VAR
1113
    i, n: INTEGER;
1113
    i, n: INTEGER;
1114
    nextLine, curLine: tLine;
1114
    nextLine, curLine: tLine;
1115
BEGIN
1115
BEGIN
1116
    IF selected(text) THEN
1116
    IF selected(text) THEN
1117
        delSelect(text)
1117
        delSelect(text)
1118
    ELSE
1118
    ELSE
1119
        i := text.cursor.X;
1119
        i := text.cursor.X;
1120
        curLine := text.curLine;
1120
        curLine := text.curLine;
1121
        IF i < curLine.length THEN
1121
        IF i < curLine.length THEN
1122
            n := i;
1122
            n := i;
1123
            INC(i);
1123
            INC(i);
1124
            IF Lines.getChar(curLine, i - 1) = TAB THEN
1124
            IF Lines.getChar(curLine, i - 1) = TAB THEN
1125
                WHILE Lines.getChar(curLine, i) = TAB1 DO
1125
                WHILE Lines.getChar(curLine, i) = TAB1 DO
1126
                    INC(i)
1126
                    INC(i)
1127
                END
1127
                END
1128
            END;
1128
            END;
1129
            Lines.delCharN(curLine, n, i - n);
1129
            Lines.delCharN(curLine, n, i - n);
1130
            Lines.modify(curLine);
1130
            Lines.modify(curLine);
1131
            modify(text)
1131
            modify(text)
1132
        ELSE
1132
        ELSE
1133
            nextLine := curLine.next(tLine);
1133
            nextLine := curLine.next(tLine);
1134
            IF nextLine # NIL THEN
1134
            IF nextLine # NIL THEN
1135
                Lines.insert2(curLine, i, nextLine);
1135
                Lines.insert2(curLine, i, nextLine);
1136
                DelLine(text, nextLine);
1136
                DelLine(text, nextLine);
1137
                Lines.modify(curLine);
1137
                Lines.modify(curLine);
1138
                modify(text)
1138
                modify(text)
1139
            END
1139
            END
1140
        END
1140
        END
1141
    END;
1141
    END;
1142
    setSelect(text)
1142
    setSelect(text)
1143
END delete;
1143
END delete;
1144
 
1144
 
1145
 
1145
 
1146
PROCEDURE move (text: tText; d: INTEGER);
1146
PROCEDURE move (text: tText; d: INTEGER);
1147
VAR
1147
VAR
1148
    pos: INTEGER;
1148
    pos: INTEGER;
1149
BEGIN
1149
BEGIN
1150
    pos := text.cursor.X + d;
1150
    pos := text.cursor.X + d;
1151
    WHILE Lines.getChar(text.curLine, pos) = TAB1 DO
1151
    WHILE Lines.getChar(text.curLine, pos) = TAB1 DO
1152
        INC(pos, d)
1152
        INC(pos, d)
1153
    END;
1153
    END;
1154
    SetPos(text, pos, text.cursor.Y)
1154
    SetPos(text, pos, text.cursor.Y)
1155
END move;
1155
END move;
1156
 
1156
 
1157
 
1157
 
1158
PROCEDURE BkSpace (text: tText);
1158
PROCEDURE BkSpace (text: tText);
1159
VAR
1159
VAR
1160
    i, k, n: INTEGER;
1160
    i, k, n: INTEGER;
1161
    curLine, line, line2: tLine;
1161
    curLine, line, line2: tLine;
1162
BEGIN
1162
BEGIN
1163
    IF selected(text) THEN
1163
    IF selected(text) THEN
1164
        delSelect(text)
1164
        delSelect(text)
1165
    ELSE
1165
    ELSE
1166
        resetSelect(text);
1166
        resetSelect(text);
1167
        curLine := text.curLine;
1167
        curLine := text.curLine;
1168
        IF text.cursor.X > 0 THEN
1168
        IF text.cursor.X > 0 THEN
1169
        	INC(text.smallChange);
1169
        	INC(text.smallChange);
1170
            i := text.cursor.X;
1170
            i := text.cursor.X;
1171
            IF autoIndents THEN
1171
            IF autoIndents THEN
1172
	            n := leadingSpaces(curLine)
1172
	            n := leadingSpaces(curLine)
1173
            ELSE
1173
            ELSE
1174
    	        n := 0
1174
    	        n := 0
1175
            END;
1175
            END;
1176
            modify(text);
1176
            modify(text);
1177
            IF n < i THEN
1177
            IF n < i THEN
1178
                move(text, -1);
1178
                move(text, -1);
1179
                delete(text)
1179
                delete(text)
1180
            ELSE
1180
            ELSE
1181
                n := i;
1181
                n := i;
1182
                line := curLine.prev(tLine);
1182
                line := curLine.prev(tLine);
1183
                line2 := line;
1183
                line2 := line;
1184
                k := n;
1184
                k := n;
1185
                WHILE (line # NIL) & (k >= n) DO
1185
                WHILE (line # NIL) & (k >= n) DO
1186
                    IF Lines.trimLength(line) # 0 THEN
1186
                    IF Lines.trimLength(line) # 0 THEN
1187
                        k := leadingSpaces(line);
1187
                        k := leadingSpaces(line);
1188
                        line2 := line;
1188
                        line2 := line;
1189
                    END;
1189
                    END;
1190
                    PrevLine(line)
1190
                    PrevLine(line)
1191
                END;
1191
                END;
1192
                IF k >= n THEN
1192
                IF k >= n THEN
1193
                    k := 0
1193
                    k := 0
1194
                END;
1194
                END;
1195
                n := k;
1195
                n := k;
1196
                Lines.delCharN(curLine, 0, i);
1196
                Lines.delCharN(curLine, 0, i);
1197
                Lines.insert3(curLine, 0, k);
1197
                Lines.insert3(curLine, 0, k);
1198
                WHILE k > 0 DO
1198
                WHILE k > 0 DO
1199
                    Lines.setChar(curLine, k - 1, Lines.getChar(line2, k - 1));
1199
                    Lines.setChar(curLine, k - 1, Lines.getChar(line2, k - 1));
1200
                    DEC(k)
1200
                    DEC(k)
1201
                END;
1201
                END;
1202
                Lines.modify(curLine);
1202
                Lines.modify(curLine);
1203
                SetPos(text, n, text.cursor.Y)
1203
                SetPos(text, n, text.cursor.Y)
1204
            END
1204
            END
1205
        ELSE
1205
        ELSE
1206
            PrevLine(curLine);
1206
            PrevLine(curLine);
1207
            IF curLine # NIL THEN
1207
            IF curLine # NIL THEN
1208
                SetPos(text, curLine.length, text.cursor.Y - 1);
1208
                SetPos(text, curLine.length, text.cursor.Y - 1);
1209
                delete(text)
1209
                delete(text)
1210
            END
1210
            END
1211
        END
1211
        END
1212
    END;
1212
    END;
1213
    setSelect(text)
1213
    setSelect(text)
1214
END BkSpace;
1214
END BkSpace;
1215
 
1215
 
1216
 
1216
 
1217
PROCEDURE enter (text: tText);
1217
PROCEDURE enter (text: tText);
1218
VAR
1218
VAR
1219
    n: INTEGER;
1219
    n: INTEGER;
1220
    curLine, newLine, line, line2: tLine;
1220
    curLine, newLine, line, line2: tLine;
1221
BEGIN
1221
BEGIN
1222
    delSelect(text);
1222
    delSelect(text);
1223
    newLine := Lines.create(FALSE);
1223
    newLine := Lines.create(FALSE);
1224
    modify(text);
1224
    modify(text);
1225
    curLine := text.curLine;
1225
    curLine := text.curLine;
1226
    IF text.cursor.X < curLine.length THEN
1226
    IF text.cursor.X < curLine.length THEN
1227
        Lines.wrap(curLine, newLine, text.cursor.X);
1227
        Lines.wrap(curLine, newLine, text.cursor.X);
1228
        Lines.modify(curLine)
1228
        Lines.modify(curLine)
1229
    END;
1229
    END;
1230
    List._insert(text, curLine, newLine);
1230
    List._insert(text, curLine, newLine);
1231
    SetPos(text, 0, text.cursor.Y + 1);
1231
    SetPos(text, 0, text.cursor.Y + 1);
1232
    line := text.curLine.prev(tLine);
1232
    line := text.curLine.prev(tLine);
1233
    n := -1;
1233
    n := -1;
1234
    WHILE (line # NIL) & (n = -1) & autoIndents DO
1234
    WHILE (line # NIL) & (n = -1) & autoIndents DO
1235
        IF (*line.length*)Lines.trimLength(line) # 0 THEN
1235
        IF (*line.length*)Lines.trimLength(line) # 0 THEN
1236
            n := leadingSpaces(line);
1236
            n := leadingSpaces(line);
1237
            line2 := line
1237
            line2 := line
1238
        END;
1238
        END;
1239
        PrevLine(line)
1239
        PrevLine(line)
1240
    END;
1240
    END;
1241
    IF n = -1 THEN
1241
    IF n = -1 THEN
1242
        n := 0
1242
        n := 0
1243
    END;
1243
    END;
1244
    Lines.insert3(text.curLine, 0, n);
1244
    Lines.insert3(text.curLine, 0, n);
1245
    SetPos(text, n, text.cursor.Y);
1245
    SetPos(text, n, text.cursor.Y);
1246
    resetSelect(text);
1246
    resetSelect(text);
1247
    WHILE n > 0 DO
1247
    WHILE n > 0 DO
1248
        Lines.setChar(text.curLine, n - 1, Lines.getChar(line2, n - 1));
1248
        Lines.setChar(text.curLine, n - 1, Lines.getChar(line2, n - 1));
1249
        DEC(n)
1249
        DEC(n)
1250
    END;
1250
    END;
1251
    Lines.modify(newLine);
1251
    Lines.modify(newLine);
1252
    SetPos(text, text.cursor.X, text.cursor.Y)
1252
    SetPos(text, text.cursor.X, text.cursor.Y)
1253
END enter;
1253
END enter;
1254
 
1254
 
1255
 
1255
 
1256
PROCEDURE incIndent (line: tLine);
1256
PROCEDURE incIndent (line: tLine);
1257
VAR
1257
VAR
1258
	c: WCHAR;
1258
	c: WCHAR;
1259
	i: INTEGER;
1259
	i: INTEGER;
1260
BEGIN
1260
BEGIN
1261
	Lines.modify(line);
1261
	Lines.modify(line);
1262
	Lines.insert3(line, 0, Lines.tab);
1262
	Lines.insert3(line, 0, Lines.tab);
1263
	IF Lines.tabs THEN
1263
	IF Lines.tabs THEN
1264
		c := TAB1
1264
		c := TAB1
1265
	ELSE
1265
	ELSE
1266
		c := SPACE
1266
		c := SPACE
1267
	END;
1267
	END;
1268
	i := Lines.tab - 1;
1268
	i := Lines.tab - 1;
1269
	WHILE i >= 0 DO
1269
	WHILE i >= 0 DO
1270
		Lines.setChar(line, i, c);
1270
		Lines.setChar(line, i, c);
1271
		DEC(i)
1271
		DEC(i)
1272
	END;
1272
	END;
1273
	IF Lines.tabs THEN
1273
	IF Lines.tabs THEN
1274
		Lines.setChar(line, 0, TAB)
1274
		Lines.setChar(line, 0, TAB)
1275
	END
1275
	END
1276
END incIndent;
1276
END incIndent;
1277
 
1277
 
1278
 
1278
 
1279
PROCEDURE decIndent (line: tLine): BOOLEAN;
1279
PROCEDURE decIndent (line: tLine): BOOLEAN;
1280
VAR
1280
VAR
1281
	n: INTEGER;
1281
	n: INTEGER;
1282
BEGIN
1282
BEGIN
1283
	n := leadingSpaces(line);
1283
	n := leadingSpaces(line);
1284
	IF n > 0 THEN
1284
	IF n > 0 THEN
1285
		Lines.delCharN(line, 0, MIN(Lines.tab, n));
1285
		Lines.delCharN(line, 0, MIN(Lines.tab, n));
1286
		Lines.modify(line)
1286
		Lines.modify(line)
1287
	END
1287
	END
1288
	RETURN n > 0
1288
	RETURN n > 0
1289
END decIndent;
1289
END decIndent;
1290
 
1290
 
1291
 
1291
 
1292
PROCEDURE Indent* (text: tText; incr: BOOLEAN);
1292
PROCEDURE Indent* (text: tText; incr: BOOLEAN);
1293
VAR
1293
VAR
1294
    i: INTEGER;
1294
    i: INTEGER;
1295
    line: tLine;
1295
    line: tLine;
1296
    selBeg, selEnd: tPoint;
1296
    selBeg, selEnd: tPoint;
1297
    modified: BOOLEAN;
1297
    modified: BOOLEAN;
1298
BEGIN
1298
BEGIN
1299
	getSelect(text, selBeg, selEnd);
1299
	getSelect(text, selBeg, selEnd);
1300
	i := selEnd.Y - selBeg.Y + 1;
1300
	i := selEnd.Y - selBeg.Y + 1;
1301
	line := getLine2(text, selBeg.Y);
1301
	line := getLine2(text, selBeg.Y);
1302
	modified := incr;
1302
	modified := incr;
1303
	WHILE i > 0 DO
1303
	WHILE i > 0 DO
1304
		IF incr THEN
1304
		IF incr THEN
1305
			incIndent(line)
1305
			incIndent(line)
1306
		ELSE
1306
		ELSE
1307
    		modified := decIndent(line) OR modified
1307
    		modified := decIndent(line) OR modified
1308
		END;
1308
		END;
1309
		NextLine(line);
1309
		NextLine(line);
1310
		DEC(i)
1310
		DEC(i)
1311
	END;
1311
	END;
1312
	line := getLine2(text, selEnd.Y);
1312
	line := getLine2(text, selEnd.Y);
1313
	text.select^ := selBeg;
1313
	text.select^ := selBeg;
1314
	text.select.X := 0;
1314
	text.select.X := 0;
1315
	SetPos(text, line.length, selEnd.Y);
1315
	SetPos(text, line.length, selEnd.Y);
1316
	IF modified THEN
1316
	IF modified THEN
1317
		INC(text.smallChange);
1317
		INC(text.smallChange);
1318
   		modify(text)
1318
   		modify(text)
1319
	END
1319
	END
1320
END Indent;
1320
END Indent;
1321
 
1321
 
1322
 
1322
 
1323
PROCEDURE input* (text: tText; code: INTEGER);
1323
PROCEDURE input* (text: tText; code: INTEGER);
1324
VAR
1324
VAR
1325
    curLine: tLine;
1325
    curLine: tLine;
1326
 
1326
 
1327
 
1327
 
1328
    PROCEDURE tab (text: tText);
1328
    PROCEDURE tab (text: tText);
1329
    VAR
1329
    VAR
1330
        i, x: INTEGER;
1330
        i, x: INTEGER;
1331
        curLine: tLine;
1331
        curLine: tLine;
1332
        c: WCHAR;
1332
        c: WCHAR;
1333
    BEGIN
1333
    BEGIN
1334
		delSelect(text);
1334
		delSelect(text);
1335
		curLine := text.curLine;
1335
		curLine := text.curLine;
1336
		x := text.cursor.X;
1336
		x := text.cursor.X;
1337
		i := Lines.tab - x MOD Lines.tab;
1337
		i := Lines.tab - x MOD Lines.tab;
1338
		Lines.insert3(curLine, x, i);
1338
		Lines.insert3(curLine, x, i);
1339
		SetPos(text, x + i, text.cursor.Y);
1339
		SetPos(text, x + i, text.cursor.Y);
1340
		IF Lines.tabs THEN
1340
		IF Lines.tabs THEN
1341
			c := TAB1
1341
			c := TAB1
1342
		ELSE
1342
		ELSE
1343
			c := SPACE
1343
			c := SPACE
1344
		END;
1344
		END;
1345
		WHILE i > 0 DO
1345
		WHILE i > 0 DO
1346
			Lines.setChar(curLine, x + i - 1, c);
1346
			Lines.setChar(curLine, x + i - 1, c);
1347
			DEC(i)
1347
			DEC(i)
1348
		END;
1348
		END;
1349
		IF Lines.tabs THEN
1349
		IF Lines.tabs THEN
1350
			Lines.setChar(curLine, x + i, TAB)
1350
			Lines.setChar(curLine, x + i, TAB)
1351
		END;
1351
		END;
1352
		Lines.modify(curLine);
1352
		Lines.modify(curLine);
1353
		modify(text)
1353
		modify(text)
1354
    END tab;
1354
    END tab;
1355
 
1355
 
1356
 
1356
 
1357
BEGIN
1357
BEGIN
1358
    IF (code >= ORD(SPACE)) & (code # 127) THEN
1358
    IF (code >= ORD(SPACE)) & (code # 127) THEN
1359
    	IF ~selected(text) THEN
1359
    	IF ~selected(text) THEN
1360
    		INC(text.smallChange)
1360
    		INC(text.smallChange)
1361
    	END;
1361
    	END;
1362
        delSelect(text);
1362
        delSelect(text);
1363
        curLine := text.curLine;
1363
        curLine := text.curLine;
1364
        Lines.insert(curLine, text.cursor.X, WCHR(code));
1364
        Lines.insert(curLine, text.cursor.X, WCHR(code));
1365
        IF autoBrackets THEN
1365
        IF autoBrackets THEN
1366
        	IF code = ORD("(") THEN
1366
        	IF code = ORD("(") THEN
1367
        		code := ORD(")")
1367
        		code := ORD(")")
1368
        	ELSIF code = ORD("[") THEN
1368
        	ELSIF code = ORD("[") THEN
1369
        		code := ORD("]")
1369
        		code := ORD("]")
1370
        	ELSIF code = ORD("{") THEN
1370
        	ELSIF code = ORD("{") THEN
1371
        		code := ORD("}")
1371
        		code := ORD("}")
1372
        	ELSE
1372
        	ELSE
1373
        		code := -1
1373
        		code := -1
1374
        	END;
1374
        	END;
1375
        	IF code # -1 THEN
1375
        	IF code # -1 THEN
1376
        		Lines.insert(curLine, text.cursor.X + 1, WCHR(code))
1376
        		Lines.insert(curLine, text.cursor.X + 1, WCHR(code))
1377
        	END
1377
        	END
1378
        END;
1378
        END;
1379
        Lines.modify(curLine);
1379
        Lines.modify(curLine);
1380
        modify(text);
1380
        modify(text);
1381
        SetPos(text, text.cursor.X + 1, text.cursor.Y)
1381
        SetPos(text, text.cursor.X + 1, text.cursor.Y)
1382
    ELSIF code = 8 THEN
1382
    ELSIF code = 8 THEN
1383
		BkSpace(text)
1383
		BkSpace(text)
1384
    ELSIF code = -8 THEN
1384
    ELSIF code = -8 THEN
1385
    	IF selected(text) THEN
1385
    	IF selected(text) THEN
1386
    		Indent(text, FALSE)
1386
    		Indent(text, FALSE)
1387
        END
1387
        END
1388
    ELSIF code = 9 THEN
1388
    ELSIF code = 9 THEN
1389
    	IF selected(text) THEN
1389
    	IF selected(text) THEN
1390
    		Indent(text, TRUE)
1390
    		Indent(text, TRUE)
1391
    	ELSE
1391
    	ELSE
1392
    		INC(text.smallChange);
1392
    		INC(text.smallChange);
1393
	        tab(text)
1393
	        tab(text)
1394
        END
1394
        END
1395
    ELSIF code = 13 THEN
1395
    ELSIF code = 13 THEN
1396
        enter(text)
1396
        enter(text)
1397
    END
1397
    END
1398
END input;
1398
END input;
1399
 
1399
 
1400
 
1400
 
1401
PROCEDURE scroll* (text: tText; h, v: INTEGER);
1401
PROCEDURE scroll* (text: tText; h, v: INTEGER);
1402
BEGIN
1402
BEGIN
1403
    INC(text.scroll.X, h);
1403
    INC(text.scroll.X, h);
1404
    INC(text.scroll.Y, v);
1404
    INC(text.scroll.Y, v);
1405
    text.scroll.X := MIN(MAX(text.scroll.X, 0), text.maxLength);
1405
    text.scroll.X := MIN(MAX(text.scroll.X, 0), text.maxLength);
1406
    text.scroll.Y := MIN(MAX(text.scroll.Y, 0), text.count - 1)
1406
    text.scroll.Y := MIN(MAX(text.scroll.Y, 0), text.count - 1)
1407
END scroll;
1407
END scroll;
1408
 
1408
 
1409
 
1409
 
1410
PROCEDURE save* (text: tText; name: RW.tFileName): BOOLEAN;
1410
PROCEDURE save* (text: tText; name: RW.tFileName): BOOLEAN;
1411
CONST
1411
CONST
1412
    tempFile = "/tmp0/1/cedit~.tmp";
1412
    tempFile = "/tmp0/1/cedit~.tmp";
1413
VAR
1413
VAR
1414
    line: tLine;
1414
    line: tLine;
1415
    file: RW.tOutput;
1415
    file: RW.tOutput;
1416
    res: BOOLEAN;
1416
    res: BOOLEAN;
1417
    Len: INTEGER;
1417
    Len: INTEGER;
1418
BEGIN
1418
BEGIN
1419
    ChangeLog.setGuard(text.edition);
1419
    ChangeLog.setGuard(text.edition);
1420
    file := RW.create(tempFile, text.enc, text.eol);
1420
    file := RW.create(tempFile, text.enc, text.eol);
1421
    IF file # NIL THEN
1421
    IF file # NIL THEN
1422
        ChangeLog.delSaved;
1422
        ChangeLog.delSaved;
1423
        line := text.first(tLine);
1423
        line := text.first(tLine);
1424
        WHILE line # NIL DO
1424
        WHILE line # NIL DO
1425
        	IF trimSpace THEN
1425
        	IF trimSpace THEN
1426
        		Len := Lines.trimLength(line)
1426
        		Len := Lines.trimLength(line)
1427
        	ELSE
1427
        	ELSE
1428
        		Len := line.length
1428
        		Len := line.length
1429
        	END;
1429
        	END;
1430
            RW.putString(file, line, Len);
1430
            RW.putString(file, line, Len);
1431
            NextLine(line);
1431
            NextLine(line);
1432
            IF line # NIL THEN
1432
            IF line # NIL THEN
1433
                RW.newLine(file)
1433
                RW.newLine(file)
1434
            END
1434
            END
1435
        END;
1435
        END;
1436
        res := RW.close(file)
1436
        res := RW.close(file)
1437
    ELSE
1437
    ELSE
1438
        res := FALSE
1438
        res := FALSE
1439
    END;
1439
    END;
1440
    IF res THEN
1440
    IF res THEN
1441
        res := File.Copy(tempFile, name);
1441
        res := File.Copy(tempFile, name);
1442
        IF res THEN
1442
        IF res THEN
1443
            text.modified := FALSE;
1443
            text.modified := FALSE;
1444
            ChangeLog.save(text.edition);
1444
            ChangeLog.save(text.edition);
1445
 
1445
 
1446
	        line := text.first(tLine);
1446
	        line := text.first(tLine);
1447
	        WHILE line # NIL DO
1447
	        WHILE line # NIL DO
1448
	            IF line.modified THEN
1448
	            IF line.modified THEN
1449
	                Lines.save(line)
1449
	                Lines.save(line)
1450
	            END;
1450
	            END;
1451
	            NextLine(line)
1451
	            NextLine(line)
1452
	        END
1452
	        END
1453
        END
1453
        END
1454
    END;
1454
    END;
1455
    IF File.Delete(tempFile) THEN END;
1455
    IF File.Delete(tempFile) THEN END;
1456
    IF ~res THEN
1456
    IF ~res THEN
1457
        ChangeLog.delCurSaved
1457
        ChangeLog.delCurSaved
1458
    END
1458
    END
1459
    RETURN res
1459
    RETURN res
1460
END save;
1460
END save;
1461
 
1461
 
1462
 
1462
 
1463
PROCEDURE redoGuard (text: tText; guard: tGuard);
1463
PROCEDURE redoGuard (text: tText; guard: tGuard);
1464
BEGIN
1464
BEGIN
1465
    text.edition := guard;
1465
    text.edition := guard;
1466
    text.cursor^ := guard.cursor;
1466
    text.cursor^ := guard.cursor;
1467
    text.select2^ := guard.select2;
1467
    text.select2^ := guard.select2;
1468
    text.scroll := guard.scroll;
1468
    text.scroll := guard.scroll;
1469
    text.CurX := guard.CurX;
1469
    text.CurX := guard.CurX;
1470
    IF guard.selected THEN
1470
    IF guard.selected THEN
1471
        text.select := text.select2
1471
        text.select := text.select2
1472
    ELSE
1472
    ELSE
1473
        text.select := text.cursor
1473
        text.select := text.cursor
1474
    END;
1474
    END;
1475
    text.curLine := getLine(text, text.cursor.Y);
1475
    text.curLine := getLine(text, text.cursor.Y);
1476
    text.comments := TRUE;
1476
    text.comments := TRUE;
1477
    text.search := TRUE
1477
    text.search := TRUE
1478
END redoGuard;
1478
END redoGuard;
1479
 
1479
 
1480
 
1480
 
1481
PROCEDURE undo* (text: tText);
1481
PROCEDURE undo* (text: tText);
1482
VAR
1482
VAR
1483
    item: List.tItem;
1483
    item: List.tItem;
1484
    guard: tGuard;
1484
    guard: tGuard;
1485
BEGIN
1485
BEGIN
1486
    guard := text.edition;
1486
    guard := text.edition;
1487
    item := guard.prev;
1487
    item := guard.prev;
1488
    WHILE (item # NIL) & ~(item IS tGuard) DO
1488
    WHILE (item # NIL) & ~(item IS tGuard) DO
1489
        item := item.prev
1489
        item := item.prev
1490
    END;
1490
    END;
1491
 
1491
 
1492
    IF item # NIL THEN
1492
    IF item # NIL THEN
1493
        guard := item(tGuard);
1493
        guard := item(tGuard);
1494
        text.edition := guard
1494
        text.edition := guard
1495
    END;
1495
    END;
1496
 
1496
 
1497
    item := ChangeLog.CL.Log.first;
1497
    item := ChangeLog.CL.Log.first;
1498
    WHILE item # guard DO
1498
    WHILE item # guard DO
1499
        ChangeLog.redo(item);
1499
        ChangeLog.redo(item);
1500
        item := item.next
1500
        item := item.next
1501
    END;
1501
    END;
1502
    redoGuard(text, guard);
1502
    redoGuard(text, guard);
1503
    ChangeLog.setGuard(guard);
1503
    ChangeLog.setGuard(guard);
1504
    text.modified := ~guard.saved;
1504
    text.modified := ~guard.saved;
1505
    ShowCursor
1505
    ShowCursor
1506
END undo;
1506
END undo;
1507
 
1507
 
1508
 
1508
 
1509
PROCEDURE redo* (text: tText);
1509
PROCEDURE redo* (text: tText);
1510
VAR
1510
VAR
1511
    item: List.tItem;
1511
    item: List.tItem;
1512
    guard: tGuard;
1512
    guard: tGuard;
1513
BEGIN
1513
BEGIN
1514
    guard := text.edition;
1514
    guard := text.edition;
1515
    item := guard.next;
1515
    item := guard.next;
1516
    WHILE (item # NIL) & ~(item IS tGuard) DO
1516
    WHILE (item # NIL) & ~(item IS tGuard) DO
1517
        ChangeLog.redo(item);
1517
        ChangeLog.redo(item);
1518
        item := item.next
1518
        item := item.next
1519
    END;
1519
    END;
1520
    IF item # NIL THEN
1520
    IF item # NIL THEN
1521
        guard := item(tGuard);
1521
        guard := item(tGuard);
1522
        redoGuard(text, guard)
1522
        redoGuard(text, guard)
1523
    END;
1523
    END;
1524
    ChangeLog.setGuard(guard);
1524
    ChangeLog.setGuard(guard);
1525
    text.modified := ~guard.saved;
1525
    text.modified := ~guard.saved;
1526
    ShowCursor
1526
    ShowCursor
1527
END redo;
1527
END redo;
1528
 
1528
 
1529
 
1529
 
1530
PROCEDURE getSelCnt* (text: tText; VAR chars, lines: INTEGER);
1530
PROCEDURE getSelCnt* (text: tText; VAR chars, lines: INTEGER);
1531
VAR
1531
VAR
1532
	selBeg, selEnd: tPoint;
1532
	selBeg, selEnd: tPoint;
1533
	first, last, line: tLine;
1533
	first, last, line: tLine;
1534
 
1534
 
1535
	PROCEDURE charCnt (line: tLine; first, last: INTEGER): INTEGER;
1535
	PROCEDURE charCnt (line: tLine; first, last: INTEGER): INTEGER;
1536
	VAR
1536
	VAR
1537
		i, res: INTEGER;
1537
		i, res: INTEGER;
1538
	BEGIN
1538
	BEGIN
1539
		res := 0;
1539
		res := 0;
1540
		FOR i := first TO last DO
1540
		FOR i := first TO last DO
1541
			IF Lines.getChar(line, i) # TAB1 THEN
1541
			IF Lines.getChar(line, i) # TAB1 THEN
1542
				INC(res)
1542
				INC(res)
1543
			END
1543
			END
1544
		END
1544
		END
1545
		RETURN res
1545
		RETURN res
1546
	END charCnt;
1546
	END charCnt;
1547
 
1547
 
1548
BEGIN
1548
BEGIN
1549
	IF selected(text) THEN
1549
	IF selected(text) THEN
1550
		getSelect(text, selBeg, selEnd);
1550
		getSelect(text, selBeg, selEnd);
1551
		first := getLine2(text, selBeg.Y);
1551
		first := getLine2(text, selBeg.Y);
1552
		last  := getLine2(text, selEnd.Y);
1552
		last  := getLine2(text, selEnd.Y);
1553
		lines := selEnd.Y - selBeg.Y + 1;
1553
		lines := selEnd.Y - selBeg.Y + 1;
1554
 
1554
 
1555
		IF lines > 1 THEN
1555
		IF lines > 1 THEN
1556
			chars := charCnt(first, selBeg.X, first.length - 1) + charCnt(last, 0, selEnd.X - 1) + lenEOL;
1556
			chars := charCnt(first, selBeg.X, first.length - 1) + charCnt(last, 0, selEnd.X - 1) + lenEOL;
1557
			line := first.next(tLine);
1557
			line := first.next(tLine);
1558
			WHILE line # last DO
1558
			WHILE line # last DO
1559
				INC(chars, charCnt(line, 0, line.length - 1) + lenEOL);
1559
				INC(chars, charCnt(line, 0, line.length - 1) + lenEOL);
1560
				NextLine(line)
1560
				NextLine(line)
1561
			END
1561
			END
1562
		ELSE
1562
		ELSE
1563
			chars := charCnt(first, selBeg.X, selEnd.X - 1)
1563
			chars := charCnt(first, selBeg.X, selEnd.X - 1)
1564
		END
1564
		END
1565
	ELSE
1565
	ELSE
1566
		chars := 0;
1566
		chars := 0;
1567
		lines := 0
1567
		lines := 0
1568
	END
1568
	END
1569
END getSelCnt;
1569
END getSelCnt;
1570
 
1570
 
1571
 
1571
 
1572
PROCEDURE copy (text: tText);
1572
PROCEDURE copy (text: tText);
1573
VAR
1573
VAR
1574
    selBeg, selEnd: tPoint;
1574
    selBeg, selEnd: tPoint;
1575
    first, line: tLine;
1575
    first, line: tLine;
1576
    cnt, n: INTEGER;
1576
    cnt, n: INTEGER;
1577
    buffer: CB.tBuffer;
1577
    buffer: CB.tBuffer;
1578
 
1578
 
1579
 
1579
 
1580
    PROCEDURE append (buffer: CB.tBuffer; line: tLine; first, last: INTEGER);
1580
    PROCEDURE append (buffer: CB.tBuffer; line: tLine; first, last: INTEGER);
1581
    BEGIN
1581
    BEGIN
1582
        IF first <= last THEN
1582
        IF first <= last THEN
1583
            CB.append(buffer, line, first, last)
1583
            CB.append(buffer, line, first, last)
1584
        ELSE
1584
        ELSE
1585
            IF U.OS = "KOS" THEN
1585
            IF U.OS = "KOS" THEN
1586
                CB.appends(buffer, SPACE, 0, 0)
1586
                CB.appends(buffer, SPACE, 0, 0)
1587
            END
1587
            END
1588
        END
1588
        END
1589
    END append;
1589
    END append;
1590
 
1590
 
1591
 
1591
 
1592
BEGIN
1592
BEGIN
1593
    getSelect(text, selBeg, selEnd);
1593
    getSelect(text, selBeg, selEnd);
1594
 
1594
 
1595
    first := getLine2(text, selBeg.Y);
1595
    first := getLine2(text, selBeg.Y);
1596
    line := first;
1596
    line := first;
1597
 
1597
 
1598
    n := selEnd.Y - selBeg.Y;
1598
    n := selEnd.Y - selBeg.Y;
1599
    cnt := 0;
1599
    cnt := 0;
1600
    WHILE n >= 0 DO
1600
    WHILE n >= 0 DO
1601
        INC(cnt, line.length + (lenEOL + ORD(U.OS = "KOS")));
1601
        INC(cnt, line.length + (lenEOL + ORD(U.OS = "KOS")));
1602
        NextLine(line);
1602
        NextLine(line);
1603
        DEC(n)
1603
        DEC(n)
1604
    END;
1604
    END;
1605
 
1605
 
1606
    buffer := CB.create(cnt + 2); (* +2 wchars EOT *)
1606
    buffer := CB.create(cnt + 2); (* +2 wchars EOT *)
1607
 
1607
 
1608
    n := selEnd.Y - selBeg.Y;
1608
    n := selEnd.Y - selBeg.Y;
1609
    line := first;
1609
    line := first;
1610
    IF n = 0 THEN
1610
    IF n = 0 THEN
1611
        append(buffer, line, selBeg.X, selEnd.X - 1)
1611
        append(buffer, line, selBeg.X, selEnd.X - 1)
1612
    ELSE
1612
    ELSE
1613
        append(buffer, line, selBeg.X, line.length - 1);
1613
        append(buffer, line, selBeg.X, line.length - 1);
1614
        REPEAT
1614
        REPEAT
1615
            DEC(n);
1615
            DEC(n);
1616
            CB.eol(buffer);
1616
            CB.eol(buffer);
1617
            NextLine(line);
1617
            NextLine(line);
1618
            IF n > 0 THEN
1618
            IF n > 0 THEN
1619
                append(buffer, line, 0, line.length - 1)
1619
                append(buffer, line, 0, line.length - 1)
1620
            END
1620
            END
1621
        UNTIL n = 0;
1621
        UNTIL n = 0;
1622
        append(buffer, line, 0, selEnd.X - 1)
1622
        append(buffer, line, 0, selEnd.X - 1)
1623
    END;
1623
    END;
1624
    CB.eot(buffer);
1624
    CB.eot(buffer);
1625
    CB.put(buffer);
1625
    CB.put(buffer);
1626
    CB.destroy(buffer)
1626
    CB.destroy(buffer)
1627
END copy;
1627
END copy;
1628
 
1628
 
1629
 
1629
 
1630
PROCEDURE paste (text: tText);
1630
PROCEDURE paste (text: tText);
1631
VAR
1631
VAR
1632
    line, newLine, curLine: tLine;
1632
    line, newLine, curLine: tLine;
1633
    w: INTEGER;
1633
    w: INTEGER;
1634
    cliptext: RW.tInput;
1634
    cliptext: RW.tInput;
1635
    eol: BOOLEAN;
1635
    eol: BOOLEAN;
1636
    cursor: pPoint;
1636
    cursor: pPoint;
1637
 
1637
 
1638
 
1638
 
1639
    PROCEDURE lineWidth (line: tLine; pos: INTEGER): INTEGER;
1639
    PROCEDURE lineWidth (line: tLine; pos: INTEGER): INTEGER;
1640
    VAR
1640
    VAR
1641
    	i, res: INTEGER;
1641
    	i, res: INTEGER;
1642
    	c: WCHAR;
1642
    	c: WCHAR;
1643
    BEGIN
1643
    BEGIN
1644
    	res := pos;
1644
    	res := pos;
1645
    	i := 0;
1645
    	i := 0;
1646
    	REPEAT
1646
    	REPEAT
1647
	    	c := Lines.getChar(line, i);
1647
	    	c := Lines.getChar(line, i);
1648
	    	IF c = TAB THEN
1648
	    	IF c = TAB THEN
1649
	    		INC(res, Lines.tab - res MOD Lines.tab)
1649
	    		INC(res, Lines.tab - res MOD Lines.tab)
1650
	    	ELSIF c # TAB1 THEN
1650
	    	ELSIF c # TAB1 THEN
1651
	    		INC(res)
1651
	    		INC(res)
1652
	    	END;
1652
	    	END;
1653
	    	INC(i)
1653
	    	INC(i)
1654
    	UNTIL c = 0X
1654
    	UNTIL c = 0X
1655
    	RETURN res - pos - 1
1655
    	RETURN res - pos - 1
1656
    END lineWidth;
1656
    END lineWidth;
1657
 
1657
 
1658
 
1658
 
1659
BEGIN
1659
BEGIN
1660
    line := Lines.create(TRUE);
1660
    line := Lines.create(TRUE);
1661
    cliptext := RW.clipboard();
1661
    cliptext := RW.clipboard();
1662
    delSelect(text);
1662
    delSelect(text);
1663
    cursor := text.cursor;
1663
    cursor := text.cursor;
1664
    WHILE (cliptext # NIL) & (RW.getString(cliptext, line, Lines.tabs, eol) >= 0) DO
1664
    WHILE (cliptext # NIL) & (RW.getString(cliptext, line, Lines.tabs, eol) >= 0) DO
1665
        IF line.length > 0 THEN
1665
        IF line.length > 0 THEN
1666
        	w := lineWidth(line, cursor.X);
1666
        	w := lineWidth(line, cursor.X);
1667
            Lines.insert2(text.curLine, cursor.X, line);
1667
            Lines.insert2(text.curLine, cursor.X, line);
1668
            Lines.modify(text.curLine);
1668
            Lines.modify(text.curLine);
1669
            modify(text);
1669
            modify(text);
1670
            SetPos(text, cursor.X + w, cursor.Y);
1670
            SetPos(text, cursor.X + w, cursor.Y);
1671
            resetSelect(text)
1671
            resetSelect(text)
1672
        END;
1672
        END;
1673
        IF eol THEN
1673
        IF eol THEN
1674
            newLine := Lines.create(FALSE);
1674
            newLine := Lines.create(FALSE);
1675
            modify(text);
1675
            modify(text);
1676
            curLine := text.curLine;
1676
            curLine := text.curLine;
1677
            IF cursor.X < curLine.length THEN
1677
            IF cursor.X < curLine.length THEN
1678
                Lines.wrap(curLine, newLine, cursor.X);
1678
                Lines.wrap(curLine, newLine, cursor.X);
1679
                Lines.modify(curLine)
1679
                Lines.modify(curLine)
1680
            END;
1680
            END;
1681
            List._insert(text, curLine, newLine);
1681
            List._insert(text, curLine, newLine);
1682
            Lines.modify(newLine);
1682
            Lines.modify(newLine);
1683
            SetPos(text, 0, cursor.Y + 1);
1683
            SetPos(text, 0, cursor.Y + 1);
1684
            resetSelect(text)
1684
            resetSelect(text)
1685
        END;
1685
        END;
1686
        Lines.destroy(line);
1686
        Lines.destroy(line);
1687
        line := Lines.create(TRUE)
1687
        line := Lines.create(TRUE)
1688
    END;
1688
    END;
1689
    SetPos(text, cursor.X, cursor.Y);
1689
    SetPos(text, cursor.X, cursor.Y);
1690
    Lines.destroy(line);
1690
    Lines.destroy(line);
1691
    RW.destroy(cliptext)
1691
    RW.destroy(cliptext)
1692
END paste;
1692
END paste;
1693
 
1693
 
1694
 
1694
 
1695
PROCEDURE searchScroll (text: tText; n: INTEGER);
1695
PROCEDURE searchScroll (text: tText; n: INTEGER);
1696
BEGIN
1696
BEGIN
1697
    IF n - text.scroll.Y > textsize.Y - 1 THEN
1697
    IF n - text.scroll.Y > textsize.Y - 1 THEN
1698
        text.scroll.Y := MAX(n - 2 * textsize.Y DIV 3, 0)
1698
        text.scroll.Y := MAX(n - 2 * textsize.Y DIV 3, 0)
1699
    ELSIF n < text.scroll.Y THEN
1699
    ELSIF n < text.scroll.Y THEN
1700
        text.scroll.Y := MAX(n - textsize.Y DIV 3, 0)
1700
        text.scroll.Y := MAX(n - textsize.Y DIV 3, 0)
1701
    END
1701
    END
1702
END searchScroll;
1702
END searchScroll;
1703
 
1703
 
1704
 
1704
 
1705
PROCEDURE goto* (text: tText; n: INTEGER): BOOLEAN;
1705
PROCEDURE goto* (text: tText; n: INTEGER): BOOLEAN;
1706
VAR
1706
VAR
1707
    res: BOOLEAN;
1707
    res: BOOLEAN;
1708
BEGIN
1708
BEGIN
1709
    DEC(n);
1709
    DEC(n);
1710
    IF (0 <= n) & (n < text.count) THEN
1710
    IF (0 <= n) & (n < text.count) THEN
1711
        resetSelect(text);
1711
        resetSelect(text);
1712
        searchScroll(text, n);
1712
        searchScroll(text, n);
1713
        SetPos(text, 0, n);
1713
        SetPos(text, 0, n);
1714
        res := TRUE
1714
        res := TRUE
1715
    ELSE
1715
    ELSE
1716
        res := FALSE
1716
        res := FALSE
1717
    END
1717
    END
1718
    RETURN res
1718
    RETURN res
1719
END goto;
1719
END goto;
1720
 
1720
 
1721
 
1721
 
1722
PROCEDURE toggleLabel* (text: tText);
1722
PROCEDURE toggleLabel* (text: tText);
1723
BEGIN
1723
BEGIN
1724
    text.curLine.label := ~text.curLine.label
1724
    text.curLine.label := ~text.curLine.label
1725
END toggleLabel;
1725
END toggleLabel;
1726
 
1726
 
1727
 
1727
 
1728
PROCEDURE gotoLabel* (text: tText; frw: BOOLEAN);
1728
PROCEDURE gotoLabel* (text: tText; frw: BOOLEAN);
1729
VAR
1729
VAR
1730
    line: tLine;
1730
    line: tLine;
1731
    n: INTEGER;
1731
    n: INTEGER;
1732
 
1732
 
1733
    PROCEDURE search (VAR line: tLine; VAR n: INTEGER; frw: BOOLEAN);
1733
    PROCEDURE search (VAR line: tLine; VAR n: INTEGER; frw: BOOLEAN);
1734
    BEGIN
1734
    BEGIN
1735
        IF frw THEN
1735
        IF frw THEN
1736
            WHILE (line # NIL) & ~line.label DO
1736
            WHILE (line # NIL) & ~line.label DO
1737
                NextLine(line);
1737
                NextLine(line);
1738
                INC(n)
1738
                INC(n)
1739
            END
1739
            END
1740
        ELSE
1740
        ELSE
1741
            WHILE (line # NIL) & ~line.label DO
1741
            WHILE (line # NIL) & ~line.label DO
1742
                PrevLine(line);
1742
                PrevLine(line);
1743
                DEC(n)
1743
                DEC(n)
1744
            END
1744
            END
1745
        END
1745
        END
1746
    END search;
1746
    END search;
1747
 
1747
 
1748
BEGIN
1748
BEGIN
1749
    n := text.cursor.Y;
1749
    n := text.cursor.Y;
1750
    line := text.curLine;
1750
    line := text.curLine;
1751
    IF frw THEN
1751
    IF frw THEN
1752
        NextLine(line);
1752
        NextLine(line);
1753
        INC(n)
1753
        INC(n)
1754
    ELSE
1754
    ELSE
1755
        PrevLine(line);
1755
        PrevLine(line);
1756
        DEC(n)
1756
        DEC(n)
1757
    END;
1757
    END;
1758
    search(line, n, frw);
1758
    search(line, n, frw);
1759
    IF line = NIL THEN
1759
    IF line = NIL THEN
1760
        IF frw THEN
1760
        IF frw THEN
1761
            n := 0;
1761
            n := 0;
1762
            line := text.first(tLine)
1762
            line := text.first(tLine)
1763
        ELSE
1763
        ELSE
1764
            n := text.count - 1;
1764
            n := text.count - 1;
1765
            line := text.last(tLine)
1765
            line := text.last(tLine)
1766
        END;
1766
        END;
1767
        search(line, n, frw)
1767
        search(line, n, frw)
1768
    END;
1768
    END;
1769
    IF line # NIL THEN
1769
    IF line # NIL THEN
1770
        IF goto(text, n + 1) THEN END
1770
        IF goto(text, n + 1) THEN END
1771
    END
1771
    END
1772
END gotoLabel;
1772
END gotoLabel;
1773
 
1773
 
1774
 
1774
 
1775
PROCEDURE changeCase (text: tText; upper: BOOLEAN);
1775
PROCEDURE changeCase (text: tText; upper: BOOLEAN);
1776
VAR
1776
VAR
1777
    i: INTEGER;
1777
    i: INTEGER;
1778
    line: tLine;
1778
    line: tLine;
1779
    func: Lines.fConvert;
1779
    func: Lines.fConvert;
1780
BEGIN
1780
BEGIN
1781
    line := text.curLine;
1781
    line := text.curLine;
1782
    i := text.cursor.X - 1;
1782
    i := text.cursor.X - 1;
1783
 
1783
 
1784
    WHILE (i >= 0) & U.isLetter(Lines.getChar(line, i)) DO
1784
    WHILE (i >= 0) & U.isLetter(Lines.getChar(line, i)) DO
1785
        DEC(i)
1785
        DEC(i)
1786
    END;
1786
    END;
1787
 
1787
 
1788
    IF upper THEN
1788
    IF upper THEN
1789
    	func := U.cap
1789
    	func := U.cap
1790
    ELSE
1790
    ELSE
1791
    	func := U.low
1791
    	func := U.low
1792
    END;
1792
    END;
1793
 
1793
 
1794
    IF Lines.convert(line, i + 1, text.cursor.X - 1, func) THEN
1794
    IF Lines.convert(line, i + 1, text.cursor.X - 1, func) THEN
1795
    	INC(text.smallChange);
1795
    	INC(text.smallChange);
1796
        modify(text)
1796
        modify(text)
1797
    END
1797
    END
1798
END changeCase;
1798
END changeCase;
1799
 
1799
 
1800
 
1800
 
1801
PROCEDURE chCase* (text: tText; upper: BOOLEAN);
1801
PROCEDURE chCase* (text: tText; upper: BOOLEAN);
1802
VAR
1802
VAR
1803
    selBeg, selEnd: tPoint;
1803
    selBeg, selEnd: tPoint;
1804
    first, line: Lines.tLine;
1804
    first, line: Lines.tLine;
1805
    cnt: INTEGER;
1805
    cnt: INTEGER;
1806
    func: Lines.fConvert;
1806
    func: Lines.fConvert;
1807
    modified: BOOLEAN;
1807
    modified: BOOLEAN;
1808
BEGIN
1808
BEGIN
1809
    modified := FALSE;
1809
    modified := FALSE;
1810
    IF selected(text) THEN
1810
    IF selected(text) THEN
1811
        getSelect(text, selBeg, selEnd);
1811
        getSelect(text, selBeg, selEnd);
1812
        first := getLine2(text, selBeg.Y);
1812
        first := getLine2(text, selBeg.Y);
1813
        line := first;
1813
        line := first;
1814
        cnt := selEnd.Y - selBeg.Y;
1814
        cnt := selEnd.Y - selBeg.Y;
1815
 
1815
 
1816
	    IF upper THEN
1816
	    IF upper THEN
1817
	    	func := U.cap
1817
	    	func := U.cap
1818
	    ELSE
1818
	    ELSE
1819
	    	func := U.low
1819
	    	func := U.low
1820
	    END;
1820
	    END;
1821
 
1821
 
1822
        IF cnt = 0 THEN
1822
        IF cnt = 0 THEN
1823
            IF Lines.convert(line, selBeg.X, selEnd.X - 1, func) THEN
1823
            IF Lines.convert(line, selBeg.X, selEnd.X - 1, func) THEN
1824
                modified := TRUE
1824
                modified := TRUE
1825
            END
1825
            END
1826
        ELSE
1826
        ELSE
1827
            IF Lines.convert(line, selBeg.X, line.length - 1, func) THEN
1827
            IF Lines.convert(line, selBeg.X, line.length - 1, func) THEN
1828
                modified := TRUE
1828
                modified := TRUE
1829
            END;
1829
            END;
1830
            WHILE cnt > 1 DO
1830
            WHILE cnt > 1 DO
1831
                NextLine(line);
1831
                NextLine(line);
1832
                IF Lines.convert(line, 0, line.length - 1, func) THEN
1832
                IF Lines.convert(line, 0, line.length - 1, func) THEN
1833
                    modified := TRUE
1833
                    modified := TRUE
1834
                END;
1834
                END;
1835
                DEC(cnt)
1835
                DEC(cnt)
1836
            END;
1836
            END;
1837
            NextLine(line);
1837
            NextLine(line);
1838
            IF Lines.convert(line, 0, selEnd.X - 1, func) THEN
1838
            IF Lines.convert(line, 0, selEnd.X - 1, func) THEN
1839
                modified := TRUE
1839
                modified := TRUE
1840
            END
1840
            END
1841
        END
1841
        END
1842
    END;
1842
    END;
1843
    IF modified THEN
1843
    IF modified THEN
1844
    	INC(text.smallChange);
1844
    	INC(text.smallChange);
1845
        modify(text)
1845
        modify(text)
1846
    END
1846
    END
1847
END chCase;
1847
END chCase;
1848
 
1848
 
1849
 
1849
 
1850
PROCEDURE UpDown (text: tText; step: INTEGER);
1850
PROCEDURE UpDown (text: tText; step: INTEGER);
1851
VAR
1851
VAR
1852
    temp: INTEGER;
1852
    temp: INTEGER;
1853
BEGIN
1853
BEGIN
1854
    IF text.CurX = -1 THEN
1854
    IF text.CurX = -1 THEN
1855
        text.CurX := text.cursor.X
1855
        text.CurX := text.cursor.X
1856
    END;
1856
    END;
1857
    temp := text.CurX;
1857
    temp := text.CurX;
1858
    SetPos(text, temp, text.cursor.Y + step);
1858
    SetPos(text, temp, text.cursor.Y + step);
1859
    text.CurX := temp
1859
    text.CurX := temp
1860
END UpDown;
1860
END UpDown;
1861
 
1861
 
1862
 
1862
 
1863
PROCEDURE delLine* (text: tText);
1863
PROCEDURE delLine* (text: tText);
1864
BEGIN
1864
BEGIN
1865
	text.smallChange := 2;
1865
	text.smallChange := 2;
1866
    resetSelect(text);
1866
    resetSelect(text);
1867
    IF text.curLine.length > 0 THEN
1867
    IF text.curLine.length > 0 THEN
1868
        Lines.delCharN(text.curLine, 0, text.curLine.length)
1868
        Lines.delCharN(text.curLine, 0, text.curLine.length)
1869
    END;
1869
    END;
1870
    SetPos(text, 0, text.cursor.Y);
1870
    SetPos(text, 0, text.cursor.Y);
1871
    IF text.cursor.Y = text.count - 1 THEN
1871
    IF text.cursor.Y = text.count - 1 THEN
1872
        BkSpace(text)
1872
        BkSpace(text)
1873
    ELSE
1873
    ELSE
1874
        delete(text)
1874
        delete(text)
1875
    END
1875
    END
1876
END delLine;
1876
END delLine;
1877
 
1877
 
1878
 
1878
 
1879
PROCEDURE dupLine* (text: tText);
1879
PROCEDURE dupLine* (text: tText);
1880
VAR
1880
VAR
1881
    newLine, curLine: tLine;
1881
    newLine, curLine: tLine;
1882
BEGIN
1882
BEGIN
1883
    curLine := text.curLine;
1883
    curLine := text.curLine;
1884
    newLine := Lines.create(FALSE);
1884
    newLine := Lines.create(FALSE);
1885
    modify(text);
1885
    modify(text);
1886
    Lines.insert3(newLine, 0, curLine.length);
1886
    Lines.insert3(newLine, 0, curLine.length);
1887
    List._insert(text, curLine, newLine);
1887
    List._insert(text, curLine, newLine);
1888
    Lines.move(curLine, newLine);
1888
    Lines.move(curLine, newLine);
1889
    Lines.modify(newLine)
1889
    Lines.modify(newLine)
1890
END dupLine;
1890
END dupLine;
1891
 
1891
 
1892
 
1892
 
1893
PROCEDURE MoveLines* (text: tText; down: BOOLEAN);
1893
PROCEDURE MoveLines* (text: tText; down: BOOLEAN);
1894
VAR
1894
VAR
1895
	last, first, line: tLine;
1895
	last, first, line: tLine;
1896
	selBeg, selEnd, temp: tPoint;
1896
	selBeg, selEnd, temp: tPoint;
1897
	step: INTEGER;
1897
	step: INTEGER;
1898
	frw: BOOLEAN;
1898
	frw: BOOLEAN;
1899
BEGIN
1899
BEGIN
1900
	getSelect(text, selBeg, selEnd);
1900
	getSelect(text, selBeg, selEnd);
1901
	IF ((selBeg.Y > 0) & ~down OR (selEnd.Y < text.count - 1) & down) THEN
1901
	IF ((selBeg.Y > 0) & ~down OR (selEnd.Y < text.count - 1) & down) THEN
1902
		modify(text);
1902
		modify(text);
1903
		step := ORD(down)*2 - 1;
1903
		step := ORD(down)*2 - 1;
1904
		IF selBeg.Y # selEnd.Y THEN
1904
		IF selBeg.Y # selEnd.Y THEN
1905
			frw := (text.cursor.X = selEnd.X) & (text.cursor.Y = selEnd.Y);
1905
			frw := (text.cursor.X = selEnd.X) & (text.cursor.Y = selEnd.Y);
1906
 
1906
 
1907
			IF down # frw THEN
1907
			IF down # frw THEN
1908
				temp := text.cursor^;
1908
				temp := text.cursor^;
1909
				SetPos(text, 0, text.select.Y);
1909
				SetPos(text, 0, text.select.Y);
1910
				setSelect(text);
1910
				setSelect(text);
1911
				text.select^ := temp
1911
				text.select^ := temp
1912
			END;
1912
			END;
1913
 
1913
 
1914
			ASSERT(selBeg.Y < selEnd.Y);
1914
			ASSERT(selBeg.Y < selEnd.Y);
1915
 
1915
 
1916
			first := getLine(text, selBeg.Y);
1916
			first := getLine(text, selBeg.Y);
1917
			last := getLine(text, selEnd.Y);
1917
			last := getLine(text, selEnd.Y);
1918
 
1918
 
1919
			line := first;
1919
			line := first;
1920
			Lines.modify(line);
1920
			Lines.modify(line);
1921
			REPEAT
1921
			REPEAT
1922
				NextLine(line);
1922
				NextLine(line);
1923
				Lines.modify(line)
1923
				Lines.modify(line)
1924
			UNTIL line = last;
1924
			UNTIL line = last;
1925
 
1925
 
1926
			IF down THEN
1926
			IF down THEN
1927
				text.curLine := last.prev(tLine)
1927
				text.curLine := last.prev(tLine)
1928
			ELSE
1928
			ELSE
1929
				text.curLine := first.next(tLine)
1929
				text.curLine := first.next(tLine)
1930
			END;
1930
			END;
1931
			selBeg.X := 0;
1931
			selBeg.X := 0;
1932
			selEnd.X := last.length;
1932
			selEnd.X := last.length;
1933
			IF down THEN
1933
			IF down THEN
1934
				last := last.next(tLine);
1934
				last := last.next(tLine);
1935
				List._delete(text, last);
1935
				List._delete(text, last);
1936
				List._insert(text, first.prev, last)
1936
				List._insert(text, first.prev, last)
1937
			ELSE
1937
			ELSE
1938
				first := first.prev(tLine);
1938
				first := first.prev(tLine);
1939
				List._delete(text, first);
1939
				List._delete(text, first);
1940
				List._insert(text, last, first)
1940
				List._insert(text, last, first)
1941
			END;
1941
			END;
1942
			IF down THEN
1942
			IF down THEN
1943
				temp := selBeg;
1943
				temp := selBeg;
1944
				selBeg := selEnd;
1944
				selBeg := selEnd;
1945
				selEnd := temp;
1945
				selEnd := temp;
1946
			END;
1946
			END;
1947
			SetPos(text, selBeg.X, selBeg.Y + step);
1947
			SetPos(text, selBeg.X, selBeg.Y + step);
1948
			setSelect(text);
1948
			setSelect(text);
1949
			text.select.X := selEnd.X;
1949
			text.select.X := selEnd.X;
1950
			text.select.Y := selEnd.Y + step
1950
			text.select.Y := selEnd.Y + step
1951
		ELSE
1951
		ELSE
1952
			first := getLine(text, selBeg.Y);
1952
			first := getLine(text, selBeg.Y);
1953
			Lines.modify(first);
1953
			Lines.modify(first);
1954
			IF down THEN
1954
			IF down THEN
1955
				last := first.next(tLine)
1955
				last := first.next(tLine)
1956
			ELSE
1956
			ELSE
1957
				last := first.prev.prev(tLine)
1957
				last := first.prev.prev(tLine)
1958
			END;
1958
			END;
1959
			List._delete(text, first);
1959
			List._delete(text, first);
1960
			List._insert(text, last, first);
1960
			List._insert(text, last, first);
1961
			INC(text.cursor.Y, step);
1961
			INC(text.cursor.Y, step);
1962
			INC(text.select.Y, step);
1962
			INC(text.select.Y, step);
1963
			SetPos(text, text.cursor.X, text.cursor.Y)
1963
			SetPos(text, text.cursor.X, text.cursor.Y)
1964
		END
1964
		END
1965
	END
1965
	END
1966
END MoveLines;
1966
END MoveLines;
1967
 
1967
 
1968
 
1968
 
1969
PROCEDURE isWordChar (c: WCHAR): BOOLEAN;
1969
PROCEDURE isWordChar (c: WCHAR): BOOLEAN;
1970
    RETURN U.isLetter(c) OR U.isDigit(c) OR (c = "_")
1970
    RETURN U.isLetter(c) OR U.isDigit(c) OR (c = "_")
1971
END isWordChar;
1971
END isWordChar;
1972
 
1972
 
1973
 
1973
 
1974
PROCEDURE getSelectedText* (text: tText; VAR s: ARRAY OF WCHAR);
1974
PROCEDURE getSelectedText* (text: tText; VAR s: ARRAY OF WCHAR);
1975
VAR
1975
VAR
1976
    n: INTEGER;
1976
    n: INTEGER;
1977
    selBeg, selEnd: tPoint;
1977
    selBeg, selEnd: tPoint;
1978
BEGIN
1978
BEGIN
1979
	s[0] := 0X;
1979
	s[0] := 0X;
1980
    IF selected(text) & (text.cursor.Y = text.select.Y) THEN
1980
    IF selected(text) & (text.cursor.Y = text.select.Y) THEN
1981
        getSelect(text, selBeg, selEnd);
1981
        getSelect(text, selBeg, selEnd);
1982
        n := getString(text.curLine, selBeg.X, selEnd.X - selBeg.X, s)
1982
        n := getString(text.curLine, selBeg.X, selEnd.X - selBeg.X, s)
1983
    END
1983
    END
1984
END getSelectedText;
1984
END getSelectedText;
1985
 
1985
 
1986
 
1986
 
1987
PROCEDURE wordSel* (text: tText);
1987
PROCEDURE wordSel* (text: tText);
1988
VAR
1988
VAR
1989
    n, i, x1, x2: INTEGER;
1989
    n, i, x1, x2: INTEGER;
1990
    selBeg, selEnd: tPoint;
1990
    selBeg, selEnd: tPoint;
1991
    str: tString;
1991
    str: tString;
1992
    curLine: tLine;
1992
    curLine: tLine;
1993
BEGIN
1993
BEGIN
1994
    curLine := text.curLine;
1994
    curLine := text.curLine;
1995
    IF selected(text) & (text.cursor.Y = text.select.Y) THEN
1995
    IF selected(text) & (text.cursor.Y = text.select.Y) THEN
1996
        getSelect(text, selBeg, selEnd);
1996
        getSelect(text, selBeg, selEnd);
1997
        x1 := selBeg.X;
1997
        x1 := selBeg.X;
1998
        x2 := selEnd.X;
1998
        x2 := selEnd.X;
1999
        n := getString(curLine, x1, x2 - x1, str);
1999
        n := getString(curLine, x1, x2 - x1, str);
2000
    ELSE
2000
    ELSE
2001
        str := ""
2001
        str := ""
2002
    END;
2002
    END;
2003
    IF str # "" THEN
2003
    IF str # "" THEN
2004
        i := 0;
2004
        i := 0;
2005
        WHILE (i < n) & isWordChar(str[i]) DO
2005
        WHILE (i < n) & isWordChar(str[i]) DO
2006
            INC(i)
2006
            INC(i)
2007
        END;
2007
        END;
2008
        IF (i # n) OR
2008
        IF (i # n) OR
2009
            ((x1 > 0) & isWordChar(Lines.getChar(curLine, x1 - 1))) OR
2009
            ((x1 > 0) & isWordChar(Lines.getChar(curLine, x1 - 1))) OR
2010
            ((x2 < curLine.length) & isWordChar(Lines.getChar(curLine, x2))) THEN
2010
            ((x2 < curLine.length) & isWordChar(Lines.getChar(curLine, x2))) THEN
2011
            str := ""
2011
            str := ""
2012
        END
2012
        END
2013
    END;
2013
    END;
2014
    IF text.searchText # str THEN
2014
    IF text.searchText # str THEN
2015
    	text.smallMove := FALSE
2015
    	text.smallMove := FALSE
2016
    END;
2016
    END;
2017
    IF search(text, str, Lang.isCS(text.lang), TRUE) THEN END
2017
    IF search(text, str, Lang.isCS(text.lang), TRUE) THEN END
2018
END wordSel;
2018
END wordSel;
2019
 
2019
 
2020
 
2020
 
2021
PROCEDURE getWordPos (line: tLine; pos: INTEGER): INTEGER;
2021
PROCEDURE getWordPos (line: tLine; pos: INTEGER): INTEGER;
2022
VAR
2022
VAR
2023
	c: WCHAR;
2023
	c: WCHAR;
2024
BEGIN
2024
BEGIN
2025
	c := Lines.getChar(line, pos);
2025
	c := Lines.getChar(line, pos);
2026
	IF isWordChar(c) THEN
2026
	IF isWordChar(c) THEN
2027
		WHILE (pos < line.length) & isWordChar(Lines.getChar(line, pos)) DO
2027
		WHILE (pos < line.length) & isWordChar(Lines.getChar(line, pos)) DO
2028
			INC(pos)
2028
			INC(pos)
2029
		END
2029
		END
2030
	ELSIF Lines.isSpace(c) THEN
2030
	ELSIF Lines.isSpace(c) THEN
2031
		WHILE (pos < line.length) & Lines.isSpace(Lines.getChar(line, pos)) DO
2031
		WHILE (pos < line.length) & Lines.isSpace(Lines.getChar(line, pos)) DO
2032
			INC(pos)
2032
			INC(pos)
2033
		END
2033
		END
2034
	ELSE
2034
	ELSE
2035
		WHILE (pos < line.length) & ~Lines.isSpace(Lines.getChar(line, pos)) & ~isWordChar(Lines.getChar(line, pos)) DO
2035
		WHILE (pos < line.length) & ~Lines.isSpace(Lines.getChar(line, pos)) & ~isWordChar(Lines.getChar(line, pos)) DO
2036
			INC(pos)
2036
			INC(pos)
2037
		END
2037
		END
2038
	END
2038
	END
2039
	RETURN pos
2039
	RETURN pos
2040
END getWordPos;
2040
END getWordPos;
2041
 
2041
 
2042
 
2042
 
2043
PROCEDURE key* (text: tText; code: INTEGER; shift, ctrl: BOOLEAN);
2043
PROCEDURE key* (text: tText; code: INTEGER; shift, ctrl: BOOLEAN);
2044
VAR
2044
VAR
2045
	n, wPos: INTEGER;
2045
	n, wPos: INTEGER;
2046
	scrX, scrY: INTEGER;
2046
	scrX, scrY: INTEGER;
2047
	resSel: BOOLEAN;
2047
	resSel: BOOLEAN;
2048
BEGIN
2048
BEGIN
2049
	resSel := FALSE;
2049
	resSel := FALSE;
2050
    IF shift THEN
2050
    IF shift THEN
2051
        setSelect(text)
2051
        setSelect(text)
2052
    ELSE
2052
    ELSE
2053
        IF (33 <= code) & (code <= 40) THEN
2053
        IF (33 <= code) & (code <= 40) THEN
2054
        	IF ~(((code = 38) OR (code = 40)) & ctrl) THEN
2054
        	IF ~(((code = 38) OR (code = 40)) & ctrl) THEN
2055
        		resSel := selected(text);
2055
        		resSel := selected(text);
2056
	            resetSelect(text)
2056
	            resetSelect(text)
2057
            END
2057
            END
2058
        END
2058
        END
2059
    END;
2059
    END;
2060
 
2060
 
2061
    CASE code OF
2061
    CASE code OF
2062
    |33:
2062
    |33:
2063
        IF ctrl THEN
2063
        IF ctrl THEN
2064
            UpDown(text, text.scroll.Y - text.cursor.Y)
2064
            UpDown(text, text.scroll.Y - text.cursor.Y)
2065
        ELSE
2065
        ELSE
2066
            text.scroll.Y := MAX(text.scroll.Y - textsize.Y, 0);
2066
            text.scroll.Y := MAX(text.scroll.Y - textsize.Y, 0);
2067
            UpDown(text, -textsize.Y)
2067
            UpDown(text, -textsize.Y)
2068
        END
2068
        END
2069
    |34:
2069
    |34:
2070
        IF ctrl THEN
2070
        IF ctrl THEN
2071
            UpDown(text, MIN(text.scroll.Y + textsize.Y - 1, text.count - 1) - text.cursor.Y)
2071
            UpDown(text, MIN(text.scroll.Y + textsize.Y - 1, text.count - 1) - text.cursor.Y)
2072
        ELSE
2072
        ELSE
2073
            text.scroll.Y := MIN(text.scroll.Y + textsize.Y, text.count - 1);
2073
            text.scroll.Y := MIN(text.scroll.Y + textsize.Y, text.count - 1);
2074
            UpDown(text, textsize.Y)
2074
            UpDown(text, textsize.Y)
2075
        END
2075
        END
2076
    |35:
2076
    |35:
2077
        IF ctrl THEN
2077
        IF ctrl THEN
2078
            SetPos(text, text.last(tLine).length, text.count - 1)
2078
            SetPos(text, text.last(tLine).length, text.count - 1)
2079
        ELSE
2079
        ELSE
2080
            SetPos(text, text.curLine.length, text.cursor.Y)
2080
            SetPos(text, text.curLine.length, text.cursor.Y)
2081
        END
2081
        END
2082
    |36:
2082
    |36:
2083
        IF ctrl THEN
2083
        IF ctrl THEN
2084
            SetPos(text, 0, 0)
2084
            SetPos(text, 0, 0)
2085
        ELSE
2085
        ELSE
2086
        	n := leadingSpaces(text.curLine);
2086
        	n := leadingSpaces(text.curLine);
2087
        	IF text.cursor.X <= n THEN
2087
        	IF text.cursor.X <= n THEN
2088
	            n := 0
2088
	            n := 0
2089
        	END;
2089
        	END;
2090
        	SetPos(text, n, text.cursor.Y)
2090
        	SetPos(text, n, text.cursor.Y)
2091
        END
2091
        END
2092
    |37:
2092
    |37:
2093
        IF (text.cursor.X = 0) & (text.curLine.prev # NIL) THEN
2093
        IF (text.cursor.X = 0) & (text.curLine.prev # NIL) THEN
2094
            SetPos(text, text.curLine.prev(tLine).length, text.cursor.Y - 1)
2094
            SetPos(text, text.curLine.prev(tLine).length, text.cursor.Y - 1)
2095
        ELSE
2095
        ELSE
2096
        	scrX := text.scroll.X;
2096
        	scrX := text.scroll.X;
2097
        	scrY := text.scroll.Y;
2097
        	scrY := text.scroll.Y;
2098
        	IF ctrl THEN
2098
        	IF ctrl THEN
2099
        		wPos := 0;
2099
        		wPos := 0;
2100
        		REPEAT
2100
        		REPEAT
2101
        			n := wPos;
2101
        			n := wPos;
2102
        			wPos := getWordPos(text.curLine, wPos)
2102
        			wPos := getWordPos(text.curLine, wPos)
2103
        		UNTIL wPos >= text.cursor.X;
2103
        		UNTIL wPos >= text.cursor.X;
2104
				move(text, n - text.cursor.X)
2104
				move(text, n - text.cursor.X)
2105
        	ELSE
2105
        	ELSE
2106
            	move(text, -1)
2106
            	move(text, -1)
2107
            END;
2107
            END;
2108
            text.smallMove := (scrX = text.scroll.X) & (scrY = text.scroll.Y) & ~resSel
2108
            text.smallMove := (scrX = text.scroll.X) & (scrY = text.scroll.Y) & ~resSel
2109
        END
2109
        END
2110
    |38:
2110
    |38:
2111
        IF ctrl THEN
2111
        IF ctrl THEN
2112
            MoveLines(text, FALSE)
2112
            MoveLines(text, FALSE)
2113
        ELSE
2113
        ELSE
2114
            UpDown(text, -1)
2114
            UpDown(text, -1)
2115
        END
2115
        END
2116
    |39:
2116
    |39:
2117
        IF (text.cursor.X = text.curLine.length) & (text.curLine.next # NIL) THEN
2117
        IF (text.cursor.X = text.curLine.length) & (text.curLine.next # NIL) THEN
2118
            SetPos(text, 0, text.cursor.Y + 1)
2118
            SetPos(text, 0, text.cursor.Y + 1)
2119
        ELSE
2119
        ELSE
2120
        	scrX := text.scroll.X;
2120
        	scrX := text.scroll.X;
2121
        	scrY := text.scroll.Y;
2121
        	scrY := text.scroll.Y;
2122
        	IF ctrl THEN
2122
        	IF ctrl THEN
2123
				move(text, getWordPos(text.curLine, text.cursor.X) - text.cursor.X)
2123
				move(text, getWordPos(text.curLine, text.cursor.X) - text.cursor.X)
2124
        	ELSE
2124
        	ELSE
2125
            	move(text, 1)
2125
            	move(text, 1)
2126
        	END;
2126
        	END;
2127
        	text.smallMove := (scrX = text.scroll.X) & (scrY = text.scroll.Y) & ~resSel
2127
        	text.smallMove := (scrX = text.scroll.X) & (scrY = text.scroll.Y) & ~resSel
2128
        END
2128
        END
2129
    |40:
2129
    |40:
2130
        IF ctrl THEN
2130
        IF ctrl THEN
2131
            MoveLines(text, TRUE)
2131
            MoveLines(text, TRUE)
2132
        ELSE
2132
        ELSE
2133
            UpDown(text, 1)
2133
            UpDown(text, 1)
2134
        END
2134
        END
2135
    |46:
2135
    |46:
2136
        IF ctrl THEN
2136
        IF ctrl THEN
2137
            delLine(text)
2137
            delLine(text)
2138
        ELSE
2138
        ELSE
2139
        	IF ~selected(text) & (text.cursor.X < text.curLine.length) THEN
2139
        	IF ~selected(text) & (text.cursor.X < text.curLine.length) THEN
2140
        		INC(text.smallChange)
2140
        		INC(text.smallChange)
2141
        	END;
2141
        	END;
2142
            delete(text);
2142
            delete(text);
2143
            ShowCursor
2143
            ShowCursor
2144
        END
2144
        END
2145
    |ORD("C"), ORD("X"):
2145
    |ORD("C"), ORD("X"):
2146
        IF ctrl THEN
2146
        IF ctrl THEN
2147
            IF selected(text) THEN
2147
            IF selected(text) THEN
2148
                copy(text);
2148
                copy(text);
2149
                IF code = ORD("X") THEN
2149
                IF code = ORD("X") THEN
2150
                	delSelect(text)
2150
                	delSelect(text)
2151
                END
2151
                END
2152
            END
2152
            END
2153
        END
2153
        END
2154
    |ORD("V"):
2154
    |ORD("V"):
2155
        IF ctrl THEN
2155
        IF ctrl THEN
2156
            IF CB.available() THEN
2156
            IF CB.available() THEN
2157
                paste(text)
2157
                paste(text)
2158
            END
2158
            END
2159
        END
2159
        END
2160
    |ORD("A"):
2160
    |ORD("A"):
2161
        IF ctrl THEN
2161
        IF ctrl THEN
2162
            text.select2.X := 0;
2162
            text.select2.X := 0;
2163
            text.select2.Y := 0;
2163
            text.select2.Y := 0;
2164
            text.select := text.select2;
2164
            text.select := text.select2;
2165
            SetPos(text, text.last(tLine).length, text.count - 1)
2165
            SetPos(text, text.last(tLine).length, text.count - 1)
2166
        END
2166
        END
2167
    |ORD("L"), ORD("U"):
2167
    |ORD("L"), ORD("U"):
2168
        IF ctrl THEN
2168
        IF ctrl THEN
2169
        	IF selected(text) THEN
2169
        	IF selected(text) THEN
2170
            	chCase(text, code = ORD("U"))
2170
            	chCase(text, code = ORD("U"))
2171
            ELSE
2171
            ELSE
2172
            	changeCase(text, code = ORD("U"))
2172
            	changeCase(text, code = ORD("U"))
2173
            END;
2173
            END;
2174
            ShowCursor
2174
            ShowCursor
2175
        END
2175
        END
2176
    |ORD("D"):
2176
    |ORD("D"):
2177
        IF ctrl THEN
2177
        IF ctrl THEN
2178
            dupLine(text)
2178
            dupLine(text)
2179
        END
2179
        END
2180
    ELSE
2180
    ELSE
2181
    END
2181
    END
2182
END key;
2182
END key;
2183
 
2183
 
2184
 
2184
 
2185
PROCEDURE mouse* (text: tText; x, y: INTEGER);
2185
PROCEDURE mouse* (text: tText; x, y: INTEGER);
2186
VAR
2186
VAR
2187
    cursorX: INTEGER;
2187
    cursorX: INTEGER;
2188
BEGIN
2188
BEGIN
2189
    DEC(x, padding.left);
2189
    DEC(x, padding.left);
2190
    DEC(y, padding.top);
2190
    DEC(y, padding.top);
2191
    cursorX := (x*2) DIV charWidth;
2191
    cursorX := (x*2) DIV charWidth;
2192
    SetPos(text, cursorX DIV 2 + cursorX MOD 2 + text.scroll.X, y DIV charHeight + text.scroll.Y)
2192
    SetPos(text, cursorX DIV 2 + cursorX MOD 2 + text.scroll.X, y DIV charHeight + text.scroll.Y)
2193
END mouse;
2193
END mouse;
2194
 
2194
 
2195
 
2195
 
2196
PROCEDURE selectWord* (text: tText);
2196
PROCEDURE selectWord* (text: tText);
2197
VAR
2197
VAR
2198
    cursorX, x1, x2: INTEGER;
2198
    cursorX, x1, x2: INTEGER;
2199
    line: tLine;
2199
    line: tLine;
2200
BEGIN
2200
BEGIN
2201
    resetSelect(text);
2201
    resetSelect(text);
2202
    cursorX := text.cursor.X;
2202
    cursorX := text.cursor.X;
2203
    line := text.curLine;
2203
    line := text.curLine;
2204
    x1 := cursorX - 1;
2204
    x1 := cursorX - 1;
2205
    IF (cursorX < line.length) & isWordChar(Lines.getChar(line, cursorX)) THEN
2205
    IF (cursorX < line.length) & isWordChar(Lines.getChar(line, cursorX)) THEN
2206
        x2 := cursorX;
2206
        x2 := cursorX;
2207
        WHILE (x2 < line.length) & isWordChar(Lines.getChar(line, x2)) DO
2207
        WHILE (x2 < line.length) & isWordChar(Lines.getChar(line, x2)) DO
2208
            INC(x2)
2208
            INC(x2)
2209
        END
2209
        END
2210
    ELSE
2210
    ELSE
2211
        WHILE (x1 >= 0) & ~isWordChar(Lines.getChar(line, x1)) DO
2211
        WHILE (x1 >= 0) & ~isWordChar(Lines.getChar(line, x1)) DO
2212
            DEC(x1)
2212
            DEC(x1)
2213
        END;
2213
        END;
2214
        x2 := x1 + 1
2214
        x2 := x1 + 1
2215
    END;
2215
    END;
2216
    WHILE (x1 >= 0) & isWordChar(Lines.getChar(line, x1)) DO
2216
    WHILE (x1 >= 0) & isWordChar(Lines.getChar(line, x1)) DO
2217
        DEC(x1)
2217
        DEC(x1)
2218
    END;
2218
    END;
2219
    INC(x1);
2219
    INC(x1);
2220
    IF x1 < x2 THEN
2220
    IF x1 < x2 THEN
2221
        SetPos(text, x1, text.cursor.Y);
2221
        SetPos(text, x1, text.cursor.Y);
2222
        setSelect(text);
2222
        setSelect(text);
2223
        SetPos(text, x2, text.cursor.Y)
2223
        SetPos(text, x2, text.cursor.Y)
2224
    END
2224
    END
2225
END selectWord;
2225
END selectWord;
2226
 
2226
 
2227
 
2227
 
2228
PROCEDURE cursor* (text: tText);
2228
PROCEDURE cursor* (text: tText);
2229
VAR
2229
VAR
2230
    x, y1, y2, scrollX, scrollY: INTEGER;
2230
    x, y1, y2, scrollX, scrollY: INTEGER;
2231
    cursor: pPoint;
2231
    cursor: pPoint;
2232
BEGIN
2232
BEGIN
2233
	IF drawCursor THEN
2233
	IF drawCursor THEN
2234
	    cursor := text.cursor;
2234
	    cursor := text.cursor;
2235
	    scrollX := text.scroll.X;
2235
	    scrollX := text.scroll.X;
2236
	    scrollY := text.scroll.Y;
2236
	    scrollY := text.scroll.Y;
2237
	    IF ~((scrollY > cursor.Y) OR (scrollY + textsize.Y <= cursor.Y) OR
2237
	    IF ~((scrollY > cursor.Y) OR (scrollY + textsize.Y + 1 <= cursor.Y) OR
2238
	       (scrollX > cursor.X) OR (scrollX + textsize.X <= cursor.X)) THEN
2238
	       (scrollX > cursor.X) OR (scrollX + textsize.X <= cursor.X)) THEN
2239
	        x := (cursor.X - scrollX)*charWidth + padding.left;
2239
	        x := (cursor.X - scrollX)*charWidth + padding.left;
2240
	        y1 := (cursor.Y - scrollY)*charHeight + padding.top + (inter DIV 2 + 1);
2240
	        y1 := (cursor.Y - scrollY)*charHeight + padding.top + (inter DIV 2 + 1);
2241
	        y2 := y1 + charHeight - (inter + 2);
2241
	        y2 := y1 + charHeight - (inter + 2);
2242
	        G.notVLine(canvas, x, y1, y2);
2242
	        G.notVLine(canvas, x, y1, y2);
2243
	        G.notVLine(canvas, x - 1, y1, y2)
2243
	        G.notVLine(canvas, x - 1, y1, y2)
2244
	    END
2244
	    END
2245
    END
2245
    END
2246
END cursor;
2246
END cursor;
2247
 
2247
 
2248
 
2248
 
2249
PROCEDURE drawSelect (text: tText; line: tLine; selBeg, selEnd, y: INTEGER);
2249
PROCEDURE drawSelect (text: tText; line: tLine; selBeg, selEnd, y: INTEGER);
2250
VAR
2250
VAR
2251
    Len, pos, x, firstCharIdx: INTEGER;
2251
    Len, pos, x, firstCharIdx: INTEGER;
2252
BEGIN
2252
BEGIN
2253
    firstCharIdx := MAX(text.scroll.X, selBeg);
2253
    firstCharIdx := MAX(text.scroll.X, selBeg);
2254
    Len := MAX(MIN(line.length - firstCharIdx, selEnd - firstCharIdx), 0);
2254
    Len := MAX(MIN(line.length - firstCharIdx, selEnd - firstCharIdx), 0);
2255
    Len := MIN(Len, textsize.X - pos + 1);
2255
    Len := MIN(Len, textsize.X - pos + 1);
2256
    SetColor(colors.seltext, colors.selback);
2256
    SetColor(colors.seltext, colors.selback);
2257
    pos := MAX((selBeg - text.scroll.X), 0);
2257
    pos := MAX((selBeg - text.scroll.X), 0);
2258
    x := pos*charWidth + padding.left;
2258
    x := pos*charWidth + padding.left;
2259
    G.SetColor(canvas, colors.selback);
2259
    G.SetColor(canvas, colors.selback);
2260
    G.FillRect(canvas, x - 1, y - inter DIV 2, x + Len*charWidth, y - inter DIV 2 + charHeight);
2260
    G.FillRect(canvas, x - 1, y - inter DIV 2, x + Len*charWidth, y - inter DIV 2 + charHeight);
2261
    G.TextOut(canvas, pos*charWidth + padding.left, y, Lines.getPChar(line, firstCharIdx), Len, colors.seltext)
2261
    G.TextOut(canvas, pos*charWidth + padding.left, y, Lines.getPChar(line, firstCharIdx), Len, colors.seltext)
2262
END drawSelect;
2262
END drawSelect;
2263
 
2263
 
2264
 
2264
 
2265
PROCEDURE mark (line: tLine; y: INTEGER);
2265
PROCEDURE mark (line: tLine; y: INTEGER);
2266
VAR
2266
VAR
2267
    color, i: INTEGER;
2267
    color, i: INTEGER;
2268
BEGIN
2268
BEGIN
2269
    IF line.modified THEN
2269
    IF line.modified THEN
2270
        color := colors.modified
2270
        color := colors.modified
2271
    ELSIF line.saved THEN
2271
    ELSIF line.saved THEN
2272
        color := colors.saved
2272
        color := colors.saved
2273
    ELSE
2273
    ELSE
2274
        color := colors.back
2274
        color := colors.back
2275
    END;
2275
    END;
2276
    G.SetColor(canvas, color);
2276
    G.SetColor(canvas, color);
2277
 
2277
 
2278
    FOR i := 3 TO mark_width + 2 DO
2278
    FOR i := 3 TO mark_width + 2 DO
2279
        G.VLine(canvas, padding.left - i, y, y + charHeight)
2279
        G.VLine(canvas, padding.left - i, y, y + charHeight)
2280
    END
2280
    END
2281
END mark;
2281
END mark;
2282
 
2282
 
2283
 
2283
 
2284
PROCEDURE setPadding (left, top: INTEGER);
2284
PROCEDURE setPadding (left, top: INTEGER);
2285
BEGIN
2285
BEGIN
2286
    padding.left := left;
2286
    padding.left := left;
2287
    padding.top := top;
2287
    padding.top := top;
2288
    textsize.X := (size.X - padding.left) DIV charWidth;
2288
    textsize.X := (size.X - padding.left) DIV charWidth;
2289
    textsize.Y := (size.Y - padding.top) DIV charHeight;
2289
    textsize.Y := (size.Y - padding.top) DIV charHeight;
2290
END setPadding;
2290
END setPadding;
2291
 
2291
 
2292
 
2292
 
2293
PROCEDURE draw* (text: tText);
2293
PROCEDURE draw* (text: tText);
2294
VAR
2294
VAR
2295
    y, n, cnt, i, x: INTEGER;
2295
    y, n, cnt, i, x: INTEGER;
2296
    line, firstLine, lastLine: tLine;
2296
    line, firstLine, lastLine: tLine;
2297
    selBeg, selEnd: tPoint;
2297
    selBeg, selEnd: tPoint;
2298
    s: ARRAY 12 OF WCHAR;
2298
    s: ARRAY 12 OF WCHAR;
2299
    backColor, numWidth, xNum, wNum: INTEGER;
2299
    backColor, numWidth, xNum, wNum: INTEGER;
2300
    p: Search.tPos;
2300
    p: Search.tPos;
2301
    guard: tGuard;
2301
    guard: tGuard;
2302
BEGIN
2302
BEGIN
2303
    IF text.comments THEN
2303
    IF text.comments THEN
2304
        Comments(text)
2304
        Comments(text)
2305
    END;
2305
    END;
2306
    IF text.search & search(text, text.searchText, text.cs, text.whole) THEN END;
2306
    IF text.search & search(text, text.searchText, text.cs, text.whole) THEN END;
2307
    IF text.guard THEN
2307
    IF text.guard THEN
2308
        NEW(guard);
2308
        NEW(guard);
2309
        List.append(ChangeLog.CL.Log, guard);
2309
        List.append(ChangeLog.CL.Log, guard);
2310
        guard.saved := ChangeLog.isFirstGuard(guard);
2310
        guard.saved := ChangeLog.isFirstGuard(guard);
2311
        text.edition := guard;
2311
        text.edition := guard;
2312
        text.guard := FALSE
2312
        text.guard := FALSE
2313
    ELSE
2313
    ELSE
2314
        guard := text.edition
2314
        guard := text.edition
2315
    END;
2315
    END;
2316
 
2316
 
2317
    guard.cursor := text.cursor^;
2317
    guard.cursor := text.cursor^;
2318
    guard.select2 := text.select2^;
2318
    guard.select2 := text.select2^;
2319
    guard.scroll := text.scroll;
2319
    guard.scroll := text.scroll;
2320
    guard.CurX := text.CurX;
2320
    guard.CurX := text.CurX;
2321
    guard.selected := text.select = text.select2;
2321
    guard.selected := text.select = text.select2;
2322
 
2322
 
2323
    G.SetColor(canvas, colors.back);
2323
    G.SetColor(canvas, colors.back);
2324
    IF ~text.smallMove THEN
2324
    IF ~text.smallMove THEN
2325
    	G.clear(canvas)
2325
    	G.clear(canvas)
2326
    END;
2326
    END;
2327
    wNum := charWidth;
2327
    wNum := charWidth;
2328
    IF lineNumbers THEN
2328
    IF lineNumbers THEN
2329
        numWidth := U.lg10(text.count) + 2;
2329
        numWidth := U.lg10(text.count) + 2;
2330
        xNum := numWidth*wNum - wNum DIV 2;
2330
        xNum := numWidth*wNum - wNum DIV 2;
2331
        setPadding(numWidth*wNum + pad_left, padding.top);
2331
        setPadding(numWidth*wNum + pad_left, padding.top);
2332
    ELSE
2332
    ELSE
2333
        setPadding(pad_left + wNum*2, padding.top)
2333
        setPadding(pad_left + wNum*2, padding.top)
2334
    END;
2334
    END;
2335
    getSelect(text, selBeg, selEnd);
2335
    getSelect(text, selBeg, selEnd);
2336
    y := padding.top + inter DIV 2;
2336
    y := padding.top + inter DIV 2;
2337
    n := text.scroll.Y;
2337
    n := text.scroll.Y;
2338
    firstLine := getLine2(text, n);
2338
    firstLine := getLine2(text, n);
-
 
2339
 
2339
    IF text.smallMove THEN
2340
    IF text.smallMove THEN
2340
    	line := text.curLine;
2341
    	line := text.curLine;
2341
    	cnt := textsize.Y - 1;
2342
    	cnt := textsize.Y;
2342
    	y := y + charHeight*(text.cursor.Y - text.scroll.Y);
2343
    	y := y + charHeight*(text.cursor.Y - text.scroll.Y);
2343
    	G.SetColor(canvas, colors.back);
2344
    	G.SetColor(canvas, colors.back);
2344
    	G.FillRect(canvas, padding.left - 2, y - inter DIV 2, size.X - 1, y - inter DIV 2 + charHeight);
2345
    	G.FillRect(canvas, padding.left - 2, y - inter DIV 2, size.X - 1, y - inter DIV 2 + charHeight);
2345
    	n := text.cursor.Y
2346
    	n := text.cursor.Y
2346
    ELSE
2347
    ELSE
2347
	    line := firstLine;
2348
	    line := firstLine;
2348
    	cnt := 0
2349
    	cnt := 0
2349
    END;
2350
    END;
2350
 
2351
 
2351
    WHILE (line # NIL) & (cnt < textsize.Y) DO
2352
    WHILE (line # NIL) & (cnt <= textsize.Y) DO
2352
        backColor := colors.back;
2353
        backColor := colors.back;
2353
        IF (line = text.curLine) & ~selected(text) THEN
2354
        IF (line = text.curLine) & ~selected(text) THEN
2354
            G.SetColor(canvas, colors.curline);
2355
            G.SetColor(canvas, colors.curline);
2355
            G.FillRect(canvas, padding.left - 2, y - inter DIV 2, size.X - 1, y - inter DIV 2 + charHeight);
2356
            G.FillRect(canvas, padding.left - 2, y - inter DIV 2, size.X - 1, y - inter DIV 2 + charHeight);
2356
            backColor := colors.curline
2357
            backColor := colors.curline
2357
        END;
2358
        END;
2358
        SetColor(colors.text, backColor);
2359
        SetColor(colors.text, backColor);
2359
		IF (selBeg.Y < n) & (n < selEnd.Y) THEN
2360
		IF (selBeg.Y < n) & (n < selEnd.Y) THEN
2360
			drawSelect(text, line, 0, line.length, y)
2361
			drawSelect(text, line, 0, line.length, y)
2361
		ELSE
2362
		ELSE
2362
			G.TextOut(canvas, padding.left, y, Lines.getPChar(line, text.scroll.X), MIN(MAX(line.length - text.scroll.X, 0), textsize.X + 1), colors.delim);
2363
			G.TextOut(canvas, padding.left, y, Lines.getPChar(line, text.scroll.X), MIN(MAX(line.length - text.scroll.X, 0), textsize.X + 1), colors.delim);
2363
			IF text.lang # Lang.langText THEN
2364
			IF text.lang # Lang.langText THEN
2364
				parse(text, line, y, backColor, text.lang)
2365
				parse(text, line, y, backColor, text.lang)
2365
			END
2366
			END
2366
		END;
2367
		END;
2367
		IF (selBeg.Y = n) & (selEnd.Y = n) & (selBeg.X # selEnd.X) THEN
2368
		IF (selBeg.Y = n) & (selEnd.Y = n) & (selBeg.X # selEnd.X) THEN
2368
            drawSelect(text, line, selBeg.X, selEnd.X, y)
2369
            drawSelect(text, line, selBeg.X, selEnd.X, y)
2369
        ELSIF (selBeg.Y = n) & (selEnd.Y # n) THEN
2370
        ELSIF (selBeg.Y = n) & (selEnd.Y # n) THEN
2370
            drawSelect(text, line, selBeg.X, line.length, y)
2371
            drawSelect(text, line, selBeg.X, line.length, y)
2371
        ELSIF (selBeg.Y # n) & (selEnd.Y = n) THEN
2372
        ELSIF (selBeg.Y # n) & (selEnd.Y = n) THEN
2372
            drawSelect(text, line, 0, selEnd.X, y)
2373
            drawSelect(text, line, 0, selEnd.X, y)
2373
        END;
2374
        END;
2374
        mark(line, y - inter DIV 2);
2375
        mark(line, y - inter DIV 2);
2375
        NextLine(line);
2376
        NextLine(line);
2376
        INC(y, charHeight);
2377
        INC(y, charHeight);
2377
        INC(n);
2378
        INC(n);
2378
        INC(cnt)
2379
        INC(cnt)
2379
    END;
2380
    END;
2380
 
2381
 
2381
    G.SetColor(canvas, colors.numback);
2382
    G.SetColor(canvas, colors.numback);
2382
    G.FillRect(canvas, 0, 0, padding.left - pad_left (*+ 1*), size.Y - 1);
2383
    G.FillRect(canvas, 0, 0, padding.left - pad_left (*+ 1*), size.Y - 1);
2383
    line := firstLine;
2384
    line := firstLine;
2384
    SetColor(colors.numtext, colors.numback);
2385
    SetColor(colors.numtext, colors.numback);
2385
    y := padding.top + inter DIV 2;
2386
    y := padding.top + inter DIV 2;
2386
    n := MIN(text.scroll.Y + textsize.Y, text.count);
2387
    n := MIN(text.scroll.Y + textsize.Y + 1, text.count);
2387
    FOR i := text.scroll.Y + 1 TO n DO
2388
    FOR i := text.scroll.Y + 1 TO n DO
2388
        IF lineNumbers THEN
2389
        IF lineNumbers THEN
2389
            IF (i MOD 10 = 0) OR (i - 1 = text.cursor.Y) OR line.label THEN
2390
            IF (i MOD 10 = 0) OR (i - 1 = text.cursor.Y) OR line.label THEN
2390
                U.int2str(i, s);
2391
                U.int2str(i, s);
2391
                G.TextOut2(canvas, (numWidth - U.lg10(i) - 1)*wNum - wNum DIV 2, y, s, LENGTH(s))
2392
                G.TextOut2(canvas, (numWidth - U.lg10(i) - 1)*wNum - wNum DIV 2, y, s, LENGTH(s))
2392
            ELSE
2393
            ELSE
2393
                G.SetColor(canvas, colors.numtext);
2394
                G.SetColor(canvas, colors.numtext);
2394
                G.HLine(canvas, y - inter DIV 2 + charHeight DIV 2, xNum - wNum DIV (1 + ORD(i MOD 5 # 0)), xNum)
2395
                G.HLine(canvas, y - inter DIV 2 + charHeight DIV 2, xNum - wNum DIV (1 + ORD(i MOD 5 # 0)), xNum)
2395
            END
2396
            END
2396
        END;
2397
        END;
2397
        IF line.label THEN
2398
        IF line.label THEN
2398
            FOR x := wNum DIV 2 TO (padding.left - pad_left) - wNum DIV 2 DO
2399
            FOR x := wNum DIV 2 TO (padding.left - pad_left) - wNum DIV 2 DO
2399
                G.notVLine(canvas, x, y, y + charHeight - inter);
2400
                G.notVLine(canvas, x, y, y + charHeight - (inter + 1));
2400
                G.xorVLine(canvas, x, y, y + charHeight - inter)
2401
                G.xorVLine(canvas, x, y, y + charHeight - (inter + 1))
2401
            END
2402
            END
2402
        END;
2403
        END;
2403
        NextLine(line);
2404
        NextLine(line);
2404
        INC(y, charHeight)
2405
        INC(y, charHeight)
2405
    END;
2406
    END;
2406
 
2407
 
2407
    IF text.searchText # "" THEN
2408
    IF text.searchText # "" THEN
2408
    	IF text.smallMove THEN
2409
    	IF text.smallMove THEN
2409
    		firstLine := text.curLine;
2410
    		firstLine := text.curLine;
2410
    		lastLine := firstLine
2411
    		lastLine := firstLine
2411
    	ELSE
2412
    	ELSE
2412
    	    lastLine := getLine2(text, MIN(text.scroll.Y + textsize.Y, text.count) - 1)
2413
    	    lastLine := getLine2(text, MIN(text.scroll.Y + textsize.Y + 1, text.count) - 1)
2413
        END;
2414
        END;
2414
        p := text.foundList.first(Search.tPos);
2415
        p := text.foundList.first(Search.tPos);
2415
        WHILE p # NIL DO
2416
        WHILE p # NIL DO
2416
        	y := padding.top + inter DIV 2;
2417
        	y := padding.top + inter DIV 2;
2417
        	IF text.smallMove THEN
2418
        	IF text.smallMove THEN
2418
        		y := y + charHeight*(text.cursor.Y - text.scroll.Y)
2419
        		y := y + charHeight*(text.cursor.Y - text.scroll.Y)
2419
            END;
2420
            END;
2420
            IF (firstLine.pos <= p.pos) & (p.pos <= lastLine.pos + lastLine.length) THEN
2421
            IF (firstLine.pos <= p.pos) & (p.pos <= lastLine.pos + lastLine.length) THEN
2421
                line := firstLine;
2422
                line := firstLine;
2422
                WHILE (line.pos <= p.pos) & (line # lastLine) DO
2423
                WHILE (line.pos <= p.pos) & (line # lastLine) DO
2423
                    NextLine(line);
2424
                    NextLine(line);
2424
                    INC(y, charHeight)
2425
                    INC(y, charHeight)
2425
                END;
2426
                END;
2426
                IF (line # lastLine) & (line # firstLine) OR (line = lastLine) & (line.pos > p.pos) THEN
2427
                IF (line # lastLine) & (line # firstLine) OR (line = lastLine) & (line.pos > p.pos) THEN
2427
                    PrevLine(line);
2428
                    PrevLine(line);
2428
                    DEC(y, charHeight)
2429
                    DEC(y, charHeight)
2429
                END;
2430
                END;
2430
                x := (p.pos - line.pos - text.scroll.X)*charWidth + padding.left;
2431
                x := (p.pos - line.pos - text.scroll.X)*charWidth + padding.left;
2431
                n := LENGTH(text.searchText)*charWidth;
2432
                n := LENGTH(text.searchText)*charWidth;
2432
                WHILE n > 0 DO
2433
                WHILE n > 0 DO
2433
                    IF x >= padding.left THEN
2434
                    IF x >= padding.left THEN
2434
                        G.notVLine(canvas, x, y, y + charHeight - inter)
2435
                        G.notVLine(canvas, x, y, y + charHeight - inter)
2435
                    END;
2436
                    END;
2436
                    INC(x);
2437
                    INC(x);
2437
                    DEC(n)
2438
                    DEC(n)
2438
                END
2439
                END
2439
            END;
2440
            END;
2440
            p := p.next(Search.tPos)
2441
            p := p.next(Search.tPos)
2441
        END
2442
        END
2442
    END;
2443
    END;
2443
 
2444
 
2444
    text.smallMove := FALSE;
2445
    text.smallMove := FALSE;
2445
 
2446
 
2446
    IF text.foundSel > 0 THEN
2447
    IF text.foundSel > 0 THEN
2447
        x := (text.cursor.X - text.scroll.X)*charWidth + padding.left;
2448
        x := (text.cursor.X - text.scroll.X)*charWidth + padding.left;
2448
        y := (text.cursor.Y - text.scroll.Y)*charHeight + padding.top + inter DIV 2;
2449
        y := (text.cursor.Y - text.scroll.Y)*charHeight + padding.top + inter DIV 2;
2449
        n := text.foundSel*charWidth;
2450
        n := text.foundSel*charWidth;
2450
        WHILE n > 0 DO
2451
        WHILE n > 0 DO
2451
            IF x >= padding.left THEN
2452
            IF x >= padding.left THEN
2452
                G.xorVLine(canvas, x, y, y + charHeight - inter)
2453
                G.xorVLine(canvas, x, y, y + charHeight - inter)
2453
            END;
2454
            END;
2454
            INC(x);
2455
            INC(x);
2455
            DEC(n)
2456
            DEC(n)
2456
        END
2457
        END
2457
    END;
2458
    END;
2458
	cursor(text)
2459
	cursor(text)
2459
END draw;
2460
END draw;
2460
 
2461
 
2461
 
2462
 
2462
PROCEDURE switch* (text: tText);
2463
PROCEDURE switch* (text: tText);
2463
BEGIN
2464
BEGIN
2464
    ChangeLog.set(text.chLog);
2465
    ChangeLog.set(text.chLog);
2465
    Lines.setMaxLength(text.maxLength);
2466
    Lines.setMaxLength(text.maxLength);
2466
    Lang.setCurLang(text.lang)
2467
    Lang.setCurLang(text.lang)
2467
END switch;
2468
END switch;
2468
 
2469
 
2469
 
2470
 
2470
PROCEDURE create (fileName: RW.tFileName): tText;
2471
PROCEDURE create (fileName: RW.tFileName): tText;
2471
VAR
2472
VAR
2472
    text: tText;
2473
    text: tText;
2473
BEGIN
2474
BEGIN
2474
    NEW(text);
2475
    NEW(text);
2475
    text.maxLength := 64;
2476
    text.maxLength := 64;
2476
    text.chLog := ChangeLog.create(text.maxLength);
2477
    text.chLog := ChangeLog.create(text.maxLength);
2477
    NEW(text.cursor);
2478
    NEW(text.cursor);
2478
    NEW(text.select2);
2479
    NEW(text.select2);
2479
    text.cursor.X := 0;
2480
    text.cursor.X := 0;
2480
    text.cursor.Y := 0;
2481
    text.cursor.Y := 0;
2481
    resetSelect(text);
2482
    resetSelect(text);
2482
    text.scroll.X := 0;
2483
    text.scroll.X := 0;
2483
    text.scroll.Y := 0;
2484
    text.scroll.Y := 0;
2484
    setPadding(padding.left, padding.top);
2485
    setPadding(padding.left, padding.top);
2485
    text.curLine := NIL;
2486
    text.curLine := NIL;
2486
    text.modified := FALSE;
2487
    text.modified := FALSE;
2487
    text.smallMove := FALSE;
2488
    text.smallMove := FALSE;
2488
    text.comments := TRUE;
2489
    text.comments := TRUE;
2489
    text.search := TRUE;
2490
    text.search := TRUE;
2490
    text.cs := FALSE;
2491
    text.cs := FALSE;
2491
    text.whole := FALSE;
2492
    text.whole := FALSE;
2492
    text.guard := TRUE;
2493
    text.guard := TRUE;
2493
    text.edition := NIL;
2494
    text.edition := NIL;
2494
    text.foundList := List.create(NIL);
2495
    text.foundList := List.create(NIL);
2495
    text.searchText := "";
2496
    text.searchText := "";
2496
    text.foundSel := 0;
2497
    text.foundSel := 0;
2497
    text.CurX := -1;
2498
    text.CurX := -1;
2498
    text.smallChange := 0;
2499
    text.smallChange := 0;
2499
    text.lang := Lang.langText;
2500
    text.lang := Lang.langText;
2500
    text.LinesVector := NIL;
2501
    text.LinesVector := NIL;
2501
    Lang.setCurLang(Lang.langText);
2502
    Lang.setCurLang(Lang.langText);
2502
    setName(text, fileName);
2503
    setName(text, fileName);
2503
    ASSERT(text = List.create(text))
2504
    ASSERT(text = List.create(text))
2504
    RETURN text
2505
    RETURN text
2505
END create;
2506
END create;
2506
 
2507
 
2507
 
2508
 
2508
PROCEDURE setColors* (text, back, seltext, selback, modified, saved, curline, numtext, numback,
2509
PROCEDURE setColors* (text, back, seltext, selback, modified, saved, curline, numtext, numback,
2509
                        comment, string, escape, num, delim, key1, key2, key3: INTEGER);
2510
                        comment, string, escape, num, delim, key1, key2, key3: INTEGER);
2510
BEGIN
2511
BEGIN
2511
    colors.text := text;
2512
    colors.text := text;
2512
    colors.back := back;
2513
    colors.back := back;
2513
    colors.seltext := seltext;
2514
    colors.seltext := seltext;
2514
    colors.selback := selback;
2515
    colors.selback := selback;
2515
    colors.modified := modified;
2516
    colors.modified := modified;
2516
    colors.saved := saved;
2517
    colors.saved := saved;
2517
    colors.curline := curline;
2518
    colors.curline := curline;
2518
    colors.numtext := numtext;
2519
    colors.numtext := numtext;
2519
    colors.numback := numback;
2520
    colors.numback := numback;
2520
    colors.comment := comment;
2521
    colors.comment := comment;
2521
    colors.string  := string;
2522
    colors.string  := string;
2522
    colors.escape  := escape;
2523
    colors.escape  := escape;
2523
    colors.num := num;
2524
    colors.num := num;
2524
    colors.delim := delim;
2525
    colors.delim := delim;
2525
    colors.key1 := key1;
2526
    colors.key1 := key1;
2526
    colors.key2 := key2;
2527
    colors.key2 := key2;
2527
    colors.key3 := key3;
2528
    colors.key3 := key3;
2528
END setColors;
2529
END setColors;
2529
 
2530
 
2530
 
2531
 
2531
PROCEDURE setCanvas* (_canvas: G.tCanvas);
2532
PROCEDURE setCanvas* (_canvas: G.tCanvas);
2532
BEGIN
2533
BEGIN
2533
    canvas := _canvas;
2534
    canvas := _canvas;
2534
    charWidth := _canvas.font.width;
2535
    charWidth := _canvas.font.width;
2535
    charHeight := _canvas.font.height + inter
2536
    charHeight := _canvas.font.height + inter
2536
END setCanvas;
2537
END setCanvas;
2537
 
2538
 
2538
 
2539
 
2539
PROCEDURE resize* (width, height: INTEGER);
2540
PROCEDURE resize* (width, height: INTEGER);
2540
BEGIN
2541
BEGIN
2541
    size.X := width;
2542
    size.X := width;
2542
    size.Y := height;
2543
    size.Y := height;
2543
    setPadding(padding.left, padding.top)
2544
    setPadding(padding.left, padding.top)
2544
END resize;
2545
END resize;
2545
 
2546
 
2546
 
2547
 
2547
PROCEDURE destroy* (VAR text: tText);
2548
PROCEDURE destroy* (VAR text: tText);
2548
BEGIN
2549
BEGIN
2549
    IF search(text, "", FALSE, FALSE) THEN END;
2550
    IF search(text, "", FALSE, FALSE) THEN END;
2550
    ChangeLog.destroy(text.chLog);
2551
    ChangeLog.destroy(text.chLog);
2551
    Lines.destroyVector(text.LinesVector);
2552
    Lines.destroyVector(text.LinesVector);
2552
    DISPOSE(text.foundList);
2553
    DISPOSE(text.foundList);
2553
    DISPOSE(text.cursor);
2554
    DISPOSE(text.cursor);
2554
    DISPOSE(text.select2);
2555
    DISPOSE(text.select2);
2555
    DISPOSE(text)
2556
    DISPOSE(text)
2556
END destroy;
2557
END destroy;
2557
 
2558
 
2558
 
2559
 
2559
PROCEDURE open* (name: RW.tFileName; ptr, size: INTEGER; VAR errno: INTEGER): tText;
2560
PROCEDURE open* (name: RW.tFileName; ptr, size: INTEGER; VAR errno: INTEGER): tText;
2560
VAR
2561
VAR
2561
    text: tText;
2562
    text: tText;
2562
    file: RW.tInput;
2563
    file: RW.tInput;
2563
    n, enc, eol: INTEGER;
2564
    n, enc, eol: INTEGER;
2564
    _eol: BOOLEAN;
2565
    _eol: BOOLEAN;
2565
    line: tLine;
2566
    line: tLine;
2566
BEGIN
2567
BEGIN
2567
    errno := 0;
2568
    errno := 0;
2568
    text := create(name);
2569
    text := create(name);
2569
    IF text # NIL THEN
2570
    IF text # NIL THEN
2570
    	IF ptr = 0 THEN
2571
    	IF ptr = 0 THEN
2571
    		file := RW.loadFromFile(name, enc, eol)
2572
    		file := RW.loadFromFile(name, enc, eol)
2572
    	ELSE
2573
    	ELSE
2573
    		file := RW.loadFromMem(ptr, size, enc, eol)
2574
    		file := RW.loadFromMem(ptr, size, enc, eol)
2574
    	END;
2575
    	END;
2575
    	IF file = NIL THEN
2576
    	IF file = NIL THEN
2576
    		destroy(text)
2577
    		destroy(text)
2577
    	END
2578
    	END
2578
    ELSE
2579
    ELSE
2579
    	file := NIL
2580
    	file := NIL
2580
    END;
2581
    END;
2581
    IF file # NIL THEN
2582
    IF file # NIL THEN
2582
        ChangeLog.changeInt(text.enc, enc);
2583
        ChangeLog.changeInt(text.enc, enc);
2583
        ChangeLog.changeInt(text.eol, eol);
2584
        ChangeLog.changeInt(text.eol, eol);
2584
        text.enc := enc;
2585
        text.enc := enc;
2585
        text.eol := eol;
2586
        text.eol := eol;
2586
        line := Lines.create(FALSE);
2587
        line := Lines.create(FALSE);
2587
        List._append(text, line);
2588
        List._append(text, line);
2588
        REPEAT
2589
        REPEAT
2589
            n := RW.getString(file, line, Lines.tabs, _eol);
2590
            n := RW.getString(file, line, Lines.tabs, _eol);
2590
            IF _eol THEN
2591
            IF _eol THEN
2591
            	line := Lines.create(FALSE);
2592
            	line := Lines.create(FALSE);
2592
            	List._append(text, line)
2593
            	List._append(text, line)
2593
            END
2594
            END
2594
        UNTIL ~_eol;
2595
        UNTIL ~_eol;
2595
        RW.destroy(file);
2596
        RW.destroy(file);
2596
        text.curLine := text.first(tLine);
2597
        text.curLine := text.first(tLine);
2597
        SetPos(text, 0, 0);
2598
        SetPos(text, 0, 0);
2598
        resetSelect(text);
2599
        resetSelect(text);
2599
        Comments(text)
2600
        Comments(text)
2600
    ELSE
2601
    ELSE
2601
        errno := 1
2602
        errno := 1
2602
    END
2603
    END
2603
    RETURN text
2604
    RETURN text
2604
END open;
2605
END open;
2605
 
2606
 
2606
 
2607
 
2607
PROCEDURE findNext* (text: tText; prev: BOOLEAN): BOOLEAN;
2608
PROCEDURE findNext* (text: tText; prev: BOOLEAN): BOOLEAN;
2608
VAR
2609
VAR
2609
    cursorPos, x, y, X, Y, Len: INTEGER;
2610
    cursorPos, x, y, X, Y, Len: INTEGER;
2610
    p: Search.tPos;
2611
    p: Search.tPos;
2611
    line: tLine;
2612
    line: tLine;
2612
    res: BOOLEAN;
2613
    res: BOOLEAN;
2613
BEGIN
2614
BEGIN
2614
    X := text.cursor.X;
2615
    X := text.cursor.X;
2615
    Y := text.cursor.Y;
2616
    Y := text.cursor.Y;
2616
    text.cursor.X := MIN(text.cursor.X, text.curLine.length);
2617
    text.cursor.X := MIN(text.cursor.X, text.curLine.length);
2617
    cursorPos := text.curLine.pos + text.cursor.X - ORD(prev) - ORD(~prev & (text.foundSel = 0));
2618
    cursorPos := text.curLine.pos + text.cursor.X - ORD(prev) - ORD(~prev & (text.foundSel = 0));
2618
    p := text.foundList.first(Search.tPos);
2619
    p := text.foundList.first(Search.tPos);
2619
    WHILE (p # NIL) & (p.pos <= cursorPos) DO
2620
    WHILE (p # NIL) & (p.pos <= cursorPos) DO
2620
        p := p.next(Search.tPos)
2621
        p := p.next(Search.tPos)
2621
    END;
2622
    END;
2622
    IF prev THEN
2623
    IF prev THEN
2623
        IF p = NIL THEN
2624
        IF p = NIL THEN
2624
            p := text.foundList.last(Search.tPos)
2625
            p := text.foundList.last(Search.tPos)
2625
        ELSE
2626
        ELSE
2626
            p := p.prev(Search.tPos)
2627
            p := p.prev(Search.tPos)
2627
        END
2628
        END
2628
    END;
2629
    END;
2629
    res := p # NIL;
2630
    res := p # NIL;
2630
    IF res THEN
2631
    IF res THEN
2631
        y := 0;
2632
        y := 0;
2632
        line := text.first(tLine);
2633
        line := text.first(tLine);
2633
        WHILE (line.pos <= p.pos) & (line.next # NIL) DO
2634
        WHILE (line.pos <= p.pos) & (line.next # NIL) DO
2634
            NextLine(line);
2635
            NextLine(line);
2635
            INC(y)
2636
            INC(y)
2636
        END;
2637
        END;
2637
        IF (line.next # NIL) OR (line.pos > p.pos) THEN
2638
        IF (line.next # NIL) OR (line.pos > p.pos) THEN
2638
            PrevLine(line);
2639
            PrevLine(line);
2639
            DEC(y)
2640
            DEC(y)
2640
        END;
2641
        END;
2641
        resetSelect(text);
2642
        resetSelect(text);
2642
        searchScroll(text, y);
2643
        searchScroll(text, y);
2643
        x := p.pos - line.pos;
2644
        x := p.pos - line.pos;
2644
        Len := LENGTH(text.searchText);
2645
        Len := LENGTH(text.searchText);
2645
        IF x + Len > text.scroll.X + textsize.X THEN
2646
        IF x + Len > text.scroll.X + textsize.X THEN
2646
            text.scroll.X := MAX(x + Len - textsize.X + 3, 0)
2647
            text.scroll.X := MAX(x + Len - textsize.X + 3, 0)
2647
        ELSIF x < text.scroll.X THEN
2648
        ELSIF x < text.scroll.X THEN
2648
            text.scroll.X := MAX(x - 3, 0)
2649
            text.scroll.X := MAX(x - 3, 0)
2649
        END;
2650
        END;
2650
        SetPos(text, x, y);
2651
        SetPos(text, x, y);
2651
        text.foundSel := Len
2652
        text.foundSel := Len
2652
    ELSE
2653
    ELSE
2653
        SetPos(text, X, Y)
2654
        SetPos(text, X, Y)
2654
    END
2655
    END
2655
    RETURN res
2656
    RETURN res
2656
END findNext;
2657
END findNext;
2657
 
2658
 
2658
 
2659
 
2659
PROCEDURE replace* (text: tText; s: ARRAY OF WCHAR; n: INTEGER);
2660
PROCEDURE replace* (text: tText; s: ARRAY OF WCHAR; n: INTEGER);
2660
VAR
2661
VAR
2661
    line: tLine;
2662
    line: tLine;
2662
    sLen, i: INTEGER;
2663
    sLen, i: INTEGER;
2663
BEGIN
2664
BEGIN
2664
    IF text.foundSel > 0 THEN
2665
    IF text.foundSel > 0 THEN
2665
        line := text.curLine;
2666
        line := text.curLine;
2666
        sLen := LENGTH(s);
2667
        sLen := LENGTH(s);
2667
        i := text.cursor.X;
2668
        i := text.cursor.X;
2668
        IF sLen > n THEN
2669
        IF sLen > n THEN
2669
            Lines.insert3(line, i, sLen - n)
2670
            Lines.insert3(line, i, sLen - n)
2670
        ELSIF n > sLen THEN
2671
        ELSIF n > sLen THEN
2671
            Lines.delCharN(line, i, n - sLen)
2672
            Lines.delCharN(line, i, n - sLen)
2672
        ELSE (* n = sLen *)
2673
        ELSE (* n = sLen *)
2673
        	Lines.copy(line)
2674
        	Lines.copy(line)
2674
        END;
2675
        END;
2675
        SetPos(text, i + sLen, text.cursor.Y);
2676
        SetPos(text, i + sLen, text.cursor.Y);
2676
	    WHILE sLen > 0 DO
2677
	    WHILE sLen > 0 DO
2677
	        DEC(sLen);
2678
	        DEC(sLen);
2678
	        Lines.setChar(line, i + sLen, s[sLen])
2679
	        Lines.setChar(line, i + sLen, s[sLen])
2679
	    END;
2680
	    END;
2680
        resetSelect(text);
2681
        resetSelect(text);
2681
        Lines.modify(line);
2682
        Lines.modify(line);
2682
        modify(text)
2683
        modify(text)
2683
    END
2684
    END
2684
END replace;
2685
END replace;
2685
 
2686
 
2686
 
2687
 
2687
PROCEDURE replaceAll* (text: tText; s: ARRAY OF WCHAR; n: INTEGER): INTEGER;
2688
PROCEDURE replaceAll* (text: tText; s: ARRAY OF WCHAR; n: INTEGER): INTEGER;
2688
VAR
2689
VAR
2689
    p: Search.tPos;
2690
    p: Search.tPos;
2690
    line: tLine;
2691
    line: tLine;
2691
    y, k, d, pos, y0: INTEGER;
2692
    y, k, d, pos, y0: INTEGER;
2692
BEGIN
2693
BEGIN
2693
    resetSelect(text);
2694
    resetSelect(text);
2694
    SetPos(text, 0, 0);
2695
    SetPos(text, 0, 0);
2695
    line := text.first(tLine);
2696
    line := text.first(tLine);
2696
    y := 0;
2697
    y := 0;
2697
    y0 := -1;
2698
    y0 := -1;
2698
    k := 0;
2699
    k := 0;
2699
    d := LENGTH(s) - n;
2700
    d := LENGTH(s) - n;
2700
    p := text.foundList.first(Search.tPos);
2701
    p := text.foundList.first(Search.tPos);
2701
    WHILE p # NIL DO
2702
    WHILE p # NIL DO
2702
        pos := p.pos;
2703
        pos := p.pos;
2703
        WHILE (line.pos <= pos) & (line.next # NIL) DO
2704
        WHILE (line.pos <= pos) & (line.next # NIL) DO
2704
            NextLine(line);
2705
            NextLine(line);
2705
            INC(y)
2706
            INC(y)
2706
        END;
2707
        END;
2707
        IF (line.next # NIL) OR (line.pos > pos) THEN
2708
        IF (line.next # NIL) OR (line.pos > pos) THEN
2708
            PrevLine(line);
2709
            PrevLine(line);
2709
            DEC(y)
2710
            DEC(y)
2710
        END;
2711
        END;
2711
        IF y = y0 THEN
2712
        IF y = y0 THEN
2712
            INC(k, d)
2713
            INC(k, d)
2713
        ELSE
2714
        ELSE
2714
            k := 0;
2715
            k := 0;
2715
            y0 := y
2716
            y0 := y
2716
        END;
2717
        END;
2717
        SetPos(text, pos - line.pos + k, y);
2718
        SetPos(text, pos - line.pos + k, y);
2718
        text.foundSel := n;
2719
        text.foundSel := n;
2719
        replace(text, s, n);
2720
        replace(text, s, n);
2720
        p := p.next(Search.tPos)
2721
        p := p.next(Search.tPos)
2721
    END
2722
    END
2722
    RETURN text.foundList.count
2723
    RETURN text.foundList.count
2723
END replaceAll;
2724
END replaceAll;
2724
 
2725
 
2725
 
2726
 
2726
PROCEDURE conv (VAR c: WCHAR; cp: E.CP; enc: INTEGER): BOOLEAN;
2727
PROCEDURE conv (VAR c: WCHAR; cp: E.CP; enc: INTEGER): BOOLEAN;
2727
VAR
2728
VAR
2728
	code: INTEGER;
2729
	code: INTEGER;
2729
	res: BOOLEAN;
2730
	res: BOOLEAN;
2730
BEGIN
2731
BEGIN
2731
	res := FALSE;
2732
	res := FALSE;
2732
	IF (c # 0X) & (c # Lines.NUL) & (c # Lines.TAB1) THEN
2733
	IF (c # 0X) & (c # Lines.NUL) & (c # Lines.TAB1) THEN
2733
		code := E.UNI[ORD(c), enc];
2734
		code := E.UNI[ORD(c), enc];
2734
		IF (0 <= code) & (code <= 255) THEN
2735
		IF (0 <= code) & (code <= 255) THEN
2735
			code := cp[code]
2736
			code := cp[code]
2736
		ELSE
2737
		ELSE
2737
			code := ORD(c)
2738
			code := ORD(c)
2738
		END;
2739
		END;
2739
		IF code # ORD(c) THEN
2740
		IF code # ORD(c) THEN
2740
			c := WCHR(code);
2741
			c := WCHR(code);
2741
			res := TRUE
2742
			res := TRUE
2742
		END
2743
		END
2743
	END
2744
	END
2744
	RETURN res
2745
	RETURN res
2745
END conv;
2746
END conv;
2746
 
2747
 
2747
 
2748
 
2748
PROCEDURE conv1251to866 (VAR c: WCHAR): BOOLEAN;
2749
PROCEDURE conv1251to866 (VAR c: WCHAR): BOOLEAN;
2749
	RETURN conv(c, E.cp866, E.CP1251)
2750
	RETURN conv(c, E.cp866, E.CP1251)
2750
END conv1251to866;
2751
END conv1251to866;
2751
 
2752
 
2752
 
2753
 
2753
PROCEDURE conv866to1251 (VAR c: WCHAR): BOOLEAN;
2754
PROCEDURE conv866to1251 (VAR c: WCHAR): BOOLEAN;
2754
	RETURN conv(c, E.cp1251, E.CP866)
2755
	RETURN conv(c, E.cp1251, E.CP866)
2755
END conv866to1251;
2756
END conv866to1251;
2756
 
2757
 
2757
 
2758
 
2758
PROCEDURE convert* (text: tText; (*cp: E.CP;*) enc: INTEGER);
2759
PROCEDURE convert* (text: tText; (*cp: E.CP;*) enc: INTEGER);
2759
VAR
2760
VAR
2760
	line: tLine;
2761
	line: tLine;
2761
	func: Lines.fConvert;
2762
	func: Lines.fConvert;
2762
	modified: BOOLEAN;
2763
	modified: BOOLEAN;
2763
BEGIN
2764
BEGIN
2764
	modified := FALSE;
2765
	modified := FALSE;
2765
	line := text.first(tLine);
2766
	line := text.first(tLine);
2766
	IF enc = E.CP866 THEN
2767
	IF enc = E.CP866 THEN
2767
		func := conv866to1251
2768
		func := conv866to1251
2768
	ELSIF enc = E.CP1251 THEN
2769
	ELSIF enc = E.CP1251 THEN
2769
		func := conv1251to866
2770
		func := conv1251to866
2770
	ELSE
2771
	ELSE
2771
		line := NIL
2772
		line := NIL
2772
	END;
2773
	END;
2773
 
2774
 
2774
	WHILE line # NIL DO
2775
	WHILE line # NIL DO
2775
		IF Lines.convert(line, 0, line.length - 1, func) THEN
2776
		IF Lines.convert(line, 0, line.length - 1, func) THEN
2776
			modified := TRUE
2777
			modified := TRUE
2777
		END;
2778
		END;
2778
		NextLine(line)
2779
		NextLine(line)
2779
	END;
2780
	END;
2780
 
2781
 
2781
	IF modified THEN
2782
	IF modified THEN
2782
		modify(text)
2783
		modify(text)
2783
	END
2784
	END
2784
END convert;
2785
END convert;
2785
 
2786
 
2786
 
2787
 
2787
PROCEDURE New* (): tText;
2788
PROCEDURE New* (): tText;
2788
VAR
2789
VAR
2789
    text: tText;
2790
    text: tText;
2790
BEGIN
2791
BEGIN
2791
    text := create("");
2792
    text := create("");
2792
    List._append(text, Lines.create(FALSE));
2793
    List._append(text, Lines.create(FALSE));
2793
    text.curLine := text.first(tLine);
2794
    text.curLine := text.first(tLine);
2794
    ChangeLog.changeInt(text.enc, E.CP866);
2795
    ChangeLog.changeInt(text.enc, E.CP866);
2795
    ChangeLog.changeInt(text.eol, E.EOL_CRLF);
2796
    ChangeLog.changeInt(text.eol, E.EOL_CRLF);
2796
    text.enc := E.CP866;
2797
    text.enc := E.CP866;
2797
    text.eol := E.EOL_CRLF;
2798
    text.eol := E.EOL_CRLF;
2798
    SetPos(text, 0, 0);
2799
    SetPos(text, 0, 0);
2799
    resetSelect(text)
2800
    resetSelect(text)
2800
    RETURN text
2801
    RETURN text
2801
END New;
2802
END New;
2802
 
2803
 
2803
 
2804
 
2804
PROCEDURE empty* (text: tText): BOOLEAN;
2805
PROCEDURE empty* (text: tText): BOOLEAN;
2805
	RETURN (text.count = 1) & (text.curLine.length = 0)
2806
	RETURN (text.count = 1) & (text.curLine.length = 0)
2806
END empty;
2807
END empty;
2807
 
2808
 
2808
 
2809
 
2809
PROCEDURE init* (pShowCursor: tProcedure; _lineNumbers, _autoIndents, _autoBrackets, _trimSpace: BOOLEAN);
2810
PROCEDURE init* (pShowCursor: tProcedure; _lineNumbers, _autoIndents, _autoBrackets, _trimSpace: BOOLEAN);
2810
BEGIN
2811
BEGIN
2811
    ShowCursor := pShowCursor;
2812
    ShowCursor := pShowCursor;
2812
    pdelete := delete;
2813
    pdelete := delete;
2813
    drawCursor := TRUE;
2814
    drawCursor := TRUE;
2814
    lineNumbers := _lineNumbers;
2815
    lineNumbers := _lineNumbers;
2815
    autoIndents := _autoIndents;
2816
    autoIndents := _autoIndents;
2816
    autoBrackets := _autoBrackets;
2817
    autoBrackets := _autoBrackets;
2817
    trimSpace := _trimSpace;
2818
    trimSpace := _trimSpace;
2818
    padding.left := pad_left;
2819
    padding.left := pad_left;
2819
    padding.top := pad_top;
2820
    padding.top := pad_top;
2820
END init;
2821
END init;
2821
 
2822
 
2822
 
2823
 
2823
END Text.
2824
END Text.