michelb2 Posted yesterday at 05:19 AM Posted yesterday at 05:19 AM I use a extended version of iniread for inserting comment and variable in a normal iniread. 1) after a ; all text are ignored. AND 2) ;variable autoit user commence et fini par $ $bdmount$ => $bdmount ;variable autoit native commence et fini par @ @Tempdir@ => @tempdir ;variable systeme native commence et fini par % %path% => %path% EXEMPLES : bdmount="w:" path_log=e:\Mes documents\HCFR\logs\ ;vrai sauf pour bootime où path_log est redéfini à e:\sna10\xfert\ pour ecrire boot_time.log daemon_mount= /l=$bdmount$ "µisoµ" ;en théorie =w ; ici =w: mais seule la 1ere lettre compte ; de plus =w inutile (mount sur le 1er disque virtuel ?) fichier_resultats=@Tempdir@\result.log ; fichier resultats des actions effectuées ""=pas de sauve all is good except "x" ; commentaire" ==>> x" could you help me ? inireadcustom.au3
argumentum Posted yesterday at 05:40 AM Posted yesterday at 05:40 AM Func IniReadOrInit($sFilename, $sSection, $sKey, $sDefault, $iExcludeComments = 1) Local $iErr = 0, $sVal = IniRead($sFilename, $sSection, $sKey, @CRLF) ; IniRead ( "filename", "section", "key", "default" ) If $sVal = @CRLF Then $iErr = Int(Not IniWrite($sFilename, $sSection, $sKey, $sDefault)) ; IniWrite ( "filename", "section", "key", "value" ) $sVal = $sDefault EndIf If $iExcludeComments And StringInStr($sVal, @TAB & ";") Then $sVal = StringStripWS(StringLeft($sVal, StringInStr($sVal, @TAB & ";") - 1), 3) Return SetError($iErr, 0, $sVal) EndFunc ;==>IniReadOrInit This is what I use. @TAB & ";" is not likely to be found by accident. Use that ? Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
michelb2 Posted yesterday at 06:14 AM Author Posted yesterday at 06:14 AM (edited) i use {space x N}; or {tab x N}; indifferentially so i would prefere not to be force to use @TAB & ";" but i think is good $sVal = StringStripWS(StringLeft($sVal, StringInStr($sVal, ";") - 1), 3) Edited yesterday at 06:19 AM by michelb2
michelb2 Posted yesterday at 06:31 AM Author Posted yesterday at 06:31 AM it's better to use if stringregexp($out,";") then $out = StringStripWS(StringLeft($out, StringInStr($out, ";") - 1), 3)
Developers Jos Posted yesterday at 08:05 AM Developers Posted yesterday at 08:05 AM Moved to the appropriate AutoIt General Help and Support forum, as the AutoIt Example Scripts forum very clearly states: Quote Share your cool AutoIt scripts, UDFs and applications with others. Do not post general support questions here, instead use the AutoIt Help and Support forums. Moderation Team SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Nine Posted 23 hours ago Posted 23 hours ago (edited) Here my take on it : expandcollapse popup; From Nine #include <Constants.au3> Local $sText = IniReadEx("Test.ini", "Section", "cle1", Null) ConsoleWrite("[" & $sText & "]" & @CRLF) $sText = IniReadEx("Test.ini", "Section", "cle2") ConsoleWrite("[" & $sText & "]" & @CRLF) $sText = IniReadEx("Test.ini", "Section", "heure") ConsoleWrite("[" & $sText & "]" & @CRLF) $sText = IniReadEx("Test.ini", "Section", "boot") ConsoleWrite("[" & $sText & "]" & @CRLF) $sText = IniReadEx("Test.ini", "Section", "Log") ConsoleWrite("[" & $sText & "]" & @CRLF) $sText = IniReadEx("Test.ini", "Section", "New", "$disk$\%username%\@scriptname@") ConsoleWrite("[" & $sText & "]" & @CRLF) Func IniReadEx($sFileName, $sSection, $sKey, $sDefault = Null) Local $sOut = IniRead($sFileName, $sSection, $sKey, $sDefault) If $sOut == $sDefault Then IniWrite($sFileName, $sSection, $sKey, $sDefault) $sOut = StringRegExpReplace($sOut, "\h*;.*", "") ; comment $sOut = StringRegExpReplace($sOut, '^"(.*?)"$', "$1") ; double-quotes Local $aText = StringRegExp($sOut, '@\w+?@', $STR_REGEXPARRAYGLOBALMATCH) ; autoit macro If Not @error Then For $sMacro In $aText $sOut = StringReplace($sOut, $sMacro, Execute(StringTrimRight($sMacro, 1))) Next EndIf $aText = StringRegExp($sOut, '\$\w+?\$', $STR_REGEXPARRAYGLOBALMATCH) ; other key If Not @error Then For $sSecKey In $aText $sOut = StringReplace($sOut, $sSecKey, IniReadEx($sFileName, $sSection, StringReplace($sSecKey, "$", ""))) Next EndIf $aText = StringRegExp($sOut, "%\w+?%", $STR_REGEXPARRAYGLOBALMATCH) ; environment If Not @error Then For $sEnv In $aText $sOut = StringReplace($sOut, $sEnv, EnvGet(StringReplace($sEnv, "%", ""))) Next EndIf Return $sOut EndFunc ;==>IniReadEx With this ini file : [Section] cle1=test1 ; comment cle2="Test2" ; comment with tab heure=@HOUR@:@MIN@:@SEC@ disk=W: boot=$disk$\test\boot\@username@ Log=%ProgramData%\AutoIt\@username@\log ; plus a comment Edited 22 hours ago by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
argumentum Posted 20 hours ago Posted 20 hours ago (edited) ...at times I make a folder representing "C:\this\here" and since that can not be done as a representation, I name the folder "C;,this,here" because it makes sense to me. Then I figure that this character ";" could be part of a filename. Hence the @tab + ";". I don't like it either, but, how can I make sure ( or less likely ) that the code will not make a mistake 🤷♂️ With the "@tab & ;" I can have an entry like: path=\\share\backups\c;,this,here@TAB; A ";" represents ":" and "," represent "\" as a comment without confusing the code, because is hard to foresee what a user will feel like doing. An inline comment in an ini file was never meant to be there so, get creative PS: When not user editable, I'd use "face delimited fields" ( Chr(1) looks like a face ) but with a user editable, @TAB; is the best I came up with. Do share your brainstorming if you find a nicer way because, I too dislike the solution I came up with. Edit: https://gist.github.com/dk949/88b2652284234f723decaeb84db2576c has good ideas. Edit 2: https://futhark-lang.org/blog/2017-10-10-block-comments-are-a-bad-idea.html sees my point. I think that the common /* comment */ is a good solution 🤔 Edited 20 hours ago by argumentum more Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ioa747 Posted 19 hours ago Posted 19 hours ago (edited) Here is my approach, taking into account @argumentum concerns about using ';' why not use a rarer character ? like: 👉, 💬, 🚩, ⁉, ⚠, ℹ, ♠, ⋮, ⅈ, © Local $sFile = @ScriptDir & "\test2.ini" Local $sMyComment ; Declare a variable to hold the comment ; Read the INI section labelled 'EXEMPLES'. This will return a 2 dimensional array. Local $aArray = IniReadSection($sFile, "EXEMPLES") If Not @error Then For $i = 1 To $aArray[0][0] Local $sResult = IniReadWithComment($sMyComment, $sFile, "EXEMPLES", $aArray[$i][0]) ConsoleWrite($aArray[$i][0] & " = " & $sResult & @CRLF) If $sMyComment Then ConsoleWrite(@TAB & "Comment: " & $sMyComment & @CRLF) Next EndIf Func IniReadWithComment(ByRef $sComment, $filename, $section, $key, $defaut = "") Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand Local $sValue = IniRead($filename, $section, $key, $defaut) Local $sCleanValue, $sRetValue Local $aPart = StringSplit($sValue, "👉", 1) If $aPart[0] = 2 Then $sCleanValue = StringStripWS($aPart[1], 3) $sComment = StringStripWS($aPart[2], 3) $sRetValue = $sCleanValue Else $sRetValue = $aPart[1] EndIf Opt("ExpandEnvStrings", 0) ;0=don't expand, 1=do expand Opt("ExpandVarStrings", 0) ;0=don't expand, 1=do expand Return $sRetValue EndFunc ;==>IniReadWithComment_ByRef test2.ini [EXEMPLES] bdmount="w:" path_log=e:\Mes documents\HCFR\logs\ 👉 vrai sauf pour bootime où path_log est redéfini à e:\sna10\xfert\ pour ecrire boot_time.log daemon_mount= /l=$bdmount$ "µisoµ" 👉 en théorie =w ; ici =w: mais seule la 1ere lettre compte ; de plus =w inutile (mount sur le 1er disque virtuel ?) fichier_resultats=@Tempdir@\result.log 👉 fichier resultats des actions effectuées ""=pas de sauve Time=@HOUR@:@MIN@:@SEC@ 👉 curent time File=$sFile$ 👉 this .ini file SCITE=%SCITE_USERHOME% 👉 On installation this variable is set to "%LOCALAPPDATA%\AutoIt v3\SciTE" for Vista and above and to "%USERPROFILE%\AutoIt v3\SciTE" for WinXP. Edited 11 hours ago by ioa747 add SCITE=%SCITE_USERHOME% I know that I know nothing
argumentum Posted 19 hours ago Posted 19 hours ago 18 minutes ago, ioa747 said: why not use a rarer character ? like: 👉, 💬, 🚩, ⁉, ⚠, ℹ, ♠, ⋮, ⅈ, © if that was the case then my "face delimited(TM)" approach using chr(1) is just as good It would have to be a keyboard character ( yes, I know about Win + "." ) so that a user could add a comment. The C style is widely known and should work. But is a pain to remove the last comment using regex. Local $sString = "Some code here /* first comment */ more code /* second comment */ /* /* last comment */" The AI is stuck and I don't know regex. I can do it with StringInStr() but regex is the challenge ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
michelb2 Posted 6 hours ago Author Posted 6 hours ago @Nine I like your solution ! the only "bad thing" is fault of iniread itself t1=xx yy t2="xx yy" t3=""xx yy"" t1 and t2 report the same thing => xx yy only t3 report "xx yy" ...but i can live with that 🙂
Nine Posted 51 minutes ago Posted 51 minutes ago oh you mean that only 2 double-quotes should result in single double-quotes ? That is quite easy to modify, try it, and come back if can't find a solution. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now