CS330 Phase Zero

Simple File Manager (SFM)

 

For the project, you have freedom to organize your software as you wish.  However, some students may want some guidance about what to do first.  I recommend starting by reading the input file and validating the commands and printing to the output file.

 

First make sure you can read a line from the input file (initially in1-01.txt) and print a line to the output file (initially out1-01.txt).  Change it to a loop to read and write all lines.

 

Command Interpretation

 

Main loop:  Read a line of input.  As long as there is a line of input, print the line, validate the line, print any results of validation, and then read the next line.

 

To validate a line of input, first remove the comment, if any, from the end of the string.  In other words, search for the “#” symbol, and if you find one, extract the substring up to that character.

 

Then, make sure that the command is in the correct form.  Your program will be simpler if you do much checking on the input as possible immediately after reading it.  One approach is to first break the input string into a series of words.  Thus, the first task is: given an input string, convert it to an array of strings, with one “word” in each string.  Lab #2 should help you with this task.

 

The next task is to compare the array of strings with patterns that match the valid commands.

 

SOS commands begin with 2 non-negative integers, which are followed a string indicating the current command name, and then possibly some other parameters:

 

<non-neg-int> <non-neg-int> <command-string> <parameters>

 

Here are the commands for Phase 0:

 

m1 m2 FScreate d SFFS 1 0 n1 n2

m1 m2 FSmount d f

m1 m2 FSshowmounts

m1 m2 FSchange f

m1 m2 FSdump n1 n2

m1 m2 FSshow

m1 m2 FSdate n

 

In these commands, m1, m2, n1, and n2, are all <non-neg-int>, and d is a <diskname> (same syntax for <file system name>) and f is a <filename> (same syntax for <file system name>). 

 

You can validate commands with a special function for each type of command.  An easier way may be to construct a 2D array of strings that shows the patterns for all valid commands.

 

{

{“nnint”, “nnint”, “FScreate”, “filename”, “SFFS”, “nnint”, “nnint”, “nnint”, “nnint”},

{“nnint”, “nnint”, “FSmount”, “filename”, “filename”, “nil”, “nil”, “nil”, “nil”},

    

}

 

Given an array of strings representing the command, try to match to the first row of the 2d array (the pattern).  A string such as “14” matches the pattern “nnint” if the string “14” can be converted to a non-negative integer.  The function atoi converts strings to integers.  So try converting the string and see what value is yielded.  You may want to write a little Boolean function called isNonNegativeInteger(). Likewise, a string such as “fs1” matches the pattern “filename” if it follows the rules for a filename (at most 15 characters long, starts with a letter, and contains only letters or digits and at most one period).  A function called isFileName() can be written.

 

Report the message “Invalid instruction” if the number of parameters is wrong or the third word (array position 2) doesn’t match a known SOS command.  For other errors involving the parameters, report “Invalid parameter”.