Well I just decided to code a basic IRC bot that is a complete ripoff of the bot on the irc.efnet.net #winprog IRC channel.
Essentially I want the bot to have the ability to give information over an API call by someone simply doing,
!api CreateFile
In the channel and it will answer and such. Unfortunately, while testing out my file handling function in another source file I've hit a snag, spaces in the files' buffer cause it to truncate the string.
My files are laid out like this:
APICALLNAME :: DESCRIPTION (this isn't longer than 1024 bytes)
So if I have like, on a totally unrelated note this:
ASDF :: Fight Club
It will give back "Fight" and that's all.
Function (excuse the stupid name of the function):
Code:
void sidiousSearch(srctSearch *information) {
//Variables
char lib, //This is a char to specify the file to open
rightFile[10], //File to open
line[1024], //Line from file (description)
nameOfAPI[40]; //The name you're searching for
FILE *file2Open; //File handle
int sent = 1; //Assume failure
char errorMSG[] = "Sorry, I couldn't find that API"; //Incase it wasn't found
//Make sure we have the appropriate file.
lib = information->query[0];
sprintf(rightFile,"file[%c].txt",lib);
//Enter exception handling block and ........
_try {
//Open
file2Open = fopen(buffer,"r");
if(file == NULL)
_leave;
//Enter loop
while((fscanf(file,"%s :: %s",nameOfAPI,line)) != EOF) {
if(strcmp(nameOfAPI,information->query)==0) {
//Success
send(information->s,line,strlen(line),0);
sent = 0;
break;
}
}
}
_finally {
//Clean up file
if(file2Open != NULL)
fclose(file2Open);
}
if(sent == 1)
send(information->s,errorMSG,strlen(errorMSG),0);
WaitForSingleObject(hMutex4Thrs,INFINITE);
thrNumInUse--;
ReleaseMutex(hMutex4Thrs);
}
The srctSearch struct has a socket to communicate to (the IRC servers') and then it has the query to be searched for, I decided to split up the files in an order so that depending on the first letter of the APIs' name it will open a specific file to that (as to avoid just searching through one massive table.)
I am wondering if there is a way to get around this with file calls like this or if I would have to put Win32 file handling at play.
Also, does anybody know of a string comparison function that does INcase sensitive matches? If the file has the API name "ASDF" and someone would go "!api Asdf" it would not work. Or do I have to make one myself?