Last active
October 1, 2016 00:24
-
-
Save blueset/3e0d15e63eccfdd72ff475da9bb175f8 to your computer and use it in GitHub Desktop.
C++ Compiling | Running script for competitive programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# compile | |
clear | |
if [ -z "$1" ] | |
then | |
echo "$0 Usage:" | |
echo " $0 sourceCode.cpp [inputFile.in]" | |
echo "" | |
echo "Example:" | |
echo " $0 test.cpp" | |
echo " $0 test.cpp test.1.in" | |
echo "" | |
echo "This script compiles the C++ source code if the" | |
echo "source is newer than the binary. Then pipe in the" | |
echo "input if exists. Finally compare it with the output" | |
echo "if exists." | |
else | |
filename=$(basename "$1") | |
extension="${filename##*.}" | |
filename="${filename%.*}" | |
if [ -z "$2" ] | |
then | |
casename=$filename | |
else | |
casename=$(basename "$2.in") | |
casename="${casename%.*}" | |
fi | |
if [ ! -f "$filename" ] || [ "$1" -nt "$filename" ] | |
then | |
g++ -lm -Wall -Wconversion -g -O2 -std=c++11 -o $filename $1 | |
fi | |
# run with input | |
if [ $? -eq 0 ] | |
then | |
if [ -f "$casename.in" ] | |
then | |
if [ -f "$casename.out" ] | |
then | |
./$filename < $casename.in | diff -y - $casename.out | |
else | |
./$filename < $casename.in | |
fi | |
else | |
./$filename | |
fi | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment