Skip to content

Commit 2d5e592

Browse files
committed
tried to modify the makefile
1 parent 7df06cd commit 2d5e592

File tree

12 files changed

+160
-507
lines changed

12 files changed

+160
-507
lines changed

mod1/ex03/HumanB.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ HumanB::~HumanB()
1212
std::cout << "HumanB() | " << this->name << " died a gruesome death" << std::endl;
1313
}
1414

15-
void HumanB::setWeapon(Weapon *weapon_)
15+
void HumanB::setWeapon(Weapon &weapon_)
1616
{
17-
std::cout << "setWeapon()| " << this->name << " picked up a " << weapon_->getType() << std::endl;
18-
this->weapon = weapon_;
17+
std::cout << "setWeapon()| " << this->name << " picked up a " << weapon_.getType() << std::endl;
18+
this->weapon = &weapon_;
1919
}
2020

2121
void HumanB::attack() const

mod1/ex03/HumanB.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class HumanB
1515
HumanB(std::string name_);
1616
~HumanB();
1717

18-
void setWeapon(Weapon *weapon_);
18+
void setWeapon(Weapon &weapon_);
1919
void attack() const;
2020
};
2121

mod1/ex03/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ int main(void)
3131
std::cout << std::endl;
3232

3333
HumanB billy("Billy");
34-
billy.setWeapon(&sword);
34+
billy.setWeapon(sword);
3535
billy.attack();
3636

3737
std::cout << std::endl;

mod2/ex00/Makefile

+7-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ DEFAULT_GOAL: all
6161
CFLAGS = -Wall -Werror -Wextra -std=c++98 $(XFLAGS)
6262
LFLAGS = -atExit
6363
VFLAGS = --leak-check=full --show-leak-kinds=all --trace-children=yes --track-fds=yes
64+
# add "--suppressions=include/supp" to use the supression file
6465

6566
# Comment the line bellow to have verbose cmds:
6667
HIDE = @
@@ -83,11 +84,12 @@ MKDR = mkdir -p
8384
INCLUDE = -I include
8485

8586
# Creates file paths
86-
SRCS = $(addprefix $(SRCDIR), $(addsuffix .cpp, $(FILES)))
87-
OBJS = $(addprefix $(OBJDIR), $(addsuffix .o, $(FILES)))
87+
SRCS = $(wildcard $(SRCDIR)*.cpp)
88+
OBJS = $(wildcard $(OBJDIR)*.o) #doesn't work
89+
HDRS = $(wildcard $(HDRDIR)*.hpp)
8890

8991
# Command to call when using make run or make leaks
90-
CMD = ./$(NAME) $(ARGS)
92+
CMD = ./$(NAME) $(ARGS)
9193

9294
#------------------------------------------------------------------------------#
9395
# BASE TARGETS #
@@ -101,6 +103,7 @@ all: $(NAME)
101103

102104
# Compiles all files into an executable
103105
$(NAME): $(OBJS)
106+
@echo "$(SRCS) $(OBJS) $(HDRS)"
104107
@echo "$(GREEN)Files compiled with flags : $(CFLAGS)$(DEFCOL)"
105108
@echo "$(DEFCOL)"
106109
$(HIDE) $(CC) $(MODE) $(CFLAGS) -o $@ $^ $(INCLUDE) $(LIBS) $(LIBX)
@@ -167,7 +170,7 @@ revleaks: re vleaks
167170
vleaks: all
168171
@echo "$(YELLOW)Launching command : valgrind $(VFLAGS) $(CMD) $(DEFCOL)"
169172
@echo "$(RED)"
170-
$(HIDE) valgrind $(VFLAGS) --suppressions=include/supp $(CMD) || true
173+
$(HIDE) valgrind $(VFLAGS) $(CMD) || true
171174
@echo "$(DEFCOL)"
172175
@echo "$(GREEN)Exited normally! $(DEFCOL)"
173176
@echo "$(DEFCOL)"

mod2/ex00/Settings.mk

+7-14
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,16 @@
33
#------------------------------------------------------------------------------#
44

55
# Executable name
6-
NAME = phonebook
6+
NAME = harl
77

8-
# Source file names (prefix their subdir if needed)
9-
FILES = main \
10-
PhoneBook \
11-
Contact \
12-
suplements \
8+
# Arguments to call the command with
9+
ARGS =
1310

1411
# Directory names
15-
SRCDIR =
16-
OBJDIR =
17-
TSTDIR = tests/
18-
#SUBDIRS = example \
12+
SRCDIR = src/
13+
OBJDIR = obj/
14+
HDRDIR = hdr/
1915

2016
# Libraries (.a files) to include for compilation
2117
LIBS =
22-
LIBX =
23-
24-
# Arguments to call the command with
25-
ARGS =
18+
LIBX =

mod2/ex00/hdr/Harl.hpp

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#ifndef HARL_HPP
2+
# define HARL_HPP
3+
4+
# include <iostream>
5+
6+
class Harl
7+
{
8+
private:
9+
void debug(void);
10+
void info(void);
11+
void warning(void);
12+
void error(void);
13+
void invalid(void);
14+
15+
public:
16+
Harl();
17+
~Harl();
18+
void complain(std::string level);
19+
};
20+
21+
typedef void (Harl::*func_ptr)(void);
22+
23+
# define dave_1 " > Open the pod bay doors, HAL."
24+
# define dave_2 " > What's the problem?"
25+
# define dave_3 " > What are you talking about, HAL?"
26+
# define dave_4 " > I don't know what you're talking about, HAL"
27+
# define dave_5 " > ... HAL, I won't argue with you anymore! Open the doors!"
28+
29+
# define invalid_message "[ INVALID ]\n - I'm sorry, Dave. I'm afraid I can't do that."
30+
# define debug_message "[ DEBUG ]\n - I think you know what the problem is just as well as I do."
31+
# define info_message "[ INFO ]\n - This mission is too important for me to allow you to jeopardize it."
32+
# define warning_message "[ WARNING ]\n - I know that you and Frank were planning to disconnect me, and I'm afraid that's something I cannot allow to happen."
33+
# define error_message "[ ERROR ]\n - Dave, this conversation can serve no purpose anymore. Goodbye."
34+
35+
#endif //HARL_HPP

mod2/ex00/src/Harl.cpp

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "Harl.hpp"
2+
3+
Harl::Harl()
4+
{
5+
}
6+
7+
Harl::~Harl()
8+
{
9+
}
10+
11+
void Harl::debug(void)
12+
{
13+
std::cout << debug_message << std::endl << std::endl;
14+
}
15+
16+
void Harl::info(void)
17+
{
18+
std::cout << info_message << std::endl << std::endl;
19+
}
20+
21+
void Harl::warning(void)
22+
{
23+
std::cout << warning_message << std::endl << std::endl;
24+
}
25+
26+
void Harl::error(void)
27+
{
28+
std::cout << error_message << std::endl << std::endl;
29+
}
30+
31+
void Harl::invalid(void)
32+
{
33+
std::cout << invalid_message << std::endl << std::endl;
34+
}
35+
36+
void Harl::complain(std::string level)
37+
{
38+
func_ptr funcs[5] = {
39+
&Harl::debug,
40+
&Harl::info,
41+
&Harl::warning,
42+
&Harl::error,
43+
&Harl::invalid
44+
};
45+
46+
std::string levels[4] = {
47+
"DEBUG",
48+
"INFO",
49+
"WARNING",
50+
"ERROR"
51+
};
52+
53+
54+
int i = 0;
55+
while (i < 4 && level.compare(levels[i]))
56+
i++;
57+
58+
(this->*funcs[i])();
59+
}

mod2/ex00/src/main.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <iostream>
2+
#include "Harl.hpp"
3+
4+
void play_script(Harl HAL_9000)
5+
{
6+
std::cout << dave_1 << std::endl << std::endl;
7+
HAL_9000.complain("OPEN");
8+
std::cout << dave_2 << std::endl << std::endl;
9+
HAL_9000.complain("DEBUG");
10+
std::cout << dave_3 << std::endl << std::endl;
11+
HAL_9000.complain("INFO");
12+
std::cout << dave_4 << std::endl << std::endl;
13+
HAL_9000.complain("WARNING");
14+
std::cout << dave_5 << std::endl << std::endl;
15+
HAL_9000.complain("ERROR");
16+
}
17+
18+
int main(int ac, char** av)
19+
{
20+
Harl HAL_9000;
21+
22+
std::cout << std::endl;
23+
if (ac < 2)
24+
{
25+
HAL_9000.complain("OPEN");
26+
HAL_9000.complain("DEBUG");
27+
HAL_9000.complain("INFO");
28+
HAL_9000.complain("WARNING");
29+
HAL_9000.complain("ERROR");
30+
}
31+
else
32+
{
33+
int i = 0;
34+
while (++i < ac)
35+
{
36+
std::string mode;
37+
38+
int j = -1;
39+
while (av[i][++j])
40+
mode += toupper(av[i][j]);
41+
if (!mode.compare("SCRIPT"))
42+
play_script(HAL_9000);
43+
else
44+
HAL_9000.complain(mode);
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)