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