source: titan/titan/rcconfig.h @ 42227

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

[titan] cleanup

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