Fixed HTML style.
[fifth.git] / doc / 5TH_ET.txt
1 .( loading editor ) update\r
2 .( done )\r
3 .( ETh - for text editor help )\r
4 \r
5 var handletxt\r
6 var handlebuf\r
7 Dstralloc const editfile\r
8 var shiftx  var shifty\r
9 var curlocx var curlocy\r
10 Dstr \listF\TXT_ET" tmphelpfile\r
11 \r
12 : disppage ( -- )\r
13 handletxt @\r
14 dynp shifty @ 50 * +\r
15 0 1 at!\r
16 1270 type ;\r
17 \r
18 : fclose (  close opened file )\r
19 handletxt @ dup if dynde handletxt off else drop then ;\r
20 \r
21 : ETnewpage fclose 27100 dynal dup handletxt ! dynp\r
22 FF swap 27100 cfill ;\r
23 \r
24 var tmp1\r
25 : fopen ( strhand -- )\r
26 fclose\r
27 dup editfile Dstr2Dstr fsDloadnew dup push dynp ( addrinp       R: handinp )\r
28 27100 dynal dup handletxt ! dynp        ( addrinp addrout       R: handinp )\r
29 FF over 27100 cfill\r
30 tmp1 off\r
31 i dyns do               ( addrinp addrout )\r
32 over c@                 ( addrinp addrout c )\r
33 dup FE = if\r
34         drop\r
35         50 tmp1 @ - + tmp1 off\r
36 else\r
37         dup FD = if\r
38                 drop tmp1 @ tab ( addrinp addrout numspaces )\r
39                 tmp1 @ over + tmp1 ! + 0\r
40         else\r
41                 over c! 1+ 0\r
42                 tmp1 @ 1+ tmp1 !\r
43         then\r
44         drop\r
45 then\r
46 swap 1+ swap\r
47 loop 2drop\r
48 pop dynde ; rh tmp1\r
49 \r
50 : dispchar ( x y -- )\r
51 2dup\r
52 swap shiftx @ -\r
53 swap shifty @ - 1+\r
54 at!\r
55 50 * + handletxt @ dynp + c@ emit ;\r
56 \r
57 : dispcur curlocx @ curlocy @ dispchar ;\r
58 \r
59 : displine ( line )\r
60 0 over shifty @ - 1+ at!\r
61 50 * handletxt @ dynp + shiftx @ + 50 type ;\r
62 \r
63 : dispstatbar\r
64 colneg\r
65 0 0 at! 50 do space loop\r
66 0 0 at! ." col:" curlocx @ .\r
67 7 0 at! ." line:" curlocy @ .\r
68 11 0 at! ." ascii:" curlocy @ 50 * curlocx @ + handletxt @ dynp + c@ .\r
69 1B 0 at! ." file:" editfile Dstr.\r
70 49 0 at! ." F1-help"\r
71 colnorm ;\r
72 \r
73 : charins ( char x y )\r
74 50 * handletxt @ dynp +         ( char x addr )\r
75 over push\r
76 + dup dup 1+ 4F pop - cmove     ( char addr )\r
77 c! ;\r
78 \r
79 : charcut ( x y -- char )\r
80 over push\r
81 50 * handletxt @ dynp + +\r
82 dup c@ swap                     ( char addr )\r
83 dup dup 1+ swap                 ( char addr addr+1 addr )\r
84 4F pop - dup push cmove         ( char addr )\r
85 pop + FF swap c! ;\r
86 \r
87 : lineins ( line )\r
88 50 * dup push handletxt @ dynp +                ( addr )\r
89 dup dup 50 + handletxt @ dyns 50 - pop - cmove  ( addr )\r
90 FF swap 50 cfill ;\r
91 \r
92 : linecut ( line )\r
93 50 * dup push handletxt @ dynp +                ( addr )\r
94 dup 50 + swap handletxt @ dyns 50 - pop - cmove ;\r
95 \r
96 : screenaim\r
97 0 curlocy @ 1E - 794 bound shifty !\r
98 disppage ;\r
99 \r
100 var tmp1\r
101 : length        ( line -- length )\r
102 50 * 4F + handletxt @ dynp +    ( addr )\r
103 51 do\r
104         i tmp1 !\r
105         dup c@ FF - if pop drop 0 push then\r
106         1-\r
107 loop\r
108 drop\r
109 tmp1 @ ; rh tmp1\r
110 \r
111 var tmp2 var tmp3\r
112 : fsavechar ( char ) tmp2 @ swap over c! 1+ tmp2 ! ;\r
113 : fsave ( -- )\r
114 27200 dynal dup dynp tmp2 !\r
115 0\r
116 7CF do\r
117         i length if drop pop 1+ 0 push then\r
118 loop\r
119 0 swap for              ( desthand )\r
120         tmp3 off\r
121         i 50 * handletxt @ dynp +\r
122         0 i length for  ( desthand srcaddr )\r
123                 dup c@\r
124                 i tab 8 = if tmp3 @ if FD fsavechar tmp3 off then then\r
125                 dup FF = if\r
126                         drop tmp3 @ 1+ tmp3 !\r
127                 else\r
128                         tmp3 @ do FF fsavechar loop tmp3 off\r
129                         fsavechar\r
130                 then\r
131                 1+\r
132         loop drop\r
133         FE fsavechar\r
134 loop\r
135 tmp2 @ over dynp - over dynresize\r
136 dup editfile fsDsave\r
137 dynde ; rh tmp2 rh tmp3\r
138 \r
139 str TXT_default" tmpdefault\r
140 \r
141 : ET\r
142 handletxt @ if\r
143 disppage\r
144 until\r
145         colneg dispcur dispstatbar KBD_FW@ colnorm dispcur\r
146 \r
147         dup 415 = if                                            ( DEL )\r
148                 curlocx @ curlocy @ charcut drop\r
149                 curlocy @ displine\r
150         then\r
151 \r
152         dup FC = if                                             ( BACKSPACE )\r
153         curlocx @ if\r
154                 curlocx @ 1- curlocy @ charcut drop\r
155                 curlocy @ displine\r
156                 drop 413\r
157         else\r
158                 curlocy @ if\r
159                         curlocy @ 1- dup length dup curlocx !   ( y-1 strlen )\r
160                         swap 50 * handletxt @ dynp +    ( strlen y1addr )\r
161                         2dup + swap 50 +                ( strlen dest src )\r
162                         swap rot 50 swap - cmove\r
163                         curlocy @ linecut\r
164                         drop 410\r
165                         disppage\r
166                 then\r
167         then\r
168         then\r
169 \r
170         dup FD = if                                             ( TAB )\r
171                 curlocx @ tab\r
172                 dup do FF curlocx @ curlocy @ charins loop\r
173                 curlocx @ + curlocx !\r
174                 curlocy @ displine\r
175         then\r
176 \r
177         dup FE = if                                             ( ENTER )\r
178                 curlocy @ 7CF < if\r
179                         curlocy @ 1+ lineins\r
180                         curlocx @ 0\r
181                         50 curlocx @ - do\r
182                                 over curlocy @ charcut\r
183                                 over curlocy @ 1+ charins\r
184                                 1+\r
185                         loop 2drop\r
186                         curlocx off\r
187                         drop 412\r
188                         disppage\r
189                 then\r
190         then\r
191 \r
192         dup 418 = if curlocy @ 3A - curlocy ! then              ( PG-UP )\r
193         dup 419 = if curlocy @ 3A + curlocy ! then              ( PG-DOWN )\r
194         dup 416 = if curlocx off then                           ( HOME )\r
195         dup 417 = if curlocy @ length curlocx ! then            ( END )\r
196         dup 401 = if tmphelpfile fsdisp disppage then           ( F1 )\r
197         dup 402 = if fsave then                                 ( F2 )\r
198         dup 403 = if fclose drop 1B then                        ( F3 )\r
199         dup 400 = if done 0 0 at! screen cls drop -1 then       ( ESC )\r
200 \r
201         0 over F0 bound? if -1 else 0 then                      ( NORMAL KEY )\r
202         over FF = if drop -1 then\r
203         if\r
204                 curlocx @ curlocy @ charins\r
205                 curlocy @ displine\r
206                 411\r
207         then\r
208 \r
209         dup 411 = if curlocx @ 1+ curlocx ! then               ( RIGHT )\r
210         dup 413 = if curlocx @ 1- curlocx ! then               ( LEFT )\r
211         dup 412 = if curlocy @ 1+ curlocy ! then               ( DOWN )\r
212         dup 410 = if curlocy @ 1- curlocy ! then               ( UP )\r
213         drop\r
214 \r
215         0 curlocx @ 4F bound curlocx !\r
216         0 curlocy @ 7CF bound curlocy !\r
217 \r
218         curlocy @ shifty @ - 3B > if screenaim then\r
219 \r
220         curlocy @ shifty @ - 3B - 0 = if\r
221                 0 0 8 screen scrollf\r
222                 shifty @ 1+ shifty !\r
223                 curlocy @ displine\r
224         then\r
225 \r
226         curlocy @ shifty @ - -1 < if screenaim then\r
227 \r
228         curlocy @ shifty @ - 1+ 0 = if\r
229                 0 0 -8 screen scrollf\r
230                 shifty @ 1- shifty !\r
231                 curlocy @ displine\r
232         then\r
233 \r
234 loop\r
235 else\r
236         tmpdefault editfile str2Dstr\r
237         ETnewpage\r
238         ET\r
239 then ;\r
240 \r
241 : ETl\r
242 fopen\r
243 curlocx off\r
244 curlocy off\r
245 shiftx off\r
246 shifty off\r
247 ET ;\r
248 \r
249 : ETs\r
250 editfile Dstr2Dstr\r
251 fsave ." saved " ;\r
252 \r
253 : ETh tmphelpfile fs. ;\r
254 \r
255 rh handletxt\r
256 rh handlebuf\r
257 rh editfile\r
258 rh shiftx rh shifty\r
259 rh curlocx rh curlocy\r
260 rh tmphelpfile\r
261 rh disppage\r
262 rh fclose rh fopen\r
263 rh dispchar rh dispcur\r
264 rh displine rh dispstatbar\r
265 rh charins rh charcut\r
266 rh lineins rh linecut\r
267 rh screenaim rh length\r
268 rh fsavechar rh fsave\r
269 rh ETnewpage rh tmpdefault\r