Code archives/Miscellaneous/AppSettings module

This code has been declared by its author to be Public Domain code.

Download source code

AppSettings module by JoshK2007
This module allows you to pass parameters to the program in the command line, as follows:

YourApp.exe +map "dm01"

When you call AppSetting("map") in the program, "dm01" will be returned.

Some settings don't need to pass a value:

YourApp.exe -fullscreen

When you call AppSetting("fullscreen") in the program, "1" will be returned.

You can specify a default value to return if the setting has not be specified. Setting names are not case-sensitive.
Import brl.map
Import brl.retro

Rem
bbdoc:
End Rem
Module leadwerks.appsettings

Private

Global AppSettings:TMap=New TMap

Function ParseAppArgs()
	For n=1 To AppArgs.length-1
		indicator$=Left(AppArgs[n],1)
		key$=Lower(Right(AppArgs[n],AppArgs[n].length-1))
		Select indicator$
			Case "+"
				n:+1
				If n>=AppArgs.length Exit
				value$=AppArgs[n]
				SetAppSetting key,value
			Case "-"
				SetAppSetting key,"1"
		EndSelect
	Next
EndFunction

Public

ParseAppArgs()

Rem
bbdoc:
End Rem
Function AppSetting$(key$,defaultvalue$="")
	If key="" Return
	key=Lower(key)
	value$=String(AppSettings.valueforkey(key$))
	If value=""
		Return defaultvalue
	Else
		Return value
	EndIf
EndFunction

Comments

None.

Code Archives Forum