<commit_before>#ifdef __linux__ /* XXX hack for strcasestr(). */
#define _GNU_SOURCE
#endif /* __linux__ */

#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>

#include "kcn_str.h"
#include "kcn_time.h"
#include "kcn_eq.h"

const char *
kcn_eq_type_ntoa(enum kcn_eq_type type)
{
	static const char *name[KCN_EQ_TYPE_MAX] = {
		[KCN_EQ_TYPE_NONE]	= "none",
		[KCN_EQ_TYPE_STORAGE]	= "storage",
		[KCN_EQ_TYPE_CPULOAD]	= "cpu",
		[KCN_EQ_TYPE_TRAFFIC]	= "traffic",
		[KCN_EQ_TYPE_RTT]	= "rtt",
		[KCN_EQ_TYPE_HOPCOUNT]	= "hopcount",
		[KCN_EQ_TYPE_ASPATHLEN]	= "aspathlen",
		[KCN_EQ_TYPE_WLANASSOC]	= "wlanassoc"
	};
	if (type <= KCN_EQ_TYPE_NONE || type >= KCN_EQ_TYPE_MAX) {
		errno = ENOENT;
		return NULL;
	}
	return name[type];
}

bool
kcn_eq_type_aton(const char *s, enum kcn_eq_type *typep)
{
#define ISMATCH(a)							\
	(strncasecmp((a), s, sizeof(a)) == 0 ? true : false)
	if (ISMATCH("HDD") || ISMATCH("storage"))
		*typep = KCN_EQ_TYPE_STORAGE;
	else if (ISMATCH("CPU") || ISMATCH("load"))
		*typep = KCN_EQ_TYPE_CPULOAD;
	else if (ISMATCH("traffic"))
		*typep = KCN_EQ_TYPE_TRAFFIC;
	else if (ISMATCH("rtt"))
		*typep = KCN_EQ_TYPE_RTT;
	else if (ISMATCH("hop") || ISMATCH("ttl"))
		*typep = KCN_EQ_TYPE_HOPCOUNT;
	else if (ISMATCH("as"))
		*typep = KCN_EQ_TYPE_ASPATHLEN;
	else if (ISMATCH("assoc"))
		*typep = KCN_EQ_TYPE_WLANASSOC;
	else {
		errno = ENOENT;
		return false;
	}
#undef ISMATCH
	return true;
}

bool
kcn_eq_operator_aton(const char *w, enum kcn_eq_operator *opp)
{

	if (strcasecmp("<", w) == 0 ||
	    strcasecmp("lt", w) == 0)
		*opp = KCN_EQ_OP_LT;
	else if (strcasecmp("<=", w) == 0 ||
	    strcasecmp("le", w) == 0)
		*opp = KCN_EQ_OP_LE;
	else if (strcasecmp("=", w) == 0 ||
	    strcasecmp("==", w) == 0 ||
	    strcasecmp("eq", w) == 0)
		*opp = KCN_EQ_OP_EQ;
	else if (strcasecmp(">", w) == 0 ||
	    strcasecmp("gt", w) == 0)
		*opp = KCN_EQ_OP_GT;
	else if (strcasecmp(">=", w) == 0 ||
	    strcasecmp("ge", w) == 0)
		*opp = KCN_EQ_OP_GE;
	else {
		errno = ENOENT;
		return false;
	}
	return true;
}

bool
kcn_eq_val_aton(const char *w, unsigned long long *valp)
{

	return kcn_strtoull(w, 0, ULLONG_MAX, valp);
}

bool
kcn_eq_time_match(time_t t, const struct kcn_eq *ke)
{

	if (ke->ke_end != KCN_TIME_NOW && t > ke->ke_end)
		return false;
	if (t < ke->ke_start)
		return false;
	return true;
}
<commit_msg>fix the wrong database string.<commit_after>#ifdef __linux__ /* XXX hack for strcasestr(). */
#define _GNU_SOURCE
#endif /* __linux__ */

#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>

#include "kcn_str.h"
#include "kcn_time.h"
#include "kcn_eq.h"

const char *
kcn_eq_type_ntoa(enum kcn_eq_type type)
{
	static const char *name[KCN_EQ_TYPE_MAX] = {
		[KCN_EQ_TYPE_NONE]	= "none",
		[KCN_EQ_TYPE_STORAGE]	= "storage",
		[KCN_EQ_TYPE_CPULOAD]	= "cpu",
		[KCN_EQ_TYPE_TRAFFIC]	= "traffic",
		[KCN_EQ_TYPE_RTT]	= "rtt",
		[KCN_EQ_TYPE_HOPCOUNT]	= "hopcount",
		[KCN_EQ_TYPE_ASPATHLEN]	= "aspathlen",
		[KCN_EQ_TYPE_WLANASSOC]	= "wlanassoc"
	};
	if (type <= KCN_EQ_TYPE_NONE || type >= KCN_EQ_TYPE_MAX) {
		errno = ENOENT;
		return NULL;
	}
	return name[type];
}

bool
kcn_eq_type_aton(const char *s, enum kcn_eq_type *typep)
{
#define ISMATCH(a)							\
	(strncasecmp((a), s, sizeof(a)) == 0 ? true : false)
	if (ISMATCH("hdd") || ISMATCH("storage"))
		*typep = KCN_EQ_TYPE_STORAGE;
	else if (ISMATCH("cpu") || ISMATCH("load"))
		*typep = KCN_EQ_TYPE_CPULOAD;
	else if (ISMATCH("traffic"))
		*typep = KCN_EQ_TYPE_TRAFFIC;
	else if (ISMATCH("rtt"))
		*typep = KCN_EQ_TYPE_RTT;
	else if (ISMATCH("hopcount") || ISMATCH("ttl"))
		*typep = KCN_EQ_TYPE_HOPCOUNT;
	else if (ISMATCH("aspathlen"))
		*typep = KCN_EQ_TYPE_ASPATHLEN;
	else if (ISMATCH("wlanassoc"))
		*typep = KCN_EQ_TYPE_WLANASSOC;
	else {
		errno = ENOENT;
		return false;
	}
#undef ISMATCH
	return true;
}

bool
kcn_eq_operator_aton(const char *w, enum kcn_eq_operator *opp)
{

	if (strcasecmp("<", w) == 0 ||
	    strcasecmp("lt", w) == 0)
		*opp = KCN_EQ_OP_LT;
	else if (strcasecmp("<=", w) == 0 ||
	    strcasecmp("le", w) == 0)
		*opp = KCN_EQ_OP_LE;
	else if (strcasecmp("=", w) == 0 ||
	    strcasecmp("==", w) == 0 ||
	    strcasecmp("eq", w) == 0)
		*opp = KCN_EQ_OP_EQ;
	else if (strcasecmp(">", w) == 0 ||
	    strcasecmp("gt", w) == 0)
		*opp = KCN_EQ_OP_GT;
	else if (strcasecmp(">=", w) == 0 ||
	    strcasecmp("ge", w) == 0)
		*opp = KCN_EQ_OP_GE;
	else {
		errno = ENOENT;
		return false;
	}
	return true;
}

bool
kcn_eq_val_aton(const char *w, unsigned long long *valp)
{

	return kcn_strtoull(w, 0, ULLONG_MAX, valp);
}

bool
kcn_eq_time_match(time_t t, const struct kcn_eq *ke)
{

	if (ke->ke_end != KCN_TIME_NOW && t > ke->ke_end)
		return false;
	if (t < ke->ke_start)
		return false;
	return true;
}

{'fraction_non_alphanumeric': 0.1704286601780907, 'fraction_numerical': 0.005384137502588528, 'mean_word_length': 4.3547671840354765, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3981268', 'n_tokens_mistral': 2351, 'n_tokens_neox': 2225, 'n_words': 450}