> what is the most elegant way to read a value out of an ini file?

Actaully reading a windows ini file .....

This is not elegant, but it parses a standard ini file, with a reasonable 
degree of error trapping -- there are some tricky bits as what goes into an INI 
file may not correspond to what REBOL thinks of as a word. And doubtless 
testing on other INI files will throw up other error conditions that need to be 
handled.

;;;=================
 ini-block: copy []
    current-section: copy []
    foreach ini-line read/lines %/c/windows/win.ini
    [section-name: ini-line
        error? try [section-name: first load/all ini-line]
        either any [error? try [block? section-name]
            not block? section-name
        ]
        [parsed-line: parse/all ini-line "="
            append last current-section parsed-line/1
            append last current-section parsed-line/2
        ]
        [append ini-block current-section
            current-section: copy []
            append current-section form section-name
            append/only current-section copy []
        ]
    ]

 
;; samples from my win.ini
 print select/skip select ini-block "ports" "com1:" 2
 print select/skip select ini-block "intl" "iCountry" 2
 print select/skip select ini-block "TrueType" "FontSmoothing" 2
;;;=================


Sunanda.
-- 
To unsubscribe from this list, just send an email to
[EMAIL PROTECTED] with unsubscribe as the subject.

Reply via email to