Compare commits
12 Commits
c8a34cbc70
...
main
Author | SHA1 | Date | |
---|---|---|---|
a79d65eb28 | |||
cc691120db | |||
daf3aa6c7d | |||
fdd15639f0 | |||
e292dcc32e | |||
c2089dac6d | |||
dcda44e695 | |||
7903a6e7a0 | |||
45f1bceaf7 | |||
197744804d | |||
914eb94ff6 | |||
c902d132c3 |
6
.gitignore
vendored
6
.gitignore
vendored
@ -3,3 +3,9 @@ compile_commands.json
|
|||||||
.cache
|
.cache
|
||||||
.direnv
|
.direnv
|
||||||
flake.lock
|
flake.lock
|
||||||
|
zombie
|
||||||
|
zombieHorde
|
||||||
|
thisisabrain
|
||||||
|
violence
|
||||||
|
sed
|
||||||
|
harl
|
||||||
|
@ -6,16 +6,18 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/11/04 10:52:33 by adjoly #+# #+# */
|
/* Created: 2024/11/04 10:52:33 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/11/04 14:49:24 by adjoly ### ########.fr */
|
/* Updated: 2024/11/04 19:21:59 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class Zombie {
|
class Zombie {
|
||||||
private:
|
private:
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void announce(void);
|
void announce(void);
|
||||||
|
|
||||||
|
@ -6,11 +6,11 @@
|
|||||||
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||||
# Updated: 2024/11/04 18:53:24 by adjoly ### ########.fr #
|
# Updated: 2024/11/04 19:09:31 by adjoly ### ########.fr #
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
NAME = zombie
|
NAME = zombieHorde
|
||||||
|
|
||||||
CC = c++
|
CC = c++
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2024/11/04 10:52:33 by adjoly #+# #+# */
|
/* Created: 2024/11/04 10:52:33 by adjoly #+# #+# */
|
||||||
/* Updated: 2024/11/04 18:54:32 by adjoly ### ########.fr */
|
/* Updated: 2024/11/04 19:22:07 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -19,6 +19,7 @@
|
|||||||
class Zombie {
|
class Zombie {
|
||||||
private:
|
private:
|
||||||
std::string name;
|
std::string name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void announce(void);
|
void announce(void);
|
||||||
void setName(std::string newName);
|
void setName(std::string newName);
|
||||||
|
54
ex02/Makefile
Normal file
54
ex02/Makefile
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||||
|
# Updated: 2024/11/04 19:17:46 by adjoly ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
NAME = thisisabrain
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
|
||||||
|
SRCS = main.cpp
|
||||||
|
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
|
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
|
||||||
|
|
||||||
|
RED = \033[0;31m
|
||||||
|
GREEN = \033[0;32m
|
||||||
|
YELLOW = \033[1;33m
|
||||||
|
PURPLE = \e[0;35m
|
||||||
|
NC = \033[0m
|
||||||
|
DELETE = \x1B[2K\r
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
|
||||||
|
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.cpp
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) $(FLAGS) -c $< -o $@
|
||||||
|
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJS)
|
||||||
|
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@rm -Rf $(OBJSDIR)
|
||||||
|
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: clean fclean all re
|
30
ex02/main.cpp
Normal file
30
ex02/main.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/04 19:01:36 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/04 19:15:33 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
std::string str = "HI THIS IS BRAIN";
|
||||||
|
std::string *stringPTR = &str;
|
||||||
|
std::string &stringREF = str;
|
||||||
|
|
||||||
|
std::cout << "The address of the string : " << &str << std::endl;
|
||||||
|
std::cout << "The address of the string pointer : " << stringPTR << std::endl;
|
||||||
|
std::cout << "The address of the string reference : " << &stringREF << std::endl;
|
||||||
|
|
||||||
|
std::cout << std::endl;
|
||||||
|
|
||||||
|
std::cout << "The value of the string : " << str << std::endl;
|
||||||
|
std::cout << "The value pointed to by stringPTR : " << *stringPTR << std::endl;
|
||||||
|
std::cout << "The value pointed to by stringREF : " << stringREF << std::endl;
|
||||||
|
}
|
21
ex03/HumanA.cpp
Normal file
21
ex03/HumanA.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* HumanA.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/04 19:41:23 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/09 18:47:57 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "HumanA.hpp"
|
||||||
|
#include "Weapon.hpp"
|
||||||
|
|
||||||
|
void HumanA::attack(void) {
|
||||||
|
std::cout << this->_name << " attacks with their " << this->_weapon.getType() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
HumanA::HumanA(std::string name, Weapon &weapon) : _name(name), _weapon(weapon) { }
|
27
ex03/HumanA.hpp
Normal file
27
ex03/HumanA.hpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* HumanA.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/04 19:36:00 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/05 17:51:09 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Weapon.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class HumanA {
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
Weapon &_weapon;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void attack(void);
|
||||||
|
|
||||||
|
HumanA(std::string name, Weapon &weapon);
|
||||||
|
};
|
24
ex03/HumanB.cpp
Normal file
24
ex03/HumanB.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* HumanB.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/04 19:43:18 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/09 18:48:06 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "HumanB.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void HumanB::attack(void) {
|
||||||
|
std::cout << this->_name << " attacks with their " << this->_weapon->getType() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HumanB::setWeapon(Weapon &newWeapon) {
|
||||||
|
this->_weapon = &newWeapon;
|
||||||
|
}
|
||||||
|
|
||||||
|
HumanB::HumanB(std::string name) : _name(name), _weapon(NULL) { }
|
28
ex03/HumanB.hpp
Normal file
28
ex03/HumanB.hpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* HumanB.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/04 19:39:47 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/05 17:53:56 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Weapon.hpp"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class HumanB {
|
||||||
|
private:
|
||||||
|
std::string _name;
|
||||||
|
Weapon *_weapon;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void attack(void);
|
||||||
|
void setWeapon(Weapon &newWeapon);
|
||||||
|
|
||||||
|
HumanB(std::string name);
|
||||||
|
};
|
57
ex03/Makefile
Normal file
57
ex03/Makefile
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||||
|
# Updated: 2024/11/05 17:11:17 by adjoly ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
NAME = violence
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
|
||||||
|
SRCS = main.cpp \
|
||||||
|
HumanA.cpp \
|
||||||
|
HumanB.cpp \
|
||||||
|
Weapon.cpp
|
||||||
|
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
|
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
|
||||||
|
|
||||||
|
RED = \033[0;31m
|
||||||
|
GREEN = \033[0;32m
|
||||||
|
YELLOW = \033[1;33m
|
||||||
|
PURPLE = \e[0;35m
|
||||||
|
NC = \033[0m
|
||||||
|
DELETE = \x1B[2K\r
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
|
||||||
|
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.cpp
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) $(FLAGS) -c $< -o $@
|
||||||
|
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJS)
|
||||||
|
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@rm -Rf $(OBJSDIR)
|
||||||
|
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: clean fclean all re
|
23
ex03/Weapon.cpp
Normal file
23
ex03/Weapon.cpp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Weapon.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/04 19:23:35 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/09 18:46:35 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "Weapon.hpp"
|
||||||
|
|
||||||
|
void Weapon::setType(std::string newType) {
|
||||||
|
this->_type = newType;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string &Weapon::getType(void) {
|
||||||
|
return (this->_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
Weapon::Weapon(std::string type) : _type(type) { }
|
26
ex03/Weapon.hpp
Normal file
26
ex03/Weapon.hpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* Weapon.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/04 19:21:24 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/09 18:46:33 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Weapon {
|
||||||
|
private:
|
||||||
|
std::string _type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
const std::string &getType(void);
|
||||||
|
void setType(std::string newType);
|
||||||
|
|
||||||
|
Weapon(std::string type);
|
||||||
|
};
|
35
ex03/main.cpp
Normal file
35
ex03/main.cpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/04 19:20:57 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/05 17:43:17 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "HumanA.hpp"
|
||||||
|
#include "HumanB.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
Weapon club = Weapon("crude spiked club");
|
||||||
|
HumanA bob("Bob", club);
|
||||||
|
bob.attack();
|
||||||
|
club.setType("some other type of club");
|
||||||
|
bob.attack();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
Weapon club = Weapon("crude spiked club");
|
||||||
|
HumanB jim("Jim");
|
||||||
|
jim.setWeapon(club);
|
||||||
|
jim.attack();
|
||||||
|
club.setType("some other type of club");
|
||||||
|
jim.attack();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
55
ex04/Makefile
Normal file
55
ex04/Makefile
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||||
|
# Updated: 2024/11/07 18:45:24 by adjoly ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
NAME = sed
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
|
||||||
|
SRCS = main.cpp \
|
||||||
|
sed.cpp
|
||||||
|
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
|
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
|
||||||
|
|
||||||
|
RED = \033[0;31m
|
||||||
|
GREEN = \033[0;32m
|
||||||
|
YELLOW = \033[1;33m
|
||||||
|
PURPLE = \e[0;35m
|
||||||
|
NC = \033[0m
|
||||||
|
DELETE = \x1B[2K\r
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
|
||||||
|
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.cpp
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) $(FLAGS) -c $< -o $@
|
||||||
|
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJS)
|
||||||
|
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@rm -Rf $(OBJSDIR)
|
||||||
|
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: clean fclean all re
|
27
ex04/main.cpp
Normal file
27
ex04/main.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/05 18:11:15 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/07 18:46:40 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "sed.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
int main(int ac, char **av) {
|
||||||
|
if (!(ac > 2 && ac <= 4))
|
||||||
|
return (std::cerr << "Invalid number of args please only give ./sed <infile> <s1> <s2>" << std::endl, 1);
|
||||||
|
|
||||||
|
std::string infile = av[1];
|
||||||
|
std::string s1 = av[2];
|
||||||
|
std::string s2 = av[3];
|
||||||
|
Sed sed(infile, s1, s2);
|
||||||
|
|
||||||
|
return (0);
|
||||||
|
}
|
50
ex04/sed.cpp
Normal file
50
ex04/sed.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* sed.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/07 16:45:25 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/09 18:49:49 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include "sed.h"
|
||||||
|
|
||||||
|
Sed::Sed(std::string &inFile, std::string &s1, std::string &s2):
|
||||||
|
_outFileName(inFile + ".replace") {
|
||||||
|
std::ifstream infile(inFile.c_str());
|
||||||
|
size_t pos = 0;
|
||||||
|
std::stringstream buf;
|
||||||
|
|
||||||
|
if (!infile) {
|
||||||
|
std::cerr << "Could not open infile" << std::endl;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
buf << infile.rdbuf();
|
||||||
|
_content = buf.str();
|
||||||
|
infile.close();
|
||||||
|
pos = _content.find(s1, pos);
|
||||||
|
while (pos < _content.length())
|
||||||
|
{
|
||||||
|
_content.erase(pos, s1.length());
|
||||||
|
_content.insert(pos, s2);
|
||||||
|
pos = _content.find(s1, pos + s2.length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Sed::~Sed(void) {
|
||||||
|
std::ofstream outfile(this->_outFileName.c_str());
|
||||||
|
|
||||||
|
if (!outfile) {
|
||||||
|
std::cout << "Cannot write to outfile" << std::endl;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
outfile << _content;
|
||||||
|
outfile.close();
|
||||||
|
}
|
27
ex04/sed.h
Normal file
27
ex04/sed.h
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* sed.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/07 16:10:36 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/07 18:36:27 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
# define fileExtension ".replace"
|
||||||
|
|
||||||
|
# include <string>
|
||||||
|
|
||||||
|
class Sed {
|
||||||
|
private:
|
||||||
|
std::string _outFileName;
|
||||||
|
std::string _content;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Sed(std::string &inFile, std::string &s1, std::string &s2);
|
||||||
|
~Sed(void);
|
||||||
|
};
|
55
ex05/Makefile
Normal file
55
ex05/Makefile
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# **************************************************************************** #
|
||||||
|
# #
|
||||||
|
# ::: :::::::: #
|
||||||
|
# Makefile :+: :+: :+: #
|
||||||
|
# +:+ +:+ +:+ #
|
||||||
|
# By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ #
|
||||||
|
# +#+#+#+#+#+ +#+ #
|
||||||
|
# Created: 2024/10/25 16:09:27 by adjoly #+# #+# #
|
||||||
|
# Updated: 2024/11/09 16:15:35 by adjoly ### ########.fr #
|
||||||
|
# #
|
||||||
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
NAME = harl
|
||||||
|
|
||||||
|
CC = c++
|
||||||
|
|
||||||
|
OBJSDIR = obj/
|
||||||
|
|
||||||
|
SRCS = main.cpp \
|
||||||
|
harl.cpp
|
||||||
|
|
||||||
|
OBJS = $(addprefix $(OBJSDIR), $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
|
FLAGS = -Wall -Werror -Wextra -std=c++98 -MMD -MP
|
||||||
|
|
||||||
|
RED = \033[0;31m
|
||||||
|
GREEN = \033[0;32m
|
||||||
|
YELLOW = \033[1;33m
|
||||||
|
PURPLE = \e[0;35m
|
||||||
|
NC = \033[0m
|
||||||
|
DELETE = \x1B[2K\r
|
||||||
|
|
||||||
|
all: $(NAME)
|
||||||
|
|
||||||
|
$(NAME): $(OBJS)
|
||||||
|
@$(CC) $(FLAGS) $(OBJS) -o $(NAME)
|
||||||
|
@printf "$(YELLOW)「✨」($(NAME)) Program compiled\n"
|
||||||
|
|
||||||
|
$(OBJSDIR)%.o: %.cpp
|
||||||
|
@mkdir -p $(@D)
|
||||||
|
@$(CC) $(FLAGS) -c $< -o $@
|
||||||
|
@printf "$(DELETE)$(GREEN)「🔨」($<) Object compiled\n"
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@rm -f $(OBJS)
|
||||||
|
@printf "$(DELETE)$(RED)「🗑️」($(OBJS)) Object deleted\n"
|
||||||
|
|
||||||
|
fclean: clean
|
||||||
|
@rm -f $(NAME)
|
||||||
|
@rm -Rf $(OBJSDIR)
|
||||||
|
@printf "$(RED)「🗑️」($(NAME)) Program deleted\n"
|
||||||
|
|
||||||
|
re: fclean all
|
||||||
|
|
||||||
|
.PHONY: clean fclean all re
|
42
ex05/harl.cpp
Normal file
42
ex05/harl.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* harl.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/09 17:15:01 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/09 19:16:07 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "harl.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
void Harl::complain(std::string level) {
|
||||||
|
std::string complainLevel[4] = {"DEBUG", "INFO", "WARNING", "ERROR"};
|
||||||
|
void (Harl::*func[4])(void) = {&Harl::debug, &Harl::info, &Harl::warning, &Harl::error};
|
||||||
|
uint8_t i = 0;
|
||||||
|
|
||||||
|
while (i < 4 && level != complainLevel[i])
|
||||||
|
i++;
|
||||||
|
if (i < 4)
|
||||||
|
(this->*func[i])();
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Harl::debug(void) {
|
||||||
|
std::cout << "[DEBUG]: NixOS is the only true answer" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Harl::info(void) {
|
||||||
|
std::cout << "[INFO]: NixOS is on 24.05" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Harl::warning(void) {
|
||||||
|
std::cout << "[WARNING]: Please no Ubuntu here" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Harl::error(void) {
|
||||||
|
std::cout << "[ERROR]: Arch issue switch to NixOS please for god sake" << std::endl;
|
||||||
|
}
|
28
ex05/harl.hpp
Normal file
28
ex05/harl.hpp
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* harl.hpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/09 16:13:40 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/09 17:35:57 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define uint8_t unsigned char
|
||||||
|
|
||||||
|
class Harl {
|
||||||
|
private:
|
||||||
|
void debug(void);
|
||||||
|
void info(void);
|
||||||
|
void warning(void);
|
||||||
|
void error(void);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void complain(std::string level);
|
||||||
|
};
|
22
ex05/main.cpp
Normal file
22
ex05/main.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/11/09 16:12:06 by adjoly #+# #+# */
|
||||||
|
/* Updated: 2024/11/09 17:43:48 by adjoly ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "harl.hpp"
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
Harl harl;
|
||||||
|
|
||||||
|
harl.complain("INFO");
|
||||||
|
harl.complain("DEBUG");
|
||||||
|
harl.complain("WARNING");
|
||||||
|
harl.complain("ERROR");
|
||||||
|
}
|
Reference in New Issue
Block a user