Edited the MakeFile
[Cbot.git] / config.c
blob6f80382303ea4ff7ab93650cb4928a91a278ca54
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 <string.h>
10 #include <stdlib.h>
11 #include <errno.h>
13 #include "config.h"
15 struct _config *set_config( void ){
16 FILE *c_file = NULL;
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' */
45 return config;