source: titan/titan/skinconfig.h @ 38592

Last change on this file since 38592 was 23286, checked in by nit, 11 years ago

[titan] cleanup

File size: 3.1 KB
Line 
1#ifndef SKINCONFIG_H
2#define SKINCONFIG_H
3
4struct clist* addskinconfigtmp(char *key, char *value)
5{
6        return addlisttmp(skinconfig, key, value);
7}
8
9struct clist* addskinconfigdef(char *key, char *value)
10{
11        return addlistdef(skinconfig, key, value);
12}
13
14struct clist* addskinconfig(char *key, char *value)
15{
16        struct clist* node = NULL;
17
18        node =  addlist(skinconfig, key, value);
19        if(node != NULL)
20                status.writeskinconfig = 1;
21
22        return node;
23}
24
25struct clist* addskinconfigscreentmp(char *key, struct skin *node)
26{
27        struct clist* ret = NULL;
28
29        if(key != NULL && node != NULL && node->ret != NULL)
30                ret = addskinconfigtmp(key, node->ret);
31       
32        return ret;
33}
34
35struct clist* addskinconfigscreentmpcheck(char *key, struct skin *node, char* check)
36{
37        if(ostrcmp(node->ret, check) == 0)
38                return addskinconfigtmp(key, "");
39        else
40                return addskinconfigscreentmp(key, node);
41}
42
43struct clist* addskinconfigscreen(char *key, struct skin *node)
44{
45        struct clist* ret = NULL;
46
47        if(key != NULL && node != NULL && node->ret != NULL)
48                ret = addskinconfig(key, node->ret);
49       
50        return ret;
51}
52
53void delskinconfig(char *key)
54{
55        status.writeskinconfig = 1;
56        dellist(skinconfig, key, 0);
57}
58
59struct clist* addskinconfigscreencheck(char *key, struct skin *node, char* check)
60{
61        if(ostrcmp(node->ret, check) == 0)
62                delskinconfig(key);
63        else
64                return addskinconfigscreen(key, node);
65
66        return NULL;
67}
68
69struct clist* addskinconfigint(char *key, int value)
70{
71        char* fileline = NULL;
72        struct clist* ret = NULL;
73
74        fileline = oitoa(value);
75        ret = addskinconfig(key, fileline);
76
77        free(fileline);
78        return ret;
79}
80
81int readskinconfig(const char *filename, struct clist** tmpskinconfig)
82{
83        FILE *fd = NULL;
84        char *fileline = NULL, *pos;
85        int len = 0;
86
87        fileline = malloc(MINMALLOC);
88        if(fileline == NULL)
89        {
90                err("no memory");       
91                return 1;
92        }
93
94        fd = fopen(filename, "r");
95        if(fd == NULL)
96        {
97                perr("can't open %s", filename);
98                free(fileline);
99                return 1;
100        }
101
102        while(fgets(fileline, MINMALLOC, fd) != NULL)
103        {
104                if(fileline[0] == '#' || fileline[0] == '\n')
105                        continue;
106                len = strlen(fileline) - 1;
107                if(len >= 0 && fileline[len] == '\n')
108                        fileline[len] = '\0';
109                len--;
110                if(len >= 0 && fileline[len] == '\r')
111                        fileline[len] = '\0';
112
113                pos = strchr(fileline, '=');
114                if(pos != NULL)
115                {
116                        pos[0] = '\0';
117                        addlist(tmpskinconfig, fileline, pos + 1);
118                }
119        }
120
121        fclose(fd);
122        free(fileline);
123        return 0;
124}
125
126int writeskinconfigtmp()
127{
128        int ret = 0;
129
130        if(writelisttmp(skinconfig) == 0)
131                status.writeskinconfig = 1;
132
133        return ret;
134}
135
136int writeskinconfig(const char *filename)
137{
138        return writelist(skinconfig, filename);
139}
140
141char* getskinconfig(char *key, char *ext)
142{
143        return getlist(skinconfig, key, ext);
144}
145
146int getskinconfigint(char *key, char *ext)
147{
148        char *ret = NULL;
149
150        ret = getlist(skinconfig, key, ext);
151        if(ret != NULL)
152                return atoi(ret);
153        else
154                return 0;
155}
156
157void delskinconfigtmpall()
158{
159        dellisttmpall(skinconfig);
160}
161
162void delskinconfigtmp(char *key)
163{
164        dellisttmp(skinconfig, key);
165}
166
167void freeskinconfig()
168{
169        freelist(skinconfig);
170}
171
172int reloadskinconfig(char *filename)
173{
174        int ret = 0;
175
176        freeskinconfig();
177        ret = readskinconfig(filename, skinconfig);
178        if(ret != 0)
179        {
180                err("readskinconfig fail");
181                return 1;
182        }
183
184        return 0;
185}
186
187#endif
Note: See TracBrowser for help on using the repository browser.