Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 28194 invoked from network); 10 Sep 2009 11:21:20 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 10 Sep 2009 11:21:20 -0000 Received: (qmail 74487 invoked by uid 500); 10 Sep 2009 11:21:20 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 74397 invoked by uid 500); 10 Sep 2009 11:21:20 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 74386 invoked by uid 99); 10 Sep 2009 11:21:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2009 11:21:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Sep 2009 11:21:16 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7400123888E7; Thu, 10 Sep 2009 11:20:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r813369 - in /commons/sandbox/runtime/trunk/src/main/native: include/acr_port.h port/shquote.c Date: Thu, 10 Sep 2009 11:20:55 -0000 To: commits@commons.apache.org From: mturk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090910112055.7400123888E7@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mturk Date: Thu Sep 10 11:20:54 2009 New Revision: 813369 URL: http://svn.apache.org/viewvc?rev=813369&view=rev Log: Add strquote that is mandatory for windows cmdlines Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h commons/sandbox/runtime/trunk/src/main/native/port/shquote.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h?rev=813369&r1=813368&r2=813369&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_port.h Thu Sep 10 11:20:54 2009 @@ -118,6 +118,7 @@ size_t shquote(const char *, char *, size_t); size_t shquotev(int, char * const *, char *, size_t); #endif +size_t strquote(const char *, char *, size_t); +size_t wcsquote(const wchar_t *, wchar_t *, size_t); #endif /* _ACR_PORT_H */ - Modified: commons/sandbox/runtime/trunk/src/main/native/port/shquote.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/port/shquote.c?rev=813369&r1=813368&r2=813369&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/port/shquote.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/port/shquote.c Thu Sep 10 11:20:54 2009 @@ -78,11 +78,9 @@ #include "acr_arch.h" #include "acr_port.h" -#if defined(ACR_WANT_SHQUOTE) - #define INCH() \ do { \ - n = ((c = *arg) != '\0') ? 1 : 0; \ + n = ((c = *arg) != 0) ? 1 : 0; \ } while (0) #define PUTC(x) \ @@ -91,8 +89,8 @@ if (bufsize != 0) { \ if (bufsize < 1 || \ (bufsize == 1 && \ - (x) != '\0')) { \ - *buf = '\0'; \ + (x) != 0)) { \ + *buf = 0; \ bufsize = 0; \ } else { \ *(buf++) = (x); \ @@ -101,6 +99,7 @@ } \ } while (0) +#if defined(ACR_WANT_SHQUOTE) size_t shquote(const char *arg, char *buf, size_t bufsize) { char c, lastc; @@ -191,8 +190,115 @@ bad: return (size_t)-1; } -#else +#endif /* ACR_WANT_SHQUOTE */ -UNUSED_SOURCE_FILE(shquote); +/* Just like shquote but surounds the arg by double quotes if + * the arg contains space sharacters + */ +size_t strquote(const char *arg, char *buf, size_t bufsize) +{ + char c, lastc; + size_t rv; + int n; -#endif /* ACR_WANT_SHQUOTE */ + rv = 0; + lastc = 0; + if (!strpbrk(arg, " \t")) { + /* Just copy over the arg */ + return strlcpy(buf, arg, bufsize); + } + if (*arg != '"') { + PUTC('"'); + } + for (;;) { + INCH(); + if (n <= 0) + break; + arg += n; + lastc = c; + + if (c == '"') { + if (rv != 0) { + PUTC('"'); + } + PUTC('\\'); + PUTC('"'); + for (;;) { + INCH(); + if (n <= 0 || c != '"') + break; + PUTC('\\'); + PUTC('"'); + arg += n; + } + if (n > 0) { + PUTC('"'); + } + } + else { + PUTC(c); + } + } + if (lastc != '"') { + PUTC('"'); + } + /* Put NUL terminator, but don't count the NUL. */ + PUTC('\0'); + rv--; + + return rv; +} + +size_t wcsquote(const wchar_t *arg, wchar_t *buf, size_t bufsize) +{ + wchar_t c, lastc; + size_t rv; + int n; + + rv = 0; + lastc = 0; + if (!wcspbrk(arg, L" \t")) { + /* Just copy over the arg */ + return wcslcpy(buf, arg, bufsize); + } + if (*arg != L'"') { + PUTC(L'"'); + } + for (;;) { + INCH(); + if (n <= 0) + break; + arg += n; + lastc = c; + + if (c == L'"') { + if (rv != 0) { + PUTC(L'"'); + } + PUTC(L'\\'); + PUTC(L'"'); + for (;;) { + INCH(); + if (n <= 0 || c != L'"') + break; + PUTC(L'\\'); + PUTC(L'"'); + arg += n; + } + if (n > 0) { + PUTC(L'"'); + } + } + else { + PUTC(c); + } + } + if (lastc != L'"') { + PUTC(L'"'); + } + /* Put NUL terminator, but don't count the NUL. */ + PUTC(L'\0'); + rv--; + + return rv; +}