Sign in to follow this  
Followers 0
AutoitNew94

Question about Strings

14 posts in this topic

#1 ·  Posted (edited)

I am working on a function that replaces the standard DOS command ECHO.

I have been searching through the help file for a little while now, and

am curious as to how one might go about searching a string for sub strings

meeting a certain criteria.

So the string would be...

Hello $World

...which would be passed from either the command line or an external script.

I guess there would be two functions to accomplish this.

First setting $World = Planet

Second searching the string for any sub strings beginning with "$"SomeStr, but

in the same respect ignoring something like "Hello $World ignore this $ as it is part of our string."

So when outputted to the command prompt would result in...

Hello Planet Ignore this $ as it is part of our string

For arguments sake I will call the au3 script "ECHO.EXE" and "SET.EXE" for the variable sets after compiled.

Now pretending that we have these two script written and compiled and we are now executing from the command

prompt.

Here is what I would like to accomplish.

C:\>SET.EXE $World=Planet
C:\>ECHO.EXE "Hello $World this is a test."
Hello Planet this is a test.

How would this be accomplished.

I am looking at StringRegExp for the string manipulation, but have no idea how I would store user defined variables.

Any and all input on this is very much appreciated.

Thank You

Edited by AutoitNew94

"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I'm confused as to why you want to accomplish this as the standard ECHO command can print variables:

>set WORLD=Planet
>echo Hello %WORLD% this is a test.
Hello Planet this is a test.

The problem with what you're attempting is that you have no way of retaining and data unless you use file to do it. You would need your SET.EXE program to write to a file, and have your ECHO.EXE use this file to look up variables.

Edited by zorphnog

Share this post


Link to post
Share on other sites

I'm confused as to why you want to accomplish this as the standard ECHO command can print variables:

I have a few other ideas for adding some other functions to the ECHO command, but am starting off with

the already existing, the fact that ECHO can interpret variables.

The problem with what you're attempting is that you have no way of retaining and data unless you use file to do it. You would need your SET.EXE program to write to a file, and have your ECHO.EXE use this file to look up variables.

Wouldn't there be a way to use the logic behind...

For $i = 1 To...

...storing the variables to numbers and then checking those values, without the need

of an external file?


"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

Autoitnew94,

Define specifically what you mean by this:

adding some other functions to the ECHO command

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Hey. As for what your attempting, I donno if it's possible. If it is, I just donno how it would work.

As I see you, you essentially wanna have a variable from AutoIt echoed, but the $ serves as an issue. Perhaps store the variables differently, like in a file? It's a bit confusing. 0_o Sorry, haven't really done anything related to what your doing. >;p

Share this post


Link to post
Share on other sites

Autoitnew94,

Define specifically what you mean by this:

kylomas

Well for instance being able to chop up the string sending them to separate lines.

In DOS it would be...

C:\>echo.Hello&echo.World
Hello
World

...whereas quoted and unquoted strings in Autoit can produce this result automatically.

If $Cmdline[0] > 0 Then
    For $i = 1 To $CmdLine[0]
        ConsoleWrite($CmdLine[$i] & @LF)
    Next
EndIf

I tried this once some time ago using a batch file to do this.

@echo off
 setlocal

:: BEGIN_FUNCTION
    set MAINStr=Hello $World $Hello World.

    set BYTEval=0
    set NEXTval=0
    :SUB-FUNCTION[BeginBYTELoop]
    set /a BYTEval=%BYTEval%+1
    call set "StrByte=%%MAINStr:~0,%BYTEval%%%"
    set "StrChar=%StrByte:~-1%"
    if "%BYTE%"=="1" goto :VARByte
    if /i "%StrChar%"=="$" set BYTE=1&&goto :SUB-FUNCTION[BeginBYTELoop]
    if /i "%StrByte%"=="%MAINStr%" goto :eof
    goto :SUB-FUNCTION[BeginBYTELoop]

    :VARByte
    set /a NEXTval=%NEXTval%+1
    if "%StrChar%"==" " (
        call set "SUBStr=%%StrByte:~-%NEXTval%%%"
        call set "BYTE="
        call :FoundString
        call set NEXTval=0
    )
    goto :SUB-FUNCTION[BeginBYTELoop]

    :FoundString
    for /f "tokens=1 delims= " %%- in ("%SUBStr%") do (
    echo.%%-
    )
:: END_FUNCTION

The idea was to find the variable strings and use +1 theory to assign

each variable to a number and then search for those values and their

corresponding strings, but I never got that far.

I figure something in the same respect can be done in Autoit using the +1

theory to assign variables to numerical values.


"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

Wouldn't there be a way to use the logic behind...

For $i = 1 To...

...storing the variables to numbers and then checking those values, without the need

of an external file?

The problem is that your variables are volatile data. As soon as SET.EXE exits, your data is lost.

Share this post


Link to post
Share on other sites

The problem is that your variables are volatile data. As soon as SET.EXE exits, your data is lost.

You are absolutely correct, so then I guess we combine the two, and

just call it NewCmd.exe, and run everything from one file.

Lots and lots of functions, so now how might this idea be approached?


"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Autoitnew94,

You might want to do some searching on inter-process, inter-script communication to see what has been done before. However, there is no DOS api or interface of any kind that I know of so you are reduced to using an external storage medium (file, for instance).

What about replacing BAT files with AutoIT, instead of trying to communicate with them?

kylomas

Edit: This just occurred to me...are you trying to write a functional equivalent to CMD.EXE?

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Edit: This just occurred to me...are you trying to write a functional equivalent to CMD.EXE?

In many ways yes and for no other purpose than for my own satisfaction. I know Powershell and, Au3Int exist.

I would just like my own flavor as perl offers it own flavor to batch in the same respect.

I should clarify though I do not wish to recode the wheel just maybe some extended utilities that I can use, but I would like to stick to the subject at hand as far as setting and storing variables and working with the echo command.

Thank You

Edited by AutoitNew94

"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Here is a small example of two scripts which share a variable. The Master sets the value in a dllstruct (whatever value is in the edit) and the slave reads from the memory used by the dll. If you had other windows then they can do the same as the slave and read form the same memory address in the same way.

This is the master. When you run as a script it will also run the slave script, but the slave script must ba saved as "slave.au3" and be in the same folder as the master script.

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
#include <guiconstants.au3>
#include <SecurityConstants.au3>
#include <nomadmemory.au3>
#include <editconstants.au3>


Opt("GUIOnEventMode", 1)
GUICreate("Master (sets variable)", 250, 70)
$input = GUICtrlCreateInput("1", 20, 20, 120, 28, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
GUISetState()


GUISetOnEvent($GUI_EVENT_CLOSE, "done")
$AutoItProdexePath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir");installDir for production

$output = DllStructCreate("int")
$opAdd = DllStructGetPtr($output)

$typeMesg = RegisterWindowMessage("someuniquetext10987")
GUIRegisterMsg($typeMesg, "tellAddr"); respond to requests for the address to use

$ToRun = '"' & $AutoItProdexePath & '\AutoIt3.exe"' & ' "' & @ScriptDir & '\slave.au3"'
Run($ToRun)

WinWait("Slave1", "", 30);wait up to 30 sec for slave
If Not WinExists("Slave1") Then Exit

Global $CurrentVal, $Lastval = -1

While 1

    $CurrentVal = Number(GUICtrlRead($input))
    If $CurrentVal <> $lastval Then
    DllStructSetData($output, 1, $CurrentVal)
    $lastval = $CurrentVal
        ConsoleWrite("set to "& $lastval & @CRLF)
    EndIf
    If not WinExists("Slave1") then exit
WEnd





Func tellAddr($hWndGUI, $MsgID, $WParam, $LParam)
    If $Wparam = 1 then Return $opAdd

EndFunc ;==>tellAddr

;register window message
;returns a unique message number. if the message has already been registered then the
;the unique number for $stext is returned.
;Useful for two windows to communicate
Func RegisterWindowMessage($sText)
    Local $aRet = DllCall('user32.dll', 'int', 'RegisterWindowMessage', 'str', $sText)

    Return $aRet[0]
EndFunc ;==>RegisterWindowMessage


Func done()

    Exit
EndFunc

This is the slave script which is run for you by the master. Instead, you could have 2 exe's and the master need not run the slave (remove the "Run" line)

; *** Start added by AutoIt3Wrapper ***
#include <GUIConstantsEx.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
#include <guiconstants.au3>
#include <SecurityConstants.au3>
#include <nomadmemory.au3>
#include <SendMessage.au3>


Opt("GUIOnEventMode", 1)
$masterTitle = "Master (sets variable)"
If Not WinExists($masterTitle) Then Exit;must run master first

$wp = WinGetPos($masterTitle)
GUICreate("Slave1", 250, 70,$wp[0],$wp[1]+$wp[3])
$labmem = GUICtrlCreateLabel("00000000000", 20, 20, 120, 28)
GUISetState()


GUISetOnEvent($GUI_EVENT_CLOSE, "done")

;get info on master
Global $pid = WinGetProcess($masterTitle), $hid = WinGetHandle($masterTitle)

Global $MemOpen = _MemoryOpen($pid), $memadd = 0


$typeMesg = RegisterWindowMessage("someuniquetext10987")

$memadd = _SendMessage($hid, $typeMesg, 1);tell master we want address of variable
;master will reply with address to use


$Lastval = -1

While 1

    $CurrentVal = Get(1)
    If $Lastval <> $CurrentVal Then
    GUICtrlSetData($labmem, $CurrentVal)
    $lastVal = $CurrentVal
    EndIf
 sleep(50)

if not winexists($masterTitle) then exit

WEnd





Func Get($var)
    ;only reads one int in this script so $var ignored
    Return _MemoryRead($memadd, $MemOpen, "int")

EndFunc ;==>Get

Func Set($var, $val);not used
    ;only write one int in this script so $var ignored
    _MemoryWrite($memadd, $MemOpen, $val, "int")
EndFunc ;==>Set

Func Done()
    Exit
EndFunc ;==>Done


Func RegisterWindowMessage($sText)
    Local $aRet = DllCall('user32.dll', 'int', 'RegisterWindowMessage', 'str', $sText)
    Return $aRet[0]
EndFunc ;==>RegisterWindowMessage

I went searching through the form and ran across this.

Thanks to the original author, but this idea seems to present

possibilities in what I am looking to accomplish.

Edited by AutoitNew94

"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Autoitnew94,

What you found is AI to AI communications. This will NOT work for DOS.

Consider using environmental variables for rudimentary data passing (ENVGET, ENVSET and ENVUPDATE).

kylomas

Edit: Addendum

Check out this link for how ripdad is processing output from CMD.EXE

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Firstly, I'm assuming that this is a DOS window under Windows as opposed to a full DOS session initiated from a boot disk - there is a very important difference between the two!

Part of the problem is that any call to a script, compiled or otherwise, will initiate a new instance of that script rather than using an already running instance. This means that creating redirecting scripts for "set" and echo" to point to a single master script "newcmd" and passing the parameters will still create a new instance of the script, so any memory variables used by previous (or still running) instances will be inaccessible.

For workarounds, you could use the shell variable structure for storage of a limited amount of data, use a file storage (flat file, INI or XML) or even write the data to the registry for storage. It may also be possible to get a hook in to an existing running script by calling it via it's PID, but this may mean writing some extensions for AutoIt, similar to calling functions and procedures stored in an external .dll (which may not be a bad thing, but it would mean some pretty heavy development work!)

The main method of attack so far is to get DOS to run AutoIt scripts from within its shell and maintain memory continuity between them. Lets put AutoIt outside the DOS box instead! Use the AutoIt script as the shell to execute the commands, and call CMD /c to execute those commands that aren't programmed into the main script! The result is that all the 'set' and 'echo' commands are now interpreted by the main AutoIt script, which remains in memory so all variables are available. Any commands not understood by the script can be passed off to an instance of cmd.exe, which returns control to the main script upon termination.

Hopefully that will spark your imagination :)

Share this post


Link to post
Share on other sites

Hopefully that will spark your imagination :)

That it most certainly does.

Another day another learning curve.

So I am borrowing this idea for my learning and testing purposes to try and understand more in depth exactly the best approach to accomplishing this project.

Many thanks to Matt Diesel for his project and source on the AutoIt3 Interpreter.

I have been pulling apart this code piece by piece function by function to try and better understand what exactly is going on.

Now if I run the source run cmd.exe from it it spawns a new process of cmd.exe but it is at least showing me how to work with Autoit from the command console. This I think is what I am after, the idea that is, being able to execute DOS commands from the Interpreter in stead of interpreting Autoit commands and then from there building extended functionality on top of the already built in functions of cmd as well as any extended utilities.

...or maybe the idea of just creating an entirely new GUI to go with it and leaving cmd out completely.

Here is the source torn down to at least keep the window open. Now I am sure all of this is not needed to accomplish this, so my question is what are the most important parts needed to work with cmd?

Matt Diesel's Source:

#NoTrayIcon
#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=Au3Int.ico
#AutoIt3Wrapper_outfile=Au3Int.exe
#AutoIt3Wrapper_Change2CUI=Y
#AutoIt3Wrapper_Res_Comment=http://www.autoitscript.com/autoit3/
#AutoIt3Wrapper_Res_Description=The dynamic interpreter for AutoIt3
#AutoIt3Wrapper_Res_Fileversion=1.0.2.10
#AutoIt3Wrapper_Res_LegalCopyright=Copyright © Matt Diesel (Mat) 2010
#AutoIt3Wrapper_Res_Field=Author|Matt Diesel (Mat)
#AutoIt3Wrapper_Res_Field=OriginalFilename|Au3Int.exe
#AutoIt3Wrapper_Res_Field=ProductName|Au3Int
#AutoIt3Wrapper_Res_Field=AutoItVersion|3.3.6.1
#AutoIt3Wrapper_Res_Icon_Add=C:\Program Files\AutoIt3\Icons\au3script_v10.ico
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 4 -w 5 -w 6
#AutoIt3Wrapper_Run_After=MD "%scriptdir%\Versions\au3int\%fileversion%"
#AutoIt3Wrapper_Run_After=MD "%scriptdir%\Versions\au3int\%fileversion%\source"
#AutoIt3Wrapper_Run_After=COPY "%in%" "%scriptdir%\Versions\au3int\%fileversion%\source\%scriptfile%.au3"
#AutoIt3Wrapper_Run_After=COPY "%icon%" "%scriptdir%\Versions\au3int\%fileversion%\source\%scriptfile%.ico"
#AutoIt3Wrapper_Run_After=COPY "%scriptdir%\au3int.chm" "%scriptdir%\Versions\au3int\%fileversion%\au3int.chm"
#AutoIt3Wrapper_Run_After=MOVE "%out%" "%scriptdir%\Versions\au3int\%fileversion%\%scriptfile%.exe"
#AutoIt3Wrapper_Run_After=DEL /F /Q "Au3Int_obfuscated.au3"
#Tidy_Parameters=/sf
#AutoIt3Wrapper_Run_Obfuscator=y
#Obfuscator_Parameters=/cs=0 /cn=0 /cf=1 /cv=1 /sf=0 /sv=0
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****

Global $hKERNEL32
Global $hPSAPI
Global $hConsoleOutput
Global $hConsoleInput
Global $sCode = ""
Global $iLimit = 400

_Au3Int_Start()

If $CmdLine[0] <> 0 Then _Au3Int_CommandLine()

While _Au3Int_Proc()
WEnd






Func _Au3Int_ArrayParse($asInd, $j) ; wraithdu
    Local $sInStr = "", $iInFunc = 0, $iInDef = 0, $sTemp = ""
    For $j = $j To StringLen($asInd)
        Switch StringMid($asInd, $j, 1)
            Case """"
                If $sInStr = "" Then
                    $sInStr = """"
                ElseIf $sInStr = """" Then
                    $sInStr = ""
                EndIf
                $sTemp &= """"
            Case "'"
                If $sInStr = "" Then
                    $sInStr = "'"
                ElseIf $sInStr = "'" Then
                    $sInStr = ""
                EndIf
                $sTemp &= "'"
            Case "("
                If $sInStr = "" Then $iInFunc += 1
                $sTemp &= "("
            Case ")"
                If $sInStr = "" Then $iInFunc -= 1
                $sTemp &= ")"
            Case "["
                If $sInStr <> "" Or $iInFunc Then
                    $sTemp &= "["
                    ContinueLoop
                EndIf
                If $iInDef Then $sTemp &= "["
                $iInDef += 1
            Case "]"
                If $sInStr <> "" Or $iInFunc Then
                    $sTemp &= "]"
                    ContinueLoop
                EndIf
                $iInDef -= 1
                If $iInDef Then
                    $sTemp &= "]"
                Else
                    ; end of dimension definition
                    Return SetError(0, $j, $sTemp)
                EndIf
            Case Else
                $sTemp &= StringMid($asInd, $j, 1)
        EndSwitch
    Next
EndFunc   ;==>_Au3Int_ArrayParse






Func _Au3Int_AssignArray(ByRef $aArray, $aDim, $vValue)
    Switch $aDim[0]
        Case 1
            $aArray[$aDim[1]] = $vValue
        Case 2
            $aArray[$aDim[1]][$aDim[2]] = $vValue
        Case 3
            $aArray[$aDim[1]][$aDim[2]][$aDim[3]] = $vValue
        Case 4
            $aArray[$aDim[1]][$aDim[2]][$aDim[3]][$aDim[4]] = $vValue
        Case 5
            $aArray[$aDim[1]][$aDim[2]][$aDim[3]][$aDim[4]][$aDim[5]] = $vValue
        Case 6
            $aArray[$aDim[1]][$aDim[2]][$aDim[3]][$aDim[4]][$aDim[5]][$aDim[6]] = $vValue
        Case Else
            _Console_Write("Error in array statement. The interpreter supports a maximum of 6 dimensions." & @CRLF)
            Return SetError(1)
    EndSwitch
EndFunc   ;==>_Au3Int_AssignArray






Func _Au3Int_AutoItInfo()
    Local $s = "HKLM\SOFTWARE\AutoIt v3\AutoIt"
    If @OSArch = "X64" Then $s = "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt"
    Local $sBetaVer = RegRead($s, "betaVersion")
    Local $sVer = RegRead($s, "Version")
    If @error And $sBetaVer = "" Then
        _Console_Write("AutoIt v3 is not installed on this computer." & @CRLF)
        Return
    EndIf

    Local $sDir = RegRead($s, "InstallDir")
    _Console_Write("AutoIt3 (" & $sVer & ") is installed in: " & $sDir & @CRLF)

    If $sBetaVer <> "" Then
        $sDir = RegRead($s, "betaInstallDir")
        If Not @error Then _Console_Write("AutoIt3 Beta (" & $sBetaVer & ") is installed in: " & $sDir & @CRLF)

        Switch RegRead("HKCR\.au3", "")
            Case "AutoIt3Script"
                _Console_Write("Currently using release version." & @CRLF)
            Case "AutoIt3ScriptBeta"
                _Console_Write("Currently using beta version." & @CRLF)
        EndSwitch
    EndIf
EndFunc   ;==>_Au3Int_AutoItInfo






Func _Au3Int_Clr()
    Local $tScreenBufferInfo = _Console_GetConsoleScreenBufferInfo()

    _Console_FillOutputCharacter(" ", DllStructGetData($tScreenBufferInfo, "SizeX") * (DllStructGetData($tScreenBufferInfo, "SizeY")), 0, 0)
    _Console_SetCursorPos(0, 0)

    Return True
EndFunc   ;==>_Au3Int_Clr






Func _Au3Int_ClrLine()
    Local $tScreenBufferInfo = _Console_GetConsoleScreenBufferInfo()

    _Console_FillOutputCharacter(" ", DllStructGetData($tScreenBufferInfo, "SizeX"), 0, DllStructGetData($tScreenBufferInfo, "CursorPositionY") - 1)
    _Console_SetCursorPos(0, DllStructGetData($tScreenBufferInfo, "CursorPositionY") - 1)

    Return True
EndFunc   ;==>_Au3Int_ClrLine






Func _Au3Int_CommandLine()
    _Console_Write("Running: " & $CmdLine[1] & @CRLF)

    Local $hTimer = TimerInit()
    Local $iCode = RunWait("""" & @AutoItExe & """ /ErrorStdOut /AutoIt3ExecuteScript """ & $CmdLine[1] & """", @ScriptDir, Default, 0x10)

    _Console_Write("Exited code: " & $iCode & ", took: " & Round(TimerDiff($hTimer)) & "ms" & @CRLF)
    RunWait(@ComSpec & " /c PAUSE", @ScriptDir, Default, 0x10)
    Exit
EndFunc   ;==>_Au3Int_CommandLine






Func _Au3Int_CommaSplit($sInput)
    Local $sInStr = "", $iInDef = 0, $iInFunc = 0, $aRet[2] = [1, ""]

    For $i = 1 To StringLen($sInput)
        Switch StringMid($sInput, $i, 1)
            Case """"
                If $sInStr = "" Then
                    $sInStr = """"
                ElseIf $sInStr = """" Then
                    $sInStr = ""
                EndIf
            Case "'"
                If $sInStr = "" Then
                    $sInStr = "'"
                ElseIf $sInStr = "'" Then
                    $sInStr = ""
                EndIf
            Case "("
                If $sInStr = "" Then $iInFunc += 1
            Case ")"
                If $sInStr = "" Then $iInFunc -= 1
            Case "["
                If $sInStr = "" Then $iInDef += 1
            Case "]"
                If $sInStr = "" Then $iInDef -= 1
            Case ","
                If ($sInStr = "") And ($iInDef = 0) And ($iInFunc = 0) Then
                    ; Good :) Add a new item to the array
                    $aRet[0] += 1
                    ReDim $aRet[$aRet[0] + 1]
                    ContinueLoop
                EndIf
        EndSwitch

        $aRet[$aRet[0]] &= StringMid($sInput, $i, 1)
    Next

    Return $aRet
EndFunc   ;==>_Au3Int_CommaSplit






Func _Au3Int_CreateArray($aDim)
    Switch $aDim[0]
        Case 1
            Local $aVar[$aDim[1]]
        Case 2
            Local $aVar[$aDim[1]][$aDim[2]]
        Case 3
            Local $aVar[$aDim[1]][$aDim[2]][$aDim[3]]
        Case 4
            Local $aVar[$aDim[1]][$aDim[2]][$aDim[3]][$aDim[4]]
        Case 5
            Local $aVar[$aDim[1]][$aDim[2]][$aDim[3]][$aDim[4]][$aDim[5]]
        Case 6
            Local $aVar[$aDim[1]][$aDim[2]][$aDim[3]][$aDim[4]][$aDim[5]][$aDim[6]]
        Case Else
            _Console_Write("Error in array declaration. The interpreter supports a maximum of 6 dimensions." & @CRLF)
            Return SetError(1)
    EndSwitch

    Return $aVar
EndFunc   ;==>_Au3Int_CreateArray






Func _Au3Int_EvalArray($aArray, $aDim)
    Switch $aDim[0]
        Case 1
            Return $aArray[$aDim[1]]
        Case 2
            Return $aArray[$aDim[1]][$aDim[2]]
        Case 3
            Return $aArray[$aDim[1]][$aDim[2]][$aDim[3]]
        Case 4
            Return $aArray[$aDim[1]][$aDim[2]][$aDim[3]][$aDim[4]]
        Case 5
            Return $aArray[$aDim[1]][$aDim[2]][$aDim[3]][$aDim[4]][$aDim[5]]
        Case 6
            Return $aArray[$aDim[1]][$aDim[2]][$aDim[3]][$aDim[4]][$aDim[5]][$aDim[6]]
        Case Else
            _Console_Write("Error in array statement. The interpreter supports a maximum of 6 dimensions." & @CRLF)
            Return SetError(1)
    EndSwitch
EndFunc   ;==>_Au3Int_EvalArray






Func _Au3Int_GetArrayElem($sInput, $iDim) ; wraithdu
    $sInput = StringStripWS($sInput, 3)
    $sInput = StringMid($sInput, 2, StringLen($sInput) - 2) ; strip outside [ ]

    $sInput = _Au3Int_CommaSplit($sInput)
    ReDim $sInput[$iDim + 2] ; prevent out of bounds errors
    Return StringStripWS($sInput[$iDim + 1], 3)
EndFunc   ;==>_Au3Int_GetArrayElem






Func _Au3Int_GetOp($sInput, $sOp) ; wraithdu
    Local $sInStr = "", $iInFunc = 0, $iInDef = 0

    For $i = 1 To StringLen($sInput)
        Switch StringMid($sInput, $i, 1)
            Case """"
                If $sInStr = "" Then
                    $sInStr = """"
                ElseIf $sInStr = """" Then
                    $sInStr = ""
                EndIf
            Case "'"
                If $sInStr = "" Then
                    $sInStr = "'"
                ElseIf $sInStr = "'" Then
                    $sInStr = ""
                EndIf
            Case "("
                If $sInStr = "" Then $iInFunc += 1
            Case ")"
                If $sInStr = "" Then $iInFunc -= 1
            Case "["
                If $sInStr = "" Then $iInDef += 1
            Case "]"
                If $sInStr = "" Then $iInDef -= 1
            Case $sOp
                If ($sInStr = "") And (Not $iInFunc) And (Not $iInDef) Then Return $i
        EndSwitch
    Next
    Return 0
EndFunc   ;==>_Au3Int_GetOp






Func _Au3Int_Install($fInstall = True)
    Local $sKey = "HKCR\Au3IntTempScript"

    If $fInstall Then
        RegWrite("HKCR\.au3", "", "REG_SZ", "Au3IntTempScript")
        RegWrite($sKey, "", "REG_SZ", "AutoIt v3 Script")
        RegWrite($sKey & "\DefaultIcon\", "", "REG_SZ", @ScriptFullPath & ",4")
        RegWrite($sKey & "\Shell\", "", "REG_SZ", "Run")

        RegWrite($sKey & "\Shell\Run", "", "REG_SZ", "Run Script")
        RegWrite($sKey & "\Shell\Run\Command", "", "REG_SZ", """" & @ScriptFullPath & """ /AutoIt3ExecuteScript ""%1"" %*")

        RegWrite($sKey & "\Shell\Runwo", "", "REG_SZ", "Run with console")
        RegWrite($sKey & "\Shell\Runwo\Command", "", "REG_SZ", """" & @ScriptFullPath & """ ""%1"" %*")

        RegWrite($sKey & "\Shell\Edit", "", "REG_SZ", "Edit")
        RegWrite($sKey & "\Shell\Edit\Command", "", "REG_SZ", "notepad.exe %1")

        _Console_Write("AutoIt3 Scripts associated with the interpreter." & @CRLF)
    Else
        RegDelete("HKCR\.au3")
        RegDelete($sKey)
    EndIf
EndFunc   ;==>_Au3Int_Install






Func _Au3Int_NQReplace($sInput, $sFind, $sReplace)
    Local $sInStr = "", $sRet = ""

    For $i = 1 To StringLen($sInput); - StringLen($sFind)
        Switch StringMid($sInput, $i, 1)
            Case """"
                If $sInStr = "" Then
                    $sInStr = """"
                ElseIf $sInStr = """" Then
                    $sInStr = ""
                EndIf
            Case "'"
                If $sInStr = "" Then
                    $sInStr = "'"
                ElseIf $sInStr = "'" Then
                    $sInStr = ""
                EndIf
            Case Else
                If ($sInStr = "") And (StringMid($sInput, $i, StringLen($sFind)) = $sFind) Then
                    $sRet &= $sReplace
                    $i += StringLen($sReplace) - 1
                    ContinueLoop
                EndIf
        EndSwitch

        $sRet &= StringMid($sInput, $i, 1)
    Next

    Return $sRet
EndFunc   ;==>_Au3Int_NQReplace






Func _Au3Int_OnExitProc()
    _Console_Write(@CRLF & "Saving Settings..." & @CRLF)

    ; Must use full path for regedit. Note that the settings are stored for AutoIt3.exe when running un-compiled.
    Local $sKey = "HKEY_CURRENT_USER\Console\" & StringReplace(@AutoItExe, "\", "_")
    RunWait("regedit /E settings.reg """ & $sKey & """", @ScriptDir, Default)
    RegDelete($sKey)

    _Console_Write(@CRLF & "Tidying up..." & @CRLF)
    FileDelete("code.au3")

;~  _Console_FreeConsole() ; Causes problems for some reason.

    _Console_Write(@CRLF & "Closing open handles..." & @CRLF)
;~  DllCallbackFree($hHandlerRoutine) ; Causes problems for some reason.
    DllClose($hKERNEL32)
    DllClose($hPSAPI)

    $hKERNEL32 = 0
    $hPSAPI = 0

    Exit
EndFunc   ;==>_Au3Int_OnExitProc






Func _Au3Int_PrintHead()
    If @Compiled Then
        _Console_Write("AutoIt3 Interpreter version: " & FileGetVersion(@ScriptFullPath) & @CRLF & _
                "Copyright (c) Matt Diesel (Mat) 2010" & @CRLF & @CRLF)
    Else
        _Console_Write("AutoIt3 Interpreter version: (Not compiled)" & @CRLF & _
                "Copyright (c) Matt Diesel (Mat) 2010" & @CRLF & "WARNING: Internal variable names are not mangled." & @CRLF & @CRLF)
    EndIf
EndFunc   ;==>_Au3Int_PrintHead






Func _Au3Int_Start()
    $hKERNEL32 = DllOpen("kernel32.dll")
    $hPSAPI = DllOpen("psapi.dll")

    ; Update settings.
    If FileExists(@ScriptDir & "\settings.reg") Then RunWait("regedit /S settings.reg", @ScriptDir)
    ;If Not @Compiled Then _Console_AllocConsole()
    _Console_AllocConsole()

    $hConsoleOutput = _Console_GetStdHandle(-11)
    $hConsoleInput = _Console_GetStdHandle(-10)

    Local $sTitle = "AutoIt3 Interpreter"

    If IsAdmin() Then $sTitle &= " (Administrator)"
    If Not @Compiled Then $sTitle &= " (Not compiled)"

    _Console_SetTitle($sTitle)
    If Not @Compiled And FileExists(@ScriptDir & "\Au3Int.ico") Then _
            _Console_SetIcon(@ScriptDir & "\Au3Int.ico")

    _Au3Int_PrintHead()
    WinActivate(_Console_GetConsoleWindow())
EndFunc   ;==>_Au3Int_Start






Func _Console_AllocConsole()
    Local $aResult = DllCall($hKERNEL32, "bool", "AllocConsole")
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc   ;==>_Console_AllocConsole





Func _Console_GetStdHandle($nStdHandle = -11)
    Local $aResult = DllCall($hKERNEL32, "handle", "GetStdHandle", "dword", $nStdHandle)
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc   ;==>_Console_GetStdHandle





Func _Console_SetTitle($sTitle)
    Local $aResult = DllCall($hKERNEL32, "bool", "SetConsoleTitleA", "str", $sTitle)
    If @error Then Return SetError(@error, @extended, False)

    Return $aResult[0]
EndFunc   ;==>_Console_SetTitle






Func _Console_Write($sText)
    Local $aResult

    $aResult = DllCall($hKERNEL32, "bool", "WriteConsoleA", "handle", $hConsoleOutput, "str", $sText, "dword", StringLen($sText), "dword*", 0, "ptr", 0)
    If @error Then Return SetError(@error, @extended, False)

    Return SetExtended($aResult[4], $aResult[0])
EndFunc   ;==>_Console_Write






Func _Console_GetConsoleWindow()
    Local $aResult = DllCall($hKERNEL32, "hwnd", "GetConsoleWindow")
    If @error Then Return SetError(@error, @extended, 0)

    Return $aResult[0]
EndFunc   ;==>_Console_GetConsoleWindow





Func _Au3Int_Proc()
    Local $sInput, $s__InternalInputCopy
    Local $error = 0, $extended = 0
    Local $iPrint ; 0 => Default, 1 = All, 2 = None
    Local $tScreenBufferInfo = DllStructCreate("SHORT SizeX; SHORT SizeY;SHORT CursorPositionX;" & _
            "SHORT CursorPositionY; SHORT Attributes;SHORT Left; SHORT Top; SHORT Right; SHORT Bottom;" & _
            "SHORT MaximumWindowSizeX; SHORT MaximumWindowSizeY")

    While 1
        DllCall($hPSAPI, "int", "EmptyWorkingSet", "long", -1)

        DllCall($hKERNEL32, "bool", "GetConsoleScreenBufferInfo", _
                "handle", $hConsoleOutput, _
                "ptr", DllStructGetPtr($tScreenBufferInfo))
        If DllStructGetData($tScreenBufferInfo, "CursorPositionX") > 1 Then _Console_Write(@CRLF)

        _Console_Write("Au3Int -> ")
        _Console_FlushInputBuffer()
        $sInput = _Au3Int_Read()
        $sInput = StringStripWS($sInput, 3)
        $s__InternalInputCopy = $sInput

        If StringLeft($sInput, 4) = "all:" Then
            $iPrint = 1
            $sInput = StringStripWS(StringTrimLeft($sInput, 4), 3)
        ElseIf StringLeft($sInput, 5) = "none:" Then
            $iPrint = 2
            $sInput = StringStripWS(StringTrimLeft($sInput, 5), 3)
        Else
            $iPrint = 0
        EndIf

        Switch $sInput
            Case ""
                _Au3Int_ClrLine()
                ContinueLoop
            Case "cap"
                _Console_Write("Output limit: " & $iLimit & @CRLF)
            Case "glass on"
                If Not _Console_BlurBehind() Then _
                        _Console_Write("Error setting glass. Requires vista or higher." & @CRLF)
            Case "glass off"
                If Not _Console_BlurBehind(False) Then _
                        _Console_Write("Error un-setting glass. Requires vista or higher." & @CRLF)
            Case "restart"
                If @Compiled Then
                    Run("""" & @ScriptFullPath & """", @ScriptDir, Default, 0x10)
                Else
                    Run("""" & @AutoItExe & """ /AutoIt3ExecuteScript """ & @ScriptFullPath & """", @ScriptDir, Default, 0x10)
                EndIf

                Exit
            Case "autoitinfo"
                _Au3Int_AutoItInfo()
            Case "install"
                If Not @Compiled Then
                    _Console_Write("Au3Int must be compiled to build associations." & @CRLF)
                    ContinueLoop
                EndIf

                RegRead("HKCR\.au3", "")
                If Not @error Then
                    _Console_Write("AutoIt3 Scripts are already associated with a program." & @CRLF)
                    ContinueLoop
                EndIf
                _Au3Int_Install(True)
            Case "uninstall"
                If RegRead("HKCR\.au3", "") = "Au3IntTempScript" Then
                    _Au3Int_Install(False)
                Else
                    _Console_Write("AutoIt3 Scripts are not associated with the interpreter." & @CRLF)
                EndIf
            Case "sciteinfo"
                _Au3Int_SciTEInfo()
            Case "@error", "error"
                _Console_Write($error & @CRLF)
            Case "@extended", "extended"
                _Console_Write($extended & @CRLF)
            Case "resetvars", "clv"
                $sCode = ""
                Return True
            Case "reset", "clear", "clr", "cls", "cmd cls"
                $sCode = ""
                If Not _Au3Int_Clr() Then _
                        _Console_Write("Error clearing the console. Code: " & @error & @CRLF)
            Case "help", "?", "hlp"
                ; Give help
                If Not FileExists("Au3Int.chm") Then
                    _Console_Write("Cannot find 'Au3Int.chm' in the program directory." & @CRLF)
                    ContinueLoop
                EndIf

                ShellExecute("Au3Int.chm")
            Case "code"
                _Au3Int_RunCode()
            Case "exit", "close"
                _Au3Int_OnExitProc()
                Return False
            Case Else
                ; Line continuations allowed
                While StringRight($sInput, 1) = "_"
                    _Console_Write("        > ")
                    $sInput = StringTrimRight($sInput, 1) & _Au3Int_Read()
                WEnd

                ; Strip comments.
                Local $sInStr = ""
                For $i = 1 To StringLen($sInput)
                    Switch StringMid($sInput, $i, 1)
                        Case """"
                            If $sInStr = "" Then
                                $sInStr = """"
                            ElseIf $sInStr = """" Then
                                $sInStr = ""
                            EndIf
                        Case "'"
                            If $sInStr = "" Then
                                $sInStr = "'"
                            ElseIf $sInStr = "'" Then
                                $sInStr = ""
                            EndIf
                        Case ";"
                            If $sInStr = "" Then
                                $sInput = StringLeft($sInput, $i)
                                ExitLoop
                            EndIf
                    EndSwitch
                Next
                $sInStr = 0

                $sInput = StringStripWS($sInput, 3)

                Switch StringLower(StringStripWS(StringLeft($sInput, StringInStr($sInput, " ")), 3))
                    Case "cap"
                        $sInput = StringStripWS(StringTrimLEft($sInput, 3), 3)
                        If Not StringIsInt($sInput) Then
                            _Console_Write("Expected an integer to be used to limit output." & @CRLF)
                        Else
                            $iLimit = Int($sInput)
                            _Console_Write("Cap set to " & $iLimit & @CRLF)
                        EndIf
                        ContinueLoop
                    Case "cmd"
                        $sInput = StringStripWS(StringTrimLeft($sInput, 4), 3)

                        RunWait(@ComSpec & " /c " & $sInput)
                        ContinueLoop
                    Case "redim"
                        $sInput = StringStripWS(StringTrimLeft($sInput, 6), 3)

                        If StringLeft($sInput, 1) <> "$" Then
                            _Console_Write("Error parsing ReDim statement. Expected '$'." & @CRLF)
                            ContinueLoop
                        EndIf

                        $sInput = StringTrimLeft($sInput, 1)

                        If Not StringInStr($sInput, "[") Then
                            _Console_Write("Error parsing ReDim statement. Expected '['." & @CRLF)
                            ContinueLoop
                        EndIf

                        Local $asInd = StringTrimLeft($sInput, StringInStr($sInput, "[") - 1) ; array dimensions, ie [1][2][3]
                        Local $sFinal = "", $sTemp
                        For $j = 1 To StringLen($asInd)
                            $sTemp = _Au3Int_ArrayParse($asInd, $j)
                            $j = @extended
                            $sTemp = Execute($sTemp)
                            $sFinal &= "[" & $sTemp & "]"
                            If @error And $sTemp = "" Then
                                _Console_Write("Error in array statement. '" & $sTemp & "' does not evaluate to a valid number." & @CRLF)
                                ContinueLoop 2
                            EndIf
                        Next
                        Local $sVar = StringLeft($sInput, StringInStr($sInput, "[") - 1)
                        $asInd = StringMid($sFinal, 2, StringLen($sFinal) - 2)
                        $asInd = StringSplit($asInd, "][", 1)

                        $sTemp = 0
                        $sFinal = 0

                        If Not IsDeclared($sVar) Then
                            _Console_Write("Error in ReDim statement. Variable '" & $sVar & "' is not declared." & @CRLF)
                            ContinueLoop
                        EndIf

                        Local $aVar = Eval($sVar)

                        If Not IsArray($aVar) Then
                            _Console_Write("Error in ReDim statement. Variable '" & $sVar & "' is not an array." & @CRLF)
                            ContinueLoop
                        EndIf

                        If UBound($aVar, 0) <> $asInd[0] Then
                            _Console_Write("Error in ReDim statement. '" & $sVar & "' has " & UBound($aVar, 0) & " dimensions, attempted to ReDim with " & $asInd[0] & "." & @CRLF)
                            ContinueLoop
                        EndIf

                        For $i = 1 To $asInd[0]
                            If Not StringIsInt($asInd[$i]) Then
                                _Console_Write("Error in ReDim statement. Dimension " & $i & " ('" & $asInd[$i] & "') is not a number." & @CRLF)
                                ContinueLoop 2
                            EndIf
                            $asInd[$i] = Int($asInd[$i])
                            If $asInd[$i] < 1 Then
                                _Console_Write("Error in ReDim statement. Dimension " & $i & " ('" & $asInd[$i] & "') is less than one." & @CRLF)
                                ContinueLoop 2
                            EndIf
                        Next

                        Switch $asInd[0]
                            Case 1
                                ReDim $aVar[$asInd[1]]
                            Case 2
                                ReDim $aVar[$asInd[1]][$asInd[2]]
                            Case 3
                                ReDim $aVar[$asInd[1]][$asInd[2]][$asInd[3]]
                            Case 4
                                ReDim $aVar[$asInd[1]][$asInd[2]][$asInd[3]][$asInd[4]]
                            Case 5
                                ReDim $aVar[$asInd[1]][$asInd[2]][$asInd[3]][$asInd[4]][$asInd[5]]
                            Case 6
                                ReDim $aVar[$asInd[1]][$asInd[2]][$asInd[3]][$asInd[4]][$asInd[5]][$asInd[6]]
                            Case Else
                                _Console_Write("Error in ReDim statement. The interpreter supports a maximum of 6 dimensions." & @CRLF)
                                ContinueLoop
                        EndSwitch

                        Assign($sVar, $aVar)
                        _Au3Int_PrintVar($aVar, "", $iPrint)

                        $asInd = 0
                        $sVar = 0
                        $aVar = 0

                        ContinueLoop
                    Case "local", "global", "dim", "static"
                        $sInput = StringStripWS(StringTrimLeft($sInput, StringInStr($sInput, " ")), 3)

                        Local $asVars = _Au3Int_CommaSplit($sInput), $sData

                        For $i = 1 To $asVars[0]
                            $asVars[$i] = StringStripWS($asVars[$i], 3)

                            If Not _Au3Int_GetOp($asVars[$i], "=") Then
                                $sVar = StringStripWS($asVars[$i], 3)
                                $sData = ""
                            Else
                                $sData = StringStripWS(StringMid($asVars[$i], _Au3Int_GetOp($asVars[$i], "=") + 1), 3)
                                $sVar = StringStripWS(StringMid($asVars[$i], 1, _Au3Int_GetOp($asVars[$i], "=") - 1), 3)
                            EndIf

                            If StringLeft($sVar, 1) <> "$" Then
                                _Console_Write("Error parsing variable declaration: " & $i & ", expected '$'." & @CRLF)
                                ContinueLoop
                            Else
                                $sVar = StringTrimLeft($sVar, 1)
                            EndIf

                            If StringInStr($sVar, "[") Then ; Array
                                Local $asInd = StringTrimLeft($sVar, StringInStr($sVar, "[") - 1) ; array dimensions, ie [1][2][3]
                                Local $sFinal = "", $sTemp
                                For $j = 1 To StringLen($asInd)
                                    $sTemp = _Au3Int_ArrayParse($asInd, $j)
                                    $j = @extended
                                    $sTemp = Execute($sTemp)
                                    If @error And $sTemp = "" Then
                                        _Console_Write("Error in array statement. '" & $sTemp & "' does not evaluate to a valid number." & @CRLF)
                                        ContinueLoop 3
                                    EndIf
                                    $sFinal &= "[" & $sTemp & "]"
                                Next

                                $sVar = StringLeft($sVar, StringInStr($sVar, "[") - 1) ; var without leading $
                                $asInd = StringMid($sFinal, 2, StringLen($sFinal) - 2) ; strip outside [ ]
                                $asInd = StringSplit($asInd, "][", 1)

                                $sTemp = 0
                                $sFinal = 0

                                For $j = 1 To $asInd[0]
                                    $asInd[$j] = Execute($asInd[$j])
                                    If Not StringIsInt($asInd[$j]) Then
                                        _Console_Write("Error in array declaration. Dimension " & $j & " ('" & $asInd[$j] & "') is not a number." & @CRLF)
                                        ContinueLoop 2
                                    EndIf
                                    $asInd[$j] = Int($asInd[$j])
                                    If $asInd[$j] < 1 Then
                                        _Console_Write("Error in array declaration. Dimension " & $j & " ('" & $asInd[$j] & "') is less than one." & @CRLF)
                                        ContinueLoop 2
                                    EndIf
                                Next

                                Local $aVar = _Au3Int_CreateArray($asInd)

                                ; Thanks to Wraithdu for the assignment code :)
                                If $sData <> "" Then
                                    ; Data checking
                                    $sData = StringStripWS($sData, 3)
                                    If StringLeft($sData, 1) <> "[" Then
                                        _Console_Write("Error in array declaration. Expected opening bracket ('[') in data." & @CRLF)
                                        ContinueLoop
                                    EndIf

                                    If StringRight($sData, 1) <> "]" Then
                                        _Console_Write("Error in array declaration. Expected closing bracket (']') to end data." & @CRLF)
                                        ContinueLoop
                                    EndIf

                                    ; init counter array
                                    Local $aDim[UBound($aVar, 0) + 1], $vTmp
                                    $aDim[0] = UBound($aVar, 0)

                                    For $n = 1 To $aDim[0]
                                        $aDim[$n] = UBound($aVar, $n) - 1
                                    Next

                                    Local $aTmp = $aDim
                                    ; assign values
                                    While 1
                                        $vTmp = $sData
                                        ; loop through to break down the array
                                        For $n = 1 To UBound($aTmp) - 1
                                            $vTmp = _Au3Int_GetArrayElem($vTmp, Number($aTmp[$n]))
                                        Next
                                        $vTmp = Execute($vTmp)

                                        _Au3Int_AssignArray($aVar, $aTmp, $vTmp)
                                        If @error Then ContinueLoop 2

                                        ; next element
                                        For $n = $aDim[0] To 1 Step -1
                                            ; decrement last element
                                            $aTmp[$n] -= 1
                                            If $n = 1 And $aTmp[$n] < 0 Then
                                                ; DONE
                                                ExitLoop 2
                                            ElseIf $aTmp[$n] < 0 Then
                                                $aTmp[$n] = $aDim[$n] ; reset this element
                                                ; move left one element
                                                ; continue
                                            Else
                                                ; got next element
                                                ExitLoop
                                            EndIf
                                        Next
                                    WEnd
                                EndIf
                                Assign($sVar, $aVar, 1)

                                _Au3Int_PrintVar($aVar, "", $iPrint)

                                $asInd = 0
                                $aVar = 0
                                $vTmp = 0
                                $aTmp = 0
                                $aDim = 0
                            ElseIf $sData <> "" Then
                                ; only assign data to non-array variables
                                $sData = Execute($sData)

                                If @error And ($sData = "") Then
                                    _Console_Write("Error parsing variable declaration: " & $i & ", Data is incorrect: '" & $sData & "'." & @CRLF)
                                Else
                                    If IsDeclared($sVar) Then _
                                            _Console_Write("Warning on variable declaration: " & $i & ", Variable is already declared. (re-assigned)" & @CRLF)

                                    If Assign($sVar, $sData, 1) = 0 Then
                                        _Console_Write("Error parsing variable declaration: " & $i & ", Error assigning variable." & @CRLF)
                                    Else
                                        _Au3Int_PrintVar($sData, "", $iPrint)
                                    EndIf
                                EndIf
                            EndIf
                        Next

                        $sVar = 0
                        $asVars = 0
                        $sData = 0

                        $sCode &= $s__InternalInputCopy & @CRLF
                        ContinueLoop
                    Case "func"
                        _Console_Write("You'll need to try out the new beta V2 Au3Int to define functions..." & @CRLF)
                        ContinueLoop
                    Case "if"
                        If StringRight($sInput, 4) = "Then" Then
                            _Console_Write("If test not ended. Would return " & (Execute(StringMid($sInput, 3, StringLen($sInput) - 7)) = True) & "." & @CRLF)
                            ContinueLoop
                        Else
                            Local $sInStr = ""

                            For $i = 1 To StringLen($sInput)
                                Switch StringMid($sInput, $i, 1)
                                    Case """"
                                        If $sInStr = "" Then
                                            $sInStr = """"
                                        ElseIf $sInStr = """" Then
                                            $sInStr = ""
                                        EndIf
                                    Case "'"
                                        If $sInStr = "" Then
                                            $sInStr = "'"
                                        ElseIf $sInStr = "'" Then
                                            $sInStr = ""
                                        EndIf
                                    Case Else
                                        If $sInStr = "" And StringMid($sInput, $i, 4) = "Then" Then
                                            Local $vResult = Execute(StringMid($sInput, 3, $i - 4))
                                            If @error And $vResult = "" Then
                                                _Console_Write("Invalid IF statement. Unable to execute statement code." & @CRLF)
                                                ContinueLoop 2
                                            EndIf
                                            If $vResult Then
                                                $sInput = StringTrimLeft($sInput, $i + 4)
                                                $i = -1
                                                $vResult = 0
                                                ExitLoop ; We let the interpreter deal with it :)
                                            Else
                                                _Console_Write("If test returned FALSE." & @CRLF)
                                                $sInStr = 0
                                                $vResult = 0
                                                ContinueLoop 2
                                            EndIf
                                        EndIf
                                EndSwitch
                            Next

                            $sInStr = 0

                            If $i <> -1 Then
                                _Console_Write("IF has no matching THEN." & @CRLF)
                                ContinueLoop
                            EndIf
                        EndIf
                EndSwitch

                If (StringLeft($sInput, 1) = "$") And _Au3Int_GetOp($sInput, "=") Then
                    Local $a = StringRegExp($sInput, "\$(\w+(?:\[.+\])*)\s*([\+\-/\*&^=]?=)\s*(.*)", 3)
                    If @error Then
                        _Console_Write("Error parsing variable operation." & @CRLF)
                        ContinueLoop
                    EndIf

                    $a[2] = _Au3Int_NQReplace($a[2], "@error", $error)
                    $a[2] = _Au3Int_NQReplace($a[2], "@extended", $extended)
                    $a[2] = Execute($a[2])
                    $error = @error
                    $extended = @extended

                    If @error And $a[2] = "" Then
                        _Console_Write("Error parsing variable statement. Error executing data." & @CRLF)
                        ContinueLoop
                    EndIf

                    DllCall($hKERNEL32, "bool", "GetConsoleScreenBufferInfo", _
                            "handle", $hConsoleOutput, _
                            "ptr", DllStructGetPtr($tScreenBufferInfo))
                    If DllStructGetData($tScreenBufferInfo, "CursorPositionX") > 1 Then _Console_Write(@CRLF)

                    If StringInStr($a[0], "[") Then
                        Local $asInd = StringTrimLeft($a[0], StringInStr($a[0], "[") - 1) ; array dimensions, ie [1][2][3]
                        Local $sFinal = "", $sTemp
                        For $j = 1 To StringLen($asInd)
                            $sTemp = _Au3Int_ArrayParse($asInd, $j)
                            $j = @extended
                            $sTemp = Execute($sTemp)
                            $sFinal &= "[" & $sTemp & "]"
                            If @error And $sTemp = "" Then
                                _Console_Write("Error in array statement. '" & $sTemp & "' does not evaluate to a valid number." & @CRLF)
                                ContinueLoop 2
                            EndIf
                        Next
                        Local $sVar = StringLeft($a[0], StringInStr($a[0], "[") - 1) ; var without leading $
                        $asInd = StringMid($sFinal, 2, StringLen($sFinal) - 2) ; strip outside [ ]
                        $asInd = StringSplit($asInd, "][", 1)

                        $sFinal = 0
                        $sTemp = 0

                        If Not IsDeclared($sVar) Then
                            _Console_Write("Error in array statement. Variable '" & $sVar & "' is not declared." & @CRLF)
                            ContinueLoop
                        EndIf

                        $aVar = Eval($sVar)

                        If Not IsArray($aVar) Then
                            _Console_Write("Error in array statement. Variable '" & $sVar & "' is not an array." & @CRLF)
                            ContinueLoop
                        ElseIf UBound($aVar, 0) <> $asInd[0] Then
                            _Console_Write("Error in array statement. '" & $sVar & "' has " & UBound($aVar, 0) & " dimensions, attempted to access with " & $asInd[0] & "." & @CRLF)
                            ContinueLoop
                        EndIf

                        For $i = 1 To $asInd[0]
                            If Not StringIsInt($asInd[$i]) Then
                                _Console_Write("Error in array statement. Dimension " & $i & " ('" & $asInd[$i] & "') is not a number." & @CRLF)
                                ContinueLoop 2
                            EndIf
                            $asInd[$i] = Int($asInd[$i])
                            If $asInd[$i] < 0 Then
                                _Console_Write("Error in array statement. Dimension " & $i & " ('" & $asInd[$i] & "') is less than zero." & @CRLF)
                                ContinueLoop 2
                            EndIf
                            If $asInd[$i] > UBound($aVar, $i) - 1 Then
                                _Console_Write("Error in array statement. Dimension " & $i & " ('" & $asInd[$i] & "') is outside the bounds of the array dimension ('" & (UBound($aVar, $i) - 1) & "')." & @CRLF)
                                ContinueLoop 2
                            EndIf
                        Next

                        Local $vVal = _Au3Int_EvalArray($aVar, $asInd)
                        If @error Then ContinueLoop

                        Switch $a[1]
                            Case "="
                                _Console_Write("Obscure instruction." & @CRLF)
                                While 1
                                    _Console_Write("Do you want to re-assign '" & $a[0] & "'? y/n ")
                                    $sInput = _Au3Int_Read()
                                    If $sInput = "y" Then
                                        $vVal = $a[2]
                                        ExitLoop
                                    ElseIf $sInput = "n" Then
                                        If $vVal = $a[2] Then
                                            _Console_Write("= > True" & @CRLF)
                                        Else
                                            _Console_Write("= > False" & @CRLF)
                                        EndIf

                                        ContinueLoop 2
                                    ElseIf $sInput = "exit" Then
                                        Exit
                                    ElseIf $sInput = "end" Then
                                        ContinueLoop 2
                                    EndIf
                                WEnd
                            Case "=="
                                If $vVal == $a[2] Then
                                    _Console_Write("=> True" & @CRLF)
                                Else
                                    _Console_Write("=> False" & @CRLF)
                                EndIf

                                ContinueLoop
                            Case ">="
                                If $vVal >= $a[2] Then
                                    _Console_Write("=> True" & @CRLF)
                                Else
                                    _Console_Write("=> False" & @CRLF)
                                EndIf

                                ContinueLoop
                            Case "<="
                                If $vVal <= $a[2] Then
                                    _Console_Write("=> True" & @CRLF)
                                Else
                                    _Console_Write("=> False" & @CRLF)
                                EndIf

                                ContinueLoop
                            Case "*="
                                $vVal *= $a[2]
                            Case "/="
                                $vVal /= $a[2]
                            Case "-="
                                $vVal -= $a[2]
                            Case "+="
                                $vVal += $a[2]
                            Case "&="
                                $vVal &= $a[2]
                        EndSwitch

                        ; Assign the new value
                        _Au3Int_AssignArray($aVar, $asInd, $vVal)
                        If @error Then ContinueLoop

                        Assign($sVar, $aVar)
                        _Au3Int_PrintVar($vVal, "", $iPrint)

                        $a = 0
                        $sVar = 0
                        $aVar = 0
                        $vVal = 0
                        $asInd = 0

                        ContinueLoop
                    EndIf

                    If Not IsDeclared($a[0]) Then
                        If $a[1] <> "=" Then
                            _Console_Write("Variable: '" & $a[0] & "' does not exist." & @CRLF)
                            ContinueLoop
                        EndIf

                        If Assign($a[0], $a[2], 1) = 0 Then _
                                _Console_Write("Error parsing variable declaration. Error assigning variable." & @CRLF)

                        _Au3Int_PrintVar(Eval($a[0]), "", $iPrint)

                        $a = 0

                        $sCode &= $s__InternalInputCopy & @CRLF
                        ContinueLoop
                    EndIf

                    Switch $a[1]
                        Case "="
                            _Console_Write("Obscure instruction." & @CRLF)
                            While 1
                                _Console_Write("Do you want to re-assign '" & $a[0] & "'? y/n ")
                                $sInput = StringStripWS(_Au3Int_Read(), 3)
                                If $sInput = "y" Then
                                    If Assign($a[0], $a[2], 1) = 0 Then _
                                            _Console_Write("Error parsing variable declaration. Error assigning variable." & @CRLF)

                                    _Au3Int_PrintVar(Eval($a[0]), "", $iPrint)
                                    $sCode &= $s__InternalInputCopy & @CRLF

                                    $a = 0

                                    ContinueLoop 2
                                ElseIf $sInput = "n" Then
                                    If Eval($a[0]) = $a[2] Then
                                        _Console_Write("=> True" & @CRLF)
                                    Else
                                        _Console_Write("=> False" & @CRLF)
                                    EndIf

                                    $sCode &= $s__InternalInputCopy & @CRLF

                                    $a = 0

                                    ContinueLoop 2
                                ElseIf $sInput = "exit" Then
                                    Exit
                                ElseIf $sInput = "end" Then
                                    $a = 0

                                    ContinueLoop 2
                                EndIf
                            WEnd
                        Case "+=", "-=", "*=", "/=", "&="
                            If $a[1] = "&=" Then
                                Assign($a[0], Eval($a[0]) & $a[2], 1)
                            Else
                                Assign($a[0], Execute(Eval($a[0]) & StringLeft($a[1], 1) & $a[2]), 1)
                            EndIf

                            _Au3Int_PrintVar(Eval($a[0]), "", $iPrint)
                            $sCode &= $s__InternalInputCopy & @CRLF

                            $a = 0
                            ContinueLoop
                        Case "=="
                            If Eval($a[0]) = $a[2] Then
                                _Console_Write("= > True" & @CRLF)
                            Else
                                _Console_Write("= > False" & @CRLF)
                            EndIf

                            $sCode &= $s__InternalInputCopy & @CRLF

                            $a = 0
                            ContinueLoop
                    EndSwitch
                EndIf

                ; Execute
                $sInput = _Au3Int_NQReplace($sInput, "@error", $error)
                $sInput = _Au3Int_NQReplace($sInput, "@extended", $extended)
                $sInput = Execute($sInput)
                $error = @error
                $extended = @extended

                DllCall($hKERNEL32, "bool", "GetConsoleScreenBufferInfo", _
                        "handle", $hConsoleOutput, _
                        "ptr", DllStructGetPtr($tScreenBufferInfo))
                If DllStructGetData($tScreenBufferInfo, "CursorPositionX") > 1 Then _Console_Write(@CRLF)

                If $error And $sInput = "" Then
                    _Console_Write("= > Error: ")

                    Local $iPid = Run(FileGetShortName(@AutoItExe) & " /ErrorStdOut /AutoIt3ExecuteLine """ & _
                            StringReplace($s__InternalInputCopy, '"', '""') & """", @ScriptDir, Default, 8)
                    Local $sText = ""

                    While 1
                        $sText &= StdoutRead($iPid)
                        If @error Then ExitLoop
                        Sleep(10)
                    WEnd

                    $sText = StringMid($sText, StringInStr($sText, "==>") + 4)
                    If $sText = "" Then $sText = "Unable to retrieve extended error information."

                    $sText = StringStripWS($sText, 3)
                    If StringRight($sText, 1) = ":" Then $sText = StringTrimRight($sText, 1)

                    _Console_Write(StringStripWS($sText, 3) & @CRLF)

                    $sText = 0
                    $iPid = 0
                Else
                    _Au3Int_PrintVar($sInput, "", $iPrint)
                    $sCode &= $s__InternalInputCopy & @CRLF
                EndIf
        EndSwitch
    WEnd

    Return False
EndFunc   ;==>_Au3Int_Proc





Func _Console_FlushInputBuffer()
    Local $aResult = DllCall($hKERNEL32, "bool", "FlushConsoleInputBuffer", "handle", $hConsoleInput)
    If @error Then Return SetError(@error, @extended, False)

    Return $aResult[0] <> 0
EndFunc   ;==>_Console_FlushInputBuffer





Func _Au3Int_Read()
    Local $sRet = "", $sTemp

    While 1
        $sTemp = _Console_ReadConsole($hConsoleInput, 1)
        If $sTemp = @CR Then ExitLoop
        $sRet &= $sTemp
    WEnd

    Return $sRet
EndFunc   ;==>_Au3Int_Read





Func _Console_ReadConsole($hConsoleInput, $nNumberOfCharsToRead)
    Local $tBuffer, $aResult

    $tBuffer = DllStructCreate("char[" & ($nNumberOfCharsToRead + 1) & "]")

    $aResult = DllCall($hKERNEL32, "bool", "ReadConsoleA", _
            "handle", $hConsoleInput, _
            "ptr", DllStructGetPtr($tBuffer), _
            "dword", $nNumberOfCharsToRead, _
            "dword*", 0, _
            "ptr", 0)
    If @error Or (Not $aResult[0]) Then Return SetError(@error, @extended, "")

    Return SetExtended($aResult[4], DllStructGetData($tBuffer, 1))
EndFunc   ;==>_Console_ReadConsole

Now another question I had regarding what Pallindrome had stated above about storing variables within the registry.

Does this work the same way as it does for cmd?

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\Session Manager\Environment

Would we store them in a new key and would this be a temporary thing that cleans it self each time the script

exits, or perhaps a switch for creating global variables that maintain even after exit?

I have also been doing research on creating ini files to store variables, but I just do not like this idea as much.

I see how this will work.

I am going to post everything that I am learning so that anyone reading this if they want to or see me doing something wrong can guide me in a more sufficient manner.

So for my testing purposes when working with an ini file I basically took arguments from the command line passed to the au3 script and stored their values in the ini.

Then inside the same script when I ran into my make shift echo command it stored the command line raw whole string into a variable which was parsed with StringSplit when it ran into a variable which was defined like it is in Autoit $Var and then split by a white space.

It would read from the ini file its corresponding value.

This to me is my understanding of using the ini.

Am I correct in this approach?

Again I thank those helping me very much your guidance is very much appreciated.


"You're not smart enough for me to open my inbox, so stop sending me mail."

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0