xref: /freebsd/contrib/tcpdump/netdissect-ctype.h (revision ee67461e56828dd1f8de165947ba83f6d9148a87)
1*ee67461eSJoseph Mingrone /*
2*ee67461eSJoseph Mingrone  * Copyright (c) 1988-1997
3*ee67461eSJoseph Mingrone  *	The Regents of the University of California.  All rights reserved.
4*ee67461eSJoseph Mingrone  *
5*ee67461eSJoseph Mingrone  * Copyright (c) 1998-2012  Michael Richardson <mcr@tcpdump.org>
6*ee67461eSJoseph Mingrone  *      The TCPDUMP project
7*ee67461eSJoseph Mingrone  *
8*ee67461eSJoseph Mingrone  * Redistribution and use in source and binary forms, with or without
9*ee67461eSJoseph Mingrone  * modification, are permitted provided that: (1) source code distributions
10*ee67461eSJoseph Mingrone  * retain the above copyright notice and this paragraph in its entirety, (2)
11*ee67461eSJoseph Mingrone  * distributions including binary code include the above copyright notice and
12*ee67461eSJoseph Mingrone  * this paragraph in its entirety in the documentation or other materials
13*ee67461eSJoseph Mingrone  * provided with the distribution, and (3) all advertising materials mentioning
14*ee67461eSJoseph Mingrone  * features or use of this software display the following acknowledgement:
15*ee67461eSJoseph Mingrone  * ``This product includes software developed by the University of California,
16*ee67461eSJoseph Mingrone  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
17*ee67461eSJoseph Mingrone  * the University nor the names of its contributors may be used to endorse
18*ee67461eSJoseph Mingrone  * or promote products derived from this software without specific prior
19*ee67461eSJoseph Mingrone  * written permission.
20*ee67461eSJoseph Mingrone  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
21*ee67461eSJoseph Mingrone  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
22*ee67461eSJoseph Mingrone  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23*ee67461eSJoseph Mingrone  */
24*ee67461eSJoseph Mingrone 
25*ee67461eSJoseph Mingrone #ifndef netdissect_ctype_h
26*ee67461eSJoseph Mingrone #define netdissect_ctype_h
27*ee67461eSJoseph Mingrone 
28*ee67461eSJoseph Mingrone /*
29*ee67461eSJoseph Mingrone  * Locale-independent macros for testing character properties and
30*ee67461eSJoseph Mingrone  * stripping the 8th bit from characters.
31*ee67461eSJoseph Mingrone  *
32*ee67461eSJoseph Mingrone  * Byte values outside the ASCII range are considered unprintable, so
33*ee67461eSJoseph Mingrone  * both ND_ASCII_ISPRINT() and ND_ASCII_ISGRAPH() return "false" for them.
34*ee67461eSJoseph Mingrone  *
35*ee67461eSJoseph Mingrone  * Assumed to be handed a value between 0 and 255, i.e. don't hand them
36*ee67461eSJoseph Mingrone  * a char, as those might be in the range -128 to 127.
37*ee67461eSJoseph Mingrone  */
38*ee67461eSJoseph Mingrone #define ND_ISASCII(c)		(!((c) & 0x80))	/* value is an ASCII code point */
39*ee67461eSJoseph Mingrone #define ND_ASCII_ISPRINT(c)	((c) >= 0x20 && (c) <= 0x7E)
40*ee67461eSJoseph Mingrone #define ND_ASCII_ISGRAPH(c)	((c) > 0x20 && (c) <= 0x7E)
41*ee67461eSJoseph Mingrone #define ND_ASCII_ISDIGIT(c)	((c) >= '0' && (c) <= '9')
42*ee67461eSJoseph Mingrone #define ND_TOASCII(c)		((c) & 0x7F)
43*ee67461eSJoseph Mingrone 
44*ee67461eSJoseph Mingrone /*
45*ee67461eSJoseph Mingrone  * Locale-independent macros for converting to upper or lower case.
46*ee67461eSJoseph Mingrone  *
47*ee67461eSJoseph Mingrone  * Byte values outside the ASCII range are not converted.  Byte values
48*ee67461eSJoseph Mingrone  * *in* the ASCII range are converted to byte values in the ASCII range;
49*ee67461eSJoseph Mingrone  * in particular, 'i' is upper-cased to 'I" and 'I' is lower-cased to 'i',
50*ee67461eSJoseph Mingrone  * even in Turkish locales.
51*ee67461eSJoseph Mingrone  */
52*ee67461eSJoseph Mingrone #define ND_ASCII_TOLOWER(c)	(((c) >= 'A' && (c) <= 'Z') ? (c) - 'A' + 'a' : (c))
53*ee67461eSJoseph Mingrone #define ND_ASCII_TOUPPER(c)	(((c) >= 'a' && (c) <= 'z') ? (c) - 'a' + 'A' : (c))
54*ee67461eSJoseph Mingrone 
55*ee67461eSJoseph Mingrone #endif /* netdissect-ctype.h */
56*ee67461eSJoseph Mingrone 
57