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.51 by ayin, Mon Jan 7 12:41:31 2008 UTC vs.
Revision 1.58 by sf-exg, Fri Sep 5 19:02:53 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
38 while (len--) 38 while (len--)
39 { 39 {
40 ssize_t l = wcrtomb (dst, *str++, mbs); 40 ssize_t l = wcrtomb (dst, *str++, mbs);
41 41
42 if (l < 0) 42 if (l < 0)
43 {
43 *dst++ = '?'; 44 *dst++ = '?';
45 wcrtomb (0, 0, mbs); // reset undefined state
46 }
44 else 47 else
45 dst += l; 48 dst += l;
46 } 49 }
47 50
48 *dst++ = 0; 51 *dst++ = 0;
162 *p = 0; 165 *p = 0;
163 166
164 return r; 167 return r;
165} 168}
166 169
167char * 170const char *
168rxvt_basename (const char *str) NOTHROW 171rxvt_basename (const char *str) NOTHROW
169{ 172{
170 char *base = strrchr (str, '/'); 173 const char *base = strrchr (str, '/');
171 174
172 return (char *) (base ? base + 1 : str); 175 return base ? base + 1 : str;
173} 176}
174 177
175/* 178/*
176 * Print an error message 179 * Print an error message
177 */ 180 */
260 263
261 return str; 264 return str;
262} 265}
263 266
264/* 267/*
265 * Split a comma-separated string into an array, stripping leading and 268 * Split a string into an array based on the given delimiter, stripping leading and
266 * trailing spaces from each entry. Empty strings are properly returned 269 * trailing spaces from each entry. Empty strings are properly returned
267 */ 270 */
268char ** 271char **
269rxvt_splitcommastring (const char *cs) NOTHROW 272rxvt_strsplit (char delim, const char *str) NOTHROW
270{ 273{
271 int l, n, p; 274 int l, n;
272 const char *s, *t; 275 char *s, *t;
273 char **ret; 276 char **ret;
274 277
275 if ((s = cs) == NULL) 278 s = strdup (str ? str : "");
276 s = "";
277 279
278 for (n = 1, t = s; *t; t++) 280 for (n = 1, t = s; *t; t++)
279 if (*t == ',') 281 if (*t == delim)
280 n++; 282 n++;
281 283
282 ret = (char **)malloc ((n + 1) * sizeof (char *)); 284 ret = (char **)malloc ((n + 1) * sizeof (char *));
283 ret[n] = NULL; 285 ret[n] = NULL;
284 286
285 for (l = 0, t = s; l < n; l++) 287 for (l = 0, t = s; l < n; l++)
286 { 288 {
287 for ( ; *t && *t != ','; t++) ; 289 for (; *t && *t != delim; t++)
288 p = t - s; 290 ;
289 ret[l] = (char *)malloc (p + 1); 291 *t = '\0';
290 memcpy (ret[l], s, p);
291 ret[l][p] = '\0'; 292 ret[l] = s;
292 rxvt_strtrim (ret[l]); 293 rxvt_strtrim (ret[l]);
293 s = ++t; 294 s = ++t;
294 } 295 }
295 296
296 return ret; 297 return ret;
297} 298}
298 299
299void
300rxvt_freecommastring (char **cs) NOTHROW
301{
302 for (int i = 0; cs[i]; ++i)
303 free (cs[i]);
304
305 free (cs);
306}
307
308void * 300void *
309rxvt_malloc (size_t size) 301rxvt_malloc (size_t size)
310{ 302{
311 void *p = malloc (size); 303 void *p = malloc (size);
312 304
335 if (!p) 327 if (!p)
336 rxvt_fatal ("memory allocation failure. aborting.\n"); 328 rxvt_fatal ("memory allocation failure. aborting.\n");
337 329
338 return p; 330 return p;
339} 331}
332
333KeySym
334rxvt_XKeycodeToKeysym (Display *dpy, KeyCode code, int index)
335{
336 int size;
337 KeySym *mapping = XGetKeyboardMapping (dpy, code, 1, &size);
338 KeySym keysym = IN_RANGE_EXC (index, 0, size) ? mapping[index] : NoSymbol;
339 XFree (mapping);
340 return keysym;
341}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines