… | |
… | |
29 | #include <new> |
29 | #include <new> |
30 | |
30 | |
31 | // alas new/delete cannot be specified as inline in C++11 (see 17.6.4.6) |
31 | // alas new/delete cannot be specified as inline in C++11 (see 17.6.4.6) |
32 | void * |
32 | void * |
33 | operator new (size_t s) |
33 | operator new (size_t s) |
34 | #if !ECB_CPP11 |
|
|
35 | throw (std::bad_alloc) |
|
|
36 | #endif |
|
|
37 | { |
34 | { |
38 | return rxvt_malloc (s); |
35 | return rxvt_malloc (s); |
39 | } |
36 | } |
40 | |
37 | |
41 | void |
38 | void |
42 | operator delete (void *p) |
39 | operator delete (void *p) noexcept |
43 | #if ECB_CPP11 |
|
|
44 | noexcept |
|
|
45 | #else |
|
|
46 | throw () |
|
|
47 | #endif |
|
|
48 | { |
40 | { |
49 | free (p); |
41 | free (p); |
50 | } |
42 | } |
51 | |
43 | |
52 | char * |
44 | char * |
… | |
… | |
189 | |
181 | |
190 | return r; |
182 | return r; |
191 | } |
183 | } |
192 | |
184 | |
193 | const char * |
185 | const char * |
194 | rxvt_basename (const char *str) NOTHROW |
186 | rxvt_basename (const char *str) noexcept |
195 | { |
187 | { |
196 | const char *base = strrchr (str, '/'); |
188 | const char *base = strrchr (str, '/'); |
197 | |
189 | |
198 | return base ? base + 1 : str; |
190 | return base ? base + 1 : str; |
199 | } |
191 | } |
200 | |
192 | |
201 | /* |
193 | /* |
202 | * Print an error message |
194 | * Print an error message |
203 | */ |
195 | */ |
204 | void |
196 | void |
205 | rxvt_vlog (const char *fmt, va_list arg_ptr) NOTHROW |
197 | rxvt_vlog (const char *fmt, va_list arg_ptr) noexcept |
206 | { |
198 | { |
207 | char msg[1024]; |
199 | char msg[1024]; |
208 | |
200 | |
209 | vsnprintf (msg, sizeof msg, fmt, arg_ptr); |
201 | vsnprintf (msg, sizeof msg, fmt, arg_ptr); |
210 | |
202 | |
… | |
… | |
213 | else |
205 | else |
214 | write (STDOUT_FILENO, msg, strlen (msg)); |
206 | write (STDOUT_FILENO, msg, strlen (msg)); |
215 | } |
207 | } |
216 | |
208 | |
217 | void |
209 | void |
218 | rxvt_log (const char *fmt,...) NOTHROW |
210 | rxvt_log (const char *fmt,...) noexcept |
219 | { |
211 | { |
220 | va_list arg_ptr; |
212 | va_list arg_ptr; |
221 | |
213 | |
222 | va_start (arg_ptr, fmt); |
214 | va_start (arg_ptr, fmt); |
223 | rxvt_vlog (fmt, arg_ptr); |
215 | rxvt_vlog (fmt, arg_ptr); |
… | |
… | |
226 | |
218 | |
227 | /* |
219 | /* |
228 | * Print an error message |
220 | * Print an error message |
229 | */ |
221 | */ |
230 | void |
222 | void |
231 | rxvt_warn (const char *fmt,...) NOTHROW |
223 | rxvt_warn (const char *fmt,...) noexcept |
232 | { |
224 | { |
233 | va_list arg_ptr; |
225 | va_list arg_ptr; |
234 | |
226 | |
235 | rxvt_log ("%s: ", RESNAME); |
227 | rxvt_log ("%s: ", RESNAME); |
236 | |
228 | |
… | |
… | |
238 | rxvt_vlog (fmt, arg_ptr); |
230 | rxvt_vlog (fmt, arg_ptr); |
239 | va_end (arg_ptr); |
231 | va_end (arg_ptr); |
240 | } |
232 | } |
241 | |
233 | |
242 | void |
234 | void |
243 | rxvt_fatal (const char *fmt,...) THROW ((class rxvt_failure_exception)) |
235 | rxvt_fatal (const char *fmt,...) |
244 | { |
236 | { |
245 | va_list arg_ptr; |
237 | va_list arg_ptr; |
246 | |
238 | |
247 | rxvt_log ("%s: ", RESNAME); |
239 | rxvt_log ("%s: ", RESNAME); |
248 | |
240 | |
… | |
… | |
252 | |
244 | |
253 | rxvt_exit_failure (); |
245 | rxvt_exit_failure (); |
254 | } |
246 | } |
255 | |
247 | |
256 | void |
248 | void |
257 | rxvt_exit_failure () THROW ((class rxvt_failure_exception)) |
249 | rxvt_exit_failure () |
258 | { |
250 | { |
259 | static class rxvt_failure_exception rxvt_failure_exception; |
251 | static class rxvt_failure_exception rxvt_failure_exception; |
260 | throw (rxvt_failure_exception); |
252 | throw (rxvt_failure_exception); |
261 | } |
253 | } |
262 | |
254 | |
263 | /* |
255 | /* |
264 | * remove leading/trailing space in place. |
256 | * remove leading/trailing space in place. |
265 | */ |
257 | */ |
266 | char * |
258 | char * |
267 | rxvt_strtrim (char *str) NOTHROW |
259 | rxvt_strtrim (char *str) noexcept |
268 | { |
260 | { |
269 | char *r, *s; |
261 | char *r, *s; |
270 | |
262 | |
271 | if (!str || !*str) /* shortcut */ |
263 | if (!str || !*str) /* shortcut */ |
272 | return str; |
264 | return str; |
… | |
… | |
290 | /* |
282 | /* |
291 | * Split a string into an array based on the given delimiter, stripping leading and |
283 | * Split a string into an array based on the given delimiter, stripping leading and |
292 | * trailing spaces from each entry. Empty strings are properly returned |
284 | * trailing spaces from each entry. Empty strings are properly returned |
293 | */ |
285 | */ |
294 | char ** |
286 | char ** |
295 | rxvt_strsplit (char delim, const char *str) NOTHROW |
287 | rxvt_strsplit (char delim, const char *str) noexcept |
296 | { |
288 | { |
297 | int l, n; |
289 | int l, n; |
298 | char *s, *t; |
290 | char *s, *t; |
299 | char **ret; |
291 | char **ret; |
300 | |
292 | |