<commit_before>#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>

struct s_props {
    //    Required
    int version;
    int is_jar;
    char* program_name;

    //    Maybe required
    char* _main_class;
    char* _jar_file;

    //    Not required
    char* _class_path;
    char* _java_opts;

};

typedef struct s_props props;

//Logic functions
static int check_version(char* command);
static void run_program(char* command, char *args[]);
static props* read_props();
static void free_props(props* p);
static int check_props(props* p);

//Utility
static char* strstrip(char *s);
static char* get_str_value(char* property);
static void error(char* error);
static void p_error(char* error);
static void safe_free(char* prop);

int main(int argc, char* argv[]) {
    props * p = read_props();
    int valid = check_version("java");
    if (valid == 1) {
        printf("Java encontrado\n");
    }
    free_props(p);
    return 0;
}

static int check_version(char* command) {
    char full_command[150];
    char* version_command = " -version 2>&1";
    memset(full_command, 0, 150);
    sprintf(full_command, "%s %s", command, version_command);
    char output[1024];
    FILE* fp;
    fp = popen(full_command, "r");
    if (fp != NULL) {
        if (fgets(output, sizeof (output), fp) != NULL) {
        } else {
            puts("Cannot get output command\n");
        }
        pclose(fp);
        return 1;
    } else {
        perror("Error while executing command");
        return 0;
    }
}

static props* read_props() {
    props* p = (props*) malloc(sizeof (props));
    char* version = get_str_value("version");
    char* is_jar = get_str_value("is_jar");
    p->_main_class = get_str_value("main_class");
    p->_class_path = get_str_value("class_path");
    p->_java_opts = get_str_value("java_opts");
    p->program_name = get_str_value("program_name");
    p->_jar_file = get_str_value("jar_file");
    p->version = version != NULL ? atoi(version) : 0;
    p->is_jar = is_jar != NULL ? atoi(is_jar) : 0;
    safe_free(version);
    safe_free(is_jar);
    int valid = check_props(p);
    if (!valid) {
        error("Configuration file is not valid, check all options values");
        free_props(p);
        exit(-1);
    }
    return p;
}

static int check_props(props * p) {
    if (p->version == 0) {
        error("version option must be set");
        return 0;
    }
    if (p->is_jar == 0) {
        error("is_jar option must be set");
        return 0;
    }
    if (p->is_jar) {
        if (!p->_jar_file) {
            error("jar_file option must be set");
            return 0;
        }
    } else {
        if (!p->_main_class) {
            error("main_class option must be set");
            return 0;
        }
    }

    return 1;
}

char* get_str_value(char* property) {
    char* value = NULL;
    FILE* file = fopen("nativeconf.conf", "r");
    if (file != NULL) {
        char* line = NULL;
        size_t len = 0;
        ssize_t read;
        while ((read = getline(&line, &len, file)) != -1) {
            char aux[read + 1];
            strcpy(aux, line);
            if (strstr(aux, property) != NULL) {
                char* rest = strchr(aux, ' ');
                if (rest != NULL) {
                    int index = rest - aux;
                    char* opt = aux + index + 1;
                    opt = strstrip(opt);
                    int size = strlen(opt) + 1;
                    if (size > 1) {
                        value = (char*) malloc(sizeof (char) * size);
                        strcpy(value, opt);
                        printf("%s: [%s][%zu]\n", property, value, strlen(value));
                        break;
                    }
                }
            }
        }
        free(line);
        fclose(file);<commit_msg>Avances<commit_after>#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>

struct s_props {
    //    Required
    int version;
    int is_jar;
    char* program_name;

    //    Maybe required
    char* _main_class;
    char* _jar_file;

    //    Not required
    char* _class_path;
    char* _java_opts;

};

typedef struct s_props props;

//Logic functions
static int check_version(char* command);
static void run_program(char* command, char *args[]);
static props* read_props();
static void free_props(props* p);
static int check_props(props* p);

//Utility
static char* strstrip(char *s);
static char* get_str_value(char* property);
static void error(char* error);
static void p_error(char* error);
static void safe_free(char* prop);

int main(int argc, char* argv[]) {
    props * p = read_props();
    int valid = check_version("java");
    if (valid == 1) {
        printf("Java encontrado\n");
    }
    free_props(p);
    return 0;
}

static int check_version(char* command) {
    char full_command[150];
    char* version_command = " -version 2>&1";
    memset(full_command, 0, 150);
    snprintf(full_command, 150, "%s %s", command, version_command);
    char output[1024];
    FILE* fp;
    fp = popen(full_command, "r");
    if (fp != NULL) {
        if (fgets(output, sizeof (output), fp) != NULL) {
            printf("Salida: %s\n", output);
        } else {
            puts("Cannot get output command\n");
        }
        pclose(fp);
        return 1;
    } else {
        perror("Error while executing command");
        return 0;
    }
}

static props* read_props() {
    props* p = (props*) malloc(sizeof (props));
    char* version = get_str_value("version");
    char* is_jar = get_str_value("is_jar");
    p->_main_class = get_str_value("main_class");
    p->_class_path = get_str_value("class_path");
    p->_java_opts = get_str_value("java_opts");
    p->program_name = get_str_value("program_name");
    p->_jar_file = get_str_value("jar_file");
    p->version = version != NULL ? atoi(version) : 0;
    p->is_jar = is_jar != NULL ? atoi(is_jar) : 0;
    safe_free(version);
    safe_free(is_jar);
    int valid = check_props(p);
    if (!valid) {
        error("Configuration file is not valid, check all options values");
        free_props(p);
        exit(-1);
    }
    return p;
}

static int check_props(props * p) {
    if (p->version == 0) {
        error("version option must be set");
        return 0;
    }
    if (p->is_jar == 0) {
        error("is_jar option must be set");
        return 0;
    }
    if (p->is_jar) {
        if (!p->_jar_file) {
            error("jar_file option must be set");
            return 0;
        }
    } else {
        if (!p->_main_class) {
            error("main_class option must be set");
            return 0;
        }
    }

    return 1;
}

char* get_str_value(char* property) {
    char* value = NULL;
    FILE* file = fopen("nativeconf.conf", "r");
    if (file != NULL) {
        char* line = NULL;
        size_t len = 0;
        ssize_t read;
        while ((read = getline(&line, &len, file)) != -1) {
            char aux[read + 1];
            memcpy(aux, line, read + 1);
            if (strstr(aux, property) != NULL) {
                char* rest = strchr(aux, ' ');
                if (rest != NULL) {
                    int index = rest - aux;
                    char* opt = aux + index + 1;
                    opt = strstrip(opt);
                    int size = strlen(opt) + 1;
                    if (size > 1) {
                        value = (char*) malloc(sizeof (char) * size);
                        memcpy(value, opt, size);
                        printf("%s: [%s][%zu]\n", property, value, strlen(value));
                        break;
                    }
                }
            }
        }
        free(line);
        fclose(file);
{'fraction_non_alphanumeric': 0.14064895247828307, 'fraction_numerical': 0.008942258559018906, 'mean_word_length': 2.0392080745341614, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 45, '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': '6238811', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2503, 'n_words': 660}