Dallas92/Operating-Systems — Issue #1: Operating Systems - Shell
Author: Dallas92
Created: 2012-02-18 15:43:03+00:00
State: open

//Console application by which you can process command arguments
/*
*@author Bulegenov Daulet
*@group CSSE 106
*/

#include
#include
#include
#include
#include

//function to which the string with 1 command will bi passed
void creTask(char **argv2, int start, int endindex,int argc)
{
//variable which is important for Add and Multiplication functions
double sum = 0;
//Addition of the elements
if(strcmp(argv2[start],"ADD")==0)
{
for(int i = start+1; i < endindex; i++)
{
sum += atof(argv2[i]);
}
printf("%s","The sum of elements is equal to ");
printf("%lf",sum);
printf("%s","\n");
}
//Multiplication of elements
if(strcmp(argv2[start],"MULTIPLY")==0)
{
sum = 1;
for(int i = start+1; i < endindex; i++)
{
sum *= atof(argv2[i]);
}
printf("%s","The multiplication of elements is equal to ");
printf("%lf",sum);
printf("%s","\n");
}
//Show all the elements
if(strcmp(argv2[start],"ARGS")==0)
{
printf("%s","All elements from command line: \n");
printf("%s","\n");
for(int i = 0; i < argc; i++)
{
printf("%s",argv2[i]);
printf("%s"," ");
}
printf("%s","\n");
}

//variable which will store Date or Time or both
char x[9]; //stores the date
char y[9]; //stores the time

if(strcmp(argv2[start],"DATE/TIME")==0)
{
printf("Date:%s\n",_strdate(x));
printf("Time: %s\n",_strtime(y));
printf("%s","\n");
}
if(strcmp(argv2[start],"DATE")==0)
{
printf("Date:%s\n",_strdate(x));
printf("%s","\n");
}
if(strcmp(argv2[start],"TIME")==0)
{
printf("Time: %s\n",_strtime(y));
printf("%s","\n");
}

if(strcmp(argv2[start],"HELP")==0)
{
//checks the next elements for null or existence of smth
int x = endindex - start;
if(x ==1)
{
printf("Add - add all numbers in command line (decimal, hexadecimal and binary).\n");
printf("Multiply - multiply all numbers in command line (decimal, hexadecimal and binary).\n");
printf("Args - list all parameters on the command line, numbers or strings.\n");
printf("Date/Time - output current system date and time.\n");
printf("Help - list all user commands and the syntax of their arguments. Help should be selective and have at least two levels of hierarchical depth.\n");
printf("Help - show the help page for particular command, for example, “Help time” will say something like “Time command shows current time” and add usage example and sample output.\n");
}
//smth after Help exist
else
{
//loop for making our command processing case sensetivity
for (int j = 0; argv2[start+1][j]; j++)
{
argv2[start+1][j] = toupper(argv2[start+1][j]);
}
if(strcmp(argv2[start+1],"ADD")==0)
{
printf("Add - add all numbers in command line (decimal, hexadecimal and binary).\n");
}
else if(strcmp(argv2[start+1],"MULTIPLY")==0)
{
printf("Multiply - multiply all numbers in command line (decimal, hexadecimal and binary).\n");
}
else if(strcmp(argv2[start+1],"ARGS")==0)
{
printf("Args - list all parameters on the command line, numbers or strings.\n");
}
else if(strcmp(argv2[start+1],"DATE")==0)
{
printf("Date - output current system date and time.\n");
}
else if(strcmp(argv2[start+1],"TIME")==0)
{
printf("Time - output current system date and time.\n");
}
else if(strcmp(argv2[start+1],"DATE/TIME")==0)
{
printf("Date/Time - output current system date and time.\n");
}
}
}
}

int main(int argc, char **argv)
{
int startIndex = 1;
int endIndex = 0;

//Memory allocation for argv variable
//argv = (char**)malloc(argc+1);

for(int i =0;i