<commit_before>
/*************** M I N I C O N F ***************/
/*  This small library allows to read a simple
    configuration file. Data can be read from
    any FILE* handle (for example stdin).
    <NAME> 2016  <EMAIL>
    GNU GPL 2 license.

    Example file:
    --------------------------
    key1 value1

    # comment
    key2 value2 value3   #  another comment

    key3 "very long # text
    with newline"

    key4   5.0
    key5   6.0  7.5  # hoorayy it's the end
    --------------------------
    CHANGELOG:
    25/02/16 get now searches backwards so that the last
        duplicated entry is found
    01/02/16 Added mincf_get_req.
************************************************/


#include "miniconf.h"

const size_t mincf_bufsz = 2048;

miniconf* mincf_read(FILE* in) {

    char ch;
    int state = PST_B4LABEL;
    int pos = -1;
    int comment = 0;
    int hold = 0;
    int exitloop = 0;
    int i;
    char* tmp;

    miniconf* conf;
    mincf_rec *rec, *tmprec;

    const char s_whsp[] = " \t\n";
    const char s_alph[] = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
    const char s_lbls[] = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM.:-_/";
    const char s_nums[] = "0123456789";

    char none_synonyms[3][20];
    strcpy(none_synonyms[0],"empty");
    strcpy(none_synonyms[1],"None");
    strcpy(none_synonyms[2],"NULL");


    // alloc the structure
    conf = (miniconf*) malloc(sizeof(miniconf));
    if (!conf) return NULL;
    memset(conf, 0, sizeof(miniconf));

    // create buffer
    conf -> buffer_sz = mincf_bufsz;<commit_msg>fixed crash when given empty file handle<commit_after>
/*************** M I N I C O N F ***************/
/*  This small library allows to read a simple
    configuration file. Data can be read from
    any FILE* handle (for example stdin).
    <NAME> 2016  <EMAIL>
    GNU GPL 2 license.

    Example file:
    --------------------------
    key1 value1

    # comment
    key2 value2 value3   #  another comment

    key3 "very long # text
    with newline"

    key4   5.0
    key5   6.0  7.5  # hoorayy it's the end
    --------------------------
    CHANGELOG:
    25/02/16 get now searches backwards so that the last
        duplicated entry is found
    01/02/16 Added mincf_get_req.
************************************************/


#include "miniconf.h"

const size_t mincf_bufsz = 2048;

miniconf* mincf_read(FILE* in) {

    char ch;
    int state = PST_B4LABEL;
    int pos = -1;
    int comment = 0;
    int hold = 0;
    int exitloop = 0;
    int i;
    char* tmp;

    miniconf* conf;
    mincf_rec *rec, *tmprec;

    const char s_whsp[] = " \t\n";
    const char s_alph[] = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
    const char s_lbls[] = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM.:-_/";
    const char s_nums[] = "0123456789";

    char none_synonyms[3][20];
    strcpy(none_synonyms[0],"empty");
    strcpy(none_synonyms[1],"None");
    strcpy(none_synonyms[2],"NULL");

    // if file handle is null, exit
    if (!in)  return NULL;


    // alloc the structure
    conf = (miniconf*) malloc(sizeof(miniconf));
    if (!conf) return NULL;
    memset(conf, 0, sizeof(miniconf));

    // create buffer
    conf -> buffer_sz = mincf_bufsz;
{'fraction_non_alphanumeric': 0.17418963950318087, 'fraction_numerical': 0.040593759466828236, 'mean_word_length': 2.505307855626327, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '700637', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1159, 'n_words': 321}