File indexing completed on 2024-06-16 04:38:11

0001 #!/bin/bash
0002 
0003 if [ "$1" == "" ]; then
0004         echo "Usage: copy.sh <all|git [commit]|files>"
0005         exit
0006 fi
0007 
0008 textc=-$(date +%Y)' Mladen Milinkovic <max\@smoothware.net>'
0009 text1=':a;N;$!ba;s/\/\*[^\/]+SPDX-FileCopyrightText:([^\/]+|[^\*]\/)+\*\//\/*\n'
0010 text2='\n    SPDX-License-Identifier: GPL-2.0-or-later\n*\//'
0011 
0012 update_copyright() {
0013         f="$1"
0014         if [[ ! -f "$f" ]]; then
0015                 return
0016         fi
0017         echo -e '\e[01;33mProcessing \e[01;39m'$f'\e[01;33m\e[00m'
0018 
0019         copy=$(perl -pe 'BEGIN{undef $/;} s!^.*?/\*[^/]*?(([\t *]*?SPDX-FileCopyrightText[^\n]*?[\t *]*?\n)+).*?$!$1!sg' "$f"\
0020                 | perl -pe 's!\(([^)>]+@[^)>]+)\)!<$1>!' \
0021                 | perl -pe "s!(-\d+)? Mladen Milinkovic [<(][^>]+[>)]!$textc!g" \
0022                 | perl -pe 's!(\d{4})(-\1)!$1!g' \
0023                 | perl -pe 'BEGIN{undef $/;} s!\n+!\\n!sg')
0024 
0025         if [[ $copy == *"Sergio Pistone"* || $copy == *"Mladen Milinkovic"* ]]; then
0026                 if [[ $copy != *"Mladen Milinkovic"* ]]; then
0027                         copy="$copy * Copyright (C) 2010-${textc:1}\n"
0028                 fi
0029                 sed -r "$text1$copy$text2" --in-place "$f"
0030         fi
0031 }
0032 
0033 if [ "$1" == "all" ]; then
0034         export -f update_copyright
0035         for f in `find . \( -name \*.cpp -or -name \*.h \)`; do
0036                 update_copyright "$f"
0037         done
0038 elif [ "$1" == "git" ]; then
0039         for f in `git diff --name-only "${@:2}" | grep -Pe '\.[ch](pp)?$'`; do
0040                 update_copyright "$f"
0041         done
0042 else
0043         for f in "${@:1}"; do
0044                 update_copyright "$f"
0045         done
0046 fi