comparison mcabber/src/utils.c @ 559:4eb579399613

Fix a small bug in split_arg()
author Mikael Berthe <mikael@lilotux.net>
date Thu, 01 Dec 2005 23:47:16 +0100
parents c4fee1a2c478
children 8b3db0b555a1
comparison
equal deleted inserted replaced
558:db019a5f874f 559:4eb579399613
386 // split_arg(arg, n, preservelast) 386 // split_arg(arg, n, preservelast)
387 // Split the string arg into a maximum of n pieces, taking care of 387 // Split the string arg into a maximum of n pieces, taking care of
388 // double quotes. 388 // double quotes.
389 // Return a null-terminated array of strings. This array should be freed 389 // Return a null-terminated array of strings. This array should be freed
390 // be the caller after use, for example with free_arg_lst(). 390 // be the caller after use, for example with free_arg_lst().
391 // If dontstriplast is true, the Nth argument isn't stripped (i.e. no
392 // processing of quote chars)
391 char **split_arg(const char *arg, unsigned int n, int dontstriplast) 393 char **split_arg(const char *arg, unsigned int n, int dontstriplast)
392 { 394 {
393 char **arglst; 395 char **arglst;
394 const char *p, *start, *end; 396 const char *p, *start, *end;
395 int i = 0; 397 int i = 0;
424 } 426 }
425 } 427 }
426 428
427 if (start < end) { 429 if (start < end) {
428 *(arglst+i) = g_strndup(start, end-start); 430 *(arglst+i) = g_strndup(start, end-start);
429 if (!dontstriplast) 431 if (!dontstriplast || i+1 < n)
430 strip_arg_special_chars(*(arglst+i)); 432 strip_arg_special_chars(*(arglst+i));
431 } 433 }
432 434
433 return arglst; 435 return arglst;
434 } 436 }