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