Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!