[gforth] / gforth / wf.fs  

gforth: gforth/wf.fs


1 : pazsan 1.1 \ wiki forth
2 :    
3 : anton 1.19 \ Copyright (C) 2003 Free Software Foundation, Inc.
4 :    
5 :     \ This file is part of Gforth.
6 :    
7 :     \ Gforth is free software; you can redistribute it and/or
8 :     \ modify it under the terms of the GNU General Public License
9 :     \ as published by the Free Software Foundation; either version 2
10 :     \ of the License, or (at your option) any later version.
11 :    
12 :     \ This program is distributed in the hope that it will be useful,
13 :     \ but WITHOUT ANY WARRANTY; without even the implied warranty of
14 :     \ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 :     \ GNU General Public License for more details.
16 :    
17 :     \ You should have received a copy of the GNU General Public License
18 :     \ along with this program; if not, write to the Free Software
19 :     \ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
20 :    
21 : pazsan 1.1 require string.fs
22 :    
23 : pazsan 1.11 : -scan ( addr u char -- addr' u' )
24 :     >r BEGIN dup WHILE 1- 2dup + c@ r@ = UNTIL THEN
25 :     rdrop ;
26 :     : -$split ( addr u char -- addr1 u1 addr2 u2 )
27 :     >r 2dup r@ -scan 2dup + c@ r> = negate over + >r
28 :     2swap r> /string ;
29 :    
30 : pazsan 1.1 \ tag handling
31 :    
32 :     : .' '' parse postpone SLiteral postpone type ; immediate
33 : pazsan 1.3 : s' '' parse postpone SLiteral ; immediate
34 : pazsan 1.1
35 : pazsan 1.3 Variable tag-option
36 :     s" " tag-option $!
37 :    
38 :     : tag ( addr u -- ) '< emit type tag-option $@ type '> emit
39 :     s" " tag-option $! ;
40 : pazsan 1.1 : /tag ( addr u -- ) '< emit '/ emit type '> emit ;
41 : pazsan 1.2 : tagged ( addr1 u1 addr2 u2 -- ) 2dup 2>r tag type 2r> /tag ;
42 : pazsan 1.1
43 : pazsan 1.3 : opt ( addr u opt u -- ) s" " tag-option $+!
44 :     tag-option $+! s' ="' tag-option $+! tag-option $+!
45 :     s' "' tag-option $+! ;
46 :     : href= ( addr u -- ) s" href" opt ;
47 : pazsan 1.10 : name= ( addr u -- ) s" name" opt ;
48 : pazsan 1.3 : src= ( addr u -- ) s" src" opt ;
49 : pazsan 1.4 : alt= ( addr u -- ) s" alt" opt ;
50 : pazsan 1.7 : width= ( addr u -- ) s" width" opt ;
51 :     : height= ( addr u -- ) s" height" opt ;
52 : pazsan 1.3 : align= ( addr u -- ) s" align" opt ;
53 :     : mailto: ( addr u -- ) s' href="mailto:' tag-option $+!
54 :     tag-option $+! s' "' tag-option $+! ;
55 :    
56 : pazsan 1.1 \ environment handling
57 :    
58 : pazsan 1.11 Variable end-sec
59 : pazsan 1.1 Variable oldenv
60 : pazsan 1.10 Variable envs 30 0 [DO] 0 , [LOOP]
61 : pazsan 1.1
62 :     : env$ ( -- addr ) envs dup @ 1+ cells + ;
63 :     : env ( addr u -- ) env$ $! ;
64 :     : env? ( -- ) envs @ oldenv @
65 :     2dup > IF env$ $@ tag THEN
66 :     2dup < IF env$ cell+ $@ /tag env$ cell+ $off THEN
67 :     drop oldenv ! ;
68 :     : +env 1 envs +! ;
69 : pazsan 1.11 : -env end-sec @ envs @ 2 > or IF -1 envs +! env? THEN ;
70 : pazsan 1.1 : -envs envs @ 0 ?DO -env cr LOOP ;
71 : pazsan 1.2 : >env ( addr u -- ) +env env env? ;
72 : pazsan 1.1
73 : pazsan 1.6 \ alignment
74 :    
75 : pazsan 1.12 Variable table-format
76 :     Variable table#
77 :     Variable table-start
78 :    
79 : pazsan 1.6 : >align ( c -- )
80 :     CASE
81 : pazsan 1.13 'l OF s" left" align= ENDOF
82 :     'r OF s" right" align= ENDOF
83 :     'c OF s" center" align= ENDOF
84 :     '< OF s" left" align= ENDOF
85 :     '> OF s" right" align= ENDOF
86 :     '= OF s" center" align= ENDOF
87 :     '~ OF s" absmiddle" align= ENDOF
88 :     ENDCASE ;
89 :    
90 :     : >talign ( c -- )
91 :     CASE
92 : pazsan 1.6 'l OF s" left" align= ENDOF
93 :     'r OF s" right" align= ENDOF
94 :     'c OF s" center" align= ENDOF
95 :     '< OF s" left" align= ENDOF
96 :     '> OF s" right" align= ENDOF
97 : pazsan 1.11 '= OF s" center" align= ENDOF
98 : pazsan 1.12 digit? IF 0 <# #S #> s" rowspan" opt
99 :     table# @ 1+ table-start ! THEN 0
100 : pazsan 1.6 ENDCASE ;
101 :    
102 : pazsan 1.10 : >border ( c -- )
103 :     case
104 :     '- of s" 0" s" border" opt endof
105 :     '+ of s" 1" s" border" opt endof
106 :     endcase ;
107 :    
108 : pazsan 1.7 \ image handling
109 :    
110 :     Create imgbuf $20 allot
111 :    
112 :     Create pngsig $89 c, $50 c, $4E c, $47 c, $0D c, $0A c, $1A c, $0A c,
113 :     Create jfif $FF c, $D8 c, $FF c, $E0 c, $00 c, $10 c, $4A c, $46 c,
114 :     $49 c, $46 c,
115 :    
116 :     : b@ ( addr -- x ) 0 swap 4 bounds ?DO 8 lshift I c@ + LOOP ;
117 :     : bw@ ( addr -- x ) 0 swap 2 bounds ?DO 8 lshift I c@ + LOOP ;
118 :    
119 :     : gif? ( -- flag )
120 : anton 1.16 s" GIF89a" imgbuf over str=
121 :     s" GIF87a" imgbuf over str= or ;
122 : pazsan 1.7 : gif-size ( -- w h )
123 : pazsan 1.10 imgbuf 8 + c@ imgbuf 9 + c@ 8 lshift +
124 :     imgbuf 6 + c@ imgbuf 7 + c@ 8 lshift + ;
125 : pazsan 1.7
126 :     : png? ( -- flag )
127 : anton 1.16 pngsig 8 imgbuf over str= ;
128 : pazsan 1.7 : png-size ( -- w h )
129 : pazsan 1.10 imgbuf $14 + b@ imgbuf $10 + b@ ;
130 : pazsan 1.7
131 :     : jpg? ( -- flag )
132 : anton 1.16 jfif 10 imgbuf over str= ;
133 : pazsan 1.7 : jpg-size ( fd -- w h ) >r
134 :     2. BEGIN
135 :     2dup r@ reposition-file throw
136 :     imgbuf $10 r@ read-file throw 0<>
137 : pazsan 1.8 imgbuf bw@ $FFC0 $FFD0 within 0= and WHILE
138 : pazsan 1.7 imgbuf 2 + bw@ 2 + 0 d+ REPEAT
139 :     2drop imgbuf 5 + bw@ imgbuf 7 + bw@ rdrop ;
140 :    
141 :     : img-size ( fd -- w h ) >r
142 :     gif? IF gif-size rdrop EXIT THEN
143 :     jpg? IF r> jpg-size EXIT THEN
144 :     png? IF png-size rdrop EXIT THEN
145 :     0 0 ;
146 :    
147 :     : .img-size ( addr u -- )
148 : pazsan 1.10 r/o open-file IF drop EXIT THEN >r
149 : pazsan 1.7 imgbuf $20 r@ read-file throw drop
150 :     r@ img-size
151 :     r> close-file throw
152 :     ?dup IF 0 <# #S #> width= THEN
153 :     ?dup IF 0 <# #S #> height= THEN ;
154 :    
155 : pazsan 1.1 \ link creation
156 :    
157 :     Variable link
158 : pazsan 1.10 Variable link-sig
159 : pazsan 1.1 Variable link-suffix
160 : pazsan 1.3 Variable iconpath
161 : pazsan 1.1
162 : pazsan 1.2 Variable do-size
163 : pazsan 1.9 Variable do-icon
164 : pazsan 1.2
165 : pazsan 1.8 Defer parse-line
166 :    
167 : pazsan 1.11 : .img ( addr u -- ) dup >r '| -$split dup r> = IF 2swap THEN
168 :     dup IF 2swap alt= ELSE 2drop THEN
169 :     tag-option $@len >r over c@ >align tag-option $@len r> = 1+ /string
170 :     tag-option $@len >r over c@ >border tag-option $@len r> = 1+ /string
171 :     2dup .img-size src= s" img" tag ;
172 :     : >img ( -- ) '{ parse type '} parse .img ;
173 :    
174 : pazsan 1.7 : alt-suffix ( -- )
175 :     link-suffix $@len 2 - link-suffix $!len
176 :     s" [" link-suffix 0 $ins
177 :     s" ]" link-suffix $+!
178 :     link-suffix $@ alt= ;
179 :    
180 : pazsan 1.6 : get-icon ( addr u -- ) iconpath @ IF 2drop EXIT THEN
181 :     link-suffix $! s" .*" link-suffix $+!
182 : pazsan 1.1 s" icons" open-dir throw >r
183 :     BEGIN
184 :     pad $100 r@ read-dir throw WHILE
185 :     pad swap 2dup link-suffix $@ filename-match
186 : pazsan 1.3 IF s" icons/" iconpath $! iconpath $+!
187 : pazsan 1.10 iconpath $@ 2dup .img-size src= '- >border
188 : pazsan 1.7 alt-suffix s" img" tag true
189 : pazsan 1.1 ELSE 2drop false THEN
190 : pazsan 1.6 UNTIL ELSE drop THEN
191 : pazsan 1.1 r> close-dir throw ;
192 :    
193 : pazsan 1.9 : link-icon? ( -- ) do-icon @ 0= ?EXIT
194 :     iconpath @ IF iconpath $off THEN
195 :     link $@ + 1- c@ '/ = IF s" index.html" ELSE link $@ THEN
196 : pazsan 1.20 '# $split 2drop
197 : pazsan 1.8 BEGIN '. $split 2swap 2drop dup WHILE
198 :     2dup get-icon REPEAT 2drop ;
199 : pazsan 1.6
200 : pazsan 1.2 : link-size? ( -- ) do-size @ 0= ?EXIT
201 : pazsan 1.1 link $@ r/o open-file IF drop EXIT THEN >r
202 :     r@ file-size throw $400 um/mod nip ." (" 0 u.r ." k)"
203 :     r> close-file throw ;
204 :    
205 : pazsan 1.10 : link-sig? ( -- )
206 :     link $@ link-sig $! s" .sig" link-sig $+!
207 :     link-sig $@ r/o open-file IF drop EXIT THEN
208 :     close-file throw
209 :     ." (" link-sig $@ href= s" a" tag
210 : pazsan 1.11 s" |-icons/sig.gif" .img ." sig" s" /a" tag ." )" ;
211 : pazsan 1.10
212 : pazsan 1.2 : link-options ( addr u -- addr' u' )
213 : pazsan 1.9 do-size off do-icon on
214 :     over c@ '% = over 0> and IF do-size on 1 /string THEN
215 :     over c@ '\ = over 0> and IF do-icon off 1 /string THEN ;
216 : pazsan 1.2
217 : anton 1.16 s" Gforth" environment? [IF] s" 0.5.0" str= [IF]
218 : pazsan 1.15 : parse-string ( c-addr u -- ) \ core,block
219 : anton 1.18 s" *evaluated string*" loadfilename>r
220 : pazsan 1.15 push-file #tib ! >tib !
221 :     >in off blk off loadfile off -1 loadline !
222 :     ['] parse-line catch
223 : anton 1.18 pop-file r>loadfilename throw ;
224 : pazsan 1.15 [ELSE]
225 : pazsan 1.8 : parse-string ( addr u -- )
226 :     evaluate-input cell new-tib #tib ! tib !
227 :     ['] parse-line catch pop-file throw ;
228 : pazsan 1.15 [THEN] [THEN]
229 : pazsan 1.8
230 : pazsan 1.11 : .link ( addr u -- ) dup >r '| -$split dup r> = IF 2swap THEN
231 : pazsan 1.2 link-options link $!
232 : pazsan 1.20 link $@len 0= IF 2dup link $! ( s" .html" link $+! ) THEN
233 : pazsan 1.10 link $@ href= s" a" tag link-icon?
234 :     parse-string s" a" /tag link-size? link-sig? ;
235 : pazsan 1.9 : >link ( -- ) '[ parse type '] parse .link ;
236 : pazsan 1.1
237 :     \ line handling
238 :    
239 : pazsan 1.4 : char? ( -- c ) >in @ char swap >in ! ;
240 : pazsan 1.1 : parse-tag ( addr u char -- )
241 :     >r r@ parse type
242 : pazsan 1.2 r> parse 2swap tagged ;
243 : pazsan 1.1
244 : pazsan 1.6 : .text ( -- ) >in @ >r char drop
245 : pazsan 1.9 source r@ /string >in @ r> - nip
246 :     bounds ?DO I c@
247 :     case
248 :     '& of ." &amp;" endof
249 :     '< of ." &lt;" endof
250 :     dup emit
251 :     endcase
252 :     LOOP ;
253 : pazsan 1.6
254 :     Create do-words $100 0 [DO] ' .text , [LOOP]
255 :    
256 : pazsan 1.9 :noname '( emit 1 >in +! ; '( cells do-words + !
257 :    
258 : pazsan 1.6 : bind-char ( xt -- ) char cells do-words + ! ;
259 :    
260 :     : char>tag ( -- ) char >r
261 :     :noname bl sword postpone SLiteral r@ postpone Literal
262 :     postpone parse-tag postpone ; r> cells do-words + ! ;
263 : pazsan 1.1
264 : pazsan 1.12 : >tag '\ parse type '\ parse tag ;
265 :    
266 : pazsan 1.6 char>tag * b
267 :     char>tag _ em
268 :     char>tag # code
269 :    
270 : pazsan 1.9 ' >link bind-char [
271 :     ' >img bind-char {
272 : pazsan 1.12 ' >tag bind-char \
273 : pazsan 1.6
274 :     : do-word ( char -- ) cells do-words + perform ;
275 : pazsan 1.4
276 : pazsan 1.9 : word? ( -- addr u ) >in @ >r bl sword r> >in ! ;
277 :    
278 :     wordlist Constant autoreplacements
279 :    
280 : pazsan 1.8 :noname ( -- )
281 : pazsan 1.9 BEGIN char? do-word source nip >in @ = UNTIL ; is parse-line
282 :    
283 :     : parse-line+ ( -- )
284 :     BEGIN
285 :     word? autoreplacements search-wordlist
286 :     IF execute bl sword 2drop
287 :     source >in @ 1- /string drop c@ bl = >in +!
288 :     ELSE char? do-word THEN
289 :     source nip >in @ = UNTIL ;
290 : pazsan 1.4
291 :     : parse-to ( char -- ) >r
292 :     BEGIN char? dup r@ <> WHILE
293 :     do-word source nip >in @ = UNTIL ELSE drop THEN
294 :     r> parse type ;
295 : pazsan 1.1
296 : pazsan 1.9 \ autoreplace
297 :    
298 :     : autoreplace ( <[string|url]> -- )
299 :     get-current autoreplacements set-current
300 :     Create set-current
301 :     here 0 , '[ parse 2drop '] parse rot $!
302 :     DOES> $@ .link ;
303 :    
304 : pazsan 1.1 \ paragraph handling
305 :    
306 :     : parse-par ( -- )
307 : pazsan 1.9 BEGIN parse-line+ cr refill WHILE
308 : pazsan 1.1 source nip 0= UNTIL THEN ;
309 :    
310 :     : par ( addr u -- ) env? 2dup tag parse-par /tag cr cr ;
311 : pazsan 1.9 : line ( addr u -- ) env? 2dup tag parse-line+ /tag cr cr ;
312 : pazsan 1.1
313 : pazsan 1.10 \ scan strings
314 :    
315 :     : get-rest ( addr -- ) 0 parse -trailing rot $! ;
316 :     Create $lf 1 c, #lf c,
317 :     : get-par ( addr -- ) >r s" " r@ $+!
318 : anton 1.16 BEGIN 0 parse 2dup s" ." str= 0= WHILE
319 : pazsan 1.10 r@ $@len IF $lf count r@ $+! THEN r@ $+!
320 :     refill 0= UNTIL ELSE 2drop THEN
321 :     rdrop ;
322 :    
323 :     \ toc handling
324 :    
325 :     Variable toc-link
326 :    
327 :     : >last ( addr link -- link' )
328 :     BEGIN dup @ WHILE @ REPEAT ! 0 ;
329 :    
330 : pazsan 1.14 Variable create-navs
331 :     Variable nav$
332 :     Variable nav-name
333 :     Variable nav-file
334 :     Create nav-buf 0 c,
335 :     : nav+ ( char -- ) nav-buf c! nav-buf 1 nav-file $+! ;
336 :    
337 :     : >nav ( addr u -- addr' u' )
338 :     nav-name $! create-navs @ 0=
339 :     IF s" navigate/nav.scm" r/w create-file throw create-navs ! THEN
340 :     s' (script-fu-nav-file "' nav$ $! nav-name $@ nav$ $+!
341 :     s' " "./navigate/' nav$ $+! s" " nav-file $!
342 :     nav-name $@ bounds ?DO
343 :     I c@ dup 'A 'Z 1+ within IF bl + nav+
344 :     ELSE dup 'a 'z 1+ within IF nav+
345 :     ELSE dup '0 '9 1+ within IF nav+
346 :     ELSE dup bl = swap '- = or IF '- nav+
347 :     THEN THEN THEN THEN
348 :     LOOP
349 :     nav-file $@ nav$ $+! s' .jpg")' nav$ $+!
350 :     nav$ $@ create-navs @ write-line throw
351 :     s" [" nav$ $! nav-name $@ nav$ $+!
352 :     s" |-navigate/" nav$ $+! nav-file $@ nav$ $+! s" .jpg" nav$ $+!
353 :     nav$ $@ ;
354 :    
355 :     : toc, ( n -- ) , '| parse >nav here 0 , $! 0 parse here 0 , $! ;
356 : pazsan 1.10 : up-toc align here toc-link >last , 0 toc, ;
357 :     : top-toc align here toc-link >last , 1 toc, ;
358 :     : this-toc align here toc-link >last , 2 toc, ;
359 :     : sub-toc align here toc-link >last , 3 toc, ;
360 : pazsan 1.12 : new-toc toc-link off ;
361 : pazsan 1.10
362 :     Variable toc-name
363 :    
364 :     : .toc-entry ( toc flag -- )
365 :     swap cell+ dup @ swap cell+ dup cell+ $@ 2dup href= s" a" tag
366 : pazsan 1.11 '# scan 1 /string toc-name $@ compare >r
367 : pazsan 1.10 $@ .img swap
368 :     IF
369 :     case
370 : pazsan 1.11 2 of s" ^]|-icons/arrow_up.jpg" .img endof
371 : pazsan 1.10 3 of
372 : pazsan 1.11 r@ 0= IF s" *]|-icons/circle.jpg"
373 :     ELSE s" v]|-icons/arrow_down.jpg" THEN .img endof
374 : pazsan 1.10 endcase
375 :     ELSE
376 :     case
377 : pazsan 1.11 0 of s" ^]|-icons/arrow_up.jpg" .img endof
378 :     1 of s" >]|-icons/arrow_right.jpg" .img endof
379 :     2 of s" *]|-icons/circle.jpg" .img endof
380 :     3 of s" v]|-icons/arrow_down.jpg" .img endof
381 : pazsan 1.10 endcase
382 :     THEN
383 :     s" a" /tag rdrop
384 :     ;
385 :     : print-toc ( -- ) cr 0 parse
386 :     dup 0= IF toc-name $! 0 ELSE
387 :     toc-name $! toc-name $@ name= s" " s" a" tagged 2
388 :     THEN >r
389 :     toc-link BEGIN @ dup WHILE
390 : pazsan 1.11 dup cell+ @ 3 = r@ 0= and IF rdrop 1 >r s" br" tag cr THEN
391 : pazsan 1.10 dup cell+ @ r@ >= IF dup r@ 2 = .toc-entry THEN
392 : pazsan 1.11 dup cell+ @ 2 = r@ 2 = and IF s" br" tag cr THEN
393 : pazsan 1.10 REPEAT drop rdrop cr ;
394 :    
395 : pazsan 1.1 \ handle global tags
396 :    
397 : pazsan 1.8 Variable indentlevel
398 : pazsan 1.10 : indent ( n -- ) indentlevel @ over indentlevel !
399 :     2dup < IF swap DO -env -env LOOP EXIT THEN
400 :     2dup > IF DO s" dl" >env s" dt" >env LOOP EXIT THEN
401 :     2dup = IF drop IF -env s" dt" >env THEN THEN ;
402 : pazsan 1.11 : +indent ( -- ) indentlevel @ IF -env s" dd" >env THEN ;
403 : pazsan 1.8
404 : pazsan 1.1 wordlist constant longtags
405 :    
406 :     longtags set-current
407 :    
408 : pazsan 1.10 : --- 0 indent cr s" hr" tag cr +indent ;
409 : pazsan 1.8 : * 1 indent s" h1" line +indent ;
410 :     : ** 1 indent s" h2" line +indent ;
411 :     : *** 2 indent s" h3" line +indent ;
412 : pazsan 1.10 : -- 0 indent cr print-toc ;
413 : pazsan 1.12 : && 0 parse name= s" " s" a" tagged ;
414 : pazsan 1.1 : - s" ul" env s" li" par ;
415 :     : + s" ol" env s" li" par ;
416 :     : << +env ;
417 : pazsan 1.3 : <* s" center" >env ;
418 : pazsan 1.10 : <red s" #ff0000" s" color" opt s" font" >env ;
419 :     : red> -env ;
420 : pazsan 1.1 : >> -env ;
421 : pazsan 1.3 : *> -env ;
422 : pazsan 1.9 : :: interpret ;
423 : pazsan 1.11 : . end-sec on 0 indent ;
424 : pazsan 1.9 : :code s" pre" >env
425 :     BEGIN source >in @ /string type cr refill WHILE
426 : anton 1.16 source s" :endcode" str= UNTIL THEN
427 : pazsan 1.9 -env ;
428 : pazsan 1.1 : \ postpone \ ;
429 :    
430 :     definitions
431 : pazsan 1.3
432 :     \ Table
433 :    
434 : pazsan 1.13 : |tag table-format $@ table# @ /string drop c@ >talign
435 : pazsan 1.6 >env 1 table# +! ;
436 : pazsan 1.12 : |d table# @ table-start @ > IF -env THEN s" td" |tag ;
437 :     : |h table# @ table-start @ > IF -env THEN s" th" |tag ;
438 :     : |line s" tr" >env table-start @ table# ! ;
439 : pazsan 1.3 : line| -env -env cr ;
440 :    
441 : pazsan 1.5 : next-char ( -- char ) source drop >in @ + c@ ;
442 :    
443 : pazsan 1.3 longtags set-current
444 :    
445 : pazsan 1.12 : <| bl sword table-format $! table-start off bl sword
446 :     dup IF s" border" opt ELSE 2drop THEN s" table" >env ;
447 :     : |> -env -env cr cr ;
448 : pazsan 1.3 : +| |line
449 :     BEGIN
450 : pazsan 1.5 |h '| parse-to next-char '+ = UNTIL line| ;
451 : pazsan 1.3 : -| |line
452 :     BEGIN
453 : pazsan 1.5 |d '| parse-to next-char '- = UNTIL line| ;
454 : pazsan 1.3
455 :     definitions
456 : pazsan 1.1
457 :     \ parse a section
458 :    
459 : pazsan 1.8 : section-line ( -- ) >in off
460 : pazsan 1.9 bl sword longtags search-wordlist
461 :     IF execute
462 : pazsan 1.8 ELSE source nip IF >in off s" p" par THEN THEN ;
463 : pazsan 1.1 : refill-loop ( -- ) end-sec off
464 : pazsan 1.8 BEGIN refill WHILE
465 :     section-line end-sec @ UNTIL THEN ;
466 : pazsan 1.1 : parse-section ( -- )
467 : pazsan 1.9 refill-loop ;
468 : pazsan 1.1
469 :     \ HTML head
470 :    
471 :     : .title ( addr u -- )
472 :     .' <!doctype html public "-//w3c//dtd html 4.0 transitional//en">' cr
473 : pazsan 1.2 s" html" >env s" head" >env
474 : pazsan 1.1 .' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">' cr
475 : pazsan 1.2 s" title" tagged cr
476 : pazsan 1.1 -env ;
477 :    
478 :     \ HTML trailer
479 :    
480 :     Variable mail
481 :     Variable mail-name
482 : pazsan 1.12 Variable orig-date
483 : pazsan 1.1
484 : pazsan 1.20 : .lastmod
485 :     ." Last modified: " time&date rot 0 u.r swap 1-
486 :     s" janfebmaraprmayjunjulaugsepoctnovdec" rot 3 * /string 3 min type
487 :     0 u.r ;
488 :    
489 : pazsan 1.1 : .trailer
490 : pazsan 1.2 s" address" >env s" center" >env
491 : pazsan 1.12 orig-date @ IF ." Created " orig-date $@ type ." . " THEN
492 : pazsan 1.20 .lastmod
493 :     ." by "
494 : pazsan 1.10 s" Mail|icons/mail.gif" .img mail $@ mailto: mail-name $@ s" a" tagged
495 : pazsan 1.1 -envs ;
496 :    
497 :     \ top word
498 :    
499 : pazsan 1.6 : parse" ( -- addr u ) '" parse 2drop '" parse ;
500 :    
501 : pazsan 1.12 : maintainer ( -- )
502 : pazsan 1.6 bl sword mail $! parse" mail-name $! ;
503 : pazsan 1.12 : created ( -- )
504 :     bl sword orig-date $! ;
505 : pazsan 1.6
506 :     Variable style$
507 :     : style> style$ @ 0= IF s" " style$ $! THEN style$ $@ tag-option $! ;
508 :     : >style tag-option $@ style$ $! s" " tag-option $! ;
509 :    
510 :     : style style> opt >style ;
511 :     : background ( -- ) parse" s" background" style ;
512 :     : text ( -- ) parse" s" text" style ;
513 :     warnings @ warnings off
514 :     : link ( -- ) parse" s" link" style ;
515 :     warnings !
516 :     : vlink ( -- ) parse" s" vlink" style ;
517 :     : marginheight ( -- ) parse" s" marginheight" style ;
518 : pazsan 1.1
519 :     : wf ( -- )
520 :     outfile-id >r
521 :     bl sword r/w create-file throw to outfile-id
522 : pazsan 1.6 parse" .title
523 :     +env style> s" body" env env?
524 : pazsan 1.1 ['] parse-section catch .trailer
525 :     outfile-id close-file throw
526 :     r> to outfile-id
527 :     dup 0< IF throw ELSE drop THEN ;
528 :    
529 : pazsan 1.8 : eval-par ( addr u -- )
530 :     s" wf-temp.wf" r/w create-file throw >r
531 :     r@ write-file r> close-file throw
532 :     push-file s" wf-temp.wf" r/o open-file throw loadfile !
533 :     parse-par parse-section
534 :     loadfile @ close-file swap 2dup or
535 :     pop-file drop throw throw
536 :     s" wf-temp.wf" delete-file throw ;
537 :    
538 : pazsan 1.2 \ simple text data base
539 :    
540 :     Variable last-entry
541 :     Variable field#
542 :    
543 :     : table: ( xt n -- ) Create , , 1 field# !
544 :     DOES> 2@ >in @ >r longtags set-current
545 :     Create definitions swap , r> >in !
546 :     here last-entry !
547 :     dup 0 DO 0 , LOOP
548 :     1 DO s" " last-entry @ I cells + $! LOOP
549 :     last-entry @ get-rest
550 :     DOES> dup cell+ swap perform ;
551 :    
552 :     : field: Create field# @ , 1 field# +!
553 :     DOES> @ cells last-entry @ + get-rest ;
554 : pazsan 1.8 : par: Create field# @ , 1 field# +!
555 :     DOES> @ cells last-entry @ + get-par ;
556 : pazsan 1.3
557 :     : >field ' >body @ cells postpone Literal postpone + ; immediate

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help