aboutsummaryrefslogtreecommitdiff
path: root/cpp01
diff options
context:
space:
mode:
Diffstat (limited to 'cpp01')
-rw-r--r--cpp01/ex05/Human.cpp4
-rw-r--r--cpp01/ex05/Human.hpp4
-rw-r--r--cpp01/ex06/HumanA.cpp4
-rw-r--r--cpp01/ex06/HumanA.hpp8
-rw-r--r--cpp01/ex06/HumanB.cpp4
-rw-r--r--cpp01/ex06/HumanB.hpp8
-rw-r--r--cpp01/ex06/main.cpp2
-rw-r--r--cpp01/ex07/files/nowrite.orig (renamed from cpp01/ex07/test1)0
-rw-r--r--cpp01/ex07/files/test1.orig6
-rw-r--r--cpp01/ex07/files/test2.orig (renamed from cpp01/ex07/test2)0
-rw-r--r--cpp01/ex07/files/test3.orig6
-rw-r--r--cpp01/ex07/files/test4.orig6
-rw-r--r--cpp01/ex07/main.cpp16
-rwxr-xr-xcpp01/ex07/test.sh54
14 files changed, 97 insertions, 25 deletions
diff --git a/cpp01/ex05/Human.cpp b/cpp01/ex05/Human.cpp
index e7f55bd..e5f2099 100644
--- a/cpp01/ex05/Human.cpp
+++ b/cpp01/ex05/Human.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 12:52:38 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:04:09 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:31:38 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,7 +19,7 @@ std::string Human::identify() const
return m_brain.identify();
}
-const Brain& Human::getBrain() const
+Brain const& Human::getBrain() const
{
return m_brain;
}
diff --git a/cpp01/ex05/Human.hpp b/cpp01/ex05/Human.hpp
index fc89d03..bf872e4 100644
--- a/cpp01/ex05/Human.hpp
+++ b/cpp01/ex05/Human.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 12:52:39 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:03:44 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:31:46 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,7 +20,7 @@ class Human
public:
Human();
std::string identify() const;
- const Brain& getBrain() const;
+ Brain const& getBrain() const;
private:
const Brain m_brain;
diff --git a/cpp01/ex06/HumanA.cpp b/cpp01/ex06/HumanA.cpp
index ab4e5f3..6d73ab2 100644
--- a/cpp01/ex06/HumanA.cpp
+++ b/cpp01/ex06/HumanA.cpp
@@ -6,13 +6,13 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:44:03 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:09:22 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:34:33 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "HumanA.hpp"
-HumanA::HumanA(std::string const& name, Weapon& weapon)
+HumanA::HumanA(std::string const& name, Weapon const& weapon)
: m_name(name), m_weapon(weapon)
{}
diff --git a/cpp01/ex06/HumanA.hpp b/cpp01/ex06/HumanA.hpp
index d05d2fd..30144bd 100644
--- a/cpp01/ex06/HumanA.hpp
+++ b/cpp01/ex06/HumanA.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:37:23 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:08:55 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:34:26 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,11 +19,11 @@
class HumanA
{
public:
- HumanA(std::string const& name, Weapon& weapon);
+ HumanA(std::string const& name, Weapon const& weapon);
void attack();
private:
- std::string m_name;
- Weapon& m_weapon;
+ std::string m_name;
+ Weapon const& m_weapon;
};
#endif
diff --git a/cpp01/ex06/HumanB.cpp b/cpp01/ex06/HumanB.cpp
index e6adb22..7aa2a5f 100644
--- a/cpp01/ex06/HumanB.cpp
+++ b/cpp01/ex06/HumanB.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:46:02 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:13:34 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:36:16 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,7 +24,7 @@ void HumanB::attack()
std::cout << m_name << " attack with his " << m_weapon->getType() << std::endl;
}
-void HumanB::setWeapon(Weapon& weapon)
+void HumanB::setWeapon(Weapon const& weapon)
{
m_weapon = &weapon;
}
diff --git a/cpp01/ex06/HumanB.hpp b/cpp01/ex06/HumanB.hpp
index fc9236c..d21cb9d 100644
--- a/cpp01/ex06/HumanB.hpp
+++ b/cpp01/ex06/HumanB.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:42:54 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:09:56 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:39:45 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -21,10 +21,10 @@ class HumanB
public:
HumanB(std::string const& name);
void attack();
- void setWeapon(Weapon& weapon);
+ void setWeapon(Weapon const& weapon);
private:
- std::string m_name;
- Weapon* m_weapon;
+ std::string m_name;
+ Weapon const* m_weapon;
};
#endif
diff --git a/cpp01/ex06/main.cpp b/cpp01/ex06/main.cpp
index 5c92b43..97dbb39 100644
--- a/cpp01/ex06/main.cpp
+++ b/cpp01/ex06/main.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 16:40:20 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:13:54 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 08:39:52 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/cpp01/ex07/test1 b/cpp01/ex07/files/nowrite.orig
index 2851ba4..2851ba4 100644
--- a/cpp01/ex07/test1
+++ b/cpp01/ex07/files/nowrite.orig
diff --git a/cpp01/ex07/files/test1.orig b/cpp01/ex07/files/test1.orig
new file mode 100644
index 0000000..2851ba4
--- /dev/null
+++ b/cpp01/ex07/files/test1.orig
@@ -0,0 +1,6 @@
+bonjour je suis un
+charles
+avec quelque bonjour
+dans ce fichier
+bonjour
+hi im bonj
diff --git a/cpp01/ex07/test2 b/cpp01/ex07/files/test2.orig
index 227746e..227746e 100644
--- a/cpp01/ex07/test2
+++ b/cpp01/ex07/files/test2.orig
diff --git a/cpp01/ex07/files/test3.orig b/cpp01/ex07/files/test3.orig
new file mode 100644
index 0000000..8950d92
--- /dev/null
+++ b/cpp01/ex07/files/test3.orig
@@ -0,0 +1,6 @@
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+abababababababababababababababababab
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+abababababababababababababababababab
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
diff --git a/cpp01/ex07/files/test4.orig b/cpp01/ex07/files/test4.orig
new file mode 100644
index 0000000..0b1cda4
--- /dev/null
+++ b/cpp01/ex07/files/test4.orig
@@ -0,0 +1,6 @@
+aaaaaaaaaaaaaaa
+abababababababa
+aaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaa
+abababababababa
+aaaaaaaaaaaaaaa
diff --git a/cpp01/ex07/main.cpp b/cpp01/ex07/main.cpp
index d98168a..3965d3d 100644
--- a/cpp01/ex07/main.cpp
+++ b/cpp01/ex07/main.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/02 17:08:28 by cacharle #+# #+# */
-/* Updated: 2020/11/09 11:22:46 by cacharle ### ########.fr */
+/* Updated: 2020/11/10 09:25:28 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,22 +25,26 @@ int main(int argc, char **argv)
std::string filename(argv[1]);
std::string s1(argv[2]);
std::string s2(argv[3]);
- if (filename.empty() || s1.empty() || s2.empty())
+ if (s1.empty() || s2.empty())
{
- std::cerr << "Error: filename, s1 and s2 should not be empty" << std::endl;
+ std::cerr << "Error: s1 and s2 should not be empty" << std::endl;
return 1;
}
std::ifstream file(filename);
- std::ofstream outfile(filename + ".replace");
+ std::ofstream outfile(filename + ".replace", std::ofstream::trunc);
if (!file.is_open())
{
- std::cerr << "Could not open " << filename;
+ std::cerr << "Could not open " << filename
+ << ": " << std::strerror(errno) << std::endl;
+ outfile.close();
return 1;
}
if (!outfile.is_open())
{
- std::cerr << "Could not create " << filename << ".replace";
+ std::cerr << "Could not create " << filename << ".replace"
+ << ": " << std::strerror(errno) << std::endl;
+ file.close();
return 1;
}
diff --git a/cpp01/ex07/test.sh b/cpp01/ex07/test.sh
index 69cdc43..8a10120 100755
--- a/cpp01/ex07/test.sh
+++ b/cpp01/ex07/test.sh
@@ -1,5 +1,55 @@
#!/bin/sh
make all
-./replace test1 bonjour aurevoir
-./replace test2 occ many
+
+replace_test () {
+ echo "----------------------------------"
+ echo "$ ./replace $1 $2 $3"
+ ./replace "$1" "$2" "$3"
+ echo "=== ORIGIN"
+ cat "$1"
+ echo "=== REPLACED"
+ cat "$1.replace"
+}
+
+replace_test_error() {
+ echo "----------------------------------"
+ echo "$ ./replace $1 $2 $3"
+ ./replace "$1" "$2" "$3"
+}
+
+echo '======== BASIC ======='
+replace_test files/test1.orig bonjour aurevoir
+replace_test files/test2.orig occ many
+replace_test files/test3.orig a A
+replace_test files/test4.orig a zZz
+
+echo '======== ARGUMENT ERROR ======='
+./replace
+./replace files/test1.orig
+./replace files/test1.orig bonjour aurevoir ye
+./replace files/test1.orig bonjour
+./replace files/test1.orig '' aurevoir
+./replace files/test1.orig bonjour ''
+./replace '' bonjour aurevoir
+
+echo '======== FILE ERROR ======='
+./replace files/doesnotexist a b
+
+touch files/noperm
+chmod 000 files/noperm
+./replace files/noperm a b
+rm -f files/noperm
+
+touch files/noread
+chmod 333 files/noread
+./replace files/noread a b
+rm -f files/noread
+
+touch files/nowrite.orig.replace
+chmod 555 files/nowrite.orig.replace
+./replace files/nowrite.orig bonjour aurevoir
+rm -f files/nowrite.orig.replace
+
+
+find files -name '*.replace' -exec rm -f \{\} \;