diff --git a/d01/ex04/Makefile b/d01/ex04/Makefile index 81dd985..495c03c 100644 --- a/d01/ex04/Makefile +++ b/d01/ex04/Makefile @@ -16,10 +16,11 @@ LIBS = INCLUDES = -I$(D_HEADERS) D_SRCS = . -SRCS = main.cpp +SRCS = main.cpp \ + Sed.cpp D_HEADERS = . -HEADERS = +HEADERS = Sed.hpp D_OBJS = builds OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o) diff --git a/d01/ex04/Sed.cpp b/d01/ex04/Sed.cpp new file mode 100644 index 0000000..748c9ca --- /dev/null +++ b/d01/ex04/Sed.cpp @@ -0,0 +1,32 @@ +#include "Sed.hpp" + +Sed::Sed(char *file, char *find, char *replacement) + : _file( file ) +// , _new_file( file.append(".replace") ) + , _find( find ) + , _replacement( replacement ) +{ + +// this->_buf = + return; + +} +Sed::~Sed() { + +// delete[] this->_buf; + return; + +} + +void Sed::replace() { + + std::ifstream file(this->_file.c_str()); + char c; + + while (file.get(c)) + { + std::cout << c; + } + +} + diff --git a/d01/ex04/Sed.hpp b/d01/ex04/Sed.hpp new file mode 100644 index 0000000..e197139 --- /dev/null +++ b/d01/ex04/Sed.hpp @@ -0,0 +1,27 @@ +#ifndef SED_HPP +# define SED_HPP + +#include +#include +#include + +class Sed { + +public: + + Sed(char *file, char *find, char *replacement); + ~Sed(); + + void replace( void ); + +private: + +// std::string _buf; + std::string const _file; + std::string const _new_file; + std::string const _find; + std::string const _replacement; + +}; + +#endif diff --git a/d01/ex04/main.cpp b/d01/ex04/main.cpp index e60f061..dbc34af 100644 --- a/d01/ex04/main.cpp +++ b/d01/ex04/main.cpp @@ -1,24 +1,28 @@ +#include "Sed.hpp" + #include #include -#include -int main() { +int sed_error(std::string msg) { - std::ifstream file("test.txt"); + std::cout << msg << std::endl; + return 1; +} - // read words separated by whitespaces or newlines -// std::string str; -// while (file >> str) -// std::cout << str << std::endl; +void cpp_sed(char **av) { - // skip whitespaces or newlines -// char c; -// while (file >> c) -// std::cout << c << std::endl; - - // seems good - char c; - while (file.get(c)) - std::cout << c; + Sed sed(av[1], av[2], av[3]); + + sed.replace(); + +} + +int main(int ac, char **av) { + + if (ac != 4) + return sed_error("you must provide 3 parameters : "); + cpp_sed(av); + + return 0; } diff --git a/d01/ex04/sed b/d01/ex04/sed index a254043..df9acd2 100755 Binary files a/d01/ex04/sed and b/d01/ex04/sed differ