(argcv_get_n): New function
Showing
2 changed files
with
21 additions
and
5 deletions
... | @@ -39,6 +39,10 @@ extern "C" { | ... | @@ -39,6 +39,10 @@ extern "C" { |
39 | extern int argcv_get __P ((const char *command, const char *delim, | 39 | extern int argcv_get __P ((const char *command, const char *delim, |
40 | const char* cmnt, | 40 | const char* cmnt, |
41 | int *argc, char ***argv)); | 41 | int *argc, char ***argv)); |
42 | extern int argcv_get_n __P((const char *command, int len, | ||
43 | const char *delim, const char *cmnt, | ||
44 | int *argc, char ***argv)); | ||
45 | |||
42 | extern int argcv_string __P ((int argc, char **argv, char **string)); | 46 | extern int argcv_string __P ((int argc, char **argv, char **string)); |
43 | extern int argcv_free __P ((int argc, char **argv)); | 47 | extern int argcv_free __P ((int argc, char **argv)); |
44 | extern int argcv_unquote_char __P((int c)); | 48 | extern int argcv_unquote_char __P((int c)); |
... | ... |
1 | /* argcv.c - simple functions for parsing input based on whitespace | 1 | /* argcv.c - simple functions for parsing input based on whitespace |
2 | Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. | 2 | Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Lesser General Public | 5 | modify it under the terms of the GNU Lesser General Public |
... | @@ -91,7 +91,7 @@ argcv_scan (int len, const char *command, const char *delim, const char* cmnt, | ... | @@ -91,7 +91,7 @@ argcv_scan (int len, const char *command, const char *delim, const char* cmnt, |
91 | to the newline and restart the token search. */ | 91 | to the newline and restart the token search. */ |
92 | if (*save <= len) | 92 | if (*save <= len) |
93 | { | 93 | { |
94 | if (cmnt && strchr (cmnt, command[*start]) != NULL) | 94 | if (strchr (cmnt, command[*start]) != NULL) |
95 | { | 95 | { |
96 | i = *save; | 96 | i = *save; |
97 | while (i < len && command[i] != '\n') | 97 | while (i < len && command[i] != '\n') |
... | @@ -300,10 +300,9 @@ argcv_quote_copy (char *dst, const char *src) | ... | @@ -300,10 +300,9 @@ argcv_quote_copy (char *dst, const char *src) |
300 | } | 300 | } |
301 | 301 | ||
302 | int | 302 | int |
303 | argcv_get (const char *command, const char *delim, const char *cmnt, | 303 | argcv_get_n (const char *command, int len, const char *delim, const char *cmnt, |
304 | int *argc, char ***argv) | 304 | int *argc, char ***argv) |
305 | { | 305 | { |
306 | int len = strlen (command); | ||
307 | int i = 0; | 306 | int i = 0; |
308 | int start, end, save; | 307 | int start, end, save; |
309 | 308 | ||
... | @@ -313,6 +312,11 @@ argcv_get (const char *command, const char *delim, const char *cmnt, | ... | @@ -313,6 +312,11 @@ argcv_get (const char *command, const char *delim, const char *cmnt, |
313 | *argc = 0; | 312 | *argc = 0; |
314 | save = 0; | 313 | save = 0; |
315 | 314 | ||
315 | if (!delim) | ||
316 | delim = ""; | ||
317 | if (!cmnt) | ||
318 | cmnt = ""; | ||
319 | |||
316 | while (argcv_scan (len, command, delim, cmnt, &start, &end, &save) <= len) | 320 | while (argcv_scan (len, command, delim, cmnt, &start, &end, &save) <= len) |
317 | (*argc)++; | 321 | (*argc)++; |
318 | 322 | ||
... | @@ -344,6 +348,14 @@ argcv_get (const char *command, const char *delim, const char *cmnt, | ... | @@ -344,6 +348,14 @@ argcv_get (const char *command, const char *delim, const char *cmnt, |
344 | return 0; | 348 | return 0; |
345 | } | 349 | } |
346 | 350 | ||
351 | int | ||
352 | argcv_get (const char *command, const char *delim, const char *cmnt, | ||
353 | int *argc, char ***argv) | ||
354 | { | ||
355 | return argcv_get_n (command, strlen (command), delim, cmnt, argc, argv); | ||
356 | } | ||
357 | |||
358 | |||
347 | /* | 359 | /* |
348 | * frees all elements of an argv array | 360 | * frees all elements of an argv array |
349 | * argc is the number of elements | 361 | * argc is the number of elements |
... | ... |
-
Please register or sign in to post a comment