xref: /netbsd-src/lib/libc/regex/utils.h (revision 185787c65b8709f0ad40171a97d99c3444434e22)
1*185787c6Schristos /*	$NetBSD: utils.h,v 1.9 2021/04/22 19:20:24 christos Exp $	*/
2eb7c1594Sagc 
3eb7c1594Sagc /*-
41ee269c3Schristos  * SPDX-License-Identifier: BSD-3-Clause
51ee269c3Schristos  *
61ee269c3Schristos  * Copyright (c) 1992, 1993, 1994 Henry Spencer.
7eb7c1594Sagc  * Copyright (c) 1992, 1993, 1994
8eb7c1594Sagc  *	The Regents of the University of California.  All rights reserved.
9eb7c1594Sagc  *
10eb7c1594Sagc  * This code is derived from software contributed to Berkeley by
11eb7c1594Sagc  * Henry Spencer.
12eb7c1594Sagc  *
13eb7c1594Sagc  * Redistribution and use in source and binary forms, with or without
14eb7c1594Sagc  * modification, are permitted provided that the following conditions
15eb7c1594Sagc  * are met:
16eb7c1594Sagc  * 1. Redistributions of source code must retain the above copyright
17eb7c1594Sagc  *    notice, this list of conditions and the following disclaimer.
18eb7c1594Sagc  * 2. Redistributions in binary form must reproduce the above copyright
19eb7c1594Sagc  *    notice, this list of conditions and the following disclaimer in the
20eb7c1594Sagc  *    documentation and/or other materials provided with the distribution.
21eb7c1594Sagc  * 3. Neither the name of the University nor the names of its contributors
22eb7c1594Sagc  *    may be used to endorse or promote products derived from this software
23eb7c1594Sagc  *    without specific prior written permission.
24eb7c1594Sagc  *
25eb7c1594Sagc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26eb7c1594Sagc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27eb7c1594Sagc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28eb7c1594Sagc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29eb7c1594Sagc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30eb7c1594Sagc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31eb7c1594Sagc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32eb7c1594Sagc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33eb7c1594Sagc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34eb7c1594Sagc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35eb7c1594Sagc  * SUCH DAMAGE.
36eb7c1594Sagc  *
37eb7c1594Sagc  *	@(#)utils.h	8.3 (Berkeley) 3/20/94
381ee269c3Schristos  * $FreeBSD: head/lib/libc/regex/utils.h 341838 2018-12-12 04:23:00Z yuripv $
397c6ed81dScgd  */
407c6ed81dScgd 
41e37fce91Schristos #ifdef NLS
42e37fce91Schristos #include <wchar.h>
43e37fce91Schristos #include <wctype.h>
44e37fce91Schristos #else
45e37fce91Schristos #include <ctype.h>
46*185787c6Schristos #define wint_t regex_wint_t
47*185787c6Schristos #define mbstate_t regex_mbstate_t
48*185787c6Schristos #define wctype_t regex_wctype_t
49e37fce91Schristos typedef short wint_t;
50e37fce91Schristos typedef char mbstate_t;
51e37fce91Schristos typedef short wctype_t;
52e37fce91Schristos #define iswupper(a) isupper(a)
53e37fce91Schristos #define iswlower(a) islower(a)
54e37fce91Schristos #define iswalpha(a) isalpha(a)
55e37fce91Schristos #define iswalnum(a) isalnum(a)
56e37fce91Schristos #define towupper(a) toupper(a)
57e37fce91Schristos #define towlower(a) tolower(a)
58e37fce91Schristos extern wctype_t __regex_wctype(const char *);
59e37fce91Schristos extern int __regex_iswctype(wint_t, wctype_t);
60e37fce91Schristos #define wctype(s) __regex_wctype(s)
61e37fce91Schristos #define iswctype(c, t) __regex_iswctype((c), (t))
62e37fce91Schristos #endif
63e37fce91Schristos 
64b90ff831Sjtc /* utility definitions */
65b90ff831Sjtc #define	DUPMAX		_POSIX2_RE_DUP_MAX	/* xxx is this right? */
66b90ff831Sjtc #define	INFINITY	(DUPMAX + 1)
671ee269c3Schristos 
681ee269c3Schristos #define	NC_MAX		(CHAR_MAX - CHAR_MIN + 1)
691ee269c3Schristos #define	NC		((MB_CUR_MAX) == 1 ? (NC_MAX) : (128))
706931099eSjtc typedef unsigned char uch;
71b90ff831Sjtc 
723ed83140Sjtc /* switch off assertions (if not already off) if no REDEBUG */
73b90ff831Sjtc #ifndef REDEBUG
74b90ff831Sjtc #ifndef NDEBUG
75b90ff831Sjtc #define	NDEBUG	/* no assertions please */
76b90ff831Sjtc #endif
77b90ff831Sjtc #endif
78b90ff831Sjtc #include <assert.h>
793ed83140Sjtc 
803ed83140Sjtc /* for old systems with bcopy() but no memmove() */
813ed83140Sjtc #ifdef USEBCOPY
823ed83140Sjtc #define	memmove(d, s, c)	bcopy(s, d, c)
833ed83140Sjtc #endif
84