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 * ===============================================================
7 * Copyright (C) 2009 "Carlos RĂos Vera" <crosvera@gmail.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *******************************************************************/
32 struct _config
*set_config( void ){
34 struct _config
*config
= NULL
;
37 /* Now we open the `CONFIG_FILE'. If an error happend, show a
38 * message, and return NULL.
39 ****************************************************************/
40 c_file
= fopen( CONFIG_FILE
, "r" );
41 if( c_file
== (FILE *)NULL
){
42 fprintf( stderr
, "\n%s: %s\n", CONFIG_FILE
, strerror( errno
) );
43 return (struct _config
*)NULL
;
46 config
= (struct _config
*) malloc( sizeof(struct _config
) );
49 /* Now we read the `CONFIG_FILE' and store the info into
50 * the config structure.
51 ***************************************************************/
52 while( fgets(fline
, sizeof(fline
), c_file
) ){
54 if( sscanf( fline
, "server: %s\n", config
->irc_server
) == 1 )
56 if( sscanf( fline
, "port: %s\n", config
->irc_port
) == 1 )
58 if( sscanf( fline
, "channel: %s\n", config
->irc_channel
) == 1 )
60 if( sscanf( fline
, "nick: %s\n", config
->irc_nick
) == 1)
62 if( sscanf( fline
, "name: %[^\n]\n", config
->irc_name
) == 1 )
64 if( sscanf( fline
, "username: %[^\n]\n", config
->username
) == 1 )
66 if( sscanf( fline
, "master: %s\n", config
->master
) == 1 )
68 if( sscanf( fline
, "log-file: %[^\n]\n", config
->log_file
) == 1)
73 if( strlen(config
->irc_server
) > 1 && strlen(config
->irc_port
) > 1
74 && strlen(config
->irc_channel
) > 1 && strlen(config
->irc_nick
) > 1
75 && strlen(config
->irc_name
) > 1 && strlen(config
->username
) > 1
76 && strlen(config
->master
) > 1 && strlen(config
->log_file
) > 1 )
77 {/* If there was no problems, go ahead !! */
83 return (struct _config
*)NULL
;