3 # Copyright (c) 2014. 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"
35 sed -n '/Copyright.*SimGrid/{
36 s/.*(c) \([[:digit:], -]*\).*/\1/
52 git log --format=%ad "$file" | cut -d\ -f5 | uniq
63 if [ $next -eq $((last + 1)) ]; then
66 if [ $first -eq $last ]; then
69 printf '%d-%d, ' $first $last
75 if [ $first -eq $last ]; then
78 printf '%d-%d\n' $first $last
85 trap "rm -f \"$tmp_head\" \"$tmp_copy\" \"$tmp_foot\"" EXIT
88 echo "########## $file ##########"
90 if [ ! -f "$file" ]; then
95 if head -n 1 "$file" | grep -q '^#!'; then
101 ### 1. create new template
102 dates=$(get_dates "$file" | sort -u | format_dates)
103 sed "s/(c) [[:digit:], -]*\./(c) $dates./" "$template" > "$tmp_copy"
104 printf '\n' >> "$tmp_copy"
106 # fix comments for scripts
107 if [ $script = 1 ]; then
108 sed -i 's!^..!#!;s! *\*/!!' "$tmp_copy"
111 ### 2. copy file body
112 if grep -q 'Copyright.*SimGrid' "$file"; then
113 sed '/Copyright.*SimGrid/,$d' "$file" > "$tmp_head"
114 sed -i '${\!^/\* *$!d}' "$tmp_head"
115 sed '1,/the terms of the license/d' "$file" > "$tmp_foot"
116 elif [ $script = 1 ]; then
117 head -n 1 "$file" > "$tmp_head"
118 tail -n +2 "$file" > "$tmp_foot"
119 printf '\n' >> "$tmp_head"
122 cp "$file" "$tmp_foot"
124 sed -i '1{\!^ *\*/!d};/[^[:space:]]/,$!d' "$tmp_foot"
126 ### 3. concatenate new template and file body into $file
130 cat "$tmp_head" "$tmp_copy" "$tmp_foot" > $file
137 *** DO NOT FORGET TO DOUBLE CHECK CHANGES BEFORE DOING ANY COMMIT! ***