]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/string-private.h
Merge changes from CUPS 1.5svn-r9313.
[thirdparty/cups.git] / cups / string-private.h
1 /*
2 * "$Id$"
3 *
4 * Private string definitions for CUPS.
5 *
6 * Copyright 2007-2010 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 */
17
18 #ifndef _CUPS_STRING_PRIVATE_H_
19 # define _CUPS_STRING_PRIVATE_H_
20
21 /*
22 * Include necessary headers...
23 */
24
25 # include <stdio.h>
26 # include <stdlib.h>
27 # include <stdarg.h>
28 # include <ctype.h>
29 # include <errno.h>
30 # include <locale.h>
31
32 # include "config.h"
33
34 # ifdef HAVE_STRING_H
35 # include <string.h>
36 # endif /* HAVE_STRING_H */
37
38 # ifdef HAVE_STRINGS_H
39 # include <strings.h>
40 # endif /* HAVE_STRINGS_H */
41
42 # ifdef HAVE_BSTRING_H
43 # include <bstring.h>
44 # endif /* HAVE_BSTRING_H */
45
46
47 /*
48 * Stuff for WIN32 and OS/2...
49 */
50
51 # if defined(WIN32) || defined(__EMX__)
52 # define strcasecmp _stricmp
53 # define strncasecmp _strnicmp
54 # endif /* WIN32 || __EMX__ */
55
56
57 /*
58 * C++ magic...
59 */
60
61 # ifdef __cplusplus
62 extern "C" {
63 # endif /* __cplusplus */
64
65
66 /*
67 * String pool structures...
68 */
69
70 # define _CUPS_STR_GUARD 0x12344321
71
72 typedef struct _cups_sp_item_s /**** String Pool Item ****/
73 {
74 # ifdef DEBUG_GUARDS
75 unsigned int guard; /* Guard word */
76 # endif /* DEBUG_GUARDS */
77 unsigned int ref_count; /* Reference count */
78 char str[1]; /* String */
79 } _cups_sp_item_t;
80
81
82 /*
83 * Replacements for the ctype macros that are not affected by locale, since we
84 * really only care about testing for ASCII characters when parsing files, etc.
85 * These are used only within libcups since the rest of CUPS doesn't call
86 * setlocale() for LC_CTYPE and doesn't have to worry about third-party
87 * libraries doing so (and if they do that is a bug: NetSNMP, I'm looking at
88 * you!)
89 *
90 * The _CUPS_INLINE definition controls whether we get an inline function body,
91 * and external function body, or an external definition.
92 */
93
94 # if defined(__GNUC__) || __STDC_VERSION__ >= 199901L
95 # define _CUPS_INLINE static inline
96 # elif defined(_MSC_VER)
97 # define _CUPS_INLINE static __inline
98 # elif defined(_CUPS_STRING_C_)
99 # define _CUPS_INLINE
100 # endif /* __GNUC__ || __STDC_VERSION__ */
101
102 # ifdef _CUPS_INLINE
103 _CUPS_INLINE int /* O - 1 on match, 0 otherwise */
104 _cups_isalnum(int ch) /* I - Character to test */
105 {
106 return ((ch >= '0' && ch <= '9') ||
107 (ch >= 'A' && ch <= 'Z') ||
108 (ch >= 'a' && ch <= 'z'));
109 }
110
111 _CUPS_INLINE int /* O - 1 on match, 0 otherwise */
112 _cups_isalpha(int ch) /* I - Character to test */
113 {
114 return ((ch >= 'A' && ch <= 'Z') ||
115 (ch >= 'a' && ch <= 'z'));
116 }
117
118 _CUPS_INLINE int /* O - 1 on match, 0 otherwise */
119 _cups_isspace(int ch) /* I - Character to test */
120 {
121 return (ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' ||
122 ch == '\v');
123 }
124
125 _CUPS_INLINE int /* O - 1 on match, 0 otherwise */
126 _cups_isupper(int ch) /* I - Character to test */
127 {
128 return (ch >= 'A' && ch <= 'Z');
129 }
130 # else
131 extern int _cups_isalnum(int ch);
132 extern int _cups_isalpha(int ch);
133 extern int _cups_isspace(int ch);
134 extern int _cups_isupper(int ch);
135 # endif /* _CUPS_INLINE */
136
137
138 /*
139 * Prototypes...
140 */
141
142 extern void _cups_strcpy(char *dst, const char *src);
143
144 # ifndef HAVE_STRDUP
145 extern char *_cups_strdup(const char *);
146 # define strdup _cups_strdup
147 # endif /* !HAVE_STRDUP */
148
149 # ifndef HAVE_STRCASECMP
150 extern int _cups_strcasecmp(const char *, const char *);
151 # define strcasecmp _cups_strcasecmp
152 # endif /* !HAVE_STRCASECMP */
153
154 # ifndef HAVE_STRNCASECMP
155 extern int _cups_strncasecmp(const char *, const char *, size_t n);
156 # define strncasecmp _cups_strncasecmp
157 # endif /* !HAVE_STRNCASECMP */
158
159 # ifndef HAVE_STRLCAT
160 extern size_t _cups_strlcat(char *, const char *, size_t);
161 # define strlcat _cups_strlcat
162 # endif /* !HAVE_STRLCAT */
163
164 # ifndef HAVE_STRLCPY
165 extern size_t _cups_strlcpy(char *, const char *, size_t);
166 # define strlcpy _cups_strlcpy
167 # endif /* !HAVE_STRLCPY */
168
169 # ifndef HAVE_SNPRINTF
170 extern int _cups_snprintf(char *, size_t, const char *, ...)
171 # ifdef __GNUC__
172 __attribute__ ((__format__ (__printf__, 3, 4)))
173 # endif /* __GNUC__ */
174 ;
175 # define snprintf _cups_snprintf
176 # endif /* !HAVE_SNPRINTF */
177
178 # ifndef HAVE_VSNPRINTF
179 extern int _cups_vsnprintf(char *, size_t, const char *, va_list);
180 # define vsnprintf _cups_vsnprintf
181 # endif /* !HAVE_VSNPRINTF */
182
183 /*
184 * String pool functions...
185 */
186
187 extern char *_cupsStrAlloc(const char *s);
188 extern void _cupsStrFlush(void);
189 extern void _cupsStrFree(const char *s);
190 extern char *_cupsStrRetain(const char *s);
191 extern size_t _cupsStrStatistics(size_t *alloc_bytes, size_t *total_bytes);
192
193
194 /*
195 * Floating point number functions...
196 */
197
198 extern char *_cupsStrFormatd(char *buf, char *bufend, double number,
199 struct lconv *loc);
200 extern double _cupsStrScand(const char *buf, char **bufptr,
201 struct lconv *loc);
202
203
204 /*
205 * C++ magic...
206 */
207
208 # ifdef __cplusplus
209 }
210 # endif /* __cplusplus */
211
212 #endif /* !_CUPS_STRING_H_ */
213
214 /*
215 * End of "$Id$".
216 */