-
Notifications
You must be signed in to change notification settings - Fork 1
/
text.fiv
139 lines (131 loc) · 2.82 KB
/
text.fiv
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
X
!00000112
\ Executing any text module ( one defined with | ) will create a file
\ and write out all text of the executed module and all modules below it.
\
\ For example, exeucting document gives the entire document. Executing
\ CHAPTER1 only writes out that chapter.
create x
-*-
v
|
!000002EA
: |
>in @
create
>in !
' , \ Save execution address.
77777777 , \ Safety flag.
>in @ , \ Save the address of text stream.
0 \ The initial count of the bytes.
>in @ \ Get the pointer to the text.
begin
dup c@@ \ Is it zero?
while \ While not null, increment the pointer.
1+ swap 1+ swap \ Increment the count and address.
repeat
>in ! \ point text pointer to null.
, \ Save the byte count.
does>
@ p \ Get execution address and print.
;
-*-
v
NAME
!00000073
( EXEC -> string )
: name cls 20 10 gotoxy
." Please enter a filename: "
pad 40 expect over + 0 swap c!
;
-*-
>
H
!0000000F
create h 99 ,
-*-
>
P
!00000100
\ ( document execution addr -> )
: p
?dup if else exit endif
dup name 32 createfile
if h ! else ." Can't open output file!" abort endif
dup >body print
child print_all
h @ close ?dup drop drop
;
-*-
v
PRINT
!00000232
: PRINT
4 +
dup @ 77777777 = not abort" Invalid text word "
dup 8 + @ swap 4 + @ \ Get length, address.
over 0 do \ For all characters,
dup c@@ buffer i + c! 1+ \ Stack: buffer buffer length address.
loop
drop \ Drop the address.
buffer swap h @ \ Buffer_addr count handle
write if drop
else
." Write error... ( {PRINT} in {P} )" abort
endif
." <"
;
-*-
v
BUFFER
!0000001F
create buffer 40 1024 * allot
-*-
^
>
PRINT_ALL
!0000009C
: print_all
?dup if else exit endif
dup comp
dup >body print
dup child print_all
next print_all
;
-*-
^
^
>
DOCUMENT
!00000048
| document
An Example Document
-- ------- --------
-*-
v
CHAPTER1
!00000086
| chapter1
Chapter 1
In this chapter we will explain the
various meanings to life, the universe,
and everything.
-*-
>
CHAPTER2
!0000006E
| chapter2
Chapter 2
This section is about a young boy,
and his trials in becoming a man.
-*-
>
CHAPTER3
!0000005F
| chapter3
Chapter 3
Here we give up any pretence of trying
to make sense.
-*-
^
^