\ File: ini.spf \ Author: Nicholas Nemtsev, Valery Kondakoff (based on Alan West idea) \ Date: 12.05.2004 \ Description: Words for retrieving/setting a string from/to the \ specified section in an ini-file. A section in the \ initialization file must have the following form: \ [section] \ key=string \ . \ . \ . \ Usage: first specify the ini-filename and ini-section: \ S" file_name" INI-FILENAME \ S" section_name" INI-SECTION \ then use INI-GET-VALUE/INI-SET-VALUE to retrieve/set the \ specified value: \ S" key_name" INI-GET-VALUE \ S" key_name" S" key_value" INI-SET-VALUE \ Example: \ #( test-get-set-ini \ NoActive \ : ini-key-name S" first_key" ; \ : ini-key-name2 S" second_key" ; \ Action: \ S" c:\temp\test.ini" INI-FILENAME \ S" first_section" INI-SECTION \ ini-key-name S" first value" INI-SET-VALUE \ ini-key-name2 S" second value" INI-SET-VALUE \ MSG: "first_section/first_key=%ini-key-name INI-GET-VALUE%" \ MSG: "first_section/second_key=%ini-key-name INI-GET-VALUE%" \ )# WINAPI: GetPrivateProfileStringA KERNEL32.DLL WINAPI: WritePrivateProfileStringA KERNEL32.DLL USER INI_FileName USER INI_SectionName : INI-FILENAME ( a u -- ) S>ZALLOC INI_FileName ! ; : INI-SECTION ( a u -- ) S>ZALLOC INI_SectionName ! ; : INI-GET-VALUE ( a1 u1 -- a2 u2 ) { \ key val -- } S>ZTEMP TO key 256 TEMP-ALLOC TO val INI_FileName @ 255 val Z" default value" key INI_SectionName @ GetPrivateProfileStringA val SWAP ; : INI-SET-VALUE ( a1 u1 a2 u2 -- ) { \ key val -- } S>ZTEMP TO val S>ZTEMP TO key INI_FileName @ val key INI_SectionName @ WritePrivateProfileStringA DROP ;