File:  [gforth] / gforth / wf.fs
Revision 1.27: download - view: text, annotated - select for diffs
Sun Aug 29 20:54:48 2004 UTC (19 years, 6 months ago) by pazsan
Branches: MAIN
CVS tags: HEAD
Added alternative icons directory

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>