Very cool. +1
Cliff Woolley wrote:
>
> On Fri, 5 Apr 2002, Jim Jagielski wrote:
>
> > Ugly, but logically it looks right:
>
> Ouch. Yeah, I'd wondered about that problem. The thing is it seems
> really silly to me to be fighting with finding the '\0' when we already
> know how many loop iterations it should be ('cause we counted them :).
>
> How about this:
>
> Index: apr_cpystrn.c
> ===================================================================
> RCS file: /home/cvs/apr/strings/apr_cpystrn.c,v
> retrieving revision 1.10
> diff -u -d -r1.10 apr_cpystrn.c
> --- apr_cpystrn.c 13 Mar 2002 20:39:26 -0000 1.10
> +++ apr_cpystrn.c 5 Apr 2002 19:34:48 -0000
> @@ -126,7 +126,7 @@
> {
> const char *cp;
> const char *ct;
> - int isquoted, numargs = 0;
> + int isquoted, numargs = 0, argnum;
>
> #define SKIP_WHITESPACE(cp) \
> for ( ; *cp == ' ' || *cp == '\t'; ) { \
> @@ -171,25 +171,26 @@
> while (*ct != '\0') {
> CHECK_QUOTATION(ct, isquoted);
> DETERMINE_NEXTSTRING(ct, isquoted);
> - ct++;
> + if (*ct != '\0') {
> + ct++;
> + }
> numargs++;
> SKIP_WHITESPACE(ct);
> }
> *argv_out = apr_palloc(token_context, numargs * sizeof(char*));
>
> /* determine first argument */
> - numargs = 0;
> - while (*cp != '\0') {
> + for (argnum = 0; argnum < (numargs-1); argnum++) {
> CHECK_QUOTATION(cp, isquoted);
> ct = cp;
> DETERMINE_NEXTSTRING(cp, isquoted);
> cp++;
> - (*argv_out)[numargs] = apr_palloc(token_context, cp - ct);
> - apr_cpystrn((*argv_out)[numargs], ct, cp - ct);
> - numargs++;
> + (*argv_out)[argnum] = apr_palloc(token_context, cp - ct);
> + apr_cpystrn((*argv_out)[argnum], ct, cp - ct);
> + argnum++;
We don't want that argnum++ though, since the for loop does it.
--
===========================================================================
Jim Jagielski [|] [EMAIL PROTECTED] [|] http://www.jaguNET.com/
"A society that will trade a little liberty for a little order
will lose both and deserve neither" - T.Jefferson