Custom @windows
Description:
We’ll use a custom @window to store a list of text lines.
Advantages:
Has powerful sorting and search options using /filter and other premade $identifiers .
Can be saved easily into .txt files for permanent storage.
When using dialog lists you should have a copy of the data in a @window and do all the sorting and searching work in the @window because it’s much more efficient.
Disadvantages:
Not as organized as hash tables.
Inefficient access to data (only direct access is by line number).
Storage:
The data is stored in as list in a custom @window, which we’ll usually prefer to hide.
Initializing a custom @window:
/window –h @name
This will activate a new window with the specified name. (-h means hidden)
Adding data:
/aline @name data
Adds data to the end of the @window. ( can use /aline –n to prevent adding lines that exist ).
Deleting data:
/dline @name N file.txt
Deletes the Nth line of data in the @window.
/window –c @name
Will close the specified @window.
Inserting data:
/iline @name N data
Inserts the line of data in the Nth line. ( can use /iline –n to prevent adding lines that exist ) .
/rline @name N data
Inserts the line of data to the Nth line, and overwrites it.
Retrieving data:
Set %line $line(@name,N)
Gets the Nth line in the @window.
Searching for data:
Set %lineNum $fline(@name,*wild*match*,N,T)
Gets the position of the Nth matching line that matches the *wild*match*.
The T is optional, if it’s set to 2 it means the match expression is a regex expression .
Set %line $fline(@name,*wild*match*,N,T).text
Gets the Nth matching line that matches the *wild*match*.
Sorting and filtering:
/window –s @name
This will make the @window sort itself automatically.
/filter –ww @name @name
This simple format is an example to show that you can use /filter’s powerful options to sort the @window, and change it. Please read more about it in the mirc’s help file, to take advantage of this ability.
Converting to .txt files:
/loadbuf @window file.txt
Will load all lines in the text file to the custom @window .
/savebuf @window file.txt
Will save the custom @window’s contents to the text file.
Retrieving size:
Set %lineNum $line(@name,0)
Will return the number of lines in the file.
Example:
Load the example to the remotes, and right click on a channel.
menu channel {
@window Store data: {
window -h @mychanneldata
filter -cww $chan @mychanneldata
iline @mychanneldata 1 $chan($chan).topic
}
@window Show data: {
if ($window(@mychanneldata)) {
echo -a Recorded channel topic: $line(@mychanneldata,1)
filter -cwwg @mychanneldata @mychanneldata /^\* $/
echo -a Number of channel events recorded: $line(@mychanneldata,0)
echo -a Here's the last event in the channel: $line(@mychanneldata,$line(@mychanneldata,0))
var %lineNum = $fline(@mychanneldata,$+(*,joined,*),1)
echo -a Here's the first join event: $line(@mychanneldata,%lineNum)
echo -a That appeared in line: %lineNum
}
}
@window Remove data :{
if ($window(@mychanneldata)) window -c @mychanneldata
}
}