Hi Rebols,

today I played around with 'parse and it's dialect.

Out came a script (attached) that splits the rebol %dictionary.html into many
little files - one word, one file - and organizes them in frames for easier
(IMHO :) navigation.

Maybe this is of some use for you, too? 
If so, I'll eventually submit it to the rebol.org script library. Any comments
or suggestions for an improved version?

Don't judge the source in it's current state, it's QAVVD - quick and very,
very dirty ;-) 


Yours,
Christian Ensel
[EMAIL PROTECTED]


REBOL [
    title:   "Dictionary Splitter"
    name:    %dictsplit.r
    author:  "Christian 'CHE' Ensel"
    date:    5-Mar-2000
    purpose: {
        Creates numerous cute litte html doc files from the all
        in one  rebol dictionary (i.e. one file  for each rebol 
        defined word) -- thus,  even on my AMIGA 68EC030 / 10MB
        (anyone laughing ...?)  I'm now able to browse the docs
        with ease.
            Even on bigger machines  navigation may get easier,
        because I added two navigation bars.
    }
    usage: {
        1. Adjust hardcoded paths to your needs
        2. DO the script
        3. Bookmark the file %main.html
    }
    version: 0.0.1
    history: [
        5-Mar-2000 "First QAD working version - CHE"
    ]
    category: ['script 'general]
]

;----- adjust to your needs -----

dictpath: %/rebol/documentation/                    ;-- this dir is created
dict:     %/rebol/dictionary.html

;--------------------------------

make-dir dictpath

frameset-source: decompress #{
    789C6D90CD0AC2300C80EF3E45C851C46E536FED40D19B20F806758BAED0AD90
    16866F6FB73A86B85B12BE7CF9914D686DB902900DE97A0862184CB054DE2FA7
    DB15CEA60AC6759ADF52A4FA008B89964FD62D790AC0AEF70A8B6CB3467838AE
    891566F8358E1478AE1432BD8C0FC4DB613296B3A072360AF26CD1F0EBD0A919
    BA5851D847D646E7227ACC8BDDFEF0C74F8B89697C3A6BCEE289E3673E604B56
    A221010000
}

write join dictpath "main.html" frameset-source

register-source: decompress #{
    789C75D4CF6E82401006F0BB4FB159EFE505165211501445F1BFB7555621A192
    6C37697DFB8AB5977EF9E634C9FC66E6F6A9CA7D34414F0855195D76CDA375B5
    6B4C50C4619E89A83EBBBABD697B17E9AD34DFCAFB9D762BDEDF8E3AB5E55D9C
    AEE7B669AD2FFBC9B3E4EB9C169535175F0EDEBA6752386DAFC6F9F2ABB56553
    7F3A190C94A7FFE190E210F190E221E288E208714C718C38A138413CA2788478
    4CF118714A718A7842F104F194E229E28CE20CF18CE219E239C573C439C539E2
    05C50BC44B8A97880B8A0BC42B8A5788D714AF116F28DE20DE52BC45BCA37887
    784FF11EF181E203E223C547C4EF14F75F58795DB405BD47D63D83F207CDDF96
    AB30050000
}

write join dictpath "register.html" register-source

template-source: decompress #{
    789CB3F108F1F5B1E35250B0F1707574013180CC10CF101F573B1B455D5D0530
    534157D7CE461F220A52AA0F536BE3E4EF12A9E0E4EEECEFE31F64ABA4EC0606
    4A506340FA9DFDFD425CFD42402680758234D871014D00590B00DEB31BEC7D00
    0000
}

append dictionary: read dict {<A NAME}

parse dictionary [
    thru <center>
    thru <center>
    copy index 
    to </center>
]
parse index [
    some [
        to {<td} start: 
        thru {>} stop: 
        (change/part start {} stop)
    ]
]
replace/all index {<TABLE WIDTH="80%" BORDER="0">} {}
replace/all index {<p>}                            {}
replace/all index {</TABLE>}                       {}
replace/all index {<tr>}                           {}
replace/all index {</td>}                          {<BR>^/}
replace/all index {</tr>}                          {}
replace/all index {<b>}                            {}
replace/all index {</b>}                           {}
replace/all index {"#}                             {"}
replace/all index {">}                             {.html" TARGET="word">}
    
;-- now split list depending on first char --
    
wl-storage: array 27

while [
    line: none parse index [to "<" copy line thru "<br>"] not none? line
] [ 
    char: (to-integer to-char uppercase to-string select line ">") - 64
    either (1 <= char) and (char <= 26) [
        ;-- letter
        either none? wl-storage/:char [ 
            poke wl-storage char join line newline
        ] [
            append wl-storage/:char join line newline
        ]  
    ] [
        ;-- no-letter
        either none? wl-storage/27 [ 
            poke wl-storage 27 join line newline
        ] [
            append wl-storage/27 join line newline
        ]  
    ]
    replace index line {}      
] 

for i 1 27 1 [
    wl: copy template-source
    replace wl {<!-- CONTENT -->} wl-storage/:i
    replace wl {<!-- TITLE -->} title: either i = 27 ["@"][to-string to-char (i + 64)]
    file: join dictpath join title ".html"
    print ["Writing file " file]
    write file wl
]

while [dictionary <> {}] [
    parse dictionary [thru {<A NAME} copy card to {<A NAME}]
    parse card [thru {="} copy id to {"}]
    ;-- get rebol word 
    parse card [thru <FONT COLOR="black"> copy title to </FONT>]
    ;-- adjust links
    parse card [
        some [
            to {<A HREF="#} copy link start: thru {">} stop:
            (replace link {="#} {="} replace link {">} {.html">} 
            change/part start link stop)
        ]
    ]  
    card: find/tail card {</A>}  
    print ["Found card for word" title ", saving as" join id ".html" "..."]
    
    source: copy template-source
    replace source {<!-- CONTENT -->} card
    replace source {<!-- TITLE -->} title
    write join dictpath join id ".html" source
    
    dictionary: find/tail dictionary {<A NAME}
]

true

Reply via email to