From e081345595453d203542e41449568ddbb8deeed2 Mon Sep 17 00:00:00 2001
From: Sebastien Barre <sebastien.barre@kitware.com>
Date: Thu, 28 Mar 2002 11:43:53 -0500
Subject: ENH: perform case insensitive comparison on test names

---
 Source/cmCreateTestSourceList.cxx | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/Source/cmCreateTestSourceList.cxx b/Source/cmCreateTestSourceList.cxx
index 895d5aa..1f64772 100644
--- a/Source/cmCreateTestSourceList.cxx
+++ b/Source/cmCreateTestSourceList.cxx
@@ -58,6 +58,7 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
 
   fout << 
     "#include <stdio.h>\n"
+    "#include <stdlib.h>\n"
     "#include <string.h>\n"
     "\n"
     "// Forward declare test functions\n"
@@ -112,6 +113,25 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
   fout << 
     "};\n"
     "\n"
+    "// Allocate and create a lowercased copy of string\n"
+    "\n"
+    "char* lowercase(const char *string)\n"
+    "{\n"
+    "  char *new_string = new char[strlen(string) + 1];\n"
+    "  if (!new_string)\n"
+    "    {\n"
+    "    return NULL;\n"
+    "    }\n"
+    "  strcpy(new_string, string);\n"
+    "  char *p = new_string;\n"
+    "  while (*p != NULL)\n"
+    "    {\n"
+    "    *p = tolower(*p);\n"
+    "    ++p;\n"
+    "    }\n"
+    "  return new_string;\n"
+    "}\n"
+    "\n"
     "int main(int ac, char** av)\n"
     "{\n"
     "  int NumTests = " << numTests << ";\n"
@@ -151,20 +171,21 @@ bool cmCreateTestSourceList::InitialPass(std::vector<std::string> const& argsIn)
     "    return -1;\n"
     "    }\n"
     "  \n"
-    "  // A test name was given, try to find it\n"
+    "  char *arg = lowercase(av[1 + partial_match]);\n"
     "  for (i =0; i < NumTests; ++i)\n"
     "    {\n"
-    "    if (partial_match && \n"
-    "        strstr(cmakeGeneratedFunctionMapEntries[i].name, av[2]) != NULL)\n"
+    "    char *test_name = lowercase(cmakeGeneratedFunctionMapEntries[i].name);\n"
+    "    if (partial_match && strstr(test_name, arg) != NULL)\n"
     "      {\n"
-    "      return (*cmakeGeneratedFunctionMapEntries[i].func)(ac-2, av+2);\n"
+    "      return (*cmakeGeneratedFunctionMapEntries[i].func)(ac - 2, av + 2);\n"
     "      }\n"
-    "    else if (!partial_match && \n"
-    "             strcmp(cmakeGeneratedFunctionMapEntries[i].name, av[1]) == 0)\n"
+    "    else if (!partial_match && strcmp(test_name, arg) == 0)\n"
     "      {\n"
-    "      return (*cmakeGeneratedFunctionMapEntries[i].func)(ac-1, av+1);\n"
+    "      return (*cmakeGeneratedFunctionMapEntries[i].func)(ac - 1, av + 1);\n"
     "      }\n"
+    "    delete [] test_name;\n"
     "    }\n"
+    "  delete [] arg;\n"
     "  \n"
     "  // If the test was not found but there is only one test, then\n"
     "  // run it with the arguments\n"
-- 
cgit v0.12