summaryrefslogtreecommitdiff
path: root/imap/src/c-client/misc.h
blob: 4e7afc23f782c7418bcd5121cf4f35f22fe5c979 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* ========================================================================
 * Copyright 2008 Mark Crispin
 * ========================================================================
 */

/*
 * Program:	Miscellaneous utility routines
 *
 * Author:	Mark Crispin
 *
 * Date:	5 July 1988
 * Last Edited:	19 November 2008
 *
 * Previous versions of this file were
 *
 * Copyright 1988-2006 University of Washington
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * This original version of this file is
 * Copyright 1988 Stanford University
 * and was developed in the Symbolic Systems Resources Group of the Knowledge
 * Systems Laboratory at Stanford University in 1987-88, and was funded by the
 * Biomedical Research Technology Program of the NationalInstitutes of Health
 * under grant number RR-00785.
 */

/* Hash table operations */

#define HASHMULT 29		/* hash polynomial multiplier */

#define HASHENT struct hash_entry

HASHENT {
  HASHENT *next;		/* next entry with same hash code */
  char *name;			/* name of this hash entry */
  void *data[1];		/* data of this hash entry */
};


#define HASHTAB struct hash_table

HASHTAB {
  size_t size;			/* size of this table */
  HASHENT *table[1];		/* table */
};


/* KLUDGE ALERT!!!
 *
 * Yes, write() is overridden here instead of in osdep.  This
 * is because misc.h is one of the last files that most things #include, so
 * this should avoid problems with some system #include file.
 */

#define write safe_write


/* Some C compilers have these as macros */

#undef min
#undef max


/* And some C libraries have these as int functions */

#define min Min
#define max Max


/* Compatibility definitions */

#define pmatch(s,pat) \
  pmatch_full (s,pat,NIL)

/* Function prototypes */

unsigned char *ucase (unsigned char *string);
unsigned char *lcase (unsigned char *string);
char *cpystr (const char *string);
char *cpytxt (SIZEDTEXT *dst,char *text,unsigned long size);
char *textcpy (SIZEDTEXT *dst,SIZEDTEXT *src);
char *textcpystring (SIZEDTEXT *text,STRING *bs);
char *textcpyoffstring (SIZEDTEXT *text,STRING *bs,unsigned long offset,
			unsigned long size);
unsigned long find_rightmost_bit (unsigned long *valptr);
long min (long i,long j);
long max (long i,long j);
long search (unsigned char *base,long basec,unsigned char *pat,long patc);
long ssearch (unsigned char *base,long basec,unsigned char *pat,long patc);
HASHTAB *hash_create (size_t size);
void hash_destroy (HASHTAB **hashtab);
void hash_reset (HASHTAB *hashtab);
unsigned long hash_index (HASHTAB *hashtab,char *key);
void **hash_lookup (HASHTAB *hashtab,char *key);
HASHENT *hash_add (HASHTAB *hashtab,char *key,void *data,long extra);
void **hash_lookup_and_add (HASHTAB *hashtab,char *key,void *data,long extra);
unsigned char hex2byte (unsigned char c1,unsigned char c2);
int compare_ulong (unsigned long l1,unsigned long l2);
int compare_uchar (unsigned char c1,unsigned char c2);
int compare_string (unsigned char *s1,unsigned char *s2);
int compare_cstring (unsigned char *s1,unsigned char *s2);
int compare_csizedtext (unsigned char *s1,SIZEDTEXT *s2);