Mercurial > hg-old > index.cgi
annotate lwlib/lw_stringlist.c @ 443:a8934dfba400 3.0 3.0.1
Fixed operator precedence for *
author | lost@l-w.ca |
---|---|
date | Sat, 30 Oct 2010 15:02:57 -0600 |
parents | 33c5bc04ea67 |
children |
rev | line source |
---|---|
324 | 1 /* |
2 lw_stringlist.c | |
3 | |
4 Copyright © 2010 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #include <config.h> | |
23 | |
326 | 24 #include <stdlib.h> |
25 | |
324 | 26 #define ___lw_stringlist_c_seen___ |
27 #include "lw_stringlist.h" | |
326 | 28 #include "lw_string.h" |
324 | 29 #include "lw_alloc.h" |
30 | |
31 lw_stringlist_t lw_stringlist_create(void) | |
32 { | |
429
33c5bc04ea67
Fixed unitialized memory in lw_stringlist_create()
lost@l-w.ca
parents:
327
diff
changeset
|
33 lw_stringlist_t s; |
33c5bc04ea67
Fixed unitialized memory in lw_stringlist_create()
lost@l-w.ca
parents:
327
diff
changeset
|
34 |
33c5bc04ea67
Fixed unitialized memory in lw_stringlist_create()
lost@l-w.ca
parents:
327
diff
changeset
|
35 |
33c5bc04ea67
Fixed unitialized memory in lw_stringlist_create()
lost@l-w.ca
parents:
327
diff
changeset
|
36 s = lw_alloc(sizeof(struct lw_stringlist_priv)); |
33c5bc04ea67
Fixed unitialized memory in lw_stringlist_create()
lost@l-w.ca
parents:
327
diff
changeset
|
37 s -> strings = NULL; |
33c5bc04ea67
Fixed unitialized memory in lw_stringlist_create()
lost@l-w.ca
parents:
327
diff
changeset
|
38 s -> nstrings = 0; |
33c5bc04ea67
Fixed unitialized memory in lw_stringlist_create()
lost@l-w.ca
parents:
327
diff
changeset
|
39 s -> cstring = 0; |
33c5bc04ea67
Fixed unitialized memory in lw_stringlist_create()
lost@l-w.ca
parents:
327
diff
changeset
|
40 |
33c5bc04ea67
Fixed unitialized memory in lw_stringlist_create()
lost@l-w.ca
parents:
327
diff
changeset
|
41 return s; |
324 | 42 } |
43 | |
44 void lw_stringlist_destroy(lw_stringlist_t S) | |
45 { | |
46 if (S) | |
47 { | |
48 int i; | |
49 for (i = 0; i < S -> nstrings; i++) | |
50 { | |
51 lw_free(S -> strings[i]); | |
52 } | |
53 lw_free(S); | |
54 } | |
55 } | |
326 | 56 |
57 void lw_stringlist_addstring(lw_stringlist_t S, char *str) | |
58 { | |
59 S -> strings = lw_realloc(S -> strings, sizeof(char *) * (S -> nstrings + 1)); | |
60 S -> strings[S -> nstrings] = lw_strdup(str); | |
61 S -> nstrings++; | |
62 } | |
63 | |
64 void lw_stringlist_reset(lw_stringlist_t S) | |
65 { | |
66 S -> cstring = 0; | |
67 } | |
68 | |
69 char *lw_stringlist_current(lw_stringlist_t S) | |
70 { | |
71 if (S -> cstring >= S -> nstrings) | |
72 return NULL; | |
73 return S -> strings[S -> cstring]; | |
74 } | |
75 | |
76 char *lw_stringlist_next(lw_stringlist_t S) | |
77 { | |
78 S -> cstring++; | |
79 return lw_stringlist_current(S); | |
80 } | |
81 | |
82 int lw_stringlist_nstrings(lw_stringlist_t S) | |
83 { | |
84 return S -> nstrings; | |
85 } | |
327 | 86 |
87 lw_stringlist_t lw_stringlist_copy(lw_stringlist_t S) | |
88 { | |
89 lw_stringlist_t r; | |
90 | |
91 r = lw_alloc(sizeof(lw_stringlist_t)); | |
92 r -> nstrings = S -> nstrings; | |
93 if (S -> nstrings) | |
94 { | |
95 int i; | |
96 | |
97 r -> strings = lw_alloc(sizeof(char *) * S -> nstrings); | |
98 for (i = 0; i < S -> nstrings; i++) | |
99 { | |
100 r -> strings[i] = lw_strdup(S -> strings[i]); | |
101 } | |
102 } | |
103 return r; | |
104 } |