Jump to content

@ Adding conditions


Recommended Posts

Hi,

I want to add any needed conditions to the StringRegExp command so it can pull out only  "File.au3", "WinAPIFiles.au3", "Test.bmp" into the array

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include 'WinAPIFiles.au3'
#include "File.au3"

; Script Start - Add your code below here
Local $bFileInstall = False ; Change to True and ammend the file paths accordingly.

; This will install the file C:\Test.bmp to the script location.
If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp")

$sFile = FileRead(@ScriptFullPath)
$aResults = StringRegExp($sFile, "(?i)(FileInstall\s*|include\s*)(.*)", 3)
_ArrayDisplay($aResults)

Thanks In Advance
Deye

Link to comment
Share on other sites

  • Moderators

@Deye you have been around long enough to know to wait 24 hours before bumping your post. This may be the most important thing in the world to you, but you need to show some patience.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi @Deye.

(?(DEFINE) (?<string>(["'])((?!\2).)*\2))(#include ((?&string))|FileInstall\(((?&string)))

is what I have so far :)

I will test in AutoIt later ;) here's the Github Gist.

Link to comment
Share on other sites

Hi @Deye.

here's what i expect are the solution you want?

#AutoIt3Wrapper_Res_File_Add=C:\Users\me\Desktop\88x31.jpg
#AutoIt3Wrapper_Res_Icon_Add=C:\Users\me\Desktop\logo.ico

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include 'WinAPIFiles.au3'
#include "File.au3"

; Script Start - Add your code below here
Local $bFileInstall = False ; Change to True and ammend the file paths accordingly.

; This will install the file C:\Test.bmp to the script location.
If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp")

$sFile = FileRead(@ScriptFullPath)
$pattern = '(?(DEFINE) (?<string>(["''''])((?!\2).)*\2))(?:#include ((?&string))|FileInstall\(((?&string))|#AutoIt3Wrapper_Res_[a-zA-Z]+_Add=([^\n]+))'
$aResults = StringRegExp($sFile, $pattern, 3)
_ArrayDisplay($aResults)

Dim $aResult[0]

For $i=0 To UBound($aResults)-1
    If StringLen($aResults[$i])>0 Then
        ReDim $aResult[UBound($aResult)+1]
        $aResult[UBound($aResult)-1] = StringRegExpReplace($aResults[$i], '^(["''''])(.*)\1', "$2")
    EndIf
Next

_ArrayDisplay($aResult)

 

Link to comment
Share on other sites

On 7/13/2018 at 2:53 PM, Deye said:

your StringRegExp() doesn't do:

#AutoIt3Wrapper_Res_File_Add=C:\Users\me\Desktop\88x31.jpg, RT_ICON ..

 

(?(DEFINE) (?<string>(["''''])((?!\2).)*\2))(?:#include ((?&string))|FileInstall\(((?&string))|#AutoIt3Wrapper_Res_[a-zA-Z]+_Add=\s*([^\n,]+))

a small update in regards to

#AutoIt3Wrapper_Res_[a-zA-Z]+_Add=

  this should omit text after the comma and allow spaces before the equals sign, just in case.

Link to comment
Share on other sites

Thanks genius257

That is exactly what I tried that worked .;.
now all is left is to include capturing *.dll that are within quotations
In could be : _BASS_FX_Startup(@scriptDir & "\dll\bass_fx.dll") or DllOpen('bass_fx.dll') not  DllOpen($sBassDLL) that's why within quotations ..

Edit: and something set in to ignore lines with "DllCall"


Deye

Edited by Deye
Link to comment
Share on other sites

Hi @Deye

I would say getting strings, that specify dll files, but not within a dllcall would require some post processing.

computation of string concatenation, translation of variables and macros, not to mention translating eval's and executes.

Also you would need to check if an expression is being extended to multi-line, with the underscore character.

A big Regex might be able to collect all the data you need, but i would argue it's the translation of the artifacts above that is the hard part.

Link to comment
Share on other sites

Hi genius257,

This is what I have used for the dll part :
Just for the sake of getting a cleaner output I added in:
|(?m)^.*\QDllCall\E.*\R?(*SKIP)(?!)
As for the rest of few leftovers  if any .. Its just easy to ignore if they aren't pointing to valid existing  ..

used with: |[a-zA-Z]+["''''].*dll\b|
This leaves a quote to the left

StringRegExpReplace($aResults[$i], '^(["''''])(.*)\1', "$2")
I think this wont remove quotes if absent in either ends or something alike ..

btw : Just now, made another update for the au3 (X) Port tool i needed this  for

Thanks

Deye
 

Edited by Deye
Link to comment
Share on other sites

Hi @genius257

actually for the dll part that worked:
|["''''].*dll\b|

My tool is missing this too, was testing out something but forgot to revert  ..

I will want to update the tool again for that and for a few more changes ..
still, what can be a good 1 pattern for only getting:

- the in between parenthesis in lines with #pragma compile 
#pragma compile(Out, myProg.exe)

- along with:
#AutoIt3Wrapper_Outfile=myProg.exe
#AutoIt3Wrapper_Res_Description=
#AutoIt3Wrapper_Res_Fileversion=

Thanks
Deye

Edit: never mind, figured out something ..

 

Edited by Deye
Link to comment
Share on other sites

The question at hand is somewhat different from The question at the OP

To refine:
what can be a pattern that will match and extract "filename & extension" with\without\partial paths
Between any none legal characters like quotes or like "=\Users\me\Desktop\88x31.jpg," skipping:  #include < *.* >
Where I can further customize it  to skip commented lines and other certain phrases 

 

#include <File.au3>
#include "WinAPIShPath.au3"

#AutoIt3Wrapper_Res_File_Add=C:\Users\me\Desktop\88x31.jpg, RT_ICON ..
#AutoIt3Wrapper_Res_Icon_Add=C:\Users\me\Desktop\logo.ico

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include 'WinAPIFiles.au3'
#include "File.au3"

; Script Start - Add your code below here
Local $bFileInstall = False ; Change to True and ammend the file paths accordingly.

; This will install the file C:\Test.bmp to the script location.
If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp")

 $pattern = '(([''"])((?!\2).)*\2)'

Local $sVar = 'Local $aPath[7] = [''\path\file(1).ext'',''c:\path\file.ext'', ''path\file'', ''c:\path\'', ''c:\'', ''file(1).ext'']' & @CRLF

Local $aResults = StringRegExp($sVar, $pattern, 3)
_ArrayDisplay($aResults)

Local $sFileRead = FileRead(@ScriptFullPath)
Local $aResults = StringRegExp($sFileRead, $pattern, 3)
_ArrayDisplay($aResults)

Thanks

Edited by Deye
Link to comment
Share on other sites

Hi @Deye.

So I think you need multiple regular expressions.

To make expression(s) you work with less complicated, I would suggest you do the following:

  • remove all comments from the string you are processing.
  • Match (almost) all strings with RegEx below.
  • Take each match and translate it into a complete string with the Execute command.
  • filter results, depending if result is a a legal path depending on your current file system (NTFS, FAT32, ...).
  • Add those results to the regex matching #include ..., #AutoIt3Wrapper_Res_File_Add=... (where you've stripped the part of the string that is not part of the file path)
  • Do whatever you want with the result

 

Note that this RegEx does not support string escapes in the AutoIt syntax.

(?(DEFINE)(?<string>(["'])((?!\2).)*\2)(?<spacing>[\h]*)(?<macro>[@][A-Za-z]+))(((?&string)|(?&macro))(\h*[&](\h+[_]\h*\n)?\h*(?&string)|(?&macro))?)+

 

Hope this is of some use to you.

Sorry for the response time, I am the process of moving ^^'

 

Edit:

Ofc. my solution does not support methods with string definition either, like:

$a = "this is a" & Mood(1) & "day"
$b = "this is a" & Mood(0) & "day"

Func Mood($good)
    Return $good?'happy':'sad'
EndFunc

 

Edited by genius257
Link to comment
Share on other sites

Thank you @genius257,

you are an excellent guide :thumbsup:
last I tried this is the outcome (will have to do for now  :sweating: until i get back to what i was wanting to with this before ..)

If anyone keen to have a better RegEx practice for this, to demo here, then you are most welcome ..

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         myName

 Script Function:
    Template AutoIt script.

#include "MsgBoxConstants.au3"
#include "StringConstants.au3"


#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#AutoIt3Wrapper_Res_File_Add=C:\Users\me\Desktop\88x31.jpg, RT_ICON .. ;
#AutoIt3Wrapper_Res_Icon_Add=C:\Users\me\Desktop\logo.ico ;

#include <FileConstants.au3>
#include <File.au3>
#include "WinAPIShPath.au3"
#include 'WinAPIFiles.au3' ;

; Script Start - Add your code below here
Local $bFileInstall = False ; Change to True and ammend the file paths accordingly.

; This will install the file C:\Test44.bmp to the script location.
If $bFileInstall Then FileInstall("C:\Test.bmp", @ScriptDir & "\Test.bmp")

$pattern = '(?m)^\s*\Q;\E.*\R?(*SKIP)(?!)|(?m)^\s*#.*\s*\Q<\E.*\R?(*SKIP)(?!)|(?m)^.*\QDllCall\E.*\R?(*SKIP)(?!)|([\w\.(\:\)*\\w]+\w+.\.\w{3})'
Local $sVar = 'Local $aPath[7] = [''\path\file(1).ext'',''c:\path\file.ext.ext.ext'', ''path\file'', ''c:\path\'', ''c:\'', ''..\..\..\file(1).ext'']' & @CRLF

Local $sFileRead = FileRead(@ScriptFullPath)
Local $aResults = StringRegExp($sFileRead, $pattern, 3)
_ArrayDisplay($aResults)

Deye

Edited by Deye
Link to comment
Share on other sites

  • 3 weeks later...

Hi,

Lost my patience and energy with this the last time @ finding a good pattern that finally worked, but couldn't jump back to what i was wanting to do with this yet ..

Now I want to add one more thing:   something that can ignore lines from instance #cs to instance #ce.

 if anyone willing to help\ add\compact .. with last touches that would be really great 

example code @ the newly edited above post

TIA

Deye

Edit :  came up with '(?m)#cs([\s\S]*?)#ce(*SKIP)(?!)'  for now ..

Edited by Deye
Link to comment
Share on other sites

Hi @Deye.

Please note that

Quote

The #comments-start and #comments-end directives can be nested.

So something like this:

(?s)(?(DEFINE)(?<comment>(#comments-start|#cs)((?!#comments-start|#cs|#ce|#comments-end).)*(?&comment)*((?!#comments-start|#cs|#ce|#comments-end).)*(#comments-end|#ce)))(?&comment)

To either remove the comments or check if your other matches are within the comments (if you use flag 1 or 2).

You could try to wrap this group in a negative lookahead, but I have not tested if that would work.

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...