<commit_before>/*
 *  version_sorter.c
 *  version_sorter
 *
 *  Created by <NAME> on 10/10/09.
 *  Copyright 2009. All rights reserved.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "version_sorter.h"


static VersionSortingItem * version_sorting_item_init(const char *, int);
static void version_sorting_item_free(VersionSortingItem *);
static void version_sorting_item_add_piece(VersionSortingItem *, char *);
static void parse_version_word(VersionSortingItem *);
static void create_normalized_version(VersionSortingItem *, const int);
static int compare_by_version(const void *, const void *);
static enum scan_state scan_state_get(const char);


VersionSortingItem *
version_sorting_item_init(const char *original, int idx)
{
    VersionSortingItem *vsi = malloc(sizeof(VersionSortingItem));
    if (vsi == NULL) {
        DIE("ERROR: Not enough memory to allocate VersionSortingItem")
    }
    vsi->head = NULL;
    vsi->tail = NULL;
    vsi->node_len = 0;
    vsi->widest_len = 0;
    vsi->original = original;
    vsi->original_len = strlen(original);
    vsi->original_idx = idx;
    vsi->normalized = NULL;
    parse_version_word(vsi);

    return vsi;
}

void
version_sorting_item_free(VersionSortingItem *vsi)
{
    VersionPiece *cur;
    while (cur = vsi->head) {
        vsi->head = cur->next;
        free(cur->str);
        free(cur);
    }
    if (vsi->normalized != NULL) {
      free(vsi->normalized);
    }
    free(vsi);
}

void
version_sorting_item_add_piece(VersionSortingItem *vsi, char *str)<commit_msg>Avoid C compiler warning due to assignment in conditional<commit_after>/*
 *  version_sorter.c
 *  version_sorter
 *
 *  Created by <NAME> on 10/10/09.
 *  Copyright 2009. All rights reserved.
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "version_sorter.h"


static VersionSortingItem * version_sorting_item_init(const char *, int);
static void version_sorting_item_free(VersionSortingItem *);
static void version_sorting_item_add_piece(VersionSortingItem *, char *);
static void parse_version_word(VersionSortingItem *);
static void create_normalized_version(VersionSortingItem *, const int);
static int compare_by_version(const void *, const void *);
static enum scan_state scan_state_get(const char);


VersionSortingItem *
version_sorting_item_init(const char *original, int idx)
{
    VersionSortingItem *vsi = malloc(sizeof(VersionSortingItem));
    if (vsi == NULL) {
        DIE("ERROR: Not enough memory to allocate VersionSortingItem")
    }
    vsi->head = NULL;
    vsi->tail = NULL;
    vsi->node_len = 0;
    vsi->widest_len = 0;
    vsi->original = original;
    vsi->original_len = strlen(original);
    vsi->original_idx = idx;
    vsi->normalized = NULL;
    parse_version_word(vsi);

    return vsi;
}

void
version_sorting_item_free(VersionSortingItem *vsi)
{
    VersionPiece *cur;
    while ((cur = vsi->head)) {
        vsi->head = cur->next;
        free(cur->str);
        free(cur);
    }
    if (vsi->normalized != NULL) {
      free(vsi->normalized);
    }
    free(vsi);
}

void
version_sorting_item_add_piece(VersionSortingItem *vsi, char *str)
{'fraction_non_alphanumeric': 0.1174266083697689, 'fraction_numerical': 0.007495315427857589, 'mean_word_length': 4.044094488188977, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 41, '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': '2629950', 'n_tokens_mistral': 1121, 'n_tokens_neox': 1076, 'n_words': 235}