<commit_before>// Copyright (c) 2016 <NAME>
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the MIT License. See LICENSE for more details.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include <sys/stat.h>
#include "config.h"
#include "modules/log.h"

#define SERVER       1
#define CLIENT       2
#define ERRMSG_SIZE  200

// Static Variables
static FILE *logFile;
static char errmsg[ERRMSG_SIZE];

void log_init(void) {
	memset(errmsg, 0, ERRMSG_SIZE);
	logFile = NULL;
}

int log_open_server(void) {
	return log_open(SERVER);
}

int log_open_client(void) {
	return log_open(CLIENT);
}

int log_open(int logType) {
	int i;
	char *homeDir;
	char *logFilePath              = LOG_FILE_PATH;
	char *logFileName;
	char *logFilePathName;
	char *logFileFullPathName;
	struct stat sb;
	
	// Do we use server of client log name?
	if (logType == SERVER) {
		logFileName = malloc(strlen(SERVER_LOG_NAME) + 1);
		strcpy(logFileName, SERVER_LOG_NAME);
	} else {
		logFileName = malloc(strlen(CLIENT_LOG_NAME) + 1);
		strcpy(logFileName, CLIENT_LOG_NAME);
	}
	
	// Combine log file path and name in to one string.
	logFilePathName = malloc(strlen(logFilePath) + strlen(logFileName) + 1);
	sprintf(logFilePathName, "%s%s", logFilePath, logFileName);
	
	// Do we have a full path or relative path?
	// If relative, use home dir as base to make full path.
	if (logFilePathName[0] == '/') {
		logFileFullPathName = logFilePathName;
	} else {<commit_msg>Check log file path config for a trailing slash and act appropriately.<commit_after>// Copyright (c) 2016 <NAME>
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the MIT License. See LICENSE for more details.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include <sys/stat.h>
#include "config.h"
#include "modules/log.h"

#define SERVER       1
#define CLIENT       2
#define ERRMSG_SIZE  200

// Static Variables
static FILE *logFile;
static char errmsg[ERRMSG_SIZE];

void log_init(void) {
	memset(errmsg, 0, ERRMSG_SIZE);
	logFile = NULL;
}

int log_open_server(void) {
	return log_open(SERVER);
}

int log_open_client(void) {
	return log_open(CLIENT);
}

int log_open(int logType) {
	int i;
	char *homeDir;
	char *logFilePath              = LOG_FILE_PATH;
	char *logFileName;
	char *logFilePathName;
	char *logFileFullPathName;
	struct stat sb;
	
	// Do we use server of client log name?
	if (logType == SERVER) {
		logFileName = malloc(strlen(SERVER_LOG_NAME) + 1);
		strcpy(logFileName, SERVER_LOG_NAME);
	} else {
		logFileName = malloc(strlen(CLIENT_LOG_NAME) + 1);
		strcpy(logFileName, CLIENT_LOG_NAME);
	}
	
	// Combine log file path and name in to one string.
	if (logFilePath[(int)strlen(logFilePath) - 1] == '/') {
		logFilePathName = malloc(strlen(logFilePath) + strlen(logFileName) + 1);
		sprintf(logFilePathName, "%s%s", logFilePath, logFileName);
	} else {
		logFilePathName = malloc(strlen(logFilePath) + strlen(logFileName) + 2);
		sprintf(logFilePathName, "%s/%s", logFilePath, logFileName);
	}
	
	// Do we have a full path or relative path?
	// If relative, use home dir as base to make full path.
	if (logFilePathName[0] == '/') {
		logFileFullPathName = logFilePathName;
	} else {
{'fraction_non_alphanumeric': 0.11996418979409132, 'fraction_numerical': 0.008952551477170993, 'mean_word_length': 4.180834621329212, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '2310691', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1156, 'n_words': 345}