hello I am trying to create an robot and I have been having a problem parsing the full string from the conf. As example the IRCServer, botnick, botname parameter does not contain the all the data. as the output shows:
#####################
# Ablaze Bot #
#####################
Loading conf file: Success....
Botnick=
Botname=
IRCServer= aBlazeNet
IRCPort= 6667
BindAdr=
BindPort= 9050
Channels= #aBlazeNet
Debug= 2
An example conf:
Botnick=aBlaze
Botname=aBlazeNet IRC Bot
IRCServer=localhost
IRCPort=6667
BindAdr=0.0.0.0
BindPort=9050
Channels=#aBlazeNet
Debug=2
The program itself:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
FILE *conffp;
char confbuffer[1024];
char *Botnick;
char *Botname;
char *IRCServer;
int IRCPort;
char *BindAdr;
int BindPort;
char *Channels;
int Debug;
int main(int argc, char *argv[]) {
printf("\n#####################\n# Ablaze Bot #\n#####################\n\n");
printf("Loading conf file: ");
if ((conffp = fopen ("ablaze.conf","r")) != NULL) {
char *key, *value;
while(fgets(confbuffer, 1024, conffp)!=NULL) {
if(confbuffer[0] == ';') continue;
key = strtok( confbuffer, "=" );
value = strtok( NULL, "\n");
if(strcmp(key,"Botnick")== 0) Botnick = value;
if(strcmp(key,"Botname")== 0) Botname = value;
if(strcmp(key,"IRCServer")== 0) IRCServer = value;
if(strcmp(key,"IRCPort")== 0) IRCPort = atoi(value);
if(strcmp(key,"BindAdr")== 0) BindAdr = value;
if(strcmp(key,"BindPort")== 0) BindPort = atoi(value);
if(strcmp(key,"Channels")== 0) Channels = value;
if(strcmp(key,"Debug")== 0) Debug = atoi(value);
//printf(value);
}
printf("Success.... %s\n", Botnick);
if(Debug > 1) {
printf("\tBotnick= %s\n", Botnick);
printf("\tBotname= %s\n", Botname);
printf("\tIRCServer= %s\n", IRCServer);
printf("\tIRCPort= %i\n", IRCPort);
printf("\tBindAdr= %s\n", BindAdr);
printf("\tBindPort= %i\n", BindPort);
printf("\tChannels= %s\n", Channels);
printf("\tDebug= %i\n", Debug);
}
fclose(conffp);
} else {
printf ("could not be opened...\n");
}
return 0;
}
I was wondering if there is a way to improve and/or fix this conf system? Thank you for your time.