<commit_before>/*
*  C Implementation: opts.c
*
* Option parser
*
* License: BSD-style license
* Copyright: <NAME> <<EMAIL>>,
*            <NAME> <<EMAIL>>
*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

#include "opts.h"
#include "stats.h"
#include "version.h"


uopt_t uopt;


void uopt_init() {
	uopt.doexit = 0;
	uopt.retval = 0;
	uopt.nbranches = 0;
	uopt.stats_enabled = false;
	uopt.cow_enabled = false; // copy-on-write
}

/**
 * Take a relative path as argument and return the absolute path by using the 
 * current working directory. The return string is malloc'ed with this function.
 */
static char *make_absolute(char *relpath) {
	// Already an absolute path
	if (*relpath == '/') return relpath;

	char cwd[PATHLEN_MAX];
	if (!getcwd(cwd, PATHLEN_MAX)) {
		perror("Unable to get current working directory");
		return NULL;
	}

	size_t cwdlen = strlen(cwd);
	if (!cwdlen) {
		fprintf(stderr, "Zero-sized length of CWD!\n");
		return NULL;
	}

	// 3 due to: +1 for '/' between cwd and relpath
	//           +1 for trailing '/'
	//           +1 for terminating '\0'<commit_msg>Simplified option initialization. That why at least everything that can be initialized with zeros won't be forgotten again.<commit_after>/*
*  C Implementation: opts.c
*
* Option parser
*
* License: BSD-style license
* Copyright: <NAME> <<EMAIL>>,
*            <NAME> <<EMAIL>>
*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

#include "opts.h"
#include "stats.h"
#include "version.h"


uopt_t uopt;


void uopt_init() {
	memset(&uopt, 0, sizeof(uopt_t)); // initialize options with zeros first

	// so far nothing more required, so far initializing with zeros sufficient
}

/**
 * Take a relative path as argument and return the absolute path by using the 
 * current working directory. The return string is malloc'ed with this function.
 */
static char *make_absolute(char *relpath) {
	// Already an absolute path
	if (*relpath == '/') return relpath;

	char cwd[PATHLEN_MAX];
	if (!getcwd(cwd, PATHLEN_MAX)) {
		perror("Unable to get current working directory");
		return NULL;
	}

	size_t cwdlen = strlen(cwd);
	if (!cwdlen) {
		fprintf(stderr, "Zero-sized length of CWD!\n");
		return NULL;
	}

	// 3 due to: +1 for '/' between cwd and relpath
	//           +1 for trailing '/'
	//           +1 for terminating '\0'
{'fraction_non_alphanumeric': 0.13745271122320302, 'fraction_numerical': 0.0058848255569567045, 'mean_word_length': 3.3992606284658042, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '3972540', 'n_tokens_mistral': 853, 'n_tokens_neox': 811, 'n_words': 266}