Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/include/alist.h
1069 views
1
/*
2
* alist.h -- resizeable arrays
3
* Copyright 1997 EPIC Software Labs
4
*/
5
6
#ifndef __alist_h__
7
#define __alist_h__
8
9
#include "irc.h"
10
#include "ircaux.h"
11
12
/*
13
* Anyone have any ideas how to optimize this further?
14
*/
15
16
#ifdef _cs_alist_hash_
17
static __inline u_32int_t cs_alist_hash (const char *s, u_32int_t *mask)
18
{
19
u_32int_t x;
20
21
if (s[0] == 0)
22
{
23
x = 0;
24
*mask = 0;
25
}
26
else if (s[1] == 0)
27
{
28
x = (s[0] << 24);
29
*mask = 0xff000000;
30
}
31
else if (s[2] == 0)
32
{
33
x = (s[0] << 24) | (s[1] << 16);
34
*mask = 0xffff0000;
35
}
36
else
37
{
38
x = (s[0] << 24) | (s[1] << 16) | (s[2] << 8) | s[3];
39
*mask = 0xffffff00 | (s[3] ? 0xff : 0x00);
40
}
41
42
return x;
43
}
44
#endif
45
46
#ifdef _ci_alist_hash_
47
static __inline u_32int_t ci_alist_hash (const char *s, u_32int_t *mask)
48
{
49
u_32int_t x;
50
51
if (s[0] == 0)
52
{
53
x = 0;
54
*mask = 0;
55
}
56
else if (s[1] == 0)
57
{
58
x = (stricmp_table[(int)s[0]] << 24);
59
*mask = 0xff000000;
60
}
61
else if (s[2] == 0)
62
{
63
x = (stricmp_table[(int)s[0]] << 24) | (stricmp_table[(int)s[1]] << 16);
64
*mask = 0xffff0000;
65
}
66
else
67
{
68
x = (stricmp_table[(int)s[0]] << 24) | (stricmp_table[(int)s[1]] << 16) | (stricmp_table[(int)s[2]] << 8) | stricmp_table[(int)s[3]];
69
*mask = 0xffffff00 | (s[3] ? 0xff : 0x00);
70
}
71
72
return x;
73
}
74
#endif
75
76
/*
77
* Everything that is to be filed with this system should have an
78
* identifying name as the first item in the struct.
79
*/
80
typedef struct
81
{
82
char *name;
83
u_32int_t hash;
84
} Array_item;
85
86
typedef int (*alist_func) (const char *, const char *, size_t);
87
typedef enum {
88
HASH_INSENSITIVE,
89
HASH_SENSITIVE
90
} hash_type;
91
92
/*
93
* This is the actual list, that contains structs that are of the
94
* form described above. It contains the current size and the maximum
95
* size of the array.
96
*/
97
typedef struct
98
{
99
Array_item **list;
100
int max;
101
int total_max;
102
alist_func func;
103
hash_type hash;
104
} Array;
105
106
Array_item *BX_add_to_array (Array *, Array_item *);
107
Array_item *BX_remove_from_array (Array *, char *);
108
Array_item *BX_array_pop (Array *, int);
109
110
Array_item *BX_remove_all_from_array (Array *, char *);
111
Array_item *BX_array_lookup (Array *, char *, int wild, int delete);
112
Array_item *BX_find_array_item (Array *, char *, int *cnt, int *loc);
113
114
void *BX_find_fixed_array_item (void *Array, size_t size, int siz, char *, int *cnt, int *loc);
115
116
#endif
117
118