]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
71e16022 | 2 | * "$Id$" |
ef416fc2 | 3 | * |
554aa7b7 | 4 | * Private string definitions for CUPS. |
ef416fc2 | 5 | * |
59189c00 | 6 | * Copyright 2007-2015 by Apple Inc. |
554aa7b7 | 7 | * Copyright 1997-2006 by Easy Software Products. |
ef416fc2 | 8 | * |
554aa7b7 MS |
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/". | |
ef416fc2 | 14 | * |
554aa7b7 | 15 | * This file is subject to the Apple OS-Developed Software exception. |
ef416fc2 | 16 | */ |
17 | ||
71e16022 MS |
18 | #ifndef _CUPS_STRING_PRIVATE_H_ |
19 | # define _CUPS_STRING_PRIVATE_H_ | |
ef416fc2 | 20 | |
21 | /* | |
22 | * Include necessary headers... | |
23 | */ | |
24 | ||
ef416fc2 | 25 | # include <stdio.h> |
a74454a7 | 26 | # include <stdlib.h> |
ef416fc2 | 27 | # include <stdarg.h> |
28 | # include <ctype.h> | |
71e16022 | 29 | # include <errno.h> |
757d2cad | 30 | # include <locale.h> |
554aa7b7 | 31 | # include <time.h> |
ef416fc2 | 32 | |
71e16022 | 33 | # include "config.h" |
a74454a7 | 34 | |
ef416fc2 | 35 | # ifdef HAVE_STRING_H |
36 | # include <string.h> | |
37 | # endif /* HAVE_STRING_H */ | |
38 | ||
39 | # ifdef HAVE_STRINGS_H | |
40 | # include <strings.h> | |
41 | # endif /* HAVE_STRINGS_H */ | |
42 | ||
43 | # ifdef HAVE_BSTRING_H | |
44 | # include <bstring.h> | |
45 | # endif /* HAVE_BSTRING_H */ | |
46 | ||
47 | ||
ef416fc2 | 48 | /* |
49 | * C++ magic... | |
50 | */ | |
51 | ||
52 | # ifdef __cplusplus | |
53 | extern "C" { | |
54 | # endif /* __cplusplus */ | |
55 | ||
56 | ||
4400e98d | 57 | /* |
58 | * String pool structures... | |
59 | */ | |
60 | ||
745129be MS |
61 | # define _CUPS_STR_GUARD 0x12344321 |
62 | ||
4400e98d | 63 | typedef struct _cups_sp_item_s /**** String Pool Item ****/ |
64 | { | |
745129be MS |
65 | # ifdef DEBUG_GUARDS |
66 | unsigned int guard; /* Guard word */ | |
67 | # endif /* DEBUG_GUARDS */ | |
4400e98d | 68 | unsigned int ref_count; /* Reference count */ |
426c6a59 | 69 | char str[1]; /* String */ |
4400e98d | 70 | } _cups_sp_item_t; |
71 | ||
72 | ||
7cf5915e MS |
73 | /* |
74 | * Replacements for the ctype macros that are not affected by locale, since we | |
75 | * really only care about testing for ASCII characters when parsing files, etc. | |
7cf5915e MS |
76 | * |
77 | * The _CUPS_INLINE definition controls whether we get an inline function body, | |
78 | * and external function body, or an external definition. | |
79 | */ | |
80 | ||
81 | # if defined(__GNUC__) || __STDC_VERSION__ >= 199901L | |
82 | # define _CUPS_INLINE static inline | |
83 | # elif defined(_MSC_VER) | |
84 | # define _CUPS_INLINE static __inline | |
85 | # elif defined(_CUPS_STRING_C_) | |
86 | # define _CUPS_INLINE | |
87 | # endif /* __GNUC__ || __STDC_VERSION__ */ | |
88 | ||
89 | # ifdef _CUPS_INLINE | |
90 | _CUPS_INLINE int /* O - 1 on match, 0 otherwise */ | |
91 | _cups_isalnum(int ch) /* I - Character to test */ | |
92 | { | |
93 | return ((ch >= '0' && ch <= '9') || | |
94 | (ch >= 'A' && ch <= 'Z') || | |
95 | (ch >= 'a' && ch <= 'z')); | |
96 | } | |
97 | ||
98 | _CUPS_INLINE int /* O - 1 on match, 0 otherwise */ | |
99 | _cups_isalpha(int ch) /* I - Character to test */ | |
100 | { | |
101 | return ((ch >= 'A' && ch <= 'Z') || | |
102 | (ch >= 'a' && ch <= 'z')); | |
103 | } | |
104 | ||
2d0a0f48 MS |
105 | _CUPS_INLINE int /* O - 1 on match, 0 otherwise */ |
106 | _cups_islower(int ch) /* I - Character to test */ | |
107 | { | |
108 | return (ch >= 'a' && ch <= 'z'); | |
109 | } | |
110 | ||
7cf5915e MS |
111 | _CUPS_INLINE int /* O - 1 on match, 0 otherwise */ |
112 | _cups_isspace(int ch) /* I - Character to test */ | |
113 | { | |
114 | return (ch == ' ' || ch == '\f' || ch == '\n' || ch == '\r' || ch == '\t' || | |
115 | ch == '\v'); | |
116 | } | |
117 | ||
118 | _CUPS_INLINE int /* O - 1 on match, 0 otherwise */ | |
119 | _cups_isupper(int ch) /* I - Character to test */ | |
120 | { | |
121 | return (ch >= 'A' && ch <= 'Z'); | |
122 | } | |
88f9aafc MS |
123 | |
124 | _CUPS_INLINE int /* O - Converted character */ | |
125 | _cups_tolower(int ch) /* I - Character to convert */ | |
126 | { | |
127 | return (_cups_isupper(ch) ? ch - 'A' + 'a' : ch); | |
128 | } | |
2d0a0f48 MS |
129 | |
130 | _CUPS_INLINE int /* O - Converted character */ | |
131 | _cups_toupper(int ch) /* I - Character to convert */ | |
132 | { | |
133 | return (_cups_islower(ch) ? ch - 'a' + 'A' : ch); | |
134 | } | |
7cf5915e MS |
135 | # else |
136 | extern int _cups_isalnum(int ch); | |
137 | extern int _cups_isalpha(int ch); | |
2d0a0f48 | 138 | extern int _cups_islower(int ch); |
7cf5915e MS |
139 | extern int _cups_isspace(int ch); |
140 | extern int _cups_isupper(int ch); | |
88f9aafc | 141 | extern int _cups_tolower(int ch); |
2d0a0f48 | 142 | extern int _cups_toupper(int ch); |
7cf5915e MS |
143 | # endif /* _CUPS_INLINE */ |
144 | ||
145 | ||
ef416fc2 | 146 | /* |
147 | * Prototypes... | |
148 | */ | |
149 | ||
59189c00 | 150 | extern ssize_t _cups_safe_vsnprintf(char *, size_t, const char *, va_list); |
ef416fc2 | 151 | extern void _cups_strcpy(char *dst, const char *src); |
152 | ||
153 | # ifndef HAVE_STRDUP | |
154 | extern char *_cups_strdup(const char *); | |
155 | # define strdup _cups_strdup | |
156 | # endif /* !HAVE_STRDUP */ | |
157 | ||
ef416fc2 | 158 | extern int _cups_strcasecmp(const char *, const char *); |
ef416fc2 | 159 | |
ef416fc2 | 160 | extern int _cups_strncasecmp(const char *, const char *, size_t n); |
ef416fc2 | 161 | |
162 | # ifndef HAVE_STRLCAT | |
163 | extern size_t _cups_strlcat(char *, const char *, size_t); | |
164 | # define strlcat _cups_strlcat | |
165 | # endif /* !HAVE_STRLCAT */ | |
166 | ||
167 | # ifndef HAVE_STRLCPY | |
168 | extern size_t _cups_strlcpy(char *, const char *, size_t); | |
169 | # define strlcpy _cups_strlcpy | |
170 | # endif /* !HAVE_STRLCPY */ | |
171 | ||
172 | # ifndef HAVE_SNPRINTF | |
173 | extern int _cups_snprintf(char *, size_t, const char *, ...) | |
85dda01c | 174 | __attribute__ ((__format__ (__printf__, 3, 4))); |
ef416fc2 | 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 | ||
4400e98d | 183 | /* |
184 | * String pool functions... | |
185 | */ | |
186 | ||
757d2cad | 187 | extern char *_cupsStrAlloc(const char *s); |
d6ae789d | 188 | extern void _cupsStrFlush(void); |
757d2cad | 189 | extern void _cupsStrFree(const char *s); |
e07d4801 | 190 | extern char *_cupsStrRetain(const char *s); |
757d2cad | 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); | |
4400e98d | 202 | |
ef416fc2 | 203 | |
554aa7b7 MS |
204 | /* |
205 | * Date function... | |
206 | */ | |
207 | ||
208 | extern char *_cupsStrDate(char *buf, size_t bufsize, time_t timeval); | |
209 | ||
210 | ||
ef416fc2 | 211 | /* |
212 | * C++ magic... | |
213 | */ | |
214 | ||
215 | # ifdef __cplusplus | |
216 | } | |
217 | # endif /* __cplusplus */ | |
218 | ||
219 | #endif /* !_CUPS_STRING_H_ */ | |
220 | ||
221 | /* | |
71e16022 | 222 | * End of "$Id$". |
ef416fc2 | 223 | */ |