#ifndef LEVDIST_H #define LEVDIST_H /** @file levdist.h This file contains the structures and functions that control the entire `levdist` command. It can be thought as the global controller object in object-oriented programming. It may be created in the main function, for example: ``` int main(int argc, char* argv[]) { levdist_t levdist; levdist_init(&levdist); return levdist_run(&levdist, argc, argv); } ``` */ #include "arguments.h" #include "dir.h" /** @brief For each file we know its name, size, and contents @todo: Move file_record_t to its own file and include it in dir.h **/ typedef struct { /// Path to the filename, relative to the levdist command call char* filename; /// Size in bytes of the file off_t size; /// Pointer to its contents in ASCII or Unicode void* contents; } file_record_t; /** @brief A comparison between two files that stores their Levenshtein distance */ typedef struct { /// The first file to compare file_record_t* file1; /// The second file to compare file_record_t* file2; /// Levenshtein distance between the two files size_t distance; } comparison_t; /** @brief Stores the atributes shared for the controller functions in this file. */ typedef struct levdist { /// What user asked by the command-line arguments. arguments_t arguments; /// Queue of files to be compared using Levenshtein distance. queue_t* files; /// Array of pairs of files to be compared comparison_t* comparisons; } levdist_t; /** @brief Initializes a record with default information required by the controller. @param this Pointer to the @a levdist_t structure to be initialized. */ void levdist_init(levdist_t* this); /** @brief Start the execution of the command @param this Pointer to the @a levdist_t structure with the shared attibutes. @param argc Argument count provided from the `main()` function. @param argv Argument vector provided from the `main()` function. @return The exit status, where 0 stands for success, otherwise for an error. */ int levdist_run(levdist_t* this, int argc, char* argv[]); /** @brief Finds all files in the directories given by arguments, and load them to the @a this->files queue. @param this Pointer to the @a levdist_t structure with the shared attibutes. @param argc Argument count provided from the `main()` function. @param argv Argument vector provided from the `main()` function. @return The exit status, where 0 stands for success, otherwise for an error. */ int levdist_process_dirs(levdist_t* this, int argc, char* argv[]); /** @brief Traverses all the directories provided by user in command-line arguments, and load all files to the @a this->files queue. @param this Pointer to the @a levdist_t structure with the shared attibutes. @param argc Argument count provided from the `main()` function. @param argv Argument vector provided from the `main()` function. @return The exit status, where 0 stands for success, otherwise for an error. */ int levdist_list_files_in_args(levdist_t* this, int argc, char* argv[]); /** @brief Returns true if the given filename is already in the files queue. @param this Pointer to the @a levdist_t structure with the shared attibutes. @param filename The filename to be searched. @return true if the given filename is already in the files queue. */ bool levdist_is_in_queue(levdist_t* this, const char* filename); /** @brief Loads the contents of the given file and add them to the files queue. @param this Pointer to the @a levdist_t structure with the shared attibutes. @param filename The relative path and name of the file to be loaded. @param load_contents If true, file's contents will be loaded to heap memory. @return The exit status, where 0 stands for success, otherwise for an error. */ int levdist_load_file(levdist_t* this, const char* filename, bool load_contents); /** @brief Releases the heap memory used @param this Pointer to the @a levdist_t structure with the shared attibutes. */ void levdist_destroy(levdist_t* this); #endif // LEVDIST_H