src/simpleShell.c
int commandParser(char* command, char** arguments,int argNo, int* conF,int* inpF, int* outpF, int* pipeF)
{
	//history support implementation
	if(command[0]=='!' && command[1]=='!')
	{
		
		if (command[2]!='\n')
		{
			printf("Please, insert a correct command.\n");
			return -2;
		}
		else if(argNo==-2) //argNo = -2 is the default value at the beginning of the program start
		{
			printf("No commands in history.\n");
			return -2;
		}
		else
		{	//to echo the last command when a !! command is typed
			printf("osh>");
			for(int i=0;i<argNo;i++)
			{
				printf("%s ",arguments[i]);
			}
			printf("\n");
			return argNo;
		}
	}
	int i=0;
	int c=0;
	int a=0;
	char temp[MAX_LINE];
	while (command[i]!='\n' && command[i]!=0)
	{
		if((command[i]==' ' || command[i]=='\t') && command[i+1]!=' ' && command[i+1]!='\t') //to store the value of the argument when a space is read
		{
			arguments[a]= (char*) malloc((c+2)*sizeof(char));
			temp[c]=0;
			strcpy(arguments[a],temp);
			a++;
			c=0;
		}
		else if (command[i]!=' ' && command[i]!='\t')
		{
			temp[c++]=command[i]; //store the characters of the arguments in the temp variable
		}
		i++;
	}
	arguments[a]= (char*) malloc((c+2)*sizeof(char)); //to store the last argument
	temp[c]='\0';
	strcpy(arguments[a],temp);
	a++;
	arguments[a]=NULL; //to store the last argument to be equal to NULL
	int x = checkForFlags(arguments,a,conF,inpF,outpF,pipeF);
	return a;
}
//a function to parse the user input and tokenize it
a function to parse the user input and tokenize it
a function to parse the user input and tokenize it
int commandParser(char* command, char** arguments,int argNo, int* conF,int* inpF, int* outpF, int* pipeF)
{
	if(command[0]=='!' && command[1]=='!')
	{
		if (command[2]!='\n')
		{
			printf("Please, insert a correct command.\n");
			return -2;
		}
		else if(argNo==-2) 
		{
			printf("No commands in history.\n");
			return -2;
		}
		else
		{	
			printf("osh>");
			for(int i=0;i<argNo;i++)
			{
				printf("%s ",arguments[i]);
			}
			printf("\n");
			return argNo;
		}
	}
	int i=0;
	int c=0;
	int a=0;
	char temp[MAX_LINE];
	while (command[i]!='\n' && command[i]!=0)
	{
		if((command[i]==' ' || command[i]=='\t') && command[i+1]!=' ' && command[i+1]!='\t') 
		{
			arguments[a]= (char*) malloc((c+2)*sizeof(char));
			temp[c]=0;
			strcpy(arguments[a],temp);
			a++;
			c=0;
		}
		else if (command[i]!=' ' && command[i]!='\t')
		{
			temp[c++]=command[i]; 
		}
		i++;
	}
	arguments[a]= (char*) malloc((c+2)*sizeof(char)); 
	temp[c]='\0';
	strcpy(arguments[a],temp);
	a++;
	arguments[a]=NULL;  to be equal to NULL
	int x = checkForFlags(arguments,a,conF,inpF,outpF,pipeF);
	return a;
}
int commandParser ( char * command , char * * arguments , int argNo , int * conF , int * inpF , int * outpF , int * pipeF ) { if ( command [ 0 ] == ' ' && command [ 1 ] == ' ' ) { if ( command [ 2 ] != ' \n ' ) { printf ( " \n " ) ; return -2 ; } else if ( argNo == -2 ) { printf ( " \n " ) ; return -2 ; } else { printf ( " " ) ; for ( int i = 0 ; i < argNo ; i ++ ) { printf ( " " , arguments [ i ] ) ; } printf ( " \n " ) ; return argNo ; } } int i = 0 ; int c = 0 ; int a = 0 ; char temp [ MAX_LINE ] ; while ( command [ i ] != ' \n ' && command [ i ] != 0 ) { if ( ( command [ i ] == ' ' || command [ i ] == ' \t ' ) && command [ i + 1 ] != ' ' && command [ i + 1 ] != ' \t ' ) { arguments [ a ] = ( char * ) malloc ( ( c + 2 ) * sizeof ( char ) ) ; temp [ c ] = 0 ; strcpy ( arguments [ a ] , temp ) ; a ++ ; c = 0 ; } else if ( command [ i ] != ' ' && command [ i ] != ' \t ' ) { temp [ c ++ ] = command [ i ] ; } i ++ ; } arguments [ a ] = ( char * ) malloc ( ( c + 2 ) * sizeof ( char ) ) ; temp [ c ] = ' \0 ' ; strcpy ( arguments [ a ] , temp ) ; a ++ ; arguments [ a ] = NULL ; int x = checkForFlags ( arguments , a , conF , inpF , outpF , pipeF ) ; return a ; }
a function to parse the user input and tokenize it
a function to parse the user input and tokenize it
//history support implementation //argNo = -2 is the default value at the beginning of the program start //to echo the last command when a !! command is typed //to store the value of the argument when a space is read //store the characters of the arguments in the temp variable //to store the last argument //to store the last argument to be equal to NULL