root/trunk/src/conf.c

Revision 680, 2.5 kB (checked in by jajcus, 3 years ago)

- dates in the copyright header updated

Line 
1 /* $Id: conf.c,v 1.6 2003/01/22 07:53:01 jajcus Exp $ */
2
3 /*
4  *  (C) Copyright 2002-2006 Jacek Konieczny [jajcus(a)jajcus,net]
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License Version 2 as
8  *  published by the Free Software Foundation.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include "ggtrans.h"
21 #include "jabber.h"
22 #include "conf.h"
23 #include <ctype.h>
24
25 xmlnode config;
26
27 char *config_load_string(const char *tag){
28 xmlnode node;
29 char *data;
30
31         node=xmlnode_get_tag(config,tag);
32         if (node==NULL) return NULL;
33         data=xmlnode_get_data(node);
34         if (data==NULL) return NULL;
35         return g_strstrip(data);
36 }
37
38 char *config_load_formatted_string(const char *tag){
39 xmlnode node,child;
40 char *out,*tmp,*add,*name;
41 int t;
42 int i,j,sp;
43
44         node=xmlnode_get_tag(config,tag);
45         if (!node) return NULL;
46         out=g_strdup("");
47         child=xmlnode_get_firstchild(node);
48         while(child){
49                 t=xmlnode_get_type(child);
50                 add=NULL;
51                 switch(t){
52                         case NTYPE_TAG:
53                                 name=xmlnode_get_name(child);
54                                 if (!g_strcasecmp(name,"p")){
55                                         if (out[0]) add=g_strdup("\n");
56                                 }
57                                 else if (!g_strcasecmp(name,"br"))
58                                         add=g_strdup("\n");
59                                 else g_warning("Unknown formatting '%s' in '%s'",
60                                                 xmlnode2str(child),xmlnode2str(node));
61                                 break;
62                         case NTYPE_CDATA:
63                                 tmp=xmlnode_get_data(child);
64                                 if (tmp==NULL) break;
65                                 add=g_new(char,strlen(tmp)+1);
66                                 sp=1;
67                                 for(i=j=0;tmp[i];i++){
68                                         if (!isspace(tmp[i])){
69                                                 sp=0;
70                                                 add[j++]=tmp[i];
71                                         }
72                                         else if (!sp){
73                                                 add[j++]=' ';
74                                                 sp=1;
75                                         }
76                                 }
77                                 if (j && sp) j--;
78                                 add[j]=0;
79                                 break;
80                         case NTYPE_ATTRIB:
81                                 g_error("Unexpected attribute");
82                                 break;
83                         default:
84                                 g_error("Unknown node type: %i",t);
85                                 break;
86                 }
87                 if (add){
88                         tmp=out;
89                         out=g_strconcat(out,add,NULL);
90                         g_free(tmp);
91                         g_free(add);
92                 }
93                 child=xmlnode_get_nextsibling(child);
94         }
95
96         return out;
97 }
98
99 int config_load_int(const char *tag,int defval){
100 xmlnode node;
101 char *data;
102
103         node=xmlnode_get_tag(config,tag);
104         if (node==NULL) return defval;
105         data=xmlnode_get_data(node);
106         if (data==NULL) return defval;
107         return atoi(g_strchug(data));
108 }
Note: See TracBrowser for help on using the browser.