<commit_before>/**
  * Touhou Community Reliant Automatic Patcher
  * Main DLL
  *
  * ----
  *
  * Logging functions.
  */

#include "thcrap.h"
#include <io.h>
#include <fcntl.h>

// -------
// Globals
// -------
static FILE *log_file = NULL;
static int console_open = 0;
static const char LOG[] = "thcrap_log.txt";
// -----------------------

#define VLA_VSPRINTF(str, va) \
	size_t str##_full_len = _vscprintf(str, va) + 1; \
	VLA(char, str##_full, str##_full_len); \
	/* vs*n*printf is not available in msvcrt.dll. Doesn't matter anyway. */ \
	vsprintf(str##_full, str, va);

void log_print(const char *str)
{
	if(console_open) {
		fprintf(stdout, str);
	}
	if(log_file) {
		fprintf(log_file, str);
		fflush(log_file);
	}
}

void log_nprint(const char *str, size_t n)
{
	fwrite(str, n, 1, stdout);
	if(log_file) {
		fwrite(str, n, 1, log_file);
	}
}

void log_vprintf(const char *str, va_list va)
{
	if(str) {
		VLA_VSPRINTF(str, va);
		log_print(str_full);
		VLA_FREE(str_full);
	}
}

void log_printf(const char *str, ...)
{
	if(str) {
		va_list va;
		va_start(va, str);
		log_vprintf(str, va);
		va_end(va);
	}<commit_msg>log_nprint(): Check if the console was opened.<commit_after>/**
  * Touhou Community Reliant Automatic Patcher
  * Main DLL
  *
  * ----
  *
  * Logging functions.
  */

#include "thcrap.h"
#include <io.h>
#include <fcntl.h>

// -------
// Globals
// -------
static FILE *log_file = NULL;
static int console_open = 0;
static const char LOG[] = "thcrap_log.txt";
// -----------------------

#define VLA_VSPRINTF(str, va) \
	size_t str##_full_len = _vscprintf(str, va) + 1; \
	VLA(char, str##_full, str##_full_len); \
	/* vs*n*printf is not available in msvcrt.dll. Doesn't matter anyway. */ \
	vsprintf(str##_full, str, va);

void log_print(const char *str)
{
	if(console_open) {
		fprintf(stdout, str);
	}
	if(log_file) {
		fprintf(log_file, str);
		fflush(log_file);
	}
}

void log_nprint(const char *str, size_t n)
{
	if(console_open) {
		fwrite(str, n, 1, stdout);
	}
	if(log_file) {
		fwrite(str, n, 1, log_file);
	}
}

void log_vprintf(const char *str, va_list va)
{
	if(str) {
		VLA_VSPRINTF(str, va);
		log_print(str_full);
		VLA_FREE(str_full);
	}
}

void log_printf(const char *str, ...)
{
	if(str) {
		va_list va;
		va_start(va, str);
		log_vprintf(str, va);
		va_end(va);
	}
{'fraction_non_alphanumeric': 0.19368785127539992, 'fraction_numerical': 0.0034587116299178555, 'mean_word_length': 3.161870503597122, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2047876', 'n_tokens_mistral': 1050, 'n_tokens_neox': 993, 'n_words': 211}