I have this bit of code:
second = strtok (NULL,"\n");
logprintf(second);
if(_stricmp(second,"WINDOWS") == 0)
The logprintf prints data into a logfile, and it prints “WINDOWS” (without quotes).
but _stricmp returns 13 somehow.. So the if check never gets passed. I’ve tried doing sscanf/sprintf/other string ways but none work. I’m out of ideas.
The full code:
#ifdef WIN32
char buf[65535];
bool found = false;
bool install = false;
bool installing = false;
unsigned int installed = 0;
WIN32_FIND_DATA fd;
HANDLE h = FindFirstFile(L"./*.AIFPAK", &fd);
char * NAME = NULL;
char * ID = NULL;
char * AUTHOR = NULL;
int VERSION;
HZIP hz = OpenZip(fd.cFileName,0);
ZIPENTRY ze;
GetZipItem(hz,-1,&ze);
int numitems=ze.index;
for (int i=0; i<numitems; ++i)
{
GetZipItem(hz,i,&ze);
if(found == false)
{
if(_wcsicmp(ze.name,L"INSTALL.AIFLIST") == 0)
{
found = true;
UnzipItem(hz,i,buf,65535);
i = 0;
stringstream strx;
strx << buf;
string line;
while (getline(strx, line)) {
char * first = NULL;
char * second = NULL;
char * third = NULL;
first = strtok ((char *)line.c_str()," ");
if(install == false)
{
if(_stricmp(first,"NAME") == 0)
{
NAME = strtok (NULL,"\n");
}
if(_stricmp(first,"ID") == 0)
{
ID = strtok (NULL,"\n");
}
if(_stricmp(first,"AUTHOR") == 0)
{
AUTHOR = strtok (NULL,"\n");
}
if(_stricmp(first,"VERSION") == 0)
{
VERSION = atoi(strtok (NULL,"\n"));
}
if(_stricmp(first,"START_INSTALL") == 0)
{
second = strtok (NULL,"\n");
logprintf(second);
if(_stricmp(second,"WINDOWS") == 0)
{
cout << "INSTALLAH\n";
install = true;
cout << NAME << "|" << ID << "|" << AUTHOR << "|" << VERSION << "|\n";
}
}
}
else
{
cout << "ELSE FIRST: " << first << "\n";
if(_stricmp(first,"UNPACK") == 0)
{
second = strtok (NULL,">");
third = strtok (NULL,"\n");
cout << first << "|" << second << "|" << third << "|\n";
ToDoVec.push_back(ToDoInfo(0,second,third));
}
if(_stricmp(first,"PRINT") == 0)
{
second = strtok (NULL,"\n");
cout << first << "|" << second << "|" << third << "|\n";
ToDoVec.push_back(ToDoInfo(3,second,""));
}
if(_stricmp(first,"ADD_PLUGIN") == 0)
{
second = strtok (NULL,"\n");
cout << first << "|" << second << "|" << third << "|\n";
ToDoVec.push_back(ToDoInfo(1,second,""));
}
if(_stricmp(first,"ADD_FILTERSCRIPT") == 0)
{
second = strtok (NULL,"\n");
cout << first << "|" << second << "|" << third << "|\n";
ToDoVec.push_back(ToDoInfo(2,second,""));
}
if(_stricmp(first,"END_INSTALL") == 0)
{
break;
}
}
}
}
}
else
{
if(installing == false)
{
i = 0;
installing = true;
for(unsigned int ix = 0; ix < ToDoVec.size(); ++ix)
{
cout << "|" << ToDoVec.at(ix).action << "|" << ToDoVec.at(ix).string1 << "|" << ToDoVec.at(ix).string2 << "|\n";
}
}
else
{
}
}
}
found = false;
install = false;
installing = false
CloseZip(hz);
while (FindNextFile(h, &fd))
{
//fnVec.push_back(fd.cFileName);
}
#else//assuming linux
#endif
The “INSTALL.AIFLIST” file looks like this:
NAME Route Connector Plugin
ID GAMER_GPS
VERSION 1733
AUTHOR Gamer_Z
START_INSTALL WINDOWS
UNPACK RouteConnector/plugins/RouteConnectorPlugin.dll>./plugins/RouteConnectorPlugin.dll
UNPACK RouteConnector/examples/other/filterscripts/Node_GPS.amx>./filterscripts/Node_GPS.amx
UNPACK RouteConnector/examples/other/filterscripts/Node_GPS.pwn>./filterscripts/Node_GPS.pwn
UNPACK RouteConnector/scriptfiles/GPS.dat>./scriptfiles/GPS.dat
UNPACK RouteConnector/sampGDK/EXTRACTED/libsampgdk-2.2.1-win32/bin/sampgdk2.dll>./sampgdk2.dll
ADD_PLUGIN RouteConnectorPlugin
ADD_FILTERSCRIPT Node_GPS
END_INSTALL
START_INSTALL LINUX
UNPACK RouteConnector/plugins/RouteConnectorPlugin.so>./plugins/RouteConnectorPlugin.so
UNPACK RouteConnector/examples/other/filterscripts/Node_GPS.amx>./filterscripts/Node_GPS.amx
UNPACK RouteConnector/examples/other/filterscripts/Node_GPS.pwn>./filterscripts/Node_GPS.pwn
UNPACK RouteConnector/scriptfiles/GPS.dat>./scriptfiles/GPS.dat
PRINT To make this plugin work you must install the sampgdk library from www.github.com/Zeex/ (if you don't have it installed)
ADD_PLUGIN RouteConnectorPlugin.so
ADD_FILTERSCRIPT Node_GPS
END_INSTALL
All the data is read correctly into ‘buf’.
Can anybody suggest how to fix that problem?
It looks as if you’re not accounting for CRLF line endings. Opening a file in text mode will translate “\r\n” to “\n”, but there’s nothing in your code that does so. If “WINDOWS” is followed by “\r\n”, you’re treating that as “WINDOWS\r” followed by a “\n”, because “\n” is all you’re passing to
strtok. There are several possible solutions, but one is passing “\r\n” tostrtokinstead.