Here's how they work:
/ini <filename> <section> <key> <data>
This writes data to an INI file.
$ini(<filename>,<section>,<key>)
and this Reads data from an INI file.
Filename = the INI file you wish to manipulate. This must be a full path+filename, like "c:\macroquest\macros\data\stuff.ini"
Section = the Section of the INI file you wish to manipulate.
Key = the Key (in the specified Section) that you wish to manipulate.
Here's an example of an INI file, for those of you who have no idea what we're talking about:
File: stuff.ini
Code: Select all
[MySection]
Key1=123
Key2=This is cool!
Key3=Wheeee... 15/echo $ini("c:\macroquest\macros\data\stuff.ini","MySection","Key3")
The output from this would be:
Code: Select all
[MacroQuest] Wheeee... 15Now let's say we want to add some data. We'd use the /ini command for this, like so:
/ini "c:\macroquest\macros\data\stuff.ini" "Section2" "ANewKey" "Some Data!"
When you run this, and open up the stuff.ini file in notepad, it'd look like this:
Code: Select all
[MySection]
Key1=123
Key2=This is cool!
Key3=Wheeee... 15
[Section2]
ANewKey=Some Data!Let's say you've got an INI file you want to look through, but you don't know what all the section names are. You can simply pass a -1 value for the sectionname and keyname paramaters in $ini and it will return all the section names in one long line, with each section name seperated by a pipe character ( | ). The end of the line will have two pipes ( || ) to let you know that you've reached the end. For example:
/echo $ini("c:\macroquest\macros\data\stuff.ini",-1,-1)
This would return:
Code: Select all
MySection|Section2||/echo $ini("c:\macroquest\macros\data\stuff.ini","MySection",-1)
would return:
Code: Select all
Key1|Key2|Key3||In a script, you could use the $instr and $mid functions to parse the output of these two special $ini operations, and then use the data given here to look in the file and retreive the data.
Phew.
That's the nuts and bolts of the /ini command and $ini function.
If you would like to add this functionality to your version of MacroQuest, do the following:
Open the EQLib_Interp.cpp file. Find the _COMMANDORDER struct in the SetCmdList function. Scroll down until you see the following line:
{ NULL, CMD_EQ },
and add this line above it:
Code: Select all
{ "/ini", CMD_MQ },Code: Select all
{"/ini", "IniOutput"},Add, to the bottom of this list, the following line:
Code: Select all
extern "C" EQLIB_API VOID IniOutput (PSPAWNINFO, PCHAR);Code: Select all
// ***************************************************************************
// Function: IniOutput
// Description: Outputs string data to an INI file using
// WritePrivateProfileString.
// Usage: /ini
// ***************************************************************************
VOID IniOutput(PSPAWNINFO pChar, PCHAR szLine)
{
CHAR szArg1[MAX_STRING] = {0}; //Filename
CHAR szArg2[MAX_STRING] = {0}; //Section
CHAR szArg3[MAX_STRING] = {0}; //Key
CHAR szArg4[MAX_STRING] = {0}; //Data to write
CHAR szOutput[MAX_STRING] = {0}; //Success / Error Output
GetArg(szArg1,szLine,1);
GetArg(szArg2,szLine,2);
GetArg(szArg3,szLine,3);
GetArg(szArg4,szLine,4);
DebugSpew("/ini input -- %s %s %s %s",szArg1,szArg2,szArg3,szArg4);
if (!WritePrivateProfileString(szArg2,szArg3,szArg4,szArg1)) {
sprintf(szOutput,"IniOutput ERROR -- during WritePrivateProfileString: %s",szLine);
DebugSpew(szOutput);
WriteChatBuffer(szOutput, CONCOLOR_RED);
} else {
sprintf(szOutput,"IniOutput Write Successful!");
DebugSpew("%s: %s",szOutput,szLine);
WriteChatBuffer(szOutput, CONCOLOR_GREEN);
}
}Finally, open the EQLib_MacroParser.cpp file. Go to the very bottom, and add this code just before the line "// $unknown":
Code: Select all
// $ini(<filename>,<sectionname>,<keyname>)
// Jalapeno & BlueSkies
} else if (!strncmp("ini(",szVar,4)) {
if ((!strstr(szVar,")")) || (!strstr(szVar,",")) || (!strstr(strstr(szVar,",")+1,","))) {
DebugSpew("PMP - Bad $ini() '%s'",szVar);
i--;
szOutput[j] = '@';
j++;
} else {
CHAR szArg1[MAX_STRING] = {0};
CHAR szArg2[MAX_STRING] = {0};
CHAR szArg3[MAX_STRING] = {0};
CHAR szBuffer[MAX_STRING] = {0};
CHAR szList[MAX_STRING] = {0};
char* szToken;
DWORD num = 0;
DWORD zz = 0;
DWORD k = 0;
for (num=0;szVar[num]!=')';num++) {
if (szVar[num]!='"') {
szBuffer[zz++] = szVar[num];
}
}
i += (strstr(szVar,")")-szVar);
strncpy(szArg1,szBuffer+4,strstr(szBuffer,",")-szBuffer-4);
strncpy(szArg2,szBuffer+4+strlen(szArg1)+1,(strstr(strstr(szBuffer,",")+1,","))-szBuffer-4-strlen(szArg1)-1);
strcpy(szArg3,strstr(strstr(szBuffer,",")+1,",")+1);
ZeroMemory(szBuffer,MAX_STRING);
if (atoi(szArg2)==-1) {
DebugSpew("INI -- Arg2 was -1.");
num=GetPrivateProfileString(NULL,NULL,"NOTFOUND",szBuffer,MAX_STRING,szArg1);
} else if (atoi(szArg3)==-1) {
DebugSpew("INI -- Arg3 was -1.");
num=GetPrivateProfileString(szArg2,NULL,"NOTFOUND",szBuffer,MAX_STRING,szArg1);
} else {
num=GetPrivateProfileString(szArg2,szArg3,"NOTFOUND",szBuffer,MAX_STRING,szArg1);
}
if ((atoi(szArg2)==-1) || (atoi(szArg3)==-1)) {
DebugSpew("INI -- Testing Null-Delimited String Output");
for (szToken = szBuffer; *szToken != NULL || k < 1; szToken += strlen(szToken) + 1, k++) {
strcat(szList,szToken);
strcat(szList,"|");
}
strcat(szList,"|");
DebugSpew(szList);
strcat(szOutput,szList);
j+=strlen(szList);
} else {
strcat(szOutput,szBuffer);
j+=strlen(szBuffer);
}
DebugSpew("PMP - $ini(%s,%s,%s) returned '%s'",szArg1,szArg2,szArg3,szList);
}To the people who have access to the CVS (like Rizwank or DKAA) -- if there's anything missing that you guys need before you can add this to the CVS, please let me know.
Oh yeah.
Examples of this functionality in use can be found here:
http://macroquest2.com/phpBB2/viewtopic ... 7056#17056



