Rev 7674 | Rev 8100 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7674 | Rev 8082 | ||
---|---|---|---|
Line 133... | Line 133... | ||
133 | } |
133 | } |
134 | if(*pp!=c) return NULL; |
134 | if(*pp!=c) return NULL; |
135 | return pp; |
135 | return pp; |
136 | } |
136 | } |
137 | 137 | ||
138 | /* searches a list. Returns index if found, -1 if nomatch. |
138 | /* searches a list. Returns index if found, (-1-index of insertion) if nomatch. |
139 | * Uses binary search, list must be sorted. */ |
139 | * Uses binary search, list must be sorted. */ |
- | 140 | ||
140 | int search_list(void *list, int items, size_t item_size, const char *str) |
141 | int search_list(void *list, int items, size_t item_size, const char *str) |
141 | { |
142 | { |
142 | int i1,i2,j,k; |
- | |
143 | char **p; |
- | |
144 |
|
143 | int i = 0; |
145 | - | ||
146 |
|
144 | while (items > 0) |
147 | j=0; c=*str; |
- | |
148 |
|
145 | { |
149 | k=**p-c; if(k==0) k=strcmp(*p,str); |
- | |
150 | if(k==0) return k; if(k>0) return -1; |
- | |
151 |
|
146 | int m = items / 2, j = i + m; |
152 | k=**p-c; if(k==0) k=strcmp(*p,str); |
- | |
153 | if(k==0) return items-1; if(k<0) return -1; |
- | |
154 | for(i1=0,i2=items-1;i2>i1+1;) { |
- | |
155 | j=i1+(i2-i1)/2; |
- | |
156 | p=list+(j*item_size); |
- | |
157 |
|
147 | int k = strcmp(*(char **)(list + j * item_size), str); |
158 |
|
148 | if (k == 0) return j; |
159 |
|
149 | if (k > 0) items = m; else {i = j + 1; items -= (m + 1);} |
160 | if(k<0) {i1=j; continue;} |
- | |
161 |
|
150 | } |
162 |
|
151 | return ~i; |
163 | } |
152 | } |
164 | 153 | ||
165 | /* Read/write to a file with variable parms to print filename */ |
154 | /* Read/write to a file with variable parms to print filename */ |
166 | void accessfile(char *content, char *type, char *s,...) |
155 | void accessfile(char *content, char *type, char *s,...) |
167 | { |
156 | { |