/* * Copyright (c) 2016 MariaDB Corporation Ab * * Use of this software is governed by the Business Source License included * in the LICENSE.TXT file and at www.mariadb.com/bsl11. * * Change Date: 2022-01-01 * * On the date above, in accordance with the Business Source License, use * of this software will be governed by version 2 or later of the General * Public License. */ #include #include #include #include #include #include #include #include #include #include #include #include using std::cout; using std::endl; int main(int argc, char** argv) { int rc = EXIT_FAILURE; if (argc != 3) { cout << "Usage: canonizer " << endl; return rc; } mxs_log_init(NULL, NULL, MXS_LOG_TARGET_STDOUT); atexit(mxs_log_finish); if (!utils_init()) { cout << "Utils library init failed." << endl; return rc; } set_libdir(strdup("../../../../query_classifier/qc_sqlite/")); set_datadir(strdup("/tmp")); set_langdir(strdup(".")); set_process_datadir(strdup("/tmp")); if (qc_init(NULL, QC_SQL_MODE_DEFAULT, "qc_sqlite", NULL)) { std::ifstream infile(argv[1]); std::ofstream outfile(argv[2]); if (infile && outfile) { for (std::string line; getline(infile, line);) { while (*line.rbegin() == '\n') { line.resize(line.size() - 1); } if (!line.empty()) { size_t psize = line.size() + 1; mxs::Buffer buf(psize + 4); auto it = buf.begin(); *it++ = (uint8_t)psize; *it++ = (uint8_t)(psize >> 8); *it++ = (uint8_t)(psize >> 16); *it++ = 0; *it++ = 3; std::copy(line.begin(), line.end(), it); char* tok = qc_get_canonical(buf.get()); outfile << tok << endl; free(tok); } } rc = EXIT_SUCCESS; } else { cout << "Opening files failed." << endl; } qc_end(); } return rc; }