[prev in list] [next in list] [prev in thread] [next in thread]
List: apr-cvs
Subject: cvs commit: apr/strings apr_cpystrn.c
From: trawick () apache ! org
Date: 2002-08-21 17:37:12
[Download RAW message or body]
trawick 2002/08/21 10:37:12
Modified: . CHANGES
strings apr_cpystrn.c
Log:
Fix apr_tokenize_to_argv() to remove the escape character
(backslash) from the argument tokens.
PR: 11793
Submitted by: Paul J. Reder
Reviewed by: Jeff Trawick
Revision Changes Path
1.322 +3 -0 apr/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/apr/CHANGES,v
retrieving revision 1.321
retrieving revision 1.322
diff -u -r1.321 -r1.322
--- CHANGES 19 Aug 2002 21:35:49 -0000 1.321
+++ CHANGES 21 Aug 2002 17:37:12 -0000 1.322
@@ -1,5 +1,8 @@
Changes with APR b1
+ *) Fix apr_tokenize_to_argv() to remove the escape character
+ (backslash) from the argument tokens. PR 11793 [Paul J. Reder]
+
*) Add APR_PARSE_ARGUMENTS and APR_LAYOUT macros for better layout
support. [Thom May]
1.14 +30 -2 apr/strings/apr_cpystrn.c
Index: apr_cpystrn.c
===================================================================
RCS file: /home/cvs/apr/strings/apr_cpystrn.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- apr_cpystrn.c 17 May 2002 14:58:27 -0000 1.13
+++ apr_cpystrn.c 21 Aug 2002 17:37:12 -0000 1.14
@@ -126,6 +126,8 @@
{
const char *cp;
const char *ct;
+ char *cleaned, *dirty;
+ int escaped;
int isquoted, numargs = 0, argnum;
#define SKIP_WHITESPACE(cp) \
@@ -138,6 +140,10 @@
if (*cp == '"') { \
isquoted = 1; \
cp++; \
+ } \
+ else if (*cp == '\'') { \
+ isquoted = 2; \
+ cp++; \
}
/* DETERMINE_NEXTSTRING:
@@ -147,15 +153,35 @@
#define DETERMINE_NEXTSTRING(cp,isquoted) \
for ( ; *cp != '\0'; cp++) { \
if ( (isquoted && (*cp == ' ' || *cp == '\t')) \
- || (*cp == '\\' && (*(cp+1) == ' ' || *(cp+1) == '\t'))) { \
+ || (*cp == '\\' && (*(cp+1) == ' ' || *(cp+1) == '\t' || \
+ *(cp+1) == '"' || *(cp+1) == '\''))) { \
cp++; \
continue; \
} \
if ( (!isquoted && (*cp == ' ' || *cp == '\t')) \
- || (isquoted && *cp == '"') ) { \
+ || (isquoted == 1 && *cp == '"') \
+ || (isquoted == 2 && *cp == '\'') ) { \
break; \
} \
}
+
+/* REMOVE_ESCAPE_CHARS:
+ * Compresses the arg string to remove all of the '\' escape chars.
+ * The final argv strings should not have any extra escape chars in it.
+ */
+#define REMOVE_ESCAPE_CHARS(cleaned, dirty, escaped) \
+ escaped = 0; \
+ while(*dirty) { \
+ if (!escaped && *dirty == '\\') { \
+ escaped = 1; \
+ } \
+ else { \
+ escaped = 0; \
+ *cleaned++ = *dirty; \
+ } \
+ ++dirty; \
+ } \
+ *cleaned = 0; /* last line of macro... */
cp = arg_str;
SKIP_WHITESPACE(cp);
@@ -187,6 +213,8 @@
cp++;
(*argv_out)[argnum] = apr_palloc(token_context, cp - ct);
apr_cpystrn((*argv_out)[argnum], ct, cp - ct);
+ cleaned = dirty = (*argv_out)[argnum];
+ REMOVE_ESCAPE_CHARS(cleaned, dirty, escaped);
SKIP_WHITESPACE(cp);
}
(*argv_out)[argnum] = NULL;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic