2 ** LCLint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2000 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 lclint: lclint-request@cs.virginia.edu
21 ** To report a bug: lclint-bug@cs.virginia.edu
22 ** For more information: http://lclint.cs.virginia.edu
27 ** based on list_template.c
29 ** where T has T_equal (or change this) and T_unparse
32 # include "lclintMacros.nf"
38 return cstringList_undefined;
41 static /*@notnull@*/ cstringList
42 cstringList_newEmpty (void)
44 cstringList s = (cstringList) dmalloc (sizeof (*s));
47 s->nspace = cstringListBASESIZE;
48 s->elements = (cstring *) dmalloc (sizeof (*s->elements) * cstringListBASESIZE);
54 cstringList_grow (/*@notnull@*/ cstringList s)
59 s->nspace += cstringListBASESIZE;
61 newelements = (cstring *) dmalloc (sizeof (*newelements)
62 * (s->nelements + s->nspace));
65 if (newelements == (cstring *) 0)
67 llfatalerror (cstring_makeLiteral ("cstringList_grow: out of memory!"));
70 for (i = 0; i < s->nelements; i++)
72 newelements[i] = s->elements[i];
76 s->elements = newelements;
79 cstringList cstringList_single (/*@keep@*/ cstring el)
81 cstringList s = cstringList_new ();
82 s = cstringList_add (s, el);
86 cstringList cstringList_add (cstringList s, /*@keep@*/ cstring el)
88 if (!cstringList_isDefined (s))
90 s = cstringList_newEmpty ();
99 s->elements[s->nelements] = el;
106 cstringList_unparse (cstringList s)
108 return cstringList_unparseSep (s, cstring_makeLiteralTemp (", "));
112 cstringList_unparseSep (cstringList s, cstring sep)
114 cstring st = cstring_undefined;
116 if (cstringList_isDefined (s))
120 for (i = 0; i < s->nelements; i++)
124 st = cstring_copy (s->elements[i]);
127 st = message ("%q%s%s", st, sep, s->elements[i]);
135 cstringList_printSpaced (cstringList s, int indent, int gap, int linelen)
137 if (cstringList_isDefined (s))
139 cstring line = cstring_undefined;
140 cstring istring = cstring_fill (cstring_undefined, indent);
141 cstring gstring = cstring_fill (cstring_undefined, gap);
147 ** find the longest string
150 for (i = 0; i < s->nelements; i++)
152 int len = cstring_length (s->elements[i]);
160 numcol = (linelen - indent) / (longest + gap);
167 for (i = 0; i < s->nelements; i++)
176 line = message ("%s%q", istring,
177 cstring_fill (s->elements[i], longest));
181 line = message ("%q%s%q", line, gstring,
182 cstring_fill (s->elements[i], longest));
187 cstring_free (istring);
188 cstring_free (gstring);
193 cstringList_unparseAbbrev (cstringList s)
195 cstring st = cstring_undefined;
197 if (cstringList_isDefined (s))
201 for (i = 0; i < s->nelements; i++)
205 st = cstring_copy (s->elements[i]);
207 else if (i > 3 && s->nelements > 5)
209 st = message ("%q, ...", st);
214 st = message ("%q, %s", st, s->elements[i]);
223 cstringList_free (cstringList s)
225 if (cstringList_isDefined (s))
233 cstringList_alphabetize (cstringList s)
235 if (cstringList_isDefined (s))
238 qsort (s->elements, (size_t) s->nelements,
239 sizeof (*s->elements), (int (*)(const void *, const void *)) cstring_xcompare);