Sign in to follow this  
Followers 0
Skitty

RegExp - SciTE config, getting the platform specific values

6 posts in this topic

#1 ·  Posted (edited)

I can usually get by with regexp, but not this time.

In scite global properties, there's an area where this is present~

if PLAT_WINNT
selection.alpha=30
selection.back=#000000
if PLAT_WIN95
selection.back=#DADADA
if PLAT_GTK
selection.alpha=30
selection.back=#000000
#selection.additional.fore=#0000A0

I want to get the WINNT ones specifically.

#include<array.au3>
$Test = ''
$Read = FileRead(RegRead("HKEY_LOCAL_MACHINESOFTWAREAutoIt v3AutoIt", "InstallDir")&"SciTESciTEGlobal.properties")
_GetProperty($Test ,$Read, 'selection.alpha', 0, 0)
ConsoleWrite($Test&@CR)

Func _GetProperty(ByRef $Var ,$Config, $Property, $Which = 0, $Rev = 0)
    Local $Test = StringRegExp($Config, StringReplace($Property, ".", ".") & "=(.*)[rn]", 3)
    _ArrayDisplay($Test)
    If (UBound($Test) > 1) Then
        ;ConsoleWrite($Config)
        Local $Temp = StringRegExp($Config, "WINNT(.*)if", 3)
        MsgBox(0,"",@error)
        _ArrayDisplay($Temp)
        If Not @error Then
            $Temp = StringRegExp($Temp[0], StringReplace($Property, ".", ".") & "=(.*)[rn]", 3)
            _ArrayDisplay($Temp)
        EndIf
    EndIf
    If @error Then Return
    Switch StringLower($Which)
        Case "fore"    ; Foreground color
            $Test = StringRegExp($Test[0], "fore:#(.*?)[,rn]", 3)
        Case "back"    ; Background color
            $Test = StringRegExp($Test[0], "back:#(.*?)[,rn]", 3)
        Case "#"    ; just the color
            $Test = StringRegExp($Test[0], "#(.*?)[,rn]", 3)
    EndSwitch
    If @error Then Return
    ;If $Rev Then $Test[0] = _Rev($Test[0])
    $Var = $Test[0]
    Return
EndFunc   ;==>_GetProperty
Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites



There are several places that you can find the words "if PLAT", will that RegExp get JUST the color settings? Plus, mine doesn't say WIN_NT for more than one setting, most times it's just "if PLAT_WIN"


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I didn't see it that way, good thing you mention it, I guess I'm just trying to get all the style properties from the windows specific ones, and then extract the property value as wanted, still trying to figure this out.


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

If you read through it line-by-line and look for "if PLAT_WINNT" at the start of the line, so that you don't pick up commented out lines, you can use that in a nested If/Then statement to look at the next line for the things you're looking for in the settings.

Do a _FileReadToArray on the properties file, search through each element for "if PLAT_WINNT" and then if you find it, search the next element for the strings you're looking for, if you don't find it, keep searching. Use a nested If comparison for that.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

This is a typical situation where use of the _StringBetween() function to extract all the data between "if PLAT_WINNT" and "if PLAT" makes life easier and then use your own regular expression to split the returned lines as required.

Note:_StringBetween() returns an array.


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If you read through it line-by-line and look for "if PLAT_WINNT" at the start of the line, so that you don't pick up commented out lines, you can use that in a nested If/Then statement to look at the next line for the things you're looking for in the settings.

Do a _FileReadToArray on the properties file, search through each element for "if PLAT_WINNT" and then if you find it, search the next element for the strings you're looking for, if you don't find it, keep searching. Use a nested If comparison for that.

I had that in mind, but I was devoted to do this using regular expression, but now that you mention it, I guess it will be more accurate using that method. Making sure to only retrieve values not commented out and those that have the tab space in them.

This is a typical situation where use of the _StringBetween() function to extract all the data between "if PLAT_WINNT" and "if PLAT" makes life easier and then use your own regular expression to split the returned lines as required.

Note:_StringBetween() returns an array.

If you look into the how that function works, it's basically using regular expression

Also, I found out why the above wasn't working, the "." by default does not match new line (CR LF), adding (?s) changes that behavior.

Thanks for the tips though.

Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

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