Page 1 of 1

Extending getkey capabilities.

Posted: 20 Mar 2011 21:45
by tiago
I was storing some values in keys and realized that I was quite limited by not having these options. Is anything that can be done, be it via scripting or command enhancements?

getsection = report sections in which a given key is found.
getkeyholder = report keys in which a given value is found.

Observing the existence of some parameters like "[...]" for getsection and "anything before=" (equal sign) for getkeyholder could avoid false positives, I guess.

Re: Extending getkey capabilities.

Posted: 26 Mar 2011 21:05
by tiago
Should I'd expect for this or bump on any time soon?

Re: Extending getkey capabilities.

Posted: 27 Mar 2011 13:59
by admin
No, I'm not interested. Thanks anyway. :)

Re: Extending getkey capabilities.

Posted: 28 Mar 2011 15:11
by tiago
Too bad, I was writing a little databank for files and general notes based on this which me and my team mates could refer to right from inside XYplorer. :(

Re: Extending getkey capabilities.

Posted: 28 Mar 2011 15:32
by Stefan
tiago wrote: getsection = report sections in which a given key is found.
getkeyholder = report keys in which a given value is found.
If you want you can do that by scripting yourself.

Pseudo code:
"_getsection"
global $INI, $KEY
$wholeINI = readfile( $INI )
 For Each Line of $wholeINI
    if instr( "[" ) Then $SectionVar = section name
    if instr( $KEY ) Then MsgBox( $KEY found in $SectionVar ) && Exit


EDIT:

An "_getsection" code could look like:

Code: Select all

// === User settings ===
    $FILE = readfile("<xydata>\XYplorer-01.ini");
    $KEY = "date";  //search for this part before the = equal sign
    
    
// === CODE ===    
    $ARRAY="";

	  // foreach() needs v9.90.0304 or newer
	  //start an loop over each line of whole file:
	  foreach($line, $FILE, "<crlf>")
	  {
		//your code here:
		 if (substr($line, 0, 1) == "[")
			{
				$SECTION = $line;
				//msg $SECTION,1;
			}

		if (strpos($line, $KEY) > -1)
			{
				 $KEYname = gettoken($line, 1, "=");
				 $KEYvalue = gettoken($line, 2, "=");
				 $ARRAY = "$ARRAY$KEY is found in section $SECTION as $KEYname with value: $KEYvalue<crlf>";
			}
	  }
	  //output:
	  text $ARRAY;

/*
 An output fo key "date" looks like:
 
date is found in section [General] as PostfixDate with value: "*-<date yyyymmdd>"
date is found in section [General] as DroppedMessageFormat with value: "<from>_<to>_<subject>_<date yyyy-mm-dd_hh-nn-ss>"
date is found in section [General] as ; Tweak: E.g. <curname><curver , v*>, mod <datem> with value: 
date is found in section [General] as ; Tweak: 'Now' in file dates with value: 
date is found in section [General] as ; Tweak: 'Today' in file dates with value: 
date is found in section [General] as ; Tweak: 'Yesterday' in file dates with value: 
date is found in section [Settings] as SortMixedOnDates with value: 0
date is found in section [Settings] as CheckForUpdates with value: 0
date is found in section [Settings] as RepOFDate with value: 0
date is found in section [Settings] as BackupPreserveItemDates with value: 1
date is found in section [Undo] as DateFormat with value: 1
date is found in section [Report] as InclDate with value: 0
date is found in section [ListDateFormats] as [ListDateFormats] with value: 
date is found in section [Find] as Date with value: 1
date is found in section [Find] as DateRange with value: 0
date is found in section [Find] as DateNum with value: "1"
date is found in section [Find] as DateUnit with value: 3
date is found in section [Find] as DateFrom with value: ""
date is found in section [Find] as DateTo with value: ""
date is found in section [FileAssoc] as 13 with value: |"Append modified date" \;*>::rename "b", "*-<datem yyyymmdd>"
*/

And BTW an code i wanna do anyway sometime:

Code: Select all

// === User settings ===
		 $FILE = readfile("<xydata>\XYplorer-01.ini");
		 $KEY = "tweak";


// === CODE ===
		 $COUNT=0;
		 $ARRAY="";

		  // foreach() needs v9.90.0304 or newer
		  //start an loop over all lines in file:
		  foreach($line, $FILE, "<crlf>")
		  {
			//your code here:
			$COUNT++;
			
			 if (substr($line, 0, 1) == "[")
				{
					 $SECTION = $line;
					 //msg $SECTION,1;
				}

			if ($GetNextLineToo==1)
				{
					 $ARRAY = "$ARRAY$line<crlf>";
					 $GetNextLineToo=0;
				}
			if (strpos($line, $KEY) > -1)
				{
					 $ARRAY = $ARRAY . "<crlf>$SECTION<crlf>Line$COUNT: $line<crlf>";
					 $GetNextLineToo=1;
				}
		  }
		  //output:
		  text $ARRAY;



/*
output look like:


[General]
Line87: ; Tweak: png (default), jpg, bmp, gif, or tif
ImageFromClipFormat=

[General]
Line89: ; Tweak: set label for unit byte
UnitByte=" bytes"

[General]
Line91: ; Tweak: set label for empty folders
FolderEmpty="[Empty]"

[General]
Line93: ; Tweak: E.g. <curname><curver , v*>, mod <datem>
StatusBar3OnFile=""

[General]
Line95: ; Tweak: 'Now' in file dates
TermThisHour=Now

[...]
*/

Re: Extending getkey capabilities.

Posted: 29 Mar 2011 16:51
by tiago
I will study your code, Stefan.
To my absolute surprise when I was following your "For Each Line of $wholeINI" guidelines I found that I could actually make readfile() to read entire lines via gettoken("<clipboard>", "X - index", "<crlf>");
What do you mean with "if instr( $KEY/"[" )"? Can't find references to such "instr".