<commit_before>#include "../include/demonize.h"

static char *my_strcat(char *str1, char *str2)
{
    char *ret = malloc(1 + strlen(str1) + strlen(str2) * sizeof (char));
    int i = 0;
    while (str1[i])
    {
        ret[i] = str1[i];
        i++;
    }
    ret[i] = ' ';
    i++;
    for (int j = 0; str2[j]; j++)
    {
        ret[i] = str2[j];
        i++;
    }
    ret[i] = '\0';
    return ret;
}

static char **get_process(char **cmd)
{
    int len = 0;
    while (cmd[len])
        len++;
    char **process = malloc((len + 3) * sizeof (char *));
    process[0] = "/bin/sh";
    process[1] = "-c";
    process[2] = malloc(sizeof (char));
    for (int i = 0; i < len; i++)
        process[2] = my_strcat(process[2], cmd[i]);
    process[3] = NULL;
    return process;
}

static void display_help()
{
    printf("Usage: dem [option] [command] ...\n");
    printf("       --cmd, -c: if there is severals commands to demonize, use this option before each of them.\n");
    printf("       --kill, -k: kill the process corresponding to the next index.\n");
    printf("       --jobs, -j: display jobs.\n");
    printf("       --help, -h: displays this help.\n");
}

static s_list *get_args(int argc, char **argv)
{
    s_list *list = NULL;
    if (argc <= 1)
    {
        fprintf(stderr, "dem: use --help or -h option");
        exit(1);
    }
    else
    {
        for (int i = 1; i < argc; i++)
            if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
            {
                display_help();
                exit(0);
            }
            else if(!strcmp(argv[i], "-j") || !strcmp(argv[i], "--jobs"))
            {
                display_pidlist();
                exit(0);
            }
            else if (!strcmp(argv[i], "--clean"))
                clean();
            else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--kill"))
            {
                if (!(argv + i + 1) || !argv[i + 1])
                {
                    fprintf(stderr, "dem: use --help or -h option");
                    exit(1);
                }
                else
                    kill(get_pid(atoi(argv[i + 1])), SIGKILL);
                exit(0);
            }
            else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--cmd"))<commit_msg>FIXED : init is not killed anymore if procces doesn't exists<commit_after>#include "../include/demonize.h"

static char *my_strcat(char *str1, char *str2)
{
    char *ret = malloc(1 + strlen(str1) + strlen(str2) * sizeof (char));
    int i = 0;
    while (str1[i])
    {
        ret[i] = str1[i];
        i++;
    }
    ret[i] = ' ';
    i++;
    for (int j = 0; str2[j]; j++)
    {
        ret[i] = str2[j];
        i++;
    }
    ret[i] = '\0';
    return ret;
}

static char **get_process(char **cmd)
{
    int len = 0;
    while (cmd[len])
        len++;
    char **process = malloc((len + 3) * sizeof (char *));
    process[0] = "/bin/sh";
    process[1] = "-c";
    process[2] = malloc(sizeof (char));
    for (int i = 0; i < len; i++)
        process[2] = my_strcat(process[2], cmd[i]);
    process[3] = NULL;
    return process;
}

static void display_help()
{
    printf("Usage: dem [option] [command] ...\n");
    printf("       --cmd, -c: if there is severals commands to demonize, use this option before each of them.\n");
    printf("       --kill, -k: kill the process corresponding to the next index.\n");
    printf("       --jobs, -j: display jobs.\n");
    printf("       --help, -h: displays this help.\n");
}

static s_list *get_args(int argc, char **argv)
{
    s_list *list = NULL;
    if (argc <= 1)
    {
        fprintf(stderr, "dem: use --help or -h option");
        exit(1);
    }
    else
    {
        for (int i = 1; i < argc; i++)
            if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
            {
                display_help();
                exit(0);
            }
            else if(!strcmp(argv[i], "-j") || !strcmp(argv[i], "--jobs"))
            {
                display_pidlist();
                exit(0);
            }
            else if (!strcmp(argv[i], "--clean"))
                clean();
            else if (!strcmp(argv[i], "-k") || !strcmp(argv[i], "--kill"))
            {
                if (!(argv + i + 1) || !argv[i + 1])
                {
                    fprintf(stderr, "dem: use --help or -h option");
                    exit(1);
                }
                else
                {
                    if (get_pid(atoi(argv[i + 1])) != -1)
                        kill(get_pid(atoi(argv[i + 1])), SIGKILL);
                    else
                        fprintf(stderr, "dem: %d: process doesn't exist!\n", atoi(argv[i + 1]));
                }
                exit(0);
            }
            else if (!strcmp(argv[i], "-c") || !strcmp(argv[i], "--cmd"))
{'fraction_non_alphanumeric': 0.18769422001243008, 'fraction_numerical': 0.013465920861818935, 'mean_word_length': 1.523784631468897, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '3165674', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1603, 'n_words': 421}