* Makefile.in (ENVSETUP): Don't assume POSIX make semantics for
[s-roff.git] / src / libs / libgroff / cset.cc
blobe4845c11012ec3adce724219ef524c1d9599798a
1 // -*- C++ -*-
2 /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.com)
5 This file is part of groff.
7 groff is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 groff is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License along
18 with groff; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #include <ctype.h>
22 #include "cset.h"
24 cset csalpha(CSET_BUILTIN);
25 cset csupper(CSET_BUILTIN);
26 cset cslower(CSET_BUILTIN);
27 cset csdigit(CSET_BUILTIN);
28 cset csxdigit(CSET_BUILTIN);
29 cset csspace(CSET_BUILTIN);
30 cset cspunct(CSET_BUILTIN);
31 cset csalnum(CSET_BUILTIN);
32 cset csprint(CSET_BUILTIN);
33 cset csgraph(CSET_BUILTIN);
34 cset cscntrl(CSET_BUILTIN);
36 #ifdef isascii
37 #define ISASCII(c) isascii(c)
38 #else
39 #define ISASCII(c) (1)
40 #endif
42 void cset::clear()
44 char *p = v;
45 for (int i = 0; i <= UCHAR_MAX; i++)
46 p[i] = 0;
49 cset::cset()
51 clear();
54 cset::cset(const char *s)
56 clear();
57 while (*s)
58 v[(unsigned char)*s++] = 1;
61 cset::cset(const unsigned char *s)
63 clear();
64 while (*s)
65 v[*s++] = 1;
68 cset::cset(cset_builtin)
70 // these are initialised by cset_init::cset_init()
73 cset &cset::operator|=(const cset &cs)
75 for (int i = 0; i <= UCHAR_MAX; i++)
76 if (cs.v[i])
77 v[i] = 1;
78 return *this;
82 int cset_init::initialised = 0;
84 cset_init::cset_init()
86 if (initialised)
87 return;
88 initialised = 1;
89 for (int i = 0; i <= UCHAR_MAX; i++) {
90 csalpha.v[i] = ISASCII(i) && isalpha(i);
91 csupper.v[i] = ISASCII(i) && isupper(i);
92 cslower.v[i] = ISASCII(i) && islower(i);
93 csdigit.v[i] = ISASCII(i) && isdigit(i);
94 csxdigit.v[i] = ISASCII(i) && isxdigit(i);
95 csspace.v[i] = ISASCII(i) && isspace(i);
96 cspunct.v[i] = ISASCII(i) && ispunct(i);
97 csalnum.v[i] = ISASCII(i) && isalnum(i);
98 csprint.v[i] = ISASCII(i) && isprint(i);
99 csgraph.v[i] = ISASCII(i) && isgraph(i);
100 cscntrl.v[i] = ISASCII(i) && iscntrl(i);