' Config reader: read #DEFINE values from a config header at compile time
#COMPILE EXE
#DIM ALL

CONST CONFIG_APP_NAME = 1
CONST CONFIG_VERSION_MAJOR = 2
CONST CONFIG_VERSION_MINOR = 3
CONST CONFIG_MAX_USERS = 4
CONST CONFIG_TIMEOUT_SECS = 5
CONST CONFIG_ENABLE_SSL = 6
CONST CONFIG_LOG_LEVEL = 7
CONST CONFIG_DB_PORT = 8
CONST CONFIG_CACHE_SIZE = 9
CONST CONFIG_DEBUG_MODE = 10
FUNCTION PBMAIN() AS LONG
    LOCAL i  AS LONG
    LOCAL numConfigs  AS LONG
    LOCAL configKey(20) AS LONG
    LOCAL configName(20) AS STRING
    LOCAL configValue(20) AS LONG
    LOCAL configStr(20) AS STRING
    LOCAL s  AS STRING
    LOCAL v  AS STRING
    LOCAL dbPort  AS LONG
    LOCAL cacheSize  AS LONG
    LOCAL maxUsers  AS LONG
    LOCAL timeoutSecs AS LONG
    LOCAL enableSSL  AS LONG
    LOCAL debugMode  AS LONG
    PRINT "=== Config Reader ==="
    PRINT
    PRINT "Reading configuration from compile-time #DEFINE values"
    PRINT

    numConfigs = 10
    configKey(0) = 1
    configName(0) = "APP_NAME                        "
    configValue(0) = 0
    configStr(0) = "MyApplication                   "

    configKey(1) = 2
    configName(1) = "VERSION_MAJOR                   "
    configValue(1) = 2
    configStr(1) = "                                "

    configKey(2) = 3
    configName(2) = "VERSION_MINOR                   "
    configValue(2) = 5
    configStr(2) = "                                "

    configKey(3) = 4
    configName(3) = "MAX_USERS                       "
    configValue(3) = 1000
    configStr(3) = "                                "

    configKey(4) = 5
    configName(4) = "TIMEOUT_SECS                    "
    configValue(4) = 30
    configStr(4) = "                                "

    configKey(5) = 6
    configName(5) = "ENABLE_SSL                      "
    configValue(5) = 1
    configStr(5) = "                                "

    configKey(6) = 7
    configName(6) = "LOG_LEVEL                       "
    configValue(6) = 2
    configStr(6) = "                                "

    configKey(7) = 8
    configName(7) = "DB_PORT                         "
    configValue(7) = 5432
    configStr(7) = "                                "

    configKey(8) = 9
    configName(8) = "CACHE_SIZE                      "
    configValue(8) = 65536
    configStr(8) = "                                "

    configKey(9) = 10
    configName(9) = "DEBUG_MODE                      "
    configValue(9) = 0
    configStr(9) = "                                "

    PRINT "--- Configuration Values ---"
    FOR i = 0 TO numConfigs - 1
        s = TRIM$(configName(i))
        v = TRIM$(configStr(i))
        IF LEN(v) > 0 THEN
            PRINT "  " & s & " = " & v
        ELSE
            PRINT "  " & s & " = " & FORMAT$(configValue(i))
        END IF
    NEXT i
    PRINT

    maxUsers = 1000
    timeoutSecs = 30
    dbPort = 5432
    cacheSize = 65536
    enableSSL = 1
    debugMode = 0

    PRINT "--- Applied Configuration ---"
    PRINT "  Application: MyApplication v" & FORMAT$(2) & "." & FORMAT$(5)
    PRINT "  Max users: " & FORMAT$(maxUsers)
    PRINT "  Timeout: " & FORMAT$(timeoutSecs) & " seconds"
    PRINT "  Database port: " & FORMAT$(dbPort)
    PRINT "  Cache size: " & FORMAT$(cacheSize) & " bytes"
    PRINT "  SSL enabled: "
    IF enableSSL = 1 THEN
        PRINT "    Yes"
    ELSE
        PRINT "    No"
    END IF
    PRINT "  Debug mode: "
    IF debugMode = 1 THEN
        PRINT "    Yes"
    ELSE
        PRINT "    No"
    END IF

    PRINT
    PRINT "--- Config Source Simulation ---"
    PRINT "To change config, edit defines at top of file:"
    PRINT "  CONFIG_MAX_USERS = 500"
    PRINT "  CONFIG_TIMEOUT_SECS = 60"
    PRINT "Then recompile."

    PRINT
    PRINT "Config reader demonstration complete."

    FUNCTION = 0
END FUNCTION
