Read a configuration file: Difference between revisions

m
m (→‎{{header|Wren}}: Minor tidy)
 
(3 intermediate revisions by 2 users not shown)
Line 1,928:
: # ( -- ) 1 PARSE 2DROP ; \ parse line and throw away
: = ( addr --) 1 PARSE trim ROT PLACE ; \ string assignment operator
synonym' ;# alias ; # \ 2nd comment operator is simple
 
FORTH DEFINITIONS
Line 1,971:
Rhu Barber
Harry Barber ok</PRE>
 
Note that parsing a config file using the forth text interpreter this way is probably only safe if you are the only one that edits the config file, as it can execute any forth word.
 
=={{header|Fortran}}==
Line 2,191 ⟶ 2,193:
Other family(0) = Rhu Barber
Other family(1) = Harry Barber
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn SaveConfiguration
CFDictionaryRef defaults = @{¬
@"FULLNAME" : @"Foo Barber",¬
@"FAVOURITEFRUIT" : @"banana",¬
@"NEEDSPEELING" : @YES,¬
@"SEEDSREMOVED" : @NO,¬
@"OTHERFAMILY" : @[@"Rhu Barber", @"Harry Barber"]}
UserDefaultsRegisterDefaults( defaults )
end fn
 
local fn ReadConfiguration
CFStringRef tempStr
CFStringRef fullname = fn UserDefaultsString( @"FULLNAME" )
CFStringRef favouritefruit = fn UserDefaultsString( @"FAVOURITEFRUIT" )
BOOL needspeeling = fn UserDefaultsBool( @"NEEDSPEELING" )
BOOL seedsremoved = fn UserDefaultsBool( @"SEEDSREMOVED" )
CFArrayRef otherfamily = fn UserDefaultsArray( @"OTHERFAMILY" )
printf @"Saved configuration:\n"
printf @"FULLNAME: %@", fullname
printf @"FAVOURITEFRUIT: %@", favouritefruit
if needspeeling == YES then tempStr = @"TRUE" else tempStr = @"FALSE"
printf @"NEEDSPEELING: %@", tempStr
if seedsremoved == YES then tempStr = @"TRUE" else tempStr = @"FALSE"
printf @"SEEDSREMOVED: %@", @"(undefined)"
printf @"OTHERFAMILY: %@, %@", otherfamily[0], otherfamily[1]
end fn
 
fn SaveConfiguration
fn ReadConfiguration
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Saved configuration:
 
FULLNAME: Foo Barber
FAVOURITEFRUIT: banana
NEEDSPEELING: TRUE
SEEDSREMOVED: (undefined)
OTHERFAMILY: Rhu Barber, Harry Barber
</pre>
 
Line 5,757 ⟶ 5,807:
{{libheader|Wren-ioutil}}
Includes 'seeds removed' in the map (with a default value of false) even though it's commented out of the configuration file.
<syntaxhighlight lang="ecmascriptwren">import "io" for File
import "./ioutil" for FileUtil
 
class Configuration {
9,476

edits