/[cvs]/eggdrop1.9/src/irccmp.c
ViewVC logotype

Annotation of /eggdrop1.9/src/irccmp.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.7 - (hide annotations) (download) (as text)
Mon Feb 17 10:22:30 2003 UTC (16 years, 7 months ago) by stdarg
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +1 -1 lines
File MIME type: text/x-chdr
FILE REMOVED
* Moved irccmp to libeggdrop
* Initial support for 005 numeric

1 tothwolf 1.1 /*
2 tothwolf 1.5 * irccmp.c --
3 tothwolf 1.1 *
4 tothwolf 1.5 * heavily based on code from src/match.c in ircd-hybrid
5 tothwolf 1.1 */
6     /*
7     * Copyright (C) 1990 Jarkko Oikarinen
8 wcc 1.6 * Copyright (C) 1999, 2000, 2001, 2002, 2003 Eggheads Development Team
9 tothwolf 1.1 *
10     * This program is free software; you can redistribute it and/or
11     * modify it under the terms of the GNU General Public License
12     * as published by the Free Software Foundation; either version 2
13     * of the License, or (at your option) any later version.
14     *
15     * This program is distributed in the hope that it will be useful,
16     * but WITHOUT ANY WARRANTY; without even the implied warranty of
17     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18     * GNU General Public License for more details.
19     *
20     * You should have received a copy of the GNU General Public License
21     * along with this program; if not, write to the Free Software
22     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23     */
24     /*
25     * This code was more or less cloned from the ircd-hybrid 5.3 source.
26     * The original code was written by Otto Harkoonen and even though it
27     * it not entirely in synch with section 2.2 of RFC1459 in that it
28     * additionally defines carat as an uppercase version of tilde, it's
29     * what is in the servers themselves so we're going with it this way.
30     *
31     * If for some reason someone who maintains the source for ircd decides
32     * to change the code to be completely RFC compliant, the change here
33     * would be absolutely miniscule.
34     *
35     * BTW, since carat characters are allowed in nicknames and tildes are
36     * not, I stronly suggest that people convert to uppercase when doing
37     * comparisons or creation of hash elements (which tcl laughably calls
38     * arrays) to avoid making entries with impossible nicknames in them.
39     *
40     * --+ Dagmar
41     */
42 tothwolf 1.5
43     #ifndef lint
44 stdarg 1.7 static const char rcsid[] = "$Id: irccmp.c,v 1.6 2003/01/02 21:33:16 wcc Exp $";
45 tothwolf 1.5 #endif
46 tothwolf 1.1
47     /* prototypes */
48     #include "irccmp.h"
49 tothwolf 1.3
50     #include "debug.h" /* assert */
51 tothwolf 1.1
52    
53     /*
54     * irccmp - case insensitive comparison of two 0 terminated strings.
55     *
56     * returns 0, if s1 equal to s2
57     * <0, if s1 lexicographically less than s2
58     * >0, if s1 lexicographically greater than s2
59     */
60     int _irccmp(const char *s1, const char *s2)
61     {
62     const unsigned char* str1 = (const unsigned char*) s1;
63     const unsigned char* str2 = (const unsigned char*) s2;
64     int res;
65 tothwolf 1.2 assert(0 != s1);
66     assert(0 != s2);
67 tothwolf 1.1
68     while ((res = ToUpper(*str1) - ToUpper(*str2)) == 0) {
69     if (*str1 == '\0')
70     return 0;
71     str1++;
72     str2++;
73     }
74     return (res);
75     }
76    
77     int _ircncmp(const char* s1, const char *s2, int n)
78     {
79     const unsigned char* str1 = (const unsigned char*) s1;
80     const unsigned char* str2 = (const unsigned char*) s2;
81     int res;
82 tothwolf 1.2 assert(0 != s1);
83     assert(0 != s2);
84 tothwolf 1.1
85     while ((res = ToUpper(*str1) - ToUpper(*str2)) == 0) {
86     str1++;
87     str2++;
88     n--;
89     if (n == 0 || (*str1 == '\0' && *str2 == '\0'))
90     return 0;
91     }
92     return (res);
93     }
94    
95     int _irctolower(int c)
96     {
97     return ToLower(c);
98     }
99    
100     int _irctoupper(int c)
101     {
102     return ToUpper(c);
103     }
104    
105     const unsigned char ToLowerTab[] = {
106     0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,
107     0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14,
108     0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
109     0x1e, 0x1f,
110     ' ', '!', '"', '#', '$', '%', '&', 0x27, '(', ')',
111     '*', '+', ',', '-', '.', '/',
112     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
113     ':', ';', '<', '=', '>', '?',
114     '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
115     'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
116     't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
117     '_',
118     '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
119     'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
120     't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
121     0x7f,
122     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
123     0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
124     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
125     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
126     0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9,
127     0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
128     0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
129     0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
130     0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
131     0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
132     0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
133     0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
134     0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
135     0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
136     0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
137     0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
138     };
139    
140     const unsigned char ToUpperTab[] = {
141     0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa,
142     0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13, 0x14,
143     0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
144     0x1e, 0x1f,
145     ' ', '!', '"', '#', '$', '%', '&', 0x27, '(', ')',
146     '*', '+', ',', '-', '.', '/',
147     '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
148     ':', ';', '<', '=', '>', '?',
149     '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
150     'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
151     'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^',
152     0x5f,
153     '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
154     'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
155     'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^',
156     0x7f,
157     0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
158     0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
159     0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
160     0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
161     0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9,
162     0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
163     0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9,
164     0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
165     0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9,
166     0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
167     0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9,
168     0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
169     0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
170     0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
171     0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
172     0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
173     };

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23