cs240/hw/hw12/README
2018-10-15 17:20:57 -04:00

45 lines
2.3 KiB
Plaintext

===== MINIDB =====
= By Max O'Cull =
(Note: error checking will be skipped over in this README for sake of brevity.)
MAIN
MiniDB starts by loading the database into memory, reading and executing commands, then saving the
database back into a file.
LOADING
The database file is read line by line and tokenized into an array. The tokens are then fed into
an add function. The add function finds an empty spot in the single linked list database in
memory, then allocates and sets values for the new structure.
COMMANDS
Similar to loading, the commands file is read line by line and tokenized into an array. The first
token is checked for the command type, then the remaining tokens are cast and fed appropriately
into the add, lookup, display, edit, and remove functions.
The lookup function prints the command and operands to the output file. Then, it loops through the
elements in the single linked list database and, based upon the feature being compared, use a
POSIX standard fnmatch call to resolve case-insensitive pattern matching (includes wildcards).
Upon a succesful match, the database entry is printed.
The display function prints the command and operands to the output file. Then, it allocates an
array of counted ID's, initialized to 0. The database is looped through, ignoring items that have
already been counted. Depending upon the order and feature arguments, titles, dates, directors, and
ID's are compared appropriately. In the case of dates, the string is parsed into day, month, and
year integers, then a sum of days is computed for purpose of comparison. After each display
iteration, the "best" entry is added to the counted ID's array, and printed. The next uncounted
entry is found in the database, and the loop continues until enough entries are found to fulfill
the max argument or the size of the database.
The edit function compares the feature and appropriately casts the data, then sets values in the
entry whose ID corresponds to the ID argument. Memory is freed and duplicated (strings) where
necessary.
The remove function starts by iterating through the database linked list to find previous and
target nodes. Once found, the target node is deleted, and the previous node's next pointer is set to
the target's next.
SAVING
Each entry in the single linked list database is iterated over, then written to file in the
appropriate CSV format.