From 219dd857197a51af43e625ddddb7a6a3563ccf2d Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Wed, 14 May 2025 22:25:29 +0200 Subject: Initial commit --- clide | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100755 clide diff --git a/clide b/clide new file mode 100755 index 0000000..a748a83 --- /dev/null +++ b/clide @@ -0,0 +1,89 @@ +#- +# This file is part of Clide. +# +# Clide 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. +# +# Clide 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 Clide. If not, see . +# + +#!/bin/sh + +__help() +{ + echo '' +} + +__update_copyright() +{ + local YEAR=$(date +%Y) + local COPYRIGHT=copyright.txt # Filename of the copyright to append to the source code + + # Extension, to know wich symbol to use for the copyright + local EXTENSION="${1##*.}" + case $EXTENSION in + java|c|h) local START='/*-'; local END=' */'; local ROW=' \*';; + properties) local START='#-'; local END='#'; local ROW='#' ;; + Makefile) local START='#-'; local END='#'; local ROW='#' ;; + esac + + # This is the range between the start and the end of the copyright header + local RANGE=$(echo $(cat $1 | grep -n "^$START$\|^$END$" | head -2 | sed -E 's/([0-9]+):.*/\1/g') | tr ' ', ',') + + if [ -z $RANGE ]; then + # If the range is empty, copyright notice must be added + RANGE=0a + local ADD_BLANK_LINE=1 + else + # Otherwise must be replaced + RANGE=${RANGE}c + fi + + # Generate the content with + local CONTENT=$(cat $COPYRIGHT \ + | sed "s/%YEAR%/$YEAR/g" \ + | sed -E "s/^(.+)/$ROW \1/g" | sed -E "s/^$/$ROW/g") + + if [ ! -z $ADD_BLANK_LINE ]; then +ed "$1" <