<commit_before>/**
 * Copyright 2012, <NAME>
 * <EMAIL>
 * GPL v2 License -- Commericial Licenses available.
 *
 * (setq-default indent-tabs-mode nil)
 * (setq c-default-style "k&r"
 *     c-basic-offset 4)
 *  indent -kr -nut
 */

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <assert.h>

// order is important here
#include "sqlparse_private.h"
#include "sqlparse_data.h"

#include "modp_burl.h"
#include "modp_ascii.h"
#include "modp_xml.h"

#ifndef MIN
#define MIN(x,y) x < y ? x : y
#endif

bool streq(const char *a, const char *b)
{
    return strcmp(a, b) == 0;
}

stoken_t *st_new()
{
    stoken_t *st = (stoken_t *) malloc(sizeof(stoken_t));
    st->type = CHAR_NULL;
    st->val[0] = CHAR_NULL;
    return st;
}

void st_destroy(stoken_t ** st)
{
    free(*st);
}

void st_clear(stoken_t * st)
{
    st->type = CHAR_NULL;
    st->val[0] = CHAR_NULL;
}

bool st_is_empty(const stoken_t * st)
{
    return st->type == CHAR_NULL;
}

void st_assign_char(stoken_t * st, const char stype, const char value)
{
    st->type = stype;
    st->val[0] = value;
    st->val[1] = CHAR_NULL;
}

void st_assign(stoken_t * st, const char stype, const char *value,
               size_t len)
{
    size_t last = MIN(len, ST_MAX_SIZE - 1);
    st->type = stype;
    strncpy(st->val, value, last);
    st->val[last] = CHAR_NULL;
}

void st_assign_cstr(stoken_t * st, const char stype, const char *value)
{
    st->type = stype;
    strncpy(st->val, value, ST_MAX_SIZE - 1);
    st->val[ST_MAX_SIZE - 1] = CHAR_NULL;
}

bool st_equals_cstr(const stoken_t * st, const char stype,
                    const char *value)
{
    return st->type == stype && !strcmp(value, st->val);
}

void st_copy(stoken_t * dest, const stoken_t * src)
{
    memcpy(dest, src, sizeof(stoken_t));
}

const char *bsearch_cstr(const char *key, const char *base[], size_t nmemb)
{

    size_t pos;
    int left = 0;
    int right = (int)nmemb - 1;
    int cmp = 0;

    while (left <= right) {
        pos = (left + right) / 2;
        cmp = strcmp(base[pos], key);
        if (cmp == 0) {
            return base[pos];
        } else if (cmp < 0) {
            left = pos + 1;
        } else {
            right = pos - 1;
        }
    }
    return NULL;
}


char bsearch_keyword_type(const char *key, const keyword_t * keywords,
                          size_t numb)
{
    int left = 0;
    int right = (int) numb - 1;

    while (left <= right) {
        int pos = (left + right) / 2;
        int cmp = strcmp(keywords[pos].word, key);<commit_msg>fix various C casting nits<commit_after>/**
 * Copyright 2012, <NAME>
 * <EMAIL>
 * GPL v2 License -- Commericial Licenses available.
 *
 * (setq-default indent-tabs-mode nil)
 * (setq c-default-style "k&r"
 *     c-basic-offset 4)
 *  indent -kr -nut
 */

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <assert.h>

// order is important here
#include "sqlparse_private.h"
#include "sqlparse_data.h"

#include "modp_burl.h"
#include "modp_ascii.h"
#include "modp_xml.h"

#ifndef MIN
#define MIN(x,y) x < y ? x : y
#endif

bool streq(const char *a, const char *b)
{
    return strcmp(a, b) == 0;
}

stoken_t *st_new()
{
    stoken_t *st = (stoken_t *) malloc(sizeof(stoken_t));
    st->type = CHAR_NULL;
    st->val[0] = CHAR_NULL;
    return st;
}

void st_destroy(stoken_t ** st)
{
    free(*st);
}

void st_clear(stoken_t * st)
{
    st->type = CHAR_NULL;
    st->val[0] = CHAR_NULL;
}

bool st_is_empty(const stoken_t * st)
{
    return st->type == CHAR_NULL;
}

void st_assign_char(stoken_t * st, const char stype, const char value)
{
    st->type = stype;
    st->val[0] = value;
    st->val[1] = CHAR_NULL;
}

void st_assign(stoken_t * st, const char stype, const char *value,
               size_t len)
{
    size_t last = MIN(len, ST_MAX_SIZE - 1);
    st->type = stype;
    strncpy(st->val, value, last);
    st->val[last] = CHAR_NULL;
}

void st_assign_cstr(stoken_t * st, const char stype, const char *value)
{
    st->type = stype;
    strncpy(st->val, value, ST_MAX_SIZE - 1);
    st->val[ST_MAX_SIZE - 1] = CHAR_NULL;
}

bool st_equals_cstr(const stoken_t * st, const char stype,
                    const char *value)
{
    return st->type == stype && !strcmp(value, st->val);
}

void st_copy(stoken_t * dest, const stoken_t * src)
{
    memcpy(dest, src, sizeof(stoken_t));
}

const char *bsearch_cstr(const char *key, const char *base[], size_t nmemb)
{

    int pos;
    int left = 0;
    int right = (int)nmemb - 1;
    int cmp = 0;

    while (left <= right) {
        pos = (left + right) / 2;
        cmp = strcmp(base[pos], key);
        if (cmp == 0) {
            return base[pos];
        } else if (cmp < 0) {
            left = pos + 1;
        } else {
            right = pos - 1;
        }
    }
    return NULL;
}


char bsearch_keyword_type(const char *key, const keyword_t * keywords,
                          size_t numb)
{
    int left = 0;
    int right = (int) numb - 1;

    while (left <= right) {
        int pos = (left + right) / 2;
        int cmp = strcmp(keywords[pos].word, key);
{'fraction_non_alphanumeric': 0.14754098360655737, 'fraction_numerical': 0.00975800156128025, 'mean_word_length': 2.527185134205093, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '5469068', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1987, 'n_words': 513}