What I'd like to see in a future CVS build of MQ is the ability to manipulate files.
The benifits are obvious. Macros that read initialization data and settings from plain text files, or obtain game data that can be put to use and manipulated (like the Bazaar stuff, for example). I'm writing a path recording macro (that at the moment relies on an external VB app I wrote to parse /MQLOG output), and that would be so much easier (and more self-contained) to use if I had access to file input/output, and I think a lot of people would find this very useful for things I can't even begin to think about.
I know there are potential problems. I remember hearing talk about 'MacroQuest Trojans' that could destroy files, etc. To be honest, I don't think this is a real problem, as any such macros posted in the macro depot would be quickly identified (not to mention the fact that you shouldn't run any macro you're not familiar with).
To further reduce risk of these types of macros, we could limit file i/o to one directory, perhaps nested in the Macros directory.
Commands could be as follows:
/openfile <nameoffile> <filehandle> <openmode>
-- This would open the specified file for input/output on the specified handle, in the specified open mode (String or Binary)
$readfile(<filehandle>,<numbytes>,[<startposition>])
-- read the specified number of bytes from the specified file, starting at the specified byte position, or if the start position is omitted, starting from the current cursor position.
$readfileline(<filehandle>,[<linenumber>])
-- reads the specified line from the specified file, or if the line number is omitted, it returns the next line.
/writefile <expression> <filehandle> [<startposition>]
-- writes the specified expression to the specified file at the specified position, or if the position is omitted, it writes to the current cursor position, overwriting whatever was previously there.
/writefileline <expression> <filehandle> <linenumber>
-- writes the specified expression to the specified file at the specified line number, or if the line number is omitted, it writes to the current line number, overwriting whatever was previously there.
/closefile <filehandle>
-- Closes the file previously opened by /openfile. Filehandle could be replaced with 'All,' and would close all open files.
And we could have functions like:
$nextfile
-- Returns the next available file handle
$getpos(<filehandle>)
-- Returns the current cursor position of the specified file. For Binary files, it'd return the literal byte position, and for String files, it'd return the line number.
/setpos <filehandle> <position>
-- Sets the current cursor position of the specified file. For Binary files, it'd set the literal byte position, and for String files, it'd set the line number. Position can also be BOF (for Beginning Of File) or EOF (for End Of File).
$sizeof(<filehandle>)
-- Returns the size (in bytes for Binary files, or lines for String files) of the specified file.
An example of the use could be something like the following:
Code: Select all
Sub Main
/openfile "somestuff.dat" 1 String
/for l1 1 to $sizeof(1)
/echo $readfileline(1,$l1)
/next l1
/closefile 1
/return
That's about all I can think of right now. I'd be more than willing to help work on this, but, as I'm just starting to learn C++ at the moment (I'm a veteran VB programmer), I'd need some guidance. PM me or Email me at BlueSkies.SC@comcast.net if anyone's interested in helping me with a nudge in the right direction, or reply here if you have questions.

