2 ** Splint - annotation-assisted static program checker
3 ** Copyright (C) 1994-2003 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
25 ** messageLog.c (from slist_template.c)
28 # include "splintMacros.nf"
34 messageLog s = (messageLog) dmalloc (sizeof (*s));
37 s->nspace = messageLogBASESIZE;
38 s->elements = (msgentry *) dmalloc (sizeof (*s->elements) * messageLogBASESIZE);
43 static /*@only@*/ msgentry
44 msgentry_create (fileloc loc, cstring mess)
46 msgentry msg = (msgentry) dmalloc (sizeof (*msg));
48 msg->loc = fileloc_copy (loc);
49 msg->msg = cstring_copy (mess);
55 static /*@unused@*/ cstring msgentry_unparse (msgentry msg) /*@*/
57 return message ("%q:%s", fileloc_unparse (msg->loc), msg->msg);
61 static void msgentry_free (/*@only@*/ msgentry msg)
63 fileloc_free (msg->loc);
64 cstring_free (msg->msg);
69 ** returns TRUE if m1 < m2
73 msgentry_lessthan (msgentry m1, msgentry m2)
75 return (fileloc_lessthan (m1->loc, m2->loc)
76 || (fileloc_equal (m1->loc, m2->loc)
77 && (cstring_lessthan (m1->msg, m2->msg))));
81 msgentry_equal (msgentry m1, msgentry m2)
83 return (fileloc_equal (m1->loc, m2->loc) &&
84 cstring_equal (m1->msg, m2->msg));
88 ** returns highest index of element less than msg
92 messageLog_index (messageLog s, msgentry msg)
97 llassert (messageLog_isDefined (s));
99 high = s->nelements - 1;
101 for (low = high; low >= 0; low--)
103 if (msgentry_lessthan (s->elements[low], msg))
113 int mid = (low + high + 1) / 2;
115 if (msgentry_lessthan (s->elements[mid], msg)) /* mid < msg */
117 if (high == mid) break;
122 if (low == mid) break;
132 messageLog_grow (/*@notnull@*/ messageLog s)
135 msgentry *newelements;
137 s->nspace += messageLogBASESIZE;
138 newelements = (msgentry *) dmalloc (sizeof (*newelements) * (s->nelements + s->nspace));
140 for (i = 0; i < s->nelements; i++)
142 newelements[i] = s->elements[i];
146 s->elements = newelements;
149 bool messageLog_add (messageLog s, fileloc fl, cstring mess)
151 msgentry msg = msgentry_create (fl, mess);
154 llassert (messageLog_isDefined (s));
156 ind = messageLog_index (s, msg);
158 if (ind + 1 < s->nelements)
160 if (msgentry_equal (msg, s->elements[ind + 1]))
167 if (s->nspace <= 0) {
171 for (i = s->nelements; i > ind + 1; i--)
173 s->elements[i] = s->elements[i-1];
176 s->elements[ind + 1] = msg;
184 messageLog_unparse (messageLog s)
187 cstring st = cstring_makeLiteral ("[");
189 if (messageLog_isDefined (s))
191 for (i = 0; i < s->nelements; i++)
195 st = message ("%q %q", st, fileloc_unparseDirect (s->elements[i]->loc));
198 st = message ("%q, %q", st, fileloc_unparseDirect (s->elements[i]->loc));
202 st = message ("%q ]", st);
207 messageLog_free (messageLog s)
213 for (i = 0; i < s->nelements; i++)
215 msgentry_free (s->elements[i]);