| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 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 |
} |
|---|