… | |
… | |
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 | #include "misc.intpro" /* PROTOS for internal routines */ |
|
|
29 | |
28 | |
30 | char * |
29 | char * |
31 | rxvt_wcstombs (const wchar_t *str, int len) |
30 | rxvt_wcstombs (const wchar_t *str, int len) |
32 | { |
31 | { |
33 | if (len < 0) len = wcslen (str); |
32 | if (len < 0) len = wcslen (str); |
… | |
… | |
282 | /* INTPROTO */ |
281 | /* INTPROTO */ |
283 | char * |
282 | char * |
284 | rxvt_Str_trim (char *str) |
283 | rxvt_Str_trim (char *str) |
285 | { |
284 | { |
286 | char *r, *s; |
285 | char *r, *s; |
287 | int n; |
|
|
288 | |
286 | |
289 | if (!str || !*str) /* shortcut */ |
287 | if (!str || !*str) /* shortcut */ |
290 | return str; |
288 | return str; |
291 | |
289 | |
292 | /* skip leading spaces */ |
290 | /* skip leading spaces */ |
293 | for (s = str; *s && isspace (*s); s++) ; |
291 | for (s = str; *s && isspace (*s); s++) ; |
|
|
292 | |
294 | /* goto end of string */ |
293 | /* goto end of string */ |
295 | for (n = 0, r = s; *r++; n++) ; |
294 | r = s + strlen (s) - 1; |
296 | r -= 2; |
295 | |
297 | /* dump return */ |
296 | /* dump return and other trailing whitespace */ |
298 | if (n > 0 && *r == '\n') |
297 | while (r > s && isspace (*r)) |
299 | n--, r--; |
298 | r--; |
300 | /* backtrack along trailing spaces */ |
299 | |
301 | for (; n > 0 && isspace (*r); r--, n--) ; |
300 | #if 0 |
302 | /* skip matching leading/trailing quotes */ |
301 | /* skip matching leading/trailing quotes */ |
303 | if (*s == '"' && *r == '"' && n > 1) |
302 | if (*s == '"' && *r == '"' && n > 1) |
304 | { |
303 | { |
305 | s++; |
304 | s++; |
306 | n -= 2; |
305 | n -= 2; |
307 | } |
306 | } |
|
|
307 | #endif |
308 | |
308 | |
309 | /* copy back over: forwards copy */ |
309 | memmove (str, s, r + 1 - s); |
310 | for (r = str; n; n--) |
310 | str[r + 1 - s] = 0; |
311 | *r++ = *s++; |
|
|
312 | *r = '\0'; |
|
|
313 | |
311 | |
314 | return str; |
312 | return str; |
315 | } |
313 | } |
316 | |
314 | |
317 | /* |
315 | /* |
… | |
… | |
400 | return (d - str); |
398 | return (d - str); |
401 | } |
399 | } |
402 | |
400 | |
403 | /* |
401 | /* |
404 | * Split a comma-separated string into an array, stripping leading and |
402 | * Split a comma-separated string into an array, stripping leading and |
405 | * trailing spaces (and paired quotes) from each entry. Empty strings |
403 | * trailing spaces from each entry. Empty strings are properly returned |
406 | * are properly returned |
|
|
407 | * Caller should free each entry and array when done |
404 | * Caller should free each entry and array when done |
408 | */ |
405 | */ |
409 | /* INTPROTO */ |
406 | /* INTPROTO */ |
410 | char ** |
407 | char ** |
411 | rxvt_splitcommastring (const char *cs) |
408 | rxvt_splitcommastring (const char *cs) |
… | |
… | |
418 | s = ""; |
415 | s = ""; |
419 | |
416 | |
420 | for (n = 1, t = s; *t; t++) |
417 | for (n = 1, t = s; *t; t++) |
421 | if (*t == ',') |
418 | if (*t == ',') |
422 | n++; |
419 | n++; |
|
|
420 | |
423 | ret = (char **)malloc ((n + 1) * sizeof (char *)); |
421 | ret = (char **)malloc ((n + 1) * sizeof (char *)); |
424 | ret[n] = NULL; |
422 | ret[n] = NULL; |
425 | |
423 | |
426 | for (l = 0, t = s; l < n; l++) |
424 | for (l = 0, t = s; l < n; l++) |
427 | { |
425 | { |
… | |
… | |
431 | strncpy (ret[l], s, p); |
429 | strncpy (ret[l], s, p); |
432 | ret[l][p] = '\0'; |
430 | ret[l][p] = '\0'; |
433 | rxvt_Str_trim (ret[l]); |
431 | rxvt_Str_trim (ret[l]); |
434 | s = ++t; |
432 | s = ++t; |
435 | } |
433 | } |
|
|
434 | |
436 | return ret; |
435 | return ret; |
437 | } |
436 | } |
438 | |
437 | |
439 | void |
438 | void |
440 | rxvt_freecommastring (char **cs) |
439 | rxvt_freecommastring (char **cs) |