Jump to content

Read out all functions and a following variable into an array.


Recommended Posts

Hi Forum.

EDIT because of new needs...:

I want to read out the name of all functions and one variable in it into an array.

for example:

AutoIT:

func example1()
$description = "The first example"
endfunc
func example2()
$description = "The second example"
endfunc

$array[2][2]

$array[0][0] = "example1()"

$array[0][1] = "The first example"

$array[1][0] = "example2()"

$array[1][1] = "The second example"

1. There's a script with functions.

2. There's a script the GUI use to know what to do..

3. There's a GUI script.

.... and there are alot other scripts...

Someone writes a new function in the 1. script. (nothing more only in script 1.)

The script 3. is there to show all functions of script 1. to choose and let a choice run.

To show the existing functions it starts script 2. which returns all functions (and a describing variable) in an array to script 3. which shows them.

The function must only be written and is automatically announced.

clear? can someone help me?

thx

Spenhouet

Edited by Spenhouet
Link to comment
Share on other sites

Hi Spenhouet,

can you show us what you've got so far?

I would loop through your code line for line, extract the function name and from the following lines the first variable.

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Read in the file, and run this:

$atest = StringRegExp ( $sString,"(?i)(?m:^|n)s*Funcs+(w+)s*(|.*$desctiption.*",3 )

*Note, used the function regular expression from George Gedye's PCRE Toolkit

Then you can loop through, where the loop steps 2...that way, $i = Function name, and $i+1 of the array is = description

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

can you show us what you've got so far?

I would loop through your code line for line, extract the function name and from the following lines the first variable.

Sounds good. But i found nothing to loop through the code...and nothing to get the following variable.

Any idea?

Read in the file, and run this:

$atest = StringRegExp ( $sString,"(?i)(?m:^|n)s*Funcs+(w+)s*(|.*$desctiption.*",3 )

*Note, used the function regular expression from George Gedye's PCRE Toolkit

Then you can loop through, where the loop steps 2...that way, $i = Function name, and $i+1 of the array is = description

I musst admit that i don't understande anything... what does all this ?i)?m:1|n.... thing mean? and where do i get $sString from...?
Link to comment
Share on other sites

Spenhouet,

there are several ways to loop through a file line for line.

You can either use FilereadLine or _FileReadToArray ... Just look up the functions in the help file.

Use StringInStr() to find strings. Or use what jdelaney wrote: Regular expressions.

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Spenhouet,

there are several ways to loop through a file line for line.

You can either use FilereadLine or _FileReadToArray ... Just look up the functions in the help file.

Use StringInStr() to find strings. Or use what jdelaney wrote: Regular expressions.

The Problem is that i don't want to get it out of a other file. My Code which saves the function name and the variable should be in the same Script as the functions...

And everytime this script runs, it saves the tests to a xml file.

So i need a command that search in the own code...

you say i shoud use the help.. but i did and found nothing.

Link to comment
Share on other sites

If you are using ScITE4AutoIt ( Link ) you can open the helpfile by pressing F1.

use the search or index function of the helpfile.

So just to understand you problem correctly: you want to write some sort of a logfile, right?

As far as I know (and that's not much ;) there is no way to tell what functions and variables are in the script.

If you want to debug your script you need to add some code to every function.

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

If you are using ScITE4AutoIt ( Link ) you can open the helpfile by pressing F1.

use the search or index function of the helpfile.

So just to understand you problem correctly: you want to write some sort of a logfile, right?

As far as I know (and that's not much ;) there is no way to tell what functions and variables are in the script.

If you want to debug your script you need to add some code to every function.

haha year i know... xD im newbie in AutoIT but not a noob :)

And like i said... i didn't found something in the help :) -> year i know clearly how it works.. ^^

And no you don't understand it correctly.

My goal is to announce a knew writen function to another AutoIT script.

A log file is also comming but not jet.

But i have no presentable code...because i have no idea to start this action jet..

Link to comment
Share on other sites

I stil don't get what you're trying to do.... ;)

Ok, i try to explain.

I want to read out the name of all functions and one variable in it into an array.

for example:

AutoIT:

func example1()
$description = "The first example"
endfunc
func example2()
$description = "The second example"
endfunc

$array[2][2]

$array[0][0] = "example1()"

$array[0][1] = "The first example"

$array[1][0] = "example2()"

$array[1][1] = "The second example"

1. There's a script with functions.

2. There's a script the GUI use to know what to do..

3. There's a GUI script.

.... and there are alot other scripts...

Someone writes a new function in the 1. script. (nothing more only in script 1.)

The script 3. is there to show all functions of script 1. to choose and let a choice run.

To show the existing functions it starts script 2. which returns all functions (and a describing variable) in an array to script 3. which shows them.

The function must only be written and is automatically announced.

clear? can someone help me?

thx

Spenhouet

First post is edit.

Edited by Spenhouet
Link to comment
Share on other sites

Perform a FileRead ( yes, of your script's file...or even make a copy of the script to a seperate file durring run time, and read that in) into the variable = $sString

$atest = StringRegExp ( $sString,"(?i)(?m:^|n)s*Funcs+(w+)s*(|.*$desctiption.*",3 )

Then loop through the array that is returned like I mentioned above.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

I assume that the "other scripts" are uncompiled, right?

I also assume that you have a list of filenames of the other script.

Try a code like this:

_FileReadToArray("path", $aContents)
For $i = 1 To $a_contents[0] - 1
    $iPos1 = StringInStr($aContents[$i], "Func ")
    If  $iPos1 > 0 Then
        $iPos2 = StringInStr($aContents[$i], "(")
        $sFunc = StringMid($a_contents[$i], $iPos1, $iPos2 - $iPos2)
        $iPos3 = StringInStr($aContents[$i + 1], "$description=")
        If $iPos3 > 0 Then
            $sDescription = StringMid($aContents[$i+1], $iPos3 + 13)
        Else
            $sDescription = 0
        EndIf
        ;Add Lines to your array
    Next
Next

I know this could be done way easier with PCRE but I'm not good at it. ;)

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Link to comment
Share on other sites

Perform a FileRead ( yes, of your script's file...or even make a copy of the script to a seperate file durring run time, and read that in) into the variable = $sString

$atest = StringRegExp ( $sString,"(?i)(?m:^|n)s*Funcs+(w+)s*(|.*$desctiption.*",3 )

Then loop through the array that is returned like I mentioned above.

Now i understood what you are talking about^^ -.-

I have never seen a regular expression befor.....

I understand what it do but can't get it done by my own... -.-

The thing with Func works realy fine, but the description is not like i want it to be.

$description = "blablabla"

I only need the blablabla. It would be the best if it's also in a new column of the array.

You would realy help me if you can write that for me.

Edited by Spenhouet
Link to comment
Share on other sites

durring the loop, do some stringinstring, to get a count after the '=', then you can do a stringright of the (stringlen - stringinstring of the = )

Let me know if that doesn't make sense ;)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

#include <Array.au3>
$a = _GetFunctionsAndDescriptionVarFromAutoItScriptSourceAndPutThemInA2DArrayPerformMatchingNowPleaseThankYouOhAndJustSoYouKnowThisFunctionReturnsFalseIfItFinds0MatchesAndExpectsTheFirstParameterToBeAutoItScript(FileRead(@ScriptFullPath))
_ArrayDisplay($a)
Func _GetFunctionsAndDescriptionVarFromAutoItScriptSourceAndPutThemInA2DArrayPerformMatchingNowPleaseThankYouOhAndJustSoYouKnowThisFunctionReturnsFalseIfItFinds0MatchesAndExpectsTheFirstParameterToBeAutoItScript($au3source)
    Local Const $description = "It's all in the name"
    Local $aArray = StringRegExp($au3source, "(?im)funch+(w+)h*(.*$s*(?:(?:dim|global|local)?(?:h+const)?)h*$descriptionh*=h*""([^""]+)""", 4)
    If @error Then Return SetError(1, 0, False)
    Local $aSubArray, $iUBound = UBound($aArray), $aReturn[$iUBound][2] = [[$iUBound]]
    For $i = 0 To $iUBound - 1
        $aSubArray = $aArray[$i]
        $aReturn[$i][0] = $aSubArray[1]
        $aReturn[$i][1] = $aSubArray[2]
    Next
    Return $aReturn
EndFunc   ;==>_GetFunctionsAndDescriptionVarFromAutoItScriptSourceAndPutThemInA2DArrayPerformMatchingNowPleaseThankYouOhAndJustSoYouKnowThisFunctionReturnsFalseIfItFinds0MatchesAndExpectsTheFirstParameterToBeAutoItScript

Edited by Robjong
Link to comment
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
 Share

×
×
  • Create New...