Smart Shell, Part III

In this programming workshop, you will finalize the smartshell you created so far. You may work alone or with one other classmate, and each person is expected to contribute equally to the effort.

To confine your debugging efforts to the new code you write in this workshop, please start with the complete working version of the smartshell code provided by the instructor.

Project Specification

All work must be completed in your csc1600/smartshell directory.
  1. Make a copy of smartshell2.c and name it smartshell3.c

  2. Using good program design practices, implement the following shell commands:

  3. Before the smartshell ends, save the history of commands in a file named history.txt in your smartshell directory (use fopen and fclose). Before the smartshell starts processing user commands, read the history of commands from history.txt, so they are available to the current shell instance. This way the history of shell commands is preserved between different shell executions.

You have developed the skills needed to complete this task in implementing the SaveSearchPaths function. Here you will need to build a datastructure, say

char * history[MAX_HISTORY];
where you keep inserting shell commands as the user issues them at your shell prompt. Initialize this data structure with InitArray, and update it using the Insert function from the stringarray library. Then the history command reduces to simply calling PrintAll. The run command reduces to calling the mysystem function.

In implementing the last piece (item 3 above) of the shell, write two functions with the following prototypes:

void ReadHistory(char * filename);
/* Open (fopen) the file with the name passed as argument (this is the file containing the history of commands typed into the shell). 
   Read each line from the file (use fgets) and save it in the history array (use Insert). Close (fclose) the file. */

void SaveHistory(char * filename);
/* Open the file with the name passed as argument. Write each string from the history array into the file (use fprintf), 
   one per line. Close the file. */ 

Compile your code using the command

      gcc smartshell3.c mysystem.c stringarray.c -o smartshell3
The three source files will be linked into one executable file called smartshell3.

Submission Instructions

This work will be completed in class. There are no handins for this assignment.

Have fun!