3 # Copyright (c) 2014-2022. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
9 if [ "$1" = "-t" ]; then
13 template=$(git rev-parse --show-toplevel)/COPYRIGHT.template
18 Usage: $0 [-t COPYRIGHT.template] files...
23 if [ ! -r "$template" ]; then
24 printf 'File not found: %s\n' "$template" >&2
28 printf 'Using template: %s\n' "$template"
33 sed -n '/Copyright.*SimGrid/{
34 s/.*(c) \([[:digit:], -]*\).*/\1/
38 | while read -r date; do
50 git log --format=%ad "$file" | cut -d\ -f5 | uniq
59 while read -r next; do
60 if [ $next -eq $((last + 1)) ]; then
63 if [ $first -eq $last ]; then
66 printf '%d-%d, ' $first $last
72 if [ $first -eq $last ]; then
75 printf '%d-%d\n' $first $last
82 trap "rm -f \"$tmp_head\" \"$tmp_copy\" \"$tmp_foot\"" EXIT
85 echo "########## $file ##########"
87 if [ ! -f "$file" ]; then
92 if grep -q "Copyright.*SimGrid" $file ; then
93 if head -n 1 "$file" | grep -q '^#!'; then
99 ### 1. create new template
100 dates=$(get_dates "$file" | sort -u | format_dates)
101 sed "s/(c) [[:digit:], -]*\./(c) $dates./" "$template" > "$tmp_copy"
102 printf '\n' >> "$tmp_copy"
104 # fix comments for scripts
105 if [ $script = 1 ]; then
106 sed -i 's!^..!#!;s! *\*/!!' "$tmp_copy"
109 ### 2. copy file body
110 if grep -q 'Copyright.*SimGrid' "$file"; then
111 sed '/Copyright.*SimGrid/,$d' "$file" > "$tmp_head"
112 sed -i '${\!^/\* *$!d}' "$tmp_head"
113 sed '1,/the terms of the license/d' "$file" > "$tmp_foot"
114 elif [ $script = 1 ]; then
115 head -n 1 "$file" > "$tmp_head"
116 tail -n +2 "$file" > "$tmp_foot"
117 printf '\n' >> "$tmp_head"
120 cp "$file" "$tmp_foot"
122 sed -i '1{\!^ *\*/!d};/[^[:space:]]/,$!d' "$tmp_foot"
124 ### 3. concatenate new template and file body into $file
128 cat "$tmp_head" "$tmp_copy" "$tmp_foot" > $file
130 echo "Pass: there is no SimGrid Copyright header."
138 *** DO NOT FORGET TO DOUBLE CHECK CHANGES BEFORE DOING ANY COMMIT! ***