Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C program Objective: Recreate the ls command and its flags. I have a linked list of linked list that represents a parsed command cmd is

C program

Objective: Recreate the ls command and its flags.

I have a linked list of linked list that represents a parsed command cmd is the start of the main command and param_list contains a char * to hold one of the parameters and a *next pointer if there is more than one. This code I have works for a little but doesn't seem to work with more than one flag like ls -l -r. The point of the code is also so that it can be reused with other commands like who and df. If you can figure out how to change it to where if someone typed ls -l < file.txt that would be helpful. Thanks~

void execommands(clt *cmds)

{

ct * cmd = cmds->head;

pid_t pid = fork();

switch(pid) {

case -1:

//error return

break;

case 0:

{

char ** rhp_argv = NULL;

char rhp *= NULL;

pt *temp = NULL;

int i = 1;

temp = cmd->param_list;

rhp = cmd->cmd;

if(0 != cmd->param_count)

{

rhp_argv = (char **) calloc((cmd->param_count +1)), sizeof(char *));

rhp_argv[0] = rhp;

while(temp != NULL) {

rhp_argv[i] = strdup(temp->param);

temp = temp->next;

i++;

}

}

else {

rhp_argv = (char **) calloc(2, sizeof(char *));

rhp_argv[0] = rhp;

}

execvp(rhp_argv[0], rhp_argv);

//error exit

}

}

]

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions