Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question: need the pseudo code turned into a workable program as specified in th

ID: 3822619 • Letter: Q

Question

Question: need the pseudo code turned into a workable program as specified in the following pseudo code.

Given Code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#define MAXLINE 80
#define MAXARGS 20
#define MAX_PATH_LENGTH 50
#define TRUE 1

/* function prototypes */
int parseline(char *cmdline, char **argv);

/* ----------------------------------------------------------------- */
/*                  The main program starts here                     */
/* ----------------------------------------------------------------- */
int main(void)
{
    char cmdline[MAXLINE];
    char *argv[MAXARGS];
    int argc;
    int status;
    pid_t pid;

    /* Loop forever to wait and process commands */
    while (TRUE) {
   /* Print your shell name: csc60mshell (m for mini shell) */
   printf("cscc60mshell> ");

   /* Read the command line */
   fgets(cmdline, MAXLINE, stdin);

   /* Call parseline to build argc/argv */
//code here

   /* If user hits enter key without a command, continue to loop
   * again at the beginning */
   /* Hint: if argc is zero, no command declared */
   /* Hint: look up for the keyword "continue" in C */
//code here
   /* Handle build-in command: exit, pwd, or cd */
   /* Put the rest of your code here */
//code here

    } /* end of the while */
} /* end of main */
/* ----------------------------------------------------------------- */
/*                  parseline                                        */
/* ----------------------------------------------------------------- */
/* parse input line into argc/argv format */

int parseline(char *cmdline, char **argv)
{
    int count = 0;
    char *separator = " "; /* Includes space, Enter, Tab */

    /* strtok searches for the characters listed in separator */
    argv[count] = strtok(cmdline, separator);
    while ((argv[count] != NULL) && (count+1 < MAXARGS)) {
   argv[++count] = strtok((char *) 0, separator);
    }      
    return count;
}

Pseudo Code (Highlight indicates provided code.) int main (void) while (TRUE) int childPid; char *cmd Line; print the prompt(); i.ee. csc60mshell Use printf*/ fgets(cmdline, MAXLINE, stdin); You have to write the call. The function itself is provided: function parseline Call the function parseline, sending in cmdline & argv, getting back argc code to print out the argc and the agrv list to make sure it all came in. Required. Print a line. Ex: "Argc %i" loop starting at zero, thru less than agrc, increment by one. print each argv[loop counter] Start processing the built-in commands if argc compare equal to zero) a command was not entered, might have been just Enter or a space&Enter; continue to end of while(TRUE)-loop next deal with the built-in commands Use strcmp to do the test after each command, do a continue to end of while(TRUE)-loop if ("exit") issue an exit call else if ("pwd") declare a char variable array of size MAX PATH LENGTH to hold the path do a getcwd print the path else if ("cd") declare a char variable dir as a pointer (with an if the argc is 1 use the getenv call with "HOME" and return the value from the call to variable dir else variable dir gets assigned the value of argv[1] execute a call to chdir(dir) with error checking. Message error changing directory end of the while loop end of main

Explanation / Answer

Here is Your Completd Code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#define MAXLINE 80
#define MAXARGS 20
#define MAX_PATH_LENGTH 50
#define TRUE 1


int parseline(char *cmdline, char **argv);

int main(void)
{
    char cmdline[MAXLINE];
    char *argv[MAXARGS];
    int argc;
    int status;
    pid_t pid;

    while (TRUE) {

int childPid;  
   int count;
   char *cmdline;

printf("cscc60mshell> ");

  
   fgets(cmdline, MAXLINE, stdin);

argc = parseline(*cmdline, **argv);

printf("Argc = %s ", argc);

   for(count = 0; count < argc; count++){
       printf("Argv %i = %s ", count, argv[count]);
       if(argv[0] == 0){
           printf("No Command Given");
           continue;      
}
   //   printf("%i" ,argv[count]);
       int strcmp(const char *s1, const char *s2);
       if(strcmp(argv[0], "exit") == 0){
           return(EXIT_SUCCESS);
       }else if(strcmp(argv[0], "pwd") == 0){
           char c[MAX_PATH_LENGTH];
           getcwd(c, MAX_PATH_LENGTH);
           fprintf(stdout, " Current Directory: %s ", c);
           continue;
       }
       else if(strcmp(argv[0], "cd")== 0){
          
           char *dir, check;
           if(argc == 1){
               dir = getenv("Home");
           }else{
               dir = argv[1];
               check = chdir(dir);
               if(check != 0){
                   fprintf(stderr, "No Command Inputted!");
               }
      
       }
       }

}

return 0;

}}

int parseline(char *cmdline, char **argv)
{
    int count = 0;
    char *separator = " "; /* Includes space, Enter, Tab */

    /* strtok searches for the characters listed in separator */
    argv[count] = strtok(cmdline, separator);
    while ((argv[count] != NULL) && (count+1 < MAXARGS)) {
   argv[++count] = strtok((char *) 0, separator);
    }      
    return count;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote