<commit_before>/* ex: set tabstop=4 noexpandtab: */
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
#include<string.h>
#include<fcntl.h>

#define MAX_LENGTH 514
#define TOKEN_DELIM " \t\n\r"

void printError()
{
	char error_message[30] = "An error has occurred\n";
	write(STDERR_FILENO, error_message, strlen(error_message));
}

char *readInput()
{
	char* cmdLine = malloc(MAX_LENGTH * sizeof(char));

	//TODO: check if we need to handle null return case
	fgets(cmdLine, MAX_LENGTH, stdin);

	//input string is more than 512 characters
	if(strlen(cmdLine) == MAX_LENGTH -1 && cmdLine[MAX_LENGTH -2] != '\n') {
		printError();
		return NULL;
	}

	return cmdLine;
}

char **parseInput(char *cmdLine)
{
    //TODO: check suitable size to allocate memory
	char **tokenList = malloc (MAX_LENGTH * sizeof(char*));
	char *token = strtok(cmdLine, TOKEN_DELIM);
	int i = 0;
	while (token != NULL) {
		tokenList[i] = token;
		i++;
		token = strtok(NULL, TOKEN_DELIM);
	}
		tokenList[i] = NULL;
	return tokenList;
}

int main(int argc, char *argv[])
{
	while (1) {
		int childPid;

		// print command line
		printf("mysh # ");

		// read input from command line or batch file
		char *cmdLine = readInput();

		if (cmdLine != NULL && strlen(cmdLine) > 1) {
			// parse input to get command
			char **shArgv = parseInput(cmdLine);
			// record command for history

			// if built in command, execute command

			// else system call

			childPid = fork();
			if (childPid == 0) {
				execvp(shArgv[0], shArgv);
				printf("Error in command execution\n");
			}
			else if (childPid > 0) {
				waitpid(childPid, NULL, 0);
			}
			free(cmdLine);
			free(shArgv);
		}
	}
	return 0;
}
<commit_msg>add stub for batch mode<commit_after>/* ex: set tabstop=4 noexpandtab: */
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
#include<string.h>
#include<fcntl.h>

#define MAX_LENGTH 514
#define TOKEN_DELIM " \t\n\r"

void printError()
{
	char error_message[30] = "An error has occurred\n";
	write(STDERR_FILENO, error_message, strlen(error_message));
}

char *readInput()
{
	char* cmdLine = malloc(MAX_LENGTH * sizeof(char));

	//TODO: check if we need to handle null return case
	fgets(cmdLine, MAX_LENGTH, stdin);

	//input string is more than 512 characters
	if(strlen(cmdLine) == MAX_LENGTH -1 && cmdLine[MAX_LENGTH -2] != '\n') {
		printError();
		return NULL;
	}

	return cmdLine;
}

char **parseInput(char *cmdLine)
{
    //TODO: check suitable size to allocate memory
	char **tokenList = malloc (MAX_LENGTH * sizeof(char*));
	char *token = strtok(cmdLine, TOKEN_DELIM);
	int i = 0;
	while (token != NULL) {
		tokenList[i] = token;
		i++;
		token = strtok(NULL, TOKEN_DELIM);
	}
		tokenList[i] = NULL;
	return tokenList;
}

int process_file(char * batch_file)
{
	return 0;
}

void run(void)
{
	while (1) {
		int childPid;

		// print command line
		printf("mysh # ");

		// read input from command line or batch file
		char *cmdLine = readInput();

		if (cmdLine != NULL && strlen(cmdLine) > 1) {
			// parse input to get command
			char **shArgv = parseInput(cmdLine);
			// record command for history

			// if built in command, execute command

			// else system call

			childPid = fork();
			if (childPid == 0) {
				execvp(shArgv[0], shArgv);
				printf("Error in command execution\n");
			}
			else if (childPid > 0) {
				waitpid(childPid, NULL, 0);
			}
			free(cmdLine);
			free(shArgv);
		}
	}
}

int main(int argc, char *argv[])
{
	if (argc == 1) {
		// Run interactive shell
		run();
	} else if (argc == 2) {
		// Run batchmode processing
		return process_file(argv[1]);
	} else {
		// unsupported mode!
		printError();
		return 1;
	}
	return 0;
}

{'fraction_non_alphanumeric': 0.14725749797352067, 'fraction_numerical': 0.011618481491488787, 'mean_word_length': 3.5423312883435583, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, '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': '383923', 'n_tokens_mistral': 1526, 'n_tokens_neox': 1359, 'n_words': 377}