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

#define STATE_NONE                      0
#define STATE_ADD                       1
#define STATE_SUB                       2
#define STATE_MUL                       3
#define STATE_DIV                       4
#define STATE_SUM                       5

static unsigned int prevstate;
static int number;
static int accumulator;

static void refresh(int value)
{

    char num[CSTRING_NUMSIZE];
    char buffer[BUFFER_SIZE];
    unsigned int count = 0;

    count += buffer_write(buffer, BUFFER_SIZE, "= result content \"", 18, count);
    count += buffer_write(buffer, BUFFER_SIZE, num, cstring_wvalue(num, CSTRING_NUMSIZE, value, 10, 0), count);
    count += buffer_write(buffer, BUFFER_SIZE, "\"\n", 2, count);

    file_notify(FILE_G0, EVENT_WMRENDERDATA, count, buffer);

}

static void updatestate(int state)
{

    switch (prevstate)
    {

    case STATE_NONE:
        accumulator = number;
        number = 0;

        break;

    case STATE_ADD:
        accumulator += number;
        number = 0;

        break;

    case STATE_SUB:
        accumulator -= number;
        number = 0;

        break;

    case STATE_MUL:
        accumulator *= number;
        number = 0;

        break;

    case STATE_DIV:
        accumulator /= number;
        number = 0;

        break;

    }

    prevstate = state;

    switch (state)
    {

        case STATE_SUM:
            refresh(accumulator);

            accumulator = 0;
            number = 0;
            prevstate = STATE_NONE;

            break;

    }

}

static void updatevalue(int value)
{

    number *= 10;
    number += value;

    refresh(number);

}

static void onmain(unsigned int source, void *mdata, unsigned int msize)
{

    file_notify(FILE_G0, EVENT_WMMAP, 0, 0);

}

static void onterm(unsigned int source, void *mdata, unsigned int msize)
{

    file_notify(FILE_G0, EVENT_WMUNMAP, 0, 0);
    channel_close();

}

static void onwmevent(unsigned int source, void *mdata, unsigned int msize)
{

    struct event_wmevent *wmevent = mdata;

    if (wmevent->type == EVENT_WMEVENTCLICK)
    {

        if (cstring_match(wmevent->clicked, "button="))
            updatevalue(STATE_SUM);
        else if (cstring_match(wmevent->clicked, "button0"))
            updatevalue(0);
        else if (cstring_match(wmevent->clicked, "button1"))
            updatevalue(1);
        else if (cstring_match(wmevent->clicked, "button2"))
            updatevalue(2);
        else if (cstring_match(wmevent->clicked, "button3"))
            updatevalue(3);
        else if (cstring_match(wmevent->clicked, "button4"))
            updatevalue(4);
        else if (cstring_match(wmevent->clicked, "button5"))
            updatevalue(5);
        else if (cstring_match(wmevent->clicked, "button6"))
            updatevalue(6);
        else if (cstring_match(wmevent->clicked, "button7"))
            updatevalue(7);
        else if (cstring_match(wmevent->clicked, "button8"))
            updatevalue(8);
        else if (cstring_match(wmevent->clicked, "button9"))
            updatevalue(9);<commit_msg>more<commit_after>#include <fudge.h>
#include <abi.h>

#define STATE_SUM                       0
#define STATE_ADD                       1
#define STATE_SUB                       2
#define STATE_MUL                       3
#define STATE_DIV                       4

static unsigned int prevstate;
static int number;
static int accumulator;

static void refresh(int value)
{

    char num[CSTRING_NUMSIZE];
    char buffer[BUFFER_SIZE];
    unsigned int count = 0;

    count += buffer_write(buffer, BUFFER_SIZE, "= result content \"", 18, count);
    count += buffer_write(buffer, BUFFER_SIZE, num, cstring_wvalue(num, CSTRING_NUMSIZE, value, 10, 0), count);
    count += buffer_write(buffer, BUFFER_SIZE, "\"\n", 2, count);

    file_notify(FILE_G0, EVENT_WMRENDERDATA, count, buffer);

}

static void updatestate(int state)
{

    switch (prevstate)
    {

    case STATE_SUM:
        accumulator = number;
        number = 0;

        break;

    case STATE_ADD:
        accumulator += number;
        number = 0;

        break;

    case STATE_SUB:
        accumulator -= number;
        number = 0;

        break;

    case STATE_MUL:
        accumulator *= number;
        number = 0;

        break;

    case STATE_DIV:
        accumulator /= number;
        number = 0;

        break;

    }

    prevstate = state;

    switch (state)
    {

    case STATE_SUM:
        refresh(accumulator);

        number = 0;

        break;

    }

}

static void updatevalue(int value)
{

    number *= 10;
    number += value;

    refresh(number);

}

static void onmain(unsigned int source, void *mdata, unsigned int msize)
{

    file_notify(FILE_G0, EVENT_WMMAP, 0, 0);

}

static void onterm(unsigned int source, void *mdata, unsigned int msize)
{

    file_notify(FILE_G0, EVENT_WMUNMAP, 0, 0);
    channel_close();

}

static void onwmevent(unsigned int source, void *mdata, unsigned int msize)
{

    struct event_wmevent *wmevent = mdata;

    if (wmevent->type == EVENT_WMEVENTCLICK)
    {

        if (cstring_match(wmevent->clicked, "button="))
            updatestate(STATE_SUM);
        else if (cstring_match(wmevent->clicked, "button0"))
            updatevalue(0);
        else if (cstring_match(wmevent->clicked, "button1"))
            updatevalue(1);
        else if (cstring_match(wmevent->clicked, "button2"))
            updatevalue(2);
        else if (cstring_match(wmevent->clicked, "button3"))
            updatevalue(3);
        else if (cstring_match(wmevent->clicked, "button4"))
            updatevalue(4);
        else if (cstring_match(wmevent->clicked, "button5"))
            updatevalue(5);
        else if (cstring_match(wmevent->clicked, "button6"))
            updatevalue(6);
        else if (cstring_match(wmevent->clicked, "button7"))
            updatevalue(7);
        else if (cstring_match(wmevent->clicked, "button8"))
            updatevalue(8);
        else if (cstring_match(wmevent->clicked, "button9"))
            updatevalue(9);
{'fraction_non_alphanumeric': 0.10765197443880059, 'fraction_numerical': 0.01572996886776995, 'mean_word_length': 2.210941609679116, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, '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': '298315', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1872, 'n_words': 462}