-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.cp_functions
78 lines (68 loc) · 2.13 KB
/
.cp_functions
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
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
# Place this file in your home directory, your template in
# ~/.cp_template.cpp, your library in ~/.cp_library.cpp and
# add ". .cp_functions" (without quotes) at the end of your .bashrc
# Initialize the solution for the given problem from the template
function cpinit()
{
if [[ -z "$1" ]]; then
echo Usage: cpinit '<problem name>'
else
if [[ -f "$1.cpp" ]]; then
echo File $1.cpp already exists
else
cp ~/.cp_template.cpp $1.cpp
export _LAST_CPINIT_FILE=$1
code $1.cpp
fi
fi
}
# Compile&run the given problem, and color the output to
# distinguish it from copy pasted input
#
# Using precompiled headers:
# - find bits/stdc++.h by compiling something with -H
# - compile it: g++ $CXXFLAGS <file> -o stdc++.h.gch
# CXXFLAGS MUST be the same options that you set below, or it will be ignored later
# - set BITSSTDCPP_GCH to the output filename WITHOUT GCH AT THE END and enjoy faster compilation
# If you don't want precompiled headers, set BITSSTDCPP_GCH to ""
function cprun()
{
CXXFLAGS="-O3 -std=c++17 -Wshadow -Wall -Wno-sign-compare -Wconversion -g -fsanitize=address -fsanitize=undefined -fno-sanitize-recover"
BITSSTDCPP_GCH="$HOME/Desktop/cp/stdc++.h"
if [[ $BITSSTDCPP_GCH ]]; then
CXXFLAGS="$CXXFLAGS -include $BITSSTDCPP_GCH"
fi
filename=$1
if [[ -z "$filename" ]]; then
if [[ "$_LAST_CPINIT_FILE" ]]; then
echo No file provided. Using last created file \"$_LAST_CPINIT_FILE\"
filename=$_LAST_CPINIT_FILE
fi
fi
# remove final .cpp if present
if [[ $filename == *.cpp ]]; then
filename=${filename::-4}
fi
if [[ -f "$filename.cpp" ]]; then
g++ $CXXFLAGS $filename.cpp -o $filename && ./$filename 2>&1 | grep --color '.*';
# g++ $CXXFLAGS $filename.cpp -o $filename && ./$filename
else
echo Usage: cprun '<problem name>'
fi
}
# Initialize a folder for a given contest. If no contest name if provided,
# use the current directory.
function cpcontest()
{
if [[ $1 ]]; then
if [[ -f "$1" ]] || [[ -d "$1" ]]; then
echo $1 already exists
return
fi
mkdir $1
cd $1
fi
code . ~/.cp_library.cpp
cpinit a
}