Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

this is trial practice for git #5

Open
wants to merge 5 commits into
base: v0.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion cmd_execution.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,56 @@
*
*/

/* Implementation of redirection output string.
* Developer: Neha Choudhary
*/

#include "nektech_shell.h"
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/file.h>


extern int redirect_flag;
extern char *file_name;

/* command Execution.*/
void run_cmd(char *argv[])
{
pid_t child_pid;
int fd;

child_pid=fork();
if(child_pid<0){
printf("SOME ERROR HAPPENED IN FORK\n");
exit(2);
}else if(child_pid==0){
if(execvp(argv[0],argv)<0)
/* redirection output code */
if(redirect_flag){
fd=open(file_name, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWGRP | S_IWUSR);
/* Handling of file creation */
if(fd<0)
switch(errno){
case EACCES:
printf("The requested access to the file is not allowed,%s\npermission is denied",file_name);
break;
case ENOENT:
printf("O_CREAT is not set and the named file: %s does not exist",file_name);
break;
case ENOMEM:
printf("Insufficient kernel memory was available.");
break;
default:
printf("Some error is happened in creating the requested file: %s",file_name);
break;
}
else{
dup2(fd,1);
close(fd);
}
}

if(execvp(argv[0],argv)<0)
switch(errno){
case ENOENT:
printf("COMMAND OR FILENAME NOT FOUND\n");
Expand Down
48 changes: 38 additions & 10 deletions input_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,23 @@
/* Taking User Input and Parsing the input to take action.
* String operations and intelligece for user input.
* Developer: Deepika Pandey
*/
*/

/* Identify Redirection output string from the user input.
* Developer: Neha choudhary
*/

int redirect_flag =0;
char *file_name=NULL;

main()
{
char cmd[MAX_LEN];
char *cmd_arg[MAX_ARG];
int cmdlen,i,j,tag;

do{
/* init cmd */

for(i=0;i<MAX_LEN;i++) cmd[i]='\0';

printf("NEK Tech>> ");
Expand All @@ -42,8 +49,11 @@ main()
cmdlen--;
cmd[cmdlen]='\0';


for(i=0;i<MAX_ARG;i++) cmd_arg[i]=NULL;

i=0; j=0; tag=0;

while(i<cmdlen && j<MAX_ARG){
if(cmd[i]==' '){
cmd[i]='\0';
Expand All @@ -53,14 +63,28 @@ main()
cmd_arg[j++]=cmd+i;
tag=1;
}
i++;
i++;
}

if(j>=MAX_ARG && i<cmdlen){
printf("TOO MANY ARGUMENTS\n");
printf("arguments exceed");
continue;
}
/* cmd_arg NULL Condition. */


for(i=0; *(cmd_arg+i)!=NULL; i++)
/* Identify redirection */
if(strcmp(cmd_arg[i],">")==0){
redirect_flag=1;
*(cmd_arg+i)=NULL;
file_name=(cmd_arg[++i]);
if(file_name==NULL){
printf("NEKTech_Shell: syntax error near unexpected command\n");
exit(1);
}
}

/* cmd_arg NULL Condition. */
if (cmd_arg[0] == NULL )
continue;
/* cmd quit/exit/q: exit NEK Tech Shell */
Expand All @@ -71,11 +95,15 @@ main()
if(strcmp(cmd_arg[0],"cd")==0){
change_dir(cmd_arg);
continue;
}

/* other cmd for fork/exec*/
}


/* other cmd for fork/exec*/

run_cmd(cmd_arg);
}while(1);
redirect_flag=0;
file_name=NULL;
}while(1);
}

/* cd - Change Directory
Expand Down