]> sourceware.org Git - systemtap.git/commitdiff
PR14927: make stap use same parser as staprun for consistency
authorJonathan Lebon <jlebon@redhat.com>
Mon, 8 Jul 2013 15:34:15 +0000 (11:34 -0400)
committerJonathan Lebon <jlebon@redhat.com>
Mon, 8 Jul 2013 17:03:30 +0000 (13:03 -0400)
In order to ensure that both stap and staprun react the same way to
various values of SYSTEMTAP_COLORS, the parsing method in staprun was
copied to replace the one in stap (with small C++ adjustments).

This will also allow us to test both stap and staprun using the same
test cases (see the next commit).

session.cxx

index a738de264badcad29dc4d357fc2183d11ce8df7e..08435beac57e0b32de35e153b688ec49dd67fdc2 100644 (file)
@@ -2124,24 +2124,30 @@ For example, the default setting would be:
 std::string
 systemtap_session::parse_stap_color(std::string type)
 {
-  const char *p = getenv("SYSTEMTAP_COLORS");
-  if (p == NULL || *p == '\0')
-    p = "error=01;31:warning=00;33:source=00;34:caret=01:token=01";
-
-  vector<string> bits;
-  tokenize(string(p), bits, ":");
-  for (unsigned i=0; i<bits.size(); i++)
-    {
-      const string& bit = bits[i];
-      if ((bit.substr(0,type.size()+1)) == (type+"=")) {
-        string val = bit.substr(type.size()+1);
-        if (val.find_first_not_of("0123456789;") != string::npos)
-          return ""; // invalid char in val
-        else
-          return val;
-      }
+  const char *key, *col, *eq;
+  int n = type.size();
+  int done = 0;
+
+  key = getenv("SYSTEMTAP_COLORS");
+  if (key == NULL || *key == '\0')
+    key = "error=01;31:warning=00;33:source=00;34:caret=01:token=01";
+
+  while (!done) {
+  if (!(col = strchr(key, ':'))) {
+      col = strchr(key, '\0');
+      done = 1;
     }
-  
+    if (!((eq = strchr(key, '=')) && eq < col))
+      return ""; /* invalid syntax: no = in range */
+    if (!(key < eq && eq < col-1))
+      return ""; /* invalid syntax: key or val empty */
+    if (strspn(eq+1, "0123456789;") < (size_t)(col-eq-1))
+      return ""; /* invalid syntax: invalid char in val */
+    if (eq-key == n && type.compare(0, n, key))
+      return string(eq+1, col-eq-1);
+    if (!done) key = col+1; /* advance to next key */
+  }
+
   // Could not find the key
   return "";
 }
This page took 0.036683 seconds and 5 git commands to generate.