<commit_before>/**
 * @file
 *
 * @brief
 *
 * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
 */

#include "parser.hpp"

#include <algorithm>
#include <fstream>
#include <iostream>

#ifndef _WIN32
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#endif

using namespace std;

static ostream & printKDBErrors (ostream & os, parse_t & p)
{
	os << "/*This is an auto-generated file generated by exporterrors. Do not modify it.*/" << endl
	   << endl
	   << "#ifndef KDBERRORS_H" << endl
	   << "#define KDBERRORS_H" << endl
	   << endl
	   << "#include <kdb.h>" << endl
	   << "#include <kdbhelper.h>" << endl
	   << "#include <kdblogger.h>" << endl
	   << "#include <kdbmacros.h>" << endl
	   << "#include <string.h>" << endl
	   << endl
	   << "#ifdef __cplusplus" << endl
	   << "	using namespace ckdb;" << endl
	   << endl;
	os << endl << endl;
	os << "#endif" << endl;

	for (size_t i = 1; i < p.size (); ++i)
	{
		os << "#define ELEKTRA_SET_" << p[i]["macro"] << "_ERROR(key, text) ELEKTRA_SET_ERROR_HELPER\\" << endl;
		os << "	(" << p[i]["number"] << ", key, text, __FILE__, __LINE__)" << endl;
		os << "#define ELEKTRA_SET_" << p[i]["macro"] << "_ERRORF(key, text, ...) ELEKTRA_SET_ERRORF_HELPER\\" << endl;
		os << "	(" << p[i]["number"] << ", key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl << endl;

		os << "#define ELEKTRA_ADD_" << p[i]["macro"] << "_WARNING(key, text) ELEKTRA_ADD_WARNING_HELPER\\" << endl;
		os << "	(" << p[i]["number"] << ", key, text, __FILE__, __LINE__)" << endl;
		os << "#define ELEKTRA_ADD_" << p[i]["macro"] << "_WARNINGF(key, text, ...) ELEKTRA_ADD_WARNINGF_HELPER\\" << endl;
		os << "	(" << p[i]["number"] << ", key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl << endl;
	}
	//    << "#define ELEKTRA_SET_ERROR(number, key, text) ELEKTRA_SET_ERROR_HELPER\\" << endl
	//    << "	(number, key, text, __FILE__, __LINE__)" << endl
	//    << endl
	os << "#define ELEKTRA_SET_ERROR_HELPER(number, key, text, file, line) ELEKTRA_SET_ERROR_HELPER_HELPER\\" << endl
	   << "	(number, key, text, file, line)" << endl
	   << endl
	   << "#define ELEKTRA_SET_ERROR_HELPER_HELPER(number, key, text, file, line) do {ELEKTRA_LOG (\"Add Error %s: %s\", "
	      "number, text); elektraSetError ## number\\"
	   << endl
	   << "	(key, text, file, #line); } while (0)" << endl
	   << endl
	   << endl
	   //    << "#define ELEKTRA_ADD_WARNING(number, key, text) ELEKTRA_ADD_WARNING_HELPER\\" << endl
	   //    << "	(number, key, text, __FILE__, __LINE__)" << endl
	   //    << "" << endl
	   << "#define ELEKTRA_ADD_WARNING_HELPER(number, key, text, file, line) ELEKTRA_ADD_WARNING_HELPER_HELPER\\" << endl
	   << "	(number, key, text, file, line)" << endl
	   << "" << endl
	   << "#define ELEKTRA_ADD_WARNING_HELPER_HELPER(number, key, text, file, line) do {ELEKTRA_LOG (\"Add Warning %s: %s\", "
	      "number, text);  elektraAddWarning ## number\\"
	   << endl
	   << "	(key, text, file, #line);} while (0)" << endl
	   << endl
	   << endl
	   << "#define ELEKTRA_SET_ERRORF(number, key, text, ...) ELEKTRA_SET_ERRORF_HELPER\\" << endl
	   << "	(number, key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl
	   << endl
	   << "#define ELEKTRA_SET_ERRORF_HELPER(number, key, text, file, line, ...) ELEKTRA_SET_ERRORF_HELPER_HELPER\\" << endl
	   << "	(number, key, text, file, line, __VA_ARGS__)" << endl
	   << endl
	   << "#define ELEKTRA_SET_ERRORF_HELPER_HELPER(number, key, text, file, line, ...) do {ELEKTRA_LOG (\"Add Error \" "
	      "ELEKTRA_STRINGIFY(number) \" : \" text, __VA_ARGS__); elektraSetErrorf ## number\\"
	   << endl
	   << "	(key, text, file, #line,  __VA_ARGS__); } while (0)" << endl
	   << endl
	   << endl
	   << "#define ELEKTRA_ADD_WARNINGF(number, key, text, ...) ELEKTRA_ADD_WARNINGF_HELPER\\" << endl
	   << "	(number, key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl
	   << "" << endl
	   << "#define ELEKTRA_ADD_WARNINGF_HELPER(number, key, text, file, line, ...) ELEKTRA_ADD_WARNINGF_HELPER_HELPER\\" << endl
	   << "	(number, key, text, file, line, __VA_ARGS__)" << endl
	   << "" << endl
	   << "#define ELEKTRA_ADD_WARNINGF_HELPER_HELPER(number, key, text, file, line, ...)  do {ELEKTRA_LOG (\"Add Warning \" "
	      "ELEKTRA_STRINGIFY(number) \" : \" text, __VA_ARGS__); elektraAddWarningf ## number\\"
	   << endl
	   << "	(key, text, file, #line, __VA_ARGS__); } while (0)" << endl
	   << endl
	   << endl;

	for (size_t i = 1; i < p.size (); ++i)
	{
		if (p[i]["unused"] == "yes")
		{
			continue;
		}

		if (p[i]["macro"].empty ())
		{
			continue;
		}

		os << "#define ELEKTRA_WARNING_" << p[i]["macro"] << " " << p[i]["number"] << "" << endl;
		os << "#define ELEKTRA_ERROR_" << p[i]["macro"] << " " << p[i]["number"] << "" << endl;
	}

	os << endl << endl;

	for (size_t i = 1; i < p.size (); ++i)
	{

		for (int f = 0; f < 2; ++f)
		{
			if (f == 0)
			{
				os << "static inline void elektraAddWarningf" << p[i]["number"] << "(Key *warningKey, const char *reason,"
				   << endl
				   << "	const char *file, const char *line, ...)  __attribute__ ((format (printf, 2, 5)));" << endl;
				os << "static inline void elektraAddWarningf" << p[i]["number"] << "(Key *warningKey, const char *reason,"
				   << endl
				   << "	const char *file, const char *line, ...)" << endl;
			}
			else
			{
				os << "static inline void elektraAddWarning" << p[i]["number"] << "(Key *warningKey, const char *reason,"
				   << endl<commit_msg>error: Added error if no macro is added<commit_after>/**
 * @file
 *
 * @brief
 *
 * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
 */

#include "parser.hpp"

#include <algorithm>
#include <fstream>
#include <iostream>

#ifndef _WIN32
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#endif

using namespace std;

static ostream & printKDBErrors (ostream & os, parse_t & p)
{
	os << "/*This is an auto-generated file generated by exporterrors. Do not modify it.*/" << endl
	   << endl
	   << "#ifndef KDBERRORS_H" << endl
	   << "#define KDBERRORS_H" << endl
	   << endl
	   << "#include <kdb.h>" << endl
	   << "#include <kdbhelper.h>" << endl
	   << "#include <kdblogger.h>" << endl
	   << "#include <kdbmacros.h>" << endl
	   << "#include <string.h>" << endl
	   << endl
	   << "#ifdef __cplusplus" << endl
	   << "	using namespace ckdb;" << endl
	   << endl;
	os << endl << endl;
	os << "#endif" << endl;

	for (size_t i = 1; i < p.size (); ++i)
	{
		os << "#define ELEKTRA_SET_" << p[i]["macro"] << "_ERROR(key, text) ELEKTRA_SET_ERROR_HELPER\\" << endl;
		os << "	(" << p[i]["number"] << ", key, text, __FILE__, __LINE__)" << endl;
		os << "#define ELEKTRA_SET_" << p[i]["macro"] << "_ERRORF(key, text, ...) ELEKTRA_SET_ERRORF_HELPER\\" << endl;
		os << "	(" << p[i]["number"] << ", key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl << endl;

		os << "#define ELEKTRA_ADD_" << p[i]["macro"] << "_WARNING(key, text) ELEKTRA_ADD_WARNING_HELPER\\" << endl;
		os << "	(" << p[i]["number"] << ", key, text, __FILE__, __LINE__)" << endl;
		os << "#define ELEKTRA_ADD_" << p[i]["macro"] << "_WARNINGF(key, text, ...) ELEKTRA_ADD_WARNINGF_HELPER\\" << endl;
		os << "	(" << p[i]["number"] << ", key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl << endl;
	}
	//    << "#define ELEKTRA_SET_ERROR(number, key, text) ELEKTRA_SET_ERROR_HELPER\\" << endl
	//    << "	(number, key, text, __FILE__, __LINE__)" << endl
	//    << endl
	os << "#define ELEKTRA_SET_ERROR_HELPER(number, key, text, file, line) ELEKTRA_SET_ERROR_HELPER_HELPER\\" << endl
	   << "	(number, key, text, file, line)" << endl
	   << endl
	   << "#define ELEKTRA_SET_ERROR_HELPER_HELPER(number, key, text, file, line) do {ELEKTRA_LOG (\"Add Error %s: %s\", "
	      "number, text); elektraSetError ## number\\"
	   << endl
	   << "	(key, text, file, #line); } while (0)" << endl
	   << endl
	   << endl
	   //    << "#define ELEKTRA_ADD_WARNING(number, key, text) ELEKTRA_ADD_WARNING_HELPER\\" << endl
	   //    << "	(number, key, text, __FILE__, __LINE__)" << endl
	   //    << "" << endl
	   << "#define ELEKTRA_ADD_WARNING_HELPER(number, key, text, file, line) ELEKTRA_ADD_WARNING_HELPER_HELPER\\" << endl
	   << "	(number, key, text, file, line)" << endl
	   << "" << endl
	   << "#define ELEKTRA_ADD_WARNING_HELPER_HELPER(number, key, text, file, line) do {ELEKTRA_LOG (\"Add Warning %s: %s\", "
	      "number, text);  elektraAddWarning ## number\\"
	   << endl
	   << "	(key, text, file, #line);} while (0)" << endl
	   << endl
	   << endl
	   << "#define ELEKTRA_SET_ERRORF(number, key, text, ...) ELEKTRA_SET_ERRORF_HELPER\\" << endl
	   << "	(number, key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl
	   << endl
	   << "#define ELEKTRA_SET_ERRORF_HELPER(number, key, text, file, line, ...) ELEKTRA_SET_ERRORF_HELPER_HELPER\\" << endl
	   << "	(number, key, text, file, line, __VA_ARGS__)" << endl
	   << endl
	   << "#define ELEKTRA_SET_ERRORF_HELPER_HELPER(number, key, text, file, line, ...) do {ELEKTRA_LOG (\"Add Error \" "
	      "ELEKTRA_STRINGIFY(number) \" : \" text, __VA_ARGS__); elektraSetErrorf ## number\\"
	   << endl
	   << "	(key, text, file, #line,  __VA_ARGS__); } while (0)" << endl
	   << endl
	   << endl
	   << "#define ELEKTRA_ADD_WARNINGF(number, key, text, ...) ELEKTRA_ADD_WARNINGF_HELPER\\" << endl
	   << "	(number, key, text, __FILE__, __LINE__, __VA_ARGS__)" << endl
	   << "" << endl
	   << "#define ELEKTRA_ADD_WARNINGF_HELPER(number, key, text, file, line, ...) ELEKTRA_ADD_WARNINGF_HELPER_HELPER\\" << endl
	   << "	(number, key, text, file, line, __VA_ARGS__)" << endl
	   << "" << endl
	   << "#define ELEKTRA_ADD_WARNINGF_HELPER_HELPER(number, key, text, file, line, ...)  do {ELEKTRA_LOG (\"Add Warning \" "
	      "ELEKTRA_STRINGIFY(number) \" : \" text, __VA_ARGS__); elektraAddWarningf ## number\\"
	   << endl
	   << "	(key, text, file, #line, __VA_ARGS__); } while (0)" << endl
	   << endl
	   << endl;

	for (size_t i = 1; i < p.size (); ++i)
	{
		if (p[i]["unused"] == "yes")
		{
			continue;
		}

		if (p[i]["macro"].empty ())
		{
			throw invalid_argument ("Error with number " + p[i]["number"] + " does not have a mandatory macro.");
		}

		os << "#define ELEKTRA_WARNING_" << p[i]["macro"] << " " << p[i]["number"] << "" << endl;
		os << "#define ELEKTRA_ERROR_" << p[i]["macro"] << " " << p[i]["number"] << "" << endl;
	}

	os << endl << endl;

	for (size_t i = 1; i < p.size (); ++i)
	{

		for (int f = 0; f < 2; ++f)
		{
			if (f == 0)
			{
				os << "static inline void elektraAddWarningf" << p[i]["number"] << "(Key *warningKey, const char *reason,"
				   << endl
				   << "	const char *file, const char *line, ...)  __attribute__ ((format (printf, 2, 5)));" << endl;
				os << "static inline void elektraAddWarningf" << p[i]["number"] << "(Key *warningKey, const char *reason,"
				   << endl
				   << "	const char *file, const char *line, ...)" << endl;
			}
			else
			{
				os << "static inline void elektraAddWarning" << p[i]["number"] << "(Key *warningKey, const char *reason,"
				   << endl
{'fraction_non_alphanumeric': 0.20897390060779406, 'fraction_numerical': 0.0025026814444047193, 'mean_word_length': 3.3401861908456167, 'pattern_counts': {'":': 0, '<': 681, '<?xml version=': 0, '>': 33, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7456808', 'n_tokens_mistral': 4614, 'n_tokens_neox': 4230, 'n_words': 999}