Skip to content
Snippets Groups Projects
Commit a6ea5394 authored by Joan Vallvé Navarro's avatar Joan Vallvé Navarro
Browse files

license script with exclude option

parent 13c9bc95
No related branches found
No related tags found
1 merge request!427Resolve "Wolf license"
......@@ -12,6 +12,7 @@ line_end_mark="//--------LICENSE_END--------"
tmp=false
mode="none"
path=""
exclude_folder=""
#recursive=true
license=""
......@@ -45,6 +46,10 @@ for i in "$@"; do
fi
shift # past argument=value
;;
--exclude=*)
exclude_folder="${i#*=}"
shift # past argument=value
;;
*)
# unknown option
;;
......@@ -77,11 +82,19 @@ else
fi
fi
echo "mode: ${mode}"
if [ "$exclude_folder" == "" ]; then
echo "No folders will be excluded"
else
if [ -d "${path}/${exclude_folder}" ]; then
echo "Valid remove folder path: ${path}/${exclude_folder}"
fi
fi
if [ $mode == "none" ]; then
echo "Error: Script should be called with one of the following options: --update or --add"
exit 1
else
echo "mode: ${mode}"
fi
# PATH (AND tmp FOLDER)
......@@ -93,30 +106,34 @@ if [ $tmp == true ]; then
folder=${path}_tmp
fi
# LIST OF FILES TO BE ITERATED ON
if [ "$exclude_folder" == "" ]; then
file_list=$(find $folder -name '*.c' -or -name '*.cpp' -or -name '*.h' -or -name '*.hpp')
else
file_list=$(find $folder -path ${folder}/${exclude_folder} -prune -name '*.c' -or -name '*.cpp' -or -name '*.h' -or -name '*.hpp')
fi
# DETECT AND REMOVE EXISTING LICENSE
if [ $mode == "update" ]; then
if [ "$mode" == "update" ]; then
echo "Recursely removing license header from all files (.c, .cpp, .h, .hpp)"
for i in $(find $folder -name '*.c' -or -name '*.cpp' -or -name '*.h' -or -name '*.hpp')
for i in $file_list
do
if grep -Fxq ${line_start_mark} $i
then
echo " Removing license header from file ${i}"
line_start="$(grep -wn $line_start_mark ${i} | head -n 1 | cut -d: -f1)"
line_end="$(grep -wn $line_end_mark ${i} | head -n 1 | cut -d: -f1)"
echo ${line_start}
echo ${line_end}
#echo "${line_start},${line_end}d" $i
#sed $('${line_start},${line_end}d)' $i
#echo ${line_start}
#echo ${line_end}
awk -v m=$line_start -v n=$line_end 'm <= NR && NR <= n {next} {print}' $i > tmpfile && mv tmpfile $i
cat $i
#cat $i
fi
done
#TODO
fi
# ADD CONTENT OF license-file AT THE BEGINNING OF CODE FILES
echo "Recursively adding license header to all files (.c, .cpp, .h, .hpp)"
for i in $(find $folder -name '*.c' -or -name '*.cpp' -or -name '*.h' -or -name '*.hpp')
for i in $file_list
do
if grep -Fxq ${line_start_mark} $i; then
echo "skippping ${i}"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment