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

#define MAX_EXTENSION_LENGTH 3
#define MAX_EXTENSIONS_SUPPORTED 6
#define MAX_COMMAND_LENGTH 25

static size_t extensions_defined = 0;
static char extensions[MAX_EXTENSIONS_SUPPORTED][MAX_EXTENSION_LENGTH + 1];
static char commands[MAX_EXTENSIONS_SUPPORTED][MAX_COMMAND_LENGTH + 1];

static const char * get_extension_command(char * exten);
static void print_configuration();
static size_t define_extension(char * exten, char * command);

int main(int argc, char *argv[])
{
	char * exten;

	/* Standard extensions */
	define_extension("doc", "libreoffice");
	define_extension("odt", "libreoffice");
	define_extension("png", "eog");
	define_extension("txt", "gedit");
	define_extension("pdf", "evince");
	define_extension("mp3", "vlc");

	if ((argc >= 2) && (strcmp("--print-config", argv[1]) == 0)) {
		print_configuration();
		return 0;
	}

	if (argc < 2) {
		fputs("Usage: anyopen <filename>\n", stderr);
		fputs("       anyopen --print-config\n", stderr);
		return 1;
	}

	exten = strrchr(argv[1], '.');

	if (!exten) {
		fputs("Unable to determine file extension.\n", stderr);
		return 2;
	}

	exten += 1;

	printf("Running `%s %s`\n", get_extension_command(exten), argv[1]);
}

static const char * get_extension_command(char * exten)
{
	size_t i;
	for(i = 0; i < extensions_defined; i++) {
		if (strcmp(exten, extensions[i]) == 0) {
			break;
		}
	}

	if (i == extensions_defined) {
		return NULL;
	}
	
	return commands[i];
}

static size_t define_extension(char * exten, char * command)
{
	size_t old_index = extensions_defined;

	if (extensions_defined == MAX_EXTENSIONS_SUPPORTED) {
		return -1;
	}<commit_msg>Fully implemented anyopen<commit_after>#include <stdio.h>
#include <unistd.h> 
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#define MAX_EXTENSION_LENGTH 3
#define MAX_EXTENSIONS_SUPPORTED 10
#define MAX_COMMAND_LENGTH 25

static size_t extensions_defined = 0;
static char extensions[MAX_EXTENSIONS_SUPPORTED][MAX_EXTENSION_LENGTH + 1];
static char commands[MAX_EXTENSIONS_SUPPORTED][MAX_COMMAND_LENGTH + 1];

static const char * get_extension_command(char * exten);
static void print_configuration();
static size_t define_extension(char * exten, char * command);

int main(int argc, char *argv[])
{
	char * exten;
	pid_t pid;

	/* Standard extensions */
	define_extension("doc", "libreoffice");
	define_extension("odt", "libreoffice");
	define_extension("png", "eog");
	define_extension("txt", "vim");
	define_extension("pdf", "evince");
	define_extension("mp3", "vlc");
	define_extension("foo", "echo");

	if ((argc >= 2) && (strcmp("--print-config", argv[1]) == 0)) {
		print_configuration();
		return 0;
	}

	if (argc < 2) {
		fputs("Usage: anyopen <filename>\n", stderr);
		fputs("       anyopen --print-config\n", stderr);
		return 1;
	}

	exten = strrchr(argv[1], '.');

	if (!exten) {
		fputs("Unable to determine file extension.\n", stderr);
		return 2;
	}

	exten += 1;

	pid = fork();
	if (pid == 0) {
		const char * command = get_extension_command(exten);
		if (!command) {
			fputs("Unrecognized extension!\n", stderr);
			return 3;
		}

		if (execlp(command, command, argv[1], (char *) NULL) == -1) {
			perror("exec");
		}
	} else {
		int status; 
		wait(&status);

		if (WIFEXITED(status)) {
			printf("Child exited with status %d\n", WEXITSTATUS(status));
			return 0;
		}

		if (WIFSIGNALED(status)) {
			printf("Child terminated by signal %d\n", WTERMSIG(status));
			return 0;
		}
	}
}

static const char * get_extension_command(char * exten)
{
	size_t i;
	for(i = 0; i < extensions_defined; i++) {
		if (strcmp(exten, extensions[i]) == 0) {
			break;
		}
	}

	if (i == extensions_defined) {
		return NULL;
	}
	
	return commands[i];
}

static size_t define_extension(char * exten, char * command)
{
	size_t old_index = extensions_defined;

	if (extensions_defined == MAX_EXTENSIONS_SUPPORTED) {
		return -1;
	}
{'fraction_non_alphanumeric': 0.15606936416184972, 'fraction_numerical': 0.01206333249560191, 'mean_word_length': 4.743145743145743, 'pattern_counts': {'":': 0, '<': 19, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '300027', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1450, 'n_words': 339}