diff options
author | 2025-05-14 22:25:29 +0200 | |
---|---|---|
committer | 2025-05-14 22:28:02 +0200 | |
commit | 219dd857197a51af43e625ddddb7a6a3563ccf2d (patch) | |
tree | 45d3472ad23c1a3568bbd70371463edeb15d8025 | |
download | clide-219dd857197a51af43e625ddddb7a6a3563ccf2d.tar.gz clide-219dd857197a51af43e625ddddb7a6a3563ccf2d.zip |
-rwxr-xr-x | clide | 89 |
1 files changed, 89 insertions, 0 deletions
@@ -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 <http://www.gnu.org/licenses/>. +# + +#!/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" <<EOF +$RANGE +$START +$CONTENT +$END + +. +w +q +EOF + else +ed "$1" <<EOF +$RANGE +$START +$CONTENT +$END +. +w +q +EOF + fi +} + +if [ $# -eq 0 ]; then + __help + exit 1 +fi + +while [ $# -gt 0 ]; do + case $1 in + --update-copyright|-uc) __update_copyright $2;; + esac + shift +done |