Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help modify cmds . c code do not change that i provided thank you A . edit cmds . c to implement the required

need help modify cmds.c code do not change that i provided thank you
A. edit cmds.c to implement the required new commands (md, ms and h)
Use sscanf to convert the argument passed md or ms from a character string of hex digits
Cmds.c files
#include
#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 "},
{"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|
", arguments);
printf(" help message: %s
", cp->help);
return 0; /* not done */
}
Slex.c file this file did not need modify do not touch it.
#include
//#include
#include "slex.h"/* for definition of type cmd */
//#include slex.h
int slex(char *linebuf,/* string from user */
Cmd cmdtable[],/* cmd table to use */
int *cnum_ptr,/* returned command number */
int *pos_ptr)/* returned new place in linebuf */
{
int i =0;
char token[MAXTOKENLEN];
int newpos;
if (gettoken(linebuf,token,&newpos)<0)/* get token from linebuf */
return -1; /* couldn't find token */
while ((cmdtable[i].cmdtoken != NULL)){
if (strcmp(cmdtable[i].cmdtoken,token)==0){
*cnum_ptr = i; /* success--return command # */
*pos_ptr = newpos; /* and where we got to in linebuf */
return 0;
}
else
i++; /* keep scanning table */
}
return -1; /* no match */
}
/******************************************************************
* get one space-delimited token from string in linebuf, also return
* new position in string
*/
int gettoken(char *linebuf, char *token, int *pos_ptr)
{
int i =0;
int j =0;
while (linebuf[i]=='')
i++; /* skip blanks */
while (linebuf[i]!=''&&linebuf[i]!='\0')
token[j++]= linebuf[i++]; /* copy chars to token */
if (j==0)
return -1; /* nothing there */
else
{
token[j]='\0'; /* null-terminate token */
*pos_ptr = i; /* return place in linebuf we got to */
return 0; /* success */
}
}

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 Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago