]> jfr.im git - irc/quakenet/snircd.git/blob - include/ircd_chattr.h
Initial import of 2.10.12.01
[irc/quakenet/snircd.git] / include / ircd_chattr.h
1 /*
2 * IRC - Internet Relay Chat, include/ircd_chattr.h
3 * Copyright (C) 1998 Andrea Cocito
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 1, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 /** @file
21 * @brief Character attribute definitions and arrays.
22 * @version $Id: ircd_chattr.h,v 1.3 2004/10/05 02:10:00 entrope Exp $
23 *
24 * This character set code is adapted from Nemesi's Tools Library,
25 * which gives us the prefix NTL_ on these macros.
26 */
27
28 #ifndef INCLUDED_ircd_chattr_h
29 #define INCLUDED_ircd_chattr_h
30 #ifndef INCLUDED_limits_h
31 #include <limits.h>
32 #define INCLUDED_limits_h
33 #endif
34 #ifndef INCLUDED_sys_types_h
35 #include <sys/types.h>
36 #define INCLUDED_sys_types_h
37 #endif
38
39 /*
40 * Character attribute macros
41 */
42 #define NTL_ALNUM 0x0001 /**< (NTL_ALPHA | NTL_DIGIT) */
43 #define NTL_ALPHA 0x0002 /**< (NTL_LOWER | NTL_UPPER) */
44 #define NTL_CNTRL 0x0004 /**< \\000 - \\037 == 0x00 - 0x1F */
45 #define NTL_DIGIT 0x0008 /**< 0123456789 */
46 #define NTL_GRAPH 0x0010 /**< (NTL_ALNUM | NTL_PUNCT) */
47 #define NTL_LOWER 0x0020 /**< abcdefghijklmnopqrstuvwxyz{|}~ */
48 #define NTL_PRINT 0x0040 /**< (NTL_GRAPH | ' ') */
49 #define NTL_PUNCT 0x0080 /**< !"#$%&'()*+,-./:;<=>?\@_` */
50 #define NTL_SPACE 0x0100 /**< \\011\\012\\013\\014\\015\\040 */
51 #define NTL_UPPER 0x0200 /**< ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ */
52 #define NTL_IRCCH 0x0400 /**< Channel's names charset */
53 #define NTL_IRCCL 0x0800 /**< Force toLower() in ch-name */
54 #define NTL_IRCNK 0x1000 /**< Nick names charset, aka isvalid() */
55 #define NTL_IRCUI 0x2000 /**< UserIDs charset, IRCHN plus tilde */
56 #define NTL_IRCHN 0x4000 /**< Hostnames charset (weak, RFC 1033) */
57 #define NTL_IRCIP 0x8000 /**< Numeric IPs charset (DIGIT and .) */
58 #define NTL_EOL 0x10000 /**< \\r\\n */
59 #define NTL_KTIME 0x20000 /**< Valid character for a k:line time */
60 #define NTL_CHPFX 0x40000 /**< channel prefix char # & + */
61 #define NTL_IRCIP6 0x80000 /**< Numeric IPv6 character (hex or colon) */
62
63 /*
64 * Tables used for translation and classification macros
65 */
66 /** Array mapping characters to RFC 1459 lower-case versions.
67 * Yes, the variable name lies about the encoding.
68 */
69 extern const char ToLowerTab_8859_1[];
70 /** Array mapping characters to RFC 1459 upper-case versions.
71 * Yes, the variable name lies about the encoding.
72 */
73 extern const char ToUpperTab_8859_1[];
74 /** Array mapping characters to attribute bitmasks. */
75 extern const unsigned int IRCD_CharAttrTab[];
76
77 /*
78 * Translation macros for channel name case translation
79 * NOTE: Channel names are supposed to be lower case insensitive for
80 * ISO 8859-1 character sets.
81 */
82 /** Convert a character to its lower-case equivalent. */
83 #define ToLower(c) (ToLowerTab_8859_1[(c) - CHAR_MIN])
84 /** Convert a character to its upper-case equivalent. */
85 #define ToUpper(c) (ToUpperTab_8859_1[(c) - CHAR_MIN])
86
87 /*
88 * Character classification macros
89 * NOTE: The IsUpper and IsLower macros do not apply to the complete
90 * ISO 8859-1 character set, unlike the ToUpper and ToLower macros above.
91 * IsUpper and IsLower only apply for comparisons of the US ASCII subset.
92 */
93 /** Test whether a character is alphanumeric. */
94 #define IsAlnum(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_ALNUM)
95 /** Test whether a character is alphabetic. */
96 #define IsAlpha(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_ALPHA)
97 /** Test whether a character is a digit. */
98 #define IsDigit(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_DIGIT)
99 /** Test whether a character is lower case. */
100 #define IsLower(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_LOWER)
101 /** Test whether a character is whitespace. */
102 #define IsSpace(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_SPACE)
103 /** Test whether a character is upper case. */
104 #define IsUpper(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_UPPER)
105 /** Test whether a character is a control character. */
106 #define IsCntrl(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_CNTRL)
107
108 /** Test whether a character is valid in a channel name. */
109 #define IsChannelChar(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCCH)
110 /** Test whether a character is a lower-case channel name character. */
111 #define IsChannelLower(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCCL)
112 /** Test whether a character is a channel prefix. */
113 #define IsChannelPrefix(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_CHPFX)
114 /** Test whether a character is valid in a nickname. */
115 #define IsNickChar(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCNK)
116 /** Test whether a character is valid in a userid. */
117 #define IsUserChar(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCUI)
118 /** Test whether a character is valid in a hostname. */
119 #define IsHostChar(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCHN)
120 /** Test whether a character is valid in an IPv4 address. */
121 #define IsIPChar(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCIP)
122 /** Test whether a character is valid in an IPv6 address. */
123 #define IsIP6Char(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCIP6)
124 /** Test whether a character is an end-of-line character. */
125 #define IsEol(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_EOL)
126 /** Test whether a character is valid in a K: line expiration string. */
127 #define IsKTimeChar(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_KTIME)
128
129
130 #endif /* INCLUDED_ircd_chattr_h */