source: titan/titan/choicebox.h @ 15272

Last change on this file since 15272 was 10254, checked in by nit, 12 years ago

[titan] fix scan

File size: 2.9 KB
Line 
1#ifndef CHOICEBOX_H
2#define CHOICEBOX_H
3
4int addchoicebox(struct skin* choicebox, char* value, char* text)
5{
6        debug(1000, "in");
7        char* tmp = NULL;
8
9        if(choicebox == NULL || value == NULL || text == NULL || strlen(value) == 0)
10        {
11                debug(1000, "out -> NULL detect");
12                return 1;
13        }
14
15        if(choicebox->input == NULL || choicebox->choiceboxvalue == NULL)
16        {
17                changeinput(choicebox, NULL);
18                changechoiceboxvalue(choicebox, NULL);
19                tmp = ostrcat(tmp, text, 1, 0);
20                changeinput(choicebox, tmp);
21                free(tmp); tmp = NULL;
22                tmp = ostrcat(tmp, value, 1, 0);
23                changechoiceboxvalue(choicebox, tmp);
24        }
25        else
26        {
27                //check once
28                if(ostrcmp(choicebox->choiceboxvalue, value) == 0) return 0;
29                //check first
30                tmp = ostrcat(value, "\n", 0, 0);
31                if(strstr(choicebox->choiceboxvalue, tmp) == choicebox->choiceboxvalue)
32                {
33                        free(tmp); tmp = NULL;
34                        return 0;
35                }
36                free(tmp); tmp = NULL;
37                //check mitddle
38                tmp = ostrcat("\n", value, 0, 0);
39                tmp = ostrcat(tmp, "\n", 1, 0);
40                if(strstr(choicebox->choiceboxvalue, tmp) != NULL)
41                {
42                        free(tmp); tmp = NULL;
43                        return 0;
44                }
45                free(tmp); tmp = NULL;
46                //check end
47                tmp = ostrcat("\n", value, 0, 0);
48                char* c = strstr(choicebox->choiceboxvalue, tmp);
49                if(c != NULL && choicebox->choiceboxvalue + strlen(choicebox->choiceboxvalue) == c + strlen(tmp))
50                {
51                        free(tmp); tmp = NULL;
52                        return 0;
53                }
54                free(tmp); tmp = NULL;
55
56                tmp = ostrcat(choicebox->choiceboxvalue, "\n", 0, 0);
57                tmp = ostrcat(tmp, value, 1, 0);
58                changechoiceboxvalue(choicebox, tmp);
59                free(tmp); tmp = NULL;
60
61                tmp = ostrcat(choicebox->input, "\n", 0, 0);
62                tmp = ostrcat(tmp, text, 1, 0);
63                changeinput(choicebox, tmp);
64        }
65       
66        free(tmp);
67
68        return 0;
69        debug(1000, "out");
70}
71
72int setchoiceboxselection(struct skin* choicebox, char* value)
73{
74        debug(1000, "in");
75        int treffer = 0;
76        char* pos = NULL, *epos = NULL, *end = NULL;
77
78        if(choicebox == NULL || choicebox->input == NULL)
79        {
80                debug(1000, "out -> NULL detect");
81                return 1;
82        }
83
84        choicebox->aktpage = 0;
85
86        if(value == NULL)
87        {
88                debug(1000, "out -> NULL detect");
89                return 1;
90        }
91
92        if(choicebox->choiceboxvalue != NULL)
93                pos = choicebox->choiceboxvalue;
94        else
95                pos = choicebox->input;
96
97        if(pos != NULL) end = pos + strlen(pos) + 1;
98
99        while(pos != NULL)
100        {
101                choicebox->aktpage++;
102
103                if(strncmp(pos, value, strlen(value)) == 0)
104                {
105                        epos = pos + strlen(value);
106                        if(epos > end) break;
107                        if(*epos == '\n' || *epos == '\0')
108                        {
109                                changeret(choicebox, value);
110                                treffer = 1;
111                                break;
112                        }
113                }
114
115                pos = strchr(pos, '\n');
116                if(pos != NULL) pos++;
117        }
118
119        if(treffer == 0)
120        {
121                if(choicebox->choiceboxvalue != NULL)
122                        pos = choicebox->choiceboxvalue;
123                else
124                        pos = choicebox->input;
125
126                if(pos != NULL)
127                {
128                        epos = strchr(pos, '\n');
129                        if(epos == NULL)
130                                changeret(choicebox, pos);
131                        else
132                        {
133                                char c = 0;
134                                c = *epos;
135                                *epos = '\0';
136                                changeret(choicebox, pos);
137                                *epos = c;
138                        }
139                        choicebox->aktpage = 1;
140                }
141        }
142
143        debug(1000, "out");
144        return 0;
145}
146
147#endif
Note: See TracBrowser for help on using the repository browser.