'******************************************************************************
'                       BCX - The Basic To C/C++ Translator
'            Copyright 1999-2026 Kevin Diggins  (All Rights Reserved)
'           Significant contributors to the BCX project have included:
' (Devs) Robert Wishlaw, Mike Henning, Wayne Halsdorf (RIP), Ljubisa Knezevic
' (Hosting)     Jeff Shollenberger, Fernando Ortiz (RIP), Dave Navarro
'******************************************************************************
'      BCX is distributed under the general conditions of the MIT License.
'                https://en.wikipedia.org/wiki/MIT_License
'******************************************************************************
' Permission is hereby granted, free of charge, to any person obtaining a copy
' of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights
' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is
' furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all
' copies or substantial portions of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
' OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
' FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
' IN THE SOFTWARE.
'******************************************************************************
$NOINI                                    ' Do not use BCX.ini, if one exists
$IPRINT_OFF                               ' Disable "\" to "\\" conversions
$WARNINGS_ON                              ' Enable compiler warnings
$NO_VKKEYS                                ' Do not output VKKEY definitions
$NO_LCCWIN                                ' Lcc-Win32 can't bootstrap anymore
'*******************************************************************************
MACRO __BCX__      = TRUE                 ' Tell BCX we are translating BC.bas
MACRO c_BCX_COLORS = TRUE                 ' Colorize (or not) BCX's output
MACRO c_BCXSTRINGS = 2048                 ' Default size for static string vars
MACRO c_VERSION$   = "8.3.8 (07/31/2026)" ' Embed this into the executable
'*******************************************************************************
'  These BCX_STR equates are to remind BCX code maintainers from accidently
'  changing certain output lines of code that are used for $PROJECT SUPPORT.
'*******************************************************************************
MACRO c_$BCX_STR_MAIN_PROG   = "Main Program"
MACRO c_$BCX_STR_RUNTIME     = "Runtime Functions"
MACRO c_$BCX_STR_VBS_STRUCTS = "VBScript Support Structures"
MACRO c_$BCX_STR_SYS_CONST   = "Runtime Library Macros"
MACRO c_$BCX_STR_STD_MACROS  = "Runtime Library Macros"
MACRO c_$BCX_STR_SYS_VARS    = "Runtime Library Variables"
MACRO c_$BCX_STR_STD_PROTOS  = "Runtime Library Function Prototypes"
MACRO c_$BCX_STR_USR_CONST   = "Application Macros"
MACRO c_$BCX_STR_USR_TYPES   = "Application Types And Unions"
MACRO c_$BCX_STR_USR_VARS    = "Application Global Variables"
MACRO c_$BCX_STR_USR_PROCS   = "Application Subs and Functions"
MACRO c_$BCX_STR_USR_PROTOS  = "Application Function Prototypes"
'*******************************************************************************
'           An assortment of macros used throughout the translator
'*******************************************************************************
MACRO m_IAm(X)               = ((X)<>1)
MACRO m_IAmNot(X)            = ((X)==0)
MACRO m_IDont(X)             = ((X)==0)
MACRO m_GetAsPosF(S, E)      = GetAsPos((S), (E), (1))
MACRO m_GetAsPosB(S, E)      = GetAsPos((S), (E), (-1))
MACRO m_iMatchLft(A, B)      = iMatch((A), (B), (0))
MACRO m_iMatchWrd(A, B)      = iMatch((A), (B), (1))
MACRO m_iMatchRgt(A, B)      = iMatch((A), (B), (2))
MACRO m_WordsInTable(A)      = (SIZEOF(A)/SIZEOF(A[0]))
MACRO m_GetBrkPairPos(S, E)  = GetBracketPair((S), (E), (1))
MACRO m_IVAL(A)              = atol((PCHAR)(A))
MACRO c_FULLSET              = " ;().=,{}<>+-[]*/':|&?^"     ' Used w/ FastLexer
MACRO c_PADSIZE              = 1                    ' Spaces after DIM datatypes
'*******************************************************************************
'                           User Defined Type Support
'*******************************************************************************
MACRO c_MaxTypes           =  2048      ' Max UDTS
MACRO c_MaxElements        =   128      ' Max UDT-Members
MACRO c_MaxLocalVars       = 16384      ' Max LOCALS
MACRO c_MaxGlobalVars      = 16384      ' Max GLOBALS
MACRO c_MaxLib             =    64      ' Max LIBRARIES
MACRO c_MaxSrcLen          = 0x100000   ' 1 megabyte limit for special strings
'*******************************************************************************
'                               Bracket Handling
'*******************************************************************************
MACRO c_SglQt             =   39
MACRO c_DblQt             =   34
MACRO c_LPar              =   40
MACRO c_RPar              =   41
MACRO c_Comma             =   44
MACRO c_LtBkt             =   91
MACRO c_RtBkt             =   93
'*******************************************************************************
ENUM
    vt_UNKNOWN             '  Not a Variable
    vt_STRLIT              '  "Quoted String Literal"
    vt_INTEGER             '  Integer%
    vt_SINGLE              '  Single!
    vt_DOUBLE              '  Double#
    vt_LDOUBLE             '  Long Double`
    vt_LLONG               '  Long Long
    vt_STRVAR              '  StringVariable$
    vt_DECFUNC             '  Translated Decimal Func: Strlen,Asin
    vt_NUMBER              '  A Pure Literal Number
    vt_FILEPTR             '  @ FILE*
    vt_UDT                 '  User ( or Windows ) Defined Type
    vt_STRUCT              '  Structures
    vt_UNION               '  Unions
    vt_PSTR                '  Pointer to string
    vt_BOOL                '  Bool
    vt_CHAR                '  8-bit unsigned char
    vt_SCHAR               '  8-bit signed char
    vt_PSTRPTR             '  pointer to string array
    vt_PCHAR               '  pointer to char
    vt_CHARPTR             '  pointer to char
    vt_VOID                '  null
    vt_LONG                '  32-bit signed integer
    vt_WORD                '  16-bit unsigned integer
    vt_DWORD               '  32-bit unsigned integer
    vt_FARPROC             '  Pointer to a function
    vt_PBYTE               '  pointer to a byte
    vt_LRESULT             '  32/64-bit signed integer
    vt_BYTE                '  byte
    vt_SHORT               '  16-bit signed integer
    vt_SSHORT              '  16-bit signed short
    vt_USHORT              '  16-bit unsigned integer
    vt_UINT                '  unsigned 32-bit integer
    vt_ULONG               '  unsigned 32-bit integer
    vt_ULONGLONG           '  unsigned 64-bit integer
    vt_HWND                '  32/64-bit pointer
    vt_HDC                 '  32/64-bit pointer
    vt_COLORREF            '  32-bit unsigned integer
    vt_HANDLE              '  32/64-bit pointer
    vt_HINSTANCE           '  32/64-bit pointer
    vt_BITMAPINFO          '  32/64-bit Windows handle
    vt_HBITMAP             '  32/64-bit Windows handle
    vt_WNDCLASSEX          '  32/64-bit pointer
    vt_HFONT               '  32/64-bit pointer
    vt_CONSTRDESTR         '  BCX identifier for CONSTRUCTOR/DESTRUCTOR
    vt_VARIANT_BOOL        '  Bool types identifier
    vt__VARIANT_BOOL       '  Bool values identifier
    vt_SCODE               '  unsigned 32-bit integer
    vt_CY                  '  signed 64-bit integer representing a currency value
    vt_DATE                '  32-bit composite variable representing a date and time
    vt_BSTR                '  32-bit composite variable representing an OLE  string
    vt_IUnknown            '  32/64-bit pointer to an IUnknown interface pointer
    vt_IDispatch           '  32/64-bit pointer to an IDispatch pointer
    vt_SAFEARRAY           '  32/64-bit pointer to a SAFEARRAY structure
    vt_PVOID               '  32/64-bit void pointer
    vt_DECIMAL             '  32/64-bit pointer to a DECIMAL member of a VARIANT structure
    vt_DOCINFO             '  32/64-bit pointer to a DOCINFO structure
    vt_LOGFONT             '  32/64-bit pointer
    vt_TEXTMETRIC          '  32/64-bit pointer to a TEXTMETRIC structure
    vt_WINBOOL             '  Alias for BOOL
    vt_VARIANT             '  32/64-bit pointer to a VARIANT structure
END ENUM

'*******************************************************************************
MACRO c_vt_VarMin = 2
MACRO c_vt_VarMax = vt_VARIANT
'*******************************************************************************

ENUM                      ' OSVersion return values
    OSUnknown = (-2)
    OSError   = (-1)
    OS_3x                  ' 0
    OS_95                  ' 1
    OS_98                  ' 2
    OS_ME                  ' 3
    OS_NT3                 ' 4
    OS_2000                ' 5
    OS_XP                  ' 6
    OS_XP_Pro_x64          ' 7
    OS_Server_2003         ' 8
    OS_Home_Server         ' 9
    OS_Server_2003_R2      ' 10
    OS_Vista               ' 11
    OS_Server_2008         ' 12
    OS_Server_2008_R2      ' 13
    OS_Win_7               ' 14
    OS_Server_2012         ' 15
    OS_Win_8               ' 16
    OS_Win_81              ' 17
    OS_Server_2012_R2      ' 18
    OS_Win_10              ' 19
    OS_Server_2016         ' 20
    OS_Win_11              ' 21
    OS_Server_2019         ' 22
    OS_Server_2022         ' 23
END ENUM

'*******************************************************************************
ENUM  ' InFunction types
    eFunctionType = (1)
    eSubType
END ENUM
'*******************************************************************************

ENUM  ' SUB Emit_If_Cond types
    ePart
    eFull
END ENUM

'*******************************************************************************

ENUM                        '***** MEMSET/STATIC Truth Table ******
    ImDim       = 0x0001    '  DIM         A        MEMSET  STATIC
    ImLocal     = 0x0002    '  LOCAL       B        MEMSET  STATIC
    ImRaw       = 0x0004    '  RAW         C
    ImStatic    = 0x0008    '  STATIC      D                STATIC
    ImAuto      = 0x0010    '  AUTO        E        MEMSET
    ImRegister  = 0x0020    '  REGISTER    F
    ImCPPPrvDim = 0x0040    '  ImCPPPrvDim
END ENUM

'*******************************************************************************

ENUM
    mt_ProcessSetCommand
    mt_FuncSubDecC_Dec
    mt_FuncSubDecC_DecAParam
    mt_FuncSubDecC_DecNoParam
    mt_Opts
    mt_OptsAParam
    mt_OptsNoParam
    mt_OverLoad
    mt_OverLoadAParam
    mt_OverLoadNoParam
    mt_ConsDes
    mt_ConsDesAParam
    mt_ConsDesNoParam
END ENUM


ENUM
    eDoNothing
    eStartSysVariables
    eDoSysVariables
    eStartUserVariables
    eDoUserVariables
    eStartMacros
    eDoMacros
    eStartStdProtos
    eDoStdProtos
    eStartUserProtos
    eDoUserProtos
    eStartUserConst
    eDoUserConst
    eStartSysConst
    eDoSysConst
    eDoMainProgram
    eDoUserProcs
    eStartUserTypes
    eDoUserTypes
END ENUM


'*******************************************************************************
'                  Variable types for COM, OLE and VARIANT
'*******************************************************************************
ENUM
    comvt_BAD = (-1)
    comvt_TRUE
    comvt_FALSE
    comvt_BOOL
    comvt__VARIANT_BOOL
    comvt_BSTR
    comvt_STRVAR
    comvt_R4
    comvt_R8
    comvt_R8_LITERAL
    comvt_CY
    comvt_DATE
    comvt_DISPATCH
    comvt_PVOID
    comvt_ERROR
    comvt_VARIANT
    comvt_UNKNOWN
    comvt_DECIMAL
    comvt_I1
    comvt_UI1
    comvt_I2
    comvt_UI2
    comvt_I4
    comvt_I4_LITERAL
    comvt_UI4
    comvt_I8
    comvt_UI8
    comvt_INT
    comvt_UINT
    comvt_VOID
    comvt_OBJECT
    comvt_EMPTY
    comvt_NULL
    comvt_HRESULT
    comvt_PTR
    comvt_SAFEARRAY
    comvt_CARRAY
    comvt_USERDEFINED
    comvt_PSTR
    comvt_PWSTR
    comvt_RECORD
    comvt_INT_PTR
    comvt_UINT_PTR
    comvt_FILETIME
    comvt_BLOB
    comvt_STREAM
    comvt_STORAGE
    comvt_STREAMED_OBJECT
    comvt_STORED_OBJECT
    comvt_BLOB_OBJECT
    comvt_CF
    comvt_CLSID
    comvt_VERSIONED_STREAM
    comvt_BSTR_BLOB
    comvt_NAMED_ARGUMENT
    comvt_CAST
    comvt_DEFAULT
    comvt_VECTOR   = 0x1000  ' unused
    comvt_ARRAY    = 0x2000
    comvt_BYREF    = 0x4000
    comvt_TYPEMASK = 0x0FFF
    comvt_ILLEGAL  = 0xFFFF  ' unused
END ENUM


'*******************************************************************************
'              LATE BINDING COM SUPPORT by Ljubisa Knezevic, et al
'*******************************************************************************
MACRO c_SizeOfName = 64
TYPE UDT_COM_NAMES_STORAGE       ' Used for COM variables
    com_VarName[c_SizeOfName] AS CHAR
    initialized               AS BOOL
END TYPE

MACRO c_MaxComStk        = 256
MACRO c_MaxParamToken    =  64
MACRO c_COM_Stack_Size   =  64  ' number of chained dispatch objects.
MACRO c_COM_Max_Gl_Objs  =  64  ' max allowable GLOBAL COM objects
MACRO c_COM_Max_Lc_Objs  =  64  ' max allowable LOCAL  COM objects (SUBs and FUNCs)
MACRO c_COM_Max_Withs    =  32  ' max allowable nested (WITH-END WITH) constructions

GLOBAL ComNdx
GLOBAL ComStk$     [c_MaxComStk]
GLOBAL ParamToken$ [c_MaxParamToken]

'**************************************************************
'             END OF LATE BINDING COM SUPPORT
'**************************************************************

MACRO c_CommaPos = 128
TYPE UDT_ARG_COMMAS_STORAGE
    NumArgs
    CommaPos [c_CommaPos]
END TYPE

'**************************************************************
'              These need to always stay in sync
'**************************************************************

MACRO c_VARTYPES$ = "%$#!@`"
SET VarTypeLookup[] AS PCHAR
    "int", "int", "char *", "double", "float", "FILE *", "long double"
END SET

'**************************************************************
'    Used to keep track of status of a SELECT structure
'**************************************************************

TYPE UDT_SELECT_CASE_ATTRIBUTES
    CaseStk        AS STRING
    CaseElseFlag   AS INT
    CaseFlag       AS INT
    iStartCase     AS INT
    NoBreak        AS INT
    iJumpTo        AS INT
END TYPE

MACRO c_MaxNestedSelects = 32
GLOBAL SelectState[c_MaxNestedSelects] AS UDT_SELECT_CASE_ATTRIBUTES

'**************************************************************
' Structure used in Emitter's findword - Lookup done on pszWord
'**************************************************************

MACRO c_NOTFOUND = (-1)
TYPE UDT_KEYWORD_EMITTER
    pszWord AS PCHAR
    iType   AS INT
    FUNCTION Emitter(Lookup$, FuncRetnFlag AS PINT) AS INT
END TYPE


TYPE UDT_ARG_TYPE
    Arg     AS STRING
    ArgType AS INT
END TYPE


MACRO c_MaxProtoType    = 8192
MACRO c_SizeOfCondition =  512
TYPE UDT_PROTOTYPE_STORAGE
    Condition[c_SizeOfCondition]      AS CHAR
    CondLevel                        AS INT
    Prototype                        AS STRING
END TYPE


MACRO c_SizeOfElementName = 64
TYPE UDT_ELEMENT_STORAGE
    ElementType                      AS INT
    ElementID                        AS INT
    ElementDynaPtr                   AS INT
    ElementName$[c_SizeOfElementName] AS CHAR
END TYPE


MACRO c_SizeOfVarName = 64
TYPE UDT_USER_TYPES_STORAGE
    VarName[c_SizeOfVarName]         AS CHAR
    TypeofDef                        AS INT
    EleCnt                           AS INT
    Elements[c_MaxElements]          AS UDT_ELEMENT_STORAGE
END TYPE


MACRO c_SizeOfLabel = 10
TYPE UDT_LOOP_STORAGE
    iLoopType                        AS INT
    iLoopLine                        AS INT
    iJumpTo                          AS INT
    szUseNeedLabel [c_SizeOfLabel]   AS CHAR
END TYPE


MACRO c_SizeOfVarDim     = 128
MACRO c_SizeOfVarCondDef = 128
MACRO c_SizeOfVarModule  = 300
TYPE UDT_VARINFO_STORAGE
    VarLine                          AS INT
    VarType                          AS INT
    VarDef                           AS INT
    VarPntr                          AS INT
    VarSF                            AS INT
    VarExtn                          AS INT
    VarCondLevel                     AS INT
    VarEmitFlag                      AS INT
    VarConstant                      AS INT
    VarName    [c_SizeOfVarName]     AS CHAR
    VarDim     [c_SizeOfVarDim]      AS CHAR
    VarModule  [c_SizeOfVarModule]   AS CHAR
    VarCondDef [c_SizeOfVarCondDef]  AS CHAR
END TYPE


TYPE UDT_VARCODE_ATTRIBUTES
    VarNo                            AS INT
    Methd                            AS INT
    IsPtrFlag                        AS INT
    IsExported                       AS INT
    UseInLine                        AS INT
    Header                           AS STRING
    Proto                            AS STRING
    Functype                         AS STRING
    StaticOut                        AS STRING
    Token                            AS STRING
    AsToken                          AS STRING
END TYPE


' Types used in LoopType
ENUM
    ePrinterGroup   = 0x0001
    eFontGroup      = 0x0002
    eClassName      = 0x0004
    eBCX_hInstance  = 0x0008
END ENUM


ENUM   ' Types used in LoopType
    lt_DOLOOP = 1
    lt_DOWHILELOOP
    lt_DOUNTILLOOP
    lt_WHILEWEND
    lt_FORNEXT
    lt_SELECT
    lt_FORXNEXT
END ENUM


ENUM
    eExitingMoreThan1Loop = 1
END ENUM


TYPE UDT_COM_VARIANT_NAMES
    sNAME AS PCHAR
    iTYPE AS INT
    iPTRS AS INT
END TYPE


SET VariantList[] AS UDT_COM_VARIANT_NAMES
    { "bVal"      , vt_BYTE           , 0 },
    { "bool"      , vt__VARIANT_BOOL  , 0 },
    { "boolVal"   , vt_VARIANT_BOOL   , 0 },
    { "bstrVal"   , vt_BSTR           , 0 },
    { "byref"     , vt_PVOID          , 0 },
    { "cVal"      , vt_CHAR           , 0 },
    { "cyVal"     , vt_CY             , 0 },
    { "date"      , vt_DATE           , 0 },
    { "dblVal"    , vt_DOUBLE         , 0 },
    { "fltVal"    , vt_SINGLE         , 0 },
    { "iVal"      , vt_SHORT          , 0 },
    { "intVal"    , vt_INTEGER        , 0 },
    { "lVal"      , vt_LONG           , 0 },
    { "llVal"     , vt_LLONG          , 0 },
    { "parray"    , vt_SAFEARRAY      , 1 },
    { "pbVal"     , vt_BYTE           , 1 },
    { "pbool"     , vt__VARIANT_BOOL  , 1 },
    { "pboolVal"  , vt_VARIANT_BOOL   , 1 },
    { "pbstrVal"  , vt_BSTR           , 1 },
    { "pcVal"     , vt_CHAR           , 1 },
    { "pcyVal"    , vt_CY             , 1 },
    { "pdate"     , vt_DATE           , 1 },
    { "pdblVal"   , vt_DOUBLE         , 1 },
    { "pdecVal"   , vt_DECIMAL        , 1 },
    { "pdispVal"  , vt_IDispatch      , 1 },
    { "pfltVal"   , vt_SINGLE         , 1 },
    { "piVal"     , vt_SHORT          , 1 },
    { "pintVal"   , vt_INTEGER        , 1 },
    { "plVal"     , vt_LONG           , 1 },
    { "pllVal"    , vt_LLONG          , 1 },
    { "pparray"   , vt_SAFEARRAY      , 2 },
    { "ppdispVal" , vt_IDispatch      , 2 },
    { "ppunkVal"  , vt_IUnknown       , 2 },
    { "pscode"    , vt_SCODE          , 1 },
    { "puiVal"    , vt_USHORT         , 1 },
    { "pulVal"    , vt_ULONG          , 1 },
    { "pullVal"   , vt_ULONGLONG      , 1 },
    { "punkVal"   , vt_IUnknown       , 1 },
    { "pvarVal"   , vt_VARIANT        , 1 },
    { "scode"     , vt_SCODE          , 0 },
    { "uiVal"     , vt_USHORT         , 0 },
    { "uintVal"   , vt_UINT           , 0 },
    { "ulVal"     , vt_ULONG          , 0 },
    { "ullVal"    , vt_ULONGLONG      , 0 },
    { NULL        , 0                 , 0 }
END SET


TYPE UDT_VARIANT_CAST_DEF
    pszCAST AS PCHAR
    iCASTID AS INT
END TYPE


SET ptVCasts[] AS UDT_VARIANT_CAST_DEF
    { "VT_BOOL"    , comvt_BOOL },
    { "VT_BSTR"    , comvt_BSTR },
    { "VT_CY"      , comvt_CY },
    { "VT_DATE"    , comvt_DATE },
    { "VT_DECIMAL" , comvt_DECIMAL },
    { "VT_DISPATCH", comvt_DISPATCH },
    { "VT_ERROR"   , comvt_ERROR },
    { "VT_I1"      , comvt_I1 },
    { "VT_I2"      , comvt_I2 },
    { "VT_I4"      , comvt_I4 },
    { "VT_I8"      , comvt_I8 },
    { "VT_INT"     , comvt_INT },
    { "VT_R4"      , comvt_R4 },
    { "VT_R8"      , comvt_R8 },
    { "VT_UI1"     , comvt_UI1 },
    { "VT_UI2"     , comvt_UI2 },
    { "VT_UI4"     , comvt_UI4 },
    { "VT_UI8"     , comvt_UI8 },
    { "VT_UINT"    , comvt_UINT },
    { "VT_UNKNOWN" , comvt_UNKNOWN },
    { NULL         , 0 }
END SET


TYPE UDT_CASTS
    pszCAST AS PCHAR
    pszVAL AS PCHAR
END TYPE


SET ptCCasts[] AS UDT_CASTS
    { "BYTE"     , "bVal" },
    { "CHAR"     , "cVal" },
    { "DOUBLE"   , "dblVal" },
    { "FLOAT"    , "fltVal" },
    { "IDispatch", "pdispVal" },
    { "INT"      , "intVal" },
    { "IUnknown" , "punkVal" },
    { "LONG"     , "lVal" },
    { "LONGLONG" , "llVal" },
    { "PVOID"    , "byref" },
    { "SHORT"    , "iVal" },
    { "UINT"     , "uintVal" },
    { "ULONG"    , "ulVal" },
    { "ULONGLONG", "ullVal" },
    { "USHORT"   , "uiVal" },
    { NULL       , NULL }
END SET


SET ConstTypes$[]
    '-----------------------------------------
    ' MrBcx 828 (refactored) - These support:
    ' CONST [type] Variable_Name = SomeValue
    ' ex: CONST LONG EndGame = 1234567890
    ' EndGame is an immutable variable object.
    '-----------------------------------------
    "byte",
    "char",
    "double",
    "dword",
    "float",
    "int",
    "integer",
    "llong",
    "long",
    "longlong",
    "sbyte",
    "short",
    "single",
    "ubyte",
    "uchar",
    "uint",
    "uint64",
    "ulong",
    "ulonglong",
    "ushort"
END SET


SET tBcxWords[] AS UDT_KEYWORD_EMITTER
    ' Must be in lower case and in alphabetical order
    { "_ftelli64"        , vt_LLONG   , NULL },
    { "abs"              , vt_DOUBLE  , NULL },
    { "acos"             , vt_DOUBLE  , NULL },
    { "acosh"            , vt_DOUBLE  , NULL },
    { "acosl"            , vt_LDOUBLE , NULL },
    { "asin"             , vt_DOUBLE  , NULL },
    { "asinh"            , vt_DOUBLE  , NULL },
    { "asinl"            , vt_LDOUBLE , NULL },
    { "atan"             , vt_DOUBLE  , NULL },
    { "atan2"            , vt_DOUBLE  , NULL },
    { "atanh"            , vt_DOUBLE  , NULL },
    { "atanl"            , vt_LDOUBLE , NULL },
    { "band"             , vt_DECFUNC , NULL },
    { "bin2dec"          , vt_INTEGER , NULL },
    { "bor"              , vt_DECFUNC , NULL },
    { "cos"              , vt_DOUBLE  , NULL },
    { "cosh"             , vt_DOUBLE  , NULL },
    { "cosl"             , vt_LDOUBLE , NULL },
    { "csrlin"           , vt_DECFUNC , NULL },
    { "cursorx"          , vt_DECFUNC , NULL },
    { "cursory"          , vt_DECFUNC , NULL },
    { "cvd"              , vt_DOUBLE  , NULL },
    { "cvld"             , vt_LDOUBLE , NULL },
    { "cvs"              , vt_SINGLE  , NULL },
    { "degtorad"         , vt_DOUBLE  , NULL },
    { "dsplit"           , vt_DECFUNC , NULL },
    { "exist"            , vt_DECFUNC , NULL },
    { "exp"              , vt_DOUBLE  , NULL },
    { "expl"             , vt_LDOUBLE , NULL },
    { "fabs"             , vt_DOUBLE  , NULL },
    { "fabsf"            , vt_SINGLE  , NULL },
    { "fabsl"            , vt_LDOUBLE , NULL },
    { "findfirstinstance", vt_DECFUNC , NULL },
    { "fint"             , vt_INTEGER , NULL },
    { "fix"              , vt_DECFUNC , NULL },
    { "frac"             , vt_DOUBLE  , NULL },
    { "fracl"            , vt_LDOUBLE , NULL },
    { "freefile"         , vt_FILEPTR , NULL },
    { "getattr"          , vt_DECFUNC , NULL },
    { "hex2dec"          , vt_INTEGER , NULL },
    { "hypot"            , vt_DOUBLE  , NULL },
    { "hypotl"           , vt_LDOUBLE , NULL },
    { "iif"              , vt_DOUBLE  , NULL },
    { "iinstr"           , vt_DECFUNC , NULL },
    { "inchr"            , vt_DECFUNC , NULL },
    { "instr"            , vt_DECFUNC , NULL },
    { "instrany"         , vt_DECFUNC , NULL },
    { "instrrev"         , vt_DECFUNC , NULL },
    { "isfile"           , vt_INTEGER , NULL },
    { "isfolder"         , vt_INTEGER , NULL },
    { "ishidden"         , vt_INTEGER , NULL },
    { "isreadonly"       , vt_INTEGER , NULL },
    { "issystem"         , vt_INTEGER , NULL },
    { "kbhit"            , vt_DECFUNC , NULL },
    { "keypress()"       , vt_DECFUNC , NULL },
    { "labs"             , vt_LONG    , NULL },
    { "llabs"            , vt_LLONG   , NULL },
    { "lof"              , vt_DOUBLE  , NULL },
    { "log"              , vt_DOUBLE  , NULL },
    { "log10"            , vt_DOUBLE  , NULL },
    { "log10l"           , vt_LDOUBLE , NULL },
    { "logl"             , vt_LDOUBLE , NULL },
    { "max"              , vt_DOUBLE  , NULL },
    { "min"              , vt_DOUBLE  , NULL },
    { "msgbox"           , vt_DECFUNC , NULL },
    { "pi"               , vt_DOUBLE  , NULL },
    { "pos"              , vt_DECFUNC , NULL },
    { "pow"              , vt_DOUBLE  , NULL },
    { "powl"             , vt_LDOUBLE , NULL },
    { "qbcolor"          , vt_DECFUNC , NULL },
    { "radtodeg"         , vt_DOUBLE  , NULL },
    { "rnd"              , vt_SINGLE  , NULL },
    { "rnd2"             , vt_DOUBLE  , NULL },
    { "round"            , vt_DOUBLE  , NULL },
    { "screen"           , vt_DECFUNC , NULL },
    { "sgn"              , vt_DECFUNC , NULL },
    { "sin"              , vt_DOUBLE  , NULL },
    { "sinh"             , vt_DOUBLE  , NULL },
    { "sinl"             , vt_LDOUBLE , NULL },
    { "sizeof"           , vt_DECFUNC , NULL },
    { "split"            , vt_DECFUNC , NULL },
    { "sqrt"             , vt_DOUBLE  , NULL },
    { "sqrtl"            , vt_LDOUBLE , NULL },
    { "strlen"           , vt_DECFUNC , NULL },
    { "tally"            , vt_DECFUNC , NULL },
    { "tan"              , vt_DOUBLE  , NULL },
    { "tanh"             , vt_DOUBLE  , NULL },
    { "tanl"             , vt_LDOUBLE , NULL },
    { "textmode"         , vt_DOUBLE  , NULL },
    { "timer"            , vt_SINGLE  , NULL },
    { "tix_now"          , vt_DOUBLE  , NULL },
    { "val"              , vt_DOUBLE  , NULL },
    { "vall"             , vt_LDOUBLE , NULL }
END SET


SET tTypes[] AS UDT_KEYWORD_EMITTER
    '*************************************************
    ' Must be in lower case and in alphabetical order
    '*************************************************
    { "bitmapinfo" , vt_BITMAPINFO  , NULL },
    { "bool"       , vt_BOOL        , NULL },
    { "boolean"    , vt_BOOL        , NULL },
    { "bstr"       , vt_BSTR        , NULL },
    { "byte"       , vt_BYTE        , NULL },
    { "char"       , vt_CHAR        , NULL },
    { "colorref"   , vt_COLORREF    , NULL },
    { "double"     , vt_DOUBLE      , NULL },
    { "dword"      , vt_DWORD       , NULL },
    { "farproc"    , vt_FARPROC     , NULL },
    { "file"       , vt_FILEPTR     , NULL },
    { "float"      , vt_SINGLE      , NULL },
    { "handle"     , vt_HANDLE      , NULL },
    { "hbitmap"    , vt_HBITMAP     , NULL },
    { "hdc"        , vt_HDC         , NULL },
    { "hfont"      , vt_HFONT       , NULL },
    { "hwnd"       , vt_HWND        , NULL },
    { "int"        , vt_INTEGER     , NULL },
    { "ldouble"    , vt_LDOUBLE     , NULL },
    { "llong"      , vt_LLONG       , NULL },
    { "long"       , vt_LONG        , NULL },
    { "longlong"   , vt_LLONG       , NULL },
    { "lpbyte"     , vt_PBYTE       , NULL },
    { "lpstr"      , vt_PSTR        , NULL },
    { "lresult"    , vt_LRESULT     , NULL },
    { "pchar"      , vt_PCHAR       , NULL },
    { "schar"      , vt_SCHAR       , NULL },
    { "short"      , vt_SHORT       , NULL },
    { "sshort"     , vt_SSHORT      , NULL },
    { "string"     , vt_STRVAR      , NULL },
    { "uint"       , vt_UINT        , NULL },
    { "uint64"     , vt_ULONGLONG   , NULL },
    { "ulong"      , vt_ULONG       , NULL },
    { "ulonglong"  , vt_ULONGLONG   , NULL },
    { "ushort"     , vt_USHORT      , NULL },
    { "variant"    , vt_VARIANT     , NULL },
    { "void"       , vt_VOID        , NULL },
    { "winbool"    , vt_WINBOOL     , NULL },
    { "wndclassex" , vt_WNDCLASSEX  , NULL }
END SET


SET atEmitWords[] AS UDT_KEYWORD_EMITTER
    '*************************************************
    ' Must be in lower case and in alphabetical order
    '*************************************************
    { "_chdir"              , 0, Emit_FolderDriveProcs },
    { "_mkdir"              , 0, Emit_FolderDriveProcs },
    { "_rmdir"              , 0, Emit_FolderDriveProcs },
    { "asm"                 , 0, Emit_CPP_Asm },
    { "auto"                , 0, Emit_Auto },
    { "bcx_set_edit_color"  , 0, Emit_BcxSetEditColor },
    { "bcx_set_font"        , 0, Emit_BcxSetFont },
    { "bcx_set_label_color" , 0, Emit_BcxSetLabelColor },
    { "beginblock"          , 0, Emit_ControlFlow },
    { "call"                , 0, Emit_ControlFlow },
    { "case"                , 0, Emit_ControlFlow },
    { "caseelse"            , 0, Emit_ControlFlow },
    { "catch"               , 0, Emit_CPP_Catch },
    { "chdir"               , 0, Emit_FolderDriveProcs },
    { "class"               , 0, Emit_CPP_Class },
    { "clear"               , 0, Emit_Clear },
    { "close"               , 0, Emit_FileIO },
    { "cls"                 , 0, Emit_ConsoleOnlyProcs },
    { "color"               , 0, Emit_ConsoleOnlyProcs },
    { "const"               , 0, Emit_Const },
    { "constructor"         , 0, Emit_ConDes },
    { "continue"            , 0, Emit_ControlFlow },
    { "copyfile"            , 0, Emit_FileManagementProcs },
    { "data"                , 0, Emit_Data },
    { "declare"             , 0, Emit_Declare },
    { "decr"                , 0, Emit_MathProcs },
    { "delay"               , 0, Emit_ConsoleOnlyProcs },
    { "delete"              , 0, Emit_CPP_Delete },
    { "destructor"          , 0, Emit_ConDes },
    { "dialogbox"           , 0, Emit_DialogBox },
    { "dim"                 , 0, Emit_Dim },
    { "do"                  , 0, Emit_ControlFlow },
    { "dynamic"             , 0, Emit_Dynamic },
    { "ejectpage"           , 0, Emit_PrinterProcs },
    { "else"                , 0, Emit_ControlFlow },
    { "elseif"              , 0, Emit_ControlFlow },
    { "end"                 , 0, Emit_ControlFlow },
    { "endblock"            , 0, Emit_ControlFlow },
    { "endclass"            , 0, Emit_CPP_EndClass },
    { "endconstructor"      , 0, Emit_ConDes },
    { "enddestructor"       , 0, Emit_ConDes },
    { "endfunction"         , 0, Emit_EndFuncSub },
    { "endif"               , 0, Emit_ControlFlow },
    { "endnamespace"        , 0, Emit_CPP_EndNamespace },
    { "endpptype"           , 0, Emit_PPType },
    { "endprepend"          , 0, Emit_ControlFlow },
    { "endprogram"          , 0, Emit_ControlFlow },
    { "endrepeat"           , 0, Emit_ControlFlow },
    { "endselect"           , 0, Emit_ControlFlow },
    { "endsub"              , 0, Emit_EndFuncSub },
    { "endtemplate"         , 0, Emit_template },
    { "endtry"              , 0, Emit_CPP_EndTry },
    { "endtype"             , 0, Emit_Type },
    { "endunion"            , 0, Emit_Union },
    { "endwhile"            , 0, Emit_ControlFlow },
    { "endwith"             , 0, Emit_ControlFlow },
    { "exit"                , 0, Emit_ControlFlow },
    { "extern"              , 0, Emit_Extern },
    { "fallthrough"         , 0, Emit_ControlFlow },
    { "finput"              , 0, Emit_FinputProcs },
    { "flush"               , 0, Emit_FileIO },
    { "for"                 , 0, Emit_ControlFlow },
    { "fprint"              , 0, Emit_FprintProcs },
    { "free"                , 0, Emit_Free },
    { "function"            , 0, Emit_FuncSub },
    { "functionreturn"      , 0, Emit_FunctionReturn },
    { "fwrite"              , 0, Emit_FwriteProcs },
    { "global"              , 0, Emit_Shared_Global },
    { "gosub"               , 0, Emit_ControlFlow },
    { "goto"                , 0, Emit_ControlFlow },
    { "gui"                 , 0, Emit_MdiGuiProcs },
    { "if"                  , 0, Emit_ControlFlow },
    { "impfunction"         , 0, Emit_Implied },
    { "incr"                , 0, Emit_MathProcs },
    { "input"               , 0, Emit_KeyboardProcs },
    { "insertmenu"          , 0, Emit_InsertMenuProc },
    { "kill"                , 0, Emit_FileManagementProcs },
    { "lineinput"           , 0, Emit_LineInputProcs },
    { "local"               , 0, Emit_Local },
    { "locate"              , 0, Emit_ConsoleOnlyProcs },
    { "loop"                , 0, Emit_ControlFlow },
    { "lprint"              , 0, Emit_PrinterProcs },
    { "mdigui"              , 0, Emit_MdiGuiProcs },
    { "midstr"              , 0, Emit_StringProcs },
    { "mkdir"               , 0, Emit_FolderDriveProcs },
    { "msgbox"              , 0, Emit_Msgbox },
    { "namespace"           , 0, Emit_CPP_Namespace },
    { "next"                , 0, Emit_ControlFlow },
    { "open"                , 0, Emit_FileIO },
    { "optfunction"         , 0, Emit_OptFuncSub },
    { "optsub"              , 0, Emit_OptFuncSub },
    { "overloadedfunction"  , 0, Emit_OverLoadFuncSub },
    { "overloadedsub"       , 0, Emit_OverLoadFuncSub },
    { "panel"               , 0, Emit_ConsoleOnlyProcs },
    { "pptype"              , 0, Emit_PPType },
    { "prepend"             , 0, Emit_ControlFlow },
    { "print"               , 0, Emit_ConsoleOnlyProcs },
    { "printerclose"        , 0, Emit_PrinterProcs },
    { "printeropen"         , 0, Emit_PrinterProcs },
    { "private"             , 0, Emit_CPP_Private },
    { "privatedim"          , 0, Emit_PrivateDim },
    { "privatefunction"     , 0, Emit_FuncSub },
    { "privatesub"          , 0, Emit_FuncSub },
    { "protected"           , 0, Emit_CPP_Protected },
    { "public"              , 0, Emit_CPP_Public },
    { "publicfunction"      , 0, Emit_FuncSub },
    { "publicsub"           , 0, Emit_FuncSub },
    { "qsort"               , 0, Emit_QsortProcs },
    { "qsortidx"            , 0, Emit_QsortIdxProcs },
    { "raw"                 , 0, Emit_Raw },
    { "record"              , 0, Emit_FileIO },
    { "redim"               , 0, Emit_Redim },
    { "register"            , 0, Emit_Register },
    { "rename"              , 0, Emit_FileManagementProcs },
    { "repeat"              , 0, Emit_ControlFlow },
    { "return"              , 0, Emit_ControlFlow },
    { "rmdir"               , 0, Emit_FolderDriveProcs },
    { "run"                 , 0, Emit_Run },
    { "seek"                , 0, Emit_SeekProcs },
    { "select"              , 0, Emit_ControlFlow },
    { "seteof"              , 0, Emit_SetEofProcs },
    { "shared"              , 0, Emit_Shared_Global },
    { "shell"               , 0, Emit_Shell },
    { "sprint"              , 0, Emit_PrinterProcs },
    { "static"              , 0, Emit_Static },
    { "sub"                 , 0, Emit_FuncSub },
    { "swap"                , 0, Emit_Swap },
    { "template"            , 0, Emit_template },
    { "textmode"            , 0, Emit_ConsoleOnlyProcs },
    { "throw"               , 0, Emit_CPP_Throw },
    { "try"                 , 0, Emit_CPP_Try },
    { "type"                , 0, Emit_Type },
    { "union"               , 0, Emit_Union },
    { "wend"                , 0, Emit_ControlFlow },
    { "while"               , 0, Emit_ControlFlow },
    { "with"                , 0, Emit_ControlFlow },
    { "write"               , 0, Emit_ConsoleOnlyProcs },
    { "xfor"                , 0, Emit_ControlFlow },
    { "xnext"               , 0, Emit_ControlFlow },
    { "~else"               , 0, Emit_ConditionalCompilation },
    { "~elseif"             , 0, Emit_ConditionalCompilation },
    { "~endif"              , 0, Emit_ConditionalCompilation },
    { "~get"                , 0, Emit_GetProcs },
    { "~hscroll"            , 0, Emit_Hscroll },
    { "~if"                 , 0, Emit_ConditionalCompilation },
    { "~ifdef"              , 0, Emit_ConditionalCompilation },
    { "~ifndef"             , 0, Emit_ConditionalCompilation },
    { "~pragmaoptimizeoff"  , 0, Emit_ConditionalCompilation },
    { "~pragmaoptimizeon"   , 0, Emit_ConditionalCompilation },
    { "~put"                , 0, Emit_PutProcs },
    { "~vscroll"            , 0, Emit_Vscroll }
END SET



SET tDirectives[] AS UDT_KEYWORD_EMITTER
    '*************************************************
    ' Must be in lower case and in alphabetical order
    '*************************************************
    { "#include"            , 0, Doinclude     },
    { "$accelerator"        , 0, Doaccelerator },
    { "$asm"                , 0, Doasm         },
    { "$bcx_resource"       , 0, Dobcx_resource },
    { "$bcxstrsize"         , 0, DoBcxStrSize  },
    { "$bcxversion"         , 0, Dobcxversion  },
    { "$case_off"           , 0, DoCase_offon  },
    { "$case_on"            , 0, DoCase_offon  },
    { "$ccode"              , 0, Doccode       },
    { "$com_off"            , 0, Docom_op      },
    { "$com_on"             , 0, Docom_op      },
    { "$com_trace"          , 0, Docom_op      },
    { "$comment"            , 0, Docomment     },
    { "$compiler"           , 0, Docompiler    },
    { "$cpp"                , 0, Docpp         },
    { "$cpphdr"             , 0, Docpphdr      },
    { "$cproto"             , 0, Docproto      },
    { "$define"             , 0, Dodefine      },
    { "$dll"                , 0, Dodll         },
    { "$filetest"           , 0, Dofiletest    },
    { "$fill"               , 0, Dofillstring  },
    { "$fsstatic"           , 0, Dofsstatic    },
    { "$genfree"            , 0, Dogenfree     },
    { "$header"             , 0, Doheader      },
    { "$include"            , 0, Doinclude     },
    { "$interface"          , 0, Dointerface   },
    { "$iprint_off"         , 0, Doiprint      },
    { "$iprint_on"          , 0, Doiprint      },
    { "$leanandmean"        , 0, Doleanandmean },
    { "$liberror"           , 0, Doliberror    },
    { "$library"            , 0, Dolibrary     },
    { "$linker"             , 0, Dolinker      },
    { "$mt"                 , 0, Domultithread },
    { "$multi"              , 0, Domultithread },
    { "$no_borland"         , 0, DoNoBorland   },
    { "$no_gcc_clang"       , 0, DoNoGccClang  },
    { "$no_lccwin"          , 0, DoNoLccwin    },
    { "$no_libs"            , 0, DoNoLibs      },
    { "$no_msvc"            , 0, DoNoMsvc      },
    { "$no_pelles"          , 0, DoNoPelles    },
    { "$no_vkkeys"          , 0, DoNoVkkeys    },
    { "$nodllmain"          , 0, Dodll         },
    { "$noini"              , 0, Donoini       },
    { "$noio"               , 0, Donoio        },
    { "$nolibrary"          , 0, Doremovelib   },
    { "$nomain"             , 0, Donomain      },
    { "$nowin"              , 0, Donowin       },
    { "$onentry"            , 0, Doonentry     },
    { "$onexit"             , 0, Doonexit      },
    { "$optimizer"          , 0, Dooptimizer   },
    { "$pack"               , 0, Dopack        },
    { "$pp"                 , 0, Dopp          },
    { "$prj"                , 0, Doprj         },
    { "$prjuse"             , 0, Doprj         },
    { "$project"            , 0, Doproject     },
    { "$rems"               , 0, Dorems        },
    { "$resource"           , 0, Doresource    },
    { "$source"             , 0, Dosource      },
    { "$stdcall"            , 0, Dostdcall     },
    { "$test"               , 0, Dotest        },
    { "$trace"              , 0, Dotrace       },
    { "$typedef"            , 0, Dotypedef     },
    { "$warnings"           , 0, DoWarningsOn  },
    { "$warnings_off"       , 0, DoWarningsOff },
    { "$warnings_on"        , 0, DoWarningsOn  },
    { "$zap"                , 0, DoZap         }
END SET

'***************************************************
$TYPEDEF UINT_PTR (CALLBACK *CPP_FARPROC)(PCHAR)
'***************************************************
'     GLOBAL CONSTANTS AND RELATED VARIABLES
'***************************************************
MACRO   c_MaxStk       = 8192
MACRO   c_MaxByref     =  128
MACRO   c_MaxDLLDecl   = 1024
MACRO   c_MaxLoopLocal =  512
MACRO   c_MaxFiles     =  512
MACRO   c_MaxMacros    = 2048
'***************************************************
GLOBAL  ConstMacro$  [c_MaxMacros]
GLOBAL  ByrefVars$   [c_MaxByref]
GLOBAL  LoopLocalVar [c_MaxLoopLocal]
GLOBAL  LoopType [c_MaxLoopLocal] AS UDT_LOOP_STORAGE
GLOBAL  LinesWritten    AS INT
GLOBAL  DebugModeOff    AS INT
GLOBAL  MacroCount      AS INT
GLOBAL  ByrefCnt        AS INT
GLOBAL  LoopLocalCnt    AS INT
GLOBAL  LoopTypeCnt     AS INT
GLOBAL  FileNdx         AS INT  ' Index of source files
GLOBAL  FPtr[c_MaxFiles] AS FILE     ' Controls $Include Files
GLOBAL  FileNames$ [c_MaxFiles]      ' Array of source filenames
GLOBAL  LineNum    [c_MaxFiles]      ' Line # in source files, also uses FileNdx
'***************************************************
MACRO   c_MaxBaseTypeDefs = 16
GLOBAL  BaseTypeDefsCnt  [c_MaxBaseTypeDefs]
GLOBAL  TypeDefName$     [c_MaxBaseTypeDefs]
GLOBAL  FP_WRITE AS FILE ' Controls whether code is emitted to main()/winmain() or functions
GLOBAL  iDoWhile
GLOBAL  iLoopCond
GLOBAL  GlobalVarCnt
GLOBAL  TypeDefsCnt
GLOBAL  GlobalDynaCnt
GLOBAL  LocalVarCnt
GLOBAL  LocalDynArrCnt                            ' Local Dynamic String Array Stack Counter
GLOBAL  LocalDynaCnt                              ' Queue Stack Counter
GLOBAL  CombineRes                                ' Join generated rc file with existing rc file
GLOBAL  UserResFile$                              ' holds name of user's *.rc file
GLOBAL  ResCompiler$                              ' resource compiler, lrc.exe
GLOBAL  FPtrNdx                                   ' Controls $Include Files
GLOBAL  Stk$ [c_MaxStk]                           ' Parse array
GLOBAL  Vchr_Stk$[c_MaxStk]                       ' Used in transforming CHR$() to VCHR$()             MrBcx 829
GLOBAL  UmQt                                      ' Handles quoted lines split with a contination _
GLOBAL  ProtoType [c_MaxProtoType] AS UDT_PROTOTYPE_STORAGE  ' C prototype declarations of user's func's
MACRO   c_MaxSingleLineIFLines = 256
GLOBAL  SrcStk$ [c_MaxSingleLineIFLines]          ' used in parsing single line if-THEN-else
MACRO   c_MaxSplitLines = 256
GLOBAL  SplitStk$ [c_MaxSplitLines]               ' used in parsing ":" separated lines
GLOBAL  SplitCnt
GLOBAL  SplitCur
GLOBAL  SrcTmp$                                   ' used for storing string to use as parameter to Parse()
MACRO   c_MaxOnEntry = 256
GLOBAL  Entry$ [c_MaxOnEntry]                     ' Controls the $OnEntry
MACRO   c_MaxOnExit = 256
GLOBAL  Xit$ [c_MaxOnExit]                        ' Controls the $OnExit
MACRO   c_MaxLocalDynArr = 256
GLOBAL  LocalDynArrName$ [c_MaxLocalDynArr]       ' Queues LOCAL dynamic string arrays
MACRO   c_MaxGlobalDyna = 256
GLOBAL  GlobalDynaStr$   [c_MaxGlobalDyna]
MACRO   c_MaxDynaStr = 256
GLOBAL  DynaStr$         [c_MaxDynaStr]           ' Queues Dynamic strings in SUBS/FUNCTIONS
MACRO   c_MaxStartSub = 32
GLOBAL  StartSub$        [c_MaxStartSub]          ' user's startup code subs
GLOBAL  StartNdx                                  ' index for StartSub$
MACRO   c_MaxExitSub = 32
GLOBAL  ExitSub$         [c_MaxExitSub]           ' user's exit code subs
GLOBAL  ExitNdx                                   ' index for ExitSub$
GLOBAL  Library$         [c_MaxLib]               ' stores libraries to used
GLOBAL  GlobalVarHash    [c_MaxGlobalVars]
GLOBAL  GlobalVars       [c_MaxGlobalVars] AS UDT_VARINFO_STORAGE
GLOBAL  LocalVars        [c_MaxLocalVars]  AS UDT_VARINFO_STORAGE
GLOBAL  TypeDefs         [c_MaxTypes]      AS UDT_USER_TYPES_STORAGE


'***************************************
' GLOBALS for parsing C++ statements
'***************************************
GLOBAL  UseCpp
GLOBAL  UseCpphdr
GLOBAL  UseIO
GLOBAL  InNameSpace
GLOBAL  InClass
GLOBAL  InCppTypeDef
GLOBAL  InClassName$
GLOBAL  iClassCnt
MACRO   c_MaxClassNames = 1024
GLOBAL  ClassNames$[c_MaxClassNames]
GLOBAL  InClassPP$
GLOBAL  IsVirtual
GLOBAL  szVirtual$
GLOBAL  UsingTemplate
GLOBAL  WasAClass
GLOBAL  HasVector
'*********************
' Directive Flags
'*********************
GLOBAL NO_VKKEYS
GLOBAL NO_BORLAND
GLOBAL NO_GCCCLANG
GLOBAL NO_LCCWIN
GLOBAL NO_LIBS
GLOBAL NO_MSVC
GLOBAL NO_PELLES
'*********************

GLOBAL  UseInLine
GLOBAL  Accelerator$
GLOBAL  CallBackFlag
GLOBAL  CallType$              ' Calling convention cdecl, stdcall
GLOBAL  LabelGenerator = 1000
GLOBAL  CaseVar$
GLOBAL  Cmd$
GLOBAL  Comma
GLOBAL  Compiler$
GLOBAL  CmdLineConst$
GLOBAL  CmdLineFileOut$
GLOBAL  CurrentFuncType
GLOBAL  DoCountLines
GLOBAL  DimType$

MACRO   c_SizeOfDllDecl = 512
GLOBAL  DllDecl$ [c_MaxDLLDecl][c_SizeOfDllDecl] AS CHAR
GLOBAL  DllCnt

MACRO   c_SizeOfLoadlibs = 512
MACRO   c_MaxLoadlibs = 128
GLOBAL  Loadlibs$ [c_MaxLoadlibs][c_SizeOfLoadlibs] AS CHAR
GLOBAL  LoadLibsCnt
GLOBAL  Elapsed AS SINGLE
GLOBAL  EndOfProgram
GLOBAL  EntryCnt
GLOBAL  ErrFile
GLOBAL  ExitSubFunc
GLOBAL  szFile$
GLOBAL  Filnam$
GLOBAL  ForceMainToFunc
GLOBAL  FunctionName$
GLOBAL  g_SubFuncPtr
GLOBAL  szFileHandle$
GLOBAL  HFileCnt

MACRO   c_MaxHFiles = 128
GLOBAL  HFiles$[c_MaxHFiles]
GLOBAL  HFile$
GLOBAL  InBlock
GLOBAL  InConditional
GLOBAL  Indent
GLOBAL  InDialogEvt
GLOBAL  InfoBoxWarn
GLOBAL  InFunction
GLOBAL  InIfDef$
GLOBAL  Inject_Local_Bcx_RetVal
GLOBAL  InMain
GLOBAL  InWinMain
GLOBAL  IsCallBack
GLOBAL  ModDialogEvt
GLOBAL  UseCProto
GLOBAL  UseFileTest = TRUE

MACRO   c_MaxLocalInBlocks = 16
GLOBAL  LocalInBlock[c_MaxLocalInBlocks]
GLOBAL  InTypeDef
GLOBAL  NoTypeDeclare
GLOBAL  InsertComments
'************************ <Variable_Storage_Type>
GLOBAL  IsAuto
GLOBAL  IsDim
GLOBAL  IsLocal
GLOBAL  IsRaw
GLOBAL  IsRegister
GLOBAL  IsStatic
'************************ <Variable_Storage_Type>
GLOBAL  IsStdFunc
GLOBAL  KillCFile
GLOBAL  Keyword1$
GLOBAL  LastCmd
GLOBAL  LinesRead
GLOBAL  Linker$
GLOBAL  MakeDLL
GLOBAL  Ndx
GLOBAL  NoMain AS BOOL
GLOBAL  NoDllMain AS BOOL
GLOBAL  OkayToSend AS BOOL
GLOBAL  OptimizerEnabled AS BOOL
GLOBAL  OptimizerFirstSetting AS BOOL
GLOBAL  OptionBase
GLOBAL  PassOne AS BOOL
GLOBAL  Project$
GLOBAL  ProtoCnt
GLOBAL  StateIdx
GLOBAL  PPFlag AS BOOL
GLOBAL  PPDLL_HANDLE AS HINSTANCE
GLOBAL  PPProc AS CPP_FARPROC
GLOBAL  Use_LoadLibraryError        ' Use error routine when loading libraries
GLOBAL  LibraryErrorLog$            ' [Path\][Name] of error log for loading libraries
GLOBAL  Use_Project AS BOOL         ' Vic McClung for $PROJECT Support
GLOBAL  Gen_Header AS BOOL          ' Vic McClung for $PROJECT Support
GLOBAL  Project_Main$               ' main file in $PROJECT
GLOBAL  Project_Path$               ' path for project output files, i.e. .h;.c;.cpp
GLOBAL  NoRT AS BOOL                ' Emit all c/c++ code -EXCEPT- BCX runtime c/c++ code
GLOBAL  Quiet AS BOOL               ' no output to screen, for use with BCX Builder
GLOBAL  WarningFlag AS BOOL
GLOBAL  ZapFlag AS BOOL             ' remove default libs and headers [-z]
GLOBAL  ReDirect AS BOOL
GLOBAL  SaveFP_WRITENum AS FILE
GLOBAL  Scoot$
GLOBAL  ShowStatus
GLOBAL  SrcCnt
GLOBAL  SrcFlag
GLOBAL  TraceFlag
GLOBAL  TestForBcxIni AS BOOL
GLOBAL  FileIn$
GLOBAL  FileOut$
GLOBAL  FileOutCopy$
GLOBAL  FileErr$
GLOBAL  g_Injection$
GLOBAL  g_FoundLocalDynArray
GLOBAL  iEmitVarGroup
GLOBAL  Res_File$
GLOBAL  ResFileOut$
GLOBAL  For_Next_Error_Detected
GLOBAL  Statements
GLOBAL  IgnoreStrCase               ' TRUE | FALSE depending on $CASE_ON | $CASE_OFF
GLOBAL  TestState
GLOBAL  gszType$
GLOBAL  TranslateSlash
GLOBAL  Use_BcxTempStr
GLOBAL  Use_BCX_stricmp
GLOBAL  UseStdCall
GLOBAL  UseImportExport
GLOBAL  Use_LCaseTbl
GLOBAL  Use_UCaseTbl
GLOBAL  WinHeaders
GLOBAL  Var$
GLOBAL  XitCount
GLOBAL  ConstLastDef$
GLOBAL  UserBcxStrSize$  ' $BCXSTRSIZE support
'**********************************************************************
'   Use_ Vars control and limit the runtime functions that BCX emits
'**********************************************************************
GLOBAL  Use_GUINoMain
GLOBAL  Use_MDIGUINoMain
GLOBAL  GUIIcon$
GLOBAL  GUIMetric$
GLOBAL  Use_Wingui
GLOBAL  Use_MainEvent
GLOBAL  Use_Mdigui
GLOBAL  Use_ShowModal
GLOBAL  Use_EndModal
GLOBAL  Use_BCX_MsgPump
GLOBAL  Use_BCX_MDI_MsgPump
GLOBAL  Use_BCX_Wnd
GLOBAL  Use_BCX_FrameWnd
GLOBAL  Use_BCX_SetBkGrdBrush
GLOBAL  Use_BCX_SetClassStyle
GLOBAL  Use_BCX_SetIcon
GLOBAL  Use_BCX_SetIconSm
GLOBAL  Use_BCX_SetMetric
GLOBAL  Use_BCX_InitGUI
GLOBAL  Use_BCX_RegWnd
GLOBAL  Use_BCX_SetCursor
GLOBAL  Use_AnsiToWide
GLOBAL  Use_Asinh
GLOBAL  Use_Acosh
GLOBAL  Use_AppActivate
GLOBAL  Use_Atanh
GLOBAL  Use_Asc
GLOBAL  Use_AppExeName
GLOBAL  Use_AppExePath
GLOBAL  Use_Bff
GLOBAL  Use_Boolstr
GLOBAL  Use_Bnot
GLOBAL  Use_BCX_Blit
GLOBAL  Use_BCX_Blit_Stretch
GLOBAL  Use_BCX_Blit_Sprite
GLOBAL  Use_BCX_Buffer
GLOBAL  Use_BCX_BmpWidth
GLOBAL  Use_BCX_BmpHeight
GLOBAL  Use_BCX_Class_Info
GLOBAL  Use_BCX_LoadBMP
GLOBAL  Use_BCX_LoadImage
GLOBAL  Use_BCX_Control
GLOBAL  Use_BCX_Colordlg
GLOBAL  Use_BCX_Cursor
GLOBAL  Use_BCX_Fontdlg
GLOBAL  Use_BCX_Floodfill
GLOBAL  Use_BCX_Get
GLOBAL  Use_BCX_Get_Window_Width
GLOBAL  Use_BCX_Get_Window_Height
GLOBAL  Use_BcxSplitPath
GLOBAL  Use_BCX_Path
GLOBAL  Use_BCX_Put
GLOBAL  Use_BCX_Preset
GLOBAL  Use_BCX_Pset
GLOBAL  Use_BCX_Polar_Pset
GLOBAL  Use_BCX_Line
GLOBAL  Use_BCX_Polar_Line
GLOBAL  Use_BCX_Lineto
GLOBAL  Use_BCX_Circle
GLOBAL  Use_BCX_Triangle
GLOBAL  Use_BCX_Gradient
GLOBAL  Use_BCX_Ellipse
GLOBAL  Use_BCX_Rectangle
GLOBAL  Use_BCX_Resize
GLOBAL  Use_BCX_Roundrect
GLOBAL  Use_BCX_Getpixel
GLOBAL  Use_BCX_Arc
GLOBAL  Use_BCX_OlePicture
GLOBAL  Use_BCX_Pie
GLOBAL  Use_BCX_Polygon
GLOBAL  Use_BCX_PolyBezier
GLOBAL  Use_BCX_Polyline
GLOBAL  Use_BCX_Print
GLOBAL  Use_BCX_Printex
GLOBAL  Use_BCX_Tile
GLOBAL  Use_BCX_Slider
GLOBAL  Use_BCX_Splitter
GLOBAL  Use_BCX_Tab
GLOBAL  Use_BCX_Toolbar
GLOBAL  Use_BCX_UpDown
GLOBAL  Use_BCX_Get_UpDown
GLOBAL  Use_Bin
GLOBAL  Use_Bin2dec
GLOBAL  Use_ByteAt
GLOBAL  Use_Cast
GLOBAL  Use_Cvd
GLOBAL  Use_Cvld
GLOBAL  Use_Cvi
GLOBAL  Use_Cvl
GLOBAL  Use_Cvs
GLOBAL  Use_Cdbl
GLOBAL  Use_Cldbl
GLOBAL  Use_Csng
GLOBAL  Use_Clear
GLOBAL  Use_Clip_Getbitmap
GLOBAL  Use_Clip_Setbitmap
GLOBAL  Use_Clip_Gettext
GLOBAL  Use_Clip_Gettextsize
GLOBAL  Use_Clip_Reset
GLOBAL  Use_Clip_Settext
GLOBAL  Use_Chrtoutf8
GLOBAL  Use_Cbool
GLOBAL  Use_Cint
GLOBAL  Use_Clng
GLOBAL  Use_Cls
GLOBAL  Use_Color
GLOBAL  Use_Command
GLOBAL  Use_ComboBoxLoadFile
GLOBAL  Use_Console
GLOBAL  Use_Consolesize
GLOBAL  Use_ContainedIn
GLOBAL  Use_Cpad
GLOBAL  Use_Static
GLOBAL  Use_CreateRegInt
GLOBAL  Use_CreateRegString
GLOBAL  Use_Crlf
GLOBAL  Use_Csrlin
GLOBAL  Use_Curdir
GLOBAL  Use_Cursor
GLOBAL  Use_Date
GLOBAL  Use_DrawStr
GLOBAL  Use_IsoDate
GLOBAL  Use_Datacount
GLOBAL  Use_Del
GLOBAL  Use_DeleteRegKey
GLOBAL  Use_Diskfree
GLOBAL  Use_Diskused
GLOBAL  Use_Disksize
GLOBAL  Use_Doevents
GLOBAL  Use_Download
GLOBAL  Use_Downloadtostr
GLOBAL  Use_Draw
GLOBAL  Use_Dynacall
GLOBAL  Use_DynacallA
GLOBAL  Use_DynacallCommon
GLOBAL  Use_DynamicA
GLOBAL  Use_DrawTransBMP
GLOBAL  Use_Elf
GLOBAL  Use_Enclose
GLOBAL  Use_Environ
GLOBAL  Use_EnumFile
GLOBAL  Use_Eof
GLOBAL  Use_EqualTo
GLOBAL  Use_Exist
GLOBAL  Use_ExitCode
GLOBAL  Use_Extract
GLOBAL  Use_ExtractAny
GLOBAL  Use_LeanAndMean
GLOBAL  Use_Lclick
GLOBAL  Use_LoadFile
GLOBAL  Use_ForEach
GLOBAL  Use_Format
GLOBAL  Use_FillArray
GLOBAL  Use_FirstInstance
GLOBAL  Use_Findfirst
GLOBAL  Use_Findnext
GLOBAL  Use_Lookahead
GLOBAL  Use_FindInType
GLOBAL  Use_Fix
GLOBAL  Use_FileLocked
GLOBAL  Use_Frac
GLOBAL  Use_Fracl
GLOBAL  Use_Freefile
GLOBAL  Use_Get
GLOBAL  Use_Getaddr
GLOBAL  Use_Setaddr
GLOBAL  Use_GetBmp
GLOBAL  Use_Gethttpfilesize
GLOBAL  Use_SetDimension
GLOBAL  Use_GetDimension
GLOBAL  Use_Getdrive
GLOBAL  Use_Getfilename
GLOBAL  Use_GetSaveAsFilename
GLOBAL  Use_Getattr
GLOBAL  Use_GetResource
GLOBAL  Use_GetSpecialFolder
GLOBAL  Use_GetSpecialFolderex
GLOBAL  Use_GetTextSize
GLOBAL  Use_GenFree
GLOBAL  Use_GoSub
GLOBAL  Use_Hex
GLOBAL  Use_Hex2Dec
GLOBAL  Use_Hook
GLOBAL  Use_Iif
GLOBAL  Use_Inputbuffer
GLOBAL  Use_Inkey
GLOBAL  Use_InkeyD
GLOBAL  Use_Inputbox
GLOBAL  Use_Infobox
GLOBAL  Use_BoxCommon
GLOBAL  Use_Isptr
GLOBAL  Use_Ins
GLOBAL  Use_Instr
GLOBAL  Use_IInstr
GLOBAL  Use_InstrAny
GLOBAL  Use_IInstrAny
GLOBAL  Use_Like_Instr
GLOBAL  Use_Inchr
GLOBAL  Use_iReplace
GLOBAL  Use_IReplaceAny
GLOBAL  Use_IRemove
GLOBAL  Use_IRemoveAny
GLOBAL  Use_Instrrev
GLOBAL  Use_Imod
GLOBAL  Use_Istrue
GLOBAL  Use_Isfalse
GLOBAL  Use_Isnull
GLOBAL  Use_Notnull
GLOBAL  Use_Iszero
GLOBAL  Use_Issystem
GLOBAL  Use_Ishidden
GLOBAL  Use_Isreadonly
GLOBAL  Use_Isfolder
GLOBAL  Use_Isfile
GLOBAL  Use_Join
GLOBAL  Use_Keypress
GLOBAL  Use_KBinput
GLOBAL  Use_Lcase
GLOBAL  Use_LccPath
GLOBAL  Use_PellesPath
GLOBAL  Use_Ldouble
GLOBAL  Use_Left
GLOBAL  Use_LeftStr
GLOBAL  Use_Like
GLOBAL  Use_LineinputKB
GLOBAL  Use_ListBoxLoadFile
GLOBAL  Use_Loc
GLOBAL  Use_Longestline
GLOBAL  Use_Locate
GLOBAL  Use_Lof
GLOBAL  Use_Lpad
GLOBAL  Use_Ltrim
GLOBAL  Use_Mcase
GLOBAL  Use_Mid
GLOBAL  Use_Midstr
GLOBAL  Use_Msgbox
GLOBAL  Use_Mkd
GLOBAL  Use_Mkld
GLOBAL  Use_Mki
GLOBAL  Use_Mkl
GLOBAL  Use_Mks
GLOBAL  Use_Mkpath
GLOBAL  Use_Min
GLOBAL  Use_Modstyle
GLOBAL  Use_Max
GLOBAL  Use_Mouse_sx
GLOBAL  Use_Mouse_sy
GLOBAL  Use_Mouse_cx
GLOBAL  Use_Mouse_cy
GLOBAL  Use_NamePathFromFP
GLOBAL  Use_Nextlinelen
GLOBAL  Use_Now
GLOBAL  Use_Notzero
GLOBAL  Use_NotEqualTo
GLOBAL  Use_Numqsortdint
GLOBAL  Use_Numqsortaint
GLOBAL  Use_Numqsortdfloat
GLOBAL  Use_Numqsortafloat
GLOBAL  Use_Numqsortddouble
GLOBAL  Use_Numqsortadouble
GLOBAL  Use_Idxqsort
GLOBAL  Use_IdxqsortSt
GLOBAL  Use_PtrqsortSt
GLOBAL  Use_PushPopColors
GLOBAL  Use_Oct
GLOBAL  Use_Overloaded
GLOBAL  Use_OSVersion
GLOBAL  Use_Panel
GLOBAL  Use_Pause
GLOBAL  Use_PeekStr
GLOBAL  Use_Pos
GLOBAL  Use_Printer
GLOBAL  Use_ProgressBar
GLOBAL  Use_Proto
GLOBAL  Use_Put
GLOBAL  Use_QBColor
GLOBAL  Use_DegToRad
GLOBAL  Use_RadToDeg
GLOBAL  Use_Randomize
GLOBAL  Use_Read
GLOBAL  Use_Readnum
GLOBAL  Use_Rec
GLOBAL  Use_RecCount
GLOBAL  Use_Remain
GLOBAL  Use_RemainAny
GLOBAL  Use_Remove
GLOBAL  Use_Repeat
GLOBAL  Use_Replace
GLOBAL  Use_ReplaceAny
GLOBAL  Use_RemoveAny
GLOBAL  Use_Reverse
GLOBAL  Use_Right
GLOBAL  Use_RightStr
GLOBAL  Use_Rpad
GLOBAL  Use_Rclick
GLOBAL  Use_Rnd
GLOBAL  Use_Rnd2
GLOBAL  Use_Exp
GLOBAL  Use_Retain
GLOBAL  Use_Round
GLOBAL  Use_Rtrim
GLOBAL  Use_Run
GLOBAL  Use_SaveBmp
GLOBAL  Use_Scan
GLOBAL  Use_Screen
GLOBAL  Use_Setattr
GLOBAL  Use_Seteof
GLOBAL  Use_SearchPath
GLOBAL  Use_Set_BCX_Bitmap
GLOBAL  Use_Set_BCX_Bitmap2
GLOBAL  Use_Set_BCX_BmpButton
GLOBAL  Use_Set_BCX_Icon
GLOBAL  Use_Sgn
GLOBAL  Use_SingleFile AS BOOL
GLOBAL  Use_Sleep
GLOBAL  Use_Sound
GLOBAL  Use_Space
GLOBAL  Use_Split
GLOBAL  Use_DSplit
GLOBAL  Use_StartupCode
GLOBAL  Use_Stristr
GLOBAL  Use_Str
GLOBAL  Use_Strl
GLOBAL  Use_Strim
GLOBAL  Use_String
GLOBAL  Use_Strptr
GLOBAL  Use_Strqsorta
GLOBAL  Use_Strqsortas
GLOBAL  Use_Strqsortd
GLOBAL  Use_Strqsortds
GLOBAL  Use_Strqsorts
GLOBAL  Use_Strtoken
GLOBAL  Use_DynStrqsorta
GLOBAL  Use_DynStrqsortas
GLOBAL  Use_DynStrqsortd
GLOBAL  Use_DynStrqsortds
GLOBAL  Use_DynAlphaNumericA
GLOBAL  Use_DynAlphaNumericD
GLOBAL  Use_AlphaNumericA
GLOBAL  Use_AlphaNumericD
GLOBAL  Use_AlphaNumeric
GLOBAL  Use_RegExist
GLOBAL  Use_RegInt
GLOBAL  Use_RegString
GLOBAL  Use_Resource
GLOBAL  Use_GenResFile
GLOBAL  Use_Swap
GLOBAL  Use_Sysdir
GLOBAL  Use_SysMacros
GLOBAL  Use_SysStr
GLOBAL  Use_sziif
GLOBAL  Use_Tally
GLOBAL  Use_Tempdir
GLOBAL  Use_TempFileName
GLOBAL  Use_Textmode
GLOBAL  Use_Threads
GLOBAL  Use_Time
GLOBAL  Use_Timer
GLOBAL  Use_Tix
GLOBAL  Use_Treeview
GLOBAL  Use_Trim
GLOBAL  Use_Ucase
GLOBAL  Use_Using
GLOBAL  Use_Ubound
GLOBAL  Use_Utf8tochr
GLOBAL  Use_Unwrap
GLOBAL  Use_VChr
GLOBAL  Use_VBS
GLOBAL  Use_Verify
GLOBAL  Use_Val
GLOBAL  Use_Vall
GLOBAL  Use_WideToAnsi
GLOBAL  Use_Vscroll
GLOBAL  Use_Hscroll
GLOBAL  Use_Newbmp
GLOBAL  Use_Makebmp
GLOBAL  Use_Makehdc
GLOBAL  Use_Windir
GLOBAL  Use_Wrap

'*******************

GLOBAL  Use_BCX_Input
GLOBAL  Use_BCX_ToolTip
GLOBAL  Use_Bitmap
GLOBAL  Use_Blackrect
GLOBAL  Use_BmpButton
GLOBAL  Use_SplitButton
GLOBAL  Use_Button
GLOBAL  Use_Center
GLOBAL  Use_Checkbox
GLOBAL  Use_Combobox
GLOBAL  Use_Datepick
GLOBAL  Use_Edit
GLOBAL  Use_BCXMDialog
GLOBAL  Use_BCXDialog
GLOBAL  Use_BCXDialogCommon
GLOBAL  Use_Form
GLOBAL  Use_GetText
GLOBAL  Use_Grayrect
GLOBAL  Use_Group
GLOBAL  Use_Hide
GLOBAL  Use_Icon
GLOBAL  Use_Label
GLOBAL  Use_Listbox
GLOBAL  Use_Listview
GLOBAL  Use_PlayWav
GLOBAL  Use_Radio
GLOBAL  Use_Refresh
GLOBAL  Use_Richedit
GLOBAL  Use_SetColor
GLOBAL  Use_Setclientsize
GLOBAL  Use_SetFont
GLOBAL  Use_SetFormColor
GLOBAL  Use_SetText
GLOBAL  Use_Show
GLOBAL  Use_Status
GLOBAL  Use_Whiterect

'********************************
' PB Compatible String Constants
'********************************

GLOBAL  Use_BEL
GLOBAL  Use_BS
GLOBAL  Use_CR
GLOBAL  Use_DDQ
GLOBAL  Use_DQ
GLOBAL  Use_EF
GLOBAL  Use_ESC
GLOBAL  Use_FF
GLOBAL  Use_LF
GLOBAL  Use_NUL
GLOBAL  Use_SPC
GLOBAL  Use_TAB
GLOBAL  Use_VT

'**************************************************************

GLOBAL  cppFile$       ' C/C++ file
GLOBAL  prcFile$       ' translated subs and functions
GLOBAL  udtFile$       ' translated User Defined Types
GLOBAL  datFile$       ' translated DATA statements
GLOBAL  UsrFile$       ' User's translated CONSTants
GLOBAL  SysFile$       ' system translated CONSTants
GLOBAL  ovrFile$       ' translated overloaded subs and functions
GLOBAL  hdrFile$       ' user specified .h directives
GLOBAL  setFile$       ' translated GLOBAL set statements
GLOBAL  resFile$       ' user specified .rc directives
GLOBAL  enuFile$       ' user's GLOBAL enum blocks
GLOBAL  defFile$       ' user's $DEFINE statements
'*************************************************************************
'               GLOBAL VARIABLES FOR LATE BINDING COM SUPPORT
'*************************************************************************

GLOBAL  ComSwitchON = FALSE                                          ' flag indicating use of COM in source
GLOBAL  ProcessingCOM_Set
GLOBAL  COM_gl_names [c_COM_Max_Gl_Objs+1] AS UDT_COM_NAMES_STORAGE  ' COM objects GLOBAL names
GLOBAL  COM_lc_names [c_COM_Max_Lc_Objs+1] AS UDT_COM_NAMES_STORAGE  ' COM objects LOCAL  names (SUBs and FUNCs)
GLOBAL  COM_gl_names_index%                                          ' count of com objects used as GLOBAL variables
GLOBAL  COM_lc_names_index%                                          ' count of com objects used as LOCAL variables (SUBs and FUNCs)
GLOBAL  COM_gl_names_free_index%                                     ' pointer to a free space in COM_gl_names[]
GLOBAL  COM_lc_names_free_index%                                     ' pointer to a free space in COM_lc_names[]
GLOBAL  COM_FOREACH_enumerator                                       ' temp variable used in (for each ...) constructions
GLOBAL  Use_COM                                                      ' COM is used in project, so emit COM functions.
GLOBAL  Use_COM_Collections                                          ' for unicode support
GLOBAL  Use_UNICODE                                                  ' for unicode support
GLOBAL  Use_MULTITHREADED_SW                                         ' for multithreaded applications
GLOBAL  COM_build_trace_code
GLOBAL  COM_with_temp_str_name$
GLOBAL  COM_open_WITH_statement
GLOBAL  Use_COM_CLSID
GLOBAL  Use_COM_CreateObject
GLOBAL  Use_COM_DispatchObject
GLOBAL  Use_COM_GetObject
GLOBAL  Use_COM_GetProperty
GLOBAL  Use_COM_InvokeMethod
GLOBAL  Use_COM_SetProperty
GLOBAL  Use_COM_SafeArray
GLOBAL  Use_COM_UsesConversion
GLOBAL  Use_SafeArrays

'*************************************************************************
'           END GLOBAL VARIABLES FOR LATE BINDING COM SUPPORT
'*************************************************************************

SET VarConst[2][8] AS CHAR
    "",
    "const "
END SET

SET VarStorage[6][18] AS CHAR
    "static ",
    "extern ",
    "",
    "static volatile ",
    "extern volatile ",
    "volatile "
END SET


'*************************************************************************
' For information on reserved words, currently how to translate
' Additional information may be added in the future.
'*************************************************************************
' Current information on reserved word, table is in alpabetical order
' Wayne Halsdorf
'*************************************************************************

ENUM
    eWI_CPPWord       = 0x0001   ' 1
    eWI_ReplaceWord   = 0x0002   ' 2
    eWI_NoFixup       = 0x0004   ' 4
    eWI_Directive     = 0x0008   ' 8
    eWI_Transform     = 0x0010   ' 16
    eWI_Position1     = 0x0020   ' 32
    eWI_Reserve10     = 0x0040   ' 64
    eWI_Reserve09     = 0x0080   ' 128
    eWI_Reserve08     = 0x0100   ' 256
    eWI_Reserve07     = 0x0200   ' 512
    eWI_Reserve06     = 0x0400   ' 1024
    eWI_Reserve05     = 0x0800   ' 2048
    eWI_Reserve04     = 0x1000   ' 4096
    eWI_Reserve03     = 0x2000   ' 8192
    eWI_Reserve02     = 0x4000   ' 16384
    eWI_Reserve01     = 0x8000   ' 32768
END ENUM

TYPE UDT_SUB_FUNC_TOKENS
    iTRAN_FLAG        AS INT    ' Where translations are legal
    pszFunctionName   AS PCHAR  ' BCX word
    pszFunctionXName  AS PCHAR  ' if eWI_ReplaceWord set directly replace with this
    iWordInfo         AS INT    ' See ENUM above
    iCOM              AS INT    ' if can be used directly with COM
END TYPE

GLOBAL iRIndex[97][2] AS INT    ' Low to High Lookup table for BCXWords[] - Reduces lookup size

SET BCXWords[] AS UDT_SUB_FUNC_TOKENS
    { 1 , "#include"                     , "#include"                     , 8 , comvt_BAD },
    { 1 , "$accelerator"                 , ""                             , 8 , comvt_BAD },
    { 1 , "$asm"                         , ""                             , 8 , comvt_BAD },
    { 1 , "$bcx_resource"                , ""                             , 8 , comvt_BAD },
    { 1 , "$bcxstrsize"                  , ""                             , 8 , comvt_BAD },
    { 1 , "$bcxversion"                  , ""                             , 8 , comvt_BAD },
    { 1 , "$case_off"                    , ""                             , 8 , comvt_BAD },
    { 1 , "$case_on"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$ccode"                       , ""                             , 8 , comvt_BAD },
    { 1 , "$com_off"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$com_on"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$com_trace"                   , ""                             , 8 , comvt_BAD },
    { 1 , "$comment"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$compiler"                    , ""                             , 8 , comvt_BAD },
    { 1 , "$cpp"                         , ""                             , 8 , comvt_BAD },
    { 1 , "$cpphdr"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$cproto"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$debug"                       , ""                             , 8 , comvt_BAD },
    { 1 , "$define"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$dll"                         , ""                             , 8 , comvt_BAD },
    { 1 , "$else"                        , "~else"                        , 2 , comvt_BAD },
    { 1 , "$elseif"                      , "~elseif"                      , 2 , comvt_BAD },
    { 1 , "$endif"                       , ""                             , 0 , comvt_BAD },
    { 1 , "$filetest"                    , ""                             , 8 , comvt_BAD },
    { 1 , "$fill"                        , ""                             , 8 , comvt_BAD },
    { 1 , "$fsstatic"                    , ""                             , 8 , comvt_BAD },
    { 1 , "$genfree"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$header"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$hscroll"                     , "~hscroll"                     , 2 , comvt_BAD },
    { 1 , "$if"                          , ""                             , 0 , comvt_BAD },
    { 1 , "$ifdef"                       , ""                             , 0 , comvt_BAD },
    { 1 , "$ifndef"                      , ""                             , 0 , comvt_BAD },
    { 1 , "$include"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$interface"                   , ""                             , 8 , comvt_BAD },
    { 1 , "$iprint_off"                  , ""                             , 8 , comvt_BAD },
    { 1 , "$iprint_on"                   , ""                             , 8 , comvt_BAD },
    { 1 , "$lcc$"                        , "$LCC$"                        , 2 , comvt_BAD },
    { 1 , "$leanandmean"                 , ""                             , 8 , comvt_BAD },
    { 1 , "$liberror"                    , ""                             , 8 , comvt_BAD },
    { 1 , "$library"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$linker"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$mt"                          , ""                             , 8 , comvt_BAD },
    { 1 , "$multi"                       , ""                             , 8 , comvt_BAD },
    { 1 , "$no_borland"                  , ""                             , 8 , comvt_BAD },
    { 1 , "$no_gcc_clang"                , ""                             , 8 , comvt_BAD },
    { 1 , "$no_lccwin"                   , ""                             , 8 , comvt_BAD },
    { 1 , "$no_libs"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$no_msvc"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$no_pelles"                   , ""                             , 8 , comvt_BAD },
    { 1 , "$no_vkkeys"                   , ""                             , 8 , comvt_BAD },
    { 1 , "$nodllmain"                   , ""                             , 8 , comvt_BAD },
    { 1 , "$noini"                       , ""                             , 8 , comvt_BAD },
    { 1 , "$noio"                        , ""                             , 8 , comvt_BAD },
    { 1 , "$nolibrary"                   , ""                             , 8 , comvt_BAD },
    { 1 , "$nomain"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$nowin"                       , ""                             , 8 , comvt_BAD },
    { 1 , "$onentry"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$onexit"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$optimizer"                   , ""                             , 8 , comvt_BAD },
    { 1 , "$pack"                        , ""                             , 8 , comvt_BAD },
    { 1 , "$pp"                          , ""                             , 8 , comvt_BAD },
    { 1 , "$prj"                         , ""                             , 8 , comvt_BAD },
    { 1 , "$prjuse"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$project"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$rems"                        , ""                             , 8 , comvt_BAD },
    { 1 , "$resource"                    , ""                             , 8 , comvt_BAD },
    { 1 , "$source"                      , ""                             , 8 , comvt_BAD },
    { 1 , "$stdcall"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$test"                        , ""                             , 8 , comvt_BAD },
    { 1 , "$trace"                       , ""                             , 8 , comvt_BAD },
    { 1 , "$typedef"                     , ""                             , 8 , comvt_BAD },
    { 1 , "$vscroll"                     , "~vscroll"                     , 2 , comvt_BAD },
    { 1 , "$warnings"                    , ""                             , 8 , comvt_BAD },
    { 1 , "$warnings_off"                , ""                             , 8 , comvt_BAD },
    { 1 , "$warnings_on"                 , ""                             , 8 , comvt_BAD },
    { 1 , "$zap"                         , ""                             , 8 , comvt_BAD },
    { 1 , "_asm"                         , "_asm"                         , 2 , comvt_BAD },
    { 1 , "_bool"                        , "_Bool"                        , 2 , comvt_BAD },
    { 1 , "abs"                          , "fabs"                         , 2 , comvt_R8 },
    { 1 , "acos"                         , "acos"                         , 2 , comvt_R8 },
    { 1 , "acosh"                        , "acosh"                        , 2 , comvt_R8 },
    { 1 , "acosl"                        , "acosl"                        , 2 , comvt_BAD },
    { 1 , "addressof"                    , ""                             , 0 , comvt_BAD },
    { 1 , "alias"                        , "alias"                        , 2 , comvt_BAD },
    { 1 , "and"                          , ""                             , 0 , comvt_BAD },
    { 1 , "andalso"                      , ""                             , 0 , comvt_BAD },
    { 1 , "ansitowide"                   , ""                             , 0 , comvt_BAD },
    { 1 , "appactivate"                  , ""                             , 0 , comvt_BAD },
    { 1 , "append"                       , ""                             , 0 , comvt_BAD },
    { 1 , "appexename$"                  , ""                             , 0 , comvt_BAD },
    { 1 , "appexepath$"                  , ""                             , 0 , comvt_BAD },
    { 1 , "argc"                         , "argc"                         , 2 , comvt_BAD },
    { 1 , "argv"                         , "argv"                         , 2 , comvt_BAD },
    { 1 , "argv$"                        , "argv$"                        , 2 , comvt_BAD },
    { 1 , "arraygetelement"              , ""                             , 0 , comvt_BAD },
    { 1 , "arrayputelement"              , ""                             , 0 , comvt_BAD },
    { 1 , "as"                           , ""                             , 0 , comvt_BAD },
    { 3 , "asc"                          , ""                             , 0 , comvt_BAD },
    { 1 , "ascending"                    , ""                             , 0 , comvt_BAD },
    { 1 , "asciiz"                       , "string"                       , 2 , comvt_BAD },
    { 1 , "asin"                         , "asin"                         , 2 , comvt_R8 },
    { 1 , "asinh"                        , "asinh"                        , 2 , comvt_R8 },
    { 1 , "asinl"                        , "asinl"                        , 2 , comvt_BAD },
    { 1 , "asm"                          , ""                             , 1 , comvt_BAD },
    { 1 , "atan"                         , "atan"                         , 2 , comvt_R8 },
    { 1 , "atan2"                        , "atan2"                        , 2 , comvt_R8 },
    { 1 , "atanh"                        , "atanh"                        , 2 , comvt_R8 },
    { 1 , "atanl"                        , "atanl"                        , 2 , comvt_R8 },
    { 1 , "atn"                          , "atan"                         , 2 , comvt_R8 },
    { 1 , "atn2"                         , "atan2"                        , 2 , comvt_R8 },
    { 1 , "atnl"                         , "atanl"                        , 2 , comvt_R8 },
    { 1 , "auto"                         , "auto"                         , 2 , comvt_BAD },
    { 3 , "band"                         , ""                             , 0 , comvt_BAD },
    { 1 , "base"                         , "base"                         , 2 , comvt_BAD },
    { 1 , "bcopy"                        , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_addtab"                   , "BCX_AddTab"                   , 2 , comvt_BAD },
    { 1 , "bcx_arc"                      , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_bitmap"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_blackrect"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_bmpbutton"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_bmpheight"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_bmpwidth"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_buffer_start"             , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_buffer_stop"              , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_button"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_checkbox"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_circle"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_classname$"               , "BCX_ClassName$"               , 2 , comvt_BAD },
    { 1 , "bcx_clsid$"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_colordlg"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_combobox"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_console"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_control"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_cursor"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_datepick"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_dialog"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_dispatchobject"           , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_edit"                     , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_ellipse"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_floodfill"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_font"                     , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_fontdlg"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_form"                     , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_framewnd"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_get"                      , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_get_com_error_code"       , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_get_com_error_desc$"      , "BCX_GET_COM_ERROR_DESC()"     , 2 , comvt_BAD },
    { 1 , "bcx_get_com_status"           , "BCX_GET_COM_STATUS"           , 2 , comvt_BAD },
    { 1 , "bcx_get_com_success"          , "BCX_GET_COM_SUCCESS()"        , 2 , comvt_BAD },
    { 1 , "bcx_get_text$"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_get_updown"               , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_get_window_height"        , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_get_window_width"         , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_getpixel"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_gradient"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_grayrect"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_group"                    , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_hinstance"                , "BCX_hInstance"                , 2 , comvt_BAD },
    { 1 , "bcx_icon"                     , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_initgui"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_input"                    , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_label"                    , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_line"                     , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_lineto"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_listbox"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_listview"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_loadbmp"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_loadimage"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_mdi_msgpump"              , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_mdialog"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_mdichild"                 , "BCX_MDICHILD"                 , 2 , comvt_BAD },
    { 1 , "bcx_mdiclass"                 , "BCX_MDICLASS"                 , 2 , comvt_BAD },
    { 1 , "bcx_mdiclient"                , "BCX_MDICLIENT"                , 2 , comvt_BAD },
    { 1 , "bcx_msgpump"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_ole_height"               , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_ole_width"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_olepicture"               , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_pensize"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_penstyle"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_pie"                      , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_polar_line"               , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_polar_pset"               , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_polybezier"               , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_polygon"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_polyline"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_popconsolesize"           , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_preset"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_print"                    , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_printex"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_progressbar"              , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_pset"                     , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_pushconsolesize"          , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_put"                      , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_radio"                    , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_rectangle"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_regwnd"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_remtab"                   , "BCX_RemTab"                   , 2 , comvt_BAD },
    { 1 , "bcx_resource"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_richedit"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_roundrect"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_scalex"                   , "BCX_ScaleX"                   , 2 , comvt_BAD },
    { 1 , "bcx_scaley"                   , "BCX_ScaleY"                   , 2 , comvt_BAD },
    { 1 , "bcx_set_edit_color"           , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_set_font"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_set_form_color"           , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_set_label_color"          , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_set_text"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_setbkgrdbrush"            , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_setclassstyle"            , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_setcolor"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_setconsolesize"           , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_setcursor"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_seticon"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_seticonsm"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_setmetric"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_setsplitpos"              , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_show_com_errors"          , "BCX_SHOW_COM_ERRORS"          , 2 , comvt_BAD },
    { 1 , "bcx_slider"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_splitbutton"              , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_splitbutton_additem"      , "BCX_SplitButton_AddItem"      , 2 , comvt_BAD },
    { 1 , "bcx_splitbutton_addseparator" , "BCX_SplitButton_AddSeparator" , 2 , comvt_BAD },
    { 1 , "bcx_splitbutton_setitems"     , "BCX_SplitButton_SetItems"     , 2 , comvt_BAD },
    { 1 , "bcx_splitter"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_status"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_stricmp"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_tab"                      , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_tabselect"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_tempstr"                  , "BCX_TempStr"                  , 2 , comvt_BAD },
    { 1 , "bcx_thread"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_threadend"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_threadkill"               , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_threadresume"             , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_threadsuspend"            , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_threadwait"               , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_tile"                     , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_toolbar"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_tooltip"                  , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_treeview"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_updown"                   , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_version$"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_whiterect"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_wnd"                      , ""                             , 0 , comvt_BAD },
    { 1 , "bcx_wndclass"                 , ""                             , 0 , comvt_BAD },
    { 1 , "bcxfont"                      , "BcxFont"                      , 2 , comvt_BAD },
    { 1 , "bcxlib"                       , "BCXLIB"                       , 2 , comvt_BAD },
    { 1 , "bcxpath$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "bcxsplitpath$"                , ""                             , 0 , comvt_BAD },
    { 1 , "bcxstrsize"                   , "BCXSTRSIZE"                   , 0 , comvt_BAD },
    { 1 , "beep"                         , "Beep"                         , 2 , comvt_BAD },
    { 1 , "begin"                        , ""                             , 0 , comvt_BAD },
    { 1 , "bel$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "bff$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "bin$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "bin2dec"                      , ""                             , 0 , comvt_I4 },
    { 1 , "binary"                       , ""                             , 0 , comvt_BAD },
    { 3 , "bnot"                         , ""                             , 0 , comvt_BAD },
    { 1 , "bool"                         , ""                             , 0 , comvt_BAD },
    { 1 , "bool$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "boolean"                      , ""                             , 0 , comvt_BAD },
    { 3 , "bor"                          , ""                             , 0 , comvt_BAD },
    { 1 , "bs$"                          , ""                             , 0 , comvt_BAD },
    { 1 , "byref"                        , ""                             , 0 , comvt_BAD },
    { 1 , "byte"                         , "unsigned char"                , 2 , comvt_BAD },
    { 1 , "byte_at"                      , ""                             , 0 , comvt_BAD },
    { 1 , "c_declare"                    , ""                             , 0 , comvt_BAD },
    { 1 , "call"                         , ""                             , 0 , comvt_BAD },
    { 1 , "callback"                     , ""                             , 0 , comvt_BAD },
    { 1 , "callwindowproc"               , ""                             , 0 , comvt_BAD },
    { 1 , "case"                         , ""                             , 0 , comvt_BAD },
    { 1 , "catch"                        , "catch"                        , 3 , comvt_BAD },
    { 1 , "cbctl"                        , "LOWORD(wParam)"               , 2 , comvt_BAD },
    { 1 , "cbctlmsg"                     , "HIWORD(wParam)"               , 2 , comvt_BAD },
    { 1 , "cbhndl"                       , "hWnd"                         , 2 , comvt_BAD },
    { 1 , "cbhwnd"                       , "hWnd"                         , 2 , comvt_BAD },
    { 1 , "cblparam"                     , "lParam"                       , 2 , comvt_BAD },
    { 1 , "cbmsg"                        , "Msg"                          , 2 , comvt_BAD },
    { 1 , "cbnmcode"                     , "((LPNMHDR)lParam)->code"      , 2 , comvt_BAD },
    { 1 , "cbnmhwnd"                     , "((LPNMHDR)lParam)->hwndFrom"  , 2 , comvt_BAD },
    { 1 , "cbnmid"                       , "((LPNMHDR)lParam)->idFrom"    , 2 , comvt_BAD },
    { 1 , "cbool"                        , ""                             , 0 , comvt_BAD },
    { 1 , "cbwparam"                     , "wParam"                       , 2 , comvt_BAD },
    { 1 , "cdbl"                         , ""                             , 0 , comvt_BAD },
    { 1 , "ceil"                         , "ceil"                         , 2 , comvt_BAD },
    { 1 , "center"                       , ""                             , 0 , comvt_BAD },
    { 1 , "char"                         , "char"                         , 2 , comvt_BAD },
    { 1 , "chdir"                        , "_chdir"                       , 2 , comvt_BAD },
    { 1 , "chdrive"                      , "_chdir"                       , 2 , comvt_BAD },
    { 1 , "chr$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "chrtoutf8$"                   , ""                             , 0 , comvt_BAD },
    { 1 , "cint"                         , ""                             , 0 , comvt_BAD },
    { 1 , "class"                        , "class"                        , 3 , comvt_BAD },
    { 1 , "cldbl"                        , ""                             , 0 , comvt_BAD },
    { 1 , "clear"                        , ""                             , 0 , comvt_BAD },
    { 1 , "clipboard_getbitmap"          , ""                             , 0 , comvt_BAD },
    { 1 , "clipboard_gettext"            , ""                             , 0 , comvt_BAD },
    { 1 , "clipboard_gettextsize"        , ""                             , 0 , comvt_BAD },
    { 1 , "clipboard_reset"              , ""                             , 0 , comvt_BAD },
    { 1 , "clipboard_setbitmap"          , ""                             , 0 , comvt_BAD },
    { 1 , "clipboard_settext"            , ""                             , 0 , comvt_BAD },
    { 1 , "clng"                         , ""                             , 0 , comvt_BAD },
    { 1 , "close"                        , ""                             , 0 , comvt_BAD },
    { 1 , "close#"                       , "close"                        , 2 , comvt_BAD },
    { 1 , "closedialog"                  , ""                             , 0 , comvt_BAD },
    { 1 , "cls"                          , ""                             , 0 , comvt_BAD },
    { 1 , "color"                        , ""                             , 0 , comvt_BAD },
    { 1 , "color_bg"                     , ""                             , 0 , comvt_BAD },
    { 1 , "color_fg"                     , ""                             , 0 , comvt_BAD },
    { 1 , "colorref"                     , "COLORREF"                     , 2 , comvt_BAD },
    { 1 , "com"                          , "COM"                          , 2 , comvt_BAD },
    { 1 , "comboboxloadfile"             , ""                             , 0 , comvt_BAD },
    { 1 , "command$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "concat"                       , ""                             , 0 , comvt_BAD },
    { 1 , "const"                        , "const"                        , 2 , comvt_BAD },
    { 1 , "const_cast"                   , "const_cast"                   , 3 , comvt_BAD },
    { 1 , "constructor"                  , ""                             , 1 , comvt_BAD },
    { 1 , "containedin"                  , ""                             , 0 , comvt_BAD },
    { 1 , "continue"                     , "continue"                     , 2 , comvt_BAD },
    { 1 , "control"                      , "HWND"                         , 2 , comvt_BAD },
    { 1 , "conwin"                       , "GetConsoleWindow()"           , 2 , comvt_BAD },
    { 1 , "copyfile"                     , "copyfile"                     , 2 , comvt_BAD },
    { 1 , "cos"                          , "cos"                          , 2 , comvt_R8 },
    { 1 , "cosh"                         , "cosh"                         , 2 , comvt_R8 },
    { 1 , "cosl"                         , "cosl"                         , 2 , comvt_BAD },
    { 1 , "cpad$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "cr$"                          , ""                             , 0 , comvt_BAD },
    { 1 , "createobject"                 , ""                             , 0 , comvt_BAD },
    { 1 , "createregint"                 , ""                             , 0 , comvt_BAD },
    { 1 , "createregstring"              , ""                             , 0 , comvt_BAD },
    { 1 , "crlf$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "csng"                         , ""                             , 0 , comvt_BAD },
    { 1 , "csrlin"                       , ""                             , 0 , comvt_BAD },
    { 1 , "curdir$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "currency"                     , "CURRENCY"                     , 2 , comvt_BAD },
    { 1 , "cursorx"                      , ""                             , 0 , comvt_BAD },
    { 1 , "cursory"                      , ""                             , 0 , comvt_BAD },
    { 1 , "cvd"                          , ""                             , 0 , comvt_BAD },
    { 1 , "cvi"                          , ""                             , 0 , comvt_BAD },
    { 1 , "cvl"                          , ""                             , 0 , comvt_BAD },
    { 1 , "cvld"                         , ""                             , 0 , comvt_BAD },
    { 1 , "cvs"                          , ""                             , 0 , comvt_BAD },
    { 1 , "data"                         , ""                             , 0 , comvt_BAD },
    { 1 , "data$"                        , "DATA$"                        , 2 , comvt_BAD },
    { 1 , "date$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "ddq$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "declare"                      , ""                             , 16, comvt_BAD },
    { 1 , "decr"                         , "decr"                         , 2 , comvt_BAD },
    { 1 , "degtorad"                     , ""                             , 0 , comvt_BAD },
    { 1 , "del$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "delay"                        , "delay"                        , 2 , comvt_BAD },
    { 1 , "delete"                       , "delete"                       , 3 , comvt_BAD },
    { 1 , "deleteregkey"                 , ""                             , 0 , comvt_BAD },
    { 1 , "descending"                   , ""                             , 0 , comvt_BAD },
    { 1 , "destroysafearray"             , "DestroySafeArray"             , 0 , comvt_BAD },
    { 1 , "destructor"                   , ""                             , 1 , comvt_BAD },
    { 1 , "dialog"                       , ""                             , 0 , comvt_BAD },
    { 1 , "dialogbox"                    , "DialogBox"                    , 2 , comvt_BAD },
    { 1 , "dim"                          , "dim"                          , 2 , comvt_BAD },
    { 1 , "diskfree"                     , "DiskFree"                     , 0 , comvt_BAD },
    { 1 , "disksize"                     , "DiskSize"                     , 0 , comvt_BAD },
    { 1 , "diskused"                     , "DiskUsed"                     , 0 , comvt_BAD },
    { 1 , "do"                           , "do"                           , 2 , comvt_BAD },
    { 1 , "doevents"                     , ""                             , 0 , comvt_BAD },
    { 1 , "double"                       , "double"                       , 2 , comvt_BAD },
    { 1 , "download"                     , ""                             , 0 , comvt_BAD },
    { 1 , "downloadtostr"                , ""                             , 0 , comvt_BAD },
    { 1 , "dpi"                          , "dpi"                          , 2 , comvt_BAD },
    { 1 , "dq$"                          , ""                             , 0 , comvt_BAD },
    { 1 , "draw"                         , ""                             , 0 , comvt_BAD },
    { 1 , "drawtransbmp"                 , ""                             , 0 , comvt_BAD },
    { 1 , "dsplit"                       , ""                             , 0 , comvt_BAD },
    { 1 , "dwl_dlgproc"                  , "DWLP_DLGPROC"                 , 2 , comvt_BAD },
    { 1 , "dwl_msgresult"                , "DWLP_MSGRESULT"               , 2 , comvt_BAD },
    { 1 , "dwl_user"                     , "DWLP_USER"                    , 2 , comvt_BAD },
    { 1 , "dword"                        , "ULONG"                        , 2 , comvt_BAD },
    { 1 , "dynamic"                      , "dynamic"                      , 2 , comvt_BAD },
    { 1 , "dynamic_cast"                 , "dynamic_cast"                 , 3 , comvt_BAD },
    { 1 , "editloadfile"                 , ""                             , 0 , comvt_BAD },
    { 1 , "ejectpage"                    , "ejectpage"                    , 2 , comvt_BAD },
    { 1 , "else"                         , "else"                         , 2 , comvt_BAD },
    { 1 , "elseif"                       , ""                             , 0 , comvt_BAD },
    { 1 , "enc$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "end"                          , ""                             , 0 , comvt_BAD },
    { 1 , "enddraw"                      , ""                             , 0 , comvt_BAD },
    { 1 , "endif"                        , "endif"                        , 2 , comvt_BAD },
    { 1 , "endmodal"                     , ""                             , 0 , comvt_BAD },
    { 1 , "enum"                         , ""                             , 0 , comvt_BAD },
    { 1 , "environ$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "eof"                          , ""                             , 0 , comvt_BAD },
    { 1 , "eof$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "equalto"                      , ""                             , 0 , comvt_BAD },
    { 1 , "esc$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "events"                       , "events"                       , 0 , comvt_BAD },
    { 1 , "exist"                        , ""                             , 0 , comvt_BAD },
    { 1 , "exit"                         , "exit"                         , 2 , comvt_BAD },
    { 1 , "exit_each"                    , "EXIT_EACH"                    , 2 , comvt_BAD },
    { 1 , "exp"                          , ""                             , 0 , comvt_R8 },
    { 1 , "explicit"                     , "explicit"                     , 3 , comvt_BAD },
    { 1 , "export"                       , "export"                       , 2 , comvt_BAD },
    { 1 , "extern"                       , "extern"                       , 2 , comvt_BAD },
    { 1 , "extract$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "extractany$"                  , ""                             , 0 , comvt_BAD },
    { 1 , "fallthrough"                  , "fallthrough"                  , 2 , comvt_BAD },
    { 1 , "false"                        , ""                             , 0 , comvt_BAD },
    { 1 , "farproc"                      , "FARPROC"                      , 2 , comvt_BAD },
    { 1 , "ff$"                          , ""                             , 0 , comvt_BAD },
    { 1 , "file"                         , "FILE"                         , 2 , comvt_BAD },
    { 1 , "filecopy"                     , "copyfile"                     , 2 , comvt_BAD },
    { 1 , "filelocked"                   , ""                             , 0 , comvt_BAD },
    { 1 , "fillarray"                    , ""                             , 0 , comvt_BAD },
    { 1 , "findfirst$"                   , ""                             , 0 , comvt_BAD },
    { 1 , "findfirstinstance"            , ""                             , 0 , comvt_BAD },
    { 1 , "findintype"                   , ""                             , 0 , comvt_BAD },
    { 1 , "findnext$"                    , ""                             , 0 , comvt_BAD },
    { 1 , "finput"                       , "finput"                       , 2 , comvt_BAD },
    { 1 , "fint"                         , ""                             , 0 , comvt_INT },
    { 1 , "fix"                          , ""                             , 0 , comvt_R4 },
    { 1 , "float"                        , "float"                        , 2 , comvt_BAD },
    { 1 , "floor"                        , "floor"                        , 2 , comvt_BAD },
    { 1 , "flush"                        , "flush"                        , 2 , comvt_BAD },
    { 1 , "for"                          , ""                             , 0 , comvt_BAD },
    { 1 , "for_each"                     , ""                             , 0 , comvt_BAD },
    { 1 , "format$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "formload"                     , "FormLoad"                     , 2 , comvt_BAD },
    { 1 , "fprint"                       , "fprint"                       , 2 , comvt_BAD },
    { 1 , "frac"                         , ""                             , 0 , comvt_R8 },
    { 1 , "fracl"                        , ""                             , 0 , comvt_BAD },
    { 1 , "free"                         , "free"                         , 2 , comvt_BAD },
    { 1 , "freefile"                     , ""                             , 0 , comvt_BAD },
    { 1 , "freeglobals"                  , "FreeGlobals"                  , 2 , comvt_BAD },
    { 1 , "freelibrary"                  , "FreeLibrary"                  , 2 , comvt_BAD },
    { 1 , "friend"                       , ""                             , 1 , comvt_BAD },
    { 1 , "from"                         , "from"                         , 2 , comvt_BAD },
    { 1 , "funcname$"                    , "__func__$"                    , 2 , comvt_BAD },
    { 1 , "function"                     , ""                             , 0 , comvt_BAD },
    { 1 , "fwrite"                       , "fwrite"                       , 2 , comvt_BAD },
    { 1 , "gcl_hbrbackground"            , "GCLP_HBRBACKGROUND"           , 2 , comvt_BAD },
    { 1 , "gcl_hcursor"                  , "GCLP_HCURSOR"                 , 2 , comvt_BAD },
    { 1 , "gcl_hicon"                    , "GCLP_HICON"                   , 2 , comvt_BAD },
    { 1 , "gcl_hiconsm"                  , "GCLP_HICONSM"                 , 2 , comvt_BAD },
    { 1 , "gcl_hmodule"                  , "GCLP_HMODULE"                 , 2 , comvt_BAD },
    { 1 , "gcl_menuname"                 , "GCLP_MENUNAME"                , 2 , comvt_BAD },
    { 1 , "gcl_wndproc"                  , "GCLP_WNDPROC"                 , 2 , comvt_BAD },
    { 1 , "get"                          , "~get"                         , 2 , comvt_BAD },
    { 1 , "get$"                         , "~get"                         , 2 , comvt_BAD },
    { 1 , "getaddr$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "getattr"                      , ""                             , 0 , comvt_BAD },
    { 1 , "getbmp"                       , ""                             , 0 , comvt_BAD },
    { 1 , "getbvalue"                    , "GetBValue"                    , 2 , comvt_BAD },
    { 1 , "getch"                        , "_getch"                       , 2 , comvt_BAD },
    { 1 , "getdimension"                 , ""                             , 0 , comvt_BAD },
    { 1 , "getdlgitem"                   , "GetDlgItem"                   , 2 , comvt_BAD },
    { 1 , "getdrive"                     , ""                             , 0 , comvt_BAD },
    { 1 , "getfilename$"                 , ""                             , 0 , comvt_BAD },
    { 1 , "getgvalue"                    , "GetGValue"                    , 2 , comvt_BAD },
    { 1 , "gethttpfilesize"              , ""                             , 0 , comvt_BAD },
    { 1 , "getobject"                    , ""                             , 0 , comvt_BAD },
    { 1 , "getprocaddress"               , ""                             , 0 , comvt_BAD },
    { 1 , "getresource"                  , ""                             , 0 , comvt_BAD },
    { 1 , "getrvalue"                    , "GetRValue"                    , 2 , comvt_BAD },
    { 1 , "getsaveasfilename"            , ""                             , 0 , comvt_BAD },
    { 1 , "getspecialfolder"             , ""                             , 0 , comvt_BAD },
    { 1 , "getspecialfolder$"            , ""                             , 0 , comvt_BAD },
    { 1 , "getspecialfolderex$"          , ""                             , 0 , comvt_BAD },
    { 1 , "gettextsize"                  , ""                             , 0 , comvt_BAD },
    { 1 , "getwindowlong"                , "GetWindowLongPtr"             , 2 , comvt_BAD },
    { 1 , "global"                       , "global"                       , 2 , comvt_BAD },
    { 1 , "gosub"                        , "gosub"                        , 2 , comvt_BAD },
    { 1 , "goto"                         , "goto"                         , 2 , comvt_BAD },
    { 1 , "gui"                          , "gui"                          , 2 , comvt_BAD },
    { 1 , "gwl_hinstance"                , "GWLP_HINSTANCE"               , 2 , comvt_BAD },
    { 1 , "gwl_hwndparent"               , "GWLP_HWNDPARENT"              , 2 , comvt_BAD },
    { 1 , "gwl_id"                       , "GWLP_ID"                      , 2 , comvt_BAD },
    { 1 , "gwl_userdata"                 , "GWLP_USERDATA"                , 2 , comvt_BAD },
    { 1 , "gwl_wndproc"                  , "GWLP_WNDPROC"                 , 2 , comvt_BAD },
    { 1 , "hex$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "hex2dec"                      , ""                             , 0 , comvt_I4 },
    { 1 , "hibyte"                       , "HIBYTE"                       , 2 , comvt_BAD },
    { 1 , "hide"                         , ""                             , 0 , comvt_BAD },
    { 1 , "hiword"                       , "HIWORD"                       , 2 , comvt_BAD },
    { 1 , "hypot"                        , "hypot"                        , 2 , comvt_R8 },
    { 1 , "hypotl"                       , "hypotl"                       , 2 , comvt_R8 },
    { 1 , "iabs"                         , "abs"                          , 2 , comvt_BAD },
    { 1 , "icompare"                     , ""                             , 0 , comvt_BAD },
    { 1 , "icon"                         , "icon"                         , 2 , comvt_BAD },
    { 1 , "if"                           , "if"                           , 16, comvt_BAD },
    { 1 , "iif"                          , ""                             , 0 , comvt_R8 },
    { 1 , "iif$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "iinstr"                       , ""                             , 0 , comvt_BAD },
    { 1 , "iinstrany"                    , ""                             , 0 , comvt_BAD },
    { 1 , "imod"                         , ""                             , 0 , comvt_BAD },
    { 1 , "impfunction"                  , "impfunction"                  , 3 , comvt_BAD },
    { 1 , "in"                           , "in"                           , 0 , comvt_BAD },
    { 1 , "inchr"                        , ""                             , 0 , comvt_R4 },
    { 1 , "incr"                         , "incr"                         , 2 , comvt_BAD },
    { 1 , "infobox"                      , ""                             , 0 , comvt_BAD },
    { 1 , "initsafearray"                , "InitSafeArray"                , 0 , comvt_BAD },
    { 1 , "inkey"                        , ""                             , 0 , comvt_BAD },
    { 1 , "inkey$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "inline"                       , ""                             , 1 , comvt_BAD },
    { 1 , "inp"                          , ""                             , 0 , comvt_BAD },
    { 1 , "input"                        , ""                             , 0 , comvt_BAD },
    { 1 , "inputbox$"                    , ""                             , 0 , comvt_BAD },
    { 1 , "inputbuffer$"                 , "InputBuffer$"                 , 0 , comvt_BAD },
    { 1 , "ins$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "instat"                       , "_kbhit()"                     , 2 , comvt_BAD },
    { 1 , "instr"                        , ""                             , 0 , comvt_R4 },
    { 1 , "instrany"                     , ""                             , 0 , comvt_BAD },
    { 1 , "instrrev"                     , ""                             , 0 , comvt_R4 },
    { 1 , "int"                          , "int"                          , 2 , comvt_BAD },
    { 1 , "integer"                      , "int"                          , 2 , comvt_BAD },
    { 1 , "iremove"                      , ""                             , 16, comvt_BAD },
    { 1 , "iremove$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "iremoveany$"                  , ""                             , 0 , comvt_BAD },
    { 1 , "ireplace"                     , ""                             , 16, comvt_BAD },
    { 1 , "ireplace$"                    , ""                             , 0 , comvt_BAD },
    { 1 , "ireplaceany$"                 , ""                             , 0 , comvt_BAD },
    { 1 , "is"                           , "is"                           , 2 , comvt_BAD },
    { 1 , "isdigit"                      , "isdigit"                      , 2 , comvt_BAD },
    { 1 , "isobject"                     , "ISOBJECT"                     , 2 , comvt_BAD },
    { 1 , "isodate"                      , ""                             , 0 , comvt_BAD },
    { 1 , "isptr"                        , ""                             , 0 , comvt_BAD },
    { 1 , "ispunct"                      , "ispunct"                      , 2 , comvt_BAD },
    { 1 , "iswxdigit"                    , "iswxdigit"                    , 2 , comvt_BAD },
    { 1 , "iterate"                      , "continue"                     , 2 , comvt_BAD },
    { 1 , "join$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "keypress"                     , ""                             , 0 , comvt_BAD },
    { 1 , "kill"                         , "kill"                         , 2 , comvt_BAD },
    { 1 , "labs"                         , "labs"                         , 2 , comvt_BAD },
    { 1 , "land"                         , ""                             , 0 , comvt_BAD },
    { 3 , "lcase$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "lccpath$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "ldouble"                      , ""                             , 0 , comvt_BAD },
    { 1 , "left$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "leftstr"                      , ""                             , 0 , comvt_BAD },
    { 1 , "len"                          , "(int)strlen"                  , 2 , comvt_R4 },
    { 1 , "lf$"                          , ""                             , 0 , comvt_BAD },
    { 1 , "lib"                          , "lib"                          , 2 , comvt_BAD },
    { 1 , "libmain"                      , "dllmain"                      , 2 , comvt_BAD },
    { 1 , "like"                         , ""                             , 0 , comvt_BAD },
    { 1 , "like_instr"                   , ""                             , 0 , comvt_BAD },
    { 1 , "line"                         , ""                             , 0 , comvt_BAD },
    { 1 , "listboxloadfile"              , ""                             , 0 , comvt_BAD },
    { 1 , "llabs"                        , "llabs"                        , 2 , comvt_BAD },
    { 1 , "load_dll"                     , "LoadLibrary"                  , 2 , comvt_BAD },
    { 1 , "loadfile$"                    , ""                             , 0 , comvt_BAD },
    { 1 , "loadlibrary"                  , "LoadLibrary"                  , 2 , comvt_BAD },
    { 1 , "lobyte"                       , "LOBYTE"                       , 2 , comvt_BAD },
    { 1 , "loc"                          , ""                             , 0 , comvt_BAD },
    { 1 , "local"                        , ""                             , 0 , comvt_BAD },
    { 1 , "locate"                       , ""                             , 0 , comvt_BAD },
    { 1 , "lof"                          , ""                             , 0 , comvt_R8 },
    { 1 , "log"                          , "log"                          , 2 , comvt_R8 },
    { 1 , "log10"                        , "log10"                        , 2 , comvt_R8 },
    { 1 , "log10l"                       , "log10l"                       , 2 , comvt_BAD },
    { 1 , "logl"                         , "logl"                         , 2 , comvt_BAD },
    { 1 , "long"                         , "long"                         , 2 , comvt_BAD },
    { 1 , "longest"                      , ""                             , 0 , comvt_BAD },
    { 1 , "longlong"                     , "LONGLONG"                     , 2 , comvt_BAD },
    { 1 , "lookahead"                    , ""                             , 0 , comvt_BAD },
    { 1 , "loop"                         , "loop"                         , 2 , comvt_BAD },
    { 1 , "lor"                          , ""                             , 0 , comvt_BAD },
    { 1 , "loword"                       , "LOWORD"                       , 2 , comvt_BAD },
    { 1 , "lpad$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "lpbyte"                       , "PBYTE"                        , 2 , comvt_BAD },
    { 1 , "lprint"                       , ""                             , 0 , comvt_BAD },
    { 1 , "lpstr"                        , "PSTR"                         , 2 , comvt_BAD },
    { 1 , "lresult"                      , "LRESULT"                      , 2 , comvt_BAD },
    { 1 , "ltoa"                         , "_ltoa"                        , 2 , comvt_BAD },
    { 1 , "ltrim$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "macro"                        , "const"                        , 2 , comvt_BAD },
    { 1 , "main"                         , "main"                         , 2 , comvt_BAD },
    { 1 , "makedword"                    , "MAKELONG"                     , 2 , comvt_BAD },
    { 1 , "makeintresource"              , "MAKEINTRESOURCE"              , 2 , comvt_BAD },
    { 1 , "makelong"                     , "MAKELONG"                     , 2 , comvt_BAD },
    { 1 , "makeword"                     , "MAKEWORD"                     , 2 , comvt_BAD },
    { 1 , "max"                          , ""                             , 0 , comvt_R8 },
    { 3 , "mcase$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "mdigui"                       , "mdigui"                       , 2 , comvt_BAD },
    { 1 , "me"                           , ""                             , 0 , comvt_BAD },
    { 1 , "memicmp"                      , "_memicmp"                     , 2 , comvt_BAD },
    { 1 , "memsize"                      , "_msize"                       , 2 , comvt_BAD },
    { 1 , "mid$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "min"                          , ""                             , 0 , comvt_R8 },
    { 1 , "mkd$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "mkdir"                        , "_mkdir"                       , 2 , comvt_BAD },
    { 1 , "mki$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "mkl$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "mkld$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "mks$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "mod"                          , "fmod"                         , 2 , comvt_BAD },
    { 1 , "modstyle"                     , ""                             , 0 , comvt_BAD },
    { 1 , "mouse_cx"                     , ""                             , 0 , comvt_BAD },
    { 1 , "mouse_cy"                     , ""                             , 0 , comvt_BAD },
    { 1 , "mouse_sx"                     , ""                             , 0 , comvt_BAD },
    { 1 , "mouse_sy"                     , ""                             , 0 , comvt_BAD },
    { 1 , "msgbox"                       , ""                             , 0 , comvt_BAD },
    { 1 , "namespace"                    , "namespace"                    , 3 , comvt_BAD },
    { 1 , "nest"                         , "nest"                         , 2 , comvt_BAD },
    { 1 , "new"                          , ""                             , 1 , comvt_BAD },
    { 1 , "newbmp"                       , ""                             , 0 , comvt_BAD },
    { 1 , "next"                         , "next"                         , 34, comvt_BAD },
    { 1 , "next_each"                    , ""                             , 0 , comvt_BAD },
    { 1 , "nextlinelen"                  , ""                             , 0 , comvt_BAD },
    { 1 , "nosort"                       , "WS_CHILD|WS_VISIBLE|WS_VSCROLL", 2, comvt_BAD },
    { 1 , "not"                          , ""                             , 0 , comvt_BAD },
    { 1 , "notequalto"                   , ""                             , 0 , comvt_BAD },
    { 1 , "nothing"                      , ""                             , 0 , comvt_BAD },
    { 1 , "now$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "nul$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "null"                         , "NULL"                         , 2 , comvt_BAD },
    { 1 , "object"                       , ""                             , 0 , comvt_BAD },
    { 1 , "oct$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "on"                           , "on"                           , 0 , comvt_BAD },
    { 1 , "open"                         , ""                             , 0 , comvt_BAD },
    { 1 , "operator"                     , ""                             , 0 , comvt_BAD },
    { 1 , "option"                       , "option"                       , 2 , comvt_BAD },
    { 1 , "optional"                     , "optional"                     , 2 , comvt_BAD },
    { 1 , "or"                           , ""                             , 0 , comvt_BAD },
    { 1 , "orelse"                       , ""                             , 0 , comvt_BAD },
    { 1 , "osversion"                    , ""                             , 0 , comvt_BAD },
    { 1 , "outp"                         , ""                             , 0 , comvt_BAD },
    { 1 , "output"                       , ""                             , 0 , comvt_BAD },
    { 1 , "outpw"                        , ""                             , 0 , comvt_BAD },
    { 1 , "overloaded"                   , ""                             , 0 , comvt_BAD },
    { 1 , "panel"                        , ""                             , 0 , comvt_BAD },
    { 1 , "pause"                        , ""                             , 0 , comvt_BAD },
    { 1 , "pchar"                        , "PCHAR"                        , 2 , comvt_BAD },
    { 1 , "peek$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "pellespath$"                  , ""                             , 0 , comvt_BAD },
    { 1 , "pi"                           , ""                             , 0 , comvt_BAD },
    { 1 , "pixels"                       , "pixels"                       , 2 , comvt_BAD },
    { 1 , "playwav"                      , ""                             , 0 , comvt_BAD },
    { 1 , "poke"                         , "memcpy"                       , 2 , comvt_BAD },
    { 1 , "popcolors"                    , ""                             , 0 , comvt_BAD },
    { 1 , "pos"                          , ""                             , 0 , comvt_R4 },
    { 1 , "pow"                          , "pow"                          , 2 , comvt_R8 },
    { 1 , "powl"                         , "powl"                         , 2 , comvt_BAD },
    { 1 , "pptype"                       , "pptype"                       , 2 , comvt_BAD },
    { 1 , "prepend"                      , "prepend"                      , 2 , comvt_BAD },
    { 1 , "preserve"                     , "PRESERVE"                     , 2 , comvt_BAD },
    { 1 , "print"                        , ""                             , 0 , comvt_BAD },
    { 1 , "print#"                       , "fprint"                       , 2 , comvt_BAD },
    { 1 , "printer"                      , ""                             , 0 , comvt_BAD },
    { 1 , "private"                      , ""                             , 1 , comvt_BAD },
    { 1 , "program"                      , "program"                      , 2 , comvt_BAD },
    { 1 , "property"                     , "property"                     , 3 , comvt_BAD },
    { 1 , "protected"                    , ""                             , 1 , comvt_BAD },
    { 1 , "ps_dash"                      , "PS_DASH"                      , 2 , comvt_BAD },
    { 1 , "ps_dashdot"                   , "PS_DASHDOT"                   , 2 , comvt_BAD },
    { 1 , "ps_dashdotdot"                , "PS_DASHDOTDOT"                , 2 , comvt_BAD },
    { 1 , "ps_dot"                       , "PS_DOT"                       , 2 , comvt_BAD },
    { 1 , "ps_solid"                     , "PS_SOLID"                     , 2 , comvt_BAD },
    { 1 , "pstr"                         , "PSTR"                         , 2 , comvt_BAD },
    { 1 , "ptr"                          , ""                             , 0 , comvt_BAD },
    { 1 , "public"                       , ""                             , 1 , comvt_BAD },
    { 1 , "pushcolors"                   , ""                             , 0 , comvt_BAD },
    { 1 , "put"                          , "~put"                         , 2 , comvt_BAD },
    { 1 , "put$"                         , "~put"                         , 2 , comvt_BAD },
    { 1 , "qbcolor"                      , ""                             , 0 , comvt_BAD },
    { 1 , "qsort"                        , "qsort"                        , 2 , comvt_BAD },
    { 1 , "qsortidx"                     , "qsortidx"                     , 2 , comvt_BAD },
    { 1 , "radtodeg"                     , ""                             , 0 , comvt_BAD },
    { 1 , "randomize"                    , ""                             , 0 , comvt_BAD },
    { 1 , "raw"                          , "raw"                          , 2 , comvt_BAD },
    { 1 , "read"                         , ""                             , 0 , comvt_BAD },
    { 1 , "read$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "rec"                          , ""                             , 0 , comvt_BAD },
    { 1 , "reccount"                     , ""                             , 0 , comvt_BAD },
    { 1 , "reclen"                       , "reclen"                       , 2 , comvt_BAD },
    { 1 , "record"                       , "record"                       , 2 , comvt_BAD },
    { 1 , "redim"                        , "redim"                        , 2 , comvt_BAD },
    { 1 , "refresh"                      , ""                             , 0 , comvt_BAD },
    { 1 , "regexist"                     , ""                             , 0 , comvt_BAD },
    { 1 , "regint"                       , ""                             , 0 , comvt_BAD },
    { 1 , "register"                     , "register"                     , 2 , comvt_BAD },
    { 1 , "regstring$"                   , ""                             , 0 , comvt_BAD },
    { 1 , "reinterpret_cast"             , "reinterpret_cast"             , 3 , comvt_BAD },
    { 1 , "release"                      , ""                             , 0 , comvt_BAD },
    { 1 , "rem"                          , "rem"                          , 0 , comvt_BAD },
    { 1 , "remain$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "remainany$"                   , ""                             , 0 , comvt_BAD },
    { 1 , "remove"                       , "remove"                       , 18, comvt_BAD },
    { 1 , "remove$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "removeany$"                   , ""                             , 0 , comvt_BAD },
    { 1 , "rename"                       , "rename"                       , 2 , comvt_BAD },
    { 1 , "repeat"                       , "repeat"                       , 0 , comvt_BAD },
    { 1 , "repeat$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "replace"                      , "replace"                      , 18, comvt_BAD },
    { 1 , "replace$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "replaceany$"                  , ""                             , 0 , comvt_BAD },
    { 1 , "resume"                       , ""                             , 0 , comvt_BAD },
    { 1 , "retain$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "return"                       , "return"                       , 2 , comvt_BAD },
    { 1 , "reverse$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "rewind"                       , ""                             , 0 , comvt_BAD },
    { 1 , "right$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "rightstr"                     , ""                             , 0 , comvt_BAD },
    { 1 , "rmdir"                        , "_rmdir"                       , 2 , comvt_BAD },
    { 1 , "rnd"                          , ""                             , 0 , comvt_R4 },
    { 1 , "rnd2"                         , ""                             , 0 , comvt_R4 },
    { 1 , "round"                        , ""                             , 0 , comvt_R8 },
    { 1 , "rpad$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "rtrim$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "run"                          , ""                             , 0 , comvt_BAD },
    { 1 , "savebmp"                      , ""                             , 0 , comvt_BAD },
    { 1 , "scanerror"                    , "ScanError"                    , 2 , comvt_BAD },   ' For access to input Error Code
    { 1 , "schar"                        , "signed char"                  , 2 , comvt_BAD },
    { 1 , "screen"                       , ""                             , 0 , comvt_BAD },
    { 1 , "searchpath$"                  , ""                             , 0 , comvt_BAD },
    { 1 , "seek"                         , "seek"                         , 2 , comvt_BAD },
    { 1 , "select"                       , "select"                       , 2 , comvt_BAD },
    { 1 , "sendmessage"                  , ""                             , 0 , comvt_BAD },
    { 1 , "set"                          , ""                             , 0 , comvt_BAD },
    { 1 , "set_bcx_bitmap"               , ""                             , 0 , comvt_BAD },
    { 1 , "set_bcx_bitmap2"              , ""                             , 0 , comvt_BAD },
    { 1 , "set_bcx_bmpbutton"            , ""                             , 0 , comvt_BAD },
    { 1 , "set_bcx_icon"                 , ""                             , 0 , comvt_BAD },
    { 1 , "setaddr"                      , ""                             , 0 , comvt_BAD },
    { 1 , "setattr"                      , ""                             , 0 , comvt_BAD },
    { 1 , "setdialogscale"               , "SetDialogScale"               , 2 , comvt_BAD },
    { 1 , "setdimension"                 , ""                             , 0 , comvt_BAD },
    { 1 , "seteof"                       , "SetEof"                       , 2 , comvt_BAD },
    { 1 , "setmode"                      , "_setmode"                     , 2 , comvt_BAD },
    { 1 , "setwindowlong"                , "SetWindowLongPtr"             , 2 , comvt_BAD },
    { 1 , "setwindowrtftext"             , ""                             , 0 , comvt_BAD },
    { 1 , "sgn"                          , ""                             , 0 , comvt_R4 },
    { 1 , "shared"                       , "shared"                       , 2 , comvt_BAD },
    { 1 , "shell"                        , "shell"                        , 2 , comvt_BAD },
    { 1 , "shl"                          , ""                             , 0 , comvt_BAD },
    { 1 , "short"                        , "short"                        , 2 , comvt_BAD },
    { 1 , "show"                         , ""                             , 0 , comvt_BAD },
    { 1 , "showmodal"                    , ""                             , 0 , comvt_BAD },
    { 1 , "shr"                          , ""                             , 0 , comvt_BAD },
    { 1 , "sin"                          , "sin"                          , 2 , comvt_R8 },
    { 1 , "single"                       , "float"                        , 2 , comvt_BAD },
    { 1 , "sinh"                         , "sinh"                         , 2 , comvt_R8 },
    { 1 , "sinl"                         , "sinl"                         , 2 , comvt_BAD },
    { 1 , "size_t"                       , "size_t"                       , 2 , comvt_R4 },
    { 1 , "sizeof"                       , "sizeof"                       , 2 , comvt_R4 },
    { 1 , "sleep"                        , ""                             , 0 , comvt_BAD },
    { 1 , "sndmsg"                       , ""                             , 0 , comvt_BAD },
    { 1 , "sound"                        , ""                             , 0 , comvt_BAD },
    { 1 , "space$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "spc$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "split"                        , ""                             , 0 , comvt_BAD },
    { 1 , "splitbarbg"                   , "SplitBarBG"                   , 2 , comvt_BAD },
    { 1 , "splitbarfg"                   , "SplitBarFG"                   , 2 , comvt_BAD },
    { 1 , "sprint"                       , "sprint"                       , 2 , comvt_BAD },
    { 1 , "sqr"                          , "sqrt"                         , 2 , comvt_R8 },
    { 1 , "sqrl"                         , "sqrtl"                        , 2 , comvt_BAD },
    { 1 , "sqrt"                         , "sqrt"                         , 2 , comvt_R8 },
    { 1 , "sqrtl"                        , "sqrtl"                        , 2 , comvt_BAD },
    { 1 , "sshort"                       , "signed short"                 , 2 , comvt_BAD },
    { 1 , "startdraw"                    , ""                             , 0 , comvt_BAD },
    { 1 , "static"                       , "static"                       , 2 , comvt_BAD },
    { 1 , "static_cast"                  , "static_cast"                  , 3 , comvt_BAD },
    { 1 , "stdcall"                      , ""                             , 0 , comvt_BAD },
    { 1 , "step"                         , ""                             , 0 , comvt_BAD },
    { 1 , "str$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "str2variant"                  , ""                             , 0 , comvt_BAD },
    { 1 , "strarray"                     , "PCHAR*"                       , 2 , comvt_BAD },
    { 1 , "strim$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "string"                       , "string"                       , 2 , comvt_BAD },
    { 1 , "string$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "strl$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "strptr"                       , ""                             , 0 , comvt_BAD },
    { 1 , "strtoken$"                    , ""                             , 0 , comvt_BAD },
    { 1 , "struct"                       , "struct"                       , 0 , comvt_BAD },
    { 1 , "sub"                          , "sub"                          , 0 , comvt_BAD },
    { 1 , "swap"                         , ""                             , 0 , comvt_BAD },
    { 1 , "sysdir$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "sysstr"                       , ""                             , 0 , comvt_BAD },
    { 1 , "szlabel"                      , ""                             , 0 , comvt_BAD },
    { 1 , "szlabel$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "tab$"                         , ""                             , 0 , comvt_BAD },
    { 1 , "tally"                        , ""                             , 0 , comvt_R4 },
    { 1 , "tan"                          , "tan"                          , 2 , comvt_R8 },
    { 1 , "tanh"                         , "tanh"                         , 2 , comvt_R8 },
    { 1 , "tanl"                         , "tanl"                         , 2 , comvt_BAD },
    { 1 , "tempdir$"                     , ""                             , 0 , comvt_BAD },
    { 1 , "tempfilename$"                , ""                             , 0 , comvt_BAD },
    { 1 , "template"                     , "template"                     , 2 , comvt_BAD },
    { 1 , "textmode"                     , ""                             , 0 , comvt_BAD },
    { 1 , "then"                         , ""                             , 0 , comvt_BAD },
    { 1 , "this"                         , "this"                         , 3 , comvt_BAD },
    { 1 , "throw"                        , "throw"                        , 3 , comvt_BAD },
    { 1 , "time$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "timer"                        , ""                             , 0 , comvt_R4 },
    { 1 , "to"                           , "to"                           , 0 , comvt_BAD },
    { 1 , "trim$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "true"                         , ""                             , 0 , comvt_BAD },
    { 1 , "try"                          , "try"                          , 3 , comvt_BAD },
    { 1 , "type"                         , "type"                         , 2 , comvt_BAD },
    { 1 , "typeid"                       , "typeid$"                      , 3 , comvt_BAD },
    { 1 , "typename"                     , ""                             , 1 , comvt_BAD },
    { 1 , "ubound"                       , ""                             , 0 , comvt_BAD },
    { 1 , "ubound_d"                     , ""                             , 0 , comvt_BAD },
    { 1 , "ubound_s"                     , ""                             , 0 , comvt_BAD },
    { 1 , "ubyte"                        , "unsigned char"                , 2 , comvt_BAD },
    { 3 , "ucase$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "uchar"                        , "UCHAR"                        , 2 , comvt_BAD },
    { 1 , "uint"                         , "UINT"                         , 2 , comvt_BAD },
    { 1 , "uint64"                       , "UINT64"                       , 2 , comvt_BAD },
    { 1 , "ulong"                        , "ULONG"                        , 2 , comvt_BAD },
    { 1 , "ulonglong"                    , "ULONGLONG"                    , 2 , comvt_BAD },
    { 1 , "uncom"                        , "UNCOM"                        , 0 , comvt_BAD },
    { 1 , "union"                        , "union"                        , 2 , comvt_BAD },
    { 1 , "until"                        , ""                             , 0 , comvt_BAD },
    { 1 , "unwrap$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "ushort"                       , "USHORT"                       , 2 , comvt_BAD },
    { 1 , "using"                        , "using"                        , 3 , comvt_BAD },
    { 1 , "using$"                       , ""                             , 0 , comvt_BAD },
    { 1 , "utf8tochr"                    , ""                             , 0 , comvt_BAD },
    { 1 , "val"                          , ""                             , 0 , comvt_R8 },
    { 1 , "vall"                         , ""                             , 0 , comvt_BAD },
    { 1 , "variant"                      , "VARIANT"                      , 2 , comvt_BAD },
    { 1 , "variant2str"                  , ""                             , 0 , comvt_BAD },
    { 1 , "vbs_addcode"                  , ""                             , 0 , comvt_BAD },
    { 1 , "vbs_error$"                   , ""                             , 0 , comvt_BAD },
    { 1 , "vbs_eval_num"                 , ""                             , 0 , comvt_BAD },
    { 1 , "vbs_eval_num#"                , ""                             , 0 , comvt_BAD },
    { 1 , "vbs_eval_str$"                , ""                             , 0 , comvt_BAD },
    { 1 , "vbs_reset"                    , ""                             , 0 , comvt_BAD },
    { 1 , "vbs_run_script"               , ""                             , 0 , comvt_BAD },
    { 1 , "vbs_start"                    , ""                             , 0 , comvt_BAD },
    { 1 , "vbs_stop"                     , ""                             , 0 , comvt_BAD },
    { 1 , "vchr$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "vector"                       , ""                             , 0 , comvt_BAD },
    { 1 , "verify"                       , ""                             , 0 , comvt_BAD },
    { 1 , "virtual"                      , ""                             , 1 , comvt_BAD },
    { 1 , "vt$"                          , ""                             , 0 , comvt_BAD },
    { 1 , "wchar"                        , "WCHAR"                        , 2 , comvt_BAD },
    { 1 , "wend"                         , "wend"                         , 2 , comvt_BAD },
    { 1 , "while"                        , ""                             , 0 , comvt_BAD },
    { 1 , "widetoansi$"                  , ""                             , 0 , comvt_BAD },
    { 1 , "winbool"                      , "winbool"                      , 2 , comvt_BAD },
    { 1 , "windir$"                      , ""                             , 0 , comvt_BAD },
    { 1 , "winmain"                      , ""                             , 0 , comvt_BAD },
    { 1 , "with"                         , ""                             , 0 , comvt_BAD },
    { 1 , "wndproc"                      , ""                             , 0 , comvt_BAD },
    { 1 , "word"                         , "WORD"                         , 2 , comvt_BAD },
    { 1 , "wrap$"                        , ""                             , 0 , comvt_BAD },
    { 1 , "write"                        , "write"                        , 2 , comvt_BAD },
    { 1 , "wstring"                      , "PWSTR"                        , 2 , comvt_BAD },
    { 3 , "xor"                          , ""                             , 0 , comvt_BAD },
    { 1 , "zzzz"                         , "zzzz"                         , 0 , comvt_BAD }
END SET

'******************************************************************************
'                              CODE BEGINS
'******************************************************************************

FUNCTION MAIN(ARGC AS INT, ARGV[] AS PCHAR)
    GLOBAL FuncStrNames$ * c_MaxSrcLen
    GLOBAL FuncSglNames$ * c_MaxSrcLen
    GLOBAL FuncDblNames$ * c_MaxSrcLen
    GLOBAL CurLine$      * c_MaxSrcLen
    GLOBAL gTmpStr$      * c_MaxSrcLen
    GLOBAL Src$          * c_MaxSrcLen
    GLOBAL AbortSrc$     * c_MaxSrcLen
    GLOBAL IF_Stmt_Tank$ * c_MaxSrcLen   ' Support for the "??" operator
    '**************************************************************************
    GLOBAL WarnMsg$      * 32767
    GLOBAL RmLibs$       * 32767         ' List of libraries to remove
    GLOBAL Version$
    GLOBAL Copyright$
    '**************************************************************************
    GLOBAL BcxPctEqual$ = "{BcxPctEqual}"   ' 838 New ..  %=
    GLOBAL BcxUpEqual$  = "{BcxUpEqual}"    ' 838 New ..  ^=
    GLOBAL BcxAndEqual$ = "{BcxAndEqual}"   ' 838 New ..  &=
    GLOBAL BcxOrEqual$  = "{BcxOrEqual}"    ' 838 New ..  |=
    GLOBAL BcxLLEqual$  = "{BcxLLEqual}"    ' 838 New .. <<=
    GLOBAL BcxRREqual$  = "{BcxRREqual}"    ' 838 New .. >>=
    '**************************************************************************
    Version$ += SPC$ + ENC$(ISODATE$, 40, 41) : REPLACE "-" WITH "/" IN Version$
    '**************************************************************************
    Copyright$ = "BCX BASIC to C/C++ Translator (c) 1999-" + RIGHT$(DATE$, 4) + " by Kevin Diggins"
    '**************************************************************************
    CALL InitReservedWordsLookup
    '**************************************************************************
    DebugModeOff           =  TRUE
    InMain                 =  TRUE
    OkayToSend             =  TRUE
    OptimizerEnabled       =  TRUE
    OptimizerFirstSetting  =  TRUE
    TranslateSlash         =  TRUE   ' Change "\" to "\\"
    Use_SingleFile         =  TRUE
    WinHeaders             =  TRUE   ' Include Win specific headers (*.h)
    '**************************************************************************
    '                     Some helper / formatting strings
    '**************************************************************************
    GLOBAL BKSLASH1$ = CHR$(92)                         ' \
    GLOBAL BKSLASH2$ = CHR$(92, 92)                     ' \\
    GLOBAL BKSLASH4$ = CHR$(92, 92, 92, 92)             ' \\\\
    '**************************************************************************
    GLOBAL DQUOT$    = CHR$(34, 34, 34)                 ' """
    GLOBAL DDQUOT$   = CHR$(34, 34, 34, 34)             ' """"
    '**************************************************************************
    PPFlag = FALSE           ' Initialize User-Defined PreProcessor
    PPProc = NULL
    PPDLL_HANDLE = NULL
    '**************************************************************************
    '      Check whether Bc.exe was started in Explorer or File Manager.
    '**************************************************************************
    IF CURSORX = 1 AND CURSORY = 1 AND ISNULL(COMMAND$) THEN
        HIDE (CONWIN)
        Copyright$ += CRLF$ + CRLF$ + CPAD$("Version " + c_VERSION$, 100)
        MSGBOX (SPACE$(10) + Copyright$ + CRLF$ + CRLF$ + SPACE$(12) + LTRIM$(Compiler_Used$()))
        END
    END IF
    '**************************************************************************
    IF ISNULL(COMMAND$) THEN
        PRINT
        PRINT Copyright$
        CALL  Display_Version_and_Compiler
        PRINT
        PRINT " Usage: BC infile [.bas] [options]"
        PRINT " [-b]   Build using user-defined bat file .. ex -b:c:\\bat\\pw.bat"
        PRINT " [-cpp] Generate C++ compatible code with .cpp extension"
        PRINT " [-d]   DEFINE a constant ... ex. BC MyFile -D:MyConst[=SomeValue]"
        PRINT " [-e]   Write ERRORS to BCX.ERR file"
        PRINT " [-f]   Output FILENAME... ex. BC MyFile -f:C:\\MyFiles\\MyFile.c"
        PRINT " [-i]   Send Warnings and Errors to INFOBOX"
        PRINT " [-k]   KILL the generated BCX generated 'C' file"
        PRINT " [-m]   Enable eMbedded BCX code in the C translation"
        PRINT " [-n]   Enable NO RUNTIME Code Generation"
        PRINT " [-o]   OUTPUT a copy of the generated C file to STDOUT"
        PRINT " [-q]   QUIET - No output to screen during translation"
        PRINT " [-r]   Update BCX Path variable in the Windows REGISTRY"
        PRINT " [-s]   Show STATUS of translation by line number"
        PRINT " [-u]   Turn UNICODE Support ON"
        PRINT " [-v]   Show BCX version and build information"
        PRINT " [-w]   Enable BCX WARNINGS during translation and all compiler warnings."
        PRINT " [-x]   EXCLUDE Win32 Headers from the resulting C file"
        PRINT " [-z]   ZAP (remove DEFAULT headers and libraries from the resulting C file"
        END                '     <<<- Nothing to translate, so we END
    END IF

    '****************************************************************************************************
    IF COMMAND$ ?? "-r" THEN
        CREATEREGSTRING (HKEY_LOCAL_MACHINE, "Software\\Bcx-32\\Bcx\\Settings", "Path", APPEXEPATH$)
        CREATEREGSTRING (HKEY_CURRENT_USER, "Software\\Bcx-32\\Bcx\\Settings",  "Path", APPEXEPATH$)
        PRINT "      BCX Path set to ", BCXPATH$
        END
    END IF

    IF COMMAND$ ?? "-v" THEN
        PRINT
        PRINT Copyright$
        CALL Display_Version_and_Compiler
        END
    END IF

    '****************************************************************************************************
    '                       Detect and setup any other command line switches
    '****************************************************************************************************

    FOR i AS INT = 2 TO ARGC-1
        gTmpStr$ = LCASE$(ARGV$[i])

        IF INSTR(gTmpStr$, "-b") THEN
            IF c_MaxOnExit = XitCount THEN
                CALL Abort("Maximum $OnExit exceeded.")
            END IF
            INCR XitCount
            Xit$[XitCount]= MID$(ARGV$[i], 4) + SPC$ + ENC$(EXTRACT$(COMMAND$(1), "."))
        END IF

        SELECT CASE gTmpStr$
            CASE "-c"   : UseCpp      = TRUE
            CASE "-cpp" : UseCpp      = TRUE
            CASE "-e"   : ErrFile     = TRUE
            CASE "-h"   : Gen_Header  = TRUE
            CASE "-i"   : InfoBoxWarn = TRUE
            CASE "-q"   : Quiet       = TRUE
            CASE "-k"   : KillCFile   = TRUE
            CASE "-m"   : SrcFlag     = TRUE
            CASE "-n"   : NoRT        = TRUE
            CASE "-o"   : ReDirect    = TRUE
            CASE "-s"   : ShowStatus  = TRUE
            CASE "-u"   : Use_UNICODE = TRUE
            CASE "-z"   : ZapFlag     = TRUE
            CASE "-w"   : TestState   = WarningFlag = TRUE
            CASE "-x"   : WinHeaders  = FALSE
        END SELECT

        IF m_iMatchLft(gTmpStr$, "-f:") THEN CmdLineFileOut$ = MID$(ARGV$[i], 4)
        IF m_iMatchLft(gTmpStr$, "-d:") THEN CmdLineConst$  += MID$(ARGV$[i], 4) + CHR$(1)
    NEXT

    '****************************************************************************
    '                           [ Announce Program ]
    '****************************************************************************

    IF ShowStatus THEN CLS

    IF NOT Quiet THEN
        IF c_BCX_COLORS THEN PUSHCOLORS
        IF c_BCX_COLORS THEN COLOR 11, 0
        PRINT
        PRINT Copyright$
        CALL Display_Version_and_Compiler
        IF c_BCX_COLORS THEN POPCOLORS
    END IF

    '****************************************************************************

    IF INCHR(COMMAND$(1), ".") THEN
        Cmd$ = COMMAND$(1)                          ' Allow ANY extension
    ELSE
        Cmd$ = EXTRACT$(COMMAND$(1), ".") + ".bas"  ' Assume implicit .bas
    END IF

    Cmd$ = FINDFIRST$(Cmd$)                         ' Retain the spelling

    IF INCHR(Cmd$, "*") OR INCHR(Cmd$, "?") THEN Cmd$ = FINDFIRST$(Cmd$)

    FileIn$ = Cmd$

    IF ISNULL(CmdLineFileOut$) THEN
        FileOut$ = LEFT$(Cmd$, INSTRREV(Cmd$, ".", 0)-1) + ".out"
    ELSE
        FileOut$ = CmdLineFileOut$
    END IF

    FileErr$ = LEFT$(Cmd$, INSTRREV(Cmd$, ".", 0)-1) + ".err"

    IF EXIST(FileErr$) THEN
        SHELL "DEL " + FileErr$
    END IF

    '*******************************************************

    IF DebugModeOff THEN
        gTmpStr$ = TEMPDIR$
        cppFile$ = TEMPFILENAME$(gTmpStr$, "ccode")
        prcFile$ = TEMPFILENAME$(gTmpStr$, "prc")
        udtFile$ = TEMPFILENAME$(gTmpStr$, "udt")
        datFile$ = TEMPFILENAME$(gTmpStr$, "dat")
        UsrFile$ = TEMPFILENAME$(gTmpStr$, "cst")     ' User's MACRO's
        SysFile$ = TEMPFILENAME$(gTmpStr$, "syscst")  ' System MACRO's
        ovrFile$ = TEMPFILENAME$(gTmpStr$, "ovr")
        hdrFile$ = TEMPFILENAME$(gTmpStr$, "hdr")
        setFile$ = TEMPFILENAME$(gTmpStr$, "set")
        resFile$ = TEMPFILENAME$(gTmpStr$, "res")
        enuFile$ = TEMPFILENAME$(gTmpStr$, "enu")
        defFile$ = TEMPFILENAME$(gTmpStr$, "def")
    ELSE
        gTmpStr$ = APPEXEPATH$
        cppFile$ = gTmpStr$ + "ccode_debug.txt"
        prcFile$ = gTmpStr$ + "prc_debug.txt"
        udtFile$ = gTmpStr$ + "udt_debug.txt"
        datFile$ = gTmpStr$ + "dat_debug.txt"
        UsrFile$ = gTmpStr$ + "cst_debug.txt"
        SysFile$ = gTmpStr$ + "syscst_debug.txt"
        ovrFile$ = gTmpStr$ + "ovr_debug.txt"
        hdrFile$ = gTmpStr$ + "hdr_debug.txt"
        setFile$ = gTmpStr$ + "set_debug.txt"
        resFile$ = gTmpStr$ + "res_debug.txt"
        enuFile$ = gTmpStr$ + "enu_debug.txt"
        defFile$ = gTmpStr$ + "def_debug.txt"
    END IF

    '**************************************************************************
    ' Find and Scan Main File and all $INCLUDED files        by MrBcx in 812
    '**************************************************************************
    CALL ScanIncludeFiles (FileIn$)

    FOR j AS INT = 0 TO FilesFound
        CALL ScanFunctionNames (IncludeFileNames$[j]) '[0] is always FileIn$
    NEXT

    '**************************************************************************

    OPEN FileIn$  FOR INPUT  AS SourceFile ' <<<<<<<<   THE MAIN  .BAS  FILE
    OPEN FileOut$ FOR OUTPUT AS FP2        ' <<<<<<<<   THE FINAL C/C++ FILE

    '**************************************************************************
    FP_WRITE = FP2    ' FP_WRITE changes to FP3 when in a SUB or FUNCTION
    '**************************************************************************

    OPEN cppFile$ FOR OUTPUT AS FP_CCODE   ' Temp file FOR CCODE
    OPEN SysFile$ FOR OUTPUT AS FP_SYSCST  ' Temp File FOR SYSTEM CONSTs
    OPEN prcFile$ FOR OUTPUT AS FP3        ' Temp File FOR User's Functions
    OPEN udtFile$ FOR OUTPUT AS FP_UDT     ' Temp File FOR User's Def Types
    OPEN datFile$ FOR OUTPUT AS FP_DAT     ' Temp File FOR User's Data statements
    OPEN UsrFile$ FOR OUTPUT AS FP_CST     ' Temp File FOR User's MACRO
    OPEN hdrFile$ FOR OUTPUT AS FP_HDR     ' Temp File FOR User's .h files
    OPEN resFile$ FOR OUTPUT AS FP_RES     ' Temp File FOR User's .rc files
    OPEN enuFile$ FOR OUTPUT AS FP_ENU     ' Temp File FOR User's GLOBAL ENUMs
    OPEN ovrFile$ FOR OUTPUT AS FP_OVR     ' Temp File FOR User's OVERLOADED subs & functions
    OPEN setFile$ FOR OUTPUT AS FP_SET     ' Temp File FOR User's SET Vars
    OPEN defFile$ FOR OUTPUT AS FP_DEF     ' Temp File FOR User's $DEFINE statements

    '**************************************************************************
    CALL ExportStringConst
    FileNdx = 1
    FileNames$[FileNdx] = FileIn$          ' Store the current module filename
    LineNum[FileNdx] = 0
    '**************************************************************************
    IF NoRT = TRUE THEN CALL EnableProject

    CALL Emit_Main_Function
    CALL ClearIfThenStacks

    IF UseCpp = TRUE THEN
        DIM RAW iTmp
        Docpp("", ADDRESSOF(iTmp))    ' Treats -c switch as $CPP directive
    END IF

    '*********************************************************************
    '                            The Main LOOP
    '*********************************************************************
    ReadSrcLine:
    '*********************************************************************
    DO WHILE NOT EOF(SourceFile) OR SplitCnt
        IF SplitCnt = 0 THEN             ' Process separated lines before
            LINE INPUT SourceFile, Src$  ' getting next line from file.
            INCR LineNum[FileNdx]
            '*************************************************************
            Src$ = LTRIM$(Src$)
            IF Src$ = "" THEN ITERATE

            '*************************************************************
            '            Change BASIC remarks to C/C++ remarks
            '*************************************************************
            IF InFunction THEN          ' Only output comments that exist
                IF InsertComments THEN  ' in a Sub, Function, Main/Winmain
                    IF *Src$ = c_SglQt THEN
                        FPRINT FP_WRITE, Scoot$, "//", (PCHAR)(Src+1)
                        Src$ = ""
                        ITERATE
                    END IF
                    IF m_iMatchLft(Src$, "rem ") THEN
                        FPRINT FP_WRITE, Scoot$, "//", (PCHAR)(Src+3)
                        Src$ = ""
                        ITERATE
                    END IF
                END IF
            END IF
            '***************************************************
            CALL Sanitize_Code(Src$)                                ' Remove spaces, tabs, comments
            IF Src$ = "" THEN ITERATE                               ' Skip over blank lines
            IF JoinLines(Src$) THEN ITERATE                         ' Join continuation lines " _"
            IF iMatchNQ(Src$, "[") THEN CALL FixBrackets(Src$, 0)   ' Fix Brackets
            '***************************************************    '
            IF PPFlag THEN                                          ' PreProcess the line  ($PP detected)
                GLOBAL ppret AS LONG = CAST(LONG, PPProc(Src$))     ' Error in $PP returns error message in Src$
                IF ppret = 0 THEN
                    CALL Abort(Src$)
                END IF
            END IF
            '***************************************************
            IF ISFALSE FoundMacro() THEN                            ' Process certain built-in BCX macros
                IF SplitLines(Src$) THEN                            ' Split statements separated by
                    INCR SplitCur
                    Src$ = LTRIM$(SplitStk$[SplitCur])              ' colons and single line if/then
                END IF
            END IF
        ELSE
            INCR SplitCur
            Src$ = LTRIM$(SplitStk$[SplitCur])
        END IF

        '*******************************************************
        CALL Early_Transforms  ' Special Replacement heuristics     ' 826 MrBcx relocated call to here
        '*******************************************************    ' to remove the colon "+=" limitation

        IF SplitCur = SplitCnt THEN SplitCur = SplitCnt = 0

        '*********************************************************************
        ' After translation, tokens displayed when an error occurs may
        ' not resemble the original tokens that are copied to AbortSrc$.
        '*********************************************************************

        AbortSrc$ = Src$

        '*********************************************************************
        ' No testing on inline c
        ' If you're using inline c then you should know what you are doing
        '*********************************************************************
        IF *Src$ = ASC("!") THEN   ' Test for inline C
            IF InFunction OR InClass OR InNameSpace OR InTypeDef THEN
                FPRINT FP_WRITE, MID$(Src$, 2)
            ELSE
                IF InMain THEN
                    FPRINT FP2, MID$(Src$, 2)
                ELSE
                    FPRINT FP_CST, MID$(Src$, 2)
                END IF
            END IF
            ITERATE
        END IF

        CALL CheckMatchedPairs  ' Checks that (), [], and "" are balanced

        IF (SrcFlag) OR (ShowStatus) OR (TraceFlag AND InFunction) THEN
            CALL ActivityFlags
        END IF

        IF ISNULL(Src$) THEN ITERATE


        '/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
        CALL Translate         '  Okay, let's translate!
        '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/


        '\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
        '   Important Handler for LOCAL DYNAMIC ARRAYS by MrBcx - 830
        '/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
        IF iMatchNQ(Src$, "dyn") THEN ' LIKE is costly, this is cheap
            IF LIKE(Src$, "*dim*dynamic*[*") THEN CALL ProcessInjection
        END IF
        '/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\


        '**************************************************************
        ' The following is needed for the BEGIN MODAL DIALOG procs
        '**************************************************************
        IF Inject_Local_Bcx_RetVal = TRUE THEN
            PassOne = TRUE
            Inject("LOCAL Bcx_RetVal AS INT")
            PassOne = TRUE
            Inject_Local_Bcx_RetVal = FALSE
        END IF
        '**************************************************************
    LOOP

    FLUSH(FP_WRITE)            '*************************************
    IF FPtrNdx THEN            '  Pop out the $Include File Handles
        CALL PopFileIO         '  and close them in sequence until
        GOTO ReadSrcLine       '  we end up back in the main file
    END IF                     '*************************************

    '****************************************************************
    '        END OF MAIN LOOP -- All Source code has been read
    '****************************************************************
    '        Everything below must not process more than once
    '****************************************************************

    CALL Emit_CompilerDefines

    IF TestForBcxIni = FALSE THEN
        TestForBcxIni = TRUE
        szFile$ = CURDIR$ + "\\bcx.ini"

        IF NOT EXIST(szFile$) THEN
            szFile$ = APPEXEPATH$ + "bcx.ini"
        END IF

        IF EXIST(szFile$) THEN
            CALL PushFileIO
            OPEN szFile$ FOR INPUT AS SourceFile

            IF FileNdx = c_MaxFiles-1 THEN
                CALL Abort("Maximum Include Files exceeded.")
            END IF

            INCR FileNdx
            FileNames$[FileNdx] = szFile$
            LineNum[FileNdx] = 0
            GOTO ReadSrcLine
        END IF
    END IF

    '***************************************************************
    '      Check for unbalanced LOOPS and IF-THEN errors
    '***************************************************************

    IF LoopTypeCnt THEN
        CALL LoopErrorMsg
    END IF

    IF Indent THEN
        PRINT REPEAT$(80, "_")
        PRINT "Possible missing END IF before END of program (", STR$(Indent, 1), ")"
        PRINT REPEAT$(80, "_")
    END IF

    '***************************************************************

    IF Use_VBS THEN
        CALL Emit_VBScript_Support     ' Writes to FP_HDR
    END IF

    IF NO_LIBS = FALSE THEN
        IF ZapFlag = FALSE THEN
            IF Use_Project = FALSE THEN
                STATIC Pass_1
                IF Pass_1 = FALSE THEN
                    INCR Pass_1
                    AddLibrary("kernel32.lib")
                    AddLibrary("user32.lib")
                    AddLibrary("gdi32.lib")
                    AddLibrary("comctl32.lib")
                    AddLibrary("advapi32.lib")
                    AddLibrary("winspool.lib")
                    AddLibrary("shell32.lib")
                    AddLibrary("Msimg32.lib")
                    AddLibrary("ole32.lib")
                    AddLibrary("oleaut32.lib")
                    AddLibrary("uuid.lib")
                    AddLibrary("odbc32.lib")
                    AddLibrary("odbccp32.lib")
                    AddLibrary("winmm.lib")
                    AddLibrary("comdlg32.lib")
                    AddLibrary("imagehlp.lib")
                    AddLibrary("version.lib")
                    AddLibrary("wininet.lib")
                    AddLibrary("urlmon.lib")
                END IF
            END IF ' Use_Project = FALSE
        END IF ' ZapFlag
    END IF ' NO_LIBS

    '***************************************************************
    IF Use_GenFree AND GlobalDynaCnt THEN
        CALL MakeFreeGlobals               ' Writes to FP_WRITE
    END IF

    CALL Emit_Libs                         ' Writes to FP_HDR
    CALL ExportInternalConst               ' Writes to FP_CST
    CALL Emit_Epilog                       ' Writes to FP_WRITE
    CALL CloseAll                          ' Close all files
    CALL AssembleParts                     ' Build final C/C++
    CALL Emit_ResourceFile            ' Build User's .RC file

    '***************************************************************
    IF ShowStatus THEN CLS
    '***************************************************************

    IF Use_Project AND Gen_Header THEN
        CALL Emit_ProjectSupport
    END IF

    IF WarnMsg$ <> "" THEN
        IF InfoBoxWarn THEN
            INFOBOX("Warnings! :" , WarnMsg$, _
            GetSystemMetrics(SM_CXSCREEN)/4, _
            GetSystemMetrics(SM_CYSCREEN)/4)
        ELSE
            PRINT "Warnings! :", CRLF$, WarnMsg$
        END IF
    END IF

    '**********************************************
    ' It's time to make some final tweaks to the
    ' C/C++ output file before ending    - MrBcx
    '**********************************************
    CALL Final_Transforms                             ' This revised order of calls
    CALL PostProcess                                  ' fixes 0xf bug in "::" lines


    IF NOT Quiet THEN
        INCR LinesRead, LineNum[1]
        Elapsed! = (FLOAT)clock()/(FLOAT)CLOCKS_PER_SEC

        IF c_BCX_COLORS THEN COLOR 11, 0
        PRINT "[Lines In:"             ; ' Suppress CRLF
        IF c_BCX_COLORS THEN COLOR 14, 0
        PRINT   LinesRead              ; ' Suppress CRLF
        IF c_BCX_COLORS THEN COLOR 11, 0
        PRINT  "] [Lines Out:"         ; ' Suppress CRLF
        IF c_BCX_COLORS THEN COLOR 14, 0
        PRINT    LinesWritten          ; ' Suppress CRLF
        IF c_BCX_COLORS THEN COLOR 11, 0
        PRINT  "] "                    ; ' Suppress CRLF
        PRINT "[Statements:"           ; ' Suppress CRLF
        IF c_BCX_COLORS THEN COLOR 14, 0
        PRINT  Statements              ; ' Suppress CRLF
        IF c_BCX_COLORS THEN COLOR 11, 0
        PRINT "] [Time: "              ; ' Suppress CRLF
        IF c_BCX_COLORS THEN COLOR 14, 0
        PRINT USING$("#.##", Elapsed!);  ' Suppress CRLF
        IF c_BCX_COLORS THEN COLOR 11, 0
        PRINT " Sec's]"

        LOCAL Tmp$
        Tmp$  = "BCX translated [" + REMOVE$(MCASE$(FileIn$), SPC$)
        Tmp$ += "] to ["   + REMOVE$(MCASE$(FileOut$), SPC$) + "]"

        IF UseCpp THEN
            Tmp$ += " for a C++ Compiler"
        ELSE
            Tmp$ += " for a C Compiler"
        END IF

        IF Use_Project THEN
            Tmp$ += " with No Runtime"
        END IF

        IF c_BCX_COLORS THEN COLOR 10, 0
        PRINT Tmp$
        PRINT
        IF c_BCX_COLORS THEN POPCOLORS
    END IF

    '*********************************************************************************
    IF KillCFile THEN KILL FileOut$                   ' -kill switch?
    CALL KillFiles
    '*********************************************************************************
    FUNCTION =  EXIT_SUCCESS
END FUNCTION  ' Function main



'*************************************************************************************
'*                                                                                   *
'*                                                                                   *
'*                                                                                   *
'*                                                                                   *
'*                        End of BCX Translator Main Function                        *
'*                                                                                   *
'*                                                                                   *
'*                                                                                   *
'*                                                                                   *
'*************************************************************************************



SUB Early_Transforms
    '*********************************************************************************
    '     Split DIM/STATIC/LOCAL/RAW assignments into two statements       838 MrBcx
    '     CRITICAL: This must run FIRST - BEFORE any macro expansion
    '*********************************************************************************
    '          Check if this line contains a declaration with an assignment
    IF iMatchNQ(Src$, " = ") THEN
        '*****************************************************************************
        ' Only process if the line starts with a declaration keyword
        '*****************************************************************************
        IF m_iMatchLft(Src$, "dim")     OR m_iMatchLft(Src$, "local")  OR _
            m_iMatchLft(Src$, "static") OR m_iMatchLft(Src$, "raw")    OR _
            m_iMatchLft(Src$, "shared") OR m_iMatchLft(Src$, "global") THEN

            FastLexer(Src$, SPC$, c_FULLSET)

            '********************************************************
            '         Simplify these common string formats
            '********************************************************
            ' DIM AS STRING newMsg = AnyStringExpression
            ' DIM RAW AS STRING newMsg = AnyStringExpression
            '********************************************************
            IF Stk$[3] ?? "STRING" THEN
                CALL LShiftStk(2)
                CALL LShiftStk(2)
                Stk$[2] += "$"
            END IF

            IF Stk$[4] ?? "STRING" THEN
                CALL LShiftStk(2)
                CALL LShiftStk(2)
                CALL LShiftStk(2)
                Stk$[2] += "$"
            END IF
            '*********************************************************
            IF Stk$[1] ?? "dim" AND Stk$[2] ?? "raw" THEN
                CALL LShiftStk(1)  ' RAW moves to Stk$[1] which is all we need
            END IF

            IF Stk$[1] ?? "dim" AND Stk$[2] ?? "static" THEN
                CALL LShiftStk(1)  ' STATIC moves to Stk$[1] which is all we need
            END IF

            IF Stk$[1] ?? "dim" AND Stk$[2] ?? "shared" THEN
                CALL LShiftStk(1)  ' SHARED moves to Stk$[1] which is all we need
            END IF
            '*********************************************************

            ' Check if this is actually a declaration with assignment
            DIM IsDecl = FALSE

            ' Check if the second token is a valid variable name
            IF Ndx >= 2 THEN
                DIM VarName$ = No_Sigil$(Stk$[2])
                DIM FirstChar = *VarName$

                ' Variable names should start with letter or underscore
                IF FirstChar = ASC("_") OR isalpha(FirstChar) THEN
                    IsDecl = TRUE

                    ' Ensure it's not a function call or something else
                    IF Ndx >= 3 THEN
                        IF m_iMatchWrd(Stk$[3], "as") THEN
                            IsDecl = TRUE
                        ELSE
                            ' Check if variable has a sigil (%!$#@`)
                            DIM LastChar = ASC(RIGHT$(VarName$, 1))
                            IF iMatchNQ(c_VARTYPES$, CHR$(LastChar)) THEN
                                IsDecl = TRUE
                            ELSE
                                ' No sigil and no AS - could be a simple DIM with assignment
                                IF Ndx >= 3 AND *Stk$[3] = ASC("=") THEN
                                    IsDecl = TRUE
                                ELSE
                                    IsDecl = FALSE
                                END IF
                            END IF
                        END IF
                    END IF
                END IF
            END IF

            IF IsDecl THEN
                CALL SplitDimAssignment
                ' Src$ is now empty - the statements are in SplitStk$ array
                ' The main loop will process them via SplitLines
                ' We need to return early to prevent further processing
                EXIT SUB
            END IF

        END IF
    END IF
    '********************************************************************************************
    '                 Temporary Replacements to preserve c/c++ operators
    '********************************************************************************************
    IF iMatchNQ(Src$, "=" ) THEN
        IF iMatchNQ(Src$, "%=")  THEN REPLACE "%="  WITH BcxPctEqual$ IN Src$ ' 838 MrBcx New
        IF iMatchNQ(Src$, "^=")  THEN REPLACE "^="  WITH BcxUpEqual$  IN Src$ ' 838 MrBcx New
        IF iMatchNQ(Src$, "<<=") THEN REPLACE "<<=" WITH BcxLLEqual$  IN Src$ ' 838 MrBcx New
        IF iMatchNQ(Src$, ">>=") THEN REPLACE ">>=" WITH BcxRREqual$  IN Src$ ' 838 MrBcx New
        IF iMatchNQ(Src$, "&=")  THEN REPLACE "&="  WITH BcxAndEqual$ IN Src$ ' 838 MrBcx New
        IF iMatchNQ(Src$, "|=")  THEN REPLACE "|="  WITH BcxOrEqual$  IN Src$ ' 838 MrBcx New
    END IF
    '***************************************************************************************
    '                  Detect and process += concat operations first
    '***************************************************************************************
    IF iMatchNQ(Src$, "xfor") = FALSE THEN      ' 838 MrBcx - LIKE() is costly, this is cheap
        IF LIKE(Src$, "*xfor*+=*") = FALSE THEN ' 831 MrBcx - Minimize | Prevent edge case

            IF iMatchNQ(Src$, "=+") AND NOT iMatchNQ(Src$, "=++") THEN
                Abort(" [=+] looks like a typo.")
            END IF

            IF iMatchNQ(Src$, "+=") THEN
                DIM AS STRING LeftSide, RightSide
                DIM AS INT i, j

                FastLexer(Src$, SPC$, c_FULLSET)

                IF *Stk$[1] = ASC("!") THEN EXIT SUB  ' Skip over inline C/C++

                IF Stk$[1] ?? "if" THEN
                    FOR i = 2 TO Ndx
                        IF Stk$[i] ?? "then" THEN EXIT FOR
                    NEXT
                    FOR j = 1 TO i
                        LeftSide += SPC$ + Stk$[j]
                    NEXT
                    FOR j = i + 1 TO Ndx
                        RightSide = RightSide + Stk$[j]
                    NEXT
                    FastLexer(RightSide, SPC$, c_FULLSET)
                END IF

                CALL StrCatOperTransform

                BuildDelimStr(1, Ndx, Src$)

                IF *LeftSide THEN Src$ = TRIM$(LeftSide + SPC$ + Src$)
            END IF
        END IF
    END IF
    Src$ = SPC$ + Src$

    '*********************************************************************************
    '       Shine more light on string comparison loops -- Added by MrBcx 833
    '       The term:  OR LIKE (Src$,"*do*while") was intentionally omitted
    '*********************************************************************************
    IF iMatchNQ(Src$, "il") THEN       ' 838 MrBcx - a cheap performance test
        IF LIKE(Src$, "*loop*while*") OR LIKE(Src$, "*do*until*") OR LIKE(Src$, "*loop*until*") THEN
            FastLexer(Src$, SPC$, c_FULLSET )
            IF NOT INCHR(Stk$[3], "$") AND Im_A_String_Var (Stk$ [3]) THEN
                CONCAT (Stk$[3], "$")
                Src$ = SPC$
                FOR i AS INT = 1 TO Ndx
                    Src$ += Stk$[i] + SPC$
                NEXT
                Src$ = SPC$ + Src$
            END IF
        END IF

        IF LIKE(Src$, "*while*") THEN
            FastLexer(Src$, SPC$, c_FULLSET )
            IF INCHR(Stk$[2], "$") = 0 AND Im_A_String_Var (Stk$ [2]) THEN
                CONCAT (Stk$[2], "$")
                Src$ = SPC$
                FOR i AS INT = 1 TO Ndx
                    Src$ += Stk$[i] + SPC$
                NEXT
                Src$ = SPC$ + Src$
            END IF
        END IF
    END IF

    '*********************************************************************************
    '         Reserved field name supporting the BCX_SPLITBUTTON() control
    '*********************************************************************************
    IF iMatchNQ(Src$, ".szlabel") OR iMatchNQ(Src$, ".szlabel$") THEN
        IREPLACE ".szlabel" WITH ".szLabel$" IN Src$
        IREPLACE "bcx_splitbuttondata" WITH "BCX_SPLITBUTTONDATA" IN Src$
    END IF

    IF iMatchNQ(Src$, "bcx_splitbuttondata")   THEN
        IREPLACE "bcx_splitbuttondata" WITH "BCX_SPLITBUTTONDATA" IN Src$
    END IF

    '*********************************************************************************
    '                             Detect Cpp keywords
    '*********************************************************************************

    IF UseCpp = FALSE THEN
        IF iMatchNQ(Src$, "<iostream>")  THEN UseCpp = TRUE : GOTO NextTest
        IF iMatchNQ(Src$, " delete ")    THEN UseCpp = TRUE : GOTO NextTest
        IF iMatchNQ(Src$, " std::cout ") THEN UseCpp = TRUE : GOTO NextTest
        IF iMatchNQ(Src$, " std::cin ")  THEN UseCpp = TRUE : GOTO NextTest
        IF iMatchNQ(Src$, " class ")     THEN UseCpp = TRUE : GOTO NextTest
        IF iMatchNQ(Src$, " interface ") THEN UseCpp = TRUE : GOTO NextTest

        NextTest:

        IF iMatchNQ(Src$, " inline ")    THEN
            IF LIKE (Src$, "*inline*function*") OR LIKE (Src$, "*inline*sub*") THEN UseCpp = TRUE
        END IF

        IF LIKE (Src$, "*HANDLE_MSG*") THEN   ' 812 Added by MrBcx
            UseCpp = FALSE
            UseInLine = FALSE
        END IF

        IF iMatchNQ(Src$, " namespace ") THEN UseCpp = TRUE
        IF iMatchNQ(Src$, " template ")  THEN UseCpp = TRUE
        IF iMatchNQ(Src$, " pptype ")    THEN UseCpp = TRUE
        IF iMatchNQ(Src$, " ator ")      THEN
            IF LIKE(Src$, "*function*operator*") THEN UseCpp = TRUE
        END IF
        IF NOT iMatchNQ(Src$, " binary ") THEN
            IF iMatchNQ(Src$, " new ")    THEN UseCpp = TRUE
        END IF
    END IF
    '*********************************************************************************
    '          Transform METHOD, PROPERTY, PROPSET, and PROPGET -  MrBcx
    '*********************************************************************************
    IF UseCpp = TRUE THEN
        IF iMatchNQ(Src$, "propget")  THEN Src$ = iReplace_NQ$ (Src$, "propget", "FUNCTION")
        IF iMatchNQ(Src$, "propset")  THEN Src$ = iReplace_NQ$ (Src$, "propset", "SUB")
        IF iMatchNQ(Src$, "property") THEN
            DIM szTmp$ = SPC$ + Src$ + SPC$
            IF IINSTR(szTmp$, " property ") THEN
                Src$ = iReplace_NQ$ (Src$, "property", "SUB")
            END IF
        END IF
        IF iMatchNQ(Src$, "method") THEN
            DIM szTmp$ = SPC$ + Src$ + SPC$
            IF IINSTR(szTmp$, " method ") OR IINSTR(szTmp$, " method=") THEN
                Src$ = iReplace_NQ$ (Src$, "method", "FUNCTION")
            END IF
        END IF
    END IF
    '*********************************************************************************
    '                      Enable range-based FOR-NEXT loops
    '*********************************************************************************
    IF UseCpp = TRUE THEN
        IF iMatchNQ(Src$, "rbfor") OR iMatchNQ(Src$, "rbnext") OR iMatchNQ(Src$, "rbexit") THEN
            CALL RBForTransform
        END IF
    END IF
    '*********************************************************************************
    IF iMatchNQ(Src$, "band") THEN
        IF LIKE(Src$, "*select*case*band*") THEN
            DIM szTmp$ = TRIM$(STRIM$(Src$))
            IF LIKE(szTmp$, "select case band*") THEN
                Src$ = iReplace_NQ$ (Src$, " band ", SPC$)
                Src$ += SPC$ + "&&"
            END IF
        END IF
    END IF
    '*********************************************************************************
    '             Improve processing of "DIM AS CONST" brackets -  MrBcx
    '*********************************************************************************
    IF iMatchNQ (Src$, "const") THEN
        IF LIKE(Src$, "*dim*as*const*") THEN
            FastLexer(Src$, SPC$, c_FULLSET)
            IF Stk$[1] ?? "dim" AND _
                Stk$[2] ?? "as" AND _
                Stk$[3] ?? "const" THEN
                REPLACE " [" WITH "[" IN Src$
                REPLACE " ]" WITH "]" IN Src$
            END IF
        END IF
    END IF
    '*********************************************************************************
    '          MrBcx 817 - Added support for CONST  [type] VarName = value
    '                      to create "DIM AS CONST" [type] VarName = value
    '*********************************************************************************
    IF iMatchNQ (Src$, "const") THEN
        FastLexer(Src$, SPC$, c_FULLSET)
        IF Stk$[1] ?? "const" THEN

            FOR_EACH(i, ConstTypes$)
                IF Stk$[2] ?? ConstTypes$[i] THEN ' ?? is a case-insensitve comparison
                    Src$ = "DIM AS " + Src$
                    EXIT_EACH
                END IF
            NEXT_EACH

        END IF
    END IF
    '*********************************************************************************
    '                Enable traditional file i/o statements
    '    Converts INPUT #1 -to- FINPUT #1 and PRINT #1 -to- FPRINT #1
    '                                MrBcx
    '*********************************************************************************
    IF iMatchTwoNQ (Src$, "input ", " #") = TRUE  THEN
        IF iMatchNQ (Src$, "line ")       = FALSE THEN
            IF iMatchNQ (Src$, "open ")   = FALSE THEN
                IF iMatchNQ (Src$, "as ") = FALSE THEN
                    Src$ = iReplace_NQ$ (Src$, " input ", " finput ")
                END IF
            END IF
        END IF
    END IF

    IF iMatchTwoNQ(Src$, "print ", " #") = TRUE  THEN
        IF iMatchNQ(Src$, "using$")  = FALSE THEN      ' 826 MrBcx - added new filter
            IF iMatchNQ(Src$, "lprint")  = FALSE THEN
                Src$ = iReplace_NQ$ (Src$, " print ", " fprint ")
            END IF
        END IF
    END IF

    IF iMatchNQ(Src$, "print") THEN
        FastLexer(Src$, SPC$, c_FULLSET)
        FOR i AS INT = 1 TO Ndx
            IF Stk$[i] ?? "print" THEN
                IF CheckType(Stk$[i+1]) = vt_FILEPTR THEN
                    Src$ = iReplace_NQ$ (Src$, " print ", " fprint ")
                END IF
            END IF
        NEXT
    END IF
    '*********************************************************************************
    IF iMatchNQ(Src$, " comset ") THEN
        IREPLACE " comset " WITH " SET " IN Src$
    END IF
    '*********************************************************************************
    IF iMatchNQ(Src$, "asciiz") THEN
        IREPLACE "asciiz" WITH "string" IN Src$
    END IF
    '*********************************************************************************
    IF INSTR(Src$, DDQUOT$) THEN                   '  """"
        Use_DDQ = TRUE
        REPLACE DDQUOT$ WITH " DDQ$ " IN Src$
    END IF

    IF INSTR(Src$, DQUOT$) THEN
        Use_DQ = TRUE
        REPLACE DQUOT$ WITH " DQ$ " IN Src$        ' """
    END IF
    '*********************************************************************************
    IF iMatchNQ(Src$, " $pragma ")   THEN
        Src$ = iReplace_NQ$ (Src$, "$pragma ", "!#pragma ")
    END IF
    '*********************************************************************************
    '                             Added in 813 by MrBcx
    '          Process the statements that are affected by the "ANY" keyword
    ' The order and masking are critical to defeat issues transforming similar keywords
    '*********************************************************************************
    IF iMatchNQ(Src$, " ANY ") THEN  ' ANY is a new BCX reserved keyword in BCX 813

        IF iMatchNQ(Src$, "EXTRACT$")   THEN
            IREPLACE "EXTRACT$" WITH "$TCARTXE" IN Src$   ' 813 MrBcx - Temporary masking
            Src$ = Replace_ANY_Keyword$(Src$, "$TCARTXE")
            IREPLACE "$TCARTXEANY" WITH " EXTRACTANY$ " IN Src$
            Use_ExtractAny = Use_BcxTempStr = TRUE
        END IF
        IF iMatchNQ(Src$, "IINSTR")   THEN
            IREPLACE "IINSTR" WITH "RTSNI2I" IN Src$      ' 813 MrBcx - Temporary masking
            Src$ = Replace_ANY_Keyword$(Src$, "RTSNI2I")
            IREPLACE "RTSNI2IANY" WITH " IINSTRANY " IN Src$
            Use_IInstrAny = Use_IInstr = TRUE
        END IF
        IF iMatchNQ(Src$, "IREMOVE$") THEN
            IREPLACE "IREMOVE$" WITH "$EVOMERI" IN Src$   ' 813 MrBcx - Temporary masking
            Src$ = Replace_ANY_Keyword$(Src$, "$EVOMERI")
            IREPLACE "$EVOMERIANY"  WITH " IREMOVEANY$ " IN Src$
            Use_IRemoveAny = Use_BcxTempStr = TRUE
        END IF
        IF iMatchNQ(Src$, "IREPLACE$") THEN
            IREPLACE "IREPLACE$" WITH "$ECALPERI" IN Src$ ' 813 MrBcx - Temporary masking
            Src$ = Replace_ANY_Keyword$(Src$, "$ECALPERI")
            IREPLACE "$ECALPERIANY"  WITH " IREPLACEANY$ " IN Src$
            Use_IReplaceAny = Use_BcxTempStr = TRUE
        END IF
        IF iMatchNQ(Src$, "REMAIN$") THEN
            IREPLACE "REMAIN$" WITH "$NIAMER" IN Src$     ' 832 MrBcx - Temporary masking
            Src$ = Replace_ANY_Keyword$(Src$, "$NIAMER")
            IREPLACE "$NIAMERANY"  WITH " REMAINANY$ " IN Src$
            Use_RemainAny = Use_BcxTempStr = TRUE
        END IF
        IF iMatchNQ(Src$, "INSTR")    THEN Src$ = Replace_ANY_Keyword$(Src$, "INSTR")
        IF iMatchNQ(Src$, "REMOVE$")  THEN Src$ = Replace_ANY_Keyword$(Src$, "REMOVE$")
        IF iMatchNQ(Src$, "REPLACE$") THEN Src$ = Replace_ANY_Keyword$(Src$, "REPLACE$")

        IREPLACE "REMOVE$ANY"   WITH " REMOVEANY$ "   IN Src$
        IREPLACE "REPLACE$ANY"  WITH " REPLACEANY$ "  IN Src$
        IREPLACE "REMAIN$ANY"   WITH " REMAINANY$ "   IN Src$
        IREPLACE "INSTRANY"     WITH " INSTRANY "     IN Src$
        IREPLACE "EXTRACT$ANY"  WITH " EXTRACTANY$ "  IN Src$
    END IF
    '*********************************************************************************
    IF LIKE(Src$, "*end*while*") THEN  ' 837 MrBcx added END WHILE (vb.net compat.)
        DIM Tmp$ = Src$
        IREMOVE "end" FROM Tmp$
        IREMOVE "while" FROM Tmp$
        IF LTRIM$(Tmp$) = "" THEN Src$ = "WEND"
    END IF
    '*********************************************************************************
    '                            Added block by MrBcx 838
    ' The following idea occured too late in SUB TokenSubstitutions.  It needs to be
    ' caught early, so that BCX can emit the function return variable Bcx_Retvar inside
    ' FUNCTIONS that contain local dynamic arrays.
    '*********************************************************************************
    IF iMatchNQ(Src$, "local") AND iMatchNQ(Src$, "dynamic") THEN
        DIM lhs = IINSTR(Src$, "local")
        DIM rhs = IINSTR(Src$, "dynamic")
        IF (rhs > lhs) AND lhs > 0 THEN
            IREPLACE "local" WITH "DIM" IN Src$
        END IF
    END IF

    Src$ = TRIM$(Src$)
END SUB  ' Early_Transforms





SUB Final_Transforms
    '**********************************************************************************
    DIM clangOld$ = CHR$ (93, 91, 66, 67, 88, 83, 84, 82, 83, 73, 90, 69, 93, 61, 123, 48, 125, 59)
    DIM clangNew$ = CHR$ (93, 91, 66, 67, 88, 83, 84, 82, 83, 73, 90, 69, 93, 61, 123, 123, 48, 125, 125, 59)
    '**********************************************************************************
    '  C_EXPORT int __stdcall DllMain
    DIM Dll_Orig$ = CHR$(67, 95, 69, 88, 80, 79, 82, 84, 32, 105, 110, 116, 32, _
    95, 95, 115, 116, 100, 99, 97, 108, 108, 32, 68, 108, 108, 77, 97, 105, 110)
    '**********************************************************************************
    ' __declspec(dllexport) BOOL WINAPI DllMain
    DIM Dll_Repl$ = CHR$(95, 95, 100, 101, 99, 108, 115, 112, 101, 99, 40, 100, 108, _
    108, 101, 120, 112, 111, 114, 116, 41, 32, 66, 79, 79, 76, 32, 87, 73, 78, _
    65, 80, 73, 32, 68, 108, 108, 77, 97, 105, 110)
    '**********************************************************************************
    ' change "char*  = DQ$" to "char*  = DQ"
    DIM QQF$ = CHR$(99, 104, 97, 114, 42, 32, 32, 61, 32, 68, 81, 36)
    DIM QQR$ = CHR$(99, 104, 97, 114, 42, 32, 32, 61, 32, 68, 81)
    '**********************************************************************************
    DIM BandAid$ = CHR$(38, 38, 61, 61)  ' Bugfix for SELECT CASE BAND
    '**********************************************************************************
    CALL StripExtraDefWndProcs
    '**********************************************************************************
    '            Determine if "#define BCXSTRSIZE 2048" can be removed
    '**********************************************************************************
    DIM ZapBCXSTRSIZE = 0
    DIM AS ULONGLONG filesize = LOF(FileOut$)
    DIM Buffer$ * (ULONG)filesize

    OPEN FileOut$ FOR BINARY READ AS FP1 : GET$ FP1, Buffer$, filesize : CLOSE FP1
    IF TALLY(Buffer$, "BCXSTRSIZE") = 1 THEN ZapBCXSTRSIZE = TRUE
    '**********************************************************************************
    OPEN FileOut$ FOR INPUT AS FP1
    OPEN "$Bcx$Temp$File$" FOR OUTPUT AS FP2
    '**********************************************************************************
    DIM Source$
    DO WHILE NOT EOF(FP1)
        LINE INPUT FP1, Source$

        '=======================================================================
        '        Restore our substituted operators with actual operators
        '=======================================================================
        ' Restore %=  remainder assignment operator
        ' Restore ^=  bitwise XOR assignment operator
        ' Restore <<= left shift assignment operator
        ' Restore >>= right shift assignment operator
        ' Restore &=  bitwise AND assignment operator
        ' Restore |=  bitwise OR assignment operator
        '=======================================================================
        IF IINSTR(Source$, "Equal}" ) THEN ' Substituted operators end in "Equal}"
            IF iMatchNQ(Source$, BcxPctEqual$) THEN
                REPLACE BcxPctEqual$ WITH "%=" IN Source$        ' 838 MrBcx New
            END IF

            IF iMatchNQ(Source$, BcxUpEqual$) THEN
                REPLACE BcxUpEqual$ WITH "^=" IN Source$         ' 838 MrBcx New
            END IF

            IF iMatchNQ(Source$, BcxLLEqual$) THEN
                REPLACE BcxLLEqual$ WITH "<<=" IN Source$        ' 838 MrBcx New
            END IF

            IF iMatchNQ(Source$, BcxRREqual$) THEN
                REPLACE BcxRREqual$ WITH ">>=" IN Source$        ' 838 MrBcx New
            END IF

            IF iMatchNQ(Source$, BcxAndEqual$) THEN
                REPLACE BcxAndEqual$ WITH "&=" IN Source$        ' 838 MrBcx New
            END IF

            IF iMatchNQ(Source$, BcxOrEqual$) THEN
                REPLACE BcxOrEqual$ WITH "|=" IN Source$         ' 838 MrBcx New
            END IF
        END IF

        '=======================================================================
        '        Edge case for one of possible ways BCX can emit WndProc
        '=======================================================================

        IF LEFTSTR(Source$, "LRESULT CALLBACK WndProc (HWND hWnd,") THEN
            FPRINT FP2, Source$
            LINE INPUT FP1, Source$    '  {
            FPRINT FP2, Source$
            LINE INPUT FP1, Source$
            IF INSTR(Source$, "Bcx_RetVal") = 0 THEN
                FPRINT FP2, "  LRESULT Bcx_RetVal={0};"
                FPRINT FP2, Source$
                Source$ = SPC$
            END IF
        END IF

        '******************************************************************************
        IF ZapBCXSTRSIZE AND INSTR(Source$, "BCXSTRSIZE") THEN ITERATE
        '******************************************************************************
        ' Prevent CLANG warning by adding double braces when DIM'ing string arrays: ={{0}}   829 MrBcx
        '******************************************************************************
        REPLACE clangOld$ WITH clangNew$ IN Source$
        '******************************************************************************
        '                Do some minor beautification of the output
        '******************************************************************************
        IF LTRIM$(Source$) = "" AND LTRIM$(LOOKAHEAD$(FP1)) = ""       THEN ITERATE
        IF LTRIM$(Source$) = "" AND LTRIM$(LOOKAHEAD$(FP1)) = "#endif" THEN ITERATE
        '******************************************************************************
        '              829 MrBcx found and resolved another edge case
        '           Prevent emitting duplicate declarations of BCX_RetStr
        '******************************************************************************
        IF INSTR(Source$, "BCX_RetStr") THEN
            IF _
                LIKE(Source$, "*char*BCX_RetStr={0};") AND _
                LIKE(TRIM$(LOOKAHEAD$(FP1)), "*char*BCX_RetStr={0};") THEN
                Source$ = ""
            END IF
        END IF
        '******************************************************************************
        REPLACE CHR$(15)  WITH  ":"       IN Source$    ' Fix recently detected mystery
        REPLACE QQF$      WITH  QQR$      IN Source$    ' Delete the $ from certain DQ$
        IF INSTR(Source$, "DllMain") THEN
            REPLACE Dll_Orig$ WITH Dll_Repl$ IN Source$ ' Force MS DllMain definition
        END IF
        '******************************************************************************
        IF LEFTSTR(Source$, "#define  3.14") THEN
            PRINT "CONST PI was detected in your program."
            PRINT "PI is a BCX reserved word and cannot be re-defined."
            PRINT "You must update your source code to remove this error."
            Source$ = ""
            '  END
        END IF
        '******************************************************************************
        IF UserBcxStrSize$ <> "" AND LEFTSTR(Source$, "#define BCXSTRSIZE") THEN
            Source$ = "#define BCXSTRSIZE " + UserBcxStrSize$
        END IF
        '*************************************************************  Make ULEX happy
        REPLACE CHR$(61, 45, 32) WITH CHR$(32, 61, 32, 45) IN Source$ ' Before: =-[space]
        REPLACE CHR$(32, 45, 62) WITH CHR$(45, 62)         IN Source$ ' Before: [space]->
        '********************************************************************************
        IF iMatchNQ(Source$, BandAid$) THEN
            IF LIKE(Source$, "*if(*") THEN
                REPLACE BandAid$ WITH " & " IN Source$                ' Part 2/2 fixing
            END IF                                                    ' SELECT CASE BAND
        END IF
        '********************************************************************************
        '                                                             '    ()() -> ()
        REPLACE CHR$(40, 41, 40, 41) WITH CHR$(40, 40) IN Source$
        '********************************************************************************
        REPLACE CHR$(70, 73, 76, 69, 32, 32, 32, 42, 32, 32) WITH "FILE   *" IN Source$
        '********************************************************************************
        '                        Cosmetic fixups by MrBcx
        '********************************************************************************
        IF INSTR (Source$, "char*") THEN REPLACE "char* ," WITH "char*," IN Source$
        IF INCHR (Source$, "(") THEN
            Source$ = iReplace_NQ$ (Source$, "( ", "(")
        END IF
        '*********************************************************************************
        '                             Added in 825 by MrBcx
        '      If Use_Sound = TRUE then we need to emit the MIDI shutdown code
        '       -> everywhere <- that we find a PostQuitMessage(0) statement
        '*********************************************************************************
        IF iMatchNQ(Source$, "PostQuitMessage(0);") AND Use_Sound THEN
            Source$ = "       midiOutClose (hMidi);" + LF$ + Source$
        END IF
        '********************************************************************************
        IF iMatchNQ(Source$, "BCXEQEQ") THEN        ' 837 IIF /IIF$ patch by MrBcx
            REPLACE "BCXEQEQ" WITH "==" IN Source$
        END IF
        '********************************************************************************
        FPRINT FP2, Source$
        INCR LinesWritten
    LOOP
    CLOSE
    KILL FileOut$
    RENAME "$Bcx$Temp$File$", FileOut$
END SUB  ' Final_Transforms


'**************************************************************************
'         Below are several new functions that are being used for
'         various internal type-detection purposes.     MrBcx 791
'**************************************************************************

FUNCTION Im_A_String_Var(A$)
    DIM RAW idx, t
    t = LookupVarType(A$, ADDRESSOF(idx))
    IF  t = vt_SCHAR OR t = vt_CHAR OR t = vt_STRVAR THEN
        FUNCTION = TRUE
    ELSE
        FUNCTION = FALSE
    END IF
END FUNCTION ' Im_A_String_Var



FUNCTION Im_Dim_StrVar(A$ AS STRING, bMulti AS INT) AS INT                  ' added by MrBcx in 838
    '***********************************************************************
    ' Shared core for Im_Single_Dim_StrVar and Im_Multi_Dim_StrVar.
    '***********************************************************************
    ' Scans GlobalVars then LocalVars for a "char *" variable named A$.
    ' bMulti = FALSE : match exactly 1 "]" in VarDim$ (single-dim array)
    ' bMulti = TRUE  : match more than 1 "]" in VarDim$ (multi-dim array)
    '***********************************************************************
    DIM i AS INT = 1
    WHILE *GlobalVars[i].VarName$
        IF GlobalVars[i].VarName$ = A$ THEN
            IF GetVarTypeName$(GlobalVars[i].VarType) = "char *" THEN
                IF bMulti THEN
                    IF TALLY(GlobalVars[i].VarDim$, "]") > 1 THEN FUNCTION = TRUE
                ELSE
                    IF TALLY(GlobalVars[i].VarDim$, "]") = 1 THEN FUNCTION = TRUE
                END IF
            END IF
        END IF
        INCR i
    WEND
    i = 1
    WHILE *LocalVars[i].VarName$
        IF LocalVars[i].VarName$ = A$ THEN
            IF GetVarTypeName$(LocalVars[i].VarType) = "char *" THEN
                IF bMulti THEN
                    IF TALLY(LocalVars[i].VarDim$, "]") > 1 THEN FUNCTION = TRUE
                ELSE
                    IF TALLY(LocalVars[i].VarDim$, "]") = 1 THEN FUNCTION = TRUE
                END IF
            END IF
        END IF
        INCR i
    WEND
    FUNCTION = FALSE
END FUNCTION ' Im_Dim_StrVar


FUNCTION Im_Single_Dim_StrVar(A$)
    FUNCTION = Im_Dim_StrVar(A$, FALSE)
END FUNCTION ' Im_Single_Dim_StrVar



FUNCTION Im_Multi_Dim_StrVar(A$)
    FUNCTION = Im_Dim_StrVar(A$, TRUE)
END FUNCTION ' Im_Multi_Dim_StrVar



FUNCTION Im_UDT_Double (szArg$)
    DIM et AS INT = GetUDT_MemberType(szArg$)
    FUNCTION = ((et == vt_DOUBLE) BOR (et == vt_LDOUBLE))
END FUNCTION ' Im_UDT_Double



FUNCTION Im_UDT_Single (szArg$)
    DIM et AS INT = (GetUDT_MemberType(szArg$) == vt_SINGLE)
    FUNCTION = et
END FUNCTION ' Im_UDT_Single



FUNCTION Im_UDT_String (szArg$)
    DIM et AS INT = GetUDT_MemberType(szArg$)
    FUNCTION = ((et == vt_STRVAR) BOR (et == vt_PCHAR) BOR (et == vt_PSTR) BOR (et == vt_CHARPTR) BOR (et == vt_SCHAR) BOR (et == vt_CHAR))
END FUNCTION ' Im_UDT_String



FUNCTION GetUDT_MemberType(szArg$) AS INT              ' 838 MrBcx updated (better detection)
    DIM RAW CopyArg$
    DIM RAW Member$
    DIM RAW segName$
    DIM RAW VarName$
    DIM RAW br AS INT
    DIM RAW datType AS INT
    DIM RAW firstDot AS INT
    DIM RAW found AS INT
    DIM RAW lastDot AS INT
    DIM RAW segEnd AS INT
    DIM RAW segStart AS INT
    DIM RAW udtIdx AS INT
    DIM RAW varidx AS INT

    CopyArg$ = No_Sigil$(szArg$)
    firstDot = INCHR(CopyArg$, ".")
    IF firstDot = 0 THEN FUNCTION = vt_UNKNOWN

    VarName$ = EXTRACT$(CopyArg$, ".")
    lastDot  = INSTRREV(CopyArg$, ".")
    Member$  = MID$(CopyArg$, lastDot + 1)

    ' Strip array indices from final member
    br = INCHR(Member$, "[")
    IF br THEN Member$ = LEFT$(Member$, br - 1)

    ' Resolve VarName$ to its specific UDT via .VarDef
    udtIdx = 0
    datType = CheckLocal(VarName$, ADDRESSOF(varidx))
    IF datType = vt_UDT OR datType = vt_STRUCT THEN
        udtIdx = LocalVars[varidx].VarDef
    ELSE
        datType = CheckGlobal(VarName$, ADDRESSOF(varidx))
        IF datType = vt_UDT OR datType = vt_STRUCT THEN
            udtIdx = GlobalVars[varidx].VarDef
        END IF
    END IF

    IF udtIdx = 0 THEN FUNCTION = vt_UNKNOWN

    ' Walk any intermediate dotted segments, descending via
    ' Elements[].ElementID.  If at any step the named element is not
    ' found, or its ElementID is 0 (unparsed UDT), return vt_UNKNOWN
    ' so the caller falls through to its established defaults.

    segStart = firstDot + 1
    DO WHILE segStart < lastDot
        segEnd = INCHR(MID$(CopyArg$, segStart), ".")
        IF segEnd = 0 THEN EXIT DO
        segName$ = MID$(CopyArg$, segStart, segEnd - 1)
        ' Strip any array subscripts from the intermediate segment
        br = INCHR(segName$, "[")
        IF br THEN segName$ = LEFT$(segName$, br - 1)

        found = FALSE
        FOR z AS INT = 0 TO TypeDefs[udtIdx].EleCnt - 1
            IF TypeDefs[udtIdx].Elements[z].ElementName$ = segName$ THEN
                udtIdx = TypeDefs[udtIdx].Elements[z].ElementID
                found  = TRUE
                EXIT FOR
            END IF
        NEXT
        IF NOT found  THEN FUNCTION = vt_UNKNOWN
        IF udtIdx = 0 THEN FUNCTION = vt_UNKNOWN   ' descended into unparsed UDT
        segStart = segStart + segEnd
    LOOP

    ' udtIdx is now the UDT that contains Member$ — search for it.
    FOR z AS INT = 0 TO TypeDefs[udtIdx].EleCnt - 1
        IF TypeDefs[udtIdx].Elements[z].ElementName$ = Member$ THEN
            DIM elType = TypeDefs[udtIdx].Elements[z].ElementType
            DIM elPtr = TypeDefs[udtIdx].Elements[z].ElementDynaPtr
            ' If the element is a pointer and it's a char, it's a string or dynamic string.
            IF elType = vt_CHAR AND elPtr > 0 THEN
                FUNCTION = vt_STRVAR
            ELSEIF elType = vt_SCHAR AND elPtr > 0 THEN
                FUNCTION = vt_STRVAR
            ELSE
                FUNCTION = elType
            END IF
        END IF
    NEXT

    FUNCTION = vt_UNKNOWN
END FUNCTION ' GetUDT_MemberType



FUNCTION iMatchTwoNQ (Buffer$, First$, Second$ = " ")
    ' --------------------------------------------
    ' Performs a case-insensitive search for two
    ' strings in order of appearance in Buffer$
    ' that are not in quotes.  Omitting the 3rd
    ' arg is similar to calling iMatchNQ().
    ' By MrBcx 2022
    ' --------------------------------------------
    DIM Position = INSTR (Buffer$, First$, 1, 1)
    IF Position = 0 THEN FUNCTION = FALSE
    DIM LEN_Buffer = LEN (Buffer$)
    DIM LEN_First  = LEN (First$)
    DIM LEN_Second = LEN (Second$)

    IF INSTR (MID$(Buffer$, 1, Position + LEN_First), DQ$) THEN FUNCTION = FALSE
    FOR i AS INT = Position TO LEN_Buffer
        IF *Buffer$ + i = 32 THEN ITERATE
        IF INSTR (MID$(Buffer$, i, LEN_Second), Second$, 1, 1) THEN FUNCTION = TRUE
    NEXT
    FUNCTION =  FALSE
END FUNCTION ' iMatchTwoNQ



FUNCTION iReplace_NQ$ (Haystack AS STRING, Needle AS STRING, Repl AS STRING) AS STRING
    '****************************************************
    '  Performs a case-insensitive search & replace for
    '  text not enclosed in double quotes
    '****************************************************
    DIM AS LONG i, lastPos
    DIM AS STRING LeftPart, RightPart, NewString

    NewString = Haystack
    i = iMatchNQ(NewString, Needle)     ' Find first match

    WHILE i > 0                         ' Loop until no more matches are found
        IF i <= lastPos THEN            ' We've encountered an unexpected corner case
            EXIT WHILE
        END IF
        LeftPart = MID$(NewString, 1, i-1)
        RightPart = MID$(NewString, i + LEN(Needle))
        NewString = LeftPart + Repl + RightPart
        lastPos = i + LEN(Repl) - 1
        i = iMatchNQ(NewString, Needle) ' Find next match
    WEND

    FUNCTION =  NewString
END FUNCTION ' iReplace_NQ$


SUB ScanFunctionNames(SrcFile$)                              ' Argument added by MrBcx in 812
    '************************************************************************************************
    ' FuncSglNames$ stores space-separated FUNCTION names that return SINGLE precision results.
    ' FuncDblNames$ stores space-separated FUNCTION names that return DOUBLE precision results.
    ' FuncStrNames$ stores space-separated FUNCTION names that return null-terminated STRING results.
    '************************************************************************************************
    LOCAL SrcCode$                                             ' Eliminates forward-reference
    LOCAL FunkName$                                            ' problems when PRINTing functions

    OPEN SrcFile$ FOR INPUT AS FPScan                          ' without type-identifying sigils.

    DO WHILE NOT EOF(FPScan)                                   ' Lines must begin with FUNCTION for
        LINE INPUT FPScan, SrcCode$                            ' this to work, whitespace tolerated.
        '*******************************************************************************************
        REPLACE "(" WITH " (" IN SrcCode$                      ' Simplify parsing
        SrcCode$ = EXTRACT$(SrcCode$, ":")                     ' Ignore multi-statements & namespaces
        SrcCode$ = TRIM$(SrcCode$)                             ' Trim whitespace, front & back
        '*******************************************************************************************
        IF LEFTSTR(SrcCode$, "declare ", 1)   THEN SrcCode$ = MID$(SrcCode$, 9)
        IF LEFTSTR(SrcCode$, "c_declare ", 1) THEN SrcCode$ = MID$(SrcCode$, 11)
        '*******************************************************************************************
        IF LEFTSTR(SrcCode$, "function ", 1) THEN              ' Beware, Vars can -look- like "function"
            SrcCode$ = MID$(SrcCode$, 9)                       ' Remove "function " <- Note the space.
            SrcCode$ = TRIM$(SrcCode$)                         ' Must trim again
            SrcCode$ = STRIM$(SrcCode$)                        ' Turn multiple spaces into single spaces
            SrcCode$ += SPC$                                   ' Needed in order to isolate FunkName$
            '****************************************************************************************
            IF MID$(SrcCode$, 1, 1) = "=" OR MID$(SrcCode$, 1, 2) = " =" THEN
                SrcCode$ = ""                                  ' Remove "FUNCTION ="
            END IF
            '****************************************************************************************
            IF *SrcCode$ THEN                                  ' If SrcCode$ is not empty ...
                FunkName$ = EXTRACT$(SrcCode$, SPC$)

                IF *FunkName$ THEN                             ' If FunkName$ is not empty ...
                    SrcCode$ = TRIM$(MID$(SrcCode$, LEN(FunkName$)+1))

                    IF RIGHTSTR(FunkName$, "$") THEN           ' We found:  FUNCTION SomeName$
                        IF NOT INSTR(FuncStrNames$, FunkName$) THEN FuncStrNames$ += SPC$ + FunkName$ + SPC$
                    END IF

                    IF RIGHTSTR(FunkName$, "!") THEN           ' We found:  FUNCTION SomeName!
                        IF NOT INSTR(FuncSglNames$, FunkName$) THEN FuncSglNames$ += SPC$ + FunkName$ + SPC$
                    END IF

                    IF RIGHTSTR(FunkName$, "#") THEN           ' We found:  FUNCTION SomeName#
                        IF NOT INSTR(FuncDblNames$, FunkName$) THEN FuncDblNames$ += SPC$ + FunkName$ + SPC$
                    END IF

                    IF RIGHTSTR(SrcCode$, "as single", 1) THEN ' We found:  FUNCTION SomeName AS SINGLE
                        IF NOT INSTR(FuncSglNames$, FunkName$) THEN FuncSglNames$ += SPC$ + FunkName$ + "! "
                    END IF

                    IF RIGHTSTR(SrcCode$, "as double", 1) THEN ' We found:  FUNCTION SomeName AS DOUBLE
                        IF NOT INSTR(FuncDblNames$, FunkName$) THEN FuncDblNames$ += SPC$ + FunkName$ + "# "
                    END IF

                    IF RIGHTSTR(SrcCode$, "as string", 1) THEN ' We found:  FUNCTION SomeName AS STRING
                        IF NOT INSTR(FuncStrNames$, FunkName$) THEN FuncStrNames$ += SPC$ + FunkName$ + "$ "
                    END IF

                END IF
            END IF
        END IF
    LOOP
    CLOSE FPScan
END SUB ' ScanFunctionNames




SUB ScanIncludeFiles(FileName$)                 ' Added by MrBcx in 812
    '*********************************************************************
    ' Finds and stores ALL project $INCLUDE files, even those included
    ' inside other $INCLUDE files.  I use this array of filenames with
    ' ScanFunctionNames() for project-wide type/sigil detection.
    '*********************************************************************
    GLOBAL IncludeFileNames$[c_MaxFiles] ' Enough for 255 $INCLUDE files
    GLOBAL FilesFound = 1                ' The -main- file counts as 1
    DIM AS LONG i = 0                    ' Controls nested file iterations
    DIM ThisFile$                        ' $INCLUDE files that are detected
    IncludeFileNames$[0] = FileName$     ' Store -main- in IncludeFileNames$[0]

    WHILE i < FilesFound

        IF EXIST(IncludeFileNames$[i]) THEN                          ' New test added in 814
            OPEN IncludeFileNames$[i] FOR INPUT AS IncFP

            WHILE NOT EOF(IncFP)
                LINE INPUT IncFP, ThisFile$
                ThisFile$ = UCASE$(TRIM$(ThisFile$))

                IF LEFTSTR(ThisFile$, "$INCLUDE") THEN               ' Zero in on $INCLUDE Directives

                    ThisFile$ = TRIM$(EXTRACT$(ThisFile$ , "'"))     ' Added 838 strip comments!

                    IREPLACE "$BCX$" WITH BCXPATH$ IN ThisFile$      ' Perform macro substitution
                    REMOVE "$INCLUDE" FROM ThisFile$                 ' Start sanitizing ThisFile$

                    IF INCHR(ThisFile$, "<") THEN                    ' Accomodate $INCLUDE < filename >
                        DIM Tmp$                                     ' $INCLUDE <filename> requires
                        ThisFile$ = REMOVE$(ThisFile$, ANY "<>")     ' an existing PATH set in the
                        ThisFile$ = TRIM$(ThisFile$)                 ' BCXLIB ENVIRON$ variable
                        Tmp$ = TRIM$(ENVIRON$("BCXLIB"))             ' Test that it is there
                        IF Tmp$ <> "" THEN                            ' If it is ...
                            ThisFile$ = ENVIRON$("BCXLIB")+ThisFile$ ' concat the filename
                        ELSE                                         ' otherwise
                            Abort("ENVIRON$(BCXLIB) is not SET")     ' report the issue
                        END IF             '                         '
                    END IF                                           ' end -- $INCLUDE <filename>

                    REMOVE DQ$ FROM ThisFile$                        ' Remove double quotes
                    ThisFile$ = TRIM$(EXTRACT$(ThisFile$, "'"))      ' Remove comments and TRIM it
                    IncludeFileNames$[FilesFound] = ThisFile$        ' ThisFile$ is now sanitized
                    INCR FilesFound
                END IF

            WEND
        END IF
        CLOSE IncFP
        INCR i
    WEND
    DECR FilesFound   ' IncludeFileNames$ [] contains filenames from [0] to [FilesFound]
END SUB ' ScanIncludeFiles




FUNCTION Replace_ANY_Keyword (Input$, Keyword$) AS STRING
    '***************************************************************
    ' Inserts the "ANY" modifier into a specified function
    ' keyword call if it lacks one, preserving parentheses and
    ' handling nested tokens using FastLexer and bracket balancing.
    '***************************************************************
    LOCAL BracketBalance, FoundANY, FunctionStartPos
    LOCAL IsInsideFunction, i
    LOCAL Result$, Token$

    FastLexer(Input$, "", "= &()[]{}',+-*/<>?;.|:^")

    WHILE i <= Ndx
        Token$ = Stk$[i]

        ' Check if the token is the Keyword$
        IF Token$ ?? Keyword$ THEN
            IsInsideFunction = TRUE
            FunctionStartPos = LEN(Result$) + LEN(SPC$)
            Result$ += SPC$ + Token$
        ELSE
            ' Handle parentheses
            IF Token$ = "(" THEN
                INCR BracketBalance
                Result$ += SPC$ + Token$
            ELSEIF Token$ = ")" THEN
                DECR BracketBalance
                Result$ += SPC$ + Token$
                IF BracketBalance = 0 AND FoundANY = TRUE THEN
                    '*****************************************************
                    '      Insert "ANY" after the function keyword
                    '*****************************************************
                    DIM A$, B$, C$
                    A$ = MID$(Result$, 1, FunctionStartPos - 1)
                    B$ = UCASE$(Keyword$ + "any")
                    C$ = MID$(Result$, 1 + FunctionStartPos + LEN(Keyword$))
                    Result$ = A$ + B$ + C$
                    '*******************************************************
                    FoundANY = FALSE
                    IsInsideFunction = FALSE
                END IF
            ELSE
                '           Check for the "ANY" keyword
                IF IsInsideFunction AND LCASE$(Token$) = "any" THEN
                    FoundANY = TRUE
                ELSE
                    ' Add other tokens to output
                    IF LEN(Token$) > 0 THEN
                        Result$ += SPC$ + Token$
                    END IF
                END IF
            END IF
        END IF

        i++
    WEND
    Ndx = 0

    ' Tidy up any extra spaces

    REPLACE " ("   WITH "("    IN Result$
    REPLACE "( "   WITH "("    IN Result$
    REPLACE " )"   WITH ")"    IN Result$
    REPLACE ") "   WITH ")"    IN Result$
    REPLACE ")+"   WITH ") + " IN Result$
    REPLACE " [ "  WITH "["    IN Result$
    REPLACE " ] "  WITH "]"    IN Result$
    REPLACE " ]"   WITH "]"    IN Result$

    FUNCTION = TRIM$(Result$)
END FUNCTION ' Replace_ANY_Keyword




SUB StrCatOperTransform
    '***************************************************************************************
    ' This SUB transforms instances of the += operator (used for string concatenation)
    ' into an equivalent form: variable = variable + arglist. It ensures transformations
    ' occurs only outside string literals and processes the first occurrence per call.
    ' Stk$[] is modified and the token count [Ndx] is updated accordingly.
    ' It is called from the beginning of SUB Early_Transforms
    '***************************************************************************************
    DIM index AS INT                    ' Local index into Stk$[]
    DIM InString AS INT                 ' Track if we're inside a string literal
    DIM ParenDepth AS INT               ' Track parenthesis nesting level
    DIM QuoteChar$                      ' Track which quote character is being used
    DIM Tmp$

    FOR i AS INT = 2 TO Ndx - 1
        IF Stk$[i] = DQ$ THEN           ' Check for string literal boundaries
            IF InString = FALSE THEN
                InString = TRUE
                QuoteChar = Stk$[i]
            ELSEIF Stk$[i] = DQ$ THEN
                InString = FALSE
            END IF
        END IF
        IF InString = FALSE THEN
            IF Stk$[i] = "+" AND Stk$[i + 1] = "=" THEN
                Tmp$ = ""              ' Reset Tmp$ to store the full left-hand variable.
                ParenDepth = 0         ' Reset parenthesis depth counter
                '                        Capture the full variable including array index, if present
                index = i - 1
                WHILE index > 0
                    ' Check for expression terminators, but handle parentheses specially
                    IF Stk$[index] = ")" THEN
                        ParenDepth = ParenDepth + 1
                        Tmp$ = Stk$[index] + Tmp$
                    ELSEIF Stk$[index] = "(" THEN
                        ParenDepth = ParenDepth - 1
                        Tmp$ = Stk$[index] + Tmp$
                        ' If we've closed all parentheses and this is a standalone opening paren
                        ' (not part of a function call), check if we should stop
                        IF ParenDepth < 0 THEN
                            ' This opening paren doesn't have a matching closing paren in our expression
                            ' so it's likely a statement delimiter - stop here and remove it
                            Tmp$ = MID$(Tmp$, 2)  ' Remove the opening paren we just added
                            EXIT WHILE
                        END IF
                    ELSEIF ParenDepth = 0 AND (Stk$[index] = SPC$ OR Stk$[index] = "," OR Stk$[index] = "=") THEN
                        ' Only stop for these delimiters when not inside parentheses
                        EXIT WHILE
                    ELSE
                        Tmp$ = Stk$[index] + Tmp$
                    END IF
                    index = index - 1
                WEND
                ' Shift tokens right
                FOR index = Ndx TO i + 1 STEP -1
                    Stk$[index + 1] = Stk$[index]
                NEXT
                ' Modify the stack
                Stk$[i] = "="       ' Convert "+=" into "="
                Stk$[i + 1] = Tmp$  ' Insert the full variable name
                Stk$[i + 2] = "+"   ' Keep "+"
                Ndx = Ndx + 1       ' Update token count
                EXIT FOR            ' Process only the first occurrence per call
            END IF
        END IF
    NEXT
END SUB ' StrCatOperTransform



FUNCTION VB2BCX(strArg$) AS STRING
    '******************************************************
    ' Convert a VBNET/VBA style FOR-loop with a typed
    ' iterator (e.g., FOR x AS LONG = ...) into a valid
    ' BCX syntax (e.g., FOR LONG x = ...), if the
    ' datatype is one of the allowed types listed below.
    '******************************************************
    DIM AS STRING AllTypes, dtype,  stepp, strArgCopy, v, t
    DIM AS INT p, q, r

    ' These are the datatypes that BCX currently accepts as FOR-NEXT iterators
    AllTypes =  "SINGLE DOUBLE FLOAT INTEGER INT LONG LLONG LONGLONG UINT UINT64 ULONG ULONGLONG CHAR UCHAR BYTE "
    AllTypes += "UBYTE SBYTE SHORT USHORT SIZE_T SSIZE_T INT8_T INT16_T INT32_T INT64_T UINT8_T UINT16_T UINT32_T UINT64_T"

    strArgCopy = TRIM$(strArg)

    ' If it's not a FOR-NEXT line of code, bail out
    IF LEFTSTR(strArgCopy, "FOR ", 1) = FALSE THEN
        FUNCTION = strArgCopy
    END IF

    ' Search for " AS " (case-insensitive)
    p = IINSTR(strArgCopy, " AS ")

    IF p THEN
        ' Find the '=' after the type
        q = INSTR(strArgCopy, "=", p + 4)
        IF q = 0 THEN FUNCTION = strArgCopy

        ' Extract the type (after AS) and the variable name (before AS)
        dtype = TRIM$(MID$(strArgCopy, p + 4, q - (p + 4)))
        v = TRIM$(MID$(strArgCopy, 5, p - 5))
        t = MID$(strArgCopy, q + 1)

        ' Check if dtype is in our approved list (case-insensitive match)
        IF IINSTR(AllTypes, dtype) = 0 THEN
            FUNCTION = strArgCopy
        END IF

        ' Look for STEP in the remaining range expression (case-insensitive)
        r = IINSTR(t, " STEP ")
        IF r THEN
            stepp = MID$(t, r)
            t = LEFT$(t, r - 1)
        ELSE
            stepp = ""
        END IF
        FUNCTION = "FOR " + dtype + SPC$ + v + " = " + TRIM$(t) + stepp
    ELSE
        ' No "AS" clause — assume already valid BCX syntax, leave untouched
        FUNCTION = strArgCopy
    END IF
END FUNCTION ' VB2BCX




SUB ScanFuncNamesTypes(LineOfCode$)
    '******************************************************
    TYPE UDT_FUNC_NAME_TYPE ' TYPE definitions have global scope.
        FunctionName$ ' Placing them in a SUB / FUNCTION
        FunctionType$ ' that uses them is one way to help
    END TYPE          ' keep things organized & coherent.
    '******************************************************
    GLOBAL FunctionNameType AS UDT_FUNC_NAME_TYPE
    FunctionNameType.FunctionName$ = ""
    FunctionNameType.FunctionType$ = ""
    '******************************************************
    DIM p1 AS INT
    DIM FunkHeader$, FunkName$, FunkType$, localLine$, tmp$

    localLine$ = LineOfCode$

    DIM RAW kw$
    DIM RAW kwList$[8]

    kwList$[0] = "optional"
    kwList$[1] = "overloaded"
    kwList$[2] = "inline"
    kwList$[3] = "uint_ptr"
    kwList$[4] = "int_ptr"
    kwList$[5] = "lresult"
    kwList$[6] = "callback"
    kwList$[7] = " export"

    FOR i AS INT = 0 TO 7
        kw$ = kwList$[i]
        IF IINSTR(localLine$, kw$) THEN
            IREMOVE kw$ FROM localLine$
            localLine$ = TRIM$(localLine$)
        END IF
    NEXT

    IF LCASE$(LEFT$(localLine$, 8)) = "function" THEN
        tmp$ = MID$(localLine$, 9)
        tmp$ = LTRIM$(tmp$)
        IF LEFT$(tmp$, 1) = "=" THEN EXIT SUB
    END IF

    IF LCASE$(LEFT$(localLine$, 8)) <> "function" THEN EXIT SUB

    FunkHeader$ = TRIM$(MID$(localLine$, 9))

    p1 = INCHR(FunkHeader$, "(")
    IF p1 THEN
        ' Function with args
        FunkName$ = TRIM$(LEFT$(FunkHeader$, p1 - 1))

        ' Flexible scan for ")" followed by "AS" with variable spacing
        DIM i%, j%, k%
        p1 = 0
        FOR i = 1 TO LEN(FunkHeader$) - 4
            IF MID$(FunkHeader$, i, 1) = ")" THEN
                j = i + 1
                WHILE j <= LEN(FunkHeader$) AND MID$(FunkHeader$, j, 1) = SPC$
                    j = j + 1
                WEND
                IF LCASE$(MID$(FunkHeader$, j, 2)) = "as" THEN
                    k = j + 2
                    WHILE k <= LEN(FunkHeader$) AND MID$(FunkHeader$, k, 1) = SPC$
                        k = k + 1
                    WEND
                    p1 = k - 1
                    EXIT FOR
                END IF
            END IF
        NEXT

        IF p1 THEN
            FunkType$ = TRIM$(MID$(FunkHeader$, p1 + 1))
        ELSE
            FunkType$ = "INTEGER"
        END IF
    ELSE
        '----------------------------------------------
        ' No args: look for "AS" with flexible spacing
        '----------------------------------------------
        DIM asPos AS INT
        asPos = 0
        FOR i AS INT = 1 TO LEN(FunkHeader$) - 2
            IF MID$(LCASE$(FunkHeader$), i, 2) = "as" THEN
                ' Check that "AS" is surrounded by spaces or line ends
                DIM before$, after$
                before$ = MID$(FunkHeader$, i - 1, 1)
                after$  = MID$(FunkHeader$, i + 2, 1)
                IF (i = 1 OR before$ = SPC$) AND (after$ = SPC$ OR (i + 2) > LEN(FunkHeader$)) THEN
                    asPos = i
                    EXIT FOR
                END IF
            END IF
        NEXT
        '----------------------------------------------
        IF asPos THEN
            FunkName$ = TRIM$(LEFT$(FunkHeader$, asPos - 1))
            FunkType$ = TRIM$(MID$(FunkHeader$, asPos + 2))
        ELSE
            FunkName$ = TRIM$(FunkHeader$)
            FunkType$ = "INTEGER"
        END IF
    END IF

    IF INSTR(FunkType$, "INTEGER") THEN
        IF INCHR(FunkName$, "$") THEN FunkType$ = "STRING"
        IF INCHR(FunkName$, "!") THEN FunkType$ = "SINGLE"
        IF INCHR(FunkName$, "#") THEN FunkType$ = "DOUBLE"
        IF INCHR(FunkName$, "%") THEN FunkType$ = "INTEGER"
    END IF

    IF FunkName$ = "Name$" THEN EXIT SUB
    IF FunkName$ = "Type$" THEN EXIT SUB
    IF INCHR(FunkName$, "=") THEN EXIT SUB
    IF LTRIM$(FunkName$) = "" THEN EXIT SUB

    FunctionNameType.FunctionName$ = TRIM$(FunkName$)

    FunkType$ = TRIM$(FunkType$)

    IF RIGHT$(FunkType$, 2) = " &" THEN   ' Edge Case -- Accomodate C++ functions that return a reference type "&" like cpp5.bas
        REMOVE "&" FROM FunkType$
        FunkType$ = "static " + FunkType$
    END IF

    FunctionNameType.FunctionType$ = FunkType$
END SUB ' ScanFuncNamesTypes




FUNCTION BeautifyCode (src AS STRING) AS STRING
    '************************************************************************************
    ' The BeautifyCode function reformats a line of source code by compressing multiple
    ' spaces into a single space outside quoted strings and by removing unnecessary
    ' spaces around common symbols. It preserves spacing inside quoted strings and
    ' ensures cleaner, more consistent code formatting for easier parsing or display.
    '*************************************************************************************
    DIM c AS UBYTE
    DIM ch AS STRING
    DIM cleaned AS STRING
    DIM inQuote AS INT
    DIM out AS STRING

    ' First pass: compress spaces outside quoted strings
    FOR i AS LONG = 0 TO LEN(src) - 1
        c = ASC(MID$(src, i + 1, 1))
        IF c = 34 THEN
            inQuote = NOT inQuote
            cleaned = cleaned + CHR$(c)
        ELSEIF inQuote THEN
            cleaned = cleaned + CHR$(c)
        ELSE
            IF c <= 32 THEN
                IF LEN(cleaned) > 0 THEN
                    IF RIGHT$(cleaned, 1) <> SPC$ THEN
                        cleaned = cleaned + SPC$
                    END IF
                END IF
            ELSE
                cleaned = cleaned + CHR$(c)
            END IF
        END IF
    NEXT

    ' Second pass: trim spaces around = ( ) , ; | [ ] < > { }
    inQuote = 0
    FOR i AS LONG = 1 TO LEN(cleaned)
        ch = MID$(cleaned, i, 1)
        IF ch = DQ$ THEN
            inQuote = NOT inQuote
            out = out + ch
        ELSEIF inQuote THEN
            out = out + ch
        ELSE
            SELECT CASE ch
                CASE "=", "(", ")", ",", ";", "|", "[", "]", "{", "}", "<", ">"
                    ' Remove space before symbol
                    WHILE LEN(out) > 0 AND RIGHT$(out, 1) = SPC$
                        out = LEFT$(out, LEN(out) - 1)
                    WEND
                    out = out + ch
                    ' Skip spaces after symbol
                    DO WHILE i < LEN(cleaned) AND MID$(cleaned, i + 1, 1) = SPC$
                        INCR i
                    LOOP
                CASE ELSE
                    out = out + ch
            END SELECT
        END IF
    NEXT
    FUNCTION = out
END FUNCTION ' BeautifyCode





SUB Convert_Chr2VChr
    '********************************************************************
    '       Convert CHR$() to VCHR$() automagically        MrBcx 829
    '********************************************************************
    DIM AS INT NewIndex, ArgCount, i

    i = 1
    WHILE i <= Ndx
        INCR NewIndex
        Vchr_Stk$[NewIndex] = Stk$[i]

        ' Check for CHR$ followed by opening paren
        IF (i < Ndx) AND LCASE$(Stk$[i]) = "chr$" THEN
            IF Stk$[i + 1] = "(" THEN
                ' Change CHR$ to VCHR$ in the new stack
                Vchr_Stk$[NewIndex] = "VCHR$"

                INCR i
                INCR NewIndex
                Vchr_Stk$[NewIndex] = Stk$[i]  ' Copy "("

                ' Count the arguments in this CHR$ call
                ArgCount = CountChrArguments(i + 1)

                ' Insert the argument count
                INCR NewIndex
                Vchr_Stk$[NewIndex] = STR$(ArgCount)

                ' Add comma if we have arguments
                IF ArgCount > 0 THEN
                    INCR NewIndex
                    Vchr_Stk$[NewIndex] = ","
                END IF
            END IF
        END IF
        INCR i
    WEND

    ' Update the main stack
    FOR i = 1 TO NewIndex
        Stk$[i] = Vchr_Stk$[i]
    NEXT
    Ndx = NewIndex
END SUB ' Convert_Chr2VChr




FUNCTION CountChrArguments(StartPos AS INT) AS INT
    DIM AS INT i, ParenDepth, ArgCount
    DIM AS BOOL HasContent

    i = StartPos
    WHILE i <= Ndx
        SELECT CASE Stk$[i]
            CASE "("
                ParenDepth = ParenDepth + 1
                HasContent = TRUE

            CASE ")"
                IF ParenDepth = 0 THEN
                    ' This is our closing paren for CHR$
                    IF HasContent THEN ArgCount = ArgCount + 1
                    '  EXIT WHILE
                    FUNCTION = ArgCount

                ELSE
                    ParenDepth = ParenDepth - 1
                    HasContent = TRUE
                END IF

            CASE ","
                IF ParenDepth = 0 THEN
                    ' Top-level comma - end of current argument
                    IF HasContent THEN ArgCount = ArgCount + 1
                    HasContent = FALSE
                ELSE
                    HasContent = TRUE
                END IF

            CASE ELSE
                IF LTRIM$(Stk$[i]) <> "" THEN
                    HasContent = TRUE
                END IF
        END SELECT
        i = i + 1
    WEND
    FUNCTION = ArgCount
END FUNCTION ' CountChrArguments



SUB ProcessInjection
    '*************************  New code block added in 830  ****************************
    ' Emit "DIM Bcx_RetVal As ???"  when inside a FUNCTION with LOCAL Dynamic Arrays
    '            This SUB is called immediately following CALL Translate()
    '************************************************************************************
    STATIC Prev_gCurrentFunction$

    IF Prev_gCurrentFunction$ = gCurrentFunction$ THEN
        EXIT SUB
    END IF

    IF InFunction AND g_FoundLocalDynArray THEN
        IF NOT InTypeDef AND NOT InCppTypeDef THEN
            CALL ScanFuncNamesTypes(gCurrentFunction$)  ' gCurrentFunction$ = f.e. "FUNCTION Foo(a,b) AS DOUBLE"
            IF LEN(FunctionNameType.FunctionName$) AND LCASE$(FunctionNameType.FunctionType$) <> "string" THEN
                g_Injection$ = "DIM Bcx_RetVal AS" + SPC$  ' <<<-- the space is intentional
                CONCAT(g_Injection$, FunctionNameType.FunctionType$)
                PassOne = TRUE
                Inject (g_Injection$) ' Injects DIM Bcx_RetVal
                PassOne = TRUE
                Prev_gCurrentFunction$ = gCurrentFunction$
            END IF
        END IF
    END IF
END SUB ' ProcessInjection



SUB SplitDimAssignment
    '*********************************************************************************
    ' This SUB detects DIM/STATIC/LOCAL/RAW/SHARED statements with assignments and
    ' splits them into two separate statements: declaration and assignment.
    '
    ' Automatically adds the RAW keyword ONLY to DIM declarations if not already
    ' present, avoiding redundant zero-initialization before assignment.
    '
    ' NOTE: GLOBAL declarations with initializers work correctly in BCX,
    ' so we skip processing them. LOCAL, STATIC, SHARED, and GLOBAL do not
    ' support the RAW keyword in BCX.
    '
    ' Handles both explicit AS type declarations and sigil-based declarations:
    '    DIM TwoPi as DOUBLE = 2 * PI          ->  DIM RAW TwoPi as DOUBLE : TwoPi = 2 * PI
    '    LOCAL TwoPi! = 2 * PI                 ->  LOCAL TwoPi! : TwoPi! = 2 * PI
    '    STATIC TwoPi$ = STR$(2 * PI)          ->  STATIC TwoPi$ : TwoPi$ = STR$(2 * PI)
    '
    ' CRITICAL: This must run BEFORE macro expansion (e.g., PI -> 3.14159)
    ' to avoid corrupting the assignment expression.
    '*********************************************************************************
    DIM FirstChar AS INT
    DIM HasRaw AS INT
    DIM iAsPos AS INT
    DIM iEqualPos AS INT
    DIM IsDimKeyword AS INT
    DIM iVarNamePos AS INT
    DIM LastOrig AS INT
    DIM Assignment AS STRING
    DIM DeclPart AS STRING
    DIM OrigVar AS STRING
    DIM TestName AS STRING
    DIM VarName AS STRING
    DIM VarType AS STRING

    IF NOT m_iMatchWrd(Stk$[1], "dim") AND _
        NOT m_iMatchWrd(Stk$[1], "local") AND _
        NOT m_iMatchWrd(Stk$[1], "static") AND _
        NOT m_iMatchWrd(Stk$[1], "raw") AND _
        NOT m_iMatchWrd(Stk$[1], "shared") AND _
        NOT m_iMatchWrd(Stk$[1], "global") THEN
        EXIT SUB
    END IF

    ' Find the first "=" position at top level (not inside parentheses)
    iEqualPos = 0
    DIM ParenCount = 0
    FOR i AS INT = 2 TO Ndx
        IF Stk$[i] = "(" THEN INCR ParenCount
        IF Stk$[i] = ")" THEN DECR ParenCount
        IF ParenCount = 0 AND *Stk$[i] = ASC("=") THEN
            iEqualPos = i
            EXIT FOR
        END IF
    NEXT

    IF iEqualPos = 0 THEN EXIT SUB  ' No assignment, nothing to split

    ' Check if RAW is already present anywhere in the declaration header
    HasRaw = FALSE
    FOR i AS INT = 1 TO iEqualPos - 1
        IF m_iMatchWrd(Stk$[i], "raw") THEN
            HasRaw = TRUE
            EXIT FOR
        END IF
    NEXT

    ' Find the LAST "AS" before the "=" (the type specification)
    ' We use the LAST one because there could be casts in the assignment
    ' that also contain "AS" (though unlikely, we should be safe)
    iAsPos = 0
    FOR i AS INT = iEqualPos - 1 TO 2 STEP -1
        IF m_iMatchWrd(Stk$[i], "as") THEN
            iAsPos = i
            EXIT FOR
        END IF
    NEXT

    ' Determine variable name and type
    IF iAsPos > 0 THEN
        ' Has explicit AS: "DIM TwoPi as DOUBLE = 2 * PI"
        ' or "DIM RAW pnmh = (LPNMHDR)CBLPARAM AS LPNMHDR"
        ' The type is the token after the LAST AS
        VarType$ = Stk$[iAsPos + 1]

        ' Find the variable name - look for the first identifier before the "="
        ' that is not a keyword
        iVarNamePos = 0
        FOR i AS INT = 2 TO iEqualPos - 1
            ' Skip the AS token and the type
            IF i = iAsPos OR i = iAsPos + 1 THEN ITERATE

            TestName$ = No_Sigil$(Stk$[i])
            FirstChar = *TestName$

            ' Check if this is a valid variable name
            IF (isalpha(FirstChar) OR FirstChar = ASC("_")) THEN
                ' Make sure it's not a keyword
                DIM RAW LowerName$ = LCASE$(TestName$)
                IF LowerName$ <> "dim" AND LowerName$ <> "local" AND _
                    LowerName$ <> "static" AND LowerName$ <> "raw" AND _
                    LowerName$ <> "global" AND LowerName$ <> "shared" AND _
                    LowerName$ <> "as" AND LowerName$ <> "ptr" AND _
                    LowerName$ <> "int" AND LowerName$ <> "long" AND _
                    LowerName$ <> "double" AND LowerName$ <> "float" AND _
                    LowerName$ <> "string" AND LowerName$ <> "char" THEN
                    iVarNamePos = i
                    VarName$ = TestName$
                    EXIT FOR
                END IF
            END IF
        NEXT

        ' If we couldn't find a variable name, use the token before the AS
        IF VarName$ = "" THEN
            VarName$ = No_Sigil$(Stk$[iAsPos - 1])
            iVarNamePos = iAsPos - 1
        END IF
    ELSE
        ' Sigil-based declaration: "LOCAL TwoPi# = 2 * PI"
        ' The variable position depends on whether token 2 is RAW
        IF m_iMatchWrd(Stk$[2], "raw") THEN
            iVarNamePos = 3
        ELSE
            iVarNamePos = 2
        END IF

        VarName$ = No_Sigil$(Stk$[iVarNamePos])

        ' Check if the variable name has a sigil
        DIM LastChar = ASC(RIGHT$(VarName$, 1))
        IF INCHR(c_VARTYPES$, CHR$(LastChar)) THEN
            VarType$ = VarTypeLookup$[ INCHR(c_VARTYPES$, CHR$(LastChar)) ]
        ELSE
            ' No sigil, assume INTEGER for sigil-less declarations
            VarType$ = "int"
        END IF
    END IF

    ' Extract the assignment expression (everything after "=")
    Assignment$ = ""
    FOR i AS INT = iEqualPos + 1 TO Ndx
        Assignment$ += Stk$[i] + SPC$
    NEXT
    Assignment$ = TRIM$(Assignment$)

    ' Check if statement strictly starts with "DIM"
    IsDimKeyword = m_iMatchWrd(Stk$[1], "dim")

    ' Build the declaration part (everything before "=")
    ' Inject RAW ONLY if it is a DIM keyword and doesn't already have RAW
    DeclPart$ = Stk$[1] + SPC$
    IF IsDimKeyword AND NOT HasRaw THEN
        DeclPart$ += "RAW "
    END IF

    FOR i AS INT = 2 TO iEqualPos - 1
        DeclPart$ += Stk$[i] + SPC$
    NEXT
    DeclPart$ = TRIM$(DeclPart$)

    ' IMPORTANT: Use the ORIGINAL variable name with sigil in the assignment
    ' This preserves the sigil for proper type checking

    DIM RAW AssignVarName$
    IF iAsPos > 0 THEN
        ' When using AS, we need to use the variable name with its sigil
        ' if it has one, or just the name if it doesn't
        AssignVarName$ = VarName$
        ' Check if original had a sigil
        IF iVarNamePos > 0 THEN
            OrigVar$ = Stk$[iVarNamePos]
            LastOrig = ASC(RIGHT$(OrigVar$, 1))
            IF INCHR(c_VARTYPES$, CHR$(LastOrig)) THEN
                AssignVarName$ = AssignVarName$ + CHR$(LastOrig)
            END IF
        END IF
    ELSE
        ' Sigil-based declaration - use the name as-is from its position
        AssignVarName$ = Stk$[iVarNamePos]
    END IF

    ' SPECIAL CASE: If this is a DIM without AS and without a sigil,
    ' and the assignment is a simple value, BCX can handle it directly.
    ' Only split if necessary.

    IF iAsPos = 0 AND INCHR(c_VARTYPES$, CHR$(ASC(RIGHT$(Stk$[iVarNamePos], 1)))) = 0 THEN
        ' No AS and no sigil - this is a simple DIM with assignment
        ' BCX should handle this correctly without splitting
        EXIT SUB
    END IF

    Src$ = DeclPart$ + " : " + AssignVarName$ + " = " + Assignment$

    ' Call SplitLines directly to break the line into separate statements
    CALL SplitLines(Src$)

    Src$ = ""    ' Clear Src$ so the main loop doesn't process it again
    Ndx = 0      ' Clear the stack
END SUB ' SplitDimAssignment






SUB NormalizeStrConcat
    '*******************************************************************************
    '  NormalizeStrConcat - Rewrite + to & where string concatenation is intended
    '
    '  Rules (derived from original logic):
    '    1. Never touch ++ operator
    '    2. String literal after +  -> use &
    '    3. Known string function  -> use & and tag with $
    '    4. UDT string member      -> use & and tag with $
    '    5. Untyped dotted member  -> use & and tag with $ (assume string)
    '    6. Variable lookup: if string type -> use &
    '*******************************************************************************
    FOR k AS LONG = 1 TO Ndx - 1
        IF Stk$[k] <> "+" THEN ITERATE

        DIM RAW NextToken$ = Stk$[k+1]

        ' Rule 1: Preserve ++ increment operator
        IF NextToken$ = "+" THEN ITERATE

        ' Rule 2: String literal
        IF LEFT$(NextToken$, 1) = DQ$ THEN
            Stk$[k] = "&"
            ITERATE
        END IF

        ' Rule 3: Known string-returning function (needs $ tag)
        IF INSTR(FuncStrNames$, SPC$ + NextToken$) THEN
            Stk$[k]   = "&"
            Stk$[k+1] += "$"
            ITERATE
        END IF

        ' Rule 4: Already typed as string? Just change operator
        IF INCHR(NextToken$, "$") THEN
            Stk$[k] = "&"
            ITERATE
        END IF

        ' Rule 5: Numeric literal? Leave alone
        IF isdigit(*NextToken$) THEN ITERATE

        ' Rule 6: UDT member with known string type?
        IF Im_UDT_String(NextToken$) THEN
            Stk$[k]   = "&"
            Stk$[k+1] += "$"
            ITERATE
        END IF

        ' Rule 7: Dotted member access (e.g., struct.field)
        IF INCHR(NextToken$, ".") THEN
            IF Im_UDT_Single(NextToken$)  THEN ITERATE
            IF Im_UDT_Double(NextToken$)  THEN ITERATE

            ' Check variable tables for type
            DIM AS INT varid, vtype
            vtype = CheckLocal(NextToken$, ADDRESSOF(varid))
            IF vtype = vt_UNKNOWN THEN
                vtype = CheckGlobal(NextToken$, ADDRESSOF(varid))
            END IF

            ' Untyped dotted member: assume string, tag with $
            IF vtype = vt_UNKNOWN THEN
                Stk$[k]   = "&"
                Stk$[k+1] += "$"
            END IF

            ITERATE
        END IF

        ' Rule 8: Plain variable — check symbol tables
        DIM AS INT varid, vtype
        vtype = CheckLocal(NextToken$, ADDRESSOF(varid))
        IF vtype = vt_UNKNOWN THEN
            vtype = CheckGlobal(NextToken$, ADDRESSOF(varid))
        END IF

        IF vtype = vt_STRVAR OR vtype = vt_CHAR OR vtype = vt_SCHAR THEN
            Stk$[k] = "&"
        END IF

    NEXT
END SUB ' NormalizeStrConcat



SUB RBForTransform
    '********************************************************************
    '  777 -  James Fuller's pre-translation FOR-NEXT transform
    '                for C++11 Range Based FOR-NEXT loops
    '                 Keywords:  RBFOR,  RBEXIT,  RBNEXT
    '*********************************************************************
    DIM Kopy$ = TRIM$(Src$)

    IF LEFTSTR(Kopy$, "rbfor", 1) THEN
        Src$ = iReplace_NQ$(Src$, "AUTO", "auto")
        Src$ = iReplace_NQ$(Src$, "rbfor", "! for ")
        Src$ += " { "
    END IF

    IF LEFTSTR(Kopy$, "rbnext", 1) THEN
        Src$ = "}"
    END IF

    IF LEFTSTR(Kopy$, "rbexit", 1) THEN
        Src$ = "break"
    END IF
END SUB  ' RBForTransform



SUB StripExtraDefWndProcs
    '*********************************************************************
    ' This subroutine reads lines from FileOut$, strips unnecessary
    ' consecutive "return DefWindowProc" lines, writes the cleaned lines
    ' to a temporary file which is renamed and replaces the original file.
    '*********************************************************************
    DIM RAW Source$
    DIM RAW CurrLin$
    DIM RAW PrevLin$
    '****************************************
    OPEN FileOut$          FOR INPUT  AS FP1
    OPEN "$Bcx$Temp$File$" FOR OUTPUT AS FP2
    '****************************************
    DO WHILE NOT EOF(FP1)
        LINE INPUT FP1, Source$
        CurrLin$ = LEFT$(LTRIM$(Source$), 20)

        IF CurrLin$ <> "return DefWindowProc" THEN
            FPRINT FP2, Source$
            PrevLin$ = LEFT$(LTRIM$(Source$), 7)  ' Warning:  Don't assume this = "return "
            ITERATE
        END IF

        IF CurrLin$ = "return DefWindowProc" AND PrevLin$ <> "return " THEN
            FPRINT FP2, Source$
        END IF

        PrevLin$ = LEFT$(LTRIM$(Source$), 7)      ' Warning:  Don't assume this = "return "
    LOOP

    CLOSE FP1, FP2
    KILL FileOut$
    RENAME "$Bcx$Temp$File$", FileOut$
END SUB  ' StripExtraDefWndProcs




FUNCTION iMatch(Arg$ AS PCTSTR, MatchStr$ AS PCTSTR, mt)
    '****************************************************
    ' Case insensitive comparison - MatchStr$ to Arg$
    ' mt = 0, 1 or 2 Match left, whole word, right
    '****************************************************
    DIM RAW L1 AS INT
    DIM RAW L2 AS INT
    IF mt = 2 THEN
        L1 = LEN(Arg$)
        L2 = LEN(MatchStr$)
        IF L1 < L2 THEN FUNCTION = FALSE
        Arg = (Arg + L1) - L2
    END IF
    DO WHILE *MatchStr
        IF ISNULL(Arg) THEN FUNCTION = FALSE                          ' If we run out string, return no match
        IF (*Arg BOR 32) <> (*MatchStr BOR 32) THEN FUNCTION = FALSE  ' bit ORing with 32 produces lower case
        INCR Arg
        INCR MatchStr
    LOOP
    IF mt AND NOTNULL(Arg$) THEN
        FUNCTION = FALSE
    ELSE
        FUNCTION = TRUE
    END IF
END FUNCTION ' iMatch



FUNCTION iMatchNQ (Arg$, MatchStr$)
    '****************************************************
    ' Returns the position of the first occurrence
    ' of MatchStr$ in Arg$ that isn't in quotes.
    '****************************************************
    DIM mi= 0
    DIM a AS PCHAR = Arg

    DO WHILE MatchStr[mi]
        IF *a = c_DblQt THEN
            mi = 0
            DO WHILE *(++a) <> c_DblQt
                IF *a = 0 THEN FUNCTION = FALSE
            LOOP
        END IF
        IF a[mi] = 0 THEN FUNCTION = FALSE               ' If we run out string, return no match
        IF (a[mi] BOR 32) <> (MatchStr[mi] BOR 32) THEN  ' bit ORing with 32 produces lower case
            INCR a
            mi = (-1)
        END IF
        INCR mi
    LOOP
    FUNCTION = CAST(INT, (a-Arg) + 1)  ' We have a match
END FUNCTION  ' iMatchNQ



FUNCTION GetBracketPair(iStart AS INT, iEnd AS INT, iDir AS INT)
    '****************************************************************************
    ' This function searches for a pair of consecutive brackets ("[") and ("]")
    ' in the Stk$ array, starting from the index iStart to iEnd in the direction
    ' specified by iDir.  If found, it returns the index of the opening bracket;
    ' otherwise, it returns 0.
    '****************************************************************************
    FOR i AS INT = iStart TO iEnd STEP iDir
        IF *Stk$[i] = ASC("[") AND *Stk$[i+1] = ASC("]") THEN
            FUNCTION = i
        END IF
    NEXT
    FUNCTION = 0
END FUNCTION ' GetBracketPair




FUNCTION GetAsPos(iStart AS INT, iEnd AS INT, iDir AS INT)
    '****************************************************************************
    ' This function searches for the word "as" in the Stk$ array,
    ' starting from the index iStart to iEnd in the direction specified by iDir.
    ' If found, it returns the index of the occurrence; otherwise, it returns 0.
    '****************************************************************************
    FOR i AS INT = iStart TO iEnd STEP iDir
        IF m_iMatchWrd(Stk$[i], "as") THEN
            FUNCTION = i
        END IF
    NEXT
    FUNCTION = 0
END FUNCTION  ' GetAsPos




SUB BuildStr(iStart, iEnd, szBuild$)
    '******************************************************************
    ' This subroutine concatenates the elements of the Stk$ array
    ' from index iStart to iEnd into the szBuild$ string, effectively
    ' building a single string from the specified range.
    '******************************************************************
    szBuild$ = ""
    FOR i AS INT = iStart TO iEnd
        szBuild$ += Stk$[i]
    NEXT
END SUB ' BuildStr



FUNCTION No_Sigil$(StringArg AS STRING)
    '*************************************************
    ' Carefully removes sigils (%$#!@`) from StringArg
    '*************************************************
    DIM RAW LTmp$
    IF iMatchNQ(StringArg, "%") THEN
        IF TRIM$(StringArg) = "%" THEN FUNCTION = " % "
    END IF
    IF iMatchNQ(StringArg, "!=") THEN FUNCTION = StringArg
    LTmp$ = StringArg
    RemoveAll(LTmp$, c_VARTYPES$, 1)   ' 1 = ignore anything in quotes
    FUNCTION = LTmp$
END FUNCTION ' No_Sigil$



SUB BuildDelimStr(iStart, iEnd, szBuild$)  ' 837 revised by MrBcx
    '*********************************************************************
    ' Joins tokens Stk$[iStart..iEnd] into szBuild$ using BCX's standard
    ' inter-token spacing rules.
    '
    ' Spacing rules:
    '   - Empty token slots are skipped.
    '   - A "!" token is emitted as " ! " so the SINGLE sigil doesn't fuse to its neighbours.
    '   - A token starting with "_" gets a leading space
    '   - All other tokens are appended directly.
    '
    ' A separator space follows the current token UNLESS any of:
    '   - it's the last token in the range,
    '   - the current token is single-character punctuation
    '   - the next token is single-character punctuation
    '   - the LINE is a BCX assignment, detected via Stk$[2] starting with "="
    '*********************************************************************
    szBuild$ = ""

    FOR i AS INT = iStart TO iEnd
        IF LEN(Stk$[i]) = 0 THEN ITERATE                            ' Skip empty slots

        IF Stk$[i] = "!" THEN                                       ' Isolate inline operator
            szBuild$ += " ! "
            ITERATE
        END IF

        IF *Stk$[i] = ASC("_") THEN                                 ' Isolate continuation char
            szBuild$ += SPC$ + Stk$[i]
        ELSE
            szBuild$ += Stk$[i]
            IF LEN(Stk$[i]) = 1 AND ispunct(*Stk$[i]) THEN ITERATE  ' skip single-char punctuation
        END IF

        IF *Stk$[2] = ASC("=")                        THEN ITERATE  ' skip assignments ( Variable = Expression )
        IF i = iEnd                                   THEN ITERATE  ' Guards against orphaned data
        IF LEN(Stk$[i+1]) = 1 AND ispunct(*Stk$[i+1]) THEN ITERATE  ' skip single-char punctuation

        szBuild$ += SPC$
    NEXT

    IF RIGHTSTR(szBuild$, " , 1);") THEN
        REPLACE " , 1);" WITH ", 1);" IN szBuild$                   '  838 MrBcx -- a formatting edge case
    END IF
END SUB ' BuildDelimStr



SUB BuildCleanStr(iStart, iEnd, szBuild$)
    '************************************************************************
    ' This SUB constructs a delimited string from an array of strings and
    ' then removes specific sigils and unwanted chars from the final string.
    '************************************************************************
    CALL BuildDelimStr(iStart, iEnd, szBuild$)
    szBuild$ = No_Sigil$(szBuild$)
END SUB ' BuildCleanStr




SUB WriteCleanTokens(iStart, iEnd)
    '***************************************************************
    ' This SUB constructs a cleaned, delimited string from an array
    ' of strings and writes the resulting string to the output file.
    '***************************************************************
    DIM RAW LTmp$
    CALL BuildCleanStr(iStart, iEnd, LTmp$)
    FPRINT FP_WRITE, LTmp$
END SUB ' WriteCleanTokens




FUNCTION HasThisToken(sToken$)
    '*****************************************************************************
    ' This function checks if the sToken$ string is present in the Stk$ array.
    ' It returns a non-zero value if the token is found; otherwise, it returns 0.
    '*****************************************************************************
    DIM ThisToken = 0
    XFOR INT j = 1 WHILE j <= Ndx AND m_IAmNot(ThisToken) BY j++
        ThisToken = m_iMatchWrd(Stk$[j], sToken$)
    XNEXT
    FUNCTION = ThisToken
END FUNCTION ' HasThisToken

'************************************************************************************************
'                                 Expand the Built-in BCX Macros
'************************************************************************************************


FUNCTION FoundMacro
    '********************************************************************************************
    ' This function checks if the source code string (Src$) contains certain macro commands
    ' (e.g., handle_msg, handle_cmd, bcx_resource, msghandler, cmdhandler, end) and processes
    ' them accordingly. If a recognized macro is found, the function executes the appropriate
    ' SUB to handle the macro, sets IsMacro to TRUE, and clears the source string (Src$).
    ' The function returns TRUE if a macro was found and processed, otherwise it returns FALSE.
    '********************************************************************************************
    DIM IsMacro = FALSE
    FastLexer(Src$, " (", "")
    DIM szMacroCheck$ = LCASE$(Stk$[1])

    IF iMatchNQ ("handle_msg handle_cmd bcx_resource msghandler cmdhandler end", szMacroCheck$) THEN
        SELECT CASE szMacroCheck$
            CASE "handle_msg"     ' handle_msg handler
                CALL CheckMatchedPairs
                CALL ProcessMsgCracker
                IsMacro = TRUE

            CASE "handle_cmd"
                CALL CheckMatchedPairs
                CALL ProcessCmdHandler
                IsMacro = TRUE

            CASE "bcx_resource"
                Use_GenResFile = TRUE
                FPRINT FP_RES, MID$(Src$, 14)
                IsMacro = TRUE

            CASE "msghandler", "cmdhandler"
                Inject_Local_Bcx_RetVal = TRUE
                CALL CheckMatchedPairs
                CALL ProcessMsgHandler
                IsMacro = TRUE

            CASE "end"
                IF ISTRUE (m_iMatchWrd(Stk$[2], "handler")) THEN
                    CALL CheckMatchedPairs
                    CALL ProcessMsgHandlerEnd
                    IsMacro = TRUE
                END IF
        END SELECT
    END IF
    IF IsMacro = TRUE THEN Src$ = ""
    FUNCTION = IsMacro
END FUNCTION ' FoundMacro





SUB Process_ASC_Function (St_idx)
    '*************************************************************************************************************
    ' This parses an "ASC" function starting at the given index (St_idx) in the Stk$ array.
    ' It detects if the function argument is a double quote and handles the function conversion accordingly.
    ' If the argument is a double quote, it sets the stack entry to "asc" and updates Use_Asc and Use_Proto flags.
    ' If the argument is not a double quote, it converts the character to its ASCII value or sets the
    ' entry to "0". For other cases, it handles arguments and sets the stack entry for further processing.
    '**************************************************************************************************************
    DIM i
    DIM j = GetNumArgs(St_idx + 2, ADDRESSOF(i))
    IF *Stk$[St_idx + 2] = *DQ$ THEN
        IF j OR *Stk$[St_idx + 3] <> ASC(")") THEN
            Stk$[St_idx] = "asc"
            Use_Asc = Use_Proto = TRUE
        ELSE
            IF Stk$[St_idx + 2] = DDQ$ THEN
                Stk$[St_idx] = "0"
            ELSE
                Stk$[St_idx] = STR$(CAST(DOUBLE, ASC(Stk$[St_idx + 2], 1)), TRUE)
            END IF
            Stk$[St_idx + 1] = ""
            Stk$[St_idx + 2] = ""
            Stk$[St_idx + 3] = ""
        END IF
    ELSE
        IF j > 0 THEN Stk$[i] = "+"
        Stk$[St_idx] = "(UCHAR)*"
    END IF
END SUB ' Process_ASC_Function




SUB ActivityFlags
    '********************************************************************************************************
    ' This subroutine manages activity flags for tracing and source output.
    ' If ShowStatus is true, it calls DisplayStatus.
    ' If TraceFlag and InFunction are true and the current line is not a trace or end statement,
    ' it logs the current source line with file name and line number, and adds a printf statement.
    ' If SrcFlag is true and the current line is not a source directive or comment, it logs the source line.
    '*********************************************************************************************************
    IF ShowStatus THEN CALL DisplayStatus
    '*******************************************
    IF ISTRUE (TraceFlag AND InFunction) THEN
        IF ISFALSE(m_iMatchLft(Src$, "$trace")) THEN
            IF ISFALSE(m_iMatchLft(Src$, "end ")) AND ISZERO (iMatchNQ(Src$, "function")) THEN
                FPRINT FP_WRITE, "// [", TRIM$(FileNames$[FileNdx]), " - ", STR$(LineNum[FileNdx], 1), "] ", Src$
                LOCAL Tmp$
                Tmp$ = TRIM$(FileNames$[FileNdx])
                Tmp$ = REPLACE$(Tmp$, BKSLASH1$, BKSLASH2$)
                Tmp$ = SPC$ + Tmp$ + " - " + STR$(LineNum[FileNdx]) + " \\n"
                Tmp$ = "printf(" + ENC$(Tmp$) + ");"
                FPRINT FP_WRITE, Tmp$
            END IF
        END IF
    END IF
    '*****************************************
    IF SrcFlag THEN
        IF ISFALSE (m_iMatchLft(Src$, "$sourc")) AND *Src <> ASC("!") THEN
            FPRINT FP_WRITE, "// [", TRIM$(FileNames$[FileNdx]), " - ", STR$(LineNum[FileNdx], 1), "] ", Src$
        END IF
    END IF
END SUB ' ActivityFlags



SUB DisplayStatus
    '**************************************************************************
    ' The purpose of this SUB is to update and display the current processing
    ' status on the screen. It shows the module being processed, the current
    ' line number, and any abort source message. Additionally, it provides an
    ' option to cancel the operation by pressing any key, which then removes
    ' unfinished translation files and notifies the user of the cancellation.
    ' The function also manages screen colors, if c_BCX_COLORS is enabled.
    '**************************************************************************
    LOCATE 5, 1, 0
    PRINT SPACE$(150)
    LOCATE 5, 1, 0
    PRINT "Processing Module: ", TRIM$(FileNames$[FileNdx]), " - Line:", LineNum[FileNdx]
    LOCATE 6, 1, 0
    PRINT SPACE$ (1000)
    IF c_BCX_COLORS THEN COLOR 10, 0
    LOCATE 6, 1, 0
    PRINT STRIM$ (AbortSrc$)
    IF c_BCX_COLORS THEN COLOR 13, 0
    LOCATE 10, 1, 0
    PRINT "Press any key to cancel"
    SLEEP (25)
    IF INSTAT THEN
        CLOSE
        SLEEP (100)
        KILL "BC.out"
        KILL "BC.c"
        KILL "BC.cpp"
        POPCOLORS
        PRINT "Cancelled by user. Unfinished translation files removed."
        END
    END IF
    POPCOLORS
END SUB ' DisplayStatus



FUNCTION GetVarTypeName$ (i)
    DIM RAW A$
    SELECT CASE i
        CASE vt_INTEGER    :    A$ = "int"
        CASE vt_STRVAR     :    A$ = "char *"
        CASE vt_STRLIT     :    A$ = "STRLIT"
        CASE vt_UNKNOWN    :    A$ = "UNKNOWN"
        CASE vt_SINGLE     :    A$ = "float"
        CASE vt_DOUBLE     :    A$ = "double"
        CASE vt_LDOUBLE    :    A$ = "LDOUBLE"
        CASE vt_DECFUNC    :    A$ = "DECFUNC"
        CASE vt_NUMBER     :    A$ = "NUMBER"
        CASE vt_FILEPTR    :    A$ = "FILE*"
        CASE vt_UDT        :    A$ = "struct"
        CASE vt_STRUCT     :    A$ = "struct"
        CASE vt_UNION      :    A$ = "union"
        CASE vt_PSTR       :    A$ = "PSTR"
        CASE vt_BSTR       :    A$ = "BSTR"
        CASE vt_BOOL       :    A$ = "BOOL"     ' When UseCpp THEN A$ = "bool" ELSE A$ = "BOOL"
        CASE vt_CHAR       :    A$ = "char"
        CASE vt_SCHAR      :    A$ = "signed char"
        CASE vt_PSTRPTR    :    A$ = "PSTR *"
        CASE vt_CHARPTR    :    A$ = "char"     ' Default String - 2048
        CASE vt_PCHAR      :    A$ = "PCHAR"
        CASE vt_VOID       :    A$ = "void"
        CASE vt_LONG       :    A$ = "long"
        CASE vt_DWORD      :    A$ = "ULONG"
        CASE vt_FARPROC    :    A$ = "FARPROC"
        CASE vt_PBYTE      :    A$ = "PBYTE"
        CASE vt_LRESULT    :    A$ = "LRESULT"
        CASE vt_BYTE       :    A$ = "BYTE"
        CASE vt_SHORT      :    A$ = "short"
        CASE vt_USHORT     :    A$ = "USHORT"
        CASE vt_SSHORT     :    A$ = "signed short"
        CASE vt_COLORREF   :    A$ = "COLORREF"
        CASE vt_UINT       :    A$ = "UINT"
        CASE vt_ULONG      :    A$ = "ULONG"
        CASE vt_ULONGLONG  :    A$ = "ULONGLONG"
        CASE vt_LLONG      :    A$ = "long long"
        CASE vt_HWND       :    A$ = "HWND"
        CASE vt_HANDLE     :    A$ = "HANDLE"
        CASE vt_HINSTANCE  :    A$ = "HINSTANCE"
        CASE vt_HDC        :    A$ = "HDC"
        CASE vt_SAFEARRAY  :    A$ = "SAFEARRAY"
        CASE vt_VARIANT    :    A$ = "VARIANT"
        CASE vt_WNDCLASSEX :    A$ = "WNDCLASSEX"
        CASE vt_HFONT      :    A$ = "HFONT"
        CASE vt_DOCINFO    :    A$ = "DOCINFO"
        CASE vt_LOGFONT    :    A$ = "LOGFONT"
        CASE vt_TEXTMETRIC :    A$ = "TEXTMETRIC"
        CASE vt_WINBOOL    :    A$ = "BOOL"
        CASE vt_BITMAPINFO :    A$ = "BITMAPINFO"
        CASE vt_HBITMAP    :    A$ = "HBITMAP"
        CASE vt_CY         :    A$ = "CY"
        CASE vt_DATE       :    A$ = "DATE"
        CASE vt_DECIMAL    :    A$ = "DECIMAL"
        CASE vt_IDispatch  :    A$ = "IDispatch"
        CASE vt_IUnknown   :    A$ = "IUnknown"
        CASE vt_PVOID      :    A$ = "PVOID"
        CASE vt_SCODE      :    A$ = "SCODE"
        CASE vt_WORD       :    A$ = "WORD"
        CASE vt_VARIANT_BOOL :  A$ = "VARIANT_BOOL"
        CASE ELSE          :    A$ = ""  ' Assume the programmer has a brain
    END SELECT
    FUNCTION = A$
END FUNCTION ' GetVarTypeName$





SUB LoopErrorMsg
    '***************************************************************************
    ' This subroutine constructs and displays an error message for loop errors.
    ' It handles different types of loop errors and specifies the line number
    ' where the error occurred.  If multiple loop errors are detected, it
    ' indicates that the innermost loop error is being reported.
    '****************************************************************************
    DIM RAW sError$
    IF LoopTypeCnt > 1 THEN
        sError$ = "Multiple loop errors, innermost starting at"
    ELSE
        sError$ = "Loop error starting at"
    END IF

    sError$ += STR$(LoopType[LoopTypeCnt].iLoopLine) + SPC$

    SELECT CASE LoopType[LoopTypeCnt].iLoopType

        CASE lt_DOLOOP
            sError$ += "DO without LOOP"

        CASE lt_DOWHILELOOP, lt_DOUNTILLOOP
            sError$ += "DO CONDITION without LOOP"

        CASE lt_WHILEWEND
            sError$ += "WHILE without WEND"

        CASE lt_FORNEXT
            sError$ += "FOR without NEXT"

        CASE lt_SELECT
            sError$ += "SELECT without END SELECT"

        CASE lt_FORXNEXT
            sError$ += "XFOR without XNEXT"
    END SELECT

    CALL Abort(sError$)
END SUB ' LoopErrorMsg




FUNCTION LoopTypeName$(iLoopType AS INT)
    '*******************************************
    '  Used to get loop type for Error Message
    '*******************************************
    DIM RAW sLoopType$

    SELECT CASE iLoopType
        CASE lt_DOLOOP
            sLoopType$ = "DO"

        CASE  lt_DOWHILELOOP, lt_DOUNTILLOOP
            sLoopType$ = "DO CONDITION"

        CASE lt_WHILEWEND
            sLoopType$ = "WHILE"

        CASE lt_FORNEXT
            sLoopType$ = "FOR"

        CASE lt_SELECT
            sLoopType$ = "SELECT"

        CASE lt_FORXNEXT
            sLoopType$ = "XFOR"

        CASE ELSE
            sLoopType$ = ""
    END SELECT

    FUNCTION = sLoopType$
END FUNCTION ' LoopTypeName$




SUB MakeFreeGlobals
    '********************************************************************************************
    ' This subroutine generates and injects code to free global dynamic variables.
    ' It writes SUB FreeGlobals procedure with statements to free each global dynamic variable.
    ' The loop iterates through the GlobalDynaStr$ array, decrementing the GlobalDynaCnt.
    ' Finally, it closes the procedure with an END SUB statement.
    '********************************************************************************************
    Src$ = "SUB FreeGlobals"
    PassOne = TRUE
    Inject(Src$)
    DO WHILE GlobalDynaCnt
        FPRINT FP_WRITE, SPC$, SPC$, GlobalDynaStr$[GlobalDynaCnt]
        DECR GlobalDynaCnt
    LOOP
    Src$ = "END SUB"
    PassOne = TRUE
    Inject(Src$)
END SUB ' MakeFreeGlobals




SUB ProcessSetCommand(GS)
    '*******************************************************************************
    ' This subroutine processes a "SET" command, generating the appropriate code
    ' for setting variables. It determines the context (CPP, global, or function)
    ' and handles variable declarations and initializations. The subroutine adjusts
    ' the source code by including necessary type information and handles special
    ' cases like strings. It injects the processed code into the output file and
    ' handles token substitutions and additional parsing.
    '*******************************************************************************
    DIM RAW VarCode AS UDT_VARCODE_ATTRIBUTES
    DIM RAW id
    DIM RAW ii
    DIM RAW iIsConst
    DIM RAW IsPointer
    DIM RAW iThisToken
    DIM RAW iFoundEqual
    DIM RAW SetString
    DIM RAW vt1
    DIM RAW szIsConst$
    DIM RAW LTmp$
    DIM RAW CVar$
    DIM RAW L_DimType$
    DIM RAW SaveFP  AS FILE

    VarCode.UseInLine = UseInLine
    VarCode.IsPtrFlag = 0
    SaveFP = FP_WRITE
    SetString = 0

    IF InNameSpace OR InClass THEN
        FP_WRITE = FP_UDT     ' CPP context
    ELSEIF InFunction = FALSE THEN
        FP_WRITE = FP_SET     ' Global context
    END IF

    IF iMatchNQ(Src$, "$") AND TALLY(Src$, "[") >1 THEN
        Src$ = STRIM$(Src$)
        IREMOVE "as string" FROM Src$
        IREMOVE "as char"   FROM Src$
        Src$ += " AS char"
    END IF

    Src$ += "="
    PassOne = TRUE

    CALL PreParse(Src$)
    CALL FixUps

    gszType$ = ""
    szIsConst$ = ""
    iThisToken = m_GetAsPosF(1, Ndx)

    IF iThisToken THEN
        Stk$[iThisToken++] = ""
        gszType$ = Stk$[iThisToken]
        IF m_iMatchWrd(gszType$, "const") THEN
            szIsConst$ = "const "
            Stk$[iThisToken++] = ""
            gszType$ = Stk$[iThisToken]
        END IF
        Stk$[iThisToken] = ""
    END IF

    IF ISNULL(gszType$) THEN
        gTmpStr$ = Stk$[2]
        SetString = DataType(gTmpStr$)
        VarCode.Methd% = mt_ProcessSetCommand
        VarCode.Token$ = gTmpStr$
        VarCode.VarNo% = SetString
        CALL GetVarCode(ADDRESSOF(VarCode), "set command")
        IF GS THEN
            FPRINT FP_WRITE, Scoot$, REMOVE$(VarCode.StaticOut$, "static "); ' Suppress CRLF
        ELSE
            FPRINT FP_WRITE, Scoot$, VarCode.StaticOut$; ' Suppress CRLF
        END IF

        LTmp$ = ""
        CVar$ = No_Sigil$(Stk$[2])
        CALL ValidateVarName(CVar$)
        vt1 = DataType(Stk$[2])
        CALL BuildStr(3, Ndx, LTmp$)
        IF vt1 = vt_STRVAR AND NOTNULL(LTmp$) THEN
            LTmp$ += "[BCXSTRSIZE]"
        END IF
        IF InFunction = FALSE THEN
            CALL AddGlobal(CVar$, vt1, 0, LTmp$, 0, 0, 0, 1)
        ELSE
            CALL AddLocal(CVar$, vt1, 0, LTmp$, 0, 0, 1)
        END IF
    ELSE
        CVar$ = No_Sigil$(Stk$[2])
        IF GS THEN
            FPRINT FP_WRITE, Scoot$, szIsConst$, gszType$, SPC$, CVar$;              ' Suppress CRLF
        ELSE
            FPRINT FP_WRITE, Scoot$, "static ", szIsConst$, gszType$, SPC$, CVar$;   ' Suppress CRLF
        END IF

        IF *szIsConst$ THEN
            iIsConst = 1
        ELSE
            iIsConst = 0
        END IF

        L_DimType$ = REMOVE$(gszType$, "*")
        CALL GetTypeInfo(gszType$, ADDRESSOF(IsPointer), &id, &vt1)

        IF vt1 = vt_STRVAR THEN
            L_DimType$ += "[BCXSTRSIZE]"
        END IF

        IF InFunction = FALSE THEN
            CALL AddGlobal(CVar$, vt1, id, L_DimType$, IsPointer, 0, 0, 1, iIsConst)
        ELSE
            CALL AddLocal(CVar$, vt1, id, L_DimType$, IsPointer, 0, 1, iIsConst)
        END IF
    END IF

    iThisToken = 2
    iFoundEqual = FALSE
    DO
        INCR iThisToken
        IF *Stk$[iThisToken] = ASC("=") THEN iFoundEqual = TRUE
        IF SetString = vt_STRVAR AND iFoundEqual THEN
            FPRINT FP_WRITE, "[BCXSTRSIZE]="; ' Suppress CRLF
        ELSE
            FPRINT FP_WRITE, Stk$[iThisToken]; ' Suppress CRLF
        END IF
        IF *Stk$[iThisToken] = ASC("=") THEN EXIT DO
        IF iThisToken = Ndx THEN EXIT DO
    LOOP

    FPRINT FP_WRITE, ""
    FPRINT FP_WRITE, "  {"

    DO WHILE NOT EOF(SourceFile)
        LINE INPUT SourceFile, Src$
        INCR LineNum[FileNdx]
        CALL Sanitize_Code(Src$)
        IF JoinLines(Src$) THEN ITERATE
        PassOne = TRUE
        CALL PreParse(Src$)
        PassOne = FALSE
        IF m_iMatchWrd(Src$, "endset") THEN EXIT DO
        CALL TokenSubstitutions(2)
        IF *Src$ THEN
            FPRINT FP_WRITE, SPC$; ' Suppress CRLF
            FOR ii = 1 TO Ndx
                FPRINT FP_WRITE, No_Sigil$(Stk$[ii]);   ' Suppress CRLF
            NEXT
            FPRINT FP_WRITE, ""
        END IF
    LOOP
    FPRINT FP_WRITE, "};"
    FPRINT FP_WRITE, ""
    Src$ = ""
    FP_WRITE = SaveFP
END SUB ' ProcessSetCommand



SUB EnableProject
    '*******************************************************************************************
    ' This subroutine enables a project by setting up necessary configurations and defines.
    ' It extracts the project main file name from the source code and command line arguments.
    ' The subroutine checks if the project has a path and extracts the file name and extension
    ' accordingly. It then prints a header define statement based on the project file name.
    '*******************************************************************************************
    STATIC iWasHere
    IF iWasHere THEN EXIT SUB
    DIM RAW cHFn$
    INCR iWasHere
    Project_Main$ = TRIM$(REMOVE$(MID$(Src$, 9), DQ$))
    Project_Main$ = EXTRACT$(Project_Main$, "'")     ' allow comments
    Project_Main$ = EXTRACT$(Project_Main$, ".")
    Use_Project = TRUE
    IF INCHR(COMMAND$(1), "\") THEN ' has a path
        cHFn$ = MID$(COMMAND$(1), INSTRREV(COMMAND$(1), "\", 0) + 1)
    ELSE
        cHFn$ = COMMAND$(1)
    END IF
    IF INCHR(cHFn$, ".") THEN                        ' has an extension
        cHFn$ = MID$(cHFn$, 1, INSTRREV(cHFn$, ".", 0) -1)
    END IF
    FPRINT FP_HDR, "#define __BCX_HEADER_", UCASE$(cHFn$), "__"
END SUB ' EnableProject





FUNCTION SubVarType(TokenNum)
    '*****************************************************************************************
    ' This function determines the variable type based on the given token number.
    ' It checks if the variable is local, global, or unknown and adjusts the type accordingly.
    ' The function also ensures correct suffixes ($) for strings and (%) for integers.
    '*****************************************************************************************
    DIM j = 0
    DIM iVarType = CheckLocal(Stk$[TokenNum], ADDRESSOF(j))

    IF iVarType = vt_CHAR OR iVarType = vt_SCHAR THEN
        IF *LocalVars[j].VarDim$ <> ASC("[") AND LocalVars[j].VarPntr = 0 THEN
            iVarType = vt_INTEGER
        END IF
    ELSE
        IF iVarType = vt_UNKNOWN THEN
            iVarType = CheckGlobal(Stk$[TokenNum], ADDRESSOF(j))
            IF iVarType = vt_CHAR OR iVarType = vt_SCHAR THEN
                IF *GlobalVars[j].VarDim$ <> ASC("[") AND GlobalVars[j].VarPntr = 0 THEN
                    iVarType = vt_INTEGER
                END IF
            END IF
        END IF
    END IF

    j = ASC(RIGHT$(Stk$[TokenNum], 1))

    SELECT CASE iVarType
        CASE vt_STRVAR, vt_CHAR, vt_SCHAR
            IF j <> ASC("$") THEN
                Stk$[TokenNum] += "$"
            END IF

        CASE vt_INTEGER
            IF j <> ASC("%") THEN
                Stk$[TokenNum] += "%"
            END IF

        CASE vt_SINGLE
            IF j <> ASC("!") THEN
                Stk$[TokenNum] += "!"
            END IF

        CASE vt_DOUBLE
            IF j <> ASC("#") THEN
                Stk$[TokenNum] += "#"
            END IF

        CASE vt_LDOUBLE
            IF j <> ASC("`") THEN
                Stk$[TokenNum] += "`"
            END IF
    END SELECT

    FUNCTION = iVarType
END FUNCTION ' SubVarType



FUNCTION PrintWriteFormat$ (DoWrite)
    '*********************************************************************************
    ' This function generates a printf format string and argument list for PRINT and
    ' WRITE statements based on the function argument. It analyses Stk$[] and builds
    ' the format string and argument list for the resulting printf statement.
    '*********************************************************************************
    DIM RAW Arg$
    DIM RAW Argcount
    DIM RAW Frmat$
    DIM RAW iThisToken
    DIM RAW iVarType
    DIM RAW LZZ$
    DIM RAW SuppressCRLF
    DIM RAW NextArgcount
    DIM RAW PWF_Cast$
    DIM RAW Tmp$
    DIM RAW Stak[128] AS UDT_ARG_TYPE
    DIM RAW x
    DIM Testing$
    DIM Dot

    SuppressCRLF =  FALSE
    NextArgcount =  1
    Argcount     =  0
    Frmat$       =  ""
    Arg$         =  ""
    LZZ$         =  ""

    IF Stk$[Ndx] = ";" THEN
        SuppressCRLF = TRUE
        DECR Ndx
    END IF

    IF Ndx = 1 THEN GOTO PrintWriteLabel

    Stak[1].ArgType = (-1)
    iThisToken = 2

    '***********************************************************
    FOR i AS INT = 1 TO Ndx
        IF Stk$[i] = "(int)strlen" THEN Stk$[i] =  "strlen"
    NEXT
    '***********************************************************
    FOR i AS INT = 2 TO Ndx
        IF Im_UDT_String (Stk$[i]) THEN Stk$[i] += "$"
        IF Im_UDT_Single (Stk$[i]) THEN Stk$[i] += "!"
        IF Im_UDT_Double (Stk$[i]) THEN Stk$[i] += "#"
    NEXT
    '***********************************************************
    FOR i AS INT = 2 TO Ndx
        x = CheckType (Stk$[i])

        SELECT CASE x
            CASE vt_STRVAR, vt_PCHAR, vt_CHARPTR
                Stk$[i] += "$"

            CASE vt_SINGLE
                Stk$[i] += "!"

            CASE vt_DOUBLE
                Stk$[i] += "#"

            CASE vt_LDOUBLE
                Stk$[i] += "`"
        END SELECT

    NEXT
    '***********************************************************
    FOR i AS INT = 2 TO Ndx
        Testing$ = SPC$ + No_Sigil$(Stk$[i]) + "$" + SPC$
        Dot = iMatchNQ (Stk$[i], ".")
        IF Dot THEN Testing$ = SPC$ + MID$(Testing$, Dot + 2)
        IF INSTR (FuncStrNames$, Testing$) THEN  ' Look for STRINGS
            IF NOT iMatchNQ(Stk$[i], "$") THEN Stk$[i] += "$"
        END IF
    NEXT

    FOR i AS INT = 2 TO Ndx
        Testing$ = SPC$ + No_Sigil$(Stk$[i]) + "!" + SPC$
        Dot = iMatchNQ (Stk$[i], ".")
        IF Dot THEN Testing$ = SPC$ + MID$(Testing$, Dot + 2)
        IF INSTR (FuncSglNames$, Testing$) THEN  ' Look for SINGLES
            IF NOT iMatchNQ(Stk$[i], "!") THEN  Stk$[i] += "!"
        END IF
    NEXT

    FOR i AS INT = 2 TO Ndx
        Testing$ = SPC$ + No_Sigil$(Stk$[i]) + "#" + SPC$
        Dot = iMatchNQ (Stk$[i], ".")
        IF Dot THEN Testing$ = SPC$ + MID$(Testing$, Dot + 2)
        IF INSTR (FuncDblNames$, Testing$) THEN  ' Look for DOUBLES
            IF NOT iMatchNQ(Stk$[i], "#") THEN  Stk$[i] += "#"
        END IF
    NEXT

    '*********************************************************************************
    '                               End of Transforms
    '*********************************************************************************

    DO WHILE iThisToken <= Ndx
        Tmp$ = No_Sigil$(Stk$[iThisToken])
        IF Tmp$ <> "BCX_DynaCallA" AND Tmp$ <> "BCX_DynaCallB" THEN
            iVarType = SubVarType(iThisToken)
            IF Stak[NextArgcount].ArgType = (-1) THEN

                SELECT CASE iVarType
                    CASE vt_CHAR, vt_SCHAR, vt_STRVAR, vt_INTEGER, vt_SINGLE, vt_DOUBLE, vt_LDOUBLE
                        Stak[NextArgcount].ArgType = iVarType
                END SELECT

            END IF

            IF *Stk$[iThisToken] = ASC("(") THEN
                DIM iCnt = 0
                DO
                    IF *Stk$[iThisToken] = ASC("(") THEN INCR iCnt
                    IF *Stk$[iThisToken] = ASC(")") THEN DECR iCnt
                    Arg$ += Stk$[iThisToken]
                    INCR iThisToken
                LOOP UNTIL iCnt <= 0 OR iThisToken >= Ndx
            END IF

            IF *Stk$[iThisToken] = ASC("[") THEN
                DIM iCnt = 0
                DO
                    IF *Stk$[iThisToken] = ASC("[") THEN INCR iCnt
                    IF *Stk$[iThisToken] = ASC("]") THEN DECR iCnt
                    Arg$ += Stk$[iThisToken]
                    INCR iThisToken
                    IF *Stk$[iThisToken] = ASC("[") AND iCnt = 0 THEN ITERATE
                LOOP UNTIL iCnt <= 0 OR iThisToken >= Ndx
            END IF

            IF *Stk$[iThisToken] = ASC(";")    _
                OR *Stk$[iThisToken] = ASC(",") _
                OR *Stk$[iThisToken] = ASC("&") THEN
                INCR Argcount
                INCR NextArgcount
                Stak[Argcount].Arg$ = Arg$
                Stak[NextArgcount].ArgType = (-1)
                Arg$ = ""
                INCR iThisToken
            ELSE
                Arg$ += Stk$[iThisToken]
                INCR iThisToken
            END IF
        ELSE
            Arg$ += Stk$[iThisToken]
            INCR iThisToken
        END IF
    LOOP

    INCR Argcount
    INCR NextArgcount
    Stak[Argcount].Arg$ = Arg$
    Arg$ = ""

    FOR iThisToken = 1 TO Argcount

        iVarType = Stak[iThisToken].ArgType
        IF iVarType = (-1) THEN
            LZZ$ = EXTRACT$ (Stak[iThisToken].Arg$, "(")
            iVarType = DataType(LZZ$)
        END IF

        IF iVarType = vt_INTEGER THEN
            ' 837 - This IF block was updated by MrBcx for improved type detection.
            ' For dotted access (struct member, possibly nested), the per-member
            ' type can't be derived from looking up the leading variable's type;
            ' that would return the struct's type, not the member's type. Skip
            ' the override and trust DataType's INT default, which aligns
            ' with the BCX rule that unparsed UDT members default to integer.

            IF iMatchNQ(LZZ$, ".") = 0 THEN
                DIM indx
                DIM A = CheckLocal (LZZ$, ADDRESSOF(indx))

                IF A = vt_UNKNOWN THEN
                    A = CheckGlobal (LZZ$, ADDRESSOF(indx))
                    IF A <> vt_UNKNOWN THEN
                        iVarType = GlobalVars[indx].VarType
                    END IF
                ELSE
                    iVarType = LocalVars[indx].VarType
                END IF
            END IF
        END IF    ' 837 -- End of change


        SELECT CASE iVarType
            CASE vt_STRLIT, vt_STRVAR, vt_CHAR, vt_SCHAR
                IF DoWrite THEN
                    Frmat$ += "\\" + DQ$ + "%s" + "\\" + DQ$ + ","
                ELSE
                    Frmat$ += "%s"
                END IF
                IF LEFTSTR(LZZ$, "BCX_DynaCall") THEN
                    Arg$ += ",(char*)" + Stak[iThisToken].Arg$
                ELSE
                    Arg$ += "," + Stak[iThisToken].Arg$
                END IF

                '**********************************************************************
            CASE vt_DOUBLE, vt_NUMBER, vt_DECFUNC     ' 838 MrBcx revised this block
                IF DoWrite THEN
                    Frmat$ += "%s,"
                    Arg$ += ",BCX_Format_Double((double)" + Stak[iThisToken].Arg$ + ",0)"
                ELSE
                    Frmat$ += "%s"
                    Arg$ += ",BCX_Format_Double((double)" + Stak[iThisToken].Arg$ + ",1)"
                END IF
                Use_Str = Use_BcxTempStr = TRUE       ' 838 MrBcx New
                '**********************************************************************

            CASE  vt_INTEGER                          ' MrBcx 832  moved to its own: vt_INTEGER
                IF DoWrite THEN
                    Frmat$ += "%d ,"
                ELSE
                    Frmat$ += " %d "
                END IF
                Arg$ += ",(int)" + Stak[iThisToken].Arg$

            CASE vt_LLONG
                IF DoWrite THEN
                    Frmat$ += "%lli,"
                ELSE
                    Frmat$ += "% lli"
                END IF
                Arg$ += ",(long long)" + Stak[iThisToken].Arg$

            CASE vt_ULONGLONG
                IF DoWrite THEN
                    Frmat$ += "%llu,"
                ELSE
                    Frmat$ += "% llu"
                END IF
                Arg$ += ",(unsigned long long)" + Stak[iThisToken].Arg$


            CASE vt_SINGLE
                IF DoWrite THEN
                    Frmat$ += "%.7G,"
                ELSE
                    Frmat$ += "% .7G"
                END IF
                Arg$ += ",(float)" + Stak[iThisToken].Arg$

            CASE vt_LDOUBLE
                IF DoWrite THEN
                    Frmat$ += "%.19LG,"
                ELSE
                    Frmat$ += "% .19LG"
                END IF
                Use_Ldouble = TRUE
                Arg$ += ",(LDOUBLE)" + Stak[iThisToken].Arg$

            CASE vt_BOOL                       ' Added by MrBcx in 832
                IF DoWrite THEN
                    Frmat$ += "%d,"
                ELSE
                    Frmat$ += "% d"
                END IF
                Arg$ += "," + Stak[iThisToken].Arg$

            CASE ELSE
                IF ASC(Stak[iThisToken].Arg$) = ASC("(") THEN

                    '************************************************************
                    ' MrBcx 837: Added new guard
                    ' Detect BYREF-deref member access:  (*ptr).member
                    ' BCX rewrites BYREF-parameter references as (*name).member.
                    ' Without this short-circuit, (*name) is not a recognized C
                    ' cast and the code below would prepend (double), producing
                    ' a "% .15G" format string for UDT members that should be
                    ' treated as integers. Since BCX does not parse Win32 header
                    ' UDTs, member types are unknown -- default to integer. The
                    ' user can override per-token by appending a type sigil.
                    '************************************************************
                    IF m_iMatchLft(Stak[iThisToken].Arg$, "(*") AND _
                        INSTR(Stak[iThisToken].Arg$, ").") THEN
                        IF DoWrite THEN
                            Frmat$ += "%d ,"
                        ELSE
                            Frmat$ += " %d "
                        END IF
                        Arg$ += ",(int)" + Stak[iThisToken].Arg$
                        ITERATE
                    END IF
                    '************************************************************
                    ' 837 - end of new guard
                    '************************************************************

                    LZZ$ = ""
                    Arg$ += ","

                    DO
                        DIM iParentheses = INCHR(Stak[iThisToken].Arg$, ")")
                        PWF_Cast$ = MID$(Stak[iThisToken].Arg$, 1, iParentheses++)
                        Stak[iThisToken].Arg$ = TRIM$(MID$(Stak[iThisToken].Arg$, iParentheses))

                        IREPLACE "char*"      WITH  "char *"             IN PWF_Cast$
                        IREPLACE "integer"    WITH  "int"                IN PWF_Cast$
                        IREPLACE "ldouble"    WITH  "LDOUBLE"            IN PWF_Cast$
                        IREPLACE "llong"      WITH  "long long"          IN PWF_Cast$
                        IREPLACE "long long"  WITH  "long long"          IN PWF_Cast$
                        IREPLACE "longlong"   WITH  "long long"          IN PWF_Cast$
                        IREPLACE "lpstr"      WITH  "char *"             IN PWF_Cast$
                        IREPLACE "single"     WITH  "float"              IN PWF_Cast$
                        IREPLACE "ulonglong"  WITH  "unsigned long long" IN PWF_Cast$

                        IF ISNULL(LZZ$) THEN
                            IF iMatchNQ("(char *)(int)(float)(double)(LDOUBLE)(long long)(unsigned long long)", PWF_Cast$) THEN
                                LZZ$ = PWF_Cast$
                            ELSE
                                LZZ$ = "(double)"
                                PWF_Cast$ = LZZ$ + PWF_Cast$
                            END IF
                            RemoveAll(LZZ$, "()")
                            IREPLACE "char *"             WITH "%s"       IN  LZZ$
                            IREPLACE "double"             WITH "% .15G "  IN  LZZ$
                            IREPLACE "float"              WITH "% .7G "   IN  LZZ$
                            IREPLACE "int"                WITH "% d "     IN  LZZ$
                            IREPLACE "ldouble"            WITH "% .19LG " IN  LZZ$
                            IREPLACE "long long"          WITH "% lli "   IN  LZZ$
                            IREPLACE "unsigned long long" WITH "% llu "   IN  LZZ$
                        END IF

                        Arg$ += PWF_Cast$
                    LOOP WHILE ASC(Stak[iThisToken].Arg$) = c_LPar

                    Arg$ += Stak[iThisToken].Arg$
                    Frmat$ += LZZ$

                    IF DoWrite THEN Frmat$ += ","
                ELSE
                    IF DoWrite THEN
                        Frmat$ += "%G,"
                    ELSE
                        Frmat$ += "% G"
                        Arg$ += ",(float)" + Stak[iThisToken].Arg$
                    END IF
                END IF

        END SELECT
    NEXT

    IF DoWrite THEN Frmat$ = LEFT$(Frmat$, LEN(Frmat$)-1)

    '*********************
    PrintWriteLabel:
    '*********************

    IF SuppressCRLF = FALSE THEN
        Frmat$ += "\\n"
    END IF
    FUNCTION = "printf(" + ENC$(Frmat$) + No_Sigil$(Arg$) + ");"
END FUNCTION ' PrintWriteFormat$





SUB InputBufferFlags
    '*********************************************************************
    ' Called by
    '   "finput" - Emit_FileInputCode - InputBufferFlags
    '   "input"  - Emit_InputCode     - CommonInputCode  - InputBufferFlags
    '*********************************************************************
    IF NOT Use_Inputbuffer THEN
        Use_Inputbuffer = TRUE
        Use_BcxTempStr  = TRUE
        Use_Scan        = TRUE
        Use_Proto       = TRUE
        Use_Split       = TRUE
        Use_Replace     = TRUE
        Use_Remove      = TRUE
        Use_Mid         = TRUE
        Use_Left        = TRUE
        Use_Instr       = TRUE
        Use_Stristr     = TRUE
        Use_UCaseTbl    = TRUE
    END IF
END SUB ' InputBufferFlags




SUB CommonInputCode (Frmat$, Arg$)
    '**************************************************************************************
    ' This SUB generates code for common input operations based on the provided arguments.
    ' It constructs the format string and argument list for input operations such as scanf.
    ' The subroutine handles various data types and formats them appropriately for input.
    '**************************************************************************************
    DIM RAW Argcount = 0
    DIM RAW iThisToken
    DIM RAW iVarType
    DIM RAW szParamToken$
    DIM RAW Stak$[128]  : CLEAR(Stak$)  ' Silence Gcc/Clang missing-braces warning

    CALL InputBufferFlags

    Arg$   = ""
    Frmat$ = ""
    iThisToken = 1

    DO WHILE iThisToken <= Ndx
        IF Stk$[iThisToken] = "," THEN
            INCR Argcount
            Stak$[Argcount]= Arg$
            Arg$ = ""
            INCR iThisToken
        ELSE
            Arg$ += Stk$[iThisToken]
            INCR iThisToken
            IF iThisToken < Ndx THEN
                DIM iCnt = TALLY(Arg$, "[") - TALLY(Arg$, "]")
                DO WHILE iCnt
                    Arg$ += Stk$[iThisToken]
                    INCR iThisToken
                    iCnt = TALLY(Arg$, "[") - TALLY(Arg$, "]")
                LOOP
            END IF
        END IF
    LOOP

    INCR Argcount
    Stak$[Argcount] = Arg$
    Arg$ = ""

    FPRINT FP_WRITE, Scoot$; ' Suppress CRLF

    FOR iThisToken = 1 TO Argcount
        szParamToken$ = Stak$[iThisToken]
        iVarType = CheckType(szParamToken$)

        IF iVarType = vt_UDT OR iVarType = vt_STRUCT OR iVarType = vt_UNION THEN
            iVarType = DataType(szParamToken$)
        ELSE
            DIM iCnt = INCHR(szParamToken$, "[")
            IF iCnt THEN *(--iCnt+szParamToken) = 0
            iVarType = DataType(szParamToken$)
        END IF

        szParamToken$ = No_Sigil$(Stak$[iThisToken])

        IF Im_UDT_String(szParamToken$) THEN iVarType = vt_STRVAR
        IF Im_UDT_Single(szParamToken$) THEN iVarType = vt_SINGLE
        IF Im_UDT_Double(szParamToken$) THEN iVarType = vt_DOUBLE

        DIM RAW x
        FOR i AS INT = 2 TO Ndx
            x = CheckType (szParamToken$)
            SELECT CASE x
                CASE vt_STRVAR  : iVarType = vt_STRVAR
                CASE vt_PCHAR   : iVarType = vt_STRVAR
                CASE vt_PSTR    : iVarType = vt_STRVAR
                CASE vt_CHARPTR : iVarType = vt_STRVAR
                CASE vt_SINGLE  : iVarType = vt_SINGLE
                CASE vt_DOUBLE  : iVarType = vt_DOUBLE
                CASE vt_LDOUBLE : iVarType = vt_LDOUBLE
            END SELECT
        NEXT


        SELECT CASE iVarType
            CASE vt_STRVAR
                Frmat$ += "%s"
                Arg$ += "," + szParamToken$
                FPRINT FP_WRITE, "*", TRIM$(szParamToken$), "=0, "; ' Suppress CRLF

            CASE vt_INTEGER
                Frmat$ += "%d"
                Arg$ += ",&" + szParamToken$
                FPRINT FP_WRITE, szParamToken$, "=0, "; ' Suppress CRLF

            CASE vt_SINGLE
                Frmat$ += "%g"
                Arg$ += ",&" + szParamToken$
                FPRINT FP_WRITE, szParamToken$, "=0, "; ' Suppress CRLF

            CASE vt_DOUBLE
                Frmat$ += "%lG"
                Arg$ += ",&" + szParamToken$
                FPRINT FP_WRITE, szParamToken$, "=0, "; ' Suppress CRLF

            CASE vt_LDOUBLE
                Frmat$ += "%lG"
                Arg$ += ",&" + szParamToken$
                FPRINT FP_WRITE, szParamToken$, "=0, "; ' Suppress CRLF

            CASE ELSE
                Frmat$ += "%d"
                Arg$ += ",&" + szParamToken$
                FPRINT FP_WRITE, szParamToken$, "=0, "; ' Suppress CRLF
        END SELECT

    NEXT
END SUB ' CommonInputCode



SUB FinishingTouches
    IF Use_Project = FALSE THEN
        DIM  Accum= Use_BCXMDialog
        INCR Accum, Use_BCXDialog
        INCR Accum, Use_BCX_Control
        INCR Accum, Use_BCX_FrameWnd
        INCR Accum, Use_BCX_InitGUI
        INCR Accum, Use_BCX_Input
        INCR Accum, Use_BCX_OlePicture
        INCR Accum, Use_BCX_RegWnd
        INCR Accum, Use_BCX_SetCursor
        INCR Accum, Use_BCX_SetIcon
        INCR Accum, Use_BCX_SetIconSm
        INCR Accum, Use_BCX_Slider
        INCR Accum, Use_BCX_Splitter
        INCR Accum, Use_BCX_Tab
        INCR Accum, Use_BCX_Toolbar
        INCR Accum, Use_BCX_UpDown
        INCR Accum, Use_BCX_Wnd
        INCR Accum, Use_Bitmap
        INCR Accum, Use_Blackrect
        INCR Accum, Use_BmpButton
        INCR Accum, Use_Button
        INCR Accum, Use_Checkbox
        INCR Accum, Use_Combobox
        INCR Accum, Use_Datepick
        INCR Accum, Use_Edit
        INCR Accum, Use_Form
        INCR Accum, Use_Grayrect
        INCR Accum, Use_Group
        INCR Accum, Use_Icon
        INCR Accum, Use_Label
        INCR Accum, Use_Listbox
        INCR Accum, Use_Listview
        INCR Accum, Use_ProgressBar
        INCR Accum, Use_Radio
        INCR Accum, Use_Richedit
        INCR Accum, Use_Set_BCX_Icon
        INCR Accum, Use_Treeview
        INCR Accum, Use_Whiterect
        IF Accum THEN
            CALL AddBCX_hInstance
            CALL AddFontVariables
        END IF
    END IF
END SUB ' FinishingTouches




SUB AssembleParts
    '**********************************************************************************************
    ' This SUB assembles various parts of the processed code into a single file. It processes the
    ' C/C++ prolog, command-line defines, constants, directives, UDTs, and global variables.  It
    ' It includes any user C/C++ code, translated SUBS and FUNCTIONS, and main program output.
    ' It performs the necessary file operations and writes the assembled code to the output file.
    '**********************************************************************************************
    DIM LTmp1$, P1$, P2$, P3$, P4$, P5$, P6$, P7$, P8$

    DoCountLines = TRUE

    CALL FinishingTouches

    IF EXIST("$WRK$.TXT") THEN KILL "$WRK$.TXT"
    RENAME FileOut$, "$WRK$.TXT"

    IF ISNULL(CmdLineFileOut$) THEN
        IF UseCpp THEN
            gTmpStr$ = EXTRACT$(FileOut$, ".") + ".cpp"
            KILL gTmpStr$
            FileOut$ = gTmpStr$
        ELSE
            gTmpStr$ = EXTRACT$(FileOut$, ".") + ".c"
            KILL gTmpStr$
            FileOut$ = gTmpStr$
        END IF
    END IF

    OPEN FileOut$ FOR OUTPUT AS FP_W
    CALL Emit_Prolog(FP_W)
    CALL Commandline_Defines(FP_W)
    CALL System_Defined_Constants(FP_W)
    CALL User_Defined_Constants(FP_W)
    CALL Emit_UserDirectives(FP_W)
    CALL User_Global_Enum_Blocks(FP_W)

    IF Use_Project = FALSE THEN
        IF Use_SingleFile = FALSE THEN
            OPEN HFile$ FOR OUTPUT AS FP_HeaderFile
        END IF
    END IF

    '*********************************************************************************************
    CALL StdProtos(FP_W)                       ' MrBcx  - I swapped the order to enable the
    CALL User_Defined_Types_And_Unions(FP_W)   ' use of BASIC runtime library inside a C++ CLASS.
    '*********************************************************************************************

    CALL Emit_System_Vars(FP_W)

    IF Use_COM THEN
        Emit_COM_SupportTypes(FP_W)
    END IF

    CALL User_Global_Variables(FP_W)
    CALL User_Data_Statements(FP_W)
    CALL AddMacros(FP_W)
    CALL User_Prototypes(FP_W)
    CALL User_Global_Initialized_Arrays(FP_W)
    CALL User_Overloaded_SubsFunctions(FP_W)
    CALL User_Global_Set_Statements(FP_W)

    IF Use_SingleFile = FALSE THEN
        CLOSE FP_HeaderFile
    END IF

    IF Use_SingleFile = TRUE AND Use_Project = FALSE THEN
        CALL Emit_RuntimeFunctions(FP_W)
    ELSE
        IF Use_Project = FALSE THEN
            CALL SetFlags      ' Write to Project$
        END IF
    END IF

    '***************************************************************
    DIM bMain = (Use_Wingui + MakeDLL + NoMain) AS BOOL
    DIM bMainOut AS BOOL = FALSE
    '***************************************************************

    IF LOF(cppFile$) THEN
        FPRINT FP_W, ""
        FPRINT FP_W, "// *************************************************"
        FPRINT FP_W, "//                   User's C code"
        FPRINT FP_W, "// *************************************************"
        FPRINT FP_W, ""

        OPEN cppFile$ FOR INPUT AS FP_R

        DO WHILE NOT EOF(FP_R)
            LINE INPUT FP_R, LTmp1$
            FPRINT FP_W, LTmp1$
        LOOP

        CLOSE FP_R
    END IF


    IF EXIST(prcFile$) AND LOF(prcFile$)>2 THEN
        FPRINT FP_W, "// *************************************************"
        FPRINT FP_W, "//            User's Subs and Functions"
        FPRINT FP_W, "// *************************************************"
        FPRINT FP_W, ""

        '***************************************************
        IF UseCpp THEN
            P1$ = CHR$(99, 111, 117, 116, 60, 60)                   '   "cout<<"
            P2$ = CHR$(99, 111, 117, 116, 32, 60, 60, 32)           '   "cout << "
            P3$ = CHR$(99, 105, 110, 60, 60)                        '   "cin<<"
            P4$ = CHR$(99, 105, 110, 32, 60, 60, 32)                '   "cin << "
            P5$ = CHR$(60, 60, 115, 116, 100, 58, 58)               '   "<<std::"
            P6$ = CHR$(32, 60, 60, 32, 115, 116, 100, 58, 58)       '   " << std::"
            P7$ = CHR$(60, 60, 101, 110, 100, 108)                  '   "<<endl"
            P8$ = CHR$(32, 60, 60, 32, 101, 110, 100, 108)          '   " << endl"
        END IF
        '***************************************************

        OPEN prcFile$ FOR INPUT AS FP_R       ' translated subs and functions

        DO WHILE NOT EOF(FP_R)
            LINE INPUT FP_R, LTmp1$
            '***************************************************
            ' Simple patch to support Unicode Lexer (ULEX.exe)
            '***************************************************
            IF UseCpp THEN
                REPLACE P1$ WITH P2$ IN LTmp1$
                REPLACE P3$ WITH P4$ IN LTmp1$
                REPLACE P5$ WITH P6$ IN LTmp1$
                REPLACE P7$ WITH P8$ IN LTmp1$
            END IF
            '***************************************************
            FPRINT FP_W, LTmp1$
            IF bMainOut THEN ITERATE
            bMainOut = CheckForMain(LTmp1$, bMain)
        LOOP
        CLOSE FP_R
    END IF

    IF Use_Wingui = FALSE AND NoMain = FALSE THEN
        FPRINT FP_W, ""
        FPRINT FP_W, "// *************************************************"
        FPRINT FP_W, "//                  ", c_$BCX_STR_MAIN_PROG
        FPRINT FP_W, "// *************************************************"
        FPRINT FP_W, ""
    END IF

    OPEN "$WRK$.TXT" FOR INPUT AS FP_R

    DO WHILE NOT EOF(FP_R)
        LINE INPUT FP_R, LTmp1$
        IF iMatchNQ (LTmp1$, "int main") THEN
            IF bMain THEN
                ITERATE
            END IF
        END IF
        FPRINT FP_W, Scoot$, LTmp1$
        IF bMainOut THEN ITERATE
        bMainOut = CheckForMain(LTmp1$, bMain)
    LOOP

    CLOSE FP_R
    KILL "$WRK$.TXT"

    CLOSE FP_W
    DoCountLines = FALSE
END SUB ' AssembleParts




FUNCTION CheckForMain (ArgStr$, bMain AS BOOL)
    '***********************************************************************************
    ' This function checks if ArgStr$ contains the keyword "main" and performs specific
    ' actions if it does. It handles these cases:
    '
    '      int main ...
    '      int WINAPI WinMain  ...
    '      __declspec(dllexport) BOOL WINAPI DllMain  ...
    '      __stdcall*DllMain*(HINSTANCE *,* ...
    '
    ' Depending on the context, it emits certain code related to console handling,
    ' startup and exit code, case tables, DLL declarations, etc.  The function returns
    ' a boolean value indicating whether the main program output has been handled.
    '***********************************************************************************
    DIM bMainOut = FALSE
    DIM LTmp1$
    DIM LZZ$

    IF iMatchNQ (ArgStr$, "main") THEN
        LZZ$ = LTRIM$(ArgStr$)
        Scoot$ = SPACE$(2)

        IF LEFTSTR(LZZ$, "int main") _
            OR LEFTSTR(LZZ$, "int WINAPI WinMain") _
            OR LEFTSTR(LZZ$, "__declspec(dllexport) BOOL WINAPI DllMain") _
            OR LIKE (LZZ$, "*__stdcall*DllMain*(HINSTANCE *,*") THEN

            IF bMain = FALSE THEN
                FPRINT FP_W, "{"        ' OPEN the main FUNCTION
            END IF

            IF bMain THEN
                LINE INPUT FP_R, LTmp1$
                FPRINT FP_W, LTmp1$
            END IF

            IF Use_Console THEN
                FPRINT FP_W, Scoot$, "hConsole=GetStdHandle(STD_OUTPUT_HANDLE);"
            END IF

            IF Use_StartupCode THEN
                FPRINT FP_W, Scoot$, "int BCX_SUCode=BCX_StartupCode_();  // execute user's startup code"
            END IF

            IF Use_ExitCode THEN
                FPRINT FP_W, Scoot$, "int BCX_EXCode=BCX_ExitCode_();     // Prepare for user's exit code"
            END IF

            IF Use_LCaseTbl THEN
                FPRINT FP_W, Scoot$, "LowCase = MakeLCaseTbl();"          ' 828 MrBcx changed - calloc was unnecessary
            END IF

            IF Use_UCaseTbl THEN
                FPRINT FP_W, Scoot$, "UprCase = MakeUCaseTbl();"          ' 828 MrBcx changed - calloc was unnecessary
            END IF

            IF DllCnt THEN
                LOCAL szLoadLibHandle$
                LOCAL LTmp$
                LOCAL i

                FPRINT FP_W, Scoot$, ""
                FPRINT FP_W, Scoot$, "// **********[ DLL Declarations ]**********"
                FPRINT FP_W, Scoot$, ""

                ' ------------------------------------------------------------------------
                ' Emit LoadLibrary assignments
                ' HMODULE  H_DLLNAME = LoadLibrary("DLLNAME.DLL");
                ' Todo: Add a check for H_DLLNAME = NULL in case of failure to load the DLL.
                ' ------------------------------------------------------------------------

                IF Use_LoadLibraryError THEN
                    FPRINT FP_W, Scoot$, "FILE   *FPLoadLibraryErrorLog;"
                    DIM Op$ = ENC$("w")
                    IF UseFileTest THEN
                        FPRINT FP_W, Scoot$, "if((FPLoadLibraryErrorLog=fopen(", LibraryErrorLog$, ", ", Op$, "))==0)"
                        FPRINT FP_W, Scoot$, " {"
                        LTmp$ = ENC$("Error: Cannot Access File or File Not Found. %s\\n")
                        FPRINT FP_W, Scoot$, "fprintf(stderr, ", LTmp$, ", ", LibraryErrorLog$, "); exit(1);"
                        FPRINT FP_W, Scoot$, " }"
                    ELSE
                        FPRINT FP_W, Scoot$, "FPLoadLibraryErrorLog = fopen(", ENC$(LibraryErrorLog$), ", ", Op$, ");"
                    END IF
                END IF

                LTmp$ = ENC$("[%s %s] Failed to load %s\\n")

                FOR i = 1 TO LoadLibsCnt
                    szLoadLibHandle$ = "H_" + UCASE$(RemoveExtension$(Loadlibs$[i]))

                    IF (INCHR(szLoadLibHandle$, "-")) OR (INCHR(szLoadLibHandle$, ".")) THEN
                        szLoadLibHandle$ = REPLACE$(szLoadLibHandle$, "-.", "_")
                        szLoadLibHandle$ = REPLACE$(szLoadLibHandle$, "-", "_")
                    END IF

                    FPRINT FP_W, Scoot$, "HMODULE  ", szLoadLibHandle$, " = LoadLibrary(", ENC$(Loadlibs$[i]), ");"

                    IF Use_LoadLibraryError THEN
                        FPRINT FP_W, Scoot$, "if(", szLoadLibHandle$, "==NULL) {"
                        FPRINT FP_W, Scoot$, "  fprintf(FPLoadLibraryErrorLog, ", LTmp$, ", date(), timef(0,0), ", ENC$(Loadlibs$[i]), ");"
                        FPRINT FP_W, Scoot$, "  }"
                    END IF
                NEXT

                LTmp$ = ENC$("[%s %s] Failed to find process %s\\n")

                FOR i = 1 TO DllCnt
                    FPRINT FP_W, Scoot$, DllDecl$[i]    ' Emit the user's DLL Declarations
                    IF Use_LoadLibraryError THEN
                        DIM iEQ = INCHR(DllDecl$[i], "=")-1
                        DIM szProcAddress$ = LEFT$(DllDecl$[i], iEQ)
                        FPRINT FP_W, Scoot$, "if(", szProcAddress$, "==NULL) {"
                        FPRINT FP_W, Scoot$, "  fprintf(FPLoadLibraryErrorLog, ", LTmp$, ",date(),timef(0,0),", ENC$(szProcAddress$), ");"
                        FPRINT FP_W, Scoot$, "  }"
                    END IF
                NEXT

                IF Use_LoadLibraryError THEN
                    FPRINT FP_W, Scoot$, "fclose(FPLoadLibraryErrorLog);"
                END IF

                FPRINT FP_W, Scoot$, ""
                FPRINT FP_W, Scoot$, "// ****************************************"
                FPRINT FP_W, Scoot$, ""
            END IF
            bMainOut = TRUE
        END IF
    END IF
    FUNCTION = bMainOut
END FUNCTION  ' CheckForMain



FUNCTION RemoveExtension(f AS STRING) AS STRING
    '****************************************************************************
    ' This function removes the file extension from a given filename string.
    ' It searches for the last occurrence of the dot (".") character and returns
    ' the substring of the filename before that dot.
    ' If no dot is found, it returns the original filename.
    '****************************************************************************
    DIM RAW i AS INT
    DIM dotPosition = INCHR(f$, ".")
    IF dotPosition THEN
        i = INSTRREV(f$, ".", 0) - 1
    ELSE
        i = LEN(f$)
    END IF
    FUNCTION = LEFT$(f$, i)
END FUNCTION ' RemoveExtension



FUNCTION CheckGlobal(szVariable$, BYREF varidx)
    '************************************************************************
    ' This function checks if a global variable exists and returns its type.
    '************************************************************************
    DIM RAW iHasValue AS ULONGLONG
    DIM RAW iTokenLoc
    DIM RAW szTemp$
    DIM RAW iBrack

    szTemp$ = szVariable$
    RemoveAll(szTemp$, "%$#!@`&*( )", 1)
    iBrack = INCHR(szTemp$, "[")
    IF iBrack THEN *(--iBrack + szTemp) = 0  ' This RTRIMS szTemp at the first "["
    iHasValue = HashNumber(szTemp$)
    DO WHILE GlobalVarHash[iHasValue]
        iTokenLoc = GlobalVarHash[iHasValue]
        IF szTemp$ = GlobalVars[iTokenLoc].VarName$ THEN
            varidx = iTokenLoc
            FUNCTION = GlobalVars[iTokenLoc].VarType
        END IF
        INCR iHasValue
        iHasValue = IMOD(iHasValue, c_MaxGlobalVars)
    LOOP
    FUNCTION = vt_UNKNOWN
END FUNCTION ' CheckGlobal



FUNCTION CheckLocal(szVariable$, BYREF varidx)
    '***********************************************************************
    ' This function checks if a local variable exists and returns its type.
    '***********************************************************************
    DIM RAW szTemp$
    DIM RAW iBrack
    DIM RAW iTokenLoc

    IF LocalVarCnt THEN
        szTemp$ = szVariable$
        RemoveAll(szTemp$, "%$#!@`&*( )", 1)
        iBrack = INCHR(szTemp$, "[")
        IF iBrack THEN *(--iBrack + szTemp) = 0 ' This RTRIMS szTemp at the first "["
        FOR iTokenLoc = LocalVarCnt TO 1 STEP -1
            IF szTemp$ = LocalVars[iTokenLoc].VarName$ THEN
                varidx = iTokenLoc
                FUNCTION = LocalVars[iTokenLoc].VarType
            END IF
        NEXT
    END IF
    FUNCTION = vt_UNKNOWN
END FUNCTION ' CheckLocal



FUNCTION CheckType(ParamStr$)
    '******************************************************
    ' This function checks the type of its string argument.
    '******************************************************
    DIM varid
    DIM Keyword$ = TRIM$(LCASE$(ParamStr$))
    DIM i = FindWord (Keyword$, tTypes, m_WordsInTable(tTypes))
    IF i <> c_NOTFOUND THEN FUNCTION = tTypes[i].iType
    i = CheckLocal(ParamStr$, ADDRESSOF(varid))
    IF i = vt_UNKNOWN THEN
        i = CheckGlobal(ParamStr$, ADDRESSOF(varid))
        IF i = vt_UNKNOWN THEN
            i = CheckTypeDefs(ParamStr$)
            IF i THEN i = TypeDefs[i].TypeofDef
        END IF
    END IF
    FUNCTION = i
END FUNCTION ' CheckType



SUB ExportStringConst
    DIM RAW FP_SAVE AS FILE
    FP_SAVE = FP_CST
    FP_CST  = FP_SYSCST
    Src$ = "MACRO BCXSTRSIZE=" + STR$ (c_BCXSTRINGS)
    PassOne = TRUE
    Inject(Src$)
    FP_CST = FP_SAVE
END SUB ' ExportStringConst



SUB ExportInternalConst
    IF Use_FillArray THEN
        DIM RAW FP_SAVE AS FILE
        FP_SAVE = FP_CST
        FP_CST = FP_SYSCST
        Src$ = "MACRO vt_INTEGER =  2"
        PassOne = TRUE
        Inject(Src$)
        Src$ = "MACRO vt_SINGLE  =  3"
        PassOne = TRUE
        Inject(Src$)
        Src$ = "MACRO vt_DOUBLE  =  4"
        PassOne = TRUE
        Inject(Src$)
        Src$ = "MACRO vt_LDOUBLE =  5"
        PassOne = TRUE
        Inject(Src$)
        FP_CST = FP_SAVE
    END IF
END SUB ' ExportInternalConst



FUNCTION RestrictedWords(ParamStr$ AS STRING) AS INT
    SELECT CASE ParamStr$
        CASE "CmdLine", "CmdShow", "hInst", "hPrev", "hWnd", "lParam", "Msg", _
            "wParam", "vt_INTEGER", "vt_SINGLE", "vt_DOUBLE", "vt_LDOUBLE"
            FUNCTION = 1
        CASE ELSE
            FUNCTION = 0
    END SELECT
END FUNCTION ' RestrictedWords



FUNCTION DataType(ParamStr AS STRING)
    '*********************************************************************
    ' The purpose of the DataType function is to determine and return
    ' the data type of a given string (ParamStr). It identifies various
    ' types such as string literals, variables, numbers, and specific
    ' type indicators (e.g., integer, single, double) by examining the
    ' string's content and attributes. If no specific type is matched,
    ' it defaults to returning vt_UNKNOWN.
    '*********************************************************************
    DIM RAW Keyword$
    DIM RAW i

    IF ParamStr[0] = c_DblQt THEN
        FUNCTION = vt_STRLIT
    END IF

    IF iMatchNQ(ParamStr$, "$") THEN
        FUNCTION = vt_STRVAR
    END IF

    IF IsDecimalNumber(ParamStr$) THEN
        FUNCTION = vt_NUMBER
    END IF

    i = CheckTypeDefs(ParamStr$)
    IF i THEN
        FUNCTION = TypeDefs[i].TypeofDef
    END IF

    '****************
    '   Functions
    '****************

    Keyword$ = LCASE$(ParamStr$)
    i = FindWord(Keyword$, tBcxWords, m_WordsInTable(tBcxWords))
    IF i <> c_NOTFOUND THEN FUNCTION = tBcxWords[i].iType

    IF iMatchNQ(ParamStr$, "%") THEN
        FUNCTION = vt_INTEGER
    END IF

    IF iMatchNQ(ParamStr$, "!") THEN
        FUNCTION = vt_SINGLE
    END IF

    IF iMatchNQ(ParamStr$, "#") THEN
        FUNCTION = vt_DOUBLE
    END IF

    IF iMatchNQ(ParamStr$, "^") THEN
        FUNCTION = vt_DOUBLE
    END IF

    IF iMatchNQ(ParamStr$, "`") THEN
        FUNCTION = vt_LDOUBLE
    END IF

    IF m_iMatchRgt(ParamStr$, "@") THEN
        FUNCTION = vt_FILEPTR
    END IF

    IF iMatchNQ(ParamStr$, SPC$) THEN
        FUNCTION = vt_UDT
    END IF

    IF m_iMatchLft(ParamStr$, "_") THEN
        FUNCTION = vt_INTEGER
    END IF

    IF isalpha(ParamStr[0]) THEN
        FUNCTION = vt_INTEGER
    END IF

    IF CAST(UINT, ParamStr[0]) > 127 THEN
        FUNCTION = vt_INTEGER
    END IF

    FUNCTION = vt_UNKNOWN
END FUNCTION ' DataType



SUB CloseAll
    IF PPDLL_HANDLE THEN
        FreeLibrary(PPDLL_HANDLE)
        PPDLL_HANDLE = NULL
        PPProc = NULL
    END IF
    CLOSE ' Flush and Close all open files
END SUB   ' CloseAll






SUB RemoveAll (Haystack$, Needles AS PCTSTR, qtflag = 0)
    '*************************************************************************
    ' This SUB removes all occurrences of specified characters from a string.
    ' If qtflag is set to 1, it ignores characters inside double quotes.
    '*************************************************************************
    DIM C   = Haystack AS PCHAR
    DIM pmc = NULL     AS PCHAR
    DO WHILE NOTNULL(Haystack$)
        IF qtflag THEN                   ' qtflag = 1 means ignore anything in quotes
            IF *Haystack = c_DblQt THEN
                *(C++) = *Haystack
                DO WHILE *(++Haystack) <> c_DblQt
                    *(C++) = *Haystack
                    IF ISNULL(Haystack$) THEN EXIT SUB
                LOOP
                *(C++) = *(Haystack++)
                ITERATE
            END IF
        END IF
        pmc = CAST(PCHAR, Needles)
        DO WHILE *pmc
            IF *(pmc++) = *Haystack THEN GOTO SKIP
        LOOP
        *(C++) = *Haystack

        SKIP:
        INCR Haystack
    LOOP
    *C = 0
END SUB ' RemoveAll



SUB Warning_ID (iWarning, WarnLvl = 0)
    SELECT CASE iWarning
        CASE eExitingMoreThan1Loop
            CALL Warning("Exiting more than one loop", WarnLvl)
    END SELECT
END SUB  ' Warning_ID



SUB Warning (ParmStr$, WarnLvl = 0)
    LOCAL fErr AS FILE
    IF WarnLvl THEN
        WarnMsg$ += " Line" + STR$(LineNum[FileNdx]) + " in Module: " + TRIM$(FileNames$[FileNdx]) + " - " + ParmStr$
    ELSE
        WarnMsg$ += ParmStr$
    END IF
    WarnMsg$ += CRLF$ + CRLF$
    IF ErrFile THEN
        OPEN FileErr$ FOR APPEND AS fErr
        FPRINT fErr, "WARNING ", ParmStr$
        CLOSE fErr
    END IF
END SUB ' Warnings




FUNCTION HashNumber(Str2Hash$) AS ULONG
    '******************************************************
    ' This function generates a hash number from a string.
    ' Daniel J. Bernstein designed the DJB2 algorithm.
    '******************************************************
    DIM StrgPtr AS PCHAR = Str2Hash
    DIM hash AS ULONG = 5381
    DIM c AS UCHAR

    WHILE *StrgPtr
        c = *StrgPtr
        hash = ((hash SHL 5) + hash) + c
        StrgPtr++
    WEND

    FUNCTION = CAST(ULONG, IMOD(hash, c_MaxGlobalVars))
END FUNCTION ' HashNumber



SUB AddLibrary (LibName$)
    '*******************************************************
    ' This SUB adds a C/C++ library to a list of libraries
    '*******************************************************
    STATIC nTimes
    LOCAL nLibNdx
    LOCAL TempLibName$

    TempLibName$ = LCASE$(LibName$)

    IF NOT INCHR(TempLibName$, DQ$) AND NOT INCHR(TempLibName$, "<") THEN
        TempLibName$ = ENC$(TempLibName$, 60, 62)
    END IF

    IF nTimes = 0 THEN
        FOR i AS INT = 0 TO c_MaxLib - 1
            Library$[i] = ""
        NEXT
        INCR nTimes
        Library$[0] = TempLibName$
        EXIT SUB
    END IF

    nLibNdx = 0
    DO WHILE NOTNULL(Library$[nLibNdx])
        IF Library$[nLibNdx] = TempLibName$ THEN EXIT SUB
        INCR nLibNdx
    LOOP

    IF nLibNdx < c_MaxLib - 1 THEN
        Library$[nLibNdx] = TempLibName$
    ELSE
        CALL Abort("Max libraries exceeded. Currently c_MaxLib set to" + STR$(c_MaxLib))
    END IF
END SUB ' AddLibrary





SUB RemoveLibrary (LibName$)
    '*************************************************************
    ' This SUB removes a C/C++ library from the list of libraries
    '*************************************************************
    IF NOT INSTR (RmLibs$, LibName$, 1, 1) THEN
        RmLibs$ += "," + LCASE$(LibName$)
    END IF
END SUB ' RemoveLibrary



SUB AddGlobal (           _
    GlobalName$ ,         _
    GlobalType  ,         _
    GlobalDef    = 0,     _
    GlobalDim$   = "",    _
    GlobalPtr    = 0,     _
    GlobalFS     = 0,     _
    GlobalExtn   = 0,     _
    iEmitted     = 0,     _
    iConst       = 0)

    '*****************************************************************************************************************************************
    ' This SUB stores global variables along with their metadata such as identifier, type, definition, dimensions, etc.
    '*****************************************************************************************************************************************
    DIM RAW FirstVar$
    DIM RAW SecondVar$
    DIM RAW Warn$
    DIM RAW GlobalNameHash AS ULONGLONG
    DIM RAW ptGlobal AS UDT_VARINFO_STORAGE PTR
    DIM RAW s

    IF Use_Project = TRUE THEN
        IF GlobalExtn = 0 THEN
            INCR GlobalExtn, 2
        END IF
    END IF

    IF RestrictedWords(GlobalName$) AND TestState THEN
        Warn$ = "Restricted Word " + GlobalName$ + " on Line"
        Warn$ += STR$(LineNum[FileNdx]) + " in Module: " + TRIM$(FileNames$[FileNdx])
        CALL Warning(Warn$)
    END IF

    GlobalNameHash = HashNumber(GlobalName$)

    DO WHILE GlobalVarHash[GlobalNameHash]
        s = GlobalVarHash[GlobalNameHash]
        ptGlobal = ADDRESSOF(GlobalVars[s])
        IF GlobalName$ = ptGlobal->VarName$ THEN
            IF InConditional = 0 OR (InConditional > 0 AND InIfDef$ = ptGlobal->VarCondDef$) THEN
                IF ptGlobal->VarType <> GlobalType OR _
                    GlobalDim$ <> ptGlobal->VarDim$ OR _
                    ptGlobal->VarDef <> GlobalDef THEN

                    FirstVar$  = ""
                    FirstVar$ += "Line" + STR$(LineNum[FileNdx]) + " in Module: "
                    FirstVar$ += TRIM$(FileNames$[FileNdx]) + " : " + GlobalName$
                    FirstVar$ += GlobalDim$ + " as " + GetVarTypeName$(GlobalType)
                    FirstVar$ += SPC$ + TypeDefs[GlobalDef].VarName$

                    SecondVar$  = ""
                    SecondVar$ += "Line" + STR$(ptGlobal->VarLine) + " in Module: "
                    SecondVar$ += ptGlobal->VarModule$ + " : " + GlobalName$
                    SecondVar$ += ptGlobal->VarDim$ + " as " + GetVarTypeName$(ptGlobal->VarType)
                    SecondVar$ += SPC$ + TypeDefs[ptGlobal->VarDef].VarName$

                    Warn$ = "Two Variables " + FirstVar$ + " previously defined at " + SecondVar$
                    CALL Warning(Warn$)
                END IF
                EXIT SUB
            END IF
        END IF
        GlobalNameHash = IMOD(GlobalNameHash + 1, c_MaxGlobalVars)
    LOOP

    INCR GlobalVarCnt

    IF GlobalVarCnt = c_MaxGlobalVars THEN
        CALL Abort("Maximum Global Variables reached.")
    END IF

    ptGlobal = ADDRESSOF(GlobalVars[GlobalVarCnt])
    ptGlobal->VarName$     =  GlobalName$
    ptGlobal->VarType      =  GlobalType
    ptGlobal->VarDef       =  GlobalDef
    ptGlobal->VarDim$      =  GlobalDim$
    ptGlobal->VarLine      =  LineNum[FileNdx]
    ptGlobal->VarPntr      =  GlobalPtr
    ptGlobal->VarSF        =  GlobalFS
    ptGlobal->VarEmitFlag  =  iEmitted
    ptGlobal->VarModule$   =  TRIM$(FileNames$[FileNdx])
    ptGlobal->VarExtn      =  GlobalExtn
    ptGlobal->VarCondLevel =  InConditional
    ptGlobal->VarConstant  =  iConst
    ptGlobal->VarCondDef$  =  InIfDef$
    GlobalVarHash[GlobalNameHash] = GlobalVarCnt
END SUB ' AddGlobal




SUB AddLocal (         _
    LocalName$ ,       _
    LocalType  ,       _
    LocalDef    = 0,   _
    LocalDim$   = "",  _
    LocalPtr    = 0,   _
    LocalFS     = 0,   _
    iEmitted    = 0,   _
    iConst      = 0)
    '***************************************************************************************************
    ' This sub adds a LOCAL variable with its details such as name, type, definition, dimensions, etc.
    '***************************************************************************************************
    DIM RAW varid = 0
    DIM RAW FirstVar$
    DIM RAW SecondVar$
    DIM RAW Warn$
    DIM RAW s

    IF LocalVarCnt AND TestState THEN
        IF CheckGlobal(LocalName$, ADDRESSOF(varid)) <> vt_UNKNOWN THEN

            IF LocalDef THEN
                FirstVar$  = ""
                FirstVar$ += "Line" + STR$(LineNum[FileNdx])
                FirstVar$ += " in Module: " + TRIM$(FileNames$[FileNdx])
                FirstVar$ += " : " + LocalName$ + LocalDim$ + " as "
                FirstVar$ += TypeDefs[LocalDef].VarName$
            ELSE
                FirstVar$ = ""
                FirstVar$ += "Line" + STR$(LineNum[FileNdx])
                FirstVar$ += " in Module: " + TRIM$(FileNames$[FileNdx])
                FirstVar$ += " : " + LocalName$ + LocalDim$ + " as "
                FirstVar$ += GetVarTypeName$(LocalType)
            END IF

            IF GlobalVars[varid].VarDef THEN
                SecondVar$ = ""
                SecondVar$ +=      "Line" + STR$(GlobalVars[varid].VarLine)
                SecondVar$ += " in Module: " + GlobalVars[varid].VarModule$
                SecondVar$ += " : " + LocalName$ + GlobalVars[varid].VarDim$
                SecondVar$ +=  " as " + TypeDefs[GlobalVars[varid].VarDef].VarName$
            ELSE
                SecondVar$ = ""
                SecondVar$ +=   "Line" + STR$(GlobalVars[varid].VarLine)
                SecondVar$ +=  " in Module: " + GlobalVars[varid].VarModule$
                SecondVar$ +=  " : " + LocalName$ + GlobalVars[varid].VarDim$
                SecondVar$ +=   " as " + GetVarTypeName$(GlobalVars[varid].VarType)
            END IF
            Warn$ = "Local Variable " + FirstVar$ + CRLF$ + "Has Same Name as Global " + SecondVar$
            CALL Warning(Warn$)
        END IF

        FOR s = 1 TO LocalVarCnt
            IF LocalName$ = LocalVars[s].VarName$ THEN
                IF LocalVars[s].VarType <> LocalType         _
                    OR LocalDim$ <> LocalVars[s].VarDim$      _
                    OR LocalVars[s].VarDef <> LocalDef THEN

                    FirstVar$  = ""
                    FirstVar$ += "Line" + STR$(LineNum[FileNdx])
                    FirstVar$ += " in Module: " + TRIM$(FileNames$[FileNdx])
                    FirstVar$ += " : " + LocalName$ + LocalDim$ + " as "
                    FirstVar$ += GetVarTypeName$(LocalType) + SPC$
                    FirstVar$ += TypeDefs[LocalDef].VarName$

                    SecondVar$  = ""
                    SecondVar$ += "Line" + STR$(LocalVars[s].VarLine) + " in Module: "
                    SecondVar$ += LocalVars[s].VarModule$ + " : " + LocalName$
                    SecondVar$ += LocalVars[s].VarDim$ + " as "
                    SecondVar$ += GetVarTypeName$(LocalVars[s].VarType) + SPC$
                    SecondVar$ += TypeDefs[LocalVars[s].VarDef].VarName$

                    Warn$ = "Two Variables " + FirstVar$ + " previously defined at " + SecondVar$
                    CALL Warning(Warn$)
                END IF
                EXIT SUB
            END IF
        NEXT
    END IF

    INCR LocalVarCnt

    IF LocalVarCnt = c_MaxLocalVars THEN
        Warn$ = "Maximum Local Variables reached."
        CALL Abort(Warn$)
    END IF

    LocalVars[LocalVarCnt].VarName$     =  LocalName$
    LocalVars[LocalVarCnt].VarType      =  LocalType
    LocalVars[LocalVarCnt].VarDef       =  LocalDef
    LocalVars[LocalVarCnt].VarDim$      =  LocalDim$
    LocalVars[LocalVarCnt].VarLine      =  LineNum[FileNdx]
    LocalVars[LocalVarCnt].VarPntr      =  LocalPtr
    LocalVars[LocalVarCnt].VarSF        =  LocalFS
    LocalVars[LocalVarCnt].VarEmitFlag  =  iEmitted
    LocalVars[LocalVarCnt].VarConstant  =  iConst
    LocalVars[LocalVarCnt].VarModule$   =  TRIM$(FileNames$[FileNdx])
END SUB ' AddLocal




FUNCTION IsDecimalNumber (szNumber AS STRING) AS BOOLEAN
    '******************************************************************
    '            Updated and renamed in 826 by MrBcx
    ' This function checks if the string argument is a valid DECIMAL
    ' or SCIENTIFIC NOTATION number according to my detection rules.
    '******************************************************************
    DIM i AS INT
    DIM HasDigit AS INT
    DIM HasE AS INT
    DIM HasMinus AS INT
    DIM HasPlus AS INT
    DIM HasDecimal AS INT
    DIM digitAfterE AS BOOLEAN
    DIM prevWasE AS BOOLEAN

    IF ISNULL(szNumber) THEN FUNCTION = FALSE         ' Handle null argument
    IF iMatchNQ(szNumber, SPC$) THEN FUNCTION = FALSE    ' No SPACES allowed

    '***********************************************************
    ' Rules for this function
    '   Can only have these characters: -+.0123456789eELl
    '   Must have at least 1 digit
    '   Only 1 "E" or "e" (case insensitive)
    '   No more than 2 plus signs, cannot end in a plus sign
    '   No more than 2 minus signs, cannot end in a minus sign
    '   No more than 1 decimal point
    '
    ' Rules of scientific notation:
    '   The base is always 10
    '   The exponent is a non-zero integer
    '   The coefficient carries the sign (+ or -)
    '   The mantissa carries the significant digits
    '***********************************************************

    ' Check for leading + or -
    IF szNumber[0] = 43 THEN      ' +
        INCR HasPlus
        INCR i
    ELSEIF szNumber[0] = 45 THEN  ' -
        INCR HasMinus
        INCR i
    END IF

    DO WHILE szNumber[i]    ' Check for valid characters
        IF szNumber[i] >= 48 AND szNumber[i] <= 57 THEN  '  0 to 9
            INCR HasDigit
            IF HasE > 0 THEN
                digitAfterE = TRUE
            END IF
            prevWasE = FALSE

        ELSEIF szNumber[i] = 46 THEN  ' .
            INCR HasDecimal
            IF HasDecimal > 1 OR HasE > 0 THEN FUNCTION = FALSE  ' Only one decimal point allowed, none after E
            prevWasE = FALSE

        ELSEIF szNumber[i] = 69 OR szNumber[i] = 101 THEN    ' E or e
            INCR HasE
            IF HasE > 1 OR HasDigit = 0 THEN FUNCTION = FALSE    ' Only one E allowed, must have digits before E
            prevWasE = TRUE

        ELSEIF szNumber[i] = 43 THEN  ' +
            INCR HasPlus
            ' Plus sign is only valid at the start (already checked) or right after E
            IF NOT prevWasE AND i > 0 THEN FUNCTION = FALSE
            IF HasPlus > 2 THEN FUNCTION = FALSE
            prevWasE = FALSE

        ELSEIF szNumber[i] = 45 THEN  ' -
            INCR HasMinus
            ' Minus sign is only valid at the start (already checked) or right after E
            IF NOT prevWasE AND i > 0 THEN FUNCTION = FALSE
            IF HasMinus > 2 THEN FUNCTION = FALSE
            prevWasE = FALSE

        ELSEIF (szNumber[i] = 76 OR szNumber[i] = 108) AND szNumber[i+1] = 0 THEN  ' L or l at the end and
            prevWasE = FALSE                                                       ' can only be the final char
        ELSE
            FUNCTION = FALSE                                                       ' Found an invalid character
        END IF

        INCR i
    LOOP

    IF i = 0 THEN FUNCTION = FALSE                                                 ' No characters found

    DECR i                                                                         ' Move index to the final character
    '                                                                              ' Check final character
    IF szNumber[i] = 43 OR szNumber[i] = 45 THEN                                   ' + or -
        FUNCTION = FALSE                                                           ' Cannot end with + or -
    END IF

    ' Final validation
    IF HasDigit = 0 THEN FUNCTION = FALSE                                          ' Must have at least one digit
    IF HasE > 0 AND NOT digitAfterE THEN FUNCTION = FALSE                          ' Must have digits after E

    FUNCTION = TRUE
END FUNCTION ' IsDecimalNumber




FUNCTION IsRadixLiteral(szArg$, RadixBase = NULL AS INT PTR) AS BOOLEAN
    '****************************************************************************
    ' This function replaced IsHexNumber() starting with BCX version 8.3.7 (MrBcx)
    ' It validates whether szArg$ is a non-decimal numeric literal in one of
    ' the supported base prefixes:
    '
    '       BCX style      C style       Base
    '       ---------      -------       ----
    '       &H...          0x...          16   hexadecimal
    '       &O...          0o...           8   octal
    '       &B...          0b...           2   binary
    '
    ' Returns TRUE if szArg$ has a recognized prefix followed by at
    ' least one valid digit, with every digit valid for that base.
    ' Case-insensitive on prefix and digits.
    '
    ' If Base is non-NULL, it receives the detected base (16, 8, or 2)
    ' on success, or 0 on failure.
    '**************************************************************************

    IF RadixBase THEN *RadixBase = 0

    IF ISNULL(szArg$)          THEN EXIT FUNCTION
    IF iMatchNQ(szArg$, SPC$)  THEN EXIT FUNCTION
    IF LEN(szArg$) < 3         THEN EXIT FUNCTION

    DIM InputStr$, Prefix$, Digits$, ValidDigits$
    DIM AS INT    DetectedBase

    InputStr$ = LCASE$(szArg$)
    Prefix$   = LEFT$(InputStr$, 2)
    Digits$   = MID$(InputStr$, 3)

    SELECT CASE Prefix$
        CASE "0x", "&h"
            DetectedBase = 16
            ValidDigits$ = "0123456789abcdef"
        CASE "0o", "&o"
            DetectedBase = 8
            ValidDigits$ = "01234567"
        CASE "0b", "&b"
            DetectedBase = 2
            ValidDigits$ = "01"
        CASE ELSE
            EXIT FUNCTION
    END SELECT

    FOR i AS INT = 1 TO LEN(Digits$)
        IF iMatchNQ(ValidDigits$, MID$(Digits$, i, 1)) = 0 THEN EXIT FUNCTION
    NEXT

    IF RadixBase THEN *RadixBase = DetectedBase
    FUNCTION = TRUE
END FUNCTION ' IsRadixLiteral



FUNCTION IsQuoted(A AS STRING) AS INT
    DIM ArgLen = LEN(A)
    IF ArgLen < 2 THEN
        FUNCTION = 0
    END IF
    IF A[0] = 34 AND A[ArgLen-1] = 34 THEN
        FUNCTION = 1
    ELSE
        FUNCTION = 0
    END IF
END FUNCTION ' IsQuoted



SUB StripTabs
    '****************************************************
    ' This SUB removes tabs from the global "Src" string,
    ' except when the tabs are inside double quotes.
    '****************************************************
    DIM RAW pszSrc AS PCHAR = Src
    DIM RAW iQuoteFlag = 0

    DO WHILE *pszSrc
        IF *pszSrc = c_DblQt THEN iQuoteFlag = iQuoteFlag XOR 1
        IF *pszSrc = 9 AND NOT iQuoteFlag THEN *pszSrc = 32
        INCR pszSrc
    LOOP
END SUB ' StripTabs



SUB PushFileIO
    '********************************************************************
    ' This SUB saves the current source file pointer by pushing
    ' it onto a stack (FPtr) and increments the stack index (FPtrNdx).
    '********************************************************************
    FPtr[++FPtrNdx] = SourceFile
END SUB ' PushFileIO




SUB PopFileIO
    '********************************************************************
    ' This SUB restores the most recently saved source file pointer from
    ' the stack, if the stack is not empty, updates the line count, and
    ' decrements the stack index (FPtrNdx).
    '********************************************************************
    IF FPtrNdx > 0 THEN
        CLOSE SourceFile
        INCR LinesRead, LineNum[FileNdx--]
        SourceFile = FPtr[FPtrNdx--]
    END IF
END SUB ' PopFileIO



SUB CheckMatchedPairs
    '********************************************************************
    ' This function ensures that all parentheses, square brackets, and
    ' double quotes in the input string are properly matched, aborting
    ' execution with an error message if they are not.
    '********************************************************************
    DIM CountR = 0                         ' Round  bracket counter
    DIM CountS = 0                         ' Square bracket counter
    DIM DoCount AS BOOL = TRUE
    DIM pszSrc  AS PCHAR  = Src

    DO WHILE *pszSrc
        IF *pszSrc = c_DblQt THEN
            DoCount = NOT DoCount
        END IF
        IF DoCount THEN
            SELECT CASE *pszSrc
                CASE c_LPar  : INCR CountR
                CASE c_RPar  : DECR CountR
                CASE c_LtBkt : INCR CountS
                CASE c_RtBkt : DECR CountS
            END SELECT
        END IF
        INCR pszSrc
    LOOP
    IF NOT DoCount THEN CALL Abort ("Unmatched Quotes")
    IF CountS THEN CALL Abort ("Unmatched []")
    IF CountR THEN CALL Abort ("Unmatched ()")
END SUB ' CheckMatchedPairs



SUB ClearIfThenStacks
    '****************************************************
    ' This SUB clears the SrcStk$ stack up to a maximum
    ' defined limit (c_MaxSingleLineIFLines) and resets
    ' the source count index (SrcCnt) to zero.
    '****************************************************
    FOR i AS LONG = 0 TO c_MaxSingleLineIFLines -1
        SrcStk$[i] = ""
    NEXT
    SrcCnt = 0
END SUB ' ClearIfThenStacks



SUB AddExpressionToStack(szAssembledExpression$)
    IF SrcCnt = c_MaxSingleLineIFLines-1 THEN
        CALL Abort("Single line conversion to multi-line stack exceeds limit.")
    END IF
    SrcStk$[++SrcCnt] = szAssembledExpression$      ' Assemble our expression
END SUB ' AddExpressionToStack



SUB Add2SplitLines(szSplitLine$)
    IF SplitCnt = c_MaxSplitLines-1 THEN
        CALL Abort("Maximum line splitting exceeded.")
    END IF
    SplitStk$[++SplitCnt] = szSplitLine$
END SUB ' Add2SplitLines





SUB PostProcess
    '*************************************************
    ' This subroutine performs post-processing tasks
    ' such as shell commands and string replacements.
    '*************************************************
    IF ReDirect = TRUE THEN
        DIM RAW LTmp1$
        OPEN FileOut$ FOR INPUT AS FP1
        DO WHILE NOT EOF(FP1)
            LINE INPUT FP1, LTmp1$
            PRINT LTmp1$
        LOOP
        CALL CloseAll
    END IF
    '**************************
    FileOutCopy$ = FileOut$
    FileOutCopy$ = EXTRACT$(FileOutCopy$, ".")

    FOR A AS INT = 1 TO EntryCnt
        Cmd$ = REMOVE$(Entry$[A], DQ$)
        REPLACE BKSLASH4$     WITH BKSLASH2$    IN Cmd$
        IREPLACE "$FILE$"     WITH FileOutCopy$ IN Cmd$
        IREPLACE "$PELLES$\\" WITH PELLESPATH$  IN Cmd$
        IREPLACE "$PELLES$"   WITH PELLESPATH$  IN Cmd$
        IREPLACE "$LCC$\\"    WITH LCCPATH$     IN Cmd$
        IREPLACE "$LCC$"      WITH LCCPATH$     IN Cmd$
        IREPLACE "$BCX$\\"    WITH BCXPATH$     IN Cmd$
        IREPLACE "$BCX$"      WITH BCXPATH$     IN Cmd$
        PRINT "Shelling Out To:", Cmd$
        SHELL Cmd$
    NEXT

    IF NOTNULL(Compiler$) THEN
        Compiler$ = TRIM$(REMOVE$(Compiler$, DQ$))
        IF INCHR(Compiler$, SPC$) THEN
            Compiler$ = ENC$(EXTRACT$(Compiler$, SPC$)) + SPC$ + REMAIN$(Compiler$, SPC$)
        ELSE
            Compiler$ = ENC$(Compiler$)
        END IF
        REPLACE BKSLASH4$     WITH BKSLASH2$    IN Compiler$
        IREPLACE "$FILE$"     WITH FileOutCopy$ IN Compiler$
        IREPLACE "$PELLES$\\" WITH PELLESPATH$  IN Compiler$
        IREPLACE "$PELLES$"   WITH PELLESPATH$  IN Compiler$
        IREPLACE "$LCC$\\"    WITH LCCPATH$     IN Compiler$
        IREPLACE "$LCC$"      WITH LCCPATH$     IN Compiler$
        REPLACE DDQ$          WITH DQ$          IN Compiler$
        PRINT "Shelling Out To:", Compiler$
        SHELL Compiler$
    END IF
    '**************************
    IF NOTNULL(ResCompiler$) THEN
        ResCompiler$ = ENC$(ResCompiler$)
        ResCompiler$ += SPC$ + Res_File$
        IREPLACE "$PELLES$\\" WITH PELLESPATH$  IN ResCompiler$
        IREPLACE "$PELLES$"   WITH PELLESPATH$  IN ResCompiler$
        IREPLACE "$LCC$\\"    WITH LCCPATH$     IN ResCompiler$
        IREPLACE "$LCC$"      WITH LCCPATH$     IN ResCompiler$
        IREPLACE "$FILE$"     WITH FileOutCopy$ IN ResCompiler$
        REPLACE BKSLASH4$     WITH BKSLASH2$    IN ResCompiler$
        REPLACE DDQ$          WITH DQ$          IN ResCompiler$
        PRINT "Shelling Out To:", ResCompiler$
        SHELL ResCompiler$
    END IF
    '**************************
    IF NOTNULL(Linker$) THEN
        Linker$ = TRIM$(REMOVE$(Linker$, DQ$))
        IF INCHR(Linker$, SPC$) THEN
            Linker$ = DQ$ + EXTRACT$(Linker$, SPC$) + DQ$ + SPC$ + REMAIN$(Linker$, SPC$)
        ELSE
            Linker$ = ENC$(Linker$)
        END IF
        IREPLACE "$PELLES$\\" WITH PELLESPATH$  IN Linker$
        IREPLACE "$PELLES$"   WITH PELLESPATH$  IN Linker$
        IREPLACE "$LCC$\\"    WITH LCCPATH$     IN Linker$
        IREPLACE "$LCC$"      WITH LCCPATH$     IN Linker$
        IREPLACE "$FILE$"     WITH FileOutCopy$ IN Linker$
        REPLACE   BKSLASH4$   WITH BKSLASH2$    IN Linker$
        REPLACE   DDQ$        WITH DQ$          IN Linker$
        IF Use_Resource THEN
            ResFileOut$ = EXTRACT$(Res_File$, ".") + ".res"
            Linker$ += SPC$ + ResFileOut$
        END IF
        PRINT "Shelling Out To:", Linker$
        SHELL Linker$
    END IF
    '**************************
    DIM szSave$ = FileOut$
    FileOut$ = EXTRACT$(FileOut$, ".")

    FOR A AS INT = 1 TO XitCount
        Cmd$ = REMOVE$(Xit$[A], DQ$)
        IREPLACE "$FILE$" WITH FileOutCopy$    IN Cmd$
        IREPLACE "$PELLES$\\" WITH PELLESPATH$ IN Cmd$
        IREPLACE "$PELLES$"   WITH PELLESPATH$ IN Cmd$
        IREPLACE "$LCC$\\"    WITH LCCPATH$    IN Cmd$
        IREPLACE "$LCC$"      WITH LCCPATH$    IN Cmd$
        IREPLACE "$BCX$\\"    WITH BCXPATH$    IN Cmd$
        IREPLACE "$BCX$"      WITH BCXPATH$    IN Cmd$
        REPLACE   BKSLASH4$   WITH BKSLASH2$   IN Cmd$
        REPLACE   DDQ$        WITH DQ$         IN Cmd$
        PRINT "Shelling Out To:", Cmd$
        SHELL Cmd$
    NEXT
    FileOut$ = szSave$
END SUB ' PostProcess




SUB Inject (szArg$)
    DIM szLine$ * c_MaxSrcLen
    szLine$ = szArg$
    CALL PreParse(szLine$)
    CALL FixUps
    CALL Function_Main_Support
END SUB ' Inject



FUNCTION Convert2SimpleFunction(Tmp AS INT)
    DIM iLParen = Tmp + 1   ' The "("
    DIM iRParen = Tmp + 2   ' The ")"
    DIM iRetVal = 0
    IF Stk$[iLParen] = "(" AND Stk$[iRParen] = ")" THEN
        Stk$[iLParen] = ""
        Stk$[iRParen] = ""
        INCR iRetVal
    END IF
    FUNCTION = iRetVal
END FUNCTION ' Convert2SimpleFunction



SUB PreParse(Statement$)
    DIM i
    DIM j
    DIM InIF
    DIM InXFOR
    DIM Gapflag
    DIM LTmp$
    '*************
    IF Statement$ = "" THEN
        Ndx = 0
        EXIT SUB
    END IF

    '====================================================================================================
    '  Handle "&H", "&O", and "&B" transforms - 837 MrBcx  -- IsRadixLiteral () replaced IsHexNumber()
    '====================================================================================================
    LOCAL RadixFlag
    FastLexer(Statement$, "", " =()[]{}',+-*/<>?;.|:^")  ' leave ampersand out of it - MrBcx

    FOR ii AS INT = 1 TO Ndx
        DIM RadixBase AS INT
        IF IsRadixLiteral(Stk$[ii], ADDRESSOF(RadixBase)) THEN
            RadixFlag = TRUE
            SELECT CASE RadixBase
                CASE 16 : IREPLACE "&h" WITH "0x" IN Stk$[ii]
                CASE 8  : Stk$[ii] = STR$(VAL("&o" + MID$(Stk$[ii], 3)))
                CASE 2  : IREPLACE "&b" WITH "0b" IN Stk$[ii]
            END SELECT
        END IF
    NEXT

    IF RadixFlag = TRUE THEN
        Statement$ = ""
        FOR ii AS INT = 1 TO Ndx
            Statement$ += Stk$[ii]
        NEXT
    END IF

    '*****************************************************************
    ' BUG FIX:  This was added by MrBcx in 829 and improved in 832
    '*****************************************************************

    LOCAL AmpFlag
    IF Im_A_String_Var(Stk$[1]) THEN
        FOR k AS LONG = 2 TO Ndx-1
            IF Stk$[k] = "" THEN EXIT FOR
            IF Stk$[k] = "]" AND Stk$[k+1] = "+" THEN
                Stk$[k+1] = "&"
                AmpFlag = TRUE
            END IF
        NEXT
    END IF
    IF AmpFlag = TRUE THEN
        Statement$ = ""
        FOR ii AS INT = 1 TO Ndx
            Statement$ += Stk$[ii]
        NEXT
        AmpFlag = FALSE
    END IF

    '*****************************************************************
    '*****************************************************************

    FastLexer(Statement$, SPC$, c_FULLSET)

    '*****************************************************************
    '                           Pre-Parse
    '*****************************************************************

    DO WHILE ++i < 20
        Stk$[i+Ndx] = ""
    LOOP

    FOR ii AS INT = 1 TO Ndx
        IF *Stk$[ii] = ASC("&") AND *Stk$[ii+1] = ASC("&") THEN
            Stk$[ii] = "and"
            LShiftStk (ii+1)
        END IF
    NEXT

    IF m_iMatchWrd(Stk$[1], "end") THEN
        LTmp$ = ENC$(LCASE$(Stk$[2]), ASC(SPC$))
        IF iMatchNQ(" events , mdievents , mdichildevents ", LTmp$) THEN
            Stk$[1] += LCASE$(Stk$[2])
            IF m_iMatchWrd(Stk$[3], "main") THEN Use_MainEvent = TRUE
            Ndx = 1
            Src$ = Stk$[1]
            EXIT SUB
        END IF
        IF Stk$[2] <> "=" AND Ndx = 2 THEN
            IF m_iMatchWrd(Stk$[2], "dialog") THEN Stk$[2] = "function"
            Stk$[1] = "end" + LCASE$(Stk$[2])
            Ndx = 1
            Src$ = Stk$[1]
            EXIT SUB
        END IF
    END IF

    IF m_iMatchWrd(Stk$[1], "end") AND m_iMatchWrd(Stk$[2], "prepend") THEN
        Stk$[1] = "endprepend"
        Src$ = Stk$[1]
        Ndx = 1
        EXIT SUB
    END IF

    IF m_iMatchWrd(Stk$[1], "end") AND m_iMatchWrd(Stk$[2], "with") THEN
        Stk$[1] = "endwith"
        Src$ = Stk$[1]
        Ndx = 1
        EXIT SUB
    END IF

    DIM iP = 1

    IF m_iMatchWrd(Stk$[iP], "public") OR m_iMatchWrd(Stk$[iP], "private") THEN INCR iP

    IF (m_iMatchWrd(Stk$[iP], "function") OR  _
        m_iMatchWrd(Stk$[iP], "catch")    OR  _
        m_iMatchWrd(Stk$[iP], "sub"))     AND _
        iMatchNQ(Statement$, "*")            THEN

        XFOR INT ii = 2, INT jjj = 1 WHILE ii < Ndx-1 AND jjj BY ii++
            jjj = m_GetAsPosF(ii, Ndx-2)
            IF jjj THEN
                ii = jjj
                IF m_iMatchWrd(Stk$[ii+1], "const") THEN INCR ii
                DO WHILE Stk$[ii+2] = "*"
                    Stk$[ii+2] = "PTR"
                    INCR ii
                LOOP
            END IF
        XNEXT

        CALL BuildDelimStr(1, Ndx, Src$)
        FastLexer(Src$, SPC$, c_FULLSET)
        Statement$ = Src$
    END IF

    Gapflag = FALSE
    FOR i = 1 TO Ndx
        IF IsDecimalNumber(Stk$[i]) AND BYTE_AT(Stk[i][1]) > 0 THEN
            Keyword1$ = RIGHT$(Stk$[i], 1)
            IF *Keyword1$ = ASC("E") OR *Keyword1$ = ASC("e") THEN
                Stk$[i] += Stk$[i+1]
                Stk$[i] += Stk$[i+2]
                Stk$[i+1] = ""
                Stk$[i+2] = ""

                IF Stk$[i-1] = "-" THEN
                    Stk$[i-1] += Stk$[i]
                    Stk$[i] = ""
                END IF
                Gapflag = TRUE
            END IF
        END IF
    NEXT

    IF Gapflag = TRUE THEN CALL RemEmptyTokens

    FOR i = 1 TO Ndx
        Keyword1$ = LCASE$(Stk$[i])

        IF Keyword1[1] THEN
            SELECT CASE Keyword1$

                CASE "not"  : Stk$[i] = "!"
                CASE "is"   : Stk$[i] = "="
                CASE "xor"  : Stk$[i] = "xor"

                CASE "if", "iif", "iif$", "case", "elseif", "while"
                    InIF = 1
                    IF Keyword1$ = "case" AND m_iMatchWrd(Stk$[i+1], "else") THEN
                        Stk$[i] = "caseelse"
                        Stk$[i+1] = ""
                        Gapflag = TRUE
                    ELSE
                        Stk$[i] = Keyword1$
                    END IF

                CASE "$if", "$ifdef"   ' Tells "OR" to be Boolean in an $IF/$IFDEF directive
                    InIF = 1

                CASE "$endif"          ' "OR" is free to change again
                    InIF = 0

                CASE "xfor"
                    InXFOR = 1

                CASE "until"
                    InIF = InXFOR
                    InXFOR = 0

                CASE "by"
                    InIF = 0

                CASE "then"
                    InIF = 0

                CASE "byval", "let"
                    Stk$[i] = ""
                    Gapflag = TRUE

                CASE "shl"
                    Stk$[i] = "<<"

                CASE "shr"
                    Stk$[i] = ">>"

                CASE "byref"
                    IF NOT m_iMatchWrd(Stk$[1], "declare") AND NOT m_iMatchWrd(Stk$[1], "c_declare") THEN
                        IF ByrefCnt = c_MaxByref-1 THEN
                            CALL Abort("Maxium number of BYREFs reached.")
                        END IF
                        ByrefVars$[++ByrefCnt] = Stk$[i+1]
                    END IF

                    DIM iDontHaveAs = TRUE

                    FOR j = i TO Ndx
                        IF m_iMatchWrd(Stk$[j], "as") THEN iDontHaveAs = FALSE
                        IF Stk$[j+1] = "," OR Stk$[j+1] = ")" THEN
                            Stk$[j] = "PTR"
                            IF iDontHaveAs THEN
                                InsertTokens(j-1, 2, "as", VarTypeLookup$[ INCHR(c_VARTYPES$, RIGHT$(ByrefVars$[ByrefCnt], 1)) ])
                            END IF
                            EXIT FOR
                        END IF
                        Stk$[j] = Stk$[j+1]
                    NEXT

                CASE "and"
                    IF InIF THEN
                        Stk$[i] = "&&"
                    ELSE
                        Stk$[i] = "&"
                    END IF

                CASE "or"
                    IF InIF THEN
                        Stk$[i] = "||"
                    ELSE
                        Stk$[i] = "|"
                    END IF

                CASE "procedure"
                    Stk$[i] = "sub"

                CASE ELSE
                    IF PassOne THEN
                        IF Keyword1$ = ENC$(CHR$(92)) THEN
                            IF *Stk$[i+1] <> c_DblQt THEN
                                Stk$[i] = "chr$"
                                InsertTokens(i, 3, "(", "92", ")")
                                INCR i, 3
                            ELSE
                                Stk$[i] += Stk$[i+1]
                                Stk$[i+1] = ""
                                Gapflag = TRUE
                            END IF
                        ELSE
                            IF TranslateSlash THEN
                                REPLACE BKSLASH1$ WITH BKSLASH2$ IN Stk$[i]
                            END IF
                        END IF
                    END IF
            END SELECT

        ELSE

            SELECT CASE ASC(Keyword1$)

                '**************
                CASE ASC("&")                                                ' Connect AddressOf operator
                    '**************

                    IF INCHR("+&,(=", Stk$[i-1]) AND *Stk$[i+1] <> ASC(".") THEN
                        Stk$[i+1] = " &" + Stk$[i+1]
                        Stk$[i] = ""
                        Gapflag = TRUE
                    END IF

                    '**************
                CASE ASC ("?")                                               ' Multiple contexts
                    '**************

                    '***********************************************************************************
                    IF Stk$[1] ?? "IF" THEN EXIT SELECT                      ' Found an "??" operator
                    '***********************************************************************************

                    IF Use_GUINoMain OR Use_MDIGUINoMain OR Use_Wingui THEN  ' Added in 752
                        Stk$[i] = "msgbox"                                   ' ? is translated to MsgBox
                        IF Stk$[i+1] = "" THEN
                            Stk$[i+1] = ENC$("")                             ' Allow an empty msgbox
                            INCR Ndx
                        END IF
                    ELSE                                                     ' ? full console mode
                        IF i = 1 OR (i > 1 AND Stk$[i-1] = ":") THEN
                            Stk$[i] = "print"                                ' ? is a traditional PRINT convenience
                        END IF
                    END IF

                    '**************
                CASE ASC ("-")
                    '**************

                    IF ASC(Stk$[i+1]) = ASC(">") THEN
                        Stk$[i] = "->" + Stk$[i+2]
                        Stk$[++i] = ""
                        Stk$[++i] = ""
                        Gapflag = TRUE
                    END IF

                    '**************
                CASE ASC (".")
                    '**************

                    IF ASC(Stk$[i+1]) = 46 AND ASC(Stk$[i+2]) = 46 THEN   ' ...
                        Stk$[i] = "..."
                        Stk$[i+1] = ""
                        Stk$[i+2] = ""
                        Gapflag = TRUE
                    END IF

                    IF IsDecimalNumber(Stk$[i-1]) THEN
                        Stk$[i] = Stk$[i-1] + "."
                        Stk$[i-1] = ""
                        Gapflag = TRUE
                    END IF

                    IF NOT INCHR( ",)=<>*/+-^", Stk$[i+1]) THEN
                        Stk$[i] += Stk$[i+1]
                        Stk$[++i] = ""
                        Gapflag = TRUE
                    END IF

            END SELECT
        END IF
    NEXT

    IF Gapflag = TRUE THEN CALL RemEmptyTokens

    '*******************************************************************
    ' Special Case Handler: BYREF - BCX prepends * to BYREF'd Variables
    '*******************************************************************

    IF PassOne = TRUE THEN
        DIM lszTmp$ = ""
        IF InFunction THEN            ' Must be in a SUB or FUNCTION
            FOR i = 1 TO Ndx
                FOR j = 1 TO ByrefCnt

                    IF m_iMatchLft(Stk$[i], " &") THEN
                        lszTmp$ = Stk$[i] + 2
                    ELSE
                        lszTmp$ = Stk$[i]
                    END IF

                    IF No_Sigil$(lszTmp$) = No_Sigil$(ByrefVars[j]) THEN

                        IF i > 2 THEN
                            IF INCHR("+-^%*/|&<=>,", Stk$[i-2]) AND Stk$[i-1] = "*" THEN
                                Stk$[i-1] = ""
                                Gapflag = TRUE
                            END IF
                            IF m_iMatchLft(Stk$[i], " &") THEN
                                Stk$[i] = Stk$[i] + 2
                                EXIT FOR
                            END IF
                        ELSEIF i = 2 THEN
                            IF Stk$[i-1] = "*" THEN
                                Stk$[i-1] = ""
                                Gapflag = 1
                            END IF
                        END IF

                        Stk$[i] = "*" + Stk$[i]
                        IF Stk$[i-1] <> "(" OR Stk$[i+1] <> ")" THEN
                            Stk$[i] = ENC$(Stk$[i], ASC("("), ASC(")"))
                        END IF
                        EXIT FOR
                    END IF

                NEXT
            NEXT
        END IF
        IF Gapflag = TRUE THEN CALL RemEmptyTokens
    END IF

    '*******************************************************************
    ' Special Case Handler: DIM BLAHBLAH[22][33] AS STATIC INT
    '*******************************************************************

    IF m_iMatchWrd(Stk$[1], "dim") THEN
        IF m_iMatchWrd(Stk$[Ndx-1], "static") THEN
            Stk$[1] = "static"
            Stk$[Ndx-1] = Stk$[Ndx]
            DECR Ndx
        END IF
    END IF

    '***********************************
    ' Used in special case handlers.
    '***********************************
    Keyword1$ = LCASE$(Stk$[1])

    '***************************************************************************
    ' Special Case Handler: In the contexts of UDT's this handler transforms:
    ' FUNCTION Foo (a as integer) AS INT         to:
    ' DIM FUNCTION Foo (a as integer) AS INT
    ' Change "as string" to "as char *" for UDTs and Declarations
    '***************************************************************************

    IF InTypeDef AND NOT InClass THEN
        DIM lsz$ = ""
        lsz$ =  ENC$(Keyword1$, ASC(SPC$))
        IF iMatchNQ(" end dim declare type union ", lsz$) = 0 THEN
            DIM iCnt = 0
            DIM iFnd = 0
            IF MacroCount THEN
                XFOR iCnt = 0 WHILE iCnt < MacroCount BY iCnt++
                    IF Stk$[1] = ConstMacro$[iCnt] THEN iFnd = TRUE
                XNEXT
            END IF
            IF iFnd = FALSE THEN InsertTokens(0, 1, "dim")
        END IF
    END IF

    '******************************

    IF NOT InTypeDef AND NOT InCppTypeDef THEN
        DIM Res
        DIM lszTemp$
        DIM Storage$

        Storage$ = " dim local global raw static shared dynamic auto register extern "

        lszTemp$ = ENC$(Keyword1$, ASC(SPC$))

        IF iMatchNQ(Storage$, lszTemp$) THEN
            Res = 1
        END IF

        lszTemp$ =  ENC$(LCASE$(Stk$[2]), ASC(SPC$))

        IF iMatchNQ(Storage$, lszTemp$) THEN
            Res = 2
        END IF

        IF Res > 0 THEN
            i = Ndx
            DO WHILE i > 1 AND Stk$[i] <> ")"
                IF m_iMatchWrd(Stk$[i], "as") THEN
                    IF m_iMatchWrd(Stk$[i+1], "function") THEN
                        IF i+1 = Ndx THEN Stk$[i] = ""  ' remove "as"
                        Stk$[i+1] = ""
                        InsertTokens(Res, 1, "function")
                    ELSEIF m_iMatchWrd(Stk$[i+1], "sub") THEN
                        IF i+1 = Ndx THEN Stk$[i] = ""  ' remove "as"
                        Stk$[i+1] = ""
                        InsertTokens(Res, 1, "sub")
                    END IF
                    CALL RemEmptyTokens
                    EXIT DO
                END IF
                DECR i
            LOOP
        END IF
    END IF

    IF InTypeDef OR m_iMatchWrd(Stk$[1], "declare") OR m_iMatchWrd(Stk$[1], "c_declare") THEN
        IF m_iMatchWrd(Stk$[2], "sub") OR m_iMatchWrd(Stk$[2], "function") THEN
            FOR mm AS INT = 2 TO Ndx
                IF m_iMatchLft(Stk$[mm], "as") AND m_iMatchWrd(Stk$[mm+1], "string") THEN
                    IF *Stk$[mm+2] <> ASC("*") THEN Stk$[mm+1] = "char *"
                END IF
            NEXT
        END IF
    END IF

END SUB ' PreParse





SUB FuncSubTemplate(Tmp AS INT)
    DIM iConc = ++Tmp AS INT
    IF Stk$[++Tmp] <> "<" THEN EXIT SUB
    XFOR INT i = Tmp, INT NotFnd = TRUE WHILE NotFnd = TRUE AND i<= Ndx BY i++
        IF Stk$[i] = "(" THEN
            NotFnd = FALSE
        ELSE
            IF Stk$[i] = "," THEN Stk$[i] = CHR$(18)
            Stk$[iConc] += Stk$[i]
            Stk$[i] = ""
        END IF
    XNEXT
    CALL RemEmptyTokens
END SUB ' FuncSubTemplate




SUB TokenSubstitutions(iSubLoc AS INT)
    '********************************
    ' Start Doing Text Substitutions
    '********************************
    DIM RAW A AS INT
    DIM RAW i AS INT
    DIM RAW iAlphaIdx  AS INT
    DIM RAW j AS INT
    DIM RAW Tmp AS INT
    DIM RAW Keyword$
    DIM RAW CompToken                ' flag that STRUCT, UDT, OR UNION can be handled
    DIM RAW NoTrans                  ' flag don't substitute tokens in DATA statements
    DIM RAW tpBCX AS UDT_SUB_FUNC_TOKENS PTR  ' points to structure holding information
    '                                ' about any word in the BCXWords dictionary
    '******************************************************************************************
    ' Following block added in 4.13 --  Dim XXX as string * 12345
    ' Works in  UDT, GLOBALS, LOCALS, and RAW
    '******************************************************************************************

    i = m_GetAsPosF(1, Ndx)
    IF i THEN
        IF m_iMatchWrd(Stk$[i+1], "string") THEN
            IF Stk$[i+2] = "*" THEN
                Stk$[i]   = "["
                Stk$[i+1] = Stk$[i+3]
                Stk$[i+2] = "]"
                Stk$[i+3] = "as"
                INCR Ndx
                Stk$[Ndx] = "char"
            END IF
        END IF
    END IF

    '******************************************************************************************
    '                                 Convert CHR$() to VCHR$()
    '******************************************************************************************

    CALL Convert_Chr2VChr  ' Added in 829 by MrBcx

    '******************************************************************************************
    '                                  Check for needed transforms
    '******************************************************************************************

    IF InFunction = FALSE THEN
        FOR i = 1 TO Ndx
            IF m_iMatchWrd(Stk$[i], "global") THEN Stk$[i] = "dim"
        NEXT
    END IF

    A = FALSE

    IF m_iMatchWrd(Stk$[1], "pptype") = 0 THEN
        FOR Tmp = 1 TO Ndx
            IF *Stk$[Tmp] = ASC("0") AND NOT _
                m_iMatchWrd(MID$(Stk$[Tmp], 2, 1), "b") AND NOT _
                m_iMatchWrd(MID$(Stk$[Tmp], 2, 1), "x") AND NOT _
                m_iMatchWrd(MID$(Stk$[Tmp], 2, 1), ".") AND NOT _
                m_iMatchWrd(MID$(Stk$[Tmp], 2, 1), "l") THEN
                Stk$[Tmp] = LTRIM$(Stk$[Tmp], 48)   ' allow leading zero's in numbers
                IF ISNULL(Stk$[Tmp]) THEN Stk$[Tmp] = "0"
            END IF

            IF m_iMatchWrd(Stk$[Tmp], "xor") THEN
                Stk$[Tmp] = "^"
            ELSE

                SELECT CASE Stk$[Tmp]
                    CASE "="
                        IF *Stk$[Tmp+1]= ASC(">") THEN
                            Stk$[Tmp]   = ">"
                            Stk$[Tmp+1] = "="
                        END IF
                        IF *Stk$[Tmp+1]= ASC("<") THEN
                            Stk$[Tmp]   = "<"
                            Stk$[Tmp+1] = "="
                        END IF
                    CASE "<"
                        IF *Stk$[Tmp+1]= ASC(">") THEN
                            Stk$[Tmp]   = "!="
                            Stk$[Tmp+1] = ""
                            A = TRUE
                        END IF
                    CASE ">"
                        IF *Stk$[Tmp+1]= ASC("<") THEN
                            Stk$[Tmp]   = "!="
                            Stk$[Tmp+1] = ""
                            A = TRUE
                        END IF
                    CASE "!"
                        IF *Stk$[Tmp+1]= ASC("=") THEN
                            Stk$[Tmp]   = "!="
                            Stk$[Tmp+1] = ""
                            A = TRUE
                        END IF
                END SELECT

            END IF
        NEXT
    END IF

    IF A = TRUE THEN CALL RemEmptyTokens

    '*************************************************************************
    ' Needed when recursively calling parse() after <> has already translated
    ' to != Otherwise, on pass 2, it emits as !== which is NOT desired.
    '*************************************************************************

    CompToken = 0

    FOR Tmp = 1 TO Ndx
        A = LookupVarType(Stk$[Tmp], ADDRESSOF(i))
        IF A = vt_STRUCT OR A = vt_UDT OR A = vt_UNION THEN
            CompToken = 1
        END IF

        IF m_iMatchWrd(Stk$[Tmp], "int") AND Stk$[Tmp+1] = "(" THEN Stk$[Tmp] = "int"

        IF m_iMatchWrd(Stk$[Tmp], "int") AND Stk$[Tmp+1] = "("  AND Stk$[Tmp+2] <> ")"  THEN
            Stk$[Tmp] = "floor"
        ELSEIF m_iMatchWrd(Stk$[Tmp], "integer") THEN
            Stk$[Tmp] = "int"
        ELSE
            IF m_iMatchWrd(Stk$[Tmp], "fint") AND Stk$[Tmp+1]= ")" THEN    ' "fint" is temporary, only used for parsing
                Stk$[Tmp] = "int"
            END IF
        END IF
    NEXT

    '*****************************

    NoTrans = 0

    FOR Tmp = 1 TO Ndx
        IF NoTrans = 1 THEN EXIT FOR
        Keyword$ = LCASE$(Stk$[Tmp])
        tpBCX = GetWordInfo(Keyword$)
        IF tpBCX THEN

            IF (tpBCX->iTRAN_FLAG BAND iSubLoc) <> iSubLoc THEN
                ITERATE
            END IF
            IF (tpBCX->iWordInfo BAND eWI_ReplaceWord) THEN ' just substitute
                IF (tpBCX->iWordInfo BAND eWI_Position1) = 0 THEN
                    Stk$[Tmp] = tpBCX->pszFunctionXName$
                    ITERATE
                ELSEIF Tmp = 1 THEN
                    Stk$[Tmp] = tpBCX->pszFunctionXName$
                    ITERATE
                END IF
            END IF
        END IF

        '*********************************************************************************
        ' This is where we can modify the input stream of tokens that have been parsed.
        ' We can do simple text substitutions, add missing arguments, add casting, set
        ' conditionals, and practically anything else that might be needed.
        '*********************************************************************************

        iAlphaIdx  = INCHR("abcdefghijklmnopqrstuvwxyz$", Keyword$)

        SELECT CASE iAlphaIdx
            CASE 1
                SELECT CASE Keyword$

                    CASE "acosh"
                        Stk$[Tmp] = "acosh"
                        Use_Acosh = Use_Proto = TRUE

                    CASE "addressof"
                        Stk$[Tmp+1] = "&" + Stk$[Tmp+1]
                        Stk$[Tmp] = ""

                    CASE "appactivate"
                        Stk$[Tmp] = "AppActivate"
                        Use_AppActivate = Use_BcxTempStr = Use_Instr = Use_Stristr = TRUE
                        Use_Lcase = Use_Left = Use_UCaseTbl = TRUE

                    CASE "appexename$"
                        Stk$[Tmp] = "AppExeName$()"
                        Use_AppExeName = Use_BcxTempStr = TRUE

                    CASE "appexepath$"
                        Stk$[Tmp] = "AppExePath$()"
                        Convert2SimpleFunction(Tmp)
                        Use_AppExePath = Use_BcxTempStr = TRUE

                    CASE "ansitowide", "ansitowide$", "a2w$", "a2w"
                        Stk$[Tmp] = "AnsiToWide"
                        Use_AnsiToWide = Use_BcxTempStr = TRUE

                    CASE "andalso"                      ' AND can be Boolean or bitwise
                        Stk$[Tmp] = " &&"               ' but ANDALSO is ALWAYS boolean

                    CASE "asc"
                        CALL Process_ASC_Function (Tmp)

                    CASE "arrayputelement"
                        ' INPUT:
                        ' ArrayPutElement(psA,lComVariant,2,0,iCol)
                        ' TRANSFORMS TO:
                        ' BEGINBLOCK
                        ' RAW indicies[2] = {0,iCol} AS long
                        ' SafeArrayPutElement(psA,indicies, (void *)&lComVariant)
                        ' ENDBLOCK
                        DIM sTmp$
                        CALL Add2SplitLines("BEGINBLOCK")   ' EMITS {
                        sTmp$ = "DIM RAW lIndex[" + Stk$[Tmp+6] + "] = {"
                        FOR i = Tmp+8 TO Ndx-1
                            sTmp$ += Stk$[i]
                        NEXT
                        CALL Add2SplitLines(sTmp$ + "} AS long")
                        Stk$[Tmp] = "SafeArrayPutElement"
                        sTmp$ = ""
                        FOR i = 1 TO Tmp+3
                            sTmp$ += Stk$[i]
                        NEXT
                        CALL Add2SplitLines(sTmp$ + "lIndex,(void *)&" + Stk$[Tmp+4] + ")")
                        CALL Add2SplitLines("ENDBLOCK")      ' EMITS }
                        Ndx = 0

                    CASE "arraygetelement"
                        DIM sTmp$
                        CALL Add2SplitLines("BEGINBLOCK")
                        sTmp$ = "DIM RAW lIndex[" + Stk$[Tmp+6] + "] = {"
                        FOR i = Tmp+8 TO Ndx-1
                            sTmp$ += No_Sigil$(Stk$[i])
                        NEXT
                        CALL Add2SplitLines(sTmp$ + "} AS long")
                        Stk$[Tmp] = "SafeArrayGetElement"
                        sTmp$ = ""
                        FOR i = 1 TO Tmp+3
                            sTmp$ += No_Sigil$(Stk$[i])
                        NEXT
                        CALL Add2SplitLines(sTmp$ + "lIndex,(void *)&" + No_Sigil$(Stk$[Tmp+4]) + ")")
                        CALL Add2SplitLines("ENDBLOCK")
                        Ndx = 0

                    CASE "asinh"
                        Stk$[Tmp] = "asinh"
                        Use_Asinh = Use_Proto = TRUE

                    CASE "atanh"
                        Stk$[Tmp] = "atanh"
                        Use_Atanh = Use_Proto = TRUE

                    CASE "auto"
                        IF m_iMatchWrd(Stk$[Tmp+1], "local") THEN
                            Stk$[Tmp] = "dim"
                            Stk$[Tmp+1] = "raw"
                        ELSE
                            Stk$[Tmp] = "auto"
                        END IF

                    CASE  "acode$", "acode"
                        Stk$[Tmp] = "$$WideToAnsi$"
                        Use_WideToAnsi = Use_BcxTempStr = TRUE

                END SELECT

            CASE  2
                SELECT CASE Keyword$

                    CASE "bcopy"
                        Stk$[1] = ""
                        FOR i = Tmp+1 TO Ndx
                            IF m_iMatchWrd(Stk$[i], "to") THEN EXIT FOR
                            Stk$[1] += Stk$[i]  ' Source
                            Stk$[1] += CHR$(1)
                        NEXT
                        Stk$[2] = ""
                        FOR i = i+1 TO Ndx
                            Stk$[2] += Stk$[i]  ' Destination
                            Stk$[2] += CHR$(1)
                        NEXT

                        '*****************************************************************************
                        ' Ian Casey requested the following casts in memmove to support UNICODE
                        '           Tested and working with all compilers - MrBcx --  766
                        '*****************************************************************************
                        Src$  = ""
                        Src$ += "memmove" + CHR$(1)          + "((char*)" + CHR$(1) + "&"     + CHR$(1)
                        Src$ += Stk$[2]   + ",(const char*)" + CHR$(1)    + "&"     + CHR$(1)
                        Src$ += Stk$[1]   + "," + CHR$(1)    + "sizeof"   + CHR$(1) + "("     + CHR$(1)
                        Src$ += Stk$[2]   + ")" + CHR$(1)    + ")"
                        '
                        '*****************************************************************************
                        REMOVE "&*" FROM Src$
                        CALL FastLexer(Src$, CHR$(1), "")

                    CASE "begin"
                        Inject_Local_Bcx_RetVal = TRUE
                        IF m_iMatchWrd(Stk$[Tmp+1], "events") OR m_iMatchWrd(Stk$[Tmp+1], "mdievents") OR m_iMatchWrd(Stk$[Tmp+1], "mdichildevents") THEN
                            IF Indent THEN
                                PRINT REPEAT$(80, "_")
                                PRINT "Possible missing END IF before start of BEGIN"
                                PRINT REPEAT$(80, "_")
                            END IF
                            IF Ndx = 3 THEN
                                Src$ = "FUNCTION|" + Stk$[Tmp+2] + "(hWnd|AS|HWND,Msg|AS|UINT,wParam|AS|WPARAM,lParam|AS|LPARAM)|AS|LRESULT|CALLBACK"
                            ELSE
                                Src$ = "FUNCTION|WndProc(hWnd|AS|HWND,Msg|AS|UINT,wParam|AS|WPARAM,lParam|AS|LPARAM)|AS|LRESULT|CALLBACK"
                            END IF
                            FastLexer(Src$, "|", ",()")
                            Use_Wingui = TRUE
                            EXIT SUB
                        END IF

                    CASE "bel$"
                        Stk$[Tmp] = "BEL$"
                        Use_BEL = Use_BcxTempStr = TRUE

                    CASE "bs$"
                        Stk$[Tmp] = "BS$"
                        Use_BS = Use_BcxTempStr = TRUE

                    CASE "bcxstrsize"
                        Stk$[Tmp] = "BCXSTRSIZE"

                    CASE "bcx_dynacall"
                        Stk$[Tmp] = "BCX_DynaCallA"
                        Use_DynacallCommon = Use_DynacallA = Use_Proto = TRUE

                        '*******************************************************************
                        ' Special Case Handler: Maintain case sensitivity for this structure
                        '*******************************************************************

                    CASE "bcx_font"
                        Stk$[Tmp] = UCASE$(Stk$[Tmp])
                        DIM temp$
                        DIM iNextToken = Tmp + 1
                        Stk$[iNextToken] = No_Sigil$(Stk$[iNextToken])
                        temp$ = UCASE$(Stk$[iNextToken])

                        SELECT CASE temp$
                            CASE ".NAME"         : Stk$[iNextToken] = ".lf.lfFaceName$"
                            CASE ".BOLD"         : Stk$[iNextToken] = ".lf.lfWeight"
                            CASE ".UNDERLINE"    : Stk$[iNextToken] = ".lf.lfUnderline"
                            CASE ".STRIKEOUT"    : Stk$[iNextToken] = ".lf.lfStrikeOut"
                            CASE ".ITALIC"       : Stk$[iNextToken] = ".lf.lfItalic"
                            CASE ".CHARSET"      : Stk$[iNextToken] = ".lf.lfCharSet"
                            CASE ".SIZE", ".RGB" : Stk$[iNextToken] = temp$
                        END SELECT

                    CASE "bcx_setcursor"
                        Stk$[Tmp] = "BCX_SetCursor"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_SetCursor = Use_BCX_InitGUI = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_msgpump"
                        Stk$[Tmp] = "BCX_MsgPump"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_MsgPump = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_wnd"
                        Stk$[Tmp] = "BCX_Wnd"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Wnd = Use_BCX_InitGUI = Use_BCX_SetMetric = Use_BCX_RegWnd = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_framewnd"
                        Stk$[Tmp] = "BCX_FrameWnd"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_FrameWnd = Use_BCX_RegWnd = Use_BCX_InitGUI = Use_BCX_SetMetric = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_setbkgrdbrush"
                        Stk$[Tmp] = "BCX_SetBkGrdBrush"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_SetBkGrdBrush = Use_BCX_InitGUI = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_setclassstyle"
                        Stk$[Tmp] = "BCX_SetClassStyle"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_SetClassStyle = Use_BCX_InitGUI = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_seticon"
                        Stk$[Tmp] = "BCX_SetIcon"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_SetIcon = Use_BCX_InitGUI = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_seticonsm"
                        Stk$[Tmp] = "BCX_SetIconSm"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_SetIconSm = Use_BCX_InitGUI = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_setmetric"
                        Stk$[Tmp] = "BCX_SetMetric"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_SetMetric = Use_BCX_InitGUI = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_initgui"
                        Stk$[Tmp] = "BCX_InitGUI"
                        Use_BCX_InitGUI = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_regwnd"
                        Stk$[Tmp] = "BCX_RegWnd"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_RegWnd = Use_BCX_InitGUI = Use_BCX_SetMetric = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_mdi_msgpump"
                        Stk$[Tmp] = "BCX_MDI_MsgPump"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_MDI_MsgPump = TRUE
                        CALL AddGUIGlobals

                    CASE "bcx_wndclass"
                        Stk$[Tmp] = "BCX_WndClass"
                        CALL AddGUIGlobals

                    CASE "bcxsplitpath$"
                        Stk$[Tmp] = "$$BcxSplitPath$"
                        Use_BcxSplitPath = Use_BcxTempStr = TRUE
                        Use_SysMacros = Use_Proto = TRUE

                    CASE "bcxpath$"
                        Stk$[Tmp] = "BcxPath$()"
                        Convert2SimpleFunction(Tmp)
                        Use_BCX_Path = Use_RegString = TRUE
                        Use_BcxTempStr = TRUE

                    CASE "bcx_pensize"
                        Stk$[Tmp] = "BCX_Pensize"
                        CALL AddPenSizeVariables

                    CASE "bcx_penstyle"
                        Stk$[Tmp] = "BCX_Penstyle"
                        CALL AddPenSizeVariables

                    CASE "bcx_arc"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Arc"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Arc = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_pie"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Pie"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Pie = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_bitmap"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Bitmap"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Bitmap = Use_Proto = TRUE

                    CASE "bcx_blit"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Blit"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Blit = Use_Proto =TRUE

                    CASE "bcx_blit_stretch"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Blit_Stretch"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Blit_Stretch = Use_Proto =TRUE

                    CASE "bcx_blit_sprite"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Blit_Sprite"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Blit_Sprite = Use_Proto = TRUE

                    CASE "bcx_buffer"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_BUFFER"
                        Use_BCX_Buffer = Use_Proto = TRUE
                        CALL AddGrafixVariables

                    CASE "bcx_buffer_start"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_BUFFER_START"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Buffer = Use_Proto = TRUE
                        CALL AddGrafixVariables

                    CASE "bcx_buffer_stop"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_BUFFER_STOP"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Buffer = Use_Proto= TRUE
                        CALL AddGrafixVariables

                    CASE "bcx_olepicture"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_OlePicture"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)          ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_OlePicture = Use_GetResource = Use_Proto = TRUE

                    CASE "bcx_ole_width"
                        Stk$[Tmp] = "BCX_OLE_WIDTH"
                        Use_SysMacros = TRUE

                    CASE "bcx_ole_height"
                        Stk$[Tmp] = "BCX_OLE_HEIGHT"
                        Use_SysMacros = TRUE

                    CASE "bcx_blackrect"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_BlackRect"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Blackrect = Use_Proto = TRUE

                    CASE "bcx_button"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Button"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Button = Use_GetTextSize = Use_Proto = TRUE

                    CASE "bcx_bmpbutton"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_BmpButton"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BmpButton = Use_Proto = TRUE

                    CASE "bcx_splitbutton"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_SplitButton"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_SplitButton = Use_GetTextSize = Use_Proto = TRUE

                    CASE "bcx_bmpwidth"
                        Stk$[Tmp] = "BCX_BmpWidth"
                        Use_BCX_BmpWidth = Use_Proto = TRUE

                    CASE "bcx_bmpheight"
                        Stk$[Tmp] = "BCX_BmpHeight"
                        Use_BCX_BmpHeight = Use_Proto = TRUE

                    CASE "bcx_checkbox"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Checkbox"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Checkbox = Use_GetTextSize = Use_Proto = TRUE

                    CASE "bcx_combobox"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Combobox"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Combobox = Use_Proto = TRUE

                    CASE "bcx_console"
                        Stk$[Tmp] = "hConsole"
                        Use_Console = Use_Proto = TRUE

                    CASE "bcx_com_error"
                        Stk$[Tmp] = "COM_BCX_ERROR"
                        ComSwitchON = Use_COM = TRUE

                    CASE "bcx_control"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Control"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Control = Use_Proto = TRUE

                    CASE "bcx_colordlg"
                        Stk$[Tmp] = "BCX_ColorDlg"
                        IF NOT INCHR(Src$, "(") THEN Stk$[Tmp] = Stk$[Tmp] + "()"
                        Use_BCX_Colordlg = Use_Hook = Use_BcxTempStr = Use_Proto = TRUE

                    CASE "bcx_cursor"
                        Stk$[Tmp] = "BCX_Cursor"
                        Use_BCX_Cursor = Use_SysMacros = TRUE

                    CASE "bcx_datepick"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_DatePick"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Datepick = Use_Proto = TRUE

                    CASE "bcx_edit"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Edit"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Edit = Use_Proto = TRUE

                    CASE "bcx_circle"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Circle"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Circle = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_ellipse"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Ellipse"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Ellipse = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_mdialog"
                        CALL AddBcxFontVar
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        IF InWinMain AND NOT Use_BCXMDialog THEN
                            FPRINT FP_WRITE, Scoot$, "BCX_hInstance = hInst;"
                            iEmitVarGroup = iEmitVarGroup BOR (eFontGroup BOR eBCX_hInstance)
                        END IF
                        Stk$[Tmp] = "BCX_MDialog"
                        IF Tmp = 3 THEN Stk$[Tmp+1] = "((DLGPROC)"
                        Use_BCXDialogCommon = Use_BCXMDialog = Use_Proto = TRUE

                    CASE "bcx_dialog"
                        CALL AddBcxFontVar
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Stk$[Tmp] = "BCX_Dialog"
                        IF Tmp = 3 THEN Stk$[Tmp+1] = "((DLGPROC)"
                        Use_BCXDialogCommon = Use_BCXDialog = Use_Proto = TRUE

                    CASE "bcx_form"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Form"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Form = Use_Proto = Use_MainEvent = TRUE

                        IF NOT Use_BCX_Class_Info THEN
                            Use_BCX_Class_Info = TRUE
                            iEmitVarGroup = iEmitVarGroup BOR (eFontGroup BOR eClassName)
                        END IF

                    CASE "bcx_fontdlg"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_FontDlg"
                        IF Tmp = Ndx THEN  Stk$[Tmp] += "()"
                        Use_BCX_Fontdlg = TRUE
                        Use_Hook = Use_BcxTempStr = Use_Proto = TRUE

                    CASE "bcx_floodfill"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_FloodFill"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Floodfill = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_get"
                        Stk$[Tmp] = "BCX_Get"
                        Use_BCX_Get = Use_Proto = TRUE

                    CASE "bcx_get_window_height"
                        Stk$[Tmp] = "BCX_Get_Window_Height"
                        Use_BCX_Get_Window_Height = Use_Proto = TRUE

                    CASE "bcx_get_window_width"
                        Stk$[Tmp] = "BCX_Get_Window_Width"
                        Use_BCX_Get_Window_Width = Use_Proto = TRUE

                    CASE "bcx_get_text$"
                        Stk$[Tmp] = "$$BCX_Get_Text$"
                        Use_GetText = Use_BcxTempStr = TRUE

                    CASE "bcx_getpixel"
                        Stk$[Tmp] = "BCX_Getpixel"
                        Use_BCX_Getpixel = Use_BcxTempStr = TRUE

                    CASE "bcx_gradient"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Gradient"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Gradient = Use_Proto = TRUE


                    CASE "bcx_grayrect"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_GrayRect"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Grayrect = Use_Proto = TRUE

                    CASE "bcx_group"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Group"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Group = Use_Proto = TRUE

                    CASE "bcx_icon"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Icon"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Icon = Use_GetResource = Use_Proto = TRUE

                    CASE "bcx_input"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Input"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Input = Use_Proto = TRUE

                    CASE "bcx_label"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Label"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Label = Use_GetTextSize = Use_Proto = TRUE

                    CASE "bcx_line"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Line"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Line = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_polar_line"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Polar_Line"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Line = Use_Proto = TRUE
                        Use_BCX_Polar_Line = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_lineto"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Lineto"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Lineto = Use_Proto = TRUE
                        CALL AddPenSizeVariables


                    CASE "bcx_triangle"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Triangle"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Triangle = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_listbox"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Listbox"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Listbox = Use_Proto = TRUE

                    CASE "bcx_listview"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_ListView"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Listview = Use_Proto = TRUE

                    CASE  "bcx_loadbmp"
                        Stk$[Tmp] = "BCX_LoadBMP"
                        Use_BCX_LoadBMP = Use_Proto = TRUE

                    CASE  "bcx_loadimage"
                        Stk$[Tmp] = "BCX_LoadImage"
                        Use_BCX_LoadImage = Use_GetResource = Use_Proto = TRUE

                    CASE "bcx_print"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Print"
                        Use_BCX_Print = Use_Proto = TRUE

                    CASE "bcx_printex"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Printex"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Printex = Use_Proto = TRUE

                    CASE "bcx_polygon"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Polygon"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Polygon = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_polybezier"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_PolyBezier"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_PolyBezier = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_polyline"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Polyline"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Polyline = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_preset"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Preset"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Preset = Use_Proto = TRUE

                    CASE "bcx_pset"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Pset"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Pset = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_polar_pset"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Polar_Pset"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Pset = Use_Proto = TRUE
                        Use_BCX_Polar_Pset = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_polar_line"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Polar_Line"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Line = Use_Proto = TRUE
                        Use_BCX_Polar_Line = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_progressbar"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_ProgressBar"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_ProgressBar = Use_Proto = TRUE

                    CASE "bcx_put"
                        Stk$[Tmp] = "BCX_Put"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Put = Use_Proto = TRUE

                    CASE "bcx_radio"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Radio"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Radio = Use_GetTextSize = Use_Proto = TRUE

                    CASE "bcx_rectangle"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Rectangle"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Rectangle = Use_BcxTempStr = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_resize"
                        Stk$[Tmp] = "BCX_RESIZE"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Resize = Use_SysMacros = TRUE

                    CASE "bcx_richedit"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_RichEdit"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Richedit = Use_Proto = TRUE

                    CASE "bcx_roundrect"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Roundrect"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Roundrect = Use_Proto = TRUE
                        CALL AddPenSizeVariables

                    CASE "bcx_slider"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Slider"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Slider = Use_Label = Use_GetTextSize = Use_Proto = TRUE

                    CASE "bcx_splitter"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Splitter"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Splitter = Use_Proto = Use_Modstyle = TRUE

                    CASE "bcx_setsplitpos"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_SetSplitPos"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Splitter = Use_Proto = Use_Modstyle = TRUE

                    CASE "bcx_tab"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Tab"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Tab = Use_Proto = TRUE

                    CASE "bcx_toolbar"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Toolbar"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_Toolbar = Use_Proto = TRUE

                    CASE "bcx_updown"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_UpDown"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_UpDown = Use_Proto = TRUE

                    CASE "bcx_version$"
                        Stk$[Tmp] = ENC$(Version$)

                    CASE "bcx_get_updown"
                        Stk$[Tmp] = "BCX_Get_UpDown"
                        Use_BCX_Get_UpDown = Use_Proto = Use_BcxTempStr = TRUE

                    CASE "bcx_set_form_color"
                        Stk$[Tmp] = "BCX_Set_Form_Color"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_SetFormColor = Use_Proto = TRUE


                    CASE "bcx_setclientsize"
                        Use_Setclientsize = Use_Proto = TRUE
                        Stk$[Tmp] = "BCX_SetClientSize"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF

                    CASE "bcx_set_font"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Set_Font"
                        Use_SetFont = Use_Proto = TRUE
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF

                    CASE "bcx_setcolor"
                        Stk$[Tmp] = "Set_Color"
                        DIM iPCnt = GetNumArgs(Tmp+2)

                        IF iPCnt = 1 THEN
                            InsertTokens(Ndx-1, 4, ",", "(HDC)wParam", ",", "(HWND)lParam")
                        ELSEIF iPCnt = 2 THEN
                            InsertTokens(Ndx-1, 2, ",", "(HWND)lParam")
                        END IF
                        Use_SetColor = Use_Proto = TRUE

                    CASE "bcx_set_text"
                        ' CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Set_Text"
                        Use_SetText = Use_Proto = TRUE
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF

                    CASE "bcx_status"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Status"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Status = Use_Proto = TRUE

                    CASE "bcx_stricmp"
                        Stk$[Tmp] = "bcx_stricmp"
                        Use_BCX_stricmp = TRUE

                    CASE "bcx_setconsolesize"
                        Stk$[Tmp] = "BCX_SetConsoleSize"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Consolesize = Use_Console = Use_Proto = TRUE

                    CASE "bcx_pushconsolesize"
                        IF Stk$[Tmp+1] <> "(" THEN Stk$[Tmp] = "BCX_PushConsoleSize()"
                        Use_Consolesize = Use_Console = Use_Proto = TRUE

                    CASE "bcx_popconsolesize"
                        IF Stk$[Tmp+1] <> "(" THEN Stk$[Tmp] = "BCX_PopConsoleSize()"
                        Use_Consolesize = Use_Console = Use_Proto = TRUE

                    CASE "bcx_tabselect"
                        Stk$[Tmp] = "BCX_TabSelect(hWnd, lParam)"
                        Use_BCX_Tab = Use_Proto = TRUE

                    CASE "bcx_tile"
                        Use_BCX_Tile = Use_Proto = TRUE
                        Stk$[Tmp] = "BCX_Tile"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF

                    CASE "bcx_thread", "bcx_threadwait", "bcx_threadsuspend", "bcx_threadresume", "bcx_threadkill", "bcx_threadend"
                        Stk$[Tmp] = UCASE$(Stk$[Tmp])
                        Use_Threads = Use_SysMacros = TRUE

                    CASE "bcx_tooltip"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_ToolTip"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BCX_ToolTip = Use_Proto = TRUE
                        CALL AddGlobal("BCX_hWnd_ToolTip", vt_HWND)

                    CASE "bcx_tempstr"
                        Stk$[Tmp] = "BCX_TempStr"
                        Use_BcxTempStr = TRUE

                    CASE "bcx_treeview"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_Treeview"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Treeview = Use_Proto = TRUE

                    CASE "bcx_whiterect"
                        CALL AddBcxFontVar
                        Stk$[Tmp] = "BCX_WhiteRect"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Whiterect = Use_Proto = TRUE

                    CASE "bcx_clsid$"
                        Stk$[Tmp] = "BCX_CLSID$"
                        Use_Proto = Use_BcxTempStr = TRUE
                        Use_COM_CLSID = Use_AnsiToWide = Use_WideToAnsi = Use_BcxTempStr = TRUE


                    CASE "bcx_dispatchobject"
                        ' x = DispatchObject(unknown,tf)
                        ' BCX_DispatchObject (unknown, &x, tf)
                        Use_BcxTempStr = TRUE
                        ComSwitchON = Use_COM  = TRUE
                        Use_COM_CreateObject   = TRUE
                        Use_COM_DispatchObject = TRUE
                        Use_COM_GetObject      = TRUE
                        Use_COM_GetProperty    = TRUE
                        Use_COM_InvokeMethod   = TRUE
                        Use_COM_SafeArray      = TRUE
                        Use_COM_SetProperty    = TRUE
                        Use_COM_UsesConversion = TRUE

                        DIM szObj$ : szObj$ = "&"
                        DIM szUnknown$
                        DIM szRelease$
                        DIM iTobj AS INT

                        iTobj = 1
                        DO WHILE Stk$[iTobj] <> "="
                            szObj$ += Stk$[iTobj]
                            INCR iTobj
                        LOOP
                        iTobj = Tmp+2
                        DO WHILE Stk$[iTobj] <> "," AND Stk$[iTobj] <> ")"
                            szUnknown$ += Stk$[iTobj]
                            INCR iTobj
                        LOOP
                        IF Stk$[iTobj] = ")" THEN
                            szRelease$ = "TRUE"
                        ELSE
                            szRelease$ = Stk$[iTobj+1]
                        END IF

                        Stk$[1] = "BCX_DispatchObject"
                        Stk$[2] = "("
                        Stk$[3] = szUnknown$
                        Stk$[4] = ","
                        Stk$[5] = szObj$
                        Stk$[6] = ","
                        Stk$[7] = szRelease$
                        Stk$[8] = ")"
                        Ndx = 8

                    CASE "bff$"
                        Stk$[Tmp] = "$$BFF$"
                        Use_Bff = Use_BcxTempStr = TRUE

                    CASE "bin$"
                        Stk$[Tmp] = "$$Bin$"
                        Use_Bin = Use_BcxTempStr = TRUE

                    CASE "bin2dec"
                        Stk$[Tmp] = "Bin2Dec"
                        Use_Bin2dec = Use_Proto = TRUE

                    CASE "bool$"
                        Stk$[Tmp] = "$$BoolStr$"
                        Use_Boolstr = Use_BcxTempStr = TRUE

                    CASE "bool"
                        Stk$[Tmp] = "BOOL"

                    CASE "boolean"
                        Stk$[Tmp] = "BOOLEAN"

                    CASE "band"
                        IF *Stk$[Tmp+1] = ASC("=") THEN
                            Stk$[Tmp+1] = "&="
                            Stk$[Tmp] = ""
                        ELSE
                            Stk$[Tmp] = " & "
                        END IF

                    CASE "bnot"
                        Stk$[Tmp] = " BNOT "
                        Use_Bnot  = Use_SysMacros = TRUE


                    CASE "byte_at"   ' Helps BCX translate statements like: IF a$[1][2] then ...
                        Stk$[Tmp] = "BYTE_AT"
                        Use_ByteAt = Use_SysMacros = TRUE


                    CASE "bor"
                        IF *Stk$[Tmp+1] = ASC("=") THEN
                            Stk$[Tmp+1] = "|="
                            Stk$[Tmp] = ""
                        ELSE
                            Stk$[Tmp] = "|"
                        END IF

                END SELECT

            CASE 3
                SELECT CASE Keyword$

                    CASE "case"
                        DIM nBrace
                        DIM CntMarker = 2
                        j = 0
                        FOR i = 2 TO Ndx
                            IF INCHR("([", Stk$[i]) THEN INCR nBrace
                            IF INCHR(")]", Stk$[i]) THEN DECR nBrace
                            IF Stk$[i] = ","  THEN
                                IF nBrace = 0 THEN CntMarker = i + 1
                            END IF
                            IF m_iMatchWrd(Stk$[i], "to") THEN
                                j = 1
                                Stk$[i] = "&&" + CHR$(1) + "<="
                                Stk$[CntMarker] = ">=" + CHR$(1) + Stk$[CntMarker]
                            END IF
                        NEXT

                        IF j = 1 THEN
                            Src$ = ""
                            FOR i = 1 TO Ndx
                                Src$ += Stk$[i] + CHR$(1)
                            NEXT
                            CALL FastLexer(Src$, CHR$(1), "")
                        END IF

                    CASE "cast"
                        Stk$[Tmp] = " CAST "
                        Use_Cast = Use_SysMacros = TRUE



                    CASE "callback"
                        Stk$[Tmp] = "CALLBACK"
                        IF Tmp = 1 THEN
                            IF Ndx > 5 THEN Warning("Extra Callback code truncated", 1)
                            Src$ = "FUNCTION|" + Stk$[3] + "(hWnd|AS|HWND,Msg|AS|UINT,wParam|AS|WPARAM,lParam|AS|LPARAM)|AS|LRESULT|CALLBACK"
                            FastLexer(Src$, "|", ",()")
                            CallBackFlag = TRUE
                        END IF

                    CASE "callwindowproc"
                        '*****************************
                        '    CallWindowProc HELPER
                        '*****************************
                        Stk$[Tmp] = "CallWindowProc"
                        IF Stk$[Tmp+3] <> "WNDPROC" THEN InsertTokens(Tmp+1, 3, "(", "WNDPROC", ")")


                    CASE "com"
                        Stk$[Tmp] = "COM"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        ComSwitchON = Use_COM = TRUE
                        Use_COM_CreateObject   = TRUE
                        Use_COM_DispatchObject = TRUE
                        Use_COM_GetObject      = TRUE
                        Use_COM_GetProperty    = TRUE
                        Use_COM_InvokeMethod   = TRUE
                        Use_COM_SafeArray      = TRUE
                        Use_COM_SetProperty    = TRUE
                        Use_COM_UsesConversion = TRUE


                    CASE "createobject"
                        ComSwitchON = Use_COM_UsesConversion = Use_COM_CreateObject = Use_COM = TRUE
                        IF Stk$[2] = "[" THEN
                            ' object from an array of objects
                            ' SET oObj [ iii ] = createobject ("Excel.Application")
                            ' BCX_CreateObject ("Excel.Application", & oTmp[iii]);
                            DIM iii = 2
                            DO WHILE Stk$[iii] <> "="
                                Stk$[1] += Stk$[iii]
                                *Stk$[iii] = 0
                                INCR iii
                            LOOP
                            CALL RemEmptyTokens
                        END IF
                        Stk$[3] = Stk$[5]
                        sprintf(Stk[5], "&%s", Stk[1])
                        Stk$[1] = "BCX_CreateObject"
                        Stk$[2] = "("
                        Stk$[4] = ","

                    CASE "concat"
                        Stk$[Tmp] = "strcat"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF

                    CASE "containedin"
                        Stk$[Tmp] = "containedin"
                        Use_ContainedIn = Use_BCX_stricmp = TRUE

                    CASE "cr$"
                        Stk$[Tmp] = "CR$"
                        Use_CR = Use_BcxTempStr = TRUE

                    CASE "close"
                        DIM iNextToken = Tmp + 1
                        IF *Stk$[iNextToken] = ASC("#") THEN
                            Stk$[iNextToken] = MID$(Stk$[iNextToken], 2)
                        END IF

                    CASE "closedialog"
                        Ndx = 1
                        IF ModDialogEvt THEN
                            Stk$[Ndx] = "EndDialog(hWnd,0)"
                        ELSE
                            Stk$[Ndx] = "DestroyWindow(hWnd)"
                        END IF

                    CASE "cvd"
                        Stk$[Tmp] ="CVD"
                        Use_Cvd = Use_Proto = TRUE

                    CASE "cvi"
                        Stk$[Tmp] ="CVI"
                        Use_Cvi = Use_Proto = TRUE

                    CASE "cvl"
                        Stk$[Tmp] ="CVL"
                        Use_Cvl = Use_Proto = TRUE

                    CASE "cvld"
                        Stk$[Tmp] ="CVLD"
                        Use_Cvld = Use_Proto = TRUE

                    CASE "cvs"
                        Stk$[Tmp] ="CVS"
                        Use_Cvs = Use_Proto = TRUE

                    CASE "chrtoutf8$"
                        Stk$[Tmp] = "ChrToUtf8$"
                        Use_Chrtoutf8 = Use_BcxTempStr = TRUE

                    CASE "crlf$"
                        Stk$[Tmp] = "CRLF$"
                        Use_Crlf = Use_BcxTempStr = TRUE

                    CASE "createregstring"
                        Stk$[Tmp] = "CreateRegString"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_CreateRegString = Use_BcxTempStr = TRUE

                    CASE "createregint"
                        Stk$[Tmp] = "CreateRegInt"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_CreateRegInt = Use_BcxTempStr = TRUE

                    CASE "cdbl"
                        Stk$[Tmp] = "CDBL"
                        Use_Cdbl = Use_SysMacros = TRUE

                    CASE "center"
                        Stk$[Tmp] = "Center"
                        Use_Center = Use_Proto = TRUE
                        IF Ndx >= 2 AND Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF

                    CASE "cint"
                        Stk$[Tmp] = "Cint"
                        Use_Cint = Use_Proto = TRUE

                    CASE "cldbl"
                        Stk$[Tmp] = "CLDBL"
                        Use_Cldbl = Use_SysMacros = TRUE

                    CASE "clng"
                        Stk$[Tmp] = "CLNG"
                        Use_Clng = Use_Proto = TRUE

                    CASE "clipboard_gettext", "clipboard_gettext$"
                        Stk$[Tmp] = "Clipboard_GetText$()"
                        Convert2SimpleFunction(Tmp)
                        Use_Clip_Gettext = Use_BcxTempStr = TRUE

                    CASE "clipboard_getbitmap"
                        Stk$[Tmp] = "Clipboard_GetBitmap()"
                        Convert2SimpleFunction(Tmp)
                        Use_Clip_Getbitmap = TRUE

                    CASE "clipboard_gettextsize"
                        Stk$[Tmp] = "Clipboard_GetTextSize()"
                        Convert2SimpleFunction(Tmp)
                        Use_Clip_Gettextsize = Use_Proto = TRUE

                    CASE "clipboard_settext"
                        Stk$[Tmp] = "Clipboard_SetText"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Clip_Settext = TRUE

                    CASE "clipboard_setbitmap"
                        Stk$[Tmp] = "Clipboard_SetBitmap"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Clip_Setbitmap = TRUE

                    CASE "clipboard_reset"
                        Stk$[Tmp] = "Clipboard_Reset"
                        Use_Clip_Reset = Use_SysMacros = TRUE

                    CASE "cls"
                        Stk$[Tmp] = "cls"
                        Use_Cls = TRUE
                        Use_Locate = Use_Console = Use_Proto = Use_Cursor = TRUE

                    CASE "color", "color_fg", "color_bg"
                        Stk$[Tmp] = LCASE$(Stk$[Tmp])
                        Use_Color = Use_Console = Use_Proto = TRUE

                    CASE "command$"
                        Use_Command = Use_BcxTempStr = TRUE
                        Stk$[Tmp] = "command$(-1)"
                        IF Stk$ [Tmp+1] = "(" THEN
                            Stk$ [Tmp]= "command$"
                        END IF

                    CASE "comboboxloadfile"
                        Stk$[Tmp] = "ComboBoxLoadFile"
                        Use_ComboBoxLoadFile = TRUE
                        Use_BcxTempStr = TRUE
                        Use_Proto = TRUE
                        Use_Trim  = TRUE



                    CASE "cbool"
                        Stk$[Tmp] = "CBOOL"
                        Use_Cbool = Use_SysMacros = TRUE
                        LOCAL iii, t, expos = 0
                        DIM RAW funcPtr AS UDT_ARG_COMMAS_STORAGE
                        CLEAR(funcPtr)
                        IF SepFuncArgs(Tmp+1, ADDRESSOF(funcPtr), TRUE) = 0 THEN
                            CALL Abort("No argument specified in CBOOL")
                        END IF

                        FOR iii = funcPtr.CommaPos[0] TO funcPtr.CommaPos[1]
                            t = INCHR("!<>=", Stk$[iii])
                            IF t THEN
                                IF t < 4 THEN
                                    IF Stk$[iii+1] = "=" THEN
                                        Stk$[iii] = Stk$[iii] + Stk$[iii+1]
                                        Stk$[iii+1] = ""
                                    ELSEIF t = 1 AND Stk$[iii] <> "!=" THEN
                                        ITERATE
                                    END IF
                                ELSE
                                    IF Stk$[iii+1] <> "=" THEN Stk$[iii] = "=="
                                END IF
                                expos = iii
                                EXIT FOR
                            END IF
                        NEXT

                        t = DataType(Stk$[expos-1])
                        IF t = vt_STRLIT OR t = vt_STRVAR THEN
                            IF expos THEN
                                Stk$[Tmp+1] += "strcmp("
                                Stk$[funcPtr.CommaPos[1]] = ")" + Stk$[expos] + "0)"
                                Stk$[expos] = ","
                                Src$ = ""
                                FOR iii = 1 TO Ndx
                                    Src$ += Stk$[iii]
                                    Src$ += SPC$
                                NEXT
                                FastLexer(Src$, SPC$, "(),")
                            END IF
                        END IF

                    CASE "csng"
                        Stk$[Tmp] = "CSNG"
                        Use_Csng = Use_SysMacros = TRUE

                    CASE "cpad$"
                        Stk$[Tmp] = "cpad$"
                        Use_Cpad = Use_Join = Use_BcxTempStr = TRUE

                    CASE "cursorx"
                        Stk$[Tmp] = "Pos()"
                        Use_Pos = Use_Proto = TRUE

                    CASE "csrlin", "cursory"
                        Stk$[Tmp]  = "Csrlin()"
                        Use_Csrlin = Use_Proto  = TRUE

                    CASE "curdir$"
                        Stk$[Tmp] = "curdir$()"
                        Convert2SimpleFunction(Tmp)
                        Use_Curdir = Use_BcxTempStr = TRUE

                    CASE "c_declare"
                        CallType$ = "__cdecl "
                        Stk$[Tmp] = "declare"
                        IF m_iMatchWrd(Stk$[4], "lib") THEN
                            NoTypeDeclare = FALSE
                        ELSE
                            NoTypeDeclare = TRUE
                        END IF

                END SELECT

            CASE 4
                SELECT CASE Keyword$

                    CASE "datacount"
                        Stk$[Tmp] = "DATACOUNT"
                        Use_Datacount = Use_SysMacros = TRUE

                    CASE "declare"
                        CallType$ = "__stdcall "
                        Stk$[Tmp] = "declare"
                        IF NOT m_iMatchWrd(Stk$[4], "lib") THEN
                            NoTypeDeclare = TRUE
                        ELSE
                            NoTypeDeclare = FALSE
                        END IF

                    CASE "degtorad"
                        Stk$[Tmp] = "DegToRad"
                        Use_DegToRad = Use_SysMacros = TRUE

                    CASE "dq$"
                        Stk$[Tmp] = "DQ$"
                        Use_DQ = Use_BcxTempStr = TRUE

                    CASE "ddq$"
                        Stk$[Tmp] = "DDQ$"
                        Use_DDQ = Use_BcxTempStr = TRUE

                    CASE "data"
                        NoTrans = 1

                    CASE "date$"
                        IF Stk$[Tmp+1] <> "(" THEN
                            Stk$[Tmp] = "date$()"
                        ELSE
                            Stk$[Tmp] = "date$"
                        END IF
                        Use_Date = Use_BcxTempStr = TRUE

                    CASE "del$"
                        Stk$[Tmp] = "del$"
                        Use_Del = Use_BcxTempStr = Use_Proto = TRUE

                    CASE "deleteregkey"
                        Stk$[Tmp] = "DeleteRegKey"
                        Use_DeleteRegKey = Use_BcxTempStr = TRUE

                    CASE "diskfree"
                        Stk$[Tmp] = "(UINT64) DiskFree"
                        Use_Diskfree = Use_Proto = TRUE

                    CASE "diskused"
                        Stk$[Tmp] = "(UINT64) DiskUsed"
                        Use_Diskused = Use_Proto = TRUE

                    CASE "disksize"
                        Stk$[Tmp] = "(UINT64) DiskSize"
                        Use_Disksize = Use_Proto = TRUE

                    CASE "dialog"
                        Inject_Local_Bcx_RetVal = TRUE

                        IF m_iMatchWrd(Stk$[1], "begin") THEN
                            IF Ndx = 4 AND m_iMatchWrd(Stk$[3], "as") THEN
                                InDialogEvt = Use_BCXDialogCommon = TRUE
                            ELSEIF Ndx = 5 AND m_iMatchWrd(Stk$[4], "as") THEN
                                ' BEGIN MODAL DIALOG AS DialogOne
                                ' function 'Stk$[Ndx]' (hWnd AS HWND, Msg AS UINT, wParam AS WPARAM, lParam AS LPARAM) AS INT_PTR CALLBACK
                                ' INT_PTR CALLBACK DialogOne (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
                                ModDialogEvt = Use_BCXDialogCommon = TRUE
                            ELSE
                                CALL Abort("Malformed Begin Dialog")
                            END IF
                            Src$ = "function " + Stk$[Ndx] + "(hWnd AS HWND,Msg AS UINT,wParam AS WPARAM,lParam AS LPARAM) AS INT_PTR CALLBACK"
                            FastLexer(Src$, SPC$, "(),")
                        END IF

                    CASE "destroysafearray"
                        Stk$[Tmp] = "DestroySafeArray"
                        Use_SafeArrays = TRUE

                    CASE "doevents"
                        Stk$[Tmp] = "DoEvents()"
                        Convert2SimpleFunction(Tmp)
                        Use_Doevents = Use_Proto = TRUE

                    CASE "drawtransbmp"
                        Stk$[Tmp] = "DrawTransBMP"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_DrawTransBMP = Use_Proto = TRUE


                    CASE "draw"
                        Stk$[Tmp] = "Draw"
                        IF Tmp = Ndx THEN Abort ("DRAW command expects a string argument")
                        CALL AddPenSizeVariables
                        Use_BCX_Floodfill = Use_BCX_Line = Use_BCX_Lineto = Use_BCX_Preset = TRUE
                        Use_BcxTempStr = Use_Bitmap = Use_DSplit = Use_Draw = Use_DrawStr = TRUE
                        Use_DynamicA = Use_Instr = Use_Left = Use_Mid = Use_Proto = Use_QBColor = TRUE
                        Use_Remove = Use_Replace = Use_Stristr = Use_UCaseTbl = Use_Ucase = Use_Val = TRUE
                        Use_SysMacros = Use_Val = TRUE

                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF

                    CASE "download"
                        IF Tmp = Ndx THEN Abort ("DOWNLOAD command expects two string arguments")
                        Stk$[Tmp] = "Download"
                        Use_Download = Use_Proto = TRUE


                    CASE "downloadtostr", "downloadtostr$"
                        IF Tmp = Ndx THEN Abort ("DOWNLOADTOSTR command expects one string arguments")
                        Stk$[Tmp] = "DownloadToStr"
                        Use_Downloadtostr = Use_Download = TRUE
                        Use_LoadFile = Use_BcxTempStr = Use_Lof = TRUE
                        Use_Exist = Use_TempFileName = TRUE
                        Use_LoadFile = Use_Get = Use_Tempdir = TRUE
                        Use_SysMacros = Use_Proto = TRUE


                    CASE "dsplit"
                        Stk$[Tmp] = "DSplit"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BcxTempStr = TRUE
                        Use_UCaseTbl = TRUE
                        Use_Stristr = TRUE
                        Use_Proto  = TRUE
                        Use_DSplit = TRUE
                        Use_Remove = TRUE
                        Use_Mid    = TRUE
                        Use_Left   = TRUE
                        Use_Instr  = TRUE
                        Use_Replace = TRUE

                END SELECT

            CASE  5
                SELECT CASE Keyword$

                    CASE "enddraw"
                        Stk$[Tmp] = "EndDraw"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Draw = TRUE

                    CASE "endmodal"
                        Stk$[Tmp] = "EndModal"
                        Use_Show = Use_SysMacros = Use_ShowModal = Use_EndModal = TRUE

                    CASE "editloadfile"
                        Stk$[Tmp] = "EditLoadFile"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BcxTempStr = TRUE
                        Use_SysMacros = TRUE
                        Use_Elf     = TRUE
                        Use_Exist   = TRUE
                        Use_Get     = TRUE
                        Use_Lof     = TRUE
                        Use_Proto   = TRUE
                        Use_Join    = TRUE


                    CASE "enc$"
                        Stk$[Tmp] = "$$enc$"
                        Use_Enclose = Use_BcxTempStr = TRUE

                    CASE "extract$"
                        Stk$[Tmp] = "$$extract$"
                        Use_Extract = Use_BcxTempStr = TRUE

                    CASE "extractany$"
                        Stk$[Tmp] = "$$extractany$"
                        Use_ExtractAny = Use_BcxTempStr = TRUE

                    CASE "eof$"
                        Stk$[Tmp] = "EF$"
                        Use_EF = Use_BcxTempStr = TRUE

                    CASE "eof"
                        Stk$[Tmp] = "EoF"
                        Use_Eof = Use_BcxTempStr = TRUE
                        REMOVE "#" FROM Stk$[Tmp+2]
                        IF Stk$[Tmp+2] = "" THEN CALL Abort ("Bad EOF Argument")
                        IF DataType(Stk$[Tmp+2]) = vt_NUMBER THEN
                            Stk$[Tmp+2]= "FP" + Stk$[Tmp+2]
                        END IF

                    CASE "equalto"
                        Stk$[Tmp] = " EqualTo "
                        Use_EqualTo = Use_SysMacros = TRUE

                    CASE "esc$"
                        Stk$[Tmp] = "ESC$"
                        Use_ESC = Use_BcxTempStr = TRUE

                    CASE "enum"
                        DIM iNamedEnum = 0
                        IF Tmp = 3 THEN
                            iNamedEnum = m_iMatchWrd(Stk$[Tmp-1], "as")
                        ELSE
                            IF Ndx = 3 THEN
                                iNamedEnum = m_iMatchWrd(Stk$[Tmp+1], "as")
                            END IF
                        END IF
                        IF Ndx = 1 OR iNamedEnum THEN
                            Use_EnumFile = TRUE
                            DIM szNameOfEnum$
                            '******************************************************
                            '     We're dealing with a ENUM - END ENUM block
                            '******************************************************
                            DIM EnumFlag = FALSE
                            FPRINT FP_ENU, ""
                            IF iNamedEnum THEN
                                IF Tmp = 3 THEN
                                    szNameOfEnum$ = Stk$[Tmp-2]
                                    FPRINT FP_ENU, "typedef enum _", szNameOfEnum$
                                ELSE
                                    szNameOfEnum$ = Stk$[Tmp+2]
                                    FPRINT FP_ENU, "typedef enum _", szNameOfEnum$
                                END IF
                                szNameOfEnum$ = SPC$ + szNameOfEnum$
                            ELSE
                                szNameOfEnum$ = ""
                                FPRINT FP_ENU, "enum"
                            END IF
                            FPRINT FP_ENU, "  {"
                            Src$ = ""
                            DO WHILE NOT m_iMatchLft(Src$, "end ")

                                IF EOF(SourceFile) THEN
                                    CALL Abort ("Unbalanced ENUM")
                                END IF

                                LINE INPUT SourceFile, Src$
                                INCR LineNum[FileNdx]
                                CALL Sanitize_Code(Src$)
                                IF m_iMatchLft(Src$, "$comme") THEN
                                    DIM RAW ccc
                                    CALL Docomment(Src$, ADDRESSOF(ccc))
                                    ITERATE
                                END IF
                                Src$ = TRIM$(Src$)
                                IF ISNULL(Src$) THEN ITERATE ' line starts with comment
                                IF LEFTSTR(Src$ + SPC$, "end ", TRUE) THEN
                                    EXIT DO
                                ELSE
                                    IF EnumFlag = FALSE THEN
                                        EnumFlag = TRUE
                                    ELSE
                                        FPRINT FP_ENU, ","
                                    END IF
                                END IF
                                FPRINT FP_ENU, "    ", RTRIM$(Src$); ' Suppress CRLF
                            LOOP
                            Src$ = ""
                            Ndx = 0
                            FPRINT FP_ENU, ""
                            FPRINT FP_ENU, "  }", szNameOfEnum$, ";\n"
                            EXIT SUB
                        END IF
                        DIM iEquallLoc = Tmp+2
                        IF Stk$[iEquallLoc] = "=" THEN
                            ' enum ONE=3
                            ' enum ONE{ONE=3};
                            Stk$[Tmp] = "enum "
                            CALL InsertTokens(iEquallLoc-1, 2, "{", Stk$[Tmp+1])
                            Stk$[++Ndx] = "}"
                            EXIT SUB
                        END IF

                        '*************************************************************
                        '  We're dealing with a smaller, single line ENUM statement
                        '*************************************************************

                        Stk$[1] = "enum {"
                        FOR j = 2 TO Ndx
                            Stk$[1] += Stk$[j]
                        NEXT
                        Stk$[1] += "}"
                        Ndx = 1

                    CASE "environ$"
                        Stk$[Tmp] = "Environ$"
                        Use_Environ = Use_BcxTempStr = TRUE

                    CASE "exist"
                        Stk$[Tmp] = "Exist"
                        Use_Exist = Use_Proto = Use_BcxTempStr = TRUE

                    CASE "exp"
                        Stk$[Tmp] = "Exp"
                        Use_Exp = Use_Proto = TRUE
                END SELECT


            CASE  6
                SELECT CASE Keyword$
                    CASE "for_each"
                        Stk$[Tmp] = "FOR_EACH"
                        Use_ForEach = Use_SysMacros = TRUE

                    CASE "ff$"
                        Stk$[Tmp] = "FF$"
                        Use_FF = Use_BcxTempStr = TRUE

                    CASE "function"
                        IF Stk$[Tmp+1] = "=" THEN
                            IF Stk$[Tmp+2] = DDQ$ THEN Stk$[Tmp+2] = "NUL$"
                            Stk$[Tmp] = "functionreturn"
                        ELSE
                            Stk$[Tmp] = "function"
                            IF UseCpp OR UseCpphdr THEN CALL FuncSubTemplate(Tmp)
                        END IF

                    CASE "false"
                        Stk$[Tmp] = "FALSE"

                    CASE "findintype"
                        ' Convert this :FindInType(char *Token, Type.member, int c)
                        ' To this      :FindInType(char *Token, Stptr + offsetof(Type,member), sizeof(Type), int c)

                        Stk$[Tmp] = "FindInType"
                        Use_FindInType = Use_Proto = Use_BCX_stricmp = TRUE

                        DIM RAW StMem$, StName$, VarName$
                        DIM RAW funcPtr AS UDT_ARG_COMMAS_STORAGE
                        CLEAR(funcPtr)
                        CALL SepFuncArgs(Tmp, ADDRESSOF(funcPtr), TRUE)

                        StMem$   = REMAIN$(No_Sigil$(GetArg$(2, ADDRESSOF(funcPtr))), ".")
                        VarName$ = EXTRACT$(No_Sigil$(GetArg$(2, ADDRESSOF(funcPtr))), ".")

                        FOR j = funcPtr.CommaPos[1] + 1 TO funcPtr.CommaPos[2] - 1
                            Stk$[j] = ""
                        NEXT

                        IF CheckLocal(VarName$, ADDRESSOF(i)) <> vt_UNKNOWN THEN
                            StName$ = TypeDefs[LocalVars[i].VarDef].VarName$
                        ELSEIF CheckGlobal(VarName$, ADDRESSOF(i)) <> vt_UNKNOWN THEN
                            StName$ = TypeDefs[GlobalVars[i].VarDef].VarName$
                        END IF

                        j = funcPtr.CommaPos[1] + 1
                        Stk$[j] =  "(char*)" + VarName$ + " + offsetof(" + StName$ + "," + StMem$ + "), sizeof(" + StName$ + ")"

                    CASE "fillarray"
                        Stk$[Tmp] = "fillarray"
                        Use_FillArray = TRUE
                        Use_Proto = TRUE

                    CASE "findfirst$"
                        Stk$[Tmp] = "findfirst$"
                        Use_Findfirst = Use_BcxTempStr = TRUE

                    CASE "findfirstinstance"
                        Stk$[Tmp] = "FindFirstInstance"
                        Use_FirstInstance = TRUE

                    CASE "findnext$"
                        Stk$[Tmp] = "findnext$()"
                        Convert2SimpleFunction(Tmp)
                        Use_Findnext = Use_BcxTempStr = TRUE

                    CASE "fint"
                        Stk$[Tmp] = "FINT"    ' fint is temporary, only used for parsing

                    CASE "fix"
                        Stk$[Tmp] = "FIX"
                        Use_Fix = Use_SysMacros = TRUE

                    CASE "filelocked"
                        Stk$[Tmp] = "FileLocked"
                        Use_FileLocked = Use_Proto = TRUE

                    CASE "format$"
                        Stk$[Tmp] = "Format$"
                        Use_Format = Use_BcxTempStr = Use_Proto = TRUE

                    CASE "ftell"      ' Typical FTELL usage:  int = ftell (FILE*)
                        Stk$[Tmp] = "_ftelli64"
                        FOR f AS INT = Tmp + 1 TO Ndx
                            REMOVE "#" FROM Stk$[f]
                            IF ISNULL(Stk$[f]) THEN CALL Abort ("Bad or Missing FTELL Argument")
                            IF DataType(Stk$[f]) = vt_NUMBER THEN
                                Stk$[f]= "FP" + Stk$[f]
                                IF FindVarInfo(Stk$[f], ADDRESSOF(f)) = NULL THEN
                                    CALL AddGlobal(Stk$[f], vt_FILEPTR)
                                    ' EXIT SELECT
                                    EXIT SUB  ' 837 changed by MrBcx to silence flawed warning
                                END IF
                            END IF
                        NEXT

                    CASE "frac"
                        Stk$[Tmp] = "FRAC"
                        Use_Fix = Use_Frac = Use_SysMacros = TRUE

                    CASE "fracl"
                        Stk$[Tmp] = "FRACL"
                        Use_Fix = Use_Fracl = Use_SysMacros = TRUE


                    CASE "freefile"
                        Stk$[Tmp] = "FreeFile()"
                        Use_Freefile = Use_Proto = TRUE

                    CASE "function"
                        IF Stk$[2] ?? "main" THEN
                            NoMain = TRUE
                        END IF
                END SELECT

            CASE  7
                SELECT CASE Keyword$
                    CASE "getdimension"
                        Stk$[Tmp] = "GetDimension"
                        Use_GetDimension = Use_Proto = TRUE

                    CASE "getobject"
                        ' COM version of getobject uses only one param,
                        ' while Windows API has three params:  Ndx > 6.

                        IF Ndx < 7 THEN
                            ComSwitchON            = TRUE
                            Use_COM                = TRUE
                            Use_COM_CreateObject   = TRUE
                            Use_COM_DispatchObject = TRUE
                            Use_COM_GetObject      = TRUE
                            Use_COM_GetProperty    = TRUE
                            Use_COM_InvokeMethod   = TRUE
                            Use_COM_SafeArray      = TRUE
                            Use_COM_SetProperty    = TRUE
                            Use_COM_UsesConversion = TRUE

                            Stk$[3] = Stk$[5]
                            sprintf(Stk[5], "&%s", Stk[1])
                            Stk$[1] = "BCX_GetObject"
                            Stk$[2] = "("
                            Stk$[4] = ","
                        END IF

                    CASE "getprocaddress"
                        LOCAL GlobalName$
                        LOCAL s
                        LOCAL GlobalNameHash AS ULONGLONG
                        LOCAL Atemp$
                        GlobalName$ = Stk$[Tmp-2]
                        GlobalNameHash = HashNumber(GlobalName$)

                        DO WHILE GlobalVarHash[GlobalNameHash]
                            s = GlobalVarHash[GlobalNameHash]
                            DIM RAW ptGlobal AS UDT_VARINFO_STORAGE PTR
                            ptGlobal = ADDRESSOF(GlobalVars[s])
                            IF GlobalName$ = ptGlobal->VarName$ THEN
                                Atemp$ = TypeDefs[ptGlobal->VarDef].VarName$
                                IF ptGlobal->VarPntr THEN
                                    Atemp$ += " *"
                                END IF
                            END IF
                            GlobalNameHash = IMOD(GlobalNameHash + 1, c_MaxGlobalVars)
                        LOOP

                        IF Atemp$ = "" THEN
                            LOCAL LocalName$
                            LocalName$ = Stk$[Tmp-2]
                            IF LocalVarCnt THEN
                                FOR yy AS INT = 1 TO LocalVarCnt
                                    IF LocalName$ = LocalVars[yy].VarName$ THEN
                                        Atemp$ = TypeDefs[LocalVars[yy].VarDef].VarName$
                                        IF LocalVars[yy].VarPntr THEN
                                            Atemp$ += " *"
                                        END IF
                                        EXIT FOR
                                    END IF
                                NEXT
                            END IF
                        END IF

                        IF Atemp$ <> "" THEN
                            Stk$[Tmp] = "(" + Atemp$ + ")GetProcAddress"
                        ELSE
                            Stk$[Tmp] = "GetProcAddress"
                        END IF

                    CASE "getaddr$"
                        Stk$[Tmp] = "GetAddr$"
                        Use_Getaddr = Use_Proto = Use_BcxTempStr = TRUE

                    CASE "getattr"
                        Stk$[Tmp] = "GETATTR"
                        Use_Getattr = Use_SysMacros = TRUE


                    CASE "gethttpfilesize"
                        Stk$[Tmp] = "GetHttpFileSize"
                        Use_Gethttpfilesize = TRUE


                    CASE "gettextsize"
                        Stk$[Tmp] = "GetTextSize"
                        Use_GetTextSize = Use_Proto = TRUE


                    CASE "getc"
                        Stk$[Tmp] = "getc"
                        REMOVE "#" FROM Stk$[Tmp+2]
                        IF DataType(Stk$[Tmp+2]) = vt_NUMBER THEN
                            Stk$[Tmp+2]= "FP" + Stk$[Tmp+2]
                        END IF

                    CASE "getbmp"
                        Stk$[Tmp] = "GetBmp"
                        Use_GetBmp = Use_Proto = Use_BcxTempStr = TRUE

                    CASE "getdrive"
                        Stk$[Tmp] = "_getdrive()"
                        Convert2SimpleFunction(Tmp)
                        Use_Getdrive = Use_Proto = TRUE

                    CASE "getfilename$"
                        Stk$[Tmp] = "$$GetFileName$"
                        Use_Getfilename = Use_Hook = TRUE

                    CASE "getsaveasfilename$"
                        Stk$[Tmp] = "GetSaveAsFileName$"
                        Use_GetSaveAsFilename = TRUE

                    CASE "getresource"
                        Stk$[Tmp] = "GetResource"
                        Use_GetResource = Use_Proto = TRUE

                    CASE "getspecialfolder$", "getspecialfolder"
                        Stk$[Tmp] = "$$GetSpecialFolder$"
                        Use_GetSpecialFolder = TRUE
                        Use_Proto = Use_BcxTempStr = TRUE

                    CASE "getspecialfolderex$"
                        Stk$[Tmp] = "GetSpecialFolderEx$"
                        Use_GetSpecialFolderex = TRUE
                        Use_Proto = Use_BcxTempStr = TRUE
                        Use_WideToAnsi = TRUE
                END SELECT

            CASE  8
                SELECT CASE Keyword$
                    CASE "hex$"
                        Stk$[Tmp] = "hex$"
                        Use_Hex = Use_BcxTempStr = TRUE

                    CASE "hex2dec"
                        Stk$[Tmp] = "Hex2Dec"
                        Use_Hex2Dec = Use_Proto = TRUE

                    CASE "hide"
                        Stk$[Tmp] = "HIDEHWND"
                        Use_Hide = Use_SysMacros = TRUE
                        IF Ndx >= 2 AND Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)     ' Allow unparenthesized expressions
                        END IF
                END SELECT

            CASE  9
                SELECT CASE Keyword$
                    CASE "icompare"
                        Stk$[Tmp] = "bcx_stricmp"
                        Use_BCX_stricmp = TRUE

                    CASE "instr"
                        Stk$[Tmp] = "instr"
                        Use_Instr = Use_Proto = TRUE
                        Use_Stristr = Use_UCaseTbl = TRUE

                    CASE "iinstr"
                        Stk$[Tmp] = "iinstr"
                        Use_IInstr = Use_Proto = TRUE
                        Use_Stristr = Use_UCaseTbl = TRUE

                    CASE "instrany"
                        Stk$[Tmp] = "InstrAny"
                        Use_InstrAny = Use_Instr = Use_Proto = TRUE
                        Use_Mid = Use_BcxTempStr = Use_Stristr = Use_UCaseTbl = TRUE

                    CASE "iinstrany"
                        Stk$[Tmp] = "IInstrAny"
                        Use_IInstrAny = Use_IInstr = Use_Proto = TRUE
                        Use_Mid = Use_BcxTempStr = Use_Stristr = Use_UCaseTbl = TRUE

                    CASE "inchr"
                        Stk$[Tmp] = "inchr"
                        Use_Inchr = Use_Proto = TRUE

                    CASE "imod"
                        Stk$[Tmp] = "imod"
                        Use_Imod = Use_SysMacros = TRUE

                    CASE "iif"
                        Stk$[Tmp] = "iif"
                        Use_Iif = Use_Proto = TRUE
                        FOR i = Tmp+1 TO Ndx
                            IF Stk$[i] = "=" THEN
                                IF Stk$[i-1] <> "<" AND Stk$[i-1] <> ">" THEN
                                    '  Stk$[i] = "=="                ' 837  bug patch by MrBcx
                                    Stk$[i] = "BCXEQEQ"              ' 837  bug patch by MrBcx
                                END IF
                            END IF
                        NEXT

                    CASE "iif$"
                        Stk$[Tmp] = "sziif$"
                        Use_sziif = Use_Proto = TRUE
                        FOR i = Tmp+1 TO Ndx
                            IF Stk$[i] = "=" THEN
                                IF Stk$[i-1] <> "<" AND Stk$[i-1] <> ">" THEN
                                    '  Stk$[i] = "=="                ' 837  bug patch by MrBcx
                                    Stk$[i] = "BCXEQEQ"              ' 837  bug patch by MrBcx
                                END IF
                            END IF
                        NEXT

                    CASE "initsafearray"
                        Stk$[Tmp] = "InitSafeArray"
                        Use_SafeArrays = TRUE
                        Stk$[Tmp+2] = "&" + Stk$[Tmp+2]

                    CASE "inkey"
                        Use_BcxTempStr = Use_Proto = Use_InkeyD = TRUE
                        Stk$[Tmp] = "inkeyd()"
                        Convert2SimpleFunction(Tmp)

                    CASE "inkey$"
                        Use_BcxTempStr = Use_Proto = Use_Inkey = TRUE
                        Stk$[Tmp] = "inkey$()"
                        Convert2SimpleFunction(Tmp)

                    CASE "inline"
                        IF Tmp = 1 THEN
                            Stk$[1] = ""
                            UseInLine = TRUE
                            CALL RemEmptyTokens
                            DECR Tmp
                        END IF

                    CASE "inputbox$"
                        Stk$[Tmp] = "InputBox$"
                        Use_BoxCommon = Use_Inputbox = Use_BcxTempStr = TRUE

                    CASE "infobox"
                        Stk$[Tmp] = "InfoBox"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_BoxCommon = Use_Infobox = Use_BcxTempStr = TRUE

                    CASE "ins$"
                        Stk$[Tmp] = "ins$"
                        Use_Ins = Use_Proto = Use_BcxTempStr = TRUE

                    CASE "instrrev"
                        Stk$[Tmp] = "InstrRev"
                        Use_Instrrev = Use_Proto = TRUE

                    CASE "isodate$"
                        IF Stk$[Tmp+1] <> "(" THEN
                            Stk$[Tmp] = "isodate$()"
                        ELSE
                            Stk$[Tmp] = "isodate$"
                        END IF
                        Use_IsoDate = Use_BcxTempStr = TRUE

                    CASE "isptr"
                        Stk$[Tmp] = "IsPtr"
                        Use_Isptr = Use_SysMacros = TRUE

                    CASE "istrue"
                        Stk$[Tmp] = "ISTRUE"
                        Use_Istrue = Use_SysMacros = TRUE

                    CASE "isfalse"
                        Stk$[Tmp] = "ISFALSE"
                        Use_Isfalse = Use_SysMacros = TRUE

                    CASE "iszero"
                        Stk$[Tmp] = "ISZERO"
                        Use_Iszero = Use_SysMacros = TRUE

                    CASE "isnull"
                        Stk$[Tmp] = "ISNULL"
                        Use_Isnull = Use_SysMacros = TRUE

                    CASE "issystem"
                        Stk$[Tmp] = "issystem"
                        Use_Issystem = Use_BcxTempStr = TRUE

                    CASE "ishidden"
                        Stk$[Tmp] = "ishidden"
                        Use_Ishidden = Use_BcxTempStr = TRUE

                    CASE "isreadonly"
                        Stk$[Tmp] = "isreadonly"
                        Use_Isreadonly = Use_BcxTempStr = TRUE

                    CASE "isfile"
                        Stk$[Tmp] = "isfile"
                        Use_Isfile = Use_BcxTempStr = TRUE

                    CASE "isfolder"
                        Stk$[Tmp] = "isfolder"
                        Use_Isfolder = Use_BcxTempStr = TRUE

                    CASE "ireplace$"
                        Stk$[Tmp] = "iReplace$"
                        Use_iReplace = Use_Stristr = Use_BcxTempStr = TRUE
                        Use_UCaseTbl = TRUE

                    CASE "ireplaceany$"
                        Stk$[Tmp] = "IReplaceAny$"
                        Use_IReplaceAny = Use_BcxTempStr = TRUE

                    CASE "iremove$"
                        Stk$[Tmp] = "IRemoveStr$"
                        Use_IRemove = Use_BcxTempStr = TRUE
                        Use_Stristr = Use_UCaseTbl = TRUE

                    CASE "iremoveany$"
                        Stk$[Tmp] = "IRemoveAny$"
                        Use_IRemoveAny = Use_BcxTempStr = TRUE
                END SELECT

            CASE  10
                SELECT CASE Keyword$
                    CASE "join$"
                        Stk$[Tmp] = "$$join$"
                        Use_Join = Use_BcxTempStr = TRUE
                END SELECT

            CASE  11
                SELECT CASE Keyword$
                    CASE "keypress"
                        Stk$[Tmp] = "keypress()"
                        Convert2SimpleFunction(Tmp)
                        Use_Keypress = Use_Proto = TRUE
                END SELECT

            CASE  12
                SELECT CASE Keyword$

                    CASE "land"
                        Stk$[Tmp] = " &&"

                    CASE "lor"
                        Stk$[Tmp] = " ||"

                    CASE "local"
                        IF m_iMatchWrd(Stk$[Tmp+1], "dynamic") THEN
                            Stk$[Tmp] = "dim"
                        END IF

                    CASE "lccpath$"
                        Stk$[Tmp] = "LccPath$()"
                        Convert2SimpleFunction(Tmp)

                        Use_LccPath = Use_RegString = Use_Instrrev = TRUE
                        Use_Left = Use_BcxTempStr = TRUE

                    CASE "loadfile$"
                        Stk$[Tmp] = "$$LoadFile$"
                        Use_LoadFile = Use_Get = Use_BcxTempStr = TRUE
                        Use_SysMacros = Use_Exist = Use_Lof = TRUE

                    CASE "listboxloadfile"
                        Stk$[Tmp] = "ListBoxLoadFile"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_ListBoxLoadFile = TRUE
                        Use_GetTextSize     = TRUE
                        Use_Proto           = TRUE
                        Use_Trim            = TRUE
                        Use_String          = TRUE
                        Use_BcxTempStr       = TRUE
                        Use_Eof = TRUE

                    CASE "lf$"
                        Stk$[Tmp] = "LF$"
                        Use_LF = Use_BcxTempStr = TRUE

                    CASE "line"
                        IF m_iMatchWrd(Stk$[Tmp+1], "input") THEN
                            Stk$[Tmp] = "lineinput"
                            j = Tmp + 4
                            Stk$[Tmp+1] = ""      ' Extract the file handle
                            FOR i = Tmp+2 TO Ndx
                                IF *Stk$[i] = ASC(",") THEN j = i+1 : EXIT FOR
                                Stk$[Tmp+1] = Stk$[Tmp+1] + Stk$[i]
                                Stk$[i] = ""
                            NEXT j

                            FOR i = j TO Ndx
                                Stk$[Tmp+2]= Stk$[Tmp+2] + Stk$[i]
                            NEXT
                        END IF

                    CASE "lcase$"
                        IF iSubLoc = 2 THEN
                            IF Stk$[Tmp+1] = "(" THEN
                                Abort("'lcase' can only be used as a Function Pointer when in a SET")
                            END IF
                            Stk$[Tmp] = "lcase"
                        ELSE
                            Stk$[Tmp] = "$$lcase$"
                        END IF
                        Use_Lcase = Use_BcxTempStr = TRUE

                    CASE "ldouble"
                        Stk$[Tmp] = "LDOUBLE"
                        Use_Ldouble = Use_BcxTempStr = TRUE

                    CASE "left$"
                        Stk$[Tmp] = "$$left$"
                        Use_Left = Use_BcxTempStr = TRUE

                    CASE "leftstr"
                        Stk$[Tmp] = "LeftStr"
                        Use_LeftStr = Use_Left = Use_Lcase = Use_BcxTempStr = TRUE

                    CASE "lprint"
                        Stk$[Tmp] = "lprint"
                        IF Tmp = Ndx THEN
                            INCR Ndx
                            Stk$[Ndx] = ENC$ ("")  ' Allow LPRINT with no args
                        END IF

                    CASE "lpad$"
                        Stk$[Tmp] = "$$lpad$"
                        Use_Lpad = Use_BcxTempStr = TRUE

                    CASE "ltrim$"
                        Stk$[Tmp] = "$$ltrim$"
                        Use_Ltrim = Use_BcxTempStr = TRUE

                    CASE "lof"
                        Stk$[Tmp] = "lof"
                        Use_Lof = Use_Proto = TRUE

                    CASE "like"
                        Stk$[Tmp] = "like"
                        Use_Like  = Use_Proto = TRUE

                    CASE "lclick"
                        Stk$[Tmp] = "lClick()"
                        Convert2SimpleFunction(Tmp)
                        Use_Lclick = Use_Proto = TRUE

                    CASE "like_instr"
                        Stk$[Tmp] = "Like_Instr"
                        Use_Like_Instr = Use_Ucase = Use_BcxTempStr = Use_Proto = Use_Mid = TRUE

                    CASE "loc"
                        DIM Tmp2 = Tmp + 2
                        IF DataType(Stk$[Tmp2]) = vt_NUMBER THEN
                            Stk$[Tmp2] = "FP" + Stk$[Tmp2]
                        END IF
                        REMOVE "#" FROM Stk$[Tmp2]
                        Stk$[Tmp] = "loc(" + Stk$[Tmp2] + "," + Stk$[Tmp2] + "len)"
                        Stk$[Tmp + 1] = ""
                        Stk$[Tmp2] = ""
                        Stk$[Tmp + 3] = ""
                        Use_Loc = TRUE

                    CASE "locate"
                        Stk$[Tmp] = "locate"
                        Use_Locate = Use_Console = Use_Proto = Use_Cursor = TRUE

                    CASE "longestline"
                        Stk$[Tmp] = "LongestLine"
                        Use_Longestline = Use_Eof = Use_Proto = TRUE

                    CASE "lookahead$"
                        Stk$[Tmp] = "LookAhead$"
                        REMOVE "#" FROM Stk$[Tmp+2]
                        IF DataType(Stk$[Tmp+2]) = vt_NUMBER THEN
                            Stk$[Tmp+2]= "FP" + Stk$[Tmp+2]
                        END IF
                        Use_Lookahead = Use_NamePathFromFP = Use_Eof = Use_Proto = Use_BcxTempStr =  TRUE
                END SELECT

            CASE  13
                SELECT CASE Keyword$
                    CASE "makebmp"
                        Stk$[Tmp] = "MakeBmp"
                        Use_Makebmp = Use_Proto = TRUE

                    CASE "makehdc"
                        Stk$[Tmp] = "MakeHdc"
                        Use_Makehdc = Use_Proto = TRUE

                        '*********************************************************
                        ' Special Case Handler: Substitute "Me." with "Me->"
                        '*********************************************************

                    CASE "me"
                        Stk$[Tmp] = "Me"
                        DIM Tmp1 = Tmp + 1
                        IF *Stk$[Tmp1] = ASC(".") THEN
                            IF InFunction THEN Stk$[Tmp1] = "->" + MID$(Stk$[Tmp1], 2)
                        END IF

                    CASE "mkd$"
                        IF Tmp > 2 THEN
                            IF INCHR(Stk$[Tmp-2], "$") AND *Stk$[Tmp-1] = ASC("=") THEN
                                Stk$[1] = "memcpy(" + Stk$[1]
                                Stk$[Tmp-1] = ","
                                Stk$[++Ndx] = ",9)"
                            END IF
                        END IF
                        Stk$[Tmp] ="MKD"
                        Use_Mkd = Use_BcxTempStr = TRUE

                    CASE "mki$"
                        IF Tmp > 2 THEN
                            IF INCHR(Stk$[Tmp-2], "$") AND *Stk$[Tmp-1] = ASC("=") THEN
                                Stk$[1] = "memcpy(" + Stk$[1]
                                Stk$[Tmp-1] = ","
                                Stk$[++Ndx] = ",3)"
                            END IF
                        END IF
                        Stk$[Tmp] ="MKI"
                        Use_Mki = Use_BcxTempStr = TRUE

                    CASE "mkl$"
                        IF Tmp > 2 THEN
                            IF INCHR(Stk$[Tmp-2], "$") AND *Stk$[Tmp-1] = ASC("=") THEN
                                Stk$[1] = "memcpy(" + Stk$[1]
                                Stk$[Tmp-1] = ","
                                Stk$[++Ndx] = ",5)"
                            END IF
                        END IF
                        Stk$[Tmp] ="MKL"
                        Use_Mkl = Use_BcxTempStr = TRUE

                    CASE "mkld$"
                        IF Tmp > 2 THEN
                            IF INCHR(Stk$[Tmp-2], "$") AND *Stk$[Tmp-1] = ASC("=") THEN
                                Stk$[1] = "memcpy(" + Stk$[1]
                                Stk$[Tmp-1] = ","
                                Stk$[++Ndx] = ",11)"
                            END IF
                        END IF
                        Stk$[Tmp] ="MKLD"
                        Use_Mkld = Use_BcxTempStr = TRUE

                    CASE "mks$"
                        IF Tmp > 2 THEN
                            IF INCHR(Stk$[Tmp-2], "$") AND *Stk$[Tmp-1] = ASC("=") THEN
                                Stk$[1] = "memcpy(" + Stk$[1]
                                Stk$[Tmp-1] = ","
                                Stk$[++Ndx] = ",5)"
                            END IF
                        END IF
                        Stk$[Tmp] ="MKS"
                        Use_Mks = Use_BcxTempStr = TRUE

                    CASE "mid$"
                        IF Tmp > 1 THEN
                            Stk$[Tmp] = "$$mid$"
                            Use_Mid = Use_BcxTempStr = TRUE
                        ELSE
                            Stk$[Tmp] = "midstr"
                            Use_Midstr = TRUE
                        END IF

                    CASE "min"
                        Stk$[Tmp] = "MIN"
                        Use_Min = Use_Proto = TRUE

                    CASE "max"
                        Stk$[Tmp] = "MAX"
                        Use_Max = Use_Proto = TRUE

                    CASE "mcase$"
                        IF iSubLoc = 2 THEN
                            IF Stk$[Tmp+1] = "(" THEN
                                Abort("'mcase' can only be used as a Function Pointer when in a SET")
                            END IF
                            Stk$[Tmp] = "mcase"
                        ELSE
                            Stk$[Tmp] = "$$mcase$"
                        END IF
                        Use_Mcase = Use_BcxTempStr = TRUE

                    CASE "mkpath"
                        Stk$[Tmp] = "MkPath"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Mkpath = Use_VChr = Use_Instr = Use_Mid =TRUE
                        Use_Join = Use_Split = Use_Replace = Use_UCaseTbl = TRUE
                        Use_Proto = Use_Remove = Use_BcxTempStr = Use_Stristr = TRUE

                    CASE "modstyle"
                        Stk$[Tmp] = "ModStyle"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Modstyle = Use_Proto = TRUE

                    CASE "mouse_sx"
                        Stk$[Tmp] = "MOUSE_SX"
                        Use_Mouse_sx = Use_Proto = TRUE

                    CASE "mouse_sy"
                        Stk$[Tmp] = "MOUSE_SY"
                        Use_Mouse_sy = Use_Proto = TRUE

                    CASE "mouse_cx"
                        Stk$[Tmp] = "MOUSE_CX"
                        Use_Mouse_cx = Use_Proto = TRUE

                    CASE "mouse_cy"
                        Stk$[Tmp] = "MOUSE_CY"
                        Use_Mouse_cy = Use_Proto = TRUE

                    CASE "msgbox"
                        DIM Tmm1 = Tmp - 1
                        IF Stk$[Tmm1]= "=" OR m_iMatchWrd(Stk$[Tmm1], "if") OR m_iMatchWrd(Stk$[Tmm1], "elseif") THEN
                            Stk$[Tmp] = "MsgBox"
                            Use_Msgbox = Use_Proto = TRUE
                        END IF
                END SELECT

            CASE  14
                SELECT CASE Keyword$
                    CASE "next_each"
                        Use_ForEach = Use_SysMacros = TRUE
                        Stk$[Tmp] = "NEXT_EACH"

                        IF Stk$ [Tmp+1] <> "(" THEN EXIT SELECT ' No argument was passed
                        INCR Tmp
                        ' Remove the unneeded argument, example: NEXT_EACH (ii)
                        DO UNTIL Tmp > Ndx
                            Stk$[Tmp] = ""
                            INCR Tmp
                        LOOP

                    CASE "new"
                        IF m_iMatchWrd(Stk$[Tmp-1], "binary") THEN EXIT SELECT
                        UseCpp = TRUE
                        Stk$[Tmp] = "new "

                    CASE "newbmp"
                        Stk$[Tmp] = "NewBmp()"
                        Use_Newbmp = Use_Proto = TRUE

                    CASE "nextlinelen"
                        Stk$[Tmp] = "NextLineLen"
                        Use_Nextlinelen = Use_Proto = TRUE

                        ' For compatibility with VB code, See CreateObject for more details what I'm doin' here

                    CASE "nothing"
                        ComSwitchON = Use_COM = TRUE

                        ' Next line should be called only if NOT inside (IF...END IF)
                        ' BCX_Remove_COM_Object(Stk$[1]) '  disabled until I figure out is it called from (IF...END IF)

                        DIM sObj$
                        DIM ii = 2
                        sObj$ = "&" + Stk$[1]
                        DO WHILE Stk$[ii] <> "="
                            sObj$ += Stk$[ii]
                            INCR ii
                        LOOP

                        Stk$[1] = "BCX_SetNothing"
                        Stk$[2] = "("
                        Stk$[3] = sObj$
                        Stk$[4] = ")"
                        Ndx = 4

                    CASE "notzero"
                        Stk$[Tmp] = "NOTZERO"
                        Use_Notzero = Use_SysMacros = TRUE

                    CASE "notnull"
                        Stk$[Tmp] = "NOTNULL"
                        Use_Notnull = Use_SysMacros = TRUE

                    CASE "notequalto"
                        Stk$[Tmp] = " NotEqualTo "
                        Use_NotEqualTo = Use_SysMacros = TRUE

                    CASE "nul$"
                        Stk$[Tmp] = "NUL$"
                        Use_NUL = Use_BcxTempStr = TRUE

                    CASE "now$"
                        IF Stk$[Tmp+1]<> "(" THEN
                            Stk$[Tmp] = "now$()"
                        ELSE
                            Stk$[Tmp] = "now$"
                        END IF
                        Use_Now = Use_BcxTempStr = TRUE
                END SELECT

            CASE  15
                SELECT CASE Keyword$
                    CASE "object"
                        ComSwitchON = Use_COM = Use_BcxTempStr = TRUE
                        Stk$[Tmp] = "OBJECT"

                    CASE "open"
                        FOR A = Tmp + 1 TO Ndx
                            IF *Stk$[A] = ASC("#") THEN
                                Stk$[A] = MID$(Stk$[A], 2)
                                EXIT FOR
                            END IF
                        NEXT

                    CASE "oct$"
                        Stk$[Tmp] = "oct$"
                        Use_Oct = Use_BcxTempStr = TRUE

                    CASE "or", "orelse"                  ' OR can be Boolean or bitwise
                        Stk$[Tmp] = " || "               ' but ORELSE is ALWAYS Boolean

                    CASE "osversion"
                        Stk$[Tmp] = "OSVersion()"
                        Convert2SimpleFunction(Tmp)
                        CALL Emit_OSVersionEnum
                        Use_OSVersion = Use_Proto = TRUE
                END SELECT

            CASE  16
                SELECT CASE Keyword$
                    CASE "pellespath$"
                        Stk$[Tmp] = "PellesPath$()"
                        Convert2SimpleFunction(Tmp)
                        Use_PellesPath = Use_RegString = Use_Instrrev = TRUE
                        Use_Left = Use_BcxTempStr = TRUE

                    CASE "putc"                                      ' MrBcx 819 (New)
                        Stk$[Tmp] = "putc"                           ' MrBcx 819 (New)

                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)         ' Allow unparenthesized expressions
                        END IF

                        REMOVE "#" FROM Stk$[Tmp + 2]                ' MrBcx 819 (New)
                        IF DataType(Stk$[Tmp + 2]) = vt_NUMBER THEN  ' MrBcx 819 (New)
                            Stk$[Tmp + 2] = "FP" + Stk$[Tmp + 2]     ' MrBcx 819 (New)
                        END IF                                       ' MrBcx 819 (New)
                        '                                            ' MrBcx 819 (New)  Rearrange: putc ( fp# ,  byte-expression )
                        '                                            ' MrBcx 819 (New)         to: putc ( byte-expression, fp# )
                        DIM fp$                                      ' MrBcx 819 (New)
                        fp$ = Stk$[Tmp + 2]                          ' MrBcx 819 (New)
                        LShiftStk(Tmp + 2)                           ' MrBcx 819 (New)
                        LShiftStk(Tmp + 2)                           ' MrBcx 819 (New)
                        Stk$[Ndx] = ","                              ' MrBcx 819 (New)
                        INCR Ndx                                     ' MrBcx 819 (New)
                        Stk$[Ndx] = fp$                              ' MrBcx 819 (New)
                        INCR Ndx                                     ' MrBcx 819 (New)
                        Stk$[Ndx] = ")"                              ' MrBcx 819 (New)


                    CASE "printer"
                        DIM Tmp1 = Tmp+1
                        IF *Stk$[Tmp1] THEN
                            IF m_iMatchWrd(Stk$[Tmp1], "open")      THEN Stk$[Tmp] = "printeropen"
                            IF m_iMatchWrd(Stk$[Tmp1], "ejectpage") THEN Stk$[Tmp] = "ejectpage"
                            IF m_iMatchWrd(Stk$[Tmp1], "close")     THEN Stk$[Tmp] = "printerclose"

                            IF m_iMatchWrd(Stk$[Tmp], "printer")    THEN
                                CALL Abort ("Unknown word '" + Stk$[Tmp1] + "' with printer")
                            END IF

                            LShiftStk(Tmp1)
                        ELSE
                            Ndx = 0
                        END IF
                        Use_Printer = Use_Proto = TRUE
                        iEmitVarGroup = iEmitVarGroup BOR ePrinterGroup
                        Use_Mid = Use_Left = TRUE
                        Use_Extract = Use_Str = Use_BcxTempStr = TRUE

                    CASE "print"
                        IF *Stk$[Tmp+1] = ASC("#") THEN
                            Stk$[Tmp] = "fprint"
                            Stk$[Tmp+1] = MID$(Stk$[Tmp+1], 2)
                        END IF

                    CASE "ptr"
                        Stk$[Tmp-1] += "*"
                        Stk$[Tmp] = ""
                        IF Tmp = Ndx THEN
                            DECR Ndx
                            DO WHILE TALLY(Stk$[Ndx], "*") = LEN(Stk$[Ndx])
                                Stk$[Ndx-1] += Stk$[Ndx]
                                Stk$[Ndx] = ""
                                DECR Ndx
                            LOOP
                        ELSE
                            i = Tmp-1
                            DO WHILE TALLY(Stk$[i], "*") = LEN(Stk$[i])
                                Stk$[i-1] += Stk$[i]
                                Stk$[i--] = ""
                            LOOP
                        END IF

                    CASE "panel"
                        Stk$[Tmp] = "panel"
                        Use_Panel = Use_Console = Use_Proto = Use_Cursor = TRUE

                    CASE "pause"
                        Stk$[Tmp] = "Pause()"
                        Convert2SimpleFunction(Tmp)
                        Use_Pause = Use_Proto = TRUE

                    CASE "peek$"
                        Stk$[Tmp] = "$$peekstr$"
                        Use_PeekStr = Use_BcxTempStr = TRUE

                    CASE "pi"
                        Stk$[Tmp] = "3.141592653589793"

                    CASE "playwav"
                        Stk$[Tmp] = "PlayWav"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_PlayWav = Use_GetResource = Use_Proto = TRUE

                    CASE "pos"
                        Stk$[Tmp] = "Pos()"
                        Use_Pos   = Use_Proto = TRUE

                    CASE "pushcolors"
                        Stk$[Tmp] = "PushColors()"
                        Use_PushPopColors = Use_Color = Use_Console = Use_Proto = TRUE

                    CASE "popcolors"
                        Stk$[Tmp] = "PopColors()"
                        Use_PushPopColors = Use_Color = Use_Console = Use_Proto = TRUE

                    CASE "private"
                        IF m_iMatchWrd(Stk$[Tmp+1], "const") THEN
                            Stk$[Tmp] = "enum "
                            Stk$[Tmp+1]= Stk$[Tmp+2] + "{"
                            INCR Ndx
                            Stk$[Ndx]= "}"
                        ELSE
                            Stk$[1] = "private"
                        END IF
                END SELECT

            CASE  17
                SELECT CASE Keyword$
                    CASE "qbcolor"
                        Stk$[Tmp] = "qbcolor"
                        Use_QBColor = Use_Proto = TRUE
                END SELECT

            CASE  18
                SELECT CASE Keyword$
                    CASE "rgb"
                        Stk$[Tmp] = "RGB"

                    CASE "read"
                        Stk$[Tmp] = "READNUM"
                        Use_Readnum = Use_SysMacros = Use_Proto = TRUE

                    CASE "read$"
                        Stk$[Tmp] = "READ$"
                        Use_Read = Use_SysMacros = Use_Proto = TRUE

                    CASE "rewind"
                        Stk$[Tmp] = "rewind"
                        DIM Tmp2 = Tmp + 2
                        IF DataType(Stk$[Tmp2]) = vt_NUMBER THEN
                            Stk$[Tmp2] = "FP" + Stk$[Tmp2]
                        END IF

                    CASE "remove$"
                        Stk$[Tmp] = "$$RemoveStr$"
                        Use_Remove = Use_BcxTempStr = TRUE

                    CASE "replace$"
                        Stk$[Tmp] = "$$replace$"
                        Use_Replace = Use_BcxTempStr = TRUE

                    CASE "replaceany$"
                        Stk$[Tmp] = "ReplaceAny$"
                        Use_ReplaceAny = Use_BcxTempStr = TRUE

                    CASE "removeany$"
                        Stk$[Tmp] = "RemoveAny$"
                        Use_RemoveAny = Use_BcxTempStr = TRUE

                    CASE "right$"
                        Stk$[Tmp] = "$$right$"
                        Use_Right = Use_BcxTempStr = TRUE

                    CASE "rightstr"
                        Stk$[Tmp] = "RightStr"
                        Use_RightStr = Use_Right = Use_Lcase = Use_BcxTempStr = TRUE

                    CASE "rclick"
                        Stk$[Tmp] = "rClick()"
                        Convert2SimpleFunction(Tmp)
                        Use_Rclick = Use_Proto = TRUE

                    CASE "randomize"
                        Stk$[Tmp] = "randomize"
                        Use_Randomize = TRUE
                        Use_Proto = TRUE
                        IF Ndx = 1 THEN
                            Use_Timer = TRUE
                            Stk$[1] ="randomize(timer())"
                        END IF
                        IF Ndx = 2 AND Stk$[2] ?? "timer" THEN
                            Use_Timer = TRUE
                            Ndx = 1
                            Stk$[1] ="randomize(timer())"
                        END IF
                        IF Ndx >= 2 AND Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)  ' Allow unparenthesized expressions
                        END IF

                    CASE "rec"
                        DIM Tmp2 = Tmp + 2
                        IF DataType(Stk$[Tmp2]) = vt_NUMBER THEN
                            Stk$[Tmp2] = "FP" + Stk$[Tmp2]
                        END IF
                        REMOVE "#" FROM Stk$[Tmp2]
                        Stk$[Tmp] = "rec(" + Stk$[Tmp2] + "," + Stk$[Tmp2] + "len)"
                        Stk$[Tmp + 1] = ""
                        Stk$[Tmp2] = ""
                        Stk$[Tmp + 3] = ""
                        Use_Rec = Use_Proto = TRUE

                    CASE "reccount"
                        DIM length$
                        DIM Tmp2 = Tmp + 2
                        IF DataType(Stk$[Tmp2]) = vt_NUMBER THEN
                            Stk$[Tmp2] = "FP" + Stk$[Tmp2]
                        END IF
                        REMOVE "#" FROM Stk$[Tmp2]
                        Stk$[Tmp] = "reccount"
                        length$ = Stk$[Tmp2] + "len)"

                        FOR i = Tmp+1 TO Ndx
                            IF *Stk$[i] = ASC(")") THEN
                                Stk$[i] = ""
                                EXIT FOR
                            END IF
                            Stk$[Tmp] += Stk$[i]
                            Stk$[i] = ""
                        NEXT

                        Stk$[Tmp] += "," + length$
                        Use_RecCount = Use_Proto = TRUE

                    CASE "refresh"
                        Stk$[Tmp] = "Refresh"
                        Use_Refresh = Use_SysMacros = TRUE

                    CASE "radtodeg"
                        Stk$[Tmp] = "RadToDeg"
                        Use_RadToDeg = Use_SysMacros = TRUE

                    CASE "regstring$"
                        Stk$[Tmp] = "$$RegString$"
                        Convert2SimpleFunction(Tmp)
                        Use_RegString = Use_BcxTempStr = TRUE

                    CASE "regexist"
                        Stk$[Tmp] = "RegExist"
                        Convert2SimpleFunction(Tmp)
                        Use_RegExist = Use_BcxTempStr = TRUE

                    CASE "regint"
                        Stk$[Tmp] = "RegInt"
                        Convert2SimpleFunction(Tmp)
                        Use_RegInt = Use_BcxTempStr = TRUE

                    CASE "remain$"
                        Stk$[Tmp] = "$$remain$"
                        Use_Remain = Use_BcxTempStr = TRUE

                    CASE "remainany$"
                        Stk$[Tmp] = "$$remainany$"
                        Use_RemainAny = Use_BcxTempStr = TRUE

                    CASE "retain$"
                        Stk$[Tmp] = "$$Retain$"
                        Use_Retain = Use_BcxTempStr = TRUE

                    CASE "repeat$"
                        Stk$[Tmp] = "$$repeat$"
                        Use_Repeat = Use_BcxTempStr = TRUE

                    CASE "reverse$"
                        Stk$[Tmp] = "$$reverse$"
                        Use_Reverse = Use_BcxTempStr = TRUE

                    CASE "rnd"
                        Stk$[Tmp] = "rnd()"
                        Convert2SimpleFunction(Tmp)
                        Use_Rnd = Use_Proto = TRUE

                    CASE "rnd2"
                        Stk$[Tmp] = "rnd2"
                        Use_Rnd2 = Use_Proto = TRUE

                    CASE "round"
                        Stk$[Tmp] = "Round"
                        Use_Round = Use_Proto = TRUE

                    CASE "rpad$"
                        Stk$[Tmp] = "$$rpad$"
                        Use_Rpad = Use_BcxTempStr = TRUE

                    CASE "rtrim$"
                        Stk$[Tmp] = "$$rtrim$"
                        Use_Rtrim = Use_BcxTempStr = TRUE

                    CASE "run"
                        Stk$[Tmp] = "Run"
                        Use_Run = Use_Proto = TRUE
                END SELECT


            CASE  19
                SELECT CASE Keyword$
                    CASE "setdimension"
                        Stk$[Tmp] = "SetDimension"
                        Use_SetDimension = Use_Proto = TRUE

                    CASE "spc$"
                        Stk$[Tmp] = "SPC$"
                        Use_SPC = Use_BcxTempStr = TRUE

                    CASE "startdraw"
                        Stk$[Tmp] = "StartDraw"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Draw = TRUE

                    CASE "str$"
                        Stk$[Tmp] = "$$str$"
                        Use_Str = Use_BcxTempStr = TRUE

                    CASE "strl$"
                        Stk$[Tmp] = "$$strl$"
                        Use_Strl = Use_BcxTempStr = TRUE

                    CASE "str2variant"
                        ' INPUT:
                        ' str2variant(string,variant)
                        ' TRANSFORMS TO
                        ' COM_AS2WS(sBuf)
                        ' lComVariant.vt = VT_BSTR
                        ' lComVariant.bstrVal = SysAllocString(COM_PWSTR_temp)
                        CALL Add2SplitLines("COM_AS2WS(" + Stk$[Tmp+2] + ")")
                        CALL Add2SplitLines(Stk$[Tmp+4] + ".vt = VT_BSTR")
                        CALL Add2SplitLines(Stk$[Tmp+4] + ".bstrVal = SysAllocString(COM_PWSTR_temp)")
                        Ndx = 0

                    CASE "searchpath$"
                        Stk$[Tmp] = "$$SEARCHPATH$"
                        Use_SearchPath = Use_BcxTempStr = TRUE

                    CASE "sendmessage", "sndmsg"
                        '*****************************
                        '    SendMessage HELPER
                        '*****************************
                        IF NOT m_iMatchWrd(Stk$[1], "const") THEN

                            IF Stk$[Tmp+1] <> "(" THEN
                                CALL InsertOptionalParens(Tmp+1)       ' Allow unparenthesized expressions
                            END IF

                            Stk$[Tmp] = "SendMessage"
                            Comma = i = 0
                            A = Tmp+1

                            DO
                                IF A > Ndx THEN
                                    CALL Abort("Malformed SendMessage")
                                END IF

                                INCR A
                                IF INCHR("([{", Stk$[A]) THEN INCR i
                                IF INCHR(")]}", Stk$[A]) THEN DECR i
                                IF NOTZERO(i) THEN ITERATE

                                IF *Stk$[A] = ASC(",") THEN
                                    IF Comma = 0 THEN
                                        IF ISFALSE(m_iMatchWrd(Stk$[A+2], "UINT")) THEN
                                            InsertTokens(A, 3, "(", "UINT", ")")
                                        END IF
                                    ELSEIF Comma = 1 THEN
                                        IF ISFALSE(m_iMatchWrd(Stk$[A+2], "WPARAM")) THEN
                                            InsertTokens(A, 3, "(", "WPARAM", ")")
                                        END IF
                                    ELSEIF Comma = 2 THEN
                                        IF ISFALSE(m_iMatchWrd(Stk$[A+2], "LPARAM")) THEN
                                            InsertTokens(A, 3, "(", "LPARAM", ")")
                                        END IF
                                        EXIT DO
                                    END IF
                                    INCR Comma
                                END IF    ' Is a comma
                            LOOP
                        END IF

                    CASE "savebmp"
                        Stk$[Tmp] = "SaveBmp"
                        Use_SaveBmp = Use_Proto = Use_BcxTempStr = TRUE

                    CASE "setaddr"
                        Stk$[Tmp] = "SetAddr"
                        Use_Setaddr = Use_Proto = Use_BcxTempStr = TRUE

                    CASE "set_bcx_bitmap"
                        Stk$[Tmp] = "Set_BCX_Bitmap"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Set_BCX_Bitmap = Use_BcxTempStr = TRUE

                    CASE "set_bcx_bitmap2"
                        Stk$[Tmp] = "Set_BCX_Bitmap2"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Set_BCX_Bitmap2 = Use_BcxTempStr = TRUE

                    CASE "set_bcx_bmpbutton"
                        Stk$[Tmp] = "Set_BCX_BmpButton"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Set_BCX_BmpButton = Use_BcxTempStr = TRUE

                    CASE "set_bcx_icon"
                        Stk$[Tmp] = "Set_BCX_Icon"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Proto = TRUE
                        Use_Set_BCX_Icon = Use_GetResource = TRUE

                    CASE "screen"
                        Stk$[Tmp] = "Screen"
                        Use_Screen = Use_Proto = TRUE

                    CASE "setattr"
                        Stk$[Tmp] = "SETATTR"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)          ' Allow unparenthesized expressions
                        END IF
                        Use_Setattr = Use_SysMacros = TRUE

                    CASE "setwindowrtftext"
                        Stk$[Tmp] = "SetWindowRTFText"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)          ' Allow unparenthesized expressions
                        END IF
                        Use_Richedit = Use_BcxTempStr = TRUE

                    CASE "sgn"
                        Stk$[Tmp] = "sgn"
                        Use_Sgn = Use_Proto = TRUE

                    CASE "show"
                        Stk$[Tmp] = "SHOWHWND"
                        Use_Show = Use_SysMacros = TRUE
                        IF Ndx >= 2 AND Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)          ' Allow unparenthesized expressions
                        END IF

                    CASE "sleep"
                        IF Ndx = 1 THEN
                            Stk$[1] = "keypress()"                    ' Allow SLEEP with no argument - 832 MrBcx
                            Use_Keypress = Use_Proto = TRUE
                        ELSE
                            Use_Sleep = TRUE
                            Stk$[Tmp] = "BCX_Sleep"
                            IF Ndx >= 2 AND Stk$[Tmp+1] <> "(" THEN
                                CALL InsertOptionalParens(Tmp+1)      ' Allow unparenthesized expressions
                            END IF
                        END IF

                    CASE "showmodal"
                        Stk$[Tmp] = "ShowModal"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)          ' Allow unparenthesized expressions
                        END IF
                        Use_Show = Use_SysMacros = Use_ShowModal = Use_EndModal = TRUE

                    CASE "space$"
                        Stk$[Tmp] = "$$space$"
                        Use_Space = Use_BcxTempStr = TRUE

                    CASE "sound"
                        Stk$[Tmp] = "Sound"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)          ' Allow unparenthesized expressions
                        END IF
                        Use_Sound = Use_Round = Use_Str = Use_BcxTempStr = TRUE

                    CASE "split"
                        Stk$[Tmp] = "Split"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)          ' Allow unparenthesized expressions
                        END IF
                        Use_Proto = TRUE
                        Use_BcxTempStr = TRUE
                        Use_UCaseTbl = TRUE
                        Use_Stristr = TRUE
                        Use_Split = TRUE
                        Use_Remove= TRUE
                        Use_Mid   = TRUE
                        Use_Left  = TRUE
                        Use_Instr = TRUE
                        Use_Replace = TRUE

                    CASE "strim$"
                        Stk$[Tmp] = "$$strim$"
                        Use_Strim = Use_BcxTempStr = TRUE

                    CASE "string$"
                        Stk$[Tmp] = "$$stringx$"
                        Use_String = Use_BcxTempStr = TRUE

                    CASE "strptr"
                        Stk$[Tmp] = "STRPTR"
                        Use_Strptr = Use_SysMacros = TRUE

                    CASE "strtoken$"
                        Stk$[Tmp] = "StrToken$"
                        Use_Strtoken = Use_BcxTempStr = Use_Mid = Use_Left = Use_Extract = TRUE
                        Use_Instr = Use_Instrrev = Use_Stristr = Use_Tally = Use_Remove = TRUE
                        Use_UCaseTbl = TRUE

                    CASE "sub"
                        IF Stk$[2] ?? "main" THEN
                            NoMain = TRUE
                            Stk$[1] = "function"
                        END IF

                    CASE "swap"
                        Stk$[Tmp] = "swap"
                        Use_Swap = Use_Proto = TRUE

                    CASE "sysdir$"
                        Stk$[Tmp] = "$$sysdir$()"
                        Convert2SimpleFunction(Tmp)
                        Use_Sysdir = Use_BcxTempStr = TRUE

                    CASE "sysstr"
                        Stk$[Tmp] = "SysStr"
                        Use_SysStr = Use_Proto = TRUE
                END SELECT

            CASE  20
                SELECT CASE Keyword$
                    CASE "tab$"
                        Stk$[Tmp] = "TAB$"
                        Use_TAB = Use_BcxTempStr = TRUE

                    CASE "true"
                        Stk$[Tmp] = "TRUE"

                    CASE "trim$"
                        Stk$[Tmp] = "$$trim$"
                        Use_Trim = Use_BcxTempStr = TRUE

                    CASE "tally"
                        Stk$[Tmp] = "tally"
                        Use_Tally = Use_UCaseTbl = Use_Stristr = Use_Proto = TRUE

                    CASE "tempdir$"
                        Stk$[Tmp] = "$$tempdir$()"
                        Convert2SimpleFunction(Tmp)
                        Use_Tempdir = Use_BcxTempStr = TRUE

                    CASE "tempfilename$"
                        Stk$[Tmp] = "$$TempFileName$"
                        Use_TempFileName = Use_BcxTempStr = TRUE

                    CASE "textmode"
                        Stk$[Tmp] = "TextMode"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        Use_Textmode = Use_Proto = TRUE

                    CASE "time$"
                        IF Stk$[Tmp+1] <> "("  THEN
                            Stk$[Tmp] = "$$timef$()"
                        ELSE
                            Stk$[Tmp] = "$$timef$"
                        END IF
                        Convert2SimpleFunction(Tmp)
                        Use_Time = Use_BcxTempStr = TRUE

                    CASE "timer"
                        Stk$[Tmp] = "timer()"
                        Convert2SimpleFunction(Tmp)
                        Use_Timer = Use_Proto = TRUE

                    CASE "tix_start"
                        Stk$[Tmp] = "TIX_START()"
                        Convert2SimpleFunction(Tmp)
                        Use_Tix = Use_Proto = TRUE

                    CASE "tix_now"
                        Stk$[Tmp] = "TIX_NOW()"
                        Convert2SimpleFunction(Tmp)
                        Use_Tix = Use_Proto = TRUE
                END SELECT

            CASE  21
                SELECT CASE Keyword$
                    CASE "ucase$"
                        IF iSubLoc = 2 THEN
                            IF Stk$[Tmp+1] = "(" THEN
                                Abort("'ucase' can only be used as a Function Pointer when in a SET")
                            END IF
                            Stk$[Tmp] = "ucase"
                        ELSE
                            Stk$[Tmp] = "$$ucase$"
                        END IF
                        Use_Ucase = Use_BcxTempStr = TRUE

                    CASE "unwrap$"
                        Stk$[Tmp] = "$$unwrap$"
                        Use_Unwrap = Use_BcxTempStr = Use_Left = Use_Right = TRUE

                    CASE "ubound"
                        Stk$[Tmp] = "ubound"
                        Use_Ubound = Use_SysMacros = TRUE

                    CASE "ubound_d"
                        Stk$[Tmp] = "ubound_d"
                        Use_Ubound = Use_SysMacros = TRUE

                    CASE "ubound_s"
                        Stk$[Tmp] = "ubound_s"
                        Use_Ubound = Use_SysMacros = TRUE

                    CASE  "ucode$", "ucode"
                        Stk$[Tmp] = "$$AnsiToWide$"
                        Use_AnsiToWide = Use_BcxTempStr = TRUE

                    CASE "utf8tochr$"
                        Stk$[Tmp] = "UTF8toCHR$"
                        Use_Utf8tochr = Use_BcxTempStr = TRUE

                    CASE "uncom"
                        Use_AnsiToWide = Use_WideToAnsi = Use_BcxTempStr = TRUE
                        Stk$[Tmp] = "UNCOM"
                        IF Stk$[Tmp+1] <> "(" THEN
                            CALL InsertOptionalParens(Tmp+1)           ' Allow unparenthesized expressions
                        END IF
                        ComSwitchON = TRUE
                        Use_COM = TRUE
                        Use_COM_CreateObject   = TRUE
                        Use_COM_DispatchObject = TRUE
                        Use_COM_GetObject      = TRUE
                        Use_COM_GetProperty    = TRUE
                        Use_COM_InvokeMethod   = TRUE
                        Use_COM_SafeArray      = TRUE
                        Use_COM_SetProperty    = TRUE
                        Use_COM_UsesConversion = TRUE

                    CASE "using$"
                        Stk$[Tmp] = "$$Using$"
                        Use_Using = Use_Instr = Use_Stristr = Use_Replace = Use_BcxTempStr = Use_UCaseTbl = Use_LCaseTbl = TRUE
                END SELECT

            CASE  22
                SELECT CASE Keyword$
                    CASE "val"
                        Stk$[Tmp] = "VAL"
                        Use_Val = Use_SysMacros = TRUE

                    CASE "vall"
                        Stk$[Tmp] = "VALL"
                        Use_Vall = Use_SysMacros = TRUE

                    CASE "variant2str"
                        ' INPUT:
                        ' variant2str(variant, string)
                        ' TRANSFORMS TO
                        ' BEGINBLOCK
                        ' RAW sBuf[wlen(variant.bstrVal)+2] AS char
                        ' wstrcpy(sBuf, lComVariant.bstrVal)
                        ' COM_WS2AS(sBuf)
                        ' string = COM_psz_tmp$
                        ' ENDBLOCK
                        CALL Add2SplitLines("BEGINBLOCK")
                        CALL Add2SplitLines("DIM RAW sBuf[wlen(" + Stk$[Tmp+2] + ".bstrVal)+2] AS char")
                        CALL Add2SplitLines("wstrcpy(sBuf," + Stk$[Tmp+2] + ".bstrVal)")
                        CALL Add2SplitLines("COM_WS2AS(sBuf)")
                        CALL Add2SplitLines(Stk$[Tmp+4] + " = COM_psz_tmp$")
                        CALL Add2SplitLines("ENDBLOCK")
                        Ndx = 0
                        Use_COM_UsesConversion = TRUE

                    CASE "varptr"
                        Stk$[Tmp+1] = "&" + Stk$[Tmp+1]
                        Stk$[Tmp] = ""

                    CASE "vchr$"
                        Stk$[Tmp] = "$$vchr$"
                        Use_VChr = Use_BcxTempStr = TRUE

                    CASE "vt$"
                        Stk$[Tmp] = "VT$"
                        Use_VT = Use_BcxTempStr = TRUE

                    CASE "virtual"
                        IF Tmp = 1 THEN
                            Stk$[Tmp] = "dim"
                            IsVirtual = TRUE

                            DIM ii = Ndx
                            DO WHILE Stk$[ii] <> ")"
                                DECR ii
                            LOOP
                            INCR ii
                            IF m_iMatchWrd(Stk$[Ndx], "stdcall") THEN
                                DIM iNdx = Ndx-1
                                IF m_iMatchWrd(Stk$[iNdx], "as") THEN DECR iNdx
                                IF ii <= iNdx THEN
                                    CALL BuildDelimStr(ii, iNdx, szVirtual$)
                                ELSE
                                    szVirtual$ = ""
                                END IF
                            ELSE
                                IF ii <= Ndx THEN
                                    CALL BuildDelimStr(ii, Ndx, szVirtual$)
                                ELSE
                                    szVirtual$ = ""
                                END IF
                            END IF
                        END IF

                    CASE "vector"
                        IF Stk$[Tmp+1] = "<" THEN
                            Stk$[Tmp] = "vector"
                            HasVector = TRUE
                        END IF

                    CASE "verify"
                        Stk$[Tmp] = "Verify"
                        Use_Verify = Use_Mid = Use_BcxTempStr = TRUE

                    CASE "vbs_addcode", "vbs_run_script", "vbs_eval_str$"
                        Stk$[Tmp] = UCASE$(Stk$[Tmp])
                        Use_VBS = Use_BcxTempStr = TRUE

                    CASE "vbs_eval_num", "vbs_eval_num#"
                        Stk$[Tmp] = "VBS_EVAL_NUM#"
                        Use_VBS = Use_BcxTempStr = TRUE

                    CASE "vbs_start", "vbs_stop", "vbs_reset", "vbs_error$"
                        Use_VBS = Use_BcxTempStr = TRUE
                        Stk$[Tmp] = UCASE$(Stk$[Tmp]) + "()"
                        Convert2SimpleFunction(Tmp)
                END SELECT

            CASE  23
                SELECT CASE Keyword$
                    CASE "wrap$"
                        Stk$[Tmp] = "$$wrap$"
                        Use_Wrap = Use_BcxTempStr = TRUE

                    CASE "widetoansi$", "widetoansi", "w2a$", "w2a"
                        Stk$[Tmp] = "$$WideToAnsi$"
                        Use_WideToAnsi = Use_BcxTempStr = TRUE

                    CASE "windir$"
                        Stk$[Tmp] = "$$windir$()"
                        Convert2SimpleFunction(Tmp)
                        Use_Windir = Use_BcxTempStr = TRUE

                    CASE "wndproc"
                        IF Tmp = 2 AND Ndx < 6 THEN
                            Src$ = "FUNCTION|WndProc(hWnd|AS|HWND,Msg|AS|UINT,wParam|AS|WPARAM,lParam|AS|LPARAM)|AS|CALLBACK|LRESULT"
                            FastLexer(Src$, "|", ",()")
                            Use_Wingui = TRUE
                            CallBackFlag= TRUE
                        END IF

                    CASE "winmain"
                        Use_Wingui = InWinMain = TRUE
                        IF Tmp = 2 AND Ndx < 6 THEN
                            Src$ = "FUNCTION|WinMain(hInst|AS|HINSTANCE,hPrev|AS|HINSTANCE,CmdLine|AS|PSTR,CmdShow|AS|int)AS|int WINAPI"
                            FastLexer(Src$, "|", ",()")
                        ELSE
                            Stk$[Tmp] = "WinMain"
                        END IF
                END SELECT

            CASE  26
                SELECT CASE Keyword$
                    CASE "zstring"
                        IF m_iMatchWrd(Stk$[Tmp+1], "ptr") THEN
                            Stk$[Tmp] = "char"
                            INCR Tmp
                            Stk$[Tmp-1] = Stk$[Tmp-1] + "*"
                            Stk$[Tmp] = ""
                            IF Tmp = Ndx THEN
                                DECR Ndx
                                DO WHILE TALLY(Stk$[Ndx], "*") = LEN(Stk$[Ndx])
                                    Stk$[Ndx-1] += Stk$[Ndx]
                                    Stk$[Ndx] = ""
                                    DECR Ndx
                                LOOP
                            ELSE
                                i = Tmp-1
                                DO WHILE TALLY(Stk$[i], "*") = LEN(Stk$[i])
                                    Stk$[i-1] += Stk$[i]
                                    Stk$[i] = ""
                                    DECR i
                                LOOP
                            END IF
                        END IF
                        Stk$[Tmp] = "string"
                END SELECT

            CASE 27
                SELECT CASE Keyword$
                    CASE "$ifndef"
                        Stk$[Tmp] = "~ifndef"
                        INCR InConditional

                    CASE "$ifdef"
                        Stk$[Tmp] = "~ifdef"
                        INCR InConditional

                    CASE "$if"
                        Stk$[Tmp] = "~if"
                        INCR InConditional

                    CASE "$endif"
                        Stk$[Tmp] = "~endif"
                        DECR InConditional
                        IF InConditional < 0 THEN       ' simple check to see if conditionals are balanced
                            Abort("Too many $ENDIFs")
                        END IF
                END SELECT
        END SELECT
    NEXT

    CALL RemEmptyTokens
    '************************************************************
    ' Moved the WITH/END WITH handling here from the Emit sub
    ' The ill formed variables would cause conflict with the new
    ' AsmUnKnown structs function.
    '************************************************************
    IF PrependCnt THEN
        i = PrependCnt
        DO WHILE i
            IF NOT m_iMatchWrd(Stk$[1], "with") _
                AND NOT m_iMatchWrd(Stk$[1], "prepend") _
                AND NOT m_iMatchWrd(Stk$[1], "endwith") _
                AND NOT m_iMatchWrd(Stk$[1], "endprepend") THEN
                CALL InsertTokens(0, 1, PrependVar$[i])
            END IF
            DECR i
        LOOP
    END IF

    ' \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Begin 837 Update  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

    IF WithCnt THEN
        LOCAL WithVarPositions[32]                                          ' Existing - 826 MrBcx
        LOCAL PrefixedPositions[32]                                         ' 837 MrBcx - track Pass-2 prefixing

        FOR i = 1 TO Ndx                                                    ' Map cells that already
            IF Stk$[i] = WithVar$[WithCnt] THEN WithVarPositions[i] = TRUE  ' contain WithVar exactly,
        NEXT                                                                ' so we can restore them later

        i = Ndx
        DO WHILE i
            IF LEFTSTR(Stk$[i], "->") OR (*Stk$[i] = ASC(".") AND NOT IsDecimalNumber(Stk$[i]+1)) THEN
                IF WithVar$[WithCnt] = "Me" AND *Stk$[i] = ASC(".") THEN
                    IF InFunction THEN  Stk$[i] = "->" + MID$(Stk$[i], 2)
                END IF
                Stk$[i] = WithVar$[WithCnt] + Stk$[i]
                PrefixedPositions[i] = TRUE                                 ' 837 MrBcx
            END IF
            DECR i
        LOOP

        '*********************************************************************
        ' 837 MrBcx - Strip WithVar back off a token only when it's actually
        ' CHAINED off the previous token. Replaces the substring-based de-dup
        ' that broke lines like  .cchTextMax = Len(.pszText)  and any line
        ' with two independent dot-tokens. The keyword check via GetWordInfo
        ' (against the full BCXWords table, which includes PRINT, WITH, IF,
        ' RETURN, etc.) distinguishes "bm.bmWidth" (chained off identifier)
        ' from "PRINT .a" and "WITH .q" (fresh access after a statement keyword).
        '*********************************************************************

        IF WithVar$[WithCnt] <> "Me" THEN
            FOR i = 2 TO Ndx
                IF PrefixedPositions[i] = TRUE THEN
                    DIM IsChain = FALSE
                    IF PrefixedPositions[i-1] = TRUE OR WithVarPositions[i-1] = TRUE THEN
                        IsChain = TRUE                                      ' .x.y or tci.x.y
                    ELSEIF LEN(Stk$[i-1]) > 0 THEN
                        DIM LastCh AS UCHAR = Stk[i-1][LEN(Stk$[i-1])-1]
                        IF LastCh = ASC("]") OR LastCh = ASC(")") THEN
                            IsChain = TRUE                                  ' arr[i].y or func().y
                        ELSEIF isalnum(LastCh) OR LastCh = ASC("_") THEN
                            DIM PrevLower$ = LCASE$(Stk$[i-1])
                            IF GetWordInfo(PrevLower$) = NULL THEN
                                IsChain = TRUE                              ' bm.bmWidth (identifier)
                            END IF
                        END IF
                    END IF
                    IF IsChain THEN
                        REMOVE WithVar$[WithCnt] FROM Stk$[i]
                    END IF
                END IF
            NEXT
        END IF

        FOR i = 1 TO Ndx                                                    ' 826 MrBcx
            IF WithVarPositions[i] = TRUE THEN Stk$[i] = WithVar$[WithCnt]  ' Restore any WithVar cells
        NEXT                                                                ' that existed before translation
    END IF

    ' /\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ End 837 Update  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\

    IF PrependCnt THEN
        CALL BuildDelimStr(1, Ndx, Src$)
        CALL PreParse(Src$)
    END IF

    '************************************************************
    ' handle programming style global and locals using same name
    '************************************************************

    IF CompToken = 1 THEN

        Keyword$ = LCASE$(Stk$[1])

        SELECT CASE Keyword$
            CASE "dim"         :  CompToken = 0
            CASE "local"       :  CompToken = 0
            CASE "global"      :  CompToken = 0
            CASE "static"      :  CompToken = 0
            CASE "shared"      :  CompToken = 0
            CASE "raw"         :  CompToken = 0
            CASE "dynamic"     :  CompToken = 0
            CASE "free"        :  CompToken = 0
            CASE "redim"       :  CompToken = 0
            CASE "sub"         :  CompToken = 0
            CASE "function"    :  CompToken = 0
            CASE "overloaded"  :  CompToken = 0
            CASE "callback"    :  CompToken = 0
            CASE "public"      :  CompToken = 0
            CASE "declare"     :  CompToken = 0
            CASE "c_declare"   :  CompToken = 0
            CASE "auto"        :  CompToken = 0
            CASE "register"    :  CompToken = 0
            CASE "extern"      :  CompToken = 0
            CASE ELSE          :  CALL AsmUnknownStructs(1)
        END SELECT

    END IF
END SUB ' TokenSubstitutions


SUB LShiftStk (ToCell AS INT)
    IF Ndx <= 0 OR ToCell < 0 OR ToCell > Ndx THEN EXIT SUB
    DECR Ndx                                ' Adjust Ndx
    FOR i AS INT = ToCell TO Ndx            ' Shift contents left
        Stk$[i] = Stk$[i+1]
    NEXT
    Stk$[Ndx+1] = ""                        ' Erase shifted element
END SUB ' LShiftStk


SUB RShiftStk (FromCell AS INT)
    IF FromCell < 0 OR FromCell > Ndx OR Ndx >= UBOUND(Stk$) THEN EXIT SUB
    INCR Ndx                                ' Bump Ndx by 1
    FOR i AS INT = Ndx TO FromCell STEP -1  ' Shift contents right
        Stk$[i] = Stk$[i-1]
    NEXT
    Stk$[FromCell] = ""                     ' Erase original position
END SUB ' RShiftStk


SUB InsertOptionalParens (StartCell)
    CALL RShiftStk (StartCell)              ' Allow unparenthesized expressions
    Stk$[StartCell] = "("                   ' Only use this SUB for simple instances
    INCR Ndx
    Stk$[Ndx] = ")"
END SUB ' InsertOptionalParens


SUB JoinStrings(iThisToken, inIF)           ' NOTE: This is a recursive SUB
    '================================================================================
    ' The JoinStrings subroutine processes a tokenized line of code (Stk$[]) and
    ' rewrites sequences of string expressions joined by & into a single join$()
    ' call for cleaner output. It tracks context using flags like OnlyPara, InBrace,
    ' and inIF to avoid transforming code inside parameter lists, brackets, or
    ' conditional expressions. It handles nested expressions recursively by calling
    ' itself when encountering a "(" token, and merges the tokens into the correct
    ' string structure as it backtracks. This function ensures that concatenated
    ' strings are joined efficiently and consistently in transformed BCX BASIC code.
    '================================================================================
    DIM sj       = iThisToken
    DIM DoJoin   = 0
    DIM InBrace  = 0
    DIM OnlyPara = 0
    DIM j        = 0
    DIM vt       = 0
    DIM szToken$ = ""

    DO WHILE iThisToken <= Ndx
        szToken$ = Stk$[iThisToken]

        IF NOT j AND NOT OnlyPara AND NOT InBrace THEN
            vt = DataType(szToken$)
            IF vt = vt_INTEGER THEN vt = GetNextVarType(iThisToken)
            IF vt = vt_STRVAR OR vt = vt_STRLIT THEN
                sj = iThisToken
                INCR iThisToken
                ITERATE
            END IF
        END IF

        szToken$ = LCASE$(szToken$)

        SELECT CASE szToken$
            CASE "&"
                IF OnlyPara THEN EXIT SELECT
                vt = DataType(Stk$[iThisToken+1])

                IF vt = vt_INTEGER THEN vt = GetNextVarType(iThisToken+1)

                IF vt <> vt_STRVAR AND vt <> vt_STRLIT THEN
                    vt = DataType(Stk$[iThisToken-1])
                    IF vt = vt_INTEGER THEN vt = GetPrevVarType(iThisToken-1, 1)
                END IF

                IF vt = vt_STRVAR OR vt = vt_STRLIT THEN
                    INCR j
                    Stk$[iThisToken] = ","
                    szToken$ = ""
                END IF

            CASE "["
                INCR InBrace

            CASE "]"
                DECR InBrace

            CASE "("
                IF Stk$[iThisToken+1] <> "*" THEN
                    CALL JoinStrings(iThisToken+1, inIF)
                    DIM iBuildHere = iThisToken-1
                    DO WHILE Stk$[iThisToken] <> ")"
                        Stk$[iBuildHere] += Stk$[iThisToken] + SPC$
                        Stk$[iThisToken] = ""
                        INCR iThisToken
                    LOOP
                    Stk$[iBuildHere] += Stk$[iThisToken]
                    Stk$[iThisToken] = ""
                END IF

            CASE ")"
                IF j THEN
                    Stk$[sj] = "join$(" + STR$(j+1, TRUE) + "," + Stk$[sj]
                    j = sj
                    DO WHILE ++j < iThisToken
                        Stk$[sj] += Stk$[j]
                        Stk$[j] = ""
                    LOOP
                    Stk$[sj] += ")"
                END IF
                EXIT SUB

            CASE "||"
                Stk$[iThisToken] = "or"
                DoJoin = TRUE

            CASE "&&"
                Stk$[iThisToken] = "and"
                DoJoin = TRUE

            CASE "then", "for", "xfor"
                DoJoin = TRUE

            CASE "="
                IF NOT inIF THEN
                    OnlyPara = TRUE
                ELSE
                    DoJoin = TRUE
                END IF

            CASE "if", "elseif", "while"
                inIF = TRUE
                sj = iThisToken + 1

            CASE "sprint", "lprint", "fprint", "fprintf", "print", "print#"
                OnlyPara = TRUE

            CASE ELSE
                IF LEFTSTR(Stk$[iThisToken], "].") OR LEFTSTR(Stk$[iThisToken], "]->") THEN
                    DECR InBrace
                END IF
        END SELECT

        IF (DoJoin OR INCHR(",+-*/^;:<>~|&", szToken$)) AND NOT OnlyPara AND NOT InBrace THEN
            DoJoin = 0
            IF j THEN
                Stk$[sj] = "join$(" + STR$(j+1, 1) + "," + Stk$[sj]
                j = sj

                DO WHILE ++j < iThisToken
                    Stk$[sj] += Stk$[j]
                    Stk$[j] = ""
                LOOP

                Stk$[sj] += ")"
            END IF

            j = 0
            sj = iThisToken + 1
        END IF
        INCR iThisToken
    LOOP

    IF j THEN
        Stk$[sj] = "join$(" + STR$(j+1, 1) + "," + TRIM$(Stk$[sj])
        j = sj
        DO WHILE ++j <= iThisToken
            Stk$[sj] += TRIM$(Stk$[j])
            Stk$[j] = ""
        LOOP
        Stk$[sj] += ")"
    END IF

END SUB ' JoinStrings



SUB Transforms
    DIM RAW a
    DIM RAW i
    DIM RAW Keyword$
    DIM RAW tpBCX AS UDT_SUB_FUNC_TOKENS PTR

    Keyword$ = LCASE$(Stk$[1])
    tpBCX = GetWordInfo(Keyword$)

    IF tpBCX THEN
        IF (tpBCX->iWordInfo BAND eWI_Transform) = 0 THEN
            EXIT SUB
        END IF
    ELSE
        EXIT SUB
    END IF

    DIM LTmp$ * c_MaxSrcLen

    a = INCHR("abcdefghijklmnopqrstuvwxyz$", Keyword$)

    SELECT CASE a
        CASE 4

            '**************************************************************************
            ' The following code introduces the following DLL declarations to BCX
            '**************************************************************************
            '  DECLARE FUNCTION Foo LIB "FOO.DLL" ALIAS "FooA" (A$)
            '                     OR
            '  DECLARE FUNCTION Foo LIB "FOO.DLL" (A$) - Alias will default to "FOO"
            '  [508] Foo = (BCXFPROTx)GetProcAddress(H_FOO, "FooA");
            '**************************************************************************

            IF Keyword$ = "declare" AND m_iMatchWrd(Stk$[4], "lib") THEN
                DIM RAW szAlias$, kk, idx = -1

                REMOVE DQ$ FROM Stk$[5]
                FOR kk = 1 TO LoadLibsCnt
                    IF Stk$[5] = Loadlibs$[kk] THEN
                        idx = kk
                        EXIT FOR
                    END IF
                NEXT
                IF idx < 0 THEN

                    IF c_MaxLoadlibs = ++LoadLibsCnt THEN
                        CALL Abort("Maximum number of LIBs that can be loaded exceeded.")
                    END IF

                    Loadlibs$[LoadLibsCnt] = Stk$[5]
                END IF

                IF m_iMatchWrd(Stk$[6], "alias") THEN
                    szAlias$ = Stk$[7]
                    Stk$[6] = ""
                    Stk$[7] = ""
                ELSE
                    szAlias$ = ENC$(UCASE$(Stk$[3]))
                END IF

                INCR DllCnt

                IF DllCnt >= c_MaxDLLDecl THEN
                    CALL Abort("Maximum number of declarations exceeded.")
                END IF

                DIM mod_name$
                mod_name$ = UCASE$(RemoveExtension$(Stk$[5]))

                IF INCHR(mod_name$, "-") OR INCHR(mod_name$, ".") THEN
                    mod_name$ = REPLACE$ (mod_name$, "-.", "_")
                    mod_name$ = REPLACE$ (mod_name$, "-", "_")
                END IF

                DllDecl$[DllCnt]  = ""
                DllDecl$[DllCnt] += No_Sigil$(Stk$[3])   + "=(BCXFPROT"
                DllDecl$[DllCnt] += STR$(DllCnt, TRUE) + ")GetProcAddress(H_"
                DllDecl$[DllCnt] += mod_name$ + ", "  + szAlias$ + ");"

                Stk$[4] = ""
                Stk$[5] = ""
            END IF
            EXIT SUB


        CASE 9

            IF Keyword$ = "iremove" THEN
                '***********************************************************
                '  Translate   IREMOVE UCASE$("aaa") FROM LTRIM$(RTRIM$(A$))
                '  into   A$ = IREMOVE$(LTRIM$(RTRIM$(A$)),UCASE$("aaa"))
                '***********************************************************
                DIM RAW Mat$, Fat$

                FOR i = 2 TO Ndx
                    IF m_iMatchWrd(Stk$[i], "from") THEN
                        Stk$[i] = ""
                        EXIT FOR
                    END IF
                NEXT

                CALL BuildStr(2, i, Mat$)      ' build match string
                CALL BuildStr(i, Ndx, Fat$)    ' build fat source

                IF INCHR(Fat$, "$") = 0 THEN Fat$ += "$"
                IF INCHR(Mat$, "$") = 0 THEN Mat$ += "$"

                LTmp$ = "=iremove$(" + Fat$ + "," + Mat$ + ")"
                FastLexer(Fat$, " ()", "")
                LTmp$ = Stk$[Ndx] + LTmp$
                CALL PreParse(LTmp$)
                CALL TokenSubstitutions(1)
                CALL Function_Main_Support
                Ndx = 0
                EXIT SUB
            END IF

            IF Keyword$ = "ireplace" THEN
                '**********************************************************
                '  IREPLACE "this" WITH "that" IN A$ is transformed into
                '  A$ = ireplace$ (A$, "this", "that")
                '  BCX 3.73 introduces CASE INSENSITIVE REPLACE
                '**********************************************************

                IF Ndx < 6 THEN
                    CALL Abort("Problem with IREPLACE statement")
                END IF

                DIM RAW W, I, VV$, RR$, WW$

                FOR W = 2 TO Ndx
                    IF m_iMatchWrd(Stk$[W], "with") THEN
                        Stk$[W]= ""
                        EXIT FOR
                    END IF
                NEXT

                FOR I = 2 TO Ndx
                    IF m_iMatchWrd(Stk$[I], "in") THEN
                        Stk$[I]= ""
                        EXIT FOR
                    END IF
                NEXT

                CALL BuildStr(I+1, Ndx, VV$)
                CALL BuildStr(2, W, RR$)
                CALL BuildStr(W+1, I, WW$)

                IF INCHR(VV$, "$") = 0 THEN VV$ += "$"
                IF INCHR(RR$, "$") = 0 THEN RR$ += "$"
                IF INCHR(WW$, "$") = 0 THEN WW$ += "$"

                LTmp$ = "=ireplace$(" + VV$ + "," + RR$ + "," + WW$ + ")"
                FastLexer(VV$, " ()", "")
                LTmp$ = Stk$[Ndx] + LTmp$
                CALL PreParse(LTmp$)
                CALL TokenSubstitutions(1)
                CALL Function_Main_Support
                Ndx = 0
            END IF
            EXIT SUB

        CASE 18
            IF Keyword$ = "remove" THEN
                '***********************************************************
                '  Translate   REMOVE UCASE$("aaa") FROM LTRIM$(RTRIM$(A$))
                '  into   A$ = REMOVE$(LTRIM$(RTRIM$(A$)),UCASE$("aaa"))
                '***********************************************************
                DIM RAW Mat$, Fat$

                XFOR i = 2 WHILE i <= Ndx AND NOT m_iMatchWrd(Stk$[i], "from") BY i++
                XNEXT

                IF i > Ndx THEN
                    CALL Abort("Malformed REMOVE statement.")
                END IF

                CALL BuildStr(2, i-1, Mat$)     ' build match string
                CALL BuildStr(i+1, Ndx, Fat$)   ' build fat source

                IF INCHR(Fat$, "$") = 0 THEN Fat$ += "$"
                IF INCHR(Mat$, "$") = 0 THEN Mat$ += "$"

                LTmp$ = "=remove$(" + Fat$ + "," + Mat$ + ")"

                FastLexer(Fat$, " ()", "")
                LTmp$ = Stk$[Ndx] + LTmp$
                CALL PreParse(LTmp$)
                CALL TokenSubstitutions(1)
                CALL Function_Main_Support
                Ndx = 0
                EXIT SUB
            END IF

            IF Keyword$ = "replace" THEN
                '*******************************************************
                '  REPLACE "this" WITH "that" IN A$ is transformed into
                '  A$ = replace$ (A$, "this", "that")
                '  BCX 2.93 allows expressions and arrays to be used
                '*******************************************************

                IF Ndx < 6 THEN
                    CALL Abort("Problem with REPLACE statement")
                END IF

                DIM RAW W, I, VV$, RR$, WW$

                FOR W = 2 TO Ndx
                    IF m_iMatchWrd(Stk$[W], "with") THEN
                        Stk$[W]= ""
                        EXIT FOR
                    END IF
                NEXT

                FOR I = 2 TO Ndx
                    IF m_iMatchWrd(Stk$[I], "in") THEN
                        Stk$[I] = ""
                        EXIT FOR
                    END IF
                NEXT

                IF I < W OR W = 0 THEN
                    CALL Abort("Malformed REPLACE statement")
                END IF

                CALL BuildStr(I+1, Ndx, VV$)
                CALL BuildStr(2, W, RR$)
                CALL BuildStr(W+1, I, WW$)

                IF INCHR(VV$, "$") = 0 THEN VV$ += "$"
                IF INCHR(RR$, "$") = 0 THEN RR$ += "$"
                IF INCHR(WW$, "$") = 0 THEN WW$ += "$"

                LTmp$ = VV$ + "=replace$(" + VV$ + "," + RR$ + "," + WW$ + ")"
                CALL PreParse(LTmp$)
                CALL TokenSubstitutions(1)
                CALL Function_Main_Support
                Ndx = 0
            END IF
            EXIT SUB
    END SELECT
END SUB ' Transforms




FUNCTION FindVarInfo(szToken$, BYREF varid AS INT) AS UDT_VARINFO_STORAGE PTR
    '***********************************************************************
    ' Looks up szToken$ first in LocalVars, then GlobalVars.
    ' Returns a pointer to the matching UDT_VARINFO_STORAGE entry, or NULL.
    ' This helper consolidates the recurring local-then-global lookup pattern.
    '***********************************************************************
    DIM RAW i AS INT = CheckLocal(szToken$, ADDRESSOF(varid))
    IF i <> vt_UNKNOWN THEN
        FUNCTION = ADDRESSOF(LocalVars[varid])
    ELSEIF CheckGlobal(szToken$, ADDRESSOF(varid)) <> vt_UNKNOWN THEN
        FUNCTION = ADDRESSOF(GlobalVars[varid])
    ELSE
        FUNCTION = NULL
    END IF
END FUNCTION ' FindVarInfo


FUNCTION LookupVarType(szToken$, pVarid AS PINT) AS INT
    '***********************************************************************
    ' Shared "try local, then global" TYPE query — companion to FindVarInfo.
    ' Returns the vt_* type found in LocalVars or GlobalVars, or vt_UNKNOWN.
    ' The matching index is stored via pVarid (same contract as CheckLocal /
    ' CheckGlobal).  Call as: A = LookupVarType(name$, ADDRESSOF(myId))
    '***********************************************************************
    DIM RAW i AS INT = CheckLocal(szToken$, pVarid)
    IF i = vt_UNKNOWN THEN i = CheckGlobal(szToken$, pVarid)
    FUNCTION = i
END FUNCTION ' LookupVarType



FUNCTION GetNextVarType(iLoc AS INT) AS INT
    DIM RAW vt1 AS INT
    DIM RAW cvt1 AS INT
    DIM RAW Tmp AS INT
    DIM RAW k AS INT

    cvt1 = CheckType(Stk$[iLoc])
    IF cvt1 = 0 THEN
        vt1 = DataType(Stk$[iLoc])
    ELSE
        IF cvt1 = vt_UDT OR cvt1 = vt_STRUCT THEN
            IF *Stk$[iLoc+1] = ASC("[") THEN
                XFOR Tmp = iLoc+2, k = 1 WHILE Tmp <= Ndx AND k BY Tmp++
                    IF *Stk$[Tmp] = ASC("[") THEN INCR k
                    IF *Stk$[Tmp] = ASC("]") THEN DECR k
                XNEXT
                vt1 = DataType(Stk$[Tmp])
            ELSE
                vt1 = DataType(Stk$[iLoc+1])
            END IF
        ELSE
            IF cvt1 = vt_CHAR OR cvt1 = vt_SCHAR THEN
                DIM RAW varid AS INT
                DIM RAW vi AS UDT_VARINFO_STORAGE PTR
                vi = FindVarInfo(Stk$[iLoc], ADDRESSOF(varid))
                IF vi THEN
                    cvt1 = CINT(IIF(*(vi->VarDim), vt_STRVAR, DataType(Stk$[iLoc])))
                ELSE
                    cvt1 = DataType(Stk$[iLoc])
                END IF
            END IF
            vt1 = cvt1
        END IF
    END IF

    FUNCTION = vt1
END FUNCTION  ' GetNextVarType



FUNCTION GetPrevVarType(iLoc AS INT, iEarly AS INT) AS INT
    DIM RAW vt AS INT
    DIM RAW Tmp AS INT
    DIM RAW k AS INT

    IF Stk$[iLoc] = ")" OR Stk$[iLoc] = "]" THEN
        XFOR Tmp = iLoc-1, k = 1 WHILE Tmp >= iEarly AND k BY Tmp--
            IF *Stk$[Tmp] = ASC(")") THEN INCR k
            IF *Stk$[Tmp] = ASC("]") THEN INCR k
            IF *Stk$[Tmp] = ASC("(") THEN DECR k
            IF *Stk$[Tmp] = ASC("[") THEN DECR k
        XNEXT
        vt = DataType(Stk$[Tmp])
    ELSE
        vt = DataType(Stk$[iLoc])
        IF vt = vt_INTEGER THEN vt = CheckType(Stk$[iLoc])
        IF vt = vt_CHAR OR vt = vt_SCHAR THEN
            DIM RAW varid AS INT
            DIM RAW vi AS UDT_VARINFO_STORAGE PTR
            vi = FindVarInfo(Stk$[iLoc], ADDRESSOF(varid))
            IF vi AND *(vi->VarDim) THEN vt = vt_STRVAR
        END IF
    END IF

    FUNCTION = vt
END FUNCTION  ' GetPrevVarType



FUNCTION LocateJoiner(iStart AS INT)
    DO WHILE iStart < Ndx
        IF (Stk$[iStart] = "&") OR ((Stk$[iStart] = "+") AND (Stk$[iStart+1] <> "+")) THEN FUNCTION = iStart
        '  ^^^  DO NOT OPTIMIZE THE ABOVE LINE WITH POINTERS.  There's no benefit.  ~ MrBcx ~    ^^^
        ' More specifically, it is easily confused with continued lines and other ambiguities.
        INCR iStart
    LOOP
    FUNCTION = 0
END FUNCTION ' LocateJoiner



FUNCTION JoinStrTest(iStart AS INT, iEarly AS INT)  ' This is a recursive function
    DIM RAW Plus2Amp, vtLeft, vtRight, iJoiner, iDoJoin
    iDoJoin = 0
    Plus2Amp = iMatchNQ(Stk$[iStart++], "&")

    iJoiner = LocateJoiner(iStart)
    IF iJoiner = 0 THEN FUNCTION = iDoJoin
    vtLeft = GetPrevVarType(iJoiner-1, iEarly)
    vtRight = GetNextVarType(iJoiner+1)

    SELECT CASE vtLeft
        CASE vt_STRVAR, vt_STRLIT, vt_PSTR, vt_PSTRPTR, vt_PCHAR
            vtLeft = 1
        CASE ELSE
            vtLeft = 0
    END SELECT

    SELECT CASE vtRight
        CASE vt_STRVAR, vt_STRLIT, vt_PSTR, vt_PSTRPTR, vt_PCHAR
            vtRight = 1
        CASE ELSE
            vtRight = 0
    END SELECT

    IF vtLeft AND vtRight THEN
        Stk$[iJoiner] = "&"
        Plus2Amp = TRUE
        iEarly = iJoiner+1
    END IF

    iStart = iJoiner+1

    IF iStart < Ndx THEN
        iDoJoin = JoinStrTest(iStart, iEarly) BOR Plus2Amp
    ELSE
        iDoJoin = Plus2Amp
    END IF

    FUNCTION = iDoJoin
END FUNCTION ' JoinStrTest




SUB TransformOperator (OpName$, Subname$)
    '********************************************************************
    ' Consolidated and improved MOD  IMOD and ^  handler   -  837 MrBcx
    '********************************************************************
    IF HasThisToken(OpName$) = FALSE THEN EXIT SUB

    DIM B, Insert1, Insert2

    '*************************************

    FOR i AS INT = 1 TO Ndx - 1   ' 838 MrBcx updated this preprocessing loop
        IF Stk$[i] = "-" THEN
            ' Check if previous token indicates unary context
            DIM IS_Unary = FALSE
            IF i = 1 THEN
                IS_Unary = TRUE
            ELSE
                DIM Prev$ = Stk$[i-1]
                ' If preceded by an operator/delimiter, it's unary
                IF Prev$ = "=" OR Prev$ = "(" OR Prev$ = "," OR Prev$ = "^" OR _
                    Prev$ = "*" OR Prev$ = "/" OR Prev$ = "+" OR Prev$ = "-" THEN
                    IS_Unary = TRUE
                END IF
            END IF

            IF IS_Unary THEN
                Stk$[i] = "-" + Stk$[i+1]
                Stk$[i+1] = ""
                LShiftStk(i+1)
                DECR i ' Re-check current index since tokens shifted left
            END IF
        END IF
    NEXT

    '*************************************

    FOR i AS INT = Ndx TO 1 STEP -1

        ' Normalize
        IF Stk$[i] ?? "MOD" THEN Stk$[i] = "mod"
        IF Stk$[i] ?? "IMOD" THEN Stk$[i] = "imod"

        ' Decide if we should process this token
        DIM ProcessThis = FALSE
        IF OpName$ = "^"    AND Stk$[i] = "^"    AND Stk$[i+1] <> "="                      THEN ProcessThis = TRUE ' 838 MrBcx Changed
        IF OpName$ = "mod"  AND Stk$[i] = "mod"  AND Stk$[i+1] <> "(" AND Stk$[i-1] <> "=" THEN ProcessThis = TRUE
        IF OpName$ = "imod" AND Stk$[i] = "imod" AND Stk$[i+1] <> "(" AND Stk$[i-1] <> "=" THEN ProcessThis = TRUE

        IF NOT ProcessThis THEN ITERATE

        ' Original left operand finder
        Insert1 = i - 1
        B = 0
        DO WHILE Stk$[Insert1] <> "="
            IF *Stk$[Insert1] = ASC("]") OR *Stk$[Insert1] = ASC(")") THEN INCR B  ' Pointer Based Comparisons
            IF *Stk$[Insert1] = ASC("[") OR *Stk$[Insert1] = ASC("(") THEN DECR B  ' Pointer Based Comparisons
            IF B = 0 THEN EXIT DO
            DECR Insert1
        LOOP

        IF *Stk$[Insert1] = ASC("[") THEN DECR Insert1                             ' Pointer Based Comparisons
        IF *Stk$[Insert1] = ASC("=") THEN INCR Insert1                             ' Pointer Based Comparisons

        IF *Stk$[Insert1] = ASC("(") THEN                                          ' Pointer Based Comparisons
            B = DataType(Stk$[Insert1-1])
            IF B = vt_INTEGER OR B = vt_SINGLE OR B = vt_DOUBLE THEN
                IF ISFALSE(m_iMatchWrd(Stk$[Insert1-1], "print")) THEN DECR Insert1
            END IF
        END IF

        DECR Insert1

        ' Replace operator with comma
        Stk$[i] = ","

        ' Find end of right operand
        Insert2 = i + 1
        B = DataType(Stk$[Insert2])
        IF B = vt_INTEGER OR B = vt_SINGLE OR B = vt_DOUBLE THEN
            IF *Stk$[Insert2 + 1] = ASC("(") OR *Stk$[Insert2 + 1] = ASC("[") THEN INCR Insert2
        END IF

        B = 0
        DO WHILE Insert2 <= Ndx
            IF *Stk$[Insert2] = ASC("[") OR *Stk$[Insert2] = ASC("(") THEN INCR B  ' Pointer Based Comparisons
            IF *Stk$[Insert2] = ASC("]") OR *Stk$[Insert2] = ASC(")") THEN DECR B  ' Pointer Based Comparisons
            IF B = 0 THEN EXIT DO
            INCR Insert2
        LOOP

        ' Insert in reverse order
        InsertTokens(Insert2, 1, ")")
        InsertTokens(Insert1, 2, Subname$, "(")

    NEXT i

    '*************************************
    FOR i AS INT = 1 TO Ndx                               ' 837 V3  by MrBcx
        ' Normalize
        IF Stk$[i] ?? "-MOD"  THEN Stk$[i] = "-fmod"   ' Looks strange but is crucial
        IF Stk$[i] ?? "-IMOD" THEN Stk$[i] = "-imod"   ' Looks strange but is crucial
    NEXT
    '*************************************
END SUB ' TransformOperator




SUB FixUps
    DIM AS INT A, B, i, j, CommaCnt, AmpCnt
    DIM AS STRING LTmp$, LStk1$, LStk2$, Var1$

    PassOne = FALSE

    '***********************************************************
    ' Join strings using Join(StringCount, string1, string2, ...)
    '***********************************************************
    IF NOT m_iMatchWrd(Stk$[1], "function")  THEN
        IF JoinStrTest(1, 1) THEN
            DIM RAW k, temp
            j = 0
            k = 0
            AmpCnt = 0

            XFOR temp = 1 WHILE temp < Ndx AND (j = 0 OR k = 0) BY temp++
                IF Stk$[temp] = "&" THEN
                    A = GetNextVarType(temp+1)
                    IF A = vt_STRVAR OR A = vt_STRLIT THEN
                        INCR AmpCnt
                        IF ISZERO(k) THEN k = temp
                    END IF
                ELSE
                    A = LookupVarType(Stk$[temp], ADDRESSOF(i))
                    IF A = vt_STRUCT OR A = vt_UDT OR A = vt_UNION THEN
                        j = 1
                    END IF
                END IF
            XNEXT

            IF AmpCnt > 1 THEN
                Use_Join = Use_BcxTempStr = TRUE
            END IF

            IF k THEN
                IF j THEN CALL AsmUnknownStructs(0)
                CALL JoinStrings(1, 0)
                CALL BuildDelimStr(1, Ndx, Src$)
                CALL PreParse(Src$)
            END IF
        END IF
    END IF


    '***********************************************************
    ' Moved here by Mike H. Was being applied too early.
    ' causing lines with multiple statements to not receive the
    ' conversion. i.e. sp->lpVtbl->Release(sp) : sp = NULL
    '***********************************************************

    IF UseCpp THEN
        IF iMatchNQ(Src$, "->lpVtbl") THEN
            FOR tt AS INT = 1 TO Ndx
                IF m_iMatchRgt(Stk$[tt], "->lpVtbl") THEN
                    Stk$[tt] = EXTRACT$(Stk$[tt], "->lpVtbl")
                    IF (Stk$[tt+3] = Stk$[tt-1] OR Stk$[tt+3] = Stk$[tt]) AND Stk$[tt+3] <> ")" THEN
                        Stk$[tt+3] = ""
                        IF Stk$[tt+4] = "," THEN Stk$[tt+4] = ""
                    END IF
                END IF
            NEXT
            CALL RemEmptyTokens
        END IF
    END IF

    '********************************************************************
    '  At this point we have a fresh set of Stk$[] values, totaling Ndx
    '                Start handling some unique situations
    '********************************************************************

    ' This block helps Im_UDT_String() distinguish pointer expressions from string expressions
    IF InTypeDef THEN
        FOR tt AS INT = 1 TO Ndx
            IF Stk$[tt] ?? "PSTR" THEN Stk$[tt] = "PTCHAR"
        NEXT
        FOR tt AS INT = 1 TO Ndx
            IF Stk$[tt] ?? "PCHAR" THEN Stk$[tt] = "PTCHAR"
        NEXT
        FOR tt AS INT = 1 TO Ndx-1
            IF Stk$[tt] ?? "CHAR" AND _
                Stk$[tt+1] ?? "PTR" THEN
                Stk$[tt] = "PTCHAR"
                LShiftStk(tt+1)
            END IF
        NEXT
    END IF

    '********************************************************************
    '    [ Call New Consolidated  Operator Handler ]  -- 837 by MrBcx
    '********************************************************************

    TransformOperator("^", "pow")     ' Arg1 = operator, Arg2 = fnc name
    TransformOperator("mod", "mod")
    TransformOperator("imod", "imod")

    '******************************
    CALL TokenSubstitutions(1)
    IF Ndx = 0 THEN EXIT SUB
    '******************************

    IF Ndx = 3 AND ISZERO(WithCnt) THEN
        IF *Stk$[2] = ASC("+") AND *Stk$[3] = ASC("+") THEN
            FPRINT FP_WRITE, Scoot$, No_Sigil$(Stk$[1]), "++;"
            Ndx = 0
            INCR Statements
            EXIT SUB
        END IF
        IF *Stk$[2] = ASC("-") AND *Stk$[3] = ASC("-") THEN
            FPRINT FP_WRITE, Scoot$, No_Sigil$(Stk$[1]), "--;"
            Ndx = 0
            INCR Statements
            EXIT SUB
        END IF
        IF *Stk$[1] = ASC("+") AND *Stk$[2] = ASC("+") THEN
            FPRINT FP_WRITE, Scoot$, "++", No_Sigil$(Stk$[3]), ";"
            Ndx = 0
            INCR Statements
            EXIT SUB
        END IF
        IF *Stk$[1] = ASC("-") AND *Stk$[2] = ASC("-") THEN
            FPRINT FP_WRITE, Scoot$, "--", No_Sigil$(Stk$[3]), ";"
            Ndx = 0
            INCR Statements
            EXIT SUB
        END IF
    END IF

    '******************************
    IsCallBack = 0
    IF m_iMatchWrd(Stk$[Ndx], "callback") THEN
        IsCallBack = 1
        Stk$[Ndx--] = ""
    END IF
    '******************************

    CALL Transforms

    IF Ndx = 0 THEN EXIT SUB

    '********************************************************************
    '          Modification to allow 2 names as function types
    '********************************************************************

    IF m_iMatchWrd(Stk$[1], "function") OR m_iMatchWrd(Stk$[1], "impfunction") THEN
        IF m_iMatchWrd(Stk$[Ndx-2], "as") AND Stk$[Ndx] <> ")" THEN
            IF ISFALSE(m_iMatchWrd(Stk$[Ndx], "export")) AND _
                ISFALSE(m_iMatchWrd(Stk$[Ndx], "stdcall")) THEN
                Stk$[Ndx-1] += SPC$ + Stk$[Ndx]
                DECR Ndx
            END IF
        END IF
    END IF

    '********************************************************************
    ' Modification to allow 2 names as argument types in sub or function
    '********************************************************************
    DIM iP = 1

    IF m_iMatchLft(Stk$[1], "public") OR m_iMatchLft(Stk$[1], "private") THEN INCR iP

    IF m_iMatchWrd(Stk$[iP], "function") OR m_iMatchWrd(Stk$[iP], "sub") THEN
        DIM RAW offset
        DIM LastBrk = Ndx - 2

        FOR i = Ndx TO 3 STEP -1
            IF *Stk$[i] = ASC(")") THEN
                LastBrk = i
                EXIT FOR
            END IF
        NEXT

        XFOR i = 3, INT jjj = 1 WHILE i <= LastBrk AND jjj BY i++
            offset = 2
            jjj = m_GetAsPosF(i, LastBrk)
            IF jjj THEN
                i = jjj
                IF (i < LastBrk) AND Stk$[i + offset] <> "=" THEN
                    IF m_iMatchWrd(Stk$[i+1], "function") THEN offset = 3
                    IF ISFALSE(INCHR(Stk$[i + offset], ")")) AND _
                        ISFALSE(INCHR(Stk$[i + offset], ",")) THEN
                        IF NOTZERO(LEN(Stk$[i + offset])) AND _
                            ISFALSE(m_iMatchWrd(Stk$[i + 3], "as")) THEN
                            Stk$[i+offset-1] += SPC$ + Stk$[i+offset]
                            Stk$[i + offset] = ""
                        END IF
                    END IF
                END IF
            END IF
        XNEXT

    END IF
    '***********************************************************
    '                      DynaCall Handler
    '***********************************************************

    IF ISFALSE(m_iMatchWrd(Stk$[1], "declare")) THEN
        FOR i = 1 TO Ndx
            IF m_iMatchWrd(Stk$[i], "lib") THEN
                IF Stk$[i-1] = "(" AND (DataType(Stk$[i+1]) = vt_STRLIT OR DataType(Stk$[i+1]) = vt_STRVAR) THEN
                    j = GetNumArgs(i+2)
                    LTmp$ = "BCX_DynaCallB"
                    IF ISFALSE(m_iMatchWrd(Stk$[1], "print")) THEN  ' print does its own casting
                        IF DataType(Stk$[i-2]) = vt_STRVAR OR DataType(Stk$[1]) = vt_STRVAR THEN
                            LTmp$ = "(char*)" + LTmp$
                        END IF
                    END IF
                    Var1$ = RIGHT$(Stk$[i-2], 1)
                    IF INCHR (c_VARTYPES$, Var1$) THEN
                        LTmp$ += Var1$
                        Stk$[i] = ENC$(LEFT$(Stk$[i-2], LEN(Stk$[i-2]) - 1))
                    ELSE
                        Stk$[i] = ENC$(Stk$[i-2])
                    END IF
                    Stk$[i-2] = LTmp$
                    FOR B = Ndx+3 TO i+3 STEP -1
                        Stk$[B] = Stk$[B-3]
                    NEXT
                    Stk$[i+2] = Stk$[i+1]
                    Stk$[i+1] = ","
                    Stk$[i+3] = ","
                    Stk$[i+4] = STR$(j, 1)
                    Stk$[i+5] = IIF$(j, ",", ")")
                    INCR Ndx, 3
                    Use_DynacallCommon = Use_Dynacall = Use_BcxTempStr = Use_Proto = TRUE
                END IF
            END IF
        NEXT
    END IF

    '*****************************************************
    LStk1$ = LCASE$(Stk$[1])   ' Performance Optimizer
    LStk2$ = LCASE$(Stk$[2])   ' Performance Optimizer
    '*****************************************************


    '*****************************************************
    ' We're looking for a OPEN "name" AS BINARY ... clause
    '*****************************************************

    IF LStk1$ = "open" THEN

        FOR A = 2 TO Ndx
            IF m_iMatchWrd(Stk$[A], "binary") THEN
                EXIT FOR
            END IF
        NEXT

        IF A = Ndx THEN EXIT SUB  ' This is not a "BINARY" clause OPEN statement

        IF A < Ndx THEN
            INCR A
            Var1$ = LCASE$(Stk$[A])

            IF Var1$ = "new" THEN
                Stk$[A-1]= "binarynew"
                LShiftStk(A)
                EXIT SUB
            END IF

            IF Var1$ = "append" THEN
                Stk$[A-1]= "binaryappend"
                LShiftStk(A)
                EXIT SUB
            END IF

            IF Var1$ = "input" THEN
                Stk$[A-1]= "binaryinput"
                LShiftStk(A)
                EXIT SUB
            END IF

            IF Var1$ = "output" THEN
                Stk$[A-1]= "binaryoutput"
                LShiftStk(A)
                EXIT SUB
            END IF
        END IF
    END IF

    '******************************

    IF LStk1$ = "option" THEN
        IF LStk2$ = "base" THEN
            OptionBase = m_IVAL (Stk$[3])
            Ndx = 0
            EXIT SUB
        END IF
    END IF

    '******************************

    IF LStk1$ = "dim"  THEN
        LTmp$ = ENC$(LStk2$, ASC(SPC$))
        IF iMatchNQ (" shared , dynamic , raw , local , auto , register , static ", LTmp$) THEN
            Stk$[1] = LStk2$
            LStk1$ = LStk2$
            LShiftStk(2)
        END IF
        EXIT SUB
    END IF

    '******************************

    IF LStk1$ = "public" THEN
        IF LStk2$ = "function" OR LStk2$ = "sub" THEN
            IF InClass THEN
                LStk1$ += LStk2$
                Stk$[1] = LStk1$
            ELSE
                Stk$[1] = LStk2$
            END IF
            LShiftStk(2)
        END IF
        EXIT SUB
    END IF

    '******************************

    ' creates a static function for use in $PROJECTs
    IF LStk1$ = "private" THEN
        IF LStk2$ = "function" OR LStk2$ = "sub" THEN
            IF InClass THEN
                LStk1$ += LStk2$
                Stk$[1] = LStk1$
            ELSE
                Use_Static = TRUE
                Stk$[1] = LStk2$
            END IF
            LShiftStk(2)
        END IF
        EXIT SUB
    END IF

    '******************************

    IF LStk1$ = "onexit" THEN
        IF LStk2$ = "sub" THEN
            Use_ExitCode = Use_Proto = TRUE

            IF c_MaxExitSub = ++ExitNdx THEN
                CALL Abort("Maximum number of exit calls exceeded.")
            END IF

            ExitSub$[ExitNdx] = Stk$[3]
            Stk$[1] = LStk2$
            LStk1$ = LStk2$
            LShiftStk(2)
        END IF
        EXIT SUB
    END IF

    '******************************

    IF LStk1$ = "onstart" THEN
        IF LStk2$ = "sub" THEN
            Use_StartupCode = Use_Proto = TRUE

            IF c_MaxStartSub = ++StartNdx THEN
                CALL Abort("Maximum number of startup calls exceeded.")
            END IF

            StartSub$[StartNdx] = Stk$[3]
            Stk$[1] = LStk2$
            LStk1$ = LStk2$
            LShiftStk(2)
            EXIT SUB
        END IF
        CALL Abort("ONSTART syntax error, can only be used with a SUB.")
    END IF

    '******************************

    IF LStk1$ = "overloaded" THEN
        IF LStk2$ = "function" THEN
            Stk$[1] = "overloadedfunction"
            LStk1$ = "overloadedfunction"
            LShiftStk(2)
            IF Stk$[2] <> "=" THEN
                OkayToSend = TRUE
            END IF
            EXIT SUB
        END IF

        IF LStk2$ = "sub" THEN
            Stk$[1]= "overloadedsub"
            LShiftStk(2)
            EXIT SUB
        END IF
    END IF

    '******************************

    IF LStk1$ = "function" THEN
        IF m_iMatchWrd(Stk$[3], "optional") THEN
            Stk$[1]= "optfunction"
            LStk1$ = "optfunction"
            LShiftStk(3)
            IF Stk$[2] <> "=" THEN
                OkayToSend = TRUE
            END IF
            EXIT SUB
        END IF
    END IF

    IF UseCpp = FALSE THEN           ' C++ doesn't need the OPTIONAL keyword
        IF LStk1$ = "function" THEN  ' Bcx 772 detects OPTIONAL without keyword
            IF Stk$[2] <> "=" THEN
                FOR ij AS INT = 3 TO Ndx
                    IF Stk$[ij] = "=" THEN
                        Stk$[1]= "optfunction"
                        LStk1$ = "optfunction"
                        OkayToSend = TRUE  ' 831 Added by MrBcx
                        EXIT SUB
                    END IF
                NEXT
            END IF
        END IF
    END IF

    '******************************

    IF LStk1$ = "sub" THEN
        IF m_iMatchWrd(Stk$[3], "optional") THEN
            LStk1$ = "optsub"
            Stk$[1]= "optsub"
            LShiftStk(3)
            EXIT SUB
        END IF
    END IF

    IF UseCpp = FALSE THEN        ' C++ doesn't need the OPTIONAL keyword
        IF LStk1$ = "sub" THEN    ' Bcx 772 detects OPTIONAL without keyword
            FOR ij AS INT = 2 TO Ndx
                IF Stk$[ij] = "=" THEN
                    Stk$[1]= "optsub"
                    LStk1$ = "optsub"
                    EXIT SUB
                END IF
            NEXT
        END IF
    END IF

    '******************************

    IF LStk1$ = "end" THEN
        IF Stk$[2] <> "=" THEN
            Stk$[1]= LStk1$ + LStk2$
            IF Ndx = 2 THEN
                Ndx = 1
                EXIT SUB
            ELSE
                IF m_iMatchWrd(Stk$[3], "as") THEN
                    Stk$[2] = ""
                    CALL RemEmptyTokens
                    EXIT SUB
                END IF
            END IF
        END IF
    END IF

    '******************************

    IF LStk1$ = "function" THEN
        IF Stk$[2] <> "=" THEN
            OkayToSend = TRUE
        END IF
    END IF

    '******************************

    IF LStk1$ = "midstr"  THEN

        IF INCHR(Stk$[3], DQ$) THEN
            CALL Abort ("MID$ statement string argument cannot be a literal")
        END IF

        CommaCnt = 0

        FOR i = 1 TO Ndx
            IF *Stk$[i] = ASC(",") THEN
                INCR CommaCnt
            ELSEIF Stk$[i]= "=" THEN
                IF CommaCnt < 2 THEN
                    Stk$[i] = "-1,"
                ELSE
                    Stk$[i]= ""
                END IF
                Stk$[i-1]= ","
                INCR Ndx
                Stk$[Ndx]= ")"
                EXIT FOR
            END IF
        NEXT
    END IF

    '******************************

    IF LStk1$ = "endevents" OR LStk1$ = "endmdievents" OR LStk1$ = "endmdichildevents" THEN
        DIM RAW szError$

        IF Use_Vscroll OR Use_Hscroll THEN
            Use_Max = Use_Min = TRUE

            Src$ = "GLOBAL BCX_siX AS SCROLLINFO"   : CALL Inject (Src$)
            Src$ = "GLOBAL BCX_siY AS SCROLLINFO"   : CALL Inject (Src$)
            Src$ = "GLOBAL BCX_DynaScroll AS INT"   : CALL Inject (Src$)

            FPRINT FP_WRITE, "static  int BCX_ViewWidth =", Use_Hscroll, ";"
            FPRINT FP_WRITE, "static  int BCX_ViewHeight =", Use_Vscroll, ";"
            FPRINT FP_WRITE, "static  int BCX_SmallChangeX;"
            FPRINT FP_WRITE, "static  int BCX_SmallChangeY;"
            FPRINT FP_WRITE, "static  int BCX_LargeChangeX;"
            FPRINT FP_WRITE, "static  int BCX_LargeChangeY;"
            FPRINT FP_WRITE, "static  int BCX_ScrollInit;"
            FPRINT FP_WRITE, ""
            FPRINT FP_WRITE, "  if(!BCX_ScrollInit)"
            FPRINT FP_WRITE, "   {"
            FPRINT FP_WRITE, "     BCX_siY.cbSize=sizeof(BCX_siY);"
            FPRINT FP_WRITE, "     BCX_siX.cbSize=sizeof(BCX_siX);"
            FPRINT FP_WRITE, "     BCX_siY.fMask=SIF_ALL;"
            FPRINT FP_WRITE, "     BCX_siX.fMask=SIF_ALL;"
            FPRINT FP_WRITE, "     BCX_siX.nMax=BCX_ViewWidth;"
            FPRINT FP_WRITE, "     BCX_siY.nMax=BCX_ViewHeight;"
            FPRINT FP_WRITE, "     BCX_SmallChangeX=1;"
            FPRINT FP_WRITE, "     BCX_LargeChangeX=20;"
            FPRINT FP_WRITE, "     BCX_SmallChangeY=1;"
            FPRINT FP_WRITE, "     BCX_LargeChangeY=20;"
            FPRINT FP_WRITE, "     BCX_siY.nPage=1;"
            FPRINT FP_WRITE, "     BCX_siX.nPage=1;"
            FPRINT FP_WRITE, "     SetScrollInfo(hWnd,SB_VERT,&BCX_siY,TRUE);"
            FPRINT FP_WRITE, "     SetScrollInfo(hWnd,SB_HORZ,&BCX_siX,TRUE);"
            FPRINT FP_WRITE, "     BCX_DynaScroll=TRUE;"
            FPRINT FP_WRITE, "     BCX_ScrollInit=TRUE;"
            FPRINT FP_WRITE, "   }"
            FPRINT FP_WRITE, " if(Msg==WM_HSCROLL||Msg==WM_VSCROLL||Msg==WM_SIZE)"
            FPRINT FP_WRITE, "   {"
            FPRINT FP_WRITE, "     BCX_Scroll(hWnd,Msg,wParam,lParam,BCX_LargeChangeX,"
            FPRINT FP_WRITE, "     BCX_LargeChangeY,BCX_SmallChangeX,BCX_SmallChangeY,"
            FPRINT FP_WRITE, "     BCX_ViewWidth,BCX_ViewHeight,BCX_DynaScroll);"
            FPRINT FP_WRITE, "   }"
        END IF

        IF ISFALSE(Use_BCX_Class_Info) THEN
            Use_BCX_Class_Info = TRUE
            iEmitVarGroup = iEmitVarGroup BOR (eFontGroup BOR eClassName)
        END IF

        IF LStk1$ <> "endmdichildevents" AND Use_MainEvent THEN
            Use_MainEvent = FALSE
            FPRINT FP_WRITE, "  if(Msg==WM_DESTROY)"
            FPRINT FP_WRITE, "    {"
            FPRINT FP_WRITE, "       OleUninitialize();"
            FPRINT FP_WRITE, "       CoUninitialize();"
            FPRINT FP_WRITE, "       PostQuitMessage(0);"
            FPRINT FP_WRITE, "       return EXIT_SUCCESS;"
            FPRINT FP_WRITE, "    }"
        END IF

        IF LStk1$ = "endevents" THEN
            FPRINT FP_WRITE, "Bcx_RetVal = DefWindowProc(hWnd,Msg,wParam,lParam);"
            FPRINT FP_WRITE, "return Bcx_RetVal; // endevents"

        ELSEIF LStk1$ = "endmdievents" THEN
            FPRINT FP_WRITE, "Bcx_RetVal = DefFrameProc(hWnd,BCX_hwndMDIClient,Msg,wParam,lParam);"
            FPRINT FP_WRITE, "return Bcx_RetVal;"

        ELSEIF LStk1$ = "endmdichildevents" THEN
            FPRINT FP_WRITE, "Bcx_RetVal = DefMDIChildProc(hWnd,Msg,wParam,lParam);"
            FPRINT FP_WRITE, "return Bcx_RetVal;"
        END IF

        FPRINT FP_WRITE, "}\n\n"
        sprintf(szError, "Too many unindents for END %s", UCASE$(LStk1+3))
        CALL BumpDown(szError$)

        IF Indent THEN
            PRINT REPEAT$(80, "_")
            PRINT "Possible missing END IF before END " + UCASE$(MID$(LStk1$, 4))
            PRINT REPEAT$(80, "_")
        END IF

        Ndx = 0
        InFunction = FALSE
        EXIT SUB
    END IF

    '******************************

    IF Stk$[2]= ":" THEN
        IF Ndx = 2 THEN
            LTmp$ = ENC$(LStk1$, ASC(SPC$))
            IF iMatchNQ(" public , private , protected ", LTmp$) = 0 THEN
                Stk$[1]= UCASE$(Stk$[1]) + ":"    ' preserve the GOTO labels
                Ndx = 1
            END IF
            EXIT SUB
        END IF
    END IF

    '******************************
    IF m_iMatchWrd(Stk$[3], "createwindow") THEN    ' HELPER
        Comma = 0
        FOR A = 4 TO Ndx
            IF Stk$[A]= "," THEN INCR Comma
            IF Stk$[A]= "," THEN
                IF Comma = 8 THEN
                    Stk$[A]= ",(HMENU)(UINT_PTR)"
                    INCR Comma
                END IF
            END IF
        NEXT
    END IF

    '******************************

    IF m_iMatchWrd(Stk$[3], "createwindowex") THEN
        Comma = 0
        FOR A = 4 TO Ndx
            IF Stk$[A]= "," THEN INCR Comma
            IF Stk$[A]= "," THEN
                IF Comma = 9 THEN       ' BEWARE - if any args contains commas, this helper blows up
                    Stk$[A]= ",(HMENU)(UINT_PTR)"
                    INCR Comma
                END IF
            END IF
        NEXT
    END IF

    '******************************

    IF *Stk$[Ndx]= ASC("*") THEN
        Stk$[Ndx-1] += "*"
        DECR Ndx
    END IF

    '******************************

    IF m_iMatchWrd(Stk$[3], "setwindowlong") OR m_iMatchWrd(Stk$[3], "setwindowlongptr") THEN    ' HELPER
        Comma = 0
        Stk$[3]= "(WNDPROC)(LONG_PTR)SetWindowLongPtr"
        FOR A = 4 TO Ndx
            IF Stk$[A]= "," THEN INCR Comma
            IF Stk$[A]= "," THEN
                IF Comma = 2 THEN
                    Stk$[A]= ",(LONG_PTR)"
                    INCR Comma
                END IF
            END IF
        NEXT
        EXIT SUB
    END IF

    IF TestState = TRUE THEN
        LOCAL Tmp$
        IF LastCmd = 0 THEN
            IF *Stk$[1] = ASC("*") THEN
                Tmp$ = No_Sigil$(Stk$[2])
            ELSE
                Tmp$ = No_Sigil$(Stk$[1])
            END IF
            IF LEFTSTR(Tmp$, "*") THEN Tmp$ = MID$(Tmp$, 2)
            i = INCHR(Tmp$, ".")
            IF i = 0 THEN i = iMatchNQ (Tmp$, "->")
            IF i > 0 THEN
                IF WithCnt THEN
                    Tmp$ = WithVar$[WithCnt]
                ELSE
                    Tmp$ = LEFT$(Tmp$, i - 1)
                END IF
            END IF
            IF INCHR(Tmp$, "[") THEN Tmp$ = EXTRACT$(Tmp$, "[")
            IF FindVarInfo(Tmp$, ADDRESSOF(j)) = NULL THEN
                Tmp$ = LCASE$(Tmp$)

                IF Stk$[2] = "=" AND IsAllowedContext(Tmp$) AND iMatchNQ(Src$, "->") = 0 THEN  ' MrBcx 827 - Refactored
                    Warning("Assignment before Declaration in Line " + STR$(LineNum[FileNdx]) + " in Module: " + TRIM$(FileNames$[FileNdx]) + ": " + Src$)
                END IF

            END IF
        END IF
    END IF
END SUB ' FixUps



FUNCTION IsAllowedContext(Tmp$) AS INT                         ' MrBcx 827 -  New
    IF Tmp$ = "functionreturn" THEN FUNCTION = FALSE
    IF Tmp$ = "bcx_retstr" THEN FUNCTION = FALSE
    IF Tmp$ = "end" THEN FUNCTION = FALSE
    FUNCTION = TRUE
END FUNCTION ' IsAllowedContext



SUB RemEmptyTokens
    '********************************************
    ' This SUB removes empty tokens from Stk$[].
    '********************************************
    DIM RAW i, j
    FOR i = 1 TO Ndx
        IF ISNULL(Stk$[i]) THEN
            j = i
            DO WHILE ISNULL(Stk$[j]) AND (j < Ndx)
                INCR j
            LOOP
            IF ISNULL(Stk$[j]) THEN EXIT FOR
            Stk$[i] = Stk$[j]
            Stk$[j] = ""
        END IF
    NEXT i
    Ndx = i-1
END SUB ' RemEmptyTokens



SUB FuncSubDecs1 ( _
    s$     ,       _
    iStart AS INT, _
    iEnd   AS INT, _
    ptVar  AS UDT_VARCODE_ATTRIBUTES PTR)

    '****************************
    DIM RAW iBrktPairLoc, iEmpty
    '****************************

    IF m_iMatchRgt(Stk$[iStart], s$) THEN
        IF DataType(Stk$[iStart+1]) = vt_STRVAR THEN
            Abort("Invalid " + s$ + " name")
        END IF
    END IF

    XFOR iEmpty = FALSE, iBrktPairLoc = m_GetBrkPairPos(iStart, iEnd) WHILE iBrktPairLoc _
        BY iBrktPairLoc = m_GetBrkPairPos(iBrktPairLoc, iEnd)
        DIM iVarLoc = iBrktPairLoc - 1
        IF m_iMatchWrd(Stk$[iBrktPairLoc+2], "as") THEN
            Stk$[iBrktPairLoc+3] = Stk$[iBrktPairLoc+3] + "*"
            Stk$[iBrktPairLoc++] = "" : Stk$[iBrktPairLoc] = ""
            iEmpty = TRUE
        ELSEIF Stk$[iBrktPairLoc+2] = "[" THEN
            DO WHILE iBrktPairLoc <= iEnd
                IF m_iMatchWrd(Stk$[iBrktPairLoc], "as") THEN EXIT DO
                IF m_iMatchRgt(Stk$[iVarLoc], "]") AND INCHR(",)=", Stk$[iBrktPairLoc]) THEN EXIT DO
                Stk$[iVarLoc] += Stk$[iBrktPairLoc]
                Stk$[iBrktPairLoc++] = ""
                iEmpty = TRUE
            LOOP
        ELSE
            DIM iDataType = DataType(Stk$[iVarLoc])
            Stk$[iVarLoc] = No_Sigil$(Stk$[iVarLoc])
            IF iDataType = vt_STRVAR THEN
                CALL InsertTokens(iBrktPairLoc+1, 5, "[", "BCXSTRSIZE", "]", "as", "char")
                INCR iEnd, 5
            ELSE
                Stk$[iBrktPairLoc++] = "as"
                Stk$[iBrktPairLoc] = GetVarTypeName$(iDataType) + "*"
            END IF
        END IF
    XNEXT

    IF m_iMatchWrd(Stk$[iEnd], "export") THEN
        DECR Ndx
        ptVar->IsExported = TRUE
        IF UseStdCall THEN
            CallType$ = "__stdcall "
        ELSE
            CallType$ = "__cdecl "
        END IF
    END IF

    IF iEmpty THEN
        CALL RemEmptyTokens
    END IF
END SUB ' FuncSubDecs1



SUB FuncSubDecs2(                           _
    s$,                                     _
    methd,                                  _
    VarCode AS UDT_VARCODE_ATTRIBUTES PTR,  _
    iFirstToken AS INT,                     _
    iLastToken  AS INT PTR)

    IF m_iMatchRgt(Stk$[iFirstToken], s$) THEN
        IF m_iMatchWrd(Stk$[*iLastToken-1], "as") THEN              ' SUB Foo () AS NOT_ALLOWED_DATATYPE
            CALL Abort("Attempted type assignment to " + s$)
        END IF
        VarCode->IsPtrFlag = 0
        CurrentFuncType = vt_VOID
    ELSE
        IF m_iMatchWrd(Stk$[(*iLastToken)-1], "as") THEN
            CurrentFuncType   = CheckType(Stk$[*iLastToken])
            VarCode->Token$   = Stk$[iFirstToken+1]
            VarCode->AsToken$ = Stk$[*iLastToken]
            VarCode->IsPtrFlag = TALLY(Stk$[*iLastToken], "*")
            Stk$[(*iLastToken)--] = ""
            Stk$[(*iLastToken)--] = ""
        ELSE
            ' Check if Constructor/Destructor
            IF Ctor_Dtor_Detected(1) THEN
                CurrentFuncType = vt_CONSTRDESTR
            ELSE
                CurrentFuncType = DataType(Stk$[iFirstToken+1])
            END IF
            VarCode->Token$ = Stk$[iFirstToken+1]
            VarCode->IsPtrFlag = TALLY(Stk$[iFirstToken+1], "*")
            VarCode->AsToken$ = ""
        END IF
    END IF
    VarCode->Proto$    = " ("
    VarCode->Header$   = " ("
    VarCode->Functype$ = ""
    VarCode->Methd%    = methd
    VarCode->VarNo%    = CurrentFuncType
    CALL GetVarCode(VarCode, "FuncSubDecs2")
END SUB ' FuncSubDecs2



SUB FuncSubDecs3(varcode AS UDT_VARCODE_ATTRIBUTES PTR, iLast AS INT, iExtended AS INT)
    '*****************************************************************************
    ' This function processes and formats the header and prototype strings for
    ' functions and subs in a specific programming context. It adjusts the header
    ' based on various conditions such as the presence of a period, whether C++ is
    ' used, and if the function accepts variant args. It also handles special cases
    ' for method prototypes, inline functions, and exported functions, ensuring
    ' that the correct syntax is applied for each scenario.
    '*****************************************************************************

    IF *Stk$[iLast-1] = ASC(".") THEN      ' Allow Functions | Subs with one or
        Stk$[iLast-1] = "..."              ' more "." TO produce the "..." needed
    END IF

    varcode->Header$ = RTRIM$(varcode->Header$)
    varcode->Header$ += ")"

    IF UseCpp = FALSE THEN
        REPLACE "()" WITH "(void)" IN varcode->Header$
    END IF

    IF iExtended THEN
        varcode->Header$ = varcode->Functype$ + "(*" + varcode->Token$ + ")" + varcode->Header$
    ELSE
        varcode->Header$ = varcode->Functype$ + varcode->Token$ + varcode->Header$
    END IF

    IF varcode->Methd% = 2 THEN
        varcode->Proto$ = RTRIM$(varcode->Proto$)
        IF m_iMatchRgt(varcode->Proto$, ",")  THEN
            MID$(varcode->Proto$, LEN(varcode->Proto$)) = ")"
        ELSE
            varcode->Proto$ += ")"
        END IF

        REPLACE "()" WITH "(void)" IN varcode->Proto$
        IF iExtended THEN
            varcode->Proto$ = varcode->Functype$ + "(*)" + varcode->Proto$
        ELSE
            varcode->Proto$ = varcode->Functype$ + varcode->Token$ + varcode->Proto$ + ";"
        END IF
    END IF

    IF varcode->UseInLine THEN
        varcode->Header$ = "inline " + varcode->Header$
        varcode->Proto$  = "inline " + varcode->Proto$
    END IF
    UseInLine = FALSE

    IF varcode->IsExported THEN
        UseImportExport = TRUE
        varcode->Proto$  = "C_EXPORT " + varcode->Proto$
        varcode->Header$ = "C_EXPORT " + varcode->Header$
    END IF

    REPLACE " . " WITH "." IN varcode->Proto$    ' 811 MrBcx  - Fix bug with opt arg with decimal values
    REPLACE " . " WITH "." IN varcode->Header$   '                          Ditto
END SUB ' FuncSubDecs3



SUB AddTypeDefs(sTypeDefName$, TDef)
    '*************************************************************
    ' This SUB adds a new type definition to the TypeDefs array.
    '*************************************************************
    INCR TypeDefsCnt
    IF TypeDefsCnt = c_MaxTypes THEN
        CALL Abort("Exceeded TYPE Limits.")
    END IF
    TypeDefs[TypeDefsCnt].VarName$ = sTypeDefName$
    TypeDefs[TypeDefsCnt].TypeofDef = TDef
    TypeDefs[TypeDefsCnt].EleCnt = 0
END SUB ' AddTypeDefs



FUNCTION CheckTypeDefs(ParmStr AS STRING)
    '****************************************************************************
    ' This function searches for a given parameter name (ParmStr) in a list
    ' of type definitions.  If (ParmStr) is found, it returns the index
    ' of the matching type definition; otherwise, it returns 0.
    '****************************************************************************
    IF TypeDefsCnt > 0 THEN
        FOR i AS INT = 1 TO TypeDefsCnt
            IF ParmStr$ = TypeDefs[i].VarName$ THEN
                FUNCTION = i
            END IF
        NEXT
    END IF
    FUNCTION = 0
END FUNCTION ' CheckTypeDefs



SUB GetTypeInfo (    _
    szArg$,          _
    BYREF IsPointer, _
    BYREF UdtIdx,    _
    BYREF vtCode)
    '**********************************************************************
    ' This SUB extracts information about a given type specified by szArg$.
    ' It determines whether the type is a pointer, searches for user-defined
    ' types (UDTs), and identifies the type code.
    ' Parameters:
    '   - szArg$: The string representing the type.
    '   - IsPointer: A variable to store whether the type is a pointer.
    '   - UdtIdx: A variable to store the index of the UDT, if applicable.
    '   - vtCode: A variable to store the type code.
    '**********************************************************************
    DIM RAW Var1$

    IsPointer = TALLY(szArg$, "*")
    Var1$     = TRIM$(REMOVE$(szArg$, "*"))

    IF RIGHTSTR (Var1$, "_CLASS") THEN Var1$ = LEFT$(Var1$, LEN(Var1$)-6)
    vtCode = CheckType(Var1$)

    IF vtCode = vt_UNKNOWN THEN
        CALL AddTypeDefs(Var1$, vt_UDT)    ' Assume its a WinApi type
        vtCode = vt_UDT
    END IF

    UdtIdx = 0
    IF vtCode = vt_STRUCT OR vtCode = vt_UNION OR vtCode = vt_UDT THEN
        UdtIdx = CheckTypeDefs(Var1$)
    END IF
END SUB ' GetTypeInfo



SUB AddTypedefElement ( _
    WorkingTypeDefsCnt, _
    ElType            , _
    EName$            , _
    EType$            , _
    EPtr = 0)

    '****************************************************************************
    ' This SUB adds an element to a UDT.
    ' Parameters:
    '   - WorkingTypeDefsCnt: The index of the UDT in the TypeDefs array.
    '   - ElType: The type of the element to be added.
    '   - EName$: The name of the element.
    '   - EType$: The type of the element (if ElType is a UDT).
    '   - EPtr: Indicates whether the element is a pointer (default is 0).
    '****************************************************************************
    DIM RAW TD AS UDT_USER_TYPES_STORAGE PTR
    TD = ADDRESSOF((TypeDefs[WorkingTypeDefsCnt]))

    IF TD->EleCnt = c_MaxElements THEN
        CALL Abort("Exceeded TYPE Element Limits.")
    END IF

    TD->Elements[TD->EleCnt].ElementType    = ElType
    TD->Elements[TD->EleCnt].ElementDynaPtr = EPtr

    IF ElType = vt_STRUCT OR ElType = vt_UNION OR ElType = vt_UDT THEN
        TD->Elements[TD->EleCnt].ElementID = CheckTypeDefs(EType$)
    ELSE
        TD->Elements[TD->EleCnt].ElementID = 0
    END IF

    TD->Elements[TD->EleCnt].ElementName$ = EName$
    TD->EleCnt = 1 + TD->EleCnt
END SUB ' AddTypedefElement



FUNCTION GetElement$(_
    StartStk        , _
    BYREF vt        , _
    BYREF dimensions, _
    id)

    '*********************************************************************
    ' This function extracts and returns the name of an element
    ' starting from StartStk, identifying its type and dimensions.
    ' It handles nested structures and unions, modifying vt, dimensions, and
    ' id as it processes array brackets and struct/union access operators.
    '*********************************************************************
    DIM RAW BC = 0, i, LZZ$

    FOR i = StartStk+1 TO Ndx
        IF *Stk$[i] = ASC("[") THEN
            INCR BC
        ELSEIF *Stk$[i] = ASC("]") THEN
            DECR BC
        ELSE
            IF BC = 0 THEN
                IF m_iMatchLft(Stk$[i], "->") OR *Stk$[i] = ASC(".") THEN
                    LZZ$ = Stk$[i]
                    RemoveAll(LZZ$, "%$#!@`.->( *)", 1)
                    vt = GetElementInfo(ADDRESSOF(id), ADDRESSOF(dimensions), LZZ$)
                    IF vt <> vt_STRUCT AND vt <> vt_UNION THEN EXIT FOR
                END IF
            END IF
        END IF
    NEXT

    IF vt = vt_UDT OR vt = vt_UNION OR vt = vt_STRUCT THEN
        LZZ$ = TypeDefs[id].VarName$
    ELSE
        LZZ$ = GetVarTypeName$(vt)
    END IF
    FUNCTION = LZZ$
END FUNCTION ' GetElement$



FUNCTION GetElementInfo(BYREF DefID, BYREF EPtr, Elename$)
    '***************************************************************
    ' This function retrieves and returns the type of an element
    ' identified by Elename$ within a user-defined type. It updates
    ' DefID and EPtr with the element's ID and dynamic pointer,
    ' respectively, or returns 0 if the element is not found.
    '***************************************************************
    DIM RAW id = DefID
    FOR i AS INT = 0 TO TypeDefs[id].EleCnt - 1
        IF Elename$ = TypeDefs[id].Elements[i].ElementName$ THEN
            DefID = TypeDefs[id].Elements[i].ElementID
            EPtr  = TypeDefs[id].Elements[i].ElementDynaPtr
            FUNCTION = TypeDefs[id].Elements[i].ElementType
        END IF
    NEXT
    FUNCTION = 0
END FUNCTION ' GetElementInfo



SUB Process_Option_Base
    FOR i AS INT = 1 TO Ndx
        '*********************************************************************
        ' Tolerate nonsense like >> DIM A% as DOUBLE << by removing the sigil
        IF m_iMatchWrd(Stk$[i], "as") THEN Stk$[i-1] = No_Sigil$(Stk$[i-1])
        '*********************************************************************
        ' Added code to prevent OPTION BASE errors                  MrBcx 818
        ' I observed, when using OPTION BASE 1, statements like this:
        '      DIM AS DOUBLE dx = BulletX [ BulletIndex ] - AsteroidX [ i ]
        ' would be erroneously translated to:
        '     double dx = BulletX [ 1 + BulletIndex] - AsteroidX [ 1 + i];
        ' which is a complete disaster waiting to happen.
        '*********************************************************************
        IF Stk$[i] = "=" THEN EXIT SUB     ' Such an easy fix!      MrBcx 818
        '*********************************************************************
        '        This was the easiest way I could see to implement this.
        '                        Improved by MrBcx
        '*********************************************************************
        IF OptionBase THEN
            '*****************************************************************
            ' Guard against statements like DIM RAW A[] = { ..      821 MrBcx
            '*****************************************************************
            IF *Stk$[i] = ASC("[") AND *Stk$[i+1] = ASC("]") THEN ITERATE
            '*****************************************************************

            IF *Stk$[i] = ASC("[") AND *Stk$[i+1] <> ASC("]")THEN
                IF DataType(Stk$[i+1]) = vt_NUMBER THEN
                    Stk$[i+1] = STR$(OptionBase + VAL(Stk$[i+1]), 1)
                ELSE
                    Stk$[i+1] = STR$(OptionBase, TRUE) + "+" + Stk$[i+1]
                END IF
            END IF
        END IF
    NEXT
END SUB ' Process_Option_Base




FUNCTION IsValidName(szArg AS STRING) AS LONG
    '*******************************************************************************************
    ' This function checks if a given string is a valid identifier name according to BCX rules.
    ' Improved to inspect the ENTIRE string, ensuring both ASCII and multi-byte Unicode
    ' characters are safely validated.
    '*******************************************************************************************
    DIM Valid AS LONG
    DIM Length AS LONG
    DIM FirstChar AS UCHAR
    DIM CurrentChar AS UCHAR
    DIM p AS PUCHAR

    Valid = TRUE
    Length = LEN(szArg)

    IF Length = 0 THEN
        Valid = FALSE
    ELSE
        ' Allow standalone pointer macro prefix or specific byref formats upfront
        IF szArg <> "&" AND NOT m_iMatchLft(szArg, "(*") THEN

            p = (PUCHAR)szArg
            FirstChar = p[0]

            ' 1. Validate the First Character
            ' Must be a letter, an underscore (_), or a Unicode lead byte (> 192)
            IF NOT isalpha(FirstChar) AND FirstChar <> 95 AND FirstChar <= 192 THEN
                Valid = FALSE
            ELSE
                ' 2. Validate all subsequent characters
                FOR i AS LONG = 1 TO Length - 1
                    CurrentChar = p[i]
                    ' Subsequent characters can be alphanumeric, underscores,
                    ' or part of a Unicode multi-byte sequence (> 127)
                    IF NOT isalnum(CurrentChar) AND CurrentChar <> 95 AND CurrentChar <= 127 THEN
                        Valid = FALSE
                    END IF
                NEXT
            END IF
        END IF
    END IF

    FUNCTION = Valid
END FUNCTION ' IsValidName




SUB ValidateVarName(v$)
    '************************************************************************
    ' This subroutine checks the validity of a variable name, ensuring
    ' it conforms to BCX naming rules and is not a restricted word.
    ' Modified by Robert Wishlaw to support UNICODE identifiers in BCX 799
    '************************************************************************
    DIM RAW LZZ$

    IF LEFTSTR(v$, " #define  3.14159") THEN Abort ("PI is predefined in BCX.  You cannot DIM PI ...")

    IF NOT isalpha(*v$) AND *v$ <> ASC("_") AND NOT ((unsigned CHAR)*v$ > 192) THEN
        IF NOT m_iMatchLft(v$, "(*") AND v$ <> "&" THEN  ' Allow byref format (*A).xxx
            Abort("Invalid String Variable Name")
        END IF
    END IF

    IF RestrictedWords(v$) AND TestState THEN
        LZZ$ = "Variable " + v$ + " on line"
        LZZ$ += STR$(LineNum[FileNdx]) + " in Module: " + TRIM$(FileNames$[FileNdx]) + " is a Restricted Word"
        CALL Warning(LZZ$)
    END IF
END SUB ' ValidateVarName




SUB PointerFix
    '*******************************************************
    ' This subroutine concatenates consecutive stack tokens
    ' containing only asterisks (*) into a single token,
    ' effectively merging pointer declarations.
    '*******************************************************
    Stk$[Ndx-1] += Stk$[Ndx]
    Stk$[Ndx] = ""
    DECR Ndx
    DO WHILE TALLY(Stk$[Ndx], "*") = LEN(Stk$[Ndx])
        Stk$[Ndx-1] += Stk$[Ndx]
        Stk$[Ndx] = ""
        DECR Ndx
    LOOP
END SUB ' PointerFix



SUB DimDynaString(SVar$, DG, s)
    DIM RAW DS$

    DS$ = "if (" + SVar$ + ") {free(" + SVar$ + ");}"       ' 838 MrBcx removed Var = NULL, as those are unnecessary
    IF InFunction AND (IsLocal OR IsDim OR IsRaw OR IsAuto OR IsRegister) AND DG = 0 THEN

        IF c_MaxDynaStr = ++LocalDynaCnt THEN
            CALL Abort("Maximum number of local dynamic allocations exceeded.")
        END IF

        DynaStr$[LocalDynaCnt] = DS$
        FPRINT FP_WRITE, Scoot$, "char *", SVar$, ";"
        CALL AddLocal(SVar$, vt_CHAR, 0, "", 1)

    ELSE

        IF Use_GenFree THEN
            CALL AddDynamicGlobal(DS$)
        END IF
        IF DG = 2 THEN
            CALL AddGlobal(SVar$, vt_CHAR, 0, "", 1, 0, 1)
        ELSE
            IF s THEN
                CALL AddGlobal(SVar$, vt_CHAR, 0, "", 1, 0, 2)
            ELSE
                CALL AddGlobal(SVar$, vt_CHAR, 0, "", 1)
            END IF
        END IF
    END IF

    IF DG <> 2 THEN
        FPRINT FP_WRITE, Scoot$, SVar$ , "=(char*)calloc(";
        INCR Ndx
        Stk$[Ndx] = ", 1);"
        CALL WriteCleanTokens(4, Ndx)
    END IF

END SUB ' DimDynaString



SUB AddDynamicGlobal(szGlobalStr AS PCHAR)
    INCR GlobalDynaCnt
    IF c_MaxGlobalDyna = GlobalDynaCnt THEN
        CALL Abort("Maximum number of global dynamic arrays exceeded.")
    END IF
    GlobalDynaStr$[GlobalDynaCnt] = szGlobalStr$
END SUB ' AddDynamicGlobal



FUNCTION SubFuncTest
    IF m_iMatchWrd(Stk$[2], "function") OR m_iMatchWrd(Stk$[2], "sub") THEN
        FUNCTION = 1
    END IF
    FUNCTION = 0
END FUNCTION ' SubFuncTest



FUNCTION Ctor_Dtor_Detected(iTokenLoc AS INT)
    IF m_iMatchWrd(Stk$[iTokenLoc], "constructor") OR m_iMatchWrd(Stk$[iTokenLoc], "destructor") THEN
        FUNCTION = 1
    END IF
    FUNCTION = 0
END FUNCTION ' Ctor_Dtor_Detected



FUNCTION DimSubFunc(iMethod)
    '********************************************************************************
    ' This function processes function declarations and initializes data if present.
    ' iMethod specifies whether the function is a method (1 for method, 0 otherwise).
    '********************************************************************************
    DIM RAW bOppFound AS BOOL
    DIM RAW Funptr = 0
    DIM RAW i
    DIM RAW id
    DIM RAW iEqualLoc
    DIM RAW LTmp$ = ""
    DIM RAW StartPoint = 3
    DIM RAW szInit$
    DIM RAW szIsConst$
    DIM RAW szStatic$
    DIM RAW szV$
    DIM RAW szWrk$
    DIM RAW vt
    DIM RAW w
    DIM RAW ACS AS UDT_ARG_COMMAS_STORAGE
    CLEAR(ACS)

    IF m_iMatchWrd(Stk$[Ndx], "stdcall") THEN
        CallType$ = "__stdcall "
        Stk$[Ndx--] = ""
        IsStdFunc = TRUE
    ELSE
        IF InClass OR InCppTypeDef THEN
            CallType$ = ""
        ELSE
            CallType$ = "__cdecl "    ' Default calling convention
        END IF
        IsStdFunc = FALSE
    END IF

    IF m_iMatchWrd(Stk$[3], "operator") THEN
        XFOR i = 4, bOppFound = FALSE WHILE NOT bOppFound BY i++
            IF Stk$[i] = "(" THEN
                IF Stk$[i+1] <> ")" AND Stk$[i+2] <> "(" THEN bOppFound = TRUE
                IF Stk$[i+1] = ")" AND i > 4 THEN bOppFound = TRUE
            END IF
            IF NOT bOppFound THEN
                Stk$[3] += Stk$[i]
                Stk$[i] = ""
            END IF
        XNEXT
    END IF

    szWrk$ = No_Sigil$(Stk$[Ndx])

    IF *szWrk$ THEN
        GetTypeInfo(szWrk$, ADDRESSOF(w), ADDRESSOF(id), ADDRESSOF(vt))
        IF vt = vt_WINBOOL THEN
            IREPLACE "WINBOOL" WITH "BOOL" IN Stk$[Ndx]
        END IF
    END IF

    ' ------------------------------------------------------
    '  Find start of function body (...)
    ' ------------------------------------------------------

    CALL SepFuncArgs(3, ADDRESSOF(ACS), TRUE)

    StartPoint = IMAX(ACS.CommaPos[0], 3)

    IF NOT InTypeDef AND NOT InCppTypeDef AND NOT InClass THEN
        g_SubFuncPtr = TRUE
        ' ------------------------------------------------------
        '  Get intialized data  " = xxx" or "= {xxx,xxx}"
        ' ------------------------------------------------------
        IF ACS.NumArgs = 0 THEN
            i = IMIN(ACS.CommaPos[1]+1, Ndx)
        ELSE
            i = IMIN(ACS.CommaPos[ACS.NumArgs]+1, Ndx)
        END IF

        IF Stk$[i] = "=" THEN
            Stk$[i++] = ""
            DO WHILE NOT m_iMatchWrd(Stk$[i], "as") AND i <= Ndx
                LTmp$ += Stk$[i]
                Stk$[i++] = ""
            LOOP
            RemoveAll(LTmp$, "{}", 1)
            IF LTmp$ <> "" THEN CALL RemEmptyTokens
        END IF
        ' ------------------------------------------------------

        FPRINT FP_UDT, Scoot$, MakeDecProto$(ADDRESSOF(ACS)), ";"

        g_SubFuncPtr = FALSE

        Ndx = StartPoint
        Stk$[2] = ""

        IF LTmp$ <> "" THEN
            Stk$[Ndx++] = "="
            Stk$[Ndx++] = "{"
            Stk$[Ndx++] = No_Sigil$(LTmp$)
            Stk$[Ndx++] = "}"
        END IF

        Stk$[Ndx++] = "as"
        Stk$[Ndx] = No_Sigil$(Stk$[3]) + "_TYPE" + STRING$(Funptr, ASC("*"))

        CALL RemEmptyTokens
        FUNCTION = FALSE

    ELSE    ' C++
        szV$       = ""
        szWrk$     = ""
        szStatic$  = ""
        szIsConst$ = ""
        szInit$    = ""
        iEqualLoc  = Ndx

        IF IsVirtual THEN
            szV$ = "virtual "
            IsVirtual = FALSE
        ELSE
            szV$ = ""
        END IF

        DO WHILE Stk$[iEqualLoc] <> "=" AND iEqualLoc
            IF Stk$[iEqualLoc] = ")" THEN EXIT DO
            DECR iEqualLoc
        LOOP

        IF Stk$[iEqualLoc] = "=" THEN
            szInit$ = Stk$[iEqualLoc++]
            szInit$ += Stk$[iEqualLoc++]
        END IF

        IF m_iMatchWrd(Stk$[Ndx], "const") THEN
            szIsConst$ = "const"
        ELSE
            szIsConst$ = ""
        END IF

        IF m_iMatchWrd(Stk$[1], "static") THEN
            szStatic$ = "static "
        ELSE
            szStatic$ = ""
        END IF

        szWrk$ = MakeDecProto$(ADDRESSOF(ACS))

        IF iMethod THEN
            szWrk$ = TRIM$(MID$(szWrk$, INCHR(szWrk$, SPC$)))
        END IF

        IF szVirtual$ = szInit$ THEN
            szInit$ = ""
        END IF

        FPRINT FP_UDT, Scoot$, szV$, szStatic$, szWrk$, szVirtual$, szInit$, szIsConst$, ";"
        szVirtual$ = ""
    END IF

    FUNCTION = TRUE
END FUNCTION ' DimSubFunc



SUB InBlockReSet
    LocalVarCnt = LocalInBlock[InBlock]
    DECR InBlock
    IF InBlock < 0 THEN
        Abort("Too many END BLOCKS")
    END IF
END SUB ' InBlockReSet




SUB InBlockSet
    '******************************************************************
    ' Manage the nesting levels of BLOCKS by keeping track of how many
    ' BLOCKS are currently active. It ensures that the number of nested
    ' BLOCKS does not exceed c_MaxLocalInBlocks and it stores relevant
    ' information about local variable scopes.
    '******************************************************************
    INCR InBlock

    IF InBlock = c_MaxLocalInBlocks THEN
        CALL Abort("Too many nested BEGINBLOCK/ENDBLOCKs")
    END IF

    LocalInBlock[InBlock] = LocalVarCnt
END SUB ' InBlockSet




SUB AddSpace(i AS INT)
    '******************************************************************
    ' Ensures proper spacing between valid names in Stk$[]
    '******************************************************************
    IF IsValidName(Stk$[i]) AND IsValidName(Stk$[i+1]) THEN
        Stk$[i] += SPC$
    END IF
END SUB ' AddSpace



SUB Display_Version_and_Compiler
    IF c_BCX_COLORS THEN COLOR 10, 0
    PRINT "Version ", c_VERSION$, Compiler_Used$()
    POPCOLORS
END SUB ' Display_Version_and_Compiler



FUNCTION Compiler_Used$
    DIM Buff$ =  " Compiled using "
    $IFDEF __BCPLUSPLUS__
        Buff$ += "Embarcadero C++"
    $ELSEIF __INTEL_LLVM_COMPILER               ' MrBcx 826  Intel OneAPI 64-bit c++ compiler
        Buff$ += "Intel C++ Compiler"
    $ELSEIF __BORLANDC__
        Buff$ += "Embarcadero C++"
    $ELSEIF __DMC__
        Buff$ += "Digital Mars C/C++"
    $ELSEIF __POCC__
        Buff$ += "Pelles C"
    $ELSEIF __LCC__
        Buff$ += "Lcc-Win32"
    $ELSEIF __clang__ AND __MINGW64__
        Buff$ += "LLVM-MinGW64 ("
        Buff$ += __VERSION__$
        Buff$ += ")"
    $ELSEIF __MINGW64__
        Buff$ += "MinGW64 C++ ("
        Buff$ += __VERSION__$
        Buff$ += ")"
    $ELSEIF __MINGW32__
        Buff$ += "MinGW32 C++ ("
        Buff$ += __VERSION__$
        Buff$ += ")"
    $ELSEIF __clang__
        Buff$ += "LLVM-Clang ("
        Buff$ += STR$(__clang_major__, 1)
        Buff$ += "."
        Buff$ += STR$(__clang_minor__, 1)
        Buff$ += "."
        Buff$ += STR$(__clang_patchlevel__, 1)
        Buff$ += ")"
    $ELSEIF _MSC_VER
        Buff$ += "MS Visual C++ ("
        Buff$ += STR$(_MSC_FULL_VER, 1)
        Buff$ += ")"
    $ELSE
        Buff$ += "Unknown Compiler"
    $ENDIF
    $IFDEF _WIN64
        Buff$ += " for 64-bit Windows"
    $ELSE
        Buff$ += " for 32-bit Windows"
    $ENDIF
    FUNCTION = Buff$
END SUB ' Compiler_Used$




SUB KillFiles
    IF DebugModeOff THEN
        KILL hdrFile$
        KILL enuFile$
        KILL SysFile$
        KILL UsrFile$
        KILL udtFile$
        KILL setFile$
        KILL cppFile$
        KILL prcFile$
        KILL ovrFile$
        KILL datFile$
        KILL resFile$
    END IF
END SUB ' KillFiles



SUB Abort(AbortStr$)
    LOCAL i AS INT
    LOCAL j AS INT
    LOCAL k AS INT
    LOCAL t$
    LOCAL varnum
    LOCAL frmt$

    WarnMsg$ = ""

    IF LEFTSTR(AbortSrc$, "$BCXVERSION") THEN
        WarnMsg$ += AbortStr$
    ELSE
        WarnMsg$ += AbortStr$ + " at line" + STR$(LineNum[FileNdx])
        WarnMsg$ += " in Module: " + TRIM$(FileNames$[FileNdx]) + CRLF$
        WarnMsg$ += "Original line" + CRLF$
        WarnMsg$ +=  AbortSrc$ + CRLF$
        WarnMsg$ += "==============" + CRLF$
        WarnMsg$ += "Current Tokens" + CRLF$
        WarnMsg$ += "==============" + CRLF$

        FOR k = 1 TO Ndx
            j = LEN(Stk$[k])

            IF j < 40 THEN
                j = 40 - j
            ELSE
                j = 8 - IMOD(j, 8)
            END IF

            frmt$ = LPAD$(STR$(k), 3)

            WarnMsg$ += frmt$ + SPC$ + Stk$[k] + STRING$(j, 32) + CRLF$

            t$ = No_Sigil$(Stk$[k])
            i = CheckLocal(t$, ADDRESSOF(varnum))

            IF i <> vt_UNKNOWN THEN
                WarnMsg$ = TRIM$(WarnMsg$)
                WarnMsg$ += " is a LOCAL defined at line" + STR$(LocalVars[varnum].VarLine)
                WarnMsg$ += " in Module: " + LocalVars[varnum].VarModule$ + CRLF$
            ELSE
                i = CheckGlobal(t$, ADDRESSOF(varnum))
                IF i <> vt_UNKNOWN THEN
                    WarnMsg$ = TRIM$(WarnMsg$)
                    WarnMsg$ += " is a GLOBAL defined at line" + STR$(GlobalVars[varnum].VarLine)
                    WarnMsg$ += " in Module: " + GlobalVars[varnum].VarModule$
                    WarnMsg$ += SPC$ + Stk$[k] + GlobalVars[varnum].VarDim$ + " as "
                    IF GlobalVars[varnum].VarDef THEN
                        WarnMsg$ += TRIM$(TypeDefs[GlobalVars[varnum].VarDef].VarName$) + CRLF$
                    ELSE
                        WarnMsg$ += TRIM$(GetVarTypeName$(GlobalVars[varnum].VarType)) + CRLF$
                    END IF
                ELSE
                    IF *Stk$[k] = c_DblQt THEN
                        WarnMsg$ = TRIM$(WarnMsg$)
                        WarnMsg$ += " is a string literal" + CRLF$
                    END IF
                END IF
            END IF
        NEXT

        WarnMsg$ += "===============" + CRLF$
        WarnMsg$ += "Original Tokens" + CRLF$
        WarnMsg$ += "===============" + CRLF$

        CALL PreParse(AbortSrc$)

        FOR k = 1 TO Ndx
            j = LEN(Stk$[k])
            IF j < 40 THEN
                j = 40 - j
            ELSE
                j = 8 - IMOD(j, 8)
            END IF

            frmt$ = LPAD$(STR$(k), 3)

            WarnMsg$ += frmt$ + SPC$ + Stk$[k] + STRING$(j, 32) + CRLF$

            t$ = No_Sigil$(Stk$[k])
            i = CheckLocal(t$, ADDRESSOF(varnum))

            IF i <> vt_UNKNOWN THEN
                WarnMsg$ = TRIM$(WarnMsg$)
                WarnMsg$ += " is a LOCAL defined at line" + STR$(LocalVars[varnum].VarLine)
                WarnMsg$ += " in Module: " + LocalVars[varnum].VarModule$ + CRLF$
            ELSE
                i = CheckGlobal(t$, ADDRESSOF(varnum))
                IF i <> vt_UNKNOWN THEN
                    WarnMsg$ = TRIM$(WarnMsg$)
                    WarnMsg$ += " is a GLOBAL defined at line" + STR$(GlobalVars[varnum].VarLine)
                    WarnMsg$ += " in Module: " + GlobalVars[varnum].VarModule$
                    WarnMsg$ += SPC$ + Stk$[k] + GlobalVars[varnum].VarDim$ + " as "
                    IF GlobalVars[varnum].VarDef THEN
                        WarnMsg$ += TypeDefs[GlobalVars[varnum].VarDef].VarName$ + CRLF$
                    ELSE
                        WarnMsg$ += GetVarTypeName$(GlobalVars[varnum].VarType) + CRLF$
                    END IF
                ELSE
                    IF *Stk$[k] = c_DblQt THEN
                        WarnMsg$ = TRIM$(WarnMsg$)
                        WarnMsg$ += " is a string literal" + CRLF$
                    END IF
                END IF
            END IF
        NEXT
    END IF

    WarnMsg$ += CRLF$

    CALL CloseAll
    CALL KillFiles
    KILL "$WRK$.TXT"
    KILL FileOut$
    KILL "$t$e$m$p"

    IF ErrFile THEN
        OPEN FileErr$ FOR APPEND AS fpErr
        FPRINT fpErr, AbortStr$ , " at line" , LineNum[FileNdx] , " in Module: ", TRIM$(FileNames$[FileNdx]) ' LinesRead
        CLOSE fpErr
    END IF

    IF InfoBoxWarn THEN
        INFOBOX("Warnings! :" , WarnMsg$, GetSystemMetrics(SM_CXSCREEN)/4, GetSystemMetrics(SM_CYSCREEN)/4)
    ELSE
        PRINT "Error!", CRLF$, FileIn$, CRLF$, WarnMsg$
    END IF
    END = 1
END SUB ' Abort



SUB BumpDown(szErr$)
    '********************************************************
    ' Decreases the indentation level by 2 spaces and aborts
    ' with an error message if indentation goes below 0
    '********************************************************
    DECR Indent, 2
    IF Indent < 0 THEN
        IF ISNULL(szErr$) THEN
            CALL Abort("Unknown Error")
        ELSE
            CALL Abort(szErr$)
        END IF
    END IF
    Scoot$ = SPACE$(Indent)
END SUB ' BumpDown


SUB BumpUp
    '********************************************************
    ' Increases the indentation level by 2 spaces,
    ' resetting it to 0 if it was negative
    '********************************************************
    IF Indent < 0 THEN Indent = 0
    INCR Indent, 2
    Scoot$ = SPACE$(Indent)
END SUB ' BumpUp



FUNCTION FixBrackets  (SrcCode$, l) AS PCHAR  ' Warning!  This is a recursive function
    '**************************************************************************************
    ' This function recursively processes SrcCode$ (a string argument) to handle nested
    ' brackets and parentheses. It differentiates between double quotes, angle brackets
    ' <> and parentheses (). The function replaces commas within angle brackets
    ' with a placeholder and ultimately replaces the placeholder with "][".
    '**************************************************************************************
    DIM RAW s AS PCHAR = SrcCode$

    SELECT CASE l
        CASE 0
            DO
                IF *s = 0 THEN EXIT DO
                IF *s = c_DblQt THEN
                    INCR s
                    DO WHILE *s <> c_DblQt
                        IF *s = 0 THEN EXIT DO
                        INCR s
                    LOOP
                END IF

                IF *s = c_LtBkt THEN
                    INCR s
                    s = FixBrackets(s, 1)
                END IF
                IF *s = c_LPar THEN
                    INCR s
                    s = FixBrackets(s, 2)
                END IF
                INCR s
            LOOP

        CASE 1
            DO WHILE *s <> c_RtBkt
                IF *s = c_DblQt THEN
                    INCR s
                    DO WHILE *s <> c_DblQt
                        IF *s = 0 THEN EXIT DO
                        INCR s
                    LOOP
                END IF

                IF *s = c_LtBkt THEN
                    INCR s
                    s = FixBrackets(s, 1)
                END IF

                IF *s = c_LPar THEN
                    INCR s
                    s = FixBrackets(s, 2)
                END IF
                IF *s = 0 THEN EXIT DO
                IF *s = c_Comma THEN *s = 1
                INCR s
            LOOP

        CASE 2
            DO WHILE *s <> c_RPar
                IF *s = c_DblQt THEN
                    INCR s
                    DO WHILE *s <> c_DblQt
                        IF *s = 0 THEN EXIT DO
                        INCR s
                    LOOP
                END IF

                IF *s = c_LtBkt THEN
                    INCR s
                    s = FixBrackets(s, 1)
                END IF

                IF *s = c_LPar THEN
                    INCR s
                    s = FixBrackets(s, 2)
                END IF
                IF *s = 0 THEN EXIT DO
                INCR s
            LOOP
    END SELECT

    IF l = 0 THEN
        REPLACE CHR$(1) WITH "][" IN SrcCode$
        FUNCTION = SrcCode$
    END IF

    FUNCTION = s
END FUNCTION ' FixBrackets



SUB PushSelectState(SelState$)
    '**************************************************************************************
    ' This SUB increments the state index and saves the current SELECT state (SelState$)
    ' onto a stack (SelectState). If the maximum number of nested SELECT/END SELECT blocks
    ' is reached, it aborts the process with an error message.
    '**************************************************************************************
    INCR StateIdx
    IF c_MaxNestedSelects = StateIdx THEN
        CALL Abort("Maximum nested SELECT/END SELECT reached.")
    END IF
    SelectState[StateIdx].CaseStk$= SelState$
END SUB ' PushSelectState




SUB PopSelectState(SelState$)
    '***************************************************************************
    ' This SUB decrements the state index and retrieves the most recently
    ' saved SELECT state from the stack (SelectState), storing it in SelState$.
    '***************************************************************************
    SelState$ = SelectState[--StateIdx].CaseStk$
END SUB ' PopSelectState



SUB Commandline_Defines(FP_OUTPUT AS FILE)
    '****************************************************************************************
    ' This SUB outputs commandline #defines to a given file (FP_OUTPUT).  If CmdLineConst$
    ' is not empty, it writes header and footer comments to the file, then processes each
    ' command line constant, converting them into MACRO definitions and directing the
    ' output to the specified file. It temporarily changes the file pointer for this output.
    '****************************************************************************************
    IF CmdLineConst$ <> "" THEN
        DIM RAW Ftmp AS FILE
        DIM RAW LTmp1$

        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// ***************************************************"
        FPRINT FP_OUTPUT, "//                 Command line Defines"
        FPRINT FP_OUTPUT, "// ***************************************************"
        FPRINT FP_OUTPUT, SPC$

        Ftmp   = FP_CST     ' Save FILE Ptr to SourceFile
        FP_CST = FP_OUTPUT   ' Direct output to HeaderFile

        FOR i AS INT = 1 TO TALLY(CmdLineConst$, CHR$(1))
            LTmp1$ = STRTOKEN$(CmdLineConst$, CHR$(1), i)
            IF ISNULL(LTmp1$) THEN EXIT FOR
            LTmp1$ = "MACRO " + LTmp1$ ' CmdLineConst$
            Inject(LTmp1$)
        NEXT

        FP_CST = Ftmp    ' Restore Ptr to SourceFile

        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// ***************************************************"
        FPRINT FP_OUTPUT, "//              End of Command Line Defines"
        FPRINT FP_OUTPUT, "// ***************************************************"
        FPRINT FP_OUTPUT, SPC$
    END IF
END SUB ' Commandline_Defines



SUB Emit_UserDirectives(FP_OUTPUT AS FILE)
    '*********************************************************************************
    ' This SUB outputs user-specified directives from a file (hdrFile$) to a
    ' given file stream (FP_OUTPUT). If the header file exists, it opens it for
    ' input, reads each line, writes it to the output file, then closes the file.
    '*********************************************************************************
    IF EXIST(hdrFile$) THEN
        DIM RAW LTmp1$
        DIM RAW LFP1 AS FILE
        OPEN hdrFile$ FOR INPUT AS LFP1     ' user specified .h directives
        DO WHILE NOT EOF(LFP1)
            LINE INPUT LFP1, LTmp1$
            FPRINT FP_OUTPUT, LTmp1$
        LOOP
        CLOSE LFP1
    END IF
END SUB ' Emit_UserDirectives



SUB User_Global_Enum_Blocks(FP_OUTPUT AS FILE)
    '*****************************************************************************************
    ' This SUB processes user-defined global enumerations stored inside (enuFile$) and writes
    ' them to a given file stream (FP_OUTPUT). If the enumeration file exists and has a size
    ' greater than 2 bytes, it opens the file, reads each line, and writes it to the output
    ' file. It then closes the enumeration file.
    '*****************************************************************************************
    DIM RAW LTmp1$
    DIM RAW LFP1 AS FILE

    IF EXIST(enuFile$) AND LOF(enuFile$) > 2 THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, "//          Application GLOBAL Enumerations"
        FPRINT FP_OUTPUT, "// *************************************************"
        OPEN enuFile$ FOR INPUT AS LFP1      ' user's GLOBAL enum blocks
        DO WHILE NOT EOF(LFP1)
            LINE INPUT LFP1, LTmp1$
            FPRINT FP_OUTPUT, LTmp1$
        LOOP
        CLOSE LFP1
    END IF
END SUB ' User_Global_Enum_Blocks



SUB System_Defined_Constants(FP_OUTPUT AS FILE)
    '*********************************************************************************
    ' This SUB processes system-defined macros stored inside the file (SysFile$) and
    ' writes them to a given file stream (FP_OUTPUT). If the system file exists and has
    ' a size greater than 2 bytes, it opens the file, reads each line, trims leading
    ' and trailing whitespace, and writes non-empty lines to the output file.
    '*********************************************************************************
    IF EXIST(SysFile$) AND LOF(SysFile$) > 2 THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, "//               System Defined Macros"
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, SPC$

        IF NO_VKKEYS = FALSE AND ZapFlag = FALSE THEN
            FPRINT FP_OUTPUT, "#ifndef    VK_0"        ' LccWin32 and Pelles include these, MSVC and MINGW do not!
            FPRINT FP_OUTPUT, "   #define VK_0  0x30"
            FPRINT FP_OUTPUT, "   #define VK_1  0x31"
            FPRINT FP_OUTPUT, "   #define VK_2  0x32"
            FPRINT FP_OUTPUT, "   #define VK_3  0x33"
            FPRINT FP_OUTPUT, "   #define VK_4  0x34"
            FPRINT FP_OUTPUT, "   #define VK_5  0x35"
            FPRINT FP_OUTPUT, "   #define VK_6  0x36"
            FPRINT FP_OUTPUT, "   #define VK_7  0x37"
            FPRINT FP_OUTPUT, "   #define VK_8  0x38"
            FPRINT FP_OUTPUT, "   #define VK_9  0x39"
            FPRINT FP_OUTPUT, "   #define VK_A  0x41"
            FPRINT FP_OUTPUT, "   #define VK_B  0x42"
            FPRINT FP_OUTPUT, "   #define VK_C  0x43"
            FPRINT FP_OUTPUT, "   #define VK_D  0x44"
            FPRINT FP_OUTPUT, "   #define VK_E  0x45"
            FPRINT FP_OUTPUT, "   #define VK_F  0x46"
            FPRINT FP_OUTPUT, "   #define VK_G  0x47"
            FPRINT FP_OUTPUT, "   #define VK_H  0x48"
            FPRINT FP_OUTPUT, "   #define VK_I  0x49"
            FPRINT FP_OUTPUT, "   #define VK_J  0x4A"
            FPRINT FP_OUTPUT, "   #define VK_K  0x4B"
            FPRINT FP_OUTPUT, "   #define VK_L  0x4C"
            FPRINT FP_OUTPUT, "   #define VK_M  0x4D"
            FPRINT FP_OUTPUT, "   #define VK_N  0x4E"
            FPRINT FP_OUTPUT, "   #define VK_O  0x4F"
            FPRINT FP_OUTPUT, "   #define VK_P  0x50"
            FPRINT FP_OUTPUT, "   #define VK_Q  0x51"
            FPRINT FP_OUTPUT, "   #define VK_R  0x52"
            FPRINT FP_OUTPUT, "   #define VK_S  0x53"
            FPRINT FP_OUTPUT, "   #define VK_T  0x54"
            FPRINT FP_OUTPUT, "   #define VK_U  0x55"
            FPRINT FP_OUTPUT, "   #define VK_V  0x56"
            FPRINT FP_OUTPUT, "   #define VK_W  0x57"
            FPRINT FP_OUTPUT, "   #define VK_X  0x58"
            FPRINT FP_OUTPUT, "   #define VK_Y  0x59"
            FPRINT FP_OUTPUT, "   #define VK_Z  0x5A"
            FPRINT FP_OUTPUT, "#endif "
            FPRINT FP_OUTPUT, SPC$
        END IF

        DIM RAW private_Tmp$
        DIM RAW private_FP1 AS FILE

        OPEN SysFile$ FOR INPUT AS private_FP1     ' SysFile$    ' System translated CONSTants
        DO WHILE NOT EOF(private_FP1)
            LINE INPUT private_FP1, private_Tmp$
            private_Tmp$ = TRIM$(private_Tmp$)
            IF private_Tmp$ <> "" THEN FPRINT FP_OUTPUT, private_Tmp$
        LOOP
        CLOSE private_FP1
    END IF
END SUB ' System_Defined_Constants



SUB User_Defined_Constants(FP_OUTPUT AS FILE)
    '***************************************************************************************
    ' This SUB processes user-defined macros stored in the file (UsrFile$) and writes them
    ' to a given file stream (FP_OUTPUT). If the user file exists and has a size greater than
    ' 2 bytes, it opens the file, reads each line, trims leading whitespace, and writes the
    ' lines to the output file. It then closes the user file.
    '***************************************************************************************
    DIM RAW LTmp1$
    DIM RAW LFP1 AS FILE
    DIM Flagged

    IF EXIST(UsrFile$) AND LOF(UsrFile$) THEN
        OPEN UsrFile$ FOR INPUT AS LFP1     ' UsrConstFile$      ' user translated CONSTants
        DO WHILE NOT EOF(LFP1)
            LINE INPUT LFP1, LTmp1$

            IF NOT Flagged AND LEN(RTRIM$(LTmp1$)) > 7 THEN
                Flagged = TRUE
                FPRINT FP_OUTPUT, SPC$
                FPRINT FP_OUTPUT, "// *************************************************"
                FPRINT FP_OUTPUT, "//            Application Defined Macros"
                FPRINT FP_OUTPUT, "// *************************************************"
            END IF

            FPRINT FP_OUTPUT, LTRIM$(LTmp1$)
        LOOP
        CLOSE LFP1
    END IF
END SUB ' User_Defined_Constants



SUB User_Defined_Types_And_Unions(FP_OUTPUT AS FILE)
    '**************************************************************************
    ' This SUB processes UDTs and unions stored inside file (udtFile$) and
    ' writes them to a given file stream (FP_OUTPUT). If the UDT file exists
    ' and has a size greater than 2 bytes, it opens the file, reads each line,
    ' and writes it to the output file. It then closes the UDT file.
    '**************************************************************************
    DIM RAW LTmp1$
    DIM RAW LFP1 AS FILE

    IF EXIST(udtFile$) AND LOF(udtFile$) > 2 THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, "//       Application Defined Types And Unions"
        FPRINT FP_OUTPUT, "// *************************************************"

        OPEN udtFile$ FOR INPUT AS LFP1       '  translated User Defined Types
        DO WHILE NOT EOF(LFP1)
            LINE INPUT LFP1, LTmp1$
            FPRINT FP_OUTPUT, LTmp1$
        LOOP
        CLOSE LFP1
    END IF
END SUB ' User_Defined_Types_And_Unions



SUB User_Data_Statements(FP_OUTPUT AS FILE)
    '*********************************************************************************
    ' This SUB processes user-defined data statements stored in file (datFile$) and
    ' writes them to a given file stream (FP_OUTPUT) as a C-style array of strings.
    ' If the data file exists and has a size greater than 0 bytes, it opens the file,
    ' reads each line, constructs the array in the output file, then closes the file.
    '*********************************************************************************
    DIM RAW LTmp1$
    DIM RAW LFP1 AS FILE
    '********************************
    ' Read In The Data Statement File
    '********************************
    IF LOF(datFile$) > 0 THEN
        OPEN datFile$ FOR INPUT AS LFP1
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, "//           Application Data Statements"
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "char * DATA[] ="
        FPRINT FP_OUTPUT, "{"
        DO WHILE NOT EOF(LFP1)
            LINE INPUT LFP1, LTmp1$
            FPRINT FP_OUTPUT, LTmp1$; ' Suppress CRLF
            IF NOT EOF(LFP1) THEN FPRINT FP_OUTPUT, ","
        LOOP
        CLOSE LFP1
        FPRINT FP_OUTPUT, "\n};"
    END IF
END SUB ' User_Data_Statements



SUB User_Global_Variables(FP_OUTPUT AS FILE)
    '***********************************************************************************
    ' This SUB declares user-defined global variables and arrays stored in various data
    ' structures. It writes them to file stream (FP_OUTPUT) with proper formatting based
    ' on their attributes such as type, storage class, dimensionality, and directives.
    '***********************************************************************************
    DIM RAW i, VarName$, Storage$, VarDim$, A, P$

    IF GlobalVarCnt OR DllCnt THEN
        FPRINT FP_W, ""
        FPRINT FP_W, "// *************************************************"
        FPRINT FP_W, "//          ", c_$BCX_STR_USR_VARS
        FPRINT FP_W, "// *************************************************"
        FPRINT FP_W, ""
    END IF

    '*************************************
    ' Declare the DLL Variables
    '*************************************

    IF DllCnt THEN
        FOR iii AS INT = 1 TO DllCnt
            FPRINT FP_W, "static BCXFPROT", STR$(iii, 1), SPC$, EXTRACT$(DllDecl$[iii], "="), ";"
        NEXT
    END IF

    '*************************************
    ' Declare the simple Variables
    '*************************************

    FOR i = 1 TO GlobalVarCnt
        IF GlobalVars[i].VarEmitFlag THEN ITERATE
        IF "" = GlobalVars[i].VarDim$ AND GlobalVars[i].VarCondLevel = 0 THEN
            P$ = ""
            IF GlobalVars[i].VarPntr THEN P$ = STRING$(GlobalVars[i].VarPntr, 42)
            A = GlobalVars[i].VarType
            IF GlobalVars[i].VarSF THEN
                VarName$ = "(*" + GlobalVars[i].VarName$ + ")"
            ELSE
                VarName$ = GlobalVars[i].VarName$
            END IF
            Storage$ = VarStorage$[GlobalVars[i].VarExtn] + VarConst$[GlobalVars[i].VarConstant]
            VarDim$ = GlobalVars[i].VarDim$
            CALL Emit_Global(FP_OUTPUT, A, i, Storage$, P$, VarName$, VarDim$)
        END IF
    NEXT

    '   Next, we declare the Arrays

    FOR i = 1 TO GlobalVarCnt
        IF GlobalVars[i].VarEmitFlag THEN ITERATE
        IF "" <> GlobalVars[i].VarDim$ AND GlobalVars[i].VarCondLevel = 0 THEN
            IF INCHR(GlobalVars[i].VarDim, "{") = 0 THEN     ' do uninitialized global arrays
                P$ = ""
                IF GlobalVars[i].VarPntr THEN P$ = STRING$(GlobalVars[i].VarPntr, 42)
                A = GlobalVars[i].VarType
                IF GlobalVars[i].VarSF THEN
                    VarName$ = "(*" + GlobalVars[i].VarName$ + EXTRACT$(GlobalVars[i].VarDim, "(") + ")"
                    VarDim$ = MID$(GlobalVars[i].VarDim, INCHR(GlobalVars[i].VarDim, "("))
                ELSE
                    VarName$ = GlobalVars[i].VarName$
                    VarDim$ = GlobalVars[i].VarDim$
                END IF
                Storage$ = VarStorage$[GlobalVars[i].VarExtn] + VarConst$[GlobalVars[i].VarConstant]
                CALL Emit_Global(FP_OUTPUT, A, i, Storage$, P$, VarName$, VarDim$)
            END IF
        END IF
    NEXT

    DIM LastDef$  = ""
    DIM LastLevel = 1

    FOR i = 1 TO GlobalVarCnt
        IF GlobalVars[i].VarEmitFlag THEN ITERATE
        IF GlobalVars[i].VarCondLevel THEN
            IF ISNULL(LastDef$) THEN
                LastDef$ = GlobalVars[i].VarCondDef$
                LastLevel = GlobalVars[i].VarCondLevel
                FPRINT FP_OUTPUT, LastDef$
            END IF
            IF LastDef$ <> GlobalVars[i].VarCondDef$ THEN
                IF GlobalVars[i].VarCondDef$ = "#else" THEN
                    DO WHILE LastLevel > GlobalVars[i].VarCondLevel
                        FPRINT FP_OUTPUT, "#endif"
                        DECR LastLevel
                    LOOP
                    FPRINT FP_OUTPUT, "#else"
                    LastDef$ = GlobalVars[i].VarCondDef$
                ELSE
                    DO WHILE LastLevel => GlobalVars[i].VarCondLevel
                        FPRINT FP_OUTPUT, "#endif"
                        DECR LastLevel
                    LOOP
                    LastDef$ = GlobalVars[i].VarCondDef$
                    LastLevel = GlobalVars[i].VarCondLevel
                    FPRINT FP_OUTPUT, LastDef$
                END IF
            END IF
            P$ = ""
            IF GlobalVars[i].VarPntr THEN P$ = STRING$(GlobalVars[i].VarPntr, 42)
            A = GlobalVars[i].VarType
            IF GlobalVars[i].VarSF THEN
                VarName$ = "(*" + GlobalVars[i].VarName$ + ")"
            ELSE
                VarName$ = GlobalVars[i].VarName$
            END IF
            VarDim$ = GlobalVars[i].VarDim
            Storage$ = VarStorage$[GlobalVars[i].VarExtn] + VarConst$[GlobalVars[i].VarConstant]
            CALL Emit_Global(FP_OUTPUT, A, i, Storage$, P$, VarName$, VarDim$)

        END IF
    NEXT

    IF *LastDef$ THEN
        DO WHILE LastLevel
            FPRINT FP_OUTPUT, "#endif"
            DECR LastLevel
        LOOP
    END IF
END SUB ' User_Global_Variables







FUNCTION GetNumArgs (Strt, NdxPos AS INT PTR = NULL)
    DIM CountR = 0  ' () counter
    DIM CountS = 0  ' [] counter
    DIM i = 0       ' loop counter
    DIM j = 0       ' comma counter
    DIM k = 1       ' function end flag

    FOR i = Strt TO Ndx
        SELECT CASE *Stk$[i]

            CASE ASC("(")
                INCR CountR
                INCR k

            CASE ASC(")")
                DECR CountR
                DECR k
                IF k = 0 THEN EXIT SELECT, FOR

            CASE ASC("[")
                INCR CountS

            CASE ASC("]")
                DECR CountS

            CASE ASC(",")
                IF CountR = 0 AND CountS = 0 THEN
                    INCR j
                    IF NdxPos THEN *NdxPos = i
                END IF

        END SELECT
    NEXT
    FUNCTION = j   ' No. of commas = No. of args
END FUNCTION ' GetNumArgs



SUB GetVarCode(varcode AS UDT_VARCODE_ATTRIBUTES PTR, szWhere AS PCHAR)
    UNREFERENCED_PARAMETER(szWhere)
    DIM RAW CB$, PT$, PTH$, VAR$, vn, RF$, bRemoveSplat AS BOOL

    IF varcode->Methd% = mt_ConsDesNoParam OR varcode->Methd% = mt_FuncSubDecC_DecNoParam OR varcode->Methd% = mt_OverLoadNoParam THEN
        varcode->Proto$ += varcode->Token$
        varcode->Header$ += varcode->Token$
        EXIT SUB
    END IF

    IF varcode->Methd% = mt_OptsNoParam THEN
        varcode->Proto$ += varcode->Token$
        IF varcode->Token$ = "," OR InClass OR varcode->Token$ = "..." THEN
            varcode->Header$ += varcode->Token$
        END IF
        EXIT SUB
    END IF

    IF IsCallBack THEN
        CB$ = "CALLBACK "
    ELSE
        CB$ = ""
    END IF

    IF varcode->Methd = mt_ConsDesAParam THEN
        DIM iSplat = INCHR(varcode->AsToken$, "*")
        DIM iLT = INCHR(varcode->AsToken$, "<")
        DIM iGT = INCHR(varcode->AsToken$, ">")
        IF iSplat > iLT AND iSplat < iGT THEN
            bRemoveSplat = FALSE
        ELSE
            bRemoveSplat =TRUE
        END IF
    ELSE
        bRemoveSplat = TRUE
    END IF

    IF ((INCHR(varcode->Token$, "*") OR INCHR(varcode->AsToken$, "*")) AND bRemoveSplat) OR varcode->IsPtrFlag THEN
        RemoveAll(varcode->Token$, "*")
        RemoveAll(varcode->AsToken$, "*")
        PT$  = STRING$(varcode->IsPtrFlag, ASC("*")) + SPC$
        PTH$ = PT$
    ELSE
        PTH$ = SPC$
        PT$ = ""
    END IF

    IF INCHR(varcode->Token$, "&") THEN
        RF$ = " &"
    ELSE
        RF$ = ""
    END IF

    vn = varcode->VarNo%
    VAR$ = GetVarTypeName$(vn)

    DIM RAW pszHead$
    DIM RAW pszProto$

    pszHead$ = No_Sigil$(varcode->Token$)
    pszProto$ = pszHead$

    IF INCHR(pszProto$, "[") THEN
        pszProto$ = MID$(pszProto$, INCHR(pszProto$, "["))
    ELSE
        pszProto$ = ""
    END IF

    SELECT CASE vn
        '************************************************************************
        CASE vt_STRVAR
            '************************************************************************

            SELECT CASE varcode->Methd%

                CASE mt_ProcessSetCommand
                    varcode->StaticOut$ = "static char   " + pszHead$

                CASE mt_FuncSubDecC_Dec
                    varcode->Functype$ = "char * " + CB$

                CASE mt_FuncSubDecC_DecAParam
                    IF NOT INCHR(varcode->Token$, "[") THEN
                        varcode->Header$ = varcode->Header$  +  "char *" + pszHead$
                        varcode->Proto$  = varcode->Proto$   +  "char *"
                    ELSE
                        varcode->Header$ = varcode->Header$  +  "char " + REMOVE$(pszHead$, "*")
                        varcode->Proto$  = varcode->Proto$   +  "char[][BCXSTRSIZE]"
                    END IF

                CASE mt_Opts
                    varcode->Functype$ = "char *"

                CASE mt_ConsDesAParam
                    varcode->Header$ = varcode->Header$  + "char *"  +  pszHead$
                    varcode->Proto$  = varcode->Proto$   + "char *"  +  pszHead$

                CASE mt_OptsAParam
                    varcode->Header$ = varcode->Header$  + "char *"  +  pszHead$
                    varcode->Proto$  = varcode->Proto$   + "char *"

                CASE mt_OverLoad
                    varcode->Functype$ = "char *"

                CASE mt_OverLoadAParam
                    varcode->Header$ = varcode->Header$ + "char *" + pszHead$

            END SELECT

            '************************************************************************
        CASE vt_BOOL, vt_BYTE, vt_COLORREF, vt_DOUBLE, vt_DWORD, vt_FARPROC, vt_HDC, _
            vt_HANDLE, vt_HINSTANCE, vt_HWND, vt_HBITMAP, vt_INTEGER, vt_PCHAR, vt_LONG, vt_PBYTE, vt_LRESULT, _
            vt_SHORT, vt_SINGLE, vt_UINT, vt_ULONG, vt_USHORT, vt_SAFEARRAY, vt_VARIANT, vt_VOID, vt_LDOUBLE, _
            vt_SSHORT, vt_SCHAR, vt_DWORD, vt_WORD, vt_WINBOOL, vt_BSTR
            '************************************************************************

            SELECT CASE varcode->Methd%

                CASE mt_ProcessSetCommand
                    varcode->StaticOut$ = "static " + VAR$ + SPC$ + pszHead$

                CASE mt_FuncSubDecC_Dec
                    varcode->Functype$ = VAR$ + PTH$ + CB$

                CASE mt_FuncSubDecC_DecAParam
                    varcode->Header$ = varcode->Header$  +  VAR$ + PTH$ + pszHead$
                    varcode->Proto$  = varcode->Proto$   +  VAR$ + RF$ + PT$

                CASE mt_Opts
                    varcode->Functype$ = VAR$ + PTH$

                CASE mt_OptsAParam
                    varcode->Header$ = varcode->Header$  +  VAR$ + PTH$ + pszHead$
                    varcode->Proto$  = varcode->Proto$   +  VAR$ + RF$ + PT$

                CASE mt_ConsDesAParam
                    varcode->Header$ = varcode->Header$  +  VAR$ + PTH$ + pszHead$
                    varcode->Proto$  = varcode->Proto$   +  VAR$ + PTH$ + pszHead$

                CASE mt_OverLoad
                    varcode->Functype$ = VAR$ + SPC$

                CASE mt_OverLoadAParam
                    varcode->Header$ = varcode->Header$ + VAR$ + PTH$ + pszHead$

            END SELECT

            '************************************************************************
        CASE vt_FILEPTR
            '************************************************************************

            SELECT CASE varcode->Methd%

                CASE mt_FuncSubDecC_Dec
                    varcode->Functype$ = VAR$ + PTH$ + CB$

                CASE mt_FuncSubDecC_DecAParam
                    varcode->Header$ = varcode->Header$   +  VAR$ + PTH$ + pszHead$
                    IF INCHR(varcode->Token$, "[") THEN
                        varcode->Proto$  = varcode->Proto$ +  VAR$ + PT$ + SPC$ + pszHead$
                    ELSE
                        varcode->Proto$  = varcode->Proto$ +  VAR$ + PT$
                    END IF

                CASE mt_Opts
                    varcode->Functype$ = VAR$ + PTH$

                CASE mt_OptsAParam                     ' y
                    varcode->Header$ = varcode->Header$  +  VAR$ + PTH$  +  pszHead$
                    varcode->Proto$  = varcode->Proto$   +  VAR$ + PT$

                CASE mt_ConsDesAParam
                    varcode->Header$ = varcode->Header$  +  VAR$ + PTH$  +  pszHead$
                    varcode->Proto$  = varcode->Proto$   +  VAR$ + PTH$  +  pszHead$

                CASE mt_OverLoad
                    varcode->Functype$ = VAR$ + SPC$

                CASE mt_OverLoadAParam
                    varcode->Header$ = varcode->Header$ + VAR$ + PTH$ + pszHead$

            END SELECT

            '************************************************************************
        CASE vt_CHAR, vt_SCHAR
            '************************************************************************

            SELECT CASE varcode->Methd%

                CASE mt_FuncSubDecC_Dec
                    varcode->Functype$ = VAR$ + PTH$ + CB$

                CASE mt_FuncSubDecC_DecAParam
                    varcode->Header$ = varcode->Header$  +  VAR$ + PTH$ + pszHead$
                    varcode->Proto$  = varcode->Proto$   +  VAR$ + PT$ + SPC$ + pszProto$

                CASE mt_Opts
                    varcode->Functype$ = VAR$ + PTH$

                CASE mt_OptsAParam
                    varcode->Header$ = varcode->Header$  +  VAR$ + PTH$  +  pszHead$
                    varcode->Proto$  = varcode->Proto$   +  VAR$ + PT$ + SPC$ + pszProto$

                CASE mt_ConsDesAParam
                    varcode->Header$ = varcode->Header$  +  VAR$ + PTH$  +  pszHead$
                    varcode->Proto$  = varcode->Proto$   +  VAR$ + PTH$  + SPC$ + pszProto$

                CASE mt_OverLoad
                    varcode->Functype$ = VAR$ + SPC$

                CASE mt_OverLoadAParam
                    varcode->Header$ = varcode->Header$ + VAR$ + PTH$ + pszHead$

            END SELECT

            '************************************************************************
        CASE vt_UDT, vt_STRUCT, vt_UNION
            '************************************************************************

            SELECT CASE varcode->Methd%

                CASE mt_ProcessSetCommand
                    IF vn = vt_UNION THEN
                        varcode->StaticOut$ = "static union  " + pszHead$
                    ELSE
                        varcode->StaticOut$ = "static struct _" + pszHead$ + SPC$
                    END IF

                CASE mt_FuncSubDecC_Dec
                    varcode->Functype$ = varcode->AsToken$ + PTH$ + CB$

                CASE mt_FuncSubDecC_DecAParam
                    varcode->Header$ = varcode->Header$  +  varcode->AsToken$ + PTH$ +  pszHead$
                    varcode->Proto$  = varcode->Proto$   +  varcode->AsToken$ + RF$ + PT$

                CASE mt_Opts
                    varcode->Functype$ = varcode->AsToken$ + PTH$

                CASE mt_OptsAParam
                    varcode->Header$ = varcode->Header$ + No_Sigil$(varcode->AsToken$) + PTH$ + SPC$ + pszHead$
                    varcode->Proto$ = varcode->Proto$   + No_Sigil$(varcode->AsToken$) + RF$ + PT$

                CASE mt_ConsDesAParam
                    varcode->Header$ = varcode->Header$ + No_Sigil$(varcode->AsToken$) + PTH$ + SPC$ + pszHead$
                    varcode->Proto$ = varcode->Proto$   + No_Sigil$(varcode->AsToken$) + PTH$ + SPC$ + pszHead$

                CASE mt_OverLoad
                    varcode->Functype$ = VAR$ + SPC$

                CASE mt_OverLoadAParam
                    varcode->Header$ = varcode->Header$ + varcode->AsToken$ + PTH$ + pszHead$

            END SELECT

        CASE vt_CONSTRDESTR
            SELECT CASE varcode->Methd%
                CASE mt_ConsDes
                    varcode->Functype$ = VAR$ + PTH$ + CB$
            END SELECT

            '************************************************************************
        CASE ELSE
            '************************************************************************

            SELECT CASE varcode->Methd%

                CASE mt_FuncSubDecC_Dec
                    varcode->Functype$ = varcode->AsToken$ + PTH$ + CB$

                CASE mt_FuncSubDecC_DecAParam
                    varcode->Header$ = varcode->Header$  +  varcode->AsToken$ + PTH$ +  pszHead$
                    varcode->Proto$ = varcode->Proto$    +  varcode->AsToken$ + RF$ + PT$

                CASE mt_Opts
                    varcode->Functype$ = varcode->AsToken$ + PTH$

                CASE mt_OptsAParam
                    varcode->Header$ = varcode->Header$ + No_Sigil$(varcode->AsToken$) + PTH$ + SPC$ + pszHead$
                    varcode->Proto$  = varcode->Proto$  + No_Sigil$(varcode->AsToken$) + RF$ + PT$

                CASE mt_ConsDesAParam
                    varcode->Header$ = varcode->Header$ + No_Sigil$(varcode->AsToken$) + SPC$ + pszHead$
                    varcode->Proto$  = varcode->Proto$  + No_Sigil$(varcode->AsToken$) + SPC$ + pszHead$

            END SELECT
    END SELECT
END SUB ' GetVarCode




SUB User_Global_Initialized_Arrays(FP_OUTPUT AS FILE)
    STATIC Banner_Printed    ' Must remain static
    DIM RAW Banner$
    DIM RAW P$, i, A
    DIM RAW VarName$
    DIM RAW VarDim$
    DIM RAW Storage$
    DIM RAW VAR$

    FOR i = 1 TO GlobalVarCnt
        IF GlobalVars[i].VarEmitFlag THEN ITERATE
        IF NOTNULL(GlobalVars[i].VarDim$) AND GlobalVars[i].VarCondLevel = 0 THEN
            IF INCHR(GlobalVars[i].VarDim, "{") THEN

                IF Banner_Printed = FALSE THEN     ' 838 MrBcx moved here - print no banner if no Arrays
                    Banner$  = ""
                    Banner$ += ""                                                     + LF$
                    Banner$ += "// *************************************************" + LF$
                    Banner$ += "//       Application Global Initialized Arrays"       + LF$
                    Banner$ += "// *************************************************" + LF$
                    Banner_Printed = TRUE
                    FPRINT FP_OUTPUT, Banner$
                END IF

                P$ = ""
                IF GlobalVars[i].VarPntr THEN P$ = STRING$(GlobalVars[i].VarPntr, 42)
                A = GlobalVars[i].VarType

                IF GlobalVars[i].VarSF THEN
                    VarName$ = "(*" + GlobalVars[i].VarName$ + EXTRACT$(GlobalVars[i].VarDim, "(") + ")"
                    VarDim$ = MID$(GlobalVars[i].VarDim, INCHR(GlobalVars[i].VarDim, "("))
                ELSE
                    VarName$ = GlobalVars[i].VarName$
                    VarDim$ = GlobalVars[i].VarDim
                END IF

                Storage$ = VarStorage$[GlobalVars[i].VarExtn] + VarConst$[GlobalVars[i].VarConstant]

                SELECT CASE A
                    ' handle exceptions

                    CASE vt_STRVAR
                        FPRINT FP_OUTPUT, Storage$, "char    ", VarName$, VarDim$, ";"

                    CASE vt_FILEPTR
                        REMOVE "@" FROM GlobalVars[i].VarName$
                        FPRINT FP_OUTPUT, Storage$, "FILE    *", VarName$, VarDim$, ";"

                    CASE vt_PSTR
                        FPRINT FP_OUTPUT, Storage$, "PSTR   ", P$, VarName$, VarDim$, ";"

                    CASE vt_UDT, vt_STRUCT, vt_UNION
                        VAR$ = TypeDefs[GlobalVars[i].VarDef].VarName$
                        VAR$ = RPAD$(VAR$, c_PADSIZE)
                        FPRINT FP_OUTPUT, Storage$, VAR$, SPC$, P$, VarName$, VarDim$, ";"

                        ' handle normal
                    CASE c_vt_VarMin TO c_vt_VarMax
                        VAR$ = GetVarTypeName$(GlobalVars[i].VarType)
                        VAR$ = RPAD$(VAR$, c_PADSIZE)
                        FPRINT FP_OUTPUT, Storage$, VAR$, SPC$, P$, VarName$, VarDim$, ";"

                END SELECT
            END IF
        END IF
    NEXT
END SUB ' User_Global_Initialized_Arrays



SUB User_Overloaded_SubsFunctions(FP_OUTPUT AS FILE)
    DIM RAW LZZ$
    DIM RAW FP_OVR_IN AS FILE

    IF Use_Overloaded THEN
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, "//       Application Overloaded Subs/Functions"
        FPRINT FP_OUTPUT, "// *************************************************"

        OPEN ovrFile$ FOR INPUT AS FP_OVR_IN

        DO WHILE NOT EOF(FP_OVR_IN)
            LINE INPUT FP_OVR_IN, LZZ$
            IF iMatchNQ (LZZ$, "overloaded") THEN
                FPRINT FP_OUTPUT, "\n"
            END IF
            FPRINT FP_OUTPUT, LZZ$
        LOOP

        CLOSE FP_OVR_IN
        FPRINT FP_OUTPUT, "\n\n"
    END IF
END SUB ' User_Overloaded_SubsFunctions



SUB User_Global_Set_Statements(FP_OUTPUT AS FILE)
    DIM RAW LTmp1$
    DIM RAW LFP1 AS FILE

    IF LOF(setFile$) > 0 THEN
        OPEN setFile$ FOR INPUT AS LFP1
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, "//         Application GLOBAL SET Statements"
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, SPC$
        DO WHILE NOT EOF(LFP1)
            LINE INPUT LFP1, LTmp1$
            FPRINT FP_OUTPUT, LTmp1$
        LOOP
        FPRINT FP_OUTPUT, SPC$
        CLOSE LFP1
    END IF
END SUB ' User_Global_Set_Statements



SUB User_Prototypes(FP_OUTPUT AS FILE)
    DIM RAW LastDef$
    DIM RAW LastLevel
    DIM RAW A

    IF ProtoCnt THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, "//        ", c_$BCX_STR_USR_PROTOS
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, SPC$

        LastDef$ = ""                                 ' f.e.: LastDef$ = ProtoType[A].Condition$
        LastLevel = 1

        FOR A = 1 TO ProtoCnt

            IF LastDef$ = "" THEN
                LastDef$ = ProtoType[A].Condition$    ' f.e.: .Condition$ = "#else"
                LastLevel = ProtoType[A].CondLevel    ' f.e.: .CondLevel = InConditional ... or zero
                IF Use_SingleFile = FALSE THEN
                    IF LastDef$ <> "" THEN FPRINT FP_HeaderFile, LastDef$
                END IF
                IF LastDef$ <> "" THEN FPRINT FP_OUTPUT, LastDef$
            END IF

            IF LastDef$ <> ProtoType[A].Condition$ THEN
                IF ProtoType[A].Condition$ = "#else" THEN
                    DO WHILE LastLevel > ProtoType[A].CondLevel
                        IF Use_SingleFile = FALSE THEN
                            FPRINT FP_HeaderFile, "#endif"
                        END IF
                        FPRINT FP_OUTPUT, "#endif"
                        DECR LastLevel
                    LOOP
                    IF Use_SingleFile = FALSE THEN
                        FPRINT FP_HeaderFile, "#else"
                    END IF
                    FPRINT FP_OUTPUT, "#else"
                    LastDef$ = ProtoType[A].Condition$
                    LastLevel = ProtoType[A].CondLevel

                ELSE

                    DO WHILE LastLevel >= ProtoType[A].CondLevel
                        IF Use_SingleFile = FALSE THEN
                            FPRINT FP_HeaderFile, "#endif"
                        END IF
                        FPRINT FP_OUTPUT, "#endif"
                        DECR LastLevel
                    LOOP
                    LastDef$ = ProtoType[A].Condition$
                    LastLevel = ProtoType[A].CondLevel
                    IF Use_SingleFile = FALSE THEN
                        IF LastDef$ <> "" THEN FPRINT FP_HeaderFile, LastDef$
                    END IF
                    IF LastDef$ <> "" THEN FPRINT FP_OUTPUT, LastDef$
                END IF
            END IF

            IF UseStdCall AND UseCpp THEN
                IF LEFTSTR(ProtoType[A].Prototype$, "C_EXPORT ") THEN
                    Emit_ExportDef(ProtoType[A].Prototype$)
                    UseImportExport = TRUE
                END IF
            END IF

            DIM RAW T$
            T$ = EXTRACT$(ProtoType[A].Prototype$, SPC$)
            T$ = RPAD$(T$, c_PADSIZE) + SPC$
            ProtoType[A].Prototype$ = T$ + REMAIN$(ProtoType[A].Prototype$, SPC$)

            $IFDEF __MINGW64__          ' 837 added by Luigi
                REPLACE "char *=" WITH "char * =" IN ProtoType[A].Prototype$
            $ENDIF

            '*************************************************************
            ' MrBcx added this block of code beautification in 838
            '*************************************************************
            DIM PrettyPrint$ = ProtoType[A].Prototype$
            DIM idx, lhs$, rhs$

            REPLACE "char*"      WITH "char *" IN PrettyPrint$
            REPLACE "char    * " WITH "char *" IN PrettyPrint$
            REPLACE "char * "    WITH "char *" IN PrettyPrint$

            idx = INCHR(PrettyPrint$, SPC$)
            lhs$ = MID$(PrettyPrint$, 1, idx)
            rhs$ = MID$(PrettyPrint$, idx+1)

            WHILE LEN(lhs$)< 8
                CONCAT(lhs$, SPC$)
            WEND
            PrettyPrint$ = lhs$ + SPC$ + rhs$
            '*************************************************************
            IF Use_SingleFile = FALSE THEN
                FPRINT FP_HeaderFile, PrettyPrint$
            END IF
            FPRINT FP_OUTPUT, PrettyPrint$
        NEXT ' A 'ProtoCnt


        IF FPDEF THEN CLOSE FPDEF

        IF LastDef$ <> "" THEN
            DO WHILE LastLevel > 0
                IF Use_SingleFile = FALSE THEN
                    FPRINT FP_HeaderFile, "#endif"
                END IF
                FPRINT FP_OUTPUT, "#endif"
                DECR LastLevel
            LOOP
        END IF
    END IF
END SUB ' User_Prototypes



SUB AddMacros(FP_OUTPUT AS FILE)

    IF Use_SysMacros OR Use_Wingui THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, "//               " , c_$BCX_STR_STD_MACROS
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, SPC$
    END IF

    DIM  Accum= Use_Form
    INCR Accum, Use_Button
    INCR Accum, Use_BmpButton
    INCR Accum, Use_SplitButton
    INCR Accum, Use_Edit
    INCR Accum, Use_BCX_Input
    INCR Accum, Use_Label
    INCR Accum, Use_Group
    INCR Accum, Use_Checkbox
    INCR Accum, Use_Radio
    INCR Accum, Use_Combobox
    INCR Accum, Use_Listbox
    INCR Accum, Use_Treeview
    INCR Accum, Use_Blackrect
    INCR Accum, Use_Whiterect
    INCR Accum, Use_Grayrect
    INCR Accum, Use_Datepick
    INCR Accum, Use_Listview
    INCR Accum, Use_BCX_Control
    INCR Accum, Use_BCX_Slider
    INCR Accum, Use_BCX_Tab
    INCR Accum, Use_BCX_Toolbar
    INCR Accum, Use_BCX_UpDown
    INCR Accum, Use_BCX_FrameWnd
    INCR Accum, Use_BCX_Wnd

    IF Accum THEN
        IF NOT Use_Project THEN
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "HFONT GetDefaultFont(void)"     ' BCX 830  Jeff Shollenberger & MrBcx
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "    HFONT result = BcxFont;"
            FPRINT FP_OUTPUT, "    if (result == 0) {"
            FPRINT FP_OUTPUT, "        NONCLIENTMETRICS ncm;"
            FPRINT FP_OUTPUT, "        ncm.cbSize = sizeof(NONCLIENTMETRICS);"
            FPRINT FP_OUTPUT, "        if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)) {"
            FPRINT FP_OUTPUT, "            BcxFont = CreateFontIndirect(&ncm.lfMessageFont);"
            FPRINT FP_OUTPUT, "            result = BcxFont;"
            FPRINT FP_OUTPUT, "        } else {"
            FPRINT FP_OUTPUT, "            result = (HFONT)GetStockObject(DEFAULT_GUI_FONT);"
            FPRINT FP_OUTPUT, "       }"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    return result;"
            FPRINT FP_OUTPUT, "}"
            FPRINT FP_OUTPUT, "#define DefaultFont GetDefaultFont()"
        ELSE
            FPRINT FP_OUTPUT, "#ifndef __BCXFONT_DEFINED__"
            FPRINT FP_OUTPUT, "  #define __BCXFONT_DEFINED__"
            FPRINT FP_OUTPUT, "HFONT GetDefaultFont(void)"     ' BCX 830 MrBcx & Jeff Shollenberger
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "    HFONT result = BcxFont;"
            FPRINT FP_OUTPUT, "    if (result == 0) {"
            FPRINT FP_OUTPUT, "        NONCLIENTMETRICS ncm;"
            FPRINT FP_OUTPUT, "        ncm.cbSize = sizeof(NONCLIENTMETRICS);"
            FPRINT FP_OUTPUT, "        if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0)) {"
            FPRINT FP_OUTPUT, "            BcxFont = CreateFontIndirect(&ncm.lfMessageFont);"
            FPRINT FP_OUTPUT, "            result = BcxFont;"
            FPRINT FP_OUTPUT, "        } else {"
            FPRINT FP_OUTPUT, "            result = (HFONT)GetStockObject(DEFAULT_GUI_FONT);"
            FPRINT FP_OUTPUT, "       }"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    return result;"
            FPRINT FP_OUTPUT, "}"
            FPRINT FP_OUTPUT, "#define DefaultFont GetDefaultFont()"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "#endif"
        END IF
        CALL AddBcxFontVar
    END IF

    '=======================================================================================================

    IF Use_SysMacros THEN

        IF Use_ForEach THEN
            FPRINT FP_OUTPUT, "#define FOR_EACH(i, a) {for(UINT i=0; i<sizeof((a))/sizeof((a)[0]); i++){"
            FPRINT FP_OUTPUT, "#define NEXT_EACH }}"
            FPRINT FP_OUTPUT, "#define EXIT_EACH break;"
        END IF

        IF Use_Clip_Reset THEN
            FPRINT FP_OUTPUT, "#define Clipboard_Reset OpenClipboard(NULL),EmptyClipboard(),CloseClipboard();"
        END IF

        IF Use_Cast THEN
            FPRINT FP_OUTPUT, "#define CAST(to_type,old_obj) ((to_type)(old_obj))"
        END IF

        IF Use_Read THEN
            FPRINT FP_OUTPUT, "#define READ(a) DATA[(a)-1]"
        END IF

        IF Use_Readnum THEN
            FPRINT FP_OUTPUT, "#define READNUM(a) (double)atof((DATA[(a)-1]))"
        END IF

        IF Use_EqualTo THEN
            FPRINT FP_OUTPUT, "#define EqualTo =="
        END IF

        IF Use_NotEqualTo THEN
            FPRINT FP_OUTPUT, "#define NotEqualTo !="
        END IF

        IF Use_BcxSplitPath THEN
            FPRINT FP_OUTPUT, "#define FDRV   2"
            FPRINT FP_OUTPUT, "#define FPATH  4"
            FPRINT FP_OUTPUT, "#define FNAME  8"
            FPRINT FP_OUTPUT, "#define FEXT  16"
        END IF

        IF Use_Cbool THEN
            FPRINT FP_OUTPUT, "#define CBOOL(A)((A)!=0)?1:0"
        END IF

        IF Use_Istrue THEN
            FPRINT FP_OUTPUT, "#define ISTRUE 0!="
        END IF

        IF Use_Notzero THEN
            FPRINT FP_OUTPUT, "#define NOTZERO 0!="
        END IF

        IF Use_Notnull THEN
            FPRINT FP_OUTPUT, "#define NOTNULL(A)(*(A)!=0)"
        END IF

        IF Use_Isnull THEN
            FPRINT FP_OUTPUT, "#define ISNULL(A)(*(A)==0)"
        END IF

        IF Use_Isfalse THEN
            FPRINT FP_OUTPUT, "#define ISFALSE 0=="
        END IF

        IF Use_Iszero THEN
            FPRINT FP_OUTPUT, "#define ISZERO 0=="
        END IF

        IF Use_Isptr THEN
            FPRINT FP_OUTPUT, "#define IsPtr(a)((ULONG_PTR)(a))"
        END IF

        IF Use_ByteAt THEN
            FPRINT FP_OUTPUT, "#define BYTE_AT(B)(B)"
        END IF

        IF Use_Bnot THEN
            FPRINT FP_OUTPUT, "#define BNOT ~(int)"
        END IF

        IF Use_Datacount THEN
            FPRINT FP_OUTPUT, "#define DATACOUNT(int)(sizeof((DATA))/sizeof((DATA[0])))"
        END IF

        IF Use_Ubound THEN
            FPRINT FP_OUTPUT, "#define ubound_s(t)(int)(sizeof((t))/sizeof((t[0]))-1)"
            FPRINT FP_OUTPUT, "#define ubound_d(i)(int)(_msize((i))/sizeof(i[0])-3)"
            FPRINT FP_OUTPUT, "#define ubound(x)((int)ubound_s(x)<2?ubound_d(x):ubound_s(x))"
        END IF

        IF Use_Clear THEN
            FPRINT FP_OUTPUT, "#define Clear(arg)memset(&arg,0,sizeof(arg))"
        END IF

        IF Use_Imod THEN
            FPRINT FP_OUTPUT, "#define imod(a,b)((a)%(b))"
        END IF

        IF Use_BCX_OlePicture THEN
            FPRINT FP_OUTPUT, "#define BCX_OLE_WIDTH(H)LOWORD(PtrToUlong(GetWindowLongPtr(H,GWLP_USERDATA)))"
            FPRINT FP_OUTPUT, "#define BCX_OLE_HEIGHT(H)HIWORD(PtrToUlong(GetWindowLongPtr(H,GWLP_USERDATA)))"
        END IF

        IF Use_BCX_Resize THEN
            FPRINT FP_OUTPUT, "#define BCX_RESIZE(hwnd,cx,cy)SetWindowPos(hwnd,NULL,0,0,(cx),(cy),SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOZORDER|SWP_FRAMECHANGED)"
        END IF

        IF Use_BCX_Cursor THEN
            FPRINT FP_OUTPUT, "#define BCX_Cursor(x)SetCursor(LoadCursor(NULL,x))"
        END IF

        IF Use_Refresh THEN
            FPRINT FP_OUTPUT, "#define Refresh(A)RedrawWindow(A,NULL,NULL,RDW_ERASE|RDW_INVALIDATE|RDW_ALLCHILDREN|RDW_UPDATENOW);"
        END IF

        IF Use_ShowModal THEN
            FPRINT FP_OUTPUT, "#define ShowModal(Window)EnableWindow(GetWindow(Window,GW_OWNER),FALSE);SHOWHWNDWindow);"
        END IF

        IF Use_EndModal THEN
            FPRINT FP_OUTPUT, "#define EndModal(Window)EnableWindow(GetWindow(Window,GW_OWNER),TRUE);DestroyWindow(Window);"
        END IF

        IF Use_Show THEN
            FPRINT FP_OUTPUT, "#define SHOWHWND(Window)RedrawWindow(Window,0,0,0);ShowWindow(Window,SW_SHOW);"
        END IF

        IF Use_Hide THEN
            FPRINT FP_OUTPUT, "#define HIDEHWND(Window)ShowWindow(Window,SW_HIDE)"
        END IF

        IF Use_Get THEN
            FPRINT FP_OUTPUT, "#define GET(A,B,C)fread((B),1,(C),(A))"
        END IF

        IF Use_Put THEN
            FPRINT FP_OUTPUT, "#define PUT(A,B,C)fwrite((B),1,(C),(A))"
        END IF

        IF Use_Seteof THEN
            FPRINT FP_OUTPUT, "#define SetEof(A)SetEndOfFile((HANDLE)_get_osfhandle(_fileno((A))))"
        END IF

        IF Use_Strptr THEN
            FPRINT FP_OUTPUT, "#define STRPTR(A)(char*)&((A))"
        END IF

        IF Use_Val THEN
            FPRINT FP_OUTPUT, "#define VAL(a)val_func((a))"               ' 837  Changed by MrBcx
        END IF

        IF Use_Vall THEN
            FPRINT FP_OUTPUT, "#if defined(__LCC__)||defined(__POCC__)||defined(__MINGW32__)||defined(__MINGW64__)"
            FPRINT FP_OUTPUT, "   #define VALL(a)(long double)strtold((a),(char**)NULL)"
            FPRINT FP_OUTPUT, "#elif defined(__BCPLUSPLUS__)"
            FPRINT FP_OUTPUT, "   #define VALL(a)(long double)_strtold((a),(char**)NULL)"
            FPRINT FP_OUTPUT, "#else"
            FPRINT FP_OUTPUT, "   #define VALL(a)(long double)strtod((a),(char**)NULL)"
            FPRINT FP_OUTPUT, "#endif"
        END IF

        IF Use_Getattr THEN
            FPRINT FP_OUTPUT, "#define GETATTR(a)(ULONG)GetFileAttributes((a))"
        END IF

        IF Use_Setattr THEN
            FPRINT FP_OUTPUT, "#define SETATTR(a,b)(ULONG)SetFileAttributes((a),(b))"
        END IF

        IF Use_Fix THEN
            FPRINT FP_OUTPUT, "#define FIX(a)(int)((a))"
        END IF

        IF Use_Frac THEN
            FPRINT FP_OUTPUT, "#define FRAC(a)(double)(((a))-FIX((a)))"
            Use_Fix = TRUE
        END IF

        IF Use_Fracl THEN
            FPRINT FP_OUTPUT, "#define FRACL(a)(long double)((a)-FIX((a)))"
            Use_Fix = TRUE
        END IF

        IF Use_Csng THEN
            FPRINT FP_OUTPUT, "#define CSNG(a)(float)((a))"
        END IF

        IF Use_Cdbl THEN
            FPRINT FP_OUTPUT, "#define CDBL(a)(double)((a))"
        END IF

        IF Use_Cldbl THEN
            FPRINT FP_OUTPUT, "#define CLDBL(a)(long double)((a))"
        END IF

        IF Use_DegToRad THEN
            FPRINT FP_OUTPUT, "#define DegToRad(Degrees)((Degrees)*0.017453292519943)"
        END IF

        IF Use_RadToDeg THEN
            FPRINT FP_OUTPUT, "#define RadToDeg(Radians)((Radians)*57.29577951308232)"
        END IF

        IF Use_Threads THEN
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "#define BCX_THREAD(a)        (HANDLE)_beginthreadex(0,0,(unsigned int (__stdcall *)(void *))a,0,0,(unsigned int *)&BCX_Thread_ID)"
            FPRINT FP_OUTPUT, "#define BCX_THREADWAIT(a)    while(WaitForSingleObject(((void *)a),0)==WAIT_TIMEOUT){}CloseHandle(((void *)a))"
            FPRINT FP_OUTPUT, "#define BCX_THREADSUSPEND(a) SuspendThread((void *)a)"
            FPRINT FP_OUTPUT, "#define BCX_THREADRESUME(a)  ResumeThread((void *)a)"
            FPRINT FP_OUTPUT, "#define BCX_THREADKILL(a)    TerminateThread((void *)a,0); CloseHandle((void *)a)"
            FPRINT FP_OUTPUT, "#define BCX_THREADEND        _endthreadex(0)"
            FPRINT FP_OUTPUT, "ULONG   BCX_Thread_ID = 0;"
            FPRINT FP_OUTPUT, SPC$
        END IF

        IF Use_LineinputKB THEN
            FPRINT FP_OUTPUT, "#define mIsDynaString(v)(sizeof((v))==4||sizeof((v))==8)?1:0"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "#define mLineInputKB(p,v)\\"
            FPRINT FP_OUTPUT, "{\\"
            FPRINT FP_OUTPUT, "   printf(", ENC$("%s"), ",(p));\\"
            FPRINT FP_OUTPUT, "   if(mIsDynaString(v))\\"
            FPRINT FP_OUTPUT, "       fgets((v), _msize((v)), stdin);\\"
            FPRINT FP_OUTPUT, "    else \\"
            FPRINT FP_OUTPUT, "       fgets((v), sizeof((v)), stdin);\\"
            FPRINT FP_OUTPUT, "   (v)[strlen((v))-1]=0;\\"
            FPRINT FP_OUTPUT, "}"
            FPRINT FP_OUTPUT, SPC$
        END IF
    END IF
END SUB ' AddMacros






FUNCTION JoinLines(Arg$)
    ' Joins lines connected using the line continuation character _
    Arg$ = RTRIM$(Arg$)
    IF     m_iMatchRgt(Arg$, " _") _
        OR m_iMatchRgt(Arg$, ",_") _
        OR m_iMatchRgt(Arg$, ";_") _
        OR m_iMatchRgt(Arg$, ":_") _
        OR m_iMatchRgt(Arg$, ")_") _
        OR m_iMatchRgt(Arg$, "(_") _
        OR m_iMatchRgt(Arg$, "]_") _
        OR m_iMatchRgt(Arg$, "[_") _
        OR m_iMatchRgt(Arg$, "}_") _
        OR m_iMatchRgt(Arg$, "{_") _
        OR m_iMatchRgt(Arg$, ">_") _
        OR m_iMatchRgt(Arg$, "<_") _
        OR m_iMatchRgt(Arg$, "+_") _
        OR m_iMatchRgt(Arg$, "-_") _
        OR m_iMatchRgt(Arg$, "*_") _
        OR m_iMatchRgt(Arg$, "/_") _
        OR m_iMatchRgt(Arg$, "\\_") _
        OR m_iMatchRgt(Arg$, "^_") _
        OR m_iMatchRgt(Arg$, "=_") _
        OR m_iMatchRgt(Arg$, "&_") _
        OR m_iMatchRgt(Arg$, "|_") _
        OR m_iMatchRgt(Arg$, "$_") _
        OR m_iMatchRgt(Arg$, DQ$ + "_") THEN
        Arg[LEN(Arg)-1] = 0
        CurLine$ += Arg$
        FUNCTION = TRUE
    END IF

    IF NOTNULL(CurLine$) THEN
        Arg$ = CurLine$ + Arg$
        CurLine$ = ""
    END IF
    UmQt = FALSE
    FUNCTION = FALSE
END FUNCTION ' JoinLines



SUB Sanitize_Code(Arg$)
    DIM RAW p AS PCHAR
    DIM RAW p2 = Arg AS PCHAR
    DIM RAW asmFlag = 0
    DIM RAW eStr = 0
    DIM RAW sub_$

    DO WHILE (*p2 >8 AND *p2 < 13) OR *p2 = 32      ' Trim leading space
        INCR p2
    LOOP

    IF *p2 = ASC("!") THEN asmFlag = NOT UmQt       ' Handle "!" Asm lines
    p = p2
    DO WHILE *p
        IF *p = 9 THEN *p = 32
        IF *p = c_DblQt THEN             ' ignore anything in string literal
            IF *(p-1) = 69 THEN          ' we're in an extended string: E"\qABCD\n"
                *(p-1) = 1               ' chr$(1) will be deleted
                eStr = TRUE
            END IF
            DO WHILE *(++p) <> c_DblQt
                IF *p = 92 AND eStr THEN ' look for a \0, \t, \n, \r, \q, \\
                    *p = 2

                    SELECT CASE *(p+1)
                        CASE 48  ' 0
                            *(p+1) = 3

                        CASE 116 ' t
                            *(p+1) = 4

                        CASE 110 ' n
                            *(p+1) = 5

                        CASE 114 ' r
                            *(p+1) = 6

                        CASE 113 ' q
                            *(p+1) = 7

                        CASE 92 ' \
                            *(p+1) = 8
                    END SELECT

                    INCR p
                END IF
                IF *p = 0 THEN
                    UmQt = NOT UmQt
                    EXIT DO
                END IF
            LOOP
        END IF

        ' If we're in a quoted continuation line then ignore comments

        IF NOT UmQt AND NOT asmFlag THEN
            IF (*p BOR 32) = ASC("r") THEN   ' Remove REM's
                IF _
                    (*(p+1) BOR 32) = ASC("e") AND _
                    (*(p+2) BOR 32) = ASC("m") AND _
                    (*(p+3) = 32 OR *(p+3) = 0) THEN
                    IF p = p2 OR *(p-1) = ASC(":") OR *(p-1) = 32 THEN
                        *p = 0
                        EXIT DO
                    END IF
                END IF
            END IF
            ' check for single quote comment marker and // C++ style comments
            IF *p = ASC("'") OR (*p = ASC("/") AND *(p+1) = ASC("/")) THEN
                *p = 0
                EXIT DO
            END IF
        END IF
        INCR p
    LOOP

    DO WHILE p2 < p
        ' Trim trailing space
        DO WHILE (*(p-1) >8 AND *(p-1) < 13) OR *(p-1) = 32
            *(--p) = 0
        LOOP

        IF UmQt OR asmFlag THEN EXIT DO

        ' Strip dangling colons
        IF *(p-1) = ASC(":") AND *(p-2) = 32 THEN
            DECR p
        ELSE
            EXIT DO
        END IF
    LOOP

    IF eStr THEN
        REMOVE CHR$(1) FROM p2$            ' E
        REMOVE CHR$(2) FROM p2$            ' \ first backslash

        sub_$ = ENC$("+CHR$(0)+")
        REPLACE CHR$(3) WITH sub_$ IN p2$  ' 0

        sub_$ = ENC$("+CHR$(9)+")
        REPLACE CHR$(4) WITH sub_$ IN p2$  ' t

        sub_$ = ENC$("+CHR$(10)+")
        REPLACE CHR$(5) WITH sub_$ IN p2$  ' n

        sub_$ = ENC$("+CHR$(13)+")
        REPLACE CHR$(6) WITH sub_$ IN p2$  ' r

        sub_$ = ENC$("+CHR$(34)+")
        REPLACE CHR$(7) WITH sub_$ IN p2$  ' q

        sub_$ = ENC$("+CHR$(92)+")
        REPLACE CHR$(8) WITH sub_$ IN p2$  ' \

        REMOVE  CHR$(c_DblQt, c_DblQt, 43) FROM  p2$
        REMOVE  CHR$(43, c_DblQt, c_DblQt) FROM  p2$
    END IF
    Arg$ = p2$
END SUB ' Sanitize_Code



SUB ProcSingleLineIf(BYREF ifFlag)
    DIM RAW Tmp$, ifp, NdIfs
    STATIC EFlag

    IF ifFlag = 0 THEN EFlag = 0

    REDO:

    IF SplitCnt = c_MaxSplitLines THEN
        CALL Abort("Stack Overflow - Too many statements on one line")
    END IF

    Tmp$ = SplitStk$[SplitCnt] + SPC$

    IF m_iMatchLft(Tmp$, "if ") THEN
        ifp = iMatchNQ(Tmp$, " then ")
        IF ifp THEN

            IF SplitCnt = c_MaxSplitLines-1 THEN
                CALL Abort("Stack Overflow - Too many statements on one line")
            END IF

            SplitStk$[SplitCnt++] = LEFT$(Tmp$, ifp+4)
            SplitStk$[SplitCnt] = LTRIM$(Tmp+ifp+4)
            EFlag = IMAX(0, EFlag-1)
            INCR (ifFlag)
            GOTO REDO
        END IF

    ELSE
        IF (ifFlag) THEN
            IF m_iMatchLft(Tmp$, "else ") THEN   ' "else xxx"

                LftLse:

                IF ++EFlag > 1 THEN
                    NdIfs = IMAX(1, (ifFlag)-1) : (ifFlag) = 1 : EFlag = 0
                    IF m_iMatchWrd(SplitStk$[SplitCnt-1], "else") THEN DECR SplitCnt

                    IF SplitCnt = c_MaxSplitLines-1 THEN
                        CALL Abort("Stack Overflow - Too many statements on one line")
                    END IF

                    REPEAT NdIfs
                        SplitStk$[SplitCnt++] = "END IF"
                    END REPEAT
                END IF

                IF SplitCnt = c_MaxSplitLines-1 THEN
                    CALL Abort("Stack Overflow - Too many statements on one line")
                END IF

                SplitStk$[SplitCnt++] = "ELSE"
                SplitStk$[SplitCnt] = TRIM$(Tmp+4)
                GOTO REDO
            ELSE
                ifp = iMatchNQ(Tmp$, " else ")
                IF ifp THEN                      ' "xxx else xxx"

                    IF SplitCnt = c_MaxSplitLines-1 THEN
                        CALL Abort("Stack Overflow - Too many statements on one line")
                    END IF

                    SplitStk$[SplitCnt++] = RTRIM$(LEFT$(Tmp$, ifp-1))
                    Tmp$ = MID$(Tmp$, ifp+1)
                    GOTO LftLse
                END IF
            END IF
        END IF
    END IF         ' process "if/then/else"
END SUB ' ProcSingleLineIf



FUNCTION SplitLines(Arg$)
    DIM p  = Arg AS PCHAR
    DIM st = Arg AS PCHAR
    DIM i, IfFlag, SpcolonFlag, ParaCnt

    IF *p = ASC("!") OR *p = ASC("$") THEN EXIT FUNCTION

    DO WHILE *p
        IF *p = 32 THEN SpcolonFlag = 1
        IF *p = c_DblQt THEN    ' ignore anything in string literal
            DO WHILE *(++p) <> c_DblQt
                IF *p = 0 THEN FUNCTION = SplitCnt
            LOOP
        END IF

        IF *p = c_LPar THEN INCR ParaCnt
        IF *p = c_RPar THEN DECR ParaCnt

        IF *p = ASC(":") THEN
            IF *(p+1) = ASC(":") THEN
                *p = 15
                *(p+1) = 15
            ELSE
                IF NOTNULL((p+1)) OR ISTRUE(SpcolonFlag) THEN

                    DO WHILE *st = 32
                        INCR st
                    LOOP         ' Forward past leading spaces

                    INCR SplitCnt

                    IF SplitCnt = c_MaxSplitLines THEN
                        CALL Abort("Stack Overflow - Too many statements on one line")
                    END IF

                    DO WHILE st < p                         ' Copy new string
                        SplitStk[SplitCnt][i++] = *(st++)
                    LOOP

                    SplitStk$[SplitCnt] = TRIM$(SplitStk$[SplitCnt])

                    SplitStk[SplitCnt][i] = 0               ' Add a string terminator
                    IF ParaCnt = 0 THEN
                        i = 0
                        INCR st                             ' advance to next start position
                        ProcSingleLineIf(ADDRESSOF(IfFlag))
                    ELSE
                        DECR SplitCnt
                    END IF
                END IF                                      ' if NOT End of line
            END IF
        END IF                                              ' if :
        INCR p
    LOOP

    ' Add the last string
    IF SplitCnt > 0 THEN
        DO WHILE *st = 32
            INCR st
        LOOP  ' Forward past leading spaces
        INCR SplitCnt

        IF SplitCnt = c_MaxSplitLines THEN
            CALL Abort("Stack Overflow - Too many statements on one line")
        END IF

        DO WHILE *st
            SplitStk[SplitCnt][i++] = *(st++)
        LOOP
        SplitStk[SplitCnt][i] = 0
        ProcSingleLineIf(ADDRESSOF(IfFlag))
        ' Process single line if/thens that don't contain colon separated statements
    ELSE
        IF m_iMatchLft(Arg$, "if ") AND NOT m_iMatchRgt(Arg$, " then") THEN
            CALL Add2SplitLines(Arg$)
            ProcSingleLineIf(ADDRESSOF(IfFlag))
        END IF
    END IF

    ' If we processed single line "if/then" then close it up
    IF IfFlag THEN
        DO WHILE IfFlag
            CALL Add2SplitLines("END IF")
            DECR IfFlag
        LOOP
    END IF

    FUNCTION = SplitCnt
END FUNCTION ' SplitLines



FUNCTION SpecialCaseHandler(Param$)
    DIM RAW i, j, k, iSrcStkIndex
    DIM RAW lsz$
    '******************************************************************************
    ' The following 783 transform helps overcome a parsing issue involving spaces
    ' in and around dimensional brackets, as in the following exaggerated example:
    '
    '                  DIM AS INT TheArray [  1  +  1  ,  1  +  4  ]
    '
    ' which enters this function in Param$ as:       TheArray [  1+1  ][  1+4  ]
    ' The ver. 783 transform corrects this to the following:
    '                                                TheArray [1+1][1+4]
    '******************************************************************************
    DIM RAW Arg$
    Arg$ = Param$

    IF INCHR(Param$, "[") OR INCHR(Param$, "]") THEN
        REPEAT 2
            REPLACE "[ " WITH "[" IN Arg$
            REPLACE " [" WITH "[" IN Arg$
            REPLACE "] " WITH "]" IN Arg$
            REPLACE " ]" WITH "]" IN Arg$
        END REPEAT
    END IF
    '******************************************************************************

    IF iMatchNQ(Arg$, " sub ") OR iMatchNQ(Arg$, " function ") THEN FUNCTION = FALSE

    '******************************************************************************
    ' Handle Multiple Dim's, Locals, Globals, Shared etc.
    ' Example: DIM a, b!, c$, d$*1000, q[100] AS ULONG
    ' Forward propagation of a type
    ' DIM AS INT a, b[10], c, d[20]
    '******************************************************************************
    lsz$ =  SPC$ + EXTRACT$(Arg$, SPC$) + SPC$

    IF iMatchNQ(" dim , local , global , raw , static , shared , dynamic , auto , register , extern ", lsz$) THEN
        CALL FastLexer(Arg$, SPC$, ",&(){}=")
        IF m_iMatchWrd("as", Stk$[3]) THEN
            lsz$ =  SPC$ + LCASE$(Stk$[2]) + SPC$
            IF iMatchNQ(" local , raw , static , shared , dynamic , auto , register ", lsz$) THEN
                Stk$[1] = Stk$[2]
                LShiftStk(2)
            END IF
        END IF

        '******************************************************************************
        ' Begin forward propagation of a type
        '******************************************************************************

        IF m_iMatchWrd("as", Stk$[2]) THEN
            DIM RAW szWrk$
            DIM RAW FirstComma, Ignore, b, EqualAt
            DIM RAW Tmp$[8]
            DIM iFUNC
            CALL BuildDelimStr(1, Ndx, szWrk$)
            CALL FastLexer(szWrk$, SPC$, ",&(){}=")

            XFOR i = 3, Ignore = 0, FirstComma = 0, EqualAt = 0 WHILE i <= Ndx AND FirstComma = 0 BY i++
                IF *Stk$[i] = ASC("=") AND Ignore = 0 THEN EqualAt = i
                IF *Stk$[i] = ASC("{") THEN INCR Ignore
                IF *Stk$[i] = ASC("(") THEN INCR Ignore : IF iFUNC = 0 THEN iFUNC = i
                IF *Stk$[i] = ASC(")") THEN DECR Ignore
                IF *Stk$[i] = ASC("}") THEN DECR Ignore
                IF *Stk$[i] = ASC(",") AND  Ignore = 0 THEN FirstComma = i
            XNEXT

            IF FirstComma = 0 THEN FirstComma = Ndx+1
            IF iFUNC THEN i = iFUNC
            IF i > EqualAt AND EqualAt THEN i = EqualAt
            b = 0
            DO
                DECR i
                IF *Stk$[i] = ASC("}") THEN INCR b
                IF *Stk$[i] = ASC(")") THEN INCR b
                IF *Stk$[i] = ASC("(") THEN DECR b
                IF *Stk$[i] = ASC("{") THEN DECR b
            LOOP WHILE b

            IF *Stk$[i] = ASC("=") THEN DECR i
            IF *Stk$[i] = ASC("(") THEN DECR i
            IF *Stk$[i] = ASC("{") THEN DECR i
            IF *Stk$[i] = ASC(",") THEN DECR i

            DIM RAW iVecCheck
            XFOR j = 0, k = 2, iVecCheck = 0 WHILE k < i BY j++, k++
                IF INCHR(Stk$[k], CHR$(15)) THEN iVecCheck = 1
                IF iVecCheck THEN REPLACE "<" WITH CHR$(16) IN Stk$[k]
                IF iVecCheck THEN REPLACE "," WITH CHR$(18) IN Stk$[k]
                IF iVecCheck THEN REPLACE ">" WITH CHR$(17) IN Stk$[k]
                Tmp$[j] = Stk$[k]
                Stk$[k] = ""
            XNEXT

            k = Ndx
            Tmp$[0] = SPC$ + Tmp$[0]

            InsertTokens(Ndx, j, Tmp$[0], Tmp$[1], Tmp$[2], Tmp$[3], Tmp$[4], Tmp$[5], Tmp$[6], Tmp$[7])
            Ignore = 0

            DO WHILE k >= FirstComma
                IF *Stk$[k] = ASC("}") THEN INCR Ignore
                IF *Stk$[k] = ASC(")") THEN INCR Ignore
                IF *Stk$[k] = ASC("(") THEN DECR Ignore
                IF *Stk$[k] = ASC("{") THEN DECR Ignore
                IF *Stk$[k] = ASC(",") AND NOT Ignore THEN
                    InsertTokens(k-1, j, Tmp$[0], Tmp$[1], Tmp$[2], Tmp$[3], Tmp$[4], Tmp$[5], Tmp$[6], Tmp$[7])
                END IF
                DECR k
            LOOP

            CALL RemEmptyTokens
            CALL BuildDelimStr(1, Ndx, Arg$)

            IF InFunction = FALSE AND UseCpp = FALSE THEN
                IF LEFTSTR(Arg$, "RAW ", 1) THEN Arg$ = "STATIC " + MID$(Arg$, 4)
            END IF

            CALL FastLexer(Arg$, SPC$, ",(){}=")
        ELSE
            XFOR i = 1, INT t = 1, INT iVecCheck = 0 WHILE i < Ndx AND t BY i++
                t = m_GetAsPosF(i, Ndx)
                IF t THEN
                    INCR t
                    XFOR iVecCheck = 0 WHILE t <= Ndx BY t++
                        IF *Stk$[t] = ASC(",") AND iVecCheck = 0 THEN EXIT XFOR
                        IF INCHR(Stk$[t], CHR$(15)) THEN iVecCheck = 1
                        IF iVecCheck THEN REPLACE "<" WITH CHR$(16) IN Stk$[t]
                        IF iVecCheck THEN REPLACE "," WITH CHR$(18) IN Stk$[t]
                        IF iVecCheck THEN REPLACE ">" WITH CHR$(17) IN Stk$[t]
                    XNEXT
                END IF
            XNEXT
        END IF                   ' End forward propagation of a type

        '******************************************************************************

        ' tolerate nonsense like >> DIM A% as DOUBLE << by removing the sigil

        XFOR i = 1, INT t = 1 WHILE i < Ndx AND t BY i++
            t = m_GetAsPosF(i, Ndx)
            IF t THEN
                i = t
                Stk$[i-1] = No_Sigil$(Stk$[i-1])
            END IF
        XNEXT

        Stk$[2] = SPC$ + Stk$[2] + SPC$
        IF iMatchNQ (" raw , local , dynamic , register , static , shared , auto ", Stk$[2]) THEN
            Stk$[1] = Stk$[1] + Stk$[2]
            Stk$[2] = ""
        END IF
        INCR SrcCnt
        j = 0
        FOR i = 1 TO Ndx
            IF *Stk$[i] = ASC("(") THEN INCR j
            IF *Stk$[i] = ASC("{") THEN INCR j
            IF *Stk$[i] = ASC(")") THEN DECR j
            IF *Stk$[i] = ASC("}") THEN DECR j
            IF *Stk$[i] = ASC(",") AND NOT j THEN
                Stk$[i]  = Stk$[1]
                INCR SrcCnt
            END IF

            IF SrcCnt = c_MaxSingleLineIFLines THEN
                CALL Abort("Single line conversion to multi-line exceeds limit.")
            END IF

            SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + SPC$
        NEXT
        GOTO ProcessNew
    END IF
    IF InDialogEvt OR ModDialogEvt THEN
        IF iMatchNQ(Arg$, "WM_INITDIALOG") THEN
            CALL AddExpressionToStack(Arg$)
            CALL AddExpressionToStack("SetDialogScale(hWnd,0)")
            GOTO ProcessNew
        END IF
    END IF

    SELECT CASE TRUE

        '******************************
        CASE m_iMatchLft(Arg$, "on ")     ' on expression gosub | goto | call  label1,label2,Sub...
            '******************************
            DIM Target = 0
            j = 0
            CALL FastLexer(Arg$, SPC$, ",")

            FOR i = 1 TO Ndx
                IF m_iMatchLft(Stk$[i], "gosub") OR _
                    m_iMatchLft(Stk$[i], "goto") OR _
                    m_iMatchLft(Stk$[i], "call") THEN
                    Target = i+1
                    EXIT FOR
                END IF
            NEXT

            IF Target = 0 THEN
                CALL Abort("Malformed ON/GOSUB,GOTO,CALL.")
            END IF

            CALL AddExpressionToStack("select case ")        ' Assemble our expression
            FOR i = 2 TO Target - 2
                SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + SPC$ + Stk$[i]
            NEXT

            FOR i = Target TO Ndx
                IF *Stk$[i] = ASC(",") THEN ITERATE
                INCR j
                CALL AddExpressionToStack("case" + STR$(j))
                CALL AddExpressionToStack(Stk$[Target-1] + SPC$ + Stk$[i])
            NEXT
            CALL AddExpressionToStack("end select")

            GOTO ProcessNew

            '******************************
        CASE m_iMatchLft(Arg$, "loop ")
            '******************************
            CALL FastLexer(Arg$, SPC$, ",()")

            IF m_iMatchLft(Stk$[2], "until") THEN
                CALL AddExpressionToStack("if ")
                FOR i = 3 TO Ndx
                    SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + SPC$
                NEXT
                SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + " then"
                CALL AddExpressionToStack("exit do")
                CALL AddExpressionToStack("end if")
                CALL AddExpressionToStack("loop")
                iLoopCond = 1
                GOTO ProcessNew

            ELSEIF m_iMatchLft(Stk$[2], "while") THEN
                CALL AddExpressionToStack("if NOT (")
                FOR i = 3 TO Ndx
                    SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + SPC$
                NEXT
                SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + ") then"
                CALL AddExpressionToStack("exit do")
                CALL AddExpressionToStack("end if")
                CALL AddExpressionToStack("loop")
                iLoopCond = 1
                GOTO ProcessNew
            ELSE
                IF Ndx > 1 THEN
                    Abort("UNKNOWN Word " + Stk$[2] + " After LOOP")
                END IF
            END IF

            '******************************
        CASE m_iMatchLft(Arg$, "do ")
            '******************************
            CALL FastLexer(Arg$, SPC$, ",()")

            IF m_iMatchLft(Stk$[2], "until") THEN
                CALL AddExpressionToStack("do")
                CALL AddExpressionToStack("if ")
                FOR i = 3 TO Ndx
                    SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + SPC$
                NEXT
                SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + "then"
                CALL AddExpressionToStack("exit do")
                CALL AddExpressionToStack("end if")
                iDoWhile = lt_DOUNTILLOOP
                GOTO ProcessNew
            ELSEIF m_iMatchLft(Stk$[2], "while") THEN
                CALL AddExpressionToStack("while ")
                iDoWhile = lt_DOWHILELOOP
                FOR i = 3 TO Ndx
                    SrcStk$[SrcCnt] = SrcStk$[SrcCnt] + Stk$[i] + SPC$
                NEXT
                GOTO ProcessNew
            ELSE
                IF Ndx > 1 THEN
                    Abort("UNKNOWN Word " + Stk$[2] + " After DO")
                END IF
            END IF
    END SELECT

    FUNCTION = FALSE

    ProcessNew:

    Ndx = iSrcStkIndex = 0
    DO WHILE SrcCnt
        Arg$ = SrcStk$[++iSrcStkIndex]
        SrcStk$[iSrcStkIndex] = ""
        DECR SrcCnt
        PassOne = TRUE
        CALL PreParse(Arg$)
        PassOne = FALSE
        CALL FixUps
        IF Ndx THEN CALL Function_Main_Support
    LOOP
    FUNCTION = TRUE
END FUNCTION ' SpecialCaseHandler





SUB FastLexer _
    (Arg$ AS PCTSTR, _
    delim1$ AS PCTSTR, _
    delim2$ AS PCTSTR, _
    TokQuote = 1)
    '**********************************************************************************
    ' delim1$ = delimiters to remove
    ' delim2$ = delimiters to keep
    '
    ' When TokQuote = 1: Quoted strings are treated as individual tokens.
    ' Each quoted string is processed separately, terminated, and stored
    ' in the token stack as a distinct token.
    '
    ' When TokQuote = 0: Quoted strings are not treated as separate tokens.
    ' They are included as part of larger tokens, potentially concatenated
    ' with other characters outside the quotes.
    '
    ' Stk$[] and Ndx are GLOBAL
    ' As long as Ndx is honored, Stk$[] does not need to be initialized
    '**********************************************************************************
    DIM RAW pd1 AS PCHAR
    DIM RAW pd2 AS PCHAR
    DIM RAW cnt1, cnt2
    cnt1 = cnt2 = 0
    Ndx  = 1

    DO WHILE Arg[cnt1]

        IF Arg[cnt1] = c_DblQt THEN    ' quotes - string literals

            IF cnt2 AND TokQuote THEN
                Stk[Ndx++][cnt2] = 0
                cnt2 = 0
            END IF

            Stk[Ndx][cnt2] = c_DblQt

            DO WHILE Arg[++cnt1] <> c_DblQt
                Stk[Ndx][++cnt2] = Arg[cnt1]
                IF Arg[cnt1] = 0 THEN EXIT SUB
            LOOP

            Stk[Ndx][++cnt2] = Arg[cnt1]

            IF TokQuote THEN
                Stk[Ndx++][++cnt2] = 0
                cnt2 = 0
                GOTO again
            END IF

        END IF

        pd1 = CAST(PCHAR, delim1)

        DO WHILE *pd1
            IF *(pd1++) = Arg[cnt1] THEN
                IF cnt2 THEN
                    Stk[Ndx++][cnt2] = 0
                    cnt2 = 0
                END IF
                GOTO again
            END IF
        LOOP

        pd2 = CAST(PCHAR, delim2)

        DO WHILE *pd2
            IF *(pd2++) = Arg[cnt1] THEN
                IF cnt2 THEN Stk[Ndx++][cnt2] = 0
                Stk[Ndx][0] = Arg[cnt1]
                Stk[Ndx++][1] = 0
                cnt2 = 0
                GOTO again
            END IF
        LOOP

        Stk[Ndx][cnt2++] = Arg[cnt1]

        again:

        INCR cnt1
    LOOP
    Stk[Ndx][cnt2] = 0
    IF cnt2 = 0 THEN DECR Ndx
END SUB ' FastLexer


SUB InsertTokens(PosAfter, NumTokens, ...)
    DIM RAW ap AS va_list, i
    FOR i = Ndx TO PosAfter + 1 STEP -1
        Stk$[i + NumTokens] = Stk$[i]
    NEXT

    va_start(ap, NumTokens)
    FOR i = PosAfter + 1 TO PosAfter+NumTokens
        Stk$[i] = va_arg(ap, CHAR*)
    NEXT
    va_end(ap)
    INCR Ndx, NumTokens
    Stk$[Ndx + 1] = ""
END SUB ' InsertTokens



SUB AppendTokens(NumTokens, ...)
    DIM RAW ap AS va_list
    va_start(ap, NumTokens)
    FOR i AS INT = Ndx + 1 TO Ndx + NumTokens
        Stk$[i] = va_arg(ap, CHAR*)
    NEXT
    va_end(ap)
    INCR Ndx, NumTokens
    Stk$[Ndx + 1] = ""
END SUB ' AppendTokens



SUB Emit_ExportDef(fs$)
    STATIC BeenHere
    STATIC fname$, Private_FunctionName$

    DIM i
    DIM sz
    DIM st = 1

    fname$ = EXTRACT$(FileIn$, ".") + ".def"

    IF NOT BeenHere THEN
        OPEN fname$ FOR OUTPUT AS FPDEF
        _splitpath(FileIn$, NULL, NULL, fname$, NULL)
        FPRINT FPDEF, "LIBRARY ", ENC$(fname$)
        FPRINT FPDEF, "EXPORTS"
        BeenHere = TRUE
    END IF

    FastLexer(fs$, "", "(,)")

    DO WHILE *Stk$[st] <> ASC("(")
        INCR st
    LOOP

    FOR i = st+1 TO Ndx
        IF *Stk$[i] = ASC(")") THEN EXIT FOR
        IF *Stk$[i] <> ASC(",") THEN
            IF INCHR(Stk$[i], "*") THEN
                INCR sz, 4
                ITERATE
            END IF

            IF iMatchNQ(Stk$[i], "longlong") OR _
                iMatchNQ(Stk$[i], "double")   OR _
                iMatchNQ(Stk$[i], "long long") THEN
                INCR sz, 8
                ITERATE
            END IF
            IF NOT INCHR(Stk$[i], "void") THEN INCR sz, 4
        END IF
    NEXT
    Stk$[1] = TRIM$(Stk$[1])
    Private_FunctionName$ = MID$(Stk$[1], INSTRREV(Stk$[1], SPC$) + 1)
    FPRINT FPDEF, Private_FunctionName$, " = _", Private_FunctionName$, "@", STR$(sz, 1)
END SUB ' Emit_ExportDef




FUNCTION GetArg$(ArgNum, funcPtr AS UDT_ARG_COMMAS_STORAGE PTR)
    '*********************************************************************************************
    ' This function retrieves the argument at the specified index from a UDT_ARG_COMMAS_STORAGE structure.
    ' Parameters:
    '   - ArgNum: The index of the argument to retrieve.
    '   - funcPtr: Pointer to a UDT_ARG_COMMAS_STORAGE structure containing information about the function.
    ' Returns:
    '   - The argument retrieved from the UDT_ARG_COMMAS_STORAGE structure.
    '*********************************************************************************************
    DIM RetArg$  = ""
    DIM ArgEnd   = funcPtr->CommaPos[ArgNum] - 1
    DIM ArgStart = funcPtr->CommaPos[ArgNum - 1] + 1

    IF ArgNum >= funcPtr->NumArgs THEN ArgEnd = Ndx

    FOR i AS INT = ArgStart TO ArgEnd
        RetArg$ += Stk$[i]
    NEXT

    FUNCTION = RetArg$
END FUNCTION ' GetArg



FUNCTION SepFuncArgs(Strt, funcPtr AS UDT_ARG_COMMAS_STORAGE PTR, functionflag AS INT)
    '***************************************************************************************
    ' This function parses the function arguments from a given starting position (Strt)
    ' in the Stk$ array.  It identifies and counts the number of arguments, considering
    ' nested parentheses and brackets. The function updates the UDT_ARG_COMMAS_STORAGE structure (funcPtr)
    ' with the positions of the arguments commas and returns the number of arguments.
    '***************************************************************************************
    DIM CountR = 0   ' () [] counter
    DIM i = Strt     ' loop counter

    IF functionflag THEN
        DO WHILE i <= Ndx
            IF *Stk$[i] = ASC("(") THEN EXIT DO
            INCR i
        LOOP
        Strt = i + 1

        funcPtr->NumArgs = 0 ' comma counter
        funcPtr->CommaPos[0] = i ' Strt-1
        IF Strt > Ndx THEN
            FUNCTION = 0
        END IF
    ELSE
        Strt = 2
        funcPtr->CommaPos[0] = 1
    END IF

    IF *Stk$[Strt] = ASC(")") THEN
        funcPtr->CommaPos[1] = Strt
        FUNCTION = 0
    END IF
    funcPtr->NumArgs = 1

    FOR i = Strt TO Ndx
        IF *Stk$[i] = ASC("(") OR *Stk$[i] = ASC("[") THEN
            INCR CountR
        ELSEIF *Stk$[i] = ASC(")") OR *Stk$[i] = ASC("]") THEN
            IF CountR = 0 THEN
                funcPtr->CommaPos[funcPtr->NumArgs] = i
                EXIT FOR
            END IF
            DECR CountR
        ELSEIF *Stk$[i] = ASC(",") AND CountR = 0 THEN
            funcPtr->CommaPos[funcPtr->NumArgs] = i
            INCR funcPtr->NumArgs

            IF funcPtr->NumArgs = c_CommaPos THEN
                CALL Abort("Number of arguments exceeds 127")
            END IF

        END IF
    NEXT
    IF functionflag = 0 THEN funcPtr->CommaPos[funcPtr->NumArgs] = Ndx

    FUNCTION = funcPtr->NumArgs ' Number of commas + 1 = Number of arguments
END FUNCTION ' SepFuncArgs



FUNCTION MakeDecProto                        _
    (funcPtr AS UDT_ARG_COMMAS_STORAGE PTR,  _
    iStart = 2 AS INT,                       _
    iEnd = Ndx AS INT,                       _
    iNoTypeDef = FALSE AS INT) AS PSTR

    '*************************************************************************
    '                    This is a recursive function
    '*************************************************************************
    ' This function generates a C-style FUNCTION DECLARATION PROTOTYPE string
    ' based on the parsed function information.  It constructs the prototype
    ' string by determining the return type, calling convention, and argument
    ' types, including handling pointers and default values.  The function
    ' supports C++ method declarations, typedefs, and function pointers,
    ' updating a static string to hold the resulting prototype.
    '*************************************************************************
    LOCAL OptFlag
    LOCAL pointer

    STATIC Proto$      ' Must remain static
    STATIC SubFunPtr   ' Must remain static
    STATIC FunType$    ' Must remain static

    DIM RAW i, ii
    DIM RAW AsType$
    DIM RAW OptValue$
    DIM RAW AsArrys$
    DIM RAW FoundAs
    DIM RAW fpp AS UDT_ARG_COMMAS_STORAGE
    CLEAR(fpp)

    IF SubFunPtr THEN GOTO argparse

    Proto$   = ""
    FunType$ = ""
    ' ------------------------
    ' Determine function type
    ' ------------------------
    ' constructor/destructor
    IF Ctor_Dtor_Detected(1) THEN
        FunType$ = ""
    ELSE
        IF m_iMatchWrd(Stk$[iStart], "sub") THEN
            FunType$ = "void"
        ELSEIF *Stk$[iEnd] = ASC(")") THEN
            ' check for type identifier suffix   ( aka, sigil )
            ' if unknown, then integer will default
            FunType$ = VarTypeLookup$[ INCHR(c_VARTYPES$, RIGHT$(Stk$[iStart+1], 1)) ]
        ELSE
            FOR i = iEnd TO funcPtr->CommaPos[funcPtr->NumArgs]+1 STEP -1
                IF m_iMatchWrd(Stk$[i], "ptr") OR *Stk$[i] = ASC("*") THEN
                    INCR pointer
                ELSEIF m_iMatchWrd(Stk$[i], "as") THEN
                    EXIT FOR
                ELSE
                    IF Stk$[i] <> "" THEN FunType$ = Stk$[i] + SPC$ + FunType$
                END IF
            NEXT
            FunType$ = TRIM$(FunType$)
        END IF
    END IF

    IF ISNULL(FunType$) THEN
        Proto$ = Stk$[iStart] + "("
    ELSE
        IF InTypeDef THEN
            DIM RAW L_Var$
            DIM RAW w
            DIM RAW id
            DIM RAW vt

            Proto$ = FunType$ + SPACE$(2) + STRING$(pointer, ASC("*")) + " ("
            Proto$ = Proto$ + CallType$ + "*" + No_Sigil$(Stk$[iStart+1]) + ")("

            L_Var$ = FunType$ + STRING$(pointer, ASC("*"))
            GetTypeInfo(L_Var$, ADDRESSOF(w), ADDRESSOF(id), ADDRESSOF(vt))
            AddTypedefElement(BaseTypeDefsCnt[InTypeDef], vt, No_Sigil$(Stk$[iStart+1]), FunType$)
        ELSEIF g_SubFuncPtr THEN
            IF iNoTypeDef THEN
                Proto$ = FunType$ + " (" + CallType$ + "*" + No_Sigil$(Stk$[iStart+1]) + ")("
            ELSE
                Proto$ = "typedef " + FunType$ + " (" + CallType$
                Proto$ += "*" + No_Sigil$(Stk$[iStart+1]) + "_TYPE)("
            END IF
        ELSEIF NOT NoTypeDeclare AND NOT InClass AND NOT InCppTypeDef THEN
            Proto$ = "typedef " + FunType$ + " (" + CallType$
            Proto$ += "*BCXFPROT" + STR$(DllCnt, 1) + ")("
        ELSE
            IF UseCProto OR InClass OR InCppTypeDef THEN
                UseCProto = FALSE
                Proto$ = FunType$ + SPC$ + STRING$(pointer, ASC("*")) + SPC$
                Proto$ += CallType$ + No_Sigil$(Stk$[iStart+1]) + "("
            ELSE
                Proto$ = "C_IMPORT " + FunType$ + SPACE$(2) + STRING$(pointer, ASC("*"))
                Proto$ += SPC$ + CallType$ + No_Sigil$(Stk$[iStart+1]) + "("
                UseImportExport = TRUE
            END IF
        END IF
    END IF

    ' -----------------------------------------------------
    argparse:
    ' -----------------------------------------------------
    ' Determine argument types
    ' -----------------------------------------------------
    IF funcPtr->NumArgs = 0 THEN
        IF FunType$ <> ""  THEN
            Proto$ += "void)"
        ELSE
            Proto$ += ")"
        END IF

    ELSE

        FOR ii = 0 TO funcPtr->NumArgs - 1

            OptValue$ = ""
            AsType$   = ""
            AsArrys$  = ""
            pointer   = 0
            FoundAs   = 0

            DIM FirstToken  = funcPtr->CommaPos[ii] + 1
            DIM LastToken   = funcPtr->CommaPos[ii+1] - 1
            DIM NumOfTokens = (LastToken - FirstToken) + 1

            i = INCHR(Stk$[FirstToken], "[")
            IF i THEN
                AsArrys$ = MID$(Stk$[FirstToken], i)
                Stk[FirstToken][i-1] = 0
            END IF

            IF NumOfTokens = 1 THEN
                ' --------------------------------------------------------
                ' The bracket handling should be handled better.
                ' currently using the preprocessing of FunSubDecs1
                ' which converts A![] to *A! and A$[] to *A$[][2048]
                ' and A[] as xxx to A as xxx*
                ' --------------------------------------------------------
                AsType$ = VarTypeLookup$[ INCHR(c_VARTYPES$, RIGHT$(Stk$[FirstToken], 1)) ]
                IF *AsArrys$ THEN
                    REMOVE "*" FROM AsType$
                ELSE
                    pointer = TALLY(Stk$[FirstToken], "*")
                END IF
                ' --------------------------------------------------------
                FoundAs = TRUE
            ELSE

                FOR i = LastToken TO FirstToken STEP -1
                    IF m_iMatchWrd(Stk$[i], "ptr") OR *Stk$[i] = ASC("*") THEN
                        INCR pointer

                    ELSEIF m_iMatchWrd(Stk$[i], "sub") THEN
                        SepFuncArgs(funcPtr->CommaPos[ii]+2, ADDRESSOF(fpp), TRUE)
                        Proto$ += "void (*)("
                        SubFunPtr = FoundAs = TRUE
                        MakeDecProto(ADDRESSOF(fpp))
                        SubFunPtr = FALSE
                        EXIT FOR

                    ELSEIF m_iMatchWrd(Stk$[i], "function") THEN
                        SepFuncArgs(funcPtr->CommaPos[ii]+2, ADDRESSOF(fpp), TRUE)
                        IF ISNULL(AsType$) THEN
                            AsType$ = VarTypeLookup$[ INCHR(c_VARTYPES$, RIGHT$(Stk$[FirstToken], 1)) ]
                        END IF
                        Proto$ += RTRIM$(AsType$) + STRING$(pointer, ASC("*")) + " (*)("
                        pointer = 0
                        AsType$ = ""
                        SubFunPtr = FoundAs = TRUE
                        MakeDecProto(ADDRESSOF(fpp))
                        SubFunPtr = FALSE
                        EXIT FOR

                    ELSEIF m_iMatchWrd(Stk$[i], "as") THEN

                        IF ISNULL(AsType$) THEN
                            CALL Abort("No type specified for argument" + STR$(ii+1))
                        END IF

                        FoundAs = TRUE
                        EXIT FOR

                    ELSEIF *Stk$[i] = ASC("=") THEN
                        OptFlag = FoundAs = TRUE
                        OptValue$ = " =" + AsType$
                        AsType$ = ""
                        IF i = FirstToken + 1 THEN
                            AsType$ = VarTypeLookup$[ INCHR(c_VARTYPES$, RIGHT$(Stk$[FirstToken], 1)) ]
                            IF *AsArrys$ THEN
                                REMOVE "*" FROM AsType$
                            ELSE
                                pointer = TALLY(Stk$[FirstToken], "*")
                            END IF
                            EXIT FOR
                        END IF
                    ELSE
                        IF *Stk$[i] <> ASC(".") THEN
                            AsType$ = Stk$[i] + SPC$ + AsType$
                        ELSE
                            IF *Stk$[i-1] = ASC(".") THEN

                                IF OptFlag THEN
                                    CALL Abort("Default value not allowed when using variable arguments")
                                END IF

                                IF ii <> (funcPtr->NumArgs-1) THEN
                                    CALL Abort("Variable argument must be the last parameter")
                                END IF

                                IF funcPtr->NumArgs = 1 THEN
                                    CALL Abort("Variable argument must be preceded by at least one other parameter")
                                END IF

                                FoundAs = TRUE
                            END IF
                            AsType$ = Stk$[i] + AsType$
                        END IF
                    END IF
                NEXT i
            END IF

            IF NOT FoundAs THEN
                CALL Abort("Malformed argument type in parameter" + STR$(ii + 1))
            END IF

            IF ii <> funcPtr->NumArgs AND OptFlag AND ISNULL(OptValue$) THEN
                CALL Warning("No default value specified for parameter" + STR$(ii + 1), 1)
            END IF

            Proto$ += RTRIM$(AsType$) + AsArrys$ + STRING$(pointer, ASC("*")) + OptValue$ + Stk$[funcPtr->CommaPos[ii+1]]
        NEXT ii
        ' -----------------------------------------------------
    END IF

    FUNCTION = Proto
END SUB ' MakeDecProto



SUB AsmUnknownStructs(CompArrays)
    '*****************************************************************************
    ' This SUB processes and assembles incomplete array and structure declarations
    ' in a tokenized code string. It concatenates array declarations split across
    ' multiple tokens and handles unknown struct member accesses by merging them
    ' into a single token.  The SUB ensures that the processed tokens are cleaned
    ' up and any empty tokens are removed.
    '*****************************************************************************
    DIM InBrace, InStruct, i
    DIM LTmp$

    FOR i = 2 TO Ndx
        ' --------------------------------
        ' Complete arrays
        ' --------------------------------
        IF CompArrays THEN
            IF *Stk$[i] = ASC("[") THEN
                LTmp$ = Stk$[i-1]
                Stk$[i-1] = ""
                DO
                    LTmp$ += Stk$[i]
                    IF *Stk$[i] = ASC("]") THEN DECR InBrace
                    IF *Stk$[i] = ASC("[") THEN INCR InBrace
                    Stk$[i] = ""
                    INCR i
                LOOP WHILE InBrace > 0 AND i <= Ndx
                Stk$[--i] = LTmp$
            END IF
        END IF
        ' --------------------------------
        ' Complete unknown struct members
        ' --------------------------------
        IF LEN(Stk$[i]) > 1 AND NOT IsDecimalNumber(Stk$[i]+1) THEN
            IF *Stk$[i] = ASC(".") OR m_iMatchLft(Stk$[i], "->") THEN
                IF InStruct = 0 THEN
                    Stk$[i] = Stk$[i-1] + Stk$[i]
                    Stk$[i-1] = ""
                    InStruct = i
                ELSE
                    Stk$[InStruct] += Stk$[i]
                    Stk$[i] = ""
                END IF
                ITERATE
            END IF
        END IF

        IF NOTNULL(Stk$[i]) AND InStruct THEN
            InStruct = 0
        END IF
    NEXT

    CALL RemEmptyTokens
END SUB ' AsmUnknownStructs



SUB CheckForASC
    '**************************************************************************
    ' This SUB scans a list of tokens for the "ASC()" function, processes each
    ' occurrence by calling Process_ASC_Function, and removes any empty tokens.
    '**************************************************************************
    DIM Tmp, iEmp
    FOR Tmp = 1 TO Ndx
        IF m_iMatchWrd(Stk$[Tmp], "asc") THEN
            iEmp = 1
            CALL Process_ASC_Function (Tmp)
        END IF
    NEXT
    IF iEmp THEN CALL RemEmptyTokens
END SUB ' CheckForASC


SUB Make_Stricmp_Map
    '******************************************************************
    ' This supports the BCX 757 "??" operator (case-insensitivity)
    ' For each IF statement, BCX will emit one or more strcmp calls.
    ' This sub helps identify which of those needs to be changed to
    ' bcx_stricmp.  It does that by building a map of which strcmp
    ' is affected by the ?? operator.  The map will contain values
    ' 1 (insensitive) or 2 (normal) that are used in: SUB Emit_IfCond
    '*******************************************************************
    GLOBAL MSMap[128]
    DIM RAW MSM_Ndx AS LONG
    DIM RAW i AS LONG
    DIM RAW hasBracket AS LONG

    MSM_Ndx = 0
    FOR i = 0 TO 127
        MSMap[i] = 0
    NEXT

    ' -------------------------------------------------------------------
    ' Pass 1: String variable fixes & bracket detection
    ' -------------------------------------------------------------------
    hasBracket = FALSE
    FOR i = 2 TO Ndx
        IF INSTR(Stk$[i], "[") > 0 THEN hasBracket = TRUE

        IF RIGHTSTR(Stk$[i], "$") = FALSE THEN
            IF Im_Multi_Dim_StrVar(Stk$[i]) THEN
                Stk$[i] += "$"
            END IF
        END IF
    NEXT

    IF hasBracket THEN
        FOR i = 2 TO Ndx
            IF Im_Single_Dim_StrVar(Stk$[i]) THEN
                REMOVE "$" FROM Stk$[i]
            END IF
        NEXT
    END IF

    ' --------------------------------------------------------------------------
    ' Pass 2: Check ambiguity and merge base 2-char tokens (==, ??, <=, >=, !=)
    ' --------------------------------------------------------------------------
    FOR i = 1 TO Ndx
        ' Ambiguity validation
        IF i <= Ndx - 2 THEN
            IF (*Stk$[i] = ASC("?") AND *Stk$[i+1] = ASC("?") AND *Stk$[i+2] = ASC("=")) OR _
                (*Stk$[i] = ASC("=") AND *Stk$[i+1] = ASC("?") AND *Stk$[i+2] = ASC("?")) OR _
                (*Stk$[i] = ASC("?") AND *Stk$[i+1] = ASC("=") AND *Stk$[i+2] = ASC("?")) THEN
                CALL Abort("Combining string operators '?' and '=' is ambiguous")
            END IF
        END IF

        ' Merge base 2-char tokens
        IF *Stk$[i] = ASC("=") AND *Stk$[i+1] = ASC("=") THEN
            Stk$[i] = "=="
            LShiftStk(i + 1)
        ELSEIF *Stk$[i] = ASC("?") AND *Stk$[i+1] = ASC("?") THEN
            Stk$[i] = "??"
            LShiftStk(i + 1)
        ELSEIF (*Stk$[i] = ASC("<") AND *Stk$[i+1] = ASC("=")) OR (*Stk$[i] = ASC("=") AND *Stk$[i+1] = ASC("<")) THEN
            Stk$[i] = "<="
            LShiftStk(i + 1)
        ELSEIF (*Stk$[i] = ASC(">") AND *Stk$[i+1] = ASC("=")) OR (*Stk$[i] = ASC("=") AND *Stk$[i+1] = ASC(">")) THEN
            Stk$[i] = ">="
            LShiftStk(i + 1)
        ELSEIF *Stk$[i] = ASC("!") AND *Stk$[i+1] = ASC("=") THEN
            Stk$[i] = "!="
            LShiftStk(i + 1)
        END IF
    NEXT

    ' -------------------------------------------------------------------
    ' Pass 3: Merge compound ?? operators (!??, >??, <??)
    ' -------------------------------------------------------------------
    FOR i = 1 TO Ndx
        ' 3-token combinations -> !??
        IF i <= Ndx - 2 THEN
            IF (*Stk$[i] = ASC("<") AND Stk$[i+1] = "??" AND *Stk$[i+2] = ASC(">")) OR _
                (*Stk$[i] = ASC("<") AND *Stk$[i+1] = ASC(">") AND Stk$[i+2] = "??") OR _
                (*Stk$[i] = ASC(">") AND Stk$[i+1] = "??" AND *Stk$[i+2] = ASC("<")) THEN
                Stk$[i] = "!??"
                LShiftStk(i + 1)
                LShiftStk(i + 1)
            END IF
        END IF

        ' 2-token compound combinations with ??
        IF (*Stk$[i] = ASC("!") AND Stk$[i+1] = "??") OR (Stk$[i] = "??" AND *Stk$[i+1] = ASC("!")) THEN
            Stk$[i] = "!??"
            LShiftStk(i + 1)
        ELSEIF (Stk$[i] = "??" AND *Stk$[i+1] = ASC(">")) OR (*Stk$[i] = ASC(">") AND Stk$[i+1] = "??") THEN
            Stk$[i] = ">??"
            LShiftStk(i + 1)
        ELSEIF (Stk$[i] = "??" AND *Stk$[i+1] = ASC("<")) OR (*Stk$[i] = ASC("<") AND Stk$[i+1] = "??") THEN
            Stk$[i] = "<??"
            LShiftStk(i + 1)
        END IF
    NEXT

    ' -------------------------------------------------------------------
    ' Pass 4: Build MSMap from finalized stack
    ' -------------------------------------------------------------------
    FOR i = 1 TO Ndx
        SELECT CASE Stk$[i]
            CASE "??"
                Stk$[i] = "="
                MSMap[++MSM_Ndx] = 1

            CASE "<??"
                Stk$[i] = "<"
                MSMap[++MSM_Ndx] = 1

            CASE ">??"
                Stk$[i] = ">"
                MSMap[++MSM_Ndx] = 1

            CASE "!??"
                Stk$[i] = "!="
                MSMap[++MSM_Ndx] = 1

            CASE "=", "<", ">", "<=", ">=", "!=", "!"
                MSMap[++MSM_Ndx] = 2
        END SELECT
    NEXT
END SUB ' Make_Stricmp_Map




SUB Emit_IfCond (CondType$, iOutputMethod)
    '*************************************************************************************
    ' Speedup/Optimize for statements like --->  if a$    = ""  THEN
    '               AND                    --->  if a$[1] = ""  THEN
    '               AND                    --->  while x = ASC("x")
    '*************************************************************************************
    DIM IsWhile
    DIM RAW A, B, TestString, ParCnt, Tmp
    DIM RAW szTest$

    '*************************************************************************************
    ' Detect and append string sigil to UDT string members, if needed   ' 832 MrBcx added
    '*************************************************************************************
    FOR i AS INT = 2 TO Ndx
        IF Im_UDT_String (Stk$[i]) AND INCHR(Stk$[i], "$") = 0 THEN CONCAT (Stk$[i], "$")

        ' 838 MrBcx added to improve sigil-less string detection, cautious of pointer access
        IF Im_A_String_Var (Stk$[i]) AND INCHR(Stk$[i], "$") = 0 AND Stk$[i+1] <> "[" THEN
            CONCAT (Stk$[i], "$")
        END IF
    NEXT

    '*************************************************************************************
    ' The code below allows a char[] array to be treated like a STRVAR in an IF statement.
    '*************************************************************************************
    IF Im_A_String_Var (Stk$[2]) THEN
        DIM ii
        IF *Stk$[3] <> ASC("[") THEN ii = TRUE
        IF ii = TRUE AND INCHR(Stk$[2], "$") = FALSE THEN
            Stk$[2] += "$"
        END IF
    END IF

    '*************************************************************************************
    CALL CheckForASC

    TestString = DataType(Stk$[2])
    IF TestString = vt_STRVAR OR TestString = vt_CHAR OR TestString = vt_SCHAR THEN
        IF Stk$[4] = DDQ$ THEN
            Stk$[2] = No_Sigil$(Stk$[2]) + "[0]"
            Stk$[4] = "0"
        ELSE
            IF Stk$[3] = "[" AND Stk$[7] = DDQ$ THEN
                Stk$[2] = "*" + No_Sigil$(Stk$[2])
                Stk$[7] = "0"
            END IF
        END IF
    END IF

    IF CondType$ = "while" THEN IsWhile = TRUE

    '********************   If Handler, ElseIf Handler, & While Handler   *********************
    '
    '   At this stage, an IF statement has been lexed and is ready to be parsed from Stk$[]
    '******************************************************************************************
    IF_Stmt_Tank$ = ""               ' GLOBAL 1MB string
    CALL  Make_Stricmp_Map
    '******************************************************************************************

    IF iOutputMethod = eFull THEN
        IF_Stmt_Tank$ = Scoot$ + CondType$ + "("
    END IF

    Tmp = 2

    DO WHILE Stk$[Tmp] = "(" OR Stk$[Tmp] = "!"  ' <<-- DO NOT OPTIMIZE THIS LINE WITH POINTERS - MrBcx
        IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
            IF_Stmt_Tank$ += Stk$[Tmp]
        END IF
        INCR Tmp
    LOOP

    TestString = FALSE

    A = DataType(Stk$[Tmp])

    IF A = vt_STRLIT OR A = vt_STRVAR  THEN
        IF Stk$[Tmp + 1] <> ")" AND ISFALSE (m_iMatchWrd(Stk$[Tmp+1], "then")) THEN
            TestString  = TRUE
            IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
                IF_Stmt_Tank$ += "strcmp("
            END IF
        END IF
    END IF

    szTest$ = ""
    ParCnt  = 0

    DO
        IF TestString THEN
            SELECT CASE Stk$[Tmp]

                CASE "="
                    Stk$[Tmp] = ","
                    szTest$   = ")==0"
                    ParCnt    =  0

                CASE "!="
                    Stk$[Tmp] = ","
                    szTest$   = ")!=0"
                    ParCnt    = 0

                CASE ">"
                    IF Stk$[Tmp + 1] = "=" THEN
                        Stk$[Tmp] = ","
                        szTest$   = ")>=0"
                        Stk$[Tmp + 1] = ""
                    ELSE
                        Stk$[Tmp] = ","
                        szTest$   = ")==1"
                    END IF
                    ParCnt = 0

                CASE "<"
                    IF Stk$[Tmp + 1] = "=" THEN
                        Stk$[Tmp] = ","
                        szTest$   = ")<=0"
                        Stk$[Tmp + 1] = ""
                    ELSE
                        Stk$[Tmp] = ","
                        szTest$   = ")==-1"
                    END IF
                    ParCnt = 0

                    '************************************************
                CASE ">="
                    Stk$[Tmp] = ","
                    szTest$   = ")>=0"
                    ParCnt = 0

                CASE "<="
                    Stk$[Tmp] = ","
                    szTest$   = ")<=0"
                    ParCnt = 0
                    '************************************************

                CASE "("
                    INCR ParCnt

                CASE ")"
                    DECR ParCnt
            END SELECT

            IF (ParCnt < 0) AND (Stk$[Tmp] = ")") AND (szTest$ <> "") THEN
                IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
                    IF_Stmt_Tank$ = IF_Stmt_Tank$ +  szTest$ +  Stk$[Tmp]
                END IF
                szTest$ = ""
            ELSE
                IF Stk$[Tmp] = "||" OR Stk$[Tmp] = "&&" THEN
                    Stk$[Tmp] = szTest$ + SPC$ + Stk$[Tmp] + SPC$
                    szTest$ = ""
                    B = 1

                    DO WHILE Stk$[Tmp + B] = "("
                        Stk$[Tmp] += "("
                        Stk$[Tmp + B] = ""
                        INCR B
                    LOOP

                    A = DataType(Stk$[Tmp+B])      ' look ahead
                    IF (A = vt_STRLIT OR A = vt_STRVAR) AND Stk$[Tmp+B+1] <> ")" THEN
                        Stk$[Tmp] += " strcmp("
                    ELSE
                        IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
                            IF_Stmt_Tank$ += No_Sigil$(Stk$[Tmp])
                        END IF
                        TestString = FALSE
                        GOTO NxtToken
                    END IF
                END IF
                IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
                    IF_Stmt_Tank$ += No_Sigil$(Stk$[Tmp])
                END IF
            END IF
        ELSE  ' Not TestString
            IF Stk$[Tmp] = "||" OR Stk$[Tmp] = "&&" THEN
                B = 1
                DO WHILE Stk$[Tmp + B] = "("
                    Stk$[Tmp] += "("
                    Stk$[Tmp + B] = ""
                    INCR B
                LOOP

                A = DataType(Stk$[Tmp+B])                ' look ahead
                IF (A = vt_STRLIT OR A = vt_STRVAR) AND Stk$[Tmp+B+1] <> ")" THEN
                    Stk$[Tmp] += " strcmp("
                    TestString  = TRUE
                    szTest$     = ""
                    ParCnt      = 0
                    IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
                        IF_Stmt_Tank$ += No_Sigil$(Stk$[Tmp])
                    END IF
                    GOTO NxtToken
                END IF
            END IF

            IF Stk$[Tmp] = "!" THEN
                IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
                    IF_Stmt_Tank$ += Stk$[Tmp]
                END IF
            ELSE
                IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
                    IF_Stmt_Tank$ += No_Sigil$(Stk$[Tmp])
                END IF
                IF NOT ispunct(*Stk$[Tmp]) THEN
                    IF Tmp < Ndx AND NOT ispunct(*Stk$[Tmp+1]) THEN
                        IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
                            IF_Stmt_Tank$ += SPC$
                        END IF
                    END IF
                END IF
            END IF
            IF Stk$[Tmp] = "=" THEN
                IF Stk$[Tmp-1] <> "<" AND Stk$[Tmp-1] <> ">" THEN
                    IF Stk$[Tmp+1] <> ">" AND Stk$[Tmp+1] <> "<" THEN
                        IF iOutputMethod = ePart OR iOutputMethod = eFull THEN
                            IF_Stmt_Tank$ += "="
                        END IF
                    END IF
                END IF
            END IF
        END IF

        NxtToken:

        INCR Tmp
        IF NOT IsWhile THEN
            IF m_iMatchWrd(Stk$[Tmp], "then") THEN
                EXIT DO
            ELSEIF Tmp > Ndx THEN
                Abort("If Without THEN")
            END IF
        END IF
    LOOP UNTIL Tmp > Ndx


    SELECT CASE iOutputMethod
        CASE   eFull
            IF_Stmt_Tank$ = IF_Stmt_Tank$ +szTest$ +  ")"

            CALL BumpUp
            IF_Stmt_Tank$ += "{"
            CALL BumpUp

        CASE ePart
            IF_Stmt_Tank$ += szTest$

    END SELECT

    '***************************************************************************************

    FastLexer(IF_Stmt_Tank$, "", " =&()[]{}',+-*/<>?;.|:^")

    FOR ii AS INT = 1 TO Ndx - 1                              ' 838 MrBcx Refactored from previous versions
        IF LEN(Stk$[ii]) = 1 AND LEN(Stk$[ii+1]) = 1 THEN
            SELECT CASE *Stk$[ii]
                CASE ASC("=")
                    IF *Stk$[ii+1] = ASC("=") THEN Stk$[ii] = "==" : LShiftStk(ii+1)
                CASE ASC(">")
                    IF *Stk$[ii+1] = ASC("=") THEN Stk$[ii] = ">=" : LShiftStk(ii+1)
                CASE ASC("<")
                    IF *Stk$[ii+1] = ASC("=") THEN Stk$[ii] = "<=" : LShiftStk(ii+1)
                CASE ASC("!")
                    IF *Stk$[ii+1] = ASC("=") THEN Stk$[ii] = "!=" : LShiftStk(ii+1)
                CASE ASC("&")
                    IF *Stk$[ii+1] = ASC("&") THEN Stk$[ii] = "&&" : LShiftStk(ii+1)
                CASE ASC("|")
                    IF *Stk$[ii+1] = ASC("|") THEN Stk$[ii] = "||" : LShiftStk(ii+1)
            END SELECT
        END IF
    NEXT

    '******************
    LOCAL Map_Idx
    '******************

    FOR ii AS INT = 1  TO Ndx
        IF Stk$[ii] = "strcmp" THEN
            IF MSMap[++Map_Idx] = 1 THEN
                Stk$[ii] = "bcx_stricmp"
                Use_BCX_stricmp = TRUE
            END IF
        END IF
    NEXT

    IF_Stmt_Tank$ = ""

    FOR ii AS INT = 1  TO Ndx
        IF_Stmt_Tank$ += Stk$[ii]
    NEXT

    IF IgnoreStrCase = TRUE THEN
        REPLACE "strcmp" WITH "bcx_stricmp" IN IF_Stmt_Tank$
        Use_BCX_stricmp = TRUE
    END IF

    '********************************************************************************
    '    These replacements improve the code formatting inside the c/c++ file
    '********************************************************************************

    REPLACE " ) {"            WITH  ") {"        IN IF_Stmt_Tank$

    IF iMatchNQ (IF_Stmt_Tank$, "cmp") THEN
        REPLACE "||  strcmp"  WITH  "|| strcmp"  IN IF_Stmt_Tank$
        REPLACE "&&  strcmp"  WITH  "&& strcmp"  IN IF_Stmt_Tank$
        REPLACE "||  stricmp" WITH  "|| stricmp" IN IF_Stmt_Tank$
        REPLACE "&&  stricmp" WITH  "&& stricmp" IN IF_Stmt_Tank$
        REPLACE "( strcmp"    WITH  "(strcmp"    IN IF_Stmt_Tank$
        REPLACE "( stricmp"   WITH  "(stricmp"   IN IF_Stmt_Tank$
    END IF

    IF ISFALSE iMatchNQ (IF_Stmt_Tank$, " || ") THEN
        REPLACE "|| " WITH  " || " IN IF_Stmt_Tank$
    END IF

    IF ISFALSE iMatchNQ (IF_Stmt_Tank$, " && ") THEN
        REPLACE "&& " WITH  " && " IN IF_Stmt_Tank$
    END IF
    '********************************************************************************
    IF iOutputMethod = ePart THEN
        FPRINT FP_WRITE, IF_Stmt_Tank$; ' Suppress CRLF
    ELSE
        FPRINT FP_WRITE, IF_Stmt_Tank$
    END IF

END SUB ' Emit_IfCond




SUB Emit_Global(        _
    FP_OUTPUT AS FILE , _
    A                 , _
    idx               , _
    Storage$          , _
    P$                , _
    VarName$          , _
    VarDim$)
    '*********************
    DIM RAW L_Var$

    SELECT CASE A
        ' handle exceptions
        CASE vt_FILEPTR
            REMOVE "@" FROM VarName$
            FPRINT FP_OUTPUT, Storage$, "FILE   *", P$; VarName$, VarDim$, ";"

        CASE vt_UDT, vt_STRUCT, vt_UNION
            L_Var$ = TypeDefs[GlobalVars[idx].VarDef].VarName$
            L_Var$ = RPAD$(L_Var$, c_PADSIZE)
            FPRINT FP_OUTPUT, ""                              ' 838 MrBcx - formatting improvement
            FPRINT FP_OUTPUT, Storage$, L_Var$, SPC$, P$, VarName$, VarDim$, ";"
            FPRINT FP_OUTPUT, ""                              ' 838 MrBcx - formatting improvement

        CASE vt_PSTR
            FPRINT FP_OUTPUT, Storage$, "PSTR ", P$, VarName$, VarDim$, ";"

        CASE vt_STRVAR
            IF ISNULL(VarDim$) THEN VarDim$ = "[BCXSTRSIZE]"
            IF P$ = "" THEN P$ = SPC$ + SPC$                  ' 838 MrBcx - formatting improvement
            FPRINT FP_OUTPUT, Storage$, "char ", P$, VarName$, VarDim$, ";"

            ' handle normal

        CASE c_vt_VarMin TO c_vt_VarMax
            L_Var$ = GetVarTypeName$(GlobalVars[idx].VarType)
            L_Var$ = RPAD$(L_Var$, c_PADSIZE)

            WHILE LEN(L_Var$) < 6                             ' 838 MrBcx - formatting improvement
                L_Var$ += SPC$
            END WHILE

            FPRINT FP_OUTPUT, Storage$, L_Var$, SPC$, P$, VarName$, VarDim$, ";"

    END SELECT
END SUB ' Emit_Global



SUB InitReservedWordsLookup
    DIM MaxReservedWords AS INT
    DIM sL$
    DIM iC AS INT
    DIM iD AS INT

    MaxReservedWords = m_WordsInTable(BCXWords) ' How many reserved words

    FOR iC = 0 TO 96
        iRIndex[iC][0] = MaxReservedWords-1
        iRIndex[iC][1] = 0
    NEXT

    FOR iC = 0 TO MaxReservedWords-1

        IF sL$ > BCXWords[iC].pszFunctionName$ THEN
            CALL Abort ("Error in BCXWords[], Names out of order" + _
            CRLF$ + sL$ + " comes after " + BCXWords[iC].pszFunctionName$ + _
            CRLF$ + "Correct and recompile")
        END IF

        sL$ = BCXWords[iC].pszFunctionName$

        iD = ASC(sL$)-32
        IF iD < 0 THEN iD = 0
        IF iD > 96 THEN iD = 96
        IF iRIndex[iD][0] > iC THEN iRIndex[iD][0] = iC
        IF iRIndex[iD][1] < iC THEN iRIndex[iD][1] = iC
    NEXT

    FOR iC = 0 TO 96
        IF iRIndex[iC][0] > iRIndex[iC][1] THEN iRIndex[iC][0] = iRIndex[iC][1]
        iRIndex[iC][1]++
    NEXT

    DIM RAW iChk AS INT
    DIM RAW iSize AS INT
    iSize = m_WordsInTable(tBcxWords)-2
    FOR iChk = 0 TO iSize
        IF tBcxWords[iChk].pszWord$ > tBcxWords[iChk+1].pszWord$ THEN
            CALL Abort("Error in SET tBcxWords: " + tBcxWords[iChk].pszWord$ + _
            " comes after " + tBcxWords[iChk+1].pszWord$)
        END IF
    NEXT

    iSize = m_WordsInTable(tTypes)-2
    FOR iChk = 0 TO iSize
        IF tTypes[iChk].pszWord$ > tTypes[iChk+1].pszWord$ THEN
            CALL Abort("Error in SET tTypes: " + tTypes[iChk].pszWord$ + _
            " comes after " + tTypes[iChk+1].pszWord$)
        END IF
    NEXT

    iSize = m_WordsInTable(atEmitWords)-2
    FOR iChk = 0 TO iSize
        IF atEmitWords[iChk].pszWord$ > atEmitWords[iChk+1].pszWord$ THEN
            CALL Abort("Error in SET atEmitWords: " + atEmitWords[iChk].pszWord$ + _
            " comes after " + atEmitWords[iChk+1].pszWord$)
        END IF
    NEXT

    iSize = m_WordsInTable(tDirectives)-2
    FOR iChk = 0 TO iSize
        IF tDirectives[iChk].pszWord$ > tDirectives[iChk+1].pszWord$ THEN
            CALL Abort("Error in SET tDirectives: " + tDirectives[iChk].pszWord$ + _
            " comes after " + tDirectives[iChk+1].pszWord$)
        END IF
    NEXT

    iSize = m_WordsInTable(VariantList)-3
    FOR iChk = 0 TO iSize
        IF VariantList[iChk].sNAME$ > VariantList[iChk+1].sNAME$ THEN
            CALL Abort("Error in SET VariantList: " + VariantList[iChk].sNAME$ + _
            " comes after " + VariantList[iChk+1].sNAME$)
        END IF
    NEXT

    iSize = m_WordsInTable(ptVCasts)-3
    FOR iChk = 0 TO iSize
        IF ptVCasts[iChk].pszCAST$ > ptVCasts[iChk+1].pszCAST$ THEN
            CALL Abort("Error in SET ptVCasts: " + ptVCasts[iChk].pszCAST$ + _
            " comes after " + ptVCasts[iChk+1].pszCAST$)
        END IF
    NEXT

    iSize = m_WordsInTable(ptCCasts)-3
    FOR iChk = 0 TO iSize
        IF ptCCasts[iChk].pszCAST$ > ptCCasts[iChk+1].pszCAST$ THEN
            CALL Abort("Error in SET ptCCasts: " + ptCCasts[iChk].pszCAST$ + _
            " comes after " + ptCCasts[iChk+1].pszCAST$)
        END IF
    NEXT
END SUB ' InitReservedWordsLookup




FUNCTION GetWordInfo(sWord$) AS UDT_SUB_FUNC_TOKENS PTR
    '************************************************************************
    ' This function performs a binary search on a list of BCX words to find
    ' a specific word (sWord$) and returns a pointer to the corresponding
    ' UDT_SUB_FUNC_TOKENS structure if found, or NULL if not found.
    '************************************************************************
    DIM RAW iH
    DIM RAW iL
    DIM RAW iM
    DIM RAW iV

    iM = ASC(sWord$)-32
    IF iM < 0 THEN iM = 0
    IF iM > 96 THEN iM = 96
    iL = iRIndex[iM][0]
    iH = iRIndex[iM][1]

    DO
        ' middle = low + ((high - low) / 2)
        iM = (iH + iL) SHR 1
        iV = strcmp(BCXWords[iM].pszFunctionName, sWord)
        SELECT CASE iV
            CASE -1
                IF iL <> iH THEN
                    IF iL = iM THEN
                        INCR iL
                    ELSE
                        iL = iM
                    END IF
                END IF
            CASE 0
                FUNCTION = ADDRESSOF(BCXWords[iM])
            CASE 1
                IF iL <> iH THEN
                    iH = iM
                END IF
        END SELECT
    LOOP UNTIL iL = iH
    FUNCTION = NULL
END FUNCTION ' GetWordInfo



FUNCTION FindWord(sWord$, tWordList AS UDT_KEYWORD_EMITTER PTR, iWordsInTable AS INT) AS INT
    '***************************************************************************
    ' The FindWord function searches for a word in a list of words.
    ' Parameters:
    '   - sWord$: The word to search for.
    '   - tWordList: Pointer to the list of words.
    '   - iWordsInTable: Number of words in the table.
    ' Returns:
    '   - The index of the found word in the list, or -1 if the word is not found.
    '***************************************************************************
    DIM RAW iH AS INT
    DIM RAW iL AS INT
    DIM RAW iM AS INT
    DIM RAW iV AS INT
    iL = 0
    iH = iWordsInTable ' How many reserved words
    DO WHILE iL <> iH
        iM = (iH + iL) SHR 1
        iV = strcmp(tWordList[iM].pszWord, sWord)
        SELECT CASE iV
            CASE -1
                IF iL = iM THEN FUNCTION = (-1)
                iL = iM
            CASE 0
                FUNCTION = iM
            CASE 1
                IF iL = iM THEN FUNCTION = (-1)
                iH = iM
        END SELECT
    LOOP
    FUNCTION = (-1)
END FUNCTION ' FindWord



SUB FixAnyArrays(Arg$)
    '************************************************************************
    ' This SUB processes and fixes any array definitions in the argument
    ' string (Arg$) by identifying and reformatting vector types, replacing
    ' angle brackets and commas with custom tokens. If any changes are made,
    ' it reconstructs the argument string.
    '************************************************************************
    DIM iMakeNewArg AS INT
    DIM iAttach AS INT
    FOR i AS INT = 1 TO Ndx
        IF m_iMatchWrd(Stk$[i], "as") THEN
            INCR i
            iAttach = 0
            IF m_iMatchWrd(Stk$[i], "vector") THEN
                INCR i
                IF *Stk$[i] = ASC("<") THEN
                    iAttach = i-1
                END IF
            ELSE
                IF m_iMatchWrd(Stk$[i+1], "vector") THEN
                    INCR i, 2
                    IF *Stk$[i] = ASC("<") THEN
                        iAttach = i-1
                    END IF
                END IF
            END IF
            IF iAttach > 0 THEN
                iMakeNewArg = 1
                FOR j AS INT = (iAttach + 1) TO Ndx
                    IF Stk$[j] = "<" THEN
                        Stk$[iAttach] += CHR$(16)
                        Stk$[j] = ""
                        XFOR INT k = j+1, INT iV = 1 WHILE k<= Ndx AND iV > 0 BY k++
                            SELECT CASE Stk$[k]
                                CASE ">"
                                    DECR iV
                                    Stk$[iAttach] += CHR$(17)
                                    Stk$[k] = ""
                                CASE "<"
                                    INCR iV
                                    Stk$[iAttach] += CHR$(16)
                                    Stk$[k] = ""
                                CASE ","
                                    Stk$[iAttach] += CHR$(18)
                                    Stk$[k] = ""
                                CASE ELSE
                                    Stk$[iAttach] += Stk$[k]
                                    Stk$[k] = ""
                            END SELECT
                        XNEXT
                    END IF
                NEXT
            END IF
        END IF
    NEXT
    IF iMakeNewArg THEN
        DIM szNewArg$ = ""
        CALL RemEmptyTokens
        FOR i AS INT = 1 TO Ndx
            szNewArg$ += Stk$[i]
            szNewArg$ += SPC$
        NEXT
        Arg$ = szNewArg$
    END IF
END SUB ' FixAnyArrays



SUB Translate
    DIM ptW AS UDT_SUB_FUNC_TOKENS PTR
    DIM szWord$
    DIM Scratch$
    DIM iEmitID
    DIM iDoFixup

    ' Handle SET
    IF m_iMatchLft(Src$, "set ") THEN
        IF ComSwitchON = TRUE THEN
            IF INCHR(Src$, "=") THEN
                Use_COM = Use_BcxTempStr = TRUE
            ELSE
                CALL ProcessSetCommand(0)
                EXIT SUB
            END IF
        ELSE
            CALL ProcessSetCommand(0)
            EXIT SUB
        END IF
    END IF

    IF m_iMatchLft(Src$, "sharedset ") THEN
        CALL ProcessSetCommand(1)
        EXIT SUB
    END IF

    PassOne = TRUE
    CALL PreParse(Src$)
    PassOne = FALSE

    IF Ndx = 0 THEN EXIT SUB

    '******************************************************************
    ' The following tests support PRINTING sigil-less user-functions
    '******************************************************************

    IF Stk$[1] ?? "FUNCTION" AND Stk$[2] <> "=" THEN

        IF Stk$[Ndx] ?? "FLOAT" AND Stk$[Ndx-1] ?? "AS" THEN
            Stk$[2] += "!"
            DECR Ndx, 2
        END IF

        IF Stk$[Ndx] ?? "SINGLE" AND Stk$[Ndx-1] ?? "AS" THEN
            Stk$[2] += "!"
            DECR Ndx, 2
        END IF

        IF Stk$[Ndx] ?? "DOUBLE" AND Stk$[Ndx-1] ?? "AS" THEN
            Stk$[2] += "#"
            DECR Ndx, 2
        END IF

        IF Stk$[Ndx] ?? "STRING" AND Stk$[Ndx-1] ?? "AS" THEN
            Stk$[2] += "$"
            DECR Ndx, 2
        END IF

    END IF

    '*************************************************************************************
    ' 775  MrBcx -- I discovered that SUB/FUNCTION arguments, declared using the ! and #
    ' sigils for single and double precisions, were being translated as integers which
    ' would result in type conflicts when attempting to compile.  This bug was introduced
    ' in BCX 650 ( circa 2010 ) and has existed ever since.  How was this never noticed?
    ' The code below seems to adequately overcome those problems.
    '*************************************************************************************
    GLOBAL TransformSigil
    LOCAL  ArgsFound

    IF UseCpp = FALSE THEN      ' This "fix" would break some C++ code
        TransformSigil = FALSE
        IF m_iMatchWrd(Stk$[1]     , "SUB")                             _
            OR (m_iMatchWrd(Stk$[1], "FUNCTION") AND Stk$[2] <> "=")    _
            OR m_iMatchWrd(Stk$[1],  "DECLARE")                         _
            OR m_iMatchWrd(Stk$[1],  "C_DECLARE")                       _
            OR m_iMatchWrd(Stk$[1],  "PUBLIC")                          _
            OR m_iMatchWrd(Stk$[1],  "PRIVATE") THEN
            FOR zz AS INT = 1 TO Ndx
                IF Stk$[zz] = "(" THEN ArgsFound = TRUE
                IF ArgsFound THEN
                    IF RIGHTSTR(Stk$[zz], "#")  THEN
                        REPLACE "#" WITH " AS DOUBLE " IN Stk$[zz]
                        TransformSigil = TRUE
                    END IF
                END IF
                IF ArgsFound THEN
                    IF RIGHTSTR(Stk$[zz], "!")  THEN
                        REPLACE "!" WITH " AS SINGLE " IN Stk$[zz]
                        TransformSigil = TRUE
                    END IF
                END IF
                IF ArgsFound THEN
                    IF TransformSigil THEN
                        FOR yy AS INT = 1 TO Ndx
                            IF Stk$[yy]  = "[" AND Stk$[zz+1] = "]" THEN
                                Stk$[yy]   = "*"
                                Stk$[yy+1] = ""
                            END IF
                        NEXT
                    END IF
                END IF
            NEXT
        END IF

        IF TransformSigil THEN
            Scratch$ = ""
            FOR zz AS INT = 1 TO Ndx
                Scratch$ += Stk$[zz]
                Scratch$ += SPC$
            NEXT
            REPLACE "DOUBLE  as double" WITH "DOUBLE" IN Scratch$ ' <-  BYREF causes this mess
            REPLACE "SINGLE  as single" WITH "SINGLE" IN Scratch$ ' <-  BYREF causes this mess
            CALL FastLexer(Scratch$, SPC$, c_FULLSET) ' Rebuild Stk$[]
        END IF
    END IF

    '********************************************************************************
    '    Try to stop users from using the word 'DATA' in ways that are not allowed.
    '********************************************************************************
    FOR i AS INT = 1 TO Ndx
        IF Stk$[i] ?? "data" AND Stk$[i+1] ?? "as" THEN
            CALL Abort("DATA is a reserved word ")
        END IF
    NEXT
    '********************************************************************************

    IF UseCpp OR UseCpphdr THEN CALL FixAnyArrays(Src$)

    IF ComSwitchON = TRUE THEN
        DIM RAW i, j
        XFOR i = 1, j = COM_open_WITH_statement WHILE i<= Ndx AND j = 0 BY i++
            IF IsVariableComObject(Stk$[i]) THEN j = 1
        XNEXT
        IF j THEN
            IF Find_COM_statement(Src$) = TRUE THEN EXIT SUB
        END IF
    END IF

    IF SpecialCaseHandler(Src$) THEN EXIT SUB

    iDoFixup = TRUE
    szWord$ = LCASE$(Stk$[1])
    ptW = GetWordInfo(szWord$)
    IF ptW THEN
        IF (ptW->iWordInfo BAND eWI_Directive) THEN
            iEmitID = FindWord(szWord$, tDirectives, m_WordsInTable(tDirectives))
            IF iEmitID <> c_NOTFOUND THEN
                DIM FuncRetnFlag
                IF tDirectives[iEmitID].Emitter(szWord$, ADDRESSOF(FuncRetnFlag)) = 0 THEN EXIT SUB
            END IF
        END IF
        IF (ptW->iWordInfo BAND eWI_NoFixup) THEN
            iDoFixup = FALSE
        END IF
    END IF

    IF iDoFixup THEN
        CALL FixUps
        PassOne = FALSE
    END IF

    IF Ndx THEN
        CALL Function_Main_Support
        IF iEmitVarGroup THEN CALL Emit_BCXVariables
    END IF
END SUB  ' Translate



SUB FixVector
    '***********************************************
    ' This SUB fixes vector declarations by joining
    ' their elements into a single string.
    '***********************************************
    DIM RAW Tmp, j, k
    FOR Tmp = 2 TO Ndx
        IF m_iMatchWrd(Stk$[Tmp], "as") THEN
            IF Stk$[Tmp+1] = "vector" THEN
                INCR Tmp
                k = Tmp
                j = 0
                DO
                    Stk$[k] += Stk$[++Tmp]
                    IF Stk$[Tmp] = ">" THEN INCR j
                    Stk$[Tmp] = ""
                LOOP UNTIL j
            END IF
        END IF
    NEXT
    CALL RemEmptyTokens
END SUB ' FixVector



SUB Function_Main_Support
    '******************************************************
    ' This SUB emits code for the main function, handling
    ' labels, special characters, and function returns.
    '******************************************************
    DIM EmitAgain = TRUE
    DIM FuncRetnFlag
    DIM iEmitID
    DIM Lookup$

    IF HasVector THEN
        CALL FixVector
        HasVector = FALSE
    END IF

    Lookup$ = LCASE$(Stk$[1])

    IF SelectState[StateIdx].NoBreak AND NOT m_iMatchLft(Lookup$, "case") AND NOT m_iMatchWrd(Lookup$, "endselect") THEN
        SelectState[StateIdx].NoBreak = 0
    END IF

    FOR i AS INT = 1 TO Ndx
        IF INCHR(Stk$[i], CHR$(15)) THEN REPLACE CHR$(15) WITH ":" IN Stk$[i]
        IF INCHR(Stk$[i], CHR$(16)) THEN REPLACE CHR$(16) WITH "<" IN Stk$[i]
        IF INCHR(Stk$[i], CHR$(17)) THEN REPLACE CHR$(17) WITH ">" IN Stk$[i]
        IF INCHR(Stk$[i], CHR$(18)) THEN REPLACE CHR$(18) WITH "," IN Stk$[i]
    NEXT

    IF m_iMatchRgt(Stk$[1], ":") THEN    ' This Must Be A Label
        FPRINT FP_WRITE, CRLF$, UCASE$(Stk$[1]), ";", CRLF$
        EXIT SUB
    END IF

    DO WHILE EmitAgain = TRUE AND Ndx > 0
        INCR Statements
        IF CurrentFuncType = vt_STRVAR AND (InFunction OR InCppTypeDef) AND OkayToSend THEN
            FPRINT FP_WRITE, Scoot$, "char  *BCX_RetStr={0};"
            OkayToSend = FALSE
        END IF
        Lookup$ = LCASE$(Stk$[1])
        iEmitID = FindWord(Lookup$, atEmitWords, m_WordsInTable(atEmitWords))
        IF iEmitID = c_NOTFOUND THEN
            Emit_Assignments(ADDRESSOF(FuncRetnFlag))
            EmitAgain = FALSE
        ELSE
            EmitAgain = atEmitWords[iEmitID].Emitter(Lookup$, ADDRESSOF(FuncRetnFlag))
        END IF
    LOOP

    IF FuncRetnFlag = 1 THEN
        IF NOTZERO (LocalDynaCnt) THEN
            FOR j AS INT = 1 TO LocalDynaCnt
                FPRINT FP_WRITE, Scoot$, DynaStr$[j]
            NEXT
        END IF

        '================  828 MrBcx - prevents heap leaks in LOCAL string arrays  ================
        IF AuxLocalDynArrayCount > 0 THEN
            FPRINT FP_WRITE, ""
            WHILE AuxLocalDynArrayCount > 0
                FPRINT FP_WRITE, Scoot$, AuxLocalDynArray$[AuxLocalDynArrayCount]
                AuxLocalDynArray$[AuxLocalDynArrayCount] = ""
                DECR AuxLocalDynArrayCount
            WEND
            FPRINT FP_WRITE, ""
        END IF
        '================  828 MrBcx - prevents heap leaks in LOCAL string arrays  ================


        FPRINT FP_WRITE, Scoot$, "return BCX_RetStr;"  ' $ FUNCTION Return
        '******************************************************************
    END IF
    ExitSubFunc = FALSE
    IF m_iMatchWrd(Stk$[1], "exit") THEN
        IF m_iMatchWrd(Stk$[2], "sub") OR m_iMatchWrd(Stk$[2], "function") THEN
            ExitSubFunc = TRUE
        END IF
    END IF
END SUB ' Function_Main_Support



FUNCTION Emit_FolderDriveProcs(Lookup$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    ' "chdir", "_chdir", "rmdir", "_rmdir", "mkdir", "_mkdir"
    FPRINT FP_WRITE, Scoot$, Lookup$, " ("; ' Suppress CRLF
    Stk$[++Ndx] = ");"
    CALL WriteCleanTokens(2, Ndx)
    FUNCTION = 0
END FUNCTION ' Emit_FolderDriveProcs



FUNCTION Emit_FunctionReturn(Lookup$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(Lookup$)

    IF g_FoundLocalDynArray = TRUE THEN   ' 830 by MrBcx - Added to enable Dynamic Array Release
        '===================================================================================================
        DIM LTmp$

        IF SelectState[StateIdx].CaseFlag THEN SelectState[StateIdx].NoBreak = TRUE

        FOR i AS INT = 1 TO Ndx
            DIM tmpLen = LEN(Stk$[i])
            IF tmpLen > 1 AND RIGHT$(Stk$[i], 1) = "!" THEN REMOVE "!" FROM Stk$[i]
            IF tmpLen > 1 AND RIGHT$(Stk$[i], 1) = "%" THEN REMOVE "%" FROM Stk$[i]
            IF tmpLen > 1 AND RIGHT$(Stk$[i], 1) = "#" THEN REMOVE "#" FROM Stk$[i]
        NEXT

        FOR i AS INT = 3 TO Ndx
            LTmp$ += Stk$[i] + SPC$         ' This is the FUNCTION return VALUE (string, number, whatever)
        NEXT

        LTmp$ = BeautifyCode (TRIM$(LTmp$))

        IF RIGHTSTR(LTmp$, " export", 1) THEN IREMOVE "export" FROM LTmp$

        IF CurrentFuncType = vt_STRVAR THEN
            LTmp$ = "BCX_RetStr$ = " + LTmp$
            *FuncRetnFlag = 1    ' 1 = return a string
            Use_BcxTempStr = TRUE
        ELSE
            ' 828 MrBcx - enables my Dynamic Array Release
            LTmp$ = "Bcx_RetVal = " + LTmp$
            Stk$[1] = "Bcx_RetVal"

            CALL JoinStrings(1, 0)
            CALL BuildDelimStr(1, Ndx, LTmp$)

            LTmp$ = TRIM$(LTmp$)             ' Trim leading and ending whitespace
            LTmp$ = No_Sigil$(LTmp$)         ' Remove unneeded sigils
            LTmp$ = BeautifyCode(LTmp$)      ' Make the code look like a human wrote it

            *FuncRetnFlag = 2    ' 2 = return a number
        END IF

        IF *FuncRetnFlag = 2 THEN
            ' 828 MrBcx - enables my Dynamic Array Release
            FPRINT FP_WRITE, Scoot$, LTmp$, ";"
        END IF

        IF *FuncRetnFlag = 2 THEN
            '*********************************
            '    Clean up dynamic strings
            '*********************************
            IF NOTZERO (LocalDynaCnt) THEN
                FOR j AS INT = 1 TO LocalDynaCnt
                    FPRINT FP_WRITE, Scoot$, DynaStr$[j]
                NEXT
            END IF
            '*********************************
            ' Clean up dynamic strings arrays
            '*********************************
            IF NOTZERO (LocalDynArrCnt) THEN
                FOR i AS INT = 1 TO LocalDynArrCnt
                    FPRINT FP_WRITE, Scoot$, LocalDynArrName$[i]
                NEXT
            END IF
            '*********************************
            IF *FuncRetnFlag = 2 THEN
                ' 828 MrBcx - enables my Dynamic Array Release
                FPRINT FP_WRITE, Scoot$, "return ", TRIM$(EXTRACT$(LTmp$, "=")), ";"
                LTmp$ = ""
            END IF
            LastCmd = 2
        END IF

        CALL PreParse(LTmp$)
        CALL FixUps
        LastCmd = 2

    ELSE    '==========================================================================

        DIM LTmp$
        IF SelectState[StateIdx].CaseFlag THEN SelectState[StateIdx].NoBreak = TRUE

        FOR iA AS INT = 3 TO Ndx
            LTmp$ = LTmp$ + Stk$[iA] + SPC$
        NEXT

        IF CurrentFuncType = vt_STRVAR THEN
            LTmp$ = "BCX_RetStr$ = " + LTmp$
            *FuncRetnFlag = 1    ' 1 = return a string
            Use_BcxTempStr = TRUE
        ELSE
            *FuncRetnFlag = 2    ' 2 = return a number
        END IF

        IF *FuncRetnFlag = 2 THEN
            '*********************************
            '    Clean up dynamic strings
            '*********************************
            IF NOTZERO (LocalDynaCnt) THEN
                FOR j AS INT = 1 TO LocalDynaCnt
                    FPRINT FP_WRITE, Scoot$, DynaStr$[j]
                NEXT
            END IF
            '*********************************
            ' Clean up dynamic strings arrays
            '*********************************
            IF NOTZERO (LocalDynArrCnt) THEN
                FOR i AS INT = 1 TO LocalDynArrCnt
                    FPRINT FP_WRITE, Scoot$, LocalDynArrName$[i]
                NEXT
            END IF
            '*********************************
            FPRINT FP_WRITE, Scoot$, "return "; ' Suppress CRLF
            LastCmd = 2
        END IF

        CALL PreParse(LTmp$)
        CALL FixUps
        LastCmd = 0
    END IF

    g_FoundLocalDynArray = FALSE       ' 830 by MrBcx - Added to enable my Dynamic Array Release
    '==========================================================================================
    FUNCTION = 1
END FUNCTION ' Emit_FunctionReturn




FUNCTION Emit_Msgbox(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    ' MsgBox Msg$,Title$,button
    DIM i, j, k

    FOR i = 2 TO Ndx
        IF Stk$[i] = "[" THEN
            INCR j
        ELSEIF Stk$[i] = "]" THEN
            DECR j
        ELSEIF Stk$[i] = "(" THEN
            INCR j
        ELSEIF Stk$[i] = ")" THEN
            DECR j
        END IF
        IF j = 0 AND Stk$[i] = "," THEN INCR k
    NEXT
    IF k = 0 THEN
        INCR Ndx
        Stk$[Ndx]= ","
        INCR Ndx
        Stk$[Ndx]= DDQ$
        k = 1
    END IF

    IF k = 1 THEN
        INCR Ndx
        Stk$[Ndx]= ","
        INCR Ndx
        Stk$[Ndx]= "MB_SYSTEMMODAL"       ' 828 Robert Wishlaw changed to this.
    END IF

    FPRINT FP_WRITE, Scoot$, "MessageBox (GetActiveWindow(),"; ' Suppress CRLF
    Stk$[++Ndx] = ");"
    CALL WriteCleanTokens(2, Ndx)
    FUNCTION = 0
END FUNCTION ' Emit_Msgbox




FUNCTION Emit_BcxSetFont (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    Use_SetFont = TRUE
    Use_Proto = TRUE
    IF Stk$[2] = "(" THEN
        LShiftStk(2)
        DECR Ndx
    END IF
    FPRINT FP_WRITE, Scoot$, "SendMessage(";   ' Suppress CRLF
    DIM i = 2
    DO
        FPRINT FP_WRITE, No_Sigil$(Stk$[i]);   ' Suppress CRLF
        INCR i
        IF Stk$[i] = "," THEN EXIT DO
        IF i > Ndx THEN
            CALL Abort ("Malformed BCX_SET_FONT")
        END IF
    LOOP
    INCR i
    FPRINT FP_WRITE, ",(UINT_PTR)WM_SETFONT,"; ' Suppress CRLF
    FPRINT FP_WRITE, "(WPARAM)BCX_Set_Font(";  ' Suppress CRLF
    Stk$[++Ndx] = "),1);"
    CALL WriteCleanTokens(i, Ndx)
    FUNCTION = FALSE
END FUNCTION  ' Emit_BcxSetFont




FUNCTION Emit_BcxSetLabelColor (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    ' These statements must appear in the EVENTS LOOP

    Use_SetColor = Use_Proto = TRUE

    IF Stk$[2] = "(" THEN
        LShiftStk(2)
        DECR Ndx
    END IF

    gTmpStr$ = ""
    DIM RAW i
    FOR i = 2 TO Ndx
        IF Stk$[i] = "," THEN EXIT FOR
        gTmpStr$ += Stk$[i]
    NEXT

    FPRINT FP_WRITE, Scoot$, "if((HWND)lParam==", gTmpStr$, " && Msg==WM_CTLCOLORSTATIC)"
    FPRINT FP_WRITE, Scoot$, "return Set_Color("; ' Suppress CRLF
    Stk$[++Ndx] = ",(HDC)(UINT_PTR)wParam,(HWND)lParam);"
    CALL WriteCleanTokens(i + 1, Ndx)

    FUNCTION = FALSE
END FUNCTION  ' Emit_BcxSetLabelColor



FUNCTION Emit_BcxSetEditColor (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    Use_SetColor = Use_Proto = TRUE

    IF Stk$[2] = "(" THEN
        LShiftStk(2)
        DECR Ndx
    END IF

    gTmpStr$ = ""

    DIM RAW iii
    FOR iii = 2 TO Ndx
        IF Stk$[iii] = "," THEN EXIT FOR
        gTmpStr$ += Stk$[iii]
    NEXT

    FPRINT FP_WRITE, Scoot$, "if((HWND)lParam==", gTmpStr$, " && Msg==WM_CTLCOLOREDIT)"
    FPRINT FP_WRITE, Scoot$, "return Set_Color("; ' Suppress CRLF
    Stk$[++Ndx] = ",(HDC)(UINT_PTR)wParam,(HWND)lParam);"
    CALL WriteCleanTokens(iii + 1, Ndx)

    FUNCTION = FALSE
END FUNCTION  ' Emit_BcxSetEditColor



FUNCTION Emit_Hscroll (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    Use_Hscroll = m_IVAL (Stk$[2])
    IF Use_Hscroll = 0 THEN Use_Hscroll = TRUE
    FUNCTION = FALSE
END FUNCTION  ' Emit_Hscroll



FUNCTION Emit_Vscroll (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    Use_Vscroll = m_IVAL (Stk$[2])
    IF Use_Vscroll = 0 THEN Use_Vscroll = TRUE
    FUNCTION = FALSE
END FUNCTION  ' Emit_Vscroll



FUNCTION Emit_InsertMenuProc (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    DIM L_Comma = 0
    FPRINT FP_WRITE, Scoot$, "InsertMenu";

    FOR A AS INT = 2 TO Ndx
        IF Stk$[A] = "," THEN INCR L_Comma
        IF Stk$[A] = "," THEN
            IF L_Comma = 3 THEN
                Stk$[A] = ",(UINT_PTR)"
            END IF
        END IF
        FPRINT FP_WRITE, No_Sigil$(Stk$[A]); ' Suppress CRLF
    NEXT
    FPRINT FP_WRITE, ";"

    FUNCTION = FALSE
END FUNCTION  ' Emit_InsertMenuProc




FUNCTION Emit_MdiGuiProcs (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)

    IF Ndx < 2 THEN
        CALL Abort("Not Enough Parameters with " + UCASE$(sWord$) + " Statement!")
    END IF

    IF m_iMatchWrd(Stk$[2], "nomain") THEN

        Use_Wingui    = TRUE
        NoMain        = TRUE
        Use_GUINoMain = TRUE

        IF m_iMatchWrd(Stk$[4], "pixels") THEN
            GUIMetric$ = "pixels"
        END IF

        IF m_iMatchWrd(Stk$[4], "dpi") THEN
            GUIMetric$ = "dpi"
        END IF

        IF m_iMatchWrd(Stk$[4], "icon") AND Stk$[6] <> "" THEN
            GUIIcon$ = " LoadIcon(BCX_hInstance,MAKEINTRESOURCE(" + Stk$[6] + "));"
        ELSEIF m_iMatchWrd(Stk$[6], "icon") AND Stk$[8] <> "" THEN
            GUIIcon$ = " LoadIcon(BCX_hInstance,MAKEINTRESOURCE(" + Stk$[8] + "));"
        ELSE
            GUIIcon$ = " LoadIcon(NULL,IDI_WINLOGO);"
        END IF

        IF sWord$ = "mdigui" THEN
            Use_Mdigui       = TRUE
            CALL Emit_MDICode(FP_WRITE)
            Use_MDIGUINoMain = TRUE
            Use_GUINoMain    = FALSE
        END IF

    ELSE '  Old GUI code before GUI NOMAIN

        Use_Wingui = TRUE

        DIM classname$
        DIM metric$

        classname$ = Stk$[2]

        IF m_iMatchWrd(Stk$[4], "pixels") THEN
            metric$ = "pixels"
            GUIMetric$ = "pixels"
        END IF

        IF m_iMatchWrd(Stk$[4], "dpi") THEN
            metric$ = "dpi"
            GUIMetric$ = "dpi"
        END IF

        IF m_iMatchWrd(Stk$[4], "icon") AND Stk$[6] <> "" THEN
            GUIIcon$ = " LoadIcon(BCX_hInstance,MAKEINTRESOURCE(" + Stk$[6] + "));"
        ELSEIF m_iMatchWrd(Stk$[6], "icon") AND Stk$[8] <> "" THEN
            GUIIcon$ = " LoadIcon(BCX_hInstance,MAKEINTRESOURCE(" + Stk$[8] + "));"
        ELSE
            GUIIcon$ = " LoadIcon(NULL,IDI_WINLOGO);"
        END IF

        Use_BCX_SetMetric = Use_BCX_InitGUI = Use_BCX_RegWnd = TRUE
        Emit_WinGUIMain(classname$, metric$, GUIIcon$)

        IF sWord$ = "mdigui" THEN
            Use_Mdigui = TRUE
            CALL Emit_MDI_MsgPump
            CALL Emit_MDICode(FP_WRITE)
        ELSE
            CALL Emit_GUI_MsgPump
        END IF ' sWord$ = "mdigui"

    END IF

    CALL AddGUIGlobals
    IF NOT Use_BCX_Class_Info THEN
        Use_BCX_Class_Info = TRUE
        iEmitVarGroup = iEmitVarGroup BOR (eFontGroup BOR eClassName)
    END IF

    FUNCTION = FALSE
END FUNCTION  ' Emit_MdiGuiProcs




FUNCTION Emit_FileIO(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    SELECT CASE sWord$
        '*************************************************************************
        CASE "flush"                  ' FLUSH handle
            '*************************************************************************
            FOR i AS INT = 2 TO Ndx
                REMOVE "#" FROM Stk$[i]
                IF ISNULL(Stk$[i]) THEN CALL Abort ("Bad FLUSH Argument")
                IF DataType(Stk$[i]) = vt_NUMBER THEN Stk$[i]= "FP" + Stk$[i]
            NEXT
            IF Stk$[2] = "(" THEN  LShiftStk(2) : DECR Ndx ' Eliminate superflous ()
            DIM  i
            IF FindVarInfo(Stk$[2], ADDRESSOF(i)) = NULL THEN
                CALL AddGlobal(Stk$[2], vt_FILEPTR)
            END IF
            szFileHandle$ = ""
            FOR j AS INT = 2 TO Ndx
                szFileHandle$ += Stk$[j]
            NEXT
            FPRINT FP_WRITE, Scoot$, "   fflush("; szFileHandle$; ");"

            '*************************************************************************
        CASE "close"                   ' CLOSE handle
            '*************************************************************************
            IF Ndx = 1 THEN
                FPRINT FP_WRITE, Scoot$, "_fcloseall();"
                EXIT SELECT
            END IF
            '*************************************************************************
            ' CLOSE multiple handles in one go:  CLOSE, #1, #2, FP3
            '*************************************************************************
            ' The basic idea here is to re-create Src$ with colon-separated CLOSE
            ' statements and then re-parse Stk$[].  Maybe useful for other things?
            '*************************************************************************
            DIM Redo                           '

            FOR i AS INT = 1 TO Ndx
                IF Stk$[i] = "," THEN
                    Stk$[i] = " : close "
                    Redo = TRUE
                END IF
            NEXT

            IF Redo THEN
                Src$ = ""
                FOR i AS INT = 1 TO Ndx
                    Src$ += Stk$[i]
                    Src$ += SPC$
                NEXT
                SplitLines(Src$)
                Src$ = LTRIM$(SplitStk$[++SplitCur])                ' Put remaining FP's in the pipeline
                CALL FastLexer(Src, SPC$, c_FULLSET) ' Rebuild Stk$[]
            END IF

            FOR i AS INT = 2 TO Ndx
                REMOVE "#" FROM Stk$[i]
                IF Stk$[i] = "" THEN CALL Abort ("Bad CLOSE Argument")
                IF DataType(Stk$[i]) = vt_NUMBER THEN Stk$[i]= "FP" + Stk$[i]
            NEXT

            IF Stk$[2] = "(" THEN LShiftStk(2) : DECR Ndx ' 763  Eliminate superflous ()

            DIM RAW i
            IF FindVarInfo(Stk$[2], ADDRESSOF(i)) = NULL THEN
                CALL AddGlobal(Stk$[2], vt_FILEPTR)
            END IF

            szFileHandle$ = ""
            FOR j AS INT = 2 TO Ndx
                szFileHandle$ += Stk$[j]
            NEXT

            IF UseFileTest THEN
                FPRINT FP_WRITE, Scoot$, "if(", szFileHandle$, ")"
                FPRINT FP_WRITE, Scoot$, " {"
                FPRINT FP_WRITE, Scoot$, "   fclose(", szFileHandle$, ");"
                FPRINT FP_WRITE, Scoot$, "   ", szFileHandle$, "=NULL;"
                FPRINT FP_WRITE, Scoot$, " }"
            ELSE
                FPRINT FP_WRITE, Scoot$, "fclose(", szFileHandle$, ");"
            END IF

            '*************************************************************************
        CASE "open"    ' OPEN filename$ FOR INPUT | OUTPUT | APPEND AS handle
            '*************************************************************************
            DIM RAW Keyword$, LTmp$, Op$, HaveFOR, HaveAS

            HaveFOR = FALSE
            HaveAS = FALSE
            Op$ = ""
            FOR iA AS INT = 1 TO Ndx
                Keyword$ = LCASE$(Stk$[iA])

                SELECT CASE Keyword$
                    CASE "open"
                        Stk$[iA] = ""

                    CASE "for"
                        Stk$[iA] = ""
                        CALL BuildCleanStr(2, iA-1, Filnam$)
                        HaveFOR = TRUE

                    CASE "as"
                        Stk$[iA] = ""
                        IF DataType(Stk$[iA + 1]) = vt_NUMBER THEN
                            Stk$[iA + 1] = "FP" + Stk$[iA + 1]
                        END IF
                        HaveAS = TRUE

                        DIM RAW i
                        IF FindVarInfo(Stk$[iA + 1], ADDRESSOF(i)) = NULL THEN
                            CALL AddGlobal(Stk$[iA + 1], vt_FILEPTR)
                        END IF

                        Var$ = ""
                        FOR j AS INT = iA+1 TO Ndx
                            IF m_iMatchWrd(Stk$[j], "reclen") THEN EXIT FOR
                            Var$ += Stk$[j]
                            Stk$[j] = ""
                        NEXT
                        szFileHandle$ = Var$ + "@"

                    CASE "input"
                        ' Op$ = ENC$("r")  ' Defeating a Pelles bug with fseeki64 / ftelli64
                        Op$ = ENC$("rb")   ' MrBcx 816 changed to "rb" from "r"
                        Stk$[iA] = ""      ' proven to prevent the bug when using BCX file i/o

                    CASE "output"
                        Op$ = ENC$("w")
                        Stk$[iA] = ""

                    CASE "append"
                        Op$ = ENC$("a")
                        Stk$[iA] = ""

                    CASE "binary"
                        Op$ = ENC$("rb+")
                        Stk$[iA] = ""

                    CASE "binaryappend"
                        Op$ = ENC$("ab+")
                        Stk$[iA] = ""

                    CASE "binarynew"
                        Op$ = ENC$("wb+")
                        Stk$[iA] = ""

                    CASE "binaryinput"
                        Op$ = ENC$("rb")
                        Stk$[iA] = ""

                    CASE "binaryoutput"
                        Op$ = ENC$("rb+")
                        Stk$[iA] = ""

                    CASE "reclen"
                        IF Stk$[iA+1] = "=" THEN
                            FOR j AS INT = iA+2 TO Ndx
                                Stk$[j-1] = Stk$[j]
                            NEXT
                            DECR Ndx
                        END IF

                        Var$ = EXTRACT$(No_Sigil$(szFileHandle$), "[") + "len"

                        DIM RAW i, j, LZZ$

                        IF CheckLocal(Var$, ADDRESSOF(i)) = vt_UNKNOWN THEN
                            CALL AddGlobal(Var$, vt_INTEGER)
                        ELSE
                            IF CheckLocal(Var$, ADDRESSOF(i)) = vt_UNKNOWN THEN
                                CALL AddLocal(Var$, vt_INTEGER)
                                Var$ = "int " + Var$
                            END IF
                        END IF

                        i = CheckType(Stk$[iA+1])
                        LZZ$ = LCASE$(Stk$[iA+1])
                        j = FindWord(LZZ$, tTypes, m_WordsInTable(tTypes))
                        IF i = vt_STRUCT OR i = vt_UNION OR j = vt_BOOL OR j = vt_BYTE OR _
                            j = vt_CHAR OR j = vt_SCHAR OR j = vt_COLORREF OR j = vt_DOUBLE OR j = vt_DWORD OR _
                            j = vt_SINGLE OR j = vt_INTEGER OR j = vt_LDOUBLE OR j = vt_LLONG OR j = vt_SSHORT OR _
                            j = vt_LONG OR j = vt_SHORT OR j = vt_UINT OR j = vt_ULONG OR _
                            j = vt_ULONGLONG OR j = vt_USHORT OR j = vt_VARIANT OR j = vt_WINBOOL THEN
                            FPRINT FP_WRITE, Scoot$, Var$, " = sizeof(", Stk$[iA+1], ");"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, Var$, " = ", No_Sigil$(Stk$[iA+1]), ";"
                        END IF
                        Stk$[iA] = ""
                        Stk$[iA+1] = ""
                END SELECT
            NEXT

            IF ISNULL(Op$)    THEN CALL Abort("Syntax Error: Missing FOR in OPEN statement")
            IF m_IDont(HaveFOR) THEN CALL Abort("Syntax Error: Missing FOR in OPEN statement")
            IF m_IDont(HaveAS)  THEN CALL Abort("Syntax Error: Missing AS  in OPEN statement")

            IF UseFileTest THEN
                FPRINT FP_WRITE, Scoot$, "if((", No_Sigil$(szFileHandle$), "=fopen(", Filnam$, ", ", Op$, "))==0)"
                FPRINT FP_WRITE, Scoot$, " {"
                LTmp$ = ENC$("Error: Cannot Access File or File Not Found. %s\\n")
                FPRINT FP_WRITE, Scoot$, "fprintf(stderr, ", LTmp$, ", ", Filnam$, "); exit(1);"
                FPRINT FP_WRITE, Scoot$, " }"
            ELSE
                FPRINT FP_WRITE, Scoot$, No_Sigil$(szFileHandle$), "=fopen(", Filnam$, ", ", Op$, ");"
            END IF

            '*************************************************************************
            ' Statement  RECORD [#] filenumber,recordnumber [,location in record]
            ' Definition:          Position the file pointer anywhere in a file.
            ' filenumber           Filenumber from  1 to 99
            ' record number        RECORD number to point to. Default first record
            ' location in record   Optional location in RECORD. Default is Zero
            ' RECORD fp1, 6[, 10]
            '*************************************************************************

        CASE "record"

            LOCAL numargs
            DIM RAW funcPtr AS UDT_ARG_COMMAS_STORAGE
            CLEAR(funcPtr)

            IF DataType(Stk$[2]) = vt_NUMBER THEN
                Stk$[2]= "FP" + Stk$[2]
            END IF

            IF Ndx > 1 THEN numargs = SepFuncArgs(1, ADDRESSOF(funcPtr), FALSE)
            IF numargs < 1 THEN Abort("Missing required arguments to RECORD")
            IF numargs > 4 THEN Abort("Too many arguments to RECORD")

            IF numargs = 3 THEN
                FPRINT FP_WRITE, Scoot$, "_fseeki64 (", GetArg$(1, ADDRESSOF(funcPtr)), ",(", GetArg$(2, ADDRESSOF(funcPtr)), "-1)*", Stk$[2], "len+", GetArg$(3, ADDRESSOF(funcPtr)), ",SEEK_SET);"
            ELSEIF numargs = 2 THEN
                FPRINT FP_WRITE, Scoot$, "_fseeki64 (", GetArg$(1, ADDRESSOF(funcPtr)), ",(", GetArg$(2, ADDRESSOF(funcPtr)), "-1)*", Stk$[2], "len,SEEK_SET);"
            ELSE
                FPRINT FP_WRITE, Scoot$, "_fseeki64 (", GetArg$(1, ADDRESSOF(funcPtr)), ",0,SEEK_SET);"
            END IF
    END SELECT

    FUNCTION = 0
END FUNCTION ' Emit_FileIO



FUNCTION Emit_FileManagementProcs(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    SELECT CASE sWord$

        CASE "copyfile"
            FPRINT FP_WRITE, Scoot$, "CopyFile ("; ' Suppress CRLF
            DIM szUS$ = UCASE$(Stk$[Ndx])
            SELECT CASE Stk$[Ndx]

                CASE "1", "0"
                    Stk$[++Ndx] = ");"
                CASE "TRUE", "FALSE"
                    IF UseCpp THEN
                        Stk$[Ndx] = LCASE$(Stk$[Ndx]) + ");"
                    ELSE
                        Stk$[Ndx] = szUS$ + ");"
                    END IF

                CASE ELSE
                    IF UseCpp THEN
                        Stk$[++Ndx] = ",false);"
                    ELSE
                        Stk$[++Ndx] = ",FALSE);"
                    END IF
            END SELECT
            CALL WriteCleanTokens(2, Ndx)


            '***********************
        CASE "kill"
            '***********************
            FPRINT FP_WRITE, Scoot$, "DeleteFile ("; ' Suppress CRLF
            IF Ndx >= 2 AND Stk$[2] <> "(" THEN
                CALL InsertOptionalParens(2)
            END IF
            Stk$[++Ndx] = ");"
            CALL WriteCleanTokens(2, Ndx)

            '***********************
        CASE "rename"
            '***********************
            FPRINT FP_WRITE, Scoot$, "MoveFile ("; ' Suppress CRLF
            Stk$[++Ndx] = ");"
            CALL WriteCleanTokens(2, Ndx)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_FileManagementProcs



FUNCTION Emit_LineInputProcs (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)

    DIM RAW Var1$
    DIM RAW Var2$
    DIM RAW CVar$
    DIM RAW L_Handle$
    DIM i = DataType(Stk$[2])              ' Test for keyboard version of LINE INPUT
    '*************************************************************************************************
    IF i = vt_STRLIT OR i = vt_STRVAR THEN
        IF i <> vt_STRLIT THEN Stk$[2] = No_Sigil$(Stk$[2])
        DIM sC_Stk3$ = No_Sigil$(Stk$[3])
        '****************************************  754 LINE INPUT allows static and dynamic strings
        Use_LineinputKB = Use_SysMacros = TRUE
        FPRINT FP_WRITE, Scoot$, "mLineInputKB (", Stk$[2], ", " , sC_Stk3$, ");"
        EXIT FUNCTION
    END IF

    '**************************************************************************************************
    '                        Okay, we're dealing with the file form of LINE INPUT
    '**************************************************************************************************

    Use_NamePathFromFP = Use_BcxTempStr = TRUE

    REMOVE "#" FROM Stk$[2]
    IF ISNULL(Stk$[2]) THEN CALL Abort ("Bad LINE INPUT File Handle")
    IF DataType(Stk$[2])= vt_NUMBER THEN
        Stk$[2]= "FP" + Stk$[2]
    END IF

    L_Handle$ = EXTRACT$(Stk$[2], "[")

    IF FindVarInfo(L_Handle$, ADDRESSOF(i)) = NULL THEN
        CALL AddGlobal(L_Handle$, vt_FILEPTR)
    END IF

    Var1$ = No_Sigil$(Stk$[3])
    Var2$ = ""
    CVar$ = Var1$

    '********************************************************************
    DIM Optional_Limit$
    Optional_Limit$ = MID$ (Var1$, INSTRREV(Var1$, ","))
    REMOVE Optional_Limit$ FROM Var1$
    REMOVE Optional_Limit$ FROM CVar$
    Optional_Limit$ = TRIM$(MID$(Optional_Limit$, 2))
    '********************************************************************

    IF INCHR(Var1$, "[") AND INCHR(Var1$, "]") THEN
        IF iMatchNQ(Var1$, "[++") THEN
            REMOVE "++" FROM CVar$
        END IF
        IF iMatchNQ(Var1$, "[--") THEN
            REMOVE "--" FROM CVar$
        END IF
        IF iMatchNQ(Var1$, "++]") THEN
            REMOVE "++" FROM CVar$
            Var2$ = MID$(Var1$, INCHR(Var1$, "[")+1)
            Var2$ = EXTRACT$(Var2$, "]")
            Var1$ = CVar$
        END IF
        IF iMatchNQ(Var1$, "--]") THEN
            REMOVE "--" FROM CVar$
            Var2$ = MID$(Var1$, INCHR(Var1$, "[")+1)
            Var2$ = EXTRACT$(Var2$, "]")
            Var1$ = CVar$
        END IF
    END IF

    FPRINT FP_WRITE, Scoot$, Var1$, "[0]=0;"
    '*******************************************************************************
    REMOVE "--" FROM Var1$   ' without this, a receiving array variable
    REMOVE "++" FROM Var1$   ' index is twice incremented or decremented
    '*******************************************************************************

    IF Optional_Limit$ <> "" THEN
        FPRINT FP_WRITE, Scoot$, "fgets(", Var1$, ", ", Optional_Limit$, ", ", No_Sigil$(Stk$[2]), ");"
    ELSE
        FPRINT FP_WRITE, Scoot$, "fgets(", Var1$, ",", BCXSTRSIZE, ", ", No_Sigil$(Stk$[2]), ");"
    END IF

    FPRINT FP_WRITE, Scoot$, "  if(feof(", No_Sigil$(Stk$[2]), ") || (", Var1$, "[strlen(", Var1$, ")-1]==10))"
    FPRINT FP_WRITE, Scoot$, "    {"
    FPRINT FP_WRITE, Scoot$, "     ", Var1$, "[strcspn(", Var1$, ",", ENC$("\\r\\n"), ")] = 0;"
    FPRINT FP_WRITE, Scoot$, "    }"
    FPRINT FP_WRITE, Scoot$, "   else"
    FPRINT FP_WRITE, Scoot$, "    {"
    FPRINT FP_WRITE, Scoot$, "      printf(", ENC$("%s%d while reading file: %s\\n"), "," , _
    ENC$("Error! - LINE INPUT truncation detected at PROGRAM line: "), ",__LINE__-7, NamePathFromFP(", No_Sigil$(Stk$[2]), "));"
    FPRINT FP_WRITE, Scoot$, "      printf(", ENC$("%s\\n"), ",", ENC$("The actual truncated line of text:"), ");"
    FPRINT FP_WRITE, Scoot$, "      printf(", ENC$("%s"), ",", Var1$, ");"
    FPRINT FP_WRITE, Scoot$, "      exit(1);"
    FPRINT FP_WRITE, Scoot$, "    }"

    IF Var2$ <> "" THEN
        FPRINT FP_WRITE, Var2$, ";"
    END IF

    FUNCTION = 0
END FUNCTION ' Emit_LineInputProcs


FUNCTION Emit_FinputProcs(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    CALL Emit_FileInputCode
    FUNCTION = 0
END FUNCTION  ' Emit_FinputProcs


FUNCTION Emit_GetProcs(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    DIM RAW i
    Use_Get = TRUE
    Use_SysMacros = TRUE
    REMOVE "#" FROM Stk$[2]
    IF ISNULL(Stk$[2]) THEN CALL Abort ("Bad GET$ Argument")
    IF DataType(Stk$[2])= vt_NUMBER THEN
        Stk$[2]= "FP" + Stk$[2]
    END IF
    IF FindVarInfo(Stk$[2], ADDRESSOF(i)) = NULL THEN
        CALL AddGlobal(Stk$[2], vt_FILEPTR)
    END IF
    FPRINT FP_WRITE, Scoot$, "GET("; ' Suppress CRLF
    Stk$[++Ndx] = ");"
    CALL WriteCleanTokens(2, Ndx)
    FUNCTION = 0
END FUNCTION  ' Emit_GetProcs


FUNCTION Emit_PutProcs(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    DIM RAW i
    Use_Put = TRUE
    Use_SysMacros = TRUE
    REMOVE "#" FROM Stk$[2]
    IF ISNULL(Stk$[2]) THEN CALL Abort ("Bad PUT$ Argument")
    IF DataType(Stk$[2])= vt_NUMBER THEN
        Stk$[2]= "FP" + Stk$[2]
    END IF
    IF FindVarInfo(Stk$[2], ADDRESSOF(i)) = NULL THEN
        CALL AddGlobal(Stk$[2], vt_FILEPTR)
    END IF
    FPRINT FP_WRITE, Scoot$, "PUT("; ' Suppress CRLF
    Stk$[++Ndx] = ");"
    CALL WriteCleanTokens(2, Ndx)
    FUNCTION = 0
END FUNCTION  ' Emit_PutProcs



FUNCTION Emit_FprintProcs(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    STATIC i
    STATIC j
    STATIC LZZ$
    DIM RAW L_Handle$
    REMOVE "#" FROM Stk$[2]
    IF ISNULL(Stk$[2]) THEN CALL Abort ("Bad FPRINT Argument")
    IF DataType(Stk$[2])= vt_NUMBER THEN
        Stk$[2]= "FP" + Stk$[2]
    END IF
    IF m_iMatchWrd(Stk$[2], "stderr") THEN
        L_Handle$ = "stderr"
    ELSE
        IF FindVarInfo(Stk$[2], ADDRESSOF(i)) = NULL THEN
            CALL AddGlobal(Stk$[2], vt_FILEPTR)
        END IF
        L_Handle$ = ""
        FOR j = 2 TO Ndx
            IF *Stk$[j] = ASC(",") OR *Stk$[j] = ASC(";") THEN
                Stk$[j] = ""
                EXIT FOR
            END IF
            L_Handle$ += Stk$[j]
            Stk$[j] = ""
        NEXT
        L_Handle$ += "@"
    END IF
    Stk$[2] = ""  ' remove the handle
    Stk$[3] = ""  ' remove the Comma
    LZZ$ = "f" + PrintWriteFormat$(0)
    LZZ$ = LEFT$(LZZ$, 8) + REMOVE$(L_Handle$, "@") + "," + MID$(LZZ$, 9)
    FPRINT FP_WRITE, Scoot$, LZZ$
    FUNCTION = 0
END FUNCTION  ' Emit_FprintProcs


FUNCTION Emit_SeekProcs(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)

    REMOVE "#" FROM Stk$[2]
    IF ISNULL(Stk$[2]) THEN CALL Abort ("Bad SEEK Argument")
    '***************************************************************************
    ' Example:  SEEK FP1, 8192 [, SEEK_CUR ]               ' MrBcx 817 - Added
    '***************************************************************************
    DIM Origin$                                            ' MrBcx 817 - Added
    SELECT CASE UCASE$(Stk$[Ndx])                          ' MrBcx 817 - Added
        CASE "SEEK_CUR", "SEEK_END", "SEEK_SET"            ' MrBcx 817 - Added
            Origin$ = UCASE$(Stk$[Ndx])                    ' MrBcx 817 - Added
            DECR Ndx, 2        ' Adjust the stack          ' MrBcx 817 - Added
        CASE ELSE                                          ' MrBcx 817 - Added
            Origin$ = "SEEK_SET"                           ' MrBcx 817 - Added
    END SELECT                                             ' MrBcx 817 - Added
    '***************************************************************************
    IF DataType(Stk$[2])= vt_NUMBER THEN
        Stk$[2]= "FP" + Stk$[2]
    END IF

    DIM i
    IF CheckLocal(Stk$[2], ADDRESSOF(i)) = vt_UNKNOWN THEN
        CALL AddGlobal(Stk$[2], vt_FILEPTR)
    END IF

    FPRINT FP_WRITE, Scoot$, "_fseeki64("; ' Suppress CRLF
    Stk$[++Ndx] = "," + Origin$ + ");"                     ' MrBcx 817 - Modified

    CALL WriteCleanTokens(2, Ndx)
    FUNCTION = 0
END FUNCTION  ' Emit_SeekProcs




FUNCTION Emit_SetEofProcs(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    Use_SysMacros = Use_Seteof = TRUE
    DIM i
    FOR i = 2 TO Ndx
        REMOVE "#" FROM Stk$[i]
    NEXT
    IF Stk$[2] = "(" THEN Stk$[2] = Stk$[3]  ' Allow SETEOF (FP1) -and-  SETEOF FP1
    IF DataType(Stk$[2])= vt_NUMBER THEN
        Stk$[2]= "FP" + Stk$[2]
    END IF
    IF CheckLocal(Stk$[2], ADDRESSOF(i)) = vt_UNKNOWN THEN
        CALL AddGlobal(Stk$[2], vt_FILEPTR)
    END IF
    FPRINT FP_WRITE, Scoot$, "SetEof(", Stk$[2], ");"
    FUNCTION = 0
END FUNCTION  ' Emit_SetEofProcs



FUNCTION Emit_FwriteProcs(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UNREFERENCED_PARAMETER(sWord$)
    DIM RAW i
    DIM RAW LZZ$
    DIM RAW L_Handle$

    REMOVE "#" FROM Stk$[2]
    IF ISNULL(Stk$[2]) THEN CALL Abort ("Bad WRITE Argument")
    IF DataType(Stk$[2])= vt_NUMBER THEN
        Stk$[2]= "FP" + Stk$[2]
    END IF

    IF CheckLocal(Stk$[2], ADDRESSOF(i)) = vt_UNKNOWN THEN
        CALL AddGlobal(Stk$[2], vt_FILEPTR)
    END IF
    L_Handle$ = ""
    FOR j AS INT = 2 TO Ndx
        IF m_iMatchWrd(Stk$[j], ",") OR m_iMatchWrd(Stk$[j], ";") THEN
            Stk$[j] = ""              ' remove the Comma
            EXIT FOR
        END IF
        L_Handle$ += Stk$[j]
        Stk$[j] = ""                  ' remove the handle
    NEXT j
    L_Handle$ += "@"
    LZZ$ = "f" + PrintWriteFormat$(1)
    LZZ$ = LEFT$(LZZ$, 8)  +  No_Sigil$(L_Handle$)  +  ","  +  MID$(LZZ$, 9)
    FPRINT FP_WRITE, Scoot$, LZZ$

    FUNCTION = 0
END FUNCTION  ' Emit_FwriteProcs




FUNCTION Emit_StringProcs(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "midstr"    ' alias for MID$ statement (not the MID$ function)
            Src$ = ""
            FOR A AS INT = 1 TO Ndx
                Src$ += No_Sigil$(Stk$[A])
            NEXT
            FPRINT FP_WRITE, Scoot$, TRIM$(Src$), ";"

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_StringProcs



FUNCTION Emit_MathProcs(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "incr"
            DIM j
            FPRINT FP_WRITE, Scoot$; ' Suppress CRLF
            FOR i AS INT = 2 TO Ndx
                IF *Stk$[i] = ASC(",") THEN
                    FPRINT FP_WRITE, "+=("; ' Suppress CRLF
                    j = TRUE
                ELSE
                    FPRINT FP_WRITE, No_Sigil$(Stk$[i]); ' Suppress CRLF
                END IF
            NEXT
            FPRINT FP_WRITE, IIF$(j, ");", "++;")

        CASE "decr"
            DIM j
            FPRINT FP_WRITE, Scoot$; ' Suppress CRLF
            FOR i AS INT = 2 TO Ndx
                IF *Stk$[i] = ASC(",") THEN
                    FPRINT FP_WRITE, "-=("; ' Suppress CRLF
                    j = TRUE
                ELSE
                    FPRINT FP_WRITE, No_Sigil$(Stk$[i]); ' Suppress CRLF
                END IF
            NEXT
            FPRINT FP_WRITE, IIF$(j, ");", "--;")

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)
    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_MathProcs



FUNCTION Emit_ConsoleOnlyProcs(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "print"
            FPRINT FP_WRITE, Scoot$, PrintWriteFormat$(0)

        CASE "locate"
            IF NoMain = TRUE OR MakeDLL = TRUE THEN
                Use_Console = TRUE
            END IF

            FPRINT FP_WRITE, Scoot$, "locate("; ' Suppress CRLF
            Stk$[++Ndx] = ");"
            CALL WriteCleanTokens(2, Ndx)

        CASE "panel"
            IF NoMain = TRUE OR MakeDLL = TRUE THEN
                Use_Console = TRUE
            END IF

            FPRINT FP_WRITE, Scoot$, "panel("; ' Suppress CRLF
            Stk$[++Ndx] = ");"
            CALL WriteCleanTokens(2, Ndx)

        CASE "cls"
            IF NoMain = TRUE OR MakeDLL = TRUE THEN
                Use_Console = TRUE
            END IF

            FPRINT FP_WRITE, Scoot$, "cls();"

        CASE "color"
            IF NoMain = TRUE OR MakeDLL = TRUE THEN
                Use_Console = TRUE
            END IF

            FPRINT FP_WRITE, Scoot$, "color("; ' Suppress CRLF
            Stk$[++Ndx] = ");"
            CALL WriteCleanTokens(2, Ndx)

        CASE "textmode"
            DIM RAW LTmp$
            CALL BuildCleanStr(2, Ndx, LTmp$)                 ' Allow size to be an expression
            FPRINT FP_WRITE, Scoot$, "TextMode(", LTmp$, ");"

        CASE "delay"
            DIM RAW LTmp$
            CALL BuildCleanStr(2, Ndx, LTmp$)                 ' Allow size to be an expression
            FPRINT FP_WRITE, Scoot$, "Sleep(1000*", LTmp$, ");"

        CASE "write"
            FPRINT FP_WRITE, Scoot$, PrintWriteFormat$(1)

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)
    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_ConsoleOnlyProcs



FUNCTION ValidExitStatement
    DIM RightTerm$
    RightTerm$ = LCASE$(Stk$[2])
    SELECT CASE RightTerm$
        CASE "sub", "function", "for", "xfor", "do", "while", "select", "nest", "loop", "repeat"
            FUNCTION = TRUE
    END SELECT
    FUNCTION = FALSE
END FUNCTION ' ValidExitStatement




FUNCTION Emit_ControlFlow(sWord$, FuncRetnFlag AS PINT)
    STATIC iFallThrough AS INT

    SELECT CASE sWord$

        CASE "exit"

            IF ValidExitStatement() = FALSE THEN
                CALL Abort("Expected to find EXIT: sub|function|for|xfor|do|while|select|nest|loop|repeat")
            END IF

            IF SelectState[StateIdx].CaseFlag THEN SelectState[StateIdx].NoBreak = TRUE

            DIM szL_Stk2$
            DIM iLoops1
            DIM iLoops2

            FOR iLoops1 = 2 TO Ndx
                IF *Stk$[iLoops1] = ASC(",") THEN ITERATE
                szL_Stk2$ = LCASE$(Stk$[iLoops1])

                SELECT CASE szL_Stk2$
                    CASE "sub"
                        IF COM_lc_names_index > 0 THEN          ' cleaning local COM objects if user forgot to
                            CALL Free_Com_Objects(FALSE)        ' call xxx = Nothing for each declared object
                        END IF
                        IF NOTZERO (LocalDynaCnt) THEN          ' Clean up dynamic strings
                            FOR j AS INT = 1 TO LocalDynaCnt
                                FPRINT FP_WRITE, Scoot$, DynaStr$[j]
                            NEXT
                        END IF
                        IF NOTZERO (LocalDynArrCnt) THEN        ' Clean up dynamic strings arrays
                            FOR i AS INT = 1 TO LocalDynArrCnt
                                FPRINT FP_WRITE, Scoot$, LocalDynArrName$[i]
                            NEXT
                        END IF
                        FPRINT FP_WRITE, Scoot$, "return;"

                    CASE "function"
                        IF NOTZERO(LocalDynaCnt) THEN ' Clean up dynamic strings
                            FOR j AS INT = 1 TO LocalDynaCnt
                                FPRINT FP_WRITE, Scoot$, DynaStr$[j]
                            NEXT
                        END IF
                        IF NOTZERO(LocalDynArrCnt) THEN ' Clean up dynamic strings arrays
                            FOR i AS INT = 1 TO LocalDynArrCnt
                                FPRINT FP_WRITE, Scoot$, LocalDynArrName$[i]
                            NEXT
                        END IF
                        FPRINT FP_WRITE, Scoot$, "return 0;"


                    CASE "for"
                        STATIC LszTmp$
                        STATIC i

                        XFOR i = LoopTypeCnt-iLoops2 _
                            UNTIL LoopType[i].iLoopType = lt_FORNEXT OR i = 0 BY i--
                        XNEXT

                        IF i THEN
                            IF i <> LoopTypeCnt-iLoops2 THEN
                                IF TestState THEN CALL Warning_ID(eExitingMoreThan1Loop, 1)
                            END IF
                            iLoops2 = LoopTypeCnt - i + 1
                            IF iLoops1 = Ndx THEN CALL Generate_Goto(i, 1)
                        ELSE
                            LszTmp$ = "No FOR to exit from. Inner most loop is "
                            LszTmp$ += LoopTypeName$(LoopType[LoopTypeCnt].iLoopType)
                            CALL Abort(LszTmp$)
                        END IF

                    CASE "xfor"
                        STATIC LszTmp$
                        STATIC i

                        XFOR i = LoopTypeCnt-iLoops2 _
                            UNTIL LoopType[i].iLoopType = lt_FORXNEXT OR i = 0 BY i--
                        XNEXT

                        IF i THEN
                            IF i <> LoopTypeCnt-iLoops2 THEN
                                IF TestState THEN CALL Warning_ID(eExitingMoreThan1Loop, 1)
                            END IF
                            iLoops2 = LoopTypeCnt - i + 1
                            IF iLoops1 = Ndx THEN CALL Generate_Goto(i, 1)
                        ELSE
                            LszTmp$ = "No XFOR to exit from. Inner most loop is "
                            LszTmp$ += LoopTypeName$(LoopType[LoopTypeCnt].iLoopType)
                            CALL Abort(LszTmp$)
                        END IF

                    CASE "do"
                        STATIC LszTmp$
                        STATIC i

                        XFOR i = LoopTypeCnt-iLoops2 _
                            UNTIL LoopType[i].iLoopType = lt_DOLOOP OR _
                            LoopType[i].iLoopType = lt_DOUNTILLOOP  OR _
                            LoopType[i].iLoopType = lt_DOWHILELOOP  OR i = 0 BY i--
                        XNEXT

                        IF i THEN
                            IF i <> LoopTypeCnt-iLoops2 THEN
                                IF TestState THEN CALL Warning_ID(eExitingMoreThan1Loop, 1)
                            END IF
                            iLoops2 = LoopTypeCnt - i + 1
                            IF iLoops1 = Ndx THEN CALL Generate_Goto(i, 1)
                        ELSE
                            LszTmp$ = "No DO to exit from. Inner most loop is "
                            LszTmp$ += LoopTypeName$(LoopType[LoopTypeCnt].iLoopType)
                            CALL Abort(LszTmp$)
                        END IF

                    CASE "while"
                        STATIC LszTmp$
                        STATIC i

                        XFOR i = LoopTypeCnt-iLoops2 _
                            UNTIL LoopType[i].iLoopType = lt_WHILEWEND OR i = 0 BY i--
                        XNEXT

                        IF i THEN
                            IF i <> LoopTypeCnt-iLoops2 THEN
                                IF TestState THEN CALL Warning_ID(eExitingMoreThan1Loop, 1)
                            END IF
                            iLoops2 = LoopTypeCnt - i + 1
                            IF iLoops1 = Ndx THEN CALL Generate_Goto(i, 1)
                        ELSE
                            LszTmp$ = "No WHILE to exit from. Inner most loop is "
                            LszTmp$ += LoopTypeName$(LoopType[LoopTypeCnt].iLoopType)
                            CALL Abort(LszTmp$)
                        END IF

                    CASE "select"
                        STATIC LszTmp$
                        STATIC i

                        XFOR i = LoopTypeCnt-iLoops2 _
                            UNTIL LoopType[i].iLoopType = lt_SELECT OR i = 0 BY i--
                        XNEXT

                        IF i THEN
                            IF i <> LoopTypeCnt-iLoops2 THEN
                                IF TestState THEN CALL Warning_ID(eExitingMoreThan1Loop, 1)
                            END IF
                            iLoops2 = LoopTypeCnt - i + 1
                            IF iLoops1 = Ndx THEN
                                CALL Generate_Goto(i, 1)
                                SelectState[StateIdx].CaseFlag++
                            END IF
                        ELSE
                            LszTmp$ = "No SELECT to exit from. Inner most loop is "
                            LszTmp$ += LoopTypeName$(LoopType[LoopTypeCnt].iLoopType)
                            CALL Abort(LszTmp$)
                        END IF

                    CASE "nest"
                        STATIC LszTmp$
                        STATIC i
                        IF LoopTypeCnt = 0 THEN
                            CALL Abort("Too many end loops")
                        END IF

                        XFOR i = LoopTypeCnt-iLoops2 _
                            UNTIL LoopType[i].iLoopType <> LoopType[LoopTypeCnt-iLoops2].iLoopType BY i--
                        XNEXT

                        LszTmp$ = "Exiting from nested control loops. Outer to inner control loops are "
                        LszTmp$ += LoopTypeName$(LoopType[LoopTypeCnt].iLoopType)

                        IF TestState THEN CALL Warning(LszTmp$, 1)
                        INCR i
                        iLoops2 = LoopTypeCnt - i + 1
                        IF iLoops1 = Ndx THEN CALL Generate_Goto(i, 1)

                    CASE ELSE
                        STATIC LszTmp$
                        LszTmp$ = "Exiting from a misnamed or unnamed control loop.  Expected: EXIT "
                        LszTmp$ += LoopTypeName$(LoopType[LoopTypeCnt].iLoopType)

                        IF TestState THEN CALL Warning(LszTmp$, 1)
                        IF iLoops1 = Ndx THEN CALL Generate_Goto(LoopTypeCnt-iLoops2, 1)
                        INCR iLoops2
                END SELECT
            NEXT


        CASE "repeat"
            DIM LTmp$

            FOR i AS INT = 2 TO Ndx
                LTmp$ += Stk$[i]
            NEXT
            LTmp$ = No_Sigil$(LTmp$)
            CALL BumpUp
            IF INCHR(Stk$[2], "-") THEN
                IF LEFTSTR(LTmp$, "-") THEN LTmp$ = MID$(LTmp$, 2)
                FPRINT FP_WRITE, Scoot$, "for(int BCX_REPEAT = ", LTmp$, "; BCX_REPEAT >= 1; BCX_REPEAT--)"
                FPRINT FP_WRITE, Scoot$, "{"
            ELSE
                FPRINT FP_WRITE, Scoot$, "for(int BCX_REPEAT = 1; BCX_REPEAT <= ", LTmp$, "; BCX_REPEAT++)"
                FPRINT FP_WRITE, Scoot$, "{"
            END IF
            CALL BumpUp


        CASE "endrepeat"
            CALL BumpDown("Too many unindents in REPEAT/END REPEAT")
            FPRINT FP_WRITE, Scoot$, "}"
            CALL BumpDown("Too many unindents in REPEAT/END REPEAT")


        CASE "while"
            CALL Emit_IfCond("while", eFull)
            IF iDoWhile THEN
                LoopType[++LoopTypeCnt].iLoopType = iDoWhile
            ELSE
                LoopType[++LoopTypeCnt].iLoopType = lt_WHILEWEND
            END IF
            LoopType[LoopTypeCnt].iJumpTo = LabelGenerator++
            LoopType[LoopTypeCnt].szUseNeedLabel$ = ""
            iDoWhile = 0
            LoopType[LoopTypeCnt].iLoopLine = LineNum[FileNdx]
            CALL InBlockSet


        CASE "wend", "endwhile"
            CALL InBlockReSet
            IF LoopTypeCnt = 0 THEN
                CALL Abort("Too many end loops")
            END IF
            IF LoopType[LoopTypeCnt].iLoopType <> lt_WHILEWEND THEN
                DIM sErr$ = LoopTypeName$(LoopType[LoopTypeCnt].iLoopType) + " at" + STR$(LoopType[LoopTypeCnt].iLoopLine) + " closed with WEND"
                CALL Abort(sErr$)
            END IF
            CALL BumpDown("Error in Emit_ControlFlow() CASE wend, endwhile")
            FPRINT FP_WRITE, Scoot$, "}"
            IF LoopType[LoopTypeCnt].szUseNeedLabel$ <> "" THEN
                FPRINT FP_WRITE, LoopType[LoopTypeCnt].szUseNeedLabel$
            END IF
            DECR LoopTypeCnt
            CALL BumpDown("Unbalanced LOOP")


        CASE "prepend"
            MACRO c_PrependVarSize = 8
            GLOBAL PrependVar$[c_PrependVarSize]
            GLOBAL PrependCnt
            INCR PrependCnt

            IF PrependCnt = c_PrependVarSize THEN
                CALL Abort("Prepend depth exceeded")
            END IF

            CALL BuildDelimStr(2, Ndx, PrependVar$[PrependCnt])


        CASE "endprepend"
            DECR PrependCnt

            IF PrependCnt < 0 THEN
                CALL Abort("Too many END PREPENDs.")
            END IF


        CASE "with"
            MACRO c_WithVarSize = 8
            GLOBAL WithVar$[c_WithVarSize]
            GLOBAL WithCnt

            INCR WithCnt

            IF WithCnt = c_WithVarSize THEN
                CALL Abort("[With] depth exceeded")
            END IF

            CALL BuildStr(2, Ndx, WithVar$[WithCnt])


        CASE "endwith"
            IF COM_open_WITH_statement THEN
                IF COM_open_WITH_statement > 1 THEN
                    FPRINT FP_WRITE, Scoot$, "COM_dispatch_storage_index--;"
                    FPRINT FP_WRITE, Scoot$, "COM_dispatch_at_offset = COM_dispatch_storage[COM_dispatch_storage_index];"
                ELSE
                    FPRINT FP_WRITE, Scoot$, "COM_dispatch_at_offset = 0;"
                    FPRINT FP_WRITE, Scoot$, "COM_dispatch_storage_index = 0;"
                END IF
                FPRINT FP_WRITE, Scoot$, "COM_reset_disp_chain(&", COM_with_temp_str_name$, ");"
                DECR COM_open_WITH_statement
            ELSE
                DECR WithCnt
            END IF


        CASE "goto"
            IF SelectState[StateIdx].CaseFlag THEN SelectState[StateIdx].NoBreak = TRUE
            FPRINT FP_WRITE, Scoot$, "goto ", UCASE$(Stk$[2]), ";"


        CASE "gosub"
            Use_GoSub = TRUE
            FPRINT FP_WRITE, Scoot$, "#if defined(__MINGW64__)"                          ' 837 modified by Luigi
            FPRINT FP_WRITE, Scoot$, "if (__builtin_setjmp(GosubStack[GosubNdx++])==0)"; ' Suppress CRLF
            FPRINT FP_WRITE, " goto ", UCASE$(Stk$[2]), ";"
            FPRINT FP_WRITE, Scoot$, "#else"
            FPRINT FP_WRITE, Scoot$, "if (setjmp(GosubStack[GosubNdx++])==0)";           ' Suppress CRLF
            FPRINT FP_WRITE, " goto ", UCASE$(Stk$[2]), ";"
            FPRINT FP_WRITE, Scoot$, "#endif"


        CASE "return"
            IF Ndx > 1 THEN
                DIM Convert$ = "FUNCTION = "   ' Reminder:  BCX Pre-Processor converts RETURN to FUNCTION =
                FOR i AS INT = 2 TO Ndx
                    Convert$ += Stk$[i] + SPC$
                NEXT
                Inject(Convert$)
                EXIT FUNCTION
            ELSE
                Use_GoSub = TRUE
                FPRINT FP_WRITE, Scoot$, "#if defined(__MINGW64__)"   ' 837 modified by Luigi
                FPRINT FP_WRITE, Scoot$, "__builtin_longjmp (GosubStack [--GosubNdx],1);"
                FPRINT FP_WRITE, Scoot$, "#else"
                FPRINT FP_WRITE, Scoot$, "longjmp (GosubStack [--GosubNdx],1);"
                FPRINT FP_WRITE, Scoot$, "#endif"
                FPRINT FP_WRITE, ""
            END IF


        CASE "fallthrough"
            iFallThrough = TRUE


        CASE "case"
            IF SelectState[StateIdx].iStartCase = 0 THEN
                CALL InBlockReSet
            END IF
            SelectState[StateIdx].iStartCase = 0
            CALL InBlockSet
            FOR i AS INT = 2 TO Ndx
                IF  Stk$[i] = "!=" THEN Stk$[i]   = "<>"
                IF *Stk$[i] = ASC("%")  AND  *Stk$[i+1] <> ASC("=") THEN Stk$[i]= " % "
                IF *Stk$[i] = ASC("!")  AND  *Stk$[i+1] = ASC("=") THEN Stk$[i] = "<>" : Stk$[i+1] = ""
                IF *Stk$[i] = ASC("<")  AND  *Stk$[i+1] = ASC(">") THEN Stk$[i] = "<>" : Stk$[i+1] = ""
                IF *Stk$[i] = ASC("=")  AND  *Stk$[i+1] = ASC("<") THEN Stk$[i] = "<=" : Stk$[i+1] = ""
                IF *Stk$[i] = ASC("<")  AND  *Stk$[i+1] = ASC("=") THEN Stk$[i] = "<=" : Stk$[i+1] = ""
                IF *Stk$[i] = ASC("=")  AND  *Stk$[i+1] = ASC(">") THEN Stk$[i] = ">=" : Stk$[i+1] = ""
                IF *Stk$[i] = ASC(">")  AND  *Stk$[i+1] = ASC("=") THEN Stk$[i] = ">=" : Stk$[i+1] = ""
                IF isalpha(*Stk$[i]) THEN
                    Stk$[i] += SPC$
                END IF
            NEXT

            gTmpStr$ = ""
            For_Next_Error_Detected = FALSE

            IF DataType(CaseVar$) = vt_STRVAR THEN For_Next_Error_Detected = TRUE

            '************************************************************************************
            '  MrBcx added the following to allow "Var AS STRING" in SELECT CASE statements
            '***********************************************************************************
            DIM ss, idx
            IF CheckLocal  (CaseVar$, ADDRESSOF(idx)) = vt_CHAR   THEN ss = TRUE
            IF CheckLocal  (CaseVar$, ADDRESSOF(idx)) = vt_SCHAR  THEN ss = TRUE
            IF CheckGlobal (CaseVar$, ADDRESSOF(idx)) = vt_CHAR   THEN ss = TRUE
            IF CheckGlobal (CaseVar$, ADDRESSOF(idx)) = vt_SCHAR  THEN ss = TRUE
            IF CheckLocal  (CaseVar$, ADDRESSOF(idx)) = vt_STRVAR THEN ss = TRUE
            IF CheckGlobal (CaseVar$, ADDRESSOF(idx)) = vt_STRVAR THEN ss = TRUE
            IF ss = TRUE THEN CaseVar$ += "$"
            '************************************************************************************

            DIM i
            FOR A AS INT = 2 TO Ndx
                IF INCHR("([", Stk$[A]) THEN INCR i
                IF INCHR(")]", Stk$[A]) THEN DECR i
                IF i THEN
                    gTmpStr$ += Stk$[A]
                    ITERATE
                END IF

                IF Stk$[A] = "," THEN   ' comma
                    IF NOT INCHR("<>=", Stk$[A+1]) THEN
                        gTmpStr$ += " or " + CaseVar$ + "="
                    ELSE
                        gTmpStr$ += " or " + CaseVar$
                    END IF
                    Stk$[A] = ""
                    ITERATE
                END IF

                IF Stk$[A] = "&&" THEN
                    gTmpStr$ += " and " + CaseVar$
                    Stk$[A] = ""
                ELSEIF Stk$[A] = "||" THEN
                    gTmpStr$ +=  " or "  + CaseVar$
                    Stk$[A] = ""
                ELSE
                    gTmpStr$ += Stk$[A]
                END IF
            NEXT
            DIM szDrop$
            IF SelectState[StateIdx].CaseFlag = 0 THEN SelectState[StateIdx].NoBreak = 0
            IF SelectState[StateIdx].CaseFlag THEN
                DIM LszTmp$
                IF iFallThrough = FALSE THEN
                    SelectState[StateIdx].CaseFlag--
                    IF SelectState[StateIdx].NoBreak = 0 THEN
                        IF SelectState[StateIdx].NoBreak = 0 THEN
                            SelectState[StateIdx].CaseFlag++
                            sprintf(LszTmp, "goto L%i;", SelectState[StateIdx].iJumpTo)
                            FPRINT FP_WRITE, Scoot$, LszTmp$
                        END IF
                    END IF
                ELSE
                    sprintf(szDrop, "L%i", LabelGenerator)
                    sprintf(LszTmp, "goto L%i;", LabelGenerator++)
                    szDrop$ += ":"
                    FPRINT FP_WRITE, Scoot$, LszTmp$
                    SelectState[StateIdx].CaseFlag--
                END IF
                CALL BumpDown("Unbalanced SELECT")
                FPRINT FP_WRITE, Scoot$, "}"
                CALL BumpDown("Unbalanced SELECT")
            END IF

            SelectState[StateIdx].CaseFlag++

            IF m_iMatchLft(CaseVar$, " BAND ") THEN
                SelectState[StateIdx].NoBreak = 1
                Src$ = "IF " + gTmpStr$ + CaseVar$ + " Then "
            ELSE
                IF INCHR("<>=", gTmpStr$) AND NOT IsQuoted(gTmpStr$) THEN
                    Src$ = "IF " + CaseVar$ + gTmpStr$ + " Then "
                ELSE
                    Src$ = "IF " + CaseVar$ + " = " + gTmpStr$ + " Then "
                END IF
            END IF

            Inject(Src$)

            IF iFallThrough THEN Inject(szDrop$)
            iFallThrough = FALSE

        CASE "select"
            LoopType[++LoopTypeCnt].iLoopType = lt_SELECT
            LoopType[LoopTypeCnt].iJumpTo = LabelGenerator++
            CALL Generate_Goto(LoopTypeCnt, 0)
            LoopType[LoopTypeCnt].iLoopLine = LineNum[FileNdx]
            CALL BuildStr(3, Ndx, CaseVar$)
            CALL PushSelectState(CaseVar$)
            SelectState[StateIdx].iStartCase = 1
            SelectState[StateIdx].CaseFlag = 0
            SelectState[StateIdx].iJumpTo = LoopType[LoopTypeCnt].iJumpTo
            iFallThrough = FALSE

        CASE "caseelse"
            IF SelectState[StateIdx].iStartCase = 0 THEN
                CALL InBlockReSet
            END IF

            CALL InBlockSet
            SelectState[StateIdx].iStartCase = 0
            SelectState[StateIdx].CaseElseFlag = TRUE
            IF SelectState[StateIdx].CaseFlag THEN
                CALL BumpDown("Unbalanced SELECT")
                FPRINT FP_WRITE, Scoot$, "}"
                CALL BumpDown("Unbalanced SELECT")
                FPRINT FP_WRITE, Scoot$, "else"
                CALL BumpUp
                FPRINT FP_WRITE, Scoot$, "{"
                CALL BumpUp
            END IF

        CASE "endselect"
            IF SelectState[StateIdx].iStartCase = 0 THEN
                CALL InBlockReSet
            END IF

            IF LoopTypeCnt = 0 THEN
                Abort("Too many end loops")
            END IF

            IF LoopType[LoopTypeCnt--].iLoopType <> lt_SELECT THEN
                STATIC sErr$

                sErr$ = LoopTypeName$(LoopType[LoopTypeCnt+1].iLoopType) + " at" + STR$(LoopType[LoopTypeCnt+1].iLoopLine) + " closed with END SELECT"
                Abort(sErr$)
            END IF

            IF SelectState[StateIdx].CaseFlag = 0 THEN
                IF SelectState[StateIdx].CaseElseFlag = 0 THEN
                    CALL Abort("Missing case statement before select end")
                ELSE
                    CALL Abort("Missing case statement before case else")
                END IF
            END IF

            CALL BumpDown("Unbalanced SELECT")
            FPRINT FP_WRITE, Scoot$, "}"
            CALL BumpDown("Unbalanced SELECT")

            IF SelectState[StateIdx].CaseFlag > 1 THEN
                STATIC LszTmp$
                sprintf(LszTmp, "L%i:;", SelectState[StateIdx].iJumpTo)
                FPRINT FP_WRITE, CRLF$, LszTmp$, CRLF$
            END IF

            SelectState[StateIdx].NoBreak = SelectState[StateIdx].CaseElseFlag = 0
            CALL PopSelectState(CaseVar$)

        CASE "for"
            IF m_iMatchWrd(Stk$[2], "each") THEN  ' "each" becomes reserved keyword
                ' beginning of for each - collections support
                DIM RAW foreachlocal$
                DIM RAW temp_parms$
                DIM RAW ComVar$

                ComVar$ = Stk$[3]
                Use_COM_Collections = Use_COM = ComSwitchON = TRUE
                FPRINT FP_WRITE, Scoot$, " VariantClear(&COM_ack_var);"
                FPRINT FP_WRITE, Scoot$, " COM_enum_var = NULL;"
                FPRINT FP_WRITE, Scoot$, " COM_long_coll = 0;"
                IF NOT IsVariableComObject(ComVar$) THEN FPRINT FP_WRITE, Scoot$, "OBJECT ", ComVar$, ";"
                FPRINT FP_WRITE, Scoot$, "ZeroMemory((PVOID)&", ComVar$, ",sizeof(OBJECT));"
                LoopLocalVar[LoopLocalCnt++] = 0
                COM_FOREACH_enumerator = TRUE
                foreachlocal$ = MID$(Src$, INSTR(Src$, " in ", 1, 1) + 3)
                IF NOT IsVariableComObject(ComVar$) THEN Add_Com_Local_Var(ComVar$)

                IF INCHR(foreachlocal$, ".") THEN
                    COM_Parse_GetProperty("COM_ack_var", foreachlocal$)
                    temp_parms$ = TRIM$(EXTRACT$(foreachlocal$, "."))
                ELSE
                    temp_parms$ = TRIM$(foreachlocal$)
                END IF

                COM_FOREACH_enumerator = FALSE

                FPRINT FP_WRITE, Scoot$, "COM_GetEnum_iface = TRUE;"
                FPRINT FP_WRITE, Scoot$, "COM_invoke(&", temp_parms$, ", L", DDQ$, ","
                FPRINT FP_WRITE, Scoot$, "DISPATCH_PROPERTYGET|DISPATCH_METHOD, &COM_ack_var);"
                FPRINT FP_WRITE, Scoot$, "COM_reset_disp_chain(&", temp_parms$ , ");"
                FPRINT FP_WRITE, Scoot$, "COM_GetEnum_iface = FALSE;\n"

                FPRINT FP_WRITE, Scoot$, "for(;;) { // for each construction ..."
                CALL BumpUp
                FPRINT FP_WRITE, Scoot$, "if (FAILED(COM_last_HR)) {"
                FPRINT FP_WRITE, Scoot$, "  COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("Get object enumerator: No Collections!"), "));"
                FPRINT FP_WRITE, Scoot$, "  break;"
                FPRINT FP_WRITE, Scoot$, "} "

                FPRINT FP_WRITE, Scoot$, "if (COM_ack_var.vt != VT_DISPATCH && COM_ack_var.vt != VT_UNKNOWN) {"
                FPRINT FP_WRITE, Scoot$, "  COM_last_HR = E_NOINTERFACE;"
                FPRINT FP_WRITE, Scoot$, "  COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("Enum interface not available! Collections unavailable!"), "));"
                FPRINT FP_WRITE, Scoot$, "  VariantClear(&COM_ack_var);"
                FPRINT FP_WRITE, Scoot$, "  break;"
                FPRINT FP_WRITE, Scoot$, "} "

                FPRINT FP_WRITE, Scoot$, "if (COM_ack_var.vt == VT_DISPATCH) {"

                CALL BumpUp

                FPRINT FP_WRITE, Scoot$, "  #ifdef __cplusplus"
                FPRINT FP_WRITE, Scoot$, "  COM_last_HR = COM_ack_var.pdispVal"
                FPRINT FP_WRITE, Scoot$, "  ->QueryInterface(IID_IEnumVARIANT, (void **)&COM_enum_var);"
                FPRINT FP_WRITE, Scoot$, "  #else"
                FPRINT FP_WRITE, Scoot$, "   COM_last_HR = COM_ack_var.pdispVal->lpVtbl"
                FPRINT FP_WRITE, Scoot$, "   ->QueryInterface(COM_ack_var.pdispVal,"
                FPRINT FP_WRITE, Scoot$, "   &IID_IEnumVARIANT, (void **)&COM_enum_var);"
                FPRINT FP_WRITE, Scoot$, "#endif\n"
                FPRINT FP_WRITE, Scoot$, "if (FAILED(COM_last_HR)) {"
                FPRINT FP_WRITE, Scoot$, "   COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("QueryInterface: Get enum variant: No Collections!"), "));"
                FPRINT FP_WRITE, Scoot$, "   VariantClear(&COM_ack_var);"
                FPRINT FP_WRITE, Scoot$, "   break;"
                FPRINT FP_WRITE, Scoot$, "} "

                CALL BumpDown("")

                FPRINT FP_WRITE, Scoot$, "} else if (COM_ack_var.vt == VT_UNKNOWN) {"

                CALL BumpUp

                FPRINT FP_WRITE, Scoot$, "  #ifdef __cplusplus"
                FPRINT FP_WRITE, Scoot$, "    COM_last_HR = COM_ack_var.punkVal"
                FPRINT FP_WRITE, Scoot$, "     ->QueryInterface(IID_IEnumVARIANT, (void **)&COM_enum_var);"
                FPRINT FP_WRITE, Scoot$, "  #else"
                FPRINT FP_WRITE, Scoot$, "    COM_last_HR = COM_ack_var.punkVal->lpVtbl"
                FPRINT FP_WRITE, Scoot$, "    ->QueryInterface(COM_ack_var.punkVal, "
                FPRINT FP_WRITE, Scoot$, "    &IID_IEnumVARIANT, (void **)&COM_enum_var);"
                FPRINT FP_WRITE, Scoot$, "#endif\n"
                FPRINT FP_WRITE, Scoot$, "if (FAILED(COM_last_HR)) {"
                FPRINT FP_WRITE, Scoot$, "  COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("QueryInterface: Get enum variant: No Collections!"), "));"
                FPRINT FP_WRITE, Scoot$, "  VariantClear(&COM_ack_var);"
                FPRINT FP_WRITE, Scoot$, "  break;"
                FPRINT FP_WRITE, Scoot$, "} "

                CALL BumpDown("")

                FPRINT FP_WRITE, Scoot$, "} "
                FPRINT FP_WRITE, Scoot$, "VariantClear(&COM_ack_var);"
                FPRINT FP_WRITE, Scoot$, "break;"
                FPRINT FP_WRITE, Scoot$, "}\n"

                FPRINT FP_WRITE, Scoot$, "  while(COM_enum_var) {"
                FPRINT FP_WRITE, Scoot$, "    BCX_SetNothing(&", ComVar$, ");"
                FPRINT FP_WRITE, Scoot$, "    #ifdef __cplusplus"
                FPRINT FP_WRITE, Scoot$, "      COM_last_HR = COM_enum_var"
                FPRINT FP_WRITE, Scoot$, "     ->Next(1, &", ComVar$, ".pObjects[0], &COM_long_coll);"
                FPRINT FP_WRITE, Scoot$, "    #else"
                FPRINT FP_WRITE, Scoot$, "      COM_last_HR = COM_enum_var->lpVtbl"
                FPRINT FP_WRITE, Scoot$, "     ->Next(COM_enum_var, 1, &", ComVar$, ".pObjects[0], &COM_long_coll);"
                FPRINT FP_WRITE, Scoot$, "    #endif"
                FPRINT FP_WRITE, Scoot$, "    if (FAILED(COM_last_HR)) {"
                FPRINT FP_WRITE, Scoot$, "      COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("Enumeration failed! No Collections!"), "));"
                FPRINT FP_WRITE, Scoot$, "    #ifdef __cplusplus"
                FPRINT FP_WRITE, Scoot$, "       if(COM_enum_var) COM_enum_var->Release();"
                FPRINT FP_WRITE, Scoot$, "    #else"
                FPRINT FP_WRITE, Scoot$, "       if(COM_enum_var) COM_enum_var->lpVtbl"
                FPRINT FP_WRITE, Scoot$, "       ->Release(COM_enum_var);"
                FPRINT FP_WRITE, Scoot$, "    #endif"
                FPRINT FP_WRITE, Scoot$, "    COM_enum_var = NULL;"
                FPRINT FP_WRITE, Scoot$, "    break;"
                FPRINT FP_WRITE, Scoot$, "  } "

                FPRINT FP_WRITE, Scoot$, "  if (", ComVar$, ".pObjects[0].vt != VT_DISPATCH)"
                FPRINT FP_WRITE, Scoot$, "    {"
                FPRINT FP_WRITE, Scoot$, "      VariantClear(&", ComVar$, ".pObjects[0]);"
                FPRINT FP_WRITE, Scoot$, "      COM_long_coll = 0;"
                FPRINT FP_WRITE, Scoot$, "    }"
                FPRINT FP_WRITE, Scoot$, "  else"
                FPRINT FP_WRITE, Scoot$, "    { "
                FPRINT FP_WRITE, Scoot$, "      ", ComVar$, ".pStatus = TRUE;"
                FPRINT FP_WRITE, Scoot$, "      ", ComVar$, ".ipointer = 0;"
                FPRINT FP_WRITE, Scoot$, "      COM_objects_cnt++;"
                FPRINT FP_WRITE, Scoot$, "    }"

                FPRINT FP_WRITE, Scoot$, "  if (0 == COM_long_coll) {"
                FPRINT FP_WRITE, Scoot$, "  #ifdef __cplusplus"
                FPRINT FP_WRITE, Scoot$, "     if(COM_enum_var) COM_enum_var->Release();"
                FPRINT FP_WRITE, Scoot$, "  #else"
                FPRINT FP_WRITE, Scoot$, "     if(COM_enum_var) COM_enum_var->lpVtbl"
                FPRINT FP_WRITE, Scoot$, "     ->Release(COM_enum_var);"
                FPRINT FP_WRITE, Scoot$, "  #endif"
                FPRINT FP_WRITE, Scoot$, "  BCX_SetNothing(&", ComVar$, ");"
                FPRINT FP_WRITE, Scoot$, "  COM_enum_var = NULL;"
                FPRINT FP_WRITE, Scoot$, "  break;"
                FPRINT FP_WRITE, Scoot$, "  }"
                CALL BumpUp
                '******************************************************
            ELSE '        this is a NORMAL For-Next Loop
                '******************************************************
                DIM FFlg
                DIM For1
                DIM For2
                DIM For3
                DIM For4
                DIM Reg$
                DIM xxx$
                DIM yyy$
                DIM zzz$
                DIM qqq$
                DIM Lvar$

                '=============================================================
                '     Allow VBNET/VBA style: "FOR i AS datatype = 1 TO 10"
                '       Implemented by MrBcx June 2025 in version 828
                '=============================================================
                DIM Scratch$
                Scratch$ = ""
                FOR zz AS LONG = 1 TO Ndx
                    Scratch$ += SPC$ + Stk$[zz]
                NEXT
                Scratch$ = VB2BCX(Scratch$)
                FastLexer(Scratch$, SPC$, c_FULLSET)
                '=============================================================


                '******************************************************
                FOR i AS INT = Ndx TO 1 STEP -1
                    IF m_iMatchWrd(Stk$[i], "step") THEN
                        FFlg = TRUE
                        EXIT FOR
                    END IF
                NEXT

                IF NOT FFlg THEN
                    INCR Ndx
                    Stk$[Ndx] = "step"
                    INCR Ndx
                    Stk$[Ndx] = "1"
                END IF
                '******************************************************
                For_Next_Error_Detected = FALSE

                FOR i AS INT = 1 TO Ndx
                    IF *Stk$[i] = ASC("=") THEN For_Next_Error_Detected = TRUE
                NEXT

                IF For_Next_Error_Detected = FALSE THEN Abort("Missing =")
                '******************************************************
                For_Next_Error_Detected = FALSE

                FOR i AS INT = 1 TO Ndx
                    IF m_iMatchWrd(Stk$[i], "to") THEN For_Next_Error_Detected = TRUE
                NEXT

                IF For_Next_Error_Detected = FALSE THEN Abort("Missing TO")
                '******************************************************

                Reg$ = LCASE$(Stk$[2])

                SELECT CASE Reg$

                    CASE "char", "sbyte"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "signed char "

                    CASE "uchar", "ubyte", "byte"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "unsigned char "

                    CASE "int", "fint"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "int "

                    CASE  "uint"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "unsigned int "

                    CASE  "long"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "long "

                    CASE "ulong"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "unsigned long "

                    CASE "llong", "longlong"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "long long "

                    CASE "ulonglong", "uint64"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "unsigned long long "

                    CASE "short"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "short "

                    CASE "ushort"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "unsigned short "

                    CASE "single", "float"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "float "

                    CASE "size_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "size_t "

                    CASE "ssize_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "SSIZE_T"

                    CASE "int8_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "int8_t "

                    CASE "int16_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "int16_t "

                    CASE "int32_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "int32_t "

                    CASE "int64_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "int64_t "

                    CASE "uint8_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "uint8_t "

                    CASE "uint16_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "uint16_t "

                    CASE "uint32_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "uint32_t "

                    CASE "uint64_t"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "uint64_t "

                    CASE "double"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "double "

                    CASE "ldouble"
                        Reg$ = SPC$
                        LoopLocalVar[LoopLocalCnt++] = 1
                        Lvar$ = "long double "
                        Use_Ldouble = TRUE

                    CASE ELSE
                        Reg$ = ""
                        LoopLocalVar[LoopLocalCnt++] = 0
                END SELECT

                IF *Reg$ THEN
                    FOR j AS INT = 3 TO Ndx
                        Stk$[j-1] = Stk$[j]
                    NEXT
                    DECR Ndx
                END IF

                '******************************************************
                ' Every statement now conforms to the following:
                ' FOR xxx = yyy TO zzz STEP qqq
                '******************************************************

                FOR i AS INT = 2 TO Ndx
                    IF Stk$[i] = "=" THEN
                        For1 = i-1       ' xxx spans from Stk$[2] to Stk$[For1]
                        EXIT FOR
                    END IF
                NEXT

                FOR i AS INT = For1 + 2 TO Ndx
                    IF m_iMatchWrd(Stk$[i], "to") THEN
                        For2 = i-1       ' yyy spans from Stk$[For1+2] to Stk$[For2]
                        EXIT FOR
                    END IF
                NEXT

                FOR i AS INT = For2 + 2 TO Ndx
                    IF m_iMatchWrd(Stk$[i], "step") THEN
                        For3 = i-1       ' zzz spans from Stk$[For2+2] to Stk$[For3]
                        EXIT FOR
                    END IF
                NEXT

                For4 = For3 + 2          ' qqq spans from Stk$[For4] to Stk$[Ndx]

                CALL BuildCleanStr(2, For1, xxx$)
                CALL BuildCleanStr(For1+2, For2, yyy$)
                CALL BuildCleanStr(For2+2, For3, zzz$)
                CALL BuildCleanStr(For4, Ndx, qqq$)

                Reg$ = Lvar$

                IF IsDecimalNumber (qqq$) THEN
                    IF LEFTSTR(qqq$, "-") THEN
                        IF qqq$ = "1" THEN
                            FPRINT FP_WRITE, Scoot$, "for(", Reg$, xxx$, "=", yyy$, "; ", xxx$, ">=" , zzz$, "; " , xxx$, "++)"
                        ELSE
                            IF qqq$ = "1" THEN
                                FPRINT FP_WRITE, Scoot$, "for(", Reg$, xxx$, "=", yyy$, "; ", xxx$, ">=" , zzz$, "; " , xxx$, "++)"
                            ELSE
                                FPRINT FP_WRITE, Scoot$, "for(", Reg$, xxx$, "=", yyy$, "; ", xxx$, ">=" , zzz$, "; " , xxx$, "+=" , qqq$, ")"
                            END IF
                        END IF
                    ELSE
                        IF qqq$ = "1" THEN
                            FPRINT FP_WRITE, Scoot$, "for(", Reg$, xxx$, "=", yyy$, "; ", xxx$, "<=" , zzz$, "; " , xxx$, "++)"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "for(", Reg$, xxx$, "=", yyy$, "; ", xxx$, "<=" , zzz$, "; " , xxx$, "+=" , qqq$, ")"
                        END IF
                    END IF
                ELSE
                    FPRINT FP_WRITE, Scoot$, "for(", Reg$, xxx$, "=", yyy$, "; (", qqq$, ">=0 ? ", xxx$, "<=" , zzz$, " : ", xxx$, ">=", zzz$, "); " , xxx$, "+=" , qqq$, ")"
                END IF

                CALL BumpUp
                FPRINT FP_WRITE, Scoot$, "{"
                CALL BumpUp
            END IF

            LoopType[++LoopTypeCnt].iLoopType = lt_FORNEXT
            LoopType[LoopTypeCnt].iJumpTo = LabelGenerator++
            LoopType[LoopTypeCnt].szUseNeedLabel$ = ""
            LoopType[LoopTypeCnt].iLoopLine = LineNum[FileNdx]

            CALL InBlockSet

        CASE "next"
            CALL InBlockReSet

            IF LoopTypeCnt = 0 THEN
                CALL Abort("Too many end loops")
            END IF

            IF LoopType[LoopTypeCnt].iLoopType <> lt_FORNEXT THEN
                DIM sErr$ = LoopTypeName$(LoopType[LoopTypeCnt].iLoopType) + " at" + STR$(LoopType[LoopTypeCnt].iLoopLine) + " closed with NEXT"
                CALL Abort(sErr$)
            END IF

            CALL BumpDown("Unbalanced FOR/NEXT")
            FPRINT FP_WRITE, Scoot$, "}"
            DECR LoopLocalVar[LoopLocalCnt]

            IF LoopType[LoopTypeCnt].szUseNeedLabel$ <> "" THEN
                FPRINT FP_WRITE, LoopType[LoopTypeCnt].szUseNeedLabel$
            END IF

            DECR LoopTypeCnt
            IF LoopLocalCnt < 0 THEN Abort ("Next without For")
            CALL BumpDown("Unbalanced FOR/NEXT")

        CASE "beginblock"
            CALL InBlockSet
            FPRINT FP_WRITE, Scoot$, "{"
            CALL BumpUp

        CASE "endblock"
            CALL InBlockReSet
            CALL BumpDown("Unbalanced BLOCK/END BLOCK")
            FPRINT FP_WRITE, Scoot$, "}"

        CASE "call"
            STATIC LTmp$
            BuildCleanStr(2, Ndx, LTmp$)
            IF NOT m_iMatchRgt(LTmp$, ")") THEN
                LTmp$ += "()"
            END IF
            LTmp$ += ";"
            FPRINT FP_WRITE, Scoot$, LTmp$

        CASE "continue"
            FPRINT FP_WRITE, Scoot$, "continue;"

        CASE "end"
            IF Ndx = 1 THEN
                InsertTokens(1, 2, "=", "0")
            END IF

            IF Stk$[2] = "=" THEN
                IF Use_Wingui = FALSE THEN
                    FPRINT FP_WRITE, Scoot$, "fflush(stdout);"
                END IF
                FPRINT FP_WRITE, Scoot$, "ExitProcess("; ' Suppress CRLF
                Stk$[++Ndx] = ");"
                CALL WriteCleanTokens(3, Ndx)
                EXIT SELECT
            END IF

            IF m_iMatchWrd(Stk$[2], "if") THEN
                CALL BumpDown("Unbalanced IF/END IF")
                FPRINT FP_WRITE, Scoot$, "}"
                CALL BumpDown("Unbalanced IF/END IF")
                EXIT SELECT
            END IF

        CASE "endif"
            CALL BumpDown("Extra unindents at ENDIF")
            FPRINT FP_WRITE, Scoot$, "}"
            CALL BumpDown("Extra unindents at ENDIF")

        CASE "endprogram"               ' Force END of main- allow inclusions outside of main
            FPRINT FP_WRITE, ""
            IF Use_Sound THEN
                FPRINT FP_WRITE, Scoot$, "midiOutClose (hMidi);"  ' Added by MrBcx 825
            END IF
            FPRINT FP_WRITE, "return EXIT_SUCCESS;    // End of main program"
            FPRINT FP_WRITE, "}\n\n"
            EndOfProgram = 1

        CASE "if"
            CALL Emit_IfCond("if", eFull)

        CASE "else"
            CALL BumpDown("Unbalanced IF/END IF")
            FPRINT FP_WRITE, Scoot$, "}"
            CALL BumpDown("Unbalanced IF/END IF")
            FPRINT FP_WRITE, Scoot$, "else"
            CALL BumpUp
            FPRINT FP_WRITE, Scoot$, "{"
            CALL BumpUp

        CASE "elseif"
            CALL BumpDown("Unbalanced IF/END IF")
            FPRINT FP_WRITE, Scoot$, "}"
            CALL BumpDown("Unbalanced IF/END IF")
            CALL Emit_IfCond("else if", eFull)

        CASE "xfor"    ' XFOR ... WHILE/UNTIL ... BY ...
            DIM iBy
            DIM iUntil
            DIM iWhile
            STATIC Ndx2
            STATIC iPB
            STATIC iLast
            STATIC Stak$[128]
            STATIC sClose$
            STATIC lszType$

            ' Basic syntax check
            FOR ii AS INT = 2 TO Ndx
                IF m_iMatchWrd(Stk$[ii], "while") THEN iWhile = ii
                IF m_iMatchWrd(Stk$[ii], "until") THEN iUntil = ii
                IF m_iMatchWrd(Stk$[ii], "by") THEN iBy = ii
            NEXT

            IF iWhile = 0 AND iUntil = 0 THEN CALL Abort("Missing WHILE or UNTIL in XFOR")
            IF iWhile AND iUntil THEN CALL Abort("Can't have both WHILE and UNTIL in XFOR")
            IF iBy = 0 THEN CALL Abort("Missing BY in XFOR")

            iLast = iWhile + iUntil
            lszType$ = ""
            IF iLast > 2 THEN   ' Have initializers
                DIM i = 2
                DIM j = 3
                DO
                    DO WHILE Stk$[j] <> "="
                        INCR j
                    LOOP
                    IF j - i > 1 THEN
                        IF lszType$ <> "" THEN lszType$ += ": RAW "
                        lszType$ += Stk$[j-1]
                        lszType$ += " AS"
                        DO WHILE i < j-1
                            lszType$ += SPC$
                            lszType$ += Stk$[i]
                            Stk$[i++] = ""
                        LOOP
                    END IF
                    i = j + 1

                    iPB = 0
                    DO WHILE i <= iLast
                        IF *Stk$[i] = ASC("(") THEN INCR iPB
                        IF *Stk$[i] = ASC(")") THEN DECR iPB
                        IF *Stk$[i] = ASC("[") THEN INCR iPB
                        IF *Stk$[i] = ASC("]") THEN DECR iPB
                        IF iPB = 0 AND Stk$[i] = "," THEN EXIT DO
                        INCR i
                    LOOP
                    INCR i
                    j = i + 1
                LOOP UNTIL i >= iLast
            END IF
            Stak$[1] = "for("
            sClose$ = "; "

            DIM jj = 2
            DIM ii = 2

            DO WHILE ii <= Ndx
                IF Stk$[ii] <> "" THEN
                    IF m_iMatchWrd(Stk$[ii], "while") THEN
                        Stk$[ii] = "; "
                        iLast = jj
                    END IF
                    IF m_iMatchWrd(Stk$[ii], "until") THEN
                        Stk$[ii] = "; !("
                        sClose$ = ");"
                        iLast = jj
                    END IF
                    IF m_iMatchWrd(Stk$[ii], "by")    THEN
                        Stk$[ii] = sClose$
                        iBy = jj
                    END IF
                    Stak$[jj] = Stk$[ii]
                    INCR jj
                END IF
                INCR ii
            LOOP
            Ndx2 = jj-1
            IF NOTNULL(lszType$) THEN
                CALL BumpUp
                FPRINT FP_WRITE, Scoot$, "{"
                CALL InBlockSet
                lszType$ = "RAW " + lszType$
                LoopLocalVar[LoopLocalCnt++] = 1
                ii = iMatchNQ (lszType$, ": RAW ")
                DO WHILE ii
                    Src$ = LEFT$(lszType$, ii-1)
                    lszType$ = MID$(lszType$, ii+2)
                    PassOne = TRUE
                    Inject(Src$)
                    ii = iMatchNQ (lszType$, ": RAW ")
                LOOP
                Src$ = lszType$
                PassOne = TRUE
                Inject(Src$)
            ELSE
                LoopLocalVar[LoopLocalCnt++] = 0
            END IF

            Stk$[1] = "while"
            FOR k AS INT = iLast+1 TO iBy-1
                Stk$[k-iLast+1] = Stak$[k]
            NEXT

            Ndx = iBy-iLast
            Stk$[Ndx+1] = ""

            FOR m AS INT = 1 TO Ndx
                IF Stk$[m] = "&&" THEN Stk$[m] = "&& "
            NEXT

            FPRINT FP_WRITE, Scoot$;               ' Suppress CRLF
            FOR k AS INT = 1 TO Ndx2
                IF k <= iLast OR k >= iBy THEN
                    FPRINT FP_WRITE, Stak$[k];     ' Suppress CRLF
                END IF
                IF k = iLast THEN
                    CALL Emit_IfCond("while", ePart)
                END IF
            NEXT

            FPRINT FP_WRITE, ")"
            CALL BumpUp
            FPRINT FP_WRITE, Scoot$, "{"
            CALL BumpUp
            LoopType[++LoopTypeCnt].iLoopType = lt_FORXNEXT
            LoopType[LoopTypeCnt].iJumpTo = LabelGenerator++
            LoopType[LoopTypeCnt].szUseNeedLabel$ = ""
            LoopType[LoopTypeCnt].iLoopLine = LineNum[FileNdx]
            CALL InBlockSet

        CASE "xnext"
            CALL InBlockReSet

            IF LoopTypeCnt = 0 THEN
                Abort("Too many end loops")
            END IF

            IF LoopType[LoopTypeCnt].iLoopType <> lt_FORXNEXT THEN
                DIM sErr$ = LoopTypeName$(LoopType[LoopTypeCnt].iLoopType) + " at" + _
                STR$(LoopType[LoopTypeCnt].iLoopLine) + " closed with NEXT"
                Abort(sErr$)
            END IF

            CALL BumpDown("Unbalanced XFOR/XNEXT")
            FPRINT FP_WRITE, Scoot$, "}"

            IF NOTZERO(LoopLocalVar[--LoopLocalCnt]) THEN
                CALL InBlockReSet
                FPRINT FP_WRITE, Scoot$, "}"
                CALL BumpDown("Unbalanced XFOR/XNEXT")
            END IF

            IF LoopType[LoopTypeCnt].szUseNeedLabel$ <> "" THEN
                FPRINT FP_WRITE, LoopType[LoopTypeCnt].szUseNeedLabel$
            END IF

            DECR LoopTypeCnt
            IF LoopLocalCnt < 0 THEN Abort ("XNEXT without XFOR")
            CALL BumpDown("Unbalanced XFOR/XNEXT")

        CASE "do"
            CALL InBlockSet

            IF iDoWhile THEN
                LoopType[++LoopTypeCnt].iLoopType = iDoWhile
            ELSE
                LoopType[++LoopTypeCnt].iLoopType = lt_DOLOOP
            END IF
            LoopType[LoopTypeCnt].iJumpTo = LabelGenerator++
            LoopType[LoopTypeCnt].szUseNeedLabel$ = ""
            iDoWhile = 0

            LoopType[LoopTypeCnt].iLoopLine = LineNum[FileNdx]
            FPRINT FP_WRITE, Scoot$, "for(;;)"
            CALL BumpUp
            FPRINT FP_WRITE, Scoot$, "{"
            CALL BumpUp

        CASE "loop"
            CALL InBlockReSet

            IF LoopTypeCnt = 0 THEN
                Abort("Too many end loops")
            END IF

            IF iLoopCond THEN
                IF LoopType[LoopTypeCnt].iLoopType <> lt_DOLOOP THEN
                    DIM sErr$ = LoopTypeName$(LoopType[LoopTypeCnt].iLoopType) + " at" + _
                    STR$(LoopType[LoopTypeCnt].iLoopLine) + " closed with LOOP CONDITION"
                    CALL Abort(sErr$)
                END IF
            END IF

            iLoopCond = 0

            CALL BumpDown("Unbalanced DO/LOOP")
            FPRINT FP_WRITE, Scoot$, "}"

            IF LoopType[LoopTypeCnt].szUseNeedLabel$ <> "" THEN
                FPRINT FP_WRITE, LoopType[LoopTypeCnt].szUseNeedLabel$
            END IF

            DECR LoopTypeCnt
            CALL BumpDown("Unbalanced DO/LOOP")

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)
    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_ControlFlow



FUNCTION Emit_KeyboardProcs(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "input"
            CALL Emit_InputCode

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_KeyboardProcs




FUNCTION Emit_QsortIdxProcs(sWord$, FuncRetnFlag AS PINT)
    ' qsortidx idx, size_of_array, A$, key
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)

    DIM i
    DIM LTmp$, Stptr$, StMem$, StName$
    Use_BcxTempStr = TRUE
    Var$ = No_Sigil$(Stk$[2])             ' index array
    BuildCleanStr(4, Ndx-4, LTmp$)     ' allow size to be an expression

    FPRINT FP_WRITE, Scoot$, "Key = ", Stk[Ndx], ";"

    IF Var$ <> "0" THEN
        FPRINT FP_WRITE, Scoot$, "int iDx;"
        FPRINT FP_WRITE, Scoot$, "for(iDx=0; iDx<", LTmp$, "; iDx += 1) ";
        FPRINT FP_WRITE, Var$, "[iDx]=iDx;"
    END IF

    IF NOT INCHR(Stk$[Ndx-2], ".") THEN   ' Check if this is a struct sort
        Use_Idxqsort = Use_BCX_stricmp = TRUE
        FPRINT FP_WRITE, Scoot$, "pppStr = ", No_Sigil$(Stk[Ndx-2]), ";"
        FPRINT FP_WRITE, Scoot$, "qsort(", Var$, ",", LTmp$, ",sizeof(int), IdxCompare);"
    ELSE
        StMem$ = REMAIN$(No_Sigil$(Stk$[Ndx-2]), ".")
        Stptr$ = EXTRACT$(Stk$[Ndx-2], ".")

        IF CheckLocal(Stptr, ADDRESSOF(i)) <> vt_UNKNOWN THEN
            StName$ = TypeDefs[LocalVars[i].VarDef].VarName$
        ELSE
            IF CheckGlobal(Stptr, ADDRESSOF(i)) <> vt_UNKNOWN THEN
                StName$ = TypeDefs[GlobalVars[i].VarDef].VarName$
            END IF
        END IF

        IF Var$ <> "0" THEN
            Use_IdxqsortSt = Use_BCX_stricmp = TRUE
            FPRINT FP_WRITE, Scoot$, "cmp1 =(char*)(", Stptr$ , ") + offsetof(", StName$, ",", StMem$, ");"
            FPRINT FP_WRITE, Scoot$, "StructSize = sizeof(", StName$, ");"
            FPRINT FP_WRITE, Scoot$, "qsort(", Var$, ",", LTmp$, ", sizeof(int), IdxCompareSt);"
        ELSE
            Use_PtrqsortSt = Use_BCX_stricmp = TRUE
            FPRINT FP_WRITE, Scoot$, "OffSet = offsetof(", StName$, ",", StMem$, ");"
            FPRINT FP_WRITE, Scoot$, "qsort(", Stptr$, ",", LTmp$, ", sizeof(", StName$, "), PtrCompareSt);"
        END IF
    END IF
    FUNCTION = 0
END FUNCTION ' Emit_QsortIdxProcs


FUNCTION Emit_QsortProcs(sWord$, FuncRetnFlag AS PINT)
    ' qsort [dynamic] A$,size_of_array[,ascending|descending][,NATURAL]
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)

    DIM iAlphaNumeric = FALSE
    DIM LTmp$
    DIM order = 0
    DIM QST = 0
    DIM vt

    Use_BcxTempStr = TRUE

    IF m_iMatchWrd(Stk$[Ndx], "sensitive") THEN
        Use_Strqsorts = TRUE
        DECR Ndx, 2
    END IF

    IF m_iMatchWrd(Stk$[2], "dynamic") THEN
        QST = TRUE
        LShiftStk(2)
    END IF

    IF m_iMatchWrd(Stk$[Ndx], "natural") THEN
        iAlphaNumeric = Use_AlphaNumeric = TRUE
        DECR Ndx, 2
    END IF

    IF m_iMatchWrd(Stk$[Ndx], "ascending")  THEN
        order = 2
        DECR Ndx, 2
    END IF

    IF m_iMatchWrd(Stk$[Ndx], "descending") THEN
        order = 1
        DECR Ndx, 2
    END IF

    IF order = 0 THEN order = 2      ' default to ascending
    CALL BuildStr(4, Ndx, LTmp$)     ' allow size to be an expression
    Var$ = No_Sigil$(Stk$[2])
    vt = DataType(Stk$[2])

    IF vt <> vt_STRVAR AND vt <> vt_INTEGER AND vt <> vt_SINGLE AND vt <> vt_DOUBLE THEN
        vt = CheckType(Stk$[2])
    END IF

    FPRINT FP_WRITE, Scoot$, "qsort(", Var$, ",", No_Sigil$(LTmp$); ' Suppress CRLF

    SELECT CASE vt

        CASE vt_STRVAR
            IF NOT QST THEN
                IF order = 1 THEN
                    IF iAlphaNumeric THEN
                        FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),AlphaNumericD);"
                        Use_AlphaNumericD = TRUE
                    ELSE
                        IF Use_Strqsorts = TRUE THEN
                            FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),StrCompareDs);"
                            Use_Strqsortds = TRUE
                            Use_Strqsorts = FALSE
                        ELSE
                            FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),StrCompareD);"
                            Use_Strqsortd = Use_BCX_stricmp = TRUE
                        END IF
                    END IF
                ELSE
                    IF iAlphaNumeric THEN
                        FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),AlphaNumericA);"
                        Use_AlphaNumericA = TRUE
                    ELSE
                        IF Use_Strqsorts = TRUE THEN
                            FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),StrCompareAs);"
                            Use_Strqsortas = TRUE
                            Use_Strqsorts = FALSE
                        ELSE
                            FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),StrCompareA);"
                            Use_Strqsorta = Use_BCX_stricmp = TRUE
                        END IF
                    END IF
                END IF
            ELSE
                IF order = 1 THEN
                    IF iAlphaNumeric THEN
                        FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),DynAlphaNumericD);"
                        Use_DynAlphaNumericD = TRUE
                    ELSE
                        IF Use_Strqsorts = TRUE THEN
                            FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),DynStrCompareDs);"
                            Use_DynStrqsortds = TRUE
                            Use_Strqsorts = FALSE
                        ELSE
                            FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),DynStrCompareD);"
                            Use_DynStrqsortd = Use_BCX_stricmp = TRUE
                        END IF
                    END IF
                ELSE
                    IF iAlphaNumeric THEN
                        FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),DynAlphaNumericA);"
                        Use_DynAlphaNumericA = TRUE
                    ELSE
                        IF Use_Strqsorts = TRUE THEN
                            FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),DynStrCompareAs);"
                            Use_DynStrqsortas = TRUE
                            Use_Strqsorts = FALSE
                        ELSE
                            FPRINT FP_WRITE, ",sizeof(", Var$, "[0]),DynStrCompareA);"
                            Use_DynStrqsorta = Use_BCX_stricmp = TRUE
                        END IF
                    END IF
                END IF
            END IF

        CASE vt_INTEGER
            IF order = 1 THEN
                FPRINT FP_WRITE, ",sizeof(int), NumCompareDint);"
                Use_Numqsortdint = TRUE
            ELSE
                FPRINT FP_WRITE, ",sizeof(int), NumCompareAint);"
                Use_Numqsortaint = TRUE
            END IF

        CASE vt_SINGLE
            IF order = 1 THEN
                FPRINT FP_WRITE, ",sizeof(float), NumCompareDfloat);"
                Use_Numqsortdfloat = TRUE
            ELSE
                FPRINT FP_WRITE, ",sizeof(float), NumCompareAfloat);"
                Use_Numqsortafloat = TRUE
            END IF

        CASE vt_DOUBLE
            IF order = 1 THEN
                FPRINT FP_WRITE, ",sizeof(double), NumCompareDdouble);"
                Use_Numqsortddouble = TRUE
            ELSE
                FPRINT FP_WRITE, ",sizeof(double), NumCompareAdouble);"
                Use_Numqsortadouble = TRUE
            END IF

        CASE ELSE
            IF order = 1 THEN
                FPRINT FP_WRITE, ",sizeof(int), NumCompareDint);"
                Use_Numqsortdint = TRUE
            ELSE
                FPRINT FP_WRITE, ",sizeof(int), NumCompareAint);"
                Use_Numqsortaint = TRUE
            END IF
    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_QsortProcs



FUNCTION Emit_template(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$
        CASE "template"
            ' template <typename Container, typename ValueType, int nPropType> class property
            DIM RAW LTmp$
            UsingTemplate = TRUE
            CALL BuildDelimStr(1, Ndx, LTmp$)
            FPRINT FP_UDT, LTmp$
            FP_WRITE = FP_UDT

        CASE "endtemplate"
            UsingTemplate = FALSE
    END SELECT
    *FuncRetnFlag = 0
    FUNCTION = 0
END FUNCTION ' Emit_template




SUB AddProto(szProto$)
    IF UsingTemplate = FALSE THEN
        INCR ProtoCnt

        IF ProtoCnt = c_MaxProtoType THEN
            CALL Abort("Maximum Prototypes Exceeded.")
        END IF

        ProtoType[ProtoCnt].Prototype$ = szProto$
    END IF
END SUB ' AddProto




FUNCTION Emit_Const (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)

    DIM Buffer$

    IF InClass THEN
        FOR i AS INT = 1 TO Ndx
            IF IsValidName(Stk$[i]) AND IsValidName(Stk$[i + 1]) THEN Stk$[i] += SPC$
            Buffer$ += Stk$[i]
        NEXT
        FPRINT FP_UDT, Scoot$, Buffer$, ";"
    ELSE
        DIM AS INT Depth
        DIM AS INT j
        DIM AS INT SegCount
        DIM AS INT SegEnd[64]
        DIM AS INT SegStart[64]

        SegCount = 0
        Depth = 0
        SegStart[0] = 2

        ' --- Stage 1: Final Refined Segment Splitting ---
        FOR i AS LONG = 2 TO Ndx
            IF Stk$[i] = "(" THEN
                INCR Depth
            ELSEIF Stk$[i] = ")" THEN
                DECR Depth
            ELSEIF Depth = 0 AND Stk$[i] = "," THEN
                ' A comma splits if the NEXT sequence looks like a new assignment:
                ' 1. [Name] [=]  -> e.g., B = 20
                ' 2. [Name] [(] ... [=] -> e.g., MULT(X,Y) = ...

                DIM AS INT LooksLikeNewAssignment
                LooksLikeNewAssignment = FALSE

                IF i + 1 <= Ndx THEN
                    IF IsValidName(Stk$[i + 1]) THEN
                        DIM AS LONG k
                        DIM AS LONG TempDepth
                        TempDepth = 0
                        FOR k = i + 2 TO Ndx
                            IF Stk$[k] = "(" THEN INCR TempDepth
                            IF Stk$[k] = ")" THEN DECR TempDepth

                            ' If we find an '=' at the same depth as the name,
                            ' it's a new definition (Constant or Macro).
                            IF TempDepth = 0 AND Stk$[k] = "=" THEN
                                LooksLikeNewAssignment = TRUE
                                EXIT FOR
                            END IF

                            ' If we hit another top-level comma before an '=',
                            ' then the previous token wasn't a new definition.
                            IF TempDepth = 0 AND Stk$[k] = "," THEN EXIT FOR
                        NEXT
                    END IF
                END IF

                IF LooksLikeNewAssignment THEN
                    SegEnd[SegCount] = i - 1
                    INCR SegCount
                    SegStart[SegCount] = i + 1
                END IF
            END IF
        NEXT

        SegEnd[SegCount] = Ndx
        INCR SegCount

        ' --- Stage 2: Process Segments ---
        FOR i AS LONG = 0 TO SegCount - 1
            DIM AS INT segS, segE
            segS = SegStart[i]
            segE = SegEnd[i]

            IF segS > segE THEN ITERATE

            Stk$[1] = ""

            ' Register macro names for the translator
            IF segE >= segS + 1 THEN
                IF Stk$[segS + 1] = "(" THEN
                    IF c_MaxMacros = MacroCount THEN
                        CALL Abort("Max Const Macros exceeded.")
                    END IF
                    ConstMacro$[MacroCount] = Stk$[segS]
                    INCR MacroCount
                END IF
            END IF

            DIM AS LONG CurrentIdx
            DIM AS LONG FoundLocalEquals
            FoundLocalEquals = FALSE

            ' Extract LHS (everything before the first '=')
            FOR CurrentIdx = segS TO segE
                IF FoundLocalEquals = FALSE AND *Stk$[CurrentIdx] = ASC("=") THEN
                    FoundLocalEquals = TRUE
                    INCR CurrentIdx
                    EXIT FOR
                ELSE
                    IF IsDecimalNumber(Stk$[CurrentIdx]) THEN Stk$[1] += SPC$
                    Stk$[1] += Stk$[CurrentIdx]
                END IF
            NEXT

            Stk$[1] = "#define " + No_Sigil$(Stk$[1]) + SPC$

            ' Build RHS (everything after the first '=')
            Buffer$ = ""
            FOR j = CurrentIdx TO segE
                IF NOT IsQuoted(Stk$[j]) THEN REMOVE "$" FROM Stk$[j]

                IF j < segE THEN
                    IF (IsValidName(Stk$[j]) AND IsValidName(Stk$[j + 1]))  OR  _
                        ((IsValidName(Stk$[j]) OR IsDecimalNumber(Stk$[j])) AND _
                    IsDecimalNumber(Stk$[j + 1])) THEN Stk$[j] += SPC$
                END IF
                Buffer$ += Stk$[j]
            NEXT

            WHILE LEN(Stk$[1]) < 45             ' 838 MrBcx -- New formatting improvement
                Stk$[1] += SPC$
            END WHILE

            Buffer$ = SPC$ + Stk$[1] + Buffer$
            REPLACE "( " WITH "(" IN Buffer$

            ' --- Stage 3: Emission ---
            IF InConditional THEN
                IF InFunction THEN
                    FPRINT FP_WRITE, Buffer$
                ELSE
                    IF ConstLastDef$ <> "FP_CST" THEN
                        FPRINT FP_CST, InIfDef$, "// FP_CST"
                        ConstLastDef$ = "FP_CST"
                    END IF
                    FPRINT FP_CST, Buffer$
                END IF
            ELSE
                FPRINT FP_CST, Buffer$
            END IF
        NEXT
    END IF

    FUNCTION = 0
END FUNCTION ' Emit_Const






FUNCTION Emit_Redim (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    '*******************************
    ' EXAMPLES
    ' REDIM b$ * 14
    ' REDIM PRESERVE b$ * 20
    ' REDIM a$[10]
    ' REDIM PRESERVE a$[20]
    '*******************************
    LOCAL VarDataType
    LOCAL IsAsterisk
    LOCAL BC
    LOCAL VI AS UDT_VARINFO_STORAGE PTR
    LOCAL vt, id, dimensions, i
    LOCAL IsPreserve, LoIndex, HiIndex
    LOCAL szVarName$, Buffsz$, SOF$

    CALL Process_Option_Base

    IsPreserve = m_iMatchWrd(Stk$[2], "preserve")
    LoIndex = 2 + IsPreserve

    VarDataType = DataType(Stk$[LoIndex])
    szVarName$ = No_Sigil$(Stk$[LoIndex])
    IsAsterisk = m_iMatchWrd(Stk$[LoIndex + 1], "*")

    CALL ValidateVarName(szVarName$)

    HiIndex = m_GetAsPosB(Ndx, 1) - 1
    IF HiIndex < 1 THEN HiIndex = Ndx

    DO WHILE HiIndex > LoIndex
        IF Stk$[HiIndex] = "[" THEN
            DECR BC
        ELSEIF Stk$[HiIndex] = "]" THEN
            INCR BC
            IF BC = 1 THEN
                DECR HiIndex
                ITERATE
            END IF
        END IF
        IF BC = 0 THEN
            IF Stk$[HiIndex-1] <> "]" THEN EXIT DO
            Buffsz$ = "," + Buffsz$
        ELSE
            Buffsz$ = Stk$[HiIndex] + Buffsz$
        END IF
        DECR HiIndex
    LOOP

    vt = CheckLocal(szVarName$, ADDRESSOF(id))

    IF vt = vt_UNKNOWN THEN
        vt = CheckGlobal(szVarName$, ADDRESSOF(id))

        IF vt = vt_UNKNOWN THEN
            '*******************************************
            ' MrBcx 827 - added REDIM without prior DIM
            '*******************************************
            DIM szTmp$
            DIM startNdx

            IF Stk$[3] = "*" OR Stk$[5] = "*" THEN ' Redim SomeString$ * 100 / REDIM somestring AS STRING * 100
                szTmp$ = "DIM "
                FOR j AS INT = 2 TO Ndx
                    szTmp$ += Stk$[j] + SPC$
                NEXT
                Inject(szTmp$)
                EXIT FUNCTION
            END IF

            IF Stk$[2] ?? "PRESERVE" THEN
                startNdx = 3
            ELSE
                startNdx = 2
            END IF

            FOR j AS INT = startNdx TO Ndx
                szTmp$ += Stk$[j] + SPC$
            NEXT
            IF InWinMain OR InMain = TRUE THEN
                Inject ("GLOBAL dynamic " + szTmp$)
            ELSE
                Inject ("LOCAL dynamic " + szTmp$)
            END IF
            EXIT FUNCTION
            '*******************************************
        END IF

        VI = ADDRESSOF(GlobalVars[id])
    ELSE
        VI = ADDRESSOF(LocalVars[id])
    END IF

    dimensions = VI->VarPntr

    IF vt = vt_STRUCT OR vt = vt_UDT OR vt = vt_UNION THEN
        SOF$ = GetElement$(LoIndex, ADDRESSOF(vt), ADDRESSOF(dimensions), VI->VarDef)
        i = Ndx
        Ndx = HiIndex-1
        CALL AsmUnknownStructs(1)
        Ndx = i
        CALL RemEmptyTokens
        szVarName$   = No_Sigil$(Stk$[LoIndex])
        IsAsterisk = m_iMatchWrd(Stk$[LoIndex + 1], "*")
    ELSE
        SOF$ = GetVarTypeName$(vt)
    END IF

    '****************************************************************************************************************
    IF LTRIM$(SOF$) <> "" THEN   ' 812  MrBcx added this new opening "IF" to patch the UDT [] argument bug
        '                        ' GetVarTypeName$() returns "" when the REDIM "variable" is a SUB/FUNCTION argument.
        '************************************************************************************************************
        IF m_iMatchWrd(Stk$[Ndx-1], "as") THEN
            IF SOF$ <> Stk$[Ndx] AND NOT m_iMatchWrd(Stk$[Ndx], "string") THEN
                CALL Abort("Cannot change types for variable " + szVarName$ + _
                " previously defined as " + SOF$ + " on line" + STR$(VI->VarLine))
            END IF
            IF m_iMatchWrd(Stk$[Ndx], "string") THEN
                DECR Ndx
                CALL AppendTokens(3, "[", "BCXSTRSIZE", "]")
            ELSE
                DECR Ndx, 2
            END IF
        ELSE
            IF ( (vt = vt_CHAR OR vt = vt_SCHAR) AND VarDataType = vt_STRVAR AND IsAsterisk = 0) OR vt = vt_CHARPTR THEN
                CALL AppendTokens(3, "[", "BCXSTRSIZE", "]")
            END IF
        END IF
    END IF

    '****************************************************************************************************************
    IF SOF$ = "" THEN SOF$ = Stk$[Ndx]   ' MrBcx 812  UDT arg bug patch - I force SOF$ to be the "AS" datatype
    '****************************************************************************************************************

    IF Stk$[3 + IsPreserve] = "[" THEN
        IF IsPreserve THEN
            LoIndex = 4
        ELSE
            FPRINT FP_WRITE, Scoot$, "if (", szVarName$ + ") { DestroyArr((void **)", szVarName$ + ",", STR$(dimensions) + ", 1); ", szVarName$ + "=NULL; }"
            LoIndex = 3
        END IF
        Use_DynamicA = Use_BcxTempStr =TRUE
        Buffsz$ = ""
        FOR i = LoIndex TO Ndx
            IF *Stk$[i] = ASC("[") THEN
                INCR i
                BC = 1
                DO WHILE BC > 0
                    IF *Stk$[i] = ASC("[") THEN
                        INCR BC
                        Buffsz$ += Stk$[i]
                    ELSE
                        IF *Stk$[i] = ASC("]") THEN
                            DECR BC
                            IF BC = 0 AND i < Ndx THEN
                                Buffsz$ += ","
                            END IF
                            IF BC THEN
                                Buffsz$ += Stk$[i]
                            END IF
                        ELSE
                            Buffsz$ += Stk$[i]
                        END IF
                    END IF
                    INCR i
                LOOP
                DECR i
            END IF
        NEXT

        Buffsz$ = No_Sigil$(Buffsz$)

        IF vt = vt_STRLIT OR vt = vt_DECFUNC OR vt = vt_NUMBER OR (vt = vt_VOID AND INCHR(Stk$[Ndx], "*") = 0) THEN
            CALL Abort(Stk$[Ndx] + " is not a valid type")
        END IF

        IF vt = vt_STRVAR THEN
            SOF$ = "char"
            Buffsz$ += ","
            Buffsz$ += "BCXSTRSIZE"
        END IF

        REPLACE "," WITH ", (size_t)" IN Buffsz$
        FPRINT FP_WRITE, Scoot$, "{"
        '****************************************************************************************************************************
        ' 812 UDT argument bug patch by MrBcx
        ' Emits a corrupt: "size_t dimensions[1] = {(size_t)ub+1};" --AS--  "size_t dimensions[1] = {(size_t)ub+1, (size_t)};"
        ' My patch below involves buffering that line and then sanitizing it.
        '****************************************************************************************************************************
        DIM szTmp$ = "size_t dimensions[" + STR$(dimensions, 1) + "] = {(size_t)" + Buffsz$ +  "};"   ' 812 UDT augument bug patch MrBcx
        REPLACE ", (size_t)};"  WITH "};" IN szTmp$                                                   ' 812 UDT augument bug patch MrBcx
        FPRINT FP_WRITE, Scoot$, szTmp$                                                               ' 812 UDT augument bug patch MrBcx
        '****************************************************************************************************************************

        IF LEFTSTR(szVarName$, "(*") THEN
            FPRINT FP_WRITE, Scoot$, szVarName$, "= (", SOF$, STRING$(dimensions-1, 42), ")CreateArr(", szVarName$, ", sizeof(", SOF$, "), ", STR$(IsPreserve, 1), ", ", STR$(dimensions-1, 1), ", dimensions);"
        ELSE
            FPRINT FP_WRITE, Scoot$, szVarName$, "= (", SOF$, STRING$(dimensions,   42), ")CreateArr(", szVarName$, ", sizeof(", SOF$, "), ", STR$(IsPreserve, 1), ", ", STR$(dimensions, 1), ", dimensions);"
        END IF

        FPRINT FP_WRITE, Scoot$, "}"
        GOTO Redim_Exit
    END IF

    IF Stk$[3]= "*" OR (IsPreserve AND Stk$[4]= "*") THEN                             ' DIM MySTRING$ * NumBytes
        IF IsPreserve THEN
            FPRINT FP_WRITE, Scoot$, szVarName$, "=(char*)realloc(", szVarName$, ","; ' Suppress CRLF
            i = 5
        ELSE
            FPRINT FP_WRITE, Scoot$, "free(", szVarName$, ");"
            FPRINT FP_WRITE, Scoot$, szVarName$, "=(char*)calloc(";                   ' Suppress CRLF
            i = 4
        END IF
        IF IsPreserve THEN
            Stk$[++Ndx] = ");"
        ELSE
            Stk$[++Ndx] = ",1);"
        END IF
        CALL WriteCleanTokens(i, Ndx)
        GOTO Redim_Exit
    END IF

    CALL Abort("Invalid REDIM statement")

    Redim_Exit:
    FUNCTION = 0
END FUNCTION ' Emit_Redim




FUNCTION Emit_Extern (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    DIM RAW IsVolatile
    DIM RAW IsSubOrFuncPtr
    DIM RAW CVar$
    DIM RAW IsPointer, id, vt
    DIM RAW L_DimType$

    IsSubOrFuncPtr = SubFuncTest()
    CALL Process_Option_Base
    IsVolatile = m_iMatchWrd(Stk$[2], "volatile")
    CVar$ = No_Sigil$(Stk$[2+IsVolatile])
    CALL ValidateVarName(CVar$)

    IF Stk$[Ndx] = "*" THEN CALL PointerFix
    IF Stk$[Ndx] = "&" THEN
        Stk$[Ndx--] = ""
        Stk$[Ndx] += "&"
    END IF

    IF Stk$[3+IsVolatile] = "*" THEN
        IF IsVolatile THEN
            CALL Abort("volatile dynamic strings not supported")
        END IF
        CALL DimDynaString(CVar$, 2, 0)
        EXIT FUNCTION
    END IF

    IF IsSubOrFuncPtr THEN
        IF IsVolatile THEN
            CALL Abort("volatile SUB/FUNCTION pointers not supported")
        END IF
        IF DimSubFunc(0) THEN EXIT FUNCTION
    END IF

    Var$ = No_Sigil$(Stk$[2+IsVolatile])
    CALL ValidateVarName(Var$)

    IsPointer = 0
    L_DimType$  = ""

    IF m_iMatchWrd(Stk$[Ndx-1], "as") THEN
        GetTypeInfo(Stk$[Ndx], ADDRESSOF(IsPointer), ADDRESSOF(id), ADDRESSOF(vt))
        Stk$[Ndx] = REMOVE$(Stk$[Ndx], "*")
        CALL BuildStr(3+IsVolatile, Ndx-2, L_DimType$)
    ELSE
        CALL BuildStr(3+IsVolatile, Ndx, L_DimType$)
        vt = DataType(Stk$[2+IsVolatile])
        id = 0
    END IF

    IF vt = vt_STRVAR THEN
        L_DimType$ += "[BCXSTRSIZE]"
    END IF

    IF IsVolatile THEN
        CALL AddGlobal(Var$, vt, id, L_DimType$, IsPointer, 0, 4)
    ELSE
        CALL AddGlobal(Var$, vt, id, L_DimType$, IsPointer, 0, 1)
    END IF
    FUNCTION = 0
END FUNCTION  ' Emit_Extern



FUNCTION Emit_Run(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    FPRINT FP_WRITE, Scoot$, "Run ("; ' Suppress CRLF
    Stk$[++Ndx] = ");"
    CALL WriteCleanTokens(2, Ndx)
    FUNCTION = 0
END FUNCTION  ' Emit_Run



FUNCTION Emit_Shell(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    DIM RAW LZZ$
    CALL BuildDelimStr(2, Ndx, LZZ$)
    IF ISNULL(LZZ$) THEN LZZ$ = DDQ$
    FPRINT FP_WRITE, Scoot$, "system(", No_Sigil$(LZZ$), ");"
    FUNCTION = 0
END FUNCTION  ' Emit_Shell



FUNCTION Emit_Data(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)

    FOR A AS INT = 2 TO Ndx                  ' *******************************
        IF Stk$[A] = "-" THEN             '
            Stk$[A] = "-" + Stk$[A+1]     '
            Stk$[A+1] = ""                '  825 New Block added by MrBcx
            LShiftStk (A +1)              '
        END IF                            '
    NEXT                                  ' *******************************

    FOR A AS INT = 2 TO Ndx
        IF INCHR(Stk$[A], DQ$) = 0 AND Stk$[A] <> "," THEN
            Stk$[A] = ENC$(Stk$[A])  ' Allow unquoted text
        END IF
        FPRINT FP_DAT, Stk$[A];      ' Suppress CRLF
    NEXT
    FPRINT FP_DAT, ""
    FUNCTION = 0
END FUNCTION ' Emit_Data



FUNCTION Emit_Declare(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    DIM RAW TempProto$
    DIM RAW Varcode AS UDT_VARCODE_ATTRIBUTES
    DIM RAW ACS AS UDT_ARG_COMMAS_STORAGE
    Varcode.IsExported = FALSE
    Varcode.UseInLine = UseInLine
    CALL FuncSubDecs1("sub", 1, Ndx, ADDRESSOF(Varcode)) ' convert [] to pointer * and $[] to [][2048]
    CALL SepFuncArgs(3, ADDRESSOF(ACS), TRUE)
    TempProto$ = MakeDecProto$(ADDRESSOF(ACS))
    IF NOT NoTypeDeclare THEN
        FPRINT FP_UDT, TempProto$, ";"
    ELSE
        CALL AddProto(TempProto$ + ";")
    END IF
    FUNCTION = 0
END FUNCTION ' Emit_Declare


FUNCTION Emit_Auto (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    CALL DimVar(ImAuto)
    FUNCTION = 0
END FUNCTION ' Emit_Auto


FUNCTION Emit_Dim (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    CALL DimVar(ImDim)
    FUNCTION = 0
END FUNCTION ' Emit_Dim


FUNCTION Emit_Local (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    CALL DimVar(ImLocal)
    FUNCTION = 0
END FUNCTION ' Emit_Local



FUNCTION Emit_PrivateDim (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    CALL DimVar(ImCPPPrvDim)
    FUNCTION = 0
END FUNCTION ' Emit_PrivateDim


FUNCTION Emit_Raw (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    CALL DimVar(ImRaw)
    FUNCTION = 0
END FUNCTION ' Emit_Raw


FUNCTION Emit_Register (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    CALL DimVar(ImRegister)
    FUNCTION = 0
END FUNCTION ' Emit_Register


FUNCTION Emit_Static (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    CALL DimVar(ImStatic)
    FUNCTION = 0
END FUNCTION ' Emit_Static



FUNCTION Emit_Clear (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    Use_Clear = Use_SysMacros = TRUE
    FPRINT FP_WRITE, Scoot$, "Clear"; ' Suppress CRLF
    IF Stk$[2] <> "(" THEN
        FPRINT FP_WRITE, "("; ' Suppress CRLF
    END IF
    FOR i AS INT = 2 TO Ndx
        FPRINT FP_WRITE, No_Sigil$(Stk$[i]); ' Suppress CRLF
    NEXT
    IF Stk$[Ndx] <> ")" THEN FPRINT FP_WRITE, ")"; ' Suppress CRLF
    FPRINT FP_WRITE, ";"
    FUNCTION = 0
END FUNCTION ' Emit_Clear


FUNCTION Emit_Swap(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord$)
    UNREFERENCED_PARAMETER(FuncRetnFlag)

    DIM RAW VI1 AS UDT_VARINFO_STORAGE PTR
    DIM RAW VI2 AS UDT_VARINFO_STORAGE PTR
    DIM RAW indx AS INT
    DIM RAW A, i, j
    DIM RAW ThirdArgExists AS BOOLEAN

    Use_BcxTempStr = TRUE

    ' Determine if there is a third argument (number of bytes to be swapped)
    ThirdArgExists = FALSE
    FOR i = 2 TO Ndx
        IF *Stk$[i] = ASC(",") THEN
            IF i < Ndx THEN
                FOR j = i + 1 TO Ndx
                    IF *Stk$[j] = ASC(",") THEN
                        ThirdArgExists = TRUE
                        EXIT FOR
                    END IF
                NEXT
            END IF
            EXIT FOR
        END IF
    NEXT

    IF ThirdArgExists THEN
        ' Emit C99 code for swap with an explicit third argument
        FPRINT FP_WRITE, Scoot$, "swap ("; ' Suppress CRLF
        FOR i = 2 TO Ndx
            IF *Stk$[i] = ASC(",") THEN
                FPRINT FP_WRITE, ", "; ' Emit first comma between x and y
            ELSE
                FPRINT FP_WRITE, No_Sigil$(Stk$[i]); ' Emit argument without a comma
            END IF
        NEXT
        FPRINT FP_WRITE, ");" ' Close the swap statement
    ELSE
        ' Emit C99 code for swap without explicit third argument (using sizeof)
        FPRINT FP_WRITE, Scoot$, "swap ((byte*)&"; ' Suppress CRLF
        FOR i = 2 TO Ndx
            IF *Stk$[i] = ASC(",") THEN EXIT FOR
            FPRINT FP_WRITE, No_Sigil$(Stk$[i]); ' Suppress CRLF
        NEXT

        A = CheckLocal(Stk$[2], ADDRESSOF(indx))
        IF A = vt_UNKNOWN THEN
            A = CheckGlobal(Stk$[2], ADDRESSOF(indx))
            IF A = vt_UNKNOWN THEN
                CALL Abort("Variable '" + Stk$[2] + "' in swap statement unknown")
            END IF
            VI1 = ADDRESSOF(GlobalVars[indx])
        ELSE
            VI1 = ADDRESSOF(LocalVars[indx])
        END IF

        IF RIGHTSTR(Stk$[i-1], "]") THEN
            IF VI1->VarType = vt_CHAR  AND VI1->VarPntr = 1 THEN FPRINT FP_WRITE, "[0]"; ' Suppress CRLF
            IF VI1->VarType = vt_SCHAR AND VI1->VarPntr = 1 THEN FPRINT FP_WRITE, "[0]"; ' Suppress CRLF
        END IF

        FPRINT FP_WRITE, ",(byte*)&"; ' Suppress CRLF

        INCR i

        FOR j = i TO Ndx
            FPRINT FP_WRITE, No_Sigil$(Stk$[j]); ' Suppress CRLF
        NEXT

        A = CheckLocal(Stk$[i], ADDRESSOF(indx))
        IF A = vt_UNKNOWN THEN
            A = CheckGlobal(Stk$[i], ADDRESSOF(indx))
            IF A = vt_UNKNOWN THEN
                CALL Abort("Variable '"+Stk$[i] + "' in swap statement unknown")
            END IF
            VI2 = ADDRESSOF(GlobalVars[indx])
        ELSE
            VI2 = ADDRESSOF(LocalVars[indx])
        END IF

        IF RIGHTSTR(Stk$[j-1], "]") THEN
            IF VI2->VarType = vt_CHAR  AND VI2->VarPntr = 1 THEN FPRINT FP_WRITE, "[0]"; ' Suppress CRLF
            IF VI2->VarType = vt_SCHAR AND VI2->VarPntr = 1 THEN FPRINT FP_WRITE, "[0]"; ' Suppress CRLF
        END IF

        IF VI1->VarType <> VI2->VarType THEN
            Warning("Possible size error in swap statement")
        END IF

        IF VI2->VarType = vt_STRVAR OR VI2->VarType = vt_CHAR OR VI2->VarType = vt_SCHAR THEN
            FPRINT FP_WRITE, ",strlen("; ' Suppress CRLF
        ELSE
            FPRINT FP_WRITE, ",sizeof("; ' Suppress CRLF
        END IF

        Stk$[++Ndx] = "));"
        CALL WriteCleanTokens(i, Ndx)
    END IF

    FUNCTION = 0
END FUNCTION ' Emit_Swap




FUNCTION Emit_PrinterProcs(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "ejectpage"
            FPRINT FP_WRITE, Scoot$, "EjectPage();"

        CASE "printerclose"
            FPRINT FP_WRITE, Scoot$, "PrinterClose();"

        CASE "printeropen"
            IF Ndx = 1 THEN
                FPRINT FP_WRITE, Scoot$, "PrinterOpen();"
            ELSE
                DIM RAW szPrinterParameters$
                CALL BuildStr(2, Ndx, szPrinterParameters$)
                FPRINT FP_WRITE, Scoot$, "PrinterOpen(", szPrinterParameters$, ");"
            END IF

        CASE "lprint", "sprint"  ' LPRINT & FPRINT  handle,{list}
            DIM IsLprint = FALSE
            DIM IsSprint = FALSE

            IF m_iMatchWrd(Stk$[1], "lprint") THEN
                Use_Proto = IsLprint = IsSprint = TRUE
                Stk$[1] = "sprint"
                InsertTokens(1, 2, "BcxPtr_Buffer", ",")
            END IF

            IF m_iMatchWrd(Stk$[1], "sprint") THEN
                IsSprint = TRUE
            END IF

            IF IsDecimalNumber(Stk$[2]) THEN
                Stk$[2] = "FP" + Stk$[2]
            END IF

            IF IsSprint THEN
                szFileHandle$ = No_Sigil$(Stk$[2])
            ELSE
                IF m_iMatchWrd(Stk$[2], "stderr") THEN
                    szFileHandle$ = "stderr"
                ELSE
                    STATIC i
                    IF CheckLocal(Stk$[2], ADDRESSOF(i)) = vt_UNKNOWN THEN
                        IF CheckGlobal(Stk$[2], ADDRESSOF(i)) = vt_UNKNOWN THEN
                            CALL AddGlobal(Stk$[2], vt_FILEPTR)
                        END IF
                    END IF

                    szFileHandle$ = ""

                    FOR iii AS INT = 2 TO Ndx
                        IF *Stk$[iii] = ASC(",") OR *Stk$[iii] = ASC(";") THEN
                            Stk$[iii] = ""
                            EXIT FOR
                        END IF
                        szFileHandle$ += Stk$[iii]
                        Stk$[iii] = ""
                    NEXT

                    szFileHandle$ += "@"
                END IF
            END IF

            Stk$[2] = ""  ' remove the handle
            Stk$[3] = ""  ' remove the Comma

            STATIC LZZ$

            IF IsSprint THEN
                LZZ$ = "s" + PrintWriteFormat$(0)
                REMOVE "\\n" FROM LZZ$
            ELSE
                LZZ$ = "f" + PrintWriteFormat$(0)
            END IF

            LZZ$ = LEFT$(LZZ$, 8) + REMOVE$(szFileHandle$, "@") + "," + MID$(LZZ$, 9)

            IF IsLprint THEN
                FPRINT FP_WRITE, Scoot$, LZZ$
                FPRINT FP_WRITE, Scoot$, "PrinterWrite(BcxPtr_Buffer);"
                IF NOT Use_Printer THEN
                    SrcTmp$ = "printer"
                    CALL Inject (SrcTmp$)   ' Force printer globals declarations
                END IF
            ELSE
                FPRINT FP_WRITE, Scoot$, LZZ$
            END IF

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)
    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_PrinterProcs




FUNCTION Emit_Free(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    DIM RAW VI AS UDT_VARINFO_STORAGE PTR
    DIM RAW A, vt, id, dimensions
    DIM RAW CVar$
    LOCAL IsDynVar

    A = 2
    IF m_iMatchWrd(Stk$[2], "dynamic") THEN
        IsDynVar = TRUE
        A = 3
    END IF

    IF Stk$[A] = "(" THEN
        INCR A
        DECR Ndx
    END IF

    CVar$ = No_Sigil$(Stk$[A])
    vt = CheckLocal(CVar$, ADDRESSOF(id))

    IF vt = vt_UNKNOWN THEN
        vt = CheckGlobal(CVar$, ADDRESSOF(id))
        IF vt = vt_UNKNOWN THEN
            Abort("Cannot REDIM " + CVar$ + " not previously dimensioned")
        END IF
        VI = ADDRESSOF(GlobalVars[id])
    ELSE
        VI = ADDRESSOF(LocalVars[id])
        IF IsDynVar THEN
            Warning("Local dynamic variables are automatically freed.", 1)
        END IF
    END IF

    CALL BuildStr(A, Ndx, CVar$)

    CVar$ = TRIM$(No_Sigil$(CVar$))

    IF vt = vt_STRUCT OR vt = vt_UNION THEN
        GetElement$(2, ADDRESSOF(vt), ADDRESSOF(dimensions), VI->VarDef)
        IF vt <> vt_UNKNOWN AND dimensions > 0 THEN
            Use_BcxTempStr = Use_DynamicA = TRUE
            FPRINT FP_WRITE, Scoot$, "if (", CVar$; ' Suppress CRLF
            FPRINT FP_WRITE, ") { DestroyArr((void **)", CVar$, ",", dimensions, ", 1); "; ' Suppress CRLF
            FPRINT FP_WRITE, CVar$, "=NULL; }"
            EXIT FUNCTION
        END IF
    END IF

    IF VI->VarPntr > 1 THEN
        Use_BcxTempStr = Use_DynamicA = TRUE
        FPRINT FP_WRITE, Scoot$, "if (", CVar$; ' Suppress CRLF
        FPRINT FP_WRITE, ") { DestroyArr((void **)", CVar$, ",", STR$(VI->VarPntr), ", 1); "; ' Suppress CRLF
        FPRINT FP_WRITE, CVar$ ; "=NULL; }"
    ELSE
        FPRINT FP_WRITE, Scoot$, "free(", CVar$, "), "; ' Suppress CRLF
        FPRINT FP_WRITE, CVar$, "=NULL;"
    END IF

    FUNCTION = 0
END FUNCTION ' Emit_Free



FUNCTION Emit_Dynamic(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)

    IF InFunction THEN g_FoundLocalDynArray = TRUE

    DIM w = 0
    DIM RAW szSizeOf$
    DIM RAW LZZ$
    DIM RAW CVar$
    DIM RAW vt, id, dimensions

    CALL Process_Option_Base
    CVar$ = No_Sigil$(Stk$[2])
    CALL ValidateVarName(CVar$)

    IF Stk$[Ndx] = "*" THEN CALL PointerFix
    IF Stk$[Ndx] = "&" THEN
        Stk$[Ndx--] = ""
        Stk$[Ndx] += "&"
    END IF

    IF m_iMatchWrd(Stk$[Ndx-1], "as") THEN
        szSizeOf$ = Stk$[Ndx]
        GetTypeInfo(szSizeOf$, ADDRESSOF(w), ADDRESSOF(id), ADDRESSOF(vt))

        IF vt = vt_STRLIT OR vt = vt_DECFUNC OR vt = vt_NUMBER OR _
            (vt = vt_VOID AND INCHR(Stk$[Ndx], "*") = 0) THEN
            CALL Abort(szSizeOf$ + " is not a valid type")
        END IF
        IF vt = vt_FILEPTR AND INCHR(szSizeOf$, "*") = 0 THEN szSizeOf$ = szSizeOf$ + "*"
        DECR Ndx, 2
    ELSE
        vt = DataType(Stk$[2])
        id = 0
        szSizeOf$ = GetVarTypeName$(vt)
    END IF

    Use_DynamicA = Use_BcxTempStr = TRUE

    CALL BuildStr(3, Ndx, LZZ$)

    dimensions = TALLY(LZZ$, "][") + 1

    IF dimensions > 1 THEN REPLACE "][" WITH "," IN LZZ$

    LZZ$ = No_Sigil$(LZZ$)

    RemoveAll(LZZ$, "[]")

    IF vt = vt_STRVAR THEN
        vt = vt_CHAR
        szSizeOf$ = "char"
        IF InTypeDef THEN
            IF Stk$[3] <> "[" THEN
                DECR dimensions
            ELSE
                vt = vt_CHARPTR
            END IF
        END IF

        INCR dimensions

        LZZ$ += ","
        LZZ$ += "BCXSTRSIZE"
    END IF

    IF InTypeDef THEN
        IF vt = vt_STRUCT THEN
            FPRINT FP_WRITE, Scoot$, "struct _", szSizeOf$, SPACE$(2), STRING$(dimensions, 42), CVar$, ";"
        ELSE
            FPRINT FP_WRITE, Scoot$, szSizeOf$, SPACE$(2), STRING$(dimensions, 42), CVar$, ";"
        END IF
        CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef], vt, CVar$, szSizeOf$, dimensions)
    ELSEIF InFunction <> FALSE THEN
        INCR LocalDynArrCnt

        IF c_MaxLocalDynArr = LocalDynArrCnt THEN
            CALL Abort("Maximum number of Local Dynamic Arrays exceeded.")
        END IF

        LocalDynArrName$ [LocalDynArrCnt] = "if (" + CVar$ + ") { DestroyArr((void **)" + CVar$ + "," + STR$(dimensions) + ", 1); " +  CVar$ + "=NULL; }"

        FPRINT FP_WRITE, Scoot$, szSizeOf$, SPACE$(2), STRING$(dimensions, 42), CVar$, "=0;"
        CALL AddLocal(CVar$, vt, id, "", dimensions)
    ELSE
        IF Use_GenFree THEN
            CALL AddDynamicGlobal("if (" + CVar$ + ") { DestroyArr((void **)" + CVar$ + "," + STR$(dimensions) + ", 1); " + CVar$ + "=NULL; }")
        END IF
        CALL AddGlobal(CVar$, vt, id, "", dimensions)
    END IF

    IF NOT InTypeDef THEN
        REPLACE "," WITH ", (size_t)" IN LZZ$
        FPRINT FP_WRITE, Scoot$, "{"
        FPRINT FP_WRITE, Scoot$, "size_t dimensions[", STR$(dimensions, 1), "] = {(size_t)", LZZ$, "};"

        '======== 828 MrBcx - prevents heap leaks in LOCAL string arrays ========

        IF InFunction THEN                    ' ← ADDED THIS GUARD    837 by MrBcx
            GLOBAL AuxLocalDynArray$[1024]
            GLOBAL AuxLocalDynArrayCount
            INCR AuxLocalDynArrayCount
            AuxLocalDynArray$[AuxLocalDynArrayCount] = "if (" + CVar$ + ") DestroyArr((void **)"
            AuxLocalDynArray$[AuxLocalDynArrayCount] += CVar$ + "," +  STR$(dimensions) + ", 1);"
        END IF                                ' ← ADDED THIS TOO  ... 837 by MrBcx

        '======== 828 MrBcx - prevents heap leaks in LOCAL string arrays ========

        FPRINT FP_WRITE, Scoot$, CVar$, "= (", szSizeOf$, STRING$(dimensions, 42), ")CreateArr (", CVar$, ",sizeof(", szSizeOf$, "),0,", STR$(dimensions, 1), ", dimensions);"
        FPRINT FP_WRITE, Scoot$, "}"
    END IF

    FUNCTION = 0
END FUNCTION ' Emit_Dynamic




SUB DimVar(iType)
    '*******************************
    ' DIM A$ * blah blah blah
    ' DIM a%[1000]  (integer)
    ' DIM a![1000]  (single)
    ' DIM a#[1000]  (double)
    ' DIM a~[1000]  (long double)
    ' DIM A$[1000]  (string)
    ' DIM r             AS DATA_TYPE
    ' DIM r[1][2]...[n] AS DATA_TYPE
    ' DIM DYNAMIC A$[1000]
    ' DIM volatile a
    ' DIM a AS PCTSTR
    '********************************
    DIM w  = 0
    DIM id = 0
    DIM vt = 0
    DIM IsALocalVar    = FALSE
    DIM NotInitialized = TRUE
    STATIC UseStatic$
    STATIC IsVolatile
    STATIC sVolatile$
    STATIC Ok2Initialize
    STATIC szVarName$
    STATIC VarType
    STATIC IsSubOrFuncPtr
    STATIC IsConsOrDestPtr
    STATIC IsPointer
    STATIC LTmp$
    STATIC L_DimType$
    STATIC szVarTypeName$
    STATIC szMemsetName$
    STATIC szVarDecName$


    IF BYTE_AT(Stk[Ndx][0]) = ASC(":") THEN
        Stk$[Ndx - 1] += Stk$[Ndx]
        DECR Ndx
    END IF

    IsDim = IsLocal = IsRaw = IsRegister = IsStatic = FALSE

    IF iType = ImDim      THEN IsDim      = TRUE
    IF iType = ImLocal    THEN IsLocal    = TRUE
    IF iType = ImRaw      THEN IsDim      = IsRaw
    IF iType = ImRegister THEN IsRegister = TRUE
    IF iType = ImStatic   THEN IsStatic   = TRUE

    IsVolatile = m_iMatchWrd(Stk$[2], "volatile")
    IF IsVolatile THEN

        IF IsRegister THEN
            CALL Abort("Register volatile not supported")
        END IF

        sVolatile$ = "volatile "
    ELSE
        sVolatile$ = ""
    END IF

    IsSubOrFuncPtr = SubFuncTest()
    IsConsOrDestPtr = Ctor_Dtor_Detected(2)

    CALL Process_Option_Base

    IF Stk$[Ndx] = "*" THEN CALL PointerFix
    IF Stk$[Ndx] = "&" THEN
        Stk$[Ndx--] = ""
        Stk$[Ndx] += "&"
    END IF

    '*************************************************************************
    IF IsSubOrFuncPtr THEN

        IF IsVolatile THEN
            CALL Abort("volatile SUB/FUNCTION pointers not supported")
        END IF

        IF DimSubFunc(0) THEN EXIT SUB
    END IF

    IF IsConsOrDestPtr THEN

        IF IsVolatile THEN
            CALL Abort("volatile SUB/FUNCTION pointers not supported")
        END IF

        IF DimSubFunc(2) THEN EXIT SUB
    END IF

    IF InFunction OR InTypeDef OR InCppTypeDef OR InClass OR InBlock OR InNameSpace THEN
        IsALocalVar = TRUE
    END IF

    IF InTypeDef OR IsVolatile THEN
        Ok2Initialize = FALSE
    ELSE
        IF UseCpphdr THEN
            IF NOTZERO (iType BAND (ImDim BOR ImLocal)) THEN
                Ok2Initialize = TRUE
            ELSE
                Ok2Initialize = FALSE
            END IF
        ELSE
            IF NOTZERO (iType BAND (ImDim BOR ImLocal BOR ImAuto)) THEN
                Ok2Initialize = TRUE
            ELSE
                Ok2Initialize = FALSE
            END IF
        END IF
    END IF

    IF InTypeDef OR InNameSpace THEN
        UseStatic$ = ""
        IsStatic = FALSE
    ELSE
        IF NOTZERO (iType BAND ImStatic) THEN
            IsStatic = TRUE
            UseStatic$ = "static "
        ELSE
            UseStatic$ = ""
            IsStatic = FALSE
        END IF
    END IF

    szVarName$ = No_Sigil$(Stk$[2+IsVolatile])

    CALL ValidateVarName(szVarName$)
    VarType = DataType(Stk$[2+IsVolatile])

    IF Stk$[3+IsVolatile] = "*" THEN       ' DIM MySTRING$ * NumBytes

        IF IsVolatile THEN
            CALL Abort("volatile dynamic strings not supported")
        END IF

        CALL DimDynaString(szVarName$, 0, 0)
        EXIT SUB
    END IF

    DIM iASoffset = m_GetAsPosB(Ndx, 2) ' AS offset

    IF iASoffset THEN
        DIM sConst$
        DIM iIsConst

        IF iASoffset = Ndx-2 THEN
            IF m_iMatchWrd(Stk$[Ndx-1], "const") THEN
                sConst$ = "const "
                iIsConst = 1
            END IF
        END IF

        IsPointer = TALLY(Stk$[Ndx], "*")

        CALL BuildStr(2+IsVolatile, iASoffset-1, LTmp$)
        CALL BuildStr(3+IsVolatile, iASoffset-1, L_DimType$)

        IF NOTZERO(INCHR(LTmp$, "=")) THEN
            NotInitialized = FALSE
        END IF

        szVarTypeName$ = REMOVE$(Stk$[Ndx], "*")
        GetTypeInfo(szVarTypeName$, ADDRESSOF(w), ADDRESSOF(id), ADDRESSOF(vt))

        IF vt = vt_WINBOOL THEN
            IREPLACE "WINBOOL" WITH "BOOL" IN Stk$[Ndx]
        END IF

        IF vt = vt_STRVAR THEN
            Stk$[Ndx] = "char"
            szVarTypeName$ = Stk$[Ndx]
            L_DimType$ += "[BCXSTRSIZE]"
            LTmp$ += "[BCXSTRSIZE]"
        END IF

        Stk$[Ndx] = RPAD$(Stk$[Ndx], c_PADSIZE)

        IF vt = vt_FILEPTR THEN
            Stk$[Ndx] += "*"
        END IF

        IF IsALocalVar THEN
            SELECT CASE iType

                CASE ImDim, ImLocal, ImRaw
                    IF vt = vt_STRUCT THEN
                        FPRINT FP_WRITE, Scoot$, UseStatic$, sVolatile$, sConst$, "struct _", Stk$[Ndx], SPACE$(2); ' Suppress CRLF
                    ELSE
                        FPRINT FP_WRITE, Scoot$, UseStatic$, sVolatile$, sConst$, Stk$[Ndx], SPACE$(2); ' Suppress CRLF
                    END IF
                    IF InTypeDef AND NOT InBlock THEN
                        IF vt = vt_UDT THEN
                            IF ComSwitchON THEN
                                IF TypeDefs[id].VarName$ = "OBJECT" THEN
                                    CALL Abort("Use of Object type in UDTs is Illegal!")
                                END IF
                            END IF
                        END IF
                        CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef], vt, szVarName$, szVarTypeName$)
                    END IF

                CASE ImStatic
                    FPRINT FP_WRITE, Scoot$, UseStatic$, sVolatile$, sConst$, Stk$[Ndx], SPACE$(2); ' Suppress CRLF

                CASE ImAuto
                    FPRINT FP_WRITE, Scoot$, SPC$, sVolatile$, sConst$, SPC$, Stk$[Ndx], SPACE$(2); ' Suppress CRLF

                CASE ImRegister
                    FPRINT FP_WRITE, Scoot$, SPC$, sConst$, Stk$[Ndx], SPACE$(2); ' Suppress CRLF

                CASE ImCPPPrvDim
                    FPRINT FP_WRITE, Scoot$, "private: ", Stk$[Ndx], SPACE$(2); ' Suppress CRLF

            END SELECT

            IF iType <> ImCPPPrvDim THEN
                IF NOT InTypeDef THEN
                    IF vt = vt_UDT THEN
                        IF ComSwitchON THEN
                            IF TypeDefs[id].VarName$ = "OBJECT" THEN
                                Add_Com_Global_Var(szVarName$)
                                Use_COM = Use_BcxTempStr = TRUE
                            END IF
                        END IF
                    END IF
                    CALL AddLocal(szVarName$, vt, id, L_DimType$, IsPointer, 0, 0, iIsConst)
                END IF
            END IF

            IF Ok2Initialize THEN
                szMemsetName$ = No_Sigil$(EXTRACT$(LTmp$, "["))

                IF IsPointer THEN
                    IF NotInitialized THEN
                        FPRINT FP_WRITE, No_Sigil$(LTmp$), "={0};"
                    ELSE
                        FPRINT FP_WRITE, No_Sigil$(LTmp$), ";"
                    END IF
                ELSE
                    SELECT CASE vt

                        CASE vt_BOOL, vt_BYTE, vt_DWORD, vt_INTEGER, vt_LONG, vt_SHORT, _
                            vt_UINT, vt_ULONG, vt_USHORT, vt_DWORD, vt_WORD, vt_DOUBLE, _
                            vt_SINGLE, vt_LDOUBLE, vt_PCHAR, vt_PBYTE, vt_SSHORT, vt_SCHAR

                            IF NotInitialized THEN
                                FPRINT FP_WRITE, No_Sigil$(LTmp$), "={0};"
                            ELSE
                                FPRINT FP_WRITE, No_Sigil$(LTmp$), ";"
                            END IF

                        CASE ELSE

                            IF NotInitialized THEN
                                FPRINT FP_WRITE, No_Sigil$(LTmp$), "={0};"
                            ELSE
                                FPRINT FP_WRITE, No_Sigil$(LTmp$), ";"
                            END IF
                    END SELECT
                END IF
            ELSE
                FPRINT FP_WRITE, No_Sigil$(LTmp$), ";"
            END IF
        ELSE
            IF IsVolatile THEN
                CALL AddGlobal(szVarName$, vt, id, L_DimType$, IsPointer, 0, 3, 0, iIsConst)
            ELSE
                IF vt = vt_UDT THEN
                    IF ComSwitchON THEN
                        IF TypeDefs[id].VarName$ = "OBJECT" THEN
                            Add_Com_Global_Var(szVarName$)
                            Use_COM = Use_BcxTempStr = TRUE
                        END IF
                    END IF
                END IF
                IF iType = ImRaw THEN
                    CALL AddGlobal(szVarName$, vt, id, L_DimType$, IsPointer, 0, 2, 0, iIsConst)
                ELSE
                    CALL AddGlobal(szVarName$, vt, id, L_DimType$, IsPointer, 0, 0, 0, iIsConst)
                END IF
            END IF
        END IF
        EXIT SUB
    END IF

    ' Dimensioned without AS
    CALL BuildStr(3+IsVolatile, Ndx, LTmp$)

    IF NOTZERO(INCHR(LTmp$, "=")) THEN
        NotInitialized = FALSE
    END IF

    IF IsALocalVar THEN LTmp$ = TRIM$(No_Sigil$(LTmp$))
    IF VarType = vt_STRVAR THEN LTmp$ += "[BCXSTRSIZE]"

    IF IsALocalVar THEN
        IF VarType = vt_STRVAR THEN
            szVarDecName$ = "char"
        ELSE
            szVarDecName$ = GetVarTypeName$(VarType)
        END IF
        szVarDecName$ = RPAD$(szVarDecName$, c_PADSIZE)

        IF UseCpphdr THEN
            DIM RAW Ok2UseMemset
            Ok2UseMemset = Ok2Initialize
            SELECT CASE iType

                CASE ImDim, ImLocal, ImRaw, ImStatic
                    IF (ImDim BOR ImLocal) BAND (Ok2UseMemset) THEN
                        FPRINT FP_WRITE, Scoot$, szVarDecName$, SPC$, szVarName$, LTmp$, "={0};"
                        Ok2UseMemset = FALSE
                    ELSE
                        FPRINT FP_WRITE, Scoot$, UseStatic$, sVolatile$, szVarDecName$, SPC$, szVarName$, LTmp$, ";"
                    END IF

                CASE ImRegister
                    IF IsVolatile THEN Abort("Register volatile not supported")
                    FPRINT FP_WRITE, Scoot$, SPC$, szVarDecName$, SPC$, szVarName$, LTmp$, ";"

                CASE ImCPPPrvDim
                    FPRINT FP_WRITE, Scoot$, "private: ", szVarDecName$, SPC$, szVarName$, LTmp$, ";"

            END SELECT

            IF Ok2UseMemset THEN
                szMemsetName$ = No_Sigil$(EXTRACT$(szVarName$, "["))
                FPRINT FP_WRITE, Scoot$, "memset(&", szMemsetName$, ",0,sizeof(", szMemsetName$, "));"
            END IF

        ELSE

            SELECT CASE iType

                CASE ImDim, ImLocal, ImStatic, ImRaw
                    IF NotInitialized AND Ok2Initialize THEN
                        FPRINT FP_WRITE, Scoot$, UseStatic$, sVolatile$, szVarDecName$, SPC$, szVarName$, LTmp$, "={0};"
                    ELSE
                        FPRINT FP_WRITE, Scoot$, UseStatic$, sVolatile$, szVarDecName$, SPC$, szVarName$, LTmp$, ";"
                    END IF

                CASE ImAuto
                    IF NotInitialized AND Ok2Initialize THEN
                        FPRINT FP_WRITE, Scoot$, "auto ", sVolatile$, szVarDecName$, SPC$, szVarName$, LTmp$, "={0};"
                    ELSE
                        FPRINT FP_WRITE, Scoot$, "auto ", sVolatile$, szVarDecName$, SPC$, szVarName$, LTmp$, ";"
                    END IF

                CASE ImRegister
                    IF IsVolatile THEN Abort("Register volatile not supported")
                    IF NotInitialized AND Ok2Initialize THEN
                        FPRINT FP_WRITE, Scoot$, SPC$, szVarDecName$, SPC$, szVarName$, LTmp$, "={0};"
                    ELSE
                        FPRINT FP_WRITE, Scoot$, SPC$, szVarDecName$, SPC$, szVarName$, LTmp$, ";"
                    END IF

                CASE ImCPPPrvDim
                    IF NotInitialized AND Ok2Initialize THEN
                        FPRINT FP_WRITE, Scoot$, "private: ", szVarDecName$, SPC$, szVarName$, LTmp$, "={0};"
                    ELSE
                        FPRINT FP_WRITE, Scoot$, "private: ", szVarDecName$, SPC$, szVarName$, LTmp$, ";"
                    END IF

            END SELECT
        END IF

        IF iType <> ImCPPPrvDim THEN
            IF InTypeDef THEN
                IF VarType = vt_UDT THEN
                    IF ComSwitchON THEN
                        IF TypeDefs[id].VarName$ = "OBJECT" THEN
                            Abort("Use of Object type in UDTs is Illegal!")
                        END IF
                    END IF
                END IF
                CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef], VarType, szVarName$, szVarTypeName$)
            ELSE
                CALL AddLocal(szVarName$, VarType, 0, LTmp$)
            END IF
        END IF
        EXIT SUB
    END IF

    '************************************************************************
    ' if we get here, we're creating with a GLOBAL variable
    '************************************************************************
    STATIC iGlobalExtn

    IF IsVolatile THEN
        iGlobalExtn = 3
    ELSE
        IF VarType = vt_UDT THEN
            IF ComSwitchON THEN
                IF TypeDefs[id].VarName$ = "OBJECT" THEN
                    Add_Com_Global_Var(szVarName$)
                    Use_COM = Use_BcxTempStr = TRUE
                END IF
            END IF
        END IF
        iGlobalExtn = 0
    END IF
    CALL AddGlobal(szVarName$, VarType, 0, LTmp$, 0, 0, iGlobalExtn)
END SUB ' DimVar



FUNCTION Emit_CPP_EndClass(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UseCpp = TRUE

    IF InClass <> 1 THEN
        CALL Abort("Syntax Error")
    END IF
    CALL BumpDown("Extra unindents and/or missing indents before END CLASS")
    FPRINT FP_UDT, Scoot$, "};"
    FPRINT FP_UDT, ""
    CALL BumpDown("Extra unindents and/or missing indents before END CLASS")
    DECR InClass
    FP_WRITE = FP2
    InClassName$ = ""
    InClassPP$ = ""

    FUNCTION = 0
END FUNCTION ' Emit_CPP_EndClass


FUNCTION Emit_CPP_Namespace(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UseCpp = TRUE
    FP_WRITE = FP_UDT
    FPRINT FP_WRITE, Scoot$, "namespace ", Stk$[2]
    CALL BumpUp
    FPRINT FP_WRITE, Scoot$, "{"
    INCR InNameSpace
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Namespace




FUNCTION Emit_CPP_Class(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UseCpp = TRUE
    IF InClass OR InTypeDef OR InCppTypeDef OR InFunction OR ISNULL(Stk$[2]) THEN
        CALL Abort("Syntax Error")
    END IF
    InClassName$ = Stk$[2]
    IF UsingTemplate = FALSE THEN FPRINT FP_UDT, ""
    IF NOTNULL(InIfDef$) AND InIfDef$ <> "FP3" THEN
        FPRINT FP_UDT, InIfDef$
    END IF
    FPRINT FP_UDT, "class "; ' Suppress CRLF
    FP_WRITE = FP_UDT
    FOR i AS INT = 2 TO Ndx
        IF m_iMatchWrd(Stk$[i+1], "inherits") THEN
            Stk$[i] += ":"
            Stk$[i+1] = "public"
        END IF
        IF Stk$[i] = "using" THEN
            FPRINT FP_UDT, " : "; ' Suppress CRLF
            ITERATE
        END IF
        IF Stk$[i] = "::" THEN
            FPRINT FP_UDT, " : "; ' Suppress CRLF
        ELSE
            IF m_iMatchWrd(Stk$[i], "private") THEN Stk$[i] = "private"
            IF m_iMatchWrd(Stk$[i], "public") THEN Stk$[i] = "public"
            AddSpace(i)
            FPRINT FP_UDT, Stk$[i]; ' Suppress CRLF
        END IF
    NEXT
    CALL BumpUp
    FPRINT FP_UDT, "\n", Scoot$, "{"
    INCR InClass
    InClassPP$ = ""
    IF UsingTemplate = TRUE THEN WasAClass = TRUE
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Class



SUB Emit_CPP_AccessSpecifier(szAccess$ AS STRING)
    '***********************************************************************
    ' Shared core for Emit_CPP_Public, Emit_CPP_Protected, Emit_CPP_Private.
    ' Emits the C++ access specifier label and manages indentation state.
    '***********************************************************************
    UseCpp = TRUE
    IF Stk$[2] = ":" THEN
        IF InClassPP[0] THEN
            FPRINT FP_UDT, ""
            CALL BumpDown("Error in Emit_CPP_" + szAccess$)
        END IF
        FPRINT FP_UDT, Scoot$, szAccess$, ":"
        CALL BumpUp
        InClassPP$ = szAccess$
    END IF
END SUB ' Emit_CPP_AccessSpecifier


FUNCTION Emit_CPP_Public(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    Emit_CPP_AccessSpecifier("public")
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Public


FUNCTION Emit_CPP_Asm(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    CALL Emit_Assignments(FuncRetnFlag)
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Asm



FUNCTION Emit_CPP_Protected(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    Emit_CPP_AccessSpecifier("protected")
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Protected



FUNCTION Emit_CPP_Private(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    Emit_CPP_AccessSpecifier("private")
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Private


FUNCTION Emit_CPP_EndNamespace(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UseCpp = TRUE
    FPRINT FP_UDT, Scoot$, "};\n"
    CALL BumpDown("Extra unindents and/or missing indents before END NAMESPACE")
    DECR InNameSpace
    FUNCTION = 0
END FUNCTION ' Emit_CPP_EndNamespace



FUNCTION Emit_CPP_Try(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UseCpp = TRUE
    FPRINT FP_WRITE, Scoot$, "try"
    CALL BumpUp
    FPRINT FP_WRITE, Scoot$, "{"
    CALL InBlockSet
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Try



FUNCTION Emit_CPP_EndTry(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UseCpp = TRUE
    FPRINT FP_WRITE, Scoot$, "}"
    CALL BumpDown("Unbalanced TRY/END TRY")
    CALL InBlockReSet
    FUNCTION = 0
END FUNCTION ' Emit_CPP_EndTry



FUNCTION Emit_CPP_Throw (sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UseCpp = TRUE
    DIM RAW LTmp$
    IF Ndx = 1 THEN
        LTmp$ = ENC$("An Exception has occured!")
    ELSE
        CALL BuildDelimStr(2, Ndx, LTmp$)
    END IF
    FPRINT FP_WRITE, Scoot$, "throw ", LTmp$, ";"
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Throw



FUNCTION Emit_CPP_Catch(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UseCpp = TRUE
    DIM RAW VarCode AS UDT_VARCODE_ATTRIBUTES
    VarCode.IsExported = FALSE
    VarCode.UseInLine = UseInLine
    CALL InBlockReSet
    gTmpStr$ = ""
    IF Ndx > 1 THEN
        DIM RAW A
        CALL FuncSubDecs1("sub", 1, Ndx, ADDRESSOF(VarCode))
        CALL FuncSubDecs2("sub", mt_Opts, ADDRESSOF(VarCode), 1, ADDRESSOF(Ndx))
        VarCode.Methd% = mt_FuncSubDecC_DecAParam
        A = 3
        DO WHILE A < Ndx
            CALL GetParameter(ADDRESSOF(A), ADDRESSOF(VarCode), mt_OptsAParam, mt_OptsNoParam, 1)
            INCR A
        LOOP
        VarCode.Methd% = mt_FuncSubDecC_DecAParam
        VarCode.Token$ = Stk$[1]
        FuncSubDecs3(ADDRESSOF(VarCode), Ndx, 0)
        gTmpStr$ = VarCode.Header$
    ELSE
        gTmpStr$ = "catch (PCTSTR str)"
    END IF
    FPRINT FP_WRITE, Scoot$, "}"
    CALL BumpDown("Extra unindents and/or missing indents before CATCH")
    CALL InBlockSet
    FPRINT FP_WRITE, Scoot$, gTmpStr$
    CALL BumpUp
    FPRINT FP_WRITE, Scoot$, "{"
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Catch



FUNCTION Emit_CPP_Delete(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(sWord)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    UseCpp = TRUE
    DIM RAW LTmp$
    CALL BuildCleanStr(2, Ndx, LTmp$)
    FPRINT FP_WRITE, Scoot$, "delete ", LTmp$, ";"
    FUNCTION = 0
END FUNCTION ' Emit_CPP_Delete



FUNCTION Emit_DialogBox(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "dialogbox" ' HELPER
            DIM L_Comma = 0
            FPRINT FP_WRITE, Scoot$, "DialogBox"; ' Suppress CRLF

            FOR A AS INT = 2 TO Ndx
                IF Stk$[A] = "," THEN INCR L_Comma

                IF L_Comma = 3 THEN
                    IF Stk$[A] = "," THEN Stk$[A] = ",(DLGPROC)"
                END IF

                FPRINT FP_WRITE, No_Sigil$(Stk$[A]); ' Suppress CRLF
            NEXT

            FPRINT FP_WRITE, ";"

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_DialogBox



FUNCTION Emit_Conditional_Operator_Repair$(szArg$)  ' Used by Emit_ConditionalCompilation()
    IF NOT INSTR (szArg$, ANY "=!<>|&" ) THEN FUNCTION = szArg$ ' MrBcx 819 updated code
    LOCAL Tmp$
    Tmp$ = TRIM$(szArg$)
    REPLACE   "= ="   WITH  "=="  IN Tmp$
    REPLACE   "! ="   WITH  "!="  IN Tmp$
    REPLACE   "< ="   WITH  "<="  IN Tmp$
    REPLACE   "> ="   WITH  ">="  IN Tmp$
    REPLACE   "| |"   WITH  "||"  IN Tmp$
    REPLACE   "& &"   WITH  "&&"  IN Tmp$
    REPLACE   "% ="   WITH  "%="  IN Tmp$
    REPLACE   "^ ="   WITH  "^="  IN Tmp$
    FUNCTION = Tmp$
END FUNCTION ' Emit_Conditional_Operator_Repair$



FUNCTION Emit_ConditionalCompilation(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "~ifndef"
            InIfDef$ = "#ifndef "
            FOR i AS INT = 2 TO Ndx
                InIfDef$ += Stk$[i] + SPC$
            NEXT
            InIfDef$ = Emit_Conditional_Operator_Repair$(InIfDef$)

            IF InFunction OR InMain THEN
                FPRINT FP_WRITE, InIfDef$
            ELSE
                FPRINT FP_CST, InIfDef$
            END IF



        CASE "~ifdef"
            InIfDef$ = "#if defined "

            FOR i AS INT = 2 TO Ndx
                InIfDef$ += Stk$[i] + SPC$
            NEXT

            InIfDef$ = Emit_Conditional_Operator_Repair$(InIfDef$)
            ConstLastDef$ = InIfDef$

            DIM tmp$                                                                               ' MrBcx 817 -- new
            tmp$ = TRIM$(LOOKAHEAD$(SourceFile, 1))                                                ' MrBcx 817 -- new
            IF LEFT$(tmp$, 4) ?? "SUB " OR  LEFT$(tmp$, 9) ?? "FUNCTION " THEN tmp$ = "SUSPEND"    ' MrBcx 817 -- new

            IF InFunction THEN
                FPRINT FP_WRITE, InIfDef$
                InIfDef$ = "FP3"
            ELSE
                IF InMain AND tmp$ <> "SUSPEND" THEN                                               ' MrBcx 817 -- modified
                    FPRINT FP_WRITE, InIfDef$
                END IF
            END IF



        CASE "~if"
            InIfDef$ = "#if "
            FOR i AS INT = 2 TO Ndx
                InIfDef$ += Stk$[i] + SPC$
            NEXT
            InIfDef$ = Emit_Conditional_Operator_Repair$(InIfDef$)
            ConstLastDef$ = InIfDef$
            IF InFunction THEN
                FPRINT FP_WRITE, InIfDef$
                InIfDef$ = "FP3"
            ELSE
                IF InMain THEN
                    FPRINT FP_WRITE, InIfDef$
                END IF
            END IF


        CASE "~elseif"
            InIfDef$ = "#elif defined "
            FOR i AS INT = 2 TO Ndx
                InIfDef$ += Stk$[i] + SPC$
            NEXT
            InIfDef$ = Emit_Conditional_Operator_Repair$(InIfDef$)
            ConstLastDef$ = InIfDef$
            IF InFunction OR InMain THEN
                FPRINT FP_WRITE, InIfDef$
            ELSE
                FPRINT FP_CST, InIfDef$
            END IF


        CASE "~else"
            InIfDef$ = "#else"
            ConstLastDef$ = InIfDef$
            IF InFunction OR InMain THEN
                FPRINT FP_WRITE, InIfDef$
            ELSE
                FPRINT FP_CST, InIfDef$
            END IF



        CASE "~endif"
            IF InIfDef$ = "FP3" THEN
                FPRINT FP3, "#endif"
            ELSE
                FPRINT FP_WRITE, "#endif"
            END IF

            IF ConstLastDef$ = "FP_CST" THEN
                FPRINT FP_CST, "#endif"
            END IF

            InIfDef$ = "#endif"

            IF InConditional = 0 THEN
                InIfDef$ = ""
                ConstLastDef$ = ""
            END IF


        CASE "~pragmaoptimizeon"
            FPRINT FP_WRITE, "#ifdef __POCC__"
            FPRINT FP_WRITE, "#pragma optimize(time)"
            FPRINT FP_WRITE, "#endif"

            FPRINT FP_WRITE, "#ifdef __LCC__"
            FPRINT FP_WRITE, "#pragma optimize(1)"
            FPRINT FP_WRITE, "#endif"

        CASE "~pragmaoptimizeoff"
            FPRINT FP_WRITE, "#ifdef __POCC__"
            FPRINT FP_WRITE, "#pragma optimize(none)"
            FPRINT FP_WRITE, "#endif"

            FPRINT FP_WRITE, "#ifdef __LCC__"
            FPRINT FP_WRITE, "#pragma optimize(0)"
            FPRINT FP_WRITE, "#endif"

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_ConditionalCompilation




FUNCTION Emit_Shared_Global(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "shared", "global"
            STATIC wxy
            STATIC szSizeOf$
            STATIC IsShared
            STATIC IsVolatile
            STATIC IsSubOrFuncPtr
            STATIC CVar$
            STATIC id, vt, dimensions, IsPointer
            STATIC LZZ$

            wxy = 0
            IsSubOrFuncPtr = SubFuncTest()
            CALL Process_Option_Base
            IsVolatile = m_iMatchWrd(Stk$[2], "volatile")
            CVar$ = No_Sigil$(Stk$[2+IsVolatile])
            CALL ValidateVarName(CVar$)

            IsShared = m_iMatchWrd(Stk$[1], "shared")

            IF Stk$[Ndx] = "*" THEN CALL PointerFix
            IF Stk$[Ndx] = "&" THEN
                Stk$[Ndx--] = ""
                Stk$[Ndx] += "&"
            END IF

            IF Stk$[3+IsVolatile] = "*" THEN
                IF IsVolatile THEN Abort("volatile dynamic strings not supported")
                CALL DimDynaString(CVar$, 1, IsShared)
                EXIT SELECT
            END IF

            IF IsSubOrFuncPtr THEN
                IF IsVolatile THEN Abort("volatile SUB/FUNCTION pointers not supported")
                CALL DimSubFunc(0)
                EXIT SELECT
            END IF

            IF m_iMatchWrd(Stk$[2], "dynamic") THEN
                CVar$ = No_Sigil$(Stk$[3])

                CALL ValidateVarName(CVar$)
                IF m_iMatchWrd(Stk$[Ndx-1], "as") THEN
                    szSizeOf$ = Stk$[Ndx]
                    GetTypeInfo(szSizeOf$, ADDRESSOF(wxy), ADDRESSOF(id), ADDRESSOF(vt))
                    IF vt = vt_STRLIT OR vt = vt_DECFUNC OR vt = vt_NUMBER OR (vt = vt_VOID AND INCHR(Stk$[Ndx], "*") = 0) THEN
                        Abort(Stk$[Ndx] + " is not a valid type")
                    END IF
                    DECR Ndx, 2
                ELSE
                    vt = DataType(Stk$[3])
                    id = 0
                    szSizeOf$ = GetVarTypeName$(vt)
                END IF

                Use_DynamicA = Use_BcxTempStr = TRUE

                CALL BuildStr(4, Ndx, LZZ$)
                dimensions = TALLY(LZZ$, "][") + 1

                IF dimensions > 1 THEN REPLACE "][" WITH "," IN LZZ$

                LZZ$ = No_Sigil$(LZZ$)
                RemoveAll(LZZ$, "[]")

                IF vt = vt_STRVAR THEN
                    vt = vt_CHAR
                    szSizeOf$ = "char"
                    INCR dimensions
                    LZZ$ += ","
                    LZZ$ += "BCXSTRSIZE"
                END IF

                IF Use_GenFree THEN
                    CALL AddDynamicGlobal("if (" + CVar$ + ") {DestroyArr((void **)" + CVar$ + "," + STR$(dimensions) + ", 1); " +  CVar$ + "=NULL;}")
                END IF

                CALL AddGlobal(CVar$, vt, id, "", dimensions)

                REPLACE "," WITH ", (size_t)" IN LZZ$

                FPRINT FP_WRITE, Scoot$, "{"
                FPRINT FP_WRITE, Scoot$, "size_t dimensions[", STR$(dimensions, 1), "] = {(size_t)", LZZ$, "};" '
                FPRINT FP_WRITE, Scoot$, CVar$ , "= (", szSizeOf$ , STRING$(dimensions, 42), ")CreateArr (", CVar$ , ", sizeof(", szSizeOf$, "), 0,", STR$(dimensions, 1), ", dimensions);"
                FPRINT FP_WRITE, Scoot$, "}"
                EXIT SELECT
            END IF

            IsPointer = 0

            Var$ = No_Sigil$(Stk$[2+IsVolatile])
            CALL ValidateVarName(Var$)

            IF m_iMatchWrd(Stk$[Ndx-1], "as") THEN
                IF INCHR(Stk$[Ndx], "*") THEN
                    IsPointer = TALLY(Stk$[Ndx], "*")
                    Stk$[Ndx] = REMOVE$(Stk$[Ndx], "*")
                END IF
                CALL BuildStr(3+IsVolatile, Ndx-2, DimType$)
                GetTypeInfo(Stk$[Ndx], ADDRESSOF(wxy), ADDRESSOF(id), ADDRESSOF(vt))
            ELSE
                CALL BuildStr(3+IsVolatile, Ndx, DimType$)
                vt = DataType(Stk$[2+IsVolatile])
                id = 0
            END IF

            IF vt = vt_STRVAR THEN
                DimType$ += "[BCXSTRSIZE]"
            END IF
            ' global object in sub/func
            IF vt = vt_UDT THEN
                IF ComSwitchON THEN
                    IF TypeDefs[id].VarName$ = "OBJECT" THEN
                        Add_Com_Global_Var(CVar$)
                        Use_COM = Use_BcxTempStr = TRUE
                    END IF
                END IF
            END IF

            wxy = 0
            IF IsShared THEN wxy = 2
            IF IsVolatile THEN wxy = wxy + 3
            CALL AddGlobal(Var$, vt, id, DimType$, IsPointer, 0, wxy)

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_Shared_Global




FUNCTION Emit_EndFuncSub(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "endfunction", "endsub"
            '*******************************************************************************
            ' MrBcx Speaks:                                      Version 830   October 2025
            ' These 4 statements are crucial for correctly freeing LOCAL DYNAMIC ARRAY and
            ' for determining when to inject "Bcx_RetVal" as a function return variable.
            '*******************************************************************************
            AuxLocalDynArrayCount = 0
            g_FoundLocalDynArray = FALSE
            InFunction = FALSE
            InMain = TRUE
            '******************************************************************************

            IF LoopTypeCnt THEN
                CALL LoopErrorMsg
            END IF

            IF COM_lc_names_index > 0 THEN
                ' cleaning local COM objects if user forgot to
                ' call xxx = Nothing for each declared object
                CALL Free_Com_Objects(TRUE)
            END IF

            IF m_iMatchWrd(Stk$[1], "endfunction") THEN
                InWinMain = FALSE
                LocalDynaCnt = 0
                LocalDynArrCnt = 0

                IF InDialogEvt THEN
                    FPRINT FP_WRITE, Scoot$, "if(Msg==WM_CLOSE) DestroyWindow(hWnd);"
                    IF Use_Sound THEN
                        FPRINT FP_WRITE, Scoot$, "midiOutClose (hMidi);"  ' Added by MrBcx 825
                    END IF
                    FPRINT FP_WRITE, Scoot$, "return EXIT_SUCCESS;"
                    InDialogEvt = FALSE
                END IF

                IF ModDialogEvt THEN
                    FPRINT FP_WRITE, Scoot$, "if(Msg==WM_CLOSE) EndDialog(hWnd,0);"
                    IF Use_Sound THEN
                        FPRINT FP_WRITE, Scoot$, "midiOutClose (hMidi);"  ' Added by MrBcx 825
                    END IF
                    FPRINT FP_WRITE, Scoot$, "return EXIT_SUCCESS;"
                    ModDialogEvt = FALSE
                END IF

                IF CallBackFlag THEN
                    FPRINT FP_WRITE, Scoot$, "return DefWindowProc(hWnd, Msg, wParam, lParam);"
                    CallBackFlag = FALSE
                END IF
            END IF

            IF m_iMatchWrd(Stk$[1], "endsub") THEN


                ' Clean up dynamic strings
                IF NOTZERO (LocalDynaCnt) THEN

                    FOR j AS INT = 1 TO LocalDynaCnt
                        FPRINT FP_WRITE, Scoot$, DynaStr$[j]
                    NEXT

                    LocalDynaCnt = 0
                END IF
                ' Clean up dynamic strings arrays
                IF NOTZERO(LocalDynArrCnt) THEN

                    FOR i AS INT = 1 TO LocalDynArrCnt
                        FPRINT FP_WRITE, Scoot$, LocalDynArrName$[i]
                    NEXT

                    LocalDynArrCnt = 0
                END IF
            END IF

            IF ForceMainToFunc = TRUE AND NoMain = FALSE THEN
                IF Use_Sound THEN
                    FPRINT FP_WRITE, Scoot$, "midiOutClose (hMidi);"  ' Added by MrBcx 825
                END IF
                FPRINT FP_WRITE, Scoot$, "return EXIT_SUCCESS;"
                ForceMainToFunc = FALSE
            END IF

            CALL BumpDown("Unbalance statements occurred before END")

            IF InNameSpace OR InClass OR InCppTypeDef THEN
                FPRINT FP_UDT, Scoot$, "}\n"

                DIM iIndentsUsed AS INT, szErr$

                iIndentsUsed = 0
                szErr$ = ""
                IF InNameSpace THEN
                    INCR iIndentsUsed, (InNameSpace * 2)
                    szErr$ = " Namespace,"
                END IF
                IF InClass THEN
                    INCR iIndentsUsed, ((InClass+1) * 2)
                    szErr$ += " Class Module,"
                END IF
                IF InCppTypeDef THEN
                    INCR iIndentsUsed, (InCppTypeDef * 2)
                    szErr$ += " PPType,"
                END IF
                IF Indent > iIndentsUsed THEN
                    szErr$ = LEFT$(szErr$, LEN(szErr$)-1)
                    szErr$ = "Possible missing (" + USING$("##", (Indent-iIndentsUsed)* 0.5) + ") END statements in" + szErr$ + " SUB/FUNCTION"
                    PRINT REPEAT$(80, "_")
                    PRINT szErr$
                    PRINT REPEAT$(80, "_")
                END IF
            ELSE
                FPRINT FP_WRITE, Scoot$, "}\n\n"
            END IF

            InFunction = Use_Static = FALSE

            IF FP_WRITE = FP3 THEN
                InIfDef$ = "FP3"
            END IF

            IF NOT (InNameSpace OR InClass) THEN
                FP_WRITE = FP2
            END IF
            ByrefCnt = 0

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_EndFuncSub




FUNCTION Emit_Union(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$
        CASE "union"

            IF InTypeDef = 0 THEN
                SaveFP_WRITENum = FP_WRITE
            END IF

            FP_WRITE = FP_UDT

            INCR InTypeDef

            IF c_MaxBaseTypeDefs = InTypeDef THEN
                CALL Abort("Maximum number of nested TypeDefs exceeded.")
            END IF

            TypeDefName$[InTypeDef] = Stk$[2]
            CALL AddTypeDefs(TypeDefName$[InTypeDef], vt_UNION)
            BaseTypeDefsCnt[InTypeDef] = TypeDefsCnt
            FPRINT FP_WRITE, ""

            IF InTypeDef = 1 THEN
                FPRINT FP_WRITE, "typedef union "
                FPRINT FP_WRITE, "{"
            ELSE
                FPRINT FP_WRITE, Scoot$, "union"
                FPRINT FP_WRITE, Scoot$, "{"
                CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef-1], vt_UNION, TypeDefName$[InTypeDef], TypeDefName$[InTypeDef])
            END IF
            CALL BumpUp

        CASE "endunion"
            CALL BumpDown("Unbalanced UNION/END UNION")
            IF InTypeDef = 1 THEN
                FPRINT FP_WRITE, "} ", TypeDefName$[InTypeDef], ", *LP", UCASE$(TypeDefName$[InTypeDef]), ", *", UCASE$(TypeDefName$[InTypeDef]), "_PTR", ";"
                FP_WRITE = SaveFP_WRITENum
            ELSE
                FPRINT FP_WRITE, Scoot$, "} ", TypeDefName$[InTypeDef], ";"
            END IF
            FPRINT FP_WRITE, ""
            DECR InTypeDef

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_Union




FUNCTION Emit_Type(sWord$, FuncRetnFlag AS PINT)
    UNREFERENCED_PARAMETER(FuncRetnFlag)
    SELECT CASE sWord$
        CASE "type"
            STATIC i, j
            IF InTypeDef = 0 THEN
                SaveFP_WRITENum = FP_WRITE
            END IF
            FP_WRITE = FP_UDT

            IF Ndx > 2 THEN
                IF InTypeDef THEN
                    CALL Abort("Single line TYPE within type/union not supported")
                END IF

                i = m_GetAsPosB(Ndx, 1)

                IF i = 0 THEN
                    CALL Abort("Missing AS TYPE")
                END IF
                FPRINT FP_WRITE, Scoot$, "typedef "; ' Suppress CRLF
                j = i-1
                INCR i

                DO WHILE i <= Ndx
                    FPRINT FP_WRITE, Stk$[i], SPC$;  ' Suppress CRLF
                    INCR i
                LOOP

                FOR i = 2 TO j
                    FPRINT FP_WRITE, Stk$[i];        ' Suppress CRLF
                NEXT
                FPRINT FP_WRITE, ";"
                FP_WRITE = SaveFP_WRITENum
            ELSE
                INCR InTypeDef

                IF c_MaxBaseTypeDefs = InTypeDef THEN
                    CALL Abort("Maximum number of nested TypeDefs exceeded.")
                END IF

                TypeDefName$[InTypeDef] = Stk$[2]
                CALL AddTypeDefs(TypeDefName$[InTypeDef], vt_STRUCT)
                BaseTypeDefsCnt[InTypeDef] = TypeDefsCnt
                IF InClass OR InTypeDef > 1 THEN
                    FPRINT FP_WRITE, Scoot$, "struct"
                    FPRINT FP_WRITE, Scoot$, "{"
                    CALL AddTypedefElement(BaseTypeDefsCnt[InTypeDef-1], vt_STRUCT, TypeDefName$[InTypeDef], TypeDefName$[InTypeDef])
                ELSE
                    FPRINT FP_WRITE, ""
                    FPRINT FP_WRITE, "typedef struct _", TypeDefName$[InTypeDef]
                    FPRINT FP_WRITE, "{"
                END IF
                CALL BumpUp
            END IF



        CASE "endtype"
            CALL BumpDown("Unbalanced TYPE/END TYPE")
            IF InClass THEN
                FPRINT FP_WRITE, Scoot$, "} ", TypeDefName$[InTypeDef], ";"
                FPRINT FP_WRITE, ""
            ELSE
                DIM szTDNames$
                IF Ndx > 1 THEN
                    STATIC i, j
                    i = m_GetAsPosB(Ndx, 1)

                    IF i = 0 THEN
                        CALL Abort("Missing AS after END TYPE")
                    END IF

                    szTDNames$ = ", "
                    FOR ii AS INT = i+1 TO Ndx
                        j = INCHR(Stk$[ii], "*")
                        IF j THEN Stk$[ii] = MID$(Stk$[ii], j)+LEFT$(Stk$[ii], j - 1)
                        szTDNames$ += Stk$[ii]
                    NEXT
                END IF
                IF InTypeDef = 1 THEN
                    FPRINT FP_WRITE, "}", TypeDefName$[InTypeDef], ", *LP", UCASE$(TypeDefName$[InTypeDef]), ", *", UCASE$(TypeDefName$[InTypeDef]), "_PTR", szTDNames$, ";"
                    FPRINT FP_WRITE, ""
                    FP_WRITE = SaveFP_WRITENum
                    '  FPRINT FP_CST, Scoot$, "#define ", UCASE$(TypeDefName$[InTypeDef]), "_CLASS struct _", UCASE$(TypeDefName$[InTypeDef]), "*"
                    '  ^^^   Replaced with improved formatting below --- 838 MrBcx

                    DIM sztemp$
                    sztemp$ = "#define " + UCASE$(TypeDefName$[InTypeDef]) + "_CLASS"
                    WHILE LEN(sztemp$) < 44  ' Not 45 ... see next comment below
                        sztemp$ += SPC$
                    END WHILE
                    '***********************************************************************************************
                    ' The space that precedes " struct _" ensures a separation between the identifier and the value
                    '***********************************************************************************************
                    FPRINT FP_CST, Scoot$, sztemp$, " struct _", UCASE$(TypeDefName$[InTypeDef]), "*"
                ELSE
                    FPRINT FP_WRITE, Scoot$, "} ", TypeDefName$[InTypeDef], szTDNames$, ";"
                    FPRINT FP_WRITE, ""
                END IF
            END IF
            DECR InTypeDef
    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_Type






FUNCTION Emit_PPType(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "pptype"
            FP_WRITE = FP_UDT

            IF InTypeDef OR InCppTypeDef OR InClass OR InFunction OR ISNULL(Stk$[2]) THEN
                CALL Abort("Syntax Error")
            END IF

            FPRINT FP_UDT, ""

            IF InIfDef$ <> "FP3" AND NOTNULL(InIfDef$) THEN
                FPRINT FP_UDT, InIfDef$
            END IF

            FPRINT FP_UDT, "struct "; ' Suppress CRLF
            FOR i AS INT = 2 TO Ndx
                IF m_iMatchWrd(Stk$[i], "using") THEN Stk$[i] = ": "
                AddSpace(i)
                FPRINT FP_UDT, Stk$[i]; ' Suppress CRLF
            NEXT
            CALL BumpUp
            FPRINT FP_UDT, "\n", Scoot$, "{"
            INCR InCppTypeDef

        CASE "endpptype"

            IF InCppTypeDef <> 1 THEN
                CALL Abort("Syntax Error")
            END IF

            CALL BumpDown("Extra unindents and/or missing indents before END PPTYPE")
            FPRINT FP_UDT, Scoot$, "};"
            DECR InCppTypeDef

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_PPType



SUB GetParameterASHelper _
    (iEQPos AS INT, _
    iASPos AS INT, _
    iOptOk AS INT, _
    iLoc AS INT)
    STATIC iLast

    IF iOptOk = 0 THEN
        CALL Abort("Optional variables not supported without OPTIONAL")
    END IF

    IF iASPos = 0 THEN
        iLast = iLoc
    ELSE
        IF iASPos < iEQPos THEN
            iLast = iLoc
        ELSE
            iLast = iASPos-1
        END IF
    END IF
    FOR i AS INT = iEQPos+1 TO iLast
        Stk$[iEQPos] += SPC$
        Stk$[iEQPos] += Stk$[i]
        Stk$[i] = ""
    NEXT
END SUB ' GetParameterASHelper



SUB GetParameter _
    (piStart AS PINT, _
    ptVar AS UDT_VARCODE_ATTRIBUTES PTR, _
    iAParam AS INT, _
    iNoParam AS INT, _
    iOptOk AS INT)
    '**************************
    ' This is a recursive SUB
    '**************************
    DIM iASPos = 0
    DIM iEQPos = 0
    DIM iNd
    DIM iLoc = *piStart
    IF ISNULL(Stk$[iLoc]) THEN EXIT SUB

    ptVar->Token$ = No_Sigil$(Stk$[iLoc])

    DO
        IF Stk$[iLoc+1] = "(" THEN
            ' function as parameter type
            DIM RAW iEndPoint    ' 837 Changed from STATIC to RAW   -- MrBcx
            DIM RAW LTmp$        ' 837 Changed from STATIC to RAW   -- MrBcx
            DIM RAW iStartPoint  ' 837 Changed from STATIC to RAW   -- MrBcx
            DIM RAW ACS AS UDT_ARG_COMMAS_STORAGE
            CLEAR(ACS)

            CallType$ = ""
            CALL SepFuncArgs(iLoc-1, ADDRESSOF(ACS), TRUE)
            iStartPoint = IMAX(ACS.CommaPos[0], iLoc)
            g_SubFuncPtr = TRUE
            ' ------------------------------------------------------
            '  Get intialized data  " = xxx" or "= {xxx,xxx}"
            ' ------------------------------------------------------
            IF ACS.NumArgs = 0 THEN
                iEndPoint = IMIN(ACS.CommaPos[1]+1, Ndx)
            ELSE
                iEndPoint = IMIN(ACS.CommaPos[ACS.NumArgs]+1, Ndx)
            END IF

            IF Stk$[iEndPoint] = "=" THEN
                Stk$[iEndPoint++] = ""
                DO WHILE NOT (iEndPoint <= Ndx) AND (m_iMatchWrd(Stk$[iEndPoint], "as"))
                    LTmp$ += Stk$[iEndPoint]
                    Stk$[iEndPoint++] = ""
                LOOP
                RemoveAll(LTmp$, "{}", 1)
                IF NOTNULL(LTmp$) THEN CALL RemEmptyTokens
            END IF
            ' ------------------------------------------------------
            DIM RAW L_FuncName$    ' 837 Changed from STATIC to RAW   -- MrBcx
            DIM RAW OldiEndPoint   ' 837 Changed from STATIC to RAW   -- MrBcx
            IF m_iMatchWrd(Stk$[iEndPoint], "as") THEN
                INCR iEndPoint
                IF m_iMatchWrd(Stk$[iEndPoint], "function") THEN
                    LShiftStk(iEndPoint)
                END IF
                DO WHILE *Stk$[iEndPoint] <> ASC(",") AND *Stk$[iEndPoint] <> ASC(")")
                    IF ISNULL(Stk$[iEndPoint]) THEN
                        LShiftStk(iEndPoint)
                    ELSE
                        INCR iEndPoint
                    END IF
                LOOP
            END IF
            OldiEndPoint = iEndPoint

            DIM RAW tVar AS UDT_VARCODE_ATTRIBUTES     ' 837 Changed from STATIC to RAW   -- MrBcx
            tVar.IsExported = FALSE
            tVar.UseInLine = UseInLine

            *piStart = iStartPoint-1
            CALL InsertTokens((*piStart)-1, 1, "function")
            CALL FuncSubDecs1("sub", iStartPoint-1, iEndPoint, ADDRESSOF(tVar))
            CALL FuncSubDecs2("sub", mt_FuncSubDecC_Dec, ADDRESSOF(tVar), *piStart, ADDRESSOF(OldiEndPoint))
            tVar.Functype$ = LTRIM$(tVar.Functype$)
            L_FuncName$ = No_Sigil$(Stk$[iStartPoint])
            *piStart = iStartPoint+2
            DO WHILE *piStart < OldiEndPoint
                CALL GetParameter(piStart, ADDRESSOF(tVar), mt_FuncSubDecC_DecAParam, mt_FuncSubDecC_DecNoParam, 0)
                (*piStart)++
            LOOP

            tVar.Methd% = mt_FuncSubDecC_DecAParam
            tVar.Token$ = L_FuncName$
            FuncSubDecs3(ADDRESSOF(tVar), OldiEndPoint, 1)
            ptVar->Header$ += tVar.Header$
            ptVar->Proto$ += tVar.Proto$
            *piStart = iEndPoint
            IF Stk$[(*piStart)+1] = "," THEN
                ptVar->Header$ += ","
                ptVar->Proto$ += ","
                (*piStart)++
            END IF
            g_SubFuncPtr = FALSE
            EXIT SUB
        END IF
        IF Stk$[iLoc] = "," OR Stk$[iLoc] = ")" THEN EXIT DO
        IF m_iMatchWrd(Stk$[iLoc], "as") THEN iASPos = iLoc
        IF m_iMatchWrd(Stk$[iLoc], "=") THEN iEQPos = iLoc
        INCR iLoc
    LOOP
    DECR iLoc
    IF Stk$[iLoc] <> "..." THEN
        DIM iIsConst = 0
        IF iEQPos THEN CALL GetParameterASHelper(iEQPos, iASPos, iOptOk, iLoc)
        IF iASPos THEN
            DIM iLast = iLoc
            DIM iAfterAs1 = iASPos+1
            DIM iAfterAs2 = iASPos+2
            IF iASPos < iEQPos THEN iLast = iEQPos-1
            IF iAfterAs1 <> iLast THEN
                IF m_iMatchWrd(Stk$[iAfterAs1], "const") THEN
                    iIsConst = 1
                    Stk$[iAfterAs1] += SPC$
                    Stk$[iAfterAs1] += Stk$[iAfterAs2]
                    Stk$[iAfterAs2] = ""
                END IF

                XFOR INT i = iAfterAs2 WHILE i <= iLast BY i++
                    IF m_iMatchWrd(Stk$[i], "ptr") THEN Stk$[i] = "*"
                    Stk$[iAfterAs1] += Stk$[i]
                    Stk$[i] = ""
                XNEXT

            END IF
            ptVar->AsToken$ = Stk$[iAfterAs1]
            CALL GetTypeInfo(ptVar->AsToken$, ADDRESSOF((ptVar->IsPtrFlag)), ADDRESSOF(iNd), ADDRESSOF((ptVar->VarNo)))
        ELSE
            DIM iPtrCnt = TALLY(Stk$[*piStart], "*")
            ptVar->AsToken$ = VarTypeLookup$[INCHR(c_VARTYPES$, RIGHT$(Stk$[*piStart], 1))] + STRING$(iPtrCnt, ASC("*"))
            REMOVE "*" FROM Stk$[*piStart]
            CALL GetTypeInfo(ptVar->AsToken$, ADDRESSOF((ptVar->IsPtrFlag)), ADDRESSOF(iNd), ADDRESSOF((ptVar->VarNo)))
        END IF
        ptVar->Methd% = iAParam
        CALL GetVarCode(ptVar, "GetParameter 1")

        IF iEQPos THEN
            ptVar->Methd% = iNoParam
            ptVar->Token$ = Stk$[iEQPos]
            CALL GetVarCode(ptVar, "GetParameter 2")
        END IF

        CALL AddLocal(ptVar->Token$, ptVar->VarNo, 0, "", ptVar->IsPtrFlag, 0, 0, iIsConst)
    ELSE
        ptVar->Methd% = iNoParam
        ptVar->Token$ = Stk$[iLoc]
        CALL GetVarCode(ptVar, "GetParameter 3")

    END IF

    INCR iLoc
    IF Stk$[iLoc] = "," THEN
        ptVar->Methd% = iNoParam
        ptVar->Token$ = Stk$[iLoc]
        CALL GetVarCode(ptVar, "GetParameter 4")
    END IF

    *piStart = iLoc
END SUB ' GetParameter



FUNCTION Emit_OptFuncSub(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$

        CASE "optfunction", "optsub"  ' , "optdeclare"
            DIM RAW IOptLoc AS INT
            DIM RAW VarCode AS UDT_VARCODE_ATTRIBUTES
            VarCode.IsExported = FALSE
            VarCode.UseInLine = UseInLine

            CALL FuncSubDecs1("optsub", 1, Ndx, ADDRESSOF(VarCode))

            InFunction = TRUE
            LocalVarCnt = 0

            IF InNameSpace THEN
                FP_WRITE = FP2
            ELSE
                IF UsingTemplate = FALSE THEN
                    FP_WRITE = FP3
                END IF
            END IF

            CALL FuncSubDecs2("optsub", mt_Opts, ADDRESSOF(VarCode), 1, ADDRESSOF(Ndx))

            FunctionName$ = No_Sigil$(Stk$[2])

            IOptLoc = 4

            DO WHILE IOptLoc < Ndx
                CALL GetParameter(ADDRESSOF(IOptLoc), ADDRESSOF(VarCode), mt_OptsAParam, mt_OptsNoParam, 1)
                INCR IOptLoc
            LOOP

            VarCode.Methd% = mt_FuncSubDecC_DecAParam
            VarCode.Token$ = FunctionName$
            FuncSubDecs3(ADDRESSOF(VarCode), Ndx, 0)

            IF Use_Static THEN
                VarCode.Header$ = "static " + VarCode.Header$
                VarCode.Proto$ = "static " + VarCode.Proto$
            END IF

            CALL AddProto(VarCode.Proto$)

            IF InIfDef$ = "FP3" THEN
                ProtoType[ProtoCnt].Condition$ = ""
            ELSE
                ProtoType[ProtoCnt].Condition$ = InIfDef$
            END IF
            ProtoType[ProtoCnt].CondLevel  = InConditional

            FPRINT FP_WRITE, VarCode.Header$    ' 775 MrBcx - Do not change these two
            FPRINT FP_WRITE, Scoot$, "{"        ' lines. You will break c++ parsing!
            CALL BumpUp

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_OptFuncSub



FUNCTION Emit_OverLoadFuncSub(sWord$, FuncRetnFlag AS PINT)
    STATIC VarCode AS UDT_VARCODE_ATTRIBUTES
    GLOBAL Use_Overloaded_Macro = TRUE

    VarCode.IsExported = FALSE
    VarCode.UseInLine = UseInLine

    SELECT CASE sWord$

        CASE "overloadedfunction", "overloadedsub"
            STATIC LTmp$
            STATIC A
            Use_Overloaded = TRUE
            CALL FuncSubDecs1("overloadedsub", 1, Ndx, ADDRESSOF(VarCode))
            IF sWord$ = "overloadedfunction" THEN
                InFunction = eFunctionType
            ELSE
                InFunction = eSubType
            END IF
            InMain = FALSE
            LocalVarCnt = 0

            IF UsingTemplate = FALSE THEN
                FP_WRITE = FP_OVR    ' <<----- writing TO BCX.OVR
            END IF

            CALL FuncSubDecs2("overloadedsub", mt_OverLoad, ADDRESSOF(VarCode), 1, ADDRESSOF(Ndx))

            FunctionName$ = No_Sigil$(Stk$[2])
            LTmp$ = " overloaded " + FunctionName$
            FunctionName$ = LTmp$

            A = 4
            DO WHILE A < Ndx
                CALL GetParameter(ADDRESSOF(A), ADDRESSOF(VarCode), mt_OverLoadAParam, mt_OverLoadNoParam, 0)
                INCR A
            LOOP

            VarCode.Methd% = mt_FuncSubDecC_Dec
            VarCode.Token$ = FunctionName$
            FuncSubDecs3(ADDRESSOF(VarCode), Ndx, 0)

            IF Use_Static THEN
                VarCode.Header$ = "static " + VarCode.Header$
            END IF

            FPRINT FP_WRITE, VarCode.Header$    ' 775 MrBcx - Do not change these two
            FPRINT FP_WRITE, Scoot$, "{"        ' lines. You will break c++ parsing!

            CALL BumpUp

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_OverLoadFuncSub



FUNCTION ClassProto(szProto AS PCHAR)
    '************************************************************************
    ' This FUNCTION checks if a given prototype string (szProto$) matches any
    ' of the class names stored in the ClassNames$ array. It iterates through
    ' the array and returns 1 if a match is found, otherwise returns 0.
    '************************************************************************
    STATIC iReturn
    STATIC iCnt
    XFOR iReturn = 0, iCnt = 0 WHILE iCnt < iClassCnt AND iReturn = 0 BY iCnt++
        IF szProto$ = ClassNames$[iCnt] THEN iReturn = 1
    XNEXT
    FUNCTION = iReturn
END FUNCTION ' ClassProto



FUNCTION Emit_ConDes(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$
        CASE "constructor", "destructor"

            IF InFunction THEN
                CALL Abort("Syntax Error: already in function")
            END IF

            DIM RAW A
            DIM RAW CTOR_USE$
            DIM RAW New_Ndx = Ndx
            DIM RAW iCPPFunSub
            DIM RAW VarCode AS UDT_VARCODE_ATTRIBUTES
            VarCode.IsExported = FALSE
            VarCode.UseInLine = UseInLine
            iCPPFunSub = 0

            FOR ct AS INT = 1 TO Ndx
                IF Stk$[ct] = "using" THEN
                    iCPPFunSub = 1
                    New_Ndx = ct-1
                    CALL BuildDelimStr(ct+1, Ndx, CTOR_USE$)
                    EXIT FOR
                END IF
            NEXT
            Ndx = New_Ndx

            CALL FuncSubDecs1("sub", 1, Ndx, ADDRESSOF(VarCode))
            IsStdFunc = FALSE

            InMain = FALSE
            LocalVarCnt = 0

            IF InNameSpace OR InClass OR InCppTypeDef THEN
                InFunction = FALSE
                FP_WRITE = FP_UDT
            ELSE
                InFunction = TRUE
                IF UsingTemplate = FALSE THEN
                    FP_WRITE = FP3
                END IF
            END IF

            CALL FuncSubDecs2("sub", mt_ConsDes, ADDRESSOF(VarCode), 1, ADDRESSOF(Ndx))
            ' to compensate previous substitution errors not fixed

            VarCode.Functype$ = LTRIM$(VarCode.Functype$)
            FunctionName$ = No_Sigil$(Stk$[2])

            A = 4
            DO WHILE A < Ndx
                CALL GetParameter(ADDRESSOF(A), ADDRESSOF(VarCode), mt_ConsDesAParam, mt_ConsDesNoParam, 1)
                INCR A
            LOOP

            IF (sWord$ = "constructor") OR (ISTRUE(INCHR(FunctionName$, "~"))) THEN
                VarCode.Token$ = FunctionName$
            ELSE
                VarCode.Token$ = "~" + FunctionName$
            END IF

            VarCode.Methd% = mt_FuncSubDecC_DecAParam
            FuncSubDecs3(ADDRESSOF(VarCode), Ndx, 0)

            IF Use_Static THEN
                VarCode.Header$ = "static " + VarCode.Header$
                VarCode.Proto$  = "static " + VarCode.Proto$
            END IF

            IF iMatchNQ (VarCode.Proto$, "::") = 0 AND m_IAmNot(InNameSpace) AND m_IAmNot(InClass) AND m_IAmNot(InCppTypeDef) THEN
                iCPPFunSub = 0
                CALL AddProto(VarCode.Proto$)
                IF InIfDef$ = "FP3" THEN
                    IF ProtoCnt > 1 THEN
                        ProtoType[ProtoCnt].Condition$ = ProtoType[ProtoCnt-1].Condition$
                    ELSE
                        ProtoType[ProtoCnt].Condition$ = ""
                    END IF
                ELSE
                    ProtoType[ProtoCnt].Condition$ = InIfDef$
                END IF

                ProtoType[ProtoCnt].CondLevel  = InConditional

                IF *InIfDef$ THEN
                    IF InIfDef$ <> "FP3" THEN
                        FPRINT FP_WRITE, InIfDef$
                    END IF
                END IF
            END IF

            IF iCPPFunSub = 1 THEN
                FPRINT FP_WRITE, Scoot$, VarCode.Header$, ": ", CTOR_USE$
            ELSE
                FPRINT FP_WRITE, Scoot$, VarCode.Header$  ' 775 MrBcx - Do not change these two
            END IF
            FPRINT FP_WRITE, Scoot$, "{"                  ' lines. You will break c++ parsing!
            CALL BumpUp

        CASE "endconstructor"
            CALL BumpDown("Unbalanced CONSTRUCTOR/END CONSTRUCTOR")
            FPRINT FP_WRITE, Scoot$, "}"
            InFunction = FALSE

        CASE "enddestructor"
            CALL BumpDown("Unbalanced DESTRUCTOR/END DESTRUCTOR")
            FPRINT FP_WRITE, Scoot$, "}"
            InFunction = FALSE

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_ConDes




FUNCTION Emit_Implied(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$
        ' IMPFUNCTION module() = 0 AS virtual double
        CASE "impfunction"
            DIM RAW A
            DIM RAW szImp$
            DIM RAW VarCode AS UDT_VARCODE_ATTRIBUTES
            VarCode.IsExported = FALSE
            VarCode.UseInLine = UseInLine

            CALL FuncSubDecs1("sub", 1, Ndx, ADDRESSOF(VarCode))
            IsStdFunc = FALSE
            InMain = FALSE
            LocalVarCnt = 0
            CALL FuncSubDecs2("sub", mt_FuncSubDecC_Dec, ADDRESSOF(VarCode), 1, ADDRESSOF(Ndx))
            szImp$ = ""
            DO
                szImp$ = Stk$[Ndx]+ szImp$
            LOOP WHILE Stk$[Ndx--] <> "="

            ' to compensate previous substitution errors not fixed

            VarCode.Functype$ = LTRIM$(VarCode.Functype$)
            FunctionName$ = No_Sigil$(Stk$[2])

            A = 4
            DO WHILE A < Ndx
                CALL GetParameter(ADDRESSOF(A), ADDRESSOF(VarCode), mt_OptsAParam, mt_OptsNoParam, 1)
                INCR A
            LOOP

            VarCode.Methd% = mt_FuncSubDecC_DecAParam
            VarCode.Token$ = FunctionName$
            FuncSubDecs3(ADDRESSOF(VarCode), Ndx, 0)
            FPRINT FP_UDT, Scoot$, VarCode.Header$, szImp$, ";"

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)
    END SELECT

    FUNCTION = 0
END FUNCTION ' Emit_Implied




FUNCTION Emit_FuncSub(sWord$, FuncRetnFlag AS PINT)
    SELECT CASE sWord$
        CASE "function", "sub", _
            "publicfunction", "publicsub", _
            "privatefunction", "privatesub"

            GLOBAL gCurrentFunction$ = AbortSrc$

            IF InFunction THEN
                CALL Abort("Syntax Error: Nested functions not supported.")
            END IF

            STATIC A
            STATIC CTOR_USE$
            STATIC iCPPFunSub
            STATIC VarCode AS UDT_VARCODE_ATTRIBUTES

            DIM New_Ndx = Ndx
            VarCode.IsExported = FALSE
            VarCode.UseInLine = UseInLine

            SELECT CASE sWord$
                CASE "publicfunction", "publicsub"
                    Stk$[1] = MID$(Stk$[1], 6)
                CASE "privatefunction", "privatesub"
                    Stk$[1] = MID$(Stk$[1], 7)
            END SELECT

            iCPPFunSub = 0

            FOR ct AS INT = 1 TO Ndx
                IF m_iMatchWrd(Stk$[ct], "using") THEN
                    iCPPFunSub = 1
                    New_Ndx = ct-1
                    CALL BuildDelimStr(ct+1, Ndx, CTOR_USE$)
                    EXIT FOR
                END IF
            NEXT
            Ndx = New_Ndx

            IF Stk$[2] = "main" THEN
                NoMain = TRUE
                Stk$[1] = "function"
                Stk$[2] = "main%"
                ForceMainToFunc = TRUE
            END IF

            CALL FuncSubDecs1("sub", 1, Ndx, ADDRESSOF(VarCode))

            IsStdFunc = FALSE

            IF m_iMatchWrd(Stk$[Ndx], "stdcall") THEN
                CallType$ = "__stdcall "
                DECR Ndx
                IsStdFunc = TRUE
            END IF

            InMain = FALSE
            LocalVarCnt = 0

            ' IF InNameSpace OR InClass OR InCppTypeDef THEN  ' 786 MrBcx - This important change correctly emits this in CLASSES:
            IF InNameSpace OR InCppTypeDef THEN               '             char *BCX_RetStr={0};
                InFunction = FALSE                            ' allowing normal BCX string functions to be used in C++ CLASSES
                FP_WRITE = FP2
            ELSE
                IF iMatchNQ (sWord$, "function") THEN
                    InFunction = eFunctionType
                ELSE
                    InFunction = eSubType
                END IF
                IF UsingTemplate = FALSE THEN
                    FP_WRITE = FP3
                END IF
            END IF
            VarCode.Functype$ = LTRIM$(VarCode.Functype$)

            CALL FuncSubDecs2("sub", mt_FuncSubDecC_Dec, ADDRESSOF(VarCode), 1, ADDRESSOF(Ndx))

            IF UseCpp AND m_iMatchRgt(Stk$[2], "operator") = TRUE THEN    ' 838 MrBcx added test for UseCPP
                VarCode.Functype$ += Stk$[2]
                VarCode.Functype$ += SPC$
                FunctionName$ = ""
                DIM RAW bOppFound AS BOOL

                XFOR A = 3, bOppFound = FALSE WHILE NOT bOppFound BY A++
                    IF *Stk$[A] = ASC("(") THEN
                        IF *Stk$[A+1] <> ASC(")") AND *Stk$[A+2] <> ASC("(") THEN bOppFound = TRUE
                        IF A > 3 AND *Stk$[A+1] = ASC(")") THEN bOppFound = TRUE
                    END IF
                    IF NOT bOppFound THEN
                        VarCode.Functype$ += Stk$[A]
                    END IF
                XNEXT

            ELSE

                FunctionName$ = No_Sigil$(Stk$[2])
                IF VarCode.IsExported OR IsStdFunc THEN
                    FunctionName$ = CallType$ + FunctionName$
                END IF
                A = 4
            END IF

            '*******************************************************************************
            ' FOR DEBUGGING:
            ' PRINT FunctionName$, " is ", VarCode.Functype$
            '*******************************************************************************

            DO WHILE A < Ndx
                IF UseCpp THEN
                    CALL GetParameter(ADDRESSOF(A), ADDRESSOF(VarCode), mt_OptsAParam, mt_OptsNoParam, 1)
                ELSE
                    CALL GetParameter(ADDRESSOF(A), ADDRESSOF(VarCode), mt_FuncSubDecC_DecAParam, mt_FuncSubDecC_DecNoParam, 0)
                END IF
                INCR A
            LOOP

            VarCode.Methd% = mt_FuncSubDecC_DecAParam
            VarCode.Token$ = FunctionName$
            FuncSubDecs3(ADDRESSOF(VarCode), Ndx, 0)

            IF m_iMatchWrd(Stk$[Ndx], "const") THEN
                VarCode.Header$ += " const"
            END IF

            IF m_iMatchLft(VarCode.Header$, "main(")  THEN
                VarCode.Header$ = "int main(int argc, PCTSTR argv[])"
                VarCode.Proto$  = "int main(int argc, PCTSTR argv[]);"
                CurrentFuncType = vt_INTEGER
            END IF

            IF Use_Static THEN
                VarCode.Header$ = "static " + VarCode.Header$
                VarCode.Proto$  = "static " + VarCode.Proto$
            END IF

            IF m_IAmNot(InNameSpace) AND m_IAmNot(InClass) AND m_IAmNot(InCppTypeDef) THEN
                DIM RAW iClassFunction
                DIM RAW tmp$

                tmp$ = EXTRACT$(VarCode.Proto$, "(")
                IF iMatchNQ (tmp$, "::") > 0 THEN
                    tmp$ = EXTRACT$(tmp, "::")
                    iClassFunction = ClassProto(tmp$)
                    IF iClassFunction = 0 THEN

                        IF c_MaxClassNames = iClassCnt THEN
                            CALL Abort("Maximum c_MaxClassNames =" + STR$(c_MaxClassNames) + " reached")
                        END IF

                        ClassNames$[iClassCnt] = tmp$
                        INCR iClassCnt
                    END IF
                    iClassFunction = 1
                ELSE
                    iClassFunction = 0
                END IF
                IF iClassFunction = 0 THEN
                    CALL AddProto(VarCode.Proto$)
                    IF InIfDef$ = "FP3" THEN
                        IF ProtoCnt > 1 THEN
                            ProtoType[ProtoCnt].Condition$ = ProtoType[ProtoCnt-1].Condition$
                        ELSE
                            ProtoType[ProtoCnt].Condition$ = ""
                        END IF
                    ELSE
                        ProtoType[ProtoCnt].Condition$ = InIfDef$
                    END IF

                    ProtoType[ProtoCnt].CondLevel  = InConditional
                    IF NOTNULL (InIfDef$) THEN
                        IF InIfDef$ <> "FP3" THEN
                            FPRINT FP_WRITE, InIfDef$
                        END IF
                    END IF
                END IF
            END IF

            IF InNameSpace OR InClass OR InCppTypeDef THEN
                DIM szCPP_SF1$
                IF InClass AND m_iMatchWrd(Stk$[2], InClassName$) THEN
                    VarCode.Header$ = REMAIN$(VarCode.Header$, SPC$)
                END IF
                FPRINT FP_UDT, Scoot$, szCPP_SF1$, VarCode.Header$; ' Suppress CRLF
                IF iCPPFunSub = 1 THEN
                    FPRINT FP_UDT, " : ", CTOR_USE$
                ELSE
                    FPRINT FP_UDT, ""
                END IF
                FP_WRITE = FP_UDT
            ELSE
                FPRINT FP_WRITE, VarCode.Header$
            END IF

            FPRINT FP_WRITE, Scoot$, "{"
            CALL BumpUp

        CASE ELSE
            CALL Emit_Assignments(FuncRetnFlag)

    END SELECT
    FUNCTION = 0
END FUNCTION ' Emit_FuncSub


'*******************************************************************
'   Global variable emitter for variables used by BCX functions.
'*******************************************************************


SUB Emit_BCXVariables
    DO WHILE iEmitVarGroup
        SELECT CASE 1

            CASE (iEmitVarGroup BAND 1)
                CALL Emit_PrinterVariables
                iEmitVarGroup = iEmitVarGroup XOR ePrinterGroup

            CASE ((iEmitVarGroup SHR 1) BAND 1)

                CALL AddFontVariables
                iEmitVarGroup = iEmitVarGroup XOR eFontGroup

            CASE ((iEmitVarGroup SHR 2) BAND 1)

                CALL AddClassName
                iEmitVarGroup = iEmitVarGroup XOR eClassName

            CASE ((iEmitVarGroup SHR 3) BAND 1)

                CALL AddBCX_hInstance
                iEmitVarGroup = iEmitVarGroup XOR eBCX_hInstance

            CASE ELSE
                CALL Abort("Unknown variable grouping was selected (Add to SUB EmitBCXVariables).")
        END SELECT
    LOOP
    ' iEmitVarGroup is zero when it gets here
END SUB ' Emit_BCXVariables



SUB AddBCX_hInstance
    STATIC IWasHere = 0
    IF IWasHere THEN EXIT SUB
    CALL AddGlobal("BCX_hInstance", vt_HINSTANCE)
    INCR IWasHere
END SUB ' AddBCX_hInstance



SUB AddClassName
    STATIC IWasHere
    IF IWasHere THEN EXIT SUB
    CALL AddGlobal("BCX_ClassName", vt_STRVAR)
    INCR IWasHere
END SUB ' AddClassName



SUB Emit_PrinterVariables
    STATIC IWasHere
    IF IWasHere THEN EXIT SUB
    CALL AddGlobal("BcxPtr_hDC"       , vt_HDC)
    CALL AddGlobal("BcxPtr_FontMetrix", vt_LONG)
    CALL AddGlobal("BcxPtr_LineCtr"   , vt_LONG)
    CALL AddGlobal("BcxPtr_PrinterOn" , vt_LONG)
    CALL AddGlobal("BcxPtr_hFont"     , vt_HFONT)
    CALL AddGlobal("BcxPtr_hFontOld"  , vt_HFONT)
    CALL AddGlobal("BcxPtr_di"        , vt_DOCINFO)
    CALL AddGlobal("BcxPtr_Lf"        , vt_LOGFONT)
    CALL AddGlobal("BcxPtr_tm"        , vt_TEXTMETRIC)
    CALL AddGlobal("BcxPtr_Text"      , vt_STRVAR)
    CALL AddGlobal("BcxPtr_Buffer"    , vt_STRVAR)
    INCR IWasHere
END SUB ' Emit_PrinterVariables



SUB AddFontVariables
    STATIC IWasHere
    IF IWasHere THEN EXIT SUB
    CALL AddGlobal("BCX_ScaleX", vt_SINGLE)
    CALL AddGlobal("BCX_ScaleY", vt_SINGLE)
    INCR IWasHere
END SUB ' AddFontVariables



SUB AddBcxFontVar
    STATIC IWasHere
    IF IWasHere THEN EXIT SUB
    CALL AddGlobal("BcxFont"  , vt_HFONT)
    INCR IWasHere
END SUB ' AddBcxFontVar


SUB AddPenSizeVariables
    STATIC IWasHere
    IF IWasHere THEN EXIT SUB
    CALL AddGlobal("BCX_Pensize=1",       vt_INTEGER)
    CALL AddGlobal("BCX_Penstyle=0",      vt_INTEGER)
    INCR IWasHere
END SUB   ' AddPenVariables


SUB AddGrafixVariables
    STATIC IWasHere
    IF IWasHere THEN EXIT SUB
    CALL AddGlobal("BCX_BUFFER_BMWIDTH",  vt_INTEGER)
    CALL AddGlobal("BCX_BUFFER_BMHEIGHT", vt_INTEGER)
    CALL AddGlobal("BCX_BUFFER",          vt_HDC)
    CALL AddGlobal("BCX_PREV_BMP",        vt_HBITMAP)
    CALL AddGlobal("BCX_BUFFER_BMP",      vt_BITMAPINFO)
    INCR IWasHere
END SUB ' AddGrafixVariables



SUB AddGUIGlobals
    STATIC IWasHere
    IF IWasHere THEN EXIT SUB
    CALL AddFontVariables
    CALL AddBCX_hInstance
    CALL AddGlobal("BCX_hwndMDIClient", vt_HWND      )
    CALL AddGlobal("BCX_WndClass"     , vt_WNDCLASSEX)
    CALL AddGlobal("BCX_GUI_Init"     , vt_WINBOOL   )
    CALL AddGlobal("BCX_ClassName"    , vt_STRVAR    )
    INCR IWasHere
END SUB ' AddGUIGlobals



SUB ProcessMsgCracker
    ' HANDLE_MSG WM_SIZE INLINE SendMessage(hWnd, WM_XXXX, 0, 0) : EXIT FUNCTION
    DIM RAW msg_$
    DIM RAW proc_$
    DIM RAW ret_$
    DIM RAW tmp_$[16]
    DIM RAW tmpNdx AS INT
    DIM RAW i AS INT
    DIM RAW j AS INT

    i = j = tmpNdx = 0
    FastLexer(Src$, SPC$, ":")
    IF m_iMatchWrd(Stk$[3], "inline") THEN
        tmp_$[++tmpNdx] = "IF Msg = " + Stk$[2] + " THEN"
        IF Stk$[Ndx] <> ":" THEN Stk$[++Ndx] = ":"
        XFOR i = 4, j = 4 WHILE i <= Ndx BY i++
            IF Stk$[i] = ":" THEN
                CALL BuildDelimStr(j, i-1, tmp_$[++tmpNdx])
                j = i+1
            END IF
        XNEXT
        tmp_$[++tmpNdx] = "END IF"
        FOR i = 1 TO tmpNdx
            CALL Inject(tmp_$[i])
        NEXT
    ELSE
        ' handle_msg(WM_SIZE, form1_onSize)
        FastLexer(Src$, " ,()", "")
        msg_$  = Stk$[2]
        proc_$ = Stk$[3]
        ret_$  = Stk$[4]
        IF NOTNULL(ret_$) THEN ret_$ = "," + ret_$
        Src$ = "IF Msg = " + msg_$ + " THEN"
        Inject(Src$)
        IF LEN(TRIM$(ret_$)) > 0 THEN
            Src$ = "  FUNCTION=" + proc_$ + "(hWnd,wParam,lParam" + ret_$ + ")"
        ELSE
            Src$ = SPACE$(2) + proc_$ + "(hWnd,wParam,lParam" + ret_$ + ")"
        END IF
        Inject(Src$)
        Src$ = "END IF"
        Inject(Src$)
    END IF
    Src$ = ""
END SUB ' ProcessMsgCracker



SUB ProcessCmdHandler
    DIM RAW id_$
    DIM RAW proc_$
    DIM RAW ret_$
    DIM RAW tmp_$[16]
    DIM RAW tmpNdx  AS INT
    DIM RAW i AS INT
    DIM RAW j AS INT
    tmpNdx = 0
    FastLexer(Src$, SPC$, ":")
    IF m_iMatchWrd(Stk$[3], "inline") THEN
        ' handle_cmd IDM_NEW INLINE SendMessage(hWnd, WM_XXXX, 0, 0) : EXIT FUNCTION:
        tmp_$[++tmpNdx] = "IF Msg = WM_COMMAND AND CBCTL = " + Stk$[2] + " THEN "
        IF Stk$[Ndx] <> ":" THEN Stk$[++Ndx] = ":"
        XFOR i = 4, j = 4 WHILE i <= Ndx BY i++
            IF Stk$[i] = ":" THEN
                CALL BuildDelimStr(j, i-1, tmp_$[++tmpNdx])
                j = i+1
            END IF
        XNEXT
        tmp_$[++tmpNdx] = "END IF"
        FOR i = 1 TO tmpNdx
            CALL Inject(tmp_$[i])
        NEXT
    ELSE
        ' handle_cmd(IDM_NEW, procedure, retval)
        FastLexer(Src$, " ,()", "")
        id_$ = Stk$[2]
        proc_$ = Stk$[3]
        ret_$ = Stk$[4]
        IF NOTNULL(ret_$) THEN ret_$ = "," + ret_$
        Src$ = "IF Msg = WM_COMMAND AND CBCTL = " + id_$ + " THEN"
        Inject(Src$)
        IF LEN(TRIM$(ret_$)) > 0 THEN
            Src$ = "  FUNCTION=" + proc_$ + "(hWnd,wParam,lParam" + ret_$ + ")"
            Inject(Src$)
        ELSE
            Src$ = SPACE$(2) + proc_$ + "(hWnd,wParam,lParam" + ret_$ + ") "
            Inject(Src$)
        END IF
        Src$ = "END IF"
        Inject(Src$)
    END IF
    Src$ = ""
END SUB ' ProcessCmdHandler



SUB ProcessMsgHandler
    ' MSGHANDLER procedure or CMDHANDLER procedure
    FastLexer(Src$, ", ()", "")
    Src$ = "FUNCTION " + Stk$[2] + " (hWnd AS HWND, wParam AS WPARAM, lParam AS LPARAM, LReturn AS LRESULT=0) AS LRESULT"
    Inject(Src$)
    Src$ = ""
END SUB ' ProcessMsgHandler



SUB ProcessMsgHandlerEnd
    Src$ = "FUNCTION = LReturn"  ' Reminder:  BCX Pre-Processor converts RETURN to FUNCTION =
    Inject(Src$)
    Src$ = "END FUNCTION"
    Inject(Src$)
    Src$ = ""
END SUB ' ProcessMsgHandlerEnd

' ==================================================================================
'                               End Expand Macros
'                   Begin  Directives - tDirectives[].Emitter()
' ==================================================================================

FUNCTION Doinclude(szWord$, iFLAG AS PINT) AS INT
    STATIC BeenHere
    *iFLAG = 0

    SELECT CASE szWord$

        CASE "#include"
            IF BeenHere = FALSE THEN
                BeenHere = TRUE
                FPRINT FP_HDR, SPC$
            END IF
            FPRINT FP_HDR, "#include", Src+8

        CASE "$include"
            DIM orgfileName$
            IREPLACE "$BCX$" WITH BCXPATH$ IN Src$
            szFile$ = EXTRACT$(Src$, "'")                        ' 838 - MrBcx New -- strip off comments
            szFile$ = TRIM$(REMOVE$(MID$(szFile$, 9), DQ$))

            IF *szFile = ASC("<") THEN
                szFile$ = MID$(szFile$, 2, LEN(szFile$)-2)
                szFile$ = ENVIRON$("BCXLIB") + szFile$
            END IF


            orgfileName$ = szFile$
            IF NOT EXIST(szFile$) THEN
                szFile$ = BCXSPLITPATH$(szFile$, FNAME | FEXT)
                szFile$ = BCXSPLITPATH$(FileNames$[FileNdx], FDRV BOR FPATH) + szFile$
            END IF

            IF NOT EXIST(szFile$) THEN
                PRINT "Debug: Inside FUNCTION Doinclude"
                PRINT "Debug: szFile =", szFile$
                PRINT "Debug: orgfileName$ =", orgfileName$
                PRINT
                Abort("Unable to $INCLUDE " + orgfileName$)  ' MrBcx 831 - modified
            END IF

            CALL PushFileIO

            OPEN szFile$ FOR INPUT AS SourceFile

            '=============================================================
            FileNdx++                       ' Added by Richard Meyer 802
            FileNames$[FileNdx] = szFile$   ' Added by Richard Meyer 802
            LineNum[FileNdx] = 0            ' Added by Richard Meyer 802
            '=============================================================

            IF FileNdx = c_MaxFiles-1 THEN
                CALL Abort("Maximum Include Files exceeded.")
            END IF

    END SELECT
    FUNCTION = 0
END FUNCTION ' Doinclude



SUB Generate_Goto(i AS INT, iSend AS INT)
    DIM RAW LszTmp$
    sprintf(LoopType[i].szUseNeedLabel, "L%i:;", LoopType[i].iJumpTo)
    IF iSend THEN
        sprintf(LszTmp, "goto L%i;", LoopType[i].iJumpTo)
        FPRINT FP_WRITE, Scoot$, LszTmp$
    END IF
END SUB ' Generate_Goto



FUNCTION Doaccelerator(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Accelerator$ = REMOVE$(Stk$[2], DQ$)
    FUNCTION = 0
END FUNCTION ' Doaccelerator



FUNCTION Doasm(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    DIM LTmp$
    *iFLAG = 0

    CALL Emit_Optimize("none", "0", "  // No Optimizations in ASM block")

    DO
        IF EOF(SourceFile) THEN Abort ("Unbalanced $Asm")
        LINE INPUT SourceFile, Src$
        INCR LineNum[FileNdx]
        IF SrcFlag THEN
            FPRINT FP_WRITE, "// ", Src$
        END IF
        CALL StripTabs
        Src$ = TRIM$(Src$)

        DIM meta_asm_loop
        DIM meta_asm_comment_present AS BOOL
        DIM Src_Len AS INT
        Src_Len = LEN(Src$)
        meta_asm_comment_present = FALSE

        FOR meta_asm_loop = 0 TO Src_Len
            '******************************************
            '   Extracts both the Basic Single Quote
            '   and the Assembly Semicolon
            '******************************************
            IF Src[meta_asm_loop] = c_SglQt OR Src[meta_asm_loop] = 59 THEN
                LTmp$ = RIGHT$(Src$, Src_Len - meta_asm_loop - 1)
                Src[meta_asm_loop] = 0
                meta_asm_comment_present = TRUE
                EXIT FOR
            END IF
        NEXT

        Src$ = TRIM$(Src$)
        IF m_iMatchLft(Src$, "$asm") THEN EXIT DO
        REPLACE "$" WITH "0x" IN Src$
        IREPLACE "&h" WITH "0x" IN Src$
        IF NOTNULL(Src$) THEN
            Src$ = "_asm(" + ENC$(Src$) + CHR$(1)
            IF meta_asm_comment_present THEN
                Src$ += TAB$ + "//" + LTmp$
            END IF
            SrcTmp$ = Src$
            FPRINT FP_WRITE, "#if !defined(__POCC__) && !defined (__cplusplus)"
            REPLACE CHR$(1) WITH ")" IN Src$
            FPRINT FP_WRITE, Src$
            FPRINT FP_WRITE, "#else"
            REPLACE "_asm(" WITH "__asm{" IN SrcTmp$
            REPLACE CHR$(1) WITH "}" IN SrcTmp$
            FPRINT FP_WRITE, REMOVE$(SrcTmp$, DQ$)
            FPRINT FP_WRITE, "#endif"
        END IF
    LOOP

    CALL Emit_Optimize("", "1", "  // Restoring Optimizer state")
    FUNCTION = 0
END FUNCTION ' Doasm



FUNCTION Dobcx_resource(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Use_GenResFile = TRUE

    DO
        IF EOF(SourceFile) THEN Abort ("Unbalanced $BCX_RESOURCE")
        LINE INPUT SourceFile, Src$
        INCR LineNum[FileNdx]
        CALL Sanitize_Code (Src$)
        IF m_iMatchLft(LTRIM$(Src$), "$bcx_r") THEN EXIT DO
        FPRINT FP_RES, Src$
    LOOP

    FUNCTION = 0
END FUNCTION ' Dobcx_resource



FUNCTION Dobcxversion(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Src$ = TRIM$(MID$(Src$, 12))
    REMOVE DQ$ FROM Src$
    IF LCASE$(c_VERSION$) < LCASE$(Src$) THEN
        Abort (CRLF$ + "Your Translator needs updating." + CRLF$ + _
        " This program " + ENC$(FileNames$[FileNdx])             + _
        " requires BCX Version: "  + Src$ + " or later." + CRLF$ + CRLF$)
    ELSE
        IF c_BCX_COLORS THEN COLOR 12, 0
        PRINT "This App needs BCX Version ", Src$, " or newer. ";
        IF c_BCX_COLORS THEN COLOR 9, 0
        PRINT "[OKAY] Detected BCX ", c_VERSION$
    END IF
    COLOR 2, 0
    FUNCTION = 0
END FUNCTION ' Dobcxversion




FUNCTION Doccode(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    DIM RAW FP_TMP AS FILE
    DIM RAW szWhere$
    *iFLAG = 0
    IF Ndx > 1 THEN
        szWhere$ = LCASE$(Stk$[2])
    ELSE
        szWhere$ = "default"
    END IF
    SELECT CASE szWhere$
        CASE "set"
            FP_TMP = FP_SET   ' Temp File FOR Storing GLOBAL SET Vars
        CASE "header"
            FP_TMP = FP_HDR   ' Temp File FOR Storing User's .H files
        CASE "const"
            FP_TMP = FP_CST   ' Temp File FOR Storing User's MACRO
        CASE "udt"
            FP_TMP = FP_UDT   ' Temp File FOR Storing User's Def Types
        CASE "enum"
            FP_TMP = FP_ENU   ' Temp File FOR Storing User's global enums
        CASE "funcsub"
            FP_TMP = FP_CCODE ' Temp File FOR Storing User's C code
        CASE ELSE
            IF InFunction THEN
                FP_TMP = FP3
            ELSE
                IF InClass OR InCppTypeDef OR InNameSpace THEN
                    FP_TMP = FP_UDT  ' Temp File FOR Storing User's Def Types
                ELSE
                    FP_TMP = FP2
                END IF
            END IF
    END SELECT

    DO
        IF EOF(SourceFile) THEN Abort ("Unbalanced $Ccode")
        LINE INPUT SourceFile, Src$
        INCR LineNum[FileNdx]
        CALL StripTabs
        IF m_iMatchLft(LTRIM$(Src$) , "$ccode") THEN
            IF SrcFlag THEN ' comments seem to interfere with C line continuations '\'
                FPRINT FP_TMP, "// [", TRIM$(FileNames$[FileNdx]), " - ", STR$(LineNum[FileNdx], 1), "] End of $CCODE Block"
            END IF
            EXIT DO
        END IF
        FPRINT FP_TMP, RTRIM$(Src$)
    LOOP

    FUNCTION = 0
END FUNCTION ' Doccode



FUNCTION Docom_op(szWord$, iFLAG AS PINT) AS INT
    *iFLAG = 0

    SELECT CASE szWord$

        CASE "$com_off"
            Use_COM = FALSE
            ComSwitchON = FALSE

        CASE "$com_on"
            Use_COM = Use_BcxTempStr = TRUE
            ComSwitchON = TRUE

        CASE "$com_trace"
            COM_build_trace_code = TRUE
            PRINT "COM trace code added to translated C file!"
            PRINT "Trace informations will be sent to file: c:\\com_trace.txt"

    END SELECT
    FUNCTION = 0
END FUNCTION ' Docom_op



FUNCTION Docomment(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    STATIC TmpFile AS FILE
    IF m_IAm(InClass) OR m_IAm(InCppTypeDef) THEN
        TmpFile = FP_UDT
    ELSE
        TmpFile = FP_WRITE
    END IF
    DO
        IF EOF(SourceFile) THEN Abort ("Unbalanced $Comment")
        LINE INPUT SourceFile, Src$
        INCR LineNum[FileNdx]
        CALL StripTabs
        IF m_iMatchLft(LTRIM$(Src$), "$comment") THEN EXIT DO
        FPRINT TmpFile, "// ", Src$
    LOOP
    FUNCTION = 0
END FUNCTION ' Docomment



FUNCTION Dofillstring (szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0

    STATIC TheVariable$
    IREMOVE "$fill" FROM Src$
    Src$ = TRIM$(Src$)

    IF ISFALSE INCHR(Src$, "$") THEN                        ' It doesn't LOOK like a string, so make it easy on BCX
        IF ISFALSE INCHR(Src$, "[") THEN                    ' It looks like a one-dimensional string
            Src$ += "$"                                     ' ... so we'll append a dollar sign
        ELSE
            DIM i = INCHR(Src$, "[")                    ' It is a member of a string array
            Src$ = MID$(Src$, 1, i-1) + "$" + MID$(Src$, i) ' ... so APPEND a $ sign TO its name
        END IF
    END IF

    Inject (Src$ + " = " + ENC$(""))                        ' 777 MrBcx -- Start with an empty variable
    TheVariable$ = Src$ + " = " + Src$ + " & "              ' This is what precedes the [string expressions]

    DO
        IF EOF(SourceFile) THEN Abort ("Unbalanced $FILL")
        LINE INPUT SourceFile, Src$
        INCR LineNum[FileNdx]
        CALL StripTabs
        Src$ = LTRIM$(Src$)
        IF LEFTSTR(Src$, "'") OR LEFTSTR(Src$, "rem", TRUE) THEN Src$ = ""
        IF LEFTSTR(Src$, "$fill", TRUE) THEN EXIT DO
        REPLACE BKSLASH2$ WITH BKSLASH4$ IN Src$            ' escape the \ character (like in RTF file data)
        REPLACE BKSLASH1$ WITH BKSLASH2$ IN Src$            '                      ditto
        IF NOTNULL(Src$) THEN Inject (TheVariable$ + Src$)  ' Inject each expression into BCX's translate stream
    LOOP
    Src$ = ""
    FUNCTION = 0
END FUNCTION ' Dofillstring


FUNCTION DoWarningsOn(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    WarningFlag = TRUE
    FUNCTION = 0
END FUNCTION ' DoWarningsOn


FUNCTION DoWarningsOff(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    WarningFlag = FALSE
    FUNCTION = 0
END FUNCTION ' DoWarningsOff


FUNCTION DoZap(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    ZapFlag = TRUE
    FUNCTION = 0
END FUNCTION ' DoZap


FUNCTION Docompiler(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Src$ = REMAIN$(Src$, SPC$)
    Compiler$ = TRIM$(Src$)
    FUNCTION = 0
END FUNCTION ' Docompiler


FUNCTION DoBcxStrSize (szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    ' We change: #define BCXSTRSIZE 2048 in SUB Final_Transforms
    UserBcxStrSize$ = TRIM$(REMAIN$(Src$, SPC$))
    FUNCTION = 0
END FUNCTION ' DoBcxStrSize


FUNCTION Docpp(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    UNREFERENCED_PARAMETER(iFLAG)
    UseCpp = TRUE
    FUNCTION = 0
END FUNCTION ' Docpp


FUNCTION Docpphdr(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    UseCpphdr = TRUE
    UseIO = TRUE
    FUNCTION = 0
END FUNCTION ' Docpphdr


FUNCTION Docproto(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0

    FastLexer(Src$, SPC$, "!")

    IF m_iMatchWrd(Stk$[2], "!") THEN
        CALL AddProto(REMAIN$(Src$, "!"))
        ProtoType[ProtoCnt].Condition$ = ""
        ProtoType[ProtoCnt].CondLevel  = 0
    ELSE
        DIM i = iMatchNQ(Src$, "function")
        IF i = 0 THEN
            i = iMatchNQ(Src$, "sub")
        END IF

        IF i THEN
            Src$ = "c_declare " + MID$(Src$, i)
        ELSE
            i = iMatchNQ(Src$, "$cproto")
            Src$ = "c_declare function " + MID$(Src$, i+7)
        END IF
        PassOne = TRUE

        CALL PreParse(Src$)

        PassOne = FALSE
        UseCProto = TRUE
        *iFLAG = 2
    END IF
    FUNCTION = *iFLAG
END FUNCTION ' Docproto




FUNCTION Dodefine(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    UNREFERENCED_PARAMETER(iFLAG)
    LOCAL Tmp$
    Tmp$ = "#define"
    FOR i AS INT = 2 TO Ndx
        Tmp$ += SPC$
        Tmp$ += Stk$[i]
        Stk$[i] = ""
    NEXT
    REPLACE " ) = "    WITH ") "       IN Tmp$  ' Important to remove this equals sign
    REPLACE " ( "      WITH " ("       IN Tmp$  ' Cosmetic
    REPLACE " , "      WITH ","        IN Tmp$  ' Cosmetic
    REPLACE " CONST "  WITH " const "  IN Tmp$  '************************************
    REPLACE " INT "    WITH " int "    IN Tmp$  ' Counteract helpful syntax editors
    REPLACE " LONG "   WITH " long "   IN Tmp$  ' This is obviously an incomplete list
    REPLACE " DOUBLE " WITH " double " IN Tmp$  ' but hopefully covers the common ones
    REPLACE " FLOAT "  WITH " float "  IN Tmp$  '************************************

    FPRINT FP_DEF, Tmp$                         ' Operation reduced to one disk-write
    Ndx = 0
    FUNCTION = 0
END FUNCTION ' Dodefine



FUNCTION Dodll(szWord$, iFLAG AS PINT) AS INT
    *iFLAG = 0
    SELECT CASE szWord$
        CASE "$dll"
            MakeDLL = TRUE
            Ndx = 0
            IF m_iMatchWrd(Stk$[2], "stdcall") THEN
                UseStdCall = TRUE
            END IF

            IF NoDllMain = FALSE THEN
                FPRINT FP_WRITE, ""
                FPRINT FP_WRITE, "__declspec(dllexport) BOOL WINAPI DllMain (HINSTANCE hInst, ULONG Reason, PVOID Reserved)"
                FPRINT FP_WRITE, "{"
                FPRINT FP_WRITE, "  switch (Reason)"
                FPRINT FP_WRITE, "  {"
                FPRINT FP_WRITE, "    case DLL_PROCESS_ATTACH:"
                FPRINT FP_WRITE, "      BCX_hInstance = hInst;"
                FPRINT FP_WRITE, "      break;"
                FPRINT FP_WRITE, "    case DLL_PROCESS_DETACH:"
                FPRINT FP_WRITE, "      break;"
                FPRINT FP_WRITE, "    case DLL_THREAD_ATTACH:"
                FPRINT FP_WRITE, "      break;"
                FPRINT FP_WRITE, "    case DLL_THREAD_DETACH:"
                FPRINT FP_WRITE, "      break;"
                FPRINT FP_WRITE, "   }"
                FPRINT FP_WRITE, " return TRUE;"
                FPRINT FP_WRITE, "}\n\n"
                CALL AddBCX_hInstance
            END IF

        CASE "$nodllmain"
            NoDllMain = TRUE
    END SELECT
    FUNCTION = 0
END FUNCTION ' Dodll




FUNCTION Dofiletest(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    IF m_iMatchWrd(Stk$[2], "ON") THEN
        UseFileTest = TRUE
    ELSEIF m_iMatchWrd(Stk$[2], "OFF") THEN
        UseFileTest = FALSE
    ELSE
        Abort("Unrecognized argument '"+Stk$[2] + "' to $FILETEST")
    END IF
    FUNCTION = 0
END FUNCTION ' Dofiletest



FUNCTION Dofsstatic(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Use_Static = NOT Use_Static
    FUNCTION = 0
END FUNCTION ' Dofsstatic



FUNCTION Dogenfree(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Use_GenFree = TRUE
    FUNCTION = 0
END FUNCTION ' Dogenfree



FUNCTION Doheader(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    FPRINT FP_HDR, SPC$
    FPRINT FP_HDR, "// *************************************************"
    DO
        IF EOF(SourceFile) THEN Abort ("Unbalanced $Header")
        LINE INPUT SourceFile, Src$
        INCR LineNum[FileNdx]
        CALL StripTabs
        Src$ = TRIM$(Src$)
        IF m_iMatchLft(Src$, "$header") THEN EXIT DO
        FPRINT FP_HDR, Src$
    LOOP
    FUNCTION = 0
END FUNCTION ' Doheader



FUNCTION Dointerface(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    UseCpp = TRUE

    Src$ = REMAIN$(Src$, SPC$)
    FPRINT FP_UDT, "interface ", Src$, "\n  {"

    DO
        IF EOF(SourceFile) THEN
            CALL Abort ("$Interface Without $EndInterface")
        END IF

        LINE INPUT SourceFile, Src$
        INCR LineNum[FileNdx]
        IF m_iMatchLft(LTRIM$(Src$), "$endinterface") THEN
            Src$ = ""
            EXIT DO
        END IF
        FPRINT FP_UDT, Src$
    LOOP

    Src$ = REMAIN$(Src$, SPC$)
    Src$ = TRIM$(Src$)
    FPRINT FP_UDT, "  } ", Src$, ";"
    FUNCTION = 0
END FUNCTION ' Dointerface



FUNCTION Doiprint (szWord$, iFLAG AS PINT) AS INT
    *iFLAG = 0
    SELECT CASE szWord$

        CASE "$iprint_on"
            TranslateSlash = TRUE

        CASE "$iprint_off"
            TranslateSlash = FALSE

    END SELECT
    FUNCTION = 0
END FUNCTION ' Doiprint


FUNCTION DoCase_offon(szWord$, iFLAG AS PINT) AS INT
    *iFLAG = 0
    SELECT CASE szWord$

        CASE "$case_on"
            IgnoreStrCase = FALSE  ' Use strcmp (default)

        CASE "$case_off"
            IgnoreStrCase = TRUE   ' Use bcx_stricmp

    END SELECT
    FUNCTION = 0
END FUNCTION ' DoCase_offon



FUNCTION Doleanandmean(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Use_LeanAndMean = TRUE
    FUNCTION = 0
END FUNCTION ' Doleanandmean



FUNCTION Doliberror(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Use_BcxTempStr = Use_Date = Use_Time = Use_LoadLibraryError = TRUE

    IF *Stk$[2] <> c_DblQt THEN
        CALL Abort("$LIBERROR requires a string literal")
    END IF

    LibraryErrorLog$ = Stk$[2]
    FUNCTION = 0
END FUNCTION ' Doliberror



FUNCTION Dolibrary(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    REPLACE BKSLASH1$ WITH BKSLASH2$ IN Src$
    Src$ = IREMOVE$(Src$, "$library")
    Src$ = TRIM$(Src$)
    AddLibrary(Src$)
    FUNCTION = 0
END FUNCTION ' Dolibrary



FUNCTION Dolinker(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Src$ = REMAIN$(Src$, SPC$)
    Linker$ = Src$
    FUNCTION = 0
END FUNCTION ' Dolinker



FUNCTION Domultithread(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Use_MULTITHREADED_SW = TRUE
    FUNCTION = 0
END FUNCTION ' Domultithread


FUNCTION DoNoBorland  (szWord$, iFLAG AS PINT) AS INT
    NO_BORLAND = TRUE
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    FUNCTION = 0
END FUNCTION ' DoNoBorland


FUNCTION DoNoGccClang (szWord$, iFLAG AS PINT) AS INT
    NO_GCCCLANG = TRUE
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    FUNCTION = 0
END FUNCTION ' DoNoGccClang


FUNCTION DoNoLccwin(szWord$, iFLAG AS PINT) AS INT
    NO_LCCWIN = TRUE
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    FUNCTION = 0
END FUNCTION ' DoNoLccwin


FUNCTION DoNoLibs  (szWord$, iFLAG AS PINT) AS INT
    NO_LIBS = TRUE
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    FUNCTION = 0
END FUNCTION ' DoNoLibs


FUNCTION DoNoMsvc  (szWord$, iFLAG AS PINT) AS INT
    NO_MSVC = TRUE
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    FUNCTION = 0
END FUNCTION ' DoNoMsvc


FUNCTION DoNoPelles(szWord$, iFLAG AS PINT) AS INT
    NO_PELLES = TRUE
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    FUNCTION = 0
END FUNCTION ' DoNoPelles


FUNCTION DoNoVkkeys (szWord$, iFLAG AS PINT) AS INT
    NO_VKKEYS = TRUE
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    FUNCTION = 0
END FUNCTION ' DoNoVkkeys


FUNCTION Donoini(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    TestForBcxIni = TRUE
    FUNCTION = 0
END FUNCTION ' Donoini



FUNCTION Donoio(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    UseIO = FALSE
    FUNCTION = 0
END FUNCTION ' Donoio



FUNCTION Doremovelib (szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    REPLACE BKSLASH1$ WITH BKSLASH2$ IN Src$
    Src$ = IREMOVE$(Src$, "$nolibrary")
    RemoveLibrary(Src$)
    FUNCTION = 0
END FUNCTION ' Doremovelib



FUNCTION Donomain(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    NoMain = TRUE
    FUNCTION = 0
END FUNCTION ' Donomain



FUNCTION Donowin(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    WinHeaders = FALSE
    FUNCTION = 0
END FUNCTION ' Donowin



FUNCTION Doonentry(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    PassOne = TRUE
    CALL PreParse(Src$)
    PassOne = FALSE
    INCR EntryCnt

    IF c_MaxOnEntry = EntryCnt THEN
        CALL Abort("Maximum $OnEnty exceeded.")
    END IF

    Entry$[EntryCnt] = Stk$[2]
    FUNCTION = 0
END FUNCTION ' Doonentry


FUNCTION Doonexit(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    INCR XitCount

    IF c_MaxOnExit = XitCount THEN
        CALL Abort("Maximum $OnExit exceeded.")
    END IF

    Xit$[XitCount]= Stk$[2]
    FUNCTION = 0
END FUNCTION ' Doonexit



FUNCTION Dooptimizer(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    DIM RAW szState$
    *iFLAG = 2
    szState$ = LCASE$(Stk$[2])
    Src$ = ""

    IF szState$ = "on" THEN
        IF OptimizerFirstSetting = TRUE THEN
            OptimizerFirstSetting = FALSE
            Src$ = "~pragmaoptimizeon"
            OptimizerEnabled = TRUE
        ELSE
            IF OptimizerEnabled = FALSE THEN
                OptimizerEnabled = TRUE
                Src$ = "~pragmaoptimizeon"
            END IF
        END IF

    ELSEIF szState$ = "off" THEN
        IF OptimizerFirstSetting = TRUE THEN
            OptimizerFirstSetting = FALSE
            Src$ = "~pragmaoptimizeoff"
            OptimizerEnabled = FALSE
        ELSE
            IF OptimizerEnabled = TRUE THEN
                OptimizerEnabled = FALSE
                Src$ = "~pragmaoptimizeoff"
            END IF
        END IF
    ELSE
        Abort("Error in $OPTIMIZER MetaStatement: " + Src$)
    END IF
    CALL PreParse(Src$)
    FUNCTION = 2
END FUNCTION ' Dooptimizer


FUNCTION Dopack(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    DIM iLoc = 2
    *iFLAG = 0
    FastLexer(Src$, "", "()")
    IF Stk$[iLoc] = "(" THEN INCR iLoc
    FPRINT FP_UDT, "#pragma pack (", Stk$[iLoc], ")"
    FUNCTION = 0
END FUNCTION ' Dopack



FUNCTION Dopp(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    PPFlag = NOT PPFlag
    IF PPFlag THEN
        IF PPDLL_HANDLE = NULL THEN
            PPDLL_HANDLE = LOADLIBRARY("BCXPP.DLL")
            IF NOT PPDLL_HANDLE THEN ' failed to load preprocessor dll
                Abort ("Failed to Open BCX Preprocessor DLL!")
            ELSE
                PRINT "BCXPP.DLL Successfully Loaded"
            END IF
            '****************************************************************************
            ' This conditional mutes GCC's FARPROC/CPP_FARPROC warning.     - MrBcx 790
            ' It is completely safe and obviously supports a very specific purpose: $PP
            ' UPDATED 807 - mostly unneeded now with current version of Mingw
            '****************************************************************************
            $IFDEF __GNUC__
                $PRAGMA GCC diagnostic ignored "-Wcast-function-type"
                PPProc = (CPP_FARPROC) GetProcAddress (PPDLL_HANDLE, "ProcessLine") ' Suppress CRLF
                $PRAGMA GCC diagnostic pop
            $ELSE
                $IFNDEF _MSC_VER
                $PRAGMA GCC diagnostic ignored "-Wcast-function-type"
            $ENDIF
            PPProc = (CPP_FARPROC) GetProcAddress (PPDLL_HANDLE, "ProcessLine") ' Suppress CRLF
        $ENDIF
        '****************************************************************************
        IF NOT PPProc THEN
            Abort ("'FUNCTION ProcessLine' missing in BCX Preprocessor DLL!")
        END IF
    END IF
END IF
FUNCTION = 0
END FUNCTION ' Dopp




FUNCTION Doprj(szWord$, iFLAG AS PINT) AS INT
    *iFLAG = 0

    SELECT CASE szWord$
        CASE "$prj"
            Project$ = UCASE$(EXTRACT$(COMMAND$(1), ".")) + ".USE"
            HFile$   = UCASE$(EXTRACT$(COMMAND$(1), ".")) + ".H"
            Use_SingleFile = FALSE
            Use_BcxTempStr = TRUE

        CASE "$prjuse"
            Use_BcxTempStr = TRUE
            FastLexer(Src$, SPC$, c_FULLSET)
            CALL SetUsed
    END SELECT
    FUNCTION = 0
END FUNCTION ' Doprj



FUNCTION Doproject(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    CALL EnableProject
    FUNCTION = 0
END FUNCTION ' Doproject



FUNCTION Dorems(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    InsertComments = ~InsertComments
    Src$ = ""
    Ndx = 0
    FUNCTION = 0
END FUNCTION ' Dorems



FUNCTION Doresource(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    Use_Resource = TRUE
    ResCompiler$ = Stk$[2]
    UserResFile$ = REMOVE$(Stk$[3], DQ$)
    FUNCTION = 0
END FUNCTION ' Doresource



FUNCTION Dosource(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    SrcFlag = NOT SrcFlag
    FUNCTION = 0
END FUNCTION ' Dosource



FUNCTION Dostdcall(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    UseStdCall = TRUE
    FUNCTION = 0
END FUNCTION ' Dostdcall



FUNCTION Dotest(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    TestState = NOT TestState
    FUNCTION = 0
END FUNCTION ' Dotest




FUNCTION Dotrace(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    TraceFlag = NOT TraceFlag
    FUNCTION = 0
END FUNCTION ' Dotrace



FUNCTION Dotypedef(szWord$, iFLAG AS PINT) AS INT
    UNREFERENCED_PARAMETER(szWord$)
    *iFLAG = 0
    FPRINT FP_UDT, ""
    IREPLACE "callback" WITH "CALLBACK" IN Src$
    IREPLACE "pchar"    WITH "PCHAR"    IN Src$      ' Added by MrBcx in 835
    FPRINT FP_UDT, "typedef ", REMAIN$(Src$, SPC$), ";"
    FUNCTION = 0
END FUNCTION ' Dotypedef


FUNCTION IMAX (a, b) AS INT
    IF a>b THEN
        FUNCTION = a
    ELSE
        FUNCTION = b
    END IF
END FUNCTION ' IMAX


FUNCTION IMIN (a, b) AS INT
    IF a<b THEN
        FUNCTION = a
    ELSE
        FUNCTION = b
    END IF
END FUNCTION ' IMIN
'***********************************************************************************************
'                                         End of Directives
'                                     Begin Standard Prototypes
'***********************************************************************************************

SUB StdProtos(FP_OUTPUT AS FILE)
    IF Use_Project = FALSE THEN

        IF Use_BcxTempStr OR Use_Console OR Use_Proto THEN
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "// *************************************************"
            FPRINT FP_OUTPUT, "//      " + c_$BCX_STR_STD_PROTOS
            FPRINT FP_OUTPUT, "// *************************************************"
            FPRINT FP_OUTPUT, SPC$
        END IF

        IF Use_GUINoMain OR Use_MDIGUINoMain OR Use_Wingui THEN
            IF Use_BCX_FrameWnd THEN
                FPRINT FP_OUTPUT, "HWND    BCX_FrameWnd (PCTSTR, WNDPROC, PCTSTR, HMENU=NULL, int=0, int=CW_USEDEFAULT, int=CW_USEDEFAULT, int=CW_USEDEFAULT, int=CW_USEDEFAULT, int=0, int=0);"
            END IF

            IF Use_BCX_Wnd THEN
                FPRINT FP_OUTPUT, "HWND    BCX_Wnd (PCTSTR, WNDPROC, PCTSTR, HWND=0, int=CW_USEDEFAULT, int=CW_USEDEFAULT, int=CW_USEDEFAULT, int=CW_USEDEFAULT, int=0, int=0, int=0);"
            END IF

            IF Use_BCX_SetBkGrdBrush THEN
                FPRINT FP_OUTPUT, "void    BCX_SetBkGrdBrush (HWND, HBRUSH);"
            END IF

            IF Use_BCX_SetClassStyle THEN
                FPRINT FP_OUTPUT, "void    BCX_SetClassStyle (HWND, long);"
            END IF

            IF Use_BCX_SetIcon THEN
                FPRINT FP_OUTPUT, "void    BCX_SetIcon (HWND, int);"
            END IF

            IF Use_BCX_SetIconSm THEN
                FPRINT FP_OUTPUT, "void    BCX_SetIconSm (HWND, int);"
            END IF

            IF Use_BCX_SetCursor THEN
                FPRINT FP_OUTPUT, "void    BCX_SetCursor (HWND, PCTSTR);"
            END IF

            IF Use_BCX_SetMetric THEN
                FPRINT FP_OUTPUT, "void    BCX_SetMetric (PCTSTR);"
            END IF

            IF Use_GUINoMain THEN
                IF Use_BCX_MsgPump THEN
                    FPRINT FP_OUTPUT, "int     BCX_MsgPump (HACCEL=0);"
                END IF
            ELSEIF Use_MDIGUINoMain THEN
                IF Use_BCX_MDI_MsgPump THEN
                    FPRINT FP_OUTPUT, "int     BCX_MDI_MsgPump (HACCEL=0);"
                END IF
            END IF

            IF Use_BCX_RegWnd THEN
                FPRINT FP_OUTPUT, "void    BCX_RegWnd (PCTSTR, WNDPROC);"
            END IF
            IF Use_BCX_InitGUI THEN
                FPRINT FP_OUTPUT, "void    BCX_InitGUI (void);"
            END IF
        END IF

        IF Use_Clng THEN
            FPRINT FP_OUTPUT, "long    CLNG (double);"
        END IF

        IF Use_Cint THEN
            FPRINT FP_OUTPUT, "int     Cint (double);"
        END IF

        IF Use_Tix THEN
            FPRINT FP_OUTPUT, "void    TIX_START(void);"
            FPRINT FP_OUTPUT, "double  TIX_NOW(void);"
        END IF

        IF Use_StartupCode THEN
            FPRINT FP_OUTPUT, "int     BCX_StartupCode_ (void);"
        END IF

        IF Use_ExitCode THEN
            FPRINT FP_OUTPUT, "int     BCX_ExitCode_ (void);"
        END IF

        IF Use_Eof THEN
            FPRINT FP_OUTPUT, "int     EoF (FILE*);"
        END IF

        IF Use_NamePathFromFP = TRUE THEN
            FPRINT FP_OUTPUT, "char*   NamePathFromFP (FILE*);"
        END IF

        IF Use_Longestline THEN
            FPRINT FP_OUTPUT, "UINT    LongestLine(PCTSTR);"
        END IF

        IF Use_Nextlinelen THEN
            FPRINT FP_OUTPUT, "UINT    NextLineLen (FILE*);"
        END IF

        IF Use_AppActivate THEN
            FPRINT FP_OUTPUT, "int     AppActivate (PCTSTR);"
        END IF

        IF Use_BoxCommon THEN
            FPRINT FP_OUTPUT, "PWORD   lpwAlign (PWORD);"
        END IF

        IF Use_Inputbox THEN
            FPRINT FP_OUTPUT, "char*   InputBox (PCTSTR, PCTSTR, PCTSTR, int=0);"
            FPRINT FP_OUTPUT, "LRESULT CreatePrompter (PCTSTR, PCTSTR, PCTSTR, int);"
            FPRINT FP_OUTPUT, "LRESULT CALLBACK Prompter (HWND, UINT, WPARAM, LPARAM);"
        END IF

        IF Use_VBS THEN
            FPRINT FP_OUTPUT, "HRESULT VBS_RUN_SCRIPT (PCTSTR);"
            FPRINT FP_OUTPUT, "HRESULT VBS_ADDCODE    (PCTSTR);"
            FPRINT FP_OUTPUT, "double  VBS_EVAL_NUM   (PCTSTR);"
            FPRINT FP_OUTPUT, "char*   VBS_EVAL_STR   (PCTSTR);"
            FPRINT FP_OUTPUT, "BOOL    VBS_START      (void);"
            FPRINT FP_OUTPUT, "void    VBS_STOP       (void);"
            FPRINT FP_OUTPUT, "void    VBS_RESET      (void);"
            FPRINT FP_OUTPUT, "char*   VBS_ERROR      (void);"
        END IF

        IF Use_Infobox THEN
            FPRINT FP_OUTPUT, "void    InfoBox (PCTSTR, PCTSTR, int=170, int=170);"
            FPRINT FP_OUTPUT, "LRESULT CALLBACK CB_InfoBox (HWND, UINT, WPARAM, LPARAM);"
        END IF

        IF Use_Mdigui THEN
            FPRINT FP_OUTPUT, "HWND    BCX_MDICHILD (PCTSTR, PCTSTR, int=CW_USEDEFAULT, int=CW_USEDEFAULT, int=CW_USEDEFAULT, int=CW_USEDEFAULT, ULONG=0, LPARAM=0);"
            FPRINT FP_OUTPUT, "void    BCX_MDICLASS (WNDPROC, PCHAR);"
            FPRINT FP_OUTPUT, "HWND    BCX_MDICLIENT (HWND, int);"
        END IF

        IF Use_BCX_Colordlg THEN
            FPRINT FP_OUTPUT, "int     BCX_ColorDlg (ULONG=RGB(128, 128, 128), HWND=0);"
        END IF

        IF Use_BCXMDialog THEN
            FPRINT FP_OUTPUT, "INT_PTR BCX_MDialog (DLGPROC, PCTSTR, HWND, int=0, int=0, int=250, int=150, int=0, int=0, PCTSTR=NULL, int=0);"
        END IF

        IF Use_BCXDialog THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Dialog (DLGPROC, PCTSTR, HWND, int=0, int=0, int=250, int=150, int=0, int=0, PCTSTR=NULL, int=0);"
        END IF

        IF Use_BCXDialogCommon THEN
            FPRINT FP_OUTPUT, "void    SetDialogScale (HWND, BOOL);"
        END IF

        IF Use_SetDimension THEN
            FPRINT FP_OUTPUT, "void    SetDimension (PCTSTR , int, HWND, BOOL=FALSE);"
        END IF

        IF Use_GetDimension THEN
            FPRINT FP_OUTPUT, "int     GetDimension (PCTSTR ,HWND, BOOL=FALSE);"
        END IF

        IF Use_Form THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Form (PCTSTR, int=0, int=0, int=250, int=150, int=-1, int=0);"
        END IF

        IF Use_Setclientsize THEN
            FPRINT FP_OUTPUT, "void    BCX_SetClientSize (HWND, int, int, float=1.0f, float=1.0f);"
        END  IF

        IF Use_BCX_Get_Window_Width THEN
            FPRINT FP_OUTPUT, "int     BCX_Get_Window_Width (HWND);"
        END  IF

        IF Use_BCX_Get_Window_Height THEN
            FPRINT FP_OUTPUT, "int     BCX_Get_Window_Height (HWND);"
        END  IF

        IF Use_Edit THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Edit (PCTSTR, HWND, int, int, int, int, int, int=0, int=-1);"
        END IF

        IF Use_BCX_Input THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Input (PCTSTR, HWND, int, int, int, int, int, int=0, int=-1);"
        END IF

        IF Use_Button THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Button (PCTSTR, HWND, int=0, int=0, int=0, int=0, int=0, int=0, int=-1);"
        END IF

        IF Use_BmpButton THEN
            FPRINT FP_OUTPUT, "HWND    BCX_BmpButton (PCTSTR, HWND, int=0, int=0, int=0, int=0, int=0, int=0, int=0, int=-1);"
        END IF

        IF Use_SplitButton THEN
            ' -------------------------------------------------------------------------
            ' Data structure for menu items (user-facing)
            ' -------------------------------------------------------------------------
            FPRINT FP_OUTPUT, "typedef struct {"
            FPRINT FP_OUTPUT, "  char szLabel[256];"
            FPRINT FP_OUTPUT, "  int  nID;"
            FPRINT FP_OUTPUT, "} BCX_SPLITBUTTONDATA;\n\n"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "#define BCX_MAX_SPLITBUTTONS 64"
            FPRINT FP_OUTPUT, "#define BCX_MAX_SPLITBUTTON_ITEMS 32\n"
            FPRINT FP_OUTPUT, "typedef struct {"
            FPRINT FP_OUTPUT, "  HWND    hWnd;"
            FPRINT FP_OUTPUT, "  int     nCtlID;"
            FPRINT FP_OUTPUT, "  HMENU   hPopupMenu;"
            FPRINT FP_OUTPUT, "  int     nItemCount;"
            FPRINT FP_OUTPUT, "  WNDPROC lpfnOrigProc;"
            FPRINT FP_OUTPUT, "} BCX_SPLITBUTTONINFO;\n"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "static BCX_SPLITBUTTONINFO BCX_SplitButtons[BCX_MAX_SPLITBUTTONS];"
            FPRINT FP_OUTPUT, "static int BCX_SplitButtonCount = 0;\n\n"
            FPRINT FP_OUTPUT, "HWND BCX_SplitButton(PCTSTR, HWND, int=0, int=0, int=0, int=0, int=0, int=0, int=0);"
            FPRINT FP_OUTPUT, "void BCX_SplitButton_SetItems(HWND, BCX_SPLITBUTTONDATA*, int);"
            FPRINT FP_OUTPUT, "void BCX_SplitButton_AddItem(HWND, PCTSTR, int);"
            FPRINT FP_OUTPUT, "void BCX_SplitButton_AddSeparator(HWND);"
        END IF

        IF Use_Label THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Label (PCTSTR, HWND, int=0, int=0, int=0, int=0, int=0, int=0, int=0);"
        END IF

        IF Use_Group THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Group (PCTSTR, HWND, int, int, int, int, int, int=0, int=0);"
        END IF

        IF Use_Checkbox THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Checkbox (PCTSTR, HWND, int=0, int=0, int=0, int=0, int=0, int=0, int=0);"
        END IF

        IF Use_Radio THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Radio (PCTSTR, HWND, int=0, int=0, int=0, int=0, int=0, int=0, int=0);"
        END IF

        IF Use_Combobox THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Combobox (PCTSTR, HWND, int, int, int, int, int, int=0, int=-1);"
        END IF

        IF Use_Listbox THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Listbox (PCTSTR, HWND, int, int, int, int, int, int=0, int=-1);"
        END IF

        IF Use_Blackrect THEN
            FPRINT FP_OUTPUT, "HWND    BCX_BlackRect (PCTSTR, HWND, int, int, int, int, int, int=0, int=0);"
        END IF

        IF Use_Whiterect THEN
            FPRINT FP_OUTPUT, "HWND    BCX_WhiteRect (PCTSTR, HWND, int, int, int, int, int, int=0, int=0);"
        END IF

        IF Use_Grayrect THEN
            FPRINT FP_OUTPUT, "HWND    BCX_GrayRect (PCTSTR, HWND, int, int, int, int, int, int=0, int=0);"
        END IF

        IF Use_Datepick THEN
            FPRINT FP_OUTPUT, "HWND    BCX_DatePick (PCTSTR, HWND, int, int, int, int, int, int=0, int=-1);"
        END IF

        IF Use_Richedit THEN
            FPRINT FP_OUTPUT, "HWND    BCX_RichEdit (PCTSTR, HWND, int, int, int, int, int, int=0, int=-1);"
            FPRINT FP_OUTPUT, "void    SetWindowRTFText (HWND, PCTSTR);"
        END IF

        IF Use_Status THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Status (PCTSTR, HWND, int=200, int=1, PINT=NULL);"
        END IF

        IF Use_BCX_OlePicture THEN
            FPRINT FP_OUTPUT, "HWND    BCX_OlePicture (PCTSTR, HWND=0, int=0, int=0, int=0, int=0, int=0, int=0, int=0, int=0);"
        END IF

        IF Use_Bitmap THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Bitmap (PCTSTR, HWND=0, int=0, int=0, int=0, int=0, int=0, int=0, int=0, int=0);"
        END IF

        IF Use_Icon THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Icon (PCTSTR, HWND=0, int=0, int=0, int=0, int=0, int=0, int=0, int=0, int=0);"
        END IF

        IF Use_Listview THEN
            FPRINT FP_OUTPUT, "HWND    BCX_ListView (PCTSTR, HWND, int, int, int, int, int, int=0, int=-1, int=15);"
        END IF

        IF Use_Treeview THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Treeview (PCTSTR, HWND, int, int, int, int, int, int=0, int=-1);"
        END IF

        IF Use_BCX_Control THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Control (PCTSTR, HWND, PCTSTR, int, int, int, int, int, int=0, int=0);"
        END IF

        IF Use_ProgressBar THEN
            FPRINT FP_OUTPUT, "HWND    BCX_ProgressBar (PCTSTR, HWND, int=0, int=0, int=0, int=0, int=0, int=0, int=-1);"
        END IF

        IF Use_BCX_Slider THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Slider (PCTSTR, HWND, int, int, int, int, int, int=0, int=0, int=0);"
        END IF

        IF Use_BCX_Splitter THEN
            FPRINT FP_OUTPUT, "void    DrawXorBar (HWND, RECT *);"
            FPRINT FP_OUTPUT, "int     BCX_SetSplitPos (HWND, int=50, int=0);"
            FPRINT FP_OUTPUT, "LRESULT CALLBACK SplitterWndProc (HWND, UINT, WPARAM, LPARAM);"
            FPRINT FP_OUTPUT, "HWND    BCX_Splitter (HWND, int, int=0, int=0, int=0, int=0, int=0, int=0);"
        END IF

        IF Use_BCX_Toolbar THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Toolbar (HWND, int, int, PCTSTR=NULL, PINT=NULL, PVOID=NULL, PINT=NULL, int=0, int=0, int=0, int=0);"
        END IF

        IF Use_BCX_Tab THEN
            FPRINT FP_OUTPUT, "HWND    BCX_Tab (HWND, int, int, HWND *, char[][BCXSTRSIZE], int, int, int, int, HIMAGELIST=NULL, int=0, int=0);"
            FPRINT FP_OUTPUT, "HWND    BCX_AddTab (HWND, int, PCTSTR, int=-1, int=0);"
            FPRINT FP_OUTPUT, "void    BCX_RemTab (HWND, int);"
            FPRINT FP_OUTPUT, "int     BCX_TabSelect (HWND, LPARAM);"
            FPRINT FP_OUTPUT, "LRESULT CALLBACK TabPageWndProc (HWND, UINT, WPARAM, LPARAM);"
            FPRINT FP_OUTPUT, "LRESULT CALLBACK TabCallback (HWND, UINT, WPARAM, LPARAM);"
            FPRINT FP_OUTPUT, "LRESULT CALLBACK TabSizeCallback (HWND, UINT, WPARAM, LPARAM);"
        END IF

        IF Use_Draw THEN
            FPRINT FP_OUTPUT, "HDC     StartDraw (HWND);"
            FPRINT FP_OUTPUT, "HBITMAP EndDraw (HWND, HDC);"
        END IF

        IF Use_BCX_UpDown THEN
            FPRINT FP_OUTPUT, "HWND    BCX_UpDown (HWND, int, int, int, int, int, int, int=0);"
        END IF

        IF Use_BCX_Get_UpDown THEN
            FPRINT FP_OUTPUT, "int     BCX_Get_UpDown (HWND);"
        END IF

        IF Use_BCX_Print THEN
            FPRINT FP_OUTPUT, "int     BCX_Print (HWND, int, int, PCTSTR, HDC=NULL);"
        END IF

        IF Use_BCX_Printex THEN
            FPRINT FP_OUTPUT, "void    BCX_Printex (HWND, long, long, char*, long, long, char*, long, HDC=NULL);"
        END IF

        IF Use_SetFormColor THEN
            FPRINT FP_OUTPUT, "void    BCX_Set_Form_Color (HWND, ULONG);"
        END IF

        IF Use_BCX_Tile THEN
            FPRINT FP_OUTPUT, "void    BCX_Tile (HWND, HBITMAP);"
        END IF

        IF Use_GetText THEN
            FPRINT FP_OUTPUT, "char*   BCX_Get_Text (HWND);"
        END IF

        IF Use_GetResource THEN
            FPRINT FP_OUTPUT, "PVOID   GetResource (int, char*, ULONG*);"
        END IF

        IF Use_SetText THEN
            FPRINT FP_OUTPUT, "int     BCX_Set_Text (HWND, PCTSTR);"
        END IF

        IF Use_Elf THEN
            FPRINT FP_OUTPUT, "void    EditLoadFile (HWND, PCTSTR);"
        END IF

        IF Use_ListBoxLoadFile THEN
            FPRINT FP_OUTPUT, "void    ListBoxLoadFile (HWND, PCTSTR, int=0, int=0);"
        END IF

        IF Use_ComboBoxLoadFile THEN
            FPRINT FP_OUTPUT, "void    ComboBoxLoadFile (HWND, PCTSTR);"
        END IF

        IF Use_SetFont THEN
            FPRINT FP_OUTPUT, "HFONT   BCX_Set_Font (PCTSTR, float, int=0, int=0, int=0, int=0, int=0, int=0);"
        END IF

        IF Use_BCX_Preset THEN
            FPRINT FP_OUTPUT, "int     BCX_Preset (HWND, int, int, HDC=NULL);"
        END IF

        IF Use_BCX_Line THEN
            FPRINT FP_OUTPUT, "int     BCX_Line (HWND, int, int, int, int, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Polar_Line THEN
            FPRINT FP_OUTPUT, "void    BCX_Polar_Line(HWND, int, int, float, float, ULONG, HDC=NULL);"
        END IF

        IF Use_BCX_Lineto THEN
            FPRINT FP_OUTPUT, "int     BCX_Lineto (HWND, int, int, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Triangle THEN
            FPRINT FP_OUTPUT, "int     BCX_Triangle(HWND, LONG, LONG, LONG, LONG, LONG, LONG, DWORD, LONG, HDC=NULL);"
        END IF

        IF Use_BCX_Gradient THEN
            FPRINT FP_OUTPUT, "void    BCX_Gradient(HWND, ULONG, ULONG, int, HDC=NULL);"
        END IF

        IF Use_BCX_Polygon THEN
            FPRINT FP_OUTPUT, "int     BCX_Polygon (HWND, const POINT *, int, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_PolyBezier THEN
            FPRINT FP_OUTPUT, "int     BCX_PolyBezier (HWND, const POINT *, int, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Polyline THEN
            FPRINT FP_OUTPUT, "int     BCX_Polyline (HWND, const POINT*, int, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Circle THEN
            FPRINT FP_OUTPUT, "int     BCX_Circle (HWND, int, int, int, int=0, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Ellipse THEN
            FPRINT FP_OUTPUT, "int     BCX_Ellipse (HWND, int, int, int, int, int=0, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Rectangle THEN
            FPRINT FP_OUTPUT, "int     BCX_Rectangle (HWND, int, int, int, int, int=0, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Roundrect THEN
            FPRINT FP_OUTPUT, "int     BCX_Roundrect(HWND, int, int, int, int, int, int, int=0, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Arc THEN
            FPRINT FP_OUTPUT, "int     BCX_Arc (HWND, int, int, int, int, int, int, int, int, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Pie THEN
            FPRINT FP_OUTPUT, "int     BCX_Pie(HWND, int, int, int, int, int, int, int, int, int=0, int=0, HDC=NULL);"
        END IF

        IF Use_Set_BCX_Bitmap THEN
            FPRINT FP_OUTPUT, "void    Set_BCX_Bitmap (HWND, PCTSTR, int=0, int=0, int=0);"
        END IF

        IF Use_Set_BCX_Bitmap2 THEN
            FPRINT FP_OUTPUT, "HBITMAP Set_BCX_Bitmap2 (HWND, HBITMAP, int=1);"
        END IF

        IF Use_Newbmp THEN
            FPRINT FP_OUTPUT, "HBITMAP NewBmp (void);"
        END IF

        IF Use_Makebmp THEN
            FPRINT FP_OUTPUT, "HBITMAP MakeBmp (HDC);"
        END IF

        IF Use_Makehdc THEN
            FPRINT FP_OUTPUT, "HDC     MakeHdc (HBITMAP);"
        END IF

        IF Use_Set_BCX_BmpButton THEN
            FPRINT FP_OUTPUT, "void    Set_BCX_BmpButton (HWND, PCTSTR, int=0);"
        END IF

        IF Use_Set_BCX_Icon THEN
            FPRINT FP_OUTPUT, "void    Set_BCX_Icon (HWND, PCTSTR, int=0, int=0, int=0);"
        END IF

        IF Use_BCX_Fontdlg THEN
            FPRINT FP_OUTPUT, "int     BCX_FontDlg (BOOL=0, HWND=0);"
        END IF

        IF Use_BCX_Blit THEN
            FPRINT FP_OUTPUT, "void    BCX_Blit (HBITMAP,HDC);"
        END IF

        IF Use_BCX_Blit_Stretch THEN
            FPRINT FP_OUTPUT, "void    BCX_Blit_Stretch (HBITMAP,HDC);"
        END IF

        IF Use_BCX_Blit_Sprite THEN
            FPRINT FP_OUTPUT, "void    BCX_Blit_Sprite (HBITMAP, int, int, ULONG, HDC);"
        END IF

        IF Use_BCX_Buffer THEN
            FPRINT FP_OUTPUT, "void    BCX_BUFFER_START (int, int);"
            FPRINT FP_OUTPUT, "void    BCX_BUFFER_STOP  (HWND);"
        END IF

        IF Use_BCX_Pset THEN
            FPRINT FP_OUTPUT, "int     BCX_Pset (HWND, int, int, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Polar_Pset THEN
            FPRINT FP_OUTPUT, "void    BCX_Polar_Pset(HWND, int, int, float, float, ULONG, HDC=NULL);"
        END IF

        IF Use_BCX_Floodfill THEN
            FPRINT FP_OUTPUT, "int     BCX_FloodFill (HWND, int, int, int, int, int=0, HDC=NULL);"
        END IF

        IF Use_BCX_Getpixel THEN
            FPRINT FP_OUTPUT, "ULONG   BCX_Getpixel (HWND, int, int, HDC=NULL);"
        END IF

        IF Use_BCX_Get THEN
            FPRINT FP_OUTPUT, "HBITMAP BCX_Get (HWND, int, int, int, int, int=SRCCOPY, HDC=NULL);"
        END IF

        IF Use_BCX_Put THEN
            FPRINT FP_OUTPUT, "void    BCX_Put (HWND, HBITMAP, int, int, int, int, int=SRCCOPY, HDC=NULL);"
        END IF

        IF Use_BCX_LoadBMP THEN
            FPRINT FP_OUTPUT, "HBITMAP BCX_LoadBMP (PCTSTR, int=0, int=0);"
        END IF

        IF Use_BCX_LoadImage THEN
            FPRINT FP_OUTPUT, "HBITMAP BCX_LoadImage (PCTSTR, int=0);"
        END IF

        IF Use_DrawTransBMP THEN
            FPRINT FP_OUTPUT, "void    DrawTransBMP (HWND, HBITMAP, ULONG, int, int, HDC=NULL);"
        END IF

        IF Use_DrawStr THEN
            FPRINT FP_OUTPUT, "void    Draw(char* DrawString);"
        END IF

        IF Use_BCX_BmpWidth THEN
            FPRINT FP_OUTPUT, "int     BCX_BmpWidth (HBITMAP);"
        END IF

        IF Use_BCX_ToolTip THEN
            FPRINT FP_OUTPUT, "LRESULT BCX_ToolTip (PCTSTR, HWND, int=0);"
            FPRINT FP_OUTPUT, "HWND    BCX_CreateToolTip (HWND, int);"
        END IF

        IF Use_BCX_BmpHeight THEN
            FPRINT FP_OUTPUT, "int     BCX_BmpHeight (HBITMAP);"
        END IF

        IF Use_QBColor THEN
            FPRINT FP_OUTPUT, "ULONG   qbcolor (int);"
        END IF

        IF Use_SetColor THEN
            FPRINT FP_OUTPUT, "LRESULT Set_Color (int, int, HDC, HWND);"
        END IF

        IF Use_PlayWav THEN
            FPRINT FP_OUTPUT, "void    PlayWav (PCTSTR, int=0,  int=SND_SYNC);"
        END IF

        IF Use_SaveBmp THEN
            FPRINT FP_OUTPUT, "void    SaveBmp (PVOID, PTSTR);"
        END IF

        IF Use_GetBmp THEN
            FPRINT FP_OUTPUT, "HDC     GetBmp (int, int, int, int, HWND);"
        END IF

        IF Use_Center THEN
            FPRINT FP_OUTPUT, "void    Center (HWND, HWND=0, HWND=0);"
        END IF

        IF Use_Cls THEN
            FPRINT FP_OUTPUT, "void    cls (void);"
        END IF

        IF Use_Color THEN
            FPRINT FP_OUTPUT, "void    color (int, int=0);"
        END IF

        IF Use_PushPopColors THEN
            FPRINT FP_OUTPUT, "void    PushColors (void);"
            FPRINT FP_OUTPUT, "void    PopColors  (void);"
        END IF

        IF Use_Consolesize THEN
            FPRINT FP_OUTPUT, "void    BCX_SetConsoleSize  (int= 80,int= 25);"
            FPRINT FP_OUTPUT, "void    BCX_PushConsoleSize (void);"
            FPRINT FP_OUTPUT, "void    BCX_PopConsoleSize  (void);"
        END IF

        IF Use_Panel THEN
            FPRINT FP_OUTPUT, "void    panel (int, int, int, int, int, int, int, int);"
        END IF

        IF Use_Locate THEN
            FPRINT FP_OUTPUT, "void    locate (int, int, int=1, int=12);"
        END IF

        IF Use_Pos THEN
            FPRINT FP_OUTPUT, "int     Pos (void);"
        END IF

        IF Use_Csrlin THEN
            FPRINT FP_OUTPUT, "int     Csrlin (void);"
        END IF

        IF Use_Run THEN
            FPRINT FP_OUTPUT, "int     Run (PCTSTR, int=1, int=0);"
        END IF

        IF Use_Doevents THEN
            FPRINT FP_OUTPUT, "void    DoEvents (void);"
        END IF

        IF Use_Randomize THEN
            FPRINT FP_OUTPUT, "void    randomize (unsigned int);"
        END IF

        IF Use_Midstr THEN
            FPRINT FP_OUTPUT, "void    midstr (char*, int, int, char *);"
        END IF

        IF Use_Swap THEN
            FPRINT FP_OUTPUT, "void    swap (byte*, byte*, int);"
        END IF

        IF Use_BcxTempStr THEN
            FPRINT FP_OUTPUT, "char*   BCX_TempStr (size_t);"
        END IF

        IF Use_sziif THEN
            FPRINT FP_OUTPUT, "char*   sziif (int, PCTSTR, PCTSTR);"
        END IF

        IF Use_Using THEN
            FPRINT FP_OUTPUT, "char*   Using (PCTSTR, long double);"
        END IF

        IF Use_Format THEN
            FPRINT FP_OUTPUT, "char*   Format (long double, PCTSTR=NULL);"
        END IF

        IF Use_TempFileName THEN
            FPRINT FP_OUTPUT, "char*   TempFileName (PCTSTR, PCTSTR);"
        END IF

        IF Use_AppExePath THEN
            FPRINT FP_OUTPUT, "char*   AppExePath (void);"
        END IF

        IF Use_AppExeName THEN
            FPRINT FP_OUTPUT, "char*   AppExeName (void);"
        END IF

        IF Use_VChr THEN
            FPRINT FP_OUTPUT, "char*   vchr (int,...);"
        END IF

        IF Use_Lcase THEN
            FPRINT FP_OUTPUT, "char*   lcase (PCTSTR);"
        END IF

        IF Use_Ucase THEN
            FPRINT FP_OUTPUT, "char*   ucase (PCTSTR);"
        END IF

        IF Use_Mid THEN
            FPRINT FP_OUTPUT, "char*   mid (PCTSTR, int, int=-1);"
        END IF

        IF Use_Ltrim THEN
            FPRINT FP_OUTPUT, "char*   ltrim (PCTSTR, char=32);"
        END IF

        IF Use_Rtrim THEN
            FPRINT FP_OUTPUT, "char*   rtrim (PCTSTR, char=32);"
        END IF

        IF Use_Trim THEN
            FPRINT FP_OUTPUT, "char*   trim (PCTSTR);"
        END IF

        IF Use_Strim THEN
            FPRINT FP_OUTPUT, "char*   strim (PCTSTR);"
        END IF

        IF Use_Left THEN
            FPRINT FP_OUTPUT, "char*   left (PCTSTR, int);"
        END IF

        IF Use_Right THEN
            FPRINT FP_OUTPUT, "char*   right (PCTSTR, int);"
        END IF

        IF Use_Cpad THEN
            FPRINT FP_OUTPUT, "char*   cpad (PCTSTR, int, int=32);"
        END IF

        IF Use_Rpad THEN
            FPRINT FP_OUTPUT, "char*   rpad (PCTSTR, int, int=32);"
        END IF

        IF Use_Lpad THEN
            FPRINT FP_OUTPUT, "char*   lpad (PCTSTR, int, int=32);"
        END IF

        IF Use_String THEN
            FPRINT FP_OUTPUT, "char*   stringx (int, int);"
        END IF

        IF Use_Repeat THEN
            FPRINT FP_OUTPUT, "char*   repeat (int, PCTSTR);"
        END IF

        IF Use_Extract THEN
            FPRINT FP_OUTPUT, "char*   extract (PCTSTR, PCTSTR);"
        END IF

        IF Use_ExtractAny THEN
            FPRINT FP_OUTPUT, "char*   extractany (PCTSTR, PCTSTR);"
        END IF

        IF Use_Remain THEN
            FPRINT FP_OUTPUT, "char*   remain (PCTSTR, PCTSTR);"
        END IF

        IF Use_RemainAny THEN
            FPRINT FP_OUTPUT, "char*   remainany (PCTSTR, PCTSTR);"
        END IF

        IF Use_Reverse THEN
            FPRINT FP_OUTPUT, "char*   reverse (PCTSTR);"
        END IF

        IF Use_Command THEN
            FPRINT FP_OUTPUT, "char*   command (int=-1);"
        END IF

        IF Use_Mcase THEN
            FPRINT FP_OUTPUT, "char*   mcase (PCTSTR);"
        END IF

        IF Use_Replace THEN
            FPRINT FP_OUTPUT, "char*   replace (PCTSTR, PCTSTR, PCTSTR);"
        END IF

        IF Use_iReplace THEN
            FPRINT FP_OUTPUT, "char*   iReplace (PCTSTR, PCTSTR, PCTSTR);"
        END IF

        IF Use_ReplaceAny THEN
            FPRINT FP_OUTPUT, "char*   ReplaceAny (PCTSTR, PCTSTR, PCTSTR);"
        END IF

        IF Use_IReplaceAny THEN
            FPRINT FP_OUTPUT, "char*   IReplaceAny (PCTSTR, PCTSTR, PCTSTR);"
        END IF


        IF Use_RemoveAny THEN
            FPRINT FP_OUTPUT, "char*   RemoveAny (PCTSTR, PCTSTR);"
        END IF

        IF Use_IRemoveAny THEN
            FPRINT FP_OUTPUT, "char*   IRemoveAny (PCTSTR, PCTSTR);"
        END IF

        IF Use_Sleep THEN
            FPRINT FP_OUTPUT, "void    BCX_Sleep (int);"
        END IF

        IF Use_Space THEN
            FPRINT FP_OUTPUT, "char*   space (int a);"
        END IF

        IF Use_Str THEN
            FPRINT FP_OUTPUT, "char*   str (double, int=0);"
        END IF

        IF Use_Strl THEN
            FPRINT FP_OUTPUT, "char*   strl (long double, int=0);"
        END IF


        IF Use_RegString THEN
            FPRINT FP_OUTPUT, "char*   RegString (HKEY, PCTSTR, PCTSTR);"
        END IF

        IF Use_CreateRegString THEN
            FPRINT FP_OUTPUT, "void    CreateRegString (HKEY, PCTSTR, PCTSTR, PCTSTR);"
        END IF

        IF Use_DeleteRegKey THEN
            FPRINT FP_OUTPUT, "void    DeleteRegKey (HKEY, PCTSTR);"
        END IF

        IF Use_CreateRegInt THEN
            FPRINT FP_OUTPUT, "void    CreateRegInt (HKEY, PCTSTR, PCTSTR, int);"
        END IF
        IF Use_Mkpath THEN
            FPRINT FP_OUTPUT, "void    MkPath (PCTSTR);"
        END IF

        IF Use_Findfirst THEN
            FPRINT FP_OUTPUT, "char*   findfirst (PCTSTR);"
        END IF

        IF Use_Findnext THEN
            FPRINT FP_OUTPUT, "char*   findnext (void);"
        END IF

        IF Use_Lookahead THEN
            FPRINT FP_OUTPUT, "char*   LookAhead (FILE*, int=1);"
        END IF

        IF Use_Issystem THEN
            FPRINT FP_OUTPUT, "int     issystem (PCTSTR);"
        END IF

        IF Use_Ishidden THEN
            FPRINT FP_OUTPUT, "int     ishidden (PCTSTR);"
        END IF

        IF Use_Isreadonly THEN
            FPRINT FP_OUTPUT, "int     isreadonly (PCTSTR);"
        END IF

        IF Use_Isfile THEN
            FPRINT FP_OUTPUT, "int     isfile (PCTSTR);"
        END IF

        IF Use_Isfolder THEN
            FPRINT FP_OUTPUT, "int     isfolder (PCTSTR);"
        END IF
        IF Use_Curdir THEN
            FPRINT FP_OUTPUT, "char*   curdir (void);"
        END IF

        IF Use_Windir THEN
            FPRINT FP_OUTPUT, "char*   windir (void);"
        END IF

        IF Use_GetSpecialFolder THEN
            FPRINT FP_OUTPUT, "char*   GetSpecialFolder (int, int=0, HWND=NULL);"
        END IF

        IF Use_GetSpecialFolderex THEN
            FPRINT FP_OUTPUT, "char*   GetSpecialFolderEx (const GUID, ULONG=0);"
        END IF

        IF Use_Sysdir THEN
            FPRINT FP_OUTPUT, "char*   sysdir (void);"
        END IF

        IF Use_Tempdir THEN
            FPRINT FP_OUTPUT, "char*   tempdir (void);"
        END IF

        IF Use_Environ THEN
            FPRINT FP_OUTPUT, "char*   Environ (PCTSTR);"
        END IF

        IF Use_Boolstr THEN
            FPRINT FP_OUTPUT, "char*   BoolStr (int);"
        END IF

        IF Use_Hex THEN
            FPRINT FP_OUTPUT, "char*   hex(uint64_t, int=0);"
        END IF

        IF Use_Bin THEN
            FPRINT FP_OUTPUT, "char*   Bin (int);"
        END IF

        IF Use_Oct THEN
            FPRINT FP_OUTPUT, "char*   oct (int);"
        END IF

        IF Use_Date THEN
            FPRINT FP_OUTPUT, "char*   date (int=0);"
        END IF

        IF Use_IsoDate THEN
            FPRINT FP_OUTPUT, "char*   isodate (int=0);"
        END IF

        IF Use_Mouse_sx THEN
            FPRINT FP_OUTPUT, "int     MOUSEX_SCREEN (void);"
            FPRINT FP_OUTPUT, "#define MOUSE_SX MOUSEX_SCREEN()"
        END IF

        IF Use_Mouse_sy THEN
            FPRINT FP_OUTPUT, "int     MOUSEY_SCREEN (void);"
            FPRINT FP_OUTPUT, "#define MOUSE_SY MOUSEY_SCREEN()"
        END IF

        IF Use_Mouse_cx THEN
            FPRINT FP_OUTPUT, "int     MOUSEX_CLIENT (void);"
            FPRINT FP_OUTPUT, "#define MOUSE_CX MOUSEX_CLIENT()"
        END IF

        IF Use_Mouse_cy THEN
            FPRINT FP_OUTPUT, "int     MOUSEY_CLIENT (void);"
            FPRINT FP_OUTPUT, "#define MOUSE_CY MOUSEY_CLIENT()"
        END IF

        IF Use_Now THEN
            FPRINT FP_OUTPUT, "char*   now (int=0);"
        END IF

        IF Use_SearchPath THEN
            FPRINT FP_OUTPUT, "char*   SEARCHPATH (PCTSTR);"
        END IF

        IF Use_BcxSplitPath THEN
            FPRINT FP_OUTPUT, "char*   BcxSplitPath (PCTSTR, int);"
        END IF

        IF Use_BCX_Path THEN
            FPRINT FP_OUTPUT, "char*   BcxPath (void);"
        END IF

        IF Use_LccPath THEN
            FPRINT FP_OUTPUT, "char*   LccPath (void);"
        END IF

        IF Use_PellesPath THEN
            FPRINT FP_OUTPUT, "char*   PellesPath (void);"
        END IF

        IF Use_Strtoken THEN
            FPRINT FP_OUTPUT, "char*   StrToken (PCTSTR, PCTSTR, int);"
        END IF

        IF Use_RegExist THEN
            FPRINT FP_OUTPUT, "long    RegExist (HKEY, PCHAR, PCHAR);"
        END IF

        IF Use_RegInt THEN
            FPRINT FP_OUTPUT, "int     RegInt (HKEY, PCTSTR, PCTSTR);"
        END IF

        IF Use_FileLocked THEN
            FPRINT FP_OUTPUT, "int     FileLocked (PCTSTR);"
        END IF

        IF Use_Bff THEN
            FPRINT FP_OUTPUT, "char*   BFF (PCTSTR, int=0, PCTSTR=NULL);"
            FPRINT FP_OUTPUT, "int     CALLBACK BFFCallBack (HWND,  UINT,  LPARAM,  LPARAM);"
        END IF

        IF Use_FillArray THEN
            FPRINT FP_OUTPUT, "int     fillarray (PCTSTR, int, int, void *);"
        END IF

        IF Use_Lclick THEN
            FPRINT FP_OUTPUT, "int     lClick (void);"
        END IF

        IF Use_Rclick THEN
            FPRINT FP_OUTPUT, "int     rClick (void);"
        END IF

        IF Use_Remove THEN
            FPRINT FP_OUTPUT, "char*   RemoveStr (PCTSTR, PCTSTR);"
        END IF

        IF Use_IRemove THEN
            FPRINT FP_OUTPUT, "char*   IRemoveStr (PCTSTR, PCTSTR);"
        END IF

        IF Use_Hook THEN
            FPRINT FP_OUTPUT, "LRESULT CALLBACK SBProc (int, WPARAM, LPARAM);"
        END IF

        IF Use_Getfilename THEN
            FPRINT FP_OUTPUT, "char*   GetFileName (PCTSTR,PCTSTR, int=0, HWND=0, ULONG=0, PCTSTR=NULL, PCTSTR=NULL, PINT=NULL);"
        END IF

        IF Use_GetSaveAsFilename THEN
            FPRINT FP_OUTPUT, "char*   GetSaveAsFileName (PCTSTR, PCTSTR, int=0, HWND=NULL, ULONG=0, PCTSTR=NULL, PCTSTR=NULL, PINT=NULL);"
        END IF

        IF Use_GetTextSize THEN
            FPRINT FP_OUTPUT, "SIZE*   GetTextSize (PCTSTR, HWND=0, HFONT=0);"
        END IF

        IF Use_Time THEN
            FPRINT FP_OUTPUT, "char*   timef (int=0, int=0);"
        END IF

        IF Use_Join THEN
            FPRINT FP_OUTPUT, "char*   join(int, PCTSTR, ...);"
        END IF

        IF Use_Enclose THEN
            FPRINT FP_OUTPUT, "char*   enc (PCTSTR, int=0, int=0);"
        END IF

        IF Use_Stristr THEN
            FPRINT FP_OUTPUT, "char*   _stristr_(PCTSTR, PCTSTR);"
        END IF

        IF Use_IInstrAny OR Use_InstrAny THEN
            FPRINT FP_OUTPUT, "char*   DeDupeSort(const char*);"
            FPRINT FP_OUTPUT, "int     DeDupeCompare(const void*, const void*);"
        END IF

        IF Use_Wrap THEN
            FPRINT FP_OUTPUT, "char*   wrap (PCTSTR, PCTSTR=", ENC$(""), ", PCTSTR=", ENC$(""), ");"
        END IF

        IF Use_Unwrap THEN
            FPRINT FP_OUTPUT, "char*   unwrap (PCTSTR, PCTSTR=", ENC$(""), ", PCTSTR=", ENC$(""), ");"
        END IF

        IF Use_Freefile THEN
            FPRINT FP_OUTPUT, "FILE*   FreeFile (void);"
        END IF

        IF Use_PeekStr THEN
            FPRINT FP_OUTPUT, "char*   peekstr (PVOID, int);"
        END IF

        IF Use_Getaddr THEN
            FPRINT FP_OUTPUT, "char    *GetAddr (PVOID);"
        END IF

        IF Use_Setaddr THEN
            FPRINT FP_OUTPUT, "void    SetAddr (int* ,int);"
        END IF

        IF Use_Asc THEN
            FPRINT FP_OUTPUT, "int     asc (PCTSTR, int=0);"
        END IF

        IF Use_Instrrev THEN
            FPRINT FP_OUTPUT, "int     InstrRev (PCTSTR, PCTSTR, int=0, int=0);"
        END IF

        IF Use_FirstInstance THEN
            FPRINT FP_OUTPUT, "BOOL    FindFirstInstance (PCTSTR);"
        END IF

        IF Use_BCX_stricmp THEN
            FPRINT FP_OUTPUT, "int     bcx_stricmp (PCTSTR cs, PCTSTR ct);"
        END IF

        IF Use_Instr THEN
            FPRINT FP_OUTPUT, "int     instr (PCTSTR, PCTSTR, int=1, int=0);"
        END IF

        IF Use_IInstr THEN
            FPRINT FP_OUTPUT, "int     iinstr (PCTSTR, PCTSTR, int=1);"
        END IF

        IF Use_InstrAny THEN
            FPRINT FP_OUTPUT, "int     InstrAny (PCTSTR, PCTSTR, int=1);"
        END IF

        IF Use_IInstrAny THEN
            FPRINT FP_OUTPUT, "int     IInstrAny (PCTSTR, PCTSTR, int=1);"
        END IF

        IF Use_Like_Instr THEN
            FPRINT FP_OUTPUT, "int     Like_Instr (PCTSTR Buffer, PCTSTR Pattern);"
        END IF

        IF Use_Verify THEN
            FPRINT FP_OUTPUT, "int     Verify (PCTSTR, PCTSTR);"
            FPRINT FP_OUTPUT, "int     VerifyInstr (PCTSTR, PCTSTR, int=0);"
        END IF

        IF Use_Retain THEN
            FPRINT FP_OUTPUT, "char*   Retain (PCTSTR, PCTSTR);"
        END IF

        IF Use_LoadFile THEN
            FPRINT FP_OUTPUT, "char*   LoadFile (PCTSTR);"
        END IF

        IF Use_Inchr THEN
            FPRINT FP_OUTPUT, "int     inchr (PCTSTR, PCTSTR);"
        END IF

        IF Use_Idxqsort THEN
            FPRINT FP_OUTPUT, "int     IdxCompare (const void *, const void *);"
        END IF

        IF Use_IdxqsortSt THEN
            FPRINT FP_OUTPUT, "int     IdxCompareSt (const void *, const void *);"
        END IF

        IF Use_PtrqsortSt THEN
            FPRINT FP_OUTPUT, "int     PtrCompareSt (const void *, const void *);"
        END IF

        IF Use_Strqsortas THEN
            FPRINT FP_OUTPUT, "int     StrCompareAs (const void *, const void *);"
        END IF

        IF Use_Strqsorta THEN
            FPRINT FP_OUTPUT, "int     StrCompareA (const void *, const void *);"
        END IF

        IF Use_Strqsortds THEN
            FPRINT FP_OUTPUT, "int     StrCompareDs (const void *, const void *);"
        END IF

        IF Use_Strqsortd THEN
            FPRINT FP_OUTPUT, "int     StrCompareD (const void *, const void *);"
        END IF

        IF Use_DynStrqsortas THEN
            FPRINT FP_OUTPUT, "int     DynStrCompareAs (const void *, const void *);"
        END IF

        IF Use_DynStrqsorta THEN
            FPRINT FP_OUTPUT, "int     DynStrCompareA (const void *, const void *);"
        END IF

        IF Use_DynStrqsortds THEN
            FPRINT FP_OUTPUT, "int     DynStrCompareDs (const void *, const void *);"
        END IF

        IF Use_DynStrqsortd THEN
            FPRINT FP_OUTPUT, "int     DynStrCompareD (const void *, const void *);"
        END IF

        IF Use_DynAlphaNumericA THEN
            FPRINT FP_OUTPUT, "int     DynAlphaNumericA (const void *, const void *);"
        END IF

        IF Use_DynAlphaNumericD THEN
            FPRINT FP_OUTPUT, "int     DynAlphaNumericD (const void *, const void *);"
        END IF

        IF Use_AlphaNumericA THEN
            FPRINT FP_OUTPUT, "int     AlphaNumericA (const void *, const void *);"
        END IF

        IF Use_AlphaNumericD THEN
            FPRINT FP_OUTPUT, "int     AlphaNumericD (const void *, const void *);"
        END IF

        IF Use_AlphaNumeric THEN
            FPRINT FP_OUTPUT, "int     AlphaNumeric (const void *, const void *);"
        END IF

        IF Use_Numqsortaint THEN
            FPRINT FP_OUTPUT, "int     NumCompareAint (const void *,const void *);"
        END IF

        IF Use_Numqsortdint THEN
            FPRINT FP_OUTPUT, "int     NumCompareDint (const void *,const void *);"
        END IF

        IF Use_Numqsortafloat THEN
            FPRINT FP_OUTPUT, "int     NumCompareAfloat (const void *,const void *);"
        END IF

        IF Use_Numqsortdfloat THEN
            FPRINT FP_OUTPUT, "int     NumCompareDfloat (const void *,const void *);"
        END IF

        IF Use_Numqsortadouble THEN
            FPRINT FP_OUTPUT, "int     NumCompareAdouble (const void *,const void *);"
        END IF

        IF Use_Numqsortddouble THEN
            FPRINT FP_OUTPUT, "int     NumCompareDdouble (const void *,const void *);"
        END IF

        IF Use_Msgbox THEN
            FPRINT FP_OUTPUT, "int     MsgBox (PCTSTR,PCTSTR,int);"
        END IF

        IF Use_Like THEN
            FPRINT FP_OUTPUT, "int     like (PCTSTR, PCTSTR);"
        END IF

        IF Use_LeftStr THEN
            FPRINT FP_OUTPUT, "int     LeftStr  (PCTSTR, PCTSTR, int=0);"
        END IF

        IF Use_RightStr THEN
            FPRINT FP_OUTPUT, "int     RightStr (PCTSTR, PCTSTR, int=0);"
        END IF

        IF Use_Textmode THEN
            FPRINT FP_OUTPUT, "int     TextMode (int);"
        END IF

        IF Use_Tally THEN
            FPRINT FP_OUTPUT, "int     tally (PCTSTR, PCTSTR, int=0);"
        END IF

        IF Use_Diskfree THEN
            FPRINT FP_OUTPUT, "UINT64  DiskFree (PCTSTR);"
        END IF

        IF Use_Diskused THEN
            FPRINT FP_OUTPUT, "UINT64  DiskUsed (PCTSTR);"
        END IF

        IF Use_Disksize THEN
            FPRINT FP_OUTPUT, "UINT64  DiskSize (PCTSTR);"
        END IF

        IF Use_Hex2Dec THEN
            FPRINT FP_OUTPUT, "UINT64  Hex2Dec (PCTSTR);"
        END IF

        IF Use_Inkey THEN
            FPRINT FP_OUTPUT, "char*   inkey (void);"
        END IF

        IF Use_InkeyD THEN
            FPRINT FP_OUTPUT, "int     inkeyd (void);"
        END IF

        IF Use_Bin2dec THEN
            FPRINT FP_OUTPUT, "int     Bin2Dec (PCTSTR);"
        END IF

        IF Use_Download THEN
            FPRINT FP_OUTPUT, "int     Download (PCTSTR, PCTSTR);"
        END IF

        IF Use_Exist THEN
            FPRINT FP_OUTPUT, "BOOL    Exist   (PCTSTR);"
            FPRINT FP_OUTPUT, "BOOL    Exist_A (PCTSTR);"
            FPRINT FP_OUTPUT, "BOOL    Exist_B (PCTSTR);"
        END IF

        IF Use_Gethttpfilesize THEN
            FPRINT FP_OUTPUT, "ULONG   GetHttpFileSize (PCTSTR);"
        END IF

        IF Use_Downloadtostr THEN
            FPRINT FP_OUTPUT, "char*   DownloadToStr (PCTSTR);"
        END IF

        IF Use_Ins THEN
            FPRINT FP_OUTPUT, "char*   ins (PCTSTR, int, PCTSTR);"
        END IF

        IF Use_Del THEN
            FPRINT FP_OUTPUT, "char*   del (PCTSTR, int, int);"
        END IF

        IF Use_Chrtoutf8 THEN
            FPRINT FP_OUTPUT, "char *ChrToUtf8 (PCSTR);"
        END IF

        IF Use_Utf8tochr THEN
            FPRINT FP_OUTPUT, "char *UTF8toCHR (PCSTR);"
        END IF


        IF Use_Screen THEN
            FPRINT FP_OUTPUT, "int     Screen (int, int, int=0);"
        END IF

        IF Use_Pause THEN
            FPRINT FP_OUTPUT, "void    Pause (void);"
        END IF

        IF Use_Clip_Gettext THEN
            FPRINT FP_OUTPUT, "char*   Clipboard_GetText (void);"
        END IF

        IF Use_Clip_Gettextsize THEN
            FPRINT FP_OUTPUT, "int     Clipboard_GetTextSize (void);"
        END IF

        IF  Use_Clip_Settext THEN
            FPRINT FP_OUTPUT, "void    Clipboard_SetText (PCTSTR);"
        END IF

        IF Use_Clip_Getbitmap THEN
            FPRINT FP_OUTPUT, "HBITMAP Clipboard_GetBitmap (void);"
        END IF

        IF  Use_Clip_Setbitmap THEN
            FPRINT FP_OUTPUT, "void    Clipboard_SetBitmap (HBITMAP);"
        END IF

        IF Use_Keypress THEN
            FPRINT FP_OUTPUT, "int     keypress (void);"
        END IF

        IF Use_Iif THEN
            FPRINT FP_OUTPUT, "double  iif (int, double, double);"
        END IF

        IF Use_Lof THEN
            FPRINT FP_OUTPUT, "unsigned long long int  lof (PCTSTR);"
        END IF

        IF Use_Sgn THEN
            FPRINT FP_OUTPUT, "double  sgn (double);"
        END IF

        IF Use_Round THEN
            FPRINT FP_OUTPUT, "double  Round (double, int);"
        END IF

        IF Use_Rnd THEN
            FPRINT FP_OUTPUT, "float   rnd (void);"
        END IF

        IF Use_Rnd2 THEN
            FPRINT FP_OUTPUT, "double  rnd2 (double, double);"
        END IF

        IF Use_Exp THEN
            FPRINT FP_OUTPUT, "double  Exp (double);"
        END IF

        IF Use_Max THEN
            FPRINT FP_OUTPUT, "double  MAX (double, double);"
        END IF

        IF Use_Min THEN
            FPRINT FP_OUTPUT, "double  MIN (double, double);"
        END IF

        IF Use_Modstyle THEN
            FPRINT FP_OUTPUT, "BOOL    ModStyle (HWND, LONG_PTR=0, LONG_PTR=0, BOOL=0);"
        END IF

        IF Use_Timer THEN
            FPRINT FP_OUTPUT, "float   timer (void);"
        END IF

        IF Use_Loc THEN
            FPRINT FP_OUTPUT, "int     loc (FILE *fp, int fplen);"
        END IF

        IF Use_Rec THEN
            FPRINT FP_OUTPUT, "int     rec (FILE *fp, int fplen);"
        END IF

        IF Use_RecCount THEN
            FPRINT FP_OUTPUT, "int     reccount (FILE *fp, int fplen);"
        END IF

        IF Use_Scan THEN
            FPRINT FP_OUTPUT, "int     scan (PCTSTR input, PCTSTR format, ...);"
        END IF

        IF Use_KBinput THEN
            FPRINT FP_OUTPUT, "void    KBinput (void);"
        END IF

        IF Use_Split THEN
            FPRINT FP_OUTPUT, "int     Split (char[][BCXSTRSIZE], PCTSTR, PCTSTR, int=0);"
        END IF

        IF Use_DSplit THEN
            FPRINT FP_OUTPUT, "int     DSplit (PSTR *, PCTSTR, PCTSTR, int=0);"
        END IF

        IF Use_SysStr THEN
            FPRINT FP_OUTPUT, "BSTR    SysStr (PCTSTR szIn, int=0, int=0);"
        END IF

        IF Use_LCaseTbl THEN
            FPRINT FP_OUTPUT, "unsigned char*  MakeLCaseTbl (void);"
        END IF

        IF Use_UCaseTbl THEN
            FPRINT FP_OUTPUT, "unsigned char*  MakeUCaseTbl (void);"
        END IF

        IF Use_Cvi THEN
            FPRINT FP_OUTPUT, "short   CVI (PCTSTR);"
        END IF

        IF Use_Mki THEN
            FPRINT FP_OUTPUT, "char*   MKI (short);"
        END IF

        IF Use_Cvl THEN
            FPRINT FP_OUTPUT, "long    CVL (PCTSTR);"
        END IF

        IF Use_Mkl THEN
            FPRINT FP_OUTPUT, "char*   MKL (int);"
        END IF

        IF Use_Cvs THEN
            FPRINT FP_OUTPUT, "float   CVS (PCTSTR);"
        END IF

        IF Use_Mks THEN
            FPRINT FP_OUTPUT, "char*   MKS (float);"
        END IF

        IF Use_Cvd THEN
            FPRINT FP_OUTPUT, "double  CVD (PCTSTR);"
        END IF

        IF Use_Cvld THEN
            FPRINT FP_OUTPUT, "long double  CVLD (PCTSTR);"
        END IF

        IF Use_Mkd THEN
            FPRINT FP_OUTPUT, "char*   MKD (double);"
        END IF

        IF Use_Mkld THEN
            FPRINT FP_OUTPUT, "char*   MKLD (long double);"
        END IF

        IF Use_OSVersion THEN
            FPRINT FP_OUTPUT, "int     OSVersion (void);"
        END IF

        IF Use_Sound THEN
            FPRINT FP_OUTPUT, "int     Sound (float, int=0, int=127, int=0, float=1.0f);"
            FPRINT FP_OUTPUT, "int     PlaySnd (void);"
        END IF

        IF Use_Hscroll OR Use_Vscroll THEN
            FPRINT FP_OUTPUT, "void    BCX_Scroll (HWND, int, int, int, int, int, int, int, int, int, int);"
        END IF

        IF Use_DynacallCommon THEN
            FPRINT FP_OUTPUT, "HINSTANCE BCX_LoadDll (PCTSTR);"
            FPRINT FP_OUTPUT, "void      BCX_UnloadDll (void);"
            IF Use_Dynacall THEN
                FPRINT FP_OUTPUT, "INT_PTR   BCX_DynaCallB (PCTSTR, PCTSTR, int, ...);"
            END IF
            IF Use_DynacallA THEN
                FPRINT FP_OUTPUT, "INT_PTR   BCX_DynaCallA(PCTSTR, PCTSTR, int, INT_PTR *);"
            END IF
        END IF

        IF Use_DynamicA THEN
            FPRINT FP_OUTPUT, "void*   CreateArr (void*, int, int, int, size_t *);"
            FPRINT FP_OUTPUT, "void    DestroyArr (void**, int, int);"
        END IF

        IF Use_ContainedIn THEN
            FPRINT FP_OUTPUT, "int     containedin (char*, char **, int=0);"
        END IF

        IF Use_FindInType THEN
            FPRINT FP_OUTPUT, "int     FindInType (PCTSTR, PCTSTR, int, int, int, int=0, PINT=NULL);"
        END IF

        IF Use_Printer THEN
            FPRINT FP_OUTPUT, "int     PrinterOpen  (PCTSTR =" , ENC$("Courier New") , ", int=12, int=DEFAULT_CHARSET);"
            FPRINT FP_OUTPUT, "void    PrinterWrite (PCTSTR, int=80, int=60);"
            FPRINT FP_OUTPUT, "void    EjectPage    (void);"
            FPRINT FP_OUTPUT, "void    PrinterClose (void);"
        END IF


        '*********************************************************************
        '                 BCX Runtime Code Library Starts Here
        '              Late binding COM support Runtime Functions
        '*********************************************************************

        IF Use_COM THEN
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "// *************************************************"
            FPRINT FP_OUTPUT, "//          Late binding COM support section"
            FPRINT FP_OUTPUT, "//  (c) Ljubisa Knezevic 2004-2009, ljube@blic.net"
            FPRINT FP_OUTPUT, "// *************************************************"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "#define COM_MSGBOX(a,b,c)MessageBox(GetActiveWindow(),(a),(b),(c))"
            FPRINT FP_OUTPUT, "#define COM_PROPS DISPATCH_PROPERTYGET|DISPATCH_METHOD"
            FPRINT FP_OUTPUT, "#define COM_PARAMS COM_param_list.pParams"
            FPRINT FP_OUTPUT, SPC$
        END IF

        IF Use_WideToAnsi THEN
            FPRINT FP_OUTPUT, "//<---UNICODE AWARE"
            FPRINT FP_OUTPUT, "char*   WideToAnsi (PWSTR, UINT=CP_ACP, ULONG=0);"  ' 827 MrBcx changed from BSTR
            FPRINT FP_OUTPUT, "//>---UNICODE AWARE"
            FPRINT FP_OUTPUT, SPC$
        END IF

        IF Use_AnsiToWide THEN
            FPRINT FP_OUTPUT, "//<---UNICODE AWARE"
            FPRINT FP_OUTPUT, "PWSTR AnsiToWide (PCSTR, UINT=CP_ACP, ULONG=MB_PRECOMPOSED, BOOL=TRUE);"
            FPRINT FP_OUTPUT, "//>---UNICODE AWARE"
            FPRINT FP_OUTPUT, SPC$
        END IF

        IF Use_SafeArrays THEN
            FPRINT FP_OUTPUT, "HRESULT InitSafeArray    (SAFEARRAY** ppsa, VARTYPE vtype, UINT ndim, ...);"
            FPRINT FP_OUTPUT, "HRESULT DestroySafeArray (SAFEARRAY* psA);"
            FPRINT FP_OUTPUT, SPC$
        END IF

        IF Use_COM_UsesConversion THEN
            FPRINT FP_OUTPUT, "HRESULT  COM_AS2WS (PCSTR  ansi_string, UINT code_page=CP_ACP);"
            FPRINT FP_OUTPUT, "HRESULT  COM_WS2AS (PCWSTR wide_string, UINT code_page=CP_ACP);"
            FPRINT FP_OUTPUT, SPC$
        END IF

        IF Use_COM_CLSID THEN
            FPRINT FP_OUTPUT, "char*    BCX_CLSID(char*);"
        END IF

        IF Use_COM THEN
            FPRINT FP_OUTPUT, "#define c_COM_Stack_Size ", c_COM_Stack_Size
            FPRINT FP_OUTPUT, "#ifndef CON_VARBOOL2BOOL"
            FPRINT FP_OUTPUT, "  #define CON_VARBOOL2BOOL(b) ((BOOL)(b ? TRUE : FALSE))"
            FPRINT FP_OUTPUT, "#endif"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "typedef struct _OBJECT {"
            FPRINT FP_OUTPUT, "  IUnknown*  p_unknown;"
            FPRINT FP_OUTPUT, "  VARIANT    pObjects[c_COM_Stack_Size];"
            FPRINT FP_OUTPUT, "  BOOL       pStatus;"
            FPRINT FP_OUTPUT, "  int        ipointer;"
            FPRINT FP_OUTPUT, "}OBJECT, *LPOBJECT;"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "typedef struct _PARAM_VARARRAY {"
            FPRINT FP_OUTPUT, "  VARIANT  pParams[c_COM_Stack_Size];"
            FPRINT FP_OUTPUT, "}PARAM_VARARRAY, *LPPARAM_VARARRAY;"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "// *************************************************"
            FPRINT FP_OUTPUT, "//       COM functions used internally by BCX"
            FPRINT FP_OUTPUT, "// *************************************************"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "void     COM_ole_initialize            (void);"
            FPRINT FP_OUTPUT, "void     COM_ole_uninitialize          (void);"
            FPRINT FP_OUTPUT, "void     COM_HR_ErrMsg                 (HRESULT hr, TCHAR *extra_info);"
            FPRINT FP_OUTPUT, "DISPID   COM_get_dispatch_ID           (IDispatch *lpDispatch, PWSTR comsegment);"
            FPRINT FP_OUTPUT, "void     COM_get_next_dispatch         (OBJECT *object, PWSTR comsegment);"
            FPRINT FP_OUTPUT, "void     COM_invoke                    (OBJECT *object, PWSTR comsegment, WORD wFlags, VARIANT *pvResult);"
            FPRINT FP_OUTPUT, "void     COM_build_except_info         (HRESULT hr, EXCEPINFO *pexcep = NULL, UINT uiArgErr = 0);"
            FPRINT FP_OUTPUT, "void     COM_clean_plist               (void);"
            FPRINT FP_OUTPUT, "void     COM_reset_disp_chain          (OBJECT *object);"
            FPRINT FP_OUTPUT, "void     COM_create_safearray          (void);"

            IF COM_build_trace_code    THEN
                FPRINT FP_OUTPUT, "static char COM_trace_line[BCXSTRSIZE];"
            END IF

            FPRINT FP_OUTPUT, "void     COM_trace_dump_DISPPARAMS     (DISPPARAMS* dp);"
            FPRINT FP_OUTPUT, "void     COM_trace_add_line            (PCTSTR dp);"
            FPRINT FP_OUTPUT, "void     COM_trace_dump_indicators     (OBJECT *object);"
            FPRINT FP_OUTPUT, "void     COM_trace_dump_flags          (WORD wFlags);"
            FPRINT FP_OUTPUT, "void     COM_FREE_TEMP_ANSI_STRING     (void);"
            FPRINT FP_OUTPUT, "void     COM_FREE_TEMP_WIDE_STRING     (void);"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "// *************************************************"
            FPRINT FP_OUTPUT, "//       Public COM support functions"
            FPRINT FP_OUTPUT, "// *************************************************"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "OBJECT   COM                    (PCTSTR);"
            FPRINT FP_OUTPUT, "void     UNCOM                  (OBJECT);"
            FPRINT FP_OUTPUT, "void     BCX_SHOW_COM_ERRORS    (BOOL);"
            FPRINT FP_OUTPUT, "void     BCX_SetNothing         (OBJECT*);"
            FPRINT FP_OUTPUT, "BOOL     BCX_GET_COM_SUCCESS    (void);"
            FPRINT FP_OUTPUT, "BOOL     BCX_GET_COM_STATUS     (OBJECT*);"
            FPRINT FP_OUTPUT, "char*    BCX_GET_COM_ERROR_DESC (void);"
            FPRINT FP_OUTPUT, "int      ISOBJECT               (OBJECT);"
            FPRINT FP_OUTPUT, "HRESULT  BCX_GET_COM_ERROR_CODE (void);"

            IF Use_COM_CreateObject THEN
                FPRINT FP_OUTPUT, "void     BCX_CreateObject       (TCHAR *objname, OBJECT *obj);"
            END IF

            IF Use_COM_GetObject THEN
                FPRINT FP_OUTPUT, "void     BCX_GetObject          (TCHAR *objname, OBJECT *obj);"
                FPRINT FP_OUTPUT, "void     BCX_GetObjectMon       (LPCOLESTR objname, OBJECT *obj);"
            END IF

            IF Use_COM_DispatchObject THEN
                FPRINT FP_OUTPUT, "void     BCX_DispatchObject     (IUnknown *iobj, OBJECT *obj, BOOL b_release = TRUE);"
            END IF

        END IF
    END IF ' IF Use_Project = FALSE
END SUB ' StdProtos




SUB Add_Com_Global_Var (p_name$)
    '************************************************************************************************************
    ' Sub: Add_Com_Global_Var (part of BCX COM parser)
    ' This sub adds OBJECT variable to global space, which is cleaned on program end.
    ' If the Global nnn an Object or Dim nnn as Object is called otside Functions ans Subs,
    ' than nnn will be added to global COM names space. This is used so that object variables could be identifed.
    '************************************************************************************************************
    IF LEN(p_name$) > 64 THEN Abort("Length of object variable " + p_name$ + " is:" + STR$(LEN(p_name$)) + ". Maximum allowed is 64 characters.")
    IF COM_gl_names_index = c_COM_Max_Gl_Objs THEN
        Abort("Max number of Global COM object variables reached:" + STR$(c_COM_Max_Gl_Objs) + CRLF$ + "Failed to reserve space for Object variable: " + p_name$)
        EXIT SUB
    END IF
    strcpy(COM_gl_names[COM_gl_names_free_index].com_VarName, p_name)
    COM_gl_names[COM_gl_names_free_index].initialized = TRUE
    INCR COM_gl_names_index
    COM_gl_names_free_index = COM_gl_names_index
END SUB ' Add_Com_Global_Var




SUB Add_Com_Local_Var (p_name$)
    '************************************************************************************************************
    ' Sub: Add_Com_Local_Var (part of BCX COM parser)
    ' This sub adds OBJECT variable to local space, which is cleaned on exit or return from function/sub
    ' If the Dim nnn as Object is called inside Functions ans Subs, than nnn will be added to local
    ' COM object space. This is used so that object variables could be identifed.
    '************************************************************************************************************
    IF LEN(p_name$) > 64 THEN Abort("Length of object variable " + p_name$ + " is:" + STR$(LEN(p_name$)) + ". Maximum allowed is 64 characters.")
    IF COM_lc_names_index = c_COM_Max_Lc_Objs THEN
        Abort("Max number of Local COM object variables reached:" + STR$(c_COM_Max_Lc_Objs) + CRLF$ + "Failed to reserve space for Object variable: " + p_name$)
        EXIT SUB
    END IF
    strcpy(COM_lc_names[COM_lc_names_free_index].com_VarName, p_name)
    COM_lc_names[COM_lc_names_free_index].initialized = TRUE
    INCR COM_lc_names_index
    COM_lc_names_free_index = COM_lc_names_index
END SUB ' Add_Com_Local_Var




FUNCTION IsVariableComObject (p_varname$)
    '************************************************************************************************************
    ' Function: IsVariableComObject (part of BCX COM parser)
    ' Checks whether variable is COM initialized as COM object or not.
    ' Return Values:
    ' Function returns index (base 1) of COM object in storage.
    ' If the name is found in local storage, it will return positive index.
    ' If the name is found in global storage, it will return index with negative preffix.
    ' Zero (0) indicates that the name is not found in COM names storage.
    '************************************************************************************************************
    DIM RAW sz_var_name$
    DIM RAW l_index AS INT

    sz_var_name$ = TRIM$(p_varname$)

    IF COM_lc_names_index > 0 THEN      ' First try to find it in local COM object space
        FOR l_index = 0 TO COM_lc_names_index-1
            IF COM_lc_names[l_index].initialized = TRUE THEN
                IF sz_var_name$ = COM_lc_names[l_index].com_VarName THEN
                    FUNCTION = l_index + 1      ' If found, then return index of it
                END IF
            END IF
        NEXT
    END IF

    IF COM_gl_names_index > 0 THEN    ' Try to find it in global COM object space
        FOR l_index = 0 TO COM_gl_names_index-1
            IF COM_gl_names[l_index].initialized = TRUE THEN
                ' if it is found, then return negative index of it, indicating that it is a global variable
                IF sz_var_name$ = COM_gl_names[l_index].com_VarName THEN FUNCTION = (-1 * (l_index + 1))
            END IF
        NEXT
    END IF
    FUNCTION = 0 ' not found, so return 0
END FUNCTION   ' IsVariableComObject




SUB Free_Com_Objects (p_remove AS BOOL)
    '*********************************************************************
    ' Sub: Free_Com_Objects (part of BCX COM parser)
    ' This sub is called when user forgot to call
    ' "Set ... = Nothing" for each created COM object.
    '*********************************************************************
    LOCAL j AS INT
    LOCAL eraseOffset
    DO
        IF COM_lc_names[j].initialized = TRUE THEN
            ' FPRINT FP_WRITE, Scoot$,"if (",COM_lc_names[j].com_VarName, ".pStatus) BCX_SetNothing(&",COM_lc_names[j].com_VarName,");"
        ELSE
            ' If it comes here, than it means that at this index, object is already released.
            ' It will happen when user calls "Set ... = Nothing" for some COM objects but not for all.
            INCR eraseOffset
        END IF
        INCR j
    LOOP WHILE j < (COM_lc_names_index + eraseOffset)
    IF p_remove = TRUE THEN
        COM_lc_names_index = 0
        COM_lc_names_free_index = 0
    END IF
END SUB  ' Free_Com_Objects



FUNCTION Find_COM_statement (pp_Src$) AS BOOL
    '*********************************************************************************
    ' Function: Find_COM_statement (part of BCX COM parser)
    ' The one and only ... *** Main COM parser *** !!!
    '
    ' Return Values:
    ' Function returns TRUE indicating that COM statement is found in currently parsed
    ' BCX line, or FALSE if COM statement is NOT found in current BCX source line.
    '*********************************************************************************
    DIM FOUND_OBJECT
    DIM FOUND_DOT
    DIM FOUND_EQU
    DIM RAW p_Src$
    DIM RAW word_left$
    DIM RAW prev_word_left$
    DIM RAW j AS INT

    p_Src$ = pp_Src$
    IF ISNULL(p_Src$) THEN FUNCTION = FALSE
    IF p_Src$ = "endwith" THEN FUNCTION = FALSE
    ProcessingCOM_Set = FALSE
    IF LEFTSTR(pp_Src$, "set ", TRUE) THEN
        ProcessingCOM_Set = TRUE
        pp_Src$ = TRIM$(MID$(pp_Src$, 5))
        p_Src$ = pp_Src$
    END IF
    IF m_iMatchLft(p_Src$, "for ") THEN FUNCTION = FALSE
    ' handles with - end with constructions used in COM statements
    IF m_iMatchLft(p_Src$, "with ") THEN
        word_left$ = TRIM$(MID$(p_Src$, 6))
        IF COM_open_WITH_statement THEN
            IF word_left[0] = 46 THEN ' Found "." this means that this is a nested (WITH - END WITH)
                INCR COM_open_WITH_statement
                p_Src$ = COM_with_temp_str_name$ + " = " + COM_with_temp_str_name$ + word_left$
            ELSE
                Abort ("Nested <WITH> statements, in open WITH block, are allowed only for interfaces of same COM object. For more info, see rules for using COM in BCX.")
            END IF
        ELSE ' first with block
            prev_word_left$ = TRIM$(EXTRACT$(word_left$, "."))
            IF IsVariableComObject(prev_word_left$) THEN
                INCR COM_open_WITH_statement
                COM_with_temp_str_name$ = prev_word_left$
                p_Src$ = word_left$
                IF INCHR(p_Src$, ".") = 0 THEN
                    pp_Src$ = ""
                    FUNCTION = TRUE
                END IF
                ' fake that this is a COM get statement
                p_Src$ = prev_word_left$ + " = " + word_left$
            END IF
        END IF
    ELSE ' not found with
        IF COM_open_WITH_statement THEN                    ' but inside with block
            IF p_Src[0] = 46 THEN ' Found "."              ' found . as first character
                p_Src$ = COM_with_temp_str_name$ + p_Src$  ' pre-append object name
            END IF
        END IF
    END IF

    CALL FastLexer(p_Src$, "", "'")

    DIM i AS INT = 2

    p_Src$ = Stk$[1]

    DO WHILE i <= Ndx
        IF *Stk$[i] = ASC("'") THEN EXIT DO
        p_Src$ += Stk$[i]
        INCR i
    LOOP

    CALL FastLexer(p_Src$, "", "= ", 0)
    i = 1
    j = 0
    DO WHILE i < Ndx
        IF *Stk$[i] = 61 THEN
            j = i
        END IF
        INCR i
    LOOP
    IF j THEN
        i = 2
        p_Src$ = TRIM$(Stk$[1])
        DO WHILE i < j
            p_Src$ += TRIM$(Stk$[i])
            INCR i
        LOOP
        p_Src$ += Stk$[j]
        DO WHILE ++j <= Ndx
            p_Src$ += TRIM$(Stk$[j])
        LOOP
    END IF

    CALL FastLexer(p_Src$, "", "[]()=. ", 0)

    DIM szLeft$
    DIM szRight$
    DIM FOUND_SPACE

    FOUND_OBJECT = FALSE
    FOUND_EQU = FALSE
    FOUND_SPACE = FALSE
    FOUND_DOT = FALSE

    DIM RAW DO_COM = 0  ' Get = -1, Method = 0, Set = 1

    FOR i = 1 TO Ndx

        IF FOUND_OBJECT = FALSE THEN
            FOUND_OBJECT = IsVariableComObject(Stk$[i])
        END IF

        IF *Stk$[i] = 61 THEN
            FOUND_EQU = TRUE     ' check for =
            IF FOUND_OBJECT = FALSE THEN
                IF DO_COM = 0 THEN
                    DO_COM = (-1)
                ELSE
                    DO_COM = 1
                END IF
            ELSE
                IF FOUND_DOT = FALSE THEN
                    DO_COM = (-1)
                ELSE
                    DO_COM = 1
                END IF
            END IF
            ITERATE
        END IF

        IF FOUND_OBJECT <> FALSE AND *Stk$[i] = 46 THEN FOUND_DOT = TRUE
        IF FOUND_OBJECT AND *Stk$[i] = 32 THEN
            FOUND_SPACE = i
            ITERATE
        END IF
        IF FOUND_EQU OR FOUND_SPACE THEN
            szRight$ += Stk$[i]
            IF Stk$[i] = "(" THEN
                DIM RAW iP AS INT
                iP = 1
                DO WHILE iP
                    INCR i
                    IF Stk$[i] = "(" THEN INCR iP
                    IF Stk$[i] = ")" THEN DECR iP
                    szRight$ += TRIM$(Stk$[i])
                LOOP
            END IF
        ELSE
            IF Stk$[i] = "(" THEN
                DIM RAW iP AS INT
                szLeft$ += Stk$[i]
                iP = 1
                DO WHILE iP
                    IF i = Ndx THEN Abort("Unbalance () in COM statement")
                    INCR i
                    IF Stk$[i] = "(" THEN INCR iP
                    IF Stk$[i] = ")" THEN DECR iP
                    szLeft$ += TRIM$(Stk$[i])
                LOOP
            ELSE
                szLeft$ += Stk$[i]
            END IF
        END IF
    NEXT

    IF FOUND_OBJECT <> FALSE THEN
        IF FOUND_DOT THEN
            IF COM_build_trace_code THEN
                FPRINT FP_WRITE, "COM_add_trace_line(", ENC$("  "), ");"
                FPRINT FP_WRITE, "COM_add_trace_line(", ENC$("***********************************************************"), ");"
                FPRINT FP_WRITE, "COM_add_trace_line(", ENC$("Source Line= "+Make_COM_Trace_Lines$(pp_Src$)), ");"
            END IF

            SELECT CASE DO_COM
                CASE -1
                    COM_Parse_GetProperty(szLeft$, szRight$)

                CASE 0
                    COM_Parse_Method(szLeft$, szRight$)

                CASE 1
                    COM_Parse_SetProperty(szLeft$, szRight$, FOUND_OBJECT)

            END SELECT
            pp_Src$ = ""
            FUNCTION = TRUE
        END IF
    END IF
    CALL PreParse(pp_Src$)
    FUNCTION = FALSE
END FUNCTION ' Find_COM_statement






SUB COM_Parse_GetProperty (varname$, com_property$)
    '***************************************************************************
    ' Sub: COM_Parse_GetProperty (part of BCX COM parser)
    ' Called internally by main com parser function, Find_COM_statement.
    ' If the statment is a COM Get Property type, this function will be called.
    '
    ' Typical sample:
    ' b$ = excel.ActiveSheet.Cells(4,1).Value
    '***************************************************************************
    Use_COM_GetProperty = Use_COM_UsesConversion = Use_COM = TRUE

    LOCAL com_method$
    LOCAL j
    LOCAL k
    LOCAL ObjName$
    LOCAL ComTok$
    LOCAL ComTokPrev$
    LOCAL temp_param$
    LOCAL force_cast$
    DIM force_casting

    com_method$ = TRIM$(com_property$)

    IF com_method[0] = c_LPar THEN ' type casting
        force_cast$ = TRIM$(UCASE$(EXTRACT$(com_method+1, ")")))
        com_method$ = TRIM$(REMAIN$(com_method, ")"))
        force_casting = 1
    END IF

    CALL ParseCom(com_method$)
    j = 1
    ObjName$ = ComStk$[j++]
    ComTok$ = ComStk$[j++]

    DO
        ComTokPrev$ = ComTok$
        ComTok$ = ComStk$[j++]
        FPRINT FP_WRITE, Scoot$, "lstrcpy(COM_ErrMsg, _T(", ENC$(Make_COM_Trace_Lines$(ComTokPrev$)), "));"

        IF INCHR(ComTokPrev$, "(") > 0 THEN
            temp_param$ = TRIM$(REMAIN$(ComTokPrev$, "("))
            k = Com_Make_Param_List(MID$(temp_param$, 1, LEN(temp_param$)-1), 1)
            FPRINT FP_WRITE, Scoot$, "COM_plist_index =", k , ";"
            ComTokPrev$ = EXTRACT$(ComTokPrev$, "(")
        END IF

        IF ComTok$ <> "" THEN
            IF COM_build_trace_code  THEN
                FPRINT FP_WRITE, "    COM_add_trace_line(", ENC$(">>> Get next dispatch for:: "+ComTokPrev$), ");"
            END IF
            FPRINT FP_WRITE, Scoot$, "COM_get_next_dispatch(&", ObjName$, ", L", ENC$(REMOVE$(ComTokPrev$, SPC$)), ");"

        ELSE
            IF COM_open_WITH_statement THEN
                IF COM_build_trace_code  THEN
                    FPRINT FP_WRITE, "    COM_add_trace_line(", ENC$("WITH construction >>> Get next dispatch for:: "+ComTokPrev$), ");"
                END IF
                FPRINT FP_WRITE, Scoot$, "COM_get_next_dispatch(&", ObjName$, ", L", ENC$(REMOVE$(ComTokPrev$, SPC$)), ");"
                FPRINT FP_WRITE, Scoot$, "COM_dispatch_at_offset = ", COM_with_temp_str_name$, ".ipointer;"
                FPRINT FP_WRITE, Scoot$, "COM_dispatch_storage_index++;"
                FPRINT FP_WRITE, Scoot$, "COM_dispatch_storage[COM_dispatch_storage_index] = COM_dispatch_at_offset;"
                EXIT SUB
            END IF

            IF COM_build_trace_code  THEN
                FPRINT FP_WRITE, "    COM_add_trace_line(", ENC$(">>> COM_invoke for:: "+ComTokPrev$), ");"
            END IF

            IF COM_FOREACH_enumerator = TRUE THEN
                FPRINT FP_WRITE, Scoot$, "COM_get_next_dispatch(&", ObjName$, ", L", ENC$(REMOVE$(ComTokPrev$, SPC$)), ");"
                EXIT SUB
            ELSE
                FPRINT FP_WRITE, Scoot$, "COM_invoke(&", ObjName$, ", L", ENC$(REMOVE$(ComTokPrev$, SPC$));
                FPRINT FP_WRITE, ",COM_PROPS, &COM_vt_result);\n"
            END IF

            IF force_casting = 1 THEN
                FPRINT FP_WRITE, Scoot$, "VariantChangeType(&COM_vt_result, &COM_vt_result,0,", force_cast$ , ");"
            END IF

            IF NOT *varname THEN EXIT DO

            DIM RAW Cleanvarname$
            Cleanvarname$ = TRIM$(No_Sigil$(varname$))

            IF force_casting = 1 THEN
                IF force_cast$ = "VT_BSTR" THEN
                    FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = SysAllocString(COM_vt_result.bstrVal);"
                ELSE
                    force_cast$ = REPLACE$(force_cast$, "VT_", "V_")
                    FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = ", force_cast$, "(&COM_vt_result);"
                END IF
            ELSE
                DIM RAW VI AS UDT_VARINFO_STORAGE PTR
                DIM RAW vt, id
                DIM RAW tVI AS UDT_VARINFO_STORAGE

                IF INCHR(Cleanvarname$, ".") THEN
                    DIM RAW sTAG$
                    sTAG$ = LEFT$(Cleanvarname$, INCHR(Cleanvarname$, ".")-1)
                    vt = LookupVarType(sTAG$, ADDRESSOF(id))
                    IF vt = vt_UNKNOWN THEN
                        Abort("Unknown structure " + sTAG$ + " not previously dimensioned")
                    END IF
                    tVI.VarPntr = 0
                    tVI.VarType = 0
                    ' FPRINT FP_WRITE, "// Structure ";sTAG$;vt  ' For Debugging
                    IF vt = vt_VARIANT THEN
                        DIM i
                        sTAG$ = MID$(Cleanvarname$, INCHR(Cleanvarname$, ".")+1)
                        i = 0
                        DO WHILE VariantList[i].sNAME
                            IF VariantList[i].sNAME$ = sTAG$ THEN
                                tVI.VarType = VariantList[i].iTYPE
                                tVI.VarPntr = VariantList[i].iPTRS
                                vt = tVI.VarType
                                EXIT DO
                            END IF
                            INCR i
                        LOOP
                    END IF
                    VI = ADDRESSOF(tVI)
                ELSE
                    vt = CheckLocal(Cleanvarname$, ADDRESSOF(id))
                    IF vt = vt_UNKNOWN THEN
                        vt = CheckGlobal(Cleanvarname$, ADDRESSOF(id))
                        IF vt = vt_UNKNOWN THEN
                            Abort("Unknown variable " + varname$ + " not previously dimensioned")
                        END IF
                        VI = ADDRESSOF(GlobalVars[id])
                    ELSE
                        VI = ADDRESSOF(LocalVars[id])
                    END IF
                END IF

                SELECT CASE vt
                    CASE vt_VARIANT

                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "VariantCopy((VARIANT *)(&", Cleanvarname$, "),&COM_vt_result);"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "VariantCopy(&", Cleanvarname$, ",&COM_vt_result);"
                        END IF

                    CASE vt_DOUBLE ' double precision float variable
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_R8|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_R8|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line(", ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.pdblVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_R8)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_R8);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line(", ENC$("Return variable for "+Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.dblVal;"
                        END IF

                    CASE vt_SINGLE ' single precision float variable
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_R4|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_R4|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.pfltVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_R4)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_R4);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for "+Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.fltVal;"
                        END IF

                    CASE vt_INTEGER ' integer variable
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_INT|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_INT|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.pintVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_INT)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "  VariantChangeType(&COM_vt_result,"
                            FPRINT FP_WRITE, Scoot$, " &COM_vt_result,0, VT_INT);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.intVal;"
                        END IF

                    CASE vt_UINT
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_UI4|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_UI4|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.uintVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_INT)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "  VariantChangeType(&COM_vt_result,"
                            FPRINT FP_WRITE, Scoot$, " &COM_vt_result,0, VT_INT);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.uintVal;"
                        END IF

                    CASE vt_LONG ' integer variable
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_I4|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_I4|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.plVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_I4)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result, &COM_vt_result,0,VT_I4);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.lVal;"
                        END IF

                    CASE vt_ULONG
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_UI4|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_UI4|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.pulVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_UI4)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_UI4);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.ulVal;"
                        END IF

                    CASE vt_LLONG
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_I8|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType (&COM_vt_result,&COM_vt_result,0,VT_I8|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.pllVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_I8)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_I8);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.llVal;"
                        END IF

                    CASE vt_ULONGLONG
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_UI8|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_UI8|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.pullVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_UI8)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_UI8);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.ullVal;"
                        END IF

                    CASE vt_SHORT, vt_SSHORT
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_I2|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_I2|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.piVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_I2)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_I2);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.iVal;"
                        END IF

                    CASE vt_USHORT
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_UI2|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_UI2|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.puiVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_UI2)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_UI2);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.uiVal;"
                        END IF


                    CASE vt_BYTE
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_UI1|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_UI1|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.pbVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_UI1)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "    VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_UI1);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "  COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.bVal;"
                        END IF

                    CASE vt_BOOL
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != (VT_BOOL|VT_BYREF))"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "     VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_BOOL|VT_BYREF);"
                            IF COM_build_trace_code THEN
                                FPRINT FP_WRITE, Scoot$, "    COM_add_trace_line("; ENC$("Return variable for " + Cleanvarname$ + " was coerced"); ");"
                            END IF
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.pboolVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = CON_VARBOOL2BOOL(COM_vt_result.boolVal);"
                        END IF


                    CASE vt_STRVAR, vt_CHAR, vt_SCHAR     ' string variable
                        FPRINT FP_WRITE, Scoot$, "if(COM_vt_result.vt == VT_NULL){"
                        FPRINT FP_WRITE, Scoot$, "  *", Cleanvarname$, "=0;"
                        FPRINT FP_WRITE, Scoot$, "} else {"
                        FPRINT FP_WRITE, Scoot$, "COM_last_HR = VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_BSTR);\n"
                        FPRINT FP_WRITE, Scoot$, "if (FAILED(COM_last_HR)) {"
                        FPRINT FP_WRITE, Scoot$, "  COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("VariantChangeType (BSTR) Failed!"), "));"
                        FPRINT FP_WRITE, Scoot$, "} else {"
                        FPRINT FP_WRITE, Scoot$, "  #ifndef UNICODE"
                        FPRINT FP_WRITE, Scoot$, "  COM_last_HR = COM_WS2AS(COM_vt_result.bstrVal);"
                        FPRINT FP_WRITE, Scoot$, "  if (FAILED(COM_last_HR)) {"
                        FPRINT FP_WRITE, Scoot$, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("COM Get Property Failed! W2A failure!"), "));"
                        FPRINT FP_WRITE, Scoot$, "  } else {"
                        FPRINT FP_WRITE, Scoot$, "   strcpy(", Cleanvarname$, ", COM_psz_tmp);"
                        FPRINT FP_WRITE, Scoot$, "  }"
                        FPRINT FP_WRITE, Scoot$, "  #else"
                        FPRINT FP_WRITE, Scoot$, "  lstrcpy(", Cleanvarname$, ",COM_vt_result.bstrVal);"
                        FPRINT FP_WRITE, Scoot$, "  #endif"
                        FPRINT FP_WRITE, Scoot$, "}"
                        FPRINT FP_WRITE, Scoot$, "}"

                    CASE vt_UDT
                        IF ProcessingCOM_Set AND IsVariableComObject(Cleanvarname$) THEN
                            ProcessingCOM_Set = FALSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_DISPATCH) {"
                            FPRINT FP_WRITE, Scoot$, "    COM_last_HR = VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_DISPATCH);"
                            FPRINT FP_WRITE, Scoot$, "}\n"
                            FPRINT FP_WRITE, Scoot$, "if (FAILED(COM_last_HR)) {"
                            FPRINT FP_WRITE, Scoot$, "  strcpy(COM_ErrMsg ,", ENC$(Cleanvarname$), ");"
                            FPRINT FP_WRITE, Scoot$, "  COM_HR_ErrMsg (COM_last_HR, _T(", ENC$("VariantChangeType failed. Expected IDispatch*"), "));"
                            FPRINT FP_WRITE, Scoot$, "} else {"
                            FPRINT FP_WRITE, Scoot$, "  VariantInit(&", Cleanvarname$, ".pObjects[0]);"
                            FPRINT FP_WRITE, Scoot$, "  COM_last_HR = VariantCopy(&", Cleanvarname$, ".pObjects[0],&COM_vt_result);\n"
                            FPRINT FP_WRITE, Scoot$, "  if (FAILED(COM_last_HR)) {"
                            FPRINT FP_WRITE, Scoot$, "    strcpy(COM_ErrMsg ,", ENC$(Cleanvarname$), ");"
                            FPRINT FP_WRITE, Scoot$, "    COM_HR_ErrMsg (COM_last_HR, _T(", ENC$("VariantCopy failed."), "));"
                            FPRINT FP_WRITE, Scoot$, "  } else {"
                            FPRINT FP_WRITE, Scoot$, "    COM_objects_cnt++;"
                            FPRINT FP_WRITE, Scoot$, "    ", Cleanvarname$, ".pStatus = TRUE;"
                            FPRINT FP_WRITE, Scoot$, "    ", Cleanvarname$, ".ipointer = 0;"
                            FPRINT FP_WRITE, Scoot$, "  }  "
                            FPRINT FP_WRITE, Scoot$, "} "
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt == VT_BOOL) {" ' convert from VARIANT_BOOL to BOOL
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = CON_VARBOOL2BOOL(COM_vt_result.boolVal);"
                            FPRINT FP_WRITE, Scoot$, "} else {"
                            FPRINT FP_WRITE, Scoot$, "switch (COM_vt_result.vt)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "  case VT_R8:"
                            FPRINT FP_WRITE, Scoot$, "      "; Cleanvarname$, " = COM_vt_result.dblVal;"
                            FPRINT FP_WRITE, Scoot$, "    break;"
                            FPRINT FP_WRITE, Scoot$, "  case VT_R4:"
                            FPRINT FP_WRITE, Scoot$, "      "; Cleanvarname$, " = COM_vt_result.fltVal;"
                            FPRINT FP_WRITE, Scoot$, "    break;"
                            FPRINT FP_WRITE, Scoot$, "  default:"
                            FPRINT FP_WRITE, Scoot$, "      "; Cleanvarname$, " = (int)COM_vt_result.lVal;"
                            FPRINT FP_WRITE, Scoot$, "    break;"
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, "}"
                        END IF

                    CASE vt_BSTR
                        IF VI->VarPntr THEN
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.pbstrVal;"
                        ELSE
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = COM_vt_result.bstrVal;"
                        END IF

                    CASE ELSE
                        IF ProcessingCOM_Set AND IsVariableComObject(Cleanvarname$) THEN
                            ProcessingCOM_Set = FALSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt != VT_DISPATCH) {"
                            FPRINT FP_WRITE, Scoot$, "    COM_last_HR = VariantChangeType(&COM_vt_result,&COM_vt_result,0,VT_DISPATCH);"
                            FPRINT FP_WRITE, Scoot$, "}\n"
                            FPRINT FP_WRITE, Scoot$, "if (FAILED(COM_last_HR)) {"
                            FPRINT FP_WRITE, Scoot$, "  strcpy(COM_ErrMsg ,", ENC$(Cleanvarname$), ");"
                            FPRINT FP_WRITE, Scoot$, "  COM_HR_ErrMsg (COM_last_HR, _T(", ENC$("VariantChangeType failed. Expected IDispatch*"), "));"
                            FPRINT FP_WRITE, Scoot$, "} else {"
                            FPRINT FP_WRITE, Scoot$, "  VariantInit(&", Cleanvarname$, ".pObjects[0]);"
                            FPRINT FP_WRITE, Scoot$, "  COM_last_HR = VariantCopy(&", Cleanvarname$, ".pObjects[0], &COM_vt_result);\n"
                            FPRINT FP_WRITE, Scoot$, "  if (FAILED(COM_last_HR)) {"
                            FPRINT FP_WRITE, Scoot$, "    strcpy(COM_ErrMsg ,", ENC$(Cleanvarname$), ");"
                            FPRINT FP_WRITE, Scoot$, "    COM_HR_ErrMsg (COM_last_HR, _T(", ENC$("VariantCopy failed."), "));"
                            FPRINT FP_WRITE, Scoot$, "  } else {"
                            FPRINT FP_WRITE, Scoot$, "    bcx_ole_objects_count++;"
                            FPRINT FP_WRITE, Scoot$, "    ", Cleanvarname$, ".pStatus = TRUE;"
                            FPRINT FP_WRITE, Scoot$, "    ", Cleanvarname$, ".ipointer = 0;"
                            FPRINT FP_WRITE, Scoot$, "  }  "
                            FPRINT FP_WRITE, Scoot$, "} "
                        ELSE
                            FPRINT FP_WRITE, Scoot$, "if (COM_vt_result.vt == VT_BOOL) {"
                            FPRINT FP_WRITE, Scoot$, Cleanvarname$, " = CON_VARBOOL2BOOL(COM_vt_result.boolVal);"
                            FPRINT FP_WRITE, Scoot$, "} else {"
                            FPRINT FP_WRITE, Scoot$, "switch (COM_vt_result.vt)"
                            FPRINT FP_WRITE, Scoot$, "  {"
                            FPRINT FP_WRITE, Scoot$, "  case VT_R8:"
                            FPRINT FP_WRITE, Scoot$, "      ", Cleanvarname$, " = COM_vt_result.dblVal;"
                            FPRINT FP_WRITE, Scoot$, "    break;"
                            FPRINT FP_WRITE, Scoot$, "  case VT_R4:"
                            FPRINT FP_WRITE, Scoot$, "      ", Cleanvarname$, " = COM_vt_result.fltVal;"
                            FPRINT FP_WRITE, Scoot$, "    break;"
                            FPRINT FP_WRITE, Scoot$, "  default:"
                            FPRINT FP_WRITE, Scoot$, "      ", Cleanvarname$, " = (int)COM_vt_result.lVal;"
                            FPRINT FP_WRITE, Scoot$, "    break;"
                            FPRINT FP_WRITE, Scoot$, "  }"
                            FPRINT FP_WRITE, Scoot$, "}"
                        END IF
                END SELECT
            END IF
            FPRINT FP_WRITE, Scoot$, "VariantClear(&COM_vt_result);"
            EXIT DO
        END IF
    LOOP
    FPRINT FP_WRITE, Scoot$, "if (0 == COM_reset_chain) COM_reset_disp_chain(&", ObjName$, ");"
END SUB ' COM_Parse_GetProperty




SUB COM_Parse_SetProperty (com_method$, pparms$, Obj_At_Index%)
    '************************************************************************************************************
    ' Sub: COM_Parse_SetProperty (part of BCX COM parser)
    ' Called internaly by main com parser function, Find_COM_statement.
    ' If the statment is a COM Set Property type, this function will be called.
    '
    ' Typical sample:
    ' (Property set)      -- app.language = "VBScript"
    ' (Property set)      -- app.visible = true
    '************************************************************************************************************
    Use_COM_SetProperty = Use_COM_UsesConversion = Use_COM = TRUE
    LOCAL j
    LOCAL k
    LOCAL ObjName$
    LOCAL ComTok$
    LOCAL ComTokPrev$
    LOCAL temp_param$
    LOCAL parms$
    LOCAL BuildSafeArray

    IF COM_build_trace_code  THEN
        FPRINT FP_WRITE, "    COM_add_trace_line(", ENC$("COM_Parse_SetProperty(" + Make_COM_Trace_Lines$(com_method$) + " , " + Make_COM_Trace_Lines$(pparms$) + " , " + STR$(Obj_At_Index%) + ")"), ");"
    END IF

    parms$ = TRIM$(pparms$)
    IF NOTNULL(parms$) THEN
        IF MID$(UCASE$(parms$), 1, 6) = "ARRAY(" OR MID$(UCASE$(parms$), 1, 6) = "ARRAY " THEN
            parms$ = REMAIN$(parms$, "(")
            j = LEN(parms$) -1
            parms[j] = 0 ' strip closing brace )
            BuildSafeArray = 1
            Use_COM_SafeArray = TRUE
        END IF
    END IF

    CALL ParseCom(com_method$)
    j = 1
    ObjName$ = ComStk$[j++]
    ComTok$ = ComStk$[j++]

    DO
        ComTokPrev$ = ComTok$
        ComTok$ = ComStk$[j++]
        FPRINT FP_WRITE, Scoot$, "lstrcpy(COM_ErrMsg, _T(", ENC$(Make_COM_Trace_Lines$(ComTokPrev$)), "));"
        IF ComTok$ <> "" THEN
            IF INCHR(ComTokPrev$, "(") > 0 THEN
                temp_param$ = TRIM$(REMAIN$(ComTokPrev$, "("))
                k = Com_Make_Param_List(MID$(temp_param$, 1, LEN(temp_param$)-1), 1)
                FPRINT FP_WRITE, Scoot$, "COM_plist_index =", k, ";"
                ComTokPrev$ = TRIM$(EXTRACT$(ComTokPrev$, "("))
            END IF

            IF COM_build_trace_code  THEN
                FPRINT FP_WRITE, "    COM_add_trace_line(", ENC$(">>> Get next dispatch for:: "+ComTokPrev$), ");"
            END IF
            FPRINT FP_WRITE, Scoot$, "COM_get_next_dispatch(&", ObjName$, ", L", ENC$(REMOVE$(ComTokPrev$, SPC$)), ");"
        ELSE
            IF COM_build_trace_code  THEN
                FPRINT FP_WRITE, "COM_add_trace_line(", ENC$("Invoke helper for:: "+ComTokPrev$), ");"
            END IF

            k = Com_Make_Param_List(parms$, 0)
            FPRINT FP_WRITE, Scoot$, "COM_plist_index =", k, ";"

            IF BuildSafeArray THEN
                FPRINT FP_WRITE, Scoot$, "COM_create_safearray();"
            END IF

            DIM RAW sXX$
            sXX$ = "\" + CHR$(c_DblQt)
            REPLACE CHR$(c_DblQt) WITH sXX$ IN ComTokPrev$
            FPRINT FP_WRITE, ""
            FPRINT FP_WRITE, Scoot$, "if (!COM_BCX_ERROR)"
            FPRINT FP_WRITE, Scoot$, "  COM_invoke(&", ObjName$, ", L", ENC$(REMOVE$(ComTokPrev$, SPC$)), ", DISPATCH_PROPERTYPUT, NULL);\n"
            EXIT DO
        END IF
    LOOP
END SUB ' COM_Parse_SetProperty



FUNCTION GetParameterTokens (sP$)
    '*******************************************************************
    ' Function to break up parameter string into parameter token blocks
    ' Note: Limited support for functions and array values as parameters
    ' 2009-01-26 - Wayne Halsdorf
    '*******************************************************************
    DIM RAW iWorkingOn AS INT
    DIM RAW iLastTokenPlus1 AS INT
    DIM RAW ParamTok$

    CALL FastLexer(sP$, "", ",()[]")
    iLastTokenPlus1 = Ndx
    IF TALLY(sP$, "(") OR TALLY(sP$, "[") THEN
        FOR iWorkingOn = 1 TO Ndx
            Stk$[iWorkingOn] = TRIM$(Stk$[iWorkingOn])
        NEXT
        CALL RemEmptyTokens
        iWorkingOn = 1
        iLastTokenPlus1 = 0
        DO WHILE BYTE_AT(Stk$[iWorkingOn][0] > 0)
            ParamTok$ = Stk$[iWorkingOn]
            IF ParamTok[0] <> c_Comma AND BYTE_AT(Stk$[iWorkingOn+1][0]) <> c_Comma THEN
                DO
                    INCR iWorkingOn
                    IF iWorkingOn > Ndx THEN EXIT DO
                    ParamTok$ += Stk$[iWorkingOn]
                    DO WHILE (TALLY(ParamTok$, "[")-TALLY(ParamTok$, "]")) <> 0 OR (TALLY(ParamTok$, "(")-TALLY(ParamTok$, ")")) <> 0
                        INCR iWorkingOn
                        ParamTok$ += Stk$[iWorkingOn]
                    LOOP
                    IF BYTE_AT(Stk$[iWorkingOn][0]) = c_Comma THEN EXIT DO
                LOOP WHILE *Stk$[iWorkingOn] > 0
            END IF
            INCR iWorkingOn
            Stk$[++iLastTokenPlus1] = ParamTok$
            IF iWorkingOn > Ndx THEN EXIT DO
        LOOP
        Ndx = iLastTokenPlus1
    END IF
    INCR iLastTokenPlus1
    Stk$[iLastTokenPlus1] = ""

    IF c_MaxParamToken <= iLastTokenPlus1 THEN
        CALL Abort("Maximum nunber of com tokens exceeded.")
    END IF

    FOR iWorkingOn = 1 TO iLastTokenPlus1
        ParamToken$[iWorkingOn] = Stk$[iWorkingOn]
    NEXT
    FUNCTION = Ndx
END FUNCTION  ' GetParameterTokens



FUNCTION Com_Make_Param_List  (parms$, IsIndex AS INT)
    '*****************************************************************************
    ' This function prepares parameters for a COM call by parsing and processing
    ' the given parameter string (parms$) containing parameter information.
    ' Parameters are placed in reverse order, as required by COM standard.
    '
    ' Return Values:
    ' returns number of created parameters for next COM call.
    '*****************************************************************************
    DIM RAW szTempStr$
    DIM RAW szCleanTemp$
    DIM RAW iTokens AS INT
    DIM RAW i AS INT
    DIM RAW j AS INT
    DIM RAW k AS INT
    DIM RAW iArrayFlag AS INT
    DIM RAW iByrefFlag AS INT
    DIM RAW P1$
    DIM RAW P2$
    DIM RAW local_parm_copy$
    DIM RAW local_temp_str$
    DIM RAW ComParameterCnt AS INT
    DIM RAW iReturn AS INT

    IF parms$ = "" THEN FUNCTION = 0  ' Handle null arguments

    ComParameterCnt = 0
    local_parm_copy$ = TRIM$(parms$)
    iTokens = GetParameterTokens(local_parm_copy$)
    i = 1
    DO WHILE i <= iTokens
        IF BYTE_AT (ParamToken[i][0]) = c_Comma THEN
            INCR i
        ELSE
            INCR i, 2
        END IF
        INCR ComParameterCnt
    LOOP
    iReturn = ComParameterCnt
    i = 1
    DO WHILE i <= iTokens
        P1$ = ""
        P2$ = ";"
        iByrefFlag = 0
        iArrayFlag = 0
        IF BYTE_AT (ParamToken[i][0]) = c_Comma THEN
            j = comvt_ERROR
            szCleanTemp$ = "DISP_E_PARAMc_NOTFOUND"
            INCR i
        ELSE
            j = ComParamType(ParamToken$[i], ADDRESSOF(k))
            IF k THEN
                szCleanTemp$ = ""
                FOR k = 1 TO Ndx
                    szCleanTemp$ += Stk$[k]
                NEXT
                szCleanTemp$ = No_Sigil$(szCleanTemp$)
            ELSE
                IF j = comvt_CAST THEN  ' Determine if C or VT cast
                    CALL ConvertCast(ParamToken$[i], local_temp_str$, szCleanTemp$)
                ELSE
                    szCleanTemp$ = No_Sigil$(ParamToken$[i])
                END IF
            END IF
            iByrefFlag = j BAND comvt_BYREF
            IF iByrefFlag THEN
                P1$ = "p"
                P2$ = "|VT_BYREF;"
            END IF
            iArrayFlag = j BAND comvt_ARRAY
            IF iArrayFlag THEN
                P1$ += "p"
                P2$ = "|VT_ARRAY"+P2$
            END IF
            j = j BAND comvt_TYPEMASK
            INCR i, 2
        END IF

        ComParameterCnt--
        szTempStr = STR$(ComParameterCnt, 1)

        SELECT CASE j
            CASE comvt_EMPTY
                IF iArrayFlag THEN Abort("Invalid: Array of empty")
                IF iByrefFlag THEN Abort("Invalid: Pointer to empty")
                ' No value was specified. If an optional argument to an Automation method is left blank,
                ' do not pass a VARIANT of type VT_EMPTY. Instead, pass a VARIANT of type VT_ERROR with a
                ' value of DISP_E_PARAMc_NOTFOUND.
                ' BY_REF INVLAID
                ' VT_ARRAY INVALID

            CASE comvt_UI1
                ' An unsigned 1-byte character is stored in bVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_UI1", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "bVal = ", szCleanTemp$, ";"

            CASE comvt_UI2
                ' An unsigned 2-byte integer value is stored in uiVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_UI2", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "uiVal = ", szCleanTemp$, ";"

            CASE comvt_UI4
                ' An unsigned 4-byte integer value is stored in ulVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_UI4", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "ulVal = ", szCleanTemp$, ";"

            CASE comvt_UI8
                ' An unsigned 8-byte integer value is stored in ullVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_UI8", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "ullVal = ", szCleanTemp$, ";"

            CASE comvt_UINT
                ' An unsigned integer value is stored in uintVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_UINT", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "uintVal = ", szCleanTemp$, ";"

            CASE comvt_INT
                ' An integer value is stored in intVal.
                IF IsIndex = 1 THEN
                    ' if warning levels add to bcx issue warning "variable type int casted to long"
                    FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_I4", P2$
                    FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].lVal = ", szCleanTemp$, ";"
                ELSE
                    FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_INT", P2$
                    FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "intVal = ", szCleanTemp$, ";"
                END IF

            CASE comvt_I1
                ' A 1-byte character value is stored in cVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_I1", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "cVal = ", szCleanTemp$, ";"

            CASE comvt_I2
                ' A 2-byte integer value is stored in iVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_I2", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "iVal = ", szCleanTemp$, ";"


            CASE comvt_I4
                ' A 4-byte integer value is stored in lVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_I4", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "lVal = ", szCleanTemp$, ";"

            CASE comvt_I8
                ' A 8-byte integer value is stored in llVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_I8", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "llval = ", szCleanTemp$, ";"

            CASE comvt_R4
                ' An IEEE 4-byte real value is stored in fltVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_R4", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "fltVal = ", szCleanTemp$, ";"

            CASE comvt_R8
                ' An 8-byte IEEE real value is stored in dblVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_R8", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "dblVal = ", szCleanTemp$, ";"

            CASE comvt_CY
                ' A currency value was specified. A currency number is stored as 64-bit (8-byte),
                ' two's complement integer, scaled by 10,000 to give a fixed-point number
                ' with 15 digits to the left of the decimal point and 4 digits to the right.
                ' The value is in cyVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_CY", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "cyVal = ", szCleanTemp$, ";"

            CASE comvt_BSTR
                ' A string was passed; it is stored in bstrVal. This pointer must be obtained and
                ' freed by the BSTR functions, which are described in Conversion and Manipulation Functions.
                REPLACE CHR$(92)       WITH CHR$(92, 92) IN szCleanTemp$
                REPLACE CHR$(92, 92, 92) WITH CHR$(92, 92) IN szCleanTemp$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_BSTR", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "bstrVal = SysAllocString(L", szCleanTemp$, ");"

            CASE comvt_DECIMAL
                ' Decimal variables are stored as 96-bit (12-byte) unsigned integers scaled by a
                ' variable power of 10. VT_DECIMAL uses the entire 16 bytes of the Variant.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_BYREF|VT_DECIMAL;"
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "decVal = ", szCleanTemp$, ";"

            CASE comvt_NULL
                IF iArrayFlag THEN Abort("Invalid: Array of NULLs")
                IF iByrefFlag THEN Abort("Invalid: Pointer to NULL")
                ' A propagating null value was specified. (This should not be confused with the null pointer.)
                ' The null value is used for tri-state logic, as with SQL.
                ' BY_REF INVALID
                ' VT_ARRAY INVALID

            CASE comvt_ERROR
                ' An SCODE was specified. The type of the error is specified in scodee. Generally,
                ' operations on error values should raise an exception or propagate the error to
                ' the return value, as appropriate.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_ERROR", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "scode = ", szCleanTemp$, ";"

            CASE comvt_BOOL
                ' A 16 bit Boolean (True/False) value was specified.
                ' A value of 0xFFFF (all bits 1) indicates True;
                ' a value of 0 (all bits 0) indicates False. No other values are valid.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_BOOL", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "boolVal = ", szCleanTemp$, ";"

            CASE comvt_TRUE
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_BOOL", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "boolVal = VARIANT_TRUE;"

            CASE comvt_FALSE
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_BOOL", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "boolVal = VARIANT_FALSE;"

            CASE comvt_DATE
                ' A value denoting a date and time was specified. Dates are represented as
                ' double-precision numbers, where midnight, January 1, 1900 is 2.0, January 2, 1900 is 3.0,
                ' and so on. The value is passed in date.
                ' This is the same numbering system used by most spreadsheet programs,
                ' although some specify incorrectly that February 29, 1900 existed, and thus
                ' set January 1, 1900 to 1.0. The date can be converted to and from an MS-DOS
                ' representation using VariantTimeToDosDateTime, which is discussed in
                ' Conversion and Manipulation Functions.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_DATE", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "date = ", szCleanTemp$, ";"

            CASE comvt_DISPATCH
                ' A pointer to an object was specified. The pointer is in pdispVal.
                ' This object is known only to implement IDispatch. The object can be queried as to
                ' whether it supports any other desired interface by calling QueryInterface on the object.
                ' Objects that do not implement IDispatch should be passed using VT_UNKNOWN.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_DISPATCH", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "pdispVal = ", szCleanTemp$, ";"

            CASE comvt_VARIANT
                ' IF NOT iByrefFlag AND NOT iArrayFlag THEN Abort("Invalid: VARIANTARGs must be passed by reference.")
                ' A pointer to another VARIANTARG is passed in pvarVal. This referenced VARIANTARG,
                ' pvarVal, cannot be another VT_VARIANT|VT_BYREF. This value can be used to support
                ' languages that allow functions to change the types of variables passed by reference.
                IF NOT iByrefFlag AND NOT iArrayFlag THEN   ' assumes variant holds a safearray of variants
                    FPRINT FP_WRITE, Scoot$, "  COM_PARAMS[", szTempStr, "].vt = VT_VARIANT|VT_ARRAY;"
                    FPRINT FP_WRITE, Scoot$, "  COM_PARAMS[", szTempStr, "].pvarVal = ", szCleanTemp$, ".pvarVal;"
                ELSE
                    FPRINT FP_WRITE, Scoot$, "  COM_PARAMS[", szTempStr, "].vt = VT_VARIANT", P2$
                    FPRINT FP_WRITE, Scoot$, "  COM_PARAMS[", szTempStr, "].", P1$, "pvarVal = ", szCleanTemp$, ";"
                END IF

            CASE comvt_UNKNOWN
                ' A pointer to an object that implements the IUnknown interface is passed in punkVal.
                ' BY_REF: A pointer to the IUnknown interface is passed in ppunkVal. The pointer to
                ' the interface is stored in the location referred to by ppunkVal.
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_UNKNOWN", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "punkVal = ", szCleanTemp$, ";"

            CASE comvt_PVOID
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_PVOID", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "byref = ", szCleanTemp$, ";"

            CASE comvt_STRVAR
                FPRINT FP_WRITE, Scoot$, "COM_last_HR = COM_AS2WS(", szCleanTemp$, ");"
                FPRINT FP_WRITE, Scoot$, "if (FAILED(COM_last_HR)) {"
                FPRINT FP_WRITE, Scoot$, "  COM_HR_ErrMsg (COM_last_HR, _T("
                FPRINT FP_WRITE, Scoot$, SPC$, ENC$("Build ParamList Failed! A2W failure!"), "));"
                FPRINT FP_WRITE, Scoot$, "} else {"
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_BSTR", P2$
                FPRINT FP_WRITE, Scoot$, "  COM_PARAMS[", szTempStr, "].bstrVal = SysAllocString(COM_PWSTR_temp);"
                FPRINT FP_WRITE, Scoot$, "}"

            CASE comvt_R8_LITERAL
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_R8", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].dblVal = ", szCleanTemp$, ";"

            CASE comvt_OBJECT
                FPRINT FP_WRITE, Scoot$, "VariantCopy(&COM_PARAMS[", szTempStr, "], &", szCleanTemp$, ".pObjects[0]);"

            CASE comvt_I4_LITERAL
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_I4", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].lVal = ", szCleanTemp$, ";"

            CASE comvt_VOID
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_VOID;"
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].lVal = (void)", szCleanTemp$, ";"


            CASE comvt_SAFEARRAY
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_SAFEARRAY", P2$
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", P1$, "parray = &", szCleanTemp$, ";"

            CASE comvt_NAMED_ARGUMENT
                Abort ("Named arguments are NOT supported in this version! (" + ParamToken$[i] + ")")

            CASE comvt_CAST
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = ", local_temp_str$, ";"
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].", szCleanTemp$, ";"

            CASE comvt_DEFAULT
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].vt = VT_I4;"
                FPRINT FP_WRITE, Scoot$, "COM_PARAMS[", szTempStr, "].lVal = (long)", szCleanTemp$, ";"

        END SELECT
    LOOP
    FUNCTION = iReturn
END FUNCTION ' COM_Prep_Param_List



FUNCTION ComParamType (sParam$, iRebuild AS INT PTR)
    '*******************************************************
    ' Function to return the parameter type used in COM
    ' Note: Limited support for functions as parameters
    ' 2008-01-26 --- Wayne Halsdorf
    '*******************************************************
    DIM RAW varidx AS INT
    DIM RAW k AS INT
    DIM RAW ptVI AS UDT_VARINFO_STORAGE PTR
    DIM RAW iBYREF_Flag AS INT

    *iRebuild = 0
    IF sParam[0] = c_LPar THEN
        FUNCTION = comvt_CAST
    END IF
    IF m_iMatchWrd(sParam$, "true") THEN
        FUNCTION = comvt_TRUE
    END IF
    IF m_iMatchWrd(sParam$, "false") THEN
        FUNCTION = comvt_FALSE
    END IF
    IF sParam[0] = c_DblQt THEN
        FUNCTION = comvt_BSTR
    END IF
    IF IsDecimalNumber(sParam$) THEN
        IF INCHR(sParam$, ".") THEN
            FUNCTION = comvt_R8_LITERAL
        ELSE
            FUNCTION = comvt_I4_LITERAL
        END IF
    END IF
    IF iMatchNQ (sParam$, ":=") > 0 THEN ' this is named argument
        FUNCTION = comvt_NAMED_ARGUMENT
    END IF
    IF IsVariableComObject(TRIM$(No_Sigil$(sParam$))) THEN
        FUNCTION = comvt_OBJECT
    END IF
    IF RIGHTSTR (sParam$, "#") THEN
        FUNCTION = comvt_R8
    END IF
    IF RIGHTSTR (sParam$, "!") THEN
        FUNCTION = comvt_R4
    END IF
    IF RIGHTSTR (sParam$, "$") THEN
        FUNCTION = comvt_STRVAR
    END IF
    IF RIGHTSTR (sParam$, "%") THEN
        FUNCTION = comvt_INT
    END IF
    ptVI = NULL
    k = CheckLocal(sParam$, ADDRESSOF(varidx))
    IF k <> vt_UNKNOWN THEN
        ptVI = ADDRESSOF(LocalVars[varidx])
    ELSE
        k = CheckGlobal(sParam$, ADDRESSOF(varidx))
        IF k <> vt_UNKNOWN THEN
            ptVI = ADDRESSOF(GlobalVars[varidx])
        END IF
    END IF

    IF ptVI <> NULL THEN

        iBYREF_Flag = 0

        IF ptVI->VarPntr = 1 THEN iBYREF_Flag = comvt_BYREF
        IF ptVI->VarPntr < 2 THEN

            SELECT CASE k
                CASE vt_VOID
                    FUNCTION = comvt_VOID BOR iBYREF_Flag
                CASE vt_STRVAR
                    FUNCTION = comvt_STRVAR BOR iBYREF_Flag
                CASE vt_DOUBLE
                    FUNCTION = comvt_R8 BOR iBYREF_Flag
                CASE vt_SINGLE
                    FUNCTION = comvt_R4 BOR iBYREF_Flag
                CASE vt_INTEGER
                    FUNCTION = comvt_INT BOR iBYREF_Flag
                CASE vt_LLONG
                    FUNCTION = comvt_I8 BOR iBYREF_Flag
                CASE vt_ULONGLONG
                    FUNCTION = comvt_UI8 BOR iBYREF_Flag
                CASE vt_LONG
                    FUNCTION = comvt_I4 BOR iBYREF_Flag
                CASE vt_ULONG
                    FUNCTION = comvt_UI4 BOR iBYREF_Flag
                CASE vt_SHORT, vt_SSHORT
                    FUNCTION = comvt_I2 BOR iBYREF_Flag
                CASE vt_USHORT
                    FUNCTION = comvt_UI2 BOR iBYREF_Flag
                CASE vt_CHAR, vt_SCHAR
                    FUNCTION = comvt_I1 BOR iBYREF_Flag
                CASE vt_BYTE
                    FUNCTION = comvt_UI1 BOR iBYREF_Flag
                CASE vt_BOOL
                    FUNCTION = comvt_BOOL BOR iBYREF_Flag
                CASE vt_UINT
                    FUNCTION = comvt_UINT BOR iBYREF_Flag
                CASE vt_VARIANT
                    FUNCTION = comvt_VARIANT BOR iBYREF_Flag
                CASE vt_UDT
                    IF TypeDefs[ptVI->VarDef].VarName$ = "SAFEARRAY" THEN
                        FUNCTION = comvt_SAFEARRAY BOR iBYREF_Flag
                    END IF
            END SELECT
        END IF
    END IF
    IF INCHR(sParam$, "(") THEN
        DIM RAW Keyword$
        DIM RAW tpBCX AS UDT_SUB_FUNC_TOKENS PTR
        *iRebuild = 1
        CALL PreParse(sParam$)
        CALL TokenSubstitutions(1)
        Keyword$ = LCASE$(Stk$[1])
        tpBCX = GetWordInfo(Keyword$)
        IF tpBCX THEN
            IF tpBCX->iCOM <> comvt_BAD THEN
                FUNCTION = tpBCX->iCOM
            END IF
        END IF
    END IF
    *iRebuild = 0
    FUNCTION = comvt_DEFAULT
END FUNCTION ' ComParamType



SUB ConvertCast (szParam$, szVT$, szVAL$)
    '  Example:  szParam$ (VT_ARRAY|VT_BYREF|VT_XXXX)(C_CAST)
    DIM RAW i AS INT
    DIM RAW szTemp$

    szVT$ = ""
    szVAL$ = ""
    szTemp$ = EXTRACT$(szParam$, ")")
    szTemp$ = MID$(szTemp$, 2)
    IF LEFTSTR(szTemp$, "VT_") THEN
        IF LEFTSTR(szTemp$, "VT_ARRAY") THEN
            szVAL$ = "parray"
            szVT$ = "VT_ARRAY"
            REMOVE "VT_ARRAY" FROM szTemp$
        END IF
        IF iMatchNQ (szTemp$, "VT_BYREF") THEN
            szVAL$ = "p"+szVAL$
            IF NOTNULL(szVT$) THEN szVT$ += "|"
            szVT$ += "VT_BYREF"
            REMOVE "VT_BYREF" FROM szTemp$
        END IF
        DO WHILE szTemp[0] = 124
            szTemp$ = MID$(szTemp$, 2)
        LOOP
        i = 0
        DO WHILE ptVCasts[i].pszCAST <> NULL
            IF LEFTSTR(szTemp$, ptVCasts[i].pszCAST$) THEN
                szTemp$ = REMAIN$(szParam$, ")")
                IF *szTemp$ = ASC("(") THEN szTemp$ = REMAIN$(szTemp$, ")")
                szVAL$ += "=" + szTemp$ ' ASSUME VALID C CAST OR NO CAST
                IF NOTNULL(szVT$) THEN szVT$ += "|"
                szVT$ += ptVCasts[i].pszCAST$
                EXIT SUB
            END IF
            INCR i
        LOOP
        IF iMatchNQ (szVAL$, "array") THEN
            IF NOTNULL(szVT$) THEN szVT$ += "|"
            szVT$ += szTemp$
            szTemp$ = REMAIN$(szParam$, ")")
            IF *szTemp$ = ASC("(") THEN szTemp$ = REMAIN$(szTemp$, ")")
            szVAL$ += "=" + szTemp$ ' ASSUME VALID C CAST OR NO CAST
            EXIT SUB
        END IF
        CALL Abort("Unknown cast. " + szTemp$ + " See help file")
    END IF
    ' DEALING WITH C CAST
    IF INCHR(szTemp$, "*") THEN szVAL$ = "p"
    REMOVE "*" FROM szTemp$
    i = 0
    DO WHILE ptCCasts[i].pszCAST <> NULL
        IF szTemp$ = ptCCasts[i].pszCAST$ THEN
            szTemp$ = REMAIN$(szParam$, ")")
            IF *szTemp$ = ASC(")") THEN szTemp$ = REMAIN$(szTemp$, ")")
            szVAL$ += ptCCasts[i].pszVAL$ + "=" + szTemp$ ' ASSUME VALID C CAST OR NO CAST
            IF NOTNULL(szVT$) THEN szVT$ += "|"
            szVT$ += ptCCasts[i].pszCAST$
            EXIT SUB
        END IF
        INCR i
    LOOP
    CALL Abort("Unknown C cast. szParam$=" + szParam$ + " szVT$="+szVT$ + " szVAL$="+ szVAL$ + " See help file")
END SUB  ' ConvertCast





SUB COM_Parse_Method (com_method$, pparms$)
    '************************************************************************************************************
    ' Sub: COM_Parse_Method (part of BCX COM parser)
    ' Called internally by main com parser function, Find_COM_statement.
    ' If the statment is a COM method (with or without parameters) this function will be called.
    '
    ' Typical samples of COM methods:
    ' (method with parms) -- app.activeworkbook.saveas "c:\temp.xls"
    ' (invoke method)     -- app.quit
    '************************************************************************************************************
    Use_COM_InvokeMethod = Use_COM_UsesConversion = Use_COM = TRUE
    LOCAL j
    LOCAL k
    LOCAL ObjName$
    LOCAL ComTok$
    LOCAL ComToken$
    LOCAL temp_param$
    LOCAL BuildSafeArray
    LOCAL parms$

    IF COM_build_trace_code  THEN
        FPRINT FP_WRITE, "    COM_add_trace_line(";
        FPRINT FP_WRITE, ENC$("COM_Parse_Method(" + Make_COM_Trace_Lines$(com_method$) + " , " + Make_COM_Trace_Lines$(parms$) + ")"), ");"
    END IF

    parms$ = TRIM$(pparms$)
    IF parms$ <> "" THEN
        IF MID$(UCASE$(parms$), 1, 6) = "ARRAY(" OR MID$(UCASE$(parms$), 1, 6) = "ARRAY " THEN
            parms$ = REMAIN$(parms$, "(")
            j = LEN(parms$) -1
            parms[j] = 0 ' strip closing brace )
            BuildSafeArray = 1
            Use_COM_SafeArray = TRUE
        END IF
    END IF
    CALL ParseCom(com_method$)

    j = 1
    ObjName$ = ComStk$[j++]

    DO
        ComTok$ = ComStk$[j++]
        ComToken$ = ComTok$
        FPRINT FP_WRITE, Scoot$, "lstrcpy(COM_ErrMsg, _T(", ENC$(Make_COM_Trace_Lines$(ComTok$)), "));"
        IF INCHR(ComTok$, "(") > 0 THEN
            temp_param$ = TRIM$(REMAIN$(ComTok$, "("))
            k = Com_Make_Param_List(MID$(temp_param$, 1, LEN(temp_param$)-1), 0)
            FPRINT FP_WRITE, Scoot$, "COM_plist_index =", k, ";"
            ComToken$ = EXTRACT$(ComTok$, "(")
        END IF
        IF COM_build_trace_code  THEN
            IF NOTNULL(ComStk$[j]) THEN
                FPRINT FP_WRITE, "    COM_add_trace_line(", ENC$("Get next dispatch for "+Make_COM_Trace_Lines$(ComTok$)), ");"
            ELSE
                FPRINT FP_WRITE, "COM_add_trace_line(", ENC$("Invoke helper for:: "+ComTok$), ");"
            END IF
        END IF
        IF ISNULL(ComStk$[j]) THEN
            IF LEN(TRIM$(parms$))>0 THEN
                k = Com_Make_Param_List(parms$, 0)
                FPRINT FP_WRITE, Scoot$, "COM_plist_index =", k, ";"
                IF BuildSafeArray THEN
                    FPRINT FP_WRITE, Scoot$, "COM_create_safearray();"
                END IF
            END IF
            FPRINT FP_WRITE, Scoot$, "COM_invoke(&", ObjName$, ", L", ENC$(REMOVE$(ComToken$, SPC$)), ", DISPATCH_METHOD, NULL);\n"
            EXIT DO
        END IF
        FPRINT FP_WRITE, Scoot$, "COM_get_next_dispatch(&", ObjName$, ", L", ENC$(REMOVE$(ComToken$, SPC$)), ");"
    LOOP
END SUB ' COM_Parse_Method



SUB ParseCom (sCom$)
    '**************************************************************
    ' Common parser for COM SUBs
    ' COM_Parse_GetProperty
    ' COM_Parse_SetProperty
    ' COM_Parse_Method
    '**************************************************************
    DIM RAW i AS INT
    DIM RAW j AS INT
    DIM RAW k AS INT
    DIM RAW ComTok$
    ComNdx = 0
    CALL FastLexer(sCom$, SPC$, "()")
    IF Ndx THEN
        i = 1
        ComStk$[++ComNdx] = STRTOKEN$(Stk$[i], ".", 1)         ' get the name of object
        j = 1
        DO
            INCR j
            ComTok$ = STRTOKEN$ (Stk$[i], "." , j)
            IF ComTok$ = RIGHT$(Stk$[i], LEN(ComTok$)) THEN
                IF i < Ndx THEN
                    IF Stk$[i+1] = "(" THEN                     ' Parameter token
                        k = 0
                        DO
                            INCR i
                            ComTok$ += Stk$[i]
                            IF Stk$[i] = "(" THEN INCR k
                            IF Stk$[i] = ")" THEN DECR k
                        LOOP WHILE k
                    END IF
                    INCR i
                    j = 1
                END IF
            END IF
            IF ISNULL(ComTok$) THEN
                EXIT DO
            END IF
            CALL Add2ComStk(ComTok$)
        LOOP
        CALL Add2ComStk("")
        ComNdx--
    END IF
END SUB ' ParseCom


SUB Add2ComStk (ComTok$)
    IF c_MaxComStk = ++ComNdx THEN
        CALL Abort("Too many COM tokens.")
    END IF
    ComStk$[ComNdx] = ComTok$
END SUB ' Add2ComStk



FUNCTION Make_COM_Trace_Lines (p_Src$) AS STRING
    '************************************************************************************************
    ' Function: Make_COM_Trace_Lines$ (part of BCX COM parser)
    ' This function is used only if $COM_TRACE option is used.
    ' Function prepares escape characters in string literals for emitting to resulting C/C++ files.
    '
    ' Return Values:
    ' Function returns altered string.
    '************************************************************************************************
    DIM pp_Src$
    pp_Src$ = TRIM$(p_Src$)
    pp_Src$ = REPLACE$(pp_Src$, BKSLASH1$, BKSLASH2$)
    pp_Src$ = REPLACE$(pp_Src$, CHR$(c_DblQt), "\" + CHR$(c_DblQt))
    pp_Src$ = REPLACE$(pp_Src$, "%", "%%")
    pp_Src$ = REPLACE$(pp_Src$, "'", "\'")
    FUNCTION = pp_Src$
END FUNCTION ' BCX_PREPARE_COM_TRACE_LINE

'***************************************************************************************************
'                             END OF LATE BINDING COM RUNTIME SUPPORT
'***************************************************************************************************


SUB Emit_Prolog(FP_OUTPUT AS FILE)
    FPRINT FP_OUTPUT, "// *************************************************"
    FPRINT FP_OUTPUT, "//      Made with BCX BASIC To C/C++ Translator"
    FPRINT FP_OUTPUT, "//            Version ", c_VERSION$
    FPRINT FP_OUTPUT, "// *************************************************"
    FPRINT FP_OUTPUT, "//    Translated for compiling with a ";

    IF UseCpp THEN
        FPRINT FP_OUTPUT, "C++ Compiler"
    ELSE
        FPRINT FP_OUTPUT, "C Compiler"
    END IF

    FPRINT FP_OUTPUT, "// *************************************************"

    IF UseCpp THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  #error A C++ compiler is required"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
    END IF

    IF NO_MSVC = FALSE THEN
        FPRINT FP_OUTPUT, "#ifdef _MSC_VER"
        FPRINT FP_OUTPUT, "  #ifndef _CRT_SECURE_NO_WARNINGS"
        FPRINT FP_OUTPUT, "    #define _CRT_SECURE_NO_WARNINGS"
        FPRINT FP_OUTPUT, "  #endif"
        FPRINT FP_OUTPUT, "#endif"
    END IF

    IF Use_LeanAndMean = TRUE THEN
        FPRINT FP_OUTPUT, "#define  WIN32_LEAN_AND_MEAN"
    END IF

    IF Use_MULTITHREADED_SW THEN
        FPRINT FP_OUTPUT, "#define __BCX_MULTITHREADED__"
    END IF

    IF Use_COM OR Use_VBS THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifndef _WIN32_DCOM"
        FPRINT FP_OUTPUT, "  #define _WIN32_DCOM"
        FPRINT FP_OUTPUT, "#endif"
    END IF

    IF Use_UNICODE THEN
        ' this should be emitted before any other windows header
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifndef UNICODE"
        FPRINT FP_OUTPUT, "  #define UNICODE   // used by Windows headers"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifndef _UNICODE"
        FPRINT FP_OUTPUT, "  #define _UNICODE  // used by CRT headers"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
    END IF

    IF UseCpp AND UseCpphdr THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#if defined(__cplusplus)"
        IF UseIO THEN
            FPRINT FP_OUTPUT, "  #include <iostream>"
        END IF
        FPRINT FP_OUTPUT, "  #include <fstream>"
        FPRINT FP_OUTPUT, "  #include <sstream>"
        FPRINT FP_OUTPUT, "  #include <iomanip>"
        FPRINT FP_OUTPUT, "  typedef std::string stdstr;"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
    END IF

    IF LOF(defFile$) > 7 THEN            ' Q. Why 7? ... A. "#define"
        OPEN defFile$ FOR INPUT AS FP99
        DO WHILE NOT EOF(FP99)
            LINE INPUT FP99, Src$
            FPRINT FP_OUTPUT, Src$
        LOOP
        CLOSE FP99
        FPRINT FP_OUTPUT, SPC$
    END IF

    IF ZapFlag = FALSE THEN

        IF WinHeaders = TRUE OR Use_Project = TRUE THEN
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "// Windows API headers"
            FPRINT FP_OUTPUT, "#include <windows.h>    // Core Windows API"
            FPRINT FP_OUTPUT, "#include <windowsx.h>   // Windows API macros and functions"
            FPRINT FP_OUTPUT, "#include <commctrl.h>   // Common Controls"
            FPRINT FP_OUTPUT, "#include <commdlg.h>    // Common Dialogs"
            FPRINT FP_OUTPUT, "#include <direct.h>     // Directory handling"
            FPRINT FP_OUTPUT, "#include <locale.h>     // Locale handling"
            FPRINT FP_OUTPUT, "#include <mmsystem.h>   // Multimedia"
            FPRINT FP_OUTPUT, "#include <ole2.h>       // OLE 2.0 functionality"
            FPRINT FP_OUTPUT, "#include <oleauto.h>    // OLE Automation"
            FPRINT FP_OUTPUT, "#include <olectl.h>     // OLE Controls"
            FPRINT FP_OUTPUT, "#include <richedit.h>   // Rich Edit Control"
            FPRINT FP_OUTPUT, "#include <shellapi.h>   // Shell API"
            FPRINT FP_OUTPUT, "#include <shlobj.h>     // Shell Objects"
            FPRINT FP_OUTPUT, "#include <shlwapi.h>    // Shell lightweight utility functions"
            FPRINT FP_OUTPUT, "#include <tchar.h>      // Unicode/ANSI character mapping"
            FPRINT FP_OUTPUT, "#include <urlmon.h>     // URL Monikers"
            FPRINT FP_OUTPUT, "#include <wchar.h>      // Wide character support"
            FPRINT FP_OUTPUT, "#include <wctype.h>     // Wide character classification"
            FPRINT FP_OUTPUT, "#include <wininet.h>    // Internet"
            FPRINT FP_OUTPUT, "#include <winsock.h>    // Windows Sockets (Winsock 1.1)"
            FPRINT FP_OUTPUT, SPC$
        END IF

        FPRINT FP_OUTPUT, "// ISO C Standard Library headers"
        FPRINT FP_OUTPUT, "#include <ctype.h>      // Character classification"
        FPRINT FP_OUTPUT, "#include <math.h>       // Mathematical functions"
        FPRINT FP_OUTPUT, "#include <setjmp.h>     // Non-local jumps"
        FPRINT FP_OUTPUT, "#include <stdarg.h>     // Variable arguments"
        FPRINT FP_OUTPUT, "#include <stddef.h>     // Common definitions"
        FPRINT FP_OUTPUT, "#include <stdio.h>      // Input/output"
        FPRINT FP_OUTPUT, "#include <stdlib.h>     // General utilities"
        FPRINT FP_OUTPUT, "#include <string.h>     // String handling"
        FPRINT FP_OUTPUT, "#include <time.h>       // Date and time"
        FPRINT FP_OUTPUT, "#include <errno.h>      // Error numbers"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// C99 Standard headers"
        FPRINT FP_OUTPUT, "#include <stdbool.h>    // Boolean type"
        FPRINT FP_OUTPUT, "#include <inttypes.h>   // Integer types"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// POSIX headers"
        FPRINT FP_OUTPUT, "#include <fcntl.h>      // File control options"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// Windows-specific headers"
        FPRINT FP_OUTPUT, "#include <process.h>    // Process control functions"
        FPRINT FP_OUTPUT, "#include <io.h>         // Low-level I/O (Windows POSIX subset)"
        FPRINT FP_OUTPUT, "#include <conio.h>      // Console I/O (Windows-specific)"
    END IF
    FPRINT FP_OUTPUT, SPC$
END SUB ' Emit_Prolog



SUB Emit_Main_Function
    FPRINT FP_WRITE, "int main(int argc, char *argv[])"
    '*****************************************************************************
    '         int main is conditionally removed later IN SUB AssembleParts
    '*****************************************************************************
    FLUSH (FP_WRITE)
END SUB ' Emit_Main_Function



SUB Emit_Epilog
    IF Use_Wingui + MakeDLL + NoMain + EndOfProgram = 0 THEN
        IF Use_Sound THEN
            FPRINT FP_WRITE, Scoot$, "midiOutClose (hMidi);"  ' Added by MrBcx 825
        END IF
        FPRINT FP_WRITE, "return EXIT_SUCCESS;   // End of main program"
        FPRINT FP_WRITE, "}"
        FLUSH(FP_WRITE)
    END IF
END SUB ' Emit_Epilog



SUB Emit_CompilerDefines
    STATIC BeenHere
    IF BeenHere THEN EXIT SUB
    BeenHere = TRUE

    FPRINT FP_HDR, ""

    IF UseImportExport THEN
        FPRINT FP_HDR, "#if defined(__cplusplus)"
        FPRINT FP_HDR, "  #define C_EXPORT EXTERN_C __declspec(dllexport)"
        FPRINT FP_HDR, "  #define C_IMPORT EXTERN_C __declspec(dllimport)"
        FPRINT FP_HDR, "#else"
        FPRINT FP_HDR, "  #define C_EXPORT __declspec(dllexport)"
        FPRINT FP_HDR, "  #define C_IMPORT __declspec(dllimport)"
        FPRINT FP_HDR, "#endif"
        FPRINT FP_HDR, ""
    END IF

    IF ZapFlag = FALSE THEN
        IF NO_MSVC = FALSE THEN
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, "//                   Microsoft VC++"
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, ""
            FPRINT FP_HDR, "#ifndef DECLSPEC_UUID"
            FPRINT FP_HDR, "  #if(_MSC_VER >= 1100) && defined(__cplusplus)"
            FPRINT FP_HDR, "    #define DECLSPEC_UUID(x)  __declspec(uuid(x))"
            FPRINT FP_HDR, "  #else"
            FPRINT FP_HDR, "    #define DECLSPEC_UUID(x)"
            FPRINT FP_HDR, "  #endif"
            FPRINT FP_HDR, "#endif"
            FPRINT FP_HDR, "#if (_MSC_VER >= 1900)            // earlier versions untested"
            FPRINT FP_HDR, "   #include <intrin.h>"
            FPRINT FP_HDR, "      #ifndef _rdtsc"
            FPRINT FP_HDR, "         #define _rdtsc __rdtsc   // MSVC uses 2 underscores"
            FPRINT FP_HDR, "      #endif"

            IF WarningFlag = FALSE THEN
                FPRINT FP_HDR, "   #pragma warning(disable: 4018) // signed/unsigned mismatch warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4100) // unreferenced argument warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4244) // conversion from type1 to type2 warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4245) // conversion from type1 to type2 warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4267) // conversion from type1 to type2 warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4305) // truncation from double to float warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4312) // truncation from cast warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4389) // conversion from signed to unsigned warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4459) // hides global declaration warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4459) // local hides global declaration"
                FPRINT FP_HDR, "   #pragma warning(disable: 4554) // use parentheses to clarify precedence"
                FPRINT FP_HDR, "   #pragma warning(disable: 4800) // forcing value to bool warnings"
                FPRINT FP_HDR, "   #pragma warning(disable: 4838) // conversion from type1 to type2 warnings"
            END IF
            FPRINT FP_HDR, "#endif"
            FPRINT FP_HDR, ""
        END IF

        IF NO_GCCCLANG = FALSE THEN
            FPRINT FP_HDR, ""
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, "//                  GCC and CLANG"
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, ""
            FPRINT FP_HDR, "#if defined(__GNUC__) || defined(__clang__)"
            FPRINT FP_HDR, "   #ifndef __BCPLUSPLUS__"
            FPRINT FP_HDR, "      #include <x86intrin.h>"
            FPRINT FP_HDR, "   #endif"

            IF WarningFlag = FALSE THEN
                FPRINT FP_HDR, "   #pragma GCC diagnostic ignored ", ENC$("-Wwrite-strings")
                FPRINT FP_HDR, "   #pragma GCC diagnostic ignored ", ENC$("-Wunused-parameter")
                FPRINT FP_HDR, "   #pragma GCC diagnostic ignored ", ENC$("-Wunknown-pragmas")
                FPRINT FP_HDR, "   #pragma GCC diagnostic ignored ", ENC$("-Wdangling-else")
                FPRINT FP_HDR, "   #pragma GCC diagnostic ignored ", ENC$("-Wint-to-pointer-cast")
                FPRINT FP_HDR, "   #pragma GCC diagnostic ignored ", ENC$("-Wdeprecated")
                FPRINT FP_HDR, "   #pragma GCC diagnostic ignored ", ENC$("-Wsizeof-pointer-div") ' MrBcx _msize warnings
            END IF
            FPRINT FP_HDR, "#endif"
            FPRINT FP_HDR, ""
        END IF

        IF NO_BORLAND = FALSE THEN
            FPRINT FP_HDR, ""
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, "//                  Embarcadero C++"
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, ""
            FPRINT FP_HDR, "#if defined(__BCPLUSPLUS__)"
            FPRINT FP_HDR, "      #include<malloc.h>"
            FPRINT FP_HDR, "      #if defined (_clang__)"
            FPRINT FP_HDR, "          #include <mmintrin.h>"
            FPRINT FP_HDR, "      #endif"
            FPRINT FP_HDR, "      #define _kbhit kbhit"
            FPRINT FP_HDR, "      #ifndef _rdtsc"
            FPRINT FP_HDR, "         #define _rdtsc __rdtsc  // Uses 2 underscores"
            FPRINT FP_HDR, "      #endif"
            FPRINT FP_HDR, "#endif"
            FPRINT FP_HDR, ""
        END IF

        IF ISFALSE UseCpp AND NO_LCCWIN = FALSE THEN
            FPRINT FP_HDR, ""
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, "//                     Lcc-Win32"
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, ""
            FPRINT FP_HDR, "#if defined(__LCC__)"
            FPRINT FP_HDR, "    #define  PCTSTR    LPCTSTR"
            FPRINT FP_HDR, "    #define _fseeki64  fseek"
            FPRINT FP_HDR, "    #define _ftelli64  ftell"
            FPRINT FP_HDR, "    #define _itoa      itoa"
            FPRINT FP_HDR, "    #define _ltoa      ltoa"
            FPRINT FP_HDR, "    #define _strdup    strdup"
            FPRINT FP_HDR, "    #define _stricmp   stricmp"
            FPRINT FP_HDR, "    #define _strnicmp  strnicmp"
            FPRINT FP_HDR, "    #include <intrinsics.h>"
            FPRINT FP_HDR, "    #include <malloc.h>  // for _msize"
            FPRINT FP_HDR, "    #if defined(__windows_h__)"
            FPRINT FP_HDR, "       #define COMPILE_MULTIMON_STUBS"
            FPRINT FP_HDR, "       #include <multimon.h>"
            FPRINT FP_HDR, "       #include <iehelper.h>"
            FPRINT FP_HDR, "       #include <exdisp.h>"
            FPRINT FP_HDR, "    #endif"
            FPRINT FP_HDR, "#endif"
            FPRINT FP_HDR, ""
        END IF

        IF Use_Overloaded_Macro THEN
            FPRINT FP_HDR, "#if !defined(__LCC__)"
            FPRINT FP_HDR, "    #define overloaded"
            FPRINT FP_HDR, "#else"
            FPRINT FP_HDR, "    #define overloaded overloaded"
            FPRINT FP_HDR, "#endif"
            FPRINT FP_HDR, ""
        END IF

        IF ISFALSE UseCpp AND NO_PELLES = FALSE THEN
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, "//                     Pelles C"
            FPRINT FP_HDR, "// *************************************************"
            FPRINT FP_HDR, ""
            FPRINT FP_HDR, "#if defined(__POCC__)"
            FPRINT FP_HDR, "    #include <intrin.h>"
            FPRINT FP_HDR, "    #pragma pack_stack(off)"

            IF WarningFlag = FALSE THEN
                FPRINT FP_HDR, "    #pragma warn(disable: 2006)    // Non-portable conversion int to const char*"
                FPRINT FP_HDR, "    #pragma warn(disable: 2007)    // Non-portable inline code"
                FPRINT FP_HDR, "    #pragma warn(disable: 2027)    // Missing prototype"
                FPRINT FP_HDR, "    #pragma warn(disable: 2073)    // Loss of precision float to int"
                FPRINT FP_HDR, "    #pragma warn(disable: 2115)    // Initialized but not used warnings"
                FPRINT FP_HDR, "    #pragma warn(disable: 2118)    // Unreferenced argument warnings"
                FPRINT FP_HDR, "    #pragma warn(disable: 2130)    // Usually flawed reporting"
                FPRINT FP_HDR, "    #pragma warn(disable: 2134)    // Possible infinite loop"
                FPRINT FP_HDR, "    #pragma warn(disable: 2154)    // Buggy unreachable code warning using sizeof"
                FPRINT FP_HDR, "    #pragma warn(disable: 2197)    // Unsigned long int not a std bit-field type"
                FPRINT FP_HDR, "    #pragma warn(disable: 2215)    // Conversion from type1 to type2 warnings"
                FPRINT FP_HDR, "    #pragma warn(disable: 2218)    // Unreferenced parameter"
                FPRINT FP_HDR, "    #pragma warn(disable: 2230)    // Incomplete struct declarations (vbs support)"
                FPRINT FP_HDR, "    #pragma warn(disable: 2232)    // Unable to check variable arguments"
                FPRINT FP_HDR, "    #pragma warn(disable: 2235)    // Not all control paths return a value"
                FPRINT FP_HDR, "    #pragma warn(disable: 2241)    // Function marked for deprecation"
                FPRINT FP_HDR, "    #pragma warn(disable: 2243)    // Use parentheses to clarify"
                FPRINT FP_HDR, "    #pragma warn(disable: 2248)    // Non-portable use of extension"
                FPRINT FP_HDR, "    #pragma warn(disable: 2250)    // Shadowing variable"
                FPRINT FP_HDR, "    #pragma warn(disable: 2251)    // Types with different signedness"
                FPRINT FP_HDR, "    #pragma warn(disable: 2804)    // Consider changing type to size_t warnings"
                FPRINT FP_HDR, "    #pragma warn(disable: 2805)    // Possible anti-aliasing violation warnings"
                FPRINT FP_HDR, "    #pragma warn(disable: 2808)    // Unsequenced assignment warnings"
                FPRINT FP_HDR, "    #pragma warn(disable: 2810)    // Potential realloc warnings"
                FPRINT FP_HDR, "    #pragma warn(disable: 2812)    // Attempt to read from non-readable location"
                FPRINT FP_HDR, "    #pragma warn(disable: 2813)    // Possible out-of-bounds warning (caused by CAST)"
            END IF
            FPRINT FP_HDR, "#endif"
            FPRINT FP_HDR, ""
        END IF
    END IF
END SUB ' Emit_CompilerDefines



SUB Emit_System_Vars(FP_OUTPUT AS FILE)
    IF Use_Console       OR _
        Use_Findfirst    OR _
        Use_Findnext     OR _
        Use_GoSub        OR _
        Use_BcxTempStr   OR _
        Use_Ldouble      OR _
        Use_Crlf         OR _
        Use_Inputbox     OR _
        Use_Infobox      OR _
        Use_Inputbuffer  OR _
        Use_BCX_Splitter OR _
        Use_Dynacall     OR _
        Use_DynacallA    OR _
        Use_LCaseTbl     OR _
        Use_UCaseTbl     THEN

        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, "//             " + c_$BCX_STR_SYS_VARS
        FPRINT FP_OUTPUT, "// *************************************************"
        FPRINT FP_OUTPUT, SPC$
    END IF


    IF Use_BCX_Splitter THEN
        FPRINT FP_OUTPUT, "static ULONG SplitBarFG=RGB(0,0,255);"
        FPRINT FP_OUTPUT, "static ULONG SplitBarBG=RGB(212,212,212);"
        FPRINT FP_OUTPUT, "#define SPLITBAR_SIZE 2"
        FPRINT FP_OUTPUT, "#define MIN_PANESIZE 4"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "typedef struct _SPLITTERINFO{"
        FPRINT FP_OUTPUT, "   BOOL  fMovingBar;"
        FPRINT FP_OUTPUT, "   HWND  hwPane1;"
        FPRINT FP_OUTPUT, "   HWND  hwPane2;"
        FPRINT FP_OUTPUT, "   int   percent;"
        FPRINT FP_OUTPUT, "   int   splittype;"
        FPRINT FP_OUTPUT, "   int   swsStyle;"
        FPRINT FP_OUTPUT, "   HCURSOR  hCursor;"
        FPRINT FP_OUTPUT, "}SPLITTERINFO, *LPSPLITTERINFO;"
        FPRINT FP_OUTPUT, SPC$
    END IF

    IF Use_Ldouble THEN
        FPRINT FP_OUTPUT, "#define LDOUBLE long double"
    END IF

    IF Use_Idxqsort THEN
        FPRINT FP_OUTPUT, "char*** pppStr;"
    END IF

    IF Use_Idxqsort OR Use_IdxqsortSt OR Use_PtrqsortSt THEN
        FPRINT FP_OUTPUT, "int     Key;"
    END IF

    IF Use_IdxqsortSt THEN
        FPRINT FP_OUTPUT, "char*   cmp1;"
        FPRINT FP_OUTPUT, "int     StructSize;"
    END IF

    IF Use_PtrqsortSt THEN
        FPRINT FP_OUTPUT, "int     OffSet;"
    END IF

    IF Use_Sound THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#define SNDQUE 10000"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "typedef struct _soundtype {"
        FPRINT FP_OUTPUT, "   float  Freq;"
        FPRINT FP_OUTPUT, "   int    Dura;"
        FPRINT FP_OUTPUT, "   int    Vol;"
        FPRINT FP_OUTPUT, "   int    Voice;"
        FPRINT FP_OUTPUT, "   float  Tempo;"
        FPRINT FP_OUTPUT, "   int    sndTid;"
        FPRINT FP_OUTPUT, "} soundtype, *LPSOUNDTYPE;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static soundtype  SndPmtr[SNDQUE+1];"
        FPRINT FP_OUTPUT, "static UINT       gTenter;"
        FPRINT FP_OUTPUT, "static UINT       gTwait;"
        FPRINT FP_OUTPUT, "static UINT       gTexit;"
        FPRINT FP_OUTPUT, "static UINT       gTarray;"
        FPRINT FP_OUTPUT, "static BOOL       gTsig;"
        FPRINT FP_OUTPUT, "static HANDLE     gSThread=NULL;"
        FPRINT FP_OUTPUT, "static HMIDIOUT   hMidi;"
        FPRINT FP_OUTPUT, SPC$
    END IF

    IF Use_BCX_Fontdlg THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "typedef struct _BCX_FONT_TYPE {"
        FPRINT FP_OUTPUT, "   LOGFONT lf;"
        FPRINT FP_OUTPUT, "   int  SIZE;"
        FPRINT FP_OUTPUT, "   int  RGB;"
        FPRINT FP_OUTPUT, "} BCX_FONT_TYPE;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "BCX_FONT_TYPE BCX_FONT;"
        FPRINT FP_OUTPUT, SPC$
    END IF

    '************************************************************************

    IF Use_NUL THEN
        FPRINT FP_OUTPUT, "static char    NUL [1]={0};        // Null"
    END IF

    IF Use_BEL THEN
        FPRINT FP_OUTPUT, "static char    BEL [2]={7,0};      // Bell"
    END IF

    IF Use_BS THEN
        FPRINT FP_OUTPUT, "static char    BS  [2]={8,0};      // Back Space"
    END IF

    IF Use_TAB THEN
        FPRINT FP_OUTPUT, "static char    TAB [2]={9,0};      // Horz Tab"
    END IF

    IF Use_LF THEN
        FPRINT FP_OUTPUT, "static char    LF  [2]={10,0};     // Line Feed"
    END IF

    IF Use_VT THEN
        FPRINT FP_OUTPUT, "static char    VT  [2]={11,0};     // Vert Tab"
    END IF

    IF Use_FF THEN
        FPRINT FP_OUTPUT, "static char    FF  [2]={12,0};     // Form Feed"
    END IF

    IF Use_CR THEN
        FPRINT FP_OUTPUT, "static char    CR  [2]={13,0};     // Carr Rtn"
    END IF

    IF Use_EF THEN
        FPRINT FP_OUTPUT, "static char    EF  [2]={26,0};     // End-of-File"
    END IF

    IF Use_ESC THEN
        FPRINT FP_OUTPUT, "static char    ESC [2]={27,0};     // Escape"
    END IF

    IF Use_SPC THEN
        FPRINT FP_OUTPUT, "static char    SPC [2]={32,0};     // Space"
    END IF

    IF Use_DQ THEN
        FPRINT FP_OUTPUT, "static char    DQ  [2]={34,0};     // Double-Quote"
    END IF

    IF Use_DDQ THEN
        FPRINT FP_OUTPUT, "static char    DDQ [3]={34,34,0};  // Double-Double-Quote"
    END IF

    IF Use_Crlf THEN
        FPRINT FP_OUTPUT, "static char    CRLF[3]={13,10,0};  // Carr Rtn & Line Feed"
    END IF

    '****************************************************************************

    IF Use_Inputbox THEN
        FPRINT FP_OUTPUT, "char   BCX_INPUTBOX_VAL[BCXSTRSIZE];"
    END IF

    IF Use_Cursor THEN
        FPRINT FP_OUTPUT, "static COORD   cursor;             // holds coordinates of cursor"
    END IF

    IF Use_Console THEN
        FPRINT FP_OUTPUT, "static HANDLE  hConsole;           // handle of console window"
    END IF

    IF Use_Cls OR Use_Color THEN
        FPRINT FP_OUTPUT, "static int     color_fg = 7;       // forground color set to default"
        FPRINT FP_OUTPUT, "static int     color_bg = 0;       // background color set to default"
    END IF

    IF Use_Consolesize THEN
        FPRINT FP_OUTPUT, "static int     BcxSaveConX;"
        FPRINT FP_OUTPUT, "static int     BcxSaveConY;"
    END IF

    IF Use_PushPopColors THEN
        FPRINT FP_OUTPUT, "static int     color_pshpop;       // Push / Pop Color storage"
    END IF


    IF Use_Scan THEN
        FPRINT FP_OUTPUT, "static int     ScanError;          // holds last error from scan function"
    END IF


    IF Use_Inputbuffer THEN
        FPRINT FP_OUTPUT, "static char    InputBuffer[2048];"   ' 832 MrBcx changed
    END IF


    IF Use_Hook THEN
        FPRINT FP_OUTPUT, "static HHOOK   CmDlgHook;"
    END IF


    IF Use_GoSub THEN
        FPRINT FP_OUTPUT, "static jmp_buf GosubStack[32];"
        FPRINT FP_OUTPUT, "static int     GosubNdx;"
    END IF


    IF Use_LCaseTbl THEN
        FPRINT FP_OUTPUT, "static unsigned char*  LowCase;"
    END IF

    IF Use_UCaseTbl THEN
        FPRINT FP_OUTPUT, "static unsigned char*  UprCase;"
    END IF

    IF Use_Findfirst OR Use_Findnext THEN
        FPRINT FP_OUTPUT, "static HANDLE  fffn_FileHandle;"
        FPRINT FP_OUTPUT, "static WIN32_FIND_DATA fffn_FindData;"
    END IF

    IF Use_DynacallCommon THEN
        FPRINT FP_OUTPUT, "static  HINSTANCE BCX_DllStore[256];"
    END IF

    FPRINT FP_OUTPUT, SPC$
END SUB ' Emit_System_Vars



SUB Emit_Assignments(FuncRetnFlag AS INT PTR)
    '********************************
    LOCAL strtest, varid, vi AS UDT_VARINFO_STORAGE PTR, vr$, brcnt, LTmp$
    LOCAL eo_H, eo_I, eo_J, eo_K
    LOCAL HasStorage
    DIM RAW Arg$
    DIM RAW EqlSgnPos

    IF Ndx = 0 THEN EXIT SUB

    FOR i AS INT = 1 TO Ndx
        IF Im_UDT_String (Stk$[i]) THEN Stk$[i] += "$"
        IF Im_UDT_Single (Stk$[i]) THEN Stk$[i] += "!"
        IF Im_UDT_Double (Stk$[i]) THEN Stk$[i] += "#"
    NEXT

    FOR EqlSgnPos = 1 TO Ndx
        IF *Stk$[EqlSgnPos] = ASC("=") THEN
            IF NOT(*Stk$[EqlSgnPos-1] = ASC("<") OR _
                *Stk$[EqlSgnPos-1] = ASC(">")    OR _
                *Stk$[EqlSgnPos-1] = ASC("+")    OR _
                *Stk$[EqlSgnPos-1] = ASC("-")    OR _
                *Stk$[EqlSgnPos-1] = ASC("/")    OR _
                *Stk$[EqlSgnPos-1] = ASC("*"))   THEN
                EXIT FOR
            END IF
        END IF
    NEXT

    IF EqlSgnPos - 1 = Ndx THEN
        CALL BuildCleanStr(1, Ndx, LTmp$)
        LTmp$ += ";"
        IF *FuncRetnFlag = 2 THEN
            FPRINT FP_WRITE, LTmp$
        ELSE
            FPRINT FP_WRITE, Scoot$, LTmp$
        END IF
        IF *FuncRetnFlag = 2 THEN
            *FuncRetnFlag = 0
            Stk$[1] = ""
            EXIT SUB
        END IF
        EXIT SUB
    END IF

    FOR eo_I = 2 TO EqlSgnPos-1
        Stk$[1] += Stk$[eo_I]
    NEXT

    '*************************  825 New Block added by MrBcx  ****************

    IF Im_UDT_String(Stk$[1]) THEN
        Stk$[1] += "$"
        FOR i AS INT = EqlSgnPos + 1 TO Ndx
            IF Stk$[i] = "+" THEN
                IF Stk$[i+1] = "+" THEN EXIT FOR
                Stk$[i] = "&"
                EXIT FOR
            END IF
        NEXT
    END IF

    '*************************************************************************

    eo_H = INCHR(Stk$[1], "*")
    IF eo_H THEN
        IF NOT (INCHR(Stk$[1], "$") AND eo_H > 1) THEN
            RemoveAll(Stk$[1], "$")
            GOTO ProcessNumeric
        END IF
    END IF

    '*************************************************************************
    '                    Process a string expression
    '*************************************************************************

    strtest = DataType(Stk$[1])

    IF *Stk$[1] <> ASC("(") THEN
        IF strtest = vt_UNKNOWN THEN
            Stk$[1] += "$"
            strtest = vt_STRVAR
        END IF
    END IF

    IF strtest = vt_INTEGER THEN
        brcnt = TALLY(Stk$[1], "[")
        vr$ = EXTRACT$(Stk$[1], "[")
        strtest = CheckLocal(vr$, ADDRESSOF(varid))

        IF strtest = vt_UNKNOWN THEN
            strtest = CheckGlobal(vr$, ADDRESSOF(varid))
            vi = ADDRESSOF((GlobalVars[varid]))
        ELSE
            vi = ADDRESSOF((LocalVars[varid]))
        END IF

        IF strtest = vt_CHAR OR strtest = vt_SCHAR THEN
            strtest = vt_STRVAR
        END IF

        IF strtest = vt_STRVAR THEN
            IF NOTZERO (vi->VarPntr) THEN
                GOTO ProcessNumeric
            END IF
            IF TALLY(vi->VarDim, "[") = brcnt THEN
                GOTO ProcessNumeric
            END IF
            IF TALLY(vi->VarDim, "[") <> brcnt + 1 THEN
                GOTO ProcessNumeric
            END IF
        END IF
    END IF

    '*************************************************************************
    '       NOTE: Do not relocate this UDT-CHECK block         - MrBcx
    '*************************************************************************

    IF strtest = vt_UNKNOWN THEN
        IF NOT INCHR(Stk$[1], "$") THEN
            IF Im_UDT_String (Stk$[1]) THEN
                Stk$[1] += "$"
                strtest = vt_STRVAR
            END IF
        END IF
    END IF

    IF strtest = vt_UNKNOWN THEN
        IF NOT INCHR(Stk$[1], "!") THEN
            IF Im_UDT_Single (Stk$[1]) THEN
                Stk$[1] += "!"
                strtest = vt_SINGLE
            END IF
        END IF
    END IF

    IF strtest = vt_UNKNOWN THEN
        IF NOT INCHR(Stk$[1], "#") THEN
            IF Im_UDT_Double (Stk$[1]) THEN
                Stk$[1] += "#"
                strtest = vt_DOUBLE
            END IF
        END IF
    END IF

    '****************************************************************************
    '           This is where we assign a value to a string variable
    '****************************************************************************

    IF strtest = vt_STRVAR THEN

        '************************************************************************
        ' 830 MrBcx -- prevent translation errors in statements like:
        '              postfix = postfix + InToPost (subexpr$) + " ? "
        '
        ' 838 MrBcx -- also sigil-unknown tokens after "+", e.g. wfd.cFileName
        '              Additional guard added for improved string translations
        '
        CALL NormalizeStrConcat  ' 838 refactored into a SUB for readability
        '************************************************************************

        IF EqlSgnPos + 1 = Ndx THEN
            IF Stk$[Ndx] = DDQ$ THEN
                FPRINT FP_WRITE, Scoot$, "*", No_Sigil$(Stk$[1]), "=0;"
                GOTO StringExit
            END IF
        END IF

        ' [ Speedup No. 1 ] *****************************************************

        IF Ndx = 3 THEN
            Stk$[1] = No_Sigil$(Stk$[1])
            Stk$[3] = No_Sigil$(Stk$[3])
            IF Stk$[1] = "BCX_RetStr" THEN
                FPRINT FP_WRITE, Scoot$, "BCX_RetStr = BCX_TempStr(strlen(", Stk$[3], "));"
            END IF
            FPRINT FP_WRITE, Scoot$, "strcpy(", Stk$[1], ",", Stk$[3], ");"
            GOTO StringExit
        END IF

        '***********************
        Arg$  = ""
        LTmp$ = ""
        eo_J = eo_K = 0
        '***********************

        IF m_iMatchLft(Stk$[3], "$$") THEN HasStorage = TRUE

        Var$ = No_Sigil$(Stk$[1])

        IF No_Sigil$(Stk$[EqlSgnPos+1]) = Var$ THEN
            eo_K = TRUE
        END IF

        FOR eo_H = EqlSgnPos+1 TO Ndx
            IF Stk$[eo_H] = "&" AND Stk$[eo_H-1] <> "," AND Stk$[eo_H-1] <> "(" THEN
                INCR eo_J
                Arg$ += LTmp$
                LTmp$ = ","
            ELSE
                LTmp$ += No_Sigil$(Stk$[eo_H])
            END IF
        NEXT

        IF NOTNULL (LTmp$) AND LTmp$ <> "," THEN
            Arg$ += LTmp$
        END IF

        '*************************************************************************
        '               String Assignment Construction Rules
        '*************************************************************************
        '           IF eo_J = 0 & K = ANY       THEN use strcpy
        '           IF eo_J = 1 & K = TRUE      THEN use strcat
        '           Everything else             THEN use join
        '*************************************************************************

        RemoveAll(Var$, SPC$)

        IF eo_J = 0 THEN
            IF Var$ = "BCX_RetStr" THEN
                IF HasStorage THEN
                    FPRINT FP_WRITE, Scoot$, "BCX_RetStr=", Arg$, ";"
                    GOTO StringExit
                ELSE
                    FPRINT FP_WRITE, Scoot$, "BCX_RetStr = BCX_TempStr(strlen(", Arg$, "));"
                END IF
            END IF
            IF RIGHT$(Var$, 3) = "[0]" AND Arg$ = "0" THEN
                FPRINT FP_WRITE, Scoot$, Var$, " = 0;"
            ELSE
                FPRINT FP_WRITE, Scoot$, "strcpy(", Var$, ",", Arg$, ");"
            END IF
            GOTO StringExit
        END IF

        IF eo_K = TRUE AND eo_J = 1 THEN
            FPRINT FP_WRITE, Scoot$, "strcat(", Arg$, ");"
            GOTO StringExit
        END IF

        LTmp$ = STR$(++eo_J, 1)
        Use_Join = Use_BcxTempStr = TRUE

        IF Var$ = "BCX_RetStr" THEN
            FPRINT FP_WRITE, Scoot$, "BCX_RetStr=join(", LTmp$, ",", Arg$, ");"
        ELSE
            FPRINT FP_WRITE, Scoot$, "strcpy(", Var$, ", join(", LTmp$, ",", Arg$, "));"
        END IF

        StringExit:
        EXIT SUB
        '***********************

    ELSE

        '***********************
        ProcessNumeric:
        '***********************

        FOR i AS INT = 1 TO Ndx
            IF Stk$[i] = "!=" THEN Stk$[i] = CHR$(198, 230)
        NEXT

        FOR eo_I = 2 TO EqlSgnPos
            Stk$[eo_I] = ""
        NEXT

        Stk$[EqlSgnPos] = "="

        IF Stk$[EqlSgnPos+1] = Stk$[1] AND Ndx = 5 THEN
            IF INSTR(Stk$[EqlSgnPos+2], ANY "+-*/") AND Stk$[EqlSgnPos+3] <> ">" THEN
                Stk$[EqlSgnPos] = Stk$[EqlSgnPos+2] + Stk$[EqlSgnPos]
                Stk$[EqlSgnPos+1] = ""
                Stk$[EqlSgnPos+2] = ""
            END IF
        END IF

        FOR eo_H = 2 TO Ndx
            IF isdigit(*Stk$[eo_H]) AND m_iMatchRgt(Stk$[eo_H], "E") THEN
                Stk$[eo_H] += Stk$[eo_H+1]
                IF *Stk$[eo_H+1] = ASC("-") THEN
                    Stk$[eo_H] += Stk$[eo_H+2]
                    Stk$[eo_H+2] = ""
                END IF
                Stk$[eo_H+1] = ""
            END IF
        NEXT

        FPRINT FP_WRITE, Scoot$, No_Sigil$(Stk$[1]);
        LOCAL eo_FoundEql
        FOR A AS INT = 2 TO Ndx
            IF *Stk$[A] = ASC("=") THEN eo_FoundEql = TRUE
            IF *Stk$[A] = ASC("!") THEN
                FPRINT FP_WRITE, "!";
                IF eo_FoundEql = FALSE THEN
                    IF *Stk$[A-1] <> ASC("=") THEN
                        REPLACE CHR$(198, 230) WITH "!=" IN Stk$[A-1]
                        FPRINT FP_WRITE, "=";
                    END IF
                END IF
            ELSE
                Stk$[A] = No_Sigil$(Stk$[A])
                REPLACE CHR$(198, 230) WITH "!=" IN Stk$[A]
                FPRINT FP_WRITE, Stk$[A];
            END IF
            IF A < Ndx THEN
                IF ISFALSE(ispunct(*Stk$[A+1])) THEN FPRINT FP_WRITE, "";
            END IF
        NEXT
        FPRINT FP_WRITE, ";"
    END IF
END SUB ' Emit_Assignments



'***************************************************************************************************
'                          Begin Standard BCX Runtime Library Functions
'***************************************************************************************************


SUB Emit_RuntimeFunctions (FP_OUTPUT AS FILE)
    FPRINT FP_OUTPUT, SPC$
    FPRINT FP_OUTPUT, "// *************************************************"
    FPRINT FP_OUTPUT, "//                 ", c_$BCX_STR_RUNTIME
    FPRINT FP_OUTPUT, "// *************************************************"
    FPRINT FP_OUTPUT, SPC$

    CALL Emit_RT_Dynacall(FP_OUTPUT)
    CALL Emit_RT_StringCore(FP_OUTPUT)
    CALL Emit_RT_StringUtils(FP_OUTPUT)
    CALL Emit_RT_FileDialogs(FP_OUTPUT)
    CALL Emit_RT_FormatPath1(FP_OUTPUT)
    CALL Emit_RT_FormatPath2(FP_OUTPUT)
    CALL Emit_RT_FileAttrClip1(FP_OUTPUT)
    CALL Emit_RT_FileAttrClip2(FP_OUTPUT)
    CALL Emit_RT_SortDynamic(FP_OUTPUT)
    CALL Emit_RT_SplitConsole(FP_OUTPUT)
    CALL Emit_RT_Controls1(FP_OUTPUT)
    CALL Emit_RT_Controls2(FP_OUTPUT)
    CALL Emit_RT_Graphics1(FP_OUTPUT)
    CALL Emit_RT_Graphics2(FP_OUTPUT)
    CALL Emit_RT_SystemCOM1(FP_OUTPUT)
    CALL Emit_RT_SystemCOM2(FP_OUTPUT)
END SUB ' Emit_RuntimeFunctions




SUB Emit_RT_Dynacall (FP_OUTPUT AS FILE)
    IF Use_Dynacall OR Use_DynacallA THEN
        FPRINT FP_OUTPUT, "HINSTANCE BCX_LoadDll (PCTSTR DllName)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static int DllCnt;"
        FPRINT FP_OUTPUT, "  static int RegUnload;"
        FPRINT FP_OUTPUT, "  if (!RegUnload) RegUnload =! atexit(BCX_UnloadDll);"
        FPRINT FP_OUTPUT, "  DllCnt = (DllCnt+1) & 255;"
        FPRINT FP_OUTPUT, "  FreeLibrary(BCX_DllStore[DllCnt]);"
        FPRINT FP_OUTPUT, "  return BCX_DllStore[DllCnt] = LoadLibrary(DllName);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void BCX_UnloadDll (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int ii;"
        FPRINT FP_OUTPUT, "  for(ii = 255;ii >= 0;ii--)"
        FPRINT FP_OUTPUT, "    FreeLibrary(BCX_DllStore[ii]);"
        FPRINT FP_OUTPUT, "}\n\n"

        IF Use_DynacallA THEN             ' Updated by MrBcx in 833
            FPRINT FP_OUTPUT, "INT_PTR BCX_DynaCallA(PCTSTR DllName, PCTSTR FuncName, int nArgs, INT_PTR argtable[])"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "    HINSTANCE hInst = 0;"
            FPRINT FP_OUTPUT, "    FARPROC lpFunc = 0;"
            FPRINT FP_OUTPUT, "    INT_PTR result = 0;"
            FPRINT FP_OUTPUT, "    char buff[256];"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    // Validate argument count"
            FPRINT FP_OUTPUT, "    if (nArgs < 0 || nArgs > 16) {"
            FPRINT FP_OUTPUT, "        return 0;"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    // Load the DLL"
            FPRINT FP_OUTPUT, "    hInst = GetModuleHandle(DllName);"
            FPRINT FP_OUTPUT, "    if (hInst == NULL) {"
            FPRINT FP_OUTPUT, "        hInst = BCX_LoadDll(DllName);"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    if (hInst == NULL) {"
            FPRINT FP_OUTPUT, "        return 0;"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    // Find the function"
            FPRINT FP_OUTPUT, "    lpFunc = GetProcAddress(hInst, FuncName);"
            FPRINT FP_OUTPUT, "    if (lpFunc == NULL) {"
            FPRINT FP_OUTPUT, "        sprintf(buff, ", ENC$("%s%s"), ", FuncName, ", ENC$("A"), ");"
            FPRINT FP_OUTPUT, "        lpFunc = GetProcAddress(hInst, buff);"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    if (lpFunc == NULL) {"
            FPRINT FP_OUTPUT, "        sprintf(buff, ", ENC$("_%s"), ", FuncName);"
            FPRINT FP_OUTPUT, "        lpFunc = GetProcAddress(hInst, buff);"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    if (lpFunc == NULL) {"
            FPRINT FP_OUTPUT, "        return 0;"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    // Call the function with properly typed function pointers"
            FPRINT FP_OUTPUT, "    // Using DWORD_PTR for consistency with DynaCallB"
            FPRINT FP_OUTPUT, "    switch (nArgs) {"
            FPRINT FP_OUTPUT, "        case 0: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func0)();"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func0)lpFunc)();"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 1: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func1)(DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func1)lpFunc)((DWORD_PTR)argtable[0]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 2: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func2)(DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func2)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 3: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func3)(DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func3)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 4: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func4)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func4)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 5: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func5)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func5)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                              (DWORD_PTR)argtable[4]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 6: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func6)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func6)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                              (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 7: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func7)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func7)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                              (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 8: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func8)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func8)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                              (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6], (DWORD_PTR)argtable[7]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 9: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func9)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func9)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                              (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6], (DWORD_PTR)argtable[7],"
            FPRINT FP_OUTPUT, "                                              (DWORD_PTR)argtable[8]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 10: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func10)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func10)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6], (DWORD_PTR)argtable[7],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[8], (DWORD_PTR)argtable[9]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 11: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func11)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func11)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6], (DWORD_PTR)argtable[7],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[8], (DWORD_PTR)argtable[9], (DWORD_PTR)argtable[10]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 12: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func12)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func12)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6], (DWORD_PTR)argtable[7],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[8], (DWORD_PTR)argtable[9], (DWORD_PTR)argtable[10], (DWORD_PTR)argtable[11]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 13: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func13)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func13)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6], (DWORD_PTR)argtable[7],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[8], (DWORD_PTR)argtable[9], (DWORD_PTR)argtable[10], (DWORD_PTR)argtable[11],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[12]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 14: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func14)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func14)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6], (DWORD_PTR)argtable[7],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[8], (DWORD_PTR)argtable[9], (DWORD_PTR)argtable[10], (DWORD_PTR)argtable[11],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[12], (DWORD_PTR)argtable[13]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 15: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func15)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func15)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6], (DWORD_PTR)argtable[7],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[8], (DWORD_PTR)argtable[9], (DWORD_PTR)argtable[10], (DWORD_PTR)argtable[11],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[12], (DWORD_PTR)argtable[13], (DWORD_PTR)argtable[14]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 16: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func16)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func16)lpFunc)((DWORD_PTR)argtable[0], (DWORD_PTR)argtable[1], (DWORD_PTR)argtable[2], (DWORD_PTR)argtable[3],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[4], (DWORD_PTR)argtable[5], (DWORD_PTR)argtable[6], (DWORD_PTR)argtable[7],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[8], (DWORD_PTR)argtable[9], (DWORD_PTR)argtable[10], (DWORD_PTR)argtable[11],"
            FPRINT FP_OUTPUT, "                                               (DWORD_PTR)argtable[12], (DWORD_PTR)argtable[13], (DWORD_PTR)argtable[14], (DWORD_PTR)argtable[15]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    return result;"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF


        IF Use_Dynacall THEN     ' Updated by MrBcx in 833
            ' *************************************************"
            '              CRITICAL FIX EXPLANATION
            ' *************************************************"
            ' The key change is using DWORD_PTR instead of INT_PTR:
            '
            ' 1. DWORD_PTR is defined as:
            '    - 32-bit: unsigned long (4 bytes)
            '    - 64-bit: unsigned __int64 (8 bytes)
            '
            ' 2. INT_PTR is defined as:
            '    - 32-bit: signed int (4 bytes)
            '    - 64-bit: signed __int64 (8 bytes)
            '
            ' 3. The Windows API uses DWORD_PTR for generic pointers (including function pointers)
            '    in many places, especially in callback-related functions like SetWindowSubclass.
            '
            ' 4. Using DWORD_PTR ensures proper alignment and handling when passing function
            '    pointers through variadic arguments on 32-bit systems.
            '
            ' 5. The explicit cast to (INT_PTR) for the result is safe because we're just
            '    returning the value, and the caller will interpret it correctly.
            ' *************************************************

            FPRINT FP_OUTPUT, "INT_PTR BCX_DynaCallB(PCTSTR FuncName, PCTSTR DllName, int nArgs, ...)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "    HINSTANCE hInst = 0;"
            FPRINT FP_OUTPUT, "    FARPROC lpFunc = 0;"
            FPRINT FP_OUTPUT, "    INT_PTR result = 0;"
            FPRINT FP_OUTPUT, "    DWORD_PTR *argtable = NULL;  // Changed to DWORD_PTR to handle all pointer types"
            FPRINT FP_OUTPUT, "    char buff[256];"
            FPRINT FP_OUTPUT, "    va_list ap;"
            FPRINT FP_OUTPUT, "    int i;"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    // Validate argument count"
            FPRINT FP_OUTPUT, "    if (nArgs < 0 || nArgs > 16) {"
            FPRINT FP_OUTPUT, "        return 0;"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    // Load the DLL"
            FPRINT FP_OUTPUT, "    hInst = GetModuleHandle(DllName);"
            FPRINT FP_OUTPUT, "    if (hInst == NULL) {"
            FPRINT FP_OUTPUT, "        hInst = BCX_LoadDll(DllName);"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    if (hInst == NULL) {"
            FPRINT FP_OUTPUT, "        return 0;"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    // Find the function"
            FPRINT FP_OUTPUT, "    lpFunc = GetProcAddress(hInst, FuncName);"
            FPRINT FP_OUTPUT, "    if (lpFunc == NULL) {"
            FPRINT FP_OUTPUT, "        sprintf(buff, ", ENC$("%s%s"), ", FuncName, ", ENC$("A"), ");"
            FPRINT FP_OUTPUT, "        lpFunc = GetProcAddress(hInst, buff);"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    if (lpFunc == NULL) {"
            FPRINT FP_OUTPUT, "        sprintf(buff, ", ENC$("_%s"), ", FuncName);"
            FPRINT FP_OUTPUT, "        lpFunc = GetProcAddress(hInst, buff);"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    if (lpFunc == NULL) {"
            FPRINT FP_OUTPUT, "        return 0;"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    // Allocate argument table"
            FPRINT FP_OUTPUT, "    if (nArgs > 0) {"
            FPRINT FP_OUTPUT, "        argtable = (DWORD_PTR*)malloc(nArgs * sizeof(DWORD_PTR));"
            FPRINT FP_OUTPUT, "        if (argtable == NULL) {"
            FPRINT FP_OUTPUT, "            return 0;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        "
            FPRINT FP_OUTPUT, "        va_start(ap, nArgs);"
            FPRINT FP_OUTPUT, "        for (i = 0; i < nArgs; i++) {"
            FPRINT FP_OUTPUT, "            // Use DWORD_PTR to properly handle all pointer types including function pointers"
            FPRINT FP_OUTPUT, "            argtable[i] = va_arg(ap, DWORD_PTR);"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        va_end(ap);"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    // Call the function with properly typed function pointers"
            FPRINT FP_OUTPUT, "    // Using DWORD_PTR instead of INT_PTR to match Windows API conventions"
            FPRINT FP_OUTPUT, "    switch (nArgs) {"
            FPRINT FP_OUTPUT, "        case 0: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func0)();"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func0)lpFunc)();"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 1: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func1)(DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func1)lpFunc)(argtable[0]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 2: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func2)(DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func2)lpFunc)(argtable[0], argtable[1]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 3: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func3)(DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func3)lpFunc)(argtable[0], argtable[1], argtable[2]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 4: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func4)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func4)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 5: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func5)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func5)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                              argtable[4]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 6: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func6)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func6)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                              argtable[4], argtable[5]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 7: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func7)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func7)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                              argtable[4], argtable[5], argtable[6]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 8: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func8)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func8)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                              argtable[4], argtable[5], argtable[6], argtable[7]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 9: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func9)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func9)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                              argtable[4], argtable[5], argtable[6], argtable[7], "
            FPRINT FP_OUTPUT, "                                              argtable[8]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 10: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func10)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func10)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                               argtable[4], argtable[5], argtable[6], argtable[7], "
            FPRINT FP_OUTPUT, "                                               argtable[8], argtable[9]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 11: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func11)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func11)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                               argtable[4], argtable[5], argtable[6], argtable[7], "
            FPRINT FP_OUTPUT, "                                               argtable[8], argtable[9], argtable[10]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 12: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func12)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func12)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                               argtable[4], argtable[5], argtable[6], argtable[7], "
            FPRINT FP_OUTPUT, "                                               argtable[8], argtable[9], argtable[10], argtable[11]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 13: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func13)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func13)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                               argtable[4], argtable[5], argtable[6], argtable[7], "
            FPRINT FP_OUTPUT, "                                               argtable[8], argtable[9], argtable[10], argtable[11],"
            FPRINT FP_OUTPUT, "                                               argtable[12]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 14: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func14)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func14)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                               argtable[4], argtable[5], argtable[6], argtable[7], "
            FPRINT FP_OUTPUT, "                                               argtable[8], argtable[9], argtable[10], argtable[11],"
            FPRINT FP_OUTPUT, "                                               argtable[12], argtable[13]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 15: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func15)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func15)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                               argtable[4], argtable[5], argtable[6], argtable[7], "
            FPRINT FP_OUTPUT, "                                               argtable[8], argtable[9], argtable[10], argtable[11],"
            FPRINT FP_OUTPUT, "                                               argtable[12], argtable[13], argtable[14]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "        case 16: {"
            FPRINT FP_OUTPUT, "            typedef DWORD_PTR (WINAPI *Func16)(DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR, DWORD_PTR);"
            FPRINT FP_OUTPUT, "            result = (INT_PTR)((Func16)lpFunc)(argtable[0], argtable[1], argtable[2], argtable[3], "
            FPRINT FP_OUTPUT, "                                               argtable[4], argtable[5], argtable[6], argtable[7], "
            FPRINT FP_OUTPUT, "                                               argtable[8], argtable[9], argtable[10], argtable[11],"
            FPRINT FP_OUTPUT, "                                               argtable[12], argtable[13], argtable[14], argtable[15]);"
            FPRINT FP_OUTPUT, "            break;"
            FPRINT FP_OUTPUT, "        }"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    if (argtable) {"
            FPRINT FP_OUTPUT, "        free(argtable);"
            FPRINT FP_OUTPUT, "    }"
            FPRINT FP_OUTPUT, "    "
            FPRINT FP_OUTPUT, "    return result;"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF
    END IF
END SUB ' Emit_RT_Dynacall




SUB Emit_RT_StringCore (FP_OUTPUT AS FILE)
    IF Use_BcxTempStr THEN
        '=========================================================================
        ' BCX_TempStr maintains a circular array of 2048 string buffers.  Each
        ' time it's called, it advances the index (StrCnt), frees any previously
        ' allocated memory at that index, allocates a new buffer of the requested
        ' size, and returns a pointer to this buffer. This approach helps manage
        ' memory efficiently and avoids frequently allocating and deallocating
        ' temporary strings.  Using EnterCriticalSection and LeaveCriticalSection
        ' ensures that only one thread can execute the critical section at a time,
        ' making the function thread-safe.  In addition, every BCX string function
        ' that utilizes BCX_TempStr() inherits some level of thread safety also,
        ' depending upon each function's implementation.
        '=========================================================================
        FPRINT FP_OUTPUT, "char *BCX_TempStr(size_t iBytes)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static int StrCnt;"
        FPRINT FP_OUTPUT, "  static char *StrFunc[2048];"
        FPRINT FP_OUTPUT, "  static CRITICAL_SECTION cs;"
        FPRINT FP_OUTPUT, "  static LONG initialized = 0;"
        FPRINT FP_OUTPUT, "  // Thread-safe one-time initialization"
        FPRINT FP_OUTPUT, "  if (InterlockedCompareExchange(&initialized, 1, 0) == 0) {"
        FPRINT FP_OUTPUT, "      InitializeCriticalSection(&cs);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  // Allocating memory before locking reduces lock duration and blocking."
        FPRINT FP_OUTPUT, "  char *newStr = (char *)calloc(iBytes + 1, sizeof(char));"
        FPRINT FP_OUTPUT, "  if (!newStr) return NULL;"
        FPRINT FP_OUTPUT, "  EnterCriticalSection(&cs);"
        FPRINT FP_OUTPUT, "      StrCnt = (StrCnt + 1) & 2047;"
        FPRINT FP_OUTPUT, "      if (StrFunc[StrCnt]) {"
        FPRINT FP_OUTPUT, "        free(StrFunc[StrCnt]);"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      StrFunc[StrCnt] = newStr;"
        FPRINT FP_OUTPUT, "  LeaveCriticalSection(&cs);"
        FPRINT FP_OUTPUT, "  return StrFunc[StrCnt];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Left THEN
        FPRINT FP_OUTPUT, "char *left (PCTSTR szSrc, int length)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  size_t tmplen = strlen(szSrc);"
        FPRINT FP_OUTPUT, "  if (length < 1) return BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "  if (length < (int)tmplen) tmplen = length;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(tmplen);"
        FPRINT FP_OUTPUT, "  return (char*)memcpy(strtmp, szSrc, tmplen);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Right THEN
        FPRINT FP_OUTPUT, "char *right (PCTSTR szSrc, int length)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  size_t tmplen = strlen(szSrc);"
        FPRINT FP_OUTPUT, "  if (length < 1) return BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "  if ((size_t)length >= tmplen) return strcpy(BCX_TempStr(tmplen), szSrc);"
        FPRINT FP_OUTPUT, "  return strcpy(BCX_TempStr(length), szSrc + (tmplen - length));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Cpad THEN
        FPRINT FP_OUTPUT, "char *cpad (PCTSTR szStr, int i_Max, int c)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char  fill[2]={0}; fill[0] = (char) c;"
        FPRINT FP_OUTPUT, "  char *szTmp = BCX_TempStr(i_Max);"
        FPRINT FP_OUTPUT, "  size_t Half = (i_Max/2) + (strlen(szStr)/2);"
        FPRINT FP_OUTPUT, "  strcpy(szTmp, szStr);"
        FPRINT FP_OUTPUT, "  while((int)strlen(szTmp) < (int)Half)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    strcpy(szTmp, join(2, fill, szTmp));"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  while((int)strlen(szTmp)<i_Max)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    strcat(szTmp, fill);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  szTmp[i_Max] = 0;"
        FPRINT FP_OUTPUT, "  return szTmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Rpad THEN
        FPRINT FP_OUTPUT, "char *rpad (PCTSTR szStr, int L, int c)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp;"
        FPRINT FP_OUTPUT, "  int s = (int)strlen(szStr);"
        FPRINT FP_OUTPUT, "  if ((L-s) < 1) return (char*)szStr;"
        FPRINT FP_OUTPUT, "  strtmp = BCX_TempStr(strlen(szStr)+L);"
        FPRINT FP_OUTPUT, "  strcpy (strtmp, szStr);"
        FPRINT FP_OUTPUT, "  memset (&strtmp[s], c, (L-s));"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Lpad THEN
        FPRINT FP_OUTPUT, "char *lpad (PCTSTR szStr, int L, int c)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp;"
        FPRINT FP_OUTPUT, "  int s = L-(int)strlen(szStr);"
        FPRINT FP_OUTPUT, "  if (s < 1) return (char*)szStr;"
        FPRINT FP_OUTPUT, "  strtmp = BCX_TempStr(L);"
        FPRINT FP_OUTPUT, "  memset (strtmp, c, s);"
        FPRINT FP_OUTPUT, "  return strcat(strtmp, szStr);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Mid THEN
        FPRINT FP_OUTPUT, "char *mid (PCTSTR szSrc, int start, int length)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp;"
        FPRINT FP_OUTPUT, "  int tmplen = (int)strlen(szSrc);"
        FPRINT FP_OUTPUT, "  if (start > tmplen||start < 1) return BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "  if (length < 0 || length > (tmplen-start) + 1)"
        FPRINT FP_OUTPUT, "    length = (tmplen-start) + 1;"
        FPRINT FP_OUTPUT, "  strtmp = BCX_TempStr(length);"
        FPRINT FP_OUTPUT, "  return (char*)memcpy(strtmp, &szSrc[start - 1], length);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Trim THEN
        ' Trims off:  CR, LF, SPACES, and horz and vert TABS
        FPRINT FP_OUTPUT, "char *trim (PCTSTR szSrc)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (0 == szSrc[0]) return (char*)szSrc;"
        FPRINT FP_OUTPUT, "  while(*szSrc == 32 || (*szSrc >= 9 && *szSrc <= 13)) szSrc++;"
        FPRINT FP_OUTPUT, "  size_t i = strlen(szSrc);"
        FPRINT FP_OUTPUT, "  while(i > 0 && (szSrc[i-1] == 32 || (szSrc[i-1] >= 9 && szSrc[i-1] <= 13))) i--;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(i);"
        FPRINT FP_OUTPUT, "  return (char*)memcpy(strtmp, szSrc, i);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Ltrim THEN
        FPRINT FP_OUTPUT, "char *ltrim (PCTSTR szSrc, char c)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (0 == szSrc[0]) return (char*) szSrc;"
        FPRINT FP_OUTPUT, "  while(*szSrc==32 || (*szSrc >= 9 && *szSrc <= 13) || *szSrc == c) szSrc++;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(strlen(szSrc));"
        FPRINT FP_OUTPUT, "  return strcpy(strtmp, szSrc);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Rtrim THEN
        FPRINT FP_OUTPUT, "char *rtrim (PCTSTR szSrc, char c)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (0 == szSrc[0]) return (char*)szSrc;"
        FPRINT FP_OUTPUT, "  size_t i = strlen(szSrc);"
        FPRINT FP_OUTPUT, "  while(i > 0 && (szSrc[i-1]==32 || (szSrc[i-1]>=9 && szSrc[i-1]<=13) || szSrc[i-1]==c)) i--;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(i);"
        FPRINT FP_OUTPUT, "  return (char*)memcpy(strtmp, szSrc, i);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Strim THEN
        FPRINT FP_OUTPUT, "char *strim (PCTSTR szSrc)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (0 == szSrc[0]) return (char*) szSrc;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(strlen(szSrc));"
        FPRINT FP_OUTPUT, "  char *dst = strtmp;"
        FPRINT FP_OUTPUT, "  while (isspace((unsigned char)*szSrc)) szSrc++;"
        FPRINT FP_OUTPUT, "  do"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    while (*szSrc && !isspace((unsigned char)*szSrc)) *dst++ = *szSrc++;"
        FPRINT FP_OUTPUT, "    if (*szSrc)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      *dst++ = *szSrc++;"
        FPRINT FP_OUTPUT, "      while (isspace((unsigned char)*szSrc)) szSrc++;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  while (*szSrc);"
        FPRINT FP_OUTPUT, "  if (isspace((unsigned char)*(--dst))) *dst = 0;"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Command THEN
        FPRINT FP_OUTPUT, "char *command (int nArg)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int ii = 0;"
        FPRINT FP_OUTPUT, "  char *c = NULL, *retstr, *s = GetCommandLine();"
        FPRINT FP_OUTPUT, "  if (nArg < ii) // return entire commandline"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    while(*s && *s != 32)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (*s == 34) while(*++s && *s != 34);"
        FPRINT FP_OUTPUT, "      s++;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    while(isspace((unsigned char)*s))s++;"
        FPRINT FP_OUTPUT, "    retstr = BCX_TempStr(strlen(s)+1);"
        FPRINT FP_OUTPUT, "    strcpy(retstr, s);"
        FPRINT FP_OUTPUT, "    if (*(retstr + strlen(retstr)-1)==20) *retstr=0;"
        FPRINT FP_OUTPUT, "    return retstr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  while(ii <= nArg)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    while(isspace((unsigned char)*s)) s++; // skip whitespace"
        FPRINT FP_OUTPUT, "    c = s;"
        FPRINT FP_OUTPUT, "    if (*s == 34) {              // argument starts a quote"
        FPRINT FP_OUTPUT, "      while(*++s && *s != 34)    // skip until next quote"
        FPRINT FP_OUTPUT, "        ;                        // Do NOT remove this semicolon"
        FPRINT FP_OUTPUT, "      if (*s) s++;               // skip quote itself"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      while(*s && *s != 32) s++;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    ii++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (*c == 34)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    c++;                       // skip leading quote"
        FPRINT FP_OUTPUT, "    if (*(s-1) == 34) s--;     // skip any trailing quotes"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  retstr = BCX_TempStr((int)(s - c) + 1);"
        FPRINT FP_OUTPUT, "  strncpy(retstr, c,(int)(s - c));"
        FPRINT FP_OUTPUT, "  retstr[s-c]=0;"
        FPRINT FP_OUTPUT, "  return retstr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Extract THEN
        FPRINT FP_OUTPUT, "char *extract (PCTSTR strSrc, PCTSTR strPattern)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  PCTSTR szMatch;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(strlen(strSrc));"
        FPRINT FP_OUTPUT, "  if (*strPattern != 0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    szMatch = strstr(strSrc, strPattern);"
        FPRINT FP_OUTPUT, "    if (szMatch) return (char*)memcpy(strtmp, strSrc, szMatch-strSrc);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return strcpy(strtmp, strSrc);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_ExtractAny THEN
        FPRINT FP_OUTPUT, "char *extractany(PCTSTR strSrc, PCTSTR strPattern)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *strtmp;"
        FPRINT FP_OUTPUT, "   int i, j;"
        FPRINT FP_OUTPUT, "   int nLenSrc = (int)strlen(strSrc);"
        FPRINT FP_OUTPUT, "   int nLenPat = (int)strlen(strPattern);"
        FPRINT FP_OUTPUT, "   for (i = 0; i < nLenSrc; ++i)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       for (j = 0; j < nLenPat; ++j)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           if (strSrc[i] == strPattern[j])"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               strtmp = BCX_TempStr(i);"
        FPRINT FP_OUTPUT, "               return (char *)memcpy(strtmp, strSrc, i);"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   strtmp = BCX_TempStr(nLenSrc);"
        FPRINT FP_OUTPUT, "   return strcpy(strtmp, strSrc);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Remain THEN
        FPRINT FP_OUTPUT, "char *remain (PCTSTR strSrc, PCTSTR strPattern)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  PCTSTR p = strstr(strSrc, strPattern);"
        FPRINT FP_OUTPUT, "  if (p)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    p += (strlen(strPattern));"
        FPRINT FP_OUTPUT, "    return (char*)p;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return (char*)strSrc;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_RemainAny THEN
        FPRINT FP_OUTPUT, "char* remainany (PCTSTR strSrc, PCTSTR strPattern)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  PCTSTR p = strSrc;"
        FPRINT FP_OUTPUT, "  PCTSTR found = NULL;"
        FPRINT FP_OUTPUT, "  size_t minPos = strlen(strSrc);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Search for each character in strPattern"
        FPRINT FP_OUTPUT, "  while (*strPattern)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      PCTSTR temp = strchr(p, *strPattern);"
        FPRINT FP_OUTPUT, "      if (temp && (temp - strSrc) < minPos)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          minPos = temp - strSrc;"
        FPRINT FP_OUTPUT, "          found = temp;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      strPattern++;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // If any character was found, return string after first match"
        FPRINT FP_OUTPUT, "    if (found)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        return (char*)(found + 1);"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // No match found, return first argument"
        FPRINT FP_OUTPUT, "  return (char*)strSrc;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Replace THEN
        FPRINT FP_OUTPUT, "char *replace(PCTSTR szMain, PCTSTR szFind, PCTSTR szRepl)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   size_t LenPat, LenRep, iTmp, iChange;"
        FPRINT FP_OUTPUT, "   char *strtmp, *cp_p, *cp_q, *cp_r;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (!szFind || !*szFind)"
        FPRINT FP_OUTPUT, "      return (char*) szMain;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   LenRep = strlen(szRepl);"
        FPRINT FP_OUTPUT, "   LenPat = strlen(szFind);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   for (iTmp = 0, cp_p = (char*)szMain; (cp_q = strstr(cp_p, (char*)szFind)) != 0; cp_p = cp_q + LenPat)"
        FPRINT FP_OUTPUT, "      iTmp += (int)(cp_q - cp_p) + LenRep;"
        FPRINT FP_OUTPUT, "   iTmp += strlen(cp_p);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   strtmp = BCX_TempStr(iTmp);"
        FPRINT FP_OUTPUT, "   if (!strtmp)"
        FPRINT FP_OUTPUT, "      return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   for (cp_r = strtmp, cp_p = (char*)szMain; (cp_q = strstr(cp_p, (char*)szFind)) != 0; cp_p = cp_q + LenPat)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "      iChange = (int)(cp_q - cp_p);"
        FPRINT FP_OUTPUT, "      memcpy(cp_r, cp_p, iChange);"
        FPRINT FP_OUTPUT, "      cp_r += iChange;"
        FPRINT FP_OUTPUT, "      strcpy(cp_r, szRepl);"
        FPRINT FP_OUTPUT, "      cp_r += LenRep;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   strcpy(cp_r, cp_p);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_iReplace THEN
        FPRINT FP_OUTPUT, "char *iReplace(PCTSTR szMain, PCTSTR szFind, PCTSTR szRepl)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   size_t LenPat, LenRep, tmpsz, iChange;"
        FPRINT FP_OUTPUT, "   char *strtmp, *cp_p, *cp_q, *cp_r;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (!szFind || !*szFind)"
        FPRINT FP_OUTPUT, "      return (char*)szMain;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   LenRep = (int)strlen(szRepl);"
        FPRINT FP_OUTPUT, "   LenPat = (int)strlen(szFind);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   for (tmpsz = 0, cp_p = (char*)szMain; (cp_q = _stristr_(cp_p, (char*)szFind)) != 0; cp_p = cp_q + LenPat)"
        FPRINT FP_OUTPUT, "      tmpsz += (int)(cp_q - cp_p) + LenRep;"
        FPRINT FP_OUTPUT, "   tmpsz += strlen(cp_p);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   strtmp = BCX_TempStr(tmpsz);"
        FPRINT FP_OUTPUT, "   if (!strtmp)"
        FPRINT FP_OUTPUT, "      return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   for (cp_r = strtmp, cp_p = (char*)szMain; (cp_q = _stristr_(cp_p, (char*)szFind)) != 0; cp_p = cp_q + LenPat)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "      iChange = (int)(cp_q - cp_p);"
        FPRINT FP_OUTPUT, "      memcpy(cp_r, cp_p, iChange);"
        FPRINT FP_OUTPUT, "      cp_r += iChange;"
        FPRINT FP_OUTPUT, "      strcpy(cp_r, (char*)szRepl);"
        FPRINT FP_OUTPUT, "      cp_r += LenRep;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   strcpy(cp_r, cp_p);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_ReplaceAny THEN
        FPRINT FP_OUTPUT, "char *ReplaceAny(PCTSTR sMainString, PCTSTR sMatchPattern, PCTSTR sReplaceWith)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *BCX_RetStr = NULL;"
        FPRINT FP_OUTPUT, "   char CopyMain[BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "   int nLenMain    = (int)strlen(sMainString);"
        FPRINT FP_OUTPUT, "   int nLenMatch   = (int)strlen(sMatchPattern);"
        FPRINT FP_OUTPUT, "   int nLenReplace = (int)strlen(sReplaceWith);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (nLenMain == 0 || nLenMatch == 0 || nLenReplace == 0) {"
        FPRINT FP_OUTPUT, "       return (PCHAR)sMainString;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   strcpy(CopyMain, sMainString);"
        FPRINT FP_OUTPUT, "   for (int i = 0; i < nLenMain; i++) {"
        FPRINT FP_OUTPUT, "       for (int y = 0; y < nLenMatch; y++) {"
        FPRINT FP_OUTPUT, "           if (CopyMain[i] == sMatchPattern[y]) {"
        FPRINT FP_OUTPUT, "               // If lengths are different, use first suitable replacement"
        FPRINT FP_OUTPUT, "               if (y < nLenReplace) {"
        FPRINT FP_OUTPUT, "                   CopyMain[i] = sReplaceWith[y];"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               break;  // Exit inner loop when match found"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   BCX_RetStr = BCX_TempStr(strlen(CopyMain));"
        FPRINT FP_OUTPUT, "   strcpy(BCX_RetStr, CopyMain);"
        FPRINT FP_OUTPUT, "   return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_IReplaceAny THEN
        FPRINT FP_OUTPUT, "char *IReplaceAny(PCTSTR sMainString, PCTSTR sMatchPattern, PCTSTR sReplaceWith)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *BCX_RetStr = NULL;"
        FPRINT FP_OUTPUT, "   char CopyMain[BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "   int nLenMain    = (int)strlen(sMainString);"
        FPRINT FP_OUTPUT, "   int nLenMatch   = (int)strlen(sMatchPattern);"
        FPRINT FP_OUTPUT, "   int nLenReplace = (int)strlen(sReplaceWith);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (nLenMain == 0 || nLenMatch == 0 || nLenReplace == 0) {"
        FPRINT FP_OUTPUT, "       return (PCHAR)sMainString;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   strcpy(CopyMain, sMainString);"
        FPRINT FP_OUTPUT, "   for (int i = 0; i < nLenMain; i++) {"
        FPRINT FP_OUTPUT, "       for (int y = 0; y < nLenMatch; y++) {"
        FPRINT FP_OUTPUT, "           if ((CopyMain[i] | 32) == (sMatchPattern[y] | 32)) {"
        FPRINT FP_OUTPUT, "               // If lengths are different, use first suitable replacement"
        FPRINT FP_OUTPUT, "               if (y < nLenReplace) {"
        FPRINT FP_OUTPUT, "                   CopyMain[i] = sReplaceWith[y];"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               break;  // Exit inner loop when match found"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   BCX_RetStr = BCX_TempStr(strlen(CopyMain));"
        FPRINT FP_OUTPUT, "   strcpy(BCX_RetStr, CopyMain);"
        FPRINT FP_OUTPUT, "   return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_RemoveAny THEN
        FPRINT FP_OUTPUT, "char *RemoveAny (PCTSTR MainStr, PCTSTR CharsToRemove)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *BCX_RetStr = NULL;"
        FPRINT FP_OUTPUT, "   char ResultStr[BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "   int i = 0;"
        FPRINT FP_OUTPUT, "   int j = 0;"
        FPRINT FP_OUTPUT, "   int MainLen  = (int)strlen(MainStr);"
        FPRINT FP_OUTPUT, "   int CharsLen = (int)strlen(CharsToRemove);"
        FPRINT FP_OUTPUT, "   int CharToRemoveFlag[255]={0};"
        FPRINT FP_OUTPUT, "   int ResultLen = 0;"
        FPRINT FP_OUTPUT, "   // Set flags for characters to be removed"
        FPRINT FP_OUTPUT, "   for (j = 0; j < CharsLen; j++) {"
        FPRINT FP_OUTPUT, "       CharToRemoveFlag[(unsigned char)CharsToRemove[j]] = 1;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   for (i = 0; i < MainLen; i++) {"
        FPRINT FP_OUTPUT, "       if (CharToRemoveFlag[(unsigned char)MainStr[i]] == 0) {"
        FPRINT FP_OUTPUT, "           ResultStr[ResultLen++] = MainStr[i];"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   ResultStr[ResultLen] = 0; // Null-terminate"
        FPRINT FP_OUTPUT, "   BCX_RetStr = BCX_TempStr(ResultLen);"
        FPRINT FP_OUTPUT, "   strcpy(BCX_RetStr, ResultStr);"
        FPRINT FP_OUTPUT, "   return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_IRemoveAny THEN
        FPRINT FP_OUTPUT, "char *IRemoveAny (PCTSTR MainStr, PCTSTR CharsToRemove)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *BCX_RetStr = NULL;"
        FPRINT FP_OUTPUT, "   char ResultStr[BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "   int i = 0;"
        FPRINT FP_OUTPUT, "   int j = 0;"
        FPRINT FP_OUTPUT, "   int MainLen  = (int) strlen(MainStr);"
        FPRINT FP_OUTPUT, "   int CharsLen = (int) strlen(CharsToRemove);"
        FPRINT FP_OUTPUT, "   int CharToRemoveFlag[255]={0};"
        FPRINT FP_OUTPUT, "   int ResultLen = 0;"
        FPRINT FP_OUTPUT, "   // Set flags for characters to be removed"
        FPRINT FP_OUTPUT, "   for (j = 0; j < CharsLen; j++) {"
        FPRINT FP_OUTPUT, "       CharToRemoveFlag[tolower((unsigned char)CharsToRemove[j])] = 1;"
        FPRINT FP_OUTPUT, "       CharToRemoveFlag[toupper((unsigned char)CharsToRemove[j])] = 1;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   for (i = 0; i < MainLen; i++) {"
        FPRINT FP_OUTPUT, "       if (CharToRemoveFlag[(unsigned char)MainStr[i]] == 0) {"
        FPRINT FP_OUTPUT, "           ResultStr[ResultLen++] = MainStr[i];"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   ResultStr[ResultLen] = 0; // Null-terminate"
        FPRINT FP_OUTPUT, "   BCX_RetStr = BCX_TempStr(ResultLen);"
        FPRINT FP_OUTPUT, "   strcpy(BCX_RetStr, ResultStr);"
        FPRINT FP_OUTPUT, "   return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_StringCore



SUB Emit_RT_StringUtils (FP_OUTPUT AS FILE)
    IF Use_Sleep THEN
        FPRINT FP_OUTPUT, "void BCX_Sleep (int Milliseconds)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static UINT Initialized;"
        FPRINT FP_OUTPUT, "  static UINT OriginalPeriod;"
        FPRINT FP_OUTPUT, "  static UINT CallCount;"
        FPRINT FP_OUTPUT, "  // If called with 0, explicitly reset timer resolution and exit"
        FPRINT FP_OUTPUT, "  if(Milliseconds <= 0 || CallCount >=65535){"
        FPRINT FP_OUTPUT, "      if(Initialized){"
        FPRINT FP_OUTPUT, "          timeEndPeriod(OriginalPeriod);"
        FPRINT FP_OUTPUT, "          Initialized = FALSE;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      return;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  // Set timer resolution to 1 ms if not already initialized"
        FPRINT FP_OUTPUT, "  if(!Initialized){"
        FPRINT FP_OUTPUT, "      TIMECAPS  tMinRes;"
        FPRINT FP_OUTPUT, "      timeGetDevCaps(&tMinRes,sizeof(TIMECAPS));"
        FPRINT FP_OUTPUT, "      OriginalPeriod = tMinRes.wPeriodMin;"
        FPRINT FP_OUTPUT, "      timeBeginPeriod(OriginalPeriod); // Typically sets to 1 ms"
        FPRINT FP_OUTPUT, "      Initialized = TRUE;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  Sleep(Milliseconds);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Reverse THEN
        FPRINT FP_OUTPUT, "char *reverse (PCTSTR szStr)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  size_t j = strlen(szStr);"
        FPRINT FP_OUTPUT, "  char *rstr = BCX_TempStr(j);"
        FPRINT FP_OUTPUT, "  while(j)  rstr[--j] = *(szStr++);"
        FPRINT FP_OUTPUT, "  return rstr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Findfirst THEN
        FPRINT FP_OUTPUT, "char *findfirst (PCTSTR szSrc)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  if (fffn_FileHandle) FindClose(fffn_FileHandle);"
        FPRINT FP_OUTPUT, "  fffn_FileHandle = FindFirstFile(szSrc, &fffn_FindData);"
        FPRINT FP_OUTPUT, "  if (fffn_FileHandle != INVALID_HANDLE_VALUE)"
        FPRINT FP_OUTPUT, "    strcpy(strtmp, fffn_FindData.cFileName);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    fffn_FileHandle = 0;"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Findnext THEN
        FPRINT FP_OUTPUT, "char *findnext (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  if (fffn_FileHandle)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    int Found = FindNextFile(fffn_FileHandle, &fffn_FindData);"
        FPRINT FP_OUTPUT, "    if (Found)"
        FPRINT FP_OUTPUT, "      strcpy(strtmp, fffn_FindData.cFileName);"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      FindClose(fffn_FileHandle);"
        FPRINT FP_OUTPUT, "      fffn_FileHandle = 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF




    IF Use_Lookahead THEN
        FPRINT FP_OUTPUT, "char *LookAhead(FILE *FilePointer, int NumLines) {"
        FPRINT FP_OUTPUT, "    char *EmptyStr = ", ENC$(""), ";"
        FPRINT FP_OUTPUT, "    char *BCX_RetStr = NULL;"
        FPRINT FP_OUTPUT, "    fpos_t CurrentPosition;"
        FPRINT FP_OUTPUT, "    char FetchLine[BCXSTRSIZE] = {0};"
        FPRINT FP_OUTPUT, "    int Counter;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Validate inputs"
        FPRINT FP_OUTPUT, "    if (FilePointer == NULL || NumLines <= 0 || ferror(FilePointer)) {"
        FPRINT FP_OUTPUT, "        BCX_RetStr = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "        if (BCX_RetStr) strcpy(BCX_RetStr, EmptyStr);"
        FPRINT FP_OUTPUT, "        return BCX_RetStr;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Save current file position"
        FPRINT FP_OUTPUT, "    if (fgetpos(FilePointer, &CurrentPosition) != 0) {"
        FPRINT FP_OUTPUT, "        BCX_RetStr = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "        if (BCX_RetStr) strcpy(BCX_RetStr, EmptyStr);"
        FPRINT FP_OUTPUT, "        return BCX_RetStr;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Read lines"
        FPRINT FP_OUTPUT, "    for (Counter = 1; Counter <= NumLines; Counter++) {"
        FPRINT FP_OUTPUT, "        FetchLine[0] = '\\0';"
        FPRINT FP_OUTPUT, "        if (fgets(FetchLine, BCXSTRSIZE, FilePointer) == NULL) {"
        FPRINT FP_OUTPUT, "            fsetpos(FilePointer, &CurrentPosition); // Restore position"
        FPRINT FP_OUTPUT, "            BCX_RetStr = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "            if (BCX_RetStr) strcpy(BCX_RetStr, EmptyStr);"
        FPRINT FP_OUTPUT, "            return BCX_RetStr;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Remove newline characters"
        FPRINT FP_OUTPUT, "    FetchLine[strcspn(FetchLine, ", ENC$("\\r\\n"), ")] = '\\0';"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Restore file position"
        FPRINT FP_OUTPUT, "    fsetpos(FilePointer, &CurrentPosition);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Allocate and copy the result"
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(strlen(FetchLine));"
        FPRINT FP_OUTPUT, "    if (BCX_RetStr) {"
        FPRINT FP_OUTPUT, "        strcpy(BCX_RetStr, FetchLine);"
        FPRINT FP_OUTPUT, "    } else {"
        FPRINT FP_OUTPUT, "        BCX_RetStr = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "        if (BCX_RetStr) strcpy(BCX_RetStr, EmptyStr);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Ucase THEN
        FPRINT FP_OUTPUT, "char *ucase (PCTSTR szStr)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return CharUpperA(strcpy(BCX_TempStr(strlen(szStr)), szStr));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Lcase THEN
        FPRINT FP_OUTPUT, "char *lcase (PCTSTR szStr)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return CharLowerA(strcpy(BCX_TempStr(strlen(szStr)), szStr));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Mcase THEN
        FPRINT FP_OUTPUT, "char *mcase (PCTSTR szStr)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(strlen(szStr)+1);"
        FPRINT FP_OUTPUT, "  char *s = strtmp;"
        FPRINT FP_OUTPUT, "  CharLowerA(strcpy(strtmp, szStr));"
        FPRINT FP_OUTPUT, "  while(*s)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (islower(*s))"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      *s-=32;"
        FPRINT FP_OUTPUT, "      while(isalpha(*++s));"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    s++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Remove THEN
        FPRINT FP_OUTPUT, "char *RemoveStr (PCTSTR szSrc, PCTSTR RemoveMe)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp, *pp, *dd;"
        FPRINT FP_OUTPUT, "  int  tmplen;"
        FPRINT FP_OUTPUT, "  strtmp = dd = BCX_TempStr(strlen(szSrc));"
        FPRINT FP_OUTPUT, "  if ((!RemoveMe) || (!*RemoveMe)) return strcpy(strtmp, szSrc);"
        FPRINT FP_OUTPUT, "  pp = strstr((char*)szSrc, (char*)RemoveMe); tmplen = (int)strlen(RemoveMe);"
        FPRINT FP_OUTPUT, "  while (pp)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    memcpy (dd, szSrc, pp-szSrc);"
        FPRINT FP_OUTPUT, "    dd+= (pp - szSrc);"
        FPRINT FP_OUTPUT, "    szSrc = pp + tmplen;"
        FPRINT FP_OUTPUT, "    pp = strstr((char*)szSrc,(char*)RemoveMe);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  strcpy (dd, (char*)szSrc);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_IRemove THEN
        FPRINT FP_OUTPUT, "char *IRemoveStr (PCTSTR szSrc, PCTSTR RemoveMe)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp, *pp, *dd;"
        FPRINT FP_OUTPUT, "  int  tmplen;"
        FPRINT FP_OUTPUT, "  strtmp = dd = BCX_TempStr(strlen(szSrc));"
        FPRINT FP_OUTPUT, "  if (!RemoveMe || !*RemoveMe) return strcpy(strtmp, szSrc);"
        FPRINT FP_OUTPUT, "  pp = _stristr_(szSrc, RemoveMe); tmplen = (int)strlen(RemoveMe);"
        FPRINT FP_OUTPUT, "  while(pp)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    memcpy (dd, szSrc, pp-szSrc);"
        FPRINT FP_OUTPUT, "    dd+= (pp - szSrc);"
        FPRINT FP_OUTPUT, "    szSrc =  pp + tmplen;"
        FPRINT FP_OUTPUT, "    pp = _stristr_(szSrc, RemoveMe);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  strcpy (dd, szSrc);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Ins THEN
        FPRINT FP_OUTPUT, "char *ins (PCTSTR szStr, int ii, PCTSTR a)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int j = (int)strlen(szStr);"
        FPRINT FP_OUTPUT, "  if (ii<1 || ii > j+1) return (char*)szStr;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(j + strlen(a));"
        FPRINT FP_OUTPUT, "  memcpy (strtmp, szStr, --ii);"
        FPRINT FP_OUTPUT, "  strcpy(&strtmp[ii], a);"
        FPRINT FP_OUTPUT, "  return strcat(strtmp, &szStr[ii]);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Del THEN
        FPRINT FP_OUTPUT, "char *del (PCTSTR szStr, int ii, int j)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  size_t ln = strlen(szStr);"
        FPRINT FP_OUTPUT, "  if (ii<1 || ii > ln) return (char*)szStr;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(ln);"
        FPRINT FP_OUTPUT, "  memcpy (strtmp, szStr, --ii);"
        FPRINT FP_OUTPUT, "  return strcat(strtmp, &szStr[ii+j]);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF




    IF Use_Chrtoutf8 THEN
        FPRINT FP_OUTPUT, "char *ChrToUtf8 (PCSTR szAnsi)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (!szAnsi || !*szAnsi)"
        FPRINT FP_OUTPUT, "      return (char *)szAnsi;"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    // Convert ANSI to wide char (Unicode)"
        FPRINT FP_OUTPUT, "    int wlen = MultiByteToWideChar(CP_ACP, 0, szAnsi, -1, NULL, 0);"
        FPRINT FP_OUTPUT, "    if (wlen <= 0)"
        FPRINT FP_OUTPUT, "      return (char *)szAnsi;"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    WCHAR *wsz = (WCHAR *)calloc(wlen, sizeof(WCHAR));"
        FPRINT FP_OUTPUT, "    if (!wsz)"
        FPRINT FP_OUTPUT, "      return (char *)szAnsi;"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    MultiByteToWideChar(CP_ACP, 0, szAnsi, -1, wsz, wlen);"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    // Convert wide char (Unicode) to UTF-8"
        FPRINT FP_OUTPUT, "    int ulen = WideCharToMultiByte(CP_UTF8, 0, wsz, -1, NULL, 0, NULL, NULL);"
        FPRINT FP_OUTPUT, "    if (ulen <= 0) {"
        FPRINT FP_OUTPUT, "      free(wsz);"
        FPRINT FP_OUTPUT, "      return (char *)szAnsi;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    char *utf8 = BCX_TempStr(ulen - 1);  // Exclude null terminator"
        FPRINT FP_OUTPUT, "    WideCharToMultiByte(CP_UTF8, 0, wsz, -1, utf8, ulen, NULL, NULL);"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    free(wsz);"
        FPRINT FP_OUTPUT, "    return utf8;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Utf8tochr THEN
        FPRINT FP_OUTPUT, "char *UTF8toCHR (PCSTR szUtf8)"
        FPRINT FP_OUTPUT, "  //*****************************************************************************************"
        FPRINT FP_OUTPUT, "  // Uses MultiByteToWideChar to go from UTF-8 → Unicode."
        FPRINT FP_OUTPUT, "  // Uses WideCharToMultiByte to go from Unicode → ANSI (codepage CP_ACP)."
        FPRINT FP_OUTPUT, "  // Allocates temp wide string with calloc (freed after use)."
        FPRINT FP_OUTPUT, "  // Returns a temp ANSI string via BCX_TempStr() just like other BCX $ string functions.  "
        FPRINT FP_OUTPUT, "  //*****************************************************************************************"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (!szUtf8 || !*szUtf8)"
        FPRINT FP_OUTPUT, "      return (char *)szUtf8;"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    // Convert UTF-8 to wide char (Unicode)"
        FPRINT FP_OUTPUT, "    int wlen = MultiByteToWideChar(CP_UTF8, 0, szUtf8, -1, NULL, 0);"
        FPRINT FP_OUTPUT, "    if (wlen <= 0)"
        FPRINT FP_OUTPUT, "      return (char *)szUtf8;"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    WCHAR *wsz = (WCHAR *)calloc(wlen, sizeof(WCHAR));"
        FPRINT FP_OUTPUT, "    if (!wsz)"
        FPRINT FP_OUTPUT, "      return (char *)szUtf8;"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    MultiByteToWideChar(CP_UTF8, 0, szUtf8, -1, wsz, wlen);"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    // Convert wide char (Unicode) to ANSI"
        FPRINT FP_OUTPUT, "    int alen = WideCharToMultiByte(CP_ACP, 0, wsz, -1, NULL, 0, NULL, NULL);"
        FPRINT FP_OUTPUT, "    if (alen <= 0) {"
        FPRINT FP_OUTPUT, "      free(wsz);"
        FPRINT FP_OUTPUT, "      return (char *)szUtf8;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    char *ansi = BCX_TempStr(alen - 1);  // Don't include null terminator"
        FPRINT FP_OUTPUT, "    WideCharToMultiByte(CP_ACP, 0, wsz, -1, ansi, alen, NULL, NULL);"
        FPRINT FP_OUTPUT, "  "
        FPRINT FP_OUTPUT, "    free(wsz);"
        FPRINT FP_OUTPUT, "    return ansi;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Str THEN
        FPRINT FP_OUTPUT, "char *BCX_Format_Double(double d_, int leading_space)"   ' MrBcx 838  Added
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *s = BCX_TempStr(64);"
        FPRINT FP_OUTPUT, "  if (leading_space)"
        FPRINT FP_OUTPUT, "    snprintf(s, 64, ", ENC$("% .15f"), ", d_);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    snprintf(s, 64, ", ENC$("%.15f"), ", d_);"
        FPRINT FP_OUTPUT, "  char *dot = strchr(s, '.');"
        FPRINT FP_OUTPUT, "  if (dot) {"
        FPRINT FP_OUTPUT, "    char *end = s + strlen(s) - 1;"
        FPRINT FP_OUTPUT, "    while (end > dot && *end == '0') *end-- = 0;"
        FPRINT FP_OUTPUT, "    if (end == dot) *end = 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return s;"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, "char *str(double d_, int nospc)"                         ' MrBcx 838 Changed
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return BCX_Format_Double(d_, !nospc);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Strl THEN
        FPRINT FP_OUTPUT, "char *strl(long double d, int nospc)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(64);"
        FPRINT FP_OUTPUT, "  if (nospc)"
        FPRINT FP_OUTPUT, "    snprintf (strtmp, 64, ", ENC$("%.19LG"), ", d);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    snprintf (strtmp, 64, ", ENC$("% .19LG"), ", d);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Curdir THEN
        FPRINT FP_OUTPUT, "char *curdir (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr("; "BCXSTRSIZE"; ");"
        FPRINT FP_OUTPUT, "  GetCurrentDirectory (BCXSTRSIZE-1, strtmp);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Hex THEN
        FPRINT FP_OUTPUT, "char *hex(uint64_t a, int len)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    if (len > 16) len = 16;"         ' Max length for a 64-bit value in hex is 16 characters"
        FPRINT FP_OUTPUT, "    char *strtmp = BCX_TempStr(34);"
        FPRINT FP_OUTPUT, "    char formatStr[8];"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (len > 0)"
        FPRINT FP_OUTPUT, "        sprintf(formatStr, ", ENC$("%%0%dllX"), ", len);"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "        sprintf(formatStr, ", ENC$("%%llX"), ");"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    sprintf(strtmp, formatStr, a);"
        FPRINT FP_OUTPUT, "    return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Val THEN                                                    ' 837  New by MrBcx
        FPRINT FP_OUTPUT, "double val_func(PCTSTR s) {"
        FPRINT FP_OUTPUT, "   if (!s) return 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // 1. Skip leading whitespace"
        FPRINT FP_OUTPUT, "   while (*s == 32 || *s == 9 || *s == 10 || *s == 13) s++;"
        FPRINT FP_OUTPUT, "   if (*s == 0) return 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // 2. Handle BASIC &H, &O, &B"
        FPRINT FP_OUTPUT, "   if (*s == '&') {"
        FPRINT FP_OUTPUT, "       s++;"
        FPRINT FP_OUTPUT, "       int type = toupper((unsigned char)*s);"
        FPRINT FP_OUTPUT, "       if (type) s++;"
        FPRINT FP_OUTPUT, "       char *endptr;"
        FPRINT FP_OUTPUT, "       if (type == 'H') return (double)strtoll(s, &endptr, 16);"
        FPRINT FP_OUTPUT, "       if (type == 'O') return (double)strtoll(s, &endptr, 8);"
        FPRINT FP_OUTPUT, "       if (type == 'B') return (double)strtoll(s, &endptr, 2);"
        FPRINT FP_OUTPUT, "       return 0; "
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // 3. Handle C-style 0x Hex"
        FPRINT FP_OUTPUT, "   if (*s == '0' && (toupper((unsigned char)*(s + 1)) == 'X')) {"
        FPRINT FP_OUTPUT, "       char *endptr;"
        FPRINT FP_OUTPUT, "       return (double)strtoll(s, &endptr, 16);"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // 4. Handle standard numbers (with internal whitespace stripping)"
        FPRINT FP_OUTPUT, "   char buffer[256];"
        FPRINT FP_OUTPUT, "   int j = 0;"
        FPRINT FP_OUTPUT, "   int has_decimal = 0, has_exponent = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   while (*s && j < 254) {"
        FPRINT FP_OUTPUT, "       if (*s == 32 || *s == 9) { s++; continue; }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "       char c = *s;"
        FPRINT FP_OUTPUT, "       if (isdigit((unsigned char)c) || c == '-' || c == '+') {"
        FPRINT FP_OUTPUT, "           buffer[j++] = c;"
        FPRINT FP_OUTPUT, "       } else if (c == '.' && !has_decimal && !has_exponent) {"
        FPRINT FP_OUTPUT, "           buffer[j++] = c;"
        FPRINT FP_OUTPUT, "           has_decimal = 1;"
        FPRINT FP_OUTPUT, "       } else if (toupper((unsigned char)c) == 'E' && !has_exponent) {"
        FPRINT FP_OUTPUT, "           buffer[j++] = 'E';"
        FPRINT FP_OUTPUT, "           has_exponent = 1;"
        FPRINT FP_OUTPUT, "           if (*(s + 1) == '-' || *(s + 1) == '+') buffer[j++] = *(++s);"
        FPRINT FP_OUTPUT, "       } else {"
        FPRINT FP_OUTPUT, "           break; "
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "       s++;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   buffer[j] = 0;"
        FPRINT FP_OUTPUT, "   return (j > 0) ? atof(buffer) : 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Tempdir THEN
        FPRINT FP_OUTPUT, "char *tempdir (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *strtmp = BCX_TempStr("; "BCXSTRSIZE"; ");"
        FPRINT FP_OUTPUT, "   GetTempPath (BCXSTRSIZE-1, strtmp);"
        FPRINT FP_OUTPUT, "   return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Windir THEN
        FPRINT FP_OUTPUT, "char *windir (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *strtmp = BCX_TempStr("; "BCXSTRSIZE"; ");"
        FPRINT FP_OUTPUT, "   GetWindowsDirectory (strtmp, BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "   return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Sysdir THEN
        FPRINT FP_OUTPUT, "char *sysdir (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *strtmp = BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "   GetSystemDirectory (strtmp, BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "   return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Repeat THEN
        FPRINT FP_OUTPUT, "char *repeat(int count, PCTSTR szArg)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   if (!szArg || count <= 0)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "      char *strtmp = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "      if (strtmp) *strtmp = 0;"
        FPRINT FP_OUTPUT, "      return strtmp;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   size_t len = strlen(szArg);"
        FPRINT FP_OUTPUT, "   char *strtmp = BCX_TempStr((count * len) + 1);"
        FPRINT FP_OUTPUT, "   char *p = strtmp;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   while (count-- > 0) {"
        FPRINT FP_OUTPUT, "       memcpy(p, szArg, len);"
        FPRINT FP_OUTPUT, "       p += len;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   *p = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_String THEN
        FPRINT FP_OUTPUT, "char *stringx (int count_, int szArg)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   if (count_<1) return BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "   char *strtmp = BCX_TempStr(count_);"
        FPRINT FP_OUTPUT, "   return (char*)memset(strtmp, szArg, count_);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Space THEN
        FPRINT FP_OUTPUT, "char *space (int count)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   if (count<1) return BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "   char *strtmp = BCX_TempStr(count);"
        FPRINT FP_OUTPUT, "   return (char*)memset(strtmp, 32, count);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Time THEN
        '***************************************************
        STATIC  T0$    '  "%H:%M:%S"
        STATIC  T1$    '  "%H"
        STATIC  T2$    '  "%M"
        STATIC  T3$    '  "%S"
        STATIC  T4$    '  "%p"
        STATIC  T5$    '  "%Y"
        STATIC  T6$    '  "%m"
        STATIC  T7$    '  "%d"
        STATIC  T8$    '  "%A"
        STATIC  T9$    '  "%w"
        STATIC  T10$   '  "%j"
        STATIC  T11$   '  "%U"
        STATIC  T12$   '  "%I:%M:%S %p"
        '***************************************************
        T0$  = CHR$(34, 37, 72, 58, 37, 77, 58, 37, 83, 34)
        T1$  = CHR$(34, 37, 72, 34)
        T2$  = CHR$(34, 37, 77, 34)
        T3$  = CHR$(34, 37, 83, 34)
        T4$  = CHR$(34, 37, 112, 34)
        T5$  = CHR$(34, 37, 89, 34)
        T6$  = CHR$(34, 37, 109, 34)
        T7$  = CHR$(34, 37, 100, 34)
        T8$  = CHR$(34, 37, 65, 34)
        T9$  = CHR$(34, 37, 119, 34)
        T10$ = CHR$(34, 37, 106, 34)
        T11$ = CHR$(34, 37, 85, 34)
        T12$ = CHR$(34, 37, 73, 58, 37, 77, 58, 37, 83, 32, 37, 112, 34)
        '***************************************************
        FPRINT FP_OUTPUT, "char *timef (int t, int u)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   time_t elapse_time;"
        FPRINT FP_OUTPUT, "   struct tm *tp;"
        FPRINT FP_OUTPUT, "   char *strtmp = BCX_TempStr(256);"
        FPRINT FP_OUTPUT, "   time (&elapse_time);"
        FPRINT FP_OUTPUT, "   if (u==0)"
        FPRINT FP_OUTPUT, "     tp = localtime(&elapse_time);"
        FPRINT FP_OUTPUT, "   else"
        FPRINT FP_OUTPUT, "     tp = gmtime(&elapse_time);"
        FPRINT FP_OUTPUT, "   switch (t)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "   case 0:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T0$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 1:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T1$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 2:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T2$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 3:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T3$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 4:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T4$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 5:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T5$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 6:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T6$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 7:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T7$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 8:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T8$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 9:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T9$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 10:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T10$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 11:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T11$, ", tp); break;"
        FPRINT FP_OUTPUT, "   case 12:"
        FPRINT FP_OUTPUT, "     strftime(strtmp, 256, ", T12$, ", tp); break;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Wrap THEN
        FPRINT FP_OUTPUT, "char *wrap (PCTSTR _a, PCTSTR _b, PCTSTR _c)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *BCX_RetStr;"
        FPRINT FP_OUTPUT, "   char  Qt[2] = {34, 0};"
        FPRINT FP_OUTPUT, "   BCX_RetStr = BCX_TempStr (strlen(_a)+strlen(_b)+strlen(_c)+3);"
        FPRINT FP_OUTPUT, "   if (*_b==0 && *_c==0)"
        FPRINT FP_OUTPUT, "     sprintf(BCX_RetStr,", ENC$("%s%s%s"), ", Qt, _a, Qt);"
        FPRINT FP_OUTPUT, "   else"
        FPRINT FP_OUTPUT, "     sprintf(BCX_RetStr,", ENC$("%s%s%s"), ", _b, _a, _c);"
        FPRINT FP_OUTPUT, "   return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Unwrap THEN
        FPRINT FP_OUTPUT, "char *unwrap (PCTSTR _a, PCTSTR _b, PCTSTR _c)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *BCX_RetStr;"
        FPRINT FP_OUTPUT, "   char  Qt[2] = {34,0};"
        FPRINT FP_OUTPUT, "   BCX_RetStr = BCX_TempStr(strlen(_a));"
        FPRINT FP_OUTPUT, "   strcpy(BCX_RetStr, _a);"
        FPRINT FP_OUTPUT, "   if (0 == *_b && 0 == *_c)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "     if (strcmp(left(BCX_RetStr, 1), Qt)==0)"
        FPRINT FP_OUTPUT, "       BCX_RetStr = BCX_RetStr + 1;"
        FPRINT FP_OUTPUT, "     if (strcmp(right(BCX_RetStr, 1), Qt)==0)"
        FPRINT FP_OUTPUT, "       BCX_RetStr[strlen(BCX_RetStr)-1]=0;"
        FPRINT FP_OUTPUT, "     return BCX_RetStr;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   if (strcmp(left(BCX_RetStr,  strlen(_b)), _b)==0)"
        FPRINT FP_OUTPUT, "     BCX_RetStr = BCX_RetStr + strlen(_b);"
        FPRINT FP_OUTPUT, "   if (strcmp(right(BCX_RetStr, strlen(_c)), _c)==0)"
        FPRINT FP_OUTPUT, "     BCX_RetStr[strlen(BCX_RetStr)-strlen(_c)]=0;"
        FPRINT FP_OUTPUT, "   return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Enclose THEN
        FPRINT FP_OUTPUT, "char *enc (PCTSTR Arg_A, int L, int R)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  size_t tmplen = strlen(Arg_A);"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr = BCX_TempStr(tmplen+3);"
        FPRINT FP_OUTPUT, "  memcpy(BCX_RetStr+1, Arg_A, tmplen);"
        FPRINT FP_OUTPUT, "  *BCX_RetStr = (char)((L==0) ? 34 : L);"
        FPRINT FP_OUTPUT, "  BCX_RetStr[++tmplen] = (char)((R==0) ? *BCX_RetStr : R);"
        FPRINT FP_OUTPUT, "  BCX_RetStr[++tmplen] = 0;"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_VChr THEN
        FPRINT FP_OUTPUT, "char *vchr(int charcount, ...)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int c = 0, ii = charcount;"
        FPRINT FP_OUTPUT, "  char *s_ = BCX_TempStr(charcount + 1);"
        FPRINT FP_OUTPUT, "  va_list marker;"
        FPRINT FP_OUTPUT, "  s_[ii] = 0;"
        FPRINT FP_OUTPUT, "  va_start(marker, charcount);"
        FPRINT FP_OUTPUT, "  while (ii-- > 0) s_[c++] = (char) va_arg(marker, int);"
        FPRINT FP_OUTPUT, "  va_end(marker);"
        FPRINT FP_OUTPUT, "  return s_;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Join THEN
        FPRINT FP_OUTPUT, "char *join(int ArgCount, PCTSTR Str1, ...)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  va_list  ap={0};"
        FPRINT FP_OUTPUT, "  PSTR BCX_RetStr = NULL;"
        FPRINT FP_OUTPUT, "  PSTR currentStr = NULL;"
        FPRINT FP_OUTPUT, "  int i;"
        FPRINT FP_OUTPUT, "  size_t totalLen;"
        FPRINT FP_OUTPUT, "  totalLen = strlen(Str1);"
        FPRINT FP_OUTPUT, "                                      //  Calc memory reqmnt"
        FPRINT FP_OUTPUT, "  va_start(ap,Str1);"
        FPRINT FP_OUTPUT, "  for(i=1; i<=ArgCount-1; i++)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      currentStr = va_arg(ap,PSTR);"
        FPRINT FP_OUTPUT, "      if(strlen(currentStr)>0) {"
        FPRINT FP_OUTPUT, "          totalLen += (int)strlen(currentStr);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  va_end(ap);"
        FPRINT FP_OUTPUT, "                                      //  Allocate memory"
        FPRINT FP_OUTPUT, "  BCX_RetStr = BCX_TempStr(totalLen);"
        FPRINT FP_OUTPUT, "  if(BCX_RetStr == 0) {"
        FPRINT FP_OUTPUT, "      return NULL;                    //   Not a good sign :-("
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "                                      //   Init result with Str1"
        FPRINT FP_OUTPUT, "  strcpy(BCX_RetStr,Str1);"
        FPRINT FP_OUTPUT, "                                      //   Concat remainiing strings"
        FPRINT FP_OUTPUT, "  va_start(ap,Str1);"
        FPRINT FP_OUTPUT, "  for(i=1; i<=ArgCount-1; i++)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      currentStr = va_arg(ap,PSTR);"
        FPRINT FP_OUTPUT, "      if((int)strlen(currentStr)>0) {"
        FPRINT FP_OUTPUT, "          strcat(BCX_RetStr,currentStr);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  va_end(ap);"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Environ THEN
        FPRINT FP_OUTPUT, "char* Environ(PCTSTR szStr)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp;"
        FPRINT FP_OUTPUT, "  DWORD len;"
        FPRINT FP_OUTPUT, "  len = GetEnvironmentVariable(szStr, NULL, 0);   // ask Windows for the real size first"
        FPRINT FP_OUTPUT, "  if (len == 0)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      strtmp = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "      *strtmp = 0;"
        FPRINT FP_OUTPUT, "      return strtmp;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  strtmp = BCX_TempStr(len);                      // request only what's actually needed"
        FPRINT FP_OUTPUT, "  GetEnvironmentVariable(szStr, strtmp, len);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}"
    END IF


    IF Use_Oct THEN
        FPRINT FP_OUTPUT, "char *oct (int a)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  sprintf(strtmp, "; CHR$(34, 37, 111, 34); ", a);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Bin THEN
        FPRINT FP_OUTPUT, "char* Bin(int number)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  _itoa(number, strtmp, 2);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Inkey THEN
        FPRINT FP_OUTPUT, "char* inkey(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(2);"
        FPRINT FP_OUTPUT, "  if (_kbhit())"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    int asccodereturn = _getch();"
        FPRINT FP_OUTPUT, "    strtmp[0] = asccodereturn;"
        FPRINT FP_OUTPUT, "    strtmp[1] = 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Mouse_sx THEN
        FPRINT FP_OUTPUT, "int MOUSEX_SCREEN (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  POINT pt={0};"
        FPRINT FP_OUTPUT, "  GetCursorPos(&pt);"
        FPRINT FP_OUTPUT, "  return pt.x;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Mouse_sy THEN
        FPRINT FP_OUTPUT, "int MOUSEY_SCREEN (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  POINT pt={0};"
        FPRINT FP_OUTPUT, "  GetCursorPos(&pt);"
        FPRINT FP_OUTPUT, "  return pt.y;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Mouse_cx THEN
        FPRINT FP_OUTPUT, "int MOUSEX_CLIENT (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int clientX={0};"
        FPRINT FP_OUTPUT, "  POINT pt   ={0};"
        FPRINT FP_OUTPUT, "  RECT rect  ={0};"
        FPRINT FP_OUTPUT, "  GetCursorPos(&pt);"
        FPRINT FP_OUTPUT, "  GetWindowRect(GetForegroundWindow(), &rect);"
        FPRINT FP_OUTPUT, "  clientX = pt.x - rect.left;"
        FPRINT FP_OUTPUT, "  if(clientX < 0) {"
        FPRINT FP_OUTPUT, "      clientX = 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else if(clientX >= (rect.right - rect.left)){"
        FPRINT FP_OUTPUT, "      clientX = (rect.right - rect.left) - 1;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  return clientX;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Mouse_cy THEN
        FPRINT FP_OUTPUT, "int MOUSEY_CLIENT (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int clientY={0};"
        FPRINT FP_OUTPUT, "  POINT pt   ={0};"
        FPRINT FP_OUTPUT, "  RECT rect  ={0};"
        FPRINT FP_OUTPUT, "  GetCursorPos(&pt);"
        FPRINT FP_OUTPUT, "  GetWindowRect(GetForegroundWindow(), &rect);"
        FPRINT FP_OUTPUT, "  clientY = pt.y - rect.top;"
        FPRINT FP_OUTPUT, "  if(clientY < 0) {"
        FPRINT FP_OUTPUT, "      clientY = 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else if(clientY >= (rect.bottom - rect.top)){"
        FPRINT FP_OUTPUT, "      clientY = (rect.bottom - rect.top) - 1;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  return clientY;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Date THEN
        FPRINT FP_OUTPUT, "char *date (int tz)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  time_t elapse_time;"
        FPRINT FP_OUTPUT, "  struct tm *tp;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(24);"
        FPRINT FP_OUTPUT, "  time(&elapse_time);"
        FPRINT FP_OUTPUT, "  if (tz == 0)"
        FPRINT FP_OUTPUT, "    tp = localtime(&elapse_time);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    tp = gmtime(&elapse_time);"
        FPRINT FP_OUTPUT, "  strftime(strtmp, 24, ", ENC$("%m-%d-%Y"), ", tp);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_IsoDate THEN
        FPRINT FP_OUTPUT, "char *isodate (int tz)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  time_t elapse_time;"
        FPRINT FP_OUTPUT, "  struct tm *tp;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(24);"
        FPRINT FP_OUTPUT, "  time(&elapse_time);"
        FPRINT FP_OUTPUT, "  if (tz == 0)"
        FPRINT FP_OUTPUT, "    tp = localtime(&elapse_time);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    tp = gmtime(&elapse_time);"
        FPRINT FP_OUTPUT, "  strftime(strtmp, 24, ", ENC$("20%y-%m-%d"), ", tp);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Now THEN
        FPRINT FP_OUTPUT, "char *now (int tz)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  time_t elapse_time;"
        FPRINT FP_OUTPUT, "  struct tm *tp;"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  time(&elapse_time);"
        FPRINT FP_OUTPUT, "  if (tz == 0)"
        FPRINT FP_OUTPUT, "    tp = localtime(&elapse_time);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    tp = gmtime(&elapse_time);"
        FPRINT FP_OUTPUT, "  strftime(strtmp, 256, ", ENC$("%m/%d/%y %I:%M:%S %p"), ", tp);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_StringUtils



SUB Emit_RT_FileDialogs (FP_OUTPUT AS FILE)
    IF Use_Getfilename THEN
        FPRINT FP_OUTPUT, "char *GetFileName(PCTSTR Title,"
        FPRINT FP_OUTPUT, "                  PCTSTR Filter,"
        FPRINT FP_OUTPUT, "                  int     Flag,"
        FPRINT FP_OUTPUT, "                  HWND    hWnd,"
        FPRINT FP_OUTPUT, "                  ULONG   Flags,"
        FPRINT FP_OUTPUT, "                  PCTSTR InitDir,"
        FPRINT FP_OUTPUT, "                  PCTSTR Initfname,"
        FPRINT FP_OUTPUT, "                  int    *ExtIdx)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  OPENFILENAME OpenFileStruct;"
        FPRINT FP_OUTPUT, "  char Extension[2048];"
        FPRINT FP_OUTPUT, "  int Counter = 0, TmpSize;"
        FPRINT FP_OUTPUT, "  static char *filename;"
        FPRINT FP_OUTPUT, "  static int BufSize;"
        FPRINT FP_OUTPUT, "  TmpSize = ((Flags & OFN_ALLOWMULTISELECT) ? 500000:MAX_PATH);"
        FPRINT FP_OUTPUT, "  if (TmpSize > BufSize)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BufSize  = TmpSize;"
        FPRINT FP_OUTPUT, "    filename = (char*)realloc(filename, BufSize);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  memset(filename, 0, BufSize);"
        FPRINT FP_OUTPUT, "  memset(Extension, 0, 2048);"
        FPRINT FP_OUTPUT, "  memset(&OpenFileStruct, 0, sizeof(OpenFileStruct));"
        FPRINT FP_OUTPUT, "  if (Initfname) strcpy(filename, Initfname);"
        FPRINT FP_OUTPUT, "  for(Counter = 0;Counter<=(int)strlen(Filter);Counter++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (Filter[Counter]=='|')"
        FPRINT FP_OUTPUT, "      Extension[Counter]=0;"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "      Extension[Counter]=Filter[Counter];"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  CmDlgHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)SBProc, NULL, GetCurrentThreadId());" ' 833 MrBcx
        FPRINT FP_OUTPUT, "  OpenFileStruct.lStructSize = sizeof(OpenFileStruct);"
        FPRINT FP_OUTPUT, "  OpenFileStruct.hwndOwner = hWnd;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.hInstance = 0;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lpstrFilter = Extension;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lpstrTitle = Title;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.nMaxFile = BufSize;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.nMaxFileTitle = 0;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lpstrFile = filename;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lpstrFileTitle = NULL;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lpstrCustomFilter = 0;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.nMaxCustFilter = 0;"
        FPRINT FP_OUTPUT, "  if (ExtIdx) OpenFileStruct.nFilterIndex=*ExtIdx;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lpstrInitialDir = InitDir;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.nFileOffset = 0;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.nFileExtension = 0;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lpstrDefExt = 0;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lCustData = 0;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lpfnHook = 0;"
        FPRINT FP_OUTPUT, "  OpenFileStruct.lpTemplateName = 0;"
        FPRINT FP_OUTPUT, "  if (!Flags)"
        FPRINT FP_OUTPUT, "    OpenFileStruct.Flags = OFN_HIDEREADONLY|OFN_CREATEPROMPT|OFN_EXPLORER;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    OpenFileStruct.Flags = Flags|OFN_EXPLORER;"
        FPRINT FP_OUTPUT, "  if (!Flag)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (GetOpenFileName(&OpenFileStruct)==0)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      *filename = 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      int len = (int)strlen(filename);"
        FPRINT FP_OUTPUT, "      if (filename[len+1]==0) return filename;"
        FPRINT FP_OUTPUT, "      char *fname = filename+len;"
        FPRINT FP_OUTPUT, "      while(fname[1])"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        *fname =  ',';"
        FPRINT FP_OUTPUT, "        len = (int)strlen(++fname);"
        FPRINT FP_OUTPUT, "        fname += len;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (GetSaveFileName(&OpenFileStruct)==0) *filename = 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (ExtIdx) *ExtIdx = OpenFileStruct.nFilterIndex;"
        FPRINT FP_OUTPUT, "  return filename;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_GetSaveAsFilename THEN
        FPRINT FP_OUTPUT, "//----------------------------------------------------------"
        FPRINT FP_OUTPUT, "//         GetSaveAsFileName Support Begins Here"
        FPRINT FP_OUTPUT, "//----------------------------------------------------------"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#include <shobjidl.h>  // For IFileOpenDialog, IFileSaveDialog, etc."
        FPRINT FP_OUTPUT, "#include <shlguid.h>   // For CLSID_FileSaveDialog"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#define ID_ENCODING         1000"
        FPRINT FP_OUTPUT, "#define FOS_HIDEREADONLY    0x00000004L"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifndef BCX_SF_BUFFER"
        FPRINT FP_OUTPUT, "static char* filename = NULL;"
        FPRINT FP_OUTPUT, "static int   BufSize = 0;"
        FPRINT FP_OUTPUT, "#define BCX_SF_BUFFER    1"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifndef ID_ENCODING"
        FPRINT FP_OUTPUT, "#define ID_ENCODING 40001"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static void ExtractDirectory(const char* fullPath, char* dirOut, size_t cch)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    size_t n = strlen(fullPath);"
        FPRINT FP_OUTPUT, "    const char* p = fullPath + n;"
        FPRINT FP_OUTPUT, "    while (p > fullPath && *p != 92 && *p != 47) --p;"
        FPRINT FP_OUTPUT, "    size_t len = (p > fullPath) ? (size_t)(p - fullPath) : 0;"
        FPRINT FP_OUTPUT, "    if (len >= cch) len = cch - 1;"
        FPRINT FP_OUTPUT, "    memcpy(dirOut, fullPath, len);"
        FPRINT FP_OUTPUT, "    dirOut[len] = 0;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static void GetExecutableDirectory(char* dirOut, size_t cch)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    char path[MAX_PATH];"
        FPRINT FP_OUTPUT, "    GetModuleFileNameA(NULL, path, MAX_PATH);"
        FPRINT FP_OUTPUT, "    ExtractDirectory(path, dirOut, cch);"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#if !defined(__POCC__) && !defined(__LCC__)  // Begin c++ support"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#include <vector>"
        FPRINT FP_OUTPUT, "#include <string>"
        FPRINT FP_OUTPUT, "#include <cwchar>"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static std::vector<COMDLG_FILTERSPEC> ConvertFilterToSpec(PCTSTR Filter, std::vector<wchar_t>& wbuf)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    std::vector<COMDLG_FILTERSPEC> v;"
        FPRINT FP_OUTPUT, "    if (!Filter || !*Filter) return v;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifdef _UNICODE"
        FPRINT FP_OUTPUT, "    std::wstring input(Filter);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "    size_t len = MultiByteToWideChar(CP_ACP, 0, Filter, -1, NULL, 0);"
        FPRINT FP_OUTPUT, "    wbuf.resize(len);"
        FPRINT FP_OUTPUT, "    MultiByteToWideChar(CP_ACP, 0, Filter, -1, wbuf.data(), (int)wbuf.size());"
        FPRINT FP_OUTPUT, "    std::wstring input(wbuf.data());"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    size_t pos = 0;"
        FPRINT FP_OUTPUT, "    while (pos < input.length()) {"
        FPRINT FP_OUTPUT, "        size_t bar1 = input.find(L'|', pos);"
        FPRINT FP_OUTPUT, "        if (bar1 == std::wstring::npos) break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        size_t bar2 = input.find(L'|', bar1 + 1);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        std::wstring name = input.substr(pos, bar1 - pos);"
        FPRINT FP_OUTPUT, "        std::wstring spec;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        if (bar2 != std::wstring::npos) {"
        FPRINT FP_OUTPUT, "            spec = input.substr(bar1 + 1, bar2 - bar1 - 1);"
        FPRINT FP_OUTPUT, "            pos = bar2 + 1;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        else {"
        FPRINT FP_OUTPUT, "            // Handle the final entry (no trailing pipe)"
        FPRINT FP_OUTPUT, "            spec = input.substr(bar1 + 1);"
        FPRINT FP_OUTPUT, "            pos = input.length(); // Exit after this"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        // Store copies of the strings"
        FPRINT FP_OUTPUT, "        wchar_t* name_copy = _wcsdup(name.c_str());"
        FPRINT FP_OUTPUT, "        wchar_t* spec_copy = _wcsdup(spec.c_str());"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        COMDLG_FILTERSPEC fs = { name_copy, spec_copy };"
        FPRINT FP_OUTPUT, "        v.push_back(fs);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    return v;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static std::wstring PrimaryExtFromSpec(const wchar_t* spec)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    if (!spec) return L", ENC$(""), ";"
        FPRINT FP_OUTPUT, "    const wchar_t* star = wcschr(spec, L'*');"
        FPRINT FP_OUTPUT, "    if (!star) return L", ENC$(""), ";"
        FPRINT FP_OUTPUT, "    const wchar_t* dot = wcschr(star, L'.');"
        FPRINT FP_OUTPUT, "    if (!dot) return L", ENC$(""), ";"
        FPRINT FP_OUTPUT, "    ++dot;"
        FPRINT FP_OUTPUT, "    std::wstring ext;"
        FPRINT FP_OUTPUT, "    while (*dot && *dot != L';' && *dot != L' ' && *dot != L')') {"
        FPRINT FP_OUTPUT, "        if (*dot == L'*' || *dot == L'?' || *dot == L'.') break;"
        FPRINT FP_OUTPUT, "        ext.push_back(*dot++);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    return ext;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "class BCX_FileTypeEvents : public IFileDialogEvents {"
        FPRINT FP_OUTPUT, "    LONG m_cRef;"
        FPRINT FP_OUTPUT, "    const std::vector<COMDLG_FILTERSPEC>& m_types;"
        FPRINT FP_OUTPUT, "public:"
        FPRINT FP_OUTPUT, "    BCX_FileTypeEvents(const std::vector<COMDLG_FILTERSPEC>& types) : m_cRef(1), m_types(types) {}"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP QueryInterface(REFIID riid, void** ppv) {"
        FPRINT FP_OUTPUT, "        if (!ppv) return E_POINTER;"
        FPRINT FP_OUTPUT, "        if (riid == IID_IUnknown || riid == IID_IFileDialogEvents) { *ppv = static_cast<IFileDialogEvents*>(this); AddRef(); return S_OK; }"
        FPRINT FP_OUTPUT, "        *ppv = 0; return E_NOINTERFACE;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP_(ULONG) AddRef() { return InterlockedIncrement(&m_cRef); }"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP_(ULONG) Release() { ULONG c = InterlockedDecrement(&m_cRef); return c; }"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP OnTypeChange(IFileDialog* pfd) {"
        FPRINT FP_OUTPUT, "        UINT idx = 0; if (FAILED(pfd->GetFileTypeIndex(&idx)) || idx == 0) return S_OK;"
        FPRINT FP_OUTPUT, "        if (idx > m_types.size()) idx = (UINT)m_types.size();"
        FPRINT FP_OUTPUT, "        const COMDLG_FILTERSPEC& fs = m_types[idx - 1];"
        FPRINT FP_OUTPUT, "        std::wstring ext = PrimaryExtFromSpec(fs.pszSpec);"
        FPRINT FP_OUTPUT, "        if (!ext.empty()) {"
        FPRINT FP_OUTPUT, "            pfd->SetDefaultExtension(ext.c_str());"
        FPRINT FP_OUTPUT, "            PWSTR cur = NULL; if (SUCCEEDED(pfd->GetFileName(&cur)) && cur && *cur) {"
        FPRINT FP_OUTPUT, "                std::wstring name(cur); CoTaskMemFree(cur);"
        FPRINT FP_OUTPUT, "                size_t slash = name.find_last_of(L", ENC$("/\\\\"), ");"
        FPRINT FP_OUTPUT, "                size_t dot = name.find_last_of(L'.');"
        FPRINT FP_OUTPUT, "                if (dot == std::wstring::npos || (slash != std::wstring::npos && dot < slash)) name += L", ENC$("."), " + ext;"
        FPRINT FP_OUTPUT, "                else { name.erase(dot + 1); name += ext; }"
        FPRINT FP_OUTPUT, "                pfd->SetFileName(name.c_str());"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        return S_OK;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP OnFileOk(IFileDialog*) { return S_OK; }"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP OnFolderChanging(IFileDialog*, IShellItem*) { return S_OK; }"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP OnFolderChange(IFileDialog*) { return S_OK; }"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP OnSelectionChange(IFileDialog*) { return S_OK; }"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP OnShareViolation(IFileDialog*, IShellItem*, FDE_SHAREVIOLATION_RESPONSE*) { return S_OK; }"
        FPRINT FP_OUTPUT, "    IFACEMETHODIMP OnOverwrite(IFileDialog*, IShellItem*, FDE_OVERWRITE_RESPONSE*) { return S_OK; }"
        FPRINT FP_OUTPUT, "};"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "char* GetSaveAsFileName(PCTSTR Title, PCTSTR Filter, int Flag, HWND hWnd, ULONG Flags, PCTSTR InitDir, PCTSTR Initfname, PINT ExtIdx)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    static char lastUsedFolder[MAX_PATH] = { 0 };"
        FPRINT FP_OUTPUT, "    int TmpSize = ((Flags & OFN_ALLOWMULTISELECT) ? 500000 : MAX_PATH);"
        FPRINT FP_OUTPUT, "    if (TmpSize > BufSize) { BufSize = TmpSize; filename = (char*)realloc(filename, BufSize); }"
        FPRINT FP_OUTPUT, "    if (!filename) return NULL;"
        FPRINT FP_OUTPUT, "    *filename = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);"
        FPRINT FP_OUTPUT, "    if (FAILED(hr)) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    IFileSaveDialog* pDlg = NULL;"
        FPRINT FP_OUTPUT, "    hr = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDlg));"
        FPRINT FP_OUTPUT, "    if (FAILED(hr)) { CoUninitialize(); return NULL; }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    DWORD fos = FOS_FORCEFILESYSTEM | FOS_OVERWRITEPROMPT;"
        FPRINT FP_OUTPUT, "    if (Flags & OFN_CREATEPROMPT) fos |= FOS_CREATEPROMPT;"
        FPRINT FP_OUTPUT, "    pDlg->SetOptions(fos);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (Title) {"
        FPRINT FP_OUTPUT, "#ifdef _UNICODE"
        FPRINT FP_OUTPUT, "        pDlg->SetTitle(Title);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "        wchar_t wTitle[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, Title, -1, wTitle, MAX_PATH);"
        FPRINT FP_OUTPUT, "        pDlg->SetTitle(wTitle);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    std::vector<wchar_t> fbuf; std::vector<COMDLG_FILTERSPEC> types = ConvertFilterToSpec(Filter, fbuf);"
        FPRINT FP_OUTPUT, "    if (!types.empty()) {"
        FPRINT FP_OUTPUT, "        pDlg->SetFileTypes((UINT)types.size(), types.data());"
        FPRINT FP_OUTPUT, "        UINT defIndex = 1;"
        FPRINT FP_OUTPUT, "        if (ExtIdx && *ExtIdx >= 1 && (UINT)*ExtIdx <= types.size()) defIndex = (UINT)*ExtIdx;"
        FPRINT FP_OUTPUT, "        pDlg->SetFileTypeIndex(defIndex);"
        FPRINT FP_OUTPUT, "        std::wstring ext = PrimaryExtFromSpec(types[defIndex - 1].pszSpec);"
        FPRINT FP_OUTPUT, "        if (!ext.empty()) pDlg->SetDefaultExtension(ext.c_str());"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    char workingDir[MAX_PATH];"
        FPRINT FP_OUTPUT, "    if (InitDir && *InitDir) { strncpy(workingDir, InitDir, MAX_PATH - 1); workingDir[MAX_PATH - 1] = 0; }"
        FPRINT FP_OUTPUT, "    else if (lastUsedFolder[0]) { strncpy(workingDir, lastUsedFolder, MAX_PATH - 1); workingDir[MAX_PATH - 1] = 0; }"
        FPRINT FP_OUTPUT, "    else { GetExecutableDirectory(workingDir, MAX_PATH); }"
        FPRINT FP_OUTPUT, "    if (workingDir[0]) {"
        FPRINT FP_OUTPUT, "#ifdef _UNICODE"
        FPRINT FP_OUTPUT, "        IShellItem* pFolder = NULL; if (SUCCEEDED(SHCreateItemFromParsingName(workingDir, NULL, IID_PPV_ARGS(&pFolder))))"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "            pDlg->SetFolder(pFolder); pFolder->Release();"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "        wchar_t wdir[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, workingDir, -1, wdir, MAX_PATH);"
        FPRINT FP_OUTPUT, "        IShellItem* pFolder = NULL; if (SUCCEEDED(SHCreateItemFromParsingName(wdir, NULL, IID_PPV_ARGS(&pFolder))))"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "            pDlg->SetFolder(pFolder); pFolder->Release();"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (Initfname) {"
        FPRINT FP_OUTPUT, "#ifdef _UNICODE"
        FPRINT FP_OUTPUT, "        pDlg->SetFileName(Initfname);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "        wchar_t wfn[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, Initfname, -1, wfn, MAX_PATH); pDlg->SetFileName(wfn);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Add the custom combo box"
        FPRINT FP_OUTPUT, "    IFileDialogCustomize* pCust = NULL;"
        FPRINT FP_OUTPUT, "    if (SUCCEEDED(pDlg->QueryInterface(IID_PPV_ARGS(&pCust)))) {"
        FPRINT FP_OUTPUT, "        pCust->AddComboBox(ID_ENCODING);"
        FPRINT FP_OUTPUT, "        pCust->AddControlItem(ID_ENCODING, 0, L", ENC$("UTF-8"), ");"
        FPRINT FP_OUTPUT, "        pCust->AddControlItem(ID_ENCODING, 1, L", ENC$("UTF-8 with BOM"), ");"
        FPRINT FP_OUTPUT, "        pCust->AddControlItem(ID_ENCODING, 2, L", ENC$("UTF-16 LE"), ");"
        FPRINT FP_OUTPUT, "        pCust->AddControlItem(ID_ENCODING, 3, L", ENC$("UTF-16 BE"), ");"
        FPRINT FP_OUTPUT, "        pCust->AddControlItem(ID_ENCODING, 4, L", ENC$("ANSI"), ");"
        FPRINT FP_OUTPUT, "        pCust->SetSelectedControlItem(ID_ENCODING, 0);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    DWORD cookie = 0; BCX_FileTypeEvents* pEvents = new BCX_FileTypeEvents(types);"
        FPRINT FP_OUTPUT, "    if (pEvents) pDlg->Advise(pEvents, &cookie);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hr = pDlg->Show(hWnd);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (SUCCEEDED(hr)) {"
        FPRINT FP_OUTPUT, "        IShellItem* pItem = NULL;"
        FPRINT FP_OUTPUT, "        if (SUCCEEDED(pDlg->GetResult(&pItem)) && pItem) {"
        FPRINT FP_OUTPUT, "            PWSTR psz = NULL; if (SUCCEEDED(pItem->GetDisplayName(SIGDN_FILESYSPATH, &psz)) && psz) {"
        FPRINT FP_OUTPUT, "                WideCharToMultiByte(CP_ACP, 0, psz, -1, filename, BufSize, NULL, NULL);"
        FPRINT FP_OUTPUT, "                ExtractDirectory(filename, lastUsedFolder, MAX_PATH);"
        FPRINT FP_OUTPUT, "                CoTaskMemFree(psz);"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "            pItem->Release();"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Correct logic to get the encoding index and overwrite the ExtIdx pointer"
        FPRINT FP_OUTPUT, "    if (pCust) {"
        FPRINT FP_OUTPUT, "        DWORD selectedEncoding = 0;"
        FPRINT FP_OUTPUT, "        if (SUCCEEDED(pCust->GetSelectedControlItem(ID_ENCODING, &selectedEncoding))) {"
        FPRINT FP_OUTPUT, "            if (ExtIdx) {"
        FPRINT FP_OUTPUT, "                *ExtIdx = (int)selectedEncoding;"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else if (ExtIdx) {"
        FPRINT FP_OUTPUT, "        // If the custom control failed to be created, set ExtIdx to a default value"
        FPRINT FP_OUTPUT, "        *ExtIdx = -1;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // This section is commented out because it conflicts with your goal of getting the encoding index."
        FPRINT FP_OUTPUT, "    // The previous code would overwrite your variable with the FileTypeIndex here."
        FPRINT FP_OUTPUT, "    // if (ExtIdx) { UINT i = 0; *ExtIdx = -1; if (SUCCEEDED(pDlg->GetFileTypeIndex(&i))) *ExtIdx = (int)i; }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (cookie) pDlg->Unadvise(cookie);"
        FPRINT FP_OUTPUT, "    if (pEvents) pEvents->Release();"
        FPRINT FP_OUTPUT, "    if (pCust) pCust->Release();"
        FPRINT FP_OUTPUT, "    pDlg->Release();"
        FPRINT FP_OUTPUT, "    // Free the duplicated strings from ConvertFilterToSpec"
        FPRINT FP_OUTPUT, "    for (auto& fs : types) {"
        FPRINT FP_OUTPUT, "        free((void*)fs.pszName);"
        FPRINT FP_OUTPUT, "        free((void*)fs.pszSpec);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    CoUninitialize();"
        FPRINT FP_OUTPUT, "    if (!filename) return NULL;"
        FPRINT FP_OUTPUT, "    return filename;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#else    // Begin c99 support (e.g., when compiling with Pelles C)"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#include <wchar.h>"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static COMDLG_FILTERSPEC* ConvertFilterToSpec(PCTSTR Filter, int* pCount)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    *pCount = 0; if (!Filter || !*Filter) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifdef _UNICODE"
        FPRINT FP_OUTPUT, "    const wchar_t* src = Filter;"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "    int wlen = MultiByteToWideChar(CP_ACP, 0, Filter, -1, NULL, 0);"
        FPRINT FP_OUTPUT, "    wchar_t* wtmp = (wchar_t*)calloc(wlen * sizeof(wchar_t), sizeof(wchar_t));"
        FPRINT FP_OUTPUT, "    MultiByteToWideChar(CP_ACP, 0, Filter, -1, wtmp, wlen);"
        FPRINT FP_OUTPUT, "    const wchar_t* src = wtmp;"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    size_t len = wcslen(src);"
        FPRINT FP_OUTPUT, "    int pipes = 0; for (size_t i = 0; i < len; ++i) if (src[i] == L'|') ++pipes;"
        FPRINT FP_OUTPUT, "    int pairs = pipes / 2; if (pairs <= 0) {"
        FPRINT FP_OUTPUT, "#ifndef _UNICODE"
        FPRINT FP_OUTPUT, "        free(wtmp);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "        return NULL;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    pairs++;"
        FPRINT FP_OUTPUT, "    wchar_t* wstore = (wchar_t*)malloc((len + 1) * sizeof(wchar_t));"
        FPRINT FP_OUTPUT, "    wcscpy(wstore, src);"
        FPRINT FP_OUTPUT, "    COMDLG_FILTERSPEC* arr = (COMDLG_FILTERSPEC*)malloc(sizeof(COMDLG_FILTERSPEC) * pairs);"
        FPRINT FP_OUTPUT, "    size_t i = 0, idx = 0;"
        FPRINT FP_OUTPUT, "    while (idx < (size_t)pairs) {"
        FPRINT FP_OUTPUT, "        wchar_t* name = wcschr(wstore + i, L'|');"
        FPRINT FP_OUTPUT, "        if (!name) break; *name = 0; name = wstore + i;"
        FPRINT FP_OUTPUT, "        i += wcslen(name) + 1;"
        FPRINT FP_OUTPUT, "        wchar_t* spec = wcschr(wstore + i, L'|');"
        FPRINT FP_OUTPUT, "        if (spec) { *spec = 0; spec = wstore + i; i += wcslen(spec) + 1; }"
        FPRINT FP_OUTPUT, "        else { spec = wstore + i; i = len; }"
        FPRINT FP_OUTPUT, "        arr[idx].pszName = name; arr[idx].pszSpec = spec; ++idx;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifndef _UNICODE"
        FPRINT FP_OUTPUT, "    free(wtmp);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    * pCount = (int)idx;"
        FPRINT FP_OUTPUT, "    return arr; // arr->pszName/Spec point into wstore; we free via arr[0].pszName"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static void PrimaryExtFromSpecW(const wchar_t* spec, wchar_t* out, size_t cch)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    if (!spec || !cch) { if (cch) out[0] = 0; return; }"
        FPRINT FP_OUTPUT, "    const wchar_t* star = wcschr(spec, L'*');"
        FPRINT FP_OUTPUT, "    const wchar_t* dot = star ? wcschr(star, L'.') : NULL;"
        FPRINT FP_OUTPUT, "    size_t j = 0;"
        FPRINT FP_OUTPUT, "    if (dot) {"
        FPRINT FP_OUTPUT, "        ++dot; while (*dot && *dot != L';' && *dot != L' ' && *dot != L')' && *dot != L'.') {"
        FPRINT FP_OUTPUT, "            if (*dot == L'*' || *dot == L'?') break; if (j + 1 < cch) out[j++] = *dot; ++dot;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    out[j] = 0;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "typedef struct BCX_FileTypeEventsC {"
        FPRINT FP_OUTPUT, "    IFileDialogEvents iface;"
        FPRINT FP_OUTPUT, "    LONG refc;"
        FPRINT FP_OUTPUT, "    const COMDLG_FILTERSPEC* types;"
        FPRINT FP_OUTPUT, "    int count;"
        FPRINT FP_OUTPUT, "} BCX_FileTypeEventsC;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static HRESULT STDMETHODCALLTYPE C_OnQueryInterface(IFileDialogEvents* This, REFIID riid, void** ppv)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    if (!ppv) return E_POINTER;"
        FPRINT FP_OUTPUT, "    if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IFileDialogEvents)) { *ppv = This; This->lpVtbl->AddRef(This); return S_OK; }"
        FPRINT FP_OUTPUT, "    *ppv = NULL; return E_NOINTERFACE;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, "static ULONG   STDMETHODCALLTYPE C_OnAddRef(IFileDialogEvents* This) { BCX_FileTypeEventsC* s = (BCX_FileTypeEventsC*)This; return InterlockedIncrement(&s->refc); }"
        FPRINT FP_OUTPUT, "static ULONG   STDMETHODCALLTYPE C_OnRelease(IFileDialogEvents* This) { BCX_FileTypeEventsC* s = (BCX_FileTypeEventsC*)This; ULONG c = InterlockedDecrement(&s->refc); if (!c) free(s); return c; }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static HRESULT STDMETHODCALLTYPE C_OnFileOk(IFileDialogEvents* This, IFileDialog* pfd) { return S_OK; }"
        FPRINT FP_OUTPUT, "static HRESULT STDMETHODCALLTYPE C_OnFolderChanging(IFileDialogEvents* This, IFileDialog* pfd, IShellItem* psi) { return S_OK; }"
        FPRINT FP_OUTPUT, "static HRESULT STDMETHODCALLTYPE C_OnFolderChange(IFileDialogEvents* This, IFileDialog* pfd) { return S_OK; }"
        FPRINT FP_OUTPUT, "static HRESULT STDMETHODCALLTYPE C_OnSelectionChange(IFileDialogEvents* This, IFileDialog* pfd) { return S_OK; }"
        FPRINT FP_OUTPUT, "static HRESULT STDMETHODCALLTYPE C_OnShareViolation(IFileDialogEvents* This, IFileDialog* pfd, IShellItem* psi, FDE_SHAREVIOLATION_RESPONSE* pResponse) { return S_OK; }"
        FPRINT FP_OUTPUT, "static HRESULT STDMETHODCALLTYPE C_OnOverwrite(IFileDialogEvents* This, IFileDialog* pfd, IShellItem* psi, FDE_OVERWRITE_RESPONSE* pResponse) { return S_OK; }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static HRESULT STDMETHODCALLTYPE C_OnTypeChange(IFileDialogEvents* This, IFileDialog* pfd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    BCX_FileTypeEventsC* s = (BCX_FileTypeEventsC*)This;"
        FPRINT FP_OUTPUT, "    UINT idx = 0; if (FAILED(pfd->lpVtbl->GetFileTypeIndex(pfd, &idx)) || idx == 0) return S_OK;"
        FPRINT FP_OUTPUT, "    if ((int)idx > s->count) idx = (UINT)s->count;"
        FPRINT FP_OUTPUT, "    wchar_t ext[32]; PrimaryExtFromSpecW(s->types[idx - 1].pszSpec, ext, 32);"
        FPRINT FP_OUTPUT, "    if (ext[0]) {"
        FPRINT FP_OUTPUT, "        pfd->lpVtbl->SetDefaultExtension(pfd, ext);"
        FPRINT FP_OUTPUT, "        PWSTR cur = 0; if (SUCCEEDED(pfd->lpVtbl->GetFileName(pfd, &cur)) && cur && *cur) {"
        FPRINT FP_OUTPUT, "            size_t len = wcslen(cur);"
        FPRINT FP_OUTPUT, "            wchar_t* name = (wchar_t*)malloc((len + 32) * sizeof(wchar_t)); wcscpy(name, cur); CoTaskMemFree(cur);"
        FPRINT FP_OUTPUT, "            wchar_t* slash = wcsrchr(name, 92); wchar_t* dot = wcsrchr(name, L'.');"
        FPRINT FP_OUTPUT, "            if (!dot || (slash && dot < slash)) { wcscat(name, L", ENC$("."), "); wcscat(name, ext); }"
        FPRINT FP_OUTPUT, "            else { *(dot + 1) = 0; wcscat(name, ext); }"
        FPRINT FP_OUTPUT, "            pfd->lpVtbl->SetFileName(pfd, name); free(name);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    return S_OK;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "static const IFileDialogEventsVtbl g_BCXEvtVtbl = {"
        FPRINT FP_OUTPUT, "    C_OnQueryInterface,"
        FPRINT FP_OUTPUT, "    C_OnAddRef,"
        FPRINT FP_OUTPUT, "    C_OnRelease,"
        FPRINT FP_OUTPUT, "    C_OnFileOk,"
        FPRINT FP_OUTPUT, "    C_OnFolderChanging,"
        FPRINT FP_OUTPUT, "    C_OnFolderChange,"
        FPRINT FP_OUTPUT, "    C_OnSelectionChange,"
        FPRINT FP_OUTPUT, "    C_OnShareViolation,"
        FPRINT FP_OUTPUT, "    C_OnTypeChange,"
        FPRINT FP_OUTPUT, "    C_OnOverwrite"
        FPRINT FP_OUTPUT, "};"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "char* GetSaveAsFileName(PCTSTR Title, PCTSTR Filter, int Flag, HWND hWnd, ULONG Flags, PCTSTR InitDir, PCTSTR Initfname, PINT ExtIdx)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    static char lastUsedFolder[MAX_PATH] = { 0 };"
        FPRINT FP_OUTPUT, "    int TmpSize = ((Flags & OFN_ALLOWMULTISELECT) ? 500000 : MAX_PATH);"
        FPRINT FP_OUTPUT, "    if (TmpSize > BufSize) { BufSize = TmpSize; filename = (char*)realloc(filename, BufSize); }"
        FPRINT FP_OUTPUT, "    if (!filename) return NULL;"
        FPRINT FP_OUTPUT, "    *filename = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);"
        FPRINT FP_OUTPUT, "    if (FAILED(hr)) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    IFileSaveDialog* pDlg = NULL;"
        FPRINT FP_OUTPUT, "    hr = CoCreateInstance(&CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, &IID_IFileSaveDialog, (void**)&pDlg);"
        FPRINT FP_OUTPUT, "    if (FAILED(hr)) { CoUninitialize(); return NULL; }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    DWORD fos = FOS_FORCEFILESYSTEM | FOS_OVERWRITEPROMPT;"
        FPRINT FP_OUTPUT, "    if (Flags & OFN_CREATEPROMPT) fos |= FOS_CREATEPROMPT;"
        FPRINT FP_OUTPUT, "    pDlg->lpVtbl->SetOptions(pDlg, fos);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (Title) {"
        FPRINT FP_OUTPUT, "#ifdef _UNICODE"
        FPRINT FP_OUTPUT, "        pDlg->lpVtbl->SetTitle(pDlg, Title);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "        wchar_t wTitle[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, Title, -1, wTitle, MAX_PATH);"
        FPRINT FP_OUTPUT, "        pDlg->lpVtbl->SetTitle(pDlg, wTitle);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    int count = 0; COMDLG_FILTERSPEC* types = ConvertFilterToSpec(Filter, &count);"
        FPRINT FP_OUTPUT, "    if (types && count > 0) {"
        FPRINT FP_OUTPUT, "        pDlg->lpVtbl->SetFileTypes(pDlg, (UINT)count, types);"
        FPRINT FP_OUTPUT, "        UINT defIndex = 1;"
        FPRINT FP_OUTPUT, "        if (ExtIdx && *ExtIdx >= 1 && *ExtIdx <= count) defIndex = (UINT)*ExtIdx;"
        FPRINT FP_OUTPUT, "        pDlg->lpVtbl->SetFileTypeIndex(pDlg, defIndex);"
        FPRINT FP_OUTPUT, "        wchar_t ext[32]; PrimaryExtFromSpecW(types[defIndex - 1].pszSpec, ext, 32);"
        FPRINT FP_OUTPUT, "        if (ext[0]) pDlg->lpVtbl->SetDefaultExtension(pDlg, ext);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    char workingDir[MAX_PATH];"
        FPRINT FP_OUTPUT, "    if (InitDir && *InitDir) { strncpy(workingDir, InitDir, MAX_PATH - 1); workingDir[MAX_PATH - 1] = 0; }"
        FPRINT FP_OUTPUT, "    else if (lastUsedFolder[0]) { strncpy(workingDir, lastUsedFolder, MAX_PATH - 1); workingDir[MAX_PATH - 1] = 0; }"
        FPRINT FP_OUTPUT, "    else { GetExecutableDirectory(workingDir, MAX_PATH); }"
        FPRINT FP_OUTPUT, "    if (workingDir[0]) {"
        FPRINT FP_OUTPUT, "#ifdef _UNICODE"
        FPRINT FP_OUTPUT, "        IShellItem* pFolder = NULL; if (SUCCEEDED(SHCreateItemFromParsingName(workingDir, NULL, &IID_IShellItem, (void**)&pFolder)))"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "            pDlg->lpVtbl->SetFolder(pDlg, pFolder); pFolder->lpVtbl->Release(pFolder);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "        wchar_t wdir[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, workingDir, -1, wdir, MAX_PATH);"
        FPRINT FP_OUTPUT, "        IShellItem* pFolder = NULL; if (SUCCEEDED(SHCreateItemFromParsingName(wdir, NULL, &IID_IShellItem, (void**)&pFolder)))"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "            pDlg->lpVtbl->SetFolder(pDlg, pFolder); pFolder->lpVtbl->Release(pFolder);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (Initfname) {"
        FPRINT FP_OUTPUT, "#ifdef _UNICODE"
        FPRINT FP_OUTPUT, "        pDlg->lpVtbl->SetFileName(pDlg, Initfname);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "        wchar_t wfn[MAX_PATH]; MultiByteToWideChar(CP_ACP, 0, Initfname, -1, wfn, MAX_PATH); pDlg->lpVtbl->SetFileName(pDlg, wfn);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Add the custom combo box"
        FPRINT FP_OUTPUT, "    IFileDialogCustomize* pCust = NULL;"
        FPRINT FP_OUTPUT, "    if (SUCCEEDED(pDlg->lpVtbl->QueryInterface(pDlg, &IID_IFileDialogCustomize, (void**)&pCust))) {"
        FPRINT FP_OUTPUT, "        pCust->lpVtbl->AddComboBox(pCust, ID_ENCODING);"
        FPRINT FP_OUTPUT, "        pCust->lpVtbl->AddControlItem(pCust, ID_ENCODING, 0, L", ENC$("UTF-8"), ");"
        FPRINT FP_OUTPUT, "        pCust->lpVtbl->AddControlItem(pCust, ID_ENCODING, 1, L", ENC$("UTF-8 with BOM"), ");"
        FPRINT FP_OUTPUT, "        pCust->lpVtbl->AddControlItem(pCust, ID_ENCODING, 2, L", ENC$("UTF-16 LE"), ");"
        FPRINT FP_OUTPUT, "        pCust->lpVtbl->AddControlItem(pCust, ID_ENCODING, 3, L", ENC$("UTF-16 BE"), ");"
        FPRINT FP_OUTPUT, "        pCust->lpVtbl->AddControlItem(pCust, ID_ENCODING, 4, L", ENC$("ANSI"), ");"
        FPRINT FP_OUTPUT, "        pCust->lpVtbl->SetSelectedControlItem(pCust, ID_ENCODING, 0);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    DWORD cookie = 0;"
        FPRINT FP_OUTPUT, "    BCX_FileTypeEventsC* sink = (BCX_FileTypeEventsC*)calloc(1, sizeof(BCX_FileTypeEventsC));"
        FPRINT FP_OUTPUT, "    if (sink) {"
        FPRINT FP_OUTPUT, "        sink->iface.lpVtbl = (IFileDialogEventsVtbl*)&g_BCXEvtVtbl;"
        FPRINT FP_OUTPUT, "        sink->refc = 1; sink->types = types; sink->count = count;"
        FPRINT FP_OUTPUT, "        pDlg->lpVtbl->Advise(pDlg, (IFileDialogEvents*)sink, &cookie);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hr = pDlg->lpVtbl->Show(pDlg, hWnd);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (SUCCEEDED(hr)) {"
        FPRINT FP_OUTPUT, "        IShellItem* pItem = NULL;"
        FPRINT FP_OUTPUT, "        if (SUCCEEDED(pDlg->lpVtbl->GetResult(pDlg, &pItem)) && pItem) {"
        FPRINT FP_OUTPUT, "            PWSTR psz = NULL; if (SUCCEEDED(pItem->lpVtbl->GetDisplayName(pItem, SIGDN_FILESYSPATH, &psz)) && psz) {"
        FPRINT FP_OUTPUT, "                WideCharToMultiByte(CP_ACP, 0, psz, -1, filename, BufSize, NULL, NULL);"
        FPRINT FP_OUTPUT, "                ExtractDirectory(filename, lastUsedFolder, MAX_PATH);"
        FPRINT FP_OUTPUT, "                CoTaskMemFree(psz);"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "            pItem->lpVtbl->Release(pItem);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Correct logic to get the encoding index and overwrite the ExtIdx pointer"
        FPRINT FP_OUTPUT, "    if (pCust) {"
        FPRINT FP_OUTPUT, "        DWORD selectedEncoding = 0;"
        FPRINT FP_OUTPUT, "        if (SUCCEEDED(pCust->lpVtbl->GetSelectedControlItem(pCust, ID_ENCODING, &selectedEncoding))) {"
        FPRINT FP_OUTPUT, "            if (ExtIdx) {"
        FPRINT FP_OUTPUT, "                *ExtIdx = (int)selectedEncoding;"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else if (ExtIdx) {"
        FPRINT FP_OUTPUT, "        // If the custom control failed to be created, set ExtIdx to a default value"
        FPRINT FP_OUTPUT, "        *ExtIdx = -1;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // This section is commented out because it conflicts with your goal of getting the encoding index."
        FPRINT FP_OUTPUT, "    // The previous code would overwrite your variable with the FileTypeIndex here."
        FPRINT FP_OUTPUT, "    // if (ExtIdx) { UINT i = 0; *ExtIdx = -1; if (SUCCEEDED(pDlg->lpVtbl->GetFileTypeIndex(pDlg, &i))) *ExtIdx = (int)i; }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (cookie) pDlg->lpVtbl->Unadvise(pDlg, cookie);"
        FPRINT FP_OUTPUT, "    if (sink)   sink->iface.lpVtbl->Release((IFileDialogEvents*)sink);"
        FPRINT FP_OUTPUT, "    if (pCust)  pCust->lpVtbl->Release(pCust);"
        FPRINT FP_OUTPUT, "    if (types) { free((void*)types[0].pszName); free(types); }"
        FPRINT FP_OUTPUT, "    pDlg->lpVtbl->Release(pDlg);"
        FPRINT FP_OUTPUT, "    CoUninitialize();"
        FPRINT FP_OUTPUT, "    if (!filename) return NULL;"
        FPRINT FP_OUTPUT, "    return filename;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "//----------------------------------------------------------"
        FPRINT FP_OUTPUT, "//         GetSaveAsFileName Support Ends Here"
        FPRINT FP_OUTPUT, "//----------------------------------------------------------"
        FPRINT FP_OUTPUT, "\n\n"
    END IF
END SUB ' Emit_RT_FileDialogs



SUB Emit_RT_FormatPath1 (FP_OUTPUT AS FILE)
    IF Use_AppExePath THEN
        FPRINT FP_OUTPUT, "char *AppExePath (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  int ii;"
        FPRINT FP_OUTPUT, "  ii = GetModuleFileName(GetModuleHandle(0), strtmp, BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  while(ii && strtmp[ii] != 0x5C)"
        FPRINT FP_OUTPUT, "    ii--;"
        FPRINT FP_OUTPUT, "  strtmp[ii+1] = 0;"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_AppExeName THEN
        FPRINT FP_OUTPUT, "char *AppExeName (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  int ii;"
        FPRINT FP_OUTPUT, "  ii = GetModuleFileName (GetModuleHandle(NULL), strtmp, BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  while(ii && strtmp[ii] != 0x5C)"
        FPRINT FP_OUTPUT, "    ii--;"
        FPRINT FP_OUTPUT, "  return &strtmp[ii+1];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_TempFileName THEN
        FPRINT FP_OUTPUT, "char *TempFileName (PCTSTR szFolder, PCTSTR szPrefix)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  GetTempFileName(szFolder, szPrefix, 0, strtmp);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Boolstr THEN
        FPRINT FP_OUTPUT, "char * BoolStr (int a)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr = BCX_TempStr(5);"
        FPRINT FP_OUTPUT, "  if (a) return strcpy(BCX_RetStr, ", ENC$("True"), ");"
        FPRINT FP_OUTPUT, "  return strcpy(BCX_RetStr, ", ENC$("False"), ");"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Using THEN
        FPRINT FP_OUTPUT, "char *Using(PCTSTR szMask, long double Num)"   ' 837 Revised by MrBcx & Claude
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int CntDec = 0;    // Count the number of ", ENC$("0"), " to left pad the result"
        FPRINT FP_OUTPUT, "  int Decimals = 0;  // Count ALL digits RIGHT of the decimal point"
        FPRINT FP_OUTPUT, "  int Dollar = 0;    // Flag to LEFT prepend ", ENC$("$"), " symbol"
        FPRINT FP_OUTPUT, "  int Percent = 0;   // Flag to append ", ENC$("%"), " symbol (does NOT scale value)"
        FPRINT FP_OUTPUT, "  int SN = 0;        // Flag to use Sci Notation "
        FPRINT FP_OUTPUT, "  int Spaces = 0;    // Flag for using spaces padding"
        FPRINT FP_OUTPUT, "  int Zeros = 0;     // Flag for using zero padding "
        FPRINT FP_OUTPUT, "  int Commas = 0;    // Flag for thousands separators (mask contains comma)"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  char *BCX_RetStr = BCX_TempStr(256);"
        FPRINT FP_OUTPUT, "  char Buf_1[256]={0};"
        FPRINT FP_OUTPUT, "  PCTSTR p = szMask;"
        FPRINT FP_OUTPUT, "  int len;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // First pass: analyze the format mask"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  while (*p)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*p == 36)  Dollar++;      // $"
        FPRINT FP_OUTPUT, "    if (Dollar>1)  Dollar=1;      // Restrict"
        FPRINT FP_OUTPUT, "    if (*p == 37)  Percent++;     // %"
        FPRINT FP_OUTPUT, "    if (Percent>1) Percent=1;     // Restrict"
        FPRINT FP_OUTPUT, "    if (*p == 32)  Spaces++;      // Space"
        FPRINT FP_OUTPUT, "    if (*p == 44)  Commas = 1;    // Comma in mask"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Track zero padding before decimal"
        FPRINT FP_OUTPUT, "    if (*p == 48 && !CntDec)  Zeros++;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Count decimal places (spaces, # or 0 after decimal point)"
        FPRINT FP_OUTPUT, "    if ((*p == 32 || *p == 35 || *p == 48) && CntDec)  Decimals++;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (*p == 46)  CntDec = 1;    // Decimal point"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (*p == 94)  SN++;          // ^ is for scientific notation"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    p++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Second pass: Assemble the resulting string"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (SN)                         // Process SN and return"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    char Tmp[64]={0};"
        FPRINT FP_OUTPUT, "    "
        FPRINT FP_OUTPUT, "    // Per manual: SN always uses full double precision; mask details ignored."
        FPRINT FP_OUTPUT, "    sprintf(Tmp, ", ENC$("%.15E"), ", (double)Num);"
        FPRINT FP_OUTPUT, "    "
        FPRINT FP_OUTPUT, "    // Strip trailing zeros from the mantissa (e.g. 1.2300000E+07 -> 1.23E+07)"
        FPRINT FP_OUTPUT, "    while (instr(Tmp, ", ENC$("0E"), "))"
        FPRINT FP_OUTPUT, "      strcpy(Tmp, replace(Tmp, ", ENC$("0E"), ", ", ENC$("E"), "));"
        FPRINT FP_OUTPUT, "    "
        FPRINT FP_OUTPUT, "    // MSVC may emit 3-digit exponents (E+007), so collapse the leading zero"
        FPRINT FP_OUTPUT, "    // only when followed by a non-zero digit. Preserve normal 2-digit form."
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      char *e = strstr(Tmp, ", ENC$("E+00"), ");"
        FPRINT FP_OUTPUT, "      if (e && e[4] >= '1' && e[4] <= '9')"
        FPRINT FP_OUTPUT, "        memmove(e + 3, e + 4, strlen(e + 4) + 1);"
        FPRINT FP_OUTPUT, "      e = strstr(Tmp, ", ENC$("E-00"), ");"
        FPRINT FP_OUTPUT, "      if (e && e[4] >= '1' && e[4] <= '9')"
        FPRINT FP_OUTPUT, "        memmove(e + 3, e + 4, strlen(e + 4) + 1);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    strcpy(BCX_RetStr, Tmp);"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Format the number with specified decimals"
        FPRINT FP_OUTPUT, "  sprintf(Buf_1, ", ENC$("%1.*Lf"), ", Decimals, Num);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Find integer part length"
        FPRINT FP_OUTPUT, "  char *decimal_pos = strchr(Buf_1, '.');"
        FPRINT FP_OUTPUT, "  int num_int_digits = decimal_pos ? (int)(decimal_pos - Buf_1) : (int)strlen(Buf_1);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Adjust for negative sign"
        FPRINT FP_OUTPUT, "  int has_negative = (Buf_1[0] == '-');"
        FPRINT FP_OUTPUT, "  if (has_negative)"
        FPRINT FP_OUTPUT, "    num_int_digits--;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Initialize the return string"
        FPRINT FP_OUTPUT, "  memset(BCX_RetStr, 0, 256);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  int zero_pad = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Calculate zero padding (apply only if needed)"
        FPRINT FP_OUTPUT, "  if (Zeros > 0 && Zeros > num_int_digits)"
        FPRINT FP_OUTPUT, "    zero_pad = Zeros - num_int_digits;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Position for the start of the number"
        FPRINT FP_OUTPUT, "  int pos = Dollar + Spaces + zero_pad;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Copy the number to the return string"
        FPRINT FP_OUTPUT, "  if (has_negative)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (Zeros > 0)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      // With zero padding, negative goes before zeros"
        FPRINT FP_OUTPUT, "      BCX_RetStr[Dollar + Spaces] = '-';"
        FPRINT FP_OUTPUT, "      strcpy(BCX_RetStr + pos, Buf_1 + 1);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      // Without zero padding, negative stays with number"
        FPRINT FP_OUTPUT, "      strcpy(BCX_RetStr + pos, Buf_1);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    strcpy(BCX_RetStr + pos, Buf_1);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Add commas for thousands (only if mask requested them)"
        FPRINT FP_OUTPUT, "  if (Commas)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    char temp[256]={0};"
        FPRINT FP_OUTPUT, "    strcpy(temp, BCX_RetStr);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Find where the number starts after any potential padding"
        FPRINT FP_OUTPUT, "    int number_start = Dollar + Spaces + zero_pad;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Handle negative sign position for proper comma placement"
        FPRINT FP_OUTPUT, "    if (has_negative && Zeros == 0)"
        FPRINT FP_OUTPUT, "      number_start++; // Skip past the negative sign for comma placement"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Find integer part end"
        FPRINT FP_OUTPUT, "    decimal_pos = strchr(temp, '.');"
        FPRINT FP_OUTPUT, "    int int_end = decimal_pos ? (int)(decimal_pos - temp) : (int)strlen(temp);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Add commas working backwards, but never insert a comma right after the negative sign"
        FPRINT FP_OUTPUT, "    for (int i = int_end - 3; i > number_start; i -= 3)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      // Ensure we don't place a comma immediately after a negative sign"
        FPRINT FP_OUTPUT, "      if (i > number_start && !(temp[i-1] == '-'))"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        memmove(temp + i + 1, temp + i, (int)strlen(temp + i) + 1);"
        FPRINT FP_OUTPUT, "        temp[i] = ',';"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    strcpy(BCX_RetStr, temp);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Add dollar sign"
        FPRINT FP_OUTPUT, "  if (Dollar)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (Num >= 0)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      BCX_RetStr[Spaces] = '$';"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (Zeros > 0)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        // With zero padding: move negative, then add dollar"
        FPRINT FP_OUTPUT, "        BCX_RetStr[Spaces] = '-';"
        FPRINT FP_OUTPUT, "        BCX_RetStr[Spaces + 1] = '$';"
        FPRINT FP_OUTPUT, "        "
        FPRINT FP_OUTPUT, "        // Remove duplicate negative sign"
        FPRINT FP_OUTPUT, "        for (int i = pos; i < (int)strlen(BCX_RetStr); i++)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          if (BCX_RetStr[i] == '-')"
        FPRINT FP_OUTPUT, "          {"
        FPRINT FP_OUTPUT, "            memmove(BCX_RetStr + i, BCX_RetStr + i + 1, (int)strlen(BCX_RetStr + i));"
        FPRINT FP_OUTPUT, "            break;"
        FPRINT FP_OUTPUT, "          }"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      else"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        // Without zero padding: dollar then negative"
        FPRINT FP_OUTPUT, "        BCX_RetStr[Spaces] = '$';"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Fill leading spaces"
        FPRINT FP_OUTPUT, "  if (Spaces)"
        FPRINT FP_OUTPUT, "    memset(BCX_RetStr, ' ', Spaces);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Fill zeros after spaces but only if needed"
        FPRINT FP_OUTPUT, "  for (int i = 0; i < zero_pad; i++)"
        FPRINT FP_OUTPUT, "    BCX_RetStr[Dollar + Spaces + i] = '0';"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Add percent sign if needed (suffix only, does NOT scale value)"
        FPRINT FP_OUTPUT, "  if (Percent)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    len = (int)strlen(BCX_RetStr);"
        FPRINT FP_OUTPUT, "    BCX_RetStr[len] = '%';"
        FPRINT FP_OUTPUT, "    BCX_RetStr[len + 1] = 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Format THEN
        FPRINT FP_OUTPUT, "char * Format (long double Num, PCTSTR szMask)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *BCX_RetStr = BCX_TempStr(256);"
        FPRINT FP_OUTPUT, "   char Buf_1[256] = {0};"
        FPRINT FP_OUTPUT, "   if (!szMask || strlen(szMask) == 0)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       sprintf(BCX_RetStr, ", ENC$("%.6f"), ", (double)Num);"
        FPRINT FP_OUTPUT, "       // Remove trailing zeros and decimal if not needed"
        FPRINT FP_OUTPUT, "       char *end =  BCX_RetStr + strlen(BCX_RetStr) - 1;"
        FPRINT FP_OUTPUT, "       while (end > BCX_RetStr && *end == '0') *end-- = 0;"
        FPRINT FP_OUTPUT, "       if (end > BCX_RetStr && *end == '.') *end = 0;"
        FPRINT FP_OUTPUT, "       return BCX_RetStr;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   PCTSTR current_mask = szMask;"
        FPRINT FP_OUTPUT, "   int zeros_left    = 0;   //  Count of zeros to left of decimal"
        FPRINT FP_OUTPUT, "   int zeros_right   = 0;   //  Count of zeros to right of decimal"
        FPRINT FP_OUTPUT, "   int hash_left     = 0;   //  Count of # to left of decimal"
        FPRINT FP_OUTPUT, "   int hash_right    = 0;   //  Count of # to right of decimal"
        FPRINT FP_OUTPUT, "   int has_decimal   = 0;   //  Has decimal point"
        FPRINT FP_OUTPUT, "   int has_percent   = 0;   //  Has percent sign"
        FPRINT FP_OUTPUT, "   int has_comma     = 0;   //  Has comma separator"
        FPRINT FP_OUTPUT, "   int sci_notation  = 0;   //  Scientific notation (E+, E-, e+, e-)"
        FPRINT FP_OUTPUT, "   int sci_plus      = 0;   //  Use + for positive exponents"
        FPRINT FP_OUTPUT, "   int sci_uppercase = 0;   //  Use uppercase E"
        FPRINT FP_OUTPUT, "   int fill_char     = 0;   //  Fill character for * format"
        FPRINT FP_OUTPUT, "   int literal_chars = 0;   //  Count of literal characters"
        FPRINT FP_OUTPUT, "   int past_decimal  = 0;"
        FPRINT FP_OUTPUT, "   int space_for_positive = 0;  // Space for positive numbers flag"
        FPRINT FP_OUTPUT, "   int has_plus_sign = 0;       // Has explicit + sign"
        FPRINT FP_OUTPUT, "   int mask_has_parentheses = 0; // Mask contains parentheses as literals"
        FPRINT FP_OUTPUT, "   char mask_prefix[32] = {0};  // Characters before number pattern"
        FPRINT FP_OUTPUT, "   char mask_suffix[32] = {0};  // Characters after number pattern"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // Check if mask has parentheses as literal characters"
        FPRINT FP_OUTPUT, "   int mask_len = (int)strlen(current_mask);"
        FPRINT FP_OUTPUT, "   if (mask_len >= 2 && current_mask[0] == '(' && current_mask[mask_len-1] == ')')"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       mask_has_parentheses = 1;"
        FPRINT FP_OUTPUT, "       // Extract prefix and suffix (the parentheses)"
        FPRINT FP_OUTPUT, "       mask_prefix[0] = '(';"
        FPRINT FP_OUTPUT, "       mask_prefix[1] = 0;"
        FPRINT FP_OUTPUT, "       mask_suffix[0] = ')';"
        FPRINT FP_OUTPUT, "       mask_suffix[1] = 0;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // Check for space-for-positive pattern ( +)"
        FPRINT FP_OUTPUT, "   if (mask_len >= 2 && current_mask[0] == ' ' && current_mask[1] == '+')"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       space_for_positive = 1;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   // Check for explicit + sign without space"
        FPRINT FP_OUTPUT, "   else if (current_mask[0] == '+')"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       has_plus_sign = 1;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   PCTSTR p = current_mask;"
        FPRINT FP_OUTPUT, "   // If mask has parentheses, skip them during pattern parsing but include everything else"
        FPRINT FP_OUTPUT, "   int skip_count = 0;"
        FPRINT FP_OUTPUT, "   if (mask_has_parentheses)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       p++;  // Skip opening parenthesis"
        FPRINT FP_OUTPUT, "       skip_count = 1;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   "
        FPRINT FP_OUTPUT, "   while (*p && (skip_count == 0 || p < current_mask + mask_len - 1))"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       switch (*p)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           case ' ':"
        FPRINT FP_OUTPUT, "               // Count spaces (we'll insert leading spaces later) "
        FPRINT FP_OUTPUT, "               if (!space_for_positive || p != current_mask)"
        FPRINT FP_OUTPUT, "                   literal_chars++;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case '+':"
        FPRINT FP_OUTPUT, "               // Skip + if it's part of space-for-positive pattern"
        FPRINT FP_OUTPUT, "               if (!space_for_positive || p != current_mask + 1)"
        FPRINT FP_OUTPUT, "                   literal_chars++;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case '0':"
        FPRINT FP_OUTPUT, "               if (past_decimal) zeros_right++;"
        FPRINT FP_OUTPUT, "               else zeros_left++;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case '#':"
        FPRINT FP_OUTPUT, "               if (past_decimal) hash_right++;"
        FPRINT FP_OUTPUT, "               else hash_left++;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case '.':"
        FPRINT FP_OUTPUT, "               has_decimal = 1;"
        FPRINT FP_OUTPUT, "               past_decimal = 1;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case '%':"
        FPRINT FP_OUTPUT, "               has_percent = 1;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case ',':"
        FPRINT FP_OUTPUT, "               has_comma = 1;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case 'E':"
        FPRINT FP_OUTPUT, "               sci_uppercase = 1;"
        FPRINT FP_OUTPUT, "               // Fall through"
        FPRINT FP_OUTPUT, "           case 'e':"
        FPRINT FP_OUTPUT, "               if (*(p+1) == '+' || *(p+1) == '-')"
        FPRINT FP_OUTPUT, "               {"
        FPRINT FP_OUTPUT, "                   sci_notation = 1;"
        FPRINT FP_OUTPUT, "                   if (*(p+1) == '+') sci_plus = 1;"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case '*':"
        FPRINT FP_OUTPUT, "               if (*(p+1)) {"
        FPRINT FP_OUTPUT, "                   fill_char = *(p+1);"
        FPRINT FP_OUTPUT, "                   p++;"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case 92:"
        FPRINT FP_OUTPUT, "               literal_chars++;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "           case 34:"
        FPRINT FP_OUTPUT, "               // Count characters inside quotes as literals"
        FPRINT FP_OUTPUT, "               p++;"
        FPRINT FP_OUTPUT, "               while (*p && *p != 34)"
        FPRINT FP_OUTPUT, "               {"
        FPRINT FP_OUTPUT, "                   literal_chars++;"
        FPRINT FP_OUTPUT, "                   p++;"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "       p++;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   // Count leading spaces in mask so we can insert them into the output"
        FPRINT FP_OUTPUT, "   int leading_spaces = 0;"
        FPRINT FP_OUTPUT, "   char *ms = (char*)current_mask;"
        FPRINT FP_OUTPUT, "   if (space_for_positive)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       // Skip the initial space and + for space-for-positive"
        FPRINT FP_OUTPUT, "       ms += 2;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   else if (has_plus_sign)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       // Skip the + sign"
        FPRINT FP_OUTPUT, "       ms += 1;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   // If mask has parentheses, skip the opening parenthesis for space counting"
        FPRINT FP_OUTPUT, "   if (mask_has_parentheses && *ms == '(')"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       ms++;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   while (*ms == ' ') { leading_spaces++; ms++; }"
        FPRINT FP_OUTPUT, "   // Apply percent conversion"
        FPRINT FP_OUTPUT, "   long double work_num = Num;"
        FPRINT FP_OUTPUT, "   if (has_percent) work_num *= 100.0L;"
        FPRINT FP_OUTPUT, "   "
        FPRINT FP_OUTPUT, "   // Process scientific notation"
        FPRINT FP_OUTPUT, "   if (sci_notation)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       // Count decimal places from the mask pattern"
        FPRINT FP_OUTPUT, "       int precision = 0;"
        FPRINT FP_OUTPUT, "       PCTSTR mask_p = current_mask;"
        FPRINT FP_OUTPUT, "       int found_decimal = 0;"
        FPRINT FP_OUTPUT, "       while (*mask_p && (*mask_p != 'E' && *mask_p != 'e'))"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           if (found_decimal && (*mask_p == '0' || *mask_p == '#'))"
        FPRINT FP_OUTPUT, "               precision++;"
        FPRINT FP_OUTPUT, "           else if (*mask_p == '.')"
        FPRINT FP_OUTPUT, "               found_decimal = 1;"
        FPRINT FP_OUTPUT, "           mask_p++;"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "       if (precision == 0) precision = 2; // Default precision"
        FPRINT FP_OUTPUT, "       char fmt[32];"
        FPRINT FP_OUTPUT, "       if (sci_uppercase)"
        FPRINT FP_OUTPUT, "           sprintf(fmt, ", ENC$("%%.%dE"), ", precision);"
        FPRINT FP_OUTPUT, "       else"
        FPRINT FP_OUTPUT, "           sprintf(fmt, ", ENC$("%%.%de"), ", precision);"
        FPRINT FP_OUTPUT, "       sprintf(BCX_RetStr, fmt, (double)work_num);"
        FPRINT FP_OUTPUT, "       "
        FPRINT FP_OUTPUT, "       // Fix exponent formatting to match expected output"
        FPRINT FP_OUTPUT, "       char *e_pos = strpbrk(BCX_RetStr, ", ENC$("Ee"), ");"
        FPRINT FP_OUTPUT, "       if (e_pos)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           char *exp_start = e_pos + 1;"
        FPRINT FP_OUTPUT, "           int exp_val = 0;"
        FPRINT FP_OUTPUT, "           int is_negative = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "           // Parse the exponent value"
        FPRINT FP_OUTPUT, "           if (*exp_start == '+' || *exp_start == '-')"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               is_negative = (*exp_start == '-');"
        FPRINT FP_OUTPUT, "               exp_val = atoi(exp_start + 1);"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "           else"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               exp_val = atoi(exp_start);"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "           // Format exponent correctly based on pattern"
        FPRINT FP_OUTPUT, "           if (sci_plus)"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               // Always show sign (E+00 or E-00)"
        FPRINT FP_OUTPUT, "               sprintf(exp_start, is_negative ? ", ENC$("-%02d"), " : ", ENC$("+%02d"), ", exp_val);"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "           else"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               // Only show - for negative (e-00 or e00)"
        FPRINT FP_OUTPUT, "               sprintf(exp_start, is_negative ? ", ENC$("-%02d"), " : ", ENC$("%02d"), ", exp_val);"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "       if (has_percent) strcat(BCX_RetStr, ", ENC$("%"), ");"
        FPRINT FP_OUTPUT, "       // Add parentheses if mask had them"
        FPRINT FP_OUTPUT, "       if (mask_has_parentheses)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           char temp[256];"
        FPRINT FP_OUTPUT, "           strcpy(temp, BCX_RetStr);"
        FPRINT FP_OUTPUT, "           sprintf(BCX_RetStr, ", ENC$("%s%s%s"), ", mask_prefix, temp, mask_suffix);"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "       return BCX_RetStr;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // Handle fill character patterns first"
        FPRINT FP_OUTPUT, "   if (fill_char)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       // Count total digit positions needed"
        FPRINT FP_OUTPUT, "       int total_positions = zeros_left + hash_left;"
        FPRINT FP_OUTPUT, "       if (total_positions > 0)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           // Format number as string first"
        FPRINT FP_OUTPUT, "           char temp_num[64];"
        FPRINT FP_OUTPUT, "           sprintf(temp_num, ", ENC$("%.0Lf"), ", work_num);"
        FPRINT FP_OUTPUT, "           int num_len = (int)strlen(temp_num);"
        FPRINT FP_OUTPUT, "           if (temp_num[0] == '-') num_len--; // Don't count minus sign"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "           // Build result with fill character"
        FPRINT FP_OUTPUT, "           memset(BCX_RetStr, 0, 256);"
        FPRINT FP_OUTPUT, "           int pos = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "           // Add negative sign if needed"
        FPRINT FP_OUTPUT, "           if (temp_num[0] == '-')"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               BCX_RetStr[pos++] = '-';"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "           // Add fill characters"
        FPRINT FP_OUTPUT, "           int actual_digits = (temp_num[0] == '-') ? num_len : num_len;"
        FPRINT FP_OUTPUT, "           for (int i = actual_digits; i < total_positions; i++)"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               BCX_RetStr[pos++] = (char)fill_char;"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "           // Add the number (without sign if already added)"
        FPRINT FP_OUTPUT, "           strcpy(BCX_RetStr + pos, (temp_num[0] == '-') ? temp_num + 1 : temp_num);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "           if (has_percent) strcat(BCX_RetStr, ", ENC$("%"), ");"
        FPRINT FP_OUTPUT, "           // Add parentheses if mask had them"
        FPRINT FP_OUTPUT, "           if (mask_has_parentheses)"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               char temp[256];"
        FPRINT FP_OUTPUT, "               strcpy(temp, BCX_RetStr);"
        FPRINT FP_OUTPUT, "               sprintf(BCX_RetStr, ", ENC$("%s%s%s"), ", mask_prefix, temp, mask_suffix);"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "           return BCX_RetStr;"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // Calculate decimal places needed"
        FPRINT FP_OUTPUT, "   int decimal_places = zeros_right + hash_right;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // Format the basic number"
        FPRINT FP_OUTPUT, "   if (decimal_places > 0 || has_decimal)"
        FPRINT FP_OUTPUT, "       sprintf(Buf_1, ", ENC$("%.*Lf"), ", decimal_places, work_num);"
        FPRINT FP_OUTPUT, "   else"
        FPRINT FP_OUTPUT, "       sprintf(Buf_1, ", ENC$("%.0Lf"), ", work_num);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // Remove trailing zeros for hash (#) format when no zeros specified"
        FPRINT FP_OUTPUT, "   if (hash_right > 0 && zeros_right == 0 && strchr(Buf_1, '.'))"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       char *end = Buf_1 + strlen(Buf_1) - 1;"
        FPRINT FP_OUTPUT, "       while (end > Buf_1 && *end == '0') *end-- = 0;"
        FPRINT FP_OUTPUT, "       if (end > Buf_1 && *end == '.') *end = 0;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // Process zero padding on the left"
        FPRINT FP_OUTPUT, "   char *decimal_pos = strchr(Buf_1, '.');"
        FPRINT FP_OUTPUT, "   int int_part_len = decimal_pos ? (int)(decimal_pos - Buf_1) : (int)strlen(Buf_1);"
        FPRINT FP_OUTPUT, "   int has_negative = (Buf_1[0] == '-');"
        FPRINT FP_OUTPUT, "   if (has_negative) int_part_len--;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   // Calculate total left padding needed"
        FPRINT FP_OUTPUT, "   int total_left_digits = zeros_left + hash_left;"
        FPRINT FP_OUTPUT, "   int padding_needed = 0;"
        FPRINT FP_OUTPUT, "   if (total_left_digits > int_part_len)"
        FPRINT FP_OUTPUT, "       padding_needed = total_left_digits - int_part_len;"
        FPRINT FP_OUTPUT, "   memset(BCX_RetStr, 0, 256);  // Build the result string"
        FPRINT FP_OUTPUT, "    if (has_negative && zeros_left > 0)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       // Negative with zero padding: -000123.45"
        FPRINT FP_OUTPUT, "       *BCX_RetStr = '-';"
        FPRINT FP_OUTPUT, "       for (int i = 0; i < padding_needed; i++)"
        FPRINT FP_OUTPUT, "           BCX_RetStr[1 + i] = '0';"
        FPRINT FP_OUTPUT, "       strcpy(BCX_RetStr + 1 + padding_needed, Buf_1 + 1);"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   else"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       // Positive or negative without zero padding"
        FPRINT FP_OUTPUT, "       if (padding_needed > 0 && zeros_left > 0)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           for (int i = 0; i < padding_needed; i++)"
        FPRINT FP_OUTPUT, "               BCX_RetStr[i] = '0';"
        FPRINT FP_OUTPUT, "           strcpy(BCX_RetStr + padding_needed, Buf_1);"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "       else"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           strcpy(BCX_RetStr, Buf_1); // No special padding"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   // Handle explicit + sign for positive numbers"
        FPRINT FP_OUTPUT, "   if (has_plus_sign && work_num >= 0 && BCX_RetStr[0] != '-')"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       int cur_len = (int)strlen(BCX_RetStr);"
        FPRINT FP_OUTPUT, "       if (cur_len < 255)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           memmove(BCX_RetStr + 1, BCX_RetStr, cur_len + 1);"
        FPRINT FP_OUTPUT, "           BCX_RetStr[0] = '+';"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   // Handle space-for-positive formatting"
        FPRINT FP_OUTPUT, "   if (space_for_positive)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       if (work_num >= 0 && BCX_RetStr[0] != '-')"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           // Insert space at beginning for positive numbers"
        FPRINT FP_OUTPUT, "           int cur_len = (int)strlen(BCX_RetStr);"
        FPRINT FP_OUTPUT, "           if (cur_len < 255)"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               memmove(BCX_RetStr + 1, BCX_RetStr, cur_len + 1);"
        FPRINT FP_OUTPUT, "               BCX_RetStr[0] = ' ';"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   // Insert leading mask spaces (if any)"
        FPRINT FP_OUTPUT, "   if (leading_spaces > 0)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       int cur_len = (int)strlen(BCX_RetStr);"
        FPRINT FP_OUTPUT, "       if (cur_len + leading_spaces < 256)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           memmove(BCX_RetStr + leading_spaces, BCX_RetStr, cur_len + 1);"
        FPRINT FP_OUTPUT, "           for (int i = 0; i < leading_spaces; i++)"
        FPRINT FP_OUTPUT, "               BCX_RetStr[i] = ' ';"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   if (has_comma)  // Add thousand separators (commas)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       char temp[256];"
        FPRINT FP_OUTPUT, "       strcpy(temp, BCX_RetStr);"
        FPRINT FP_OUTPUT, "       char *dec = strchr(temp, '.');   // Find where integer part ends"
        FPRINT FP_OUTPUT, "       int int_end = dec ? (int)(dec - temp) : (int)strlen(temp);"
        FPRINT FP_OUTPUT, "        // Add commas from right to left in integer part"
        FPRINT FP_OUTPUT, "       for (int pos = int_end - 3; pos > 0; pos -= 3)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "           if (temp[pos-1] != '-' && temp[pos-1] != ' ' && temp[pos-1] != '+') // Don't add comma right after sign or space"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "               memmove(temp + pos + 1, temp + pos, strlen(temp + pos) + 1);"
        FPRINT FP_OUTPUT, "               temp[pos] = ',';"
        FPRINT FP_OUTPUT, "               int_end++; // Adjust end position"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "       strcpy(BCX_RetStr, temp);"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   if (has_percent)  strcat(BCX_RetStr, ", ENC$("%"), ");"
        FPRINT FP_OUTPUT, "   "
        FPRINT FP_OUTPUT, "   // Add parentheses if mask had them as literal characters"
        FPRINT FP_OUTPUT, "   if (mask_has_parentheses)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "       char temp[256];"
        FPRINT FP_OUTPUT, "       strcpy(temp, BCX_RetStr);"
        FPRINT FP_OUTPUT, "       sprintf(BCX_RetStr, ", ENC$("%s%s%s"), ", mask_prefix, temp, mask_suffix);"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   "
        FPRINT FP_OUTPUT, "   return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_SearchPath THEN
        FPRINT FP_OUTPUT, "char *SEARCHPATH (PCTSTR szFile)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr = BCX_TempStr(MAX_PATH+1);"
        FPRINT FP_OUTPUT, "  PSTR lpbs = 0;"
        FPRINT FP_OUTPUT, "  SearchPath(0, szFile, 0, MAX_PATH, BCX_RetStr, &lpbs);"
        FPRINT FP_OUTPUT, "  if (lpbs) *lpbs = 0;"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_stricmp THEN                ' Locale-specific version
        FPRINT FP_OUTPUT, "int bcx_stricmp (PCTSTR szOne, PCTSTR szTwo)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char  c1 [BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  char  c2 [BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  strcpy(c1,szOne);"
        FPRINT FP_OUTPUT, "  strcpy(c2,szTwo);"
        FPRINT FP_OUTPUT, "  CharUpperA(c1);"
        FPRINT FP_OUTPUT, "  CharUpperA(c2);"
        FPRINT FP_OUTPUT, "  int counter=0;"
        FPRINT FP_OUTPUT, "  for(;;)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if(c1[counter]^c2[counter])"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if(c1[counter]>c2[counter])"
        FPRINT FP_OUTPUT, "        return  1;"
        FPRINT FP_OUTPUT, "      return -1;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if(!c1[counter]) return 0;"
        FPRINT FP_OUTPUT, "    counter++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Stristr THEN
        FPRINT FP_OUTPUT, "char *_stristr_(PCTSTR Haystack, PCTSTR Needle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int mi = (-1);"
        FPRINT FP_OUTPUT, "  while(Needle[++mi])"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (Haystack[mi]==0) return 0;"
        FPRINT FP_OUTPUT, "    if (UprCase[(unsigned char)Haystack[mi]] != UprCase[(unsigned char)Needle[mi]])"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      Haystack++;"
        FPRINT FP_OUTPUT, "      mi = (-1);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return (char*)Haystack;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF




    IF Use_sziif THEN
        FPRINT FP_OUTPUT, "char *sziif (int cond, PCTSTR szOne, PCTSTR szTwo)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (cond!=0) return (char*)szOne;"
        FPRINT FP_OUTPUT, "  return (char*)szTwo;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Retain THEN
        FPRINT FP_OUTPUT, "char *Retain (PCTSTR Text, PCTSTR ValidChars)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr = BCX_TempStr(strlen(Text));"
        FPRINT FP_OUTPUT, "  char *temp = BCX_RetStr;"
        FPRINT FP_OUTPUT, "  while(*Text)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (strchr(ValidChars, *Text)) *(temp++) = *Text;"
        FPRINT FP_OUTPUT, "    Text++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_FormatPath1



SUB Emit_RT_FormatPath2 (FP_OUTPUT AS FILE)
    IF Use_LoadFile THEN
        FPRINT FP_OUTPUT, "char* LoadFile (PCTSTR lfName)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  FILE* Channel;"
        FPRINT FP_OUTPUT, "  char* BCX_RetStr;"
        FPRINT FP_OUTPUT, "  if (Exist(lfName))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(lof(lfName)+1);"
        FPRINT FP_OUTPUT, "    if ((Channel = fopen(lfName, ", ENC$("rb"), "))!=0)"
        FPRINT FP_OUTPUT, "    GET(Channel, BCX_RetStr, lof(lfName));"
        FPRINT FP_OUTPUT, "    fclose(Channel);"
        FPRINT FP_OUTPUT, "    Channel = NULL;"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(128);"
        FPRINT FP_OUTPUT, "    return strcpy(BCX_RetStr,", ENC$("Error: Cannot Access File or File Not Found. %s\\n"), ");"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_PeekStr THEN
        FPRINT FP_OUTPUT, "char *peekstr (PVOID Src, int Count)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *Des = BCX_TempStr(Count);"
        FPRINT FP_OUTPUT, "  memmove(Des, Src, Count);"
        FPRINT FP_OUTPUT, "  return Des;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Getaddr THEN
        FPRINT FP_OUTPUT, "char *GetAddr (PVOID X)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   char *BCX_RetStr = BCX_TempStr(64);"
        FPRINT FP_OUTPUT, "   // Cast pointer to uintptr_t so it safely adapts to 32-bit or 64-bit"
        FPRINT FP_OUTPUT, "   snprintf(BCX_RetStr, 64, ", ENC$("0x%016"), " PRIxPTR, (uintptr_t)X);"
        FPRINT FP_OUTPUT, "   return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Setaddr THEN
        FPRINT FP_OUTPUT, "void SetAddr (int* Adr, int value)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   (*Adr)=value;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Inputbox THEN
        FPRINT FP_OUTPUT, "char *InputBox (PCTSTR Title, PCTSTR Prompt, PCTSTR Value, int iHide)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr;"
        FPRINT FP_OUTPUT, "  CreatePrompter(Title, Prompt, Value, iHide);"
        FPRINT FP_OUTPUT, "  BCX_RetStr = BCX_TempStr(strlen(BCX_INPUTBOX_VAL));"
        FPRINT FP_OUTPUT, "  return strcpy(BCX_RetStr, BCX_INPUTBOX_VAL);"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, "LRESULT CreatePrompter (PCTSTR Title, PCTSTR Prpt, PCTSTR Value, int iHide)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  LPDLGITEMTEMPLATE lpdit;"
        FPRINT FP_OUTPUT, "  LPDLGTEMPLATE lpdt;"
        FPRINT FP_OUTPUT, "  HINSTANCE hInst;"
        FPRINT FP_OUTPUT, "  HGLOBAL hgbl;"
        FPRINT FP_OUTPUT, "  LRESULT ret;"
        FPRINT FP_OUTPUT, "  PWORD lpw;"
        FPRINT FP_OUTPUT, "  PWSTR lpwsz;"
        FPRINT FP_OUTPUT, "  ULONG  MyStyle;"
        FPRINT FP_OUTPUT, "  int ID_CANCEL = 101;"
        FPRINT FP_OUTPUT, "  int ID_TEXT   = 102;"
        FPRINT FP_OUTPUT, "  int ID_EDIT   = 103;"
        FPRINT FP_OUTPUT, "  int ID_OK     = 104;"
        FPRINT FP_OUTPUT, "  hgbl = GlobalAlloc(GMEM_ZEROINIT, 32767);"
        FPRINT FP_OUTPUT, "  lpdt = (LPDLGTEMPLATE)GlobalLock(hgbl);\n"
        FPRINT FP_OUTPUT, "  MyStyle = WS_VISIBLE|DS_NOFAILCREATE|WS_BORDER|DS_CENTER|DS_SETFONT;"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  //  Create the InputBox Window"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  lpdt->style = MyStyle;"
        FPRINT FP_OUTPUT, "  lpdt->cdit = 4;"
        FPRINT FP_OUTPUT, "  lpdt->cx = 160;"
        FPRINT FP_OUTPUT, "  lpdt->cy =  70;"
        FPRINT FP_OUTPUT, "  lpw = (PWORD)(lpdt+1);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;"
        FPRINT FP_OUTPUT, "  lpwsz = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  lpw += MultiByteToWideChar(CP_ACP, 0, Title, -1, lpwsz, 1+strlen(Title)*2);"
        FPRINT FP_OUTPUT, "  *lpw++ = DEFAULT_PITCH;"
        FPRINT FP_OUTPUT, "  lpwsz = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  lpw += MultiByteToWideChar(CP_ACP, 0, ", ENC$("MS Sans Serif") , ", -1, lpwsz, 27);"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  //  Create the CANCEL button."
        FPRINT FP_OUTPUT, "  // ********************************\n"
        FPRINT FP_OUTPUT, "  lpw   = lpwAlign(lpw);"
        FPRINT FP_OUTPUT, "  lpdit = (LPDLGITEMTEMPLATE)lpw;"
        FPRINT FP_OUTPUT, "  lpdit->x  = 95;"
        FPRINT FP_OUTPUT, "  lpdit->y  = 31;"
        FPRINT FP_OUTPUT, "  lpdit->cx = 35;"
        FPRINT FP_OUTPUT, "  lpdit->cy = 12;"
        FPRINT FP_OUTPUT, "  lpdit->id=(SHORT)ID_CANCEL;"
        FPRINT FP_OUTPUT, "  lpdit->style = WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  lpw = (PWORD)(lpdit+1);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0xFFFF;"
        FPRINT FP_OUTPUT, "  *lpw++ = 0x0080;"
        FPRINT FP_OUTPUT, "  lpwsz  = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  lpw += MultiByteToWideChar(CP_ACP, 0, " , ENC$("CANCEL"), ", -1, lpwsz, 13);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  //  Create the OK button."
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  lpw   = lpwAlign(lpw);"
        FPRINT FP_OUTPUT, "  lpdit = (LPDLGITEMTEMPLATE)lpw;"
        FPRINT FP_OUTPUT, "  lpdit->x = 20;"
        FPRINT FP_OUTPUT, "  lpdit->y = 31;"
        FPRINT FP_OUTPUT, "  lpdit->cx= 35;"
        FPRINT FP_OUTPUT, "  lpdit->cy= 12;"
        FPRINT FP_OUTPUT, "  lpdit->id=(SHORT)ID_OK;"
        FPRINT FP_OUTPUT, "  lpdit->style = WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  lpw    = (PWORD)(lpdit+1);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0xFFFF;"
        FPRINT FP_OUTPUT, "  *lpw++ = 0x0080;"
        FPRINT FP_OUTPUT, "  lpwsz  = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  lpw += MultiByteToWideChar(CP_ACP, 0, ", ENC$("OK"), ", -1, lpwsz, 5);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  //  Create the STATIC control"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  lpw   = lpwAlign(lpw);"
        FPRINT FP_OUTPUT, "  lpdit = (LPDLGITEMTEMPLATE)lpw;"
        FPRINT FP_OUTPUT, "  lpdit->x  =  10;"
        FPRINT FP_OUTPUT, "  lpdit->y  =   5;"
        FPRINT FP_OUTPUT, "  lpdit->cx = 140;"
        FPRINT FP_OUTPUT, "  lpdit->cy =  10;"
        FPRINT FP_OUTPUT, "  lpdit->id=(SHORT)ID_TEXT;"
        FPRINT FP_OUTPUT, "  lpdit->style = WS_CHILD|WS_VISIBLE|SS_LEFT;"
        FPRINT FP_OUTPUT, "  lpw=(PWORD)(lpdit+1);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0xFFFF;"
        FPRINT FP_OUTPUT, "  *lpw++ = 0x0082;"
        FPRINT FP_OUTPUT, "  lpwsz  = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  lpw += MultiByteToWideChar(CP_ACP, 0, Prpt, -1, lpwsz, 1+strlen(Prpt)*2);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;     // no creation data"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  //  Create the EDIT control"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  lpw   = (PWORD)lpwAlign(lpw);"
        FPRINT FP_OUTPUT, "  lpdit = (LPDLGITEMTEMPLATE)lpw;"
        FPRINT FP_OUTPUT, "  lpdit->x  =  10;"
        FPRINT FP_OUTPUT, "  lpdit->y  =  15;"
        FPRINT FP_OUTPUT, "  lpdit->cx = 130;"
        FPRINT FP_OUTPUT, "  lpdit->cy =  12;"
        FPRINT FP_OUTPUT, "  lpdit->id=(SHORT)ID_EDIT;"
        FPRINT FP_OUTPUT, "  if (iHide==0)"
        FPRINT FP_OUTPUT, "    lpdit->style = WS_CHILD|WS_TABSTOP|WS_VISIBLE|ES_AUTOHSCROLL|WS_BORDER;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    lpdit->style = ES_PASSWORD|WS_CHILD|WS_TABSTOP|WS_VISIBLE|ES_AUTOHSCROLL|WS_BORDER;"
        FPRINT FP_OUTPUT, "  lpw    = (PWORD)(lpdit+1);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0xFFFF;"
        FPRINT FP_OUTPUT, "  *lpw++ = 0x0081;"
        FPRINT FP_OUTPUT, "  lpwsz  = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  lpw += MultiByteToWideChar(CP_ACP, 0, Value, -1, lpwsz, 1+strlen(Value)*2);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;"
        FPRINT FP_OUTPUT, "  // ******************"
        FPRINT FP_OUTPUT, "  GlobalUnlock(hgbl);"
        FPRINT FP_OUTPUT, "  hInst = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(0, GWLP_HINSTANCE);"
        FPRINT FP_OUTPUT, "  ret = DialogBoxIndirect (hInst, (LPDLGTEMPLATE)hgbl, GetActiveWindow(), (DLGPROC)Prompter);"
        FPRINT FP_OUTPUT, "  GlobalFree(hgbl);"
        FPRINT FP_OUTPUT, "  return ret;"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, "LRESULT CALLBACK Prompter (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int ID_CANCEL = 101;"
        FPRINT FP_OUTPUT, "  int ID_EDIT   = 103;"
        FPRINT FP_OUTPUT, "  int ID_OK     = 104;\n"
        FPRINT FP_OUTPUT, "  for(;;)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (Msg == WM_INITDIALOG)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      SetFocus(GetDlgItem(hWnd, ID_EDIT));"
        FPRINT FP_OUTPUT, "      return 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (Msg == WM_COMMAND)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (LOWORD(wParam) == ID_OK)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        GetDlgItemText(hWnd, ID_EDIT, BCX_INPUTBOX_VAL, BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "        EndDialog(hWnd, 0);"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      if (LOWORD(wParam) == ID_CANCEL)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        *BCX_INPUTBOX_VAL = 0;"
        FPRINT FP_OUTPUT, "        SendMessage(hWnd, WM_CLOSE, 0, 0);"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      break;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (Msg == WM_CLOSE)"
        FPRINT FP_OUTPUT, "      EndDialog(hWnd, 0);"
        FPRINT FP_OUTPUT, "    break;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_GetSpecialFolder THEN
        FPRINT FP_OUTPUT, "char *GetSpecialFolder (int nFolder, int bCreate, HWND hWnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr = BCX_TempStr(MAX_PATH);"
        FPRINT FP_OUTPUT, "  if (!SHGetSpecialFolderPath(hWnd, BCX_RetStr, nFolder, bCreate))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr[0]=0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_GetSpecialFolderex THEN
        FPRINT FP_OUTPUT    , "char *GetSpecialFolderEx(const GUID KFID, ULONG KFFlag)"
        FPRINT FP_OUTPUT    , "{"
        FPRINT FP_OUTPUT    , "  PCHAR BCX_RetStr;"
        FPRINT FP_OUTPUT    , "  CHAR  szBuffer[2048];"
        FPRINT FP_OUTPUT    , "  static PWSTR pwsBuffer;"
        FPRINT FP_OUTPUT    , "  if (NULL == pwsBuffer)"
        FPRINT FP_OUTPUT    , "    {"
        FPRINT FP_OUTPUT    , "      pwsBuffer = (PWSTR)calloc(2048, sizeof(char)+1);"
        FPRINT FP_OUTPUT    , "    }"
        FPRINT FP_OUTPUT    , "  #ifndef __cplusplus"
        FPRINT FP_OUTPUT    , "     int rc = SHGetKnownFolderPath(&KFID, KFFlag, 0, &pwsBuffer);"
        FPRINT FP_OUTPUT    , "  #else"
        FPRINT FP_OUTPUT    , "     int rc = SHGetKnownFolderPath(KFID, KFFlag, 0, &pwsBuffer);"
        FPRINT FP_OUTPUT    , "  #endif"
        FPRINT FP_OUTPUT    , "  if (S_OK == rc)"
        FPRINT FP_OUTPUT    , "    {"
        FPRINT FP_OUTPUT    , "      strcpy(szBuffer, WideToAnsi(pwsBuffer));"
        FPRINT FP_OUTPUT    , "      BCX_RetStr = BCX_TempStr(strlen(szBuffer));"
        FPRINT FP_OUTPUT    , "      strcpy(BCX_RetStr, szBuffer);"
        FPRINT FP_OUTPUT    , "      return BCX_RetStr;"
        FPRINT FP_OUTPUT    , "    }"
        FPRINT FP_OUTPUT    , "  BCX_RetStr = 0;"
        FPRINT FP_OUTPUT    , "  return BCX_RetStr;"
        FPRINT FP_OUTPUT    , "}\n\n"
    END IF



    IF Use_GetText THEN
        FPRINT FP_OUTPUT, "char *BCX_Get_Text (HWND hWnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int tmpint;"
        FPRINT FP_OUTPUT, "  tmpint = 1 + GetWindowTextLength(hWnd);"
        FPRINT FP_OUTPUT, "  char *strtmp = BCX_TempStr(tmpint);"
        FPRINT FP_OUTPUT, "  GetWindowText(hWnd,strtmp,tmpint);"
        FPRINT FP_OUTPUT, "  return strtmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Bff THEN
        FPRINT FP_OUTPUT, "char *BFF(PCTSTR Instructions,int BIF_Flags,PCTSTR InitPath)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr = BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  CoInitialize(NULL);"
        FPRINT FP_OUTPUT, "  BROWSEINFO tBFF = {0, 0, 0, 0, 0, NULL, 0, 0};"
        FPRINT FP_OUTPUT, "  LPITEMIDLIST lpIDList = {0};"
        FPRINT FP_OUTPUT, "  tBFF.hwndOwner = GetActiveWindow();"
        FPRINT FP_OUTPUT, "  tBFF.lpszTitle = Instructions;"
        FPRINT FP_OUTPUT, "  tBFF.ulFlags = BIF_Flags;"
        FPRINT FP_OUTPUT, "  if (InitPath)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    tBFF.lpfn = BFFCallBack;"
        FPRINT FP_OUTPUT, "    tBFF.lParam = (LPARAM)InitPath;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  lpIDList = SHBrowseForFolder(&tBFF);"
        FPRINT FP_OUTPUT, "  if (lpIDList != NULL)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    SHGetPathFromIDList((LPITEMIDLIST)lpIDList, BCX_RetStr);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  CoTaskMemFree(lpIDList);"
        FPRINT FP_OUTPUT, "  CoUninitialize();"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, "int CALLBACK BFFCallBack (HWND hWnd, UINT Msg, LPARAM lparam, LPARAM lpData)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (Msg == BFFM_INITIALIZED)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (GetFileAttributes((char*)lpData) != 0xffffffff)"
        FPRINT FP_OUTPUT, "      SendMessage(hWnd,(UINT_PTR)BFFM_SETSELECTION, (WPARAM)TRUE, (LPARAM)(char*)lpData);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BcxSplitPath THEN
        FPRINT FP_OUTPUT, "char *BcxSplitPath (PCTSTR FPath, int mask)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!FPath) return BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr = BCX_TempStr(strlen(FPath));"
        FPRINT FP_OUTPUT, "  char tmp[MAX_PATH*4];"
        FPRINT FP_OUTPUT, "  _splitpath(FPath, tmp, &tmp[MAX_PATH], &tmp[MAX_PATH*2], &tmp[MAX_PATH*3]);"
        FPRINT FP_OUTPUT, "  if (mask & FDRV) strcat(BCX_RetStr, tmp);"
        FPRINT FP_OUTPUT, "  if (mask & FPATH)strcat(BCX_RetStr, &tmp[MAX_PATH]);"
        FPRINT FP_OUTPUT, "  if (mask & FNAME)strcat(BCX_RetStr, &tmp[MAX_PATH*2]);"
        FPRINT FP_OUTPUT, "  if (mask & FEXT) strcat(BCX_RetStr, &tmp[MAX_PATH*3]);"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Path THEN
        FPRINT FP_OUTPUT, "char *BcxPath (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RegPath=BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  strcpy(BCX_RegPath,RegString"
        FPRINT FP_OUTPUT, "         (HKEY_LOCAL_MACHINE,", ENC$("Software\\\\Bcx-32\\\\Bcx\\\\Settings"), ",", ENC$("Path"), "));"
        FPRINT FP_OUTPUT, "  if (BCX_RegPath[0] == 0)"
        FPRINT FP_OUTPUT, "    strcpy(BCX_RegPath,RegString"
        FPRINT FP_OUTPUT, "           (HKEY_CURRENT_USER,", ENC$("Software\\\\Bcx-32\\\\Bcx\\\\Settings"), ",", ENC$("Path"), "));"
        FPRINT FP_OUTPUT, "  if (BCX_RegPath[0] == 0)"
        FPRINT FP_OUTPUT, "    return strcpy(BCX_RegPath,", ENC$("Not Found"), ");"
        FPRINT FP_OUTPUT, "  return BCX_RegPath;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_LccPath THEN
        FPRINT FP_OUTPUT, "char *LccPath (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr={0};"
        FPRINT FP_OUTPUT, "  static char LCC_Reg     [BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  static char LCC_RegPath [BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  strcpy(LCC_Reg,", ENC$("Software\\\\lcc\\\\lcclnk\\\\"), ");"
        FPRINT FP_OUTPUT, "  strcpy(LCC_RegPath,(char*)RegString(HKEY_LOCAL_MACHINE, LCC_Reg,", ENC$("libpath"), "));"
        FPRINT FP_OUTPUT, "  if (LCC_RegPath[0] == 0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    strcpy(LCC_RegPath, (char*)RegString(HKEY_CURRENT_USER, LCC_Reg,", ENC$("libpath"), "));"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (strcmp(LCC_RegPath,", DDQ$, ")!=0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(260);"
        FPRINT FP_OUTPUT, "    return strcpy(BCX_RetStr, (char*)left(LCC_RegPath, InstrRev(LCC_RegPath,", ENC$("\\\\"), ")));"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr=BCX_TempStr(strlen(LCC_RegPath));"
        FPRINT FP_OUTPUT, "    return strcpy(BCX_RetStr,LCC_RegPath);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_PellesPath THEN
        FPRINT FP_OUTPUT, "char *PellesPath (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr={0};"
        FPRINT FP_OUTPUT, "  static char Pelles_Reg     [BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  static char Pelles_RegPath [BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  strcpy(Pelles_Reg,", ENC$("Software\\\\Pelle Orinius\\\\PellesC\\\\Directories\\\\"), ");"
        FPRINT FP_OUTPUT, "  strcpy(Pelles_RegPath,(char*)RegString(HKEY_LOCAL_MACHINE,Pelles_Reg,", ENC$("PathDirs"), "));"
        FPRINT FP_OUTPUT, "  if (Pelles_RegPath[0]==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    strcpy(Pelles_RegPath,(char*)RegString(HKEY_CURRENT_USER,Pelles_Reg,", ENC$("PathDirs"), "));"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (strcmp(Pelles_RegPath,", DDQ$, ")!=0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr=BCX_TempStr(256);"
        FPRINT FP_OUTPUT, "    return strcpy(BCX_RetStr,(char*)left(Pelles_RegPath,InstrRev(Pelles_RegPath,", ENC$("\\\\"), ")));"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(strlen(Pelles_RegPath));"
        FPRINT FP_OUTPUT, "    return strcpy(BCX_RetStr, Pelles_RegPath);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_RegString THEN
        FPRINT FP_OUTPUT, "char *RegString (HKEY hKey, PCTSTR RegPath, PCTSTR SubKey)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *Result = BCX_TempStr (BCXSTRSIZE);"
        FPRINT FP_OUTPUT, "  int BufferLen = BCXSTRSIZE;"
        FPRINT FP_OUTPUT, "  if (!RegOpenKeyEx(hKey,RegPath,0,KEY_QUERY_VALUE,&hKey))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    RegQueryValueEx(hKey,SubKey,0,0,(PBYTE)Result,(PDWORD)&BufferLen);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  RegCloseKey(hKey);"
        FPRINT FP_OUTPUT, "  return Result;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_CreateRegString THEN
        FPRINT FP_OUTPUT, "void CreateRegString (HKEY HK, PCTSTR Key, PCTSTR VarName, PCTSTR Value)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HKEY  hKey;"
        FPRINT FP_OUTPUT, "  char  Buff[100]={0};"
        FPRINT FP_OUTPUT, "  ULONG  Result;"
        FPRINT FP_OUTPUT, "  RegCreateKeyEx(HK,Key,0,Buff,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,&hKey,&Result);"
        FPRINT FP_OUTPUT, "  RegSetValueEx(hKey,VarName,0,REG_SZ,(PBYTE)Value,(ULONG)strlen(Value)+1);"
        FPRINT FP_OUTPUT, "  RegCloseKey(hKey);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Strtoken THEN
        FPRINT FP_OUTPUT, "char *StrToken (PCTSTR Source, PCTSTR TokenChar, int n)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr = NULL;"
        FPRINT FP_OUTPUT, "  char *RetVal = NULL;"
        FPRINT FP_OUTPUT, "  PCTSTR Copy = NULL;"
        FPRINT FP_OUTPUT, "  int Posn = 0;"
        FPRINT FP_OUTPUT, "  int Find = 0;"
        FPRINT FP_OUTPUT, "  int LenSrc = (int)strlen(Source);"
        FPRINT FP_OUTPUT, "  Copy = Source;"
        FPRINT FP_OUTPUT, "  if (tally(Source,TokenChar)==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr=BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (n==1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(LenSrc);"
        FPRINT FP_OUTPUT, "    strcpy(BCX_RetStr,(char*)extract(Source,TokenChar));"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (n>tally(Source,TokenChar)+1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr=BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  while(*Copy)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*Copy==TokenChar[0]) Find++;"
        FPRINT FP_OUTPUT, "    if (Find==n) break;"
        FPRINT FP_OUTPUT, "    Copy++;"
        FPRINT FP_OUTPUT, "    Posn++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (n==tally(Source,TokenChar)+1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Posn=LenSrc;"
        FPRINT FP_OUTPUT, "    Copy=Source+Posn;"
        FPRINT FP_OUTPUT, "    while(*Copy && Source[Posn]!=TokenChar[0])"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      Posn--;"
        FPRINT FP_OUTPUT, "      Copy--;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  RetVal = (char*)calloc(LenSrc+1,sizeof(char));"
        FPRINT FP_OUTPUT, "  strcpy(RetVal,(char*)mid(Source,1,Posn));"
        FPRINT FP_OUTPUT, "  strcpy(RetVal,(char*)mid(RetVal,InstrRev(RetVal,TokenChar)));"
        FPRINT FP_OUTPUT, "  BCX_RetStr=BCX_TempStr(LenSrc);"
        FPRINT FP_OUTPUT, "  strcpy(BCX_RetStr,(char*)RemoveStr(RetVal,(char*)TokenChar));"
        FPRINT FP_OUTPUT, "  if (RetVal)free(RetVal);"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_AnsiToWide THEN      ' 831  Robert Wishlaw corrected and enhanced this function
        FPRINT FP_OUTPUT, "//<---UNICODE AWARE"
        FPRINT FP_OUTPUT, "PWSTR AnsiToWide (PCSTR AnsiStr, UINT CodePage, ULONG dwFlags, BOOL NullTerm)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int AnsiByteLen;"
        FPRINT FP_OUTPUT, "  if (NullTerm)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    AnsiByteLen=-1;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    AnsiByteLen=(int)strlen(AnsiStr);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  int WideCharLen;"
        FPRINT FP_OUTPUT, "  WideCharLen = MultiByteToWideChar(CodePage, dwFlags, AnsiStr, AnsiByteLen, 0, 0);"
        FPRINT FP_OUTPUT, "  if (WideCharLen == 0) return (PWSTR)BCX_TempStr(2);"
        FPRINT FP_OUTPUT, "  PWSTR WideStr;"
        FPRINT FP_OUTPUT, "  WideStr = (PWSTR)BCX_TempStr(WideCharLen * sizeof(WCHAR));"
        FPRINT FP_OUTPUT, "  MultiByteToWideChar(CodePage, dwFlags, AnsiStr, AnsiByteLen, WideStr, WideCharLen);"
        FPRINT FP_OUTPUT, "  WideStr[WideCharLen] = 0;"
        FPRINT FP_OUTPUT, "  return WideStr;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, "//>---UNICODE AWARE\n"
    END IF


    IF Use_WideToAnsi THEN
        FPRINT FP_OUTPUT, "//<---UNICODE AWARE"
        FPRINT FP_OUTPUT, "char* WideToAnsi (PWSTR WideStr, UINT CodePage, ULONG dwFlags)"   ' 827 MrBcx - changed from BSTR
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr;"
        FPRINT FP_OUTPUT, "  UINT uLen;"
        FPRINT FP_OUTPUT, "  uLen = WideCharToMultiByte(CodePage, dwFlags, WideStr,-1,0,0,0,0);"
        FPRINT FP_OUTPUT, "  BCX_RetStr = (char*)BCX_TempStr(uLen);"
        FPRINT FP_OUTPUT, "  WideCharToMultiByte(CodePage, dwFlags, WideStr, -1, BCX_RetStr,uLen,0,0);"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, "//>---UNICODE AWARE\n"
    END IF


    IF Use_Mki THEN
        FPRINT FP_OUTPUT, "char *MKI (short cvt)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static char temp[3];"
        FPRINT FP_OUTPUT, "  return (char*)memmove(temp,&cvt,2);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Mkl THEN
        FPRINT FP_OUTPUT, "char *MKL (int cvt)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static char temp[5];"
        FPRINT FP_OUTPUT, "  return (char*) memmove(temp,&cvt,4);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Mks THEN
        FPRINT FP_OUTPUT, "char *MKS (float cvt)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static char temp[5];"
        FPRINT FP_OUTPUT, "  return (char*) memmove(temp,&cvt,4);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Mkd THEN
        FPRINT FP_OUTPUT, "char *MKD (double cvt)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static char temp[9];"
        FPRINT FP_OUTPUT, "  return (char*) memmove(temp,&cvt,8);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Mkld THEN
        FPRINT FP_OUTPUT, "char *MKLD (long double cvt)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static char temp[11];"
        FPRINT FP_OUTPUT, "  return (char*) memmove(temp,&cvt,10);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Cvi THEN
        FPRINT FP_OUTPUT, "short CVI (PCTSTR s)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return ((short*)s)[0];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Cvl THEN
        FPRINT FP_OUTPUT, "long CVL (PCTSTR s)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return ((long*)s)[0];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Cvs THEN
        FPRINT FP_OUTPUT, "float CVS (PCTSTR s)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return ((float*)s)[0];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Cvd THEN
        FPRINT FP_OUTPUT, "double CVD (PCTSTR s)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return ((double*)s)[0];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Cvld THEN
        FPRINT FP_OUTPUT, "long double CVLD (PCTSTR s)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return ((long double*)s)[0];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Eof THEN
        FPRINT FP_OUTPUT, "int EoF(FILE *filstream) {"
        FPRINT FP_OUTPUT, "    int c;"
        FPRINT FP_OUTPUT, "    // Validate file stream"
        FPRINT FP_OUTPUT, "    if (filstream == NULL || ferror(filstream)) {"
        FPRINT FP_OUTPUT, "        return -1; // Indicate error"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    // Read a character"
        FPRINT FP_OUTPUT, "    c = fgetc(filstream);"
        FPRINT FP_OUTPUT, "    if (c == EOF) {"
        FPRINT FP_OUTPUT, "        if (ferror(filstream)) {"
        FPRINT FP_OUTPUT, "            return -1; // File error"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        return 1; // True EOF"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    // Push back the character if it was not EOF"
        FPRINT FP_OUTPUT, "    if (ungetc(c, filstream) == EOF) {"
        FPRINT FP_OUTPUT, "        return -1; // ungetc failed"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    return 0; // Not EOF"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_FormatPath2



SUB Emit_RT_FileAttrClip1 (FP_OUTPUT AS FILE)
    IF Use_NamePathFromFP = TRUE THEN
        FPRINT FP_OUTPUT, "char *NamePathFromFP (FILE *FP)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr={0};"
        FPRINT FP_OUTPUT, "  char *szTmp={0};"
        FPRINT FP_OUTPUT, "  szTmp = (char*)calloc(2048, 1);"
        FPRINT FP_OUTPUT, "  if(GetFinalPathNameByHandle((HANDLE)_get_osfhandle(_fileno(FP)),szTmp,2047,0))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    strcpy(szTmp, szTmp+4);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  BCX_RetStr = BCX_TempStr(strlen(szTmp));"
        FPRINT FP_OUTPUT, "  strcpy(BCX_RetStr,szTmp);"
        FPRINT FP_OUTPUT, "  if (szTmp)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    free(szTmp);"
        FPRINT FP_OUTPUT, "    szTmp = NULL;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Longestline THEN
        FPRINT FP_OUTPUT, "UINT LongestLine(PCTSTR FName)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  UINT Longest = 0;"
        FPRINT FP_OUTPUT, "  int Counter = 0;"
        FPRINT FP_OUTPUT, "  BYTE OneByte[1]={0};"
        FPRINT FP_OUTPUT, "  FILE *FP = NULL;"
        FPRINT FP_OUTPUT, "  if (0xffffffff == GetFileAttributes(FName))"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "  FP = fopen(FName, ", ENC$("rb"), ");"  ' MrBcx 817 (changed to "rb" from "r")
        FPRINT FP_OUTPUT, "  if (FP == 0)   return 0;"
        FPRINT FP_OUTPUT, "  while (!EoF(FP))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    *OneByte = 0;"
        FPRINT FP_OUTPUT, "    Counter = 0;"
        FPRINT FP_OUTPUT, "    while (*OneByte != 10)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      fread(OneByte, 1, 1, FP);"
        FPRINT FP_OUTPUT, "      Counter++;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    Counter--;"
        FPRINT FP_OUTPUT, "    fseek(FP, -(Counter + 2), SEEK_CUR);"
        FPRINT FP_OUTPUT, "    if (Counter > Longest)"
        FPRINT FP_OUTPUT, "      Longest = Counter;"
        FPRINT FP_OUTPUT, "    fseek(FP, (Counter + 2), SEEK_CUR);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (FP)fclose(FP);"
        FPRINT FP_OUTPUT, "  return Longest;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Nextlinelen THEN
        FPRINT FP_OUTPUT, "UINT NextLineLen (FILE *FP)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int Counter=0;"
        FPRINT FP_OUTPUT, "  BYTE  OneByte[1]={0};"
        FPRINT FP_OUTPUT, "  while(*OneByte!=10)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    fread (OneByte,1,1,FP);"
        FPRINT FP_OUTPUT, "    Counter++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  Counter--;"
        FPRINT FP_OUTPUT, "  fseek (FP,-(Counter+2),SEEK_CUR);"
        FPRINT FP_OUTPUT, "  return Counter;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_AppActivate THEN
        FPRINT FP_OUTPUT, "int AppActivate (PCTSTR Arg_Z)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int   CurThread;"
        FPRINT FP_OUTPUT, "  int   NewThread;"
        FPRINT FP_OUTPUT, "  int   Rc;"
        FPRINT FP_OUTPUT, "  int   ArgLen;"
        FPRINT FP_OUTPUT, "  char  Buffer[BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  HWND  hWnd;"
        FPRINT FP_OUTPUT, "  *Buffer = 0;"
        FPRINT FP_OUTPUT, "  ArgLen  = (int)strlen(Arg_Z);"
        FPRINT FP_OUTPUT, "  CurThread = GetCurrentThreadId();"
        FPRINT FP_OUTPUT, "  hWnd = GetForegroundWindow();"
        FPRINT FP_OUTPUT, "  for(Rc=0; Rc<=1000; Rc++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    hWnd = GetNextWindow(hWnd, GW_HWNDNEXT);"
        FPRINT FP_OUTPUT, "    GetWindowText(hWnd, Buffer, 256);"
        FPRINT FP_OUTPUT, "    if (instr(left(lcase(Buffer), ArgLen), lcase(Arg_Z))) break;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (Rc==1001) return 0;"
        FPRINT FP_OUTPUT, "  NewThread = GetWindowThreadProcessId(hWnd, NULL);"
        FPRINT FP_OUTPUT, "  AttachThreadInput(CurThread, NewThread, TRUE);"
        FPRINT FP_OUTPUT, "  SetActiveWindow(hWnd);"
        FPRINT FP_OUTPUT, "  return TRUE;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Tix THEN
        FPRINT FP_OUTPUT, "static double  TIX_CPU_FREQ;"
        FPRINT FP_OUTPUT, "static int64_t TIX_COUNTER;"
        FPRINT FP_OUTPUT, "void TIX_START(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    LARGE_INTEGER li;"
        FPRINT FP_OUTPUT, "    if (!QueryPerformanceFrequency(&li)) return;"
        FPRINT FP_OUTPUT, "    TIX_CPU_FREQ = (double)li.QuadPart * 0.001;"
        FPRINT FP_OUTPUT, "    QueryPerformanceCounter(&li);"
        FPRINT FP_OUTPUT, "    TIX_COUNTER = li.QuadPart;"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, "double TIX_NOW(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    LARGE_INTEGER li;"
        FPRINT FP_OUTPUT, "    QueryPerformanceCounter(&li);"
        FPRINT FP_OUTPUT, "    return (double)(li.QuadPart - TIX_COUNTER)/TIX_CPU_FREQ;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Cint THEN
        FPRINT FP_OUTPUT, "int Cint (double Arg_A)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return (Arg_A >= 0 ? (int)(Arg_A + 0.5) : (int)(Arg_A - 0.5));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Clng THEN
        FPRINT FP_OUTPUT, "long CLNG (double Arg_A)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  float   r = 0.5f;"
        FPRINT FP_OUTPUT, "  double  a = Arg_A-(long)Arg_A;"
        FPRINT FP_OUTPUT, "  if (Arg_A < 0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    r = -0.5;"
        FPRINT FP_OUTPUT, "    a = -a;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (((long)Arg_A % 2) == 0 && a<= 0.5)"
        FPRINT FP_OUTPUT, "    return (long)Arg_A;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    return (long)(Arg_A+r);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Isfolder THEN
        FPRINT FP_OUTPUT, "int isfolder (PCTSTR FName)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, " DWORD attr = GetFileAttributes(FName);"
        FPRINT FP_OUTPUT, " return (attr != INVALID_FILE_ATTRIBUTES) &&"
        FPRINT FP_OUTPUT, "        (attr & FILE_ATTRIBUTE_DIRECTORY);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Isfile THEN
        FPRINT FP_OUTPUT, "int isfile (PCTSTR FName)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, " DWORD attr = GetFileAttributes(FName);"
        FPRINT FP_OUTPUT, " return (attr != INVALID_FILE_ATTRIBUTES) &&"
        FPRINT FP_OUTPUT, "        !(attr & FILE_ATTRIBUTE_DIRECTORY);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Ishidden THEN
        FPRINT FP_OUTPUT, "int ishidden (PCTSTR FName)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, " DWORD attr = GetFileAttributes(FName);"
        FPRINT FP_OUTPUT, " return (attr != INVALID_FILE_ATTRIBUTES) &&"
        FPRINT FP_OUTPUT, "        (attr & FILE_ATTRIBUTE_HIDDEN);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Isreadonly THEN
        FPRINT FP_OUTPUT, "int isreadonly (PCTSTR FName)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, " DWORD attr = GetFileAttributes(FName);"
        FPRINT FP_OUTPUT, " return (attr != INVALID_FILE_ATTRIBUTES) &&"
        FPRINT FP_OUTPUT, "        (attr & FILE_ATTRIBUTE_READONLY);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Issystem THEN
        FPRINT FP_OUTPUT, "int issystem (PCTSTR FName)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, " DWORD attr = GetFileAttributes(FName);"
        FPRINT FP_OUTPUT, " return (attr != INVALID_FILE_ATTRIBUTES) &&"
        FPRINT FP_OUTPUT, "        (attr & FILE_ATTRIBUTE_SYSTEM);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Pause THEN
        FPRINT FP_OUTPUT, "void Pause(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  printf(", ENC$("\\n%s\\n"), ",", ENC$("Press any key to continue . . ."), ");"
        FPRINT FP_OUTPUT, "  _getch();"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Clip_Gettextsize THEN
        FPRINT FP_OUTPUT, "int Clipboard_GetTextSize(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HANDLE  hGlob = NULL;"
        FPRINT FP_OUTPUT, "  WCHAR  *pWide = NULL;"
        FPRINT FP_OUTPUT, "  int     cblen = 0;"
        FPRINT FP_OUTPUT, "  if (!OpenClipboard(NULL)) return 0;"
        FPRINT FP_OUTPUT, "  hGlob = GetClipboardData(CF_UNICODETEXT);"
        FPRINT FP_OUTPUT, "  if (hGlob)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    pWide = (WCHAR*)GlobalLock(hGlob);"
        FPRINT FP_OUTPUT, "    if (pWide)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      cblen = WideCharToMultiByte(CP_UTF8, 0, pWide, -1, NULL, 0, NULL, NULL);"
        FPRINT FP_OUTPUT, "      GlobalUnlock(hGlob);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  CloseClipboard();"
        FPRINT FP_OUTPUT, "  return cblen;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Clip_Gettext THEN
        FPRINT FP_OUTPUT, "char *Clipboard_GetText(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char   *BCX_RetStr = NULL;"
        FPRINT FP_OUTPUT, "  HGLOBAL hGlob      = NULL;"
        FPRINT FP_OUTPUT, "  WCHAR  *pWide      = NULL;"
        FPRINT FP_OUTPUT, "  int     nBytes     = 0;"
        FPRINT FP_OUTPUT, "  if (!IsClipboardFormatAvailable(CF_UNICODETEXT))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (!OpenClipboard(NULL))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    MessageBox(GetActiveWindow(),", ENC$("Cannot open clipboard!"), ",", ENC$("Error!"), ", 0);"
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  hGlob = GetClipboardData(CF_UNICODETEXT);"
        FPRINT FP_OUTPUT, "  if (hGlob)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    pWide = (WCHAR*)GlobalLock(hGlob);"
        FPRINT FP_OUTPUT, "    if (pWide)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      nBytes = WideCharToMultiByte(CP_UTF8, 0, pWide, -1, NULL, 0, NULL, NULL);"
        FPRINT FP_OUTPUT, "      BCX_RetStr = BCX_TempStr(nBytes);"
        FPRINT FP_OUTPUT, "      WideCharToMultiByte(CP_UTF8, 0, pWide, -1, BCX_RetStr, nBytes, NULL, NULL);"
        FPRINT FP_OUTPUT, "      GlobalUnlock(hGlob);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  CloseClipboard();"
        FPRINT FP_OUTPUT, "  if (!BCX_RetStr) BCX_RetStr = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Clip_Settext THEN
        FPRINT FP_OUTPUT, "void Clipboard_SetText(const char *Txt)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HGLOBAL hGlobMem = NULL;"
        FPRINT FP_OUTPUT, "  WCHAR  *pWide    = NULL;"
        FPRINT FP_OUTPUT, "  int     nWChars  = 0;"
        FPRINT FP_OUTPUT, "  if (!Txt) return;"
        FPRINT FP_OUTPUT, "  nWChars = MultiByteToWideChar(CP_UTF8, 0, Txt, -1, NULL, 0);"
        FPRINT FP_OUTPUT, "  if (!nWChars) return;"
        FPRINT FP_OUTPUT, "  hGlobMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, nWChars * sizeof(WCHAR));"
        FPRINT FP_OUTPUT, "  if (!hGlobMem) return;"
        FPRINT FP_OUTPUT, "  pWide = (WCHAR*)GlobalLock(hGlobMem);"
        FPRINT FP_OUTPUT, "  if (!pWide)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    GlobalFree(hGlobMem);"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  MultiByteToWideChar(CP_UTF8, 0, Txt, -1, pWide, nWChars);"
        FPRINT FP_OUTPUT, "  GlobalUnlock(hGlobMem);"
        FPRINT FP_OUTPUT, "  if (!OpenClipboard(NULL))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    GlobalFree(hGlobMem);"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  EmptyClipboard();"
        FPRINT FP_OUTPUT, "  SetClipboardData(CF_UNICODETEXT, hGlobMem);"
        FPRINT FP_OUTPUT, "  CloseClipboard();"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Clip_Setbitmap THEN
        FPRINT FP_OUTPUT, "void Clipboard_SetBitmap (HBITMAP hBmp)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if((hBmp==NULL))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    MessageBox (GetActiveWindow(),", ENC$("Cannot copy bitmap to clipboard"), ",", ENC$("Invalid bitmap"), ", 0);"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  OpenClipboard(0);"
        FPRINT FP_OUTPUT, "  EmptyClipboard();"
        FPRINT FP_OUTPUT, "  SetClipboardData(CF_BITMAP,(HANDLE)hBmp);"
        FPRINT FP_OUTPUT, "  CloseClipboard();"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Clip_Getbitmap THEN
        FPRINT FP_OUTPUT, "HBITMAP Clipboard_GetBitmap (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static HBITMAP  hBmp;"
        FPRINT FP_OUTPUT, "  if(IsClipboardFormatAvailable(CF_BITMAP))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    OpenClipboard(0);"
        FPRINT FP_OUTPUT, "    hBmp = (HBITMAP)GetClipboardData(CF_BITMAP);"
        FPRINT FP_OUTPUT, "    CloseClipboard();"
        FPRINT FP_OUTPUT, "    if(hBmp==NULL)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      MessageBox (GetActiveWindow(),", ENC$("Cannot retrieve bitmap from clipboard"), ",", ENC$("Invalid bitmap"), ", 0);"
        FPRINT FP_OUTPUT, "      return NULL;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return hBmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Keypress THEN
        FPRINT FP_OUTPUT, "int keypress(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int ch = 0;"
        FPRINT FP_OUTPUT, "  int ii = 0;"
        FPRINT FP_OUTPUT, "  INPUT_RECORD InputRecord;"
        FPRINT FP_OUTPUT, "  ULONG Count = 0, cks;"
        FPRINT FP_OUTPUT, "  WORD vkc, vsc;"
        FPRINT FP_OUTPUT, "  HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);"
        FPRINT FP_OUTPUT, "  ULONG OldConsoleMode;"
        FPRINT FP_OUTPUT, "  static char uchr[] ="
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    0x7E, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,"
        FPRINT FP_OUTPUT, "    0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x7C,"
        FPRINT FP_OUTPUT, "    0x7B, 0x7D, 0x3A, 0x22, 0x3C, 0x3E, 0x3F,"
        FPRINT FP_OUTPUT, "    0x60, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,"
        FPRINT FP_OUTPUT, "    0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x5C,"
        FPRINT FP_OUTPUT, "    0x5B, 0x5D, 0x3B, 0x27, 0x2C, 0x2E, 0x2F, 0x00"
        FPRINT FP_OUTPUT, "  };"
        FPRINT FP_OUTPUT, "  static char lchr[] ="
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    0x60, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,"
        FPRINT FP_OUTPUT, "    0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x5C,"
        FPRINT FP_OUTPUT, "    0x5B, 0x5D, 0x3B, 0x27, 0x2C, 0x2E, 0x2F,"
        FPRINT FP_OUTPUT, "    0x7E, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,"
        FPRINT FP_OUTPUT, "    0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x7C,"
        FPRINT FP_OUTPUT, "    0x7B, 0x7D, 0x3A, 0x22, 0x3C, 0x3E, 0x3F, 0x00"
        FPRINT FP_OUTPUT, "  };"
        FPRINT FP_OUTPUT, "  PeekConsoleInput(hStdIn, &InputRecord, 1, &Count);"
        FPRINT FP_OUTPUT, "  GetConsoleMode(hStdIn, &OldConsoleMode);"
        FPRINT FP_OUTPUT, "  SetConsoleMode(hStdIn, 0);"
        FPRINT FP_OUTPUT, "  do"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    ReadConsoleInput(hStdIn, &InputRecord, 1, &Count);"
        FPRINT FP_OUTPUT, "    SetConsoleMode(hStdIn, OldConsoleMode);"
        FPRINT FP_OUTPUT, "    if (Count && InputRecord.EventType == KEY_EVENT && InputRecord.Event.KeyEvent.bKeyDown)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      vkc = InputRecord.Event.KeyEvent.wVirtualKeyCode;"
        FPRINT FP_OUTPUT, "      vsc = InputRecord.Event.KeyEvent.wVirtualScanCode;"
        FPRINT FP_OUTPUT, "      ch = InputRecord.Event.KeyEvent.uChar.AsciiChar;"
        FPRINT FP_OUTPUT, "      cks = InputRecord.Event.KeyEvent.dwControlKeyState;"
        FPRINT FP_OUTPUT, "      FlushConsoleInputBuffer(hStdIn);"
        FPRINT FP_OUTPUT, "      if ((!ch && vsc > 58))"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        if ((cks & 3))"
        FPRINT FP_OUTPUT, "          return (1000 + vsc) * (-1);"
        FPRINT FP_OUTPUT, "        if ((cks & 12))"
        FPRINT FP_OUTPUT, "          return (2000 + vsc) * (-1);"
        FPRINT FP_OUTPUT, "        return vsc * (-1);"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      if (ch && (cks & 3))"
        FPRINT FP_OUTPUT, "        return vkc + 1000;"
        FPRINT FP_OUTPUT, "      if ((vsc == 15) && (cks & 16))"
        FPRINT FP_OUTPUT, "        return 15;"
        FPRINT FP_OUTPUT, "      if (vkc == 27)"
        FPRINT FP_OUTPUT, "        return 27;"
        FPRINT FP_OUTPUT, "      if (ch && (cks & 128))"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        for (ii = 0; ii <= (int)strlen(lchr); ii++)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          if (uchr[ii] == ch)"
        FPRINT FP_OUTPUT, "          {"
        FPRINT FP_OUTPUT, "            ch = lchr[ii];"
        FPRINT FP_OUTPUT, "            break;"
        FPRINT FP_OUTPUT, "          }"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      if (ch)"
        FPRINT FP_OUTPUT, "        return ch;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  while (TRUE);"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_InkeyD THEN
        FPRINT FP_OUTPUT, "int inkeyd(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int ch = 0;"
        FPRINT FP_OUTPUT, "  int ii = 0;"
        FPRINT FP_OUTPUT, "  INPUT_RECORD InputRecord;"
        FPRINT FP_OUTPUT, "  ULONG Count = 0, cks;"
        FPRINT FP_OUTPUT, "  WORD vkc, vsc;"
        FPRINT FP_OUTPUT, "  HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);"
        FPRINT FP_OUTPUT, "  ULONG OldConsoleMode;"
        FPRINT FP_OUTPUT, "  static char uchr[] ="
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    0x7E, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,"
        FPRINT FP_OUTPUT, "    0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x7C,"
        FPRINT FP_OUTPUT, "    0x7B, 0x7D, 0x3A, 0x22, 0x3C, 0x3E, 0x3F,"
        FPRINT FP_OUTPUT, "    0x60, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,"
        FPRINT FP_OUTPUT, "    0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x5C,"
        FPRINT FP_OUTPUT, "    0x5B, 0x5D, 0x3B, 0x27, 0x2C, 0x2E, 0x2F, 0x00"
        FPRINT FP_OUTPUT, "  };"
        FPRINT FP_OUTPUT, "  static char lchr[] ="
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    0x60, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,"
        FPRINT FP_OUTPUT, "    0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x5C,"
        FPRINT FP_OUTPUT, "    0x5B, 0x5D, 0x3B, 0x27, 0x2C, 0x2E, 0x2F,"
        FPRINT FP_OUTPUT, "    0x7E, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,"
        FPRINT FP_OUTPUT, "    0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x7C,"
        FPRINT FP_OUTPUT, "    0x7B, 0x7D, 0x3A, 0x22, 0x3C, 0x3E, 0x3F, 0x00"
        FPRINT FP_OUTPUT, "  };"
        FPRINT FP_OUTPUT, "  PeekConsoleInput(hStdIn, &InputRecord, 1, &Count);"
        FPRINT FP_OUTPUT, "  GetConsoleMode(hStdIn, &OldConsoleMode);"
        FPRINT FP_OUTPUT, "  SetConsoleMode(hStdIn, 0);"
        FPRINT FP_OUTPUT, "  ReadConsoleInput(hStdIn, &InputRecord, 1, &Count);"
        FPRINT FP_OUTPUT, "  SetConsoleMode(hStdIn, OldConsoleMode);"
        FPRINT FP_OUTPUT, "  if (Count && InputRecord.EventType == KEY_EVENT && InputRecord.Event.KeyEvent.bKeyDown)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    vkc = InputRecord.Event.KeyEvent.wVirtualKeyCode;"
        FPRINT FP_OUTPUT, "    vsc = InputRecord.Event.KeyEvent.wVirtualScanCode;"
        FPRINT FP_OUTPUT, "    ch = InputRecord.Event.KeyEvent.uChar.AsciiChar;"
        FPRINT FP_OUTPUT, "    cks = InputRecord.Event.KeyEvent.dwControlKeyState;"
        FPRINT FP_OUTPUT, "    FlushConsoleInputBuffer(hStdIn);"
        FPRINT FP_OUTPUT, "    if (!ch && vsc > 58)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (cks & 3)"
        FPRINT FP_OUTPUT, "        return (1000 + vsc) * (-1);"
        FPRINT FP_OUTPUT, "      if (cks & 12)"
        FPRINT FP_OUTPUT, "        return (2000 + vsc) * (-1);"
        FPRINT FP_OUTPUT, "      return vsc * (-1);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (ch && (cks & 3))"
        FPRINT FP_OUTPUT, "      return vkc + 1000;"
        FPRINT FP_OUTPUT, "    if ((vsc == 15) && (cks & 16))"
        FPRINT FP_OUTPUT, "      return 15;"
        FPRINT FP_OUTPUT, "    if (vkc == 27)"
        FPRINT FP_OUTPUT, "      return 27;"
        FPRINT FP_OUTPUT, "    if (ch && (cks & 128))"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      for (ii = 0; ii <= (int)strlen(lchr); ii++)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        if (uchr[ii] == ch)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          ch = lchr[ii];"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (ch)"
        FPRINT FP_OUTPUT, "      return ch;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Hook THEN
        FPRINT FP_OUTPUT, "LRESULT CALLBACK SBProc (int Msg, WPARAM wParam, LPARAM lParam)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (Msg==HCBT_ACTIVATE)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    HMONITOR     hMonitor={0};"
        FPRINT FP_OUTPUT, "    MONITORINFO  MonitorInfo;"
        FPRINT FP_OUTPUT, "    int          Width={0};"
        FPRINT FP_OUTPUT, "    int          Height={0};"
        FPRINT FP_OUTPUT, "    RECT         rc1;"
        FPRINT FP_OUTPUT, "    memset(&MonitorInfo, 0, sizeof(MONITORINFO));"
        FPRINT FP_OUTPUT, "    GetWindowRect((HWND)wParam, &rc1);"
        FPRINT FP_OUTPUT, "    Width = rc1.right-rc1.left;"
        FPRINT FP_OUTPUT, "    Height = rc1.bottom-rc1.top;"
        FPRINT FP_OUTPUT, "    if(GetSystemMetrics(SM_CMONITORS) == 1)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "       hMonitor = MonitorFromRect(&rc1,MONITOR_DEFAULTTOPRIMARY);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "       hMonitor = MonitorFromRect(&rc1,MONITOR_DEFAULTTONEAREST);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    MonitorInfo.cbSize = sizeof(MONITORINFO);"
        FPRINT FP_OUTPUT, "    GetMonitorInfo(hMonitor, &MonitorInfo);"
        FPRINT FP_OUTPUT, "    rc1.left = MonitorInfo.rcWork.left+((MonitorInfo.rcWork.right-MonitorInfo.rcWork.left-Width)/2);"
        FPRINT FP_OUTPUT, "    rc1.top = MonitorInfo.rcWork.top+((MonitorInfo.rcWork.bottom-MonitorInfo.rcWork.top-Height)/2);"
        FPRINT FP_OUTPUT, "    rc1.right = rc1.left+Width;"
        FPRINT FP_OUTPUT, "    rc1.bottom = rc1.top+Height;"
        FPRINT FP_OUTPUT, "    SetWindowPos((HWND)wParam, NULL, rc1.left, rc1.top, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);"
        FPRINT FP_OUTPUT, "    UnhookWindowsHookEx(CmDlgHook);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Instr THEN
        FPRINT FP_OUTPUT, "int instr(PCTSTR Haystack, PCTSTR Needle, int offset, int sensflag)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if(offset == 0) {return 0;}"
        FPRINT FP_OUTPUT, "  PCTSTR s;"
        FPRINT FP_OUTPUT, "  if (!Haystack||!*Haystack||!Needle||!*Needle||offset>(int)strlen(Haystack)) return 0;"
        FPRINT FP_OUTPUT, "  if (sensflag)"
        FPRINT FP_OUTPUT, "    s = _stristr_(offset > 0 ? Haystack + offset - 1 : Haystack, Needle);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    s = strstr(offset > 0 ? Haystack + offset - 1 : Haystack, Needle);"
        FPRINT FP_OUTPUT, "  return s ? (int)(s-Haystack)+1 : 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_IInstr THEN
        FPRINT FP_OUTPUT, "int iinstr(PCTSTR Haystack, PCTSTR Needle, int offset)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if(offset == 0) return 0;"
        FPRINT FP_OUTPUT, "  PCTSTR s;"
        FPRINT FP_OUTPUT, "  if (!Haystack||!*Haystack||!Needle||!*Needle||offset>=(int)strlen(Haystack)) return 0;"
        FPRINT FP_OUTPUT, "    s = _stristr_(offset > 0 ? Haystack + offset-1 : Haystack, Needle);"
        FPRINT FP_OUTPUT, "  return s ? (int)(s-Haystack)+1 : 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_IInstrAny OR Use_InstrAny THEN
        FPRINT FP_OUTPUT, "int DeDupeCompare(const void *a, const void *b) {"
        FPRINT FP_OUTPUT, "    return (*(char*)a - *(char*)b);"
        FPRINT FP_OUTPUT, "}"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "char* DeDupeSort(const char* input) {"
        FPRINT FP_OUTPUT, "    int CharFreq[256]={0}; "
        FPRINT FP_OUTPUT, "    int length = (int)strlen(input);"
        FPRINT FP_OUTPUT, "    char *result = (char*)malloc(length + 1);"
        FPRINT FP_OUTPUT, "    int index = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Iterate over each character in the input string"
        FPRINT FP_OUTPUT, "    for (int i = 0; i < length; i++) {"
        FPRINT FP_OUTPUT, "        unsigned char ch = input[i];"
        FPRINT FP_OUTPUT, "        if (CharFreq[ch] == 0) { // If character not encountered before"
        FPRINT FP_OUTPUT, "            CharFreq[ch] = 1;"
        FPRINT FP_OUTPUT, "            result[index++] = ch; // Add character to the result"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    result[index] = 0;  "
        FPRINT FP_OUTPUT, "    qsort(result, index, sizeof(char), DeDupeCompare);"
        FPRINT FP_OUTPUT, "    return result; "
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_InstrAny THEN
        FPRINT FP_OUTPUT, "int InstrAny (PCTSTR Main, PCTSTR Words, int Start)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char Buffer[BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  strcpy (Buffer, DeDupeSort(Words));"
        FPRINT FP_OUTPUT, "  int BufLen = (int)strlen(Buffer);"
        FPRINT FP_OUTPUT, "  for(int i = 1; i <= BufLen; i++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    int Found = instr(Main, mid(Buffer, i, 1), Start, 0);"
        FPRINT FP_OUTPUT, "    if (Found) return Found;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_IInstrAny THEN
        FPRINT FP_OUTPUT, "int IInstrAny (PCTSTR Main, PCTSTR Words, int Start)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char Buffer[BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  strcpy (Buffer, DeDupeSort(Words));"
        FPRINT FP_OUTPUT, "  int BufLen = (int)strlen(Buffer);"
        FPRINT FP_OUTPUT, "  for(int i = 1; i <= BufLen; i++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    int Found = iinstr(Main, mid(Buffer, i, 1), Start);"
        FPRINT FP_OUTPUT, "    if (Found) return Found;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Instrrev THEN
        FPRINT FP_OUTPUT, "int InstrRev (PCTSTR Haystack, PCTSTR Needle, int offset, int sens)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int sl, pl, ox;"
        FPRINT FP_OUTPUT, "  int (*cmp)(PCTSTR, PCTSTR, size_t);"
        FPRINT FP_OUTPUT, "  if (!Haystack || !Needle)  return 0;"
        FPRINT FP_OUTPUT, "  sl = (int)strlen(Haystack); pl  = (int)strlen(Needle);"
        FPRINT FP_OUTPUT, "  if (offset > sl || 0 == sl || 0 == pl || (ox = sl - pl) < 0)"
        FPRINT FP_OUTPUT, "     return 0;"
        FPRINT FP_OUTPUT, "  if (offset <= 0)"
        FPRINT FP_OUTPUT, "     offset = ox ;"
        FPRINT FP_OUTPUT, "  else if (offset >= pl)"
        FPRINT FP_OUTPUT, "     offset = offset - pl ;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "     return 0;"
        FPRINT FP_OUTPUT, "  cmp = (sens ? _strnicmp : strncmp);"
        FPRINT FP_OUTPUT, "  do"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "     if (cmp(Haystack + offset , Needle, pl) == 0)"
        FPRINT FP_OUTPUT, "        return offset+1;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  while (offset--);"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_FileAttrClip1



SUB Emit_RT_FileAttrClip2 (FP_OUTPUT AS FILE)
    IF Use_Like_Instr THEN
        FPRINT FP_OUTPUT, "static int MatchPattern(PCTSTR Buffer, PCTSTR Pattern, int BufferPos, int PatternPos) {"
        FPRINT FP_OUTPUT, "   int BufferLen = (int)strlen(Buffer);"
        FPRINT FP_OUTPUT, "   int PatternLen = (int)strlen(Pattern);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   while (PatternPos <= PatternLen && BufferPos <= BufferLen) {"
        FPRINT FP_OUTPUT, "       if (PatternPos > PatternLen) {"
        FPRINT FP_OUTPUT, "           // Pattern exhausted - success if buffer is also exhausted"
        FPRINT FP_OUTPUT, "           return (BufferPos > BufferLen);"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "       int PatternChar = (PatternPos <= PatternLen) ? Pattern[PatternPos - 1] : 0;"
        FPRINT FP_OUTPUT, "       switch (PatternChar) {"
        FPRINT FP_OUTPUT, "           case '*':"
        FPRINT FP_OUTPUT, "               // Wildcard - try matching rest of pattern from each remaining position"
        FPRINT FP_OUTPUT, "               PatternPos++;"
        FPRINT FP_OUTPUT, "               if (PatternPos > PatternLen) {"
        FPRINT FP_OUTPUT, "                   // Pattern ends with *, so it matches"
        FPRINT FP_OUTPUT, "                   return 1;"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               // Try matching the rest of the pattern from current position onwards"
        FPRINT FP_OUTPUT, "               for (int i = BufferPos; i <= BufferLen + 1; i++) {"
        FPRINT FP_OUTPUT, "                   if (MatchPattern(Buffer, Pattern, i, PatternPos)) {"
        FPRINT FP_OUTPUT, "                       return 1;"
        FPRINT FP_OUTPUT, "                   }"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               return 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "           case '?':"
        FPRINT FP_OUTPUT, "               // Single character wildcard"
        FPRINT FP_OUTPUT, "               if (BufferPos > BufferLen) {"
        FPRINT FP_OUTPUT, "                   return 0;"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               BufferPos++;"
        FPRINT FP_OUTPUT, "               PatternPos++;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "               "
        FPRINT FP_OUTPUT, "           case '#':"
        FPRINT FP_OUTPUT, "               // Single digit wildcard"
        FPRINT FP_OUTPUT, "               if (BufferPos > BufferLen) {"
        FPRINT FP_OUTPUT, "                   return 0;"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               if (!isdigit((unsigned char)Buffer[BufferPos - 1])) {"
        FPRINT FP_OUTPUT, "                   return 0;"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               BufferPos++;"
        FPRINT FP_OUTPUT, "               PatternPos++;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "               "
        FPRINT FP_OUTPUT, "           default:"
        FPRINT FP_OUTPUT, "               // Literal character match"
        FPRINT FP_OUTPUT, "               if (BufferPos > BufferLen) {"
        FPRINT FP_OUTPUT, "                   return 0;"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               if (Buffer[BufferPos - 1] != PatternChar) {"
        FPRINT FP_OUTPUT, "                   return 0;"
        FPRINT FP_OUTPUT, "               }"
        FPRINT FP_OUTPUT, "               BufferPos++;"
        FPRINT FP_OUTPUT, "               PatternPos++;"
        FPRINT FP_OUTPUT, "               break;"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "   // Check if both pattern and buffer are exhausted"
        FPRINT FP_OUTPUT, "   return (PatternPos > PatternLen && BufferPos > BufferLen);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "int Like_Instr(PCTSTR Buffer, PCTSTR Pattern) {"
        FPRINT FP_OUTPUT, "    char UBuffer[BCXSTRSIZE] = {0};"
        FPRINT FP_OUTPUT, "    char UPattern[BCXSTRSIZE] = {0};"
        FPRINT FP_OUTPUT, "    int BufferLen = 0;"
        FPRINT FP_OUTPUT, "    int PatternLen = 0;"
        FPRINT FP_OUTPUT, "    int i, j, k;"
        FPRINT FP_OUTPUT, "    if (Buffer[0] == 0 || Pattern[0] == 0) {"
        FPRINT FP_OUTPUT, "        return 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    strcpy(UBuffer, ucase(Buffer));"
        FPRINT FP_OUTPUT, "    strcpy(UPattern, ucase(Pattern));"
        FPRINT FP_OUTPUT, "    BufferLen = (int)strlen(UBuffer);"
        FPRINT FP_OUTPUT, "    PatternLen = (int)strlen(UPattern);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (BufferLen == 0 || PatternLen == 0) {"
        FPRINT FP_OUTPUT, "        return 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    // Special handling for patterns starting with *"
        FPRINT FP_OUTPUT, "    if (UPattern[0] == '*') {"
        FPRINT FP_OUTPUT, "        // Find the literal part after the *"
        FPRINT FP_OUTPUT, "        char LiteralPart[BCXSTRSIZE] = {0};"
        FPRINT FP_OUTPUT, "        int LiteralLen = 0;"
        FPRINT FP_OUTPUT, "        // Extract everything after the first *"
        FPRINT FP_OUTPUT, "        for (i = 1; i < PatternLen; i++) {"
        FPRINT FP_OUTPUT, "            LiteralPart[LiteralLen++] = UPattern[i];"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        LiteralPart[LiteralLen] = 0;"
        FPRINT FP_OUTPUT, "        "
        FPRINT FP_OUTPUT, "        if (LiteralLen == 0) {"
        FPRINT FP_OUTPUT, "            // Pattern is just ", ENC$("*"), ", match at position 1"
        FPRINT FP_OUTPUT, "            return 1;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        // Search for the literal part in the buffer"
        FPRINT FP_OUTPUT, "        for (i = 1; i <= BufferLen - LiteralLen + 1; i++) {"
        FPRINT FP_OUTPUT, "            int Match = 1;"
        FPRINT FP_OUTPUT, "            for (j = 0; j < LiteralLen; j++) {"
        FPRINT FP_OUTPUT, "                char BufferChar = UBuffer[i - 1 + j];"
        FPRINT FP_OUTPUT, "                char PatternChar = LiteralPart[j];"
        FPRINT FP_OUTPUT, "                if (PatternChar == '?') {"
        FPRINT FP_OUTPUT, "                    // Single character wildcard - always matches"
        FPRINT FP_OUTPUT, "                    continue;"
        FPRINT FP_OUTPUT, "                } else if (PatternChar == '#') {"
        FPRINT FP_OUTPUT, "                    // Single digit wildcard"
        FPRINT FP_OUTPUT, "                    if (!isdigit((unsigned char)BufferChar)) {"
        FPRINT FP_OUTPUT, "                        Match = 0;"
        FPRINT FP_OUTPUT, "                        break;"
        FPRINT FP_OUTPUT, "                    }"
        FPRINT FP_OUTPUT, "                } else {"
        FPRINT FP_OUTPUT, "                    // Literal character"
        FPRINT FP_OUTPUT, "                    if (BufferChar != PatternChar) {"
        FPRINT FP_OUTPUT, "                        Match = 0;"
        FPRINT FP_OUTPUT, "                        break;"
        FPRINT FP_OUTPUT, "                    }"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "            if (Match) {"
        FPRINT FP_OUTPUT, "                return i; // Return position where literal part starts"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        return 0; // No match found"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    for (i = 1; i <= BufferLen; i++) {"
        FPRINT FP_OUTPUT, "        j = i;"
        FPRINT FP_OUTPUT, "        k = 1;"
        FPRINT FP_OUTPUT, "        int MatchFound = 1;"
        FPRINT FP_OUTPUT, "        while (k <= PatternLen && j <= BufferLen && MatchFound) {"
        FPRINT FP_OUTPUT, "            char PatternChar = UPattern[k-1];"
        FPRINT FP_OUTPUT, "            char BufferChar = UBuffer[j-1];"
        FPRINT FP_OUTPUT, "            "
        FPRINT FP_OUTPUT, "            if (PatternChar == '*') {"
        FPRINT FP_OUTPUT, "                k++;"
        FPRINT FP_OUTPUT, "                if (k > PatternLen) return i; "
        FPRINT FP_OUTPUT, "                "
        FPRINT FP_OUTPUT, "                while (j <= BufferLen) {"
        FPRINT FP_OUTPUT, "                    if (Like_Instr(mid(UBuffer, j), mid(UPattern, k))) {"
        FPRINT FP_OUTPUT, "                        return i;"
        FPRINT FP_OUTPUT, "                    }"
        FPRINT FP_OUTPUT, "                    j++;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                MatchFound = 0;"
        FPRINT FP_OUTPUT, "            } else if (PatternChar == '#') {"
        FPRINT FP_OUTPUT, "                if (!isdigit((unsigned char)BufferChar)) {"
        FPRINT FP_OUTPUT, "                    MatchFound = 0;"
        FPRINT FP_OUTPUT, "                } else {"
        FPRINT FP_OUTPUT, "                    j++;"
        FPRINT FP_OUTPUT, "                    k++;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "            } else if (PatternChar == '?') {"
        FPRINT FP_OUTPUT, "                j++;"
        FPRINT FP_OUTPUT, "                k++;"
        FPRINT FP_OUTPUT, "            } else {"
        FPRINT FP_OUTPUT, "                if (BufferChar != PatternChar) {"
        FPRINT FP_OUTPUT, "                    MatchFound = 0;"
        FPRINT FP_OUTPUT, "                } else {"
        FPRINT FP_OUTPUT, "                    j++;"
        FPRINT FP_OUTPUT, "                    k++;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (MatchFound && k > PatternLen) {"
        FPRINT FP_OUTPUT, "            return i;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_LCaseTbl THEN
        FPRINT FP_OUTPUT, "unsigned char* MakeLCaseTbl (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static unsigned char tbl[257];"
        FPRINT FP_OUTPUT, "  int ii; for (ii = 0; ii < 256; ii++)"
        FPRINT FP_OUTPUT, "  tbl[ii] = (unsigned char) ii;"
        FPRINT FP_OUTPUT, "  tbl[0] = 1;"
        FPRINT FP_OUTPUT, "  tbl[256] = 0;"
        FPRINT FP_OUTPUT, "  CharLowerA((char *)tbl);"
        FPRINT FP_OUTPUT, "  tbl[0] = 0;"
        FPRINT FP_OUTPUT, "  return tbl;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_UCaseTbl THEN
        FPRINT FP_OUTPUT, "unsigned char* MakeUCaseTbl (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static unsigned char tbl[257];"
        FPRINT FP_OUTPUT, "  int ii; for (ii = 0; ii < 256; ii++)"
        FPRINT FP_OUTPUT, "  tbl[ii] = (unsigned char) ii;"
        FPRINT FP_OUTPUT, "  tbl[0] = 1;"
        FPRINT FP_OUTPUT, "  tbl[256] = 0;"
        FPRINT FP_OUTPUT, "  CharUpperA((char *)tbl);"
        FPRINT FP_OUTPUT, "  tbl[0] = 0;"
        FPRINT FP_OUTPUT, "  return tbl;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Inchr THEN
        FPRINT FP_OUTPUT, "int inchr (PCTSTR Haystack, PCTSTR Needle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  PCTSTR Idx = Haystack;"
        FPRINT FP_OUTPUT, "  while(*Idx)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*Idx == *Needle) return (int)(Idx-Haystack)+1;"
        FPRINT FP_OUTPUT, "    Idx++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Asc THEN
        FPRINT FP_OUTPUT, "extern int asc (PCTSTR z, int index)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return (unsigned char) z[index];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Sgn THEN
        FPRINT FP_OUTPUT, "double sgn (double a)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (a < 0) return -1;"
        FPRINT FP_OUTPUT, "  if (a > 0) return  1;"
        FPRINT FP_OUTPUT, "  return  0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Round THEN
        FPRINT FP_OUTPUT, "double Round (double n, int d)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  double factor = pow(10.0, d);"
        FPRINT FP_OUTPUT, "  return round(n * factor) / factor;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Exist THEN
        FPRINT FP_OUTPUT, "BOOL Exist (PCTSTR szFilePath)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    if (!szFilePath || !*szFilePath) return FALSE;"
        FPRINT FP_OUTPUT, ""
        FPRINT FP_OUTPUT, "    if (_tcschr(szFilePath, _T('*')) || _tcschr(szFilePath, _T('?')))"
        FPRINT FP_OUTPUT, "        return Exist_A(szFilePath);"
        FPRINT FP_OUTPUT, ""
        FPRINT FP_OUTPUT, "    return Exist_B(szFilePath);"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "BOOL Exist_A (PCTSTR szFilePath)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    WIN32_FIND_DATA W32FindData;"
        FPRINT FP_OUTPUT, "    HANDLE hFind = FindFirstFile(szFilePath, &W32FindData);"
        FPRINT FP_OUTPUT, "    if (hFind == INVALID_HANDLE_VALUE) "
        FPRINT FP_OUTPUT, "        return FALSE;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    FindClose(hFind);"
        FPRINT FP_OUTPUT, "    return TRUE;"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "BOOL Exist_B (PCTSTR szFilePath)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    WIN32_FILE_ATTRIBUTE_DATA fileInfo;"
        FPRINT FP_OUTPUT, "    if (GetFileAttributesEx(szFilePath, GetFileExInfoStandard, &fileInfo))"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "        // Returns TRUE if path exists (file or directory)"
        FPRINT FP_OUTPUT, "        return TRUE; "
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    return FALSE;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Gethttpfilesize THEN
        FPRINT FP_OUTPUT, "ULONG GetHttpFileSize (PCTSTR url)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HINTERNET hInternet={0};"
        FPRINT FP_OUTPUT, "  HINTERNET hConnect={0};"
        FPRINT FP_OUTPUT, "  ULONG fileSize ={0};"
        FPRINT FP_OUTPUT, "  ULONG bufferSize={0};"
        FPRINT FP_OUTPUT, "  ULONG statusCode={0};"
        FPRINT FP_OUTPUT, "  ULONG statusSize={0};"
        FPRINT FP_OUTPUT, "  hInternet = InternetOpen(", ENC$("xcb"), ", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);"
        FPRINT FP_OUTPUT, "  if(hInternet == NULL ) {"
        FPRINT FP_OUTPUT, "      return 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  hConnect = InternetOpenUrl(hInternet, url, NULL, 0, INTERNET_FLAG_RELOAD, 0);"
        FPRINT FP_OUTPUT, "  if(hConnect == NULL ) {"
        FPRINT FP_OUTPUT, "      InternetCloseHandle(hInternet);"
        FPRINT FP_OUTPUT, "      return 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  statusSize = sizeof(ULONG);"
        FPRINT FP_OUTPUT, "  if(!HttpQueryInfo(hConnect, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER,"
        FPRINT FP_OUTPUT, "                    &statusCode, &statusSize,NULL)) {"
        FPRINT FP_OUTPUT, "      InternetCloseHandle(hConnect);"
        FPRINT FP_OUTPUT, "      InternetCloseHandle(hInternet);"
        FPRINT FP_OUTPUT, "      return 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  if(statusCode != 200) {"
        FPRINT FP_OUTPUT, "      InternetCloseHandle(hConnect);"
        FPRINT FP_OUTPUT, "      InternetCloseHandle(hInternet);"
        FPRINT FP_OUTPUT, "      return 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  bufferSize = sizeof(ULONG);"
        FPRINT FP_OUTPUT, "  if(!HttpQueryInfo(hConnect, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, "
        FPRINT FP_OUTPUT, "                    &fileSize, &bufferSize,NULL)) {"
        FPRINT FP_OUTPUT, "      fileSize = 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  InternetCloseHandle(hConnect);"
        FPRINT FP_OUTPUT, "  InternetCloseHandle(hInternet);"
        FPRINT FP_OUTPUT, "  return fileSize;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Downloadtostr THEN
        FPRINT FP_OUTPUT, "char *DownloadToStr (PCTSTR Url)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr={0};"
        FPRINT FP_OUTPUT, "  char  Fname[BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "  strcpy(Fname, TempFileName(tempdir(),", ENC$("any"), "));"
        FPRINT FP_OUTPUT, "  Download(Url, Fname);"
        FPRINT FP_OUTPUT, "  char *Buffer;"
        FPRINT FP_OUTPUT, "  Buffer = (char*)calloc(lof(Fname)+1, 1);"
        FPRINT FP_OUTPUT, "  if(Exist(Fname)){"
        FPRINT FP_OUTPUT, "      strcpy(Buffer, LoadFile(Fname));"
        FPRINT FP_OUTPUT, "      DeleteFile ((Fname));"
        FPRINT FP_OUTPUT, "      BCX_RetStr = BCX_TempStr(strlen(Buffer));"
        FPRINT FP_OUTPUT, "      strcpy(BCX_RetStr, Buffer);"
        FPRINT FP_OUTPUT, "      if (Buffer) {free(Buffer); Buffer = NULL;}"
        FPRINT FP_OUTPUT, "      return BCX_RetStr;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      BCX_RetStr = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "      if (Buffer) {free(Buffer); Buffer = NULL;}"
        FPRINT FP_OUTPUT, "      return BCX_RetStr;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Diskfree THEN
        FPRINT FP_OUTPUT, "UINT64 DiskFree (PCTSTR Drv)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  UINT64  Capacity;"
        FPRINT FP_OUTPUT, "  UINT64  TotalFree;"
        FPRINT FP_OUTPUT, "  GetDiskFreeSpaceExA(Drv, NULL, (PULARGE_INTEGER)&Capacity, (PULARGE_INTEGER)&TotalFree);"
        FPRINT FP_OUTPUT, "  return TotalFree;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Diskused THEN
        FPRINT FP_OUTPUT, "UINT64 DiskUsed (PCTSTR Drv)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  UINT64  Capacity;"
        FPRINT FP_OUTPUT, "  UINT64  TotalFree;"
        FPRINT FP_OUTPUT, "  GetDiskFreeSpaceExA(Drv, NULL, (PULARGE_INTEGER)&Capacity, (PULARGE_INTEGER)&TotalFree);"
        FPRINT FP_OUTPUT, "  return Capacity-TotalFree;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Disksize THEN
        FPRINT FP_OUTPUT, "UINT64 DiskSize (PCTSTR Drv)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  UINT64  Capacity;"
        FPRINT FP_OUTPUT, "  UINT64  TotalFree;"
        FPRINT FP_OUTPUT, "  GetDiskFreeSpaceExA(Drv, NULL, (PULARGE_INTEGER)&Capacity, (PULARGE_INTEGER)&TotalFree);"
        FPRINT FP_OUTPUT, "  return Capacity;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Tally THEN
        FPRINT FP_OUTPUT, "int tally (PCTSTR Haystack, PCTSTR Needle, int sensflag)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!*Needle) return 0;"
        FPRINT FP_OUTPUT, "  if (!*Haystack) return 0;"
        FPRINT FP_OUTPUT, "  size_t mlen = strlen(Needle);"
        FPRINT FP_OUTPUT, "  int iCount = 0;"
        FPRINT FP_OUTPUT, "  PCTSTR p = (0 == sensflag ? strstr(Haystack, Needle) : _stristr_(Haystack, Needle));"
        FPRINT FP_OUTPUT, "  while (p)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    iCount++;"
        FPRINT FP_OUTPUT, "    p += mlen;"
        FPRINT FP_OUTPUT, "    p = (0 == sensflag ? strstr(p, Needle) : _stristr_(p, Needle));"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return iCount;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Timer THEN
        FPRINT FP_OUTPUT, "float timer (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return (GetTickCount() * 0.001f);"   ' Multiply executes faster than divide
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Rnd THEN
        FPRINT FP_OUTPUT, "float rnd (void)"
        FPRINT FP_OUTPUT, "{"                                   ' Most compilers define RAND_MAX =      32767
        FPRINT FP_OUTPUT, "  return (float)rand()/RAND_MAX;"    ' Pelles C       define RAND_MAX = 1073741823
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Rnd2 THEN
        FPRINT FP_OUTPUT, "double rnd2(double minimum, double maximum)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   double value = minimum + 0.5 + ((double)rand() * (maximum - minimum) / (RAND_MAX + 1.0));"
        FPRINT FP_OUTPUT, "   return (value > maximum) ? maximum : value;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Exp THEN
        FPRINT FP_OUTPUT, "double Exp (double arg)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return pow(2.718281828459045, arg);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Randomize THEN
        FPRINT FP_OUTPUT, "void randomize (unsigned int seed)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  srand(seed);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Max THEN
        FPRINT FP_OUTPUT, "double MAX (double dbl_a, double dbl_b)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return  dbl_a > dbl_b ? dbl_a : dbl_b;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Min THEN
        FPRINT FP_OUTPUT, "double MIN (double dbl_a, double dbl_b)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return  dbl_a < dbl_b ? dbl_a : dbl_b;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Locate THEN
        FPRINT FP_OUTPUT, "void locate (int row, int col, int show, int shape)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  CONSOLE_CURSOR_INFO cci;"
        FPRINT FP_OUTPUT, "  memset (&cci, 0, sizeof(CONSOLE_CURSOR_INFO));"
        FPRINT FP_OUTPUT, "  cursor.X = (SHORT)col-1;"
        FPRINT FP_OUTPUT, "  cursor.Y = (SHORT)row-1;"
        FPRINT FP_OUTPUT, "  SetConsoleCursorPosition(hConsole, cursor);"
        FPRINT FP_OUTPUT, "  cci.bVisible = show;"
        FPRINT FP_OUTPUT, "  cci.dwSize   = shape;"
        FPRINT FP_OUTPUT, "  SetConsoleCursorInfo(hConsole, &cci);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Pos THEN
        FPRINT FP_OUTPUT, "int Pos (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HANDLE  hStdOut;"
        FPRINT FP_OUTPUT, "  CONSOLE_SCREEN_BUFFER_INFO csbi;"
        FPRINT FP_OUTPUT, "  memset (&csbi, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFO));"
        FPRINT FP_OUTPUT, "  hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);"
        FPRINT FP_OUTPUT, "  GetConsoleScreenBufferInfo(hStdOut, &csbi);"
        FPRINT FP_OUTPUT, "  return csbi.dwCursorPosition.X+1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Csrlin THEN
        FPRINT FP_OUTPUT, "int Csrlin (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HANDLE  hStdOut;"
        FPRINT FP_OUTPUT, "  CONSOLE_SCREEN_BUFFER_INFO csbi;"
        FPRINT FP_OUTPUT, "  memset (&csbi, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFO));"
        FPRINT FP_OUTPUT, "  hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);"
        FPRINT FP_OUTPUT, "  GetConsoleScreenBufferInfo(hStdOut, &csbi);"
        FPRINT FP_OUTPUT, "  return csbi.dwCursorPosition.Y+1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Cls THEN
        FPRINT FP_OUTPUT, "void cls(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    ULONG cCharsWritten;"
        FPRINT FP_OUTPUT, "    COORD coordScreen = { 0, 0 };"
        FPRINT FP_OUTPUT, "    CONSOLE_SCREEN_BUFFER_INFO csbi;"
        FPRINT FP_OUTPUT, "    ULONG dwConSize;"
        FPRINT FP_OUTPUT, "    WORD attr;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Get current screen buffer info"
        FPRINT FP_OUTPUT, "    GetConsoleScreenBufferInfo(hConsole, &csbi);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Calculate the console screen size"
        FPRINT FP_OUTPUT, "    dwConSize = csbi.dwSize.X * csbi.dwSize.Y;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Fill the console with spaces"
        FPRINT FP_OUTPUT, "    FillConsoleOutputCharacter(hConsole, (TCHAR)' ', dwConSize, coordScreen, &cCharsWritten);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Fill the console with the current text and background colors"
        FPRINT FP_OUTPUT, "    attr = (WORD)color_fg + (WORD)color_bg * 16;"
        FPRINT FP_OUTPUT, "    FillConsoleOutputAttribute(hConsole, attr, dwConSize, coordScreen, &cCharsWritten);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifndef __LCC__"
        FPRINT FP_OUTPUT, "    // Clear the scrollback buffer by resizing the console buffer"
        FPRINT FP_OUTPUT, "    SMALL_RECT rect;"
        FPRINT FP_OUTPUT, "    rect.Left = 0;"
        FPRINT FP_OUTPUT, "    rect.Top = 0;"
        FPRINT FP_OUTPUT, "    rect.Right = csbi.dwSize.X;"
        FPRINT FP_OUTPUT, "    rect.Bottom = csbi.dwSize.Y-1;"
        FPRINT FP_OUTPUT, "    SetConsoleWindowInfo(hConsole, TRUE, &rect);"
        FPRINT FP_OUTPUT, "    SetConsoleScreenBufferSize(hConsole, csbi.dwSize);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    locate(1, 1, 1);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Color THEN
        FPRINT FP_OUTPUT, "void color(int fg, int bg)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (bg == (-1))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    SetConsoleTextAttribute(hConsole, (WORD)fg + (WORD)color_bg * 16);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    SetConsoleTextAttribute(hConsole, (WORD)fg + (WORD)bg * 16);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  color_fg = fg;"
        FPRINT FP_OUTPUT, "  if (bg!=(-1)) color_bg = bg;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_PushPopColors THEN
        FPRINT FP_OUTPUT, "void PushColors (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  CONSOLE_SCREEN_BUFFER_INFO csbi;"
        FPRINT FP_OUTPUT, "  memset (&csbi, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFO));"
        FPRINT FP_OUTPUT, "  if(0==GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    color_pshpop = 7;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    color_pshpop = csbi.wAttributes;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void PopColors (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if(color_pshpop == 0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    color (7,0);"
        FPRINT FP_OUTPUT, "    color_fg = 7;"
        FPRINT FP_OUTPUT, "    color_bg = 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),(WORD)color_pshpop);"
        FPRINT FP_OUTPUT, "    color_fg = (color_pshpop & 0x0F);"
        FPRINT FP_OUTPUT, "    color_bg = (color_pshpop & 0xF0) / 16;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Consolesize THEN
        FPRINT FP_OUTPUT, "void BCX_SetConsoleSize (int NewX,int NewY)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  COORD    Coords={0};"
        FPRINT FP_OUTPUT, "  HANDLE   hconsole={0};"
        FPRINT FP_OUTPUT, "  SMALL_RECT  ConsoleSize={0};"
        FPRINT FP_OUTPUT, "  CONSOLE_SCREEN_BUFFER_INFO csbi;"
        FPRINT FP_OUTPUT, "  memset (&csbi, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFO));"
        FPRINT FP_OUTPUT, "  hconsole=GetStdHandle(STD_OUTPUT_HANDLE);"
        FPRINT FP_OUTPUT, "  GetConsoleScreenBufferInfo (hconsole, &csbi);"
        FPRINT FP_OUTPUT, "  if(csbi.dwSize.X>NewX)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Coords.X = csbi.dwSize.X;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Coords.X = NewX;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if(csbi.dwSize.Y > NewY)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Coords.Y=csbi.dwSize.Y;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Coords.Y=NewY;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  ConsoleSize.Right = NewX-1;"
        FPRINT FP_OUTPUT, "  ConsoleSize.Bottom = NewY-1;"
        FPRINT FP_OUTPUT, "  SetConsoleScreenBufferSize (hconsole, Coords);"
        FPRINT FP_OUTPUT, "  SetConsoleWindowInfo (hconsole, TRUE, &ConsoleSize);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void BCX_PushConsoleSize (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  COORD    Coords={0};"
        FPRINT FP_OUTPUT, "  HANDLE   hconsole={0};"
        FPRINT FP_OUTPUT, "  CONSOLE_SCREEN_BUFFER_INFO  csbi;"
        FPRINT FP_OUTPUT, "  memset (&csbi, 0, sizeof(CONSOLE_SCREEN_BUFFER_INFO));"
        FPRINT FP_OUTPUT, "  SMALL_RECT  ConsoleSize={0};"
        FPRINT FP_OUTPUT, "  hconsole=GetStdHandle(STD_OUTPUT_HANDLE);"
        FPRINT FP_OUTPUT, "  GetConsoleScreenBufferInfo (hconsole , &csbi);"
        FPRINT FP_OUTPUT, "  BcxSaveConX = 1 + csbi.srWindow.Right-csbi.srWindow.Left;"
        FPRINT FP_OUTPUT, "  BcxSaveConY = 1 + csbi.srWindow.Bottom-csbi.srWindow.Top;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void BCX_PopConsoleSize (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  BCX_SetConsoleSize (BcxSaveConX ,BcxSaveConY);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Panel THEN
        FPRINT FP_OUTPUT, "void panel (int x1, int y1, int x2, int y2, int fg, int bg, int charcode, int flg)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  ULONG ret;"
        FPRINT FP_OUTPUT, "  int attr = fg+bg*16, x, y;"
        FPRINT FP_OUTPUT, "  for(y = y1;y<=y2;y++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    for(x = x1;x<=x2;x++)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      cursor.X = x - 1;"
        FPRINT FP_OUTPUT, "      cursor.Y = y - 1;"
        FPRINT FP_OUTPUT, "      if (flg) FillConsoleOutputCharacter(hConsole, charcode,  1, cursor, &ret);"
        FPRINT FP_OUTPUT, "      FillConsoleOutputAttribute(hConsole, attr, 1, cursor, &ret);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Midstr THEN
        FPRINT FP_OUTPUT, "void midstr (char *szSrc, int st, int length, char *rep)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int srclen = (int)strlen(szSrc);"
        FPRINT FP_OUTPUT, "  if (st > srclen++ || st<1) return;"
        FPRINT FP_OUTPUT, "  int replen = (int)strlen(rep);"
        FPRINT FP_OUTPUT, "  if (replen < length || length==(-1)) length = replen;"
        FPRINT FP_OUTPUT, "  if ((st+length) > srclen) length = srclen-st;"
        FPRINT FP_OUTPUT, "  memcpy(&szSrc[st-1], rep, length);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Swap THEN
        FPRINT FP_OUTPUT, "void swap (byte* A_, byte* B_, int length)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  byte t;"
        FPRINT FP_OUTPUT, "  while(length--)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    t = *A_;"
        FPRINT FP_OUTPUT, "    *(A_++) = *B_;"
        FPRINT FP_OUTPUT, "    *(B_++) = t;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Like THEN
        FPRINT FP_OUTPUT, "int like (PCTSTR Haystack, PCTSTR Needle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  while (*Needle)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*Needle == '#')"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (! *Haystack) return false;"
        FPRINT FP_OUTPUT, "      if (! isdigit(*Haystack)) return false;"
        FPRINT FP_OUTPUT, "      ++Haystack;"
        FPRINT FP_OUTPUT, "      ++Needle;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else if (*Needle == '?')"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (! *Haystack) return false;"
        FPRINT FP_OUTPUT, "      ++Haystack;"
        FPRINT FP_OUTPUT, "      ++Needle;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else if (*Needle == '*')"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (like(Haystack, Needle + 1)) return true;"
        FPRINT FP_OUTPUT, "      if (*Haystack && like(Haystack + 1, Needle))"
        FPRINT FP_OUTPUT, "        return true;"
        FPRINT FP_OUTPUT, "      return false;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else if ((*Haystack++ | 32) != (*Needle++ | 32)) return false; // case-insensitive"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return !*Haystack && !*Needle;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Lof THEN
        FPRINT FP_OUTPUT, "unsigned long long int lof (PCTSTR FName)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  WIN32_FILE_ATTRIBUTE_DATA fad;"
        FPRINT FP_OUTPUT, "  if (!GetFileAttributesEx(FName, GetFileExInfoStandard, &fad))"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "  LARGE_INTEGER size;"
        FPRINT FP_OUTPUT, "  size.HighPart = fad.nFileSizeHigh;"
        FPRINT FP_OUTPUT, "  size.LowPart = fad.nFileSizeLow;"
        FPRINT FP_OUTPUT, "  return size.QuadPart;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Mkpath THEN
        FPRINT FP_OUTPUT, "void MkPath (PCTSTR szPath_)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char Buf[64][BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "  char Tmp[BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "  int  Elements={0};"
        FPRINT FP_OUTPUT, "  int  i;"
        FPRINT FP_OUTPUT, "  Elements = Split(Buf, szPath_, vchr(1,92)) - 1;"
        FPRINT FP_OUTPUT, "  for(i = 0; i<=Elements; i += 1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    strcpy(Tmp, join(3,Tmp,Buf[i],vchr(1,92)));"
        FPRINT FP_OUTPUT, "    _mkdir (Tmp);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Screen THEN
        FPRINT FP_OUTPUT, "int Screen (int y, int x, int mode)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HANDLE  hConsole_ = GetStdHandle(STD_OUTPUT_HANDLE);"
        FPRINT FP_OUTPUT, "  ULONG Slen;"
        FPRINT FP_OUTPUT, "  COORD Coord;"
        FPRINT FP_OUTPUT, "  WORD  Attr;"
        FPRINT FP_OUTPUT, "  char  Char[2];"
        FPRINT FP_OUTPUT, "  Coord.X = x-1;"
        FPRINT FP_OUTPUT, "  Coord.Y = y-1;"
        FPRINT FP_OUTPUT, "  ReadConsoleOutputCharacterA(hConsole_, Char, 1, Coord, &Slen);"
        FPRINT FP_OUTPUT, "  ReadConsoleOutputAttribute(hConsole_, &Attr, 1, Coord, &Slen);"
        FPRINT FP_OUTPUT, "  if (mode)"
        FPRINT FP_OUTPUT, "  return  Attr;"
        FPRINT FP_OUTPUT, "  return  (unsigned char)Char[0];"   ' 831 mod by Robert Wishlaw - supports foreign codepages
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Iif THEN
        FPRINT FP_OUTPUT, "double iif (int cond, double tp, double fp)"    ' 766 Changed cond to int
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (cond!=0) return tp;"
        FPRINT FP_OUTPUT, "  return fp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Doevents THEN
        FPRINT FP_OUTPUT, "void DoEvents (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  MSG Msg;"
        FPRINT FP_OUTPUT, "  while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    TranslateMessage(&Msg);"
        FPRINT FP_OUTPUT, "    DispatchMessage(&Msg);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_FileAttrClip2



SUB Emit_RT_SortDynamic (FP_OUTPUT AS FILE)
    IF Use_DynamicA THEN
        FPRINT FP_OUTPUT, "void *CreateArr(void *dynavar, int elem_size, int update, int num_dims, size_t *args) {"
        FPRINT FP_OUTPUT, "  size_t s, s1, s2;"
        FPRINT FP_OUTPUT, "  void **vp;"
        FPRINT FP_OUTPUT, "  size_t *marker;"
        FPRINT FP_OUTPUT, "  marker = args;"
        FPRINT FP_OUTPUT, "  s = *marker++;"
        FPRINT FP_OUTPUT, "  s2 = s + 2;"
        FPRINT FP_OUTPUT, "  if (num_dims == 1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (update && dynavar)"
        FPRINT FP_OUTPUT, "      dynavar = realloc(dynavar, s2 * elem_size);"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "      dynavar = calloc(s2, elem_size);"
        FPRINT FP_OUTPUT, "    return dynavar;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else if (update && dynavar)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    s1 = 0;"
        FPRINT FP_OUTPUT, "    vp = (void**)dynavar;"
        FPRINT FP_OUTPUT, "    while(*vp && s1 <= s)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      vp++;"
        FPRINT FP_OUTPUT, "      s1++;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (s1 > s)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      vp--;"
        FPRINT FP_OUTPUT, "      DestroyArr(vp, num_dims, 0);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    dynavar = realloc(dynavar, s2 * sizeof(int *));"
        FPRINT FP_OUTPUT, "    s1 = 0;"
        FPRINT FP_OUTPUT, "    vp = (void**)dynavar;"
        FPRINT FP_OUTPUT, "    while(*vp && s1 <= s)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      vp++;"
        FPRINT FP_OUTPUT, "      s1++;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    while(s1 < s2)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      *(((void **)vp)) = NULL;"
        FPRINT FP_OUTPUT, "      vp++;"
        FPRINT FP_OUTPUT, "      s1++;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    dynavar = calloc(s2 * sizeof(int *), 1);"
        FPRINT FP_OUTPUT, "  vp = (void**)dynavar;"
        FPRINT FP_OUTPUT, "  if (--num_dims > 0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    for(s1 = 0; s1 < s; s1++)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      vp[s1] = CreateArr(vp[s1], elem_size, update, num_dims, marker);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return dynavar;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void DestroyArr (void** dynavar,int num_dims, int top_free)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int ii = 0;"
        FPRINT FP_OUTPUT, "  static int s = 0;"
        FPRINT FP_OUTPUT, "  if (num_dims == 1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    free(dynavar);"
        FPRINT FP_OUTPUT, "    dynavar = NULL;"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  s++;"
        FPRINT FP_OUTPUT, "  num_dims--;"
        FPRINT FP_OUTPUT, "  while(dynavar[ii])"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    DestroyArr((void**)dynavar[ii], num_dims, top_free);"
        FPRINT FP_OUTPUT, "    if (num_dims > 1)"
        FPRINT FP_OUTPUT, "      free(dynavar[ii]);"
        FPRINT FP_OUTPUT, "    dynavar[ii++]=NULL;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  s--;"
        FPRINT FP_OUTPUT, "  if (0 == s && top_free)"
        FPRINT FP_OUTPUT, "    free(dynavar);"
        FPRINT FP_OUTPUT, "  dynavar = NULL;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Idxqsort THEN
        FPRINT FP_OUTPUT, "int IdxCompare (const void *one, const void *two)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int *ptr1 = (int*)(one);"
        FPRINT FP_OUTPUT, "  int *ptr2 = (int*)(two);"
        FPRINT FP_OUTPUT, "  return bcx_stricmp (pppStr[Key][*ptr1], pppStr[Key][*ptr2]);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_IdxqsortSt THEN
        FPRINT FP_OUTPUT, "int IdxCompareSt (const void* one, const void* two)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "#define compare1 cmp1+(StructSize * (*(UINT*)(one)))"
        FPRINT FP_OUTPUT, "#define compare2 cmp1+(StructSize * (*(UINT*)(two)))"

        FPRINT FP_OUTPUT, "  if (Key==0)"      ' String
        FPRINT FP_OUTPUT, "    return  bcx_stricmp(compare1, compare2);"

        FPRINT FP_OUTPUT, "  if (Key==1)"      ' INTEGER
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*(int*)(compare1) < *(int*)(compare2)) return -1;"
        FPRINT FP_OUTPUT, "    if (*(int*)(compare1) > *(int*)(compare2)) return 1;"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "  }"

        FPRINT FP_OUTPUT, "  if (Key==2)"      ' Double
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*(double*)(compare1) < *(double*)(compare2)) return -1;"
        FPRINT FP_OUTPUT, "    if (*(double*)(compare1) > *(double*)(compare2)) return 1;"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "  }"

        FPRINT FP_OUTPUT, "  if (Key==3)"      ' Unsigned integer
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*(UINT*)(compare1) < *(UINT*)(compare2)) return -1;"
        FPRINT FP_OUTPUT, "    if (*(UINT*)(compare1) > *(UINT*)(compare2)) return 1;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_PtrqsortSt THEN
        FPRINT FP_OUTPUT, "int PtrCompareSt (const void* one, const void* two)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "#define pcompare1 ((char*)(one)+OffSet)"
        FPRINT FP_OUTPUT, "#define pcompare2 ((char*)(two)+OffSet)"

        FPRINT FP_OUTPUT, "  if (Key==0)"
        FPRINT FP_OUTPUT, "    return  bcx_stricmp(pcompare1, pcompare2);"

        FPRINT FP_OUTPUT, "  if (Key==1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*(int*)(pcompare1) < *(int*)(pcompare2)) return -1;"
        FPRINT FP_OUTPUT, "    if (*(int*)(pcompare1) > *(int*)(pcompare2)) return 1;"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "  }"

        FPRINT FP_OUTPUT, "  if (Key==2)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*(double*)(pcompare1) < *(double*)(pcompare2)) return -1;"
        FPRINT FP_OUTPUT, "    if (*(double*)(pcompare1) > *(double*)(pcompare2)) return 1;"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "  }"

        FPRINT FP_OUTPUT, "  if (Key==3)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*(UINT*)(pcompare1) < *(UINT*)(pcompare2)) return -1;"
        FPRINT FP_OUTPUT, "    if (*(UINT*)(pcompare1) > *(UINT*)(pcompare2)) return 1;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Strqsortas THEN
        FPRINT FP_OUTPUT, "int StrCompareAs (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = (char*) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = (char*) arg2;"
        FPRINT FP_OUTPUT, "  return strcmp (v1, v2);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Strqsorta THEN
        FPRINT FP_OUTPUT, "int StrCompareA (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = (char*) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = (char*) arg2;"
        FPRINT FP_OUTPUT, "  return bcx_stricmp (v1,v2);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Strqsortds THEN
        FPRINT FP_OUTPUT, "int StrCompareDs (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = (char*) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = (char*) arg2;"
        FPRINT FP_OUTPUT, "  return strcmp (v2, v1);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Strqsortd THEN
        FPRINT FP_OUTPUT, "int StrCompareD (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = (char*) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = (char*) arg2;"
        FPRINT FP_OUTPUT, "  return bcx_stricmp (v2, v1);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_DynStrqsortas THEN
        FPRINT FP_OUTPUT, "int DynStrCompareAs (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = *(char **) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = *(char **) arg2;"
        FPRINT FP_OUTPUT, "  return strcmp(v1, v2);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_DynStrqsorta THEN
        FPRINT FP_OUTPUT, "int DynStrCompareA (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = *(char **) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = *(char **) arg2;"
        FPRINT FP_OUTPUT, "  return bcx_stricmp(v1, v2);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_DynStrqsortds THEN
        FPRINT FP_OUTPUT, "int DynStrCompareDs (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = *(char **) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = *(char **) arg2;"
        FPRINT FP_OUTPUT, "  return strcmp(v2, v1);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_DynStrqsortd THEN
        FPRINT FP_OUTPUT, "int DynStrCompareD (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = *(char **) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = *(char **) arg2;"
        FPRINT FP_OUTPUT, "  return bcx_stricmp(v2, v1);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_DynAlphaNumericA THEN
        FPRINT FP_OUTPUT, "int DynAlphaNumericA (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = *(char **) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = *(char **) arg2;"
        FPRINT FP_OUTPUT, "  return AlphaNumeric(v1, v2);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_DynAlphaNumericD THEN
        FPRINT FP_OUTPUT, "int DynAlphaNumericD (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *v1 = *(char **) arg1;"
        FPRINT FP_OUTPUT, "  char *v2 = *(char **) arg2;"
        FPRINT FP_OUTPUT, "  return AlphaNumeric(v2, v1);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_AlphaNumericA THEN
        FPRINT FP_OUTPUT, "int AlphaNumericA (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return AlphaNumeric (arg1, arg2);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_AlphaNumericD THEN
        FPRINT FP_OUTPUT, "int AlphaNumericD (const void *arg1, const void *arg2)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return AlphaNumeric (arg2, arg1);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_AlphaNumeric THEN
        FPRINT FP_OUTPUT, "int AlphaNumeric(const void *s1p, const void *s2p)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *s1 = (char*)s1p;"
        FPRINT FP_OUTPUT, "  char *s2 = (char*)s2p;"
        FPRINT FP_OUTPUT, "  do"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (isdigit(s1[0]) && isdigit(s2[0]))"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      // Compare numbers as numbers"
        FPRINT FP_OUTPUT, "      int c1 = strspn(s1, "; ENC$("0123456789"); ");"
        FPRINT FP_OUTPUT, "      int c2 = strspn(s2, "; ENC$("0123456789"); ");"
        FPRINT FP_OUTPUT, "      if (c1 > c2)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        return 1;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      else if (c1 < c2)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        return -1;"
        FPRINT FP_OUTPUT, "      };"
        FPRINT FP_OUTPUT, "      // the digit strings have equal length, so compare digit by digit"
        FPRINT FP_OUTPUT, "      while (c1--)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        if (s1[0] > s2[0])"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          return 1;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        else if (s1[0] < s2[0])"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          return -1;"
        FPRINT FP_OUTPUT, "        };"
        FPRINT FP_OUTPUT, "        s1++;"
        FPRINT FP_OUTPUT, "        s2++;"
        FPRINT FP_OUTPUT, "      };"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else if (s1[0] > s2[0])"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      return 1;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else if (s1[0] < s2[0])"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      return -1;"
        FPRINT FP_OUTPUT, "    };"
        FPRINT FP_OUTPUT, "    s1++;"
        FPRINT FP_OUTPUT, "    s2++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  while ((*s1!=0) || (*s2!=0));"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Numqsortaint THEN
        FPRINT FP_OUTPUT, "int NumCompareAint (const void *one, const void *two)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int *ptr1 = (int *)(one);"
        FPRINT FP_OUTPUT, "  int *ptr2 = (int *)(two);"
        FPRINT FP_OUTPUT, "  if (*ptr1 < *ptr2) return -1;"
        FPRINT FP_OUTPUT, "  else if (*ptr1 == *ptr2) return 0;"
        FPRINT FP_OUTPUT, "  else return 1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Numqsortdint THEN
        FPRINT FP_OUTPUT, "int NumCompareDint (const void *one, const void *two)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int *ptr1 = (int *)(one);"
        FPRINT FP_OUTPUT, "  int *ptr2 = (int *)(two);"
        FPRINT FP_OUTPUT, "  if (*ptr1 > *ptr2) return -1;"
        FPRINT FP_OUTPUT, "  else if (*ptr1 == *ptr2) return 0;"
        FPRINT FP_OUTPUT, "  else return 1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Numqsortafloat THEN
        FPRINT FP_OUTPUT, "int NumCompareAfloat (const void *one, const void *two)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  float *ptr1 = (float *)(one);"
        FPRINT FP_OUTPUT, "  float *ptr2 = (float *)(two);"
        FPRINT FP_OUTPUT, "  if (*ptr1 < *ptr2) return -1;"
        FPRINT FP_OUTPUT, "  else if (*ptr1 == *ptr2) return 0;"
        FPRINT FP_OUTPUT, "  else return 1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Numqsortdfloat THEN
        FPRINT FP_OUTPUT, "int NumCompareDfloat (const void *one, const void *two)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  float *ptr1 = (float *)(one);"
        FPRINT FP_OUTPUT, "  float *ptr2 = (float *)(two);"
        FPRINT FP_OUTPUT, "  if (*ptr1 > *ptr2) return -1;"
        FPRINT FP_OUTPUT, "  else if (*ptr1 == *ptr2) return 0;"
        FPRINT FP_OUTPUT, "  else return 1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Numqsortadouble THEN
        FPRINT FP_OUTPUT, "int NumCompareAdouble (const void *one, const void *two)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  double *ptr1 = (double *)(one);"
        FPRINT FP_OUTPUT, "  double *ptr2 = (double *)(two);"
        FPRINT FP_OUTPUT, "  if (*ptr1 < *ptr2) return -1;"
        FPRINT FP_OUTPUT, "  else if (*ptr1 == *ptr2) return 0;"
        FPRINT FP_OUTPUT, "  else return 1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Numqsortddouble THEN
        FPRINT FP_OUTPUT, "int NumCompareDdouble (const void *one, const void *two)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  double *ptr1 = (double *)(one);"
        FPRINT FP_OUTPUT, "  double *ptr2 = (double *)(two);"
        FPRINT FP_OUTPUT, "  if (*ptr1 > *ptr2) return -1;"
        FPRINT FP_OUTPUT, "  else if (*ptr1 == *ptr2) return 0;"
        FPRINT FP_OUTPUT, "  else return 1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_FillArray THEN
        FPRINT FP_OUTPUT, "int fillarray(PCTSTR input, int ArrayType, int MaxCnt, void *Array)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (MaxCnt < 1) return -1;"
        FPRINT FP_OUTPUT, "  int c = 0, cnt=(-1), cnt2;"
        FPRINT FP_OUTPUT, "  char A [BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  int    *intptr    = (int *)Array;"
        FPRINT FP_OUTPUT, "  float  *floatptr  = (float *)Array;"
        FPRINT FP_OUTPUT, "  double *doubleptr = (double *)Array;"
        FPRINT FP_OUTPUT, "  long double *ldoubleptr = (long double *)Array;"
        FPRINT FP_OUTPUT, "  for(;;)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    cnt2 = 0;"
        FPRINT FP_OUTPUT, "    while(input[++cnt]!=',')"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (input[cnt]==0) break;"
        FPRINT FP_OUTPUT, "      A[cnt2++]=input[cnt];"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    A[cnt2]=0;"
        FPRINT FP_OUTPUT, "    if (cnt2==0||c==MaxCnt) break;"
        FPRINT FP_OUTPUT, "    if (ArrayType==2)"
        FPRINT FP_OUTPUT, "      intptr[c++] = atoi(A);"
        FPRINT FP_OUTPUT, "    else if (ArrayType==3)"
        FPRINT FP_OUTPUT, "      floatptr[c++] = atof(A);"
        FPRINT FP_OUTPUT, "    else if (ArrayType==4)"
        FPRINT FP_OUTPUT, "      doubleptr[c++] = atof(A);"
        FPRINT FP_OUTPUT, "    else if (ArrayType==5)"
        FPRINT FP_OUTPUT, "      ldoubleptr[c++] = atof(A);"
        FPRINT FP_OUTPUT, "    if (input[cnt]==0) break;"
        FPRINT FP_OUTPUT, "  } "
        FPRINT FP_OUTPUT, "  return (c-1);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Lclick THEN
        FPRINT FP_OUTPUT, "int lClick (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if(GetSystemMetrics(SM_SWAPBUTTON)){"
        FPRINT FP_OUTPUT, "      if(GetAsyncKeyState(VK_RBUTTON)&0x8000) {"
        FPRINT FP_OUTPUT, "          return TRUE;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      else"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          return FALSE;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  if(GetAsyncKeyState(VK_LBUTTON)&0x8000) {"
        FPRINT FP_OUTPUT, "      return TRUE;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      return FALSE;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Rclick THEN
        FPRINT FP_OUTPUT, "int rClick (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if(GetSystemMetrics(SM_SWAPBUTTON)){"
        FPRINT FP_OUTPUT, "      if(GetAsyncKeyState(VK_LBUTTON)&0x8000) {"
        FPRINT FP_OUTPUT, "          return TRUE;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      else"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          return FALSE;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  if(GetAsyncKeyState(VK_RBUTTON)&0x8000) {"
        FPRINT FP_OUTPUT, "      return TRUE;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      return FALSE;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Loc THEN
        FPRINT FP_OUTPUT, "int loc(FILE *fp, int fplen)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  fpos_t t;"
        FPRINT FP_OUTPUT, "  fgetpos(fp, &t);"
        FPRINT FP_OUTPUT, "#if defined(__POCC__)"
        FPRINT FP_OUTPUT, "  t.off %= fplen;"
        FPRINT FP_OUTPUT, "  return (int)t.off;"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  t %= fplen;"
        FPRINT FP_OUTPUT, "  return (int)t;"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Rec THEN
        FPRINT FP_OUTPUT, "int rec(FILE *fp, int fplen)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  fpos_t t;"
        FPRINT FP_OUTPUT, "  fgetpos(fp, &t);"
        FPRINT FP_OUTPUT, "#if defined(__POCC__)"
        FPRINT FP_OUTPUT, "  t.off /= fplen;"
        FPRINT FP_OUTPUT, "  return (int)++t.off;"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  t /= fplen;"
        FPRINT FP_OUTPUT, "  return (int)++t;"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_RecCount THEN
        FPRINT FP_OUTPUT, "int reccount(FILE *fp, int fplen)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  fpos_t t;"
        FPRINT FP_OUTPUT, "  _fseeki64 (fp, 0, SEEK_END);"
        FPRINT FP_OUTPUT, "  fgetpos(fp, &t);"
        FPRINT FP_OUTPUT, "#if defined(__POCC__)"
        FPRINT FP_OUTPUT, "  t.off /= fplen;"
        FPRINT FP_OUTPUT, "  return (int)t.off;"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  t /= fplen;"
        FPRINT FP_OUTPUT, "  return (int)t;"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Scan THEN
        FPRINT FP_OUTPUT, "int scan(PCTSTR input, PCTSTR format, ... )"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int       L_c ;"
        FPRINT FP_OUTPUT, "  int       L_d ;"
        FPRINT FP_OUTPUT, "  char     *s_;"
        FPRINT FP_OUTPUT, "  int      *intptr;"
        FPRINT FP_OUTPUT, "  float    *floatptr;"
        FPRINT FP_OUTPUT, "  double   *doubleptr;"
        FPRINT FP_OUTPUT, "  char      L_ScanBuffer[50][BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  va_list   marker;"
        FPRINT FP_OUTPUT, "  L_c = 0;"
        FPRINT FP_OUTPUT, "  L_d = Split(L_ScanBuffer,input,"; ENC$(",") ; ");"
        FPRINT FP_OUTPUT, "  va_start(marker, format); //Initialize arguments"
        FPRINT FP_OUTPUT, "  while(L_d && *format)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (*format == '%') format++;"
        FPRINT FP_OUTPUT, "    if (*format == 's')"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      s_ = va_arg(marker, char *);"
        FPRINT FP_OUTPUT, "      strcpy(s_, L_ScanBuffer[L_c]);"
        FPRINT FP_OUTPUT, "      L_c++;"
        FPRINT FP_OUTPUT, "      L_d--;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (*format == 'd')"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      intptr = va_arg(marker, int *);"
        FPRINT FP_OUTPUT, "      *intptr = atoi(L_ScanBuffer[L_c]);"
        FPRINT FP_OUTPUT, "      L_c++;"
        FPRINT FP_OUTPUT, "      L_d--;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (*format == 'g')"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      floatptr = va_arg(marker, float *);"
        FPRINT FP_OUTPUT, "      *floatptr = strtof(L_ScanBuffer[L_c], NULL);"
        FPRINT FP_OUTPUT, "      L_c++;"
        FPRINT FP_OUTPUT, "      L_d--;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (*format == 'l')"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      format++;"
        FPRINT FP_OUTPUT, "      doubleptr = va_arg(marker, double *);"
        FPRINT FP_OUTPUT, "      *doubleptr = atof(L_ScanBuffer[L_c]);"
        FPRINT FP_OUTPUT, "      L_c++;"
        FPRINT FP_OUTPUT, "      L_d--;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    format++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  va_end(marker);              // Reset variable arguments"
        FPRINT FP_OUTPUT, "  if (L_d) return(1);          // More data than variables"
        FPRINT FP_OUTPUT, "  if (0 == *format) return(0); // OK"
        FPRINT FP_OUTPUT, "  return(-1);                  // More variables than data"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_SortDynamic



SUB Emit_RT_SplitConsole (FP_OUTPUT AS FILE)
    IF Use_KBinput THEN
        FPRINT FP_OUTPUT, "void KBinput (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  *InputBuffer = 0;"
        FPRINT FP_OUTPUT, "  fgets(InputBuffer, sizeof(InputBuffer)-1, stdin);"
        FPRINT FP_OUTPUT, "  InputBuffer[(int)strlen(InputBuffer)-1]=0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Split THEN
        FPRINT FP_OUTPUT, "int Split (char Buf[][BCXSTRSIZE], PCTSTR T, PCTSTR Delim, int Flg)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int  Begin = 0;"
        FPRINT FP_OUTPUT, "  int  Count = 0;"
        FPRINT FP_OUTPUT, "  int  Quote = 0;"
        FPRINT FP_OUTPUT, "  int  Index = 0;"
        FPRINT FP_OUTPUT, "  int  ii    = 0;"
        FPRINT FP_OUTPUT, "  int  lenT  = (int)strlen(T);"
        FPRINT FP_OUTPUT, "  if (Flg<0||Flg>4) Flg=0;"
        FPRINT FP_OUTPUT, "  const char DDQt [3] = {34,34,0}; // Double Quotation Mark"
        FPRINT FP_OUTPUT, "  const char US   [2] = {30,0};    // Information Separator One"
        FPRINT FP_OUTPUT, "  const char DQt  [2] = {34,0};    // Quotation Mark"
        FPRINT FP_OUTPUT, "  for(Index = 1;Index<=lenT;Index++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (instr(Delim, mid(T, Index, 1)) && !Quote)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      strcpy(Buf[Count], (char*)mid(T, Begin, Index-Begin));"
        FPRINT FP_OUTPUT, "      if (0 == (Flg & 2))"
        FPRINT FP_OUTPUT, "        Count++;"
        FPRINT FP_OUTPUT, "      else"
        FPRINT FP_OUTPUT, "      if (Buf[Count][0] != 0) Count++;"
        FPRINT FP_OUTPUT, "      Begin = 0;"
        FPRINT FP_OUTPUT, "      if ((Flg & 1) == 1)   // 1 if true"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Count++], (char*)mid(T, Index, 1));"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (strcmp(mid(T, Index, 1), DQt)==0) Quote=!Quote;"
        FPRINT FP_OUTPUT, "      if (Begin==0) Begin = Index;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (Begin)"
        FPRINT FP_OUTPUT, "    strcpy(Buf[Count++], (char*)mid(T, Begin, Index-Begin));"
        FPRINT FP_OUTPUT, "  if ((0 == (Flg & 1)) && (Flg < 4)) // 0 if false"
        FPRINT FP_OUTPUT, "    for(ii = 0;ii<Count;ii++) strcpy(Buf[ii], (char*)RemoveStr(Buf[ii], DQt));"
        FPRINT FP_OUTPUT, "  if(Flg == 4)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    for(Index = 0;Index<Count;Index++)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if(instr(Buf[Index],DDQt))"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Index],replace(Buf[Index],DDQt,US));"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Index],RemoveStr(Buf[Index],DQt));"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Index],replace(Buf[Index],US,DQt));"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      else"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Index],RemoveStr(Buf[Index],DQt));"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return Count;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_DSplit THEN
        FPRINT FP_OUTPUT, "int DSplit (PSTR *Buf, PCTSTR T, PCTSTR Delim, int Flg) {"
        FPRINT FP_OUTPUT, " int  Begin = 0;"
        FPRINT FP_OUTPUT, "  int  Count = 0;"
        FPRINT FP_OUTPUT, "  int  Quote = 0;"
        FPRINT FP_OUTPUT, "  int  Index = 0;"
        FPRINT FP_OUTPUT, "  int  lenT  = (int)strlen(T);"
        FPRINT FP_OUTPUT, "  if (Flg<0||Flg>4) Flg=0;"
        FPRINT FP_OUTPUT, "  const char DDQt [3] = {34,34,0}; // Double Quotation Mark"
        FPRINT FP_OUTPUT, "  const char US   [2] = {30,0};    // Information Separator One"
        FPRINT FP_OUTPUT, "  const char DQt  [2] = {34,0};    // Quotation Mark"
        FPRINT FP_OUTPUT, "  for(Index = 1;Index<=lenT;Index++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (instr(Delim, mid(T, Index, 1)) && !Quote)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      strcpy(Buf[Count], (char*)mid(T, Begin, Index-Begin));"
        FPRINT FP_OUTPUT, "      if (0 == (Flg & 2))"
        FPRINT FP_OUTPUT, "        Count++;"
        FPRINT FP_OUTPUT, "      else"
        FPRINT FP_OUTPUT, "      if (Buf[Count][0] != 0) Count++;"
        FPRINT FP_OUTPUT, "      Begin = 0;"
        FPRINT FP_OUTPUT, "      if ((Flg & 1) == 1)   // 1 if true"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Count++], (char*)mid(T, Index, 1));"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (strcmp(mid(T, Index, 1), DQt)==0) Quote=!Quote;"
        FPRINT FP_OUTPUT, "      if (Begin==0)  Begin = Index;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (Begin) strcpy(Buf[Count++], (char*)mid(T, Begin, Index-Begin));"
        FPRINT FP_OUTPUT, "  if ((0 == (Flg & 1)) && (Flg < 4))   // 0 if false"
        FPRINT FP_OUTPUT, "    for(Index = 0;Index<Count;Index++) strcpy(Buf[Index], (char*)RemoveStr(Buf[Index], DQt));"
        FPRINT FP_OUTPUT, "  if(Flg == 4)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    for(Index = 0;Index<Count;Index++)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if(instr(Buf[Index],DDQt))"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Index],replace(Buf[Index],DDQt,US));"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Index],RemoveStr(Buf[Index],DQt));"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Index],replace(Buf[Index],US,DQt));"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      else"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        strcpy(Buf[Index],RemoveStr(Buf[Index],DQt));"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return Count;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Bin2dec THEN
        FPRINT FP_OUTPUT, "int Bin2Dec (PCTSTR cptr)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int ii, j = 0;"
        FPRINT FP_OUTPUT, "  while(cptr && *cptr && strchr("; ENC$("01"); ", *cptr))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    ii = *cptr++ - '0';"
        FPRINT FP_OUTPUT, "    j <<= 1;"
        FPRINT FP_OUTPUT, "    j |= (ii & 0x01);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, " return(j);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Hex2Dec THEN
        FPRINT FP_OUTPUT, "UINT64 Hex2Dec (PCTSTR szInput)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if(*szInput==38){"                             ' &h
        FPRINT FP_OUTPUT, "    return strtoull(szInput + 2, NULL, 16);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else if(*szInput + 1 == 120){"                 ' 0x
        FPRINT FP_OUTPUT, "    return strtoull(szInput + 2, NULL, 16);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    return strtoull(szInput, NULL, 16);"         ' no prefix
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Verify THEN
        FPRINT FP_OUTPUT, "int Verify (PCTSTR szSrc, PCTSTR Allowed)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  UINT ii, j;"
        FPRINT FP_OUTPUT, "  for (ii = 1; ii<=(int)strlen(szSrc); ii++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    j = VerifyInstr(Allowed, mid(szSrc, ii, 1));"
        FPRINT FP_OUTPUT, "    if (!j) return 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return TRUE;"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, "int VerifyInstr(PCTSTR szSrc, PCTSTR strPattern, int offset)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *s;"
        FPRINT FP_OUTPUT, "  if (!szSrc || !strPattern || !*strPattern || offset > (int)strlen(szSrc)) return 0;"
        FPRINT FP_OUTPUT, "  s = (char*)strstr (offset>0 ? szSrc+offset-1 : szSrc, strPattern);"
        FPRINT FP_OUTPUT, "  return s ? (int)(s-szSrc)+1 : 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Freefile THEN
        FPRINT FP_OUTPUT, "FILE* FreeFile (void)"
        FPRINT FP_OUTPUT, "{"                  ' 828 MrBcx - Previous versions had a memory leak.
        FPRINT FP_OUTPUT, "    return NULL;"   ' OPEN FILE fills the actual FILE structure, including the handle
        FPRINT FP_OUTPUT, "}\n\n"              ' This function is nothing more than unneeded syntactic sugar.
    END IF


    IF Use_Textmode THEN
        FPRINT FP_OUTPUT, "int TextMode (int Y)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HANDLE hCons = GetStdHandle(STD_OUTPUT_HANDLE);"
        FPRINT FP_OUTPUT, "  COORD  Coord;"
        FPRINT FP_OUTPUT, "  Coord.X = 80;"
        FPRINT FP_OUTPUT, "  Coord.Y = Y;"
        FPRINT FP_OUTPUT, "  return SetConsoleScreenBufferSize(hCons, Coord);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Msgbox THEN
        FPRINT FP_OUTPUT, "int MsgBox (PCTSTR pszMsg, PCTSTR pszTitle, int iNum)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return MessageBox(GetActiveWindow(), pszMsg, pszTitle, iNum);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Center THEN
        FPRINT FP_OUTPUT, "void Center (HWND hwnd, HWND Xhwnd, HWND Yhwnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  RECT rect, rectP;"
        FPRINT FP_OUTPUT, "  int x, y, width, height;"
        FPRINT FP_OUTPUT, "  int screenwidth, screenheight;"
        FPRINT FP_OUTPUT, "  HMONITOR    hMonitor={0};"
        FPRINT FP_OUTPUT, "  MONITORINFO MonitorInfo;"
        FPRINT FP_OUTPUT, "  memset(&MonitorInfo, 0, sizeof(MONITORINFO));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  GetWindowRect((HWND)hwnd, &rect);"
        FPRINT FP_OUTPUT, "  width = rect.right-rect.left;"
        FPRINT FP_OUTPUT, "  height = rect.bottom-rect.top;"
        FPRINT FP_OUTPUT, "  if(GetSystemMetrics(SM_CMONITORS) == 1)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      hMonitor = MonitorFromRect(&rect,MONITOR_DEFAULTTOPRIMARY);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      hMonitor = MonitorFromRect(&rect,MONITOR_DEFAULTTONEAREST);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  MonitorInfo.cbSize = sizeof(MONITORINFO);"
        FPRINT FP_OUTPUT, "  GetMonitorInfo(hMonitor, &MonitorInfo);"
        FPRINT FP_OUTPUT, "  if(Xhwnd==NULL)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      rect.left = MonitorInfo.rcWork.left + ((MonitorInfo.rcWork.right - MonitorInfo.rcWork.left - width)/2);"
        FPRINT FP_OUTPUT, "      rect.top = MonitorInfo.rcWork.top + ((MonitorInfo.rcWork.bottom - MonitorInfo.rcWork.top - height)/2);"
        FPRINT FP_OUTPUT, "      rect.right = rect.left + width;"
        FPRINT FP_OUTPUT, "      rect.bottom = rect.top + height;"
        FPRINT FP_OUTPUT, "      SetWindowPos(hwnd, NULL, rect.left, rect.top, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);"
        FPRINT FP_OUTPUT, "      return;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  GetWindowRect(hwnd, &rect);"
        FPRINT FP_OUTPUT, "  GetWindowRect(Xhwnd, &rectP);"
        FPRINT FP_OUTPUT, "  width = rect.right-rect.left;"
        FPRINT FP_OUTPUT, "  x = ((rectP.right-rectP.left)-width)/2+rectP.left;"
        FPRINT FP_OUTPUT, "  if(Yhwnd == NULL)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      height = rect.bottom-rect.top;"
        FPRINT FP_OUTPUT, "      y = ((rectP.bottom-rectP.top)-height)/2+rectP.top;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      GetWindowRect(Yhwnd, &rectP);;"
        FPRINT FP_OUTPUT, "      height = rect.bottom-rect.top;;"
        FPRINT FP_OUTPUT, "      y = ((rectP.bottom-rectP.top)-height)/2+rectP.top;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  screenwidth = MonitorInfo.rcWork.right;"
        FPRINT FP_OUTPUT, "  screenheight = MonitorInfo.rcWork.bottom;"
        FPRINT FP_OUTPUT, "  if(x < MonitorInfo.rcWork.left)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      x = MonitorInfo.rcWork.left+(width/2);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  if(y < MonitorInfo.rcWork.top)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      y = MonitorInfo.rcWork.top+(height/2);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  if(((x + width>screenwidth)))"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      x = screenwidth-width;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  if(((y + height>screenheight)))"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      y = screenheight-height;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  MoveWindow (hwnd, x, y, width, height, FALSE);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Colordlg THEN
        FPRINT FP_OUTPUT, "int BCX_ColorDlg (ULONG defcolor, HWND hWnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static ULONG  CustColors[16];"
        FPRINT FP_OUTPUT, "  CHOOSECOLOR cc;"
        FPRINT FP_OUTPUT, "  memset(&cc, 0, sizeof(cc));"
        FPRINT FP_OUTPUT, "  cc.lStructSize = sizeof(CHOOSECOLOR);"
        FPRINT FP_OUTPUT, "  cc.hwndOwner = hWnd;"
        FPRINT FP_OUTPUT, "  cc.rgbResult = defcolor;"
        FPRINT FP_OUTPUT, "  cc.lpCustColors = CustColors;"
        FPRINT FP_OUTPUT, "  cc.Flags = CC_RGBINIT|CC_FULLOPEN;"
        FPRINT FP_OUTPUT, "  CmDlgHook = SetWindowsHookEx(WH_CBT, (HOOKPROC)SBProc, NULL, GetCurrentThreadId());" ' 833 MrBcx changed
        FPRINT FP_OUTPUT, "  ChooseColor(&cc);"
        FPRINT FP_OUTPUT, "  return cc.rgbResult;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Print THEN
        FPRINT FP_OUTPUT, "int BCX_Print(HWND hWnd, int x, int y, PCTSTR Text, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  int a = TextOut(DrawHDC, x, y, Text, strlen(Text));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd, DrawHDC);"
        FPRINT FP_OUTPUT, "  return a;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Printex THEN
        FPRINT FP_OUTPUT, "void BCX_Printex (HWND hWnd,long x,long y,char* MyText,long FG_Color,long BG_Color,char* FontFace,long FontSize,HDC hDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HDC   L_hDC;"
        FPRINT FP_OUTPUT, "  HFONT L_hFont;"
        FPRINT FP_OUTPUT, "  RECT  L_rc;"
        FPRINT FP_OUTPUT, "  SIZE  L_textSize;"
        FPRINT FP_OUTPUT, "  if(hDC != 0){"
        FPRINT FP_OUTPUT, "      L_hDC = hDC;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      L_hDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  L_hFont = CreateFont(FontSize, 0,0,0,0,0,0,0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, FontFace);"
        FPRINT FP_OUTPUT, "  SelectObject(L_hDC, L_hFont);"
        FPRINT FP_OUTPUT, "  GetTextExtentPoint32(L_hDC, MyText, (int)strlen(MyText), &L_textSize);"
        FPRINT FP_OUTPUT, "  L_rc.left = x;"
        FPRINT FP_OUTPUT, "  L_rc.top = y;"
        FPRINT FP_OUTPUT, "  L_rc.right = L_rc.left + L_textSize.cx;"
        FPRINT FP_OUTPUT, "  L_rc.bottom = L_rc.top + L_textSize.cy;"
        FPRINT FP_OUTPUT, "  SetTextColor(L_hDC, FG_Color);"
        FPRINT FP_OUTPUT, "  SetBkColor(L_hDC, BG_Color);"
        FPRINT FP_OUTPUT, "  DrawText(L_hDC, MyText, (int)strlen(MyText), &L_rc, DT_LEFT|DT_TOP);"
        FPRINT FP_OUTPUT, "  if(hDC == 0){"
        FPRINT FP_OUTPUT, "      ReleaseDC(hWnd, L_hDC);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  DeleteObject(L_hFont);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Run THEN
        '--------------------------------------------------------------------------------------
        ' MrBcx Updated August 2025
        ' Keeps BCX backward compatibility (it omits using the OS shell by default).
        ' Adds robust support for shell redirection & pipes by invoking COMSPEC /c when needed.
        '--------------------------------------------------------------------------------------
        FPRINT FP_OUTPUT, "int Run (PCTSTR Cmdline, int ShowHide, int WaitState)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int    fRet              =  0;"
        FPRINT FP_OUTPUT, "  ULONG  dwState           =  0;"
        FPRINT FP_OUTPUT, "  MSG    msg               = {0};"
        FPRINT FP_OUTPUT, "  BOOL   bQuitReceived     = FALSE;"
        FPRINT FP_OUTPUT, "  BOOL   needShell         = FALSE;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  PTSTR dynCmd            = {0};"
        FPRINT FP_OUTPUT, "  PTSTR shellArgs         = {0};"
        FPRINT FP_OUTPUT, "  PTSTR appName           = {0};"
        FPRINT FP_OUTPUT, "  PTSTR cmdLineToRun      = {0};"
        FPRINT FP_OUTPUT, "  TCHAR  comspec[MAX_PATH] = {0};"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  STARTUPINFO         si;"
        FPRINT FP_OUTPUT, "  PROCESS_INFORMATION pi;"
        FPRINT FP_OUTPUT, "  ZeroMemory(&pi, sizeof(pi));"
        FPRINT FP_OUTPUT, "  ZeroMemory(&si, sizeof(si));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  si.cb = sizeof(si);"
        FPRINT FP_OUTPUT, "  // Copy original Cmdline (CreateProcess could modify buffer)"
        FPRINT FP_OUTPUT, "  dynCmd = _tcsdup(Cmdline);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (!dynCmd) goto EXITRUN;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Always honor requested show/hide state"
        FPRINT FP_OUTPUT, "  si.dwFlags |= STARTF_USESHOWWINDOW;"
        FPRINT FP_OUTPUT, "  si.wShowWindow = (WORD)ShowHide;"
        FPRINT FP_OUTPUT, "  // Determine if a command processor is needed (for >, <, |, & etc.)"
        FPRINT FP_OUTPUT, "  needShell = (_tcspbrk(Cmdline, TEXT(" + ENC$(">|<&") + ")) != NULL);"
        FPRINT FP_OUTPUT, "  appName = NULL;"
        FPRINT FP_OUTPUT, "  cmdLineToRun = dynCmd;"
        FPRINT FP_OUTPUT, "  if (needShell)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    DWORD n = GetEnvironmentVariable(TEXT(" + ENC$("COMSPEC") + "), comspec, MAX_PATH);"
        FPRINT FP_OUTPUT, "    if (n == 0 || n >= MAX_PATH) _tcscpy(comspec, TEXT(" + ENC$("cmd.exe") + "));"
        FPRINT FP_OUTPUT, "    size_t len = _tcslen(Cmdline) + 4;"
        FPRINT FP_OUTPUT, "    shellArgs = (PTSTR)malloc((len + 1) * sizeof(TCHAR));"
        FPRINT FP_OUTPUT, "    if (!shellArgs) goto EXITRUN;"
        FPRINT FP_OUTPUT, "    _tcscpy(shellArgs, TEXT(" + ENC$(" /c ") + "));"
        FPRINT FP_OUTPUT, "    _tcscat(shellArgs, Cmdline);"
        FPRINT FP_OUTPUT, "    appName = comspec;"
        FPRINT FP_OUTPUT, "    cmdLineToRun = shellArgs;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (CreateProcess((PCTSTR)appName, (PTSTR)cmdLineToRun, NULL, NULL, TRUE,"
        FPRINT FP_OUTPUT, "                     NORMAL_PRIORITY_CLASS, NULL, NULL, &si, &pi))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (WaitState)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      do"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        dwState = MsgWaitForMultipleObjects(1, &pi.hProcess, FALSE, INFINITE, QS_ALLINPUT);"
        FPRINT FP_OUTPUT, "        if (dwState == (WAIT_OBJECT_0 + 1))"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))"
        FPRINT FP_OUTPUT, "          {"
        FPRINT FP_OUTPUT, "            if (msg.message == WM_QUIT) bQuitReceived = TRUE;"
        FPRINT FP_OUTPUT, "            TranslateMessage(&msg);"
        FPRINT FP_OUTPUT, "            DispatchMessage(&msg);"
        FPRINT FP_OUTPUT, "          }"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      } while ((dwState == (WAIT_OBJECT_0 + 1)) && !bQuitReceived);"
        FPRINT FP_OUTPUT, "      if (dwState == WAIT_OBJECT_0) fRet = 1;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      // Process launched successfully, don't wait"
        FPRINT FP_OUTPUT, "      fRet = 1;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    fRet = -1;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "EXITRUN:"
        FPRINT FP_OUTPUT, "  if (dynCmd)      free(dynCmd);"
        FPRINT FP_OUTPUT, "  if (shellArgs)   free(shellArgs);"
        FPRINT FP_OUTPUT, "  if (pi.hThread)  CloseHandle(pi.hThread);"
        FPRINT FP_OUTPUT, "  if (pi.hProcess) CloseHandle(pi.hProcess);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Only repost WM_QUIT if we actually received one"
        FPRINT FP_OUTPUT, "  if (bQuitReceived) PostQuitMessage(0);"
        FPRINT FP_OUTPUT, "  return fRet;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_PlayWav THEN
        FPRINT FP_OUTPUT, "void PlayWav (PCTSTR WavFileName, int rsid, int Sync)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!rsid)"
        FPRINT FP_OUTPUT, "    PlaySound(WavFileName, NULL, SND_FILENAME|SND_NODEFAULT|Sync);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    PSTR lpRes = (PSTR)GetResource(rsid, RT_RCDATA, 0);"
        FPRINT FP_OUTPUT, "    if (lpRes==NULL) return;"
        FPRINT FP_OUTPUT, "    PlaySound(lpRes, NULL, SND_MEMORY|SND_NODEFAULT|Sync);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Download THEN
        FPRINT FP_OUTPUT, "int Download (PCTSTR URL,PCTSTR Localname)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  DeleteUrlCacheEntryA(URL);"
        FPRINT FP_OUTPUT, "  if (URLDownloadToFile(NULL, URL, Localname, BINDF_GETNEWESTVERSION, NULL) == S_OK)"
        FPRINT FP_OUTPUT, "    return 1;"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_FirstInstance THEN
        FPRINT FP_OUTPUT, "static HANDLE g_hSingleInstanceMutex = NULL;\n\n"
        FPRINT FP_OUTPUT, "BOOL FindFirstInstance (PCTSTR Application)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char MutexName[BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  HWND hWnd;"
        FPRINT FP_OUTPUT, "  int  i;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  strcpy(MutexName, Application);"
        FPRINT FP_OUTPUT, "  strcat(MutexName, ", ENC$("_BCX_SingleInstance"), ");"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  g_hSingleInstanceMutex = CreateMutex(NULL, FALSE, MutexName);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (g_hSingleInstanceMutex == NULL)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    return FALSE;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (GetLastError() != ERROR_ALREADY_EXISTS)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    return FALSE;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  hWnd = FindWindow(Application, NULL);"
        FPRINT FP_OUTPUT, "  if (hWnd)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (IsIconic(hWnd))"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      ShowWindow(hWnd, SW_RESTORE);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    for (i = 0; i < 6 && GetForegroundWindow() != hWnd; i++)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      FlashWindow(hWnd, TRUE);"
        FPRINT FP_OUTPUT, "      Sleep(150);"
        FPRINT FP_OUTPUT, "      FlashWindow(hWnd, FALSE);"
        FPRINT FP_OUTPUT, "      Sleep(150);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    SetForegroundWindow(hWnd);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  CloseHandle(g_hSingleInstanceMutex);"
        FPRINT FP_OUTPUT, "  g_hSingleInstanceMutex = NULL;"
        FPRINT FP_OUTPUT, "  return TRUE;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_BCX_ToolTip THEN ' MS changed Balloon style to only work for single line tips
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, " LRESULT BCX_ToolTip(PCTSTR Text, HWND hWnd, int TTStyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    TOOLINFO tti={0};"
        FPRINT FP_OUTPUT, "    if (BCX_CreateToolTip(GetParent(hWnd), TTStyle) == 0)"
        FPRINT FP_OUTPUT, "        return 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    tti.cbSize = sizeof(tti);"
        FPRINT FP_OUTPUT, "    tti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;"
        FPRINT FP_OUTPUT, "    tti.hwnd = GetParent(hWnd);"
        FPRINT FP_OUTPUT, "    tti.uId = (INT_PTR)hWnd;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Remove existing tool if present"
        FPRINT FP_OUTPUT, "    if (SendMessage(BCX_hWnd_ToolTip, TTM_GETTOOLINFO, 0, (LPARAM)&tti))"
        FPRINT FP_OUTPUT, "        SendMessage(BCX_hWnd_ToolTip, TTM_DELTOOL, 0, (LPARAM)&tti);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Set up the tool info structure"
        FPRINT FP_OUTPUT, "    tti.lpszText = (PTSTR)Text;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Set the maximum width for the tooltip (adjust as needed)"
        FPRINT FP_OUTPUT, "    SendMessage(BCX_hWnd_ToolTip, TTM_SETMAXTIPWIDTH, 0, 300);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Add the tool"
        FPRINT FP_OUTPUT, "    return SendMessage(BCX_hWnd_ToolTip, TTM_ADDTOOL, 0, (LPARAM)&tti);"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, "HWND BCX_CreateToolTip(HWND hWnd, int TTStyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    ULONG TTType = 0;"
        FPRINT FP_OUTPUT, "    if (TTStyle == 0)"
        FPRINT FP_OUTPUT, "        TTType = TTS_ALWAYSTIP | TTS_BALLOON;  // Balloon tooltip"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "        TTType = TTS_ALWAYSTIP;  // Rectangular tooltip"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (BCX_hWnd_ToolTip == NULL)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "        if (hWnd == NULL)"
        FPRINT FP_OUTPUT, "            hWnd = GetActiveWindow();"
        FPRINT FP_OUTPUT, "        if (hWnd == NULL)"
        FPRINT FP_OUTPUT, "            return 0;"
        FPRINT FP_OUTPUT, "        BCX_hWnd_ToolTip = CreateWindowEx("
        FPRINT FP_OUTPUT, "            WS_EX_TOPMOST,"
        FPRINT FP_OUTPUT, "            TOOLTIPS_CLASS,"
        FPRINT FP_OUTPUT, "            NULL,"
        FPRINT FP_OUTPUT, "            WS_POPUP | TTType,"
        FPRINT FP_OUTPUT, "            CW_USEDEFAULT, CW_USEDEFAULT,"
        FPRINT FP_OUTPUT, "            CW_USEDEFAULT, CW_USEDEFAULT,"
        FPRINT FP_OUTPUT, "            hWnd,"
        FPRINT FP_OUTPUT, "            NULL,"
        FPRINT FP_OUTPUT, "            (HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE),"
        FPRINT FP_OUTPUT, "            NULL"
        FPRINT FP_OUTPUT, "        );\n\n"
        FPRINT FP_OUTPUT, "        // Enable multiline tooltips"
        FPRINT FP_OUTPUT, "        SetWindowPos(BCX_hWnd_ToolTip, HWND_TOPMOST, 0, 0, 0, 0, "
        FPRINT FP_OUTPUT, "                     SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);"
        FPRINT FP_OUTPUT, "        SendMessage(BCX_hWnd_ToolTip, TTM_SETDELAYTIME, TTDT_AUTOPOP, MAKELPARAM(32767, 0));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        // Retrieve desktop shortcut font (icon title font)"
        FPRINT FP_OUTPUT, "        LOGFONT lf={0};"
        FPRINT FP_OUTPUT, "        if (SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, 0))"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "            // Create font based on desktop shortcut font"
        FPRINT FP_OUTPUT, "            HFONT hFont = CreateFontIndirect(&lf);"
        FPRINT FP_OUTPUT, "            SendMessage(BCX_hWnd_ToolTip, WM_SETFONT, (WPARAM)hFont, TRUE);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    return BCX_hWnd_ToolTip;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_LeftStr THEN
        FPRINT FP_OUTPUT, "int LeftStr (PCTSTR Haystack, PCTSTR Needle, int Insensitive)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (0 == Insensitive)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (strcmp(left(Haystack, (int)strlen(Needle)), Needle)==0)"
        FPRINT FP_OUTPUT, "      return 1;"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "      return 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (strcmp(lcase(left(Haystack, (int)strlen(Needle))), lcase(Needle))==0)"
        FPRINT FP_OUTPUT, "    return 1;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_RightStr THEN
        FPRINT FP_OUTPUT, "int RightStr (PCTSTR Haystack, PCTSTR Needle, int Insensitive)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (0 == Insensitive)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (strcmp(right(Haystack, (int)strlen(Needle)), Needle) == 0)"
        FPRINT FP_OUTPUT, "      return 1;"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "      return 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (strcmp(lcase(right(Haystack,(int)strlen(Needle))), lcase(Needle))==0)"
        FPRINT FP_OUTPUT, "    return 1;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Infobox THEN
        FPRINT FP_OUTPUT, "void InfoBox(PCTSTR Title, PCTSTR xValue, int xSize, int ySize)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  PSTR Value = _strdup(xValue);"
        FPRINT FP_OUTPUT, "  if((int)strlen(Value)>32500) Value[32500] = 0;" ' Protect against edit control overrun
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  LPDLGITEMTEMPLATE lpdit;"
        FPRINT FP_OUTPUT, "  LPDLGTEMPLATE lpdt;"
        FPRINT FP_OUTPUT, "  HINSTANCE hInst;"
        FPRINT FP_OUTPUT, "  HGLOBAL hgbl;"
        FPRINT FP_OUTPUT, "  PWORD lpw;"
        FPRINT FP_OUTPUT, "  PWSTR lpwsz;"
        FPRINT FP_OUTPUT, "  int nchar;"
        FPRINT FP_OUTPUT, "  int ID_EDIT = 101;"
        FPRINT FP_OUTPUT, "  int ID_OKAY = 102;"
        FPRINT FP_OUTPUT, "  // *************************************"
        FPRINT FP_OUTPUT, "  hgbl=GlobalAlloc(GMEM_ZEROINIT, 0xFFFF);"
        FPRINT FP_OUTPUT, "  lpdt=(LPDLGTEMPLATE)GlobalLock(hgbl);"
        FPRINT FP_OUTPUT, "  // *************************************"
        FPRINT FP_OUTPUT, "  //  Create the InfoBox Window"
        FPRINT FP_OUTPUT, "  // *************************************"
        FPRINT FP_OUTPUT, "  lpdt->style = WS_VISIBLE|DS_NOFAILCREATE|WS_BORDER|DS_CENTER|DS_SETFONT;"
        FPRINT FP_OUTPUT, "  lpdt->cdit = 2;"
        FPRINT FP_OUTPUT, "  lpdt->cx = (SHORT)xSize;"
        FPRINT FP_OUTPUT, "  lpdt->cy = (SHORT)ySize + 10;"
        FPRINT FP_OUTPUT, "  lpw = (PWORD)(lpdt+1);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;"
        FPRINT FP_OUTPUT, "  lpwsz = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  nchar = MultiByteToWideChar(CP_ACP, 0, Title, -1, lpwsz, 2*(int)strlen(Title) + 1);"
        FPRINT FP_OUTPUT, "  lpw +=  nchar;"
        FPRINT FP_OUTPUT, "  *lpw++ = DEFAULT_PITCH;"
        FPRINT FP_OUTPUT, "  lpwsz = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  nchar = MultiByteToWideChar(CP_ACP, 0, ", ENC$("Courier"), ", -1, lpwsz, 15);"
        FPRINT FP_OUTPUT, "  lpw +=  nchar;"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  //  Create the OKAY button."
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  lpw   = lpwAlign(lpw);"
        FPRINT FP_OUTPUT, "  lpdit = (LPDLGITEMTEMPLATE)lpw;"
        FPRINT FP_OUTPUT, "  lpdit->x  = (SHORT)(xSize* 0.5)-24;"
        FPRINT FP_OUTPUT, "  lpdit->y  = (SHORT)ySize - 29;"
        FPRINT FP_OUTPUT, "  lpdit->cx = (SHORT)40;"
        FPRINT FP_OUTPUT, "  lpdit->cy = (SHORT)12;"
        FPRINT FP_OUTPUT, "  lpdit->id = (SHORT)ID_OKAY;"
        FPRINT FP_OUTPUT, "  lpdit->style = WS_CHILD|WS_VISIBLE|BS_DEFPUSHBUTTON|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  lpw = (PWORD)(lpdit+1);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0xFFFF;"
        FPRINT FP_OUTPUT, "  *lpw++ = 0x0080;"
        FPRINT FP_OUTPUT, "  lpwsz  = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  nchar  = MultiByteToWideChar(CP_ACP, 0, ", ENC$("Okay"), ", -1, lpwsz, 9);"
        FPRINT FP_OUTPUT, "  lpw +=  nchar;"
        FPRINT FP_OUTPUT, "  lpw = lpwAlign(lpw);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;"
        FPRINT FP_OUTPUT, "  // ************************************"
        FPRINT FP_OUTPUT, "  //  Create the Read-Only EDIT control"
        FPRINT FP_OUTPUT, "  // ************************************"
        FPRINT FP_OUTPUT, "  lpw   = (PWORD)lpwAlign(lpw);"
        FPRINT FP_OUTPUT, "  lpdit = (LPDLGITEMTEMPLATE)lpw;"
        FPRINT FP_OUTPUT, "  lpdit->x  =  4;"
        FPRINT FP_OUTPUT, "  lpdit->y  =  8;"
        FPRINT FP_OUTPUT, "  lpdit->cx = (SHORT)xSize-9;"
        FPRINT FP_OUTPUT, "  lpdit->cy = (SHORT)ySize-40;"
        FPRINT FP_OUTPUT, "  lpdit->id = (SHORT)ID_EDIT;"
        FPRINT FP_OUTPUT, "  lpdit->style = WS_VISIBLE|WS_VSCROLL|ES_AUTOHSCROLL|WS_CHILD|"
        FPRINT FP_OUTPUT, "                 ES_READONLY|ES_MULTILINE|ES_WANTRETURN|WS_HSCROLL;"
        FPRINT FP_OUTPUT, "  lpw    = (PWORD)(lpdit+1);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0xFFFF;"
        FPRINT FP_OUTPUT, "  *lpw++ = 0x0081;"
        FPRINT FP_OUTPUT, "  lpwsz  = (PWSTR)lpw;"
        FPRINT FP_OUTPUT, "  nchar  = MultiByteToWideChar(CP_ACP, 0, Value, -1, lpwsz, 2*(int)strlen(Value) + 1);"
        FPRINT FP_OUTPUT, "  lpw   += nchar;"
        FPRINT FP_OUTPUT, "  lpw    = lpwAlign(lpw);"
        FPRINT FP_OUTPUT, "  *lpw++ = 0;"
        FPRINT FP_OUTPUT, "  // ********************************"
        FPRINT FP_OUTPUT, "  GlobalUnlock(hgbl);"
        FPRINT FP_OUTPUT, "  hInst = (HINSTANCE)(LONG_PTR)GetWindowLongPtr(0, GWLP_HINSTANCE);"
        FPRINT FP_OUTPUT, "  DialogBoxIndirect (hInst, (LPDLGTEMPLATE)hgbl, GetActiveWindow(), (DLGPROC)CB_InfoBox);"
        FPRINT FP_OUTPUT, "  GlobalFree(hgbl);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "LRESULT CALLBACK CB_InfoBox(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  UNREFERENCED_PARAMETER(lParam);"
        FPRINT FP_OUTPUT, "  int ID_OKAY = 102;"
        FPRINT FP_OUTPUT, "  if (Msg == WM_INITDIALOG)"
        FPRINT FP_OUTPUT, "      return TRUE;\n"
        FPRINT FP_OUTPUT, "  if (Msg == WM_COMMAND && LOWORD(wParam) == ID_OKAY)"
        FPRINT FP_OUTPUT, "      EndDialog(hWnd, 0);\n"
        FPRINT FP_OUTPUT, "  if (Msg == WM_CLOSE)"
        FPRINT FP_OUTPUT, "      EndDialog(hWnd, 0);"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Inputbox OR Use_Infobox THEN
        FPRINT FP_OUTPUT, "PWORD lpwAlign(PWORD lpIn)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return (PWORD)((((uintptr_t)lpIn) + 3) & (~3));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_BCXMDialog THEN
        FPRINT FP_OUTPUT, "INT_PTR BCX_MDialog (DLGPROC DPro, PCTSTR title, HWND hWnd, int X, int Y, int W, int H, int Style, int Exstyle, PCTSTR fntface, int fsz)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  LPDLGTEMPLATE  lpdt;"
        FPRINT FP_OUTPUT, "  PWORD  lpw;"
        FPRINT FP_OUTPUT, "  PVOID tc = calloc(1024, 1);"
        FPRINT FP_OUTPUT, "  lpdt=(LPDLGTEMPLATE)tc;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    lpdt->style = WS_POPUP|WS_SYSMENU|DS_MODALFRAME|WS_CAPTION;"
        FPRINT FP_OUTPUT, "    if (fsz) lpdt->style = lpdt->style|DS_SETFONT;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    lpdt->style = Style;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  lpdt->dwExtendedStyle = Exstyle;"
        FPRINT FP_OUTPUT, "  lpdt->cdit = 0;"
        FPRINT FP_OUTPUT, "  lpdt->x  = X;  lpdt->y  = Y;"
        FPRINT FP_OUTPUT, "  lpdt->cx = W;  lpdt->cy = H;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  lpw=(PWORD)(lpdt+1);"
        FPRINT FP_OUTPUT, "  *lpw++=0; *lpw++=0;"
        FPRINT FP_OUTPUT, "  lpw += MultiByteToWideChar(CP_ACP, 0, title, -1, (PWSTR)lpw, 2*(int)strlen(title) + 1);"
        FPRINT FP_OUTPUT, "  if (fsz)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    *lpw++ = fsz;"
        FPRINT FP_OUTPUT, "    MultiByteToWideChar(CP_ACP, 0, fntface, -1, (PWSTR)lpw, 2*(int)strlen(fntface) + 1);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  INT_PTR ret = DialogBoxIndirect(BCX_hInstance, (LPDLGTEMPLATE)tc, hWnd, (DLGPROC)DPro);"
        FPRINT FP_OUTPUT, "  free(tc);"
        FPRINT FP_OUTPUT, "  tc = NULL;"
        FPRINT FP_OUTPUT, "  SetDialogScale(0, 1);  //restore previous scale"
        FPRINT FP_OUTPUT, "  return ret;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCXDialog THEN
        FPRINT FP_OUTPUT, "HWND BCX_Dialog (DLGPROC DPro, PCTSTR title, HWND hWnd, int X, int Y, int W, int H, int Style, int Exstyle, PCTSTR fntface, int fsz)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static HWND hdlgs[32];"
        FPRINT FP_OUTPUT, "  static DLGPROC dp[32];"
        FPRINT FP_OUTPUT, "  int ii=(-1), nxt=(-1);"
        FPRINT FP_OUTPUT, "  while (++ii <32 && dp[ii] != DPro)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (dp[ii]==0 && nxt==(-1)) nxt = ii;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (ii<32) // if < 32 then we have a match"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (IsWindow(hdlgs[ii])!=0) return 0;"
        FPRINT FP_OUTPUT, "    if (nxt==(-1)) nxt = ii;"
        FPRINT FP_OUTPUT, "    dp[ii]=0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  dp[nxt]=DPro;"
        FPRINT FP_OUTPUT, "  LPDLGTEMPLATE  lpdt;"
        FPRINT FP_OUTPUT, "  PWORD  lpw;"
        FPRINT FP_OUTPUT, "  PVOID tc = calloc(1024,1);"
        FPRINT FP_OUTPUT, "  lpdt=(LPDLGTEMPLATE)tc;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    lpdt->style = WS_POPUP|WS_BORDER|WS_SYSMENU|WS_VISIBLE|WS_CAPTION;"
        FPRINT FP_OUTPUT, "    if (fsz) lpdt->style = lpdt->style|DS_SETFONT;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    lpdt->style = Style;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  lpdt->dwExtendedStyle = Exstyle;"
        FPRINT FP_OUTPUT, "  lpdt->cdit = 0;"
        FPRINT FP_OUTPUT, "  lpdt->x = X;  lpdt->y =Y;"
        FPRINT FP_OUTPUT, "  lpdt->cx = W; lpdt->cy=H;"
        FPRINT FP_OUTPUT, "  lpw=(PWORD)(lpdt+1);"
        FPRINT FP_OUTPUT, "  *lpw++=0; *lpw++=0;"
        FPRINT FP_OUTPUT, "  lpw += MultiByteToWideChar(CP_ACP, 0, title, -1, (PWSTR)lpw, 2*(int)strlen(title)+1);"
        FPRINT FP_OUTPUT, "  if (fsz)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    *lpw++ = fsz;"
        FPRINT FP_OUTPUT, "    MultiByteToWideChar(CP_ACP, 0, fntface, -1, (PWSTR)lpw, 2*(int)strlen(fntface)+1);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  hdlgs[nxt]=CreateDialogIndirect(BCX_hInstance, (LPDLGTEMPLATE)tc, hWnd, (DLGPROC)DPro);"
        FPRINT FP_OUTPUT, "  free(tc);"
        FPRINT FP_OUTPUT, "  tc = NULL;"
        FPRINT FP_OUTPUT, "  SetDialogScale(0, 1);  //restore previous scale"
        FPRINT FP_OUTPUT, "  return hdlgs[nxt];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCXDialog OR Use_BCXMDialog OR Use_BCXDialogCommon THEN
        FPRINT FP_OUTPUT, "void SetDialogScale (HWND hdlg, BOOL Restor)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static float BaseX, BaseY;"
        FPRINT FP_OUTPUT, "  if (Restor && BaseX)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_ScaleX = BaseX;"
        FPRINT FP_OUTPUT, "    BCX_ScaleY = BaseY;"
        FPRINT FP_OUTPUT, "    BaseX = BaseY = 0;"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (!BaseX)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BaseX = BCX_ScaleX; BaseY = BCX_ScaleY;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  BaseX = BCX_ScaleX; BaseY = BCX_ScaleY;"
        FPRINT FP_OUTPUT, "  RECT rc = {0, 0, 4, 8};"
        FPRINT FP_OUTPUT, "  MapDialogRect (hdlg, &rc);"
        FPRINT FP_OUTPUT, "  BCX_ScaleX = (float)rc.right/4;"
        FPRINT FP_OUTPUT, "  BCX_ScaleY = (float)rc.bottom/8;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_GetDimension THEN
        FPRINT FP_OUTPUT, "int GetDimension (PCTSTR PROPNAME, HWND WINHANDLE, BOOL InPixel)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  RECT  rcc, rcp;"
        FPRINT FP_OUTPUT, "  int   SX, SY, CAPH, PIX;"
        FPRINT FP_OUTPUT, "  if (InPixel==TRUE)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    PIX = 1;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    PIX = 15;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  SX = (GetSystemMetrics(SM_CXSIZEFRAME))*PIX;"
        FPRINT FP_OUTPUT, "  SY = (GetSystemMetrics(SM_CYSIZEFRAME))*PIX;"
        FPRINT FP_OUTPUT, "  CAPH = (GetSystemMetrics(SM_CYCAPTION))*PIX;"
        FPRINT FP_OUTPUT, "  GetWindowRect(WINHANDLE, &rcc);"
        FPRINT FP_OUTPUT, "  GetWindowRect(GetParent(WINHANDLE), &rcp);"
        FPRINT FP_OUTPUT, "  if (_stricmp(PROPNAME,", ENC$("LEFT"), ")==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    return ((rcc.left-rcp.left)*PIX)-SX;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (_stricmp(PROPNAME,", ENC$("TOP"), ")==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    return ((rcc.top-rcp.top)*PIX)-CAPH-SY;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (_stricmp(PROPNAME,", ENC$("WIDTH"), ")==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    return (rcc.right-rcc.left)*PIX;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (_stricmp(PROPNAME,", ENC$("HEIGHT"), ")==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    return (rcc.bottom-rcc.top)*PIX;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_SetDimension THEN
        FPRINT FP_OUTPUT, "void SetDimension (PCTSTR PROPNAME, int PROPVAL, HWND WINHANDLE, BOOL InPixel)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  RECT  rcc, rcp;"
        FPRINT FP_OUTPUT, "  int   X, Y, W, H, SX, SY, CAPH, PIX;"
        FPRINT FP_OUTPUT, "  if (InPixel==TRUE)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    PIX = 1;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    PIX = 15;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  SX = (GetSystemMetrics(SM_CXSIZEFRAME))*PIX;"
        FPRINT FP_OUTPUT, "  SY = (GetSystemMetrics(SM_CYSIZEFRAME))*PIX;"
        FPRINT FP_OUTPUT, "  CAPH = (GetSystemMetrics(SM_CYCAPTION))*PIX;"
        FPRINT FP_OUTPUT, "  GetWindowRect(WINHANDLE, &rcc);"
        FPRINT FP_OUTPUT, "  GetWindowRect(GetParent(WINHANDLE), &rcp);"
        FPRINT FP_OUTPUT, "  X = ((rcc.left-rcp.left)*PIX)-SX;"
        FPRINT FP_OUTPUT, "  Y = ((rcc.top-rcp.top)*PIX)-CAPH-SY;"
        FPRINT FP_OUTPUT, "  W = (rcc.right-rcc.left)*PIX;"
        FPRINT FP_OUTPUT, "  H = (rcc.bottom-rcc.top)*PIX;"
        FPRINT FP_OUTPUT, "  if (_stricmp(PROPNAME,", ENC$("LEFT"), ")==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    X = PROPVAL;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else if (_stricmp(PROPNAME,", ENC$("TOP"), ")==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Y = PROPVAL;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else if (_stricmp(PROPNAME,", ENC$("WIDTH"), ")==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    W = PROPVAL;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else if (_stricmp(PROPNAME,", ENC$("HEIGHT"), ")==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    H = PROPVAL;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  MoveWindow(WINHANDLE, X/PIX, Y/PIX, W/PIX, H/PIX, TRUE);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_SplitConsole



SUB Emit_RT_Controls1 (FP_OUTPUT AS FILE)
    IF Use_Form THEN
        FPRINT FP_OUTPUT, "HWND BCX_Form (PCTSTR Caption, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    if (Style == (-1))"
        FPRINT FP_OUTPUT, "        Style = WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS;"
        FPRINT FP_OUTPUT, "    HWND A = CreateWindowEx(Exstyle, BCX_ClassName, Caption, Style, X * BCX_ScaleX, Y * BCX_ScaleY,"
        FPRINT FP_OUTPUT, "             BCX_ScaleX * (4 + W), BCX_ScaleY * (12 + H), NULL, (HMENU)(UINT_PTR)NULL, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    SendMessage(A, WM_SETFONT, (WPARAM)((BcxFont == 0) ? GetStockObject"
        FPRINT FP_OUTPUT, "               (DEFAULT_GUI_FONT) : BcxFont), (LPARAM) MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "    SetWindowPos(A, NULL, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);"
        FPRINT FP_OUTPUT, "    return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Setclientsize THEN
        FPRINT FP_OUTPUT, "void BCX_SetClientSize(HWND hwnd, int iWidth, int iHeight, float RatioX, float RatioY)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  RECT rc={0};"
        FPRINT FP_OUTPUT, "  RECT rcTemp={0};"
        FPRINT FP_OUTPUT, "  int cx, cy;"
        FPRINT FP_OUTPUT, "  HMENU hMenu = GetMenu(hwnd);"
        FPRINT FP_OUTPUT, "  LONG_PTR dwStyle = GetWindowLongPtr(hwnd, GWL_STYLE);"
        FPRINT FP_OUTPUT, "  SetRect(&rc, 0, 0, iWidth * RatioX, iHeight * RatioY);"
        FPRINT FP_OUTPUT, "  AdjustWindowRectEx(&rc, dwStyle, (hMenu != NULL), GetWindowLongPtr(hwnd, GWL_EXSTYLE));"
        FPRINT FP_OUTPUT, "  if (hMenu != NULL)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    rcTemp = rc;"
        FPRINT FP_OUTPUT, "    rcTemp.bottom = 0x7FFF;"
        FPRINT FP_OUTPUT, "    SendMessage(hwnd, (UINT_PTR) WM_NCCALCSIZE, (WPARAM) 0, (LPARAM) &rcTemp);"
        FPRINT FP_OUTPUT, "    rc.bottom += rcTemp.top;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if ((dwStyle & WS_HSCROLL) == WS_HSCROLL)"
        FPRINT FP_OUTPUT, "    rc.bottom = rc.bottom + GetSystemMetrics(SM_CYHSCROLL);"
        FPRINT FP_OUTPUT, "  if ((dwStyle & WS_VSCROLL) == WS_VSCROLL)"
        FPRINT FP_OUTPUT, "    rc.right = rc.right + GetSystemMetrics(SM_CXVSCROLL);"
        FPRINT FP_OUTPUT, "  cx = rc.right - rc.left;"
        FPRINT FP_OUTPUT, "  cy = rc.bottom - rc.top;"
        FPRINT FP_OUTPUT, "  SetWindowPos(hwnd, NULL, 0, 0, cx, cy, SWP_NOZORDER|SWP_NOMOVE|SWP_NOACTIVATE);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Get_Window_Width THEN
        FPRINT FP_OUTPUT, "int BCX_Get_Window_Width (HWND hWnd){"
        FPRINT FP_OUTPUT, "  RECT rect;"
        FPRINT FP_OUTPUT, "  GetClientRect(hWnd, &rect);"
        FPRINT FP_OUTPUT, "  return rect.right-rect.left;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Get_Window_Height THEN
        FPRINT FP_OUTPUT, "int BCX_Get_Window_Height (HWND hWnd){"
        FPRINT FP_OUTPUT, "  RECT rect;"
        FPRINT FP_OUTPUT, "  GetClientRect(hWnd, &rect);"
        FPRINT FP_OUTPUT, "  return rect.bottom-rect.top;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Status THEN
        FPRINT FP_OUTPUT, "HWND BCX_Status (PCTSTR Text, HWND hWnd, int ID, int numparts, int *parts) {"
        FPRINT FP_OUTPUT, "   HWND A = CreateWindow(STATUSCLASSNAME,0,WS_CHILD|WS_VISIBLE,0,0,0,0,hWnd,0,BCX_hInstance,0);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   int pts[] = {-1};"
        FPRINT FP_OUTPUT, "   if (!parts) parts = pts;"
        FPRINT FP_OUTPUT, "   SendMessage(A, (UINT_PTR)SB_SETPARTS, (WPARAM)numparts, (LPARAM)parts);"
        FPRINT FP_OUTPUT, "   return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Modstyle THEN
        FPRINT FP_OUTPUT, "BOOL ModStyle(HWND hWnd, LONG_PTR dwAdd, LONG_PTR dwRemove, BOOL bEx)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  SetLastError(0);"
        FPRINT FP_OUTPUT, "  LONG_PTR dwStyle = GetWindowLongPtr(hWnd, (bEx ? GWL_EXSTYLE:GWL_STYLE));"
        FPRINT FP_OUTPUT, "  LONG_PTR dwNewStyle = (dwStyle & (~dwRemove)) | dwAdd;"
        FPRINT FP_OUTPUT, "  SetWindowLongPtr(hWnd, (bEx ? GWL_EXSTYLE : GWL_STYLE), dwNewStyle);"
        FPRINT FP_OUTPUT, "  SetWindowPos(hWnd, NULL, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_FRAMECHANGED);"
        FPRINT FP_OUTPUT, "  return (0 == GetLastError());"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Button THEN
        FPRINT FP_OUTPUT, "HWND BCX_Button(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|WS_VISIBLE|BS_MULTILINE|BS_PUSHBUTTON|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  if (Exstyle == (-1))"
        FPRINT FP_OUTPUT, "    Exstyle = WS_EX_STATICEDGE;"
        FPRINT FP_OUTPUT, "  HWND A = CreateWindowEx(Exstyle,"; ENC$("button") ; ", Text, Style,"
        FPRINT FP_OUTPUT, "                          X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                          hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  if (W==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    SIZE *size = GetTextSize(Text, A);"
        FPRINT FP_OUTPUT, "    MoveWindow(A, X*BCX_ScaleX, Y*BCX_ScaleY, size->cx+28, size->cy+12, TRUE);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BmpButton THEN
        FPRINT FP_OUTPUT, "HWND BCX_BmpButton(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Res, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND A;"
        FPRINT FP_OUTPUT, "  HBITMAP hBmp;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_BITMAP;"
        FPRINT FP_OUTPUT, "  if (Exstyle==(-1))"
        FPRINT FP_OUTPUT, "    Exstyle = WS_EX_STATICEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("button"); ","; DDQ$; ",Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id,BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  if (!Res)"
        FPRINT FP_OUTPUT, "    hBmp = (HBITMAP)LoadImage(0, Text, IMAGE_BITMAP,"
        FPRINT FP_OUTPUT, "                              W*BCX_ScaleX, H*BCX_ScaleY, LR_LOADFROMFILE);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    hBmp = (HBITMAP)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(Res),"
        FPRINT FP_OUTPUT, "                              IMAGE_BITMAP, W*BCX_ScaleX, H*BCX_ScaleY, 0);"
        FPRINT FP_OUTPUT, "  if (!W && !H)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BITMAP B;"
        FPRINT FP_OUTPUT, "    GetObject(hBmp, sizeof(BITMAP), &B);"
        FPRINT FP_OUTPUT, "    SetWindowPos(A, 0, 0, 0, B.bmWidth, B.bmHeight, SWP_NOMOVE|SWP_FRAMECHANGED);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  SendMessage (A, (UINT_PTR)BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBmp);"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    ' ============================================================================
    ' BCX_SPLITBUTTON Runtime Implementation
    ' ============================================================================
    ' Internal helper: Find split button info by HWND
    ' ----------------------------------------------------------------------------
    IF Use_SplitButton THEN
        FPRINT FP_OUTPUT, "static BCX_SPLITBUTTONINFO* BCX_FindSplitButton(HWND hWnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  for (int i = 0; i < BCX_SplitButtonCount; i++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (BCX_SplitButtons[i].hWnd == hWnd)"
        FPRINT FP_OUTPUT, "      return &BCX_SplitButtons[i];"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return NULL;"
        FPRINT FP_OUTPUT, "}\n\n"

        ' ------------------------------------------------------------------------
        ' Internal helper: Find split button info by Control ID
        ' ------------------------------------------------------------------------

        FPRINT FP_OUTPUT, "static BCX_SPLITBUTTONINFO* BCX_FindSplitButtonByID(int nCtlID)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  for (int i = 0; i < BCX_SplitButtonCount; i++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (BCX_SplitButtons[i].nCtlID == nCtlID)"
        FPRINT FP_OUTPUT, "      return &BCX_SplitButtons[i];"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return NULL;"
        FPRINT FP_OUTPUT, "}\n\n"

        ' -----------------------------------------------------------------------------
        ' Parent window subclass procedure to intercept WM_NOTIFY and WM_COMMAND
        ' -----------------------------------------------------------------------------

        FPRINT FP_OUTPUT, "static LRESULT CALLBACK BCX_SplitButtonParentProc(HWND hWnd, UINT uMsg,"
        FPRINT FP_OUTPUT, "                                                   WPARAM wParam, LPARAM lParam,"
        FPRINT FP_OUTPUT, "                                                   UINT_PTR uIdSubclass, DWORD_PTR dwRefData)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (uMsg == WM_NOTIFY)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    LPNMHDR pnmh = (LPNMHDR)lParam;"
        FPRINT FP_OUTPUT, "    if (pnmh->code == BCN_DROPDOWN)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      BCX_SPLITBUTTONINFO *pInfo = BCX_FindSplitButtonByID((int)pnmh->idFrom);"
        FPRINT FP_OUTPUT, "      if (pInfo && pInfo->hPopupMenu)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        LPNMBCDROPDOWN pDropDown = (LPNMBCDROPDOWN)lParam;"
        FPRINT FP_OUTPUT, "        RECT rc;"
        FPRINT FP_OUTPUT, "        CopyRect(&rc, &pDropDown->rcButton);"
        FPRINT FP_OUTPUT, "        MapWindowPoints(pInfo->hWnd, HWND_DESKTOP, (LPPOINT)&rc, 2);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        SetForegroundWindow(hWnd);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        UINT nSelected = (UINT)TrackPopupMenu(pInfo->hPopupMenu,"
        FPRINT FP_OUTPUT, "                       TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,"
        FPRINT FP_OUTPUT, "                       rc.left, rc.bottom, 0, hWnd, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        // Verify this ID exists in the menu (handles cancel returning 0)"
        FPRINT FP_OUTPUT, "        MENUITEMINFO mii;"
        FPRINT FP_OUTPUT, "        ZeroMemory(&mii, sizeof(MENUITEMINFO));"
        FPRINT FP_OUTPUT, "        mii.cbSize = sizeof(MENUITEMINFO);"
        FPRINT FP_OUTPUT, "        mii.fMask = MIIM_STRING;"
        FPRINT FP_OUTPUT, "        mii.dwTypeData = NULL;"
        FPRINT FP_OUTPUT, "        mii.cch = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        if (GetMenuItemInfo(pInfo->hPopupMenu, nSelected, FALSE, &mii))"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          // Valid selection - get the label text"
        FPRINT FP_OUTPUT, "          TCHAR szLabel[256];"
        FPRINT FP_OUTPUT, "          mii.dwTypeData = szLabel;"
        FPRINT FP_OUTPUT, "          mii.cch = 256;"
        FPRINT FP_OUTPUT, "          if (GetMenuItemInfo(pInfo->hPopupMenu, nSelected, FALSE, &mii))"
        FPRINT FP_OUTPUT, "          {"
        FPRINT FP_OUTPUT, "            SetWindowText(pInfo->hWnd, szLabel);"
        FPRINT FP_OUTPUT, "          }"
        FPRINT FP_OUTPUT, "          // Update the control ID to the selected item's ID"
        FPRINT FP_OUTPUT, "          pInfo->nCtlID = nSelected;"
        FPRINT FP_OUTPUT, "          SetWindowLongPtr(pInfo->hWnd, GWLP_ID, (LONG_PTR)nSelected);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        return TRUE;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else if (uMsg == WM_NCDESTROY)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    RemoveWindowSubclass(hWnd, BCX_SplitButtonParentProc, uIdSubclass);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return DefSubclassProc(hWnd, uMsg, wParam, lParam);"
        FPRINT FP_OUTPUT, "}\n\n"

        ' ------------------------------------------------------------------------
        ' Internal helper: Add a Split Button Separator
        ' ------------------------------------------------------------------------

        FPRINT FP_OUTPUT, "void BCX_SplitButton_AddSeparator(HWND hSplitBtn)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  BCX_SPLITBUTTONINFO *pInfo = BCX_FindSplitButton(hSplitBtn);"
        FPRINT FP_OUTPUT, "  if (!pInfo) return;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Create popup menu if it doesn't exist"
        FPRINT FP_OUTPUT, "  if (!pInfo->hPopupMenu)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    pInfo->hPopupMenu = CreatePopupMenu();"
        FPRINT FP_OUTPUT, "    pInfo->nItemCount = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    MENUINFO mi;"
        FPRINT FP_OUTPUT, "    mi.cbSize = sizeof(MENUINFO);"
        FPRINT FP_OUTPUT, "    mi.fMask = MIM_STYLE | MIM_BACKGROUND;"
        FPRINT FP_OUTPUT, "    mi.dwStyle = MNS_NOCHECK;"
        FPRINT FP_OUTPUT, "    mi.hbrBack = GetSysColorBrush(COLOR_3DFACE);"
        FPRINT FP_OUTPUT, "    SetMenuInfo(pInfo->hPopupMenu, &mi);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Add the separator"
        FPRINT FP_OUTPUT, "  if (pInfo->nItemCount < BCX_MAX_SPLITBUTTON_ITEMS)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    InsertMenu(pInfo->hPopupMenu, -1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);"
        FPRINT FP_OUTPUT, "    pInfo->nItemCount++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"

        ' ---------------------------------------------------------------------
        ' BCX_SplitButton - Create a split button control
        ' ---------------------------------------------------------------------

        FPRINT FP_OUTPUT, "HWND BCX_SplitButton(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD | WS_VISIBLE | BS_SPLITBUTTON | WS_TABSTOP | BS_TEXT | BS_VCENTER;"
        FPRINT FP_OUTPUT, "  if (!Exstyle)"
        FPRINT FP_OUTPUT, "    Exstyle = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  HWND A = CreateWindowEx(Exstyle, TEXT("; ENC$("button"); "), Text, Style,"
        FPRINT FP_OUTPUT, "                          X * BCX_ScaleX, Y * BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                          W * BCX_ScaleX, H * BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                          hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (W == 0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    SIZE *size = GetTextSize(Text, A);"
        FPRINT FP_OUTPUT, "    MoveWindow(A, X * BCX_ScaleX, Y * BCX_ScaleY, size->cx + 48, size->cy + 12, TRUE);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Register this split button in our tracking array"
        FPRINT FP_OUTPUT, "  if (BCX_SplitButtonCount < BCX_MAX_SPLITBUTTONS)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_SPLITBUTTONINFO *pInfo = &BCX_SplitButtons[BCX_SplitButtonCount++];"
        FPRINT FP_OUTPUT, "    pInfo->hWnd = A;"
        FPRINT FP_OUTPUT, "    pInfo->nCtlID = id;"
        FPRINT FP_OUTPUT, "    pInfo->hPopupMenu = NULL;"
        FPRINT FP_OUTPUT, "    pInfo->nItemCount = 0;"
        FPRINT FP_OUTPUT, "    pInfo->lpfnOrigProc = NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Subclass the parent window to intercept WM_NOTIFY"
        FPRINT FP_OUTPUT, "    SetWindowSubclass(hWnd, BCX_SplitButtonParentProc, (UINT_PTR)id, 0);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"

        ' ---------------------------------------------------------------------
        ' BCX_SplitButton_SetItems - Assign menu items from an array
        ' ---------------------------------------------------------------------

        FPRINT FP_OUTPUT, "void BCX_SplitButton_SetItems(HWND hSplitBtn, BCX_SPLITBUTTONDATA *pItems, int nCount)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  BCX_SPLITBUTTONINFO *pInfo = BCX_FindSplitButton(hSplitBtn);"
        FPRINT FP_OUTPUT, "  if (!pInfo) return;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Destroy existing menu if any"
        FPRINT FP_OUTPUT, "  if (pInfo->hPopupMenu)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    DestroyMenu(pInfo->hPopupMenu);"
        FPRINT FP_OUTPUT, "    pInfo->hPopupMenu = NULL;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Create new popup menu"
        FPRINT FP_OUTPUT, "  pInfo->hPopupMenu = CreatePopupMenu();"
        FPRINT FP_OUTPUT, "  pInfo->nItemCount = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Configure menu style"
        FPRINT FP_OUTPUT, "  MENUINFO mi;"
        FPRINT FP_OUTPUT, "  mi.cbSize = sizeof(MENUINFO);"
        FPRINT FP_OUTPUT, "  mi.fMask = MIM_STYLE | MIM_BACKGROUND;"
        FPRINT FP_OUTPUT, "  mi.dwStyle = MNS_NOCHECK;"
        FPRINT FP_OUTPUT, "  mi.hbrBack = GetSysColorBrush(COLOR_3DFACE);"
        FPRINT FP_OUTPUT, "  SetMenuInfo(pInfo->hPopupMenu, &mi);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Add menu items"
        FPRINT FP_OUTPUT, "  for (int i = 0; i < nCount && i < BCX_MAX_SPLITBUTTON_ITEMS; i++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    InsertMenu(pInfo->hPopupMenu, -1, MF_BYPOSITION | MF_STRING,"
        FPRINT FP_OUTPUT, "               pItems[i].nID, pItems[i].szLabel);"
        FPRINT FP_OUTPUT, "    pInfo->nItemCount++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"

        ' ---------------------------------------------------------------------
        ' BCX_SplitButton_AddItem - Add a single menu item
        ' ---------------------------------------------------------------------

        FPRINT FP_OUTPUT, "void BCX_SplitButton_AddItem(HWND hSplitBtn, PCTSTR szLabel, int nID)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  BCX_SPLITBUTTONINFO *pInfo = BCX_FindSplitButton(hSplitBtn);"
        FPRINT FP_OUTPUT, "  if (!pInfo) return;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Create popup menu if it doesn't exist"
        FPRINT FP_OUTPUT, "  if (!pInfo->hPopupMenu)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    pInfo->hPopupMenu = CreatePopupMenu();"
        FPRINT FP_OUTPUT, "    pInfo->nItemCount = 0;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    MENUINFO mi;"
        FPRINT FP_OUTPUT, "    mi.cbSize = sizeof(MENUINFO);"
        FPRINT FP_OUTPUT, "    mi.fMask = MIM_STYLE | MIM_BACKGROUND;"
        FPRINT FP_OUTPUT, "    mi.dwStyle = MNS_NOCHECK;"
        FPRINT FP_OUTPUT, "    mi.hbrBack = GetSysColorBrush(COLOR_3DFACE);"
        FPRINT FP_OUTPUT, "    SetMenuInfo(pInfo->hPopupMenu, &mi);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Add the new item"
        FPRINT FP_OUTPUT, "  if (pInfo->nItemCount < BCX_MAX_SPLITBUTTON_ITEMS)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    InsertMenu(pInfo->hPopupMenu, -1, MF_BYPOSITION | MF_STRING, nID, szLabel);"
        FPRINT FP_OUTPUT, "    pInfo->nItemCount++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Edit THEN
        FPRINT FP_OUTPUT, "HWND BCX_Edit(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|WS_VISIBLE|ES_WANTRETURN|WS_TABSTOP|"
        FPRINT FP_OUTPUT, "            WS_VSCROLL|ES_MULTILINE|ES_AUTOVSCROLL|ES_AUTOHSCROLL;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (Exstyle==(-1))"
        FPRINT FP_OUTPUT, "    Exstyle = WS_EX_CLIENTEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("edit") ; ", Text, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Elf THEN
        FPRINT FP_OUTPUT, "void EditLoadFile (HWND hWnd, PCTSTR File)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  long FileLen;"
        FPRINT FP_OUTPUT, "  char *Buff;"
        FPRINT FP_OUTPUT, "  FILE *FP;"
        FPRINT FP_OUTPUT, "  if (!Exist(File))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    MessageBox (GetActiveWindow(), join(2,", ENC$("File Not Found:"), ",File), ", ENC$("Error!"), ",0);"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if ((FP = fopen(File,", ENC$("rb"), "))==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    MessageBox (GetActiveWindow(), join(2,", ENC$("Could not read file:"), ",File),", ENC$("Error!"), ",0);"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  FileLen = lof(File)+1;"
        FPRINT FP_OUTPUT, "  Buff=(char*)calloc(FileLen, sizeof(char));"
        FPRINT FP_OUTPUT, "  GET(FP, Buff, FileLen);"
        FPRINT FP_OUTPUT, "  fclose(FP);"
        FPRINT FP_OUTPUT, "  FP = NULL;"
        FPRINT FP_OUTPUT, "  SendMessage(hWnd, (UINT_PTR)WM_SETTEXT, (WPARAM)0, (LPARAM)Buff);"
        FPRINT FP_OUTPUT, "  if (Buff)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    free(Buff);"
        FPRINT FP_OUTPUT, "    Buff = NULL;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_ListBoxLoadFile THEN
        FPRINT FP_OUTPUT, "void ListBoxLoadFile (HWND hWnd, PCTSTR Arg_Astr, int apend, int scrol)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  FILE* fp;"
        FPRINT FP_OUTPUT, "  static int siz;"
        FPRINT FP_OUTPUT, "  int buflen;"
        FPRINT FP_OUTPUT, "  char Buff[2049];"
        FPRINT FP_OUTPUT, "  if ((fp = fopen(Arg_Astr,", ENC$("rb"), "))==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    MessageBox (GetActiveWindow(),", ENC$("File Not Found"), ",", ENC$("Error!"), ",0);"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (!apend)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    siz = 0;"
        FPRINT FP_OUTPUT, "    SendMessage(hWnd, LB_RESETCONTENT, 0, 0);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "   while(!EoF(fp))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    *Buff = 0;"
        FPRINT FP_OUTPUT, "    fgets(Buff, 2048, fp);"
        FPRINT FP_OUTPUT, "    Buff[strcspn(Buff, ", ENC$("\\r\\n"), ")] = 0;"      ' MrBcx  817 (added)
        FPRINT FP_OUTPUT, "    strcpy(Buff, trim(Buff));"
        FPRINT FP_OUTPUT, "    buflen = strlen(Buff);"
        FPRINT FP_OUTPUT, "    if (buflen>siz) siz = buflen;"
        FPRINT FP_OUTPUT, "    if (buflen)"
        FPRINT FP_OUTPUT, "      SendMessage(hWnd, (UINT_PTR)LB_ADDSTRING,  0, (LPARAM)Buff);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (scrol)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    buflen = 10+GetTextSize(stringx(siz, 65), hWnd)->cx;"
        FPRINT FP_OUTPUT, "    SendMessage(hWnd, (UINT_PTR)LB_SETHORIZONTALEXTENT, (WPARAM)buflen, 0);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (fp) fclose(fp);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_ComboBoxLoadFile THEN
        FPRINT FP_OUTPUT, "void ComboBoxLoadFile (HWND hWnd, PCTSTR Arg_Astr)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  FILE* fp;"
        FPRINT FP_OUTPUT, "  char Buff[2049];"
        FPRINT FP_OUTPUT, "  if ((fp = fopen(Arg_Astr,", ENC$("rb"), "))==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    MessageBox (GetActiveWindow(),", ENC$("File Not Found"), ",", ENC$("Error!"), ",0);"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  SendMessage (hWnd, CB_RESETCONTENT, 0, 0);"
        FPRINT FP_OUTPUT, "  while(!feof(fp))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    *Buff = 0;"
        FPRINT FP_OUTPUT, "    fgets(Buff, 2048, fp);"
        FPRINT FP_OUTPUT, "    Buff[strcspn(Buff, ", ENC$("\\r\\n"), ")] = 0;"          ' MrBcx  817 (added)
        FPRINT FP_OUTPUT, "    strcpy(Buff, trim(Buff));"
        FPRINT FP_OUTPUT, "    if (strlen(Buff))"
        FPRINT FP_OUTPUT, "      SendMessage(hWnd, (UINT_PTR)CB_ADDSTRING, (WPARAM)0, (LPARAM)Buff);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (fp) fclose(fp);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Input THEN
        FPRINT FP_OUTPUT, "HWND BCX_Input(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_LEFT|ES_AUTOHSCROLL;"
        FPRINT FP_OUTPUT, "  if (Exstyle==(-1))"
        FPRINT FP_OUTPUT, "    Exstyle = WS_EX_CLIENTEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("edit") ; ",Text, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Label THEN
        FPRINT FP_OUTPUT, "HWND BCX_Label(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|SS_NOTIFY|SS_LEFT|WS_VISIBLE;"
        FPRINT FP_OUTPUT, "  HWND A = CreateWindowEx(Exstyle,"; ENC$("static") ; ",Text, Style,"
        FPRINT FP_OUTPUT, "                          X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                          hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  if (W==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    SIZE* size = GetTextSize(Text, A);"
        FPRINT FP_OUTPUT, "    MoveWindow(A, X*BCX_ScaleX, Y*BCX_ScaleY, size->cx, size->cy, TRUE);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Group THEN
        FPRINT FP_OUTPUT, "HWND BCX_Group(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = BS_GROUPBOX|WS_CHILD|WS_VISIBLE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("button") ; ",Text, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Checkbox THEN
        FPRINT FP_OUTPUT, "HWND BCX_Checkbox(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("button") ; ",Text, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  if (W==0)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      SIZE *size = GetTextSize(Text, A);"
        FPRINT FP_OUTPUT, "      MoveWindow(A, X*BCX_ScaleX, Y*BCX_ScaleY, size->cx+28, size->cy, TRUE);"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Radio THEN
        FPRINT FP_OUTPUT, "HWND BCX_Radio(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = Style|WS_CHILD|WS_TABSTOP|WS_VISIBLE|BS_AUTORADIOBUTTON;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("button") ; ",Text, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  if (W==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    SIZE *size = GetTextSize(Text, A);"
        FPRINT FP_OUTPUT, "    MoveWindow(A, X*BCX_ScaleX, Y*BCX_ScaleY, size->cx+28, size->cy, TRUE);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Combobox THEN
        FPRINT FP_OUTPUT, "HWND BCX_Combobox(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|WS_VISIBLE|CBS_DROPDOWN|CBS_SORT|WS_VSCROLL|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  if (Exstyle == (-1))"
        FPRINT FP_OUTPUT, "    Exstyle = WS_EX_CLIENTEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("Combobox") ; ", NULL,"; "Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Listbox THEN
        FPRINT FP_OUTPUT, "HWND BCX_Listbox(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = LBS_STANDARD|WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  if (Exstyle == (-1))"
        FPRINT FP_OUTPUT, "    Exstyle = WS_EX_CLIENTEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("Listbox") ; ",NULL,"; "Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Treeview THEN
        FPRINT FP_OUTPUT, "HWND BCX_Treeview(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_VISIBLE|WS_CHILD|WS_TABSTOP|TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT;"
        FPRINT FP_OUTPUT, "  if (Exstyle == (-1))"
        FPRINT FP_OUTPUT, "    Exstyle = WS_EX_CLIENTEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle, WC_TREEVIEW, NULL, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Blackrect THEN
        FPRINT FP_OUTPUT, "HWND BCX_BlackRect(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|SS_NOTIFY|WS_VISIBLE|SS_BLACKRECT;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("static") ; ",NULL,"; "Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Whiterect THEN
        FPRINT FP_OUTPUT, "HWND BCX_WhiteRect(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "      Style = WS_CHILD|SS_NOTIFY|WS_VISIBLE|SS_WHITERECT;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("static") ; ",NULL,"; "Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Grayrect THEN
        FPRINT FP_OUTPUT, "HWND BCX_GrayRect(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|SS_NOTIFY|WS_VISIBLE|SS_GRAYRECT;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("static") ; ",NULL, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Datepick THEN
        FPRINT FP_OUTPUT, "HWND BCX_DatePick(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD|WS_TABSTOP|WS_VISIBLE|DTS_LONGDATEFORMAT;"
        FPRINT FP_OUTPUT, "  if (Exstyle == (-1))"
        FPRINT FP_OUTPUT, "    Exstyle = WS_EX_CLIENTEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,";
        FPRINT FP_OUTPUT, ENC$("SysDateTimePick32"); ", NULL, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Richedit THEN
        FPRINT FP_OUTPUT, "HWND BCX_RichEdit(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static HMODULE hMsftedit = NULL;"
        FPRINT FP_OUTPUT, "  if (!hMsftedit)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    hMsftedit = LoadLibrary(", ENC$("Msftedit.dll"), ");"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  HWND  A;"
        FPRINT FP_OUTPUT, "  if (!Style)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Style = WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | WS_VISIBLE |"
        FPRINT FP_OUTPUT, "            WS_HSCROLL | WS_VSCROLL | ES_MULTILINE |"
        FPRINT FP_OUTPUT, "            ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (Exstyle==(-1))   Exstyle = WS_EX_CLIENTEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,", ENC$("RichEdit50W"), ", NULL, Style,"
        FPRINT FP_OUTPUT, "                     X * BCX_ScaleX, Y * BCX_ScaleY, W * BCX_ScaleX, H * BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, EM_EXLIMITTEXT, 0, 0x7FFFFFFF); // Increase allowable size to 2 GB"
        FPRINT FP_OUTPUT, "  SetWindowRTFText(A, Text);"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "void SetWindowRTFText (HWND hWnd, PCTSTR Text)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  typedef struct _SETTEXTEX"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    UINT  codepage;"
        FPRINT FP_OUTPUT, "    ULONG flags;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  SETTEXTEX, *LPSETTEXTEX;"
        FPRINT FP_OUTPUT, "  SETTEXTEX  Rtb;"
        FPRINT FP_OUTPUT, "  Rtb.flags = 2; //ST_SELECTION;"
        FPRINT FP_OUTPUT, "  Rtb.codepage = CP_ACP;"
        FPRINT FP_OUTPUT, "  SendMessage(hWnd, (UINT_PTR)EM_SETTEXTEX, (WPARAM)&Rtb, (LPARAM)Text);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Bitmap THEN
        FPRINT FP_OUTPUT, "HWND BCX_Bitmap(PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Res, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND A;"
        FPRINT FP_OUTPUT, "  HBITMAP hBitmap = NULL;"
        FPRINT FP_OUTPUT, "  if (!Style) Style = WS_CLIPSIBLINGS|WS_CHILD|WS_VISIBLE|SS_BITMAP|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle, "; ENC$("static"); ", NULL, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY,W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (Res)"
        FPRINT FP_OUTPUT, "    hBitmap=(HBITMAP)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(Res), IMAGE_BITMAP,"
        FPRINT FP_OUTPUT, "                               W*BCX_ScaleX, H*BCX_ScaleY, LR_CREATEDIBSECTION);"
        FPRINT FP_OUTPUT, "  else if (Text != NULL)"
        FPRINT FP_OUTPUT, "     {"
        FPRINT FP_OUTPUT, "       if (*Text)"
        FPRINT FP_OUTPUT, "         hBitmap=(HBITMAP)LoadImage(0, Text, IMAGE_BITMAP, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                                    LR_LOADFROMFILE|LR_CREATEDIBSECTION);"
        FPRINT FP_OUTPUT, "     }"
        FPRINT FP_OUTPUT, "   if (hBitmap)"
        FPRINT FP_OUTPUT, "     SendMessage(A, (UINT_PTR)STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap);"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_OlePicture THEN
        FPRINT FP_OUTPUT, "HWND BCX_OlePicture (PCTSTR szFile, HWND hWnd, int id, int X, int Y, int W, int H, int Res, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND       A;"
        FPRINT FP_OUTPUT, "  HBITMAP    hBitmap;"
        FPRINT FP_OUTPUT, "  BITMAP     bm;"
        FPRINT FP_OUTPUT, "  ULONG      dwFileSize;"
        FPRINT FP_OUTPUT, "  ULONG      dwBytesRead;"
        FPRINT FP_OUTPUT, "  HANDLE     hFile;"
        FPRINT FP_OUTPUT, "  LPPICTURE  gpPicture;"
        FPRINT FP_OUTPUT, "  PVOID     lpPicData;"
        FPRINT FP_OUTPUT, "  PVOID     pvData;"
        FPRINT FP_OUTPUT, "  LPSTREAM   pstm;"
        FPRINT FP_OUTPUT, "  HGLOBAL    hGlobal;"
        FPRINT FP_OUTPUT, "  if (!Style) Style = WS_CHILD|WS_VISIBLE|WS_TABSTOP|SS_BITMAP;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,", ENC$("static"), ", NULL, Style, X*BCX_ScaleX, Y*BCX_ScaleY, 0, 0, hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (Res)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    lpPicData = GetResource(Res, RT_RCDATA, &dwFileSize);"
        FPRINT FP_OUTPUT, "    if (lpPicData==NULL) return 0;"
        FPRINT FP_OUTPUT, "    hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);"
        FPRINT FP_OUTPUT, "    pvData = GlobalLock(hGlobal);"
        FPRINT FP_OUTPUT, "    CopyMemory(pvData, lpPicData, dwFileSize);"
        FPRINT FP_OUTPUT, "    GlobalUnlock(hGlobal);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    hFile = CreateFile(szFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);"
        FPRINT FP_OUTPUT, "    dwFileSize = GetFileSize(hFile, NULL);"
        FPRINT FP_OUTPUT, "    if (dwFileSize==(-1))"
        FPRINT FP_OUTPUT, "      return NULL;"
        FPRINT FP_OUTPUT, "    hGlobal = GlobalAlloc(GMEM_MOVEABLE, dwFileSize);"
        FPRINT FP_OUTPUT, "    pvData = GlobalLock(hGlobal);"
        FPRINT FP_OUTPUT, "    ReadFile(hFile, pvData, dwFileSize, &dwBytesRead, NULL);"
        FPRINT FP_OUTPUT, "    GlobalUnlock(hGlobal);"
        FPRINT FP_OUTPUT, "    CloseHandle(hFile);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  CreateStreamOnHGlobal(hGlobal, TRUE, &pstm);"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  OleLoadPicture(pstm, 0, FALSE, &IID_IPicture, (PVOID*)&gpPicture);"
        FPRINT FP_OUTPUT, "  pstm->lpVtbl->Release(pstm);"
        FPRINT FP_OUTPUT, "  gpPicture->lpVtbl->get_Handle(gpPicture, (OLE_HANDLE*)&hBitmap);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  OleLoadPicture(pstm, 0, FALSE, IID_IPicture, (PVOID*)&gpPicture);"
        FPRINT FP_OUTPUT, "  pstm->Release();"
        FPRINT FP_OUTPUT, "  gpPicture->get_Handle((OLE_HANDLE*)&hBitmap);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  GetObject(hBitmap, sizeof(bm), &bm);"
        FPRINT FP_OUTPUT, "  SetWindowLongPtr(A, GWLP_USERDATA, (LONG_PTR)MAKELONG(bm.bmWidth, bm.bmHeight));"
        FPRINT FP_OUTPUT, "  hBitmap = (HBITMAP)CopyImage(hBitmap, IMAGE_BITMAP, W*BCX_ScaleX, H*BCX_ScaleY, 0);"
        FPRINT FP_OUTPUT, "  SendMessage(A, (UINT_PTR)STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap);"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  gpPicture->lpVtbl->Release(gpPicture);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  gpPicture->Release();"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Icon THEN
        FPRINT FP_OUTPUT, "HWND BCX_Icon (PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Res, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HICON hIcon;"
        FPRINT FP_OUTPUT, "  ULONG dwSize;"
        FPRINT FP_OUTPUT, "  PBYTE pBytes;"
        FPRINT FP_OUTPUT, "  if (!Style) Style = WS_CHILD|WS_VISIBLE|SS_ICON|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  HWND A = CreateWindowEx(Exstyle, "; ENC$("static"); ", NULL, Style,"
        FPRINT FP_OUTPUT, "                          X*BCX_ScaleX, Y*BCX_ScaleY, 0, 0,"
        FPRINT FP_OUTPUT, "                          hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (!Res)"
        FPRINT FP_OUTPUT, "    hIcon=(HICON)LoadImage(0, Text, IMAGE_ICON, W, H, LR_LOADFROMFILE);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    pBytes=(PBYTE)GetResource(Res, RT_ANICURSOR, &dwSize);"
        FPRINT FP_OUTPUT, "    if (pBytes==NULL)"
        FPRINT FP_OUTPUT, "      hIcon=(HICON)LoadImage(BCX_hInstance, MAKEINTRESOURCE(Res), IMAGE_ICON, W, H, 0);"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "      hIcon = CreateIconFromResourceEx(pBytes, dwSize, FALSE, 0x00030000, W, H, LR_DEFAULTCOLOR);"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "  SendMessage(A, (UINT_PTR)STM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIcon);"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_Controls1



SUB Emit_RT_Controls2 (FP_OUTPUT AS FILE)
    IF Use_Listview THEN
        FPRINT FP_OUTPUT, "HWND BCX_ListView (PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle, int Cols)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND A;"
        FPRINT FP_OUTPUT, "  LV_COLUMN Local_lvCol ="
        FPRINT FP_OUTPUT, "  { LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM, LVCFMT_LEFT, 65, ", DDQ$, ", 0, 0 };\n"
        FPRINT FP_OUTPUT, "  // Note: 0x241 = LVS_REPORT|LVS_SHAREIMAGELISTS|LVS_EDITLABELS"
        FPRINT FP_OUTPUT, "  if (!Style) Style = WS_CHILD|WS_TABSTOP|WS_VISIBLE|0x241|WS_BORDER;"
        FPRINT FP_OUTPUT, "  if (Exstyle==(-1)) Exstyle = WS_EX_CLIENTEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle," ; ENC$("SysListView32"); ", NULL, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  Style = LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT;"
        FPRINT FP_OUTPUT, "  SendMessage(A, (UINT_PTR)LVM_SETEXTENDEDLISTVIEWSTYLE, (WPARAM)0, (LPARAM)Style);"
        FPRINT FP_OUTPUT, "  for(; Local_lvCol.iSubItem<Cols; Local_lvCol.iSubItem += 1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    ListView_InsertColumn(A, 0, &Local_lvCol);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Control THEN
        FPRINT FP_OUTPUT, "HWND BCX_Control (PCTSTR Class, HWND hWnd, PCTSTR Caption, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND A;"
        FPRINT FP_OUTPUT, "  if (!Style) Style = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle, Class, Caption, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd, (HMENU)(UINT_PTR)id,  BCX_hInstance,  NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_ProgressBar THEN
        FPRINT FP_OUTPUT, "HWND BCX_ProgressBar (PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND A;"
        FPRINT FP_OUTPUT, "  if (!Style) Style = WS_CHILD|WS_VISIBLE|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  if (Exstyle==(-1)) Exstyle = WS_EX_CLIENTEDGE;"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle,"; ENC$("msctls_progress32") ; ",Text, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY, hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A, PBM_SETRANGE, 0, MAKELONG(0, 100));"
        FPRINT FP_OUTPUT, "  SendMessage(A, PBM_SETSTEP, 1, 0);"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_GetResource THEN
        FPRINT FP_OUTPUT, "PVOID GetResource (int Res, char *ResType, ULONG *ResSize)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HRSRC hRes;"
        FPRINT FP_OUTPUT, "  HMODULE hMod = GetModuleHandle(NULL);"
        FPRINT FP_OUTPUT, "  hRes = FindResource(hMod, MAKEINTRESOURCE(Res), ResType);"
        FPRINT FP_OUTPUT, "  if (hRes==NULL) return 0;"
        FPRINT FP_OUTPUT, "  if (ResSize) *ResSize = SizeofResource(hMod, hRes);"
        FPRINT FP_OUTPUT, "  return LockResource(LoadResource(hMod, hRes));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_GetTextSize THEN
        FPRINT FP_OUTPUT, "SIZE* GetTextSize (PCTSTR Text, HWND hWnd, HFONT fnt)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HDC  hdc = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  if (!fnt) fnt = (HFONT)SendMessage(hWnd, WM_GETFONT, 0, 0);"
        FPRINT FP_OUTPUT, "  HFONT sobj = (HFONT)SelectObject(hdc, fnt);"
        FPRINT FP_OUTPUT, "  static SIZE sz;"
        FPRINT FP_OUTPUT, "  GetTextExtentPoint32(hdc, (char*)Text, strlen(Text), &sz);"
        FPRINT FP_OUTPUT, "  SelectObject(hdc, sobj);"
        FPRINT FP_OUTPUT, "  ReleaseDC(hWnd, hdc);"
        FPRINT FP_OUTPUT, "  return (&sz);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Slider THEN
        FPRINT FP_OUTPUT, "HWND BCX_Slider (PCTSTR Text, HWND hWnd, int id, int X, int Y, int W, int H, int orient, int Style, int Exstyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND  A,B;"
        FPRINT FP_OUTPUT, "  if (Style==0||Style==TBS_VERT)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Style = Style|WS_CHILD|WS_VISIBLE|TBS_AUTOTICKS|WS_TABSTOP;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  A = CreateWindowEx(Exstyle, TRACKBAR_CLASS, Text, Style,"
        FPRINT FP_OUTPUT, "                     X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                     hWnd,(HMENU)(UINT_PTR)id, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (*Text==0) return A;"
        FPRINT FP_OUTPUT, "  SIZE*  size = GetTextSize(Text, 0, (HFONT)DefaultFont);"
        FPRINT FP_OUTPUT, "  size->cy += 4; size->cx += 4;"
        FPRINT FP_OUTPUT, "  if (orient==0||orient>3) {X = X+(W-size->cx) * 0.5; Y = Y+H+2;}" ' Bottom
        FPRINT FP_OUTPUT, "  if (orient==1) {X = X+(W-size->cx) * 0.5; Y = Y-size->cy;}"      ' Top
        FPRINT FP_OUTPUT, "  if (orient==2) {X = X-size->cx; Y = Y+(H-size->cy) * 0.5;}"      ' Left
        FPRINT FP_OUTPUT, "  if (orient==3) {X = X+W+4; Y = Y+(H-size->cy) * 0.5;}"           ' Right
        FPRINT FP_OUTPUT, "  B = BCX_Label(Text, hWnd, 0, X, Y, size->cx, size->cy, WS_CHILD|WS_VISIBLE|WS_TABSTOP|SS_CENTER);"
        FPRINT FP_OUTPUT, "  SetWindowLongPtr(A, GWLP_USERDATA, (LONG_PTR)B);"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Splitter THEN
        FPRINT FP_OUTPUT, "HWND BCX_Splitter (HWND hWnd, int id, int swsStyle, int splittype, int X, int Y, int W, int H)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  LPSPLITTERINFO  lpsiWndInfo;"
        FPRINT FP_OUTPUT, "  RECT  rParentRect;"
        FPRINT FP_OUTPUT, "  static  ATOM  Class;"
        FPRINT FP_OUTPUT, "  if (!Class)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    static WNDCLASS  wc;"
        FPRINT FP_OUTPUT, "    wc.style = CS_PARENTDC;"
        FPRINT FP_OUTPUT, "    wc.lpfnWndProc=(WNDPROC)SplitterWndProc;"
        FPRINT FP_OUTPUT, "    wc.cbClsExtra = 0;"
        FPRINT FP_OUTPUT, "    wc.cbWndExtra = 4;"
        FPRINT FP_OUTPUT, "    wc.hInstance = BCX_hInstance;"
        FPRINT FP_OUTPUT, "    wc.hIcon=(HICON)NULL;"
        FPRINT FP_OUTPUT, "    wc.hCursor=(HCURSOR)NULL;"
        FPRINT FP_OUTPUT, "    wc.hbrBackground=(HBRUSH)(COLOR_ACTIVEBORDER+1);"
        FPRINT FP_OUTPUT, "    wc.lpszMenuName = NULL;"
        FPRINT FP_OUTPUT, "    wc.lpszClassName="; ENC$("SplitterWndClass"); ";"
        FPRINT FP_OUTPUT, "    Class = RegisterClass(&wc);"
        FPRINT FP_OUTPUT, "    if (!Class) return 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  lpsiWndInfo=(LPSPLITTERINFO)GlobalAlloc(GPTR, sizeof(SPLITTERINFO));"
        FPRINT FP_OUTPUT, "  if (lpsiWndInfo==NULL) return NULL;"
        FPRINT FP_OUTPUT, "  lpsiWndInfo->swsStyle = swsStyle;"
        FPRINT FP_OUTPUT, "  lpsiWndInfo->splittype = splittype;"
        FPRINT FP_OUTPUT, "  lpsiWndInfo->percent = 50;"
        FPRINT FP_OUTPUT, "  if (swsStyle==HS_HORIZONTAL)"
        FPRINT FP_OUTPUT, "    lpsiWndInfo->hCursor = LoadCursor(NULL, IDC_SIZENS);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    lpsiWndInfo->hCursor = LoadCursor(NULL, IDC_SIZEWE);"
        FPRINT FP_OUTPUT, "  if (W==0||H==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    GetClientRect(hWnd, &rParentRect);"
        FPRINT FP_OUTPUT, "    X = Y = 0;"
        FPRINT FP_OUTPUT, "    W = rParentRect.right;"
        FPRINT FP_OUTPUT, "    H = rParentRect.bottom;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return CreateWindow ("; ENC$("SplitterWndClass"); ","; DDQ$; ", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,"
        FPRINT FP_OUTPUT, "                       X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY, hWnd, (HMENU)(UINT_PTR)id, BCX_hInstance, lpsiWndInfo);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "int  BCX_SetSplitPos (HWND hwnd, int nPercentPos, int nNewPos)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  LPSPLITTERINFO  lpsiInfo=(LPSPLITTERINFO)(LONG_PTR)GetWindowLongPtr(hwnd, GWLP_USERDATA);"
        FPRINT FP_OUTPUT, "  RECT  rcClient;"
        FPRINT FP_OUTPUT, "  int  nPosMax;"
        FPRINT FP_OUTPUT, "  int  vhExtent;"
        FPRINT FP_OUTPUT, "  if (NULL==lpsiInfo->hwPane1) lpsiInfo->hwPane1 = GetWindow(hwnd, GW_CHILD);"
        FPRINT FP_OUTPUT, "  if (NULL==lpsiInfo->hwPane2 && NULL!=lpsiInfo->hwPane1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    lpsiInfo->hwPane2 = GetWindow(lpsiInfo->hwPane1, GW_HWNDNEXT);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  GetClientRect(hwnd, &rcClient);"
        FPRINT FP_OUTPUT, "  if (lpsiInfo->swsStyle==HS_HORIZONTAL)"
        FPRINT FP_OUTPUT, "    vhExtent = rcClient.bottom;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    vhExtent = rcClient.right;"
        FPRINT FP_OUTPUT, "  if (!nNewPos)"
        FPRINT FP_OUTPUT, "    nNewPos=(vhExtent*nPercentPos)/100;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    nPercentPos = 0;"
        FPRINT FP_OUTPUT, "  if (nNewPos<(MIN_PANESIZE+SPLITBAR_SIZE))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    lpsiInfo->fMovingBar = FALSE;"
        FPRINT FP_OUTPUT, "    ReleaseCapture();"
        FPRINT FP_OUTPUT, "    nNewPos = MIN_PANESIZE+SPLITBAR_SIZE;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    nPosMax = vhExtent-(MIN_PANESIZE+SPLITBAR_SIZE);"
        FPRINT FP_OUTPUT, "    if (nNewPos>nPosMax)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      nNewPos = nPosMax;"
        FPRINT FP_OUTPUT, "      lpsiInfo->fMovingBar = FALSE;"
        FPRINT FP_OUTPUT, "      ReleaseCapture();"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (!nPercentPos)"
        FPRINT FP_OUTPUT, "    lpsiInfo->percent=(100*nNewPos)/vhExtent;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    lpsiInfo->percent = nPercentPos;"
        FPRINT FP_OUTPUT, "  if (lpsiInfo->fMovingBar && lpsiInfo->splittype) return nNewPos;"
        FPRINT FP_OUTPUT, "  // ============================================================="
        FPRINT FP_OUTPUT, "  //                       Redraw Splitter"
        FPRINT FP_OUTPUT, "  // ============================================================="
        FPRINT FP_OUTPUT, "  if (lpsiInfo->swsStyle==HS_HORIZONTAL)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (lpsiInfo->hwPane1)"
        FPRINT FP_OUTPUT, "      MoveWindow(lpsiInfo->hwPane1,0, 0, rcClient.right, nNewPos, TRUE);"
        FPRINT FP_OUTPUT, "    if (lpsiInfo->hwPane2)"
        FPRINT FP_OUTPUT, "      MoveWindow(lpsiInfo->hwPane2, 0, nNewPos+SPLITBAR_SIZE, rcClient.right, rcClient.bottom-(nNewPos+SPLITBAR_SIZE), TRUE);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (lpsiInfo->hwPane1)"
        FPRINT FP_OUTPUT, "      MoveWindow(lpsiInfo->hwPane1, 0, 0, nNewPos, rcClient.bottom, TRUE);"
        FPRINT FP_OUTPUT, "    if (lpsiInfo->hwPane2)"
        FPRINT FP_OUTPUT, "      MoveWindow(lpsiInfo->hwPane2, nNewPos+SPLITBAR_SIZE, 0, rcClient.right-(nNewPos+SPLITBAR_SIZE), rcClient.bottom, TRUE);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return nNewPos;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "LRESULT CALLBACK SplitterWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  LPSPLITTERINFO lpsiInfo=(LPSPLITTERINFO)(LONG_PTR)GetWindowLongPtr(hwnd,GWLP_USERDATA);"
        FPRINT FP_OUTPUT, "  static RECT rrc;"
        FPRINT FP_OUTPUT, "  static BOOL neederase;"
        FPRINT FP_OUTPUT, "  int temppos;\n"
        FPRINT FP_OUTPUT, "  for(;;)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (msg==WM_CREATE)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      LPCREATESTRUCT  lpCreateStruct=(LPCREATESTRUCT)lParam;"
        FPRINT FP_OUTPUT, "      SetWindowLongPtr (hwnd, GWLP_USERDATA, (LONG_PTR)lpCreateStruct->lpCreateParams);"
        FPRINT FP_OUTPUT, "      break;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (msg==WM_SIZE)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (wParam!=SIZE_MINIMIZED) BCX_SetSplitPos(hwnd, lpsiInfo->percent);"
        FPRINT FP_OUTPUT, "      break;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (msg==WM_LBUTTONDOWN)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      lpsiInfo->fMovingBar = TRUE;"
        FPRINT FP_OUTPUT, "      SetCursor(lpsiInfo->hCursor);"
        FPRINT FP_OUTPUT, "      SetCapture(hwnd);"
        FPRINT FP_OUTPUT, "      if (lpsiInfo->splittype)"
        FPRINT FP_OUTPUT, "        GetClientRect(hwnd, &rrc);"
        FPRINT FP_OUTPUT, "      break;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (msg==WM_LBUTTONUP)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (lpsiInfo->fMovingBar)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        lpsiInfo->fMovingBar = FALSE;"
        FPRINT FP_OUTPUT, "        ReleaseCapture();"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      if (lpsiInfo->splittype)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        if (neederase) // Don't redraw(erase) if we never moved the bar"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          DrawXorBar(hwnd, 0);"
        FPRINT FP_OUTPUT, "          neederase = FALSE;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        BCX_SetSplitPos(hwnd, lpsiInfo->percent);"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      break;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (msg==WM_MOUSEMOVE)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (lpsiInfo->fMovingBar)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        if (lpsiInfo->swsStyle==HS_HORIZONTAL)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          temppos = BCX_SetSplitPos(hwnd, 0, HIWORD(lParam));"
        FPRINT FP_OUTPUT, "          rrc.top = temppos-2;"
        FPRINT FP_OUTPUT, "          rrc.bottom = temppos+2;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        else"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          temppos = BCX_SetSplitPos(hwnd, 0, LOWORD(lParam));"
        FPRINT FP_OUTPUT, "          rrc.left = temppos-2;"
        FPRINT FP_OUTPUT, "          rrc.right = temppos+2;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (lpsiInfo->splittype && lpsiInfo->fMovingBar)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          if (neederase) DrawXorBar(hwnd, 0);"
        FPRINT FP_OUTPUT, "          DrawXorBar(hwnd, &rrc);"
        FPRINT FP_OUTPUT, "          neederase = TRUE;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      else"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        SetCursor(lpsiInfo->hCursor);"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      break;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (msg==WM_COMMAND || msg==WM_NOTIFY || msg==WM_HSCROLL || msg==WM_VSCROLL || msg==WM_CTLCOLOREDIT ||"
        FPRINT FP_OUTPUT, "        msg==WM_CTLCOLORSTATIC || msg==WM_CTLCOLORBTN || msg==WM_CTLCOLORLISTBOX ||msg==WM_CTLCOLORSCROLLBAR ||"
        FPRINT FP_OUTPUT, "        msg==WM_MEASUREITEM || msg==WM_CONTEXTMENU  || msg==WM_DRAWITEM)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      return SendMessage(GetParent(hwnd), (UINT_PTR)msg, (WPARAM)wParam, (LPARAM)lParam);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (msg==WM_DESTROY)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      GlobalFree(lpsiInfo);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    break;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return DefWindowProc(hwnd, msg, wParam, lParam);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void DrawXorBar (HWND hWnd, RECT *rc)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static RECT R;"
        FPRINT FP_OUTPUT, "  HBITMAP hbm;"
        FPRINT FP_OUTPUT, "  HBRUSH  hbr, hbrushOld;"
        FPRINT FP_OUTPUT, "  WORD dotPatternBmp[] = { 170, 85, 170, 85, 170, 85, 170, 85 };"
        FPRINT FP_OUTPUT, "  HDC hdc = GetDCEx(hWnd, 0, DCX_PARENTCLIP);"
        FPRINT FP_OUTPUT, "  SetTextColor(hdc, SplitBarFG ^ RGB(255, 255, 255));"
        FPRINT FP_OUTPUT, "  SetBkColor  (hdc, SplitBarBG ^ RGB(255, 255, 255));"
        FPRINT FP_OUTPUT, "  hbm = CreateBitmap(8, 8, 1, 1, dotPatternBmp);"
        FPRINT FP_OUTPUT, "  hbr = CreatePatternBrush(hbm);"
        FPRINT FP_OUTPUT, "  if (rc) CopyRect(&R, rc);"
        FPRINT FP_OUTPUT, "  SetBrushOrgEx(hdc, R.left, R.top, 0);"
        FPRINT FP_OUTPUT, "  hbrushOld = (HBRUSH)SelectObject(hdc, hbr);"
        FPRINT FP_OUTPUT, "  PatBlt(hdc, R.left, R.top, R.right-R.left, R.bottom-R.top, PATINVERT);"
        FPRINT FP_OUTPUT, "  SelectObject(hdc, hbrushOld);"
        FPRINT FP_OUTPUT, "  DeleteObject(hbr);"
        FPRINT FP_OUTPUT, "  DeleteObject(hbm);"
        FPRINT FP_OUTPUT, "  ReleaseDC(hWnd,hdc);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Tab THEN
        FPRINT FP_OUTPUT, "HWND BCX_Tab (HWND hWnd, int id, int NumTabs, HWND *htab,char Names[][BCXSTRSIZE], int X, int Y, int W, int H, HIMAGELIST image, int Style, int StyleEx)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int    ii;"
        FPRINT FP_OUTPUT, "  static WNDCLASSEX twcx;"
        FPRINT FP_OUTPUT, "  static ATOM Class;"
        FPRINT FP_OUTPUT, "  if (!Class)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    // Register the Tab page holder windows... "
        FPRINT FP_OUTPUT, "    twcx.cbSize = sizeof(twcx);"
        FPRINT FP_OUTPUT, "    twcx.style = CS_PARENTDC;"
        FPRINT FP_OUTPUT, "    twcx.lpfnWndProc = (WNDPROC)TabPageWndProc;"
        FPRINT FP_OUTPUT, "    twcx.cbClsExtra = 0;"
        FPRINT FP_OUTPUT, "    twcx.cbWndExtra = 4;"
        FPRINT FP_OUTPUT, "    twcx.hInstance = BCX_hInstance;"
        FPRINT FP_OUTPUT, "    twcx.hIcon = NULL;"
        FPRINT FP_OUTPUT, "    twcx.hCursor = LoadCursor(NULL, IDC_ARROW);"
        FPRINT FP_OUTPUT, "    twcx.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);"
        FPRINT FP_OUTPUT, "    twcx.lpszMenuName = NULL;"
        FPRINT FP_OUTPUT, "    twcx.lpszClassName =", ENC$("TABPAGEHOLDER"), ";"
        FPRINT FP_OUTPUT, "    twcx.hIconSm = NULL;"
        FPRINT FP_OUTPUT, "    Class = RegisterClassEx(&twcx);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  // SubClass tab control parent so we can intercept WM_NOTIFY msgs used to switch pages"
        FPRINT FP_OUTPUT, "  if (id>=0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (GetProp(hWnd,", ENC$("Wprc"), ")==NULL)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      SetProp(hWnd,", ENC$("Wprc"), ", (HANDLE)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_WNDPROC));"
        FPRINT FP_OUTPUT, "      SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)TabCallback);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (!Style) Style = WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_CLIPSIBLINGS |"
        FPRINT FP_OUTPUT, "                        TCS_TABS|TCS_SINGLELINE|TCS_FOCUSONBUTTONDOWN;"
        FPRINT FP_OUTPUT, "  HWND hMainTab = CreateWindowEx(StyleEx,", ENC$("SysTabControl32"), ",", DDQ$, ",Style,"
        FPRINT FP_OUTPUT, "                                 X*BCX_ScaleX, Y*BCX_ScaleY, W*BCX_ScaleX, H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                                 hWnd, (HMENU)(UINT_PTR)abs(id), BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (hMainTab == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(hMainTab, WM_SETFONT, (WPARAM)DefaultFont, (LPARAM)MAKELPARAM(FALSE, 0));"
        FPRINT FP_OUTPUT, "  SetWindowLongPtr(hMainTab, GWLP_USERDATA, (LONG_PTR)htab);"
        FPRINT FP_OUTPUT, "  SetProp(hMainTab,", ENC$("TabSzWprc"), ",(HANDLE)(LONG_PTR)GetWindowLongPtr(hMainTab, GWLP_WNDPROC));"
        FPRINT FP_OUTPUT, "  SetWindowLongPtr(hMainTab, GWLP_WNDPROC,(LONG_PTR)TabSizeCallback);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  // Insert tabs in the tab control..."
        FPRINT FP_OUTPUT, "  for(ii = 0; ii<NumTabs; ii += 1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_AddTab (hMainTab, ii, Names[ii], (image != NULL ? ii : -1), 1);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (image) TabCtrl_SetImageList(hMainTab, image);"
        FPRINT FP_OUTPUT, "  SendMessage(hMainTab, (UINT_PTR)WM_SIZE, (WPARAM)SIZE_RESTORED, 0);"
        FPRINT FP_OUTPUT, "  TabCtrl_SetCurSel(hMainTab, 0);"
        FPRINT FP_OUTPUT, "  ShowWindow(htab[0], SW_SHOW);"
        FPRINT FP_OUTPUT, "  return hMainTab;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "HWND BCX_AddTab (HWND thwnd, int idx, PCTSTR text, int Imgidx, int showhide)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  TC_ITEM  tc;"
        FPRINT FP_OUTPUT, "  int      ii;"
        FPRINT FP_OUTPUT, "  int      cnt = TabCtrl_GetItemCount(thwnd);"
        FPRINT FP_OUTPUT, "  HWND     *ptab = (HWND*)(LONG_PTR)GetWindowLongPtr(thwnd, GWLP_USERDATA);"
        FPRINT FP_OUTPUT, "  tc.mask = TCIF_TEXT|TCIF_IMAGE;"
        FPRINT FP_OUTPUT, "  tc.pszText = (char*)text;"
        FPRINT FP_OUTPUT, "  tc.iImage = Imgidx;"
        FPRINT FP_OUTPUT, "  TabCtrl_InsertItem(thwnd, idx, &tc);"
        FPRINT FP_OUTPUT, "  for(ii = cnt; ii>idx; ii += (-1))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    ptab[ii] = ptab[ii-1];"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  ptab[idx] = CreateWindowEx(WS_EX_CONTROLPARENT, ", ENC$("TABPAGEHOLDER"), ",", ENC$(""), ", WS_CHILD | WS_CLIPCHILDREN, 0, 0, 10, 10, GetParent(thwnd), (HMENU)(UINT_PTR)0, BCX_hInstance, NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (ptab[idx] == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SetWindowPos(ptab[idx], HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);"
        FPRINT FP_OUTPUT, "  if (showhide==0)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    ShowWindow(ptab[TabCtrl_GetCurSel(thwnd)], SW_HIDE);"
        FPRINT FP_OUTPUT, "    SendMessage(thwnd, (UINT_PTR)WM_SIZE, (WPARAM)SIZE_RESTORED, 0);"
        FPRINT FP_OUTPUT, "    TabCtrl_SetCurSel(thwnd, idx);"
        FPRINT FP_OUTPUT, "    ShowWindow(ptab[idx], SW_SHOW);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return ptab[idx];"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "LRESULT CALLBACK TabSizeCallback(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  WNDPROC old = (WNDPROC)GetProp(hWnd,(PCSTR)", ENC$("TabSzWprc"), ");"
        FPRINT FP_OUTPUT, "  if (Msg==WM_SIZE && wParam != SIZE_MINIMIZED)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    HWND *ptab = (HWND*)(LONG_PTR)GetWindowLongPtr(hWnd, GWLP_USERDATA);"
        FPRINT FP_OUTPUT, "    RECT  rc2, rc1 = {0,0 , 0, 0};"
        FPRINT FP_OUTPUT, "    TabCtrl_AdjustRect(hWnd,TRUE, &rc1);"
        FPRINT FP_OUTPUT, "    GetClientRect(hWnd, &rc2);"
        FPRINT FP_OUTPUT, "    MapWindowPoints(hWnd, GetParent(hWnd), (LPPOINT)&rc2, 2);"
        FPRINT FP_OUTPUT, "    rc1.top =  -rc1.top; rc1.bottom = -rc1.bottom;"
        FPRINT FP_OUTPUT, "    rc1.left = -rc1.left; rc1.right = -rc1.right;"
        FPRINT FP_OUTPUT, "    int page;"
        FPRINT FP_OUTPUT, "    for(page = 0; page <= TabCtrl_GetItemCount(hWnd)-1; page += 1)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      MoveWindow(ptab[page], rc2.left + rc1.left, rc2.top + rc1.top,"
        FPRINT FP_OUTPUT, "                 rc1.right - rc1.left + (rc2.right - rc2.left), rc1.bottom - rc1.top + (rc2.bottom - rc2.top), TRUE);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else if (Msg == WM_DESTROY)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    SetWindowLongPtr(hWnd, GWLP_WNDPROC, (LONG_PTR)RemoveProp(hWnd, ", ENC$("TabSzWprc"), "));"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return CallWindowProc(old, hWnd, Msg, wParam, lParam);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "\n#ifndef WM_MOUSEWHEEL"
        FPRINT FP_OUTPUT, "    #define WM_MOUSEWHEEL 0x020A"
        FPRINT FP_OUTPUT, "#endif\n"

        FPRINT FP_OUTPUT, "LRESULT CALLBACK TabPageWndProc (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (Msg==WM_COMMAND||Msg==WM_NOTIFY||Msg==WM_HSCROLL||Msg==WM_VSCROLL||Msg==WM_CTLCOLOREDIT||"
        FPRINT FP_OUTPUT, "      Msg==WM_CTLCOLORSTATIC||Msg==WM_CTLCOLORBTN||Msg==WM_CTLCOLORLISTBOX||Msg==WM_CTLCOLORSCROLLBAR||"
        FPRINT FP_OUTPUT, "      Msg==WM_DRAWITEM||Msg==WM_MEASUREITEM||Msg==WM_MOUSEWHEEL||Msg==WM_GETFONT)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    return SendMessage(GetParent(hWnd),(UINT_PTR)Msg,(WPARAM)wParam,(LPARAM)lParam);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return DefWindowProc(hWnd,Msg,wParam,lParam);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "int BCX_TabSelect (HWND hWnd, LPARAM lParam)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int PageNo=(-1);"
        FPRINT FP_OUTPUT, "  NMHDR*   ptnmhdr = (NMHDR*) lParam;"
        FPRINT FP_OUTPUT, "  HWND *ptab=(HWND*)(LONG_PTR)GetWindowLongPtr(ptnmhdr->hwndFrom,GWLP_USERDATA);"
        FPRINT FP_OUTPUT, "  if (ptab)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (ptnmhdr->code==TCN_SELCHANGING)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      PageNo = TabCtrl_GetCurSel(ptnmhdr->hwndFrom);"
        FPRINT FP_OUTPUT, "      if (PageNo!=(-1))"
        FPRINT FP_OUTPUT, "        ShowWindow(ptab[PageNo],SW_HIDE);"
        FPRINT FP_OUTPUT, "      PageNo += 0xffff;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else if (ptnmhdr->code==TCN_SELCHANGE)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      PageNo = TabCtrl_GetCurSel(ptnmhdr->hwndFrom);"
        FPRINT FP_OUTPUT, "      if (PageNo!=(-1))"
        FPRINT FP_OUTPUT, "        ShowWindow(ptab[PageNo],SW_SHOW);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return PageNo;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "LRESULT CALLBACK TabCallback (HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  WNDPROC old=(WNDPROC)GetProp(hWnd,(PCSTR)", ENC$("Wprc"), ");"
        FPRINT FP_OUTPUT, "  if (Msg==WM_DESTROY)"
        FPRINT FP_OUTPUT, "    SetWindowLongPtr(hWnd,GWLP_WNDPROC,(LONG_PTR)RemoveProp(hWnd,", ENC$("Wprc"), "));"
        FPRINT FP_OUTPUT, "  else if (Msg==WM_NOTIFY)"
        FPRINT FP_OUTPUT, "    BCX_TabSelect(hWnd,lParam);"
        FPRINT FP_OUTPUT, "  return CallWindowProc(old,hWnd,Msg,wParam,lParam);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void BCX_RemTab (HWND thwnd, int idx)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int cur, cnt;"
        FPRINT FP_OUTPUT, "  HWND*  ptab = (HWND*)(LONG_PTR)GetWindowLongPtr(thwnd,GWLP_USERDATA);"
        FPRINT FP_OUTPUT, "  cnt = TabCtrl_GetItemCount(thwnd)-1;"
        FPRINT FP_OUTPUT, "  if (cnt<0||idx>cnt) return;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  if (TabCtrl_GetCurSel(thwnd)==idx)"
        FPRINT FP_OUTPUT, "    TabCtrl_SetCurFocus(thwnd,(cnt>idx?idx+1:idx-1));"
        FPRINT FP_OUTPUT, "  TabCtrl_DeleteItem(thwnd,idx);"
        FPRINT FP_OUTPUT, "  DestroyWindow(ptab[idx]);"
        FPRINT FP_OUTPUT, "  for(cur = idx; cur<cnt; cur += 1)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    ptab[cur] = ptab[cur+1];"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  ptab[cnt] = NULL;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Toolbar THEN
        FPRINT FP_OUTPUT, "HWND BCX_Toolbar (HWND hWnd,int id,int NumBtns,PCTSTR Text,int* Bstyles,void* img,int* imgidx,int bx,int by,int Style,int ExStyle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  TBBUTTON*  tbb = (TBBUTTON*)calloc(NumBtns+20,sizeof(TBBUTTON));"
        FPRINT FP_OUTPUT, "  TBADDBITMAP  tbbitmap = {0,0};"
        FPRINT FP_OUTPUT, "  static  BITMAP  bm;"
        FPRINT FP_OUTPUT, "  int  seppos = 0, absidx = 0, index = 0;"
        FPRINT FP_OUTPUT, "  int  txtlen = strlen(Text);"
        FPRINT FP_OUTPUT, "  if(!Style) Style = WS_CHILD|WS_BORDER;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  HWND A = CreateWindowEx(ExStyle,TOOLBARCLASSNAME,", DDQ$, ",Style|TBSTYLE_FLAT|CCS_NODIVIDER,0,0,0,0,hWnd,(HMENU)(UINT_PTR)id,BCX_hInstance,NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "   if (A == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(A,(UINT_PTR)TB_BUTTONSTRUCTSIZE,(WPARAM)sizeof(TBBUTTON),(LPARAM)0);"
        FPRINT FP_OUTPUT, "  SendMessage(A,WM_SETFONT,(WPARAM)DefaultFont,(LPARAM)0);"
        FPRINT FP_OUTPUT, "  if(bx&&by) SendMessage(A,(UINT_PTR)TB_SETBUTTONSIZE,(WPARAM)0,(LPARAM)MAKELONG(bx,by));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  while(absidx<NumBtns)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "     while(txtlen)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        if (Text[seppos]=='|') break;"
        FPRINT FP_OUTPUT, "        if(!seppos||seppos==txtlen) {seppos=0; break;}"
        FPRINT FP_OUTPUT, "        seppos++;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      if(Text[seppos]=='|'&&Text[seppos+1]=='|')"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "          tbb[index].fsStyle = TBSTYLE_SEP;"
        FPRINT FP_OUTPUT, "       }else{"
        FPRINT FP_OUTPUT, "          if(imgidx)"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "              tbb[index].iBitmap = imgidx[absidx];"
        FPRINT FP_OUTPUT, "           }else{"
        FPRINT FP_OUTPUT, "              tbb[index].iBitmap = absidx;"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "          tbb[index].idCommand = id+absidx+1;"
        FPRINT FP_OUTPUT, "          tbb[index].fsState = TBSTATE_ENABLED;"
        FPRINT FP_OUTPUT, "          if(Bstyles) tbb[index].fsStyle = Bstyles[absidx];"
        FPRINT FP_OUTPUT, "          tbb[index].iString = absidx;"
        FPRINT FP_OUTPUT, "          absidx++;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "      seppos++;"
        FPRINT FP_OUTPUT, "      index++;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  SendMessage(A,(UINT_PTR)TB_ADDBUTTONS,(WPARAM)index,(LPARAM)(LPTBBUTTON)tbb);"
        FPRINT FP_OUTPUT, "  if(img!=0)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if(img==HINST_COMMCTRL)"
        FPRINT FP_OUTPUT, "       {"
        FPRINT FP_OUTPUT, "          tbbitmap.hInst = HINST_COMMCTRL;"
        FPRINT FP_OUTPUT, "          tbbitmap.nID = imgidx[NumBtns];"
        FPRINT FP_OUTPUT, "          SendMessage(A,(UINT_PTR)TB_ADDBITMAP,0,(LPARAM)(LPTBADDBITMAP)&tbbitmap);"
        FPRINT FP_OUTPUT, "       }else{"
        FPRINT FP_OUTPUT, "          if(!GetObject((HBITMAP)(img),sizeof(BITMAP),&bm))"
        FPRINT FP_OUTPUT, "           {"
        FPRINT FP_OUTPUT, "              SendMessage(A, TB_SETIMAGELIST, 0, (LPARAM)img);"
        FPRINT FP_OUTPUT, "           }else{"
        FPRINT FP_OUTPUT, "              tbbitmap.nID = (UINT_PTR)(img);"
        FPRINT FP_OUTPUT, "              SendMessage(A,(UINT_PTR)TB_SETBITMAPSIZE,(WPARAM)0,(LPARAM)MAKELONG(bm.bmWidth/NumBtns,bm.bmHeight));"
        FPRINT FP_OUTPUT, "              SendMessage(A,(UINT_PTR)TB_ADDBITMAP,(WPARAM)NumBtns,(LPARAM)(LPTBADDBITMAP)&tbbitmap);"
        FPRINT FP_OUTPUT, "           }"
        FPRINT FP_OUTPUT, "       }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  if(txtlen && Text[0] != '-')"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      char*  titles;"
        FPRINT FP_OUTPUT, "      titles = (char*)calloc(2+txtlen,sizeof(char));"
        FPRINT FP_OUTPUT, "      absidx = 0;"
        FPRINT FP_OUTPUT, "      for(index = 0;index<txtlen;index++)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        if(Text[index]=='|')"
        FPRINT FP_OUTPUT, "         {"
        FPRINT FP_OUTPUT, "            if(Text[index+1]=='|'||titles[0]==0) continue;"
        FPRINT FP_OUTPUT, "            titles[absidx] = 0;"
        FPRINT FP_OUTPUT, "         }else{"
        FPRINT FP_OUTPUT, "            titles[absidx] = Text[index];"
        FPRINT FP_OUTPUT, "         }"
        FPRINT FP_OUTPUT, "        absidx++;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      SendMessage(A,(UINT_PTR)TB_ADDSTRING,(WPARAM)0,(LPARAM)titles);"
        FPRINT FP_OUTPUT, "      free(titles);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  SendMessage(A,(UINT_PTR)TB_AUTOSIZE, 0, 0);"
        FPRINT FP_OUTPUT, "  ShowWindow(A,SW_SHOW);"
        FPRINT FP_OUTPUT, "  free(tbb);"
        FPRINT FP_OUTPUT, "  return A;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_BCX_UpDown THEN
        FPRINT FP_OUTPUT, "HWND BCX_UpDown (HWND hWnd,int X,int Y,int W,int H,int Lo,int Hi,int Start)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HWND UpDn;"
        FPRINT FP_OUTPUT, "  HWND Buddy;"
        FPRINT FP_OUTPUT, "  int  Style = WS_CHILD|WS_VISIBLE|WS_TABSTOP|ES_NUMBER|ES_LEFT|ES_AUTOHSCROLL;"
        FPRINT FP_OUTPUT, "  Buddy = CreateWindowEx(WS_EX_CLIENTEDGE,", ENC$("edit"), ",0,Style,"
        FPRINT FP_OUTPUT, "                       X*BCX_ScaleX,Y*BCX_ScaleY,W*BCX_ScaleX,H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                       hWnd,(HMENU)(UINT_PTR)0,BCX_hInstance,NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (Buddy == NULL) return NULL;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  SendMessage(Buddy,WM_SETFONT,(WPARAM)DefaultFont,(LPARAM)MAKELPARAM(0,0));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  UpDn = CreateUpDownControl(WS_CHILD|WS_VISIBLE|WS_TABSTOP|WS_BORDER|"
        FPRINT FP_OUTPUT, "                           UDS_ARROWKEYS|UDS_SETBUDDYINT|UDS_ALIGNRIGHT|UDS_NOTHOUSANDS,"
        FPRINT FP_OUTPUT, "                           X*BCX_ScaleX,Y*BCX_ScaleY,W*BCX_ScaleX,H*BCX_ScaleY,"
        FPRINT FP_OUTPUT, "                           hWnd,0,BCX_hInstance,Buddy,Hi,Lo,Start);"
        FPRINT FP_OUTPUT, "  return UpDn;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Get_UpDown THEN
        FPRINT FP_OUTPUT, "int BCX_Get_UpDown (HWND hWnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr={0};"
        FPRINT FP_OUTPUT, "  HWND  hBuddy;"
        FPRINT FP_OUTPUT, "  int   k;"
        FPRINT FP_OUTPUT, "  hBuddy = (HWND)SendMessage(hWnd,(UINT_PTR)UDM_GETBUDDY,(WPARAM)0,(LPARAM)0);"
        FPRINT FP_OUTPUT, "  k = GetWindowTextLength(hBuddy)+1;"
        FPRINT FP_OUTPUT, "  BCX_RetStr = BCX_TempStr(1);"
        FPRINT FP_OUTPUT, "  GetWindowText(hBuddy,BCX_RetStr,k);"
        FPRINT FP_OUTPUT, "  return (int)atof(BCX_RetStr);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_Controls2



SUB Emit_RT_Graphics1 (FP_OUTPUT AS FILE)
    IF Use_Draw THEN
        FPRINT FP_OUTPUT, "HDC StartDraw (HWND hWnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HBITMAP oldbmp, tmpbmp;"
        FPRINT FP_OUTPUT, "  HDC  hDestDC, WinDC;"
        FPRINT FP_OUTPUT, "  RECT rc;"
        FPRINT FP_OUTPUT, "  tmpbmp = (HBITMAP)SendMessage(hWnd,STM_GETIMAGE,0,0);"
        FPRINT FP_OUTPUT, "  if (tmpbmp==NULL)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    GetClientRect(hWnd,&rc);"
        FPRINT FP_OUTPUT, "    WinDC = GetDC(NULL);"
        FPRINT FP_OUTPUT, "    tmpbmp = CreateCompatibleBitmap(WinDC,rc.right,rc.bottom);"
        FPRINT FP_OUTPUT, "    ReleaseDC(NULL,WinDC);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  hDestDC = CreateCompatibleDC(NULL);"
        FPRINT FP_OUTPUT, "  oldbmp = (HBITMAP)SelectObject(hDestDC,tmpbmp);"
        FPRINT FP_OUTPUT, "  SetProp(hWnd,", ENC$("oldbmp"), ",(HANDLE)oldbmp);"
        FPRINT FP_OUTPUT, "  return hDestDC;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "HBITMAP EndDraw (HWND hWnd, HDC hDestDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HBITMAP  oldbmp, tmpbmp;"
        FPRINT FP_OUTPUT, "  oldbmp = (HBITMAP)GetProp(hWnd,", ENC$("oldbmp"), ");"
        FPRINT FP_OUTPUT, "  tmpbmp = (HBITMAP)SelectObject(hDestDC,oldbmp);"
        FPRINT FP_OUTPUT, "  DeleteDC(hDestDC);"
        FPRINT FP_OUTPUT, "  SendMessage(hWnd,STM_SETIMAGE,IMAGE_BITMAP,(LPARAM)tmpbmp);"
        FPRINT FP_OUTPUT, "  return tmpbmp;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_SetText THEN
        FPRINT FP_OUTPUT, "int BCX_Set_Text (HWND hWnd, PCTSTR Text)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  return SetWindowText(hWnd,Text);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_SetFormColor THEN
        FPRINT FP_OUTPUT, "void BCX_Set_Form_Color (HWND hWnd, ULONG Kolor)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HBRUSH hbr = CreateSolidBrush(Kolor);"
        FPRINT FP_OUTPUT, "  DeleteObject((HBRUSH)SetClassLongPtr(hWnd,GCLP_HBRBACKGROUND,(LONG_PTR)hbr));"
        FPRINT FP_OUTPUT, "  InvalidateRect (hWnd,NULL,TRUE);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Tile THEN
        FPRINT FP_OUTPUT, "void BCX_Tile (HWND hWnd, HBITMAP hBmp)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HBRUSH hbr = CreatePatternBrush(hBmp);"
        FPRINT FP_OUTPUT, "  DeleteObject((HBRUSH)SetClassLongPtr(hWnd,GCLP_HBRBACKGROUND,(LONG_PTR)hbr));"
        FPRINT FP_OUTPUT, "  RedrawWindow(hWnd,0,0,0);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_SetColor THEN
        FPRINT FP_OUTPUT, "LRESULT Set_Color (int TxtColr, int BkColr, HDC wParam, HWND lParam)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static HBRUSH  ReUsableBrush;"
        FPRINT FP_OUTPUT, "  SetTextColor(wParam,TxtColr);"
        FPRINT FP_OUTPUT, "  if (BkColr==(-1))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BkColr = (UINT_PTR)GetClassLongPtr(GetParent(lParam),GCLP_HBRBACKGROUND);"
        FPRINT FP_OUTPUT, "    if ((UINT_PTR)BkColr>31)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      SetBkMode(wParam,TRANSPARENT);"
        FPRINT FP_OUTPUT, "      return BkColr;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      BkColr = GetSysColor(BkColr-1);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  DeleteObject(ReUsableBrush);"
        FPRINT FP_OUTPUT, "  ReUsableBrush = CreateSolidBrush(BkColr);"
        FPRINT FP_OUTPUT, "  SetBkColor(wParam,BkColr);"
        FPRINT FP_OUTPUT, "  return (LRESULT)ReUsableBrush;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_SetFont THEN
        FPRINT FP_OUTPUT, "HFONT BCX_Set_Font (PCTSTR Font, float Size, int Bold, int Italic, int Underline, int StrikeThru, int CharSet, int Angle)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HDC hDC = GetDC(HWND_DESKTOP);"
        FPRINT FP_OUTPUT, "  int CyPixels = GetDeviceCaps(hDC,LOGPIXELSY);"
        FPRINT FP_OUTPUT, "  ReleaseDC(HWND_DESKTOP,hDC);"
        FPRINT FP_OUTPUT, "  return CreateFont(0-(Size*CyPixels)/72,0,Angle,0,Bold,Italic,Underline,StrikeThru,"
        FPRINT FP_OUTPUT, "                    CharSet,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,Font);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Preset THEN
        FPRINT FP_OUTPUT, "int BCX_Preset (HWND hWnd, int x, int y, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int a;"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  a = MoveToEx(DrawHDC,x,y,NULL);"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return a;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Blit THEN
        FPRINT FP_OUTPUT, "void BCX_Blit (HBITMAP hBmp, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HDC     hdcDest = CreateCompatibleDC(NULL);"
        FPRINT FP_OUTPUT, "  HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcDest, hBmp);"
        FPRINT FP_OUTPUT, "  BITMAP  bmpInfo;"
        FPRINT FP_OUTPUT, "  GetObject(hBmp,sizeof(BITMAP), &bmpInfo);"
        FPRINT FP_OUTPUT, "  int bmpWidth = bmpInfo.bmWidth;"
        FPRINT FP_OUTPUT, "  int bmpHeight = bmpInfo.bmHeight;"
        FPRINT FP_OUTPUT, "  BitBlt(DrawHDC, 0, 0, bmpWidth, bmpHeight, hdcDest, 0, 0, SRCCOPY);"
        FPRINT FP_OUTPUT, "  SelectObject(hdcDest, hOldBitmap);"
        FPRINT FP_OUTPUT, "  DeleteDC(hdcDest);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Blit_Stretch THEN
        FPRINT FP_OUTPUT, "void BCX_Blit_Stretch (HBITMAP hBmp, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HDC     hdcDest = CreateCompatibleDC(NULL);"
        FPRINT FP_OUTPUT, "  HBITMAP hOldBitmap = (HBITMAP)SelectObject(hdcDest, hBmp);"
        FPRINT FP_OUTPUT, "  BITMAP  bmpInfo;"
        FPRINT FP_OUTPUT, "  GetObject(hBmp,sizeof(BITMAP), &bmpInfo);"
        FPRINT FP_OUTPUT, "  int bmpWidth = bmpInfo.bmWidth;"
        FPRINT FP_OUTPUT, "  int bmpHeight = bmpInfo.bmHeight;"
        FPRINT FP_OUTPUT, "  StretchBlt(DrawHDC,0,0,MAXX,MAXY,hdcDest,0,0,bmpWidth,bmpHeight,SRCCOPY);"
        FPRINT FP_OUTPUT, "  SelectObject(hdcDest, hOldBitmap);"
        FPRINT FP_OUTPUT, "  DeleteDC(hdcDest);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Blit_Sprite THEN
        FPRINT FP_OUTPUT, "void BCX_Blit_Sprite (HBITMAP hBmp, int Left, int Top, ULONG rgbMask, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HDC      hdcDest={0};"
        FPRINT FP_OUTPUT, "  HBITMAP  hOldBitmap={0};"
        FPRINT FP_OUTPUT, "  BITMAP   bmpInfo={0};  "
        FPRINT FP_OUTPUT, "  if(!hBmp || !DrawHDC){  "
        FPRINT FP_OUTPUT, "      return; "
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  hdcDest = CreateCompatibleDC(NULL);"
        FPRINT FP_OUTPUT, "  hOldBitmap = (HBITMAP)SelectObject(hdcDest,hBmp);"
        FPRINT FP_OUTPUT, "  GetObject(hBmp,sizeof(BITMAP), &bmpInfo);"
        FPRINT FP_OUTPUT, "  TransparentBlt(DrawHDC, Left, Top, bmpInfo.bmWidth, bmpInfo.bmHeight,"
        FPRINT FP_OUTPUT, "                 hdcDest, 0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, rgbMask);"
        FPRINT FP_OUTPUT, "  SelectObject(hdcDest,hOldBitmap);"
        FPRINT FP_OUTPUT, "  DeleteDC(hdcDest);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Buffer THEN
        FPRINT FP_OUTPUT, "void BCX_BUFFER_START (int x, int y)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   if(BCX_PREV_BMP)"
        FPRINT FP_OUTPUT, "   {"
        FPRINT FP_OUTPUT, "     DeleteObject(SelectObject(BCX_BUFFER,BCX_PREV_BMP));"
        FPRINT FP_OUTPUT, "     BCX_PREV_BMP = NULL;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "  if (BCX_BUFFER) DeleteDC(BCX_BUFFER);"
        FPRINT FP_OUTPUT, "  BCX_BUFFER = CreateCompatibleDC(0);"
        FPRINT FP_OUTPUT, "  BCX_BUFFER_BMWIDTH  = x;"
        FPRINT FP_OUTPUT, "  BCX_BUFFER_BMHEIGHT = y;"
        FPRINT FP_OUTPUT, "  BCX_BUFFER_BMP.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);"
        FPRINT FP_OUTPUT, "  BCX_BUFFER_BMP.bmiHeader.biWidth = BCX_BUFFER_BMWIDTH;"
        FPRINT FP_OUTPUT, "  BCX_BUFFER_BMP.bmiHeader.biHeight = -BCX_BUFFER_BMHEIGHT;"
        FPRINT FP_OUTPUT, "  BCX_BUFFER_BMP.bmiHeader.biPlanes = 1;"
        FPRINT FP_OUTPUT, "  BCX_BUFFER_BMP.bmiHeader.biBitCount = 32;"
        FPRINT FP_OUTPUT, "  BCX_BUFFER_BMP.bmiHeader.biCompression = BI_RGB;"
        FPRINT FP_OUTPUT, "  BCX_PREV_BMP = (HBITMAP)SelectObject(BCX_BUFFER,CreateDIBSection(0, &BCX_BUFFER_BMP,DIB_RGB_COLORS,0,0,0));"
        FPRINT FP_OUTPUT, "}\n\n"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "void BCX_BUFFER_STOP (HWND hWnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HDC Local_HDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  BitBlt(Local_HDC,0,0,BCX_BUFFER_BMWIDTH,BCX_BUFFER_BMHEIGHT,BCX_BUFFER,0,0,SRCCOPY);"
        FPRINT FP_OUTPUT, "  ReleaseDC(hWnd,Local_HDC);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(BCX_BUFFER,BCX_PREV_BMP));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Pset THEN
        FPRINT FP_OUTPUT, "int BCX_Pset (HWND hWnd, int x1, int y1, int Pen, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  int OldPenSize = BCX_Pensize;"
        FPRINT FP_OUTPUT, "  HPEN hOldPen;"
        FPRINT FP_OUTPUT, "  HPEN hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  MoveToEx(DrawHDC,x1,y1,NULL);"
        FPRINT FP_OUTPUT, "  if(BCX_Pensize<4)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      RetCode = SetPixelV(DrawHDC,x1,y1,Pen); // Use fast thin pixels"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      RetCode = LineTo(DrawHDC,x1,y1);        // Use slow fat pixels"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldPen));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  BCX_Pensize = OldPenSize;"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_BCX_Floodfill THEN
        FPRINT FP_OUTPUT, "int BCX_FloodFill (HWND hWnd,int X,int Y,int Areacolor,int Fillcolor,int FillType,HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN hNewPen = CreatePen(BCX_Penstyle,1,Fillcolor);"
        FPRINT FP_OUTPUT, "  HPEN hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  HBRUSH hOldBrush;"
        FPRINT FP_OUTPUT, "  HBRUSH hNewBrush;"
        FPRINT FP_OUTPUT, "  hNewBrush = CreateSolidBrush(Fillcolor);"
        FPRINT FP_OUTPUT, "  hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  if (!FillType)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    RetCode = ExtFloodFill(DrawHDC, X, Y, Areacolor, 0);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    RetCode = ExtFloodFill(DrawHDC, X, Y, Areacolor, 1);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldPen));"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldBrush));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Line THEN
        FPRINT FP_OUTPUT, "int BCX_Line(HWND hWnd, int x1, int y1, int x2, int y2, int Pen, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  HPEN hOldPen;"
        FPRINT FP_OUTPUT, "  HPEN hNewPen = CreatePen(BCX_Penstyle, BCX_Pensize, Pen);"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  hOldPen = (HPEN)SelectObject(DrawHDC, hNewPen);"
        FPRINT FP_OUTPUT, "  MoveToEx(DrawHDC, x1, y1, NULL);"
        FPRINT FP_OUTPUT, "  RetCode = LineTo(DrawHDC, x2, y2);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC, hOldPen));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd, DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Lineto THEN
        FPRINT FP_OUTPUT, "int BCX_Lineto (HWND hWnd, int x, int y, int Pen, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  HPEN hOldPen;"
        FPRINT FP_OUTPUT, "  HPEN hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  RetCode = LineTo(DrawHDC,x,y);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldPen));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Triangle THEN
        FPRINT FP_OUTPUT, "int BCX_Triangle(HWND hWnd, LONG x1, LONG y1, LONG x2, LONG y2, LONG x3, LONG y3, DWORD fillColor, LONG filled, HDC hdc) {"
        FPRINT FP_OUTPUT, "    POINT MyPoint[3];"
        FPRINT FP_OUTPUT, "    HBRUSH hBrush=NULL, hOldBrush=NULL;"
        FPRINT FP_OUTPUT, "    HPEN hPen=NULL, hOldPen=NULL;"
        FPRINT FP_OUTPUT, "    HDC localHDC=NULL;"
        FPRINT FP_OUTPUT, "    int needToRelease=0;"
        FPRINT FP_OUTPUT, "    int RetCode=0;"
        FPRINT FP_OUTPUT, "    // Ensure minimum pen size"
        FPRINT FP_OUTPUT, "    if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Determine which HDC to use"
        FPRINT FP_OUTPUT, "    if (hWnd != 0) {"
        FPRINT FP_OUTPUT, "        localHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "        needToRelease = true;"
        FPRINT FP_OUTPUT, "    } else {"
        FPRINT FP_OUTPUT, "        localHDC = hdc;"
        FPRINT FP_OUTPUT, "        needToRelease = false;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Set up the POINT array"
        FPRINT FP_OUTPUT, "    MyPoint[0].x = x1; MyPoint[0].y = y1;"
        FPRINT FP_OUTPUT, "    MyPoint[1].x = x2; MyPoint[1].y = y2;"
        FPRINT FP_OUTPUT, "    MyPoint[2].x = x3; MyPoint[2].y = y3;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Create and select the brush for filling"
        FPRINT FP_OUTPUT, "    if (filled) {"
        FPRINT FP_OUTPUT, "        hBrush = CreateSolidBrush(fillColor);"
        FPRINT FP_OUTPUT, "        hOldBrush = (HBRUSH)SelectObject(localHDC, hBrush);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Create and select a pen for the outline"
        FPRINT FP_OUTPUT, "    hPen = CreatePen(BCX_Penstyle, BCX_Pensize, fillColor);"
        FPRINT FP_OUTPUT, "    hOldPen = (HPEN)SelectObject(localHDC, hPen);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Draw the triangle"
        FPRINT FP_OUTPUT, "    BeginPath(localHDC);"
        FPRINT FP_OUTPUT, "    Polygon(localHDC, MyPoint, 3);"
        FPRINT FP_OUTPUT, "    EndPath(localHDC);"
        FPRINT FP_OUTPUT, "    if (filled) {"
        FPRINT FP_OUTPUT, "        FillPath(localHDC);"
        FPRINT FP_OUTPUT, "    } else {"
        FPRINT FP_OUTPUT, "        StrokePath(localHDC);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Clean up"
        FPRINT FP_OUTPUT, "    if (filled) {"
        FPRINT FP_OUTPUT, "        SelectObject(localHDC, hOldBrush);"
        FPRINT FP_OUTPUT, "        DeleteObject(hBrush);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    SelectObject(localHDC, hOldPen);"
        FPRINT FP_OUTPUT, "    DeleteObject(hPen);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Release the DC if we got it from the window"
        FPRINT FP_OUTPUT, "    if (needToRelease) {"
        FPRINT FP_OUTPUT, "        ReleaseDC(hWnd, localHDC);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF




    IF Use_BCX_Gradient THEN
        FPRINT FP_OUTPUT, "void BCX_Gradient(HWND MyhWnd, ULONG StartRGB, ULONG EndRGB, int Direction, HDC Myhdc)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    HDC myHDC;"
        FPRINT FP_OUTPUT, "    RECT myRECT;"
        FPRINT FP_OUTPUT, "    int needRelease = 0;"
        FPRINT FP_OUTPUT, "    int w, h, i, range;"
        FPRINT FP_OUTPUT, "    int r1, g1, b1;"
        FPRINT FP_OUTPUT, "    int r2, g2, b2;"
        FPRINT FP_OUTPUT, "    double stepR, stepG, stepB;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Get DC and dimensions"
        FPRINT FP_OUTPUT, "    if (MyhWnd) {"
        FPRINT FP_OUTPUT, "        myHDC = GetDC(MyhWnd);"
        FPRINT FP_OUTPUT, "        needRelease = 1;"
        FPRINT FP_OUTPUT, "        GetClientRect(MyhWnd, &myRECT);"
        FPRINT FP_OUTPUT, "    } else {"
        FPRINT FP_OUTPUT, "        myHDC = Myhdc;"
        FPRINT FP_OUTPUT, "        GetClipBox(myHDC, &myRECT);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    w = myRECT.right - myRECT.left;"
        FPRINT FP_OUTPUT, "    h = myRECT.bottom - myRECT.top;"
        FPRINT FP_OUTPUT, "    if (!myHDC || w < 1 || h < 1) return;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Extract RGB components"
        FPRINT FP_OUTPUT, "    r1 = GetRValue(StartRGB);"
        FPRINT FP_OUTPUT, "    g1 = GetGValue(StartRGB);"
        FPRINT FP_OUTPUT, "    b1 = GetBValue(StartRGB);"
        FPRINT FP_OUTPUT, "    r2 = GetRValue(EndRGB);"
        FPRINT FP_OUTPUT, "    g2 = GetGValue(EndRGB);"
        FPRINT FP_OUTPUT, "    b2 = GetBValue(EndRGB);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Determine range and steps based on direction"
        FPRINT FP_OUTPUT, "    if (Direction) {"
        FPRINT FP_OUTPUT, "        range = w - 1;"
        FPRINT FP_OUTPUT, "    } else {"
        FPRINT FP_OUTPUT, "        range = h - 1;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (range < 1) range = 1;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    stepR = (double)(r2 - r1) / range;"
        FPRINT FP_OUTPUT, "    stepG = (double)(g2 - g1) / range;"
        FPRINT FP_OUTPUT, "    stepB = (double)(b2 - b1) / range;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    // Draw gradient lines"
        FPRINT FP_OUTPUT, "    for (i = 0; i <= range; i++) {"
        FPRINT FP_OUTPUT, "        int currR = r1 + (int)round(stepR * i);"
        FPRINT FP_OUTPUT, "        int currG = g1 + (int)round(stepG * i);"
        FPRINT FP_OUTPUT, "        int currB = b1 + (int)round(stepB * i);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        currR = currR < 0 ? 0 : (currR > 255 ? 255 : currR);"
        FPRINT FP_OUTPUT, "        currG = currG < 0 ? 0 : (currG > 255 ? 255 : currG);"
        FPRINT FP_OUTPUT, "        currB = currB < 0 ? 0 : (currB > 255 ? 255 : currB);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        HPEN hPen = CreatePen(PS_SOLID, 1, RGB(currR, currG, currB));"
        FPRINT FP_OUTPUT, "        if (!hPen) continue;"
        FPRINT FP_OUTPUT, "        HPEN hOldPen = (HPEN)SelectObject(myHDC, hPen);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        if (Direction) {"
        FPRINT FP_OUTPUT, "            MoveToEx(myHDC, i, 0, NULL);"
        FPRINT FP_OUTPUT, "            LineTo(myHDC, i, h);"
        FPRINT FP_OUTPUT, "        } else {"
        FPRINT FP_OUTPUT, "            MoveToEx(myHDC, 0, i, NULL);"
        FPRINT FP_OUTPUT, "            LineTo(myHDC, w, i);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        SelectObject(myHDC, hOldPen);"
        FPRINT FP_OUTPUT, "        DeleteObject(hPen);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (needRelease) ReleaseDC(MyhWnd, myHDC);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Polar_Pset THEN
        FPRINT FP_OUTPUT, "void BCX_Polar_Pset(HWND hWnd, int RadiusX, int RadiusY, float Radius, float AzDecDeg, ULONG RgbColor, HDC MyHdc)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  while(AzDecDeg<0) AzDecDeg = AzDecDeg + 360;"
        FPRINT FP_OUTPUT, "  AzDecDeg = (270 + AzDecDeg) * 0.017453;"
        FPRINT FP_OUTPUT, "  int X = RadiusX + (int)(Radius * cos(AzDecDeg));"
        FPRINT FP_OUTPUT, "  int Y = RadiusY + (int)(Radius * sin(AzDecDeg));"
        FPRINT FP_OUTPUT, "  if (hWnd) {"
        FPRINT FP_OUTPUT, "    BCX_Pset(hWnd, X, Y, RgbColor);"
        FPRINT FP_OUTPUT, "      } else {"
        FPRINT FP_OUTPUT, "    BCX_Pset(NULL, X, Y, RgbColor, MyHdc);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Polar_Line THEN
        FPRINT FP_OUTPUT, "void BCX_Polar_Line(HWND hWnd, int RadiusX, int RadiusY, float Radius, float AzDecDeg, ULONG RgbColor, HDC MyHdc)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  while(AzDecDeg<0) AzDecDeg = AzDecDeg + 360;"
        FPRINT FP_OUTPUT, "  AzDecDeg = (270 + AzDecDeg) * 0.017453;"
        FPRINT FP_OUTPUT, "  int X = RadiusX + (int)(Radius * cos(AzDecDeg));"
        FPRINT FP_OUTPUT, "  int Y = RadiusY + (int)(Radius * sin(AzDecDeg));"
        FPRINT FP_OUTPUT, "  if(hWnd){"
        FPRINT FP_OUTPUT, "    BCX_Line(hWnd, RadiusX, RadiusY, X, Y, RgbColor);"
        FPRINT FP_OUTPUT, "      } else {"
        FPRINT FP_OUTPUT, "    BCX_Line(NULL, RadiusX, RadiusY, X, Y, RgbColor, MyHdc);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Polygon THEN
        FPRINT FP_OUTPUT, "int BCX_Polygon (HWND hWnd, const POINT *lpPoints, int nCount, int Pen, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  HPEN hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  int RetCode = Polygon(DrawHDC,lpPoints,nCount);"
        FPRINT FP_OUTPUT, "  SelectObject(DrawHDC,hOldPen);"
        FPRINT FP_OUTPUT, "  DeleteObject(hNewPen);"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_PolyBezier THEN
        FPRINT FP_OUTPUT, "int BCX_PolyBezier (HWND hWnd, const POINT *lpPoints, int nCount, int Pen, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  HPEN hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  RetCode = PolyBezier(DrawHDC,lpPoints,nCount);"
        FPRINT FP_OUTPUT, "  SelectObject(DrawHDC,hOldPen);"
        FPRINT FP_OUTPUT, "  DeleteObject(hNewPen);"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Polyline THEN
        FPRINT FP_OUTPUT, "int BCX_Polyline (HWND hWnd, const POINT *lpPoints, int nCount, int Pen, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  HPEN hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  RetCode = Polyline(DrawHDC,lpPoints,nCount);"
        FPRINT FP_OUTPUT, "  SelectObject(DrawHDC,hOldPen);"
        FPRINT FP_OUTPUT, "  DeleteObject(hNewPen);"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Circle THEN
        FPRINT FP_OUTPUT, "int BCX_Circle (HWND hWnd, int X, int Y, int R, int Pen, int Fill, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN   hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  HPEN   hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  HBRUSH hOldBrush;"
        FPRINT FP_OUTPUT, "  HBRUSH hNewBrush;"
        FPRINT FP_OUTPUT, "  if (Fill)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    hNewBrush = CreateSolidBrush(Pen);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  } else {"
        FPRINT FP_OUTPUT, "    hNewBrush = (HBRUSH)GetStockObject(NULL_BRUSH);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  RetCode = Ellipse(DrawHDC,X-R,Y+R,X+R,Y-R);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldPen));"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldBrush));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Ellipse THEN
        FPRINT FP_OUTPUT, "int BCX_Ellipse (HWND hWnd, int Left, int Top, int Right, int Bottom, int Pen, int Fill, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN   hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  HPEN   hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  HBRUSH hOldBrush;"
        FPRINT FP_OUTPUT, "  HBRUSH hNewBrush;"
        FPRINT FP_OUTPUT, "  if (Fill)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    hNewBrush = CreateSolidBrush(Pen);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  } else {"
        FPRINT FP_OUTPUT, "    hNewBrush = (HBRUSH)GetStockObject(NULL_BRUSH);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  RetCode = Ellipse(DrawHDC,Left,Top,Right,Bottom);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldPen));"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldBrush));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Rectangle THEN
        FPRINT FP_OUTPUT, "int BCX_Rectangle (HWND hWnd, int Left, int Top, int Right, int Bottom, int Pen, int Fill, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN   hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  HPEN   hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  HBRUSH hOldBrush;"
        FPRINT FP_OUTPUT, "  HBRUSH hNewBrush;"
        FPRINT FP_OUTPUT, "  if (Fill)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    hNewBrush = CreateSolidBrush(Pen);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  } else {"
        FPRINT FP_OUTPUT, "    hNewBrush = (HBRUSH)GetStockObject(NULL_BRUSH);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  RetCode = Rectangle(DrawHDC,Left,Top,Right,Bottom);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldPen));"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldBrush));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Roundrect THEN
        FPRINT FP_OUTPUT, "int BCX_Roundrect (HWND hWnd, int Left, int Top, int Right, int Bottom, int W,  int H, int Pen, int Fill, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN   hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  HPEN   hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  HBRUSH hOldBrush;"
        FPRINT FP_OUTPUT, "  HBRUSH hNewBrush;"
        FPRINT FP_OUTPUT, "  if (Fill)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    hNewBrush = CreateSolidBrush(Pen);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  } else {"
        FPRINT FP_OUTPUT, "    hNewBrush = (HBRUSH)GetStockObject(NULL_BRUSH);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  RetCode = RoundRect(DrawHDC,Left,Top,Right,Bottom,W,H);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldPen));"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldBrush));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Arc THEN
        FPRINT FP_OUTPUT, "int BCX_Arc (HWND hWnd, int Left, int Top, int Right, int Bottom, int BCX, int BCY, int ECX, int ECY, int Pen, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  HPEN hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  RetCode = Arc(DrawHDC,Left,Top,Right,Bottom,BCX,BCY,ECX,ECY);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldPen));"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Pie THEN
        FPRINT FP_OUTPUT, "int BCX_Pie (HWND hWnd, int Left, int Top, int Right, int Bottom, int BCX, int BCY, int ECX, int ECY, int Pen, int Fill, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int RetCode;"
        FPRINT FP_OUTPUT, "  if (BCX_Pensize < 1) BCX_Pensize = 1;"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HPEN hNewPen = CreatePen(BCX_Penstyle,BCX_Pensize,Pen);"
        FPRINT FP_OUTPUT, "  HPEN hOldPen = (HPEN)SelectObject(DrawHDC,hNewPen);"
        FPRINT FP_OUTPUT, "  HBRUSH hOldBrush;"
        FPRINT FP_OUTPUT, "  HBRUSH hNewBrush;"
        FPRINT FP_OUTPUT, "  if (Fill)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    hNewBrush = CreateSolidBrush(Pen);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  } else {"
        FPRINT FP_OUTPUT, "    hNewBrush = (HBRUSH)GetStockObject(NULL_BRUSH);"
        FPRINT FP_OUTPUT, "    hOldBrush = (HBRUSH)SelectObject(DrawHDC,hNewBrush);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  RetCode = Pie(DrawHDC,Left,Top,Right,Bottom,BCX,BCY,ECX,ECY);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC,hOldPen));"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(DrawHDC, hOldBrush));"   ' 836 Added by MrBcx found GDI Leak!
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return RetCode;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_BCX_Fontdlg THEN
        FPRINT FP_OUTPUT, "int BCX_FontDlg (BOOL UseBcxFont, HWND hWnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  CHOOSEFONT cf;"
        FPRINT FP_OUTPUT, "  memset(&cf,0,sizeof(cf));"
        FPRINT FP_OUTPUT, "  if (UseBcxFont)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    HDC hdc = GetDC(0);"
        FPRINT FP_OUTPUT, "    BCX_FONT.lf.lfHeight = -MulDiv(BCX_FONT.SIZE, GetDeviceCaps(hdc, LOGPIXELSY), 72);"
        FPRINT FP_OUTPUT, "    ReleaseDC(0,hdc);"
        FPRINT FP_OUTPUT, "    cf.rgbColors = BCX_FONT.RGB;"
        FPRINT FP_OUTPUT, "  } else {"
        FPRINT FP_OUTPUT, "    memset(&BCX_FONT.lf,0,sizeof(BCX_FONT.lf));"
        FPRINT FP_OUTPUT, "    GetObject(GetStockObject(DEFAULT_GUI_FONT),sizeof(BCX_FONT.lf),&BCX_FONT.lf);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  cf.lStructSize = sizeof(CHOOSEFONT);"
        FPRINT FP_OUTPUT, "  cf.hwndOwner = hWnd;"
        FPRINT FP_OUTPUT, "  cf.lpLogFont = &BCX_FONT.lf;"
        FPRINT FP_OUTPUT, "  cf.Flags = CF_INITTOLOGFONTSTRUCT|CF_SCREENFONTS|CF_EFFECTS;"
        FPRINT FP_OUTPUT, "  CmDlgHook = SetWindowsHookEx(WH_CBT,(HOOKPROC)SBProc,NULL,GetCurrentThreadId());" ' 833 MrBcx Changed
        FPRINT FP_OUTPUT, "  int rc = ChooseFont(&cf);"
        FPRINT FP_OUTPUT, "  if (rc)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    BCX_FONT.SIZE = cf.iPointSize/10;"
        FPRINT FP_OUTPUT, "    BCX_FONT.RGB = cf.rgbColors;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, " return rc;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_Getpixel THEN
        FPRINT FP_OUTPUT, "ULONG BCX_Getpixel(HWND hWnd, int X, int Y, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!DrawHDC) DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  int i = GetPixel(DrawHDC,X,Y);"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,DrawHDC);"
        FPRINT FP_OUTPUT, "  return i;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_QBColor THEN
        FPRINT FP_OUTPUT, "ULONG qbcolor (int N)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static int Initialized;"
        FPRINT FP_OUTPUT, "  static ULONG Colors[32];"
        FPRINT FP_OUTPUT, "  if(!Initialized){"
        FPRINT FP_OUTPUT, "    Colors[0]  = 0x00000000;"
        FPRINT FP_OUTPUT, "    Colors[1]  = 0X00A80000;"
        FPRINT FP_OUTPUT, "    Colors[2]  = 0X0000A800;"
        FPRINT FP_OUTPUT, "    Colors[3]  = 0X00A8A800;"
        FPRINT FP_OUTPUT, "    Colors[4]  = 0X000000A8;"
        FPRINT FP_OUTPUT, "    Colors[5]  = 0X00A800A8;"
        FPRINT FP_OUTPUT, "    Colors[6]  = 0X000054A8;"
        FPRINT FP_OUTPUT, "    Colors[7]  = 0X00A8A8A8;"
        FPRINT FP_OUTPUT, "    Colors[8]  = 0X00545454;"
        FPRINT FP_OUTPUT, "    Colors[9]  = 0X00FC5454;"
        FPRINT FP_OUTPUT, "    Colors[10] = 0X0054FC54;"
        FPRINT FP_OUTPUT, "    Colors[11] = 0X00FCFC54;"
        FPRINT FP_OUTPUT, "    Colors[12] = 0X005454FC;"
        FPRINT FP_OUTPUT, "    Colors[13] = 0X00FC54FC;"
        FPRINT FP_OUTPUT, "    Colors[14] = 0X0054FCFC;"
        FPRINT FP_OUTPUT, "    Colors[15] = 0X00FCFCFC;"
        FPRINT FP_OUTPUT, "    Colors[16] = 0X00A4A4A4;"
        FPRINT FP_OUTPUT, "    Colors[17] = 0X00FFA080;"
        FPRINT FP_OUTPUT, "    Colors[18] = 0X00A0FFA0;"
        FPRINT FP_OUTPUT, "    Colors[19] = 0X00FFFFA0;"
        FPRINT FP_OUTPUT, "    Colors[20] = 0X00A0A0FF;"
        FPRINT FP_OUTPUT, "    Colors[21] = 0X00FFA0FF;"
        FPRINT FP_OUTPUT, "    Colors[22] = 0X00A0FFFF;"
        FPRINT FP_OUTPUT, "    Colors[23] = 0X00D4D4D4;"
        FPRINT FP_OUTPUT, "    Colors[24] = 0X00B4B4B4;"
        FPRINT FP_OUTPUT, "    Colors[25] = 0X00FFDCBC;"
        FPRINT FP_OUTPUT, "    Colors[26] = 0X00DCFFDC;"
        FPRINT FP_OUTPUT, "    Colors[27] = 0X00FFFFDC;"
        FPRINT FP_OUTPUT, "    Colors[28] = 0X00DCDCFF;"
        FPRINT FP_OUTPUT, "    Colors[29] = 0X00FFDCFF;"
        FPRINT FP_OUTPUT, "    Colors[30] = 0X00DCFFFF;"
        FPRINT FP_OUTPUT, "    Colors[31] = 0X00E4E4E4;"
        FPRINT FP_OUTPUT, "    Initialized = 1;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return Colors[N];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_Graphics1



SUB Emit_RT_Graphics2 (FP_OUTPUT AS FILE)
    IF Use_GetBmp THEN   ' 821 MrBcx update.  Considers/utilizes the clientarea when needed
        FPRINT FP_OUTPUT, "HDC GetBmp (int Left, int Top, int Width, int Height, HWND hWnd)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "   int x, y;"
        FPRINT FP_OUTPUT, "   RECT rc;"
        FPRINT FP_OUTPUT, "   GetClientRect(hWnd, &rc);"
        FPRINT FP_OUTPUT, "   x = rc.right - rc.left;"
        FPRINT FP_OUTPUT, "   y = rc.bottom - rc.top;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "// Adjust Width and Height if they violate client-area sizes"
        FPRINT FP_OUTPUT, "   if (Width  > x || Width  < 1) Width  = x;"
        FPRINT FP_OUTPUT, "   if (Height > y || Height < 1) Height = y;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  HDC      HdcSrc = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HDC      HdcMem = CreateCompatibleDC(HdcSrc);"
        FPRINT FP_OUTPUT, "  HBITMAP  hBmp = CreateCompatibleBitmap(HdcSrc, Width, Height);"
        FPRINT FP_OUTPUT, "  DeleteObject(SelectObject(HdcMem, hBmp));"
        FPRINT FP_OUTPUT, "  BitBlt    (HdcMem, 0, 0, Width, Height, HdcSrc, Left, Top, SRCCOPY);"
        FPRINT FP_OUTPUT, "  ReleaseDC (hWnd, HdcSrc);"
        FPRINT FP_OUTPUT, "  return HdcMem;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_SaveBmp THEN
        FPRINT FP_OUTPUT, "void SaveBmp(PVOID hobj, PTSTR pszFile) {"
        FPRINT FP_OUTPUT, "    BITMAP bmp;"
        FPRINT FP_OUTPUT, "    PBITMAPINFO pbmi;"
        FPRINT FP_OUTPUT, "    WORD cClrBits;"
        FPRINT FP_OUTPUT, "    FILE* file;"
        FPRINT FP_OUTPUT, "    BITMAPFILEHEADER hdr;"
        FPRINT FP_OUTPUT, "    PBITMAPINFOHEADER pbih;"
        FPRINT FP_OUTPUT, "    PBYTE lpBits;"
        FPRINT FP_OUTPUT, "    ULONG cb;"
        FPRINT FP_OUTPUT, "    BYTE* hp;"
        FPRINT FP_OUTPUT, "    HDC hDC = (HDC)hobj;"
        FPRINT FP_OUTPUT, "    HBITMAP hBmp = (HBITMAP)hobj;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (GetObjectType(hobj) != OBJ_BITMAP)"
        FPRINT FP_OUTPUT, "        hBmp = (HBITMAP)GetCurrentObject(hDC, OBJ_BITMAP);"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "        hDC = CreateCompatibleDC(NULL);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    GetObject(hBmp, sizeof(BITMAP), (PSTR)&bmp);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    cClrBits = (WORD)(bmp.bmPlanes * bmp.bmBitsPixel);"
        FPRINT FP_OUTPUT, "    if (cClrBits == 1)"
        FPRINT FP_OUTPUT, "        cClrBits = 1;"
        FPRINT FP_OUTPUT, "    else if (cClrBits <= 4)"
        FPRINT FP_OUTPUT, "        cClrBits = 4;"
        FPRINT FP_OUTPUT, "    else if (cClrBits <= 8)"
        FPRINT FP_OUTPUT, "        cClrBits = 8;"
        FPRINT FP_OUTPUT, "    else if (cClrBits <= 16)"
        FPRINT FP_OUTPUT, "        cClrBits = 16;"
        FPRINT FP_OUTPUT, "    else if (cClrBits <= 24)"
        FPRINT FP_OUTPUT, "        cClrBits = 24;"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "        cClrBits = 32;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (cClrBits != 24)"
        FPRINT FP_OUTPUT, "        pbmi = (PBITMAPINFO)LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * (int)(1 << cClrBits));"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "        pbmi = (PBITMAPINFO)LocalAlloc(LPTR, sizeof(BITMAPINFOHEADER));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);"
        FPRINT FP_OUTPUT, "    pbmi->bmiHeader.biWidth = bmp.bmWidth;"
        FPRINT FP_OUTPUT, "    pbmi->bmiHeader.biHeight = bmp.bmHeight;"
        FPRINT FP_OUTPUT, "    pbmi->bmiHeader.biPlanes = bmp.bmPlanes;"
        FPRINT FP_OUTPUT, "    pbmi->bmiHeader.biBitCount = bmp.bmBitsPixel;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (cClrBits < 24)"
        FPRINT FP_OUTPUT, "        pbmi->bmiHeader.biClrUsed = (1 << cClrBits);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    pbmi->bmiHeader.biCompression = BI_RGB;"
        FPRINT FP_OUTPUT, "    pbmi->bmiHeader.biSizeImage = ((pbmi->bmiHeader.biWidth * cClrBits + 31) & ~31) / 8 * pbmi->bmiHeader.biHeight;"
        FPRINT FP_OUTPUT, "    pbmi->bmiHeader.biClrImportant = 0;"
        FPRINT FP_OUTPUT, "    pbih = (PBITMAPINFOHEADER)pbmi;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    lpBits = (PBYTE)malloc(pbih->biSizeImage);"
        FPRINT FP_OUTPUT, "    GetDIBits(hDC, hBmp, 0, (WORD)pbih->biHeight, lpBits, pbmi, DIB_RGB_COLORS);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    file = fopen(pszFile, ", ENC$("wb"), ");"
        FPRINT FP_OUTPUT, "    if (file == NULL) {"
        FPRINT FP_OUTPUT, "        printf(", ENC$("Failed to open file for writing."), ");"
        FPRINT FP_OUTPUT, "        return;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hdr.bfType = 0x4d42;"
        FPRINT FP_OUTPUT, "    hdr.bfSize = (ULONG)(sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD) + pbih->biSizeImage);"
        FPRINT FP_OUTPUT, "    hdr.bfReserved1 = 0;"
        FPRINT FP_OUTPUT, "    hdr.bfReserved2 = 0;"
        FPRINT FP_OUTPUT, "    hdr.bfOffBits = (ULONG)sizeof(BITMAPFILEHEADER) + pbih->biSize + pbih->biClrUsed * sizeof(RGBQUAD);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    fwrite(&hdr, sizeof(BITMAPFILEHEADER), 1, file);"
        FPRINT FP_OUTPUT, "    fwrite(pbih, sizeof(BITMAPINFOHEADER) + pbih->biClrUsed * sizeof(RGBQUAD), 1, file);"
        FPRINT FP_OUTPUT, "    cb = pbih->biSizeImage;"
        FPRINT FP_OUTPUT, "    hp = lpBits;"
        FPRINT FP_OUTPUT, "    fwrite(hp, cb, 1, file);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    fclose(file);"
        FPRINT FP_OUTPUT, "    free(lpBits);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (GetObjectType(hobj) == OBJ_BITMAP)"
        FPRINT FP_OUTPUT, "        DeleteDC(hDC);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Set_BCX_Bitmap THEN
        FPRINT FP_OUTPUT, "void Set_BCX_Bitmap(HWND hWnd, PCTSTR File, int Res,  int W,  int H)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HBITMAP Bm_Handle = NULL;"
        FPRINT FP_OUTPUT, "  if (Res)"
        FPRINT FP_OUTPUT, "     Bm_Handle = (HBITMAP)LoadImage(GetModuleHandle(0),MAKEINTRESOURCE(Res),"
        FPRINT FP_OUTPUT, "                IMAGE_BITMAP,W*BCX_ScaleX,H*BCX_ScaleY,LR_CREATEDIBSECTION);"
        FPRINT FP_OUTPUT, "  else if (File != NULL)"
        FPRINT FP_OUTPUT, "     Bm_Handle = (HBITMAP)LoadImage(0,File,IMAGE_BITMAP,"
        FPRINT FP_OUTPUT, "                W*BCX_ScaleX,H*BCX_ScaleY,LR_LOADFROMFILE|LR_CREATEDIBSECTION);"
        FPRINT FP_OUTPUT, "  if (Bm_Handle)"
        FPRINT FP_OUTPUT, "     DeleteObject((HBITMAP)SendMessage(hWnd,(UINT_PTR)STM_SETIMAGE,"
        FPRINT FP_OUTPUT, "                  (WPARAM)IMAGE_BITMAP,(LPARAM)Bm_Handle));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Set_BCX_Bitmap2 THEN
        FPRINT FP_OUTPUT, "HBITMAP Set_BCX_Bitmap2 (HWND hWnd, HBITMAP Bmp, int DeleteBM)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HBITMAP bm = (HBITMAP)SendMessage(hWnd,STM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)Bmp);"
        FPRINT FP_OUTPUT, "  if (DeleteBM)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    DeleteObject(bm);"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return bm;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Newbmp THEN
        FPRINT FP_OUTPUT, "HBITMAP NewBmp (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int screenHeight;"
        FPRINT FP_OUTPUT, "  int screenWidth;"
        FPRINT FP_OUTPUT, "  HDC hdcScreen;"
        FPRINT FP_OUTPUT, "  HBITMAP hBitmap;"
        FPRINT FP_OUTPUT, "  hdcScreen = GetDC(NULL);"
        FPRINT FP_OUTPUT, "  screenWidth = GetDeviceCaps(hdcScreen,HORZRES);"
        FPRINT FP_OUTPUT, "  screenHeight = GetDeviceCaps(hdcScreen,VERTRES);"
        FPRINT FP_OUTPUT, "  hBitmap = CreateCompatibleBitmap(hdcScreen,screenWidth,screenHeight);"
        FPRINT FP_OUTPUT, "  ReleaseDC(NULL,hdcScreen);"
        FPRINT FP_OUTPUT, "  return hBitmap;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Makebmp THEN
        FPRINT FP_OUTPUT, "HBITMAP MakeBmp(HDC hDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  BITMAP  bmpInfo;"
        FPRINT FP_OUTPUT, "  HBITMAP hBitmap;"
        FPRINT FP_OUTPUT, "  HDC     hTempDC;"
        FPRINT FP_OUTPUT, "  long    BmpWidth;"
        FPRINT FP_OUTPUT, "  long    BmpHeight;"
        FPRINT FP_OUTPUT, "  GetObject(GetCurrentObject(hDC, OBJ_BITMAP), sizeof(BITMAP), &bmpInfo);"
        FPRINT FP_OUTPUT, "  BmpWidth = bmpInfo.bmWidth;"
        FPRINT FP_OUTPUT, "  BmpHeight = bmpInfo.bmHeight;"
        FPRINT FP_OUTPUT, "  hBitmap = CreateCompatibleBitmap(hDC, BmpWidth, BmpHeight);"
        FPRINT FP_OUTPUT, "  hTempDC = CreateCompatibleDC(hDC);"
        FPRINT FP_OUTPUT, "  SelectObject(hTempDC, hBitmap);"
        FPRINT FP_OUTPUT, "  BitBlt(hTempDC, 0, 0, BmpWidth, BmpHeight, hDC, 0, 0, SRCCOPY);"
        FPRINT FP_OUTPUT, "  DeleteDC(hTempDC);"
        FPRINT FP_OUTPUT, "  return hBitmap;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Makehdc THEN
        FPRINT FP_OUTPUT, "HDC MakeHdc (HBITMAP hBitmap)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HDC hDC;"
        FPRINT FP_OUTPUT, "  hDC = CreateCompatibleDC(NULL);"
        FPRINT FP_OUTPUT, "  if(hDC == NULL){"
        FPRINT FP_OUTPUT, "     return NULL;"
        FPRINT FP_OUTPUT, "   }"
        FPRINT FP_OUTPUT, "  SelectObject(hDC,hBitmap);"
        FPRINT FP_OUTPUT, "  return hDC;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Set_BCX_BmpButton THEN
        FPRINT FP_OUTPUT, "void Set_BCX_BmpButton(HWND hWnd, PCTSTR File, int Res)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  RECT rc;"
        FPRINT FP_OUTPUT, "  GetClientRect(hWnd, &rc);"
        FPRINT FP_OUTPUT, "  HBITMAP Bm_Handle;"
        FPRINT FP_OUTPUT, "  if (!Res)"
        FPRINT FP_OUTPUT, "      Bm_Handle = (HBITMAP)LoadImage(0, (char*)File, IMAGE_BITMAP, rc.right, rc.bottom, LR_LOADFROMFILE);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "      Bm_Handle = (HBITMAP)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(Res), IMAGE_BITMAP, rc.right, rc.bottom, 0);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  DeleteObject((HBITMAP)SendMessage"
        FPRINT FP_OUTPUT, "               (hWnd, (UINT_PTR)BM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)Bm_Handle));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Set_BCX_Icon THEN
        FPRINT FP_OUTPUT, "void Set_BCX_Icon(HWND hWnd, PCTSTR File, int Res, int W, int H)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HICON hIcon;"
        FPRINT FP_OUTPUT, "  ULONG dwSize;"
        FPRINT FP_OUTPUT, "  PBYTE pBytes;"
        FPRINT FP_OUTPUT, "  if (!Res)"
        FPRINT FP_OUTPUT, "    hIcon = (HICON)LoadImage(0,File,IMAGE_ICON,W,H,LR_LOADFROMFILE);"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    pBytes = (PBYTE)GetResource(Res,RT_ANICURSOR,&dwSize);"
        FPRINT FP_OUTPUT, "    if (pBytes==NULL)"
        FPRINT FP_OUTPUT, "      hIcon = (HICON)LoadImage(BCX_hInstance,MAKEINTRESOURCE(Res),IMAGE_ICON,W,H,0);"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "      hIcon = CreateIconFromResourceEx (pBytes,dwSize,FALSE,0x00030000,W,H,LR_DEFAULTCOLOR);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  DestroyIcon((HICON)SendMessage"
        FPRINT FP_OUTPUT, "              (hWnd,(UINT_PTR)STM_SETIMAGE,(WPARAM)IMAGE_ICON,(LPARAM)hIcon));"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_BCX_Get THEN
        FPRINT FP_OUTPUT, "HBITMAP BCX_Get(HWND hWnd, int Left, int Top,"
        FPRINT FP_OUTPUT, "                int Width, int Height, int Style, HDC SrcHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!SrcHDC) SrcHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, "  HDC MemHDC = CreateCompatibleDC(SrcHDC);"
        FPRINT FP_OUTPUT, "  HBITMAP OldBMP;"
        FPRINT FP_OUTPUT, "  static HBITMAP RetBMP;"
        FPRINT FP_OUTPUT, "  if (RetBMP) DeleteObject(RetBMP);"
        FPRINT FP_OUTPUT, "  RetBMP = CreateCompatibleBitmap (SrcHDC,Width,Height);"
        FPRINT FP_OUTPUT, "  OldBMP = (HBITMAP)SelectObject(MemHDC,RetBMP);"
        FPRINT FP_OUTPUT, "  BitBlt (MemHDC,0,0,Width,Height,SrcHDC,Left,Top,Style);"
        FPRINT FP_OUTPUT, "  SelectObject(MemHDC,OldBMP);"
        FPRINT FP_OUTPUT, "  DeleteDC(MemHDC);"
        FPRINT FP_OUTPUT, "  if (hWnd) ReleaseDC(hWnd,SrcHDC);"
        FPRINT FP_OUTPUT, "  return RetBMP;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_BCX_Put THEN
        FPRINT FP_OUTPUT, "void BCX_Put(HWND DesthWnd, HBITMAP hBitmap, int LtDest, int TopDest,"
        FPRINT FP_OUTPUT, "             int WidDest, int HgtDest, int Style, HDC DesHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!DesHDC) DesHDC = GetDC(DesthWnd);"
        FPRINT FP_OUTPUT, "  HDC MemHDC = CreateCompatibleDC(DesHDC);"
        FPRINT FP_OUTPUT, "  HBITMAP OldBmp = (HBITMAP)SelectObject(MemHDC,hBitmap);"
        FPRINT FP_OUTPUT, "  SetMapMode(MemHDC,GetMapMode(DesHDC));"
        FPRINT FP_OUTPUT, "  BitBlt (DesHDC,LtDest,TopDest,WidDest,HgtDest,MemHDC,0,0,Style);"
        FPRINT FP_OUTPUT, "  SelectObject(MemHDC,OldBmp);"
        FPRINT FP_OUTPUT, "  if (DesthWnd) ReleaseDC(DesthWnd,DesHDC);"
        FPRINT FP_OUTPUT, "  DeleteDC(MemHDC);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_BCX_LoadBMP THEN
        FPRINT FP_OUTPUT, "HBITMAP BCX_LoadBMP (PCTSTR F, int ii, int t)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (t) t = LR_LOADTRANSPARENT|LR_LOADMAP3DCOLORS;"
        FPRINT FP_OUTPUT, "  if (ii)"
        FPRINT FP_OUTPUT, "    return (HBITMAP)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(ii),IMAGE_BITMAP,0,0,t);"
        FPRINT FP_OUTPUT, "  return (HBITMAP)LoadImage(NULL,F,IMAGE_BITMAP,0,0,LR_LOADFROMFILE|t);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_BCX_LoadImage THEN
        FPRINT FP_OUTPUT, "HBITMAP BCX_LoadImage (PCTSTR szFile, int Res)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HANDLE   hFile;"
        FPRINT FP_OUTPUT, "  ULONG    dwFileSize;"
        FPRINT FP_OUTPUT, "  PVOID    pvData;"
        FPRINT FP_OUTPUT, "  HGLOBAL  hGlobal;"
        FPRINT FP_OUTPUT, "  ULONG    dwBytesRead = 0;"
        FPRINT FP_OUTPUT, "  LPSTREAM pstm;"
        FPRINT FP_OUTPUT, "  HBITMAP  hTempBitmap;"
        FPRINT FP_OUTPUT, "  PVOID   lpPicData;"
        FPRINT FP_OUTPUT, "  LPPICTURE gpPicture;"
        FPRINT FP_OUTPUT, "  if(Res)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      lpPicData = GetResource(Res,RT_RCDATA,&dwFileSize);"
        FPRINT FP_OUTPUT, "      if(lpPicData==NULL) return 0;"
        FPRINT FP_OUTPUT, "      hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD,dwFileSize);"
        FPRINT FP_OUTPUT, "      pvData = GlobalLock(hGlobal);"
        FPRINT FP_OUTPUT, "      CopyMemory(pvData,lpPicData,dwFileSize);"
        FPRINT FP_OUTPUT, "      GlobalUnlock(hGlobal);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if(GetFileAttributes(szFile) == 0xffffffff) return 0;"
        FPRINT FP_OUTPUT, "      hFile = CreateFile(szFile,GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);"
        FPRINT FP_OUTPUT, "      dwFileSize = GetFileSize(hFile,NULL);"
        FPRINT FP_OUTPUT, "      hGlobal = GlobalAlloc(GMEM_MOVEABLE|GMEM_NODISCARD,dwFileSize);"
        FPRINT FP_OUTPUT, "      pvData = GlobalLock(hGlobal);"
        FPRINT FP_OUTPUT, "      ReadFile(hFile,pvData,dwFileSize,&dwBytesRead,NULL);"
        FPRINT FP_OUTPUT, "      GlobalUnlock(hGlobal);"
        FPRINT FP_OUTPUT, "      CloseHandle(hFile);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  pstm = NULL;"
        FPRINT FP_OUTPUT, "  CreateStreamOnHGlobal(hGlobal,TRUE,&pstm);"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  OleLoadPicture(pstm,dwFileSize,FALSE,&IID_IPicture,(PVOID*)&gpPicture);"
        FPRINT FP_OUTPUT, "  pstm->lpVtbl->Release(pstm);"
        FPRINT FP_OUTPUT, "  gpPicture->lpVtbl->get_Handle(gpPicture,(OLE_HANDLE*)&hTempBitmap);"
        FPRINT FP_OUTPUT, "  hTempBitmap = (HBITMAP)CopyImage(hTempBitmap,IMAGE_BITMAP,0,0,LR_COPYRETURNORG);"
        FPRINT FP_OUTPUT, "  gpPicture->lpVtbl->Release(gpPicture);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  OleLoadPicture(pstm,dwFileSize,FALSE,IID_IPicture,(PVOID*)&gpPicture);"
        FPRINT FP_OUTPUT, "  pstm->Release();"
        FPRINT FP_OUTPUT, "  gpPicture->get_Handle((OLE_HANDLE*)&hTempBitmap);"
        FPRINT FP_OUTPUT, "  hTempBitmap = (HBITMAP)CopyImage(hTempBitmap,IMAGE_BITMAP,0,0,LR_COPYRETURNORG);"
        FPRINT FP_OUTPUT, "  gpPicture->Release();"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  return hTempBitmap;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_DrawTransBMP THEN
        FPRINT FP_OUTPUT, "void DrawTransBMP(HWND hWnd, HBITMAP hBitmap, ULONG cTransparentColor, int xStart, int yStart, HDC DrawHDC)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    BITMAP bm;"
        FPRINT FP_OUTPUT, "    ULONG cColor;"
        FPRINT FP_OUTPUT, "    HBITMAP bmAndBack = NULL, bmAndObject = NULL, bmAndMem = NULL, bmSave = NULL;"
        FPRINT FP_OUTPUT, "    HBITMAP bmBackOld = NULL, bmObjectOld = NULL, bmMemOld = NULL, bmSaveOld = NULL, hmTMP = NULL;"
        FPRINT FP_OUTPUT, "    HBITMAP bmTempOld = NULL;"
        FPRINT FP_OUTPUT, "    HDC hdcMem = NULL, hdcBack = NULL, hdcObject = NULL, hdcTemp = NULL, hdcSave = NULL;"
        FPRINT FP_OUTPUT, "    POINT ptSize;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (!DrawHDC)"
        FPRINT FP_OUTPUT, "        DrawHDC = GetDC(hWnd);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hdcTemp = CreateCompatibleDC(DrawHDC);"
        FPRINT FP_OUTPUT, "    bmTempOld = (HBITMAP)SelectObject(hdcTemp, hBitmap);"
        FPRINT FP_OUTPUT, "    GetObject(hBitmap, sizeof(BITMAP), (PSTR)&bm);"
        FPRINT FP_OUTPUT, "    ptSize.x = bm.bmWidth;"
        FPRINT FP_OUTPUT, "    ptSize.y = bm.bmHeight;"
        FPRINT FP_OUTPUT, "    DPtoLP(hdcTemp, &ptSize, 1);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hdcBack = CreateCompatibleDC(DrawHDC);"
        FPRINT FP_OUTPUT, "    hdcObject = CreateCompatibleDC(DrawHDC);"
        FPRINT FP_OUTPUT, "    hdcMem = CreateCompatibleDC(DrawHDC);"
        FPRINT FP_OUTPUT, "    hdcSave = CreateCompatibleDC(DrawHDC);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);"
        FPRINT FP_OUTPUT, "    bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL);"
        FPRINT FP_OUTPUT, "    bmAndMem = CreateCompatibleBitmap(DrawHDC, ptSize.x, ptSize.y);"
        FPRINT FP_OUTPUT, "    bmSave = CreateCompatibleBitmap(DrawHDC, ptSize.x, ptSize.y);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack);"
        FPRINT FP_OUTPUT, "    bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject);"
        FPRINT FP_OUTPUT, "    bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem);"
        FPRINT FP_OUTPUT, "    bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    SetMapMode(hdcTemp, GetMapMode(DrawHDC));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);"
        FPRINT FP_OUTPUT, "    cColor = SetBkColor(hdcTemp, cTransparentColor);"
        FPRINT FP_OUTPUT, "    BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY);"
        FPRINT FP_OUTPUT, "    SetBkColor(hdcTemp, cColor);"
        FPRINT FP_OUTPUT, "    BitBlt(hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, DrawHDC, xStart, yStart, SRCCOPY);"
        FPRINT FP_OUTPUT, "    BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND);"
        FPRINT FP_OUTPUT, "    BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND);"
        FPRINT FP_OUTPUT, "    BitBlt(hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT);"
        FPRINT FP_OUTPUT, "    BitBlt(DrawHDC, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY);"
        FPRINT FP_OUTPUT, "    BitBlt(hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    SelectObject(hdcTemp, bmTempOld);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hmTMP = (HBITMAP)SelectObject(hdcBack, bmBackOld);"
        FPRINT FP_OUTPUT, "    DeleteObject(hmTMP);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hmTMP = (HBITMAP)SelectObject(hdcObject, bmObjectOld);"
        FPRINT FP_OUTPUT, "    DeleteObject(hmTMP);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hmTMP = (HBITMAP)SelectObject(hdcMem, bmMemOld);"
        FPRINT FP_OUTPUT, "    DeleteObject(hmTMP);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hmTMP = (HBITMAP)SelectObject(hdcSave, bmSaveOld);"
        FPRINT FP_OUTPUT, "    DeleteObject(hmTMP);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    DeleteDC(hdcMem);"
        FPRINT FP_OUTPUT, "    DeleteDC(hdcBack);"
        FPRINT FP_OUTPUT, "    DeleteDC(hdcObject);"
        FPRINT FP_OUTPUT, "    DeleteDC(hdcSave);"
        FPRINT FP_OUTPUT, "    DeleteDC(hdcTemp);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (hWnd)"
        FPRINT FP_OUTPUT, "        ReleaseDC(hWnd, DrawHDC);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_BCX_BmpWidth THEN
        FPRINT FP_OUTPUT, "int BCX_BmpWidth (HBITMAP hBmp)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  BITMAP bm;"
        FPRINT FP_OUTPUT, "  if (hBmp)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    GetObject(hBmp,sizeof(bm),&bm);"
        FPRINT FP_OUTPUT, "    return bm.bmWidth;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_BCX_BmpHeight THEN
        FPRINT FP_OUTPUT, "int BCX_BmpHeight (HBITMAP hBmp)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  BITMAP bm;"
        FPRINT FP_OUTPUT, "  if (hBmp)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    GetObject(hBmp,sizeof(bm),&bm);"
        FPRINT FP_OUTPUT, "    return bm.bmHeight;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_DrawStr THEN
        FPRINT FP_OUTPUT, "void Draw(char* DrawString) {"
        FPRINT FP_OUTPUT, "    if(strlen(DrawString) > 8192) return;"
        FPRINT FP_OUTPUT, "    static HWND hParent;"
        FPRINT FP_OUTPUT, "    static HWND Canvas;"
        FPRINT FP_OUTPUT, "    if (hParent == NULL) {"
        FPRINT FP_OUTPUT, "        hParent = GetActiveWindow();"
        FPRINT FP_OUTPUT, "        Canvas = BCX_Bitmap(0, hParent, "
        FPRINT FP_OUTPUT, "                            0, 0, 0, "
        FPRINT FP_OUTPUT, "                            GetSystemMetrics(SM_CXSCREEN), "
        FPRINT FP_OUTPUT, "                            GetSystemMetrics(SM_CYSCREEN));"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    static int X;"
        FPRINT FP_OUTPUT, "    static int Y;"
        FPRINT FP_OUTPUT, "    static int PreviousX;"
        FPRINT FP_OUTPUT, "    static int PreviousY;"
        FPRINT FP_OUTPUT, "    static int IsRelative;"
        FPRINT FP_OUTPUT, "    static int ReturnFlag;"
        FPRINT FP_OUTPUT, "    static double Scale = 1;"
        FPRINT FP_OUTPUT, "    static HDC hDestDC;"
        FPRINT FP_OUTPUT, "    static int PENCOLOR = RGB(255, 255, 255);"
        FPRINT FP_OUTPUT, "    int Distance = 0;"
        FPRINT FP_OUTPUT, "    int Ndx = 0;"
        FPRINT FP_OUTPUT, "    char Shape[BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "    char** Stk = 0;"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "       Stk = NULL;"
        FPRINT FP_OUTPUT, "        size_t dimensions[2] = {(size_t)8192, (size_t)1};"
        FPRINT FP_OUTPUT, "        Stk = (char**)CreateArr(Stk, 4, 0, 2, dimensions);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    char Verb[BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "    char Tmp[BCXSTRSIZE] ={0};"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    strcpy(Shape, ucase(DrawString));"
        FPRINT FP_OUTPUT, "    strcpy(Shape, RemoveStr(Shape, ", ENC$(";"), "));"
        FPRINT FP_OUTPUT, "    strcpy(Shape, RemoveStr(Shape, ", ENC$("="), "));"
        FPRINT FP_OUTPUT, "    strcpy(Shape, RemoveStr(Shape, ", ENC$(SPC$), "));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hDestDC = StartDraw(Canvas);"
        FPRINT FP_OUTPUT, "    Ndx = DSplit(Stk, Shape, ", ENC$("ABCDEFGHLMNPRSU,"), ", 1);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    for (int i = 1; i <= Ndx; i++) {"
        FPRINT FP_OUTPUT, "        strcpy(Verb, ucase(Stk[i]));"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        // Map strings to character constants"
        FPRINT FP_OUTPUT, "        char command = Verb[0];"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "        switch (command) {"
        FPRINT FP_OUTPUT, "            case 'B':"
        FPRINT FP_OUTPUT, "                PreviousX = X;"
        FPRINT FP_OUTPUT, "                PreviousY = Y;"
        FPRINT FP_OUTPUT, "                i++;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "                if (isdigit(*Stk[i])) {"
        FPRINT FP_OUTPUT, "                    X = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                    i += 2;"
        FPRINT FP_OUTPUT, "                    Y = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                    BCX_Preset(0, X, Y, hDestDC);"
        FPRINT FP_OUTPUT, "                } else {"
        FPRINT FP_OUTPUT, "                    i++;"
        FPRINT FP_OUTPUT, "                    switch (Stk[i][0]) {"
        FPRINT FP_OUTPUT, "                        case 'U':"
        FPRINT FP_OUTPUT, "                            Distance = VAL(Stk[i + 1]);"
        FPRINT FP_OUTPUT, "                            Y = Y - Distance * Scale;"
        FPRINT FP_OUTPUT, "                            break;"
        FPRINT FP_OUTPUT, "                        case 'D':"
        FPRINT FP_OUTPUT, "                            Distance = VAL(Stk[i + 1]);"
        FPRINT FP_OUTPUT, "                            Y = Y + Distance * Scale;"
        FPRINT FP_OUTPUT, "                            break;"
        FPRINT FP_OUTPUT, "                        case 'L':"
        FPRINT FP_OUTPUT, "                            Distance = VAL(Stk[i + 1]);"
        FPRINT FP_OUTPUT, "                            X = X - Distance * Scale;"
        FPRINT FP_OUTPUT, "                            break;"
        FPRINT FP_OUTPUT, "                        case 'R':"
        FPRINT FP_OUTPUT, "                            Distance = VAL(Stk[i + 1]);"
        FPRINT FP_OUTPUT, "                            X = X + Distance * Scale;"
        FPRINT FP_OUTPUT, "                            break;"
        FPRINT FP_OUTPUT, "                        case 'E':"
        FPRINT FP_OUTPUT, "                            strcpy(Tmp, Stk[i + 1]);"
        FPRINT FP_OUTPUT, "                            if (isdigit(*Stk[i + 2])) {"
        FPRINT FP_OUTPUT, "                                strcat(Tmp, Stk[i + 2]);"
        FPRINT FP_OUTPUT, "                                strcpy(Stk[i + 1], ", ENC$(SPC$), ");"
        FPRINT FP_OUTPUT, "                                strcpy(Stk[i + 2], ", ENC$(SPC$), ");"
        FPRINT FP_OUTPUT, "                            }"
        FPRINT FP_OUTPUT, "                            Distance = VAL(Tmp);"
        FPRINT FP_OUTPUT, "                            X = X + Distance * Scale;"
        FPRINT FP_OUTPUT, "                            Y = -Scale + Y - Distance * Scale;"
        FPRINT FP_OUTPUT, "                            break;"
        FPRINT FP_OUTPUT, "                        case 'F':"
        FPRINT FP_OUTPUT, "                            strcpy(Tmp, Stk[i + 1]);"
        FPRINT FP_OUTPUT, "                            if (isdigit(*Stk[i + 2])) {"
        FPRINT FP_OUTPUT, "                                strcat(Tmp, Stk[i + 2]);"
        FPRINT FP_OUTPUT, "                                strcpy(Stk[i + 1], ", ENC$(SPC$), ");"
        FPRINT FP_OUTPUT, "                                strcpy(Stk[i + 2], ", ENC$(SPC$), ");"
        FPRINT FP_OUTPUT, "                            }"
        FPRINT FP_OUTPUT, "                            Distance = VAL(Tmp);"
        FPRINT FP_OUTPUT, "                            X = X + Distance * Scale;"
        FPRINT FP_OUTPUT, "                            Y = -Scale + Y + Distance * Scale;"
        FPRINT FP_OUTPUT, "                            break;"
        FPRINT FP_OUTPUT, "                        case 'G':"
        FPRINT FP_OUTPUT, "                            strcpy(Tmp, Stk[i + 1]);"
        FPRINT FP_OUTPUT, "                            if (isdigit(*Stk[i + 2])) {"
        FPRINT FP_OUTPUT, "                                strcat(Tmp, Stk[i + 2]);"
        FPRINT FP_OUTPUT, "                                strcpy(Stk[i + 1], ", ENC$(SPC$), ");"
        FPRINT FP_OUTPUT, "                                strcpy(Stk[i + 2], ", ENC$(SPC$), ");"
        FPRINT FP_OUTPUT, "                            }"
        FPRINT FP_OUTPUT, "                            Distance = VAL(Tmp);"
        FPRINT FP_OUTPUT, "                            X = X - Distance * Scale;"
        FPRINT FP_OUTPUT, "                            Y = -Scale + Y + Distance * Scale;"
        FPRINT FP_OUTPUT, "                            break;"
        FPRINT FP_OUTPUT, "                        case 'H':"
        FPRINT FP_OUTPUT, "                            strcpy(Tmp, Stk[i + 1]);"
        FPRINT FP_OUTPUT, "                            if (isdigit(*Stk[i + 2])) {"
        FPRINT FP_OUTPUT, "                                strcat(Tmp, Stk[i + 2]);"
        FPRINT FP_OUTPUT, "                                strcpy(Stk[i + 1], ", ENC$(SPC$), ");"
        FPRINT FP_OUTPUT, "                                strcpy(Stk[i + 2], ", ENC$(SPC$), ");"
        FPRINT FP_OUTPUT, "                            }"
        FPRINT FP_OUTPUT, "                            Distance = VAL(Tmp);"
        FPRINT FP_OUTPUT, "                            X = X + Distance * Scale;"
        FPRINT FP_OUTPUT, "                            Y = -Scale + Y + Distance * Scale;"
        FPRINT FP_OUTPUT, "                            break;"
        FPRINT FP_OUTPUT, "                    }"
        FPRINT FP_OUTPUT, "                    BCX_Preset(0, X, Y, hDestDC);"
        FPRINT FP_OUTPUT, "                    PreviousX = X;"
        FPRINT FP_OUTPUT, "                    PreviousY = Y;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'C':"
        FPRINT FP_OUTPUT, "                i++;"
        FPRINT FP_OUTPUT, "                PENCOLOR = qbcolor(VAL(Stk[i]));"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'D':"
        FPRINT FP_OUTPUT, "                PreviousX = X;"
        FPRINT FP_OUTPUT, "                PreviousY = Y;"
        FPRINT FP_OUTPUT, "                i++;"
        FPRINT FP_OUTPUT, "                Distance = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                if (Distance <= 0) {"
        FPRINT FP_OUTPUT, "                    Distance = 1;"
        FPRINT FP_OUTPUT, "                    i--;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                Distance *= Scale;"
        FPRINT FP_OUTPUT, "                BCX_Line(0, X, Y, X, Y + Distance, PENCOLOR, hDestDC);"
        FPRINT FP_OUTPUT, "                Y += Distance;"
        FPRINT FP_OUTPUT, "                if (ReturnFlag) {"
        FPRINT FP_OUTPUT, "                    X = PreviousX;"
        FPRINT FP_OUTPUT, "                    Y = PreviousY;"
        FPRINT FP_OUTPUT, "                    ReturnFlag = FALSE;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'E':"
        FPRINT FP_OUTPUT, "                PreviousX = X;"
        FPRINT FP_OUTPUT, "                PreviousY = Y;"
        FPRINT FP_OUTPUT, "                i++;"
        FPRINT FP_OUTPUT, "                Distance = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                if (Distance <= 0) {"
        FPRINT FP_OUTPUT, "                    Distance = 1;"
        FPRINT FP_OUTPUT, "                    i--;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                Distance *= Scale;"
        FPRINT FP_OUTPUT, "                BCX_Line(0, X, Y, X + Distance, Y - Distance, PENCOLOR, hDestDC);"
        FPRINT FP_OUTPUT, "                X += Distance;"
        FPRINT FP_OUTPUT, "                Y -= Distance;"
        FPRINT FP_OUTPUT, "                if (ReturnFlag) {"
        FPRINT FP_OUTPUT, "                    X = PreviousX;"
        FPRINT FP_OUTPUT, "                    Y = PreviousY;"
        FPRINT FP_OUTPUT, "                    ReturnFlag = FALSE;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'F':"
        FPRINT FP_OUTPUT, "                PreviousX = X;"
        FPRINT FP_OUTPUT, "                PreviousY = Y;"
        FPRINT FP_OUTPUT, "                i++;"
        FPRINT FP_OUTPUT, "                Distance = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                if (Distance <= 0) {"
        FPRINT FP_OUTPUT, "                    Distance = 1;"
        FPRINT FP_OUTPUT, "                    i--;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                Distance *= Scale;"
        FPRINT FP_OUTPUT, "                BCX_Line(0, X, Y, X + Distance, Y + Distance, PENCOLOR, hDestDC);"
        FPRINT FP_OUTPUT, "                X += Distance;"
        FPRINT FP_OUTPUT, "                Y += Distance;"
        FPRINT FP_OUTPUT, "                if (ReturnFlag) {"
        FPRINT FP_OUTPUT, "                    X = PreviousX;"
        FPRINT FP_OUTPUT, "                    Y = PreviousY;"
        FPRINT FP_OUTPUT, "                    ReturnFlag = FALSE;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'G':"
        FPRINT FP_OUTPUT, "                PreviousX = X;"
        FPRINT FP_OUTPUT, "                PreviousY = Y;"
        FPRINT FP_OUTPUT, "                i++;"
        FPRINT FP_OUTPUT, "                Distance = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                if (Distance <= 0) {"
        FPRINT FP_OUTPUT, "                    Distance = 1;"
        FPRINT FP_OUTPUT, "                    i--;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                Distance *= Scale;"
        FPRINT FP_OUTPUT, "                BCX_Line(0, X, Y, X - Distance, Y + Distance, PENCOLOR, hDestDC);"
        FPRINT FP_OUTPUT, "                X -= Distance;"
        FPRINT FP_OUTPUT, "                Y += Distance;"
        FPRINT FP_OUTPUT, "                if (ReturnFlag) {"
        FPRINT FP_OUTPUT, "                    X = PreviousX;"
        FPRINT FP_OUTPUT, "                    Y = PreviousY;"
        FPRINT FP_OUTPUT, "                    ReturnFlag = FALSE;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'H':"
        FPRINT FP_OUTPUT, "                PreviousX = X;"
        FPRINT FP_OUTPUT, "                PreviousY = Y;"
        FPRINT FP_OUTPUT, "                i++;"
        FPRINT FP_OUTPUT, "                Distance = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                if (Distance <= 0) {"
        FPRINT FP_OUTPUT, "                    Distance = 1;"
        FPRINT FP_OUTPUT, "                    i--;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                Distance *= Scale;"
        FPRINT FP_OUTPUT, "                BCX_Line(0, X, Y, X - Distance, Y - Distance, PENCOLOR, hDestDC);"
        FPRINT FP_OUTPUT, "                X -= Distance;"
        FPRINT FP_OUTPUT, "                Y -= Distance;"
        FPRINT FP_OUTPUT, "                if (ReturnFlag) {"
        FPRINT FP_OUTPUT, "                    X = PreviousX;"
        FPRINT FP_OUTPUT, "                    Y = PreviousY;"
        FPRINT FP_OUTPUT, "                    ReturnFlag = FALSE;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'L':"
        FPRINT FP_OUTPUT, "                PreviousX = X;"
        FPRINT FP_OUTPUT, "                PreviousY = Y;"
        FPRINT FP_OUTPUT, "                i++;"
        FPRINT FP_OUTPUT, "                Distance = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                if (Distance <= 0) {"
        FPRINT FP_OUTPUT, "                    Distance = 1;"
        FPRINT FP_OUTPUT, "                    i--;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                Distance *= Scale;"
        FPRINT FP_OUTPUT, "                BCX_Line(0, X, Y, X - Distance, Y, PENCOLOR, hDestDC);"
        FPRINT FP_OUTPUT, "                X -= Distance;"
        FPRINT FP_OUTPUT, "                if (ReturnFlag) {"
        FPRINT FP_OUTPUT, "                    X = PreviousX;"
        FPRINT FP_OUTPUT, "                    Y = PreviousY;"
        FPRINT FP_OUTPUT, "                    ReturnFlag = FALSE;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'M':"
        FPRINT FP_OUTPUT, "                PreviousX = X;"
        FPRINT FP_OUTPUT, "                PreviousY = Y;"
        FPRINT FP_OUTPUT, "                i++;"
        FPRINT FP_OUTPUT, "                IsRelative = FALSE;"
        FPRINT FP_OUTPUT, "                if ((strcmp(mid(Stk[i], 1, 1), ", ENC$("+"), ") == 0 || strcmp(mid(Stk[i], 1, 1), ", ENC$("-"), ") == 0)) {"
        FPRINT FP_OUTPUT, "                    IsRelative = TRUE;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                if (IsRelative) {"
        FPRINT FP_OUTPUT, "                    X = X + VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                    i += 2;"
        FPRINT FP_OUTPUT, "                    Y = Y + VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                } else {"
        FPRINT FP_OUTPUT, "                    X = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                    i += 2;"
        FPRINT FP_OUTPUT, "                    Y = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                BCX_Lineto(0, X, Y, PENCOLOR, hDestDC);"
        FPRINT FP_OUTPUT, "                if (ReturnFlag) {"
        FPRINT FP_OUTPUT, "                    X = PreviousX;"
        FPRINT FP_OUTPUT, "                    Y = PreviousY;"
        FPRINT FP_OUTPUT, "                    ReturnFlag = FALSE;"
        FPRINT FP_OUTPUT, "                }"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'N':"
        FPRINT FP_OUTPUT, "                ReturnFlag = TRUE;"
        FPRINT FP_OUTPUT, "                break;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "            case 'P':"
        FPRINT FP_OUTPUT, "                BCX_FloodFill(0, X, Y, qbcolor(VAL(Stk[i + 3])), qbcolor(VAL(Stk[i + 1])), 1, hDestDC);"
        FPRINT FP_OUTPUT, "                 break;"
        FPRINT FP_OUTPUT, "                 "
        FPRINT FP_OUTPUT, "            case 'R':     "
        FPRINT FP_OUTPUT, "                "
        FPRINT FP_OUTPUT, "                  PreviousX = X;"
        FPRINT FP_OUTPUT, "            PreviousY = Y;"
        FPRINT FP_OUTPUT, "            i++;"
        FPRINT FP_OUTPUT, "            Distance = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "            if (Distance <= 0) {"
        FPRINT FP_OUTPUT, "                Distance = 1;"
        FPRINT FP_OUTPUT, "                i--;"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "            Distance *= Scale;"
        FPRINT FP_OUTPUT, "            BCX_Line(0, X, Y, X + Distance, Y, PENCOLOR, hDestDC);"
        FPRINT FP_OUTPUT, "            X += Distance;"
        FPRINT FP_OUTPUT, "            if (ReturnFlag) {"
        FPRINT FP_OUTPUT, "                X = PreviousX;"
        FPRINT FP_OUTPUT, "                Y = PreviousY;"
        FPRINT FP_OUTPUT, "                ReturnFlag = FALSE;"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "             break;"
        FPRINT FP_OUTPUT, "             "
        FPRINT FP_OUTPUT, "             case 'S':"
        FPRINT FP_OUTPUT, "              i++;"
        FPRINT FP_OUTPUT, "            Scale = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "            if (Scale <= 0) {"
        FPRINT FP_OUTPUT, "                Scale = 1;"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "            break;"
        FPRINT FP_OUTPUT, "            "
        FPRINT FP_OUTPUT, "            case 'U':"
        FPRINT FP_OUTPUT, "              PreviousX = X;"
        FPRINT FP_OUTPUT, "            PreviousY = Y;"
        FPRINT FP_OUTPUT, "            i++;"
        FPRINT FP_OUTPUT, "            Distance = VAL(Stk[i]);"
        FPRINT FP_OUTPUT, "            if (Distance <= 0) {"
        FPRINT FP_OUTPUT, "                Distance = 1;"
        FPRINT FP_OUTPUT, "                i--;"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "            Distance *= Scale;"
        FPRINT FP_OUTPUT, "            BCX_Line(0, X, Y, X, Y - Distance, PENCOLOR, hDestDC);"
        FPRINT FP_OUTPUT, "            Y -= Distance;"
        FPRINT FP_OUTPUT, "            if (ReturnFlag) {"
        FPRINT FP_OUTPUT, "                X = PreviousX;"
        FPRINT FP_OUTPUT, "                Y = PreviousY;"
        FPRINT FP_OUTPUT, "                ReturnFlag = FALSE;"
        FPRINT FP_OUTPUT, "            }"
        FPRINT FP_OUTPUT, "            break; "
        FPRINT FP_OUTPUT, "         }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    EndDraw(Canvas, hDestDC);"
        FPRINT FP_OUTPUT, "    if (Stk) {"
        FPRINT FP_OUTPUT, "        DestroyArr((void**)Stk, 2, 1);"
        FPRINT FP_OUTPUT, "        Stk = NULL;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF
END SUB ' Emit_RT_Graphics2




SUB Emit_RT_SystemCOM1 (FP_OUTPUT AS FILE)
    IF Use_RegExist THEN
        FPRINT FP_OUTPUT, "long RegExist (HKEY HK, PCHAR Key, PCHAR SubKey)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HKEY hKey;"
        FPRINT FP_OUTPUT, "  long Result;"
        FPRINT FP_OUTPUT, "  Result = RegOpenKeyEx(HK, Key, 0, KEY_QUERY_VALUE, &hKey);"
        FPRINT FP_OUTPUT, "  if (Result == ERROR_SUCCESS)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    static char SubKeyResult [BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "    memset(&SubKeyResult,0,sizeof(SubKeyResult));"
        FPRINT FP_OUTPUT, "    int BufferLen = sizeof(SubKeyResult);"
        FPRINT FP_OUTPUT, "    Result = -RegQueryValueEx (hKey,SubKey,0,0,(PBYTE)SubKeyResult,(PDWORD)&BufferLen);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  RegCloseKey(hKey);"
        FPRINT FP_OUTPUT, "  return Result;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_DeleteRegKey THEN
        FPRINT FP_OUTPUT, "void DeleteRegKey (HKEY HK, PCTSTR Key)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  RegDeleteKey(HK,Key);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_CreateRegInt THEN
        FPRINT FP_OUTPUT, "void CreateRegInt (HKEY HK, PCTSTR Key, PCTSTR VarName, int Value)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char  Buf[100]={0};"
        FPRINT FP_OUTPUT, "  ULONG Result;"
        FPRINT FP_OUTPUT, "  HKEY  hKey;"
        FPRINT FP_OUTPUT, "  RegCreateKeyEx(HK,Key,0,Buf,REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,0,&hKey,&Result);"
        FPRINT FP_OUTPUT, "  RegSetValueEx(hKey,VarName,0,REG_DWORD,(BYTE*)&Value,sizeof(int));"
        FPRINT FP_OUTPUT, "  RegCloseKey(hKey);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_RegInt THEN
        FPRINT FP_OUTPUT, "int RegInt(HKEY HK, PCTSTR Key, PCTSTR SubKey)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HKEY  hKey   =  0;"
        FPRINT FP_OUTPUT, "  ULONG Result =  0;"
        FPRINT FP_OUTPUT, "  ULONG Size   =  sizeof(ULONG);"
        FPRINT FP_OUTPUT, "  RegOpenKeyEx    (HK,Key,0,KEY_QUERY_VALUE,&HK);"
        FPRINT FP_OUTPUT, "  RegQueryValueEx (HK,SubKey,0,0,(PBYTE)&Result,&Size);"
        FPRINT FP_OUTPUT, "  RegCloseKey     (hKey);"
        FPRINT FP_OUTPUT, "  return Result;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_Printer THEN
        FPRINT FP_OUTPUT, "int PrinterOpen (PCTSTR fontname, int PointSize, int charset)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char zPrinter[BCXSTRSIZE];"
        FPRINT FP_OUTPUT, "  GetProfileString(", ENC$("WINDOWS"), ",", ENC$("DEVICE"), ",", DDQ$, ",zPrinter,127);"
        FPRINT FP_OUTPUT, "  strcpy(zPrinter,(char*)extract(zPrinter,", ENC$(","), "));"
        FPRINT FP_OUTPUT, "  strcpy(BcxPtr_Text,", ENC$("Printing ..."), ");"
        FPRINT FP_OUTPUT, "  BcxPtr_hDC = CreateDC(", DDQ$, ",zPrinter,", DDQ$, ",0);"
        FPRINT FP_OUTPUT, "  if (!BcxPtr_hDC) return 0;"
        FPRINT FP_OUTPUT, "  BcxPtr_di.cbSize = sizeof(BcxPtr_di);"
        FPRINT FP_OUTPUT, "  BcxPtr_di.lpszDocName = BcxPtr_Text;"
        FPRINT FP_OUTPUT, "  StartDoc(BcxPtr_hDC,&BcxPtr_di);"
        FPRINT FP_OUTPUT, "  StartPage(BcxPtr_hDC);"
        FPRINT FP_OUTPUT, "  SetTextAlign(BcxPtr_hDC,TA_BASELINE|TA_NOUPDATECP|TA_LEFT);"
        FPRINT FP_OUTPUT, "  SetBkMode(BcxPtr_hDC,TRANSPARENT);"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfHeight = PointSize*GetDeviceCaps(BcxPtr_hDC,LOGPIXELSY)/72;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfWidth = 0;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfEscapement = 0;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfOrientation = 0;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfWeight = FW_NORMAL;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfItalic = 0;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfUnderline = 0;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfStrikeOut = 0;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfCharSet = charset;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfOutPrecision = OUT_DEFAULT_PRECIS;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfQuality = PROOF_QUALITY;"
        FPRINT FP_OUTPUT, "  BcxPtr_Lf.lfPitchAndFamily = VARIABLE_PITCH|FF_ROMAN;"
        FPRINT FP_OUTPUT, "  strcpy(BcxPtr_Lf.lfFaceName,fontname); "
        FPRINT FP_OUTPUT, "  BcxPtr_hFont = CreateFontIndirect(&BcxPtr_Lf);"
        FPRINT FP_OUTPUT, "  BcxPtr_hFontOld = (HFONT)SelectObject(BcxPtr_hDC,BcxPtr_hFont);"
        FPRINT FP_OUTPUT, "  GetTextMetrics(BcxPtr_hDC, &BcxPtr_tm);"
        FPRINT FP_OUTPUT, "  BcxPtr_FontMetrix = BcxPtr_Lf.lfHeight;"
        FPRINT FP_OUTPUT, "  BcxPtr_PrinterOn = 1;"
        FPRINT FP_OUTPUT, "  return 1;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void PrinterWrite (PCTSTR TextIn, int CPL, int LPP)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char sTemp[BCXSTRSIZE]={0};"
        FPRINT FP_OUTPUT, "  if (!BcxPtr_PrinterOn)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    MessageBox (GetActiveWindow(),", ENC$("Problem with Printer"), ",", DDQ$, ",0);"
        FPRINT FP_OUTPUT, "    return;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  strcpy(sTemp,TextIn);"
        FPRINT FP_OUTPUT, "  for(;;)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if ((int)strlen(sTemp) > (int)CPL)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      strcpy(BcxPtr_Text,(char*)left(sTemp,CPL));"
        FPRINT FP_OUTPUT, "      strcpy(sTemp,(char*)mid(sTemp,CPL+1));"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      strcpy(BcxPtr_Text,sTemp);"
        FPRINT FP_OUTPUT, "      *sTemp = 0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (BcxPtr_LineCtr > LPP)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      EndPage(BcxPtr_hDC);"
        FPRINT FP_OUTPUT, "      BcxPtr_LineCtr = 0;"
        FPRINT FP_OUTPUT, "      StartPage(BcxPtr_hDC);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    BcxPtr_LineCtr += 1;"
        FPRINT FP_OUTPUT, "    TextOut(BcxPtr_hDC,20,BcxPtr_FontMetrix*BcxPtr_LineCtr,BcxPtr_Text,(int)strlen(BcxPtr_Text));"
        FPRINT FP_OUTPUT, "    if (sTemp[0]==0) break;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void PrinterClose (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  if (!BcxPtr_PrinterOn) return;"
        FPRINT FP_OUTPUT, "  SelectObject(BcxPtr_hDC,BcxPtr_hFontOld);"
        FPRINT FP_OUTPUT, "  DeleteObject(BcxPtr_hFont);"
        FPRINT FP_OUTPUT, "  EndPage(BcxPtr_hDC);"
        FPRINT FP_OUTPUT, "  EndDoc(BcxPtr_hDC);"
        FPRINT FP_OUTPUT, "  DeleteDC(BcxPtr_hDC);"
        FPRINT FP_OUTPUT, "  BcxPtr_LineCtr = 0;"
        FPRINT FP_OUTPUT, "  BcxPtr_PrinterOn = 0;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void EjectPage(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  EndPage(BcxPtr_hDC);"
        FPRINT FP_OUTPUT, "  BcxPtr_LineCtr = 0;"
        FPRINT FP_OUTPUT, "  StartPage(BcxPtr_hDC);"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_COM_CLSID THEN
        FPRINT FP_OUTPUT, "char* BCX_CLSID(char* ProgID)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "    CLSID ClassID={0};"
        FPRINT FP_OUTPUT, "    HRESULT hr={0};"
        FPRINT FP_OUTPUT, "    PWSTR pCLSIDString = NULL;"
        FPRINT FP_OUTPUT, "    char *BCX_RetStr={0};"
        FPRINT FP_OUTPUT, "    char Result[256]={0};"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    hr = CoInitialize(NULL);"
        FPRINT FP_OUTPUT, "    if (hr != S_OK) {"
        FPRINT FP_OUTPUT, "        BCX_RetStr = BCX_TempStr(strlen(", ENC$("COM initialization failed"), "));"
        FPRINT FP_OUTPUT, "        strcpy(BCX_RetStr, ", ENC$("COM initialization failed"), ");"
        FPRINT FP_OUTPUT, "        return BCX_RetStr;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    hr = CLSIDFromProgID(AnsiToWide(ProgID), &ClassID);"
        FPRINT FP_OUTPUT, "    if (hr == S_OK) {"
        FPRINT FP_OUTPUT, "        // Convert CLSID to a string"
        FPRINT FP_OUTPUT, "        #ifdef __cplusplus"
        FPRINT FP_OUTPUT, "        hr = StringFromCLSID(ClassID, &pCLSIDString);"
        FPRINT FP_OUTPUT, "        #else"
        FPRINT FP_OUTPUT, "        hr = StringFromCLSID(&ClassID, &pCLSIDString);"
        FPRINT FP_OUTPUT, "        #endif"
        FPRINT FP_OUTPUT, "        if (hr == S_OK) {"
        FPRINT FP_OUTPUT, "            strcpy(Result, WideToAnsi(pCLSIDString));"
        FPRINT FP_OUTPUT, "            CoTaskMemFree(pCLSIDString);"
        FPRINT FP_OUTPUT, "        } else {"
        FPRINT FP_OUTPUT, "            strcpy(Result, ", ENC$("Failed to convert CLSID to string"), ");"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "    } else {"
        FPRINT FP_OUTPUT, "        strcpy(Result, ", ENC$("Failed to get CLSID"), ");"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    CoUninitialize();"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(strlen(Result));"
        FPRINT FP_OUTPUT, "    strcpy(BCX_RetStr, Result);"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"

    END IF


    IF Use_SysStr THEN
        FPRINT FP_OUTPUT, "BSTR SysStr (PCTSTR szIn, int widstr, int bfree)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static BSTR bStr[32];"
        FPRINT FP_OUTPUT, "  static int  index;"
        FPRINT FP_OUTPUT, "  static int  result;"
        FPRINT FP_OUTPUT, "  if (bfree)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    for (index = 0; index<32; index += 1) "
        FPRINT FP_OUTPUT, "    SysFreeString(bStr[index]);"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  result = (++index & 31);"   ' This silences GCC's sequence point warning
        FPRINT FP_OUTPUT, "  index = result;"            '
        FPRINT FP_OUTPUT, "  SysFreeString(bStr[index]);"
        FPRINT FP_OUTPUT, "  ULONG length = (ULONG)strlen(szIn);"
        FPRINT FP_OUTPUT, "  if (widstr)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    bStr[index] = SysAllocStringLen(NULL, (2*length));"
        FPRINT FP_OUTPUT, "    MultiByteToWideChar(CP_ACP, 0, szIn, -1, bStr[index], (2*length+1));"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    bStr[index] = SysAllocStringByteLen(szIn, length);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return bStr[index];"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_SafeArrays THEN Emit_BCX_SafeArray(FP_OUTPUT)


    IF Use_COM THEN
        CALL Emit_COM_StandardSet(FP_OUTPUT)
        IF COM_build_trace_code    THEN CALL Emit_COM_TraceCalls(FP_OUTPUT)
        IF Use_COM_CreateObject    THEN CALL Emit_COM_CreateObject(FP_OUTPUT)
        IF Use_COM_GetObject       THEN CALL Emit_COM_GetObject(FP_OUTPUT)
        IF Use_COM_DispatchObject  THEN CALL Emit_COM_DispatchObject(FP_OUTPUT)
        IF Use_COM_SafeArray       THEN CALL Emit_COM_SafeArray(FP_OUTPUT)
        IF Use_COM_UsesConversion  THEN CALL Emit_COM_UsesConversion(FP_OUTPUT)
        IF Use_COM_GetProperty     THEN CALL Emit_COM_GetProperty(FP_OUTPUT)
        IF Use_COM_SetProperty     THEN CALL Emit_COM_SetProperty(FP_OUTPUT)
        IF Use_COM_InvokeMethod    THEN CALL Emit_COM_InvokeMethod(FP_OUTPUT)
    END IF
END SUB ' Emit_RT_SystemCOM1




SUB Emit_RT_SystemCOM2 (FP_OUTPUT AS FILE)
    IF Use_VBS THEN
        FPRINT FP_OUTPUT, "BOOL VBS_START (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  HRESULT  hResult;"
        FPRINT FP_OUTPUT, "  GUID  clsid;"
        FPRINT FP_OUTPUT, "  BSTR  Language;"
        FPRINT FP_OUTPUT, "  OLE_ERROR_S = FALSE;"
        FPRINT FP_OUTPUT, "  if (S_OK!=OleInitialize(0))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    MessageBox(NULL,", ENC$("Couldn't initialize OLE!"), ",NULL,MB_OK);"
        FPRINT FP_OUTPUT, "    PostQuitMessage(0);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "#ifdef __BCX_MULTITHREADED__"
        FPRINT FP_OUTPUT, "  CoInitializeEx(NULL, COINIT_MULTITHREADED);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  hResult=CLSIDFromProgID(OLESTR(", ENC$("MSScriptControl.ScriptControl"), "),&clsid);"
        FPRINT FP_OUTPUT, "  if (hResult!=S_OK)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    for(;;)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (hResult==REGDB_E_CLASSNOTREG)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        OleUninitialize();"
        FPRINT FP_OUTPUT, "        MessageBox (GetActiveWindow(),", ENC$("MSScriptControl::Class not registered"), ",", ENC$("Error"), ",MB_SETFOREGROUND);"
        FPRINT FP_OUTPUT, "        PostQuitMessage(0);"
        FPRINT FP_OUTPUT, "        break;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      if (hResult==CLASS_E_NOAGGREGATION)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        OleUninitialize();"
        FPRINT FP_OUTPUT, "        MessageBox (GetActiveWindow(),", ENC$("MSScriptControl::Class not created"), ",", ENC$("Error"), ",MB_SETFOREGROUND);"
        FPRINT FP_OUTPUT, "        PostQuitMessage(0);"
        FPRINT FP_OUTPUT, "        break;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      if (hResult==CLASS_E_CLASSNOTAVAILABLE)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        OleUninitialize();"
        FPRINT FP_OUTPUT, "        MessageBox (GetActiveWindow(),", ENC$("MSScriptControl::Class not available"), ",", ENC$("Error"), ",MB_SETFOREGROUND);"
        FPRINT FP_OUTPUT, "        PostQuitMessage(0);"
        FPRINT FP_OUTPUT, "        break;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        VBS_STOP();"
        FPRINT FP_OUTPUT, "        MessageBox (GetActiveWindow(),", ENC$("MSScriptControl::Unknown error"), ",", ENC$("Error"), ",MB_SETFOREGROUND);"
        FPRINT FP_OUTPUT, "        PostQuitMessage(0);"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      break;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  hResult=CoCreateInstance(&clsid,0,CLSCTX_SERVER,&IID_IScriptControl,(void**)&pSC);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  hResult=CoCreateInstance(clsid,0,CLSCTX_SERVER,IID_IScriptControl,(void**)&pSC);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  Language=SysAllocString(OLESTR(", ENC$("VBScript"), "));"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  hResult=pSC->lpVtbl->put_Language(pSC,Language);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  hResult=pSC->put_Language(Language);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  SysFreeString(Language);"
        FPRINT FP_OUTPUT, "  if (hResult!=S_OK)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    VBS_STOP();"
        FPRINT FP_OUTPUT, "    MessageBox (GetActiveWindow(),", ENC$("Could not start ScriptControl"), ",", ENC$("Error"), ",MB_SETFOREGROUND);"
        FPRINT FP_OUTPUT, "    PostQuitMessage(0);"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return TRUE;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void VBS_STOP (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  pSC->lpVtbl->Release(pSC);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  pSC->Release();"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  pSC=0;;"
        FPRINT FP_OUTPUT, "  OleUninitialize();"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "void VBS_RESET (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  pSC->lpVtbl->Reset(pSC);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  pSC->Reset();"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "HRESULT VBS_RUN_SCRIPT (PCTSTR VB_SCRIPT)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  BSTR  MyCode;"
        FPRINT FP_OUTPUT, "  HRESULT  hResult;"
        FPRINT FP_OUTPUT, "  MyCode=SysAllocString(AnsiToWide(VB_SCRIPT));"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  hResult=pSC->lpVtbl->ExecuteStatement(pSC,MyCode);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  hResult=pSC->ExecuteStatement(MyCode);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  SysFreeString(MyCode);"
        FPRINT FP_OUTPUT, "  return SUCCEEDED(hResult);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "HRESULT VBS_ADDCODE (PCTSTR Code)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int CodeLen;"
        FPRINT FP_OUTPUT, "  wchar_t* Buf;"
        FPRINT FP_OUTPUT, "  BSTR Bbuf;"
        FPRINT FP_OUTPUT, "  HRESULT hResult;"
        FPRINT FP_OUTPUT, "  CodeLen=(int)strlen(Code);"
        FPRINT FP_OUTPUT, "  Buf=(wchar_t*)calloc(2*(CodeLen+1),sizeof(wchar_t));"
        FPRINT FP_OUTPUT, "  mbstowcs(Buf,Code,CodeLen);"
        FPRINT FP_OUTPUT, "  Bbuf=SysAllocString(Buf);"
        FPRINT FP_OUTPUT, "  free((Buf));"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  hResult=pSC->lpVtbl->AddCode(pSC,Bbuf);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  hResult=pSC->AddCode(Bbuf);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  SysFreeString(Bbuf);"
        FPRINT FP_OUTPUT, "  return SUCCEEDED(hResult);"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "double VBS_EVAL_NUM (PCTSTR VB_SCRIPT)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  BSTR  MyCode;"
        FPRINT FP_OUTPUT, "  HRESULT HResult;"
        FPRINT FP_OUTPUT, "  VARIANT vResult;"
        FPRINT FP_OUTPUT, "  MyCode=SysAllocString(AnsiToWide(VB_SCRIPT));"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  HResult=pSC->lpVtbl->Eval(pSC,MyCode,&vResult);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  HResult=pSC->Eval(MyCode,&vResult);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  SysFreeString(MyCode);\n"
        FPRINT FP_OUTPUT, "  if (SUCCEEDED(HResult))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    HResult=VariantChangeType(&vResult,&vResult,0,VT_R8);"
        FPRINT FP_OUTPUT, "    return vResult.dblVal;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "char* VBS_ERROR(void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr= {0};"
        FPRINT FP_OUTPUT, "  IScriptError* pScriptError;"
        FPRINT FP_OUTPUT, "  HRESULT HResult;"
        FPRINT FP_OUTPUT, "  long  ErrNumber;"
        FPRINT FP_OUTPUT, "  BSTR  ErrDescription = NULL;"
        FPRINT FP_OUTPUT, "  BSTR  ErrText = NULL;"
        FPRINT FP_OUTPUT, "  long  ErrLine;"
        FPRINT FP_OUTPUT, "  long  ErrColumn;"
        FPRINT FP_OUTPUT, "  UINT  Errdesclen;"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  HResult = pSC->lpVtbl->get_Error(pSC, &pScriptError);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  HResult = pSC->get_Error(&pScriptError);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  if FAILED(HResult)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    *BCX_RetStr=0;"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (pScriptError)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "    pScriptError->lpVtbl->Get_Number(pScriptError,&ErrNumber);"
        FPRINT FP_OUTPUT, "    pScriptError->lpVtbl->Get_Description(pScriptError, &ErrDescription);"
        FPRINT FP_OUTPUT, "    pScriptError->lpVtbl->Get_Text(pScriptError, &ErrText);"
        FPRINT FP_OUTPUT, "    pScriptError->lpVtbl->Get_Line(pScriptError, &ErrLine);"
        FPRINT FP_OUTPUT, "    pScriptError->lpVtbl->Get_Column(pScriptError, &ErrColumn);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "    pScriptError->Get_Number(&ErrNumber);"
        FPRINT FP_OUTPUT, "    pScriptError->Get_Description(&ErrDescription);"
        FPRINT FP_OUTPUT, "    pScriptError->Get_Text(&ErrText);"
        FPRINT FP_OUTPUT, "    pScriptError->Get_Line(&ErrLine);"
        FPRINT FP_OUTPUT, "    pScriptError->Get_Column(&ErrColumn);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "    if (NULL == ErrDescription)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      ErrDescription = SysAllocString(OLESTR(", ENC$("No description available."), "));"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (NULL == ErrText)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      ErrText = SysAllocString(OLESTR(", ENC$("No extra error info available."), "));"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    Errdesclen =  SysStringLen(ErrDescription) + SysStringLen(ErrText) + 512;"
        FPRINT FP_OUTPUT, "    BCX_RetStr=BCX_TempStr(Errdesclen);"
        FPRINT FP_OUTPUT, "    sprintf(BCX_RetStr," , ENC$("VBScript error 0x%lX\\nline:%d, column:%d\\nDescription: %s\\nError text: %s") , ", ErrNumber, ErrLine, ErrColumn,WideToAnsi(ErrDescription),WideToAnsi(ErrText));"
        FPRINT FP_OUTPUT, "    SysFreeString(ErrDescription);"
        FPRINT FP_OUTPUT, "    SysFreeString(ErrText);"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "    pScriptError->lpVtbl->Release(pScriptError);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "    pScriptError->Release();"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  *BCX_RetStr=0;"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "char* VBS_EVAL_STR(PCTSTR VB_SCRIPT)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  char *BCX_RetStr= {0};"
        FPRINT FP_OUTPUT, "  BSTR  MyCode;"
        FPRINT FP_OUTPUT, "  HRESULT HResult;"
        FPRINT FP_OUTPUT, "  VARIANT vResult;"
        FPRINT FP_OUTPUT, "  MyCode=SysAllocString(AnsiToWide(VB_SCRIPT));"
        FPRINT FP_OUTPUT, "#ifndef __cplusplus"
        FPRINT FP_OUTPUT, "  HResult=pSC->lpVtbl->Eval(pSC,MyCode,&vResult);"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  HResult=pSC->Eval(MyCode,&vResult);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, "  SysFreeString(MyCode);"
        FPRINT FP_OUTPUT, "  if (SUCCEEDED(HResult))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    HResult = VariantChangeType(&vResult,&vResult,0,VT_BSTR);"
        FPRINT FP_OUTPUT, "    BCX_RetStr = BCX_TempStr(strlen(WideToAnsi(vResult.bstrVal)));"
        FPRINT FP_OUTPUT, "    strcpy(BCX_RetStr,(PCTSTR)WideToAnsi(vResult.bstrVal));"
        FPRINT FP_OUTPUT, "    return BCX_RetStr;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  *BCX_RetStr=0;"
        FPRINT FP_OUTPUT, "  return BCX_RetStr;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_FileLocked THEN
        FPRINT FP_OUTPUT, "int FileLocked (PCTSTR Filename)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  FILE *FP = fopen (Filename,", ENC$("rb+"), ");"
        FPRINT FP_OUTPUT, "  if (FP == 0) return 1;"
        FPRINT FP_OUTPUT, "  fclose(FP);"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_Sound THEN
        FPRINT FP_OUTPUT, "int Sound (float Freq, int Dura, int Vol, int Voice, float Tempo)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static int MidiRunning;"
        FPRINT FP_OUTPUT, "  if(MidiRunning == FALSE)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      MidiRunning = TRUE;"
        FPRINT FP_OUTPUT, "      midiOutOpen(&hMidi, (UINT)(-1), 0, 0, CALLBACK_NULL);"
        FPRINT FP_OUTPUT, "      Sound(0, 1 ,0);"
        FPRINT FP_OUTPUT, "      Sleep(500);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  ULONG dwThreadId;"
        FPRINT FP_OUTPUT, "  if (Freq == 0 && Dura <1) return gTenter-gTexit;"
        FPRINT FP_OUTPUT, "  if (Freq == 0) Vol=0;"
        FPRINT FP_OUTPUT, "  if (Dura<5)  Dura=5;"
        FPRINT FP_OUTPUT, "  gTenter++;"
        FPRINT FP_OUTPUT, "  gTsig = FALSE;"
        FPRINT FP_OUTPUT, "  if (gTenter >= SNDQUE)"
        FPRINT FP_OUTPUT, "    gTarray = gTenter % SNDQUE + 1;"
        FPRINT FP_OUTPUT, "  else"
        FPRINT FP_OUTPUT, "    gTarray = gTenter;"
        FPRINT FP_OUTPUT, "  SndPmtr[gTarray].Freq=Freq;"
        FPRINT FP_OUTPUT, "  SndPmtr[gTarray].Dura=Dura;"
        FPRINT FP_OUTPUT, "  SndPmtr[gTarray].Tempo=Tempo;"
        FPRINT FP_OUTPUT, "  SndPmtr[gTarray].Vol=Vol;"
        FPRINT FP_OUTPUT, "  SndPmtr[gTarray].Voice=Voice;"
        FPRINT FP_OUTPUT, "  SndPmtr[gTarray].sndTid=gTenter;"
        FPRINT FP_OUTPUT, "  if (gSThread==NULL && (Freq==fabsf(Freq)||Freq==0))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    gSThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)PlaySnd,(PSTR)"; ENC$("PlaySnd"); ",0,&dwThreadId);"
        FPRINT FP_OUTPUT, "    timeBeginPeriod(1);  // Set system timer resolution to 1ms"
        FPRINT FP_OUTPUT, "       Sleep(1);"
        FPRINT FP_OUTPUT, "    timeEndPeriod(1);    // Restore normal resolution"
        FPRINT FP_OUTPUT, "    return 0;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  if (Freq!=fabsf(Freq))"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (Freq == (-1))"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      Freq=0;"
        FPRINT FP_OUTPUT, "      SndPmtr[gTarray].Vol=0;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    SndPmtr[gTarray].Freq=fabsf(Freq);"
        FPRINT FP_OUTPUT, "    gTsig = TRUE;"
        FPRINT FP_OUTPUT, "    while(gSThread != NULL)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "    timeBeginPeriod(1);  // Set system timer resolution to 1ms"
        FPRINT FP_OUTPUT, "       Sleep(1);"
        FPRINT FP_OUTPUT, "    timeEndPeriod(1);    // Restore normal resolution"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    gTexit = gTenter-1;"
        FPRINT FP_OUTPUT, "    gTwait = gTenter-1;"
        FPRINT FP_OUTPUT, "    gTsig = FALSE;"
        FPRINT FP_OUTPUT, "    return PlaySnd();"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"

        FPRINT FP_OUTPUT, "int PlaySnd (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  soundtype  LocSndPar;"
        FPRINT FP_OUTPUT, "  UINT lTarray;"
        FPRINT FP_OUTPUT, "  while(gTenter > gTexit && gTsig == FALSE)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    gTwait++;"
        FPRINT FP_OUTPUT, "    if (gTwait >= SNDQUE)"
        FPRINT FP_OUTPUT, "      lTarray = gTwait % SNDQUE+1;"
        FPRINT FP_OUTPUT, "    else"
        FPRINT FP_OUTPUT, "      lTarray = gTwait;"
        FPRINT FP_OUTPUT, "    LocSndPar = SndPmtr[lTarray];"
        FPRINT FP_OUTPUT, "    int L_Note = 0;"
        FPRINT FP_OUTPUT, "    int Phrase = 0;"
        FPRINT FP_OUTPUT, "    midiOutShortMsg (hMidi,(256 * LocSndPar.Voice) + 192);"
        FPRINT FP_OUTPUT, "    L_Note = Round ((log((double) LocSndPar.Freq)- log((double)440.0))/log((double)2)*12+69,0);"
        FPRINT FP_OUTPUT, "    Phrase = (LocSndPar.Vol * 256 + L_Note) * 256 + 144;"
        FPRINT FP_OUTPUT, "    midiOutShortMsg (hMidi, Phrase);"
        FPRINT FP_OUTPUT, "    timeBeginPeriod(1);  // Set system timer resolution to 1ms"
        FPRINT FP_OUTPUT, "       Sleep (LocSndPar.Dura * (1/LocSndPar.Tempo + 0.0001f));"
        FPRINT FP_OUTPUT, "    timeEndPeriod(1);    // Restore normal resolution"
        FPRINT FP_OUTPUT, "    Phrase = (LocSndPar.Vol * 256 + L_Note) * 256 + 128;"
        FPRINT FP_OUTPUT, "    midiOutShortMsg (hMidi,Phrase);"
        FPRINT FP_OUTPUT, "    gTexit++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  CloseHandle(gSThread);"
        FPRINT FP_OUTPUT, "  gSThread = NULL;"
        FPRINT FP_OUTPUT, "  return 0;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_OSVersion THEN
        FPRINT FP_OUTPUT, "int OSVersion (void)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  OSVERSIONINFOEXW  osvi= {0};"
        FPRINT FP_OUTPUT, "  osvi.dwOSVersionInfoSize=sizeof(osvi);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "#ifdef __LCC__"
        FPRINT FP_OUTPUT, "  FARPROC RtlGetVersion;"
        FPRINT FP_OUTPUT, "#define SM_SERVERR2  89"
        FPRINT FP_OUTPUT, "#define VER_SUITE_WH_SERVER  32768"
        FPRINT FP_OUTPUT, "#define PROCESSOR_ARCHITECTURE_AMD64  9"
        FPRINT FP_OUTPUT, "#else"
        FPRINT FP_OUTPUT, "  NTSTATUS (WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);"
        FPRINT FP_OUTPUT, "#endif"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  *(FARPROC*)&RtlGetVersion=GetProcAddress(GetModuleHandle(", ENC$("ntdll"), "), ", ENC$("RtlGetVersion"), ");"
        FPRINT FP_OUTPUT, "  if (RtlGetVersion != NULL)  RtlGetVersion(&osvi);"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  switch (osvi.dwPlatformId)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "  case VER_PLATFORM_WIN32_NT:"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (osvi.dwMajorVersion==10 && osvi.dwMinorVersion==0)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (osvi.dwBuildNumber >= 22000)                       return  OS_Win_11;"
        FPRINT FP_OUTPUT, "      if (osvi.wProductType == VER_NT_WORKSTATION)           return  OS_Win_10;"
        FPRINT FP_OUTPUT, "      if (osvi.dwBuildNumber == 17763)                       return  OS_Server_2019;"
        FPRINT FP_OUTPUT, "      if (osvi.dwBuildNumber >= 20348)                       return  OS_Server_2022;"
        FPRINT FP_OUTPUT, "      return  OS_Server_2016;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (osvi.dwMajorVersion==6 && osvi.dwMinorVersion==3)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (osvi.wProductType == VER_NT_WORKSTATION)           return  OS_Win_81;"
        FPRINT FP_OUTPUT, "      return  OS_Server_2012_R2;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (osvi.dwMajorVersion==6 && osvi.dwMinorVersion==2)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (osvi.wProductType == VER_NT_WORKSTATION)           return  OS_Win_8;"
        FPRINT FP_OUTPUT, "      return  OS_Server_2012;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (osvi.dwMajorVersion==6 && osvi.dwMinorVersion==1)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (osvi.wProductType == VER_NT_WORKSTATION)            return OS_Win_7;"
        FPRINT FP_OUTPUT, "      return OS_Server_2008_R2;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (osvi.dwMajorVersion==6 && osvi.dwMinorVersion==0)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (osvi.wProductType != VER_NT_WORKSTATION)             return OS_Server_2008;"
        FPRINT FP_OUTPUT, "      return OS_Vista;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "    if (osvi.dwMajorVersion >= 5 && osvi.dwMinorVersion >= 2)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      int iTestForSM_SERVERR2;"
        FPRINT FP_OUTPUT, "      iTestForSM_SERVERR2 = GetSystemMetrics(SM_SERVERR2);"
        FPRINT FP_OUTPUT, "      if (iTestForSM_SERVERR2 != 0)                            return OS_Server_2003_R2;"
        FPRINT FP_OUTPUT, "      if ((osvi.wSuiteMask & VER_SUITE_WH_SERVER) != 0)        return OS_Home_Server;"
        FPRINT FP_OUTPUT, "      if (0 == iTestForSM_SERVERR2)                            return OS_Server_2003;"
        FPRINT FP_OUTPUT, "      SYSTEM_INFO siSysInfo;"
        FPRINT FP_OUTPUT, "      GetSystemInfo(&siSysInfo);"
        FPRINT FP_OUTPUT, "      if ((osvi.wProductType == VER_NT_WORKSTATION) && (siSysInfo.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)) return OS_XP_Pro_x64;"
        FPRINT FP_OUTPUT, "      return OSUnknown;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (osvi.dwMajorVersion==5 && osvi.dwMinorVersion==1)      return OS_XP;"
        FPRINT FP_OUTPUT, "    if (osvi.dwMajorVersion==5 && osvi.dwMinorVersion==0)      return OS_2000;"
        FPRINT FP_OUTPUT, "    if (osvi.dwMajorVersion==3 && osvi.dwMinorVersion==51)     return OS_NT3;"
        FPRINT FP_OUTPUT, "    return OSUnknown;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  case VER_PLATFORM_WIN32_WINDOWS:"
        FPRINT FP_OUTPUT, "    if ((osvi.dwMajorVersion==4 && osvi.dwMinorVersion==90))   return OS_ME;"
        FPRINT FP_OUTPUT, "    if ((osvi.dwMajorVersion==4 && osvi.dwMinorVersion==10))   return OS_98;"
        FPRINT FP_OUTPUT, "    if ((osvi.dwMajorVersion==4 && osvi.dwMinorVersion==0))    return OS_95;"
        FPRINT FP_OUTPUT, "    return OSUnknown;"
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  case VER_PLATFORM_WIN32s:"
        FPRINT FP_OUTPUT, "    return OS_3x;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return OSUnknown;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF



    IF Use_ContainedIn THEN
        FPRINT FP_OUTPUT, "int containedin(char *Token, char **Contain, int SensFlag)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int ii=0;"
        FPRINT FP_OUTPUT, "  while (Contain[ii][0])"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (0 == ((SensFlag == 0 || SensFlag == 2) ? strcmp(Contain[ii], Token) : bcx_stricmp(Contain[ii], Token)))"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      return ((SensFlag < 2) ? 0 : ii);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    ii++;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return -1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF


    IF Use_FindInType THEN
        FPRINT FP_OUTPUT, "int FindInType(PCTSTR Token, PCTSTR StOffset, int StSize, int start, int finish, int c, int *idx)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  int j;"
        FPRINT FP_OUTPUT, "  PCTSTR Srch;"
        FPRINT FP_OUTPUT, "  int (*cmp)(PCTSTR, PCTSTR);"
        FPRINT FP_OUTPUT, "  cmp = ((c == 0 || c == 2) ? strcmp : bcx_stricmp);"
        FPRINT FP_OUTPUT, "  for(j=start; j<=finish; j++)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    Srch = StOffset + ((idx==0) ? j*StSize : idx[j]*StSize);"
        FPRINT FP_OUTPUT, "    if (cmp(Srch,Token)==0)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      return ((c < 2) ? 0 : j);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "  return -1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_Hscroll OR Use_Vscroll THEN
        FPRINT FP_OUTPUT, "void BCX_Scroll (HWND hWnd, int Msg, int wParam, int lParam, int BCX_LargeChangeX,"
        FPRINT FP_OUTPUT, "                 int BCX_LargeChangeY, int BCX_SmallChangeX, int BCX_SmallChangeY,"
        FPRINT FP_OUTPUT, "                 int BCX_ViewWidth, int BCX_ViewHeight, int BCX_DynaScrollArg)"
        FPRINT FP_OUTPUT, "{"
        FPRINT FP_OUTPUT, "  static int oldX;"
        FPRINT FP_OUTPUT, "  static int oldY;"
        FPRINT FP_OUTPUT, "  static RECT Rc;"
        FPRINT FP_OUTPUT, "  for (;;)"
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    if (Msg == WM_VSCROLL)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      int yChange;"
        FPRINT FP_OUTPUT, "      int yPos;"
        FPRINT FP_OUTPUT, "      int LowWp = LOWORD(wParam);"
        FPRINT FP_OUTPUT, "      for(;;)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_LINEUP)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          yPos = BCX_siY.nPos-BCX_SmallChangeY;"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_LINEDOWN)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          yPos = BCX_siY.nPos+BCX_SmallChangeY;"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_PAGEUP)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          yPos = BCX_siY.nPos-BCX_LargeChangeY;"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_PAGEDOWN)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          yPos = BCX_siY.nPos+BCX_LargeChangeY;"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_THUMBPOSITION)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          yPos = HIWORD(wParam);"
        FPRINT FP_OUTPUT, "          if (yPos+(int)BCX_siY.nPage >= (int)BCX_siY.nMax)"
        FPRINT FP_OUTPUT, "          {"
        FPRINT FP_OUTPUT, "            yPos = BCX_siY.nMax;"
        FPRINT FP_OUTPUT, "          }"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          yPos = BCX_siY.nPos;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        break;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      yPos = (int)MAX(0,yPos);"
        FPRINT FP_OUTPUT, "      yPos = (int)MIN(BCX_siY.nMax,yPos);"
        FPRINT FP_OUTPUT, "      if (yPos == BCX_siY.nPos) return;"
        FPRINT FP_OUTPUT, "      yChange = yPos-BCX_siY.nPos;"
        FPRINT FP_OUTPUT, "      BCX_siY.nPos = yPos;"
        FPRINT FP_OUTPUT, "      ScrollWindowEx(hWnd,0,-yChange,0,0,0,0,SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);"
        FPRINT FP_OUTPUT, "      SetScrollInfo(hWnd,SB_VERT,&BCX_siY,TRUE);"
        FPRINT FP_OUTPUT, "      break;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (Msg == WM_HSCROLL)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      int xChange;"
        FPRINT FP_OUTPUT, "      int xPos;"
        FPRINT FP_OUTPUT, "      int LowWp = LOWORD(wParam);"
        FPRINT FP_OUTPUT, "      for(;;)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_LINELEFT)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          xPos = BCX_siX.nPos-BCX_SmallChangeX;"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_LINERIGHT)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          xPos = BCX_siX.nPos+BCX_SmallChangeX;"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_PAGEUP)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          xPos = BCX_siX.nPos-BCX_LargeChangeX;"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_PAGEDOWN)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          xPos = BCX_siX.nPos+BCX_LargeChangeX;"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (LowWp == SB_THUMBPOSITION)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          xPos = HIWORD(wParam);"
        FPRINT FP_OUTPUT, "          if (xPos+(int)BCX_siX.nPage >= (int)BCX_siX.nMax)"
        FPRINT FP_OUTPUT, "          {"
        FPRINT FP_OUTPUT, "            xPos = BCX_siX.nMax;"
        FPRINT FP_OUTPUT, "          }"
        FPRINT FP_OUTPUT, "          break;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          xPos = BCX_siX.nPos;"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        break;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "      xPos = (int)MAX(0,xPos);"
        FPRINT FP_OUTPUT, "      xPos = (int)MIN(BCX_siX.nMax,xPos);"
        FPRINT FP_OUTPUT, "      if (xPos == (int)BCX_siX.nPos) return;"
        FPRINT FP_OUTPUT, "      xChange = xPos-BCX_siX.nPos;"
        FPRINT FP_OUTPUT, "      BCX_siX.nPos = xPos;"
        FPRINT FP_OUTPUT, "      ScrollWindowEx(hWnd,-xChange,0,0,0,0,0,SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);"
        FPRINT FP_OUTPUT, "      SetScrollInfo(hWnd,SB_HORZ,&BCX_siX,TRUE);"
        FPRINT FP_OUTPUT, "      break;"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    if (Msg == WM_SIZE)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      if (BCX_DynaScrollArg)"
        FPRINT FP_OUTPUT, "      {"
        FPRINT FP_OUTPUT, "        int xNewSize;"
        FPRINT FP_OUTPUT, "        int yNewSize = HIWORD(lParam);"
        FPRINT FP_OUTPUT, "        int offsetX = 0;"
        FPRINT FP_OUTPUT, "        int offsetY = 0;"
        FPRINT FP_OUTPUT, "        xNewSize = (GetSystemMetrics(SM_CXFRAME)*2)+(GetSystemMetrics(SM_CXBORDER)*2);"
        FPRINT FP_OUTPUT, "        GetWindowRect(hWnd,&Rc);"
        FPRINT FP_OUTPUT, "        xNewSize = (Rc.right-Rc.left)-xNewSize-GetSystemMetrics(SM_CXVSCROLL);"
        FPRINT FP_OUTPUT, "        if (xNewSize > BCX_ViewWidth-(int)BCX_siX.nPos && (int)BCX_siX.nPos > 0)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          offsetX = (int)MAX(0,(int)MIN(xNewSize-oldX,BCX_siX.nPos));"
        FPRINT FP_OUTPUT, "          BCX_siX.nPos = (int)MAX(0,BCX_siX.nPos-offsetX);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (yNewSize > BCX_ViewHeight-(int)BCX_siY.nPos && (int)BCX_siY.nPos > 0)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          offsetY = (int)MAX(0,(int)MIN(yNewSize-oldY,BCX_siY.nPos));"
        FPRINT FP_OUTPUT, "          BCX_siY.nPos = (int)MAX(0,BCX_siY.nPos-offsetY);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        if (offsetX || offsetY)"
        FPRINT FP_OUTPUT, "        {"
        FPRINT FP_OUTPUT, "          ScrollWindowEx(hWnd,offsetX,offsetY,0,0,0,0,SW_SCROLLCHILDREN|SW_ERASE|SW_INVALIDATE);"
        FPRINT FP_OUTPUT, "        }"
        FPRINT FP_OUTPUT, "        BCX_siX.nMax = (int)MAX(BCX_ViewWidth-xNewSize,0);"
        FPRINT FP_OUTPUT, "        BCX_siX.nPage = (int)MAX(BCX_siX.nMax/BCX_LargeChangeX,0);"
        FPRINT FP_OUTPUT, "        BCX_siX.nPos = (int)MIN(BCX_siX.nPos,BCX_siX.nMax);"
        FPRINT FP_OUTPUT, "        SetScrollInfo(hWnd,SB_HORZ,&BCX_siX,TRUE);"
        FPRINT FP_OUTPUT, "        BCX_siY.nMax = (int)MAX(BCX_ViewHeight-yNewSize,0);"
        FPRINT FP_OUTPUT, "        BCX_siY.nPage = (int)MAX(BCX_siY.nMax/BCX_LargeChangeY,0);"
        FPRINT FP_OUTPUT, "        BCX_siY.nPos = (int)MIN(BCX_siY.nPos,BCX_siY.nMax);"
        FPRINT FP_OUTPUT, "        SetScrollInfo(hWnd,SB_VERT,&BCX_siY,TRUE);"
        FPRINT FP_OUTPUT, "        oldX = xNewSize;"
        FPRINT FP_OUTPUT, "        oldY = yNewSize;"
        FPRINT FP_OUTPUT, "      }"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "    break;"
        FPRINT FP_OUTPUT, "  }"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_StartupCode THEN
        FPRINT FP_OUTPUT, "int BCX_StartupCode_(void) {"
        FOR i AS INT = 1 TO StartNdx
            FPRINT FP_OUTPUT, SPACE$(2) ; StartSub$[i]; "();"
        NEXT
        FPRINT FP_OUTPUT, "  return 1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    IF Use_ExitCode THEN
        FPRINT FP_OUTPUT, "int BCX_ExitCode_(void) {"
        FOR i AS INT = 1 TO ExitNdx
            FPRINT FP_OUTPUT, "  atexit("; ExitSub$[i]; ");"
        NEXT
        FPRINT FP_OUTPUT, "  return 1;"
        FPRINT FP_OUTPUT, "}\n\n"
    END IF

    ' Emit nomain gui/mdigui code here

    IF Use_GUINoMain OR Use_MDIGUINoMain OR Use_Wingui THEN

        IF Use_BCX_FrameWnd THEN
            FPRINT FP_OUTPUT, "HWND BCX_FrameWnd (PCTSTR classname, WNDPROC FrameWndProc, PCTSTR caption, HMENU hMenu, int nMenuPos, int X, int Y, int W, int H, int nStyle, int nExStyle)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  HWND  hWnd;"
            FPRINT FP_OUTPUT, "  if (!BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    BCX_InitGUI();"
            FPRINT FP_OUTPUT, "  BCX_RegWnd (classname,FrameWndProc);"
            FPRINT FP_OUTPUT, "  if (nStyle == 0)"
            FPRINT FP_OUTPUT, "    nStyle = WS_OVERLAPPEDWINDOW;"
            FPRINT FP_OUTPUT, "  hWnd = CreateWindowEx(nExStyle,classname,caption,nStyle,X*BCX_ScaleX,Y*BCX_ScaleY,W*BCX_ScaleX,H*BCX_ScaleY,NULL,(HMENU)(UINT_PTR)hMenu,BCX_hInstance,NULL);"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "    if (hWnd == NULL) return NULL;"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "  SendMessage (hWnd,WM_SETFONT,(WPARAM)DefaultFont,(LPARAM)MAKELPARAM(FALSE,0));"
            FPRINT FP_OUTPUT, "  CLIENTCREATESTRUCT ccs={0,1};"
            FPRINT FP_OUTPUT, "  //  Find window menu where children will be listed"
            FPRINT FP_OUTPUT, "  ccs.hWindowMenu = GetSubMenu (GetMenu(hWnd),nMenuPos-1);"
            FPRINT FP_OUTPUT, "  //  Create the MDI client filling the client area"
            FPRINT FP_OUTPUT, "  BCX_hwndMDIClient = CreateWindow(", ENC$("MDICLIENT"), ",NULL, WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL,"
            FPRINT FP_OUTPUT, "                                     0,0,0,0,hWnd,(HMENU)(UINT_PTR)hMenu,BCX_hInstance,(PVOID)&ccs);"
            FPRINT FP_OUTPUT, "  return hWnd;"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF


        IF Use_BCX_Wnd THEN
            FPRINT FP_OUTPUT, "HWND BCX_Wnd(PCTSTR classname, WNDPROC wndProc, PCTSTR caption, HWND hParentWnd,int X,int Y,int W,int H,int nStyle,int nExStyle,int nID)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  if (!BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    BCX_InitGUI();"
            FPRINT FP_OUTPUT, "  BCX_SetMetric("; ENC$("pixels"); ");"
            FPRINT FP_OUTPUT, "  BCX_RegWnd (classname,wndProc);"
            FPRINT FP_OUTPUT, "  if (nStyle == 0)"
            FPRINT FP_OUTPUT, "    nStyle = WS_OVERLAPPEDWINDOW;"
            FPRINT FP_OUTPUT, "  HWND hWnd = CreateWindowEx(nExStyle,classname,caption,nStyle,X*BCX_ScaleX,Y*BCX_ScaleY,"
            FPRINT FP_OUTPUT, "                             W*BCX_ScaleX,H*BCX_ScaleY,hParentWnd,(HMENU)(UINT_PTR) nID,BCX_hInstance,NULL);"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "    if (hWnd == NULL) return NULL;"
            FPRINT FP_OUTPUT, SPC$
            FPRINT FP_OUTPUT, "  SendMessage(hWnd,WM_SETFONT,(WPARAM)DefaultFont,(LPARAM)MAKELPARAM(FALSE,0));"
            FPRINT FP_OUTPUT, "  return hWnd;"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF


        IF Use_BCX_SetBkGrdBrush THEN
            FPRINT FP_OUTPUT, "void BCX_SetBkGrdBrush (HWND hWnd, HBRUSH hBrush)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  if (!BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    BCX_InitGUI();"
            FPRINT FP_OUTPUT, "  if (!hWnd)"
            FPRINT FP_OUTPUT, "    BCX_WndClass.hbrBackground=hBrush;"
            FPRINT FP_OUTPUT, "  if (hWnd)"
            FPRINT FP_OUTPUT, "    SetClassLongPtr(hWnd,GCLP_HBRBACKGROUND,(LONG_PTR)hBrush);"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF


        IF Use_BCX_SetClassStyle THEN
            FPRINT FP_OUTPUT, "void BCX_SetClassStyle (HWND hWnd, long nNewValue)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  if (!BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    BCX_InitGUI();"
            FPRINT FP_OUTPUT, "  if (!hWnd)"
            FPRINT FP_OUTPUT, "    BCX_WndClass.style=nNewValue;"
            FPRINT FP_OUTPUT, "  if (hWnd)"
            FPRINT FP_OUTPUT, "    SetClassLongPtr(hWnd,GCL_STYLE,(LONG_PTR)nNewValue);"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF

        IF Use_BCX_SetIcon THEN
            FPRINT FP_OUTPUT, "void BCX_SetIcon (HWND hWnd, int nRes)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  if (!BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    BCX_InitGUI();"
            FPRINT FP_OUTPUT, "  if (hWnd == 0)"
            FPRINT FP_OUTPUT, "    BCX_WndClass.hIcon = LoadIcon(BCX_hInstance,MAKEINTRESOURCE(nRes));"
            FPRINT FP_OUTPUT, "  if (hWnd)"
            FPRINT FP_OUTPUT, "    SetClassLongPtr(hWnd,GCLP_HICON,(LONG_PTR)LoadIcon(BCX_hInstance,MAKEINTRESOURCE(nRes)));"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF

        IF Use_BCX_SetIconSm THEN
            FPRINT FP_OUTPUT, "void BCX_SetIconSm (HWND hWnd, int nRes)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  if (!BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    BCX_InitGUI();"
            FPRINT FP_OUTPUT, "  if (hWnd == 0)"
            FPRINT FP_OUTPUT, "    BCX_WndClass.hIconSm = LoadIcon(BCX_hInstance,MAKEINTRESOURCE(nRes));"
            FPRINT FP_OUTPUT, "  if (hWnd)"
            FPRINT FP_OUTPUT, "    SetClassLongPtr(hWnd,GCLP_HICONSM,(LONG_PTR)LoadIcon(BCX_hInstance,MAKEINTRESOURCE(nRes)));"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF

        IF Use_BCX_SetCursor THEN
            FPRINT FP_OUTPUT, "void BCX_SetCursor (HWND hWnd, PCTSTR cCursor)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  if (!BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    BCX_InitGUI();"
            FPRINT FP_OUTPUT, "  if (hWnd == 0)"
            FPRINT FP_OUTPUT, "    BCX_WndClass.hCursor = LoadCursor(BCX_hInstance,cCursor);"
            FPRINT FP_OUTPUT, "  if (hWnd)"
            FPRINT FP_OUTPUT, "    SetClassLongPtr(hWnd,GCLP_HCURSOR,(LONG_PTR)LoadCursor(BCX_hInstance,cCursor));"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF

        IF Use_BCX_SetMetric THEN
            FPRINT FP_OUTPUT, "void BCX_SetMetric (PCTSTR metric)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  if (!BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    BCX_InitGUI();"
            FPRINT FP_OUTPUT, "  if (_stricmp(metric,", ENC$("PIXELS"), ")==0)"
            FPRINT FP_OUTPUT, "  {"
            FPRINT FP_OUTPUT, "    BCX_ScaleX = 1;"
            FPRINT FP_OUTPUT, "    BCX_ScaleY = 1;"
            FPRINT FP_OUTPUT, "  }"
            FPRINT FP_OUTPUT, "  else if (_stricmp((char*)metric,", ENC$("DPI"), ")==0)"
            FPRINT FP_OUTPUT, "  {"
            FPRINT FP_OUTPUT, "    HDC  hDc = GetDC(0);"
            FPRINT FP_OUTPUT, "    BCX_ScaleX = (GetDeviceCaps(hDc, LOGPIXELSX) / 96);"
            FPRINT FP_OUTPUT, "    BCX_ScaleY = (GetDeviceCaps(hDc, LOGPIXELSY) / 96);"
            FPRINT FP_OUTPUT, "    ReleaseDC(0, hDc);"
            FPRINT FP_OUTPUT, "  }"
            FPRINT FP_OUTPUT, "  else"
            FPRINT FP_OUTPUT, "  {"
            FPRINT FP_OUTPUT, "    RECT  rc = {0,0,4,8};"
            FPRINT FP_OUTPUT, "    MapDialogRect(NULL,&rc);"
            FPRINT FP_OUTPUT, "    BCX_ScaleX = rc.right/2;"
            FPRINT FP_OUTPUT, "    BCX_ScaleY = rc.bottom/4;"
            FPRINT FP_OUTPUT, "  }"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF


        IF Use_GUINoMain THEN
            IF Use_BCX_MsgPump THEN
                FPRINT FP_OUTPUT, "int BCX_MsgPump (HACCEL Accel)"
                FPRINT FP_OUTPUT, "{"
                FPRINT FP_OUTPUT, "  MSG  Msg;"
                FPRINT FP_OUTPUT, "  if (Accel)"
                FPRINT FP_OUTPUT, "  {"
                FPRINT FP_OUTPUT, "    while(GetMessage(&Msg,NULL,0,0) > 0)"
                FPRINT FP_OUTPUT, "    {"
                FPRINT FP_OUTPUT, "      if (!TranslateAccelerator(GetActiveWindow(),Accel,&Msg) && !IsWindow(GetActiveWindow())||!IsDialogMessage(GetActiveWindow(),&Msg))"
                FPRINT FP_OUTPUT, "      {"
                FPRINT FP_OUTPUT, "        TranslateMessage(&Msg);"
                FPRINT FP_OUTPUT, "        DispatchMessage(&Msg);"
                FPRINT FP_OUTPUT, "      }"
                FPRINT FP_OUTPUT, "    }"
                FPRINT FP_OUTPUT, "  }"
                FPRINT FP_OUTPUT, "  else"
                FPRINT FP_OUTPUT, "  {"
                FPRINT FP_OUTPUT, "    while(GetMessage(&Msg,NULL,0,0) > 0)"
                FPRINT FP_OUTPUT, "    {"
                FPRINT FP_OUTPUT, "      if (!IsWindow(GetActiveWindow())||!IsDialogMessage(GetActiveWindow(),&Msg))"
                FPRINT FP_OUTPUT, "      {"
                FPRINT FP_OUTPUT, "        TranslateMessage(&Msg);"
                FPRINT FP_OUTPUT, "        DispatchMessage(&Msg);"
                FPRINT FP_OUTPUT, "      }"
                FPRINT FP_OUTPUT, "    }"
                FPRINT FP_OUTPUT, "  }"
                FPRINT FP_OUTPUT, "  return Msg.wParam;"
                FPRINT FP_OUTPUT, "}\n\n"
            END IF
        END IF

        IF Use_MDIGUINoMain THEN
            IF Use_BCX_MDI_MsgPump THEN
                FPRINT FP_OUTPUT, "int BCX_MDI_MsgPump (HACCEL  Accel)"
                FPRINT FP_OUTPUT, "{"
                FPRINT FP_OUTPUT, "  MSG  Msg;"
                FPRINT FP_OUTPUT, "  if (Accel)"
                FPRINT FP_OUTPUT, "  {"
                FPRINT FP_OUTPUT, "    if (!BCX_hwndMDIClient)"
                FPRINT FP_OUTPUT, "      return FALSE;"
                FPRINT FP_OUTPUT, "    while(GetMessage(&Msg,NULL,0,0) > 0)"
                FPRINT FP_OUTPUT, "    {"
                FPRINT FP_OUTPUT, "      if (!TranslateMDISysAccel(BCX_hwndMDIClient,&Msg))"
                FPRINT FP_OUTPUT, "      {"
                FPRINT FP_OUTPUT, "        if (!TranslateAccelerator(GetActiveWindow(),Accel,&Msg))"
                FPRINT FP_OUTPUT, "        {"
                FPRINT FP_OUTPUT, "          TranslateMessage(&Msg);"
                FPRINT FP_OUTPUT, "          DispatchMessage(&Msg);"
                FPRINT FP_OUTPUT, "        }"
                FPRINT FP_OUTPUT, "      }"
                FPRINT FP_OUTPUT, "    }"
                FPRINT FP_OUTPUT, "  }"
                FPRINT FP_OUTPUT, "  else"
                FPRINT FP_OUTPUT, "  {"
                FPRINT FP_OUTPUT, "    if (!BCX_hwndMDIClient)"
                FPRINT FP_OUTPUT, "      return FALSE;"
                FPRINT FP_OUTPUT, "    while(GetMessage(&Msg,NULL,0,0) > 0)"
                FPRINT FP_OUTPUT, "    {"
                FPRINT FP_OUTPUT, "      if (!TranslateMDISysAccel(BCX_hwndMDIClient,&Msg))"
                FPRINT FP_OUTPUT, "       {"
                FPRINT FP_OUTPUT, "         TranslateMessage(&Msg);"
                FPRINT FP_OUTPUT, "         DispatchMessage(&Msg);"
                FPRINT FP_OUTPUT, "       }"
                FPRINT FP_OUTPUT, "     }"
                FPRINT FP_OUTPUT, "   }"
                FPRINT FP_OUTPUT, "  return Msg.wParam;"
                FPRINT FP_OUTPUT, "}\n\n"
            END IF
        END IF

        IF Use_BCX_RegWnd THEN
            FPRINT FP_OUTPUT, "void BCX_RegWnd (PCTSTR classname, WNDPROC Form_WndProc)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  if (classname[0] == 0)"
            FPRINT FP_OUTPUT, "  {"
            FPRINT FP_OUTPUT, "    MessageBox (GetActiveWindow(),"
            FPRINT FP_OUTPUT, "                ", ENC$("Empty String For BCX_ClassName NOT Allowed"), ","
            FPRINT FP_OUTPUT, "                ", ENC$("Empty ClassName"), ",0);"
            FPRINT FP_OUTPUT, "    fflush(stdout);"
            FPRINT FP_OUTPUT, "    ExitProcess(1);"
            FPRINT FP_OUTPUT, "  }"
            FPRINT FP_OUTPUT, "  if (GetClassInfoEx(BCX_hInstance, classname, &BCX_WndClass)!=0)"
            FPRINT FP_OUTPUT, "  {"
            FPRINT FP_OUTPUT, "    if (!Form_WndProc)"
            FPRINT FP_OUTPUT, "      UnregisterClass(classname,BCX_hInstance);"
            FPRINT FP_OUTPUT, "    return;"
            FPRINT FP_OUTPUT, "  }"
            FPRINT FP_OUTPUT, "  if (!BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    BCX_InitGUI();"
            FPRINT FP_OUTPUT, "  if (BCX_ScaleX == 0 && BCX_ScaleY == 0)"
            FPRINT FP_OUTPUT, "    BCX_SetMetric(", ENC$("Pixels"), ");"
            FPRINT FP_OUTPUT, "  strcpy(BCX_ClassName,classname);"
            FPRINT FP_OUTPUT, "  BCX_WndClass.lpfnWndProc = Form_WndProc;"
            FPRINT FP_OUTPUT, "  BCX_WndClass.hInstance = BCX_hInstance;"
            FPRINT FP_OUTPUT, "  BCX_WndClass.lpszClassName = classname;"
            FPRINT FP_OUTPUT, "  RegisterClassEx(&BCX_WndClass);"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF

        IF Use_BCX_InitGUI THEN
            FPRINT FP_OUTPUT, "void BCX_InitGUI (void)"
            FPRINT FP_OUTPUT, "{"
            FPRINT FP_OUTPUT, "  INITCOMMONCONTROLSEX iccex;"
            FPRINT FP_OUTPUT, "  if (BCX_GUI_Init)"
            FPRINT FP_OUTPUT, "    return;"

            IF m_iMatchWrd (GUIMetric$, "pixels") THEN
                FPRINT FP_OUTPUT, "  BCX_ScaleX = 1;"
                FPRINT FP_OUTPUT, "  BCX_ScaleY = 1;"
            ELSEIF m_iMatchWrd (GUIMetric$, "dpi") THEN
                FPRINT FP_OUTPUT, "  HDC  hDc = GetDC(0);"
                FPRINT FP_OUTPUT, "  BCX_ScaleX = (GetDeviceCaps(hDc, LOGPIXELSX) / 96);"
                FPRINT FP_OUTPUT, "  BCX_ScaleY = (GetDeviceCaps(hDc, LOGPIXELSY) / 96);"
                FPRINT FP_OUTPUT, "  ReleaseDC(0, hDc);"
            ELSE
                FPRINT FP_OUTPUT, "  RECT rc = {0, 0, 4, 8};"
                FPRINT FP_OUTPUT, "  MapDialogRect(NULL, &rc);"
                FPRINT FP_OUTPUT, "  BCX_ScaleX = rc.right/2;"
                FPRINT FP_OUTPUT, "  BCX_ScaleY = rc.bottom/4;"
            END IF

            FPRINT FP_OUTPUT, "  BCX_hInstance = GetModuleHandle(NULL);"
            FPRINT FP_OUTPUT, "  BCX_hwndMDIClient = NULL;"
            FPRINT FP_OUTPUT, "  BCX_WndClass.cbSize = sizeof(BCX_WndClass);"
            FPRINT FP_OUTPUT, "  BCX_WndClass.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC|CS_DBLCLKS;"
            FPRINT FP_OUTPUT, "  BCX_WndClass.cbClsExtra = 0;"
            FPRINT FP_OUTPUT, "  BCX_WndClass.cbWndExtra = 0;"

            IF ISNULL(GUIIcon$) THEN GUIIcon$ = " LoadIcon(NULL, IDI_WINLOGO);"

            FPRINT FP_OUTPUT, "  BCX_WndClass.hIcon = "; GUIIcon$; ";"
            FPRINT FP_OUTPUT, "  BCX_WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);"
            FPRINT FP_OUTPUT, "  BCX_WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);"
            FPRINT FP_OUTPUT, "  BCX_WndClass.lpszMenuName = NULL;"
            FPRINT FP_OUTPUT, "  BCX_WndClass.hIconSm = NULL;"
            FPRINT FP_OUTPUT, "  iccex.dwSize = sizeof(INITCOMMONCONTROLSEX);"
            FPRINT FP_OUTPUT, "  iccex.dwICC = ICC_LISTVIEW_CLASSES|ICC_TREEVIEW_CLASSES |"
            FPRINT FP_OUTPUT, "                ICC_BAR_CLASSES|ICC_TAB_CLASSES|ICC_UPDOWN_CLASS |"
            FPRINT FP_OUTPUT, "                ICC_PROGRESS_CLASS|ICC_USEREX_CLASSES|ICC_DATE_CLASSES;"
            FPRINT FP_OUTPUT, "  InitCommonControlsEx(&iccex);"
            FPRINT FP_OUTPUT, "  OleInitialize(0);"
            FPRINT FP_OUTPUT, "  CoInitialize(0);"
            FPRINT FP_OUTPUT, "  BCX_GUI_Init = TRUE;"
            FPRINT FP_OUTPUT, "}\n\n"
        END IF
    END IF
END SUB ' Emit_RT_SystemCOM2

SUB Emit_COM_SupportTypes (FP_OUTPUT AS FILE)
    '*********************************************************************
    ' Sub: Emit_COM_SupportTypes (part of BCX COM parser)
    ' This sub emits standard typedefs and global variables
    ' used by BCX late binding COM interface.
    '*********************************************************************
    DIM RAW prefix$ = "static "
    IF Use_Project THEN prefix$ = ""

    FPRINT FP_OUTPUT, "// *************************************************"
    FPRINT FP_OUTPUT, "//    Global vars used by late binding COM support"
    FPRINT FP_OUTPUT, "// *************************************************"
    FPRINT FP_OUTPUT, SPC$
    FPRINT FP_OUTPUT, prefix$ + "PARAM_VARARRAY  COM_param_list;"
    FPRINT FP_OUTPUT, prefix$ + "_TCHAR          COM_last_ErrMsg[4096];"
    FPRINT FP_OUTPUT, prefix$ + "_TCHAR          COM_ErrMsg[64];"
    FPRINT FP_OUTPUT, prefix$ + "int             COM_plist_index = 0;"
    FPRINT FP_OUTPUT, prefix$ + "VARIANT         COM_vt_result;"
    FPRINT FP_OUTPUT, prefix$ + "HRESULT         COM_last_HR;"
    FPRINT FP_OUTPUT, prefix$ + "BOOL            COM_ole_initd = FALSE;"
    FPRINT FP_OUTPUT, prefix$ + "int             COM_objects_cnt = 0;"
    FPRINT FP_OUTPUT, prefix$ + "int             COM_reset_chain = 0;"
    FPRINT FP_OUTPUT, prefix$ + "BOOL            COM_BCX_ERROR = FALSE;"
    FPRINT FP_OUTPUT, prefix$ + "BOOL            COM_bSHOW_ERROR = FALSE;"
    FPRINT FP_OUTPUT, prefix$ + "SAFEARRAY *     COM_PTR_safearray = NULL;"
    FPRINT FP_OUTPUT, prefix$ + "PWSTR           COM_PWSTR_temp = NULL;"
    FPRINT FP_OUTPUT, prefix$ + "char*           COM_psz_tmp = NULL;"
    FPRINT FP_OUTPUT, prefix$ + "ULONG           COM_wstr_size = 0;"
    FPRINT FP_OUTPUT, prefix$ + "ULONG           COM_zstr_size = 0;"
    FPRINT FP_OUTPUT, prefix$ + "BOOL            COM_GetEnum_iface = FALSE;"

    ' <WITH - END WITH>
    FPRINT FP_OUTPUT, prefix$ + "int             COM_dispatch_storage[", c_COM_Max_Withs, "];"
    FPRINT FP_OUTPUT, prefix$ + "int             COM_dispatch_storage_index = 0;"
    FPRINT FP_OUTPUT, prefix$ + "int             COM_dispatch_at_offset = 0;" ' for nested (with/end with)
    ' </WITH - END WITH>

    IF Use_COM_Collections THEN
        FPRINT FP_OUTPUT, prefix$ + "VARIANT         COM_ack_var;"
        FPRINT FP_OUTPUT, prefix$ + "IEnumVARIANT*   COM_enum_var = NULL;"
        FPRINT FP_OUTPUT, prefix$ + "ULONG           COM_long_coll = 0;"
    END IF
END SUB ' Emit_COM_SupportTypes





SUB Emit_COM_StandardSet (FP_OUTPUT AS FILE)
    '*********************************************************************
    ' Code emission for BCX late binding COM interface.
    '*********************************************************************
    FPRINT FP_OUTPUT, "// *************************************************"
    FPRINT FP_OUTPUT, "//              COM Runtime Functions"
    FPRINT FP_OUTPUT, "// *************************************************"
    FPRINT FP_OUTPUT, SPC$
    FPRINT FP_OUTPUT, "OBJECT COM (PCTSTR szProgID_) {"
    FPRINT FP_OUTPUT, "    static OBJECT oProxy;"
    FPRINT FP_OUTPUT, "    BCX_CreateObject ((char*)szProgID_, &oProxy);"
    FPRINT FP_OUTPUT, "    return oProxy;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void UNCOM (OBJECT oObj_) {"
    FPRINT FP_OUTPUT, "    static OBJECT oProxy;"
    FPRINT FP_OUTPUT, "    oProxy = oObj_;"
    FPRINT FP_OUTPUT, "    BCX_SetNothing (&oProxy);"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "int ISOBJECT (OBJECT Obj) {"
    FPRINT FP_OUTPUT, "    if(Obj.pStatus)"
    FPRINT FP_OUTPUT, "        return TRUE;"
    FPRINT FP_OUTPUT, "   else"
    FPRINT FP_OUTPUT, "       return FALSE;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "HRESULT BCX_GET_COM_ERROR_CODE (void) {"
    FPRINT FP_OUTPUT, "    return COM_last_HR;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "_TCHAR* BCX_GET_COM_ERROR_DESC (void) {"
    FPRINT FP_OUTPUT, "    return COM_last_ErrMsg;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "BOOL BCX_GET_COM_SUCCESS (void) {"
    FPRINT FP_OUTPUT, "    return (!COM_BCX_ERROR);"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void BCX_SHOW_COM_ERRORS (BOOL Show_err) {"
    FPRINT FP_OUTPUT, "    COM_bSHOW_ERROR = Show_err;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "BOOL BCX_GET_COM_STATUS(OBJECT *object) {"
    FPRINT FP_OUTPUT, "    if(object)"
    FPRINT FP_OUTPUT, "        return object->pStatus;"
    FPRINT FP_OUTPUT, "    return 0;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void  COM_clean_plist (void) {"
    FPRINT FP_OUTPUT, "int total_parms = COM_plist_index;"
    FPRINT FP_OUTPUT, "if (COM_plist_index > 0)"
    FPRINT FP_OUTPUT, "   {"
    FPRINT FP_OUTPUT, "      do"
    FPRINT FP_OUTPUT, "   {"

    IF COM_build_trace_code THEN
        FPRINT FP_OUTPUT, "    sprintf(COM_trace_line, ", ENC$("+++ clear parameter list. Clear variant at index %d. Variant type = %d"), ",COM_plist_index-1,"
        FPRINT FP_OUTPUT, "          COM_PARAMS[COM_plist_index-1].vt);"
        FPRINT FP_OUTPUT, "    COM_add_trace_line (COM_trace_line);"
    END IF

    ' it appears that VariantClear can't clear a variant that has a vt = VT_ARRAY | VT_VARIANT

    FPRINT FP_OUTPUT, "        COM_last_HR = VariantClear (&COM_PARAMS[COM_plist_index-1]);"
    FPRINT FP_OUTPUT, "        if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "        {"
    FPRINT FP_OUTPUT, "        wsprintf (COM_ErrMsg, _T(", ENC$("\\nVariant type = %d, at index %d, total params = %d.") , "),"
    FPRINT FP_OUTPUT, "                  COM_PARAMS[COM_plist_index-1].vt, COM_plist_index-1, total_parms);"
    FPRINT FP_OUTPUT, "        COM_HR_ErrMsg (COM_last_HR, _T(", ENC$("Error while cleaning parameter list." ), "));"
    FPRINT FP_OUTPUT, "      }"
    FPRINT FP_OUTPUT, "        COM_plist_index--;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "      while (COM_plist_index > 0);"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void  COM_reset_disp_chain (OBJECT *object) {"
    FPRINT FP_OUTPUT, "  if (object->ipointer>COM_dispatch_at_offset)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    do"
    FPRINT FP_OUTPUT, "    {"

    IF COM_build_trace_code THEN
        FPRINT FP_OUTPUT, "  sprintf(COM_trace_line, ", ENC$("Dispath release at index %d. Variant Type = %d")
        FPRINT FP_OUTPUT, "  ,object->ipointer,object->pObjects[object->ipointer].vt);"
        FPRINT FP_OUTPUT, "  COM_add_trace_line (COM_trace_line);"
    END IF

    FPRINT FP_OUTPUT, "      VariantClear (&object->pObjects[object->ipointer]);"
    FPRINT FP_OUTPUT, "      object->ipointer--;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    while (object->ipointer > COM_dispatch_at_offset);"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void  COM_ole_uninitialize (void) {"
    FPRINT FP_OUTPUT, "  if (COM_objects_cnt)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    _TCHAR ermm[BCXSTRSIZE];"
    FPRINT FP_OUTPUT, "    wsprintf (ermm,_T(", ENC$("Check SET Nothing statement!\\nUnreleased objects: %d"), "),COM_objects_cnt);"
    FPRINT FP_OUTPUT, "    COM_MSGBOX (ermm, _T(", ENC$("Memory leaks detected!"), "),MB_OK|MB_ICONWARNING|MB_TASKMODAL);"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  COM_FREE_TEMP_WIDE_STRING();"
    FPRINT FP_OUTPUT, "  COM_FREE_TEMP_ANSI_STRING();"
    FPRINT FP_OUTPUT, "  CoUninitialize();"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void  COM_get_next_dispatch (OBJECT *object, PWSTR comsegment) {"
    FPRINT FP_OUTPUT, "  if (!object->pStatus) return;"
    FPRINT FP_OUTPUT, "  if (0 == object->ipointer) COM_BCX_ERROR = FALSE;"
    FPRINT FP_OUTPUT, "  if (COM_BCX_ERROR) return;"
    FPRINT FP_OUTPUT, "  COM_reset_chain++;"
    FPRINT FP_OUTPUT, "  COM_invoke (object, comsegment,COM_PROPS,&object->pObjects[object->ipointer+1]);"
    FPRINT FP_OUTPUT, "  COM_reset_chain--;"
    FPRINT FP_OUTPUT, "  if (!COM_BCX_ERROR)"
    FPRINT FP_OUTPUT, "     object->ipointer++;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void COM_HR_ErrMsg (HRESULT hr, _TCHAR *extra_info) {"
    FPRINT FP_OUTPUT, "  COM_BCX_ERROR = TRUE;"
    FPRINT FP_OUTPUT, "  PVOID pMsgBuf;"
    FPRINT FP_OUTPUT, SPC$
    FPRINT FP_OUTPUT, "  FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,"
    FPRINT FP_OUTPUT, "  NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (PTSTR)&pMsgBuf, 0, NULL);"
    FPRINT FP_OUTPUT, SPC$
    FPRINT FP_OUTPUT, "  wsprintf(COM_last_ErrMsg, _T(", ENC$("COM error code %d (0x%X)\\n%s\\n%s\\nmember: %s"), "),"
    FPRINT FP_OUTPUT, "  hr, hr, extra_info, pMsgBuf, COM_ErrMsg);"

    IF COM_build_trace_code  THEN
        FPRINT FP_OUTPUT, SPC$
        FPRINT FP_OUTPUT, "  COM_trace_add_line(", ENC$(">>> COM ERROR DUMP >>> COM ERROR DUM >>> COM ERROR DUMP >>>"), ");"
        FPRINT FP_OUTPUT, "  COM_trace_add_line(COM_last_ErrMsg);"
        FPRINT FP_OUTPUT, "  COM_trace_add_line(", ENC$("<<< COM ERROR DUMP <<< COM ERROR DUM <<< COM ERROR DUMP <<<"), ");"
        FPRINT FP_OUTPUT, SPC$
    END IF

    FPRINT FP_OUTPUT, SPC$
    FPRINT FP_OUTPUT, "  memset(&COM_ErrMsg,0,sizeof(COM_ErrMsg));"
    FPRINT FP_OUTPUT, "  if (COM_bSHOW_ERROR)"
    FPRINT FP_OUTPUT, "      COM_MSGBOX(COM_last_ErrMsg,_T(", ENC$("COM Parser Error Report:"), "),"
    FPRINT FP_OUTPUT, "      MB_OK|MB_ICONERROR|MB_SYSTEMMODAL);"
    FPRINT FP_OUTPUT, "  LocalFree(pMsgBuf);"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void BCX_SetNothing (OBJECT *obj) {"
    FPRINT FP_OUTPUT, "  if (!obj->pStatus) return;"

    IF COM_build_trace_code THEN
        FPRINT FP_OUTPUT, "  COM_trace_add_line (", ENC$("Called BCX_SetNothing"), ");"
    END IF

    FPRINT FP_OUTPUT, "  COM_objects_cnt--;"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    if (obj->p_unknown) obj->p_unknown->Release();"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    if (obj->p_unknown) obj->p_unknown->lpVtbl->Release(obj->p_unknown);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  if (obj->ipointer)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_reset_disp_chain (obj);"
    FPRINT FP_OUTPUT, "    obj->ipointer = 0;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  COM_last_HR = VariantClear (&obj->pObjects[0]);"
    FPRINT FP_OUTPUT, "  if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    lstrcpy(COM_ErrMsg, _T(", ENC$("BCX_SetNothing Failed!"), "));"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR, _T(", ENC$("Release of IDispatch objs failed!" ), "));"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  obj->pStatus = FALSE;"
    FPRINT FP_OUTPUT, "  Sleep(100);"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void COM_ole_initialize (void) {"
    FPRINT FP_OUTPUT, "  if (COM_ole_initd) return;"

    IF COM_build_trace_code  THEN
        FPRINT FP_OUTPUT, "DeleteFile (", ENC$("c:\\com_trace.txt"), ");"
    END IF

    FPRINT FP_OUTPUT, "  #ifdef __BCX_MULTITHREADED__"
    FPRINT FP_OUTPUT, "    COM_last_HR = CoInitializeEx (NULL, COINIT_MULTITHREADED);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    COM_last_HR = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  if (SUCCEEDED (COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_ole_initd = TRUE;"
    FPRINT FP_OUTPUT, "    VariantInit (&COM_vt_result);"

    ' Next line atexit ANSI C function causes COM_ole_uninitialize to call when program exits

    FPRINT FP_OUTPUT, "    atexit (COM_ole_uninitialize);"
    FPRINT FP_OUTPUT, SPC$
    FPRINT FP_OUTPUT, "    COM_dispatch_storage[0] = 0;"
    FPRINT FP_OUTPUT, "    COM_dispatch_storage_index = 0;"
    FPRINT FP_OUTPUT, SPC$
    FPRINT FP_OUTPUT, "    if (COM_PWSTR_temp) CoTaskMemFree((void*)COM_PWSTR_temp);"
    FPRINT FP_OUTPUT, "    COM_PWSTR_temp = (PWSTR)CoTaskMemAlloc (BCXSTRSIZE);"
    FPRINT FP_OUTPUT, "    if (NULL == COM_PWSTR_temp)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      COM_wstr_size = 0;"
    FPRINT FP_OUTPUT, "      COM_last_HR =  E_OUTOFMEMORY;"
    FPRINT FP_OUTPUT, "      COM_HR_ErrMsg (COM_last_HR,_T("
    FPRINT FP_OUTPUT, "     ", ENC$("CoInitializeEx: Memory allocation failure!"), "));"
    FPRINT FP_OUTPUT, "      return;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    COM_wstr_size = BCXSTRSIZE;"
    FPRINT FP_OUTPUT, "    if (COM_psz_tmp) free(COM_psz_tmp);"
    FPRINT FP_OUTPUT, "    COM_psz_tmp = (char*)calloc(BCXSTRSIZE, sizeof(char));"
    FPRINT FP_OUTPUT, "    if (NULL == COM_psz_tmp)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      COM_last_HR =  E_OUTOFMEMORY;"
    FPRINT FP_OUTPUT, "      COM_HR_ErrMsg (COM_last_HR,_T("
    FPRINT FP_OUTPUT, "     ", ENC$("CoInitializeEx: Memory allocation failure!"), "));"
    FPRINT FP_OUTPUT, "    return;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    COM_zstr_size = BCXSTRSIZE;"
    FPRINT FP_OUTPUT, "    return;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  else"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("CoInitializeEx Failed!"), "));"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void COM_build_except_info (HRESULT hr, EXCEPINFO *pexcep, UINT uiArgErr) {"
    FPRINT FP_OUTPUT, "  SCODE oleSCODE;"
    FPRINT FP_OUTPUT, "  static _TCHAR lv_message[BCXSTRSIZE];"
    FPRINT FP_OUTPUT, "  oleSCODE = GetScode(hr);"
    FPRINT FP_OUTPUT, "  for (;;)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    if (oleSCODE==DISP_E_PARAMNOTFOUND)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      wsprintf (lv_message, _T(", ENC$("\\nArgument not found, argument %d."), "), uiArgErr);"
    FPRINT FP_OUTPUT, "      _tcscat(COM_last_ErrMsg, lv_message);"
    FPRINT FP_OUTPUT, "      break;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    if (oleSCODE==DISP_E_TYPEMISMATCH)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      wsprintf (lv_message, _T(", ENC$("\\nType mismatch, argument %d."), "), uiArgErr);"
    FPRINT FP_OUTPUT, "      _tcscat (COM_last_ErrMsg, lv_message);"
    FPRINT FP_OUTPUT, "      break;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    if (oleSCODE==DISP_E_BADVARTYPE)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      _tcscat(COM_last_ErrMsg, _T(", ENC$("\\nOne or more invalid VARIANT arguments."), "));"
    FPRINT FP_OUTPUT, "      break;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    if (oleSCODE==E_INVALIDARG)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      _tcscat(COM_last_ErrMsg, _T(", ENC$("\\nOne of the arguments is invalid."), "));"
    FPRINT FP_OUTPUT, "      break;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    break;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  if (pexcep)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    wsprintf(lv_message, _T(", ENC$("\\nCOM Error %X:"), "), pexcep->wCode);"
    FPRINT FP_OUTPUT, "    if (pexcep->bstrDescription)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      _TCHAR err_desc[512];"
    FPRINT FP_OUTPUT, "      #ifndef UNICODE"
    FPRINT FP_OUTPUT, "        COM_last_HR = COM_WS2AS (pexcep->bstrDescription);"
    FPRINT FP_OUTPUT, "        if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "          COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("Get Error Desc: W2A failure!"), "));"
    FPRINT FP_OUTPUT, "        else"
    FPRINT FP_OUTPUT, "          wsprintf(err_desc, _T(", ENC$("\\nException desc: %s"), "), COM_psz_tmp);"
    FPRINT FP_OUTPUT, "      #else"
    FPRINT FP_OUTPUT, "          wsprintf(err_desc, _T(", ENC$("\\nException desc: %s"), "), pexcep->bstrDescription);"
    FPRINT FP_OUTPUT, "      #endif"
    FPRINT FP_OUTPUT, "      _tcscat(lv_message, err_desc);"
    FPRINT FP_OUTPUT, "      SysFreeString(pexcep->bstrDescription);"
    FPRINT FP_OUTPUT, "      pexcep->bstrDescription = NULL;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    if (pexcep->bstrSource)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      _TCHAR err_desc[512];"
    FPRINT FP_OUTPUT, "      #ifndef UNICODE"
    FPRINT FP_OUTPUT, "        COM_last_HR = COM_WS2AS (pexcep->bstrSource);"
    FPRINT FP_OUTPUT, "        if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "            COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("Get Error Source Failed! W2A failure!"), "));"
    FPRINT FP_OUTPUT, "        else"
    FPRINT FP_OUTPUT, "            wsprintf(err_desc, _T(", ENC$("\\nException source: %s"), "), COM_psz_tmp);"
    FPRINT FP_OUTPUT, "      #else"
    FPRINT FP_OUTPUT, "            wsprintf(err_desc, _T(", ENC$("\\nException source: %s"), "), pexcep->bstrSource);"
    FPRINT FP_OUTPUT, "      #endif"
    FPRINT FP_OUTPUT, "      _tcscat (lv_message, err_desc);"
    FPRINT FP_OUTPUT, "      SysFreeString (pexcep->bstrSource);"
    FPRINT FP_OUTPUT, "      pexcep->bstrSource = NULL;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    if (pexcep->bstrHelpFile)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      _TCHAR err_desc[512];"
    FPRINT FP_OUTPUT, "      #ifndef UNICODE"
    FPRINT FP_OUTPUT, "        COM_last_HR = COM_WS2AS (pexcep->bstrHelpFile);"
    FPRINT FP_OUTPUT, "        if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "        COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("Help File failed: W2A failure!"), "));"
    FPRINT FP_OUTPUT, "        else"
    FPRINT FP_OUTPUT, "        wsprintf(err_desc, _T("
    FPRINT FP_OUTPUT, "        ", ENC$("\\nHelp file: %s | topic: %lu"), "), COM_psz_tmp, pexcep->dwHelpContext);"
    FPRINT FP_OUTPUT, "      #else"
    FPRINT FP_OUTPUT, "        wsprintf(err_desc, _T("
    FPRINT FP_OUTPUT, "        ", ENC$("\\nHelp file: %s | topic: %lu"), "), pexcep->bstrHelpFile, pexcep->dwHelpContext);"
    FPRINT FP_OUTPUT, "      #endif"
    FPRINT FP_OUTPUT, "      _tcscat(lv_message, err_desc);"
    FPRINT FP_OUTPUT, "      SysFreeString (pexcep->bstrHelpFile);"
    FPRINT FP_OUTPUT, "      pexcep->bstrHelpFile = NULL;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    _tcscat (COM_last_ErrMsg ,lv_message);"
    FPRINT FP_OUTPUT, "  }"

    IF COM_build_trace_code  THEN
        FPRINT FP_OUTPUT, "  COM_trace_add_line(", ENC$(">>> COM EXCEPTION DUMP >>> COM EXCEPTION DUMP >>>"), ");"
        FPRINT FP_OUTPUT, "  COM_trace_add_line(COM_last_ErrMsg);"
        FPRINT FP_OUTPUT, "  COM_trace_add_line(", ENC$("<<< COM EXCEPTION DUMP <<< COM EXCEPTION DUMP <<<"), ");"
    END IF

    FPRINT FP_OUTPUT, "  if (COM_bSHOW_ERROR)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_MSGBOX(COM_last_ErrMsg, _T(", ENC$("COM Parser Exception Info:"), "),"
    FPRINT FP_OUTPUT, "    MB_OK|MB_ICONERROR|MB_SYSTEMMODAL);"

    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "DISPID COM_get_dispatch_ID (IDispatch* lpDispatch, PWSTR comsegment) {"
    FPRINT FP_OUTPUT, "  static DISPID D_ID;"
    FPRINT FP_OUTPUT, "  D_ID = 0;"
    FPRINT FP_OUTPUT, "  if (!lpDispatch) return -1;"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    COM_last_HR = lpDispatch->GetIDsOfNames"
    FPRINT FP_OUTPUT, "                 (IID_NULL, &comsegment, 1, LOCALE_SYSTEM_DEFAULT, &D_ID);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    COM_last_HR = lpDispatch->lpVtbl->GetIDsOfNames"
    FPRINT FP_OUTPUT, "                 (lpDispatch, &IID_NULL, &comsegment, 1, LOCALE_SYSTEM_DEFAULT, &D_ID);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("Unrecognized member name"), "));"
    FPRINT FP_OUTPUT, "    return -1;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  return D_ID;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void COM_invoke (OBJECT *object, PWSTR comsegment, WORD wFlags, VARIANT *pvResult) {"
    FPRINT FP_OUTPUT, "  if (!object->pStatus) return;"
    FPRINT FP_OUTPUT, "  if (COM_BCX_ERROR) return;"
    FPRINT FP_OUTPUT, "  DISPID lv_DID;"
    FPRINT FP_OUTPUT, "  EXCEPINFO exception;"
    FPRINT FP_OUTPUT, "  UINT argerr = 0;"
    FPRINT FP_OUTPUT, "  DISPPARAMS dp = {NULL, NULL, 0, 0 };"
    FPRINT FP_OUTPUT, "  WORD invoke_flags = 0;"
    FPRINT FP_OUTPUT, "  DISPID setdispid = DISPID_PROPERTYPUT;"

    IF COM_build_trace_code THEN
        FPRINT FP_OUTPUT, "  char extra_error_info[BCXSTRSIZE];"
    END IF

    FPRINT FP_OUTPUT, "  if (COM_GetEnum_iface)"
    FPRINT FP_OUTPUT, "    lv_DID = DISPID_NEWENUM;"
    FPRINT FP_OUTPUT, "  else"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    lv_DID = COM_get_dispatch_ID (object->pObjects[object->ipointer].pdispVal, comsegment);"
    FPRINT FP_OUTPUT, "    if (-1 == lv_DID) goto cleanInProp;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  memset (&exception, 0, sizeof(EXCEPINFO));"
    FPRINT FP_OUTPUT, "  if (COM_plist_index>0)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    setdispid = DISPID_PROPERTYPUT;"
    FPRINT FP_OUTPUT, "    dp.rgvarg = (VARIANTARG*)COM_PARAMS;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  if (wFlags & DISPATCH_PROPERTYPUT)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    dp.rgdispidNamedArgs = &setdispid;"
    FPRINT FP_OUTPUT, "    dp.cNamedArgs = 1;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  dp.cArgs = COM_plist_index;"
    FPRINT FP_OUTPUT, "  invoke_flags = wFlags;"
    FPRINT FP_OUTPUT, "  if (wFlags & DISPATCH_PROPERTYGET)"
    FPRINT FP_OUTPUT, "    if (pvResult) VariantInit(pvResult);"

    IF COM_build_trace_code  THEN
        FPRINT FP_OUTPUT, "  COM_trace_dump_DISPPARAMS(&dp);"
        FPRINT FP_OUTPUT, "  COM_trace_dump_flags(wFlags);"
        FPRINT FP_OUTPUT, "  COM_trace_dump_indicators(object);"
    END IF

    FPRINT FP_OUTPUT, "  if (VT_DISPATCH!=object->pObjects[object->ipointer].vt||NULL==object->pObjects[object->ipointer].pdispVal)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "     COM_last_HR = E_NOINTERFACE;"
    FPRINT FP_OUTPUT, "     COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("COM_invoke::Invalid IDispatch interface."), "));"
    FPRINT FP_OUTPUT, "     goto cleanInProp;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "    #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    COM_last_HR = object->pObjects[object->ipointer].pdispVal"
    FPRINT FP_OUTPUT, "      ->Invoke (lv_DID, IID_NULL, LOCALE_SYSTEM_DEFAULT, "
    FPRINT FP_OUTPUT, "        invoke_flags, &dp, pvResult, &exception, &argerr);"
    FPRINT FP_OUTPUT, "    #else"
    FPRINT FP_OUTPUT, "    COM_last_HR = object->pObjects[object->ipointer].pdispVal->lpVtbl"
    FPRINT FP_OUTPUT, "      ->Invoke(object->pObjects[object->ipointer].pdispVal, lv_DID, &IID_NULL, "
    FPRINT FP_OUTPUT, "        LOCALE_SYSTEM_DEFAULT, invoke_flags , &dp, pvResult, &exception, &argerr);"
    FPRINT FP_OUTPUT, "    #endif"
    FPRINT FP_OUTPUT, "  if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"

    IF COM_build_trace_code  THEN
        FPRINT FP_OUTPUT, "  COM_trace_add_line(", ENC$("Invoke FAILED!"), ");"
    END IF

    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("COM_invoke::Invoke failed."), "));"
    FPRINT FP_OUTPUT, "    COM_build_except_info (COM_last_HR, &exception, argerr);"
    FPRINT FP_OUTPUT, "  }"

    IF COM_build_trace_code  THEN
        FPRINT FP_OUTPUT, "  else "
        FPRINT FP_OUTPUT, "  {"
        FPRINT FP_OUTPUT, "    COM_add_trace_line (", ENC$("Invoke SUCEEDED!"), ");"
        FPRINT FP_OUTPUT, "    if(wFlags & DISPATCH_PROPERTYGET)"
        FPRINT FP_OUTPUT, "    {"
        FPRINT FP_OUTPUT, "      sprintf (extra_error_info,", ENC$("result Variant type = %d"), ",pvResult->vt);"
        FPRINT FP_OUTPUT, "      COM_add_trace_line (extra_error_info);"
        FPRINT FP_OUTPUT, "    }"
        FPRINT FP_OUTPUT, "  }"
    END IF

    FPRINT FP_OUTPUT, "cleanInProp:"
    FPRINT FP_OUTPUT, "  if (V_ISARRAY(&COM_PARAMS[0]))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    if ((VT_ARRAY|VT_VARIANT)==COM_PARAMS[0].vt)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      COM_last_HR = SafeArrayDestroy(V_ARRAY(&COM_PARAMS[0]));"
    FPRINT FP_OUTPUT, "      if (FAILED (COM_last_HR))"
    FPRINT FP_OUTPUT, "      {"
    FPRINT FP_OUTPUT, "        lstrcpy(COM_ErrMsg, _T(", ENC$("SafeArrayDestroy failed"), "));"
    FPRINT FP_OUTPUT, "        COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("Error wiping param list."), "));"
    FPRINT FP_OUTPUT, "      }"
    FPRINT FP_OUTPUT, "      ZeroMemory((PVOID)&COM_PARAMS[0],sizeof(VARIANT));"
    FPRINT FP_OUTPUT, "      COM_PTR_safearray = NULL;"
    FPRINT FP_OUTPUT, "      COM_plist_index = 0;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  if (COM_plist_index)  COM_clean_plist();"
    FPRINT FP_OUTPUT, "  if (0 == COM_reset_chain)  COM_reset_disp_chain(object);"
    FPRINT FP_OUTPUT, "}\n\n"
END SUB ' Emit_COM_StandardSet



SUB Emit_COM_GetObject (FP_OUTPUT AS FILE)
    ' TCHAR is used to support UNICODE versions of programs
    FPRINT FP_OUTPUT, "void BCX_GetObject (_TCHAR *objname, OBJECT *obj) {"
    FPRINT FP_OUTPUT, "  if (!COM_ole_initd) COM_ole_initialize();"
    FPRINT FP_OUTPUT, "  CLSID clsid;"
    FPRINT FP_OUTPUT, "  #ifndef UNICODE"
    FPRINT FP_OUTPUT, "    COM_last_HR = COM_AS2WS (objname);"
    FPRINT FP_OUTPUT, "    if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("CreateObject Failed! A2W failure!"), "));"
    FPRINT FP_OUTPUT, "      return;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    COM_last_HR = COM_WS2AS (COM_PWSTR_temp);"
    FPRINT FP_OUTPUT, "    if (FAILED (COM_last_HR))"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("CreateObject Failed! W2A failure!"), "));"
    FPRINT FP_OUTPUT, "      return;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    sprintf (COM_ErrMsg,", ENC$("%s, WideName(%s)"), ", objname, COM_psz_tmp);"
    FPRINT FP_OUTPUT, "    COM_last_HR = CLSIDFromProgID((LPCOLESTR)COM_PWSTR_temp, (LPCLSID)&clsid);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    COM_last_HR = COM_WS2AS ((PCWSTR)objname);"
    FPRINT FP_OUTPUT, "    lstrcpy (COM_ErrMsg, COM_psz_tmp);"
    FPRINT FP_OUTPUT, "    COM_last_HR = CLSIDFromProgID ((LPCOLESTR)objname, (LPCLSID)&clsid);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  if (FAILED (COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "  #ifndef UNICODE"
    FPRINT FP_OUTPUT, "    BCX_GetObjectMon ((LPCOLESTR)COM_PWSTR_temp, obj);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    BCX_GetObjectMon ((LPCOLESTR)objname, obj);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "    return;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    COM_last_HR = GetActiveObject((REFCLSID)clsid, NULL, (IUnknown**)&obj->p_unknown);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    COM_last_HR = GetActiveObject((REFCLSID)&clsid, NULL, (IUnknown**)&obj->p_unknown);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  if (FAILED (COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("GetActiveObject failed!"), "));"
    FPRINT FP_OUTPUT, "    return;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  else"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    VariantInit (&obj->pObjects[0]);"
    FPRINT FP_OUTPUT, "    #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "      COM_last_HR = obj->p_unknown"
    FPRINT FP_OUTPUT, "      ->QueryInterface(IID_IDispatch, (void**)&obj->pObjects[0].pdispVal);"
    FPRINT FP_OUTPUT, "    #else"
    FPRINT FP_OUTPUT, "      COM_last_HR = obj->p_unknown->lpVtbl"
    FPRINT FP_OUTPUT, "      ->QueryInterface(obj->p_unknown, &IID_IDispatch, (void **)&obj->pObjects[0].pdispVal);"
    FPRINT FP_OUTPUT, "    #endif"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  if (FAILED (COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("QueryInterface::IID_IDispatch  failed!"), "));"
    FPRINT FP_OUTPUT, "    if (obj->p_unknown)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "    #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "      obj->p_unknown->Release();"
    FPRINT FP_OUTPUT, "    #else"
    FPRINT FP_OUTPUT, "      obj->p_unknown->lpVtbl->Release(obj->p_unknown);"
    FPRINT FP_OUTPUT, "    #endif"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  else"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    obj->pObjects[0].vt = VT_DISPATCH;"
    FPRINT FP_OUTPUT, "    obj->pStatus = TRUE;"
    FPRINT FP_OUTPUT, "    obj->ipointer = 0;"
    FPRINT FP_OUTPUT, "    COM_objects_cnt++;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void BCX_GetObjectMon (LPCOLESTR objname, OBJECT *obj) {"
    FPRINT FP_OUTPUT, "  IBindCtx* vBindCtx = NULL;"                  ' Bind context to be used
    FPRINT FP_OUTPUT, "  IMoniker* vMoniker = NULL;"                  ' Receives moniker built from display name
    FPRINT FP_OUTPUT, "  ULONG vChEaten = 0;"                         ' Receives number of characters consumed
    FPRINT FP_OUTPUT, "  COM_last_HR = CreateBindCtx(0, &vBindCtx);"  ' Receives the pointer to the bind context
    FPRINT FP_OUTPUT, "  if (COM_last_HR != S_OK)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("GetObject: CreateBindCtx failed!"), "));"
    FPRINT FP_OUTPUT, "    return;"                                   ' no interfaces, so it may return.
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  COM_last_HR = MkParseDisplayName(vBindCtx, objname, &vChEaten, &vMoniker);"
    FPRINT FP_OUTPUT, "  if (COM_last_HR != S_OK)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("GetObject: Receive Moniker failed!"), "));"
    FPRINT FP_OUTPUT, "    goto CleanGetObjectMon;"                   ' clean all and then exit.
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  VariantInit(&obj->pObjects[0]);"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    COM_last_HR = vMoniker->BindToObject(vBindCtx, NULL, IID_IDispatch, "
    FPRINT FP_OUTPUT, "                                        (void **)&obj->pObjects[0].pdispVal);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    COM_last_HR = vMoniker->lpVtbl->BindToObject(vMoniker, vBindCtx, NULL, &IID_IDispatch,"
    FPRINT FP_OUTPUT, "                                                (void **)&obj->pObjects[0].pdispVal);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  if (COM_last_HR != S_OK)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("GetObject: Moniker BindToObject failed!"), "));"
    FPRINT FP_OUTPUT, "    goto CleanGetObjectMon;"                   ' clean all and then exit.
    FPRINT FP_OUTPUT, "  }"                                           ' we have IDispatch, set the flags then object is ready to use
    FPRINT FP_OUTPUT, "  obj->p_unknown = NULL;"                      ' doesn't get IUnknown this way
    FPRINT FP_OUTPUT, "  obj->pObjects[0].vt = VT_DISPATCH;"
    FPRINT FP_OUTPUT, "  obj->pStatus = TRUE;"
    FPRINT FP_OUTPUT, "  obj->ipointer = 0;"
    FPRINT FP_OUTPUT, "  COM_objects_cnt++;"
    FPRINT FP_OUTPUT, "CleanGetObjectMon:"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    if (vMoniker) vMoniker->Release();"
    FPRINT FP_OUTPUT, "    if (vBindCtx) vBindCtx->Release();"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    if (vMoniker) vMoniker->lpVtbl->Release (vMoniker);"
    FPRINT FP_OUTPUT, "    if (vBindCtx) vBindCtx->lpVtbl->Release (vBindCtx);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "}\n\n"
END SUB ' Emit_COM_GetObject



SUB Emit_COM_DispatchObject (FP_OUTPUT AS FILE)
    FPRINT FP_OUTPUT, "void BCX_DispatchObject(IUnknown *iobj, OBJECT *obj, BOOL b_release) {"
    FPRINT FP_OUTPUT, "  if (!obj) return;"
    FPRINT FP_OUTPUT, "  static ULONG inc_inf_ussage=0;"
    FPRINT FP_OUTPUT, "  if (!COM_ole_initd) COM_ole_initialize();"
    FPRINT FP_OUTPUT, "  obj->p_unknown = iobj;"

    ' Now, we are going to increment IUnknown usage, so that parameter iobj can be released.

    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    inc_inf_ussage = obj->p_unknown->AddRef();"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    inc_inf_ussage = obj->p_unknown->lpVtbl->AddRef(obj->p_unknown);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  VariantInit(&obj->pObjects[0]);"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    COM_last_HR = obj->p_unknown"
    FPRINT FP_OUTPUT, "    ->QueryInterface(IID_IDispatch, (void**)&obj->pObjects[0].pdispVal);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    COM_last_HR = obj->p_unknown->lpVtbl"
    FPRINT FP_OUTPUT, "    ->QueryInterface(obj->p_unknown, &IID_IDispatch,"
    FPRINT FP_OUTPUT, "     (void**)&obj->pObjects[0].pdispVal);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  if (FAILED (COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("QueryInterface::IID_IDispatch  failed!"), "));"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "      obj->p_unknown->Release();"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "      obj->p_unknown->lpVtbl->Release(obj->p_unknown);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "    return;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  if (b_release)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "     iobj->Release();"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "     iobj->lpVtbl->Release(obj->p_unknown);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  obj->pObjects[0].vt = VT_DISPATCH;"
    FPRINT FP_OUTPUT, "  obj->pStatus = TRUE;"
    FPRINT FP_OUTPUT, "  obj->ipointer = 0;"
    FPRINT FP_OUTPUT, "  COM_objects_cnt++;"
    FPRINT FP_OUTPUT, "}\n\n"
END SUB ' Emit_COM_DispatchObject



SUB Emit_COM_GetProperty (FP_OUTPUT AS FILE)
    UNREFERENCED_PARAMETER(FP_OUTPUT)
END SUB ' Emit_COM_GetProperty



SUB Emit_COM_SetProperty (FP_OUTPUT AS FILE)
    UNREFERENCED_PARAMETER(FP_OUTPUT)
END SUB ' Emit_COM_SetProperty



SUB Emit_COM_InvokeMethod (FP_OUTPUT AS FILE)
    UNREFERENCED_PARAMETER(FP_OUTPUT)
END SUB ' Emit_COM_InvokeMethod



SUB Emit_COM_SafeArray (FP_OUTPUT AS FILE)
    FPRINT FP_OUTPUT, "void COM_create_safearray(void) {"
    FPRINT FP_OUTPUT, "  long lv_param_incr = 0;"
    FPRINT FP_OUTPUT, "  long lv_param_incr_rev = 0;"
    FPRINT FP_OUTPUT, "  HRESULT hr = NO_ERROR;"
    FPRINT FP_OUTPUT, "  COM_PTR_safearray = "
    FPRINT FP_OUTPUT, "  SafeArrayCreateVector (VT_VARIANT,0,COM_plist_index);"
    FPRINT FP_OUTPUT, "  if (COM_PTR_safearray == NULL)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_clean_plist();"
    FPRINT FP_OUTPUT, "    COM_last_HR = E_OUTOFMEMORY;"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("SafeArrayCreate failed."), "));"
    FPRINT FP_OUTPUT, "    return;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  for (lv_param_incr = COM_plist_index-1; lv_param_incr>=0; lv_param_incr-=1)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    hr = SafeArrayPutElement (COM_PTR_safearray,"
    FPRINT FP_OUTPUT, "    &lv_param_incr, &COM_PARAMS[lv_param_incr_rev]);"
    FPRINT FP_OUTPUT, "    if (FAILED(hr))"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      wsprintf(COM_ErrMsg, _T(", ENC$("Param Index = %d."), "),lv_param_incr);"
    FPRINT FP_OUTPUT, "      if (COM_PTR_safearray) SafeArrayDestroy (COM_PTR_safearray);"
    FPRINT FP_OUTPUT, "      COM_PTR_safearray = NULL;"
    FPRINT FP_OUTPUT, "      COM_clean_plist();"
    FPRINT FP_OUTPUT, "      COM_last_HR = hr;"
    FPRINT FP_OUTPUT, "      COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("SafeArrayPutElement failed!"), "));"
    FPRINT FP_OUTPUT, "      return;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    lv_param_incr_rev++;"
    FPRINT FP_OUTPUT, "  }"

    IF COM_build_trace_code THEN
        FPRINT FP_OUTPUT, "  COM_add_trace_line(", ENC$("SafeArray created. Cleaning temp variants...") , ");"
    END IF

    FPRINT FP_OUTPUT, "  COM_clean_plist();"
    FPRINT FP_OUTPUT, "  if(COM_PTR_safearray)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "     VariantInit (&COM_PARAMS[0]);"
    FPRINT FP_OUTPUT, "     COM_PARAMS[0].vt = VT_ARRAY|VT_VARIANT;"
    FPRINT FP_OUTPUT, "     V_ARRAY (&COM_PARAMS[0]) = COM_PTR_safearray;"
    FPRINT FP_OUTPUT, "     COM_plist_index = 1;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "}\n\n"
END SUB ' Emit_COM_SafeArray



SUB Emit_COM_UsesConversion (FP_OUTPUT AS FILE)
    FPRINT FP_OUTPUT, "HRESULT COM_WS2AS(PCWSTR wide_string, UINT code_page) {"
    FPRINT FP_OUTPUT, "  if (wide_string==NULL) return (HRESULT) NO_ERROR;"
    FPRINT FP_OUTPUT, "  ULONG bytes_copied=0;"
    FPRINT FP_OUTPUT, "  ULONG temp_ansi_len = (ULONG)WideCharToMultiByte ("
    FPRINT FP_OUTPUT, "  code_page,0,wide_string,-1,COM_psz_tmp,0,NULL,NULL);"
    FPRINT FP_OUTPUT, "  if (temp_ansi_len == 0) return (HRESULT) NO_ERROR;"
    FPRINT FP_OUTPUT, "  if (COM_zstr_size < temp_ansi_len)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    if (COM_psz_tmp) free(COM_psz_tmp);"
    FPRINT FP_OUTPUT, "    COM_psz_tmp = (char*)calloc(temp_ansi_len+1,sizeof(char));"
    FPRINT FP_OUTPUT, "    if (NULL == COM_psz_tmp)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      COM_zstr_size = 0;"
    FPRINT FP_OUTPUT, "      return E_OUTOFMEMORY;"
    FPRINT FP_OUTPUT, "    } "
    FPRINT FP_OUTPUT, "    COM_zstr_size = temp_ansi_len;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  if ((bytes_copied = WideCharToMultiByte(code_page, 0, wide_string, -1,"
    FPRINT FP_OUTPUT, "       COM_psz_tmp, temp_ansi_len,NULL, NULL))==0)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    return HRESULT_FROM_WIN32 (GetLastError());"
    FPRINT FP_OUTPUT, "  } "
    FPRINT FP_OUTPUT, "  COM_psz_tmp [bytes_copied] = '\\0';"
    FPRINT FP_OUTPUT, "  return (HRESULT)NO_ERROR;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "HRESULT COM_AS2WS(PCSTR ansi_string, UINT code_page) {"
    FPRINT FP_OUTPUT, "  if (!*ansi_string) return (HRESULT)NO_ERROR;"
    FPRINT FP_OUTPUT, "  ULONG ansi_str_len = (ULONG)strlen (ansi_string);"
    FPRINT FP_OUTPUT, "  if (!ansi_str_len) return (HRESULT)NO_ERROR;"
    FPRINT FP_OUTPUT, "  ULONG wide_str_len = (ansi_str_len * 2);"
    FPRINT FP_OUTPUT, "  if (COM_wstr_size < wide_str_len)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    if (COM_PWSTR_temp)"
    FPRINT FP_OUTPUT, "       CoTaskMemFree((void*)COM_PWSTR_temp);"
    FPRINT FP_OUTPUT, "    COM_PWSTR_temp = (PWSTR)CoTaskMemAlloc (wide_str_len);"
    FPRINT FP_OUTPUT, "    if (NULL == COM_PWSTR_temp)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      COM_wstr_size = 0;"
    FPRINT FP_OUTPUT, "      return E_OUTOFMEMORY;"
    FPRINT FP_OUTPUT, "    } "
    FPRINT FP_OUTPUT, "    COM_wstr_size = wide_str_len;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  if (MultiByteToWideChar (code_page, MB_PRECOMPOSED, ansi_string, "
    FPRINT FP_OUTPUT, "      ansi_str_len, COM_PWSTR_temp, wide_str_len)==0)"
    FPRINT FP_OUTPUT, "         return HRESULT_FROM_WIN32(GetLastError());"
    FPRINT FP_OUTPUT, "  COM_PWSTR_temp[ansi_str_len] = L'\\0';"
    FPRINT FP_OUTPUT, "  return (HRESULT)NO_ERROR;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void COM_FREE_TEMP_WIDE_STRING(void) {"
    FPRINT FP_OUTPUT, "  if (COM_PWSTR_temp)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    CoTaskMemFree ((void*)COM_PWSTR_temp);"
    FPRINT FP_OUTPUT, "    COM_PWSTR_temp = NULL;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void COM_FREE_TEMP_ANSI_STRING (void) {"
    FPRINT FP_OUTPUT, "  if (COM_psz_tmp)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    free (COM_psz_tmp);"
    FPRINT FP_OUTPUT, "    COM_psz_tmp = NULL;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "}"
END SUB ' Emit_COM_UsesConversion



SUB Emit_COM_TraceCalls (FP_OUTPUT AS FILE)
    FPRINT FP_OUTPUT, "void bcx_com_trace_dump_DISPPARAMS(DISPPARAMS* dp) {"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(", ENC$("   --- BEGIN DUMP OF DISPPARAMS  ---"), ");"
    FPRINT FP_OUTPUT, "  if (!dp)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_add_trace_line(", ENC$("*** bcx_com_trace_dump_DISPPARAMS failed!"), ");"
    FPRINT FP_OUTPUT, "    COM_add_trace_line(", ENC$("*** NULL argument received for DISPPARAMS* dp"), ");"
    FPRINT FP_OUTPUT, "    COM_add_trace_line(", ENC$("   --- END DUMP OF DISPPARAMS ---"), ");"
    FPRINT FP_OUTPUT, "    return;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("     DISPPARAMS.rgvarg = %lu  // pointer to array of arguments."), ", dp->rgvarg);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("     DISPPARAMS.rgdispidNamedArgs = %lu // pointer to array of Dispatch IDs of named arguments."), ", dp->rgdispidNamedArgs);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("     DISPPARAMS.cArgs = %d // Number of arguments."), ", dp->cArgs);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("     DISPPARAMS.cNamedArgs = %d  // Number of named arguments"), ", dp->cNamedArgs);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(", ENC$("   --- END DUMP OF DISPPARAMS ---"), ");"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void bcx_com_trace_dump_indicators(OBJECT *object) {"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(", ENC$("*** start dump of global vars ***"), ");"
    FPRINT FP_OUTPUT, "  if (object->pStatus)"
    FPRINT FP_OUTPUT, "     strcpy(COM_trace_line, ", ENC$("   Object status - Initialized"), ");"
    FPRINT FP_OUTPUT, "  else"
    FPRINT FP_OUTPUT, "     strcpy(COM_trace_line, ", ENC$("   Object status - UnInitialized"), ");"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("   dispatch chain index = %d"), ", object->ipointer);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("   Count of params = %d"), ", COM_plist_index);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("   COM_ole_initd = %d"), ", COM_ole_initd);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("   COM_objects_cnt = %d"), ", COM_objects_cnt);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("   don't reset dispatch chain afer invoke = %d"), ", COM_reset_chain);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(", ENC$("*** end dump of global vars ***"), ");"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void bcx_com_trace_dump_flags(WORD wFlags) {"
    FPRINT FP_OUTPUT, "  wsprintf(COM_trace_line, ", ENC$("calling invoke with flags: "), ");"
    FPRINT FP_OUTPUT, "  if(wFlags & DISPATCH_PROPERTYPUT) strcat(COM_trace_line,", ENC$("| DISPATCH_PROPERTYPUT "), ");"
    FPRINT FP_OUTPUT, "  if(wFlags & DISPATCH_PROPERTYGET) strcat(COM_trace_line,", ENC$("| DISPATCH_PROPERTYGET "), ");"
    FPRINT FP_OUTPUT, "  if(wFlags & DISPATCH_PROPERTYPUTREF) strcat(COM_trace_line,", ENC$("| DISPATCH_PROPERTYPUTREF "), ");"
    FPRINT FP_OUTPUT, "  if(wFlags & DISPATCH_METHOD) strcat(COM_trace_line,", ENC$("| DISPATCH_METHOD "), ");"
    FPRINT FP_OUTPUT, "  COM_add_trace_line(COM_trace_line);"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "void COM_add_trace_line(PCTSTR trcline) {"
    FPRINT FP_OUTPUT, "  static FILE *com_trc_file;"
    FPRINT FP_OUTPUT, "  if((com_trc_file=fopen(", ENC$("c:\\com_trace.txt"), ",", ENC$("a"), "))==0)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    fprintf(stderr,", ENC$("Error: File access or File not found. c:\\com_trace.txt\\n"), ");"
    FPRINT FP_OUTPUT, "    exit(1);"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  fprintf(com_trc_file,", ENC$("%s\\n"), ", trcline);"
    FPRINT FP_OUTPUT, "  if (com_trc_file)"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    fflush(com_trc_file);"
    FPRINT FP_OUTPUT, "    fclose(com_trc_file);"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "}\n\n"
END SUB ' Emit_COM_TraceCalls



SUB Emit_BCX_SafeArray (FP_OUTPUT AS FILE)
    FPRINT FP_OUTPUT, "HRESULT InitSafeArray (SAFEARRAY **ppsa, VARTYPE vtype, UINT ndim, ...) {"
    FPRINT FP_OUTPUT, "  int iCNT;"
    FPRINT FP_OUTPUT, "  int iDIM;"
    FPRINT FP_OUTPUT, "  va_list  marker;"
    FPRINT FP_OUTPUT, "  SAFEARRAYBOUND  tArraySize[10];"
    FPRINT FP_OUTPUT, "  va_start(marker,ndim);"
    FPRINT FP_OUTPUT, "  iCNT = 0;"
    FPRINT FP_OUTPUT, "  iDIM = ndim;"
    FPRINT FP_OUTPUT, "  while(iDIM--)"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      tArraySize[iCNT].lLbound = va_arg(marker,long);"
    FPRINT FP_OUTPUT, "      tArraySize[iCNT].cElements = va_arg(marker,long);"
    FPRINT FP_OUTPUT, "      iCNT++;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "  *ppsa = SafeArrayCreate (vtype,ndim,tArraySize);"
    FPRINT FP_OUTPUT, "  if(*ppsa == NULL)"
    FPRINT FP_OUTPUT, "      return E_OUTOFMEMORY;"
    FPRINT FP_OUTPUT, "  return S_OK;"
    FPRINT FP_OUTPUT, "}\n\n"
    FPRINT FP_OUTPUT, "HRESULT DestroySafeArray(SAFEARRAY *psA) {"
    FPRINT FP_OUTPUT, "  return SafeArrayDestroy(psA);"
    FPRINT FP_OUTPUT, "}\n"
END SUB ' Emit_BCX_SafeArray



SUB Emit_COM_CreateObject (FP_OUTPUT AS FILE)
    FPRINT FP_OUTPUT, "void BCX_CreateObject (_TCHAR *objname, OBJECT *obj) {"
    FPRINT FP_OUTPUT, "  if (!COM_ole_initd) COM_ole_initialize();"
    FPRINT FP_OUTPUT, "  CLSID clsid;"
    FPRINT FP_OUTPUT, "  #ifndef UNICODE"
    FPRINT FP_OUTPUT, "    COM_last_HR = COM_AS2WS(objname);"
    FPRINT FP_OUTPUT, "    if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "      COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("CreateObject Failed! A2W failure!"), "));"
    FPRINT FP_OUTPUT, "      return;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    COM_last_HR = COM_WS2AS(COM_PWSTR_temp);"
    FPRINT FP_OUTPUT, "    if (FAILED (COM_last_HR))"
    FPRINT FP_OUTPUT, "    {"
    FPRINT FP_OUTPUT, "       COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("CreateObject Failed! W2A failure!"), "));"
    FPRINT FP_OUTPUT, "      return;"
    FPRINT FP_OUTPUT, "    }"
    FPRINT FP_OUTPUT, "    sprintf(COM_ErrMsg,", ENC$("%s, WideName(%s)"), ", objname, COM_psz_tmp);"
    FPRINT FP_OUTPUT, "    COM_last_HR = CLSIDFromProgID ((LPCOLESTR)COM_PWSTR_temp, (LPCLSID)&clsid);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    lstrcpy(COM_ErrMsg, objname);"
    FPRINT FP_OUTPUT, "    COM_last_HR = CLSIDFromProgID ((LPCOLESTR)objname, (LPCLSID)&clsid);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  if (FAILED (COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("CLSIDFromProgID failed!"), "));"
    FPRINT FP_OUTPUT, "    return;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    COM_last_HR = CoCreateInstance((REFCLSID)clsid, NULL,  "
    FPRINT FP_OUTPUT, "    CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER, IID_IUnknown, (void **)&obj->p_unknown);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    COM_last_HR = CoCreateInstance ((REFCLSID)&clsid, NULL, "
    FPRINT FP_OUTPUT, "    CLSCTX_INPROC_SERVER|CLSCTX_LOCAL_SERVER,&IID_IUnknown, (void **)&obj->p_unknown);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  if (FAILED (COM_last_HR))"
    FPRINT FP_OUTPUT, "     COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("CoCreateInstance failed!"), "));"
    FPRINT FP_OUTPUT, "  else"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    VariantInit(&obj->pObjects[0]);"
    FPRINT FP_OUTPUT, "    obj->pObjects[0].vt = VT_DISPATCH;"
    FPRINT FP_OUTPUT, "  #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "    COM_last_HR = obj->p_unknown"
    FPRINT FP_OUTPUT, "    ->QueryInterface(IID_IDispatch, (void **)&obj->pObjects[0].pdispVal);"
    FPRINT FP_OUTPUT, "  #else"
    FPRINT FP_OUTPUT, "    COM_last_HR = obj->p_unknown->lpVtbl"
    FPRINT FP_OUTPUT, "    ->QueryInterface(obj->p_unknown, &IID_IDispatch, (void**)&obj->pObjects[0].pdispVal);"
    FPRINT FP_OUTPUT, "  #endif"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  if (FAILED(COM_last_HR))"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    COM_HR_ErrMsg (COM_last_HR,_T(", ENC$("QueryInterface::IID_IDispatch  failed!"), "));"
    FPRINT FP_OUTPUT, "    obj->pObjects[0].vt = VT_NULL;"
    FPRINT FP_OUTPUT, "    VariantClear(&obj->pObjects[0]);"
    FPRINT FP_OUTPUT, "    #ifdef __cplusplus"
    FPRINT FP_OUTPUT, "       obj->p_unknown->Release();"
    FPRINT FP_OUTPUT, "    #else"
    FPRINT FP_OUTPUT, "       obj->p_unknown->lpVtbl->Release(obj->p_unknown);"
    FPRINT FP_OUTPUT, "    #endif"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "  else"
    FPRINT FP_OUTPUT, "  {"
    FPRINT FP_OUTPUT, "    obj->pStatus = TRUE;"
    FPRINT FP_OUTPUT, "    obj->ipointer = 0;"
    FPRINT FP_OUTPUT, "    COM_objects_cnt++;"
    FPRINT FP_OUTPUT, "  }"
    FPRINT FP_OUTPUT, "}\n\n"
END SUB ' Emit_COM_CreateObject



SUB Emit_VBScript_Support
    STATIC nTimes = 0
    IF nTimes > 0 THEN EXIT SUB
    INCR nTimes
    Use_AnsiToWide = Use_WideToAnsi = Use_BcxTempStr = TRUE
    FPRINT FP_HDR, ""
    FPRINT FP_HDR, "// ****************************************"
    FPRINT FP_HDR, "// ***** "; c_$BCX_STR_VBS_STRUCTS; "  *****"
    FPRINT FP_HDR, "// ****************************************"
    FPRINT FP_HDR, ""
    FPRINT FP_HDR, "const GUID IID_IScriptControl ="
    FPRINT FP_HDR, "{"
    FPRINT FP_HDR, "   0x0e59f1d3,0x1fbe,0x11d0,"
    FPRINT FP_HDR, "  {0x8f,0xf2,0x00,0xa0,0xd1,0x00,0x38,0xbc}"
    FPRINT FP_HDR, "};"
    FPRINT FP_HDR, ""
    FPRINT FP_HDR, "enum ScriptControlStates"
    FPRINT FP_HDR, "{"
    FPRINT FP_HDR, "  SCRIPTSTATE_UNINITIALIZED0, SCRIPTSTATE_STARTED1, SCRIPTSTATE_CONNECTED2,"
    FPRINT FP_HDR, "  SCRIPTSTATE_DISCONNECTED3, SCRIPTSTATE_CLOSED4, SCRIPTSTATE_INITIALIZED5"
    FPRINT FP_HDR, "};"
    FPRINT FP_HDR, ""
    FPRINT FP_HDR, "const GUID IID_IScriptError ="
    FPRINT FP_HDR, "{"
    FPRINT FP_HDR, "   0x70841C78, 0x67D, 0x11D0,"
    FPRINT FP_HDR, "  {0x95, 0xD8, 0x0, 0xA0, 0x24, 0x63, 0xAB, 0x28}"
    FPRINT FP_HDR, "};"
    FPRINT FP_HDR, ""
    FPRINT FP_HDR, "// *******************************************************************"
    FPRINT FP_HDR, "#undef  INTERFACE"
    FPRINT FP_HDR, "#define INTERFACE IScriptError"
    FPRINT FP_HDR, "// *******************************************************************"
    FPRINT FP_HDR, "DECLARE_INTERFACE_(IScriptError, IDispatch) {"
    FPRINT FP_HDR, "STDMETHOD (QueryInterface)(THIS_ REFIID riid, PVOID *ppvObj) PURE;"
    FPRINT FP_HDR, "STDMETHOD_(ULONG, AddRef)(THIS)  PURE;"
    FPRINT FP_HDR, "STDMETHOD_(ULONG, Release)(THIS) PURE;"
    FPRINT FP_HDR, "STDMETHOD (GetTypeInfoCount)(THIS_ UINT *pctinfo) PURE;"
    FPRINT FP_HDR, "STDMETHOD (GetTypeInfo)(THIS_ UINT itinfo, LCID lcid,"
    FPRINT FP_HDR, "ITypeInfo **pptinfo) PURE;"
    FPRINT FP_HDR, "STDMETHOD (GetIDsOfNames)(THIS_ REFIID riid, OLECHAR **rgszNames,"
    FPRINT FP_HDR, "           UINT cNames, LCID lcid, DISPID *rgdispid) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Invoke)(THIS_ DISPID dispidMember, REFIID riid, LCID lcid,"
    FPRINT FP_HDR, "           WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult,"
    FPRINT FP_HDR, "           EXCEPINFO *pexcepinfo, UINT *puArgErr) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Get_Number)(THIS_ long *pNumber) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Get_Source)(THIS_ BSTR *pbstrSource) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Get_Description)(THIS_ BSTR *pbstrDescription) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Get_HelpFile)(THIS_ BSTR *pbstrHelpFile) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Get_HelpContext)(THIS_ long *pHelpContext) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Get_Text)(THIS_ BSTR *pbstrText) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Get_Line)(THIS_ long *pLine) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Get_Column)(THIS_ long *pColumn) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Clear)(THIS) PURE;};"
    FPRINT FP_HDR, ""
    FPRINT FP_HDR, "// *******************************************************************"
    FPRINT FP_HDR, "#undef  INTERFACE"
    FPRINT FP_HDR, "#define INTERFACE IScriptControl"
    FPRINT FP_HDR, "// *******************************************************************"
    FPRINT FP_HDR, "DECLARE_INTERFACE_(IScriptControl, IDispatch) {"
    FPRINT FP_HDR, "STDMETHOD (QueryInterface)(THIS_ REFIID riid, PVOID *ppvObj) PURE;"
    FPRINT FP_HDR, "STDMETHOD_(ULONG, AddRef)(THIS)  PURE;"
    FPRINT FP_HDR, "STDMETHOD_(ULONG, Release)(THIS) PURE;"
    FPRINT FP_HDR, "STDMETHOD (GetTypeInfoCount)(THIS_ UINT *pctinfo) PURE;"
    FPRINT FP_HDR, "STDMETHOD (GetTypeInfo)(THIS_ UINT itinfo, LCID lcid,"
    FPRINT FP_HDR, "ITypeInfo  **pptinfo) PURE;"
    FPRINT FP_HDR, "STDMETHOD (GetIDsOfNames)(THIS_ REFIID riid, OLECHAR **rgszNames,"
    FPRINT FP_HDR, "           UINT cNames, LCID lcid, DISPID *rgdispid) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Invoke)(THIS_ DISPID dispidMember, REFIID riid, LCID lcid,"
    FPRINT FP_HDR, "           WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult,"
    FPRINT FP_HDR, "           EXCEPINFO *pexcepinfo, UINT *puArgErr) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_Language)(THIS_ BSTR* pbstrLanguage) PURE;"
    FPRINT FP_HDR, "STDMETHOD (put_Language)(THIS_ BSTR pbstrLanguage) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_State)(THIS_ enum ScriptControlStates* pssState) PURE;"
    FPRINT FP_HDR, "STDMETHOD (put_State)(THIS_ enum ScriptControlStates pssState) PURE;"
    FPRINT FP_HDR, "STDMETHOD (put_SitehWnd)(THIS_ long phwnd) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_SitehWnd)(THIS_ long* phwnd) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_Timeout)(THIS_ long* plMilliseconds) PURE;"
    FPRINT FP_HDR, "STDMETHOD (put_Timeout)(THIS_ long plMilliseconds) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_AllowUI)(THIS_ VARIANT_BOOL* pfAllowUI) PURE;"
    FPRINT FP_HDR, "STDMETHOD (put_AllowUI)(THIS_ VARIANT_BOOL pfAllowUI) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_UseSafeSubset)(THIS_ VARIANT_BOOL* pfUseSafeSubset) PURE;"
    FPRINT FP_HDR, "STDMETHOD (put_UseSafeSubset)(THIS_ VARIANT_BOOL pfUseSafeSubset) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_Modules)(THIS_ interface"
    FPRINT FP_HDR, "           IScriptModuleCollection** ppmods) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_Error)(THIS_ interface IScriptError** ppse) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_CodeObject)(THIS_ IDispatch** ppdispObject) PURE;"
    FPRINT FP_HDR, "STDMETHOD (get_Procedures)(THIS_ interface"
    FPRINT FP_HDR, "           IScriptProcedureCollection** ppdispProcedures) PURE;"
    FPRINT FP_HDR, "STDMETHOD (_AboutBox)(THIS) PURE;"
    FPRINT FP_HDR, "STDMETHOD (AddObject)(THIS_ BSTR Name, IDispatch* Object,"
    FPRINT FP_HDR, "           VARIANT_BOOL AddMembers) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Reset)(THIS) PURE;"
    FPRINT FP_HDR, "STDMETHOD (AddCode)(THIS_ BSTR Code) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Eval)(THIS_ BSTR Expression, VARIANT* pvarResult) PURE;"
    FPRINT FP_HDR, "STDMETHOD (ExecuteStatement)(THIS_ BSTR Statement) PURE;"
    FPRINT FP_HDR, "STDMETHOD (Run)(THIS_ BSTR ProcedureName, SAFEARRAY** Parameters,"
    FPRINT FP_HDR, "           VARIANT* pvarResult) PURE;};"
    FPRINT FP_HDR, ""

    IF Use_Project   THEN
        FPRINT FP_HDR, "BOOL OLE_ERROR_S;"
        FPRINT FP_HDR, "IScriptControl *pSC;"
    ELSE
        FPRINT FP_HDR, "static BOOL OLE_ERROR_S;"
        FPRINT FP_HDR, "static IScriptControl *pSC;"
    END IF

    AddLibrary("ole32.lib")
    AddLibrary("oleaut32.lib")
END SUB ' Emit_VBScript_Support


SUB Emit_Optimize (Str1$, Str2$, Str3 = "" AS PCTSTR)
    IF OptimizerEnabled THEN
        FPRINT FP_WRITE, "#if defined (__POCC__) && !defined(__cplusplus)"
        FPRINT FP_WRITE, "  #pragma optimize(", Str1$, ")", Str3$
        FPRINT FP_WRITE, "#elif !defined (__cplusplus)"
        FPRINT FP_WRITE, "  #pragma optimize(", Str2$, ")", Str3$
        FPRINT FP_WRITE, "#endif"
    END IF
END SUB ' Emit_Optimize

SUB Emit_InputCode
    '*********************************************************************************************
    ' This SUB emits code for input operations, such as reading input from the keyboard.
    ' It builds the format string and argument list for scanf-like input operations based on the
    ' provided arguments. It handles various data types and formats them appropriately for input.
    '*********************************************************************************************
    DIM Frmat$
    DIM Arg$
    DIM szWrk$
    DIM TestType
    DIM iThisToken = 2

    IF DataType(Stk$[iThisToken]) = vt_STRLIT THEN
        IF Stk$[iThisToken+1] = "," THEN
            FPRINT FP_WRITE, Scoot$, "printf(", No_Sigil$(Stk$[iThisToken]), "), "; ' Suppress CRLF
            '                         ^^^ this is for:   "prompt" comma var               MrBcx 819
        ELSE
            FPRINT FP_WRITE, Scoot$, "printf(", ENC$("%s? "), ",", No_Sigil$(Stk$[iThisToken]), "), "; ' Suppress CRLF
            '                         ^^^  this is for:  "prompt" semicolon  var          MrBcx 819
        END IF
        iThisToken = 4
    END IF

    FOR i AS INT = 1 TO Ndx
        IF Im_UDT_String(Stk$[i]) THEN Stk$[i] += "$"
        IF Im_UDT_Single(Stk$[i]) THEN Stk$[i] += "!"
        IF Im_UDT_Double(Stk$[i]) THEN Stk$[i] += "#"

        TestType = CheckType (Stk$[i])

        IF TestType = vt_STRVAR THEN Stk$[i] += "$"
        IF TestType = vt_SINGLE THEN Stk$[i] += "!"
        IF TestType = vt_DOUBLE THEN Stk$[i] += "#"
        IF TestType = vt_LDOUBLE THEN Stk$[i] += "#"
    NEXT

    CALL BuildStr(iThisToken, Ndx, szWrk$)
    FastLexer(szWrk$, "", ",")
    CALL CommonInputCode(Frmat$, Arg$)

    Use_KBinput = Use_Scan = TRUE
    FPRINT FP_WRITE, Scoot$, "KBinput(),"; ' Suppress CRLF
    FPRINT FP_WRITE, Scoot$, "ScanError=scan(InputBuffer,", ENC$(Frmat$), Arg$, ");"
END SUB ' Emit_InputCode




SUB Emit_FileInputCode
    '*******************************************************************************
    ' This SUB emits code for file input operations, such as reading from a file.
    ' It builds the format string and argument list for scanf-like input operations
    ' based on the contents found in the Stk$[] array. It handles various data types
    ' and formats them appropriately for input from the file.
    '*******************************************************************************
    DIM Arg$
    DIM Frmat$
    DIM szWrk$
    DIM iThisToken
    DIM FHandle$

    CALL InputBufferFlags

    FOR Tmp AS INT = 2 TO Ndx
        IF *Stk$[Tmp] = ASC("#") THEN REMOVE "#" FROM Stk$[Tmp]
    NEXT
    IF DataType (Stk$[2])= vt_NUMBER THEN
        Stk$[2] = "FP" + Stk$[2]
    END IF

    iThisToken = 4                                   ' Extract the file handle
    FOR j AS INT = 2 TO Ndx
        IF *Stk$[j] = ASC(",") THEN
            iThisToken = j+1
            EXIT FOR
        END IF
        FHandle$ += Stk$[j]
    NEXT

    FOR i AS INT = 1 TO Ndx
        IF Im_UDT_String (Stk$[i]) THEN Stk$[i] += "$"
        IF Im_UDT_Single (Stk$[i]) THEN Stk$[i] += "!"
        IF Im_UDT_Double (Stk$[i]) THEN Stk$[i] += "#"

        IF CheckType (Stk$[i]) = vt_STRVAR THEN Stk$[i] += "$"
        IF CheckType (Stk$[i]) = vt_SINGLE THEN Stk$[i] += "!"
        IF CheckType (Stk$[i]) = vt_DOUBLE THEN Stk$[i] += "#"
        IF CheckType (Stk$[i]) = vt_LDOUBLE THEN Stk$[i] += "#"
    NEXT

    CALL BuildStr (iThisToken, Ndx, szWrk$) ' build the variable list
    FastLexer (szWrk$, "", ",")
    CALL CommonInputCode (Frmat$, Arg$)

    FPRINT FP_WRITE, "fgets(InputBuffer, 0x100000, ", FHandle$, ");"
    FPRINT FP_WRITE, Scoot$, "InputBuffer[strcspn(InputBuffer, ", ENC$("\\r\\n"), ")] = 0;"
    FPRINT FP_WRITE, Scoot$, "ScanError = scan(InputBuffer,", ENC$(Frmat$), Arg$, ");"
    FPRINT FP_WRITE, Scoot$, "*InputBuffer=0;"
END SUB ' Emit_FileInputCode



SUB Emit_OSVersionEnum
    STATIC BeenHereDoneThat
    IF BeenHereDoneThat = TRUE THEN EXIT SUB
    BeenHereDoneThat = TRUE
    FPRINT FP_ENU, ""
    FPRINT FP_ENU, "enum"
    FPRINT FP_ENU, "{"
    FPRINT FP_ENU, "   OSUnknown = -2,"
    FPRINT FP_ENU, "   OSError = -1,"
    FPRINT FP_ENU, "   OS_3x,"
    FPRINT FP_ENU, "   OS_95,"
    FPRINT FP_ENU, "   OS_98,"
    FPRINT FP_ENU, "   OS_ME,"
    FPRINT FP_ENU, "   OS_NT3,"
    FPRINT FP_ENU, "   OS_2000,"
    FPRINT FP_ENU, "   OS_XP,"
    FPRINT FP_ENU, "   OS_XP_Pro_x64,"
    FPRINT FP_ENU, "   OS_Server_2003,"
    FPRINT FP_ENU, "   OS_Home_Server,"
    FPRINT FP_ENU, "   OS_Server_2003_R2,"
    FPRINT FP_ENU, "   OS_Vista,"
    FPRINT FP_ENU, "   OS_Server_2008,"
    FPRINT FP_ENU, "   OS_Server_2008_R2,"
    FPRINT FP_ENU, "   OS_Win_7,"
    FPRINT FP_ENU, "   OS_Server_2012,"
    FPRINT FP_ENU, "   OS_Win_8,"
    FPRINT FP_ENU, "   OS_Win_81,"
    FPRINT FP_ENU, "   OS_Server_2012_R2,"
    FPRINT FP_ENU, "   OS_Win_10,"
    FPRINT FP_ENU, "   OS_Server_2016,"
    FPRINT FP_ENU, "   OS_Win_11,"
    FPRINT FP_ENU, "   OS_Server_2019,"
    FPRINT FP_ENU, "   OS_Server_2022"
    FPRINT FP_ENU, "};"
    FPRINT FP_ENU, ""
END SUB ' Emit_OSVersionEnum



SUB Emit_MDI_MsgPump
    IF LEN(Accelerator$) THEN
        FPRINT FP_WRITE, "if(!BCX_hwndMDIClient)"
        FPRINT FP_WRITE, "   {"
        FPRINT FP_WRITE, "      return FALSE;"
        FPRINT FP_WRITE, "   }"
        FPRINT FP_WRITE, "   while((GetMessage(&Msg,NULL,0,0)))"
        FPRINT FP_WRITE, "     {"
        FPRINT FP_WRITE, "       HWND hActiveWindow=GetActiveWindow();"
        FPRINT FP_WRITE, "       if((!TranslateMDISysAccel(BCX_hwndMDIClient,&Msg)))"
        FPRINT FP_WRITE, "         {"
        FPRINT FP_WRITE, "           if((!TranslateAccelerator(hActiveWindow,", Accelerator$, ",&Msg)))"
        FPRINT FP_WRITE, "             {"
        FPRINT FP_WRITE, "               TranslateMessage(&Msg);"
        FPRINT FP_WRITE, "               DispatchMessage(&Msg);"
        FPRINT FP_WRITE, "             }"
        FPRINT FP_WRITE, "         }"
        FPRINT FP_WRITE, "     }"
        FPRINT FP_WRITE, "  return Msg.wParam;"
        FPRINT FP_WRITE, "}\n"
    ELSE
        FPRINT FP_WRITE, " if(!BCX_hwndMDIClient)"
        FPRINT FP_WRITE, " {"
        FPRINT FP_WRITE, "   return FALSE;"
        FPRINT FP_WRITE, " }"
        FPRINT FP_WRITE, " while((GetMessage(&Msg,NULL,0,0)))"
        FPRINT FP_WRITE, "   {"
        FPRINT FP_WRITE, "   if((!TranslateMDISysAccel(BCX_hwndMDIClient,&Msg)))"
        FPRINT FP_WRITE, "     {"
        FPRINT FP_WRITE, "       TranslateMessage(&Msg);"
        FPRINT FP_WRITE, "       DispatchMessage(&Msg);"
        FPRINT FP_WRITE, "     }"
        FPRINT FP_WRITE, "   }"
        FPRINT FP_WRITE, "return Msg.wParam;"
        FPRINT FP_WRITE, "}\n"
    END IF
END SUB ' Emit_MDI_MsgPump



SUB Emit_GUI_MsgPump
    IF LEN(Accelerator$) THEN
        FPRINT FP_WRITE, " while(GetMessage(&Msg,NULL,0,0))"
        FPRINT FP_WRITE, "   {"
        FPRINT FP_WRITE, "    HWND hActiveWindow = GetActiveWindow();"
        FPRINT FP_WRITE, "    if(!TranslateAccelerator(hActiveWindow,", Accelerator$, ",&Msg) &&"
        FPRINT FP_WRITE, "       ((!IsDialogMessage(hActiveWindow,&Msg)) || (!IsWindow(hActiveWindow))))"
        FPRINT FP_WRITE, "      {"
        FPRINT FP_WRITE, "        TranslateMessage(&Msg);"
        FPRINT FP_WRITE, "        DispatchMessage(&Msg);"
        FPRINT FP_WRITE, "      }"
        FPRINT FP_WRITE, "   }"
        FPRINT FP_WRITE, " return Msg.wParam;"
        FPRINT FP_WRITE, "}\n"
    ELSE
        FPRINT FP_WRITE, " while(GetMessage(&Msg,NULL,0,0))"
        FPRINT FP_WRITE, "   {"
        FPRINT FP_WRITE, "    HWND hActiveWindow = GetActiveWindow();"
        FPRINT FP_WRITE, "    if((!IsWindow(hActiveWindow)) || (!IsDialogMessage(hActiveWindow,&Msg)))"
        FPRINT FP_WRITE, "      {"
        FPRINT FP_WRITE, "        TranslateMessage(&Msg);"
        FPRINT FP_WRITE, "        DispatchMessage(&Msg);"
        FPRINT FP_WRITE, "      }"
        FPRINT FP_WRITE, "    }"
        FPRINT FP_WRITE, " return Msg.wParam;"
        FPRINT FP_WRITE, "}\n"
    END IF
END SUB ' Emit_GUI_MsgPump



SUB Emit_WinGUIMain(classname$, metric$, icon$)
    FPRINT FP_WRITE, ""
    FPRINT FP_WRITE, "int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,PSTR CmdLine,int CmdShow) {"
    FPRINT FP_WRITE, "   MSG  Msg;"
    FPRINT FP_WRITE, "   strcpy(BCX_ClassName," ; classname$; ");"
    FPRINT FP_WRITE, "   BCX_SetMetric("; ENC$(metric$); ");"
    FPRINT FP_WRITE, "   BCX_InitGUI();"
    FPRINT FP_WRITE, "   BCX_hInstance       =  hInst;"
    FPRINT FP_WRITE, "   BCX_WndClass.hIcon  = " ; icon$
    FPRINT FP_WRITE, "   BCX_RegWnd(BCX_ClassName, WndProc);"
    FPRINT FP_WRITE, ""
    FPRINT FP_WRITE, "   // ******************************************"
    FPRINT FP_WRITE, "                     FormLoad();"
    FPRINT FP_WRITE, "   // ******************************************"
END SUB ' Emit_WinGUIMain



SUB Emit_MDICode(FP_OUTPUT AS FILE)
    FPRINT FP_OUTPUT, "HWND BCX_MDICHILD (PCTSTR title, PCTSTR MdiClassName,int x,int y,int cx,int cy,ULONG style,LPARAM lParam) {"
    FPRINT FP_OUTPUT, "   HWND  hwndChild;"
    FPRINT FP_OUTPUT, "   char rgch"; "[BCXSTRSIZE]={0};"
    FPRINT FP_OUTPUT, "   static int cUntitled=1;"
    FPRINT FP_OUTPUT, "   if(title[0]==0)"
    FPRINT FP_OUTPUT, "      {"
    FPRINT FP_OUTPUT, "        sprintf(rgch," , ENC$("%s%i") , "," , ENC$("Untitled") , ",cUntitled++);"
    FPRINT FP_OUTPUT, "      }"
    FPRINT FP_OUTPUT, "    else"
    FPRINT FP_OUTPUT, "      {"
    FPRINT FP_OUTPUT, "        strcpy(rgch,title);"
    FPRINT FP_OUTPUT, "      }"
    FPRINT FP_OUTPUT, "  //  Create the MDI child window"
    FPRINT FP_OUTPUT, "    hwndChild = CreateMDIWindow(MdiClassName, rgch, style, x, y,"
    FPRINT FP_OUTPUT, "                cx, cy, BCX_hwndMDIClient, BCX_hInstance, lParam);"
    FPRINT FP_OUTPUT, "return hwndChild;"
    FPRINT FP_OUTPUT, "}\n\n"

    FPRINT FP_OUTPUT, "void BCX_MDICLASS (WNDPROC MCWP, PCHAR ClassName) {"
    FPRINT FP_OUTPUT, "   WNDCLASS wc={0};"
    FPRINT FP_OUTPUT, "   wc.style=0;"
    FPRINT FP_OUTPUT, "   wc.lpfnWndProc=(WNDPROC)MCWP;"
    FPRINT FP_OUTPUT, "   wc.cbClsExtra=0;"
    FPRINT FP_OUTPUT, "   wc.cbWndExtra=20;"
    FPRINT FP_OUTPUT, "   wc.hInstance=BCX_hInstance;"
    FPRINT FP_OUTPUT, "   wc.hIcon= ", GUIIcon$
    FPRINT FP_OUTPUT, "   wc.hCursor=LoadCursor(NULL,IDC_ARROW);"
    FPRINT FP_OUTPUT, "   wc.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);"
    FPRINT FP_OUTPUT, "   wc.lpszMenuName=NULL;"
    FPRINT FP_OUTPUT, "   wc.lpszClassName=ClassName;"
    FPRINT FP_OUTPUT, "   RegisterClass((LPWNDCLASS)&wc);"
    FPRINT FP_OUTPUT, "}\n\n"


    FPRINT FP_OUTPUT, "HWND BCX_MDICLIENT (HWND hwndparent, int icount) {"
    FPRINT FP_OUTPUT, "   CLIENTCREATESTRUCT ccs={0,1};"
    FPRINT FP_OUTPUT, "   //  Find window menu where children will be listed"
    FPRINT FP_OUTPUT, "   ccs.hWindowMenu=GetSubMenu(GetMenu(hwndparent),icount-1);"
    FPRINT FP_OUTPUT, "   //  Create the MDI client filling the client area"
    FPRINT FP_OUTPUT, "   BCX_hwndMDIClient=CreateWindow(", ENC$("MDICLIENT"), ",NULL, WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL,"
    FPRINT FP_OUTPUT, "                                  0,0,0,0,hwndparent,(HMENU)(UINT_PTR)NULL,BCX_hInstance,(PVOID)&ccs);"
    FPRINT FP_OUTPUT, "   return BCX_hwndMDIClient;"
    FPRINT FP_OUTPUT, "}\n\n"
END SUB      ' Emit_MDICode



'********************** End of Runtime Library ********************
'
'                       Begin $Project Support
'******************************************************************


SUB Emit_ProjectSupport
    '**************************************************************
    ' This reads the .c file created by BCX and creates the .h files
    ' from the information at the top of the .c file in sections such
    ' as User Defined Structs, Unions, User Prototyes, etc.
    ' The c_$BCX_STR_XXX_XXX MACROS guard againt changes being made that
    ' could adversely affect this code.
    '**************************************************************
    DIM nPos1
    DIM nPos2
    DIM sExt$
    DIM cHFn$
    DIM iWork
    DIM Tmp$

    IF EXIST (FileOut$) THEN
        CLOSE
        IF ISNULL(CmdLineFileOut$) THEN
            Project_Path$ = CURDIR$
        ELSE
            Project_Path$ = MID$(CmdLineFileOut$, 1, INSTRREV(CmdLineFileOut$, "\", 0) - 1)
        END IF
        IF INCHR(COMMAND$(1), "\") THEN ' has a path
            cHFn$ = MID$(COMMAND$(1), INSTRREV(COMMAND$(1), "\", 0) + 1)
        ELSE
            cHFn$ = COMMAND$(1)
        END IF
        IF INCHR(cHFn$, ".") THEN ' has an extension
            cHFn$ = MID$(cHFn$, 1, INSTRREV(cHFn$, ".", 0) -1)
        END IF
        HFile$ = Project_Path$ + "\" + cHFn$ + ".bh"

        OPEN FileOut$ FOR INPUT AS PJ1
        OPEN HFile$ FOR OUTPUT AS PJ2
        FPRINT PJ2, "#ifndef __BCX_HEADER_"; UCASE$(cHFn$) + "__"
        iWork = eDoNothing

        DO WHILE NOT EOF(PJ1)
            LINE INPUT PJ1, Tmp$
            IF LEFTSTR(Tmp$, "// *") THEN
                LINE INPUT PJ1, Tmp$
                ITERATE
            END IF
            IF Tmp$ = "" THEN ITERATE
            IF LEFTSTR(TRIM$(Tmp$), "//") THEN ITERATE
            IF INSTR(Tmp$, c_$BCX_STR_SYS_VARS)   THEN
                iWork = eStartSysVariables
            ELSEIF INSTR(Tmp$, c_$BCX_STR_USR_VARS)   THEN
                iWork = eStartUserVariables
            ELSEIF INSTR(Tmp$, c_$BCX_STR_STD_MACROS) THEN
                iWork = eStartMacros
            ELSEIF INSTR(Tmp$, c_$BCX_STR_STD_PROTOS) THEN
                iWork = eStartStdProtos
            ELSEIF INSTR(Tmp$, c_$BCX_STR_USR_PROTOS) THEN
                iWork = eStartUserProtos
            ELSEIF INSTR(Tmp$, c_$BCX_STR_USR_CONST)  THEN
                iWork = eStartUserConst
            ELSEIF INSTR(Tmp$, c_$BCX_STR_SYS_CONST)  THEN
                iWork = eStartSysConst
            ELSEIF INSTR(Tmp$, c_$BCX_STR_MAIN_PROG)  THEN
                iWork = eDoMainProgram
            ELSEIF INSTR(Tmp$, c_$BCX_STR_USR_PROCS)  THEN
                iWork = eDoUserProcs
            ELSEIF INSTR(Tmp$, c_$BCX_STR_USR_TYPES)  THEN
                iWork = eStartUserTypes
            END IF
            ' no CASE needed for these eDoMainProgram, eDoUserProcs so iterate
            IF iWork = eDoMainProgram OR iWork = eDoUserProcs THEN ITERATE
            SELECT CASE iWork

                CASE eStartSysVariables
                    LINE INPUT PJ1, Tmp$ ' remove the '// ***************
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, "// "; c_$BCX_STR_SYS_VARS
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, ""
                    iWork = eDoSysVariables

                CASE eDoSysVariables
                    IF NOT (LEFT$(Tmp$, 6) = "static") THEN
                        IF INCHR(Tmp$, "=") THEN
                            ' remove the = TO ;
                            ' char    CRLF[3]={13,10,0}; // Carr Rtn & Line Feed
                            nPos1 = INCHR(Tmp$, "=")
                            nPos2 = INCHR(Tmp$, ";")
                            sExt$ = MID$(Tmp$, nPos1, nPos2 - nPos1)
                            REMOVE sExt$ FROM Tmp$
                        END IF
                        FPRINT PJ2, "extern "; Tmp$
                    END IF

                CASE eStartUserVariables
                    LINE INPUT PJ1, Tmp$                 ' remove the '// ***************
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, "// "; c_$BCX_STR_USR_VARS
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, ""
                    iWork = eDoUserVariables

                CASE eDoUserVariables
                    IF *TRIM$(Tmp$) = ASC("#") THEN
                        FPRINT PJ2, Tmp$
                    ELSE
                        IF INCHR(Tmp$, "=") THEN
                            ' remove the = TO ;
                            nPos1 = INCHR(Tmp$, "=")
                            nPos2 = INCHR(Tmp$, ";")
                            sExt$ = MID$(Tmp$, nPos1, nPos2 - nPos1)
                            REMOVE sExt$ FROM Tmp$
                        END IF
                        IF LEFTSTR(Tmp$, "extern") = FALSE THEN
                            FPRINT PJ2, "extern "; Tmp$
                        ELSE
                            FPRINT PJ2, Tmp$
                        END IF
                    END IF

                CASE eStartMacros
                    LINE INPUT PJ1, Tmp$ ' remove the '// ***************
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, "// "; c_$BCX_STR_STD_MACROS
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, ""
                    iWork = eDoMacros

                CASE eStartStdProtos
                    LINE INPUT PJ1, Tmp$ ' remove the '// ***************
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, "// "; c_$BCX_STR_STD_PROTOS
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, ""
                    iWork = eDoStdProtos

                CASE eDoStdProtos
                    DIM RAW p AS PCHAR
                    ' added to remove the assignment to optional parameters
                    ' PellesC doesn't like them

                    DO WHILE INCHR(Tmp$, "=")
                        ' remove = up to comma, space, right paren, semi-colon
                        ' char*   mid (char*, int, int=-1);
                        nPos1 = INCHR(Tmp$, "=")
                        p = Tmp$
                        p = p + nPos1 - 1

                        DO
                            IF *p <> ASC(",") AND *p <> ASC(SPC$) AND *p <> ASC(")") THEN
                                *p = 1
                            ELSE
                                EXIT DO
                            END IF
                            INCR p
                        LOOP

                        REMOVE CHR$(1) FROM Tmp$
                    LOOP

                    IF ISFALSE(LEFTSTR(Tmp$, "extern")) THEN
                        FPRINT PJ2, "extern "; Tmp$
                    ELSE
                        FPRINT PJ2, Tmp$
                    END IF

                CASE eStartUserProtos
                    LINE INPUT PJ1, Tmp$ ' remove the '// ***************
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, "// "; c_$BCX_STR_USR_PROTOS
                    FPRINT PJ2, "// *****************\n"

                    iWork = eDoUserProtos

                CASE eDoUserProtos
                    IF ISTRUE(iMatchNQ(Tmp$, " main")) OR ISTRUE(iMatchNQ(Tmp$, " WinMain")) THEN EXIT SELECT
                    IF *Tmp$ = ASC(SPC$) THEN EXIT SELECT
                    FPRINT PJ2, "extern "; Tmp$

                CASE eStartUserConst
                    LINE INPUT PJ1, Tmp$ ' remove the '// ***************
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, "// "; c_$BCX_STR_USR_CONST
                    FPRINT PJ2, "// *****************\n"

                    iWork = eDoUserConst

                CASE eStartSysConst
                    LINE INPUT PJ1, Tmp$ ' remove the '// ***************
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, "// "; c_$BCX_STR_SYS_CONST
                    FPRINT PJ2, "// *****************\n"

                    iWork = eDoSysConst

                CASE eStartUserTypes
                    LINE INPUT PJ1, Tmp$ ' remove the '// ***************
                    FPRINT PJ2, "// *****************"
                    FPRINT PJ2, "// "; c_$BCX_STR_USR_TYPES
                    FPRINT PJ2, "// *****************\n"

                    iWork = eDoUserTypes

                CASE eDoUserTypes, eDoUserConst, eDoSysConst, eDoMacros
                    FPRINT PJ2, Tmp$

                    ' no CASE needed for these eDoMainProgram, eDoUserProcs
            END SELECT
        LOOP

        FPRINT PJ2, "#endif // __BCX_HEADER_"; UCASE$(cHFn$); "__"
        CLOSE PJ1, PJ2
    END IF
END SUB ' Emit_ProjectSupport



SUB Emit_Libs
    '***********************************************
    ' This SUB emits codes that instructs the
    ' linker to search for object/import libraries.
    '***********************************************
    STATIC IWasHere  ' Must remain static
    STATIC nCount    ' Must remain static
    LOCAL  LTmp$

    IF IWasHere THEN EXIT SUB
    INCR IWasHere
    IF Library$[0] = "" THEN EXIT SUB

    IF NO_LIBS = FALSE THEN
        XFOR INT i = 0 WHILE i < c_MaxLib AND NOTNULL(Library[i]) BY i++
            LTmp$ = Library$[i]
            RemoveAll(LTmp$, "<>" + DQ$)
            IF INSTR(RmLibs$, LTmp$) THEN ITERATE ' skip libraries that have been removed
            IF nCount = 0 THEN
                INCR nCount
                FPRINT FP_HDR, ""
                FPRINT FP_HDR, "// *************************************************"
                FPRINT FP_HDR, "// Instruct Linker to Search Object/Import Libraries"
                FPRINT FP_HDR, "// *************************************************"
                FPRINT FP_HDR, ""
                FPRINT FP_HDR, "#if !defined(__GNUC__) && !defined(__TINYC__)"
                FPRINT FP_HDR, "   #if !(defined(__BCPLUSPLUS__) && defined(_WIN64))"
                IF UseCpp = FALSE THEN
                    FPRINT FP_HDR, "      #if !defined(__LCC__)"
                END IF
            END IF
            FPRINT FP_HDR, "    #pragma comment(lib,", ENC$(LTmp$), ")"
        XNEXT

        IF UseCpp = FALSE THEN
            FPRINT FP_HDR, "  #else"
            '***************************************************************************************
            ' add lccwin32's default libraries to the remove library list, so they won't be emitted
            '***************************************************************************************
            RmLibs$ += ",<libc.lib>,<kernel32.lib>,<comdlg32.lib>,<user32.lib>,"
            RmLibs$ += "<gdi32.lib>,<advapi32.lib>,<comctl32.lib>,<crtdll.lib>,<Msimg32.lib>"

            XFOR INT i = 0 WHILE i < c_MaxLib AND NOTNULL(Library[i]) BY i++
                IF INSTR(RmLibs$, Library$[i]) THEN ITERATE ' skip libraries that have been removed
                IF nCount = 0 THEN
                    INCR nCount
                    FPRINT FP_HDR, "  #if !defined(__LCC__)"
                END IF
                FPRINT FP_HDR, "    #pragma lib ", Library$[i]
            XNEXT
        END IF

        IF NOTZERO (nCount) THEN
            IF ISFALSE UseCpp THEN
                FPRINT FP_HDR, "     #endif"
            END IF
            FPRINT FP_HDR, "  #endif"
            FPRINT FP_HDR, "#endif"
        END IF
    END IF
END SUB ' Emit_Libs



SUB Emit_ResourceFile
    LOCAL Tmp$
    IF Use_Resource AND NOT Use_GenResFile THEN
        IF NOTNULL(UserResFile$) THEN Res_File$ = UserResFile$
    END IF

    IF Use_GenResFile THEN
        CombineRes = FALSE

        IF EXIST(UserResFile$) THEN CombineRes = TRUE ' don't overwrite rc file
        gTmpStr$ = EXTRACT$(UCASE$(FileOut$), ".") + "__.rc"
        Res_File$ = gTmpStr$

        OPEN resFile$ FOR INPUT  AS ResIn
        OPEN gTmpStr$   FOR OUTPUT AS ResOut

        FPRINT ResOut, "//  BCX Generated Resource File"
        FPRINT ResOut, "//  Date: ", DATE$, " Time: ", TIME$
        FPRINT ResOut, ""
        FPRINT ResOut, "#include <windows.h>"
        FPRINT ResOut, ""

        IF CombineRes THEN
            OPEN UserResFile$ FOR INPUT AS UserResIn
            FPRINT ResOut, "// User's *.rc file listing"
            FPRINT ResOut, ""
            DO WHILE NOT EOF(UserResIn)
                LINE INPUT UserResIn, Tmp$     ' Read from user's resource file
                IF INSTR(Tmp$, "windows.h", 1, 1) > 0 THEN
                    Tmp$ = ""
                END IF
                FPRINT ResOut, Tmp$            ' Write to final *.rc file
            LOOP
        END IF

        FPRINT ResOut, ""
        FPRINT ResOut, "// BCX generated *.rc file listing"
        FPRINT ResOut, ""

        DO WHILE NOT EOF(ResIn)
            LINE INPUT ResIn, Tmp$            ' Read from temp$
            IF INSTR(Tmp$, "include", 1, 1) > 0 THEN
                FPRINT ResOut, ""
            END IF
            FPRINT ResOut, Tmp$               ' Write to final *.rc file
        LOOP

        CLOSE ResOut, ResIn

        IF CombineRes THEN
            CLOSE UserResIn
        END IF

    END IF

    IF EXIST(resFile$) THEN
        KILL resFile$
    END IF
END SUB ' Emit_ResourceFile




SUB SetUsed
    DIM RAW i AS INT
    DIM RAW x AS INT
    FOR i = 2 TO Ndx
        HFiles$[HFileCnt] = "#include " + DQ$ + EXTRACT$(Stk$[i], ".") + ".h" + DQ$

        IF c_MaxHFiles = ++HFileCnt THEN
            CALL Abort("Maximum number of INCLUDE files exceeded.")
        END IF

        OPEN Stk$[i] FOR INPUT AS FPUSE
        DO WHILE NOT EOF(FPUSE)
            LINE INPUT FPUSE, Src$
            x = INCHR("ABCDEFGHIJKLMNOPQRSTUVWXYZ", UCASE$(MID$(Src$, 5, 1)))
            SELECT CASE x
                CASE 1
                    IF Src$ = "Use_Acosh" THEN Use_Acosh = TRUE
                    IF Src$ = "Use_AnsiToWide" THEN Use_AnsiToWide = TRUE
                    IF Src$ = "Use_AppActivate" THEN Use_AppActivate = TRUE
                    IF Src$ = "Use_AppExeName" THEN Use_AppExeName = TRUE
                    IF Src$ = "Use_AppExePath" THEN Use_AppExePath = TRUE
                    IF Src$ = "Use_Asc" THEN Use_Asc = TRUE
                    IF Src$ = "Use_Asinh" THEN Use_Asinh = TRUE
                    IF Src$ = "Use_Atanh" THEN Use_Atanh = TRUE
                CASE  2
                    IF Src$ = "Use_BcxTempStr" THEN Use_BcxTempStr = TRUE
                    IF Src$ = "Use_BCX_Arc" THEN Use_BCX_Arc = TRUE
                    IF Src$ = "Use_BCX_Pie" THEN Use_BCX_Pie = TRUE
                    IF Src$ = "Use_BCX_BmpHeight" THEN Use_BCX_BmpHeight = TRUE
                    IF Src$ = "Use_BCX_Buffer" THEN Use_BCX_Buffer = TRUE
                    IF Src$ = "Use_BCX_Blit"   THEN Use_BCX_Blit = TRUE
                    IF Src$ = "Use_BCX_Blit_Stretch" THEN Use_BCX_Blit_Stretch = TRUE
                    IF Src$ = "Use_BCX_Blit_Sprite"   THEN Use_BCX_Blit_Sprite = TRUE
                    IF Src$ = "Use_BCX_BmpHeight" THEN Use_BCX_BmpHeight = TRUE
                    IF Src$ = "Use_BCX_BmpWidth" THEN Use_BCX_BmpWidth = TRUE
                    IF Src$ = "Use_BCX_Circle" THEN Use_BCX_Circle = TRUE
                    IF Src$ = "Use_BCX_Colordlg" THEN Use_BCX_Colordlg = TRUE
                    IF Src$ = "Use_BCX_Control" THEN Use_BCX_Control = TRUE
                    IF Src$ = "Use_Consolesize" THEN Use_Consolesize = TRUE
                    IF Src$ = "Use_BCXMDialog" THEN Use_BCXDialogCommon = Use_BCXMDialog = TRUE
                    IF Src$ = "Use_BCXDialog" THEN Use_BCXDialogCommon = Use_BCXDialog = TRUE
                    IF Src$ = "Use_BCX_Ellipse" THEN Use_BCX_Ellipse = TRUE
                    IF Src$ = "Use_BCX_Floodfill" THEN Use_BCX_Floodfill = TRUE
                    IF Src$ = "Use_BCX_Fontdlg" THEN Use_BCX_Fontdlg = TRUE
                    IF Src$ = "Use_BCX_Get" THEN Use_BCX_Get = TRUE
                    IF Src$ = "Use_BCX_Getpixel" THEN Use_BCX_Getpixel = TRUE
                    IF Src$ = "Use_BCX_Get_UpDown" THEN Use_BCX_Get_UpDown = TRUE
                    IF Src$ = "Use_BCX_Get_Window_Height" THEN Use_BCX_Get_Window_Height = TRUE
                    IF Src$ = "Use_BCX_Get_Window_Width" THEN Use_BCX_Get_Window_Width = TRUE
                    IF Src$ = "Use_BCX_Input" THEN Use_BCX_Input = TRUE
                    IF Src$ = "Use_BCX_Line" THEN Use_BCX_Line = TRUE
                    IF Src$ = "Use_BCX_Polar_Line" THEN Use_BCX_Polar_Line = TRUE
                    IF Src$ = "Use_BCX_Lineto" THEN Use_BCX_Lineto = TRUE
                    IF Src$ = "Use_BCX_Triangle" THEN Use_BCX_Triangle = TRUE
                    IF Src$ = "Use_BCX_Gradient" THEN Use_BCX_Gradient = TRUE
                    IF Src$ = "Use_BCX_LoadBMP" THEN Use_BCX_LoadBMP = TRUE
                    IF Src$ = "Use_BCX_LoadImage" THEN Use_BCX_LoadImage = TRUE
                    IF Src$ = "Use_BCX_OlePicture" THEN Use_BCX_OlePicture = TRUE
                    IF Src$ = "Use_BCX_Path" THEN Use_BCX_Path = TRUE
                    IF Src$ = "Use_BcxSplitPath" THEN Use_BcxSplitPath = TRUE
                    IF Src$ = "Use_BCX_PolyBezier" THEN Use_BCX_PolyBezier = TRUE
                    IF Src$ = "Use_BCX_Polygon" THEN Use_BCX_Polygon = TRUE
                    IF Src$ = "Use_BCX_Polyline" THEN Use_BCX_Polyline = TRUE
                    IF Src$ = "Use_BCX_Preset" THEN Use_BCX_Preset = TRUE
                    IF Src$ = "Use_BCX_Print" THEN Use_BCX_Print = TRUE
                    IF Src$ = "Use_BCX_Printex" THEN Use_BCX_Printex = TRUE
                    IF Src$ = "Use_BCX_Pset" THEN Use_BCX_Pset = TRUE
                    IF Src$ = "Use_BCX_Polar_Pset" THEN Use_BCX_Polar_Pset = TRUE
                    IF Src$ = "Use_BCX_Put" THEN Use_BCX_Put = TRUE
                    IF Src$ = "Use_BCX_Rectangle" THEN Use_BCX_Rectangle = TRUE
                    IF Src$ = "Use_BCX_Resize" THEN Use_BCX_Resize = TRUE
                    IF Src$ = "Use_BCX_Roundrect" THEN Use_BCX_Roundrect = TRUE
                    IF Src$ = "Use_BCX_Tab" THEN Use_BCX_Tab = TRUE
                    IF Src$ = "Use_BCX_Toolbar" THEN Use_BCX_Toolbar = TRUE
                    IF Src$ = "Use_BCX_Tile" THEN Use_BCX_Tile = TRUE
                    IF Src$ = "Use_BCX_UpDown" THEN Use_BCX_UpDown = TRUE
                    IF Src$ = "Use_BCX_stricmp" THEN Use_BCX_stricmp = TRUE
                    IF Src$ = "Use_BCX_Slider" THEN Use_BCX_Slider = TRUE
                    IF Src$ = "Use_BCX_Splitter" THEN Use_BCX_Splitter = TRUE
                    IF Src$ = "Use_Bff" THEN Use_Bff = TRUE
                    IF Src$ = "Use_Bin" THEN Use_Bin = TRUE
                    IF Src$ = "Use_Bin2dec" THEN Use_Bin2dec = TRUE
                    IF Src$ = "Use_Bitmap" THEN Use_Bitmap = TRUE
                    IF Src$ = "Use_Blackrect" THEN Use_Blackrect = TRUE
                    IF Src$ = "Use_BmpButton" THEN Use_BmpButton = TRUE
                    IF Src$ = "Use_Boolstr" THEN Use_Boolstr = TRUE
                    IF Src$ = "Use_Button" THEN Use_Button = TRUE
                CASE  3
                    IF Src$ = "Use_Center" THEN Use_Center = TRUE
                    IF Src$ = "Use_Checkbox" THEN Use_Checkbox = TRUE
                    IF Src$ = "Use_Chrtoutf8" THEN Use_Chrtoutf8 = TRUE
                    IF Src$ = "Use_Cint" THEN Use_Cint = TRUE
                    IF Src$ = "Use_Clip_Getbitmap" THEN  Use_Clip_Getbitmap = TRUE
                    IF Src$ = "Use_Clip_Setbitmap" THEN Use_Clip_Setbitmap = TRUE
                    IF Src$ = "Use_Clip_Gettext" THEN  Use_Clip_Gettext = TRUE
                    IF Src$ = "Use_Clip_Gettextsize" THEN Use_Clip_Gettextsize = TRUE
                    IF Src$ = "Use_Clip_Settext" THEN Use_Clip_Settext = TRUE
                    IF Src$ = "Use_Clip_Reset" THEN  Use_Clip_Reset   = TRUE
                    IF Src$ = "Use_Clng" THEN Use_Clng = TRUE
                    IF Src$ = "Use_Cls" THEN Use_Cls = TRUE
                    IF Src$ = "Use_Color" THEN Use_Color = TRUE
                    IF Src$ = "Use_COM" THEN Use_COM = TRUE
                    IF Src$ = "Use_Combobox" THEN Use_Combobox = TRUE
                    IF Src$ = "Use_ComboBoxLoadFile" THEN Use_ComboBoxLoadFile = TRUE
                    IF Src$ = "Use_Command" THEN Use_Command = TRUE
                    IF Src$ = "Use_ContainedIn" THEN Use_ContainedIn = TRUE
                    IF Src$ = "Use_CreateRegInt" THEN Use_CreateRegInt = TRUE
                    IF Src$ = "Use_CreateRegString" THEN Use_CreateRegString = TRUE
                    IF Src$ = "Use_Csrlin" THEN Use_Csrlin = TRUE
                    IF Src$ = "Use_Curdir" THEN Use_Curdir = TRUE
                    IF Src$ = "Use_Cvd" THEN Use_Cvd = TRUE
                    IF Src$ = "Use_Cvi" THEN Use_Cvi = TRUE
                    IF Src$ = "Use_Cvl" THEN Use_Cvl = TRUE
                    IF Src$ = "Use_Cvld" THEN Use_Cvld = TRUE
                    IF Src$ = "Use_Cvs" THEN Use_Cvs = TRUE
                    IF Src$ = "Use_Cpad" THEN Use_Cpad = TRUE
                CASE  4
                    IF Src$ = "Use_Datepick" THEN Use_Datepick = TRUE
                    IF Src$ = "Use_Del" THEN Use_Del = TRUE
                    IF Src$ = "Use_DeleteRegKey" THEN Use_DeleteRegKey = TRUE
                    IF Src$ = "Use_Diskfree" THEN Use_Diskfree = TRUE
                    IF Src$ = "Use_Diskused" THEN Use_Diskused = TRUE
                    IF Src$ = "Use_Disksize" THEN Use_Disksize = TRUE
                    IF Src$ = "Use_Doevents" THEN Use_Doevents = TRUE
                    IF Src$ = "Use_Download" THEN Use_Download = TRUE
                    IF Src$ = "Use_Draw" THEN Use_Draw = TRUE
                    IF Src$ = "Use_DrawTransBMP" THEN Use_DrawTransBMP = TRUE
                    IF Src$ = "Use_DSplit" THEN Use_DSplit = TRUE
                    IF Src$ = "Use_Dynacall" THEN Use_DynacallCommon = Use_Dynacall = TRUE
                    IF Src$ = "Use_DynamicA" THEN Use_DynamicA = TRUE
                    IF Src$ = "Use_DynStrqsorta" THEN Use_DynStrqsorta = TRUE
                    IF Src$ = "Use_DynStrqsortas" THEN Use_DynStrqsortas = TRUE
                    IF Src$ = "Use_DynStrqsortd" THEN Use_DynStrqsortd = TRUE
                    IF Src$ = "Use_DynStrqsortds" THEN Use_DynStrqsortds = TRUE
                CASE  5
                    IF Src$ = "Use_Edit" THEN Use_Edit = TRUE
                    IF Src$ = "Use_Elf" THEN Use_Elf = TRUE
                    IF Src$ = "Use_Enclose" THEN Use_Enclose = TRUE
                    IF Src$ = "Use_Environ" THEN Use_Environ = TRUE
                    IF Src$ = "Use_Eof" THEN Use_Eof = TRUE
                    IF Src$ = "Use_Exist" THEN Use_Exist = TRUE
                    IF Src$ = "Use_Exp" THEN Use_Exp = TRUE
                    IF Src$ = "Use_Extract" THEN Use_Extract = TRUE
                CASE  6
                    IF Src$ = "Use_FileLocked" THEN Use_FileLocked = TRUE
                    IF Src$ = "Use_FillArray" THEN Use_FillArray = TRUE
                    IF Src$ = "Use_Findfirst" THEN Use_Findfirst = TRUE
                    IF Src$ = "Use_Findnext" THEN Use_Findnext = TRUE
                    IF Src$ = "Use_FirstInstance" THEN Use_FirstInstance = TRUE
                    IF Src$ = "Use_FindInType" THEN Use_FindInType = TRUE
                    IF Src$ = "Use_Form" THEN Use_Form = TRUE
                    IF Src$ = "Use_Freefile" THEN Use_Freefile = TRUE
                CASE  7
                    IF Src$ = "Use_GetBmp" THEN Use_GetBmp = TRUE
                    IF Src$ = "Use_GetDimension" THEN Use_GetDimension = TRUE
                    IF Src$ = "Use_Getfilename" THEN Use_Getfilename = TRUE
                    IF Src$ = "Use_GetSpecialFolder" THEN Use_GetSpecialFolder = TRUE
                    IF Src$ = "Use_GetSpecialFolderex" THEN Use_GetSpecialFolderex = TRUE
                    IF Src$ = "Use_GetText" THEN Use_GetText = TRUE
                    IF Src$ = "Use_GetTextSize" THEN Use_GetTextSize = TRUE
                    IF Src$ = "Use_Grayrect" THEN Use_Grayrect = TRUE
                    IF Src$ = "Use_Group" THEN Use_Group = TRUE
                CASE  8
                    IF Src$ = "Use_Hex" THEN Use_Hex = TRUE
                    IF Src$ = "Use_Hex2Dec" THEN Use_Hex2Dec = TRUE
                    IF Src$ = "Use_Hook" THEN Use_Hook = TRUE
                    IF Src$ = "Use_Hscroll" THEN Use_Hscroll = TRUE
                CASE  9
                    IF Src$ = "Use_Icon" THEN Use_Icon = TRUE
                    IF Src$ = "Use_Idxqsort" THEN Use_Idxqsort = TRUE
                    IF Src$ = "Use_IdxqsortSt" THEN Use_IdxqsortSt = TRUE
                    IF Src$ = "Use_Inchr" THEN Use_Inchr = TRUE
                    IF Src$ = "Use_Infobox" THEN Use_BoxCommon = Use_Infobox = TRUE
                    IF Src$ = "Use_Inkey" THEN Use_Inkey = TRUE
                    IF Src$ = "Use_InkeyD" THEN Use_InkeyD = TRUE
                    IF Src$ = "Use_Inputbox" THEN Use_BoxCommon = Use_Inputbox = TRUE
                    IF Src$ = "Use_Ins" THEN Use_Ins = TRUE
                    IF Src$ = "Use_Instr" THEN Use_Instr = TRUE
                    IF Src$ = "Use_InstrAny" THEN Use_InstrAny = TRUE
                    IF Src$ = "Use_Instrrev" THEN Use_Instrrev = TRUE
                    IF Src$ = "Use_IRemove" THEN Use_IRemove = TRUE
                    IF Src$ = "Use_iReplace" THEN Use_iReplace = TRUE
                CASE  10
                    IF Src$ = "Use_Join" THEN Use_Join = TRUE
                CASE  11
                    IF Src$ = "Use_Keypress" THEN Use_Keypress = TRUE
                CASE  12
                    IF Src$ = "Use_Label" THEN Use_Label = TRUE
                    IF Src$ = "Use_Lcase" THEN Use_Lcase = TRUE
                    IF Src$ = "Use_LCaseTbl" THEN Use_LCaseTbl = TRUE
                    IF Src$ = "Use_LccPath" THEN Use_LccPath = TRUE
                    IF Src$ = "Use_Left" THEN Use_Left = TRUE
                    IF Src$ = "Use_Like" THEN Use_Like = TRUE
                    IF Src$ = "Use_Listbox" THEN Use_Listbox = TRUE
                    IF Src$ = "Use_ListBoxLoadFile" THEN Use_ListBoxLoadFile = TRUE
                    IF Src$ = "Use_Listview" THEN Use_Listview = TRUE
                    IF Src$ = "Use_LoadFile" THEN Use_LoadFile = TRUE
                    IF Src$ = "Use_Loc" THEN Use_Loc = TRUE
                    IF Src$ = "Use_Longestline" THEN Use_Longestline = TRUE
                    IF Src$ = "Use_Locate" THEN Use_Locate = TRUE
                    IF Src$ = "Use_Lof" THEN Use_Lof = TRUE
                    IF Src$ = "Use_Lpad" THEN Use_Lpad = TRUE
                    IF Src$ = "Use_Ltrim" THEN Use_Ltrim = TRUE
                CASE  13
                    IF Src$ = "Use_Makebmp" THEN Use_Makebmp = TRUE
                    IF Src$ = "Use_Makehdc" THEN Use_Makehdc = TRUE
                    IF Src$ = "Use_Max" THEN Use_Max = TRUE
                    IF Src$ = "Use_Mcase" THEN Use_Mcase = TRUE
                    IF Src$ = "Use_Mid" THEN Use_Mid = TRUE
                    IF Src$ = "Use_Midstr" THEN Use_Midstr = TRUE
                    IF Src$ = "Use_Min" THEN Use_Min = TRUE
                    IF Src$ = "Use_Mkd" THEN Use_Mkd = TRUE
                    IF Src$ = "Use_Mki" THEN Use_Mki = TRUE
                    IF Src$ = "Use_Mkl" THEN Use_Mkl = TRUE
                    IF Src$ = "Use_Mkld" THEN Use_Mkld = TRUE
                    IF Src$ = "Use_Mks" THEN Use_Mks = TRUE
                    IF Src$ = "Use_Mkpath" THEN Use_Mks = TRUE
                    IF Src$ = "Use_Modstyle" THEN Use_Modstyle = TRUE
                    IF Src$ = "Use_Msgbox" THEN Use_Msgbox = TRUE
                CASE  14
                    IF Src$ = "Use_Newbmp" THEN Use_Newbmp = TRUE
                    IF Src$ = "Use_Nextlinelen" THEN Use_Nextlinelen = TRUE
                    IF Src$ = "Use_Now" THEN Use_Now = TRUE
                    IF Src$ = "Use_Numqsortadouble" THEN Use_Numqsortadouble = TRUE
                    IF Src$ = "Use_Numqsortafloat" THEN Use_Numqsortafloat = TRUE
                    IF Src$ = "Use_Numqsortaint" THEN Use_Numqsortaint = TRUE
                    IF Src$ = "Use_Numqsortddouble" THEN Use_Numqsortddouble = TRUE
                    IF Src$ = "Use_Numqsortdfloat" THEN Use_Numqsortdfloat = TRUE
                    IF Src$ = "Use_Numqsortdint" THEN Use_Numqsortdint = TRUE
                CASE  15
                    IF Src$ = "Use_Oct" THEN Use_Oct = TRUE
                    IF Src$ = "Use_OSVersion" THEN Use_OSVersion = TRUE
                CASE  16
                    IF Src$ = "Use_Panel" THEN Use_Panel = TRUE
                    IF Src$ = "Use_Pause" THEN Use_Pause = TRUE
                    IF Src$ = "Use_PeekStr" THEN Use_PeekStr = TRUE
                    IF Src$ = "Use_PellesPath" THEN Use_PellesPath = TRUE
                    IF Src$ = "Use_PlayWav" THEN Use_PlayWav = TRUE
                    IF Src$ = "Use_Pos" THEN Use_Pos = TRUE
                    IF Src$ = "UseCpp" THEN UseCpp = TRUE
                    IF Src$ = "Use_Printer" THEN Use_Printer = TRUE
                    IF Src$ = "Use_ProgressBar" THEN Use_ProgressBar = TRUE
                    IF Src$ = "Use_PtrqsortSt" THEN Use_PtrqsortSt = TRUE
                CASE  17
                    IF Src$ = "Use_QBColor" THEN Use_QBColor = TRUE
                CASE  18
                    IF Src$ = "Use_Radio" THEN Use_Radio = TRUE
                    IF Src$ = "Use_Randomize" THEN Use_Randomize = TRUE
                    IF Src$ = "Use_Rec" THEN Use_Rec = TRUE
                    IF Src$ = "Use_RecCount" THEN Use_RecCount = TRUE
                    IF Src$ = "Use_RegInt" THEN Use_RegInt = TRUE
                    IF Src$ = "Use_RegString" THEN Use_RegString = TRUE
                    IF Src$ = "Use_Remain" THEN Use_Remain = TRUE
                    IF Src$ = "Use_Remove" THEN Use_Remove = TRUE
                    IF Src$ = "Use_RemoveAny" THEN Use_RemoveAny = TRUE
                    IF Src$ = "Use_Repeat" THEN Use_Repeat = TRUE
                    IF Src$ = "Use_Replace" THEN Use_Replace = TRUE
                    IF Src$ = "Use_ReplaceAny" THEN Use_ReplaceAny = TRUE
                    IF Src$ = "Use_Retain" THEN Use_Retain = TRUE
                    IF Src$ = "Use_Reverse" THEN Use_Reverse = TRUE
                    IF Src$ = "Use_Richedit" THEN Use_Richedit = TRUE
                    IF Src$ = "Use_Right" THEN Use_Right = TRUE
                    IF Src$ = "Use_Rnd" THEN Use_Rnd = TRUE
                    IF Src$ = "Use_Rnd2" THEN Use_Rnd2 = TRUE
                    IF Src$ = "Use_Round" THEN Use_Round = TRUE
                    IF Src$ = "Use_Rpad" THEN Use_Rpad = TRUE
                    IF Src$ = "Use_Rtrim" THEN Use_Rtrim = TRUE
                    IF Src$ = "Use_Run" THEN Use_Run = TRUE
                CASE  19
                    IF Src$ = "Use_SaveBmp" THEN Use_SaveBmp = TRUE
                    IF Src$ = "Use_Scan" THEN Use_Scan = TRUE
                    IF Src$ = "Use_Screen" THEN Use_Screen = TRUE
                    IF Src$ = "Use_SearchPath" THEN Use_SearchPath = TRUE
                    IF Src$ = "Use_Setclientsize" THEN Use_Setclientsize = TRUE
                    IF Src$ = "Use_SetColor" THEN Use_SetColor = TRUE
                    IF Src$ = "Use_SetDimension" THEN Use_SetDimension = TRUE
                    IF Src$ = "Use_SetFont" THEN Use_SetFont = TRUE
                    IF Src$ = "Use_SetFormColor" THEN Use_SetFormColor = TRUE
                    IF Src$ = "Use_SetText" THEN Use_SetText = TRUE
                    IF Src$ = "Use_Set_BCX_Bitmap" THEN Use_Set_BCX_Bitmap = TRUE
                    IF Src$ = "Use_Set_BCX_Bitmap2" THEN Use_Set_BCX_Bitmap2 = TRUE
                    IF Src$ = "Use_Set_BCX_BmpButton" THEN Use_Set_BCX_BmpButton = TRUE
                    IF Src$ = "Use_Set_BCX_Icon" THEN Use_Set_BCX_Icon = TRUE
                    IF Src$ = "Use_Sgn" THEN Use_Sgn = TRUE
                    IF Src$ = "Use_Sound" THEN Use_Sound = TRUE
                    IF Src$ = "Use_Space" THEN Use_Space = TRUE
                    IF Src$ = "Use_Split" THEN Use_Split = TRUE
                    IF Src$ = "Use_Status" THEN Use_Status = TRUE
                    IF Src$ = "Use_Str" THEN Use_Str = TRUE
                    IF Src$ = "Use_Strim" THEN Use_Strim = TRUE
                    IF Src$ = "Use_String" THEN Use_String = TRUE
                    IF Src$ = "Use_Stristr" THEN Use_Stristr = TRUE
                    IF Src$ = "Use_Strl" THEN Use_Strl = TRUE
                    IF Src$ = "Use_Strqsorta" THEN Use_Strqsorta = TRUE
                    IF Src$ = "Use_Strqsortas" THEN Use_Strqsortas = TRUE
                    IF Src$ = "Use_Strqsortd" THEN Use_Strqsortd = TRUE
                    IF Src$ = "Use_Strqsortds" THEN Use_Strqsortds = TRUE
                    IF Src$ = "Use_Strtoken" THEN Use_Strtoken = TRUE
                    IF Src$ = "Use_Swap" THEN Use_Swap = TRUE
                    IF Src$ = "Use_Sysdir" THEN Use_Sysdir = TRUE
                    IF Src$ = "Use_SysStr" THEN Use_SysStr = TRUE
                    IF Src$ = "Use_sziif" THEN Use_sziif = TRUE
                CASE  20
                    IF Src$ = "Use_Tix" THEN Use_Tix = TRUE
                    IF Src$ = "Use_Tally" THEN Use_Tally = TRUE
                    IF Src$ = "Use_Tempdir" THEN Use_Tempdir = TRUE
                    IF Src$ = "Use_TempFileName" THEN Use_TempFileName = TRUE
                    IF Src$ = "Use_Textmode" THEN Use_Textmode = TRUE
                    IF Src$ = "Use_Time" THEN Use_Time = TRUE
                    IF Src$ = "Use_Timer" THEN Use_Timer = TRUE
                    IF Src$ = "Use_Treeview" THEN Use_Treeview = TRUE
                    IF Src$ = "Use_Trim" THEN Use_Trim = TRUE
                CASE  21
                    IF Src$ = "Use_Utf8tochr" THEN Use_Utf8tochr = TRUE
                    IF Src$ = "Use_Ucase" THEN Use_Ucase = TRUE
                    IF Src$ = "Use_UCaseTbl" THEN Use_UCaseTbl = TRUE
                    IF Src$ = "Use_Using" THEN Use_Using = TRUE
                    IF Src$ = "Use_Unwrap" THEN Use_Unwrap = TRUE
                CASE  22
                    IF Src$ = "Use_VBS" THEN Use_VBS = TRUE
                    IF Src$ = "Use_VChr" THEN Use_VChr = TRUE
                    IF Src$ = "Use_Verify" THEN Use_Verify = TRUE
                CASE  23
                    IF Src$ = "Use_Whiterect" THEN Use_Whiterect = TRUE
                    IF Src$ = "Use_WideToAnsi" THEN Use_WideToAnsi = TRUE
                    IF Src$ = "Use_Windir" THEN Use_Windir = TRUE
                    IF Src$ = "Use_Wrap" THEN Use_Wrap = TRUE
            END SELECT
        LOOP
        CLOSE FPUSE
    NEXT
END SUB ' SetUsed



SUB SetFlags
    OPEN Project$ FOR OUTPUT AS FPFLAGS
    IF Use_Acosh THEN FPRINT FPFLAGS, "Use_Acosh"
    IF Use_AnsiToWide THEN FPRINT FPFLAGS, "Use_AnsiToWide"
    IF Use_AppActivate THEN FPRINT FPFLAGS, "Use_AppActivate"
    IF Use_AppExeName THEN FPRINT FPFLAGS, "Use_AppExeName"
    IF Use_AppExePath THEN FPRINT FPFLAGS, "Use_AppExePath"
    IF Use_Asc THEN FPRINT FPFLAGS, "Use_Asc"
    IF Use_Asinh THEN FPRINT FPFLAGS, "Use_Asinh"
    IF Use_Atanh THEN FPRINT FPFLAGS, "Use_Atanh"
    IF Use_BCX_Arc THEN FPRINT FPFLAGS, "Use_BCX_Arc"
    IF Use_BCX_Pie THEN FPRINT FPFLAGS, "Use_BCX_Pie"
    IF Use_BCX_BmpHeight THEN FPRINT FPFLAGS, "Use_BCX_BmpHeight"
    IF Use_BCX_Blit THEN FPRINT FPFLAGS, "Use_BCX_Blit"
    IF Use_BCX_Blit_Stretch THEN FPRINT FPFLAGS, "Use_BCX_Blit_Stretch"
    IF Use_BCX_Blit_Sprite THEN FPRINT FPFLAGS, "Use_BCX_Blit_Sprite"
    IF Use_BCX_Buffer THEN FPRINT FPFLAGS, "Use_BCX_Buffer"
    IF Use_BCX_BmpHeight THEN FPRINT FPFLAGS, "Use_BCX_BmpHeight"
    IF Use_BCX_BmpWidth THEN FPRINT FPFLAGS, "Use_BCX_BmpWidth"
    IF Use_BCX_Circle THEN FPRINT FPFLAGS, "Use_BCX_Circle"
    IF Use_BCX_Colordlg THEN FPRINT FPFLAGS, "Use_BCX_Colordlg"
    IF Use_BCX_Control THEN FPRINT FPFLAGS, "Use_BCX_Control"
    IF Use_Consolesize THEN FPRINT FPFLAGS, "Use_BCX_Consolesize"
    IF Use_BCX_Ellipse THEN FPRINT FPFLAGS, "Use_BCX_Ellipse"
    IF Use_BCX_Floodfill THEN FPRINT FPFLAGS, "Use_BCX_Floodfill"
    IF Use_BCX_Fontdlg THEN FPRINT FPFLAGS, "Use_BCX_Fontdlg"
    IF Use_BCX_Get THEN FPRINT FPFLAGS, "Use_BCX_Get"
    IF Use_BCX_Get_Window_Height THEN FPRINT FPFLAGS, "Use_BCX_Get_Window_Height"
    IF Use_BCX_Get_Window_Width THEN FPRINT FPFLAGS, "Use_BCX_Get_Window_Width"
    IF Use_BCX_Getpixel THEN FPRINT FPFLAGS, "Use_BCX_Getpixel"
    IF Use_BCX_Get_UpDown THEN FPRINT FPFLAGS, "Use_BCX_Get_UpDown"
    IF Use_BCX_Input THEN FPRINT FPFLAGS, "Use_BCX_Input"
    IF Use_BCX_Line THEN FPRINT FPFLAGS, "Use_BCX_Line"
    IF Use_BCX_Polar_Line THEN FPRINT FPFLAGS, "Use_BCX_Polar_Line"
    IF Use_BCX_Lineto THEN FPRINT FPFLAGS, "Use_BCX_Lineto"
    IF Use_BCX_Triangle THEN FPRINT FPFLAGS, "Use_BCX_Triangle"
    IF Use_BCX_Gradient THEN FPRINT FPFLAGS, "Use_BCX_Gradient"
    IF Use_BCX_LoadBMP THEN FPRINT FPFLAGS, "Use_BCX_LoadBMP"
    IF Use_BCX_LoadImage THEN FPRINT FPFLAGS, "Use_BCX_LoadImage"
    IF Use_BCX_OlePicture THEN FPRINT FPFLAGS, "Use_BCX_OlePicture"
    IF Use_BCX_Path THEN FPRINT FPFLAGS, "Use_BCX_Path"
    IF Use_BcxSplitPath THEN FPRINT FPFLAGS, "Use_BcxSplitPath"
    IF Use_BCX_PolyBezier THEN FPRINT FPFLAGS, "Use_BCX_PolyBezier"
    IF Use_BCX_Polygon THEN FPRINT FPFLAGS, "Use_BCX_Polygon"
    IF Use_BCX_Polyline THEN FPRINT FPFLAGS, "Use_BCX_Polyline"
    IF Use_BCX_Preset THEN FPRINT FPFLAGS, "Use_BCX_Preset"
    IF Use_BCX_Print THEN FPRINT FPFLAGS, "Use_BCX_Print"
    IF Use_BCX_Printex THEN FPRINT FPFLAGS, "Use_BCX_Printex"
    IF Use_BCX_Pset THEN FPRINT FPFLAGS, "Use_BCX_Pset"
    IF Use_BCX_Polar_Pset THEN FPRINT FPFLAGS, "Use_BCX_Polar_Pset"
    IF Use_BCX_Put THEN FPRINT FPFLAGS, "Use_BCX_Put"
    IF Use_BCX_Rectangle THEN FPRINT FPFLAGS, "Use_BCX_Rectangle"
    IF Use_BCX_Resize THEN FPRINT FPFLAGS, "Use_BCX_Resize"
    IF Use_BCX_Roundrect THEN FPRINT FPFLAGS, "Use_BCX_Roundrect"
    IF Use_BCX_Tab THEN FPRINT FPFLAGS, "Use_BCX_Tab"
    IF Use_BCX_Toolbar THEN FPRINT FPFLAGS, "Use_BCX_Toolbar"
    IF Use_BCX_Tile THEN FPRINT FPFLAGS, "Use_BCX_Tile"
    IF Use_BCX_UpDown THEN FPRINT FPFLAGS, "Use_BCX_UpDown"
    IF Use_BCX_Slider THEN FPRINT FPFLAGS, "Use_BCX_Slider"
    IF Use_BCX_Splitter THEN FPRINT FPFLAGS, "Use_BCX_Splitter"
    IF Use_BCX_stricmp THEN FPRINT FPFLAGS, "Use_BCX_stricmp"
    IF Use_BcxTempStr THEN FPRINT FPFLAGS, "Use_BcxTempStr"
    IF Use_Bff THEN FPRINT FPFLAGS, "Use_Bff"
    IF Use_Bin THEN FPRINT FPFLAGS, "Use_Bin"
    IF Use_Bin2dec THEN FPRINT FPFLAGS, "Use_Bin2dec"
    IF Use_Bitmap THEN FPRINT FPFLAGS, "Use_Bitmap"
    IF Use_Blackrect THEN FPRINT FPFLAGS, "Use_Blackrect"
    IF Use_BmpButton THEN FPRINT FPFLAGS, "Use_BmpButton"
    IF Use_Boolstr THEN FPRINT FPFLAGS, "Use_Boolstr"
    IF Use_Button THEN FPRINT FPFLAGS, "Use_Button"
    IF Use_Center THEN FPRINT FPFLAGS, "Use_Center"
    IF Use_Checkbox THEN FPRINT FPFLAGS, "Use_Checkbox"
    IF Use_Chrtoutf8 THEN FPRINT FPFLAGS, "Use_Chrtoutf8"
    IF Use_Cint THEN FPRINT FPFLAGS, "Use_Cint"
    IF Use_Clip_Getbitmap THEN FPRINT FPFLAGS, "Use_Clip_Getbitmap"
    IF Use_Clip_Setbitmap THEN FPRINT FPFLAGS, "Use_Clip_Setbitmap"
    IF Use_Clip_Gettext THEN FPRINT FPFLAGS, "Use_Clip_Gettext"
    IF Use_Clip_Gettextsize THEN FPRINT FPFLAGS, "Use_Clip_Gettextsize"
    IF Use_Clip_Settext THEN FPRINT FPFLAGS, "Use_Clip_Settext"
    IF Use_Clip_Reset THEN FPRINT FPFLAGS, "Use_Clip_Reset"
    IF Use_Clng THEN FPRINT FPFLAGS, "Use_Clng"
    IF Use_Cls THEN FPRINT FPFLAGS, "Use_Cls"
    IF Use_Color THEN FPRINT FPFLAGS, "Use_Color"
    IF Use_COM THEN FPRINT FPFLAGS, "Use_COM"
    IF Use_Combobox THEN FPRINT FPFLAGS, "Use_Combobox"
    IF Use_ComboBoxLoadFile THEN FPRINT FPFLAGS, "Use_ComboBoxLoadFile"
    IF Use_Command THEN FPRINT FPFLAGS, "Use_Command"
    IF Use_ContainedIn THEN FPRINT FPFLAGS, "Use_ContainedIn"
    IF Use_CreateRegInt THEN FPRINT FPFLAGS, "Use_CreateRegInt"
    IF Use_CreateRegString THEN FPRINT FPFLAGS, "Use_CreateRegString"
    IF Use_Cpad THEN FPRINT FPFLAGS, "Use_Cpad"
    IF Use_Csrlin THEN FPRINT FPFLAGS, "Use_Csrlin"
    IF Use_Curdir THEN FPRINT FPFLAGS, "Use_Curdir"
    IF Use_Cvd THEN FPRINT FPFLAGS, "Use_Cvd"
    IF Use_Cvi THEN FPRINT FPFLAGS, "Use_Cvi"
    IF Use_Cvl THEN FPRINT FPFLAGS, "Use_Cvl"
    IF Use_Cvld THEN FPRINT FPFLAGS, "Use_Cvld"
    IF Use_Cvs THEN FPRINT FPFLAGS, "Use_Cvs"
    IF Use_Datepick THEN FPRINT FPFLAGS, "Use_Datepick"
    IF Use_Del THEN FPRINT FPFLAGS, "Use_Del"
    IF Use_Diskfree THEN FPRINT FPFLAGS, "Use_Diskfree"
    IF Use_Diskused THEN FPRINT FPFLAGS, "Use_Diskused"
    IF Use_Disksize THEN FPRINT FPFLAGS, "Use_Disksize"
    IF Use_DeleteRegKey THEN FPRINT FPFLAGS, "Use_DeleteRegKey"
    IF Use_BCXMDialog THEN FPRINT FPFLAGS, "Use_BCXMDialog"
    IF Use_BCXDialog THEN FPRINT FPFLAGS, "Use_BCXDialog"
    IF Use_Doevents THEN FPRINT FPFLAGS, "Use_Doevents"
    IF Use_Download THEN FPRINT FPFLAGS, "Use_Download"
    IF Use_Draw THEN FPRINT FPFLAGS, "Use_Draw"
    IF Use_DrawTransBMP THEN FPRINT FPFLAGS, "Use_DrawTransBMP"
    IF Use_DSplit THEN FPRINT FPFLAGS, "Use_DSplit"
    IF Use_Dynacall AND NOT DllCnt THEN FPRINT FPFLAGS, "Use_Dynacall"
    IF Use_DynamicA THEN FPRINT FPFLAGS, "Use_DynamicA"
    IF Use_DynStrqsorta THEN FPRINT FPFLAGS, "Use_DynStrqsorta"
    IF Use_DynStrqsortas THEN FPRINT FPFLAGS, "Use_DynStrqsortas"
    IF Use_DynStrqsortd THEN FPRINT FPFLAGS, "Use_DynStrqsortd"
    IF Use_DynStrqsortds THEN FPRINT FPFLAGS, "Use_DynStrqsortds"
    IF Use_Edit THEN FPRINT FPFLAGS, "Use_Edit"
    IF Use_Elf THEN FPRINT FPFLAGS, "Use_Elf"
    IF Use_Enclose THEN FPRINT FPFLAGS, "Use_Enclose"
    IF Use_Environ THEN FPRINT FPFLAGS, "Use_Environ"
    IF Use_Eof THEN FPRINT FPFLAGS, "Use_Eof"
    IF Use_Exist THEN FPRINT FPFLAGS, "Use_Exist"
    IF Use_Exp THEN FPRINT FPFLAGS, "Use_Exp"
    IF Use_Extract THEN FPRINT FPFLAGS, "Use_Extract"
    IF Use_FileLocked THEN FPRINT FPFLAGS, "Use_FileLocked"
    IF Use_FillArray THEN FPRINT FPFLAGS, "Use_FillArray"
    IF Use_Findfirst THEN FPRINT FPFLAGS, "Use_Findfirst"
    IF Use_Findnext THEN FPRINT FPFLAGS, "Use_Findnext"
    IF Use_FirstInstance THEN FPRINT FPFLAGS, "Use_FirstInstance"
    IF Use_FindInType THEN FPRINT FPFLAGS, "Use_FindInType"
    IF Use_Form THEN FPRINT FPFLAGS, "Use_Form"
    IF Use_Freefile THEN FPRINT FPFLAGS, "Use_Freefile"
    IF Use_GetBmp THEN FPRINT FPFLAGS, "Use_GetBmp"
    IF Use_GetDimension THEN FPRINT FPFLAGS, "Use_GetDimension"
    IF Use_Getfilename THEN FPRINT FPFLAGS, "Use_Getfilename"
    IF Use_GetSpecialFolder THEN FPRINT FPFLAGS, "Use_GetSpecialFolder"
    IF Use_GetSpecialFolderex THEN FPRINT FPFLAGS, "Use_GetSpecialFolderex"
    IF Use_GetText THEN FPRINT FPFLAGS, "Use_GetText"
    IF Use_GetTextSize THEN FPRINT FPFLAGS, "Use_GetTextSize"
    IF Use_Grayrect THEN FPRINT FPFLAGS, "Use_Grayrect"
    IF Use_Group THEN FPRINT FPFLAGS, "Use_Group"
    IF Use_Hex THEN FPRINT FPFLAGS, "Use_Hex"
    IF Use_Hex2Dec THEN FPRINT FPFLAGS, "Use_Hex2Dec"
    IF Use_Hook THEN FPRINT FPFLAGS, "Use_Hook"
    IF Use_Hscroll OR Use_Vscroll THEN FPRINT FPFLAGS, "Use_Hscroll"
    IF Use_Icon THEN FPRINT FPFLAGS, "Use_Icon"
    IF Use_Idxqsort THEN FPRINT FPFLAGS, "Use_Idxqsort"
    IF Use_IdxqsortSt THEN FPRINT FPFLAGS, "Use_IdxqsortSt"
    IF Use_Iif THEN FPRINT FPFLAGS, "Use_Iif"
    IF Use_Inchr THEN FPRINT FPFLAGS, "Use_Inchr"
    IF Use_Infobox THEN FPRINT FPFLAGS, "Use_Infobox"
    IF Use_Inkey THEN FPRINT FPFLAGS, "Use_Inkey"
    IF Use_InkeyD THEN FPRINT FPFLAGS, "Use_InkeyD"
    IF Use_Infobox THEN FPRINT FPFLAGS, "Use_Infobox"
    IF Use_Inputbox THEN FPRINT FPFLAGS, "Use_Inputbox"
    IF Use_Ins THEN FPRINT FPFLAGS, "Use_Ins"
    IF Use_Instr THEN FPRINT FPFLAGS, "Use_Instr"
    IF Use_InstrAny THEN FPRINT FPFLAGS, "Use_InstrAny"
    IF Use_Instrrev THEN FPRINT FPFLAGS, "Use_Instrrev"
    IF Use_IRemove THEN FPRINT FPFLAGS, "Use_IRemove"
    IF Use_iReplace THEN FPRINT FPFLAGS, "Use_iReplace"
    IF Use_Join THEN FPRINT FPFLAGS, "Use_Join"
    IF Use_Keypress THEN FPRINT FPFLAGS, "Use_Keypress"
    IF Use_Label THEN FPRINT FPFLAGS, "Use_Label"
    IF Use_LCaseTbl THEN FPRINT FPFLAGS, "Use_LCaseTbl"
    IF Use_Lcase THEN FPRINT FPFLAGS, "Use_Lcase"
    IF Use_LccPath THEN FPRINT FPFLAGS, "Use_LccPath"
    IF Use_Left THEN FPRINT FPFLAGS, "Use_Left"
    IF Use_LeftStr THEN FPRINT FPFLAGS, "Use_LeftStr"
    IF Use_Like THEN FPRINT FPFLAGS, "Use_Like"
    IF Use_Listbox THEN FPRINT FPFLAGS, "Use_Listbox"
    IF Use_ListBoxLoadFile THEN FPRINT FPFLAGS, "Use_ListBoxLoadFile"
    IF Use_Listview THEN FPRINT FPFLAGS, "Use_Listview"
    IF Use_LoadFile THEN FPRINT FPFLAGS, "Use_LoadFile"
    IF Use_Loc THEN FPRINT FPFLAGS, "Use_Loc"
    IF Use_Locate THEN FPRINT FPFLAGS, "Use_Locate"
    IF Use_Lof THEN FPRINT FPFLAGS, "Use_Lof"
    IF Use_Longestline THEN FPRINT FPFLAGS, "Use_Longestline"
    IF Use_Lpad THEN FPRINT FPFLAGS, "Use_Lpad"
    IF Use_Ltrim THEN FPRINT FPFLAGS, "Use_Ltrim"
    IF Use_Max THEN FPRINT FPFLAGS, "Use_Max"
    IF Use_Mcase THEN FPRINT FPFLAGS, "Use_Mcase"
    IF Use_Mid THEN FPRINT FPFLAGS, "Use_Mid"
    IF Use_Midstr THEN FPRINT FPFLAGS, "Use_Midstr"
    IF Use_Min THEN FPRINT FPFLAGS, "Use_Min"
    IF Use_Mkd THEN FPRINT FPFLAGS, "Use_Mkd"
    IF Use_Mki THEN FPRINT FPFLAGS, "Use_Mki"
    IF Use_Mkl THEN FPRINT FPFLAGS, "Use_Mkl"
    IF Use_Mkld THEN FPRINT FPFLAGS, "Use_Mkld"
    IF Use_Mks THEN FPRINT FPFLAGS, "Use_Mks"
    IF Use_Mkpath THEN FPRINT FPFLAGS, "Use_Mkpath"
    IF Use_Modstyle THEN FPRINT FPFLAGS, "Use_Modstyle"
    IF Use_Msgbox THEN FPRINT FPFLAGS, "Use_Msgbox"
    IF Use_Nextlinelen THEN FPRINT FPFLAGS, "Use_Nextlinelen"
    IF Use_Now THEN FPRINT FPFLAGS, "Use_Now"
    IF Use_Numqsortadouble THEN FPRINT FPFLAGS, "Use_Numqsortadouble"
    IF Use_Numqsortafloat THEN FPRINT FPFLAGS, "Use_Numqsortafloat"
    IF Use_Numqsortaint THEN FPRINT FPFLAGS, "Use_Numqsortaint"
    IF Use_Numqsortddouble THEN FPRINT FPFLAGS, "Use_Numqsortddouble"
    IF Use_Numqsortdfloat THEN FPRINT FPFLAGS, "Use_Numqsortdfloat"
    IF Use_Numqsortdint THEN FPRINT FPFLAGS, "Use_Numqsortdint"
    IF Use_Oct THEN FPRINT FPFLAGS, "Use_Oct"
    IF Use_OSVersion THEN FPRINT FPFLAGS, "Use_OSVersion"
    IF Use_Panel THEN FPRINT FPFLAGS, "Use_Panel"
    IF Use_Pause THEN FPRINT FPFLAGS, "Use_Pause"
    IF Use_PeekStr THEN FPRINT FPFLAGS, "Use_PeekStr"
    IF Use_PellesPath THEN FPRINT FPFLAGS, "Use_PellesPath"
    IF Use_PlayWav THEN FPRINT FPFLAGS, "Use_PlayWav"
    IF Use_Pos THEN FPRINT FPFLAGS, "Use_Pos"
    IF UseCpp THEN FPRINT FPFLAGS, "UseCpp"
    IF Use_Printer THEN FPRINT FPFLAGS, "Use_Printer"
    IF Use_ProgressBar THEN FPRINT FPFLAGS, "Use_ProgressBar"
    IF Use_PtrqsortSt THEN FPRINT FPFLAGS, "Use_PtrqsortSt"
    IF Use_QBColor THEN FPRINT FPFLAGS, "Use_QBColor"
    IF Use_Radio THEN FPRINT FPFLAGS, "Use_Radio"
    IF Use_Randomize THEN FPRINT FPFLAGS, "Use_Randomize"
    IF Use_Rec THEN FPRINT FPFLAGS, "Use_Rec"
    IF Use_RecCount THEN FPRINT FPFLAGS, "Use_RecCount"
    IF Use_RegInt THEN FPRINT FPFLAGS, "Use_RegInt"
    IF Use_RegString THEN FPRINT FPFLAGS, "Use_RegString"
    IF Use_Remain THEN FPRINT FPFLAGS, "Use_Remain"
    IF Use_Remove THEN FPRINT FPFLAGS, "Use_Remove"
    IF Use_RemoveAny THEN FPRINT FPFLAGS, "Use_RemoveAny"
    IF Use_Repeat THEN FPRINT FPFLAGS, "Use_Repeat"
    IF Use_Replace THEN FPRINT FPFLAGS, "Use_Replace"
    IF Use_ReplaceAny THEN FPRINT FPFLAGS, "Use_ReplaceAny"
    IF Use_Retain THEN FPRINT FPFLAGS, "Use_Retain"
    IF Use_Reverse THEN FPRINT FPFLAGS, "Use_Reverse"
    IF Use_Richedit THEN FPRINT FPFLAGS, "Use_Richedit"
    IF Use_Right THEN FPRINT FPFLAGS, "Use_Right"
    IF Use_RightStr THEN FPRINT FPFLAGS, "Use_RightStr"
    IF Use_Rnd THEN FPRINT FPFLAGS, "Use_Rnd"
    IF Use_Rnd2 THEN FPRINT FPFLAGS, "Use_Rnd2"
    IF Use_Round THEN FPRINT FPFLAGS, "Use_Round"
    IF Use_Rpad THEN FPRINT FPFLAGS, "Use_Rpad"
    IF Use_Rtrim THEN FPRINT FPFLAGS, "Use_Rtrim"
    IF Use_Run THEN FPRINT FPFLAGS, "Use_Run"
    IF Use_SaveBmp THEN FPRINT FPFLAGS, "Use_SaveBmp"
    IF Use_Scan THEN FPRINT FPFLAGS, "Use_Scan"
    IF Use_Screen THEN FPRINT FPFLAGS, "Use_Screen"
    IF Use_SearchPath THEN FPRINT FPFLAGS, "Use_SearchPath"
    IF Use_SetColor THEN FPRINT FPFLAGS, "Use_SetColor"
    IF Use_Setclientsize THEN FPRINT FPFLAGS, "Use_Setclientsize"
    IF Use_SetDimension THEN FPRINT FPFLAGS, "Use_SetDimension"
    IF Use_SetFont THEN FPRINT FPFLAGS, "Use_SetFont"
    IF Use_SetFormColor THEN FPRINT FPFLAGS, "Use_SetFormColor"
    IF Use_SetText THEN FPRINT FPFLAGS, "Use_SetText"
    IF Use_Set_BCX_Bitmap THEN FPRINT FPFLAGS, "Use_Set_BCX_Bitmap"
    IF Use_Set_BCX_Bitmap2 THEN FPRINT FPFLAGS, "Use_Set_BCX_Bitmap2"
    IF Use_Newbmp THEN FPRINT FPFLAGS, "Use_Newbmp"
    IF Use_Makebmp THEN FPRINT FPFLAGS, "Use_Makebmp"
    IF Use_Makehdc THEN FPRINT FPFLAGS, "Use_Makehdc"
    IF Use_Set_BCX_BmpButton THEN FPRINT FPFLAGS, "Use_Set_BCX_BmpButton"
    IF Use_Set_BCX_Icon THEN FPRINT FPFLAGS, "Use_Set_BCX_Icon"
    IF Use_Sgn THEN FPRINT FPFLAGS, "Use_Sgn"
    IF Use_Sound THEN FPRINT FPFLAGS, "Use_Sound"
    IF Use_Space THEN FPRINT FPFLAGS, "Use_Space"
    IF Use_Split THEN FPRINT FPFLAGS, "Use_Split"
    IF Use_Status THEN FPRINT FPFLAGS, "Use_Status"
    IF Use_Str THEN FPRINT FPFLAGS, "Use_Str"
    IF Use_Strim THEN FPRINT FPFLAGS, "Use_Strim"
    IF Use_String THEN FPRINT FPFLAGS, "Use_String"
    IF Use_Stristr THEN FPRINT FPFLAGS, "Use_Stristr"
    IF Use_Strl THEN FPRINT FPFLAGS, "Use_Strl"
    IF Use_Strqsorta THEN FPRINT FPFLAGS, "Use_Strqsorta"
    IF Use_Strqsortas THEN FPRINT FPFLAGS, "Use_Strqsortas"
    IF Use_Strqsortd THEN FPRINT FPFLAGS, "Use_Strqsortd"
    IF Use_Strqsortds THEN FPRINT FPFLAGS, "Use_Strqsortds"
    IF Use_Strtoken THEN FPRINT FPFLAGS, "Use_Strtoken"
    IF Use_Swap THEN FPRINT FPFLAGS, "Use_Swap"
    IF Use_Sysdir THEN FPRINT FPFLAGS, "Use_Sysdir"
    IF Use_SysStr THEN FPRINT FPFLAGS, "Use_SysStr"
    IF Use_sziif THEN FPRINT FPFLAGS, "Use_sziif"
    IF Use_Tally THEN FPRINT FPFLAGS, "Use_Tally"
    IF Use_Tix THEN FPRINT FPFLAGS, "Use_Tix"
    IF Use_Tempdir THEN FPRINT FPFLAGS, "Use_Tempdir"
    IF Use_TempFileName THEN FPRINT FPFLAGS, "Use_TempFileName"
    IF Use_Textmode THEN FPRINT FPFLAGS, "Use_Textmode"
    IF Use_Time THEN FPRINT FPFLAGS, "Use_Time"
    IF Use_Timer THEN FPRINT FPFLAGS, "Use_Timer"
    IF Use_Treeview THEN FPRINT FPFLAGS, "Use_Treeview"
    IF Use_Trim THEN FPRINT FPFLAGS, "Use_Trim"
    IF Use_Ucase THEN FPRINT FPFLAGS, "Use_Ucase"
    IF Use_Using THEN FPRINT FPFLAGS, "Use_Using"
    IF Use_Utf8tochr THEN FPRINT FPFLAGS, "Use_Utf8tochr"
    IF Use_VBS THEN FPRINT FPFLAGS, "Use_VBS"
    IF Use_VChr THEN FPRINT FPFLAGS, "Use_VChr"
    IF Use_Verify THEN FPRINT FPFLAGS, "Use_Verify"
    IF Use_Whiterect THEN FPRINT FPFLAGS, "Use_Whiterect"
    IF Use_WideToAnsi THEN FPRINT FPFLAGS, "Use_WideToAnsi"
    IF Use_Windir THEN FPRINT FPFLAGS, "Use_Windir"
    CLOSE FPFLAGS
END SUB ' SetFlags

