Answered step by step
Verified Expert Solution
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 cmdsc code do not change that i provided thank you
A edit cmdsc 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
Cmdsc 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 stopCmd cp char arguments;
PROTOTYPE int memdisplayCmd cp char arguments;
command table
Cmd cmdsmd memdisplay, "Memory display: MD
s stop, "Stop"
NULL NULL, NULL; null cmd to flag end of table
char xyz ; test global variable
char pxyz &xyz; test pointer to xyz
command routines
Each command routine is called with args, the remaining
part of the line to parse and a pointer to the struct cmd for this
command. Each returns for continue or for alldone.
int stopCmd cp char arguments
return ; all done flag
memdisplay: display contents of bytes in hex
int memdisplayCmd cp char arguments
printfReached memdisplay, passed argument string: s
arguments;
printf help message: s
cphelp;
return ; 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 slexchar linebuf string from user
Cmd cmdtable cmd table to use
int cnumptr returned command number
int posptr returned new place in linebuf
int i ;
char tokenMAXTOKENLEN;
int newpos;
if gettokenlinebuftoken,&newpos get token from linebuf
return ; couldn't find token
while cmdtableicmdtoken NULL
if strcmpcmdtableicmdtoken,token
cnumptr i; successreturn command #
posptr newpos; and where we got to in linebuf
return ;
else
i; keep scanning table
return ; no match
get one spacedelimited token from string in linebuf, also return
new position in string
int gettokenchar linebuf char token int posptr
int i ;
int j ;
while linebufi
i; skip blanks
while linebufi&&linebufi
tokenj linebufi; copy chars to token
if j
return ; nothing there
else
tokenj; nullterminate token
posptr i; return place in linebuf we got to
return ; success
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started