From: Arnaud Giersch Date: Wed, 5 Feb 2014 21:40:29 +0000 (+0100) Subject: Add script used as a basis to update copyright notices. X-Git-Tag: v3_11_beta~84 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/1aa500b99be3b2807ddaee6c428a82e09a7c567e Add script used as a basis to update copyright notices. --- diff --git a/tools/check_dist_archive.exclude b/tools/check_dist_archive.exclude index 97b941c313..0e31b8cbbd 100644 --- a/tools/check_dist_archive.exclude +++ b/tools/check_dist_archive.exclude @@ -45,5 +45,6 @@ + tools/check_dist_archive + tools/check_dist_archive\.exclude + tools/normalize-pointers\.py ++ tools/update_copyright_header + tools/spell/.* diff --git a/tools/update_copyright_header b/tools/update_copyright_header new file mode 100755 index 0000000000..36c11af230 --- /dev/null +++ b/tools/update_copyright_header @@ -0,0 +1,139 @@ +#!/bin/bash + +# Copyright (c) 2014. The SimGrid Team. +# All rights reserved. + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the license (GNU LGPL) which comes with this package. + +if [ "$1" = "-t" ]; then + template=$2 + shift 2 +else + template=$(git rev-parse --show-toplevel)/COPYRIGHT.template +fi + +if [ $# -eq 0 ]; then + cat >&2 <&2 + exit 1 +fi + +printf 'Using template: %s\n' "$template" + +now=$(date +%Y) + +get_dates() { + local file=$1 + local date + sed -n '/Copyright.*SimGrid/{ + s/.*(c) \([[:digit:], -]*\).*/\1/ + s/[, ]\+/\n/g + p + }' "$file" \ + | while read date; do + case "$date" in + "") + ;; + *-*) + seq ${date/-/ } + ;; + *) + echo $date + ;; + esac + done + git log --format=%ad "$file" | cut -d\ -f5 | uniq + echo $now +} + +format_dates() { + local first + local last + local next + read first + last=$first + while read next; do + if [ $next -eq $((last + 1)) ]; then + last=$next + else + if [ $first -eq $last ]; then + printf '%d, ' $first + else + printf '%d-%d, ' $first $last + fi + first=$next + last=$first + fi + done + if [ $first -eq $last ]; then + printf '%d\n' $first + else + printf '%d-%d\n' $first $last + fi +} + +tmp_head=$(mktemp) +tmp_copy=$(mktemp) +tmp_foot=$(mktemp) +trap "rm -f \"$tmp_head\" \"$tmp_copy\" \"$tmp_foot\"" EXIT + +for file; do + echo "########## $file ##########" + + if [ ! -f "$file" ]; then + echo "!!! skip" + continue + fi + + if head -n 1 "$file" | grep -q '^#!'; then + script=1 + else + script=0 + fi + + ### 1. create new template + dates=$(get_dates "$file" | sort -u | format_dates) + sed "s/(c) [[:digit:], -]*\./(c) $dates./" "$template" > "$tmp_copy" + printf '\n' >> "$tmp_copy" + + # fix comments for scripts + if [ $script = 1 ]; then + sed -i 's!^..!#!;s! *\*/!!' "$tmp_copy" + fi + + ### 2. copy file body + if grep -q 'Copyright.*SimGrid' "$file"; then + sed '/Copyright.*SimGrid/,$d' "$file" > "$tmp_head" + sed -i '${\!^/\* *$!d}' "$tmp_head" + sed '1,/the terms of the license/d' "$file" > "$tmp_foot" + elif [ $script = 1 ]; then + head -n 1 "$file" > "$tmp_head" + tail -n +2 "$file" > "$tmp_foot" + printf '\n' >> "$tmp_head" + else + :> "$tmp_head" + cp "$file" "$tmp_foot" + fi + sed -i '1{\!^ *\*/!d};/[^[:space:]]/,$!d' "$tmp_foot" + + ### 3. concatenate new template and file body into $file +# cat "$tmp_head" +# cat "$tmp_copy" +# cat "$tmp_foot" + cat "$tmp_head" "$tmp_copy" "$tmp_foot" > $file +done + +cat <