Generate all APIs.

This CL expands the generator to create all the .rsh files, not just
the core_math one.  To do so, processing of types (simple, struct, enums)
and constants was added.  .spec files corresponding to each .rsh file was
created.  Documentation was added.

This CL also generates HTML documentation files.  This generation will soon
be upgraded.

To make the code easier to expand, I've done fairly extensive refactoring.

In a subsequent CL, the APIs will be regrouped in different header files to
simplify learning the APIs.  In an other, the documentation generation will
be futher improved and incorporated in the actual online help.

Also removes rs_path & related functions.

Change-Id: I2c88554c9c6a8625233772b89e055fc6c4ad5da5
diff --git a/api/Utilities.cpp b/api/Utilities.cpp
new file mode 100644
index 0000000..80ebb0d
--- /dev/null
+++ b/api/Utilities.cpp
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <iostream>
+#include <sstream>
+
+#include "Utilities.h"
+
+using namespace std;
+
+const char LEGAL_NOTICE[] =
+            "/*\n"
+            " * Copyright (C) 2015 The Android Open Source Project\n"
+            " *\n"
+            " * Licensed under the Apache License, Version 2.0 (the \"License\");\n"
+            " * you may not use this file except in compliance with the License.\n"
+            " * You may obtain a copy of the License at\n"
+            " *\n"
+            " *      http://www.apache.org/licenses/LICENSE-2.0\n"
+            " *\n"
+            " * Unless required by applicable law or agreed to in writing, software\n"
+            " * distributed under the License is distributed on an \"AS IS\" BASIS,\n"
+            " * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
+            " * See the License for the specific language governing permissions and\n"
+            " * limitations under the License.\n"
+            " */\n\n";
+
+const char AUTO_GENERATED_WARNING[] =
+            "Don't edit this file!  It is auto-generated by frameworks/rs/api/gen_runtime.";
+
+string capitalize(const string& source) {
+    int length = source.length();
+    string result;
+    bool capitalize = true;
+    for (int s = 0; s < length; s++) {
+        if (source[s] == '_') {
+            capitalize = true;
+        } else if (capitalize) {
+            result += toupper(source[s]);
+            capitalize = false;
+        } else {
+            result += source[s];
+        }
+    }
+    return result;
+}
+
+void trimSpaces(string* s) {
+    const size_t end = s->find_last_not_of(" ");
+    if (end == string::npos) {
+        // All spaces
+        s->erase();
+        return;
+    } else {
+        s->erase(end + 1);
+    }
+    const size_t start = s->find_first_not_of(" ");
+    if (start > 0) {
+        s->erase(0, start);
+    }
+}
+
+string stringReplace(string s, string match, string rep) {
+    while (1) {
+        // This is not efficient but we don't care, as this program runs very rarely.
+        size_t p = s.find(match);
+        if (p == string::npos) break;
+
+        s.erase(p, match.size());
+        s.insert(p, rep);
+    }
+    return s;
+}
+
+bool charRemoved(char c, string* s) {
+    size_t p = s->find(c);
+    if (p != string::npos) {
+        s->erase(p, 1);
+        return true;
+    }
+    return false;
+}
+
+string stripHtml(const string& html) {
+    string s;
+    for (size_t start = 0; start < html.size(); start++) {
+        size_t lt = html.find('<', start);
+        if (lt == string::npos) {
+            s += html.substr(start);
+            break;
+        }
+        s += html.substr(start, lt - start);
+        if (isalpha(html[lt + 1]) || html[lt + 1] == '/') {
+            // It's an HTML tag.  Search for the end.
+            start = html.find('>', lt + 1);
+            if (start == string::npos) {
+                break;
+            }
+        } else {
+            s += '<';
+        }
+    }
+    s = stringReplace(s, "&gt;", ">");
+    s = stringReplace(s, "&lt;", "<");
+    s = stringReplace(s, "&nbsp;", " ");
+    return s;
+}
+
+string hashString(const string& s) {
+    long hash = 0;
+    for (size_t i = 0; i < s.length(); i++) {
+        hash = hash * 43 + s[i];
+    }
+    stringstream stream;
+    stream << "0x" << std::hex << hash << "l";
+    return stream.str();
+}
+
+bool testAndSet(const string& flag, set<string>* set) {
+    if (set->find(flag) == set->end()) {
+        set->insert(flag);
+        return false;
+    }
+    return true;
+}
+
+double maxDoubleForInteger(int numberOfIntegerBits, int mantissaSize) {
+    /* Double has only 52 bits of precision (53 implied). So for longs, we want
+     * to create smaller values to avoid a round up.  Same for floats and halfs.
+     */
+    int lowZeroBits = max(0, numberOfIntegerBits - mantissaSize);
+    unsigned long l = (0xffffffffffffffff >> (64 - numberOfIntegerBits + lowZeroBits))
+                      << lowZeroBits;
+    return (double)l;
+}
+
+// Opens the stream.  Reports an error if it can't.
+bool GeneratedFile::start(const string& name) {
+    open(name.c_str(), ios::out | ios::trunc);
+    if (!is_open()) {
+        cerr << "Error.  Can't open the output file: " << name << "\n";
+        return false;
+    }
+    return true;
+}
+
+void GeneratedFile::writeNotices() {
+    *this << LEGAL_NOTICE;
+    *this << "// " << AUTO_GENERATED_WARNING << "\n\n";
+}
+
+void GeneratedFile::increaseIndent() {
+    mIndent.append(string(TAB_SIZE, ' '));
+}
+
+void GeneratedFile::decreaseIndent() {
+    mIndent.erase(0, TAB_SIZE);
+}