<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>

#define BUFSIZE 1024
#define MAXARGS 100

size_t readline(char* buf, size_t len)
{
    size_t pos = 0;
    while (pos < len && read(0, &buf[pos], 1) && buf[pos] != '\n')
        pos++;
    if (pos < len)
        buf[pos] = '\0';
    return pos;
}

int main(int argc, char** argv)
{
    do
    {
        write(1, "$ ", 2);

        char cmd[BUFSIZE];
        readline(cmd, BUFSIZE);

        char* cmd_argv[MAXARGS];
        size_t cmd_pos = 0;
        cmd_argv[cmd_pos++] = strtok(cmd, " ");
        do
            cmd_argv[cmd_pos] = strtok(NULL, " ");
        while (cmd_argv[cmd_pos++]);

        if (!strcmp(cmd_argv[0], "exit") || !strcmp(cmd_argv[0], "quit"))
            exit(0);

        pid_t pid = fork();
        if (!pid)
            execvp(cmd_argv[0], cmd_argv);
        else
        {
            int status;
            waitpid(pid, &status, 0);
            if (WIFEXITED(status))
                printf("%d\n", WEXITSTATUS(status));
        }
    }
    while (1);

    return 0;
}<commit_msg>added displaying of an error message if a command could not be started<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>

#define BUFSIZE 1024
#define MAXARGS 100

size_t readline(char* buf, size_t len)
{
    size_t pos = 0;
    while (pos < len && read(0, &buf[pos], 1) && buf[pos] != '\n')
        pos++;
    if (pos < len)
        buf[pos] = '\0';
    return pos;
}

int main(int argc, char** argv)
{
    do
    {
        write(1, "$ ", 2);

        char cmd[BUFSIZE];
        readline(cmd, BUFSIZE);

        char* cmd_argv[MAXARGS];
        size_t cmd_pos = 0;
        cmd_argv[cmd_pos++] = strtok(cmd, " ");
        do
            cmd_argv[cmd_pos] = strtok(NULL, " ");
        while (cmd_argv[cmd_pos++]);

        if (!strcmp(cmd_argv[0], "exit") || !strcmp(cmd_argv[0], "quit"))
            exit(0);

        pid_t pid = fork();
        if (!pid && execvp(cmd_argv[0], cmd_argv) < 0)
        {
            printf("error: command `%s` does not exist\n", cmd_argv[0]);
            exit(0);
        }
        else
        {
            int status;
            waitpid(pid, &status, 0);
            if (WIFEXITED(status))
                printf("%d\n", WEXITSTATUS(status));
        }
    }
    while (1);

    return 0;
}
{'fraction_non_alphanumeric': 0.16466694249069094, 'fraction_numerical': 0.018618121638394703, 'mean_word_length': 1.930909090909091, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 13, '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': '686788', 'n_tokens_mistral': 903, 'n_tokens_neox': 861, 'n_words': 203}