#!/bin/bash

# Copyright © 2015 František Kučera (frantovo.cz)
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Viz https://blog.frantovo.cz/c/351/CLOC%3A%20po%C4%8D%C3%ADt%C3%A1me%20%C5%99%C3%A1dky%20k%C3%B3du

DIR=$(dirname $(realpath $0));
XSLT="$DIR/cloc-sql.xsl"

CLOC_ARGS=( "$@" );
test ${#CLOC_ARGS[@]} == 0 && CLOC_ARGS+=("."); 

CLOC_XML=$(cloc --xml "${CLOC_ARGS[@]}" | tail -n +5);

if [[ -z "$CLOC_XML" ]]; then
	echo "cloc nic nespočítal – pravděpodobně nenašel zdrojáky"
	exit 1;
fi

SCRIPT=$(echo "$CLOC_XML" | xsltproc "$XSLT" -);

bash -c "$SCRIPT";

