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