Added the configuration feature (config.h & config.c) that allow the bot reads the...
[Cbot.git] / config.c
blobd1534438902531f35d37a66ea2316e994b49e156
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 *******************************************************************/
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <errno.h>
12 #include "config.h"
14 struct _config *set_config( void ){
15 FILE *c_file = NULL;
16 struct _config *config = NULL;
18 /* Now we open the `CONFIG_FILE'. If an error happend, show a
19 * message, and return NULL.
20 ****************************************************************/
21 c_file = fopen( CONFIG_FILE, "r" );
22 if( c_file == (FILE *)NULL ){
23 printf("\n%s: %s\n", CONFIG_FILE, strerror( errno ) );
24 return (struct _config *)NULL;
27 config = (struct _config *) malloc( sizeof(struct _config) );
30 /* Now we read the `CONFIG_FILE' and store the info into
31 * the config structure.
32 ***************************************************************/
33 fscanf( c_file, "server: %s\n", config->irc_server );
34 fscanf( c_file, "port: %d\n", &config->irc_port );
35 fscanf( c_file, "channel: %s\n", config->irc_channel );
36 fscanf( c_file, "nick: %s\n", config->irc_nick );
38 fclose( c_file ); /* Close the `CONFIG_FILE' */
40 return config;