#ifndef SARAPP_H #define SARAPP_H #include const size_t BUFFER_SIZE = 1024; class SarApp { private: /// True if search must ignore case bool caseSensitive; /// True if files must be overwritten after replace each search-text occurrence bool overwriteFiles; /// True if user wants to know each line in search results bool showLines; /// True if user asked only for help bool showHelp; /// Preservates the letter for a given unknown option char unknownParameter; /// The number of given filenames by user in parameters size_t fileCount; /// The text to search given by parameter. It is mandatory const char* searchText; /// The text to replace each occurence of searchText. NULL if user only wants to search const char* replacementText; /// Points to the replacement-text when it is not valid const char* badReplacementParameter; /// Name of the current file being processed const char* currentFilename; private: /// Analyzes each given parameter in main() and fills each data member of this object void processParams(int argc, char* argv[]); /// Analyzes if all parameters are a valid combination. Return 0 on success. On error /// prints a helpful message in stderr and returns an error value int validateParams(); /// Searches or replaces in the given filename bool sarFile(const char* filename); /// Searches or replaces in the given open source file and target file bool sarFile(FILE* source, FILE* target); /// Searches or replaces in the given line from source file bool sarLine(const char* const line, FILE* target, size_t lineNumber); /// Returns true if two characters are equal considering the case chosen by user bool equals(char ch1, char ch2) const; /// This line has the search text, print it in stdout bool printOccurrence(const char* const line, FILE* target, size_t lineNumber); public: /// Constructor SarApp(); /// Executes the search and replace and returns an error code int run(int argc, char* argv[]); /// Prints usage help in standard output static int printHelp(); }; #endif // SARAPP_H