<commit_before>#include <iostream>
#include <unistd.h>
#include <string>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <errno.h>
#include <vector>
#include <stdlib.h>


using namespace std;


void parse(char * line, vector<string> & input) {
    

    char * pch;
	pch = strtok (line, " \n");
	while (pch!= NULL) {
	    
	    // Ignore after comments
	    if (*pch == '#')
		break;
	    
	    // Check for && and ||
	    // Break input up
	    char * a = strstr(pch, "&&");
	    char * b = strstr(pch, "||");
	    char * c = strstr(pch, ";");

	    // If there are connectors, break up the string
	    // into parts and add them individually to the vector
	    if (a!=NULL || b!=NULL || c!=NULL) {
		while (strlen(pch) != 0 ) {

		    // Checks for && and ||
		    if ((pch[0] == '&' && pch[1] == '&') ||
			(pch[0] == '|' && pch[1] == '|')) {
			
			string tmp;
			tmp += *pch;
			tmp += *(pch+1);
			tmp[2] = '\0';
			
			input.push_back(tmp);
			memmove(pch, pch+2, strlen(pch) - 2);
			pch[strlen(pch)-2] = '\0';
		    }
		    // Check for semicolons
		    else if (*pch == ';') {
			input.push_back(";");
			memmove(pch, pch+1, strlen(pch) -1);
			pch[strlen(pch)-1] = '\0';
		    }
		    else {
			string word;
			int numletters = 0;

			char *d = pch;
			while (d!=a && d!=b && d!=c) {
			    if (*d == '\0')
				break;
			    word += *d;
			    numletters++;
			    d++;
			}
			input.push_back(word);
			memmove(pch, pch+numletters, strlen(pch) -numletters);
			pch[strlen(pch)-numletters] = '\0';
		    }
		
		    a = strstr(pch, "&&");
		    b = strstr(pch, "||");
		    c = strstr(pch, ";");
		}
	    }

	    // If no connectors, just add to vector	
	    if (*pch != '\0' && *pch != '\n' && *pch != '#')
		input.push_back(pch);
	    pch = strtok (NULL, " \n");
	}
}

void execute(vector<string> & input, int start, int end) {

    //Call execvp, based on which elements in the string vector to use
    char * argv[5];
	    
	    int i = 0;
	    
	    for (i = 0; i <= (end - start); i++) {
		argv[i] = new char[5];
	    }

	    for (i = 0; i < (end-start); i++) {
		strcpy(argv[i], input[i+start].c_str());
	    }
	    
	    argv[i] = NULL;

	    int status = execvp(argv[0], argv);
	    if (status == -1)
		perror("execvp");
		exit(1); 
}


int main() {

    vector<string> input; 
    int status=0;

    // Get username
    char * usrname = getlogin();
    if (usrname == NULL){
	perror ("getlogin");
	exit(1);
    }

    // Get hostname
    char hostname[20];

    if (gethostname(hostname, sizeof hostname) ==-1) {
	perror("gethostname");
	exit(1);
    }



    // Main loop
    while (1) {
	
	status = 0;
	if (input.size() != 0)
	    input.clear();
		
	cout << usrname << "@" << hostname <<"$ ";

	string string1;
	getline(cin, string1);
	char * line = new char [string1.length() + 1];
	strcpy(line, string1.c_str());

	parse(line, input);

	delete line;

	if (input.size() == 0)
	    continue;
	
	if (strcmp(input[0].c_str(), "exit") == 0)
	    exit(0);


	int pid=fork();
    if (pid == -1)
        perror ("fork");
	int pid2;
	if (pid == 0) {
	    

	    int start = 0;
	    int end = input.size();
	    unsigned i;
		
loop:		

	    end = input.size();
	    for (i = start; i < input.size(); i++) {



		if (input[i] == ";" || input[i] == "&&" || input[i] == "||") {
		    string connector = input[i];

		    pid2 = fork();<commit_msg>updated rshell<commit_after>#include <iostream>
#include <unistd.h>
#include <string>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <errno.h>
#include <vector>
#include <stdlib.h>


using namespace std;


void parse(char * line, vector<string> & input) {
    

    char * pch;
	pch = strtok (line, " \n");
	while (pch!= NULL) {
	    
	    // Ignore after comments
	    if (*pch == '#')
		break;
	    
	    // Check for && and ||
	    // Break input up
	    char * a = strstr(pch, "&&");
	    char * b = strstr(pch, "||");
	    char * c = strstr(pch, ";");

	    // If there are connectors, break up the string
	    // into parts and add them individually to the vector
	    if (a!=NULL || b!=NULL || c!=NULL) {
		while (strlen(pch) != 0 ) {

		    // Checks for && and ||
		    if ((pch[0] == '&' && pch[1] == '&') ||
			(pch[0] == '|' && pch[1] == '|')) {
			
			string tmp;
			tmp += *pch;
			tmp += *(pch+1);
			tmp[2] = '\0';
			
			input.push_back(tmp);
			memmove(pch, pch+2, strlen(pch) - 2);
			pch[strlen(pch)-2] = '\0';
		    }
		    // Check for semicolons
		    else if (*pch == ';') {
			input.push_back(";");
			memmove(pch, pch+1, strlen(pch) -1);
			pch[strlen(pch)-1] = '\0';
		    }
		    else {
			string word;
			int numletters = 0;

			char *d = pch;
			while (d!=a && d!=b && d!=c) {
			    if (*d == '\0')
				break;
			    word += *d;
			    numletters++;
			    d++;
			}
			input.push_back(word);
			memmove(pch, pch+numletters, strlen(pch) -numletters);
			pch[strlen(pch)-numletters] = '\0';
		    }
		
		    a = strstr(pch, "&&");
		    b = strstr(pch, "||");
		    c = strstr(pch, ";");
		}
	    }

	    // If no connectors, just add to vector	
	    if (*pch != '\0' && *pch != '\n' && *pch != '#')
		input.push_back(pch);
	    pch = strtok (NULL, " \n");
	}
}

void execute(vector<string> & input, int start, int end) {

    //Call execvp, based on which elements in the string vector to use
    char * argv[5];
	    
	    int i = 0;
	    
	    for (i = 0; i <= (end - start); i++) {
		argv[i] = new char[5];
	    }

	    for (i = 0; i < (end-start); i++) {
		strcpy(argv[i], input[i+start].c_str());
	    }
	    
	    argv[i] = NULL;

	    int status = execvp(argv[0], argv);
	    if (status == -1)
		perror("execvp");
		exit(1); 
}


int main() {

    vector<string> input; 
    int status=0;

    // Get username
    char * usrname = getlogin();
    if (usrname == NULL){
	perror ("getlogin");
	exit(1);
    }

    // Get hostname
    char hostname[20];

    if (gethostname(hostname, sizeof hostname) ==-1) {
	perror("gethostname");
	exit(1);
    }



    // Main loop
    while (1) {
	
	status = 0;
	if (input.size() != 0)
	    input.clear();
		
	cout << usrname << "@" << hostname <<"$ ";

	string string1;
	getline(cin, string1);
	char * line = new char [string1.length() + 1];
	strcpy(line, string1.c_str());

	parse(line, input);

	delete line;

	if (input.size() == 0)
	    continue;

    for (int i = 0; i < input.size(); i++)
	    if (strcmp(input[i].c_str(), "exit") == 0) exit(0);


	int pid=fork();
    if (pid == -1)
        perror ("fork");
	int pid2;
	if (pid == 0) {
	    

	    int start = 0;
	    int end = input.size();
	    unsigned i;
		
loop:		

	    end = input.size();
	    for (i = start; i < input.size(); i++) {



		if (input[i] == ";" || input[i] == "&&" || input[i] == "||") {
		    string connector = input[i];

		    pid2 = fork();
{'fraction_non_alphanumeric': 0.2081507449605609, 'fraction_numerical': 0.014899211218229623, 'mean_word_length': 2.1728452270620946, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 29, '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': '3340960', 'n_tokens_mistral': 3040, 'n_tokens_neox': 2665, 'n_words': 661}