<commit_before>#include <fudge.h>
#include "call.h"
#include "channel.h"
#include "file.h"
#include "job.h"

static char *nextword(char *current)
{

    return current + ascii_lengthz(current);

}

unsigned int job_parse(struct job *jobs, unsigned int n, void *buffer, unsigned int count)
{

    char *start = buffer;
    char *end = start + count;
    unsigned int njobs = 0;

    buffer_clear(jobs, sizeof (struct job) * n);

    while (start < end)
    {

        struct job *p = &jobs[njobs];

        switch (start[0])
        {

        case 'P':
            start = nextword(start);
            p->program = start;
            njobs++;

            break;

        case 'D':
            start = nextword(start);
            p->paths[p->npaths] = start;
            p->npaths++;

            break;

        case 'O':
            start = nextword(start);
            p->options[p->noptions].value = start;
            start = nextword(start);
            p->options[p->noptions].key = start;
            p->noptions++;

            break;

        case 'E':
            start = nextword(start);

            return njobs;

        }

        start = nextword(start);

    }

    return njobs;

}

static unsigned int spawn(struct job *job)
{

    if (!file_walk2(FILE_L0, "/bin"))
        return 0;

    if (!(file_walk(FILE_CP, FILE_L0, job->program) || file_walk2(FILE_CP, job->program)))
        return 0;

    return call_spawn();

}

void activatenext(unsigned int index, struct job *jobs, unsigned int n)
{

    if (index < n)
    {

        struct job *job = &jobs[index];

        if (job->id)
            channel_send(job->id, EVENT_MAIN);

    }

}

unsigned int job_spawn(struct job *jobs, unsigned int n)
{

    unsigned int i;

    for (i = 0; i < n; i++)
    {

        struct job *job = &jobs[i];

        job->id = spawn(job);

        if (!job->id)
        {

            job_send(jobs, i, EVENT_TERM, 0, 0);

            return 0;

        }

    }

    return n;

}

void job_pipe(struct job *jobs, unsigned int n)
{

    unsigned int i;

    for (i = 0; i < n; i++)
    {

        struct job *job = &jobs[i];

        if (job->id)
        {

            channel_sendredirectback(job->id, EVENT_CLOSE);
            channel_sendredirectback(job->id, EVENT_PATH);

            if (i < n - 1)
                channel_sendredirectto(job->id, EVENT_DATA, jobs[i + 1].id);
            else
                channel_sendredirectback(job->id, EVENT_DATA);

        }

    }

}

unsigned int job_run(struct job *jobs, unsigned int n)
{

    unsigned int i;

    for (i = 0; i < n; i++)
    {

        struct job *job = &jobs[i];

        if (job->id)
        {

            unsigned int j;
            struct message message;

            for (j = 0; j < job->noptions; j++)
            {<commit_msg>more<commit_after>#include <fudge.h>
#include "call.h"
#include "channel.h"
#include "file.h"
#include "job.h"

static char *nextword(char *current)
{

    return current + ascii_lengthz(current);

}

unsigned int job_parse(struct job *jobs, unsigned int n, void *buffer, unsigned int count)
{

    char *start = buffer;
    char *end = start + count;
    unsigned int njobs = 0;

    buffer_clear(jobs, sizeof (struct job) * n);

    while (start < end)
    {

        struct job *p = &jobs[njobs];

        switch (start[0])
        {

        case 'P':
            start = nextword(start);
            p->program = start;
            njobs++;

            break;

        case 'D':
            start = nextword(start);
            p->paths[p->npaths] = start;
            p->npaths++;

            break;

        case 'O':
            start = nextword(start);
            p->options[p->noptions].value = start;
            start = nextword(start);
            p->options[p->noptions].key = start;
            p->noptions++;

            break;

        case 'E':
            start = nextword(start);

            return njobs;

        }

        start = nextword(start);

    }

    return njobs;

}

static unsigned int spawn(struct job *job)
{

    if (!file_walk2(FILE_L0, "/bin"))
        return 0;

    if (!(file_walk(FILE_CP, FILE_L0, job->program) || file_walk2(FILE_CP, job->program)))
        return 0;

    return call_spawn();

}

void activatenext(unsigned int index, struct job *jobs, unsigned int n)
{

    if (index < n)
    {

        struct job *job = &jobs[index];

        if (job->id)
            channel_send(job->id, EVENT_MAIN);

    }

}

unsigned int job_spawn(struct job *jobs, unsigned int n)
{

    unsigned int i;

    for (i = 0; i < n; i++)
    {

        struct job *job = &jobs[i];

        job->id = spawn(job);

        if (!job->id)
        {

            job_send(jobs, i, EVENT_TERM, 0, 0);

            return 0;

        }

    }

    return n;

}

void job_pipe(struct job *jobs, unsigned int n)
{

    unsigned int i;

    for (i = 0; i < n; i++)
    {

        struct job *job = &jobs[i];

        if (job->id)
        {

            channel_sendredirectback(job->id, EVENT_CLOSE);
            channel_sendredirectback(job->id, EVENT_PATH);

            if (i < n - 1)
                channel_sendredirectto(job->id, EVENT_DATA, jobs[i + 1].id);
            else
                channel_sendredirectback(job->id, EVENT_DATA);

        }

    }

}

unsigned int job_run(struct job *jobs, unsigned int n)
{

    unsigned int i;

    for (i = 0; i < n; i++)
    {

        struct job *job = &jobs[i];

        if (job->id)
        {

            unsigned int j;

            for (j = 0; j < job->noptions; j++)
            {

                struct message message;
{'fraction_non_alphanumeric': 0.13153217205830076, 'fraction_numerical': 0.006043370067543548, 'mean_word_length': 1.6368322399250235, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 49, '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': '2521855', 'n_tokens_mistral': 1947, 'n_tokens_neox': 1792, 'n_words': 482}