Ignore machine-check MSRs
[freebsd-src/fkvm-freebsd.git] / contrib / gperf / src / iterator.cc
blobca66bbb8aca48a03e5a5cbbeb9c4ed3f2a6313f3
1 /* Provides an Iterator for keyword characters.
2 Copyright (C) 1989-1998, 2000 Free Software Foundation, Inc.
3 written by Douglas C. Schmidt (schmidt@ics.uci.edu)
5 This file is part of GNU GPERF.
7 GNU GPERF is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
10 any later version.
12 GNU GPERF is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU GPERF; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
21 #include "iterator.h"
23 #include <ctype.h>
24 #include "trace.h"
26 /* Constructor for Iterator. */
28 Iterator::Iterator (const char *s, int lo, int hi, int word_end, int bad_val, int key_end)
30 T (Trace t ("Iterator::Iterator");)
31 end = key_end;
32 error_value = bad_val;
33 end_word = word_end;
34 str = s;
35 hi_bound = hi;
36 lo_bound = lo;
39 /* Provide an Iterator, returning the ``next'' value from
40 the list of valid values given in the constructor. */
42 int
43 Iterator::operator() (void)
45 T (Trace t ("Iterator::operator()");)
46 /* Variables to record the Iterator's status when handling ranges, e.g., 3-12. */
48 static int size;
49 static int curr_value;
50 static int upper_bound;
52 if (size)
54 if (++curr_value >= upper_bound)
55 size = 0;
56 return curr_value;
58 else
60 while (*str)
61 switch (*str)
63 default: return error_value;
64 case ',': str++; break;
65 case '$': str++; return end_word;
66 case '0': case '1': case '2': case '3': case '4':
67 case '5': case '6': case '7': case '8': case '9':
68 for (curr_value = 0; isdigit ((unsigned char)(*str)); str++)
69 curr_value = curr_value * 10 + (*str - '0');
71 if (*str == '-')
74 for (size = 1, upper_bound = 0;
75 isdigit ((unsigned char)(*++str));
76 upper_bound = upper_bound * 10 + (*str - '0'));
78 if (upper_bound <= curr_value || upper_bound > hi_bound)
79 return error_value;
81 return curr_value >= lo_bound && curr_value <= hi_bound
82 ? curr_value : error_value;
85 return end;