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 grep -q "Copyright.*SimGrid" $file ; then
96 if head -n 1 "$file" | grep -q '^#!'; then
102 ### 1. create new template
103 dates=$(get_dates "$file" | sort -u | format_dates)
104 sed "s/(c) [[:digit:], -]*\./(c) $dates./" "$template" > "$tmp_copy"
105 printf '\n' >> "$tmp_copy"
107 # fix comments for scripts
108 if [ $script = 1 ]; then
109 sed -i 's!^..!#!;s! *\*/!!' "$tmp_copy"
112 ### 2. copy file body
113 if grep -q 'Copyright.*SimGrid' "$file"; then
114 sed '/Copyright.*SimGrid/,$d' "$file" > "$tmp_head"
115 sed -i '${\!^/\* *$!d}' "$tmp_head"
116 sed '1,/the terms of the license/d' "$file" > "$tmp_foot"
117 elif [ $script = 1 ]; then
118 head -n 1 "$file" > "$tmp_head"
119 tail -n +2 "$file" > "$tmp_foot"
120 printf '\n' >> "$tmp_head"
123 cp "$file" "$tmp_foot"
125 sed -i '1{\!^ *\*/!d};/[^[:space:]]/,$!d' "$tmp_foot"
127 ### 3. concatenate new template and file body into $file
131 cat "$tmp_head" "$tmp_copy" "$tmp_foot" > $file
133 echo "Pass: there is no SimGrid Copyright header."
141 *** DO NOT FORGET TO DOUBLE CHECK CHANGES BEFORE DOING ANY COMMIT! ***