2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2002 University of Virginia,
4 ** Massachusetts Institute of Technology
6 ** This program is free software; you can redistribute it and/or modify it
7 ** under the terms of the GNU General Public License as published by the
8 ** Free Software Foundation; either version 2 of the License, or (at your
9 ** option) any later version.
11 ** This program is distributed in the hope that it will be useful, but
12 ** WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 ** General Public License for more details.
16 ** The GNU General Public License is available from http://www.gnu.org/ or
17 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
18 ** MA 02111-1307, USA.
20 ** For information on splint: info@splint.org
21 ** To report a bug: splint-bug@splint.org
22 ** For more information: http://www.splint.org
27 ** based on list_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "splintMacros.nf"
38 return cstringSList_undefined;
41 static /*@notnull@*/ cstringSList
42 cstringSList_newEmpty (void)
44 cstringSList s = (cstringSList) dmalloc (sizeof (*s));
47 s->nspace = cstringSListBASESIZE;
48 s->elements = (cstring *) dmalloc (sizeof (*s->elements) * cstringSListBASESIZE);
54 cstringSList_grow (/*@notnull@*/ cstringSList s)
59 s->nspace += cstringSListBASESIZE;
61 newelements = (cstring *) dmalloc (sizeof (*newelements)
62 * (s->nelements + s->nspace));
65 if (newelements == (cstring *) 0)
67 llfatalerror (cstring_makeLiteral ("cstringSList_grow: out of memory!"));
70 for (i = 0; i < s->nelements; i++)
72 newelements[i] = s->elements[i];
76 s->elements = newelements;
79 cstringSList cstringSList_single (/*@exposed@*/ cstring el)
81 cstringSList s = cstringSList_new ();
82 s = cstringSList_add (s, el);
86 cstringSList cstringSList_add (cstringSList s, /*@exposed@*/ cstring el)
88 if (!cstringSList_isDefined (s))
90 s = cstringSList_newEmpty ();
95 cstringSList_grow (s);
99 s->elements[s->nelements] = el;
106 cstringSList_get (cstringSList s, int index)
108 llassert (s != NULL);
109 llassert (index < s->nelements);
110 return s->elements[index];
114 cstringSList_unparse (cstringSList s)
116 return cstringSList_unparseSep (s, cstring_makeLiteralTemp (", "));
120 cstringSList_unparseSep (cstringSList s, cstring sep)
122 cstring st = cstring_undefined;
124 if (cstringSList_isDefined (s))
128 for (i = 0; i < s->nelements; i++)
132 st = cstring_copy (s->elements[i]);
135 st = message ("%q%s%s", st, sep, s->elements[i]);
143 cstringSList_printSpaced (cstringSList s, size_t indent, size_t gap, int linelen)
145 if (cstringSList_isDefined (s))
147 cstring line = cstring_undefined;
148 cstring istring = cstring_fill (cstring_undefined, indent);
149 cstring gstring = cstring_fill (cstring_undefined, gap);
155 ** find the longest string
158 for (i = 0; i < s->nelements; i++)
160 size_t len = cstring_length (s->elements[i]);
168 numcol = (linelen - indent) / (longest + gap);
175 for (i = 0; i < s->nelements; i++)
184 line = message ("%s%q", istring,
185 cstring_fill (s->elements[i], longest));
189 line = message ("%q%s%q", line, gstring,
190 cstring_fill (s->elements[i], longest));
195 cstring_free (istring);
196 cstring_free (gstring);
201 cstringSList_unparseAbbrev (cstringSList s)
203 cstring st = cstring_undefined;
205 if (cstringSList_isDefined (s))
209 for (i = 0; i < s->nelements; i++)
213 st = cstring_copy (s->elements[i]);
215 else if (i > 3 && s->nelements > 5)
217 st = message ("%q, ...", st);
222 st = message ("%q, %s", st, s->elements[i]);
231 cstringSList_free (cstringSList s)
233 if (cstringSList_isDefined (s))
236 ** A modification of observer message is reported here, since
237 ** *s->elements is an observer. But sfree doesn't REALLY modify
238 ** the value of this object.
250 cstringSList_alphabetize (cstringSList s)
252 if (cstringSList_isDefined (s))
255 qsort (s->elements, (size_t) s->nelements,
256 sizeof (*s->elements), (int (*)(const void *, const void *)) cstring_xcompare);