Correct word hyphenations
[oota-llvm.git] / utils / TableGen / OptParserEmitter.cpp
index f2694361db0553f391ed5955cf87b8a6af03c969..9c4daaf7747dbed13c427dbfec7a1c46d767e778 100644 (file)
 #include "llvm/TableGen/Record.h"
 #include "llvm/TableGen/TableGenBackend.h"
 #include <cstring>
+#include <cctype>
 #include <map>
-#include <strings.h>
 
 using namespace llvm;
 
 // Ordering on Info. The logic should match with the consumer-side function in
 // llvm/Option/OptTable.h.
 static int StrCmpOptionName(const char *A, const char *B) {
-  size_t I = strlen(A);
-  size_t J = strlen(B);
-  if (I == J) {
-    if (int N = strcasecmp(A, B))
-      return N;
-    return strcmp(A, B);
+  const char *X = A, *Y = B;
+  char a = tolower(*A), b = tolower(*B);
+  while (a == b) {
+    if (a == '\0')
+      return strcmp(A, B);
+
+    a = tolower(*++X);
+    b = tolower(*++Y);
   }
-  if (I < J)
-    return strncasecmp(A, B, I) < 0 ? -1 : 1;
-  return strncasecmp(A, B, J) <= 0 ? -1 : 1;
+
+  if (a == '\0') // A is a prefix of B.
+    return 1;
+  if (b == '\0') // B is a prefix of A.
+    return -1;
+
+  // Otherwise lexicographic.
+  return (a < b) ? -1 : 1;
 }
 
-static int CompareOptionRecords(const void *Av, const void *Bv) {
-  const Record *A = *(const Record*const*) Av;
-  const Record *B = *(const Record*const*) Bv;
+static int CompareOptionRecords(Record *const *Av, Record *const *Bv) {
+  const Record *A = *Av;
+  const Record *B = *Bv;
 
   // Sentinel options precede all others and are only ordered by precedence.
   bool ASent = A->getValueAsDef("Kind")->getValueAsBit("Sentinel");
@@ -72,7 +79,7 @@ static int CompareOptionRecords(const void *Av, const void *Bv) {
   if (APrec == BPrec &&
       A->getValueAsListOfStrings("Prefixes") ==
       B->getValueAsListOfStrings("Prefixes")) {
-    PrintError(A->getLoc(), Twine("Option is equivilent to"));
+    PrintError(A->getLoc(), Twine("Option is equivalent to"));
     PrintError(B->getLoc(), Twine("Other defined here"));
     PrintFatalError("Equivalent Options found.");
   }