/[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.1 - (hide annotations) (download) (as text)
Thu Oct 11 18:24:01 2001 UTC (18 years ago) by tothwolf
Branch: MAIN
File MIME type: text/x-chdr
* rfc1459.c cleaned up and renamed to irccmp.c
* rfc_casecmp() renamed to irccmp()
* rfc_ncasecmp() renamed to ircncmp()
* rfc_toupper() renamed to irctoupper()
* rfc_tolower() renamed to irctolower()
* more match.c cleanups

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

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23