Mercurial > hg-old > index.cgi
comparison lwlib/lw_stringlist.c @ 326:2eb058346cad
Added string module and expanded stringlist module
author | lost |
---|---|
date | Sat, 13 Feb 2010 05:21:20 +0000 |
parents | be63116281b0 |
children | 80826bf2827b |
comparison
equal
deleted
inserted
replaced
325:619fd6ad4ab9 | 326:2eb058346cad |
---|---|
19 this program. If not, see <http://www.gnu.org/licenses/>. | 19 this program. If not, see <http://www.gnu.org/licenses/>. |
20 */ | 20 */ |
21 | 21 |
22 #include <config.h> | 22 #include <config.h> |
23 | 23 |
24 #include <stdlib.h> | |
25 | |
24 #define ___lw_stringlist_c_seen___ | 26 #define ___lw_stringlist_c_seen___ |
25 #include "lw_stringlist.h" | 27 #include "lw_stringlist.h" |
26 | 28 #include "lw_string.h" |
27 #include "lw_alloc.h" | 29 #include "lw_alloc.h" |
28 | 30 |
29 lw_stringlist_t lw_stringlist_create(void) | 31 lw_stringlist_t lw_stringlist_create(void) |
30 { | 32 { |
31 return lw_alloc(sizeof(struct lw_stringlist_priv)); | 33 return lw_alloc(sizeof(struct lw_stringlist_priv)); |
41 lw_free(S -> strings[i]); | 43 lw_free(S -> strings[i]); |
42 } | 44 } |
43 lw_free(S); | 45 lw_free(S); |
44 } | 46 } |
45 } | 47 } |
48 | |
49 void lw_stringlist_addstring(lw_stringlist_t S, char *str) | |
50 { | |
51 S -> strings = lw_realloc(S -> strings, sizeof(char *) * (S -> nstrings + 1)); | |
52 S -> strings[S -> nstrings] = lw_strdup(str); | |
53 S -> nstrings++; | |
54 } | |
55 | |
56 void lw_stringlist_reset(lw_stringlist_t S) | |
57 { | |
58 S -> cstring = 0; | |
59 } | |
60 | |
61 char *lw_stringlist_current(lw_stringlist_t S) | |
62 { | |
63 if (S -> cstring >= S -> nstrings) | |
64 return NULL; | |
65 return S -> strings[S -> cstring]; | |
66 } | |
67 | |
68 char *lw_stringlist_next(lw_stringlist_t S) | |
69 { | |
70 S -> cstring++; | |
71 return lw_stringlist_current(S); | |
72 } | |
73 | |
74 int lw_stringlist_nstrings(lw_stringlist_t S) | |
75 { | |
76 return S -> nstrings; | |
77 } |