gwenhywfar  4.3.3
stringlist2.c
Go to the documentation of this file.
1 /***************************************************************************
2  $RCSfile$
3  -------------------
4  cvs : $Id$
5  begin : Thu Apr 03 2003
6  copyright : (C) 2003 by Martin Preuss
7  email : martin@libchipcard.de
8 
9  ***************************************************************************
10  * *
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This library is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
24  * MA 02111-1307 USA *
25  * *
26  ***************************************************************************/
27 
28 
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 
33 #include <gwenhywfar/gwenhywfarapi.h>
34 #include <gwenhywfar/misc.h>
35 #include "stringlist2_p.h"
36 #include "debug.h"
37 #include <stdlib.h>
38 #include <assert.h>
39 #include <string.h>
40 #ifdef HAVE_STRINGS_H
41 # include <strings.h>
42 #endif
43 
44 
46  GWEN_STRINGLIST2 *sl2;
47  GWEN_REFPTR_INFO *rpi;
48 
50  rpi=GWEN_RefPtrInfo_new();
53  sl2->listPtr=GWEN_List_new();
54  GWEN_List_SetRefPtrInfo(sl2->listPtr, rpi);
56 
57  return sl2;
58 }
59 
60 
61 
63  if (sl2) {
64  GWEN_List_free(sl2->listPtr);
65  GWEN_FREE_OBJECT(sl2);
66  }
67 }
68 
69 
70 
72  GWEN_STRINGLIST2 *nsl2;
73 
75  nsl2->listPtr=GWEN_List_dup(sl2->listPtr);
76  nsl2->senseCase=sl2->senseCase;
77 
78  return nsl2;
79 }
80 
81 
82 
84  assert(sl2);
85  sl2->senseCase=i;
86 }
87 
88 
89 
91  const char *s,
92  int take,
94  GWEN_REFPTR *rp;
95 
96  assert(sl2);
97  assert(s);
98 
101 
102  it=GWEN_StringList2__GetString(sl2, s);
103  if (it) {
105  if (take)
106  free((void*)s);
108  return 0;
109  }
112  if (take)
113  free((void*)s);
115  return 0;
116  }
118  }
119  }
120 
121  if (take)
122  rp=GWEN_RefPtr_new((void*)s, GWEN_List_GetRefPtrInfo(sl2->listPtr));
123  else
124  rp=GWEN_RefPtr_new(strdup(s), GWEN_List_GetRefPtrInfo(sl2->listPtr));
126  GWEN_List_PushBackRefPtr(sl2->listPtr, rp);
127  return 1;
128 }
129 
130 
131 
133  const char *s,
134  int take,
136  GWEN_REFPTR *rp;
137 
138  assert(sl2);
139  assert(s);
140 
143 
144  it=GWEN_StringList2__GetString(sl2, s);
145  if (it) {
147  if (take)
148  free((void*)s);
150  return 0;
151  }
154  if (take)
155  free((void*)s);
157  return 0;
158  }
160  }
161  }
162 
163  if (take)
164  rp=GWEN_RefPtr_new((void*)s, GWEN_List_GetRefPtrInfo(sl2->listPtr));
165  else
166  rp=GWEN_RefPtr_new(strdup(s), GWEN_List_GetRefPtrInfo(sl2->listPtr));
168  GWEN_List_PushFrontRefPtr(sl2->listPtr, rp);
169  return 1;
170 }
171 
172 
173 
175  const char *s){
177 
178  it=GWEN_StringList2__GetString(sl2, s);
179  if (it) {
180  int lc;
181 
183  GWEN_List_Erase(sl2->listPtr, it);
185  if (lc<2)
186  return 1;
187  }
188 
189  return 0;
190 }
191 
192 
193 
195  const char *s){
197  int gotIt;
198 
199  it=GWEN_StringList2_First(sl2);
200  gotIt=0;
201  if (it) {
202  const char *t;
203 
205  if (sl2->senseCase) {
206  while(t) {
207  if (strcmp(s, t)) {
208  gotIt=1;
209  break;
210  }
212  }
213  }
214  else {
215  while(t) {
216  if (strcasecmp(s, t)) {
217  gotIt=1;
218  break;
219  }
221  }
222  }
224  }
225 
226  return gotIt;
227 }
228 
229 
230 
233  const char *s){
235  GWEN_REFPTR *rp;
236 
237  it=GWEN_StringList2_First(sl2);
238  if (it) {
240 
241  if (sl2->senseCase) {
242  while(rp) {
243  const char *t;
244 
245  t=(const char*)GWEN_RefPtr_GetData(rp);
246  assert(t);
247  if (strcmp(s, t)==0)
248  return it;
250  }
251  }
252  else {
253  while(rp) {
254  const char *t;
255 
256  t=(const char*)GWEN_RefPtr_GetData(rp);
257  assert(t);
258  if (strcasecmp(s, t)==0)
259  return it;
261  }
262  }
264  }
265 
266  return 0;
267 }
268 
269 
270 
271 
272 
273 
274 
275 
276 
277 
278 
279 
280 
281 
282 
284  assert(l);
285  return (GWEN_STRINGLIST2_ITERATOR*) GWEN_List_First(l->listPtr);
286 }
287 
288 
289 
291  assert(l);
292  return (GWEN_STRINGLIST2_ITERATOR*) GWEN_List_Last(l->listPtr);
293 }
294 
295 
296 
298  assert(li);
300 }
301 
302 
304  assert(li);
305  return (const char*) GWEN_ListIterator_Previous((GWEN_LIST_ITERATOR*)li);
306 }
307 
308 
310  assert(li);
311  return (const char*) GWEN_ListIterator_Next((GWEN_LIST_ITERATOR*)li);
312 }
313 
314 
316  assert(li);
317  return (const char*) GWEN_ListIterator_Data((GWEN_LIST_ITERATOR*)li);
318 }
319 
320 
321 
324  assert(li);
326 }
327 
328 
329 
330 unsigned int
332  assert(li);
334 }
335 
336 
337 
340 
341  it=GWEN_StringList2_First(sl2);
342  if (it) {
343  const char *t;
344  int i;
345 
347  i=0;
348  while(t) {
349  fprintf(stderr, "String %d: \"%s\" [%d]\n", i, t,
352  }
354  }
355  else {
356  fprintf(stderr, "Empty string list.\n");
357  }
358 }
359 
360 
361 
362 
363 
364 
365 
366 
367