<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include "cJSON.h"
#include "mcsg.h"
#include "mcs.h"

static char *str_to_upper(const char *str)
{
    size_t i;
    char *str_out = malloc(strlen(str) + 1);
    for(i = 0; str[i]; i++) {
        str_out[i] = toupper(str[i]);
    }

    str_out[i] = 0; /* NULL character */

    return str_out;
}

int mcsg_type_identifier(cJSON *json)
{
    int i;
    cJSON *subitem = json->child;
    for(i = 0; i < MCSG_COMMAND_TYPE_FIELD; i++) subitem = subitem->next;
    if(strcmp(subitem->valuestring, "message") == 0) return MCS_TYPE_MESSAGE;
    else if(strcmp(subitem->valuestring, "state") == 0) return MCS_TYPE_STATE;
    else if(strcmp(subitem->valuestring, "payload") == 0) return MCS_TYPE_PAYLOAD;
    else return 0;
}

void mcsg_message_translator(cJSON *json, FILE *out)
{
    cJSON *subitem;
    char *group_name;

    json = json->child;
    fprintf(out, "    {\n    .cmd = {\n        .name = \"%s\",\n", json->valuestring);
    json = json->next;
    fprintf(out, "        /*%s*/\n", json->valuestring);
    json = json->next;
    fprintf(out, "        .nargs = %d,\n", json->valueint);
    json = json->next;
    if(json->valueint) fprintf(out, "        .raw_data = true,\n");
    else fprintf(out, "        .raw_data = false,\n");
    /*Go to the configuration field*/
    json = json->next->next->child;
    /*Go to the response size field using a temporary variable because we will go over other fields.
     *  The original 'json' variable will continue to point in the logical, sequential order*/
    subitem = json->next->next->next;
    fprintf(out, "        .response_size = %d,\n", subitem->valueint);
    fprintf(out, "    },\n    .destination = \"%s\",\n", json->valuestring);
    json = json->next;
    fprintf(out, "    .origin_groups = {");
    if(json->child) {
        subitem = json->child;
        group_name = str_to_upper(subitem->valuestring);<commit_msg>Make NULL value real NULL in MCSg<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include "cJSON.h"
#include "mcsg.h"
#include "mcs.h"

static char *str_to_upper(const char *str)
{
    size_t i;
    char *str_out = malloc(strlen(str) + 1);
    for(i = 0; str[i]; i++) {
        str_out[i] = toupper(str[i]);
    }

    str_out[i] = 0; /* NULL character */

    return str_out;
}

int mcsg_type_identifier(cJSON *json)
{
    int i;
    cJSON *subitem = json->child;
    for(i = 0; i < MCSG_COMMAND_TYPE_FIELD; i++) subitem = subitem->next;
    if(strcmp(subitem->valuestring, "message") == 0) return MCS_TYPE_MESSAGE;
    else if(strcmp(subitem->valuestring, "state") == 0) return MCS_TYPE_STATE;
    else if(strcmp(subitem->valuestring, "payload") == 0) return MCS_TYPE_PAYLOAD;
    else return 0;
}

void mcsg_message_translator(cJSON *json, FILE *out)
{
    cJSON *subitem;
    char *group_name;

    json = json->child;
    fprintf(out, "    {\n    .cmd = {\n        .name = \"%s\",\n", json->valuestring);
    json = json->next;
    fprintf(out, "        /*%s*/\n", json->valuestring);
    json = json->next;
    fprintf(out, "        .nargs = %d,\n", json->valueint);
    json = json->next;
    if(json->valueint) fprintf(out, "        .raw_data = true,\n");
    else fprintf(out, "        .raw_data = false,\n");
    /*Go to the configuration field*/
    json = json->next->next->child;
    /*Go to the response size field using a temporary variable because we will go over other fields.
     *  The original 'json' variable will continue to point in the logical, sequential order*/
    subitem = json->next->next->next;
    fprintf(out, "        .response_size = %d,\n", subitem->valueint);
    fprintf(out, "    },\n");

    if (json->valuestring == NULL) {
        fprintf(out, "    .destination = NULL,\n");
    } else {
        fprintf(out, "    .destination = \"%s\",\n", json->valuestring);
    }

    json = json->next;
    fprintf(out, "    .origin_groups = {");
    if(json->child) {
        subitem = json->child;
        group_name = str_to_upper(subitem->valuestring);
{'fraction_non_alphanumeric': 0.16682738669238187, 'fraction_numerical': 0.003857280617164899, 'mean_word_length': 2.8667287977632805, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 64, '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': '3192133', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1498, 'n_words': 353}