1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2005 Wilmer van der Gaast and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* INI file reading code */ |
---|
8 | |
---|
9 | /* |
---|
10 | This program is free software; you can redistribute it and/or modify |
---|
11 | it under the terms of the GNU General Public License as published by |
---|
12 | the Free Software Foundation; either version 2 of the License, or |
---|
13 | (at your option) any later version. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, |
---|
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | GNU General Public License for more details. |
---|
19 | |
---|
20 | You should have received a copy of the GNU General Public License with |
---|
21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
22 | if not, write to the Free Software Foundation, Inc., 59 Temple Place, |
---|
23 | Suite 330, Boston, MA 02111-1307 USA |
---|
24 | */ |
---|
25 | #define BITLBEE_CORE |
---|
26 | #include "bitlbee.h" |
---|
27 | |
---|
28 | ini_t *ini_open( char *file ) |
---|
29 | { |
---|
30 | ini_t *ini = g_new0( ini_t, 1 ); |
---|
31 | |
---|
32 | if( ( ini->fp = fopen( file, "r" ) ) == NULL ) |
---|
33 | { |
---|
34 | g_free( ini ); |
---|
35 | return( NULL ); |
---|
36 | } |
---|
37 | |
---|
38 | return( ini ); |
---|
39 | } |
---|
40 | |
---|
41 | int ini_read( ini_t *file ) |
---|
42 | { |
---|
43 | char key[MAX_STRING], s[MAX_STRING], *t; |
---|
44 | int i; |
---|
45 | |
---|
46 | while( !feof( file->fp ) ) |
---|
47 | { |
---|
48 | *s = 0; |
---|
49 | fscanf( file->fp, "%127[^\n#]s", s ); |
---|
50 | fscanf( file->fp, "%*[^\n]s" ); |
---|
51 | fgetc( file->fp ); /* Skip newline */ |
---|
52 | file->line ++; |
---|
53 | if( strchr( s, '=' ) ) |
---|
54 | { |
---|
55 | sscanf( s, "%[^ =]s", key ); |
---|
56 | if( ( t = strchr( key, '.' ) ) ) |
---|
57 | { |
---|
58 | *t = 0; |
---|
59 | strcpy( file->section, key ); |
---|
60 | t ++; |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | strcpy( file->section, file->c_section ); |
---|
65 | t = key; |
---|
66 | } |
---|
67 | sscanf( t, "%s", file->key ); |
---|
68 | t = strchr( s, '=' ) + 1; |
---|
69 | for( i = 0; t[i] == ' '; i ++ ); |
---|
70 | strcpy( file->value, &t[i] ); |
---|
71 | for( i = strlen( file->value ) - 1; file->value[i] == 32; i -- ) |
---|
72 | file->value[i] = 0; |
---|
73 | |
---|
74 | return( 1 ); |
---|
75 | } |
---|
76 | else if( ( t = strchr( s, '[' ) ) ) |
---|
77 | { |
---|
78 | strcpy( file->c_section, t + 1 ); |
---|
79 | t = strchr( file->c_section, ']' ); |
---|
80 | *t = 0; |
---|
81 | } |
---|
82 | } |
---|
83 | return( 0 ); |
---|
84 | } |
---|
85 | |
---|
86 | void ini_close( ini_t *file ) |
---|
87 | { |
---|
88 | fclose( file->fp ); |
---|
89 | g_free( file ); |
---|
90 | } |
---|