/***********************************************/
/* VX-Rexx Macro to build the lstaccts.etm     */
/* E-Teller macro.                             */
/* Please do not modify                        */
/***********************************************/
/* Custom mainline for macro */

    call RXFuncAdd "VRLoadFuncs", "VROBJ", "VRLoadFuncs"
    call VRLoadFuncs

    _VREVersion = SubWord( VRVersion( "VRObj" ), 1, 1 )
    if( _VREVersion < 2.02 )then do
        call VRMessage "", "This program requires VX-REXX version 2.0b to run.", "Error!"
        return 32000
    end

    signal on SYNTAX name _VRESyntax
    signal _VREMain

_VRESyntax:
    parse source . . _VRESourceSpec
    call VRMessage "", "Syntax error in" _VRESourceSpec "line" SIGL, "Error!"
    exit 32000

_VREMain:
/*:VRX         Main
*/
Main:
parse arg INI .
if INI = '' then do
   call VRMessage 'Screen', 'Command line error.  ', 'Error'
   exit
end
MAC = 'macros\lstaccts.etm'
AcctDir = VRGetINI( 'Main', 'AcctDir', INI )
if AcctDir = '' then AcctDir = VRGet( 'Application', 'WorkingDirectory' )
s = VRDir( AcctDir||'\*.clr', 'N' )
count = 1
accounts.0 = 0
do while s <> ''
    accounts.count = AcctDir||'\'||s
    accounts.0 = count
    count = count + 1
    s = VRDir( , 'N' )
end
do i = 1 to accounts.0
    call stream accounts.i, 'c', 'open'
    call stream accounts.i, 'c', 'seek =1'
    do forever
        if( lines( accounts.i ) = 0 )then
            leave
        line = linein( accounts.i )
        parse var line key '=' value
        if key = 'Account' then
            account.i = value
        if key = 'Type' then do
            AccountType.i = value
            leave
        end
    end
    call stream accounts.i, 'c', 'close'
    drop line key value
end
Account.0 = accounts.0
AccountType.0 = accounts.0

if( VRFileExists( MAC ) )then
    call VRDeleteFile MAC
call lineout MAC, '/**************************************************/'
call lineout MAC, '/* Macro file for reading accounts into container */'
call lineout MAC, '/* DO NOT MODIFY                                  */'
call lineout MAC, '/**************************************************/'
call lineout MAC, "if VRFileExists( '!.!!!' )then call VRDeleteFile '!.!!!'"
call lineout MAC, "if( \VRFileExists( 'q2et.exe' ) )then call VRSet 'MenuUtilQIF', 'Enabled', 0"
call lineout MAC, "if( \VRFileExists( 'etreport.exe' ) )then call VRSet 'MenuAccountsPrint', 'Enabled', 0"
call lineout MAC, "if( \VRFileExists( 'etbudget.exe' ) )then call VRSet 'MenuAccountsBudget', 'Enabled', 0"
call lineout MAC, "icon = ''"
if accounts.0 = 0 then do
    buttons.0 = 3
    buttons.1 = "~Create account..."
    buttons.2 = "~Select directory..."
    buttons.3 = "~Cancel"
    msg.0 = 5
    msg.1 = "Unable to locate account files in directory:  "AcctDir"\."
    msg.2 = ""
    msg.3 = "Possible reasons are:"
    msg.4 = "1) Accounts have not yet been created."
    msg.5 = "2) Accounts reside in a different directory."
    id = VRMessageStem( "", "msg.", "Accounts Not Found", "Information", "buttons.", 1, 3 )
    drop buttons. msg.
    if id = 1 then
        call VRMethod 'Application', 'PostQueue', 0, 1, 'call MenuAccountsNew_Click'
    if id = 2 then
        call VRMethod 'Application', 'PostQueue', 0, 1, 'call MenuAccountsDir_Click'
    drop id
    call stream MAC, 'c', 'close'
    exit
end
if accounts.0 <> 0 then do i = 1 to accounts.0
    call lineout MAC, "call lineout '!.!!!', '"account.i"'"
    call lineout MAC, "call lineout '!.!!!', '"accounts.i"'"
end
call lineout MAC, "call stream '!.!!!', 'c', 'close'"
if accounts.0 <> 0 then do i = 1 to accounts.0
    call lineout MAC, "recHandle = VRMethod( 'CNAccounts', 'AddRecord', , , '"account.i"' )"
    call lineout MAC, "if recHandle <> '' then do; call VRMethod 'CNAccounts', 'SetRecordAttr', recHandle, 'Caption', '"account.i"', 'FileName', '"accounts.i"'; call VRMethod 'CNAccounts', 'SetFieldData', recHandle, field.!Type, '"AccountType.i"'; end"
end
call lineout MAC, "call GetIcon"
call stream MAC, 'c', 'close'
drop MAC accounts. account. accounttype. s i AcctDir
exit

