<commit_before>#include <abi.h>
#include <fudge.h>

union settings
{

    unsigned char raw[FUDGE_BSIZE];
    struct ctrl_header header;
    struct ctrl_consolesettings consolesettings;
    struct ctrl_videosettings videosettings;

};

static unsigned int writestring(unsigned int offset, char *value)
{

    call_seek(CALL_PO, offset);

    return call_write(CALL_PO, ascii_length(value), value);

}

static unsigned int writeboolean(unsigned int offset, unsigned int value)
{

    if (value)
        return writestring(offset, "yes");
    else
        return writestring(offset, "no");

}

static unsigned int writedec(unsigned int offset, unsigned int value)
{

    char num[32];
    unsigned int count = ascii_wvalue(num, 32, value, 10, 0);

    call_seek(CALL_PO, offset);

    return call_write(offset, count, num);

}

/*
static unsigned int writehex2(unsigned int offset, unsigned char value)
{

    char num[32];
    unsigned int count = ascii_wzerovalue(num, 32, value, 16, 2, 0);

    return call_write(CALL_PO, offset, count, 1, num);

}
*/

static unsigned int writeheader(unsigned int offset, struct ctrl_header *header)
{

    offset += writestring(offset, "type: ");

    switch (header->type)
    {

    case CTRL_TYPE_CONSOLE:
        offset += writestring(offset, "consolesettings");

        break;

    case CTRL_TYPE_VIDEO:
        offset += writestring(offset, "videosettings");

        break;

    default:
        offset += writestring(offset, "<null>");

        break;

    }

    offset += writestring(offset, "\n");

    return offset;

}

static unsigned int writeconsolesettings(unsigned int offset, struct ctrl_consolesettings *settings)
{

    offset += writestring(offset, "scroll: ");
    offset += writeboolean(offset, settings->scroll);
    offset += writestring(offset, "\n");

    return offset;

}

static unsigned int writevideosettings(unsigned int offset, struct ctrl_videosettings *settings)
{

    offset += writestring(offset, "width: ");
    offset += writedec(offset, settings->w);
    offset += writestring(offset, "\n");
    offset += writestring(offset, "height: ");
    offset += writedec(offset, settings->h);
    offset += writestring(offset, "\n");
    offset += writestring(offset, "bpp: ");
    offset += writedec(offset, settings->bpp);
    offset += writestring(offset, "\n");

    return offset;

}

void main(void)
{

    union settings buffer;
    unsigned int woff;

    call_open(CALL_PO);
    call_open(CALL_P0);
    call_read(CALL_P0, sizeof (struct ctrl_header), &buffer.header);

    woff = writeheader(0, &buffer.header);

    switch (buffer.header.type)
    {

    case CTRL_TYPE_CONSOLE:
        call_read(CALL_P0, sizeof (struct ctrl_consolesettings), &buffer.consolesettings);
        writeconsolesettings(woff, &buffer.consolesettings);

        break;

    case CTRL_TYPE_VIDEO:
        call_read(CALL_P0, sizeof (struct ctrl_videosettings), &buffer.videosettings);
        writevideosettings(woff, &buffer.videosettings);

        break;

    }

    call_close(CALL_P0);
    call_close(CALL_PO);

}

<commit_msg>minor cleanups<commit_after>#include <abi.h>
#include <fudge.h>

union settings
{

    unsigned char raw[FUDGE_BSIZE];
    struct ctrl_header header;
    struct ctrl_consolesettings consolesettings;
    struct ctrl_videosettings videosettings;

};

static unsigned int writestring(char *value)
{

    return call_write(CALL_PO, ascii_length(value), value);

}

static unsigned int writeboolean(unsigned int value)
{

    return (value) ? writestring("yes") : writestring("no");

}

static unsigned int writedec(unsigned int value)
{

    char num[32];

    return call_write(CALL_PO, ascii_wvalue(num, 32, value, 10, 0), num);

}

/*
static unsigned int writehex2(unsigned int offset, unsigned char value)
{

    char num[32];
    unsigned int count = ascii_wzerovalue(num, 32, value, 16, 2, 0);

    return call_write(CALL_PO, offset, count, 1, num);

}
*/

static void writeheader(struct ctrl_header *header)
{

    writestring("type: ");

    switch (header->type)
    {

    case CTRL_TYPE_CONSOLE:
        writestring("consolesettings");

        break;

    case CTRL_TYPE_VIDEO:
        writestring("videosettings");

        break;

    default:
        writestring("<null>");

        break;

    }

    writestring("\n");

}

static void writeconsolesettings(struct ctrl_consolesettings *settings)
{

    writestring("scroll: ");
    writeboolean(settings->scroll);
    writestring("\n");

}

static void writevideosettings(struct ctrl_videosettings *settings)
{

    writestring("width: ");
    writedec(settings->w);
    writestring("\n");
    writestring("height: ");
    writedec(settings->h);
    writestring("\n");
    writestring("bpp: ");
    writedec(settings->bpp);
    writestring("\n");

}

void main(void)
{

    union settings buffer;

    call_open(CALL_PO);
    call_open(CALL_P0);
    call_read(CALL_P0, sizeof (struct ctrl_header), &buffer.header);

    writeheader(&buffer.header);

    switch (buffer.header.type)
    {

    case CTRL_TYPE_CONSOLE:
        call_read(CALL_P0, sizeof (struct ctrl_consolesettings), &buffer.consolesettings);
        writeconsolesettings(&buffer.consolesettings);

        break;

    case CTRL_TYPE_VIDEO:
        call_read(CALL_P0, sizeof (struct ctrl_videosettings), &buffer.videosettings);
        writevideosettings(&buffer.videosettings);

        break;

    }

    call_close(CALL_P0);
    call_close(CALL_PO);

}


{'fraction_non_alphanumeric': 0.1191302758998721, 'fraction_numerical': 0.008222181618856203, 'mean_word_length': 3.542738589211618, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '5956965', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1742, 'n_words': 394}