ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/misc.C
(Generate patch)

Comparing rxvt-unicode/src/misc.C (file contents):
Revision 1.53 by root, Sun Apr 26 01:59:53 2009 UTC vs.
Revision 1.59 by sf-exg, Wed Nov 12 12:12:02 2014 UTC

4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston 6 * Copyright (c) 1996 mj olesen <olesen@me.QueensU.CA> Queen's Univ at Kingston
7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
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 <pcg@goof.com> 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)
32void *
33operator new (size_t s)
34#if !ECB_CPP11
35 throw (std::bad_alloc)
36#endif
37{
38 return rxvt_malloc (s);
39}
40
41void
42operator delete (void *p)
43#if ECB_CPP11
44 noexcept
45#else
46 throw ()
47#endif
48{
49 free (p);
50}
28 51
29char * 52char *
30rxvt_wcstombs (const wchar_t *str, int len) 53rxvt_wcstombs (const wchar_t *str, int len)
31{ 54{
32 if (len < 0) len = wcslen (str); 55 if (len < 0) len = wcslen (str);
168} 191}
169 192
170const char * 193const char *
171rxvt_basename (const char *str) NOTHROW 194rxvt_basename (const char *str) NOTHROW
172{ 195{
173 char *base = strrchr (str, '/'); 196 const char *base = strrchr (str, '/');
174 197
175 return (char *) (base ? base + 1 : str); 198 return base ? base + 1 : str;
176} 199}
177 200
178/* 201/*
179 * Print an error message 202 * Print an error message
180 */ 203 */
263 286
264 return str; 287 return str;
265} 288}
266 289
267/* 290/*
268 * Split a comma-separated string into an array, stripping leading and 291 * 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 292 * trailing spaces from each entry. Empty strings are properly returned
270 */ 293 */
271char ** 294char **
272rxvt_splitcommastring (const char *cs) NOTHROW 295rxvt_strsplit (char delim, const char *str) NOTHROW
273{ 296{
274 int l, n, p; 297 int l, n;
275 const char *s, *t; 298 char *s, *t;
276 char **ret; 299 char **ret;
277 300
278 if ((s = cs) == NULL) 301 s = strdup (str ? str : "");
279 s = "";
280 302
281 for (n = 1, t = s; *t; t++) 303 for (n = 1, t = s; *t; t++)
282 if (*t == ',') 304 if (*t == delim)
283 n++; 305 n++;
284 306
285 ret = (char **)malloc ((n + 1) * sizeof (char *)); 307 ret = (char **)malloc ((n + 1) * sizeof (char *));
286 ret[n] = NULL; 308 ret[n] = NULL;
287 309
288 for (l = 0, t = s; l < n; l++) 310 for (l = 0, t = s; l < n; l++)
289 { 311 {
290 for ( ; *t && *t != ','; t++) ; 312 for (; *t && *t != delim; t++)
291 p = t - s; 313 ;
292 ret[l] = (char *)malloc (p + 1); 314 *t = '\0';
293 memcpy (ret[l], s, p);
294 ret[l][p] = '\0'; 315 ret[l] = s;
295 rxvt_strtrim (ret[l]); 316 rxvt_strtrim (ret[l]);
296 s = ++t; 317 s = ++t;
297 } 318 }
298 319
299 return ret; 320 return ret;
300} 321}
301 322
302void
303rxvt_freecommastring (char **cs) NOTHROW
304{
305 for (int i = 0; cs[i]; ++i)
306 free (cs[i]);
307
308 free (cs);
309}
310
311void * 323void *
312rxvt_malloc (size_t size) 324rxvt_malloc (size_t size)
313{ 325{
314 void *p = malloc (size); 326 void *p = malloc (size);
315 327
338 if (!p) 350 if (!p)
339 rxvt_fatal ("memory allocation failure. aborting.\n"); 351 rxvt_fatal ("memory allocation failure. aborting.\n");
340 352
341 return p; 353 return p;
342} 354}
355
356KeySym
357rxvt_XKeycodeToKeysym (Display *dpy, KeyCode code, int index)
358{
359 int size;
360 KeySym *mapping = XGetKeyboardMapping (dpy, code, 1, &size);
361 KeySym keysym = IN_RANGE_EXC (index, 0, size) ? mapping[index] : NoSymbol;
362 XFree (mapping);
363 return keysym;
364}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines