-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.sh
executable file
·66 lines (51 loc) · 1.67 KB
/
template.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# Use this file for generating template code for solving a problem.
# Each new problem will be within its directory, and this directory
# will itself belong to a problem category. Thus pass both problem name
# and name of problem category directory.
# Sample input and output files are created as well, and relevant cmake
# files will be updated.
# Run from root of project.
# Usage: ./template.sh dir_name problem_name
dir_name=$1
problem_name=$2
# Check if the problem category directory exists
if [ ! -d "$dir_name" ]; then
# If it doesn't exist, create it
mkdir -p "$dir_name"
# create a cmake file within it
touch "$dir_name/CMakeLists.txt"
echo "add_subdirectory(dir_name)" >> "CMakeLists.txt"
fi
echo "add_subdirectory($problem_name)" >> "$dir_name/CMakeLists.txt"
mkdir -p "$dir_name/$problem_name"
touch "$dir_name/$problem_name/CMakeLists.txt"
cat <<EOT >> $dir_name/$problem_name/CMakeLists.txt
# Add an executable for the $problem_name problem
add_executable($problem_name main.cpp)
# Link the algorithms library
target_link_libraries($problem_name PRIVATE algorithms -fsanitize=undefined -fsanitize=address)
EOT
touch "$dir_name/$problem_name/main.cpp"
touch "$dir_name/$problem_name/sample.in"
touch "$dir_name/$problem_name/sample.output"
cat <<EOT >> $dir_name/$problem_name/main.cpp
/**
* main.cpp
* -----------------
* $problem_name (https://open.kattis.com/problems/$problem_name):
*
*
* Solution:
*
*
**/
#include "../../algorithms/$dir_name.hpp"
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
return 0;
}
// ============== END OF FILE ==============
EOT
echo "Created template files."