Question: Project: Node Manager - C Program Shell Implementation Overview: - Create a C program that acts as a basic shell named Node Manager. - Reinforces

Project: Node Manager - C Program Shell Implementation
Overview:
- Create a C program that acts as a basic shell named Node Manager.
- Reinforces linked lists, string handling, bitwise operations, and managing multiple source files.
Files and Directory Structure:
-`p3_handout` Directory contains:
-`src/nodemngr.c`: The source file you need to modify.
-`inc/listnode.h`: Contains the ListNode structure.
-`inc/exec.h`: Contains function prototypes.
-`obj/exec.o`: Object file for linking during compilation.
-`inputs/` and `outputs/`: Test case directories used with the testing script.
-`Makefile`: Used for compiling the project.
-`driver.py`: Python script to test the shell.
- Text files (`joestar.txt`,`kakyoin.txt`,`avdol.txt`): Provided for testing with List Nodes.
Shell Requirements:
-**Command Prompt and Input Loop**:
- Shell prompt: `262$`.
- Print prompt using `fflush(stdout);`.
- Continuously loop until EOF is detected.
-**Command Parsing and Execution**:
- Parse input commands using whitespace as the delimiter.
- Commands can have multiple arguments, with input size limited to **10,000 characters**.
Built-in Commands:
1.**`quit`**: Exits the shell, deallocates resources, no arguments.
2.**`cd [dir]`**: Changes current directory using `chdir`. Prints errors for invalid directory or incorrect arguments.
3.**`history`**: Displays/manages history of the last **100 commands**.
-**`history -c`**: Clears command history.
-**`history [index]`**: Re-executes a command from history by index.
4.**`new CMD [args]`**: Creates a new List Node with a command and arguments.
- A List Node includes: command, arguments, and other details.
5.**`list`**: Displays information about all current List Nodes.
6.**`open [id][filename]`**: Opens a file and assigns its contents to the List Node by ID.
- Handles errors for invalid IDs, missing files, and incorrect arguments.
7.**`execute [id]`**: Executes the command stored in a List Node by calling `run_command()`.
- Extracts exit status and reports errors if unsuccessful.
- Commands are limited to **127 arguments**.
Key Implementation Requirements:
-**No Global Variables**: Only local variables are allowed.
-**Memory Management**: Proper deallocation of resources (must pass Valgrind with no memory leaks).
-**Command History**: Manages up to **100 commands**, replacing the oldest entry when full.
ListNode Structure (from `listnode.h`):
```c
typedef struct ListNode {
char *command; // Command associated with the node
char **arguments; // Array of argument strings (command is arguments[0])
struct ListNode *next; // Pointer to the next List Node
int id; // ID of the List Node (starts from 0)
int arguments_length; // Number of arguments excluding ending NULL pointer
char *file_contents; // Contents of any file opened for this node
} ListNode;
```
Testing and Submission Instructions:
1.**Testing**:
- Use the provided `Makefile` to compile the project.
- Run **`driver.py`** to test with provided test cases.
- Example output from **`driver.py`** awards scores based on functionality and memory safety.
Driver Script (`driver.py`) Scoring:
- Scores range from **0 to 2**:
-**0**: Compilation failure or incorrect output with memory leaks.
-**1**: Correct output but with memory leaks.
-**2**: Correct output and no memory leaks.

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 Programming Questions!