<commit_before>#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>

#include "hdlc.h"


// Input file must contains only ANSI hexadecimal characters without spaces
int main(int argc, char** argv)
{
    if (argc == 2)
    {
        char *buffer = NULL;
        size_t sz = 0U;
        FILE *f = fopen(argv[1], "r");
        if (f != NULL)
        {
            fseek(f, 0L, SEEK_END);
            sz = ftell(f);
            rewind(f);
            printf("File size: %d\r\n", sz);

            buffer = malloc(sz);
            if (buffer != NULL)
            {
                fread(buffer, 1, sz, f);
                // now close the file as we have finish with it
                fclose(f);
            }
            else
            {
                printf("Cannot allocate memory!\r\n");
            }
        }
        else
        {
            printf("Not a file, reading input string\r\n");
            sz = strlen(argv[1]);
            printf("String size: %d\r\n", sz);
            buffer = malloc(sz);
            if (buffer != NULL)
            {
                memcpy(buffer, argv[1], sz);
            }
            else
            {
                printf("Cannot allocate memory!\r\n");
            }
        }

        // Simple test: we must have a even number of bytes
        if (!(sz%2))
        {
            printf("Input string: ");
            for(int i = 0; i<sz; i++) printf("%c", buffer[i]);
            printf("\r\n");

            // Now, transform the hexadecimal string into an array of integers
            size_t packet_size = sz/2U;
            uint8_t *packet = malloc(packet_size);

            if (packet != NULL)
            {
                int ret;

                hex2bin(buffer, packet, sz);
                //print_hex(packet, packet_size);

                hdlc_t hdlc;
                hdlc_init(&hdlc);

                ret = hdlc_decode(&hdlc, packet, packet_size);
                print_hdlc_result(&hdlc, ret);

                free(packet);<commit_msg>rename<commit_after>#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>

#include "hdlc.h"


// Input file must contains only ANSI hexadecimal characters without spaces
int main(int argc, char** argv)
{
    if (argc == 2)
    {
        char *buffer = NULL;
        size_t sz = 0U;
        FILE *f = fopen(argv[1], "r");
        if (f != NULL)
        {
            fseek(f, 0L, SEEK_END);
            sz = ftell(f);
            rewind(f);
            printf("File size: %d\r\n", sz);

            buffer = malloc(sz);
            if (buffer != NULL)
            {
                fread(buffer, 1, sz, f);
                // now close the file as we have finish with it
                fclose(f);
            }
            else
            {
                printf("Cannot allocate memory!\r\n");
            }
        }
        else
        {
            printf("Not a file, reading input string\r\n");
            sz = strlen(argv[1]);
            printf("String size: %d\r\n", sz);
            buffer = malloc(sz);
            if (buffer != NULL)
            {
                memcpy(buffer, argv[1], sz);
            }
            else
            {
                printf("Cannot allocate memory!\r\n");
            }
        }

        // Simple test: we must have a even number of bytes
        if (!(sz%2))
        {
            printf("Input string: ");
            for(int i = 0; i<sz; i++) printf("%c", buffer[i]);
            printf("\r\n");

            // Now, transform the hexadecimal string into an array of integers
            size_t packet_size = sz/2U;
            uint8_t *packet = malloc(packet_size);

            if (packet != NULL)
            {
                int ret;

                hex2bin(buffer, packet, sz);
                //print_hex(packet, packet_size);

                hdlc_t hdlc;
                hdlc_init(&hdlc);

                ret = hdlc_decode(&hdlc, packet, packet_size);
                hdlc_print_result(&hdlc, ret);

                free(packet);
{'fraction_non_alphanumeric': 0.12379778051787917, 'fraction_numerical': 0.00591861898890259, 'mean_word_length': 1.2297965915338098, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '5800028', 'n_tokens_mistral': 1232, 'n_tokens_neox': 1173, 'n_words': 315}