1 /* A set of byte positions.
2 Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc.
3 Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
4 and Bruno Haible <bruno@clisp.org>.
6 This file is part of GNU GPERF.
8 GNU GPERF is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU GPERF is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
24 #include "positions.h"
27 #include <stdlib.h> /* declares exit() */
30 /* ---------------------------- Class Positions ---------------------------- */
32 /* Set operations. Assumes the array is in reverse order. */
35 Positions::contains (int pos) const
37 unsigned int count = _size;
38 const int *p = _positions + _size - 1;
40 for (; count > 0; p--, count--)
51 Positions::add (int pos)
55 unsigned int count = _size;
57 if (count == MAX_SIZE)
59 fprintf (stderr, "Positions::add internal error: overflow\n");
63 int *p = _positions + _size - 1;
65 for (; count > 0; p--, count--)
69 fprintf (stderr, "Positions::add internal error: duplicate\n");
81 Positions::remove (int pos)
85 unsigned int count = _size;
88 int *p = _positions + _size - 1;
119 fprintf (stderr, "Positions::remove internal error: not found\n");
123 /* Output in external syntax. */
125 Positions::print () const
132 bool seen_LASTCHAR = false;
133 unsigned int count = _size;
134 const int *p = _positions + _size - 1;
136 for (; count > 0; p--)
140 seen_LASTCHAR = true;
145 printf ("%d", *p + 1);
146 if (count > 0 && p[-1] == *p + 1)
154 while (count > 0 && p[-1] == *p + 1);
155 printf ("%d", *p + 1);
169 /* ------------------------------------------------------------------------- */
173 #define INLINE /* not inline */
174 #include "positions.icc"
177 #endif /* not defined __OPTIMIZE__ */