lease Modify this code according to this instructions cmds.c – Need to modify the Cmd struct to include: “ms” and “h” – Add code in mem_display
plese modify the code according to the instruction in c
Please Modify this code according to this instructions
cmds.c
– Need to modify the Cmd struct to include:
“ms” and “h”
– Add code in mem_display(), help(), mem_set() functions
– Command routine calls with 2 arguments, e.g.
- mem_display(Cmd *cp, char *arguments)
&cmds[0]
Address of the string “10000”
– If we enter a command “md 10000” to display the contents of 16 locations starting with 10000, the arguments passed are:
file: cmds.c
/* the Makefile arranges that #include <..> searches in the right
places for these headers-- 200920*/
#include <stdio.h>
#include "slex.h"
/*===================================================================*
*
* Command table for tutor program -- an array of structures of type
* cmd -- for each command provide the token, the function to call when
* that token is found, and the help message.
*
* slex.h contains the typdef for struct cmd, and declares the
* cmds array as extern to all the other parts of the program.
* Code in slex.c parses user input command line and calls the
* requested semantic action, passing a pointer to the cmd struct
* and any arguments the user may have entered.
*
*===================================================================*/
PROTOTYPE int stop(Cmd *cp, char *arguments);
PROTOTYPE int mem_display(Cmd *cp, char *arguments);
/* command table */
Cmd cmds[] = {{"md", mem_display, "Memory display: MD <addr>"},
{"s", stop, "Stop" },
{NULL, NULL, NULL}}; /* null cmd to flag end of table */
char xyz = 6; /* test global variable */
char *pxyz = &xyz; /* test pointer to xyz */
/*===================================================================*
* command routines
*
* Each command routine is called with 2 args, the remaining
* part of the line to parse and a pointer to the struct cmd for this
* command. Each returns 0 for continue or 1 for all-done.
*
*===================================================================*/
int stop(Cmd *cp, char *arguments)
{
return 1; /* all done flag */
}
/*===================================================================*
*
* mem_display: display contents of 16 bytes in hex
*
*/
int mem_display(Cmd *cp, char *arguments)
{
printf("Reached mem_display, passed argument string: |%s|\n", arguments);
printf(" help message: %s\n", cp->help);
return 0; /* not done */
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps