2 * Check: a unit test framework for C
3 * Copyright (C) 2001, 2002 Arien Malec
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
21 #include "../lib/libcompat.h"
26 #include "check_list.h"
27 #include "check_error.h"
39 unsigned int max_elts;
40 int current; /* pointer to the current node */
41 int last; /* pointer to the node before END */
46 maybe_grow (List * lp)
48 if (lp->n_elts >= lp->max_elts) {
49 lp->max_elts *= LGROW;
51 (void **) erealloc (lp->data, lp->max_elts * sizeof (lp->data[0]));
56 check_list_create (void)
60 lp = (List *) emalloc (sizeof (List));
63 lp->data = (void **) emalloc (sizeof (lp->data[0]) * LINIT);
64 lp->current = lp->last = -1;
69 check_list_add_front (List * lp, void *val)
74 memmove (lp->data + 1, lp->data, lp->n_elts * sizeof lp->data[0]);
78 lp->data[lp->current] = val;
82 check_list_add_end (List * lp, void *val)
89 lp->current = lp->last;
90 lp->data[lp->current] = val;
94 check_list_at_end (List * lp)
96 if (lp->current == -1)
99 return (lp->current > lp->last);
103 check_list_front (List * lp)
105 if (lp->current == -1)
112 check_list_free (List * lp)
122 check_list_val (List * lp)
126 if (lp->current == -1 || lp->current > lp->last)
129 return lp->data[lp->current];
133 check_list_advance (List * lp)
137 if (check_list_at_end (lp))
144 check_list_apply (List * lp, void (*fp) (void *))
146 if (lp == NULL || fp == NULL)
149 for (check_list_front (lp); !check_list_at_end (lp); check_list_advance (lp))
150 fp (check_list_val (lp));