<commit_before>#include <fudge.h>
#include <gfx/gfx.h>
#include <gfx/pcx.h>

static struct pcx_header header;

static unsigned int size(unsigned int id)
{

    unsigned char buffer[FUDGE_BSIZE];
    unsigned int offset;
    unsigned int count;

    for (offset = 0; (count = call_read(id, offset, FUDGE_BSIZE, buffer)); offset += count);

    return offset;

}

static unsigned int read_scanline(unsigned int id, unsigned int offset, unsigned int count, void *buffer)
{

    unsigned char raw[FUDGE_BSIZE];
    unsigned int width = header.xend - header.xstart + 1;
    unsigned int rindex = 0;
    unsigned int oindex = 0;
    unsigned int repeat;
    unsigned char current;

    call_read(id, offset, count, raw);

    do
    {

        repeat = 1;
        current = raw[rindex];
        rindex++;

        if ((current & 0xC0) == 0xC0)
        {

            repeat = current & 0x3F;
            current = raw[rindex];
            rindex++;

        }

        while (repeat--)
        {

            ((char *)buffer)[oindex] = current;
            oindex++;

        }

    } while (oindex < width);

    return rindex;

}

static unsigned int read_colormap(unsigned int id, unsigned int offset, unsigned int count, void *buffer)
{

    if (count < 769)
        return 0;

    offset = size(id) - 769;
    count = call_read(id, offset, 769, buffer);

    if (((char *)buffer)[0] != PCX_COLORMAP_MAGIC)
        return 0;

    return count;

}

static void set_resolution()
{

    call_open(3, FUDGE_ROOT, 27, "system/video/vga/resolution");
    call_write(3, 0, 9, "320x200x8");
    call_close(3);

}

static void set_colormap(char *colormap)
{

    unsigned int i;

    call_open(3, FUDGE_ROOT, 25, "system/video/vga/colormap");

    for (i = 0; i < PCX_COLORMAP_SLOTS; i++)
        call_write(3, i * 4, 3, &colormap[i * 3 + 1]);

    call_close(3);

}

static void render(unsigned int id, char *colormap)
{

    unsigned int width = header.xend - header.xstart + 1;
    unsigned int height = header.yend - header.ystart + 1;
    unsigned int offset = 128;
    unsigned int row;

    set_resolution();
    set_colormap(colormap);

    call_open(3, FUDGE_ROOT, 21, "system/video/vga/data");

    for (row = 0; row < height; row++)
    {

        char buffer[FUDGE_BSIZE];

        offset += read_scanline(id, offset, FUDGE_BSIZE, buffer);<commit_msg>more cleanups<commit_after>#include <fudge.h>
#include <gfx/gfx.h>
#include <gfx/pcx.h>

static struct pcx_header header;

static unsigned int size(unsigned int id)
{

    unsigned char buffer[FUDGE_BSIZE];
    unsigned int offset;
    unsigned int count;

    for (offset = 0; (count = call_read(id, offset, FUDGE_BSIZE, buffer)); offset += count);

    return offset;

}

static unsigned int read_scanline(unsigned int id, unsigned int offset, unsigned int count, void *buffer)
{

    unsigned char raw[FUDGE_BSIZE];
    unsigned int width = header.xend - header.xstart + 1;
    unsigned int rindex = 0;
    unsigned int oindex = 0;
    unsigned int repeat;
    unsigned char current;

    call_read(id, offset, count, raw);

    do
    {

        repeat = 1;
        current = raw[rindex];
        rindex++;

        if ((current & 0xC0) == 0xC0)
        {

            repeat = current & 0x3F;
            current = raw[rindex];
            rindex++;

        }

        while (repeat--)
        {

            ((char *)buffer)[oindex] = current;
            oindex++;

        }

    } while (oindex < width);

    return rindex;

}

static unsigned int read_colormap(unsigned int id, unsigned int offset, unsigned int count, void *buffer)
{

    unsigned char magic;

    call_read(id, size(id) - 768 - 1, 1, &magic);

    if (magic != PCX_COLORMAP_MAGIC)
        return 0;

    count = call_read(id, size(id) - 768, 768, buffer);

    if (count < 768)
        return 0;

    return count;

}

static void set_resolution()
{

    call_open(3, FUDGE_ROOT, 27, "system/video/vga/resolution");
    call_write(3, 0, 9, "320x200x8");
    call_close(3);

}

static void set_colormap(char *colormap)
{

    unsigned int i;

    call_open(3, FUDGE_ROOT, 25, "system/video/vga/colormap");

    for (i = 0; i < PCX_COLORMAP_SLOTS; i++)
        call_write(3, i * 4, 3, &colormap[i * 3]);

    call_close(3);

}

static void render(unsigned int id, char *colormap)
{

    unsigned int width = header.xend - header.xstart + 1;
    unsigned int height = header.yend - header.ystart + 1;
    unsigned int offset = 128;
    unsigned int row;

    set_resolution();
    set_colormap(colormap);
    call_open(3, FUDGE_ROOT, 21, "system/video/vga/data");

    for (row = 0; row < height; row++)
    {

        char buffer[FUDGE_BSIZE];

        offset += read_scanline(id, offset, FUDGE_BSIZE, buffer);
{'fraction_non_alphanumeric': 0.12107150390213035, 'fraction_numerical': 0.02425648597342333, 'mean_word_length': 2.5335320417287632, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 9, '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': '3675494', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1608, 'n_words': 449}