Reading Commands
Description
Unformatted Attachment Preview
Spring 2023
Math & CS Department
Reading Commands
In this assignment, you are to implement and test functions char
*wish_read_line(FILE *in) and int wish_read_config(char *fname). The
necessary constants are defined in the file wish.h (provided).
Function char *wish_read_line(FILE *in) shall read up to
WISH_MAX_INPUT characters from the previously opened file in. The
newline character, if any, shall be removed from the line. The
function shall allocate enough memory to store the input as a NULLterminated character string and return a pointer to the buffer. If
any I/O or memory operation fails, the function shall print an error
message with perror() and return NULL. If the input is longer than
WISH_MAX_INPUT, the function shall discard it (to the next newline,
including the newline itself), return NULL, and display the following
error message to stderr:
wish: line too long
If the line is blank (empty or consists only of white spaces, as
defined by isspace()), the function shall return NULL.
You are encouraged to use the library function getline() to implement
wish_read_line() but may choose to resort to fgets().
Function int wish_read_config(char *fname, int ok_if_missing) shall
read all lines from the file fname using the function wish_read_line.
The function is responsible for opening and closing the file and
reporting any errors associated with opening or closing the file
using perror(). However, if the file does not exist and the parameter
ok_if_missing is 1, the function shall do nothing (in particular, not
report an error). The function shall return 0 in case of success and
1 in case of failure.
Write function int main(int argc, char *argv[]) that shall read the
commands from the previously created file wish.conf (provided)
located in the $HOME directory1. The program then shall display the
prompt WISH_DEFAULT_PROMPT and read a command from stdin using
wish_read_line. The program shall then free all previously allocated
memory. The program shall successfully terminate by returning
EXIT_SUCCESS. If any of the involved functions fails, the program
shall return EXIT_FAILURE.
The main function shall be implemented in the file wish.c (provided).
The other two functions shall be implemented in the file wish_read.c
(provided). The files must include wish.h.
1
Function getenv() reads the value of a shell variable, such as $HOME.
Operating systems
Shell project
CMPSC-F355
Suffolk University
Spring 2023
Math & CS Department
The project must have a Makefile (provided) with all the necessary
dependencies. I will build your project (and you should, too) by
running make without any parameters. If I run make again without
modifying the submitted files, the project should not be rebuilt.
When I type make clean, the files that can be rebuilt (e.g., wish,
wish.o, and wish_read.o) shall be deleted. Those files should not be
placed under version control.
Operating systems
Shell project
CMPSC-F355
Purchase answer to see full
attachment
Have a similar assignment? "Place an order for your assignment and have exceptional work written by our team of experts, guaranteeing you A results."