386BSD 0.0 release
[unix-history] / usr / src / usr.bin / groff / libgroff / cset.cc
CommitLineData
af5ae739
WJ
1// -*- C++ -*-
2/* Copyright (C) 1989, 1990 Free Software Foundation, Inc.
3 Written by James Clark (jjc@jclark.uucp)
4
5This file is part of groff.
6
7groff is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 1, or (at your option) any later
10version.
11
12groff is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License along
18with groff; see the file LICENSE. If not, write to the Free Software
19Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21#include <ctype.h>
22#include "cset.h"
23
24cset csalpha(CSET_BUILTIN);
25cset csupper(CSET_BUILTIN);
26cset cslower(CSET_BUILTIN);
27cset csdigit(CSET_BUILTIN);
28cset csxdigit(CSET_BUILTIN);
29cset csspace(CSET_BUILTIN);
30cset cspunct(CSET_BUILTIN);
31cset csalnum(CSET_BUILTIN);
32cset csprint(CSET_BUILTIN);
33cset csgraph(CSET_BUILTIN);
34cset cscntrl(CSET_BUILTIN);
35
36#define ISASCII(c) isascii(c)
37#if 0
38#define ISASCII(c) 1 /* use this is you have an ANSI ctype.h */
39#endif
40
41void cset::clear()
42{
43 char *p = v;
44 for (int i = 0; i <= UCHAR_MAX; i++)
45 p[i] = 0;
46}
47
48cset::cset()
49{
50 clear();
51}
52
53cset::cset(const char *s)
54{
55 clear();
56 while (*s)
57 v[(unsigned char)*s++] = 1;
58}
59
60cset::cset(const unsigned char *s)
61{
62 clear();
63 while (*s)
64 v[*s++] = 1;
65}
66
67cset::cset(cset_builtin)
68{
69 // these are initialised by cset_init::cset_init()
70}
71
72cset &cset::operator|=(const cset &cs)
73{
74 for (int i = 0; i <= UCHAR_MAX; i++)
75 if (cs.v[i])
76 v[i] = 1;
77 return *this;
78}
79
80
81int cset_init::initialised = 0;
82
83cset_init::cset_init()
84{
85 if (initialised)
86 return;
87 initialised = 1;
88 for (int i = 0; i <= UCHAR_MAX; i++) {
89 csalpha.v[i] = ISASCII(i) && isalpha(i);
90 csupper.v[i] = ISASCII(i) && isupper(i);
91 cslower.v[i] = ISASCII(i) && islower(i);
92 csdigit.v[i] = ISASCII(i) && isdigit(i);
93 csxdigit.v[i] = ISASCII(i) && isxdigit(i);
94 csspace.v[i] = ISASCII(i) && isspace(i);
95 cspunct.v[i] = ISASCII(i) && ispunct(i);
96 csalnum.v[i] = ISASCII(i) && isalnum(i);
97 csprint.v[i] = ISASCII(i) && isprint(i);
98 csgraph.v[i] = ISASCII(i) && isgraph(i);
99 cscntrl.v[i] = ISASCII(i) && iscntrl(i);
100 }
101}