… | |
… | |
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 |
… | |
… | |
168 | } |
168 | } |
169 | |
169 | |
170 | const char * |
170 | const char * |
171 | rxvt_basename (const char *str) NOTHROW |
171 | rxvt_basename (const char *str) NOTHROW |
172 | { |
172 | { |
173 | char *base = strrchr (str, '/'); |
173 | const char *base = strrchr (str, '/'); |
174 | |
174 | |
175 | return (char *) (base ? base + 1 : str); |
175 | return base ? base + 1 : str; |
176 | } |
176 | } |
177 | |
177 | |
178 | /* |
178 | /* |
179 | * Print an error message |
179 | * Print an error message |
180 | */ |
180 | */ |
… | |
… | |
263 | |
263 | |
264 | return str; |
264 | return str; |
265 | } |
265 | } |
266 | |
266 | |
267 | /* |
267 | /* |
268 | * 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 |
269 | * trailing spaces from each entry. Empty strings are properly returned |
269 | * trailing spaces from each entry. Empty strings are properly returned |
270 | */ |
270 | */ |
271 | char ** |
271 | char ** |
272 | rxvt_splitcommastring (const char *cs) NOTHROW |
272 | rxvt_strsplit (char delim, const char *str) NOTHROW |
273 | { |
273 | { |
274 | int l, n, p; |
274 | int l, n; |
275 | const char *s, *t; |
275 | char *s, *t; |
276 | char **ret; |
276 | char **ret; |
277 | |
277 | |
278 | if ((s = cs) == NULL) |
278 | s = strdup (str ? str : ""); |
279 | s = ""; |
|
|
280 | |
279 | |
281 | for (n = 1, t = s; *t; t++) |
280 | for (n = 1, t = s; *t; t++) |
282 | if (*t == ',') |
281 | if (*t == delim) |
283 | n++; |
282 | n++; |
284 | |
283 | |
285 | ret = (char **)malloc ((n + 1) * sizeof (char *)); |
284 | ret = (char **)malloc ((n + 1) * sizeof (char *)); |
286 | ret[n] = NULL; |
285 | ret[n] = NULL; |
287 | |
286 | |
288 | for (l = 0, t = s; l < n; l++) |
287 | for (l = 0, t = s; l < n; l++) |
289 | { |
288 | { |
290 | for ( ; *t && *t != ','; t++) ; |
289 | for (; *t && *t != delim; t++) |
291 | p = t - s; |
290 | ; |
292 | ret[l] = (char *)malloc (p + 1); |
291 | *t = '\0'; |
293 | memcpy (ret[l], s, p); |
|
|
294 | ret[l][p] = '\0'; |
292 | ret[l] = s; |
295 | rxvt_strtrim (ret[l]); |
293 | rxvt_strtrim (ret[l]); |
296 | s = ++t; |
294 | s = ++t; |
297 | } |
295 | } |
298 | |
296 | |
299 | return ret; |
297 | return ret; |
300 | } |
298 | } |
301 | |
299 | |
302 | void |
|
|
303 | rxvt_freecommastring (char **cs) NOTHROW |
|
|
304 | { |
|
|
305 | for (int i = 0; cs[i]; ++i) |
|
|
306 | free (cs[i]); |
|
|
307 | |
|
|
308 | free (cs); |
|
|
309 | } |
|
|
310 | |
|
|
311 | void * |
300 | void * |
312 | rxvt_malloc (size_t size) |
301 | rxvt_malloc (size_t size) |
313 | { |
302 | { |
314 | void *p = malloc (size); |
303 | void *p = malloc (size); |
315 | |
304 | |
… | |
… | |
338 | if (!p) |
327 | if (!p) |
339 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
328 | rxvt_fatal ("memory allocation failure. aborting.\n"); |
340 | |
329 | |
341 | return p; |
330 | return p; |
342 | } |
331 | } |
|
|
332 | |
|
|
333 | KeySym |
|
|
334 | rxvt_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 | } |