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

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help