<commit_before>// New BSD License, part of efene, see LICENSE for details
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <assert.h>
#include <libgen.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "fnc.h"

#define STR_BUFFER_SIZE 2048
#define PATHS_SIZE 512

// copy the path to efene from the environment variable FNPATH if available
// if not found return NULL
// you have to free the variable
char* get_efene_path_from_env() {
	char *fnpath, *result;

	result = NULL;
	fnpath = getenv("FNPATH");

	if (fnpath != NULL) {
		result = strdup(fnpath);
		assert(result != NULL);
	}

	return result;
}

void show_usage() {
	printf("usage:\n");
	printf("\tfnc -s: run the interactive shell\n");
	printf("\tfnc -h: shows this help\n");
	printf("\tfnc -r module function [argumens*]: runs function from module passing optional arguments\n");
	printf("options:\n");
	printf("\t-t: type, can be beam (the default), lex, tree, ast, mod, erl or erl2ast\n");
	printf("\t-o: output path, the path where the compiled files will be written\n");
	printf("\t-T: test, instead of running the command print it to the screen\n");
	printf("examples:\n");
	printf("\tfnc foo.ifn: compile foo.ifn, write the result in the current directory\n");
	printf("\tfnc foo.ifn bar.fn baz.ifn: same as before but multiple files compiled\n");
	printf("\tfnc foo.ifn -o /tmp: compile foo.ifn, write the result in /tmp\n");
	printf("\tfnc -t beam -o /tmp foo.ifn: same as before but with the type set\n");
	printf("\tfnc -t erl foo.ifn: translate foo.ifn to erlang\n");
	printf("\tfnc -r foo run: runs the run function in the foo module\n");
}

int is_dir(const char *path) {
	struct stat st;
	return (stat(path, &st) == 0 && S_ISDIR(st.st_mode));
}

int fn_run(const char *args, char *argv0, int is_test) {
	int count, status;
	char *fnpath, buffer[STR_BUFFER_SIZE], *basepath;
	fnpath = get_efene_path_from_env();
	basepath = dirname(dirname(argv0));
<commit_msg>add help for -a and -p<commit_after>// New BSD License, part of efene, see LICENSE for details
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include <string.h>
#include <assert.h>
#include <libgen.h>
#include <sys/types.h>
#include <sys/stat.h>

#include "fnc.h"

#define STR_BUFFER_SIZE 2048
#define PATHS_SIZE 512

// copy the path to efene from the environment variable FNPATH if available
// if not found return NULL
// you have to free the variable
char* get_efene_path_from_env() {
	char *fnpath, *result;

	result = NULL;
	fnpath = getenv("FNPATH");

	if (fnpath != NULL) {
		result = strdup(fnpath);
		assert(result != NULL);
	}

	return result;
}

void show_usage() {
	printf("usage:\n");
	printf("\tfnc -s: run the interactive shell\n");
	printf("\tfnc -h: shows this help\n");
	printf("\tfnc -r module function [argumens*]: runs function from module passing optional arguments\n");
	printf("options:\n");
	printf("\t-t: type, can be beam (the default), lex, tree, ast, mod, erl or erl2ast\n");
	printf("\t-o: output path, the path where the compiled files will be written\n");
	printf("\t-T: test, instead of running the command print it to the screen\n");
	printf("\t-a: append a path to look for modules\n");
	printf("\t-p: prepend a path to look for modules\n");
	printf("examples:\n");
	printf("\tfnc foo.ifn: compile foo.ifn, write the result in the current directory\n");
	printf("\tfnc foo.ifn bar.fn baz.ifn: same as before but multiple files compiled\n");
	printf("\tfnc foo.ifn -o /tmp: compile foo.ifn, write the result in /tmp\n");
	printf("\tfnc -t beam -o /tmp foo.ifn: same as before but with the type set\n");
	printf("\tfnc -t erl foo.ifn: translate foo.ifn to erlang\n");
	printf("\tfnc -r foo run: runs the run function in the foo module\n");
}

int is_dir(const char *path) {
	struct stat st;
	return (stat(path, &st) == 0 && S_ISDIR(st.st_mode));
}

int fn_run(const char *args, char *argv0, int is_test) {
	int count, status;
	char *fnpath, buffer[STR_BUFFER_SIZE], *basepath;
	fnpath = get_efene_path_from_env();
	basepath = dirname(dirname(argv0));

{'fraction_non_alphanumeric': 0.14918190567853706, 'fraction_numerical': 0.0052935514918190565, 'mean_word_length': 4.275380710659898, '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': '7336722', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1470, 'n_words': 509}