-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditor.4th
166 lines (136 loc) · 4.34 KB
/
editor.4th
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
\ @+leo-ver=4-thin
\ @+node:leonardoce.20090630084051.2:@thin editor.4th
\ @@language forth
\ QEditor
only definitions
1024 constant buffer-length local
create buffer buffer-length allot
64 constant line-length
32 constant space-ascii
13 constant newline-ascii
\ @+others
\ @+node:leonardoce.20090630084051.11:Schermo Singolo
\ @+others
\ @+node:leonardoce.20090630084051.4:Utili
: >offset ( l -- addr )
line-length * buffer + ;
: parse-editor-arg ( "<space>ccc.." -- caddr u )
newline-ascii parse line-length min ;
: get-line ( i -- ) >offset line-length ;
: cr! ( addr -- ) 10 swap c! ;
\ @-node:leonardoce.20090630084051.4:Utili
\ @+node:leonardoce.20090630084051.5:Cancellazione
: insert-cr ( -- ) 16 0 do i get-line 1- + cr! loop ;
: wipe ( -- )
buffer dup 1024 + swap do space-ascii i c! loop
insert-cr ;
: wipe-line ( n -- )
dup get-line 1- + cr!
get-line over + 1- swap do space-ascii i c! loop ;
\ @-node:leonardoce.20090630084051.5:Cancellazione
\ @+node:leonardoce.20090630084051.6:Modifica
: p ( i "<space>ccc.." -- )
dup wipe-line
>offset parse-editor-arg
underswap cmove ;
\ @nonl
\ @-node:leonardoce.20090630084051.6:Modifica
\ @+node:leonardoce.20090701090549.3:Trattamento linee
: line-move ( orig dest -- )
swap get-line drop
swap get-line cmove ;
: back-move-lines ( n -- ) 1+ 15 swap do i i 1- line-move loop ;
: forward-move-lines ( n -- ) 15 do i 1- i line-move 0 1- +loop ;
: dd ( n -- ) dup 15 <> if back-move-lines 15 wipe-line then ;
: ii ( n -- ) dup forward-move-lines wipe-line ;
\ @nonl
\ @-node:leonardoce.20090701090549.3:Trattamento linee
\ @+node:leonardoce.20090630084051.7:Stampa Schermo
: print-lineno ( i -- ) <# # # #> type space ;
: print-line ( i -- )
dup print-lineno
get-line over + swap do i c@ emit loop ;
: l ( -- )
16 0 do i print-line loop ;
\ @nonl
\ @-node:leonardoce.20090630084051.7:Stampa Schermo
\ @-others
\ @nonl
\ @-node:leonardoce.20090630084051.11:Schermo Singolo
\ @+node:leonardoce.20090630084051.8:Trattamento file
0 value current-fileid
0 value blk
\ @+others
\ @+node:leonardoce.20090630084051.9:Utili
: check-file-error ( ior -- )
0<> if abort" I/O error" then ; local
\ @-node:leonardoce.20090630084051.9:Utili
\ @+node:leonardoce.20090630084051.10:Gestione Schermi
: reposition ( n -- ) blk buffer-length * current-fileid
reposition-file check-file-error ; local
: write ( -- )
reposition
buffer buffer-length current-fileid write-file
check-file-error ; local
: read ( -- )
reposition
wipe
buffer buffer-length current-fileid read-file check-file-error drop ;
: list ( n -- )
to blk read l ;
\ @-node:leonardoce.20090630084051.10:Gestione Schermi
\ @+node:leonardoce.20090630084051.22:Gestione Files
: blocks-in-file ( -- )
0 current-fileid reposition-file-from-end check-file-error
current-fileid file-position check-file-error buffer-length /
0 to blk reposition ;
: remove-last-screen ( -- )
blocks-in-file 1- buffer-length * current-fileid resize-file drop ;
: close ( -- ) current-fileid close-file check-file-error
0 to current-fileid ;
: use ( "<space>ccc.." -- )
parse-editor-arg r/w bin open-file check-file-error to current-fileid
0 to blk read ;
: new ( "<space>ccc.." -- )
parse-editor-arg w/o bin open-file check-file-error to current-fileid
wipe 0 to blk write close ;
\ @-node:leonardoce.20090630084051.22:Gestione Files
\ @+node:leonardoce.20090701090549.10:Spostamento Schermi
: i-screen ( s -- )
dup blocks-in-file do
i 1- to blk read
i to blk write
0 1- +loop
to blk wipe write ;
: d-screen ( s -- )
blocks-in-file swap do
i 1+ to blk read
i to blk write
loop
;
\ @-node:leonardoce.20090701090549.10:Spostamento Schermi
\ @+node:leonardoce.20090630084051.25:Indice
: read-index-line ( -- )
pad line-length current-fileid read-file check-file-error drop
blk <# # # #> type space
pad line-length type ;
: index ( -- )
blocks-in-file 0 do
i to blk reposition read-index-line
loop
0 to blk reposition ;
\ @-node:leonardoce.20090630084051.25:Indice
\ @+node:leonardoce.20090630084051.26:Interprete
: load ( n -- )
to blk read
buffer buffer-length loadstring ;
\ @nonl
\ @-node:leonardoce.20090630084051.26:Interprete
\ @-others
\ @nonl
\ @-node:leonardoce.20090630084051.8:Trattamento file
\ @-others
wipe
\ @nonl
\ @-node:leonardoce.20090630084051.2:@thin editor.4th
\ @-leo