1
1
Fork 0
mirror of https://github.com/QB64Official/qb64.git synced 2024-05-12 12:00:14 +00:00

Compare commits

...

2 commits

Author SHA1 Message Date
Cory Smith f77cee413f
Merge pull request #39 from DualBrain/master
Moved config related functions to the new config.bas file.
2022-11-07 19:01:24 -06:00
Cory Smith 391b6178b8 Moved config related functions to the new config.bas file. 2022-10-07 10:17:15 -05:00
3 changed files with 102 additions and 97 deletions

View file

@ -25752,15 +25752,6 @@ SUB Give_Error (a$)
Error_Message = a$
END SUB
SUB WriteConfigSetting (section$, item$, value$)
WriteSetting ConfigFile$, section$, item$, value$
END SUB
FUNCTION ReadConfigSetting (section$, item$, value$)
value$ = ReadSetting$(ConfigFile$, section$, item$)
ReadConfigSetting = (LEN(value$) > 0)
END FUNCTION
FUNCTION VRGBS~& (text$, DefaultColor AS _UNSIGNED LONG)
'Value of RGB String = VRGBS without a ton of typing
'A function to get the RGB value back from a string such as _RGB32(255,255,255)
@ -26309,7 +26300,13 @@ SUB increaseUDTArrays
REDIM _PRESERVE udtenext(x + 1000) AS LONG
END SUB
' Generic method (can be used outside of QB64) includes:
'$INCLUDE:'utilities\strings.bas'
' Custom method (designed specifically for QB64) includes:
'$INCLUDE:'utilities\config.bas'
'$INCLUDE:'utilities\file.bas'
'$INCLUDE:'subs_functions\extensions\opengl\opengl_methods.bas'
'$INCLUDE:'utilities\ini-manager\ini.bm'

View file

@ -0,0 +1,84 @@
SUB WriteConfigSetting (section$, item$, value$)
WriteSetting ConfigFile$, section$, item$, value$
END SUB
FUNCTION ReadConfigSetting (section$, item$, value$)
value$ = ReadSetting$(ConfigFile$, section$, item$)
ReadConfigSetting = (LEN(value$) > 0)
END FUNCTION
' Convert a boolean value to 'True' or 'False'.
FUNCTION BoolToTFString$ (b AS LONG)
IF b THEN BoolToTFString$ = "True" ELSE BoolToTFString$ = "False"
END FUNCTION
' Convert 'True' or 'False' to a boolean value.
' Any string not 'True' or 'False' is returned as -2.
FUNCTION TFStringToBool% (s AS STRING)
SELECT CASE _TRIM$(UCASE$(s))
CASE "TRUE": TFStringToBool% = -1
CASE "FALSE": TFStringToBool% = 0
CASE ELSE: TFStringToBool% = -2
END SELECT
END FUNCTION
' Reads the bool setting at section:setting.
' If it is not there or invalid, writes the default value to it.
FUNCTION ReadWriteBooleanSettingValue% (section AS STRING, setting AS STRING, default AS INTEGER)
DIM checkResult AS INTEGER
DIM value AS STRING
DIM result AS INTEGER
result = ReadConfigSetting(section, setting, value)
checkResult = TFStringToBool%(value)
IF checkResult = -2 THEN
WriteConfigSetting section, setting, BoolToTFString$(default)
ReadWriteBooleanSettingValue% = default
ELSE
ReadWriteBooleanSettingValue% = checkResult
END IF
END FUNCTION
' Reads the string setting at section:setting.
' If it is not there or invalid, writes the default value to it.
FUNCTION ReadWriteStringSettingValue$ (section AS STRING, setting AS STRING, default AS STRING)
DIM value AS STRING
DIM result AS INTEGER
result = ReadConfigSetting(section, setting, value)
IF result = 0 THEN
WriteConfigSetting section, setting, default
ReadWriteStringSettingValue$ = default
ELSE
ReadWriteStringSettingValue$ = value
END IF
END FUNCTION
' Reads the integer setting at section:setting.
' If it is not there or invalid, writes the default value to it.
' Verifies the value is positive and non-zero.
FUNCTION ReadWriteLongSettingValue& (section AS STRING, setting AS STRING, default AS LONG)
DIM value AS STRING
DIM result AS INTEGER
DIM checkResult AS LONG
result = ReadConfigSetting(section, setting, value)
checkResult = VAL(value)
IF result = 0 OR checkResult <= 0 THEN
WriteConfigSetting section, setting, str2$(default)
ReadWriteLongSettingValue& = default
ELSE
ReadWriteLongSettingValue& = checkResult
END IF
END FUNCTION

View file

@ -1,5 +1,11 @@
''' String manipulation functions
FUNCTION StrRemove$ (myString$, whatToRemove$) ' noncase sensitive
' String Extensions
' Please reserve this module for only string methods that can be
' utilized outside of QB64. Meaning, anyone could add this to their
' personal project and leverage the same functionality.
' Removes a string pattern from an existing string (case-insensitive).
FUNCTION StrRemove$ (myString$, whatToRemove$)
DIM a$, b$
DIM AS LONG i
a$ = myString$
@ -12,7 +18,8 @@ FUNCTION StrRemove$ (myString$, whatToRemove$) ' noncase sensitive
StrRemove$ = a$
END FUNCTION
FUNCTION StrReplace$ (myString$, find$, replaceWith$) ' noncase sensitive
' Replaces a string pattern within an existing string (case-insensitive).
FUNCTION StrReplace$ (myString$, find$, replaceWith$)
DIM a$, b$
DIM AS LONG basei, i
IF LEN(myString$) = 0 THEN EXIT FUNCTION
@ -28,90 +35,7 @@ FUNCTION StrReplace$ (myString$, find$, replaceWith$) ' noncase sensitive
StrReplace$ = a$
END FUNCTION
' Adds quotation (ASCII 034) marks around a string.
FUNCTION AddQuotes$ (s$)
AddQuotes$ = CHR$(34) + s$ + CHR$(34)
END FUNCTION
' Convert a boolean value to 'True' or 'False'.
FUNCTION BoolToTFString$ (b AS LONG)
IF b THEN
BoolToTFString$ = "True"
ELSE
BoolToTFString$ = "False"
END IF
END FUNCTION
' Convert 'True' or 'False' to a boolean value.
' Any string not 'True' or 'False' is returned as -2.
FUNCTION TFStringToBool% (s AS STRING)
DIM s2 AS STRING
s2 = _TRIM$(UCASE$(s))
IF s2 = "TRUE" THEN
TFStringToBool% = -1
ELSEIF s2 = "FALSE" THEN
TFStringToBool% = 0
ELSE
TFStringToBool% = -2
END IF
END FUNCTION
''' Reads the bool setting at section:setting.
''' If it is not there or invalid, writes the default value to it.
FUNCTION ReadWriteBooleanSettingValue% (section AS STRING, setting AS STRING, default AS INTEGER)
DIM checkResult AS INTEGER
DIM value AS STRING
DIM result AS INTEGER
result = ReadConfigSetting(section, setting, value)
checkResult = TFStringToBool%(value)
IF checkResult = -2 THEN
WriteConfigSetting section, setting, BoolToTFString$(default)
ReadWriteBooleanSettingValue% = default
ELSE
ReadWriteBooleanSettingValue% = checkResult
END IF
END FUNCTION
''' Reads the string setting at section:setting.
''' If it is not there or invalid, writes the default value to it.
FUNCTION ReadWriteStringSettingValue$ (section AS STRING, setting AS STRING, default AS STRING)
DIM value AS STRING
DIM result AS INTEGER
result = ReadConfigSetting(section, setting, value)
IF result = 0 THEN
WriteConfigSetting section, setting, default
ReadWriteStringSettingValue$ = default
ELSE
ReadWriteStringSettingValue$ = value
END IF
END FUNCTION
''' Reads the integer setting at section:setting.
''' If it is not there or invalid, writes the default value to it.
''' Verifies the value is positive and non-zero.
FUNCTION ReadWriteLongSettingValue& (section AS STRING, setting AS STRING, default AS LONG)
DIM value AS STRING
DIM result AS INTEGER
DIM checkResult AS LONG
result = ReadConfigSetting(section, setting, value)
checkResult = VAL(value)
IF result = 0 OR checkResult <= 0 THEN
WriteConfigSetting section, setting, str2$(default)
ReadWriteLongSettingValue& = default
ELSE
ReadWriteLongSettingValue& = checkResult
END IF
END FUNCTION
END FUNCTION