Skip to content

Commit be0d95b

Browse files
committed
Initial commit
0 parents  commit be0d95b

11 files changed

+171
-0
lines changed

.editorconfig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
tab_width = 2
8+
indent_style = space
9+
insert_final_newline = true
10+
trim_trailing_whitespace = true
11+
12+
[{Makefile,*.{c,h,mk}}]
13+
indent_size = 4
14+
tab_width = 4
15+
indent_style = tab
16+
17+
[*.txt]
18+
insert_final_newline = false
19+
trim_trailing_whitespace = false

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.cache
2+
compile_commands.json
3+
.vscode/*
4+
!.vscode/settings.json
5+
6+
ex00/*
7+
!ex00/Makefile
8+
!ex00/main.cpp
9+
!ex00/whatever.hpp

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"[cpp]": {
3+
"editor.formatOnSave": true,
4+
},
5+
"files.associations": {
6+
"compile_commands.json": "jsonc",
7+
},
8+
"sonarlint.pathToCompileCommands": "${workspaceFolder}/compile_commands.json",
9+
}

Makefile

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
all: test
2+
.PHONY: all
3+
4+
5+
.PHONY: test
6+
test:
7+
@sh run_test.sh
8+
9+
.PHONY: clean
10+
clean:
11+
@sh run_clean.sh
12+
@sh run_make.sh clean
13+
14+
.PHONY: fclean
15+
fclean:
16+
@sh run_clean.sh
17+
@sh run_make.sh fclean
18+
19+
.PHONY: re
20+
re:
21+
$(MAKE) fclean
22+
$(MAKE) all
23+
24+
25+
.PHONY: compile_commands.json
26+
compile_commands.json: pre_dev
27+
@(echo "[" && find . -name "*.part.json" | xargs cat && echo "]") > $@
28+
29+
.PHONY: pre_dev
30+
pre_dev:
31+
@sh run_pre_dev.sh
32+
33+
.PHONY: dev
34+
dev: compile_commands.json

ex00/Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
NAME = ex00
2+
OBJS = main.o
3+
4+
CXXFLAGS = -Wall -Wextra -Werror
5+
6+
7+
all: $(NAME)
8+
.PHONY: all
9+
10+
11+
.PHONY: clean
12+
clean:
13+
rm -f $(OBJS)
14+
15+
.PHONY: fclean
16+
fclean: clean
17+
rm -f $(NAME)
18+
19+
.PHONY: re
20+
re:
21+
$(MAKE) fclean
22+
$(MAKE) all
23+
24+
25+
.cpp.o:
26+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c $<
27+
28+
$(NAME): $(OBJS)
29+
$(CXX) $(LDFLAGS) -o $@ $^

ex00/main.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <iostream>
2+
3+
#include "whatever.hpp"
4+
5+
int main(void) {
6+
{
7+
int a = 2;
8+
int b = 3;
9+
::swap(a, b);
10+
std::cout << "a = " << a << ", b = " << b << std::endl;
11+
std::cout << "min( a, b ) = " << ::min(a, b) << std::endl;
12+
std::cout << "max( a, b ) = " << ::max(a, b) << std::endl;
13+
std::string c = "chaine1";
14+
std::string d = "chaine2";
15+
::swap(c, d);
16+
std::cout << "c = " << c << ", d = " << d << std::endl;
17+
std::cout << "min( c, d ) = " << ::min(c, d) << std::endl;
18+
std::cout << "max( c, d ) = " << ::max(c, d) << std::endl;
19+
}
20+
{
21+
int a = 0;
22+
int b = 42;
23+
::swap(a, b);
24+
std::cout << a << ", " << b << std::endl;
25+
min(a, b) = 4242;
26+
std::cout << a << ", " << b << std::endl;
27+
max(a, b) = 0;
28+
std::cout << a << ", " << b << std::endl;
29+
}
30+
return 0;
31+
}

ex00/whatever.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#ifndef EX00_WHATEVER_HPP_INCLUDED
2+
#define EX00_WHATEVER_HPP_INCLUDED
3+
4+
template <typename T> void swap(T &a, T &b) {
5+
T tmp = a;
6+
a = b;
7+
b = tmp;
8+
}
9+
10+
template <typename T> T &min(T &a, T &b) { return a < b ? a : b; }
11+
12+
template <typename T> T &max(T &a, T &b) { return a > b ? a : b; }
13+
14+
#endif

run_clean.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
find . \( -name "*.cpp.o" -o -name "*.cxx.o" -o -name "*.cc.o" -o -name "*.part.json" \) -delete

run_make.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
ls -1 | grep "^ex[[:digit:]]\\+\$" | while IFS= read -r line
6+
do
7+
(cd "$line" && make "$1")
8+
done

run_pre_dev.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
find . -name "*.cpp" -o -name "*.cxx" -o -name "*.cc" | while IFS= read -r line
6+
do
7+
clang -Wall -Wextra -Werror -std=c++98 -pedantic -c "$line" -o "$line.o" -MJ "$line.part.json"
8+
done

run_test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
echo "Nothing to be done."

0 commit comments

Comments
 (0)