… | |
… | |
8 | * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com> |
8 | * Copyright (c) 1998-2000 Geoff Wing <gcw@pobox.com> |
9 | * Copyright (c) 2003-2006 Marc Lehmann <schmorp@schmorp.de> |
9 | * Copyright (c) 2003-2006 Marc Lehmann <schmorp@schmorp.de> |
10 | * |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by |
12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or |
13 | * the Free Software Foundation; either version 3 of the License, or |
14 | * (at your option) any later version. |
14 | * (at your option) any later version. |
15 | * |
15 | * |
16 | * This program is distributed in the hope that it will be useful, |
16 | * This program is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
… | |
… | |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
24 | *----------------------------------------------------------------------*/ |
24 | *----------------------------------------------------------------------*/ |
25 | |
25 | |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
|
|
28 | |
|
|
29 | #include <new> |
|
|
30 | |
|
|
31 | // alas new/delete cannot be specified as inline in C++11 (see 17.6.4.6) |
|
|
32 | void * |
|
|
33 | operator new (size_t s) |
|
|
34 | { |
|
|
35 | return rxvt_malloc (s); |
|
|
36 | } |
|
|
37 | |
|
|
38 | void |
|
|
39 | operator delete (void *p) noexcept |
|
|
40 | { |
|
|
41 | free (p); |
|
|
42 | } |
28 | |
43 | |
29 | char * |
44 | char * |
30 | rxvt_wcstombs (const wchar_t *str, int len) |
45 | rxvt_wcstombs (const wchar_t *str, int len) |
31 | { |
46 | { |
32 | if (len < 0) len = wcslen (str); |
47 | if (len < 0) len = wcslen (str); |
… | |
… | |
166 | |
181 | |
167 | return r; |
182 | return r; |
168 | } |
183 | } |
169 | |
184 | |
170 | const char * |
185 | const char * |
171 | rxvt_basename (const char *str) NOTHROW |
186 | rxvt_basename (const char *str) noexcept |
172 | { |
187 | { |
173 | const char *base = strrchr (str, '/'); |
188 | const char *base = strrchr (str, '/'); |
174 | |
189 | |
175 | return base ? base + 1 : str; |
190 | return base ? base + 1 : str; |
176 | } |
191 | } |
177 | |
192 | |
178 | /* |
193 | /* |
179 | * Print an error message |
194 | * Print an error message |
180 | */ |
195 | */ |
181 | void |
196 | void |
182 | rxvt_vlog (const char *fmt, va_list arg_ptr) NOTHROW |
197 | rxvt_vlog (const char *fmt, va_list arg_ptr) noexcept |
183 | { |
198 | { |
184 | char msg[1024]; |
199 | char msg[1024]; |
185 | |
200 | |
186 | vsnprintf (msg, sizeof msg, fmt, arg_ptr); |
201 | vsnprintf (msg, sizeof msg, fmt, arg_ptr); |
187 | |
202 | |
… | |
… | |
190 | else |
205 | else |
191 | write (STDOUT_FILENO, msg, strlen (msg)); |
206 | write (STDOUT_FILENO, msg, strlen (msg)); |
192 | } |
207 | } |
193 | |
208 | |
194 | void |
209 | void |
195 | rxvt_log (const char *fmt,...) NOTHROW |
210 | rxvt_log (const char *fmt,...) noexcept |
196 | { |
211 | { |
197 | va_list arg_ptr; |
212 | va_list arg_ptr; |
198 | |
213 | |
199 | va_start (arg_ptr, fmt); |
214 | va_start (arg_ptr, fmt); |
200 | rxvt_vlog (fmt, arg_ptr); |
215 | rxvt_vlog (fmt, arg_ptr); |
… | |
… | |
203 | |
218 | |
204 | /* |
219 | /* |
205 | * Print an error message |
220 | * Print an error message |
206 | */ |
221 | */ |
207 | void |
222 | void |
208 | rxvt_warn (const char *fmt,...) NOTHROW |
223 | rxvt_warn (const char *fmt,...) noexcept |
209 | { |
224 | { |
210 | va_list arg_ptr; |
225 | va_list arg_ptr; |
211 | |
226 | |
212 | rxvt_log ("%s: ", RESNAME); |
227 | rxvt_log ("%s: ", RESNAME); |
213 | |
228 | |
… | |
… | |
215 | rxvt_vlog (fmt, arg_ptr); |
230 | rxvt_vlog (fmt, arg_ptr); |
216 | va_end (arg_ptr); |
231 | va_end (arg_ptr); |
217 | } |
232 | } |
218 | |
233 | |
219 | void |
234 | void |
220 | rxvt_fatal (const char *fmt,...) THROW ((class rxvt_failure_exception)) |
235 | rxvt_fatal (const char *fmt,...) |
221 | { |
236 | { |
222 | va_list arg_ptr; |
237 | va_list arg_ptr; |
223 | |
238 | |
224 | rxvt_log ("%s: ", RESNAME); |
239 | rxvt_log ("%s: ", RESNAME); |
225 | |
240 | |
… | |
… | |
229 | |
244 | |
230 | rxvt_exit_failure (); |
245 | rxvt_exit_failure (); |
231 | } |
246 | } |
232 | |
247 | |
233 | void |
248 | void |
234 | rxvt_exit_failure () THROW ((class rxvt_failure_exception)) |
249 | rxvt_exit_failure () |
235 | { |
250 | { |
236 | static class rxvt_failure_exception rxvt_failure_exception; |
251 | static class rxvt_failure_exception rxvt_failure_exception; |
237 | throw (rxvt_failure_exception); |
252 | throw (rxvt_failure_exception); |
238 | } |
253 | } |
239 | |
254 | |
240 | /* |
255 | /* |
241 | * remove leading/trailing space in place. |
256 | * remove leading/trailing space in place. |
242 | */ |
257 | */ |
243 | char * |
258 | char * |
244 | rxvt_strtrim (char *str) NOTHROW |
259 | rxvt_strtrim (char *str) noexcept |
245 | { |
260 | { |
246 | char *r, *s; |
261 | char *r, *s; |
247 | |
262 | |
248 | if (!str || !*str) /* shortcut */ |
263 | if (!str || !*str) /* shortcut */ |
249 | return str; |
264 | return str; |
… | |
… | |
267 | /* |
282 | /* |
268 | * 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 |
269 | * trailing spaces from each entry. Empty strings are properly returned |
284 | * trailing spaces from each entry. Empty strings are properly returned |
270 | */ |
285 | */ |
271 | char ** |
286 | char ** |
272 | rxvt_strsplit (char delim, const char *str) NOTHROW |
287 | rxvt_strsplit (char delim, const char *str) noexcept |
273 | { |
288 | { |
274 | int l, n; |
289 | int l, n; |
275 | char *s, *t; |
290 | char *s, *t; |
276 | char **ret; |
291 | char **ret; |
277 | |
292 | |
… | |
… | |
327 | if (!p) |
342 | if (!p) |
328 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
343 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
329 | |
344 | |
330 | return p; |
345 | return p; |
331 | } |
346 | } |
|
|
347 | |
|
|
348 | KeySym |
|
|
349 | rxvt_XKeycodeToKeysym (Display *dpy, KeyCode code, int index) |
|
|
350 | { |
|
|
351 | int size; |
|
|
352 | KeySym *mapping = XGetKeyboardMapping (dpy, code, 1, &size); |
|
|
353 | KeySym keysym = IN_RANGE_EXC (index, 0, size) ? mapping[index] : NoSymbol; |
|
|
354 | XFree (mapping); |
|
|
355 | return keysym; |
|
|
356 | } |