1 /* config.c - Functions which reads a config file to set the bot
2 * ===============================================================
4 * The `CONFIG_FILE' macro is set in `config.h', this macro
5 * sets the path where the config file is.
6 *******************************************************************/
15 struct _config
*set_config( void ){
17 struct _config
*config
= NULL
;
19 /* Now we open the `CONFIG_FILE'. If an error happend, show a
20 * message, and return NULL.
21 ****************************************************************/
22 c_file
= fopen( CONFIG_FILE
, "r" );
23 if( c_file
== (FILE *)NULL
){
24 fprintf( stderr
, "\n%s: %s\n", CONFIG_FILE
, strerror( errno
) );
25 return (struct _config
*)NULL
;
28 config
= (struct _config
*) malloc( sizeof(struct _config
) );
31 /* Now we read the `CONFIG_FILE' and store the info into
32 * the config structure.
33 ***************************************************************/
34 fscanf( c_file
, "server: %s\n", config
->irc_server
);
35 fscanf( c_file
, "port: %s\n", config
->irc_port
);
36 fscanf( c_file
, "channel: %s\n", config
->irc_channel
);
37 fscanf( c_file
, "nick: %s\n", config
->irc_nick
);
38 fscanf( c_file
, "name: %[^\n]\n", config
->irc_name
);
39 fscanf( c_file
, "username: %[^\n]\n", config
->username
);
40 fscanf( c_file
, "master: %s\n", config
->master
);
42 fclose( c_file
); /* Close the `CONFIG_FILE' */