Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Newbie questions

From: SunandaDH:aol at: 2-Oct-2003 19:22

> 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.