<commit_before>#include <fudge/module.h>
#include <kernel/vfs.h>
#include <system/system.h>
#include "base.h"
#include "clock.h"

static struct clock_node
{

    struct system_group base;
    struct base_clock_interface *interface;
    struct base_device *device;
    struct system_stream timestamp;
    struct system_stream date;
    struct system_stream time;

} node[8];

static struct system_group root;
static struct system_group dev;
static unsigned int dotm365[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
static unsigned int dotm366[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 365};

static unsigned int isleapyear(unsigned short year)
{

    if ((year % 4) != 0)
        return 0;

    if ((year % 100) == 0)
        return ((year % 400) == 0);

    return 1;

}

static unsigned int dateticks(unsigned int year, unsigned int month, unsigned int day)
{

    unsigned int dyear = 365 * (year - 1970);
    unsigned int dmonth = isleapyear(year) ? dotm366[month - 1] : dotm365[month - 1];

    return (dyear + dmonth + day) * 86400;

}

static unsigned int timeticks(unsigned int hour, unsigned int minute, unsigned int second)
{

    return ((hour * 3600) + (minute * 60) + second);

}

static unsigned int timestamp_read(struct system_node *self, unsigned int offset, unsigned int count, void *buffer)
{

    struct clock_node *node = (struct clock_node *)self->parent;
    char num[32];
    unsigned int timestamp = 0;
    
    timestamp += dateticks(node->interface->get_year(node->device), node->interface->get_month(node->device), node->interface->get_day(node->device));
    timestamp += timeticks(node->interface->get_hours(node->device), node->interface->get_minutes(node->device), node->interface->get_seconds(node->device));

    return memory_read(buffer, count, num, memory_write_number(num, 32, timestamp, 10, 0), offset);

}

static unsigned int date_read(struct system_node *self, unsigned int offset, unsigned int count, void *buffer)
{

    struct clock_node *node = (struct clock_node *)self->parent;
    char *num = "0000-00-00";

    memory_write_paddednumber(num, 10, node->interface->get_year(node->device), 10, 4, 0);
    memory_write_paddednumber(num, 10, node->interface->get_month(node->device), 10, 2, 5);
    memory_write_paddednumber(num, 10, node->interface->get_day(node->device), 10, 2, 8);

    return memory_read(buffer, count, num, 10, offset);

}
<commit_msg>more cleanups<commit_after>#include <fudge/module.h>
#include <kernel/vfs.h>
#include <system/system.h>
#include "base.h"
#include "clock.h"

static struct clock_node
{

    struct system_group base;
    struct base_clock_interface *interface;
    struct base_device *device;
    struct system_stream timestamp;
    struct system_stream date;
    struct system_stream time;

} node[8];

static struct system_group root;
static struct system_group dev;
static unsigned int dotm365[13] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
static unsigned int dotm366[13] = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 365};

static unsigned int isleapyear(unsigned short year)
{

    if ((year % 4) != 0)
        return 0;

    if ((year % 100) == 0)
        return ((year % 400) == 0);

    return 1;

}

static unsigned int timestamp_read(struct system_node *self, unsigned int offset, unsigned int count, void *buffer)
{

    struct clock_node *node = (struct clock_node *)self->parent;
    unsigned int year = node->interface->get_year(node->device);
    unsigned int month = node->interface->get_month(node->device);
    unsigned int day = node->interface->get_day(node->device);
    unsigned int hour = node->interface->get_hours(node->device);
    unsigned int minute = node->interface->get_minutes(node->device);
    unsigned int second = node->interface->get_seconds(node->device);
    unsigned int dyear = 365 * (year - 1970);
    unsigned int dmonth = isleapyear(year) ? dotm366[month - 1] : dotm365[month - 1];
    unsigned int timestamp = ((dyear + dmonth + day) * 86400) + ((hour * 3600) + (minute * 60) + second);
    char num[32];

    return memory_read(buffer, count, num, memory_write_number(num, 32, timestamp, 10, 0), offset);

}

static unsigned int date_read(struct system_node *self, unsigned int offset, unsigned int count, void *buffer)
{

    struct clock_node *node = (struct clock_node *)self->parent;
    char *num = "0000-00-00";

    memory_write_paddednumber(num, 10, node->interface->get_year(node->device), 10, 4, 0);
    memory_write_paddednumber(num, 10, node->interface->get_month(node->device), 10, 2, 5);
    memory_write_paddednumber(num, 10, node->interface->get_day(node->device), 10, 2, 8);

    return memory_read(buffer, count, num, 10, offset);

}

{'fraction_non_alphanumeric': 0.1351408154686843, 'fraction_numerical': 0.0641025641025641, 'mean_word_length': 4.184095860566448, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5590265', 'n_tokens_mistral': 1816, 'n_tokens_neox': 1517, 'n_words': 462}