]> sourceware.org Git - newlib-cygwin.git/commitdiff
* environ.cc (strbrk): New function.
authorChristopher Faylor <me@cgf.cx>
Sun, 9 Feb 2014 20:30:24 +0000 (20:30 +0000)
committerChristopher Faylor <me@cgf.cx>
Sun, 9 Feb 2014 20:30:24 +0000 (20:30 +0000)
(parse_options): Use strbrk to parse CYGWIN environment variable.

winsup/cygwin/ChangeLog
winsup/cygwin/environ.cc

index a53aad0e889096a2c8db1e63515141dd97ffd872..3e8dacdd44ce8447b8b26b71a27df0a7e61a6c98 100644 (file)
@@ -1,3 +1,8 @@
+2014-02-09  Christopher Faylor  <me.cygwin2014@cgf.cx>
+
+       * environ.cc (strbrk): New function.
+       (parse_options): Use strbrk to parse CYGWIN environment variable.
+
 2014-02-09  Corinna Vinschen  <corinna@vinschen.de>
 
        Introduce reading passwd/group entries from SAM/AD.  Introduce
index 295f4248ac7daa1051fa642cc56c60c6455efb4a..5ac155e37e863eb75eb847c29c0b757e9c485a35 100644 (file)
@@ -137,13 +137,54 @@ static struct parse_thing
   {NULL, {0}, setdword, 0, {{0}, {0}}}
 };
 
+/* Return a possibly-quoted token.
+   Returns NULL when no more tokens available.  */
+static char *
+strbrk(char *&buf)
+{
+  buf += strspn(buf, " \t");
+  if (!*buf)
+    return NULL;
+  char *tok = buf;
+  char *sep = buf + strcspn(buf, " \t");
+  char *quotestart = strchr(buf, '"');
+  if (quotestart > sep)
+    {
+      quotestart = NULL;
+      buf = sep + 1;
+    }
+  else
+    {
+      char *quote = quotestart;
+      sep = NULL;
+      while (!sep)
+       {
+         char *clquote = strchr (quote + 1, '"');
+         if (!clquote)
+           sep = strchr (quote, '\0');
+         else if (clquote[-1] != '\\')
+           sep = clquote;
+         else
+           {
+             memmove (clquote - 1, clquote, 1 + strchr (clquote, '\0') - clquote);
+             quote = clquote - 1;
+           }
+       }
+      buf = sep + 1;
+      memmove (quotestart, quotestart + 1, sep - quotestart);
+      sep--;
+    }
+  *sep = '\0';
+  return tok;
+}
+
+
 /* Parse a string of the form "something=stuff somethingelse=more-stuff",
    silently ignoring unknown "somethings".  */
 static void __stdcall
 parse_options (const char *inbuf)
 {
   int istrue;
-  char *p, *lasts;
   parse_thing *k;
 
   if (inbuf == NULL)
@@ -168,9 +209,8 @@ parse_options (const char *inbuf)
     }
 
   char *buf = strcpy ((char *) alloca (strlen (inbuf) + 1), inbuf);
-  for (p = strtok_r (buf, " \t", &lasts);
-       p != NULL;
-       p = strtok_r (NULL, " \t", &lasts))
+
+  while (char *p = strbrk (buf))
     {
       char *keyword_here = p;
       if (!(istrue = !ascii_strncasematch (p, "no", 2)))
This page took 0.036167 seconds and 5 git commands to generate.