Question: Need help modifying the program for a simple implementation of a shell to work with a queue for the environment values instead of an array

Need help modifying the program for a simple implementation of a shell to work with a queue for the environment values instead of an array as it is currently. Coding in C for Linux.

1. Need to modify the node struct to accept environ table value.

2. Need to add a function to queue.c to allow for searching and replacing of named values that is currently done in varlib.c. Also the function needs to be moved from varlib.c to queue.c and implemented to work there.

varlib.h

#include #include #include #include #include

int VLenviron2table(char **); int VLexport(char *); char *VLlookup(char *); void VLlist(); int VLstore(char *, char *); char **VLtable2environ(); int VLenviron2table(char **);

varlib.c

#include #include #include "varlib.h" #include

#define MAXVARS 200

struct var { char *str; int global; };

static struct var tab[MAXVARS];

static char *new_string(char *, char *); static struct var *find_item(char *, int);

int VLstore(char *name, char *val) {

struct var *itemp; char *s; int rv = 1;

if ((itemp=find_item(name, 1)) != NULL && (s=new_string(name, val)) != NULL) { if (itemp->str) free(itemp->str); itemp->str = s; rv = 0; } return rv; }

char * new_string(char *name, char *val) {

char *retval;

retval = malloc( strlen(name) + strlen(val) + 2); if (retval != NULL) sprintf(retval, "%s=%s", name, val); return retval; }

char * VLlookup(char * name) {

struct var *itemp;

if ((itemp = find_item(name, 0)) != NULL) return itemp->str + 1 + strlen(name); return "";

}

int VLexport(char *name) {

struct var *itemp; int rv = 1;

if ((itemp = find_item(name, 0)) != NULL) { itemp->global = 1; rv = 0; } else if (VLstore(name, "") == 1) rv = VLexport(name); return rv; }

static struct var *find_item(char *name, int first_blank) {

int i; int len = strlen(name); char *s;

for (i = 0; i

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!