<commit_before>#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <SD.h>
#include <Time.h>
#include "LLShitCore.h"
#include "LLShitFull.h"

#define DEBUG

namespace LLSHITFULL_STRING {
    // String Table
	enum{
	  DEFAULT_BASE_PATH,
      FULL_CURRENT_LOG_FORMAT,
      WRITE_EVENT_FORMAT,
      LLSHITFULL_STRINGS_ENUM_COUNT
	};
	const char DEFAULT_BASE_PATH_STRING[] PROGMEM = "";
    const char FULL_CURRENT_LOG_FORMAT_STRING[] PROGMEM = "%s%s";
    #ifdef DEBUG
        const char WRITE_EVENT_FORMAT_STRING[] PROGMEM = "%s - %s\t%s\n";
    #else
        const char WRITE_EVENT_FORMAT_STRING[] PROGMEM = "%s\t%s\n";
    #endif
    const char DUMMY_STRING[] PROGMEM = "";

	PGM_P const LLSHITFULL_STRING_TABLE[] PROGMEM = {
	  DEFAULT_BASE_PATH_STRING,
      FULL_CURRENT_LOG_FORMAT_STRING,
      WRITE_EVENT_FORMAT_STRING,
      DUMMY_STRING
	};
}

LLSLogger::LLSLogger(){
    this->logPath = new char[sizeof(char)*(strlen(LLSHITFULL_STRING::DEFAULT_BASE_PATH_STRING)+1)];
    strcpy_P(this->logPath, (PGM_P)pgm_read_word(&(LLSHITFULL_STRING::LLSHITFULL_STRING_TABLE[LLSHITFULL_STRING::DEFAULT_BASE_PATH])));
}

LLSLogger::~LLSLogger(){
    delete(this->logPath);
}

/**
  * Return the log number (1-31) representing the date
  * If daysBack > 0 go back the appropriate number of days
  *     Rules when going back:
  *         Check for existence of log - never return a
  *             log number that fails SD.exists()
  *         Return 0 if there is no log (current day is 3, 2 doesn't exist etc)
  *         If we go back from 1, try 31, 30, and 29 without the above return 0
  *             it's possible we're coming around to Feb.  However if there's
  *             no 28-31 then we know to return 0
  */
uint8_t LLSLogger::getLogNumberOnly(uint8_t daysBack){
    uint8_t curDay;
    //Ensure we never get a 0... somehow we do when the function runs
    //  early in execution (first couple ms)
    curDay = max(1,day());
    //If we just want the standard "current log number"
    if(daysBack == 0){
        //Detect if this is a new log number relative to last logged event
        if(curDay != this->lastLogDay){
            //Reset flags if this is new
            this->lastLogDay = curDay;
            this->newLog = 1;
        }
    }else{
        char* buffer = new char[0];
        //We want a previous log, loop until we're back far enough
        while(daysBack > 0){
            //Go back one day
            curDay--;
            //If we need to wrap around
            if(curDay == 0){
                curDay = 31;
            }
            buffer = this->formatDateToFullLogName(buffer,curDay);
            if(!SD.exists(buffer)){
                if(curDay <= 28){
                    //See "Feb" rule in function notes
                    return 0;
                }else{
                    continue;
                }
            }
            //Decrement
            daysBack--;
        }
        delete(buffer);
    }
    //Return the day
    return curDay;
}
uint8_t LLSLogger::getLogNumberOnly(){return this->getLogNumberOnly(0);}

char* LLSLogger::getLogName(char* logName, uint8_t date){
    //Ensure char array is of suitable size
    logName = (char*)realloc(logName,sizeof(char)*13);//12345678.123\n
    sprintf_P(logName,PSTR("%u.log"),date);

    return logName;
}

char* LLSLogger::formatDateToFullLogName(char* ret,uint8_t date){
    char* logName = new char[0];
    logName = this->getLogName(logName,date);
    uint8_t nameLength;
    nameLength = strlen(this->logPath)+strlen(logName)+1;

    char format[strlen(LLSHITFULL_STRING::FULL_CURRENT_LOG_FORMAT_STRING)+1];
    strcpy_P(format, (PGM_P)pgm_read_word(&(LLSHITFULL_STRING::LLSHITFULL_STRING_TABLE[LLSHITFULL_STRING::FULL_CURRENT_LOG_FORMAT])));<commit_msg>Found you, you little fucker<commit_after>#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#include <SD.h>
#include <Time.h>
#include "LLShitCore.h"
#include "LLShitFull.h"

#define DEBUG

namespace LLSHITFULL_STRING {
    // String Table
	enum{
	  DEFAULT_BASE_PATH,
      FULL_CURRENT_LOG_FORMAT,
      WRITE_EVENT_FORMAT,
      LLSHITFULL_STRINGS_ENUM_COUNT
	};
	const char DEFAULT_BASE_PATH_STRING[] PROGMEM = "";
    const char FULL_CURRENT_LOG_FORMAT_STRING[] PROGMEM = "%s%s";
    #ifdef DEBUG
        const char WRITE_EVENT_FORMAT_STRING[] PROGMEM = "%s - %s\t%s\n";
    #else
        const char WRITE_EVENT_FORMAT_STRING[] PROGMEM = "%s\t%s\n";
    #endif
    const char DUMMY_STRING[] PROGMEM = "";

	PGM_P const LLSHITFULL_STRING_TABLE[] PROGMEM = {
	  DEFAULT_BASE_PATH_STRING,
      FULL_CURRENT_LOG_FORMAT_STRING,
      WRITE_EVENT_FORMAT_STRING,
      DUMMY_STRING
	};
}

LLSLogger::LLSLogger(){
    this->logPath = new char[sizeof(char)*(strlen(LLSHITFULL_STRING::DEFAULT_BASE_PATH_STRING)+1)];
    strcpy_P(this->logPath, (PGM_P)pgm_read_word(&(LLSHITFULL_STRING::LLSHITFULL_STRING_TABLE[LLSHITFULL_STRING::DEFAULT_BASE_PATH])));
}

LLSLogger::~LLSLogger(){
    delete(this->logPath);
}

/**
  * Return the log number (1-31) representing the date
  * If daysBack > 0 go back the appropriate number of days
  *     Rules when going back:
  *         Check for existence of log - never return a
  *             log number that fails SD.exists()
  *         Return 0 if there is no log (current day is 3, 2 doesn't exist etc)
  *         If we go back from 1, try 31, 30, and 29 without the above return 0
  *             it's possible we're coming around to Feb.  However if there's
  *             no 28-31 then we know to return 0
  */
uint8_t LLSLogger::getLogNumberOnly(uint8_t daysBack){
    uint8_t curDay;
    //Ensure we never get a 0... somehow we do when the function runs
    //  early in execution (first couple ms)
    curDay = max(1,day());
    //If we just want the standard "current log number"
    if(daysBack == 0){
        //Detect if this is a new log number relative to last logged event
        if(curDay != this->lastLogDay){
            //Reset flags if this is new
            this->lastLogDay = curDay;
            this->newLog = 1;
        }
    }else{
        char* buffer = new char[0];
        //We want a previous log, loop until we're back far enough
        while(daysBack > 0){
            //Go back one day
            curDay--;
            //If we need to wrap around
            if(curDay == 0){
                curDay = 31;
            }
            buffer = this->formatDateToFullLogName(buffer,curDay);
            if(!SD.exists(buffer)){
                if(curDay <= 28){
                    //See "Feb" rule in function notes
                    curDay = 0;
                    break;
                }else{
                    continue;
                }
            }
            //Decrement
            daysBack--;
        }
        delete(buffer);
    }
    //Return the day
    return curDay;
}
uint8_t LLSLogger::getLogNumberOnly(){return this->getLogNumberOnly(0);}

char* LLSLogger::getLogName(char* logName, uint8_t date){
    //Ensure char array is of suitable size
    logName = (char*)realloc(logName,sizeof(char)*13);//12345678.123\n
    sprintf_P(logName,PSTR("%u.log"),date);

    return logName;
}

char* LLSLogger::formatDateToFullLogName(char* ret,uint8_t date){
    char* logName = new char[0];
    logName = this->getLogName(logName,date);
    uint8_t nameLength;
    nameLength = strlen(this->logPath)+strlen(logName)+1;

    char format[strlen(LLSHITFULL_STRING::FULL_CURRENT_LOG_FORMAT_STRING)+1];
    strcpy_P(format, (PGM_P)pgm_read_word(&(LLSHITFULL_STRING::LLSHITFULL_STRING_TABLE[LLSHITFULL_STRING::FULL_CURRENT_LOG_FORMAT])));
{'fraction_non_alphanumeric': 0.10933020589001824, 'fraction_numerical': 0.01563721657544957, 'mean_word_length': 2.5881252921926134, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, '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': '4520519', 'n_tokens_mistral': 2600, 'n_tokens_neox': 2476, 'n_words': 630}