Author: Bleep <tomh@inxpress.net>
[ircu2.10.12-pk.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  * $Id$
20  *
21  */
22 /*
23  * All the code in common.h/common.c is taken from the NTL
24  * (Nemesi's Tools Library), adapted for ircu's character set
25  * and thereafter released under GNU GPL, from there comes the
26  * NTL_ prefix of all macro and object names.
27  * Removed isXdigit() to leave space to other char sets in the
28  * bitmap, should give the same results as isxdigit() on any
29  * implementation and isn't used in IRC anyway.
30  */
31 #ifndef INCLUDED_ircd_chattr_h
32 #define INCLUDED_ircd_chattr_h
33 #ifndef INCLUDED_limits_h
34 #include <limits.h>
35 #define INCLUDED_limits_h
36 #endif
37 #ifndef INCLUDED_sys_types_h
38 #include <sys/types.h>
39 #define INCLUDED_sys_types_h
40 #endif
41
42 /*
43  * Character attribute macros
44  */
45 #define NTL_ALNUM   0x0001  /* (NTL_ALPHA | NTL_DIGIT)             */
46 #define NTL_ALPHA   0x0002  /* (NTL_LOWER | NTL_UPPER)             */
47 #define NTL_CNTRL   0x0004  /* \000 - \037 == 0x00 - 0x1F          */
48 #define NTL_DIGIT   0x0008  /* 0123456789                          */
49 #define NTL_GRAPH   0x0010  /* (NTL_ALNUM | NTL_PUNCT)             */
50 #define NTL_LOWER   0x0020  /* abcdefghijklmnopqrstuvwxyz{|}~      */
51 #define NTL_PRINT   0x0040  /* (NTL_GRAPH | ' ')                   */
52 #define NTL_PUNCT   0x0080  /* !"#$%&'()*+,-./:;<=>?@_`            */
53 #define NTL_SPACE   0x0100  /* \011\012\013\014\015\040            */
54 #define NTL_UPPER   0x0200  /* ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^      */
55 #define NTL_IRCCH   0x0400  /* Channel's names charset             */
56 #define NTL_IRCCL   0x0800  /* Force toLower() in ch-name          */
57 #define NTL_IRCNK   0x1000  /* Nick names charset, aka isvalid()   */
58 #define NTL_IRCUI   0x2000  /* UserIDs charset, IRCHN plus tilde   */
59 #define NTL_IRCHN   0x4000  /* Hostnames charset (weak, RFC 1033)  */
60 #define NTL_IRCIP   0x8000  /* Numeric IPs charset (DIGIT and .)   */
61 #define NTL_EOL    0x10000  /* \r\n                                */
62 #define NTL_KTIME  0x20000  /* Valid character for a k:line time   */
63 #define NTL_CHPFX  0x40000  /* channel prefix char # & +           */
64
65 /*
66  * Tables used for translation and classification macros
67  */
68 extern const char ToLowerTab_8859_1[];
69 extern const char ToUpperTab_8859_1[];
70 extern const unsigned int  IRCD_CharAttrTab[];
71
72 /*
73  * Translation macros for channel name case translation
74  * NOTE: Channel names are supposed to be lower case insensitive for
75  * ISO 8859-1 character sets.
76  */
77 #define ToLower(c)        (ToLowerTab_8859_1[(c) - CHAR_MIN])
78 #define ToUpper(c)        (ToUpperTab_8859_1[(c) - CHAR_MIN])
79
80 /*
81  * Character classification macros
82  * NOTE: The IsUpper and IsLower macros do not apply to the complete
83  * ISO 8859-1 character set, unlike the ToUpper and ToLower macros above.
84  * IsUpper and IsLower only apply for comparisons of the US ASCII subset.
85  */
86 #define IsAlnum(c)         (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_ALNUM)
87 #define IsAlpha(c)         (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_ALPHA)
88 #define IsDigit(c)         (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_DIGIT)
89 #define IsLower(c)         (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_LOWER)
90 #define IsSpace(c)         (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_SPACE)
91 #define IsUpper(c)         (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_UPPER)
92 #define IsCntrl(c)         (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_CNTRL)
93
94 #define IsChannelChar(c)   (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCCH)
95 #define IsChannelLower(c)  (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCCL)
96 #define IsChannelPrefix(c) (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_CHPFX)
97 #define IsNickChar(c)      (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCNK)
98 #define IsUserChar(c)      (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCUI)
99 #define IsHostChar(c)      (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCHN)
100 #define IsIPChar(c)        (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_IRCIP)
101 #define IsEol(c)           (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_EOL)
102 #define IsKTimeChar(c)     (IRCD_CharAttrTab[(c) - CHAR_MIN] & NTL_KTIME)
103
104
105 #endif /* INCLUDED_ircd_chattr_h */