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

CVS Admin

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help