Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Have create_jbod() return a JbodPtr instead of Jbod* to avoid memleaks
[simgrid.git] / tools / internal / update_copyright_header
index 36c11af..7f0f378 100755 (executable)
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/usr/bin/env bash
 
-# Copyright (c) 2014. The SimGrid Team.
+# Copyright (c) 2014-2023. The SimGrid Team.
 # All rights reserved.
 
 # This program is free software; you can redistribute it and/or modify it
@@ -27,8 +27,6 @@ fi
 
 printf 'Using template: %s\n' "$template"
 
-now=$(date +%Y)
-
 get_dates() {
     local file=$1
     local date
@@ -37,7 +35,7 @@ get_dates() {
               s/[, ]\+/\n/g
               p
             }' "$file" \
-    | while read date; do
+    | while read -r date; do
         case "$date" in
             "")
                 ;;
@@ -50,16 +48,15 @@ get_dates() {
         esac
     done
     git log --format=%ad "$file" | cut -d\  -f5 | uniq
-    echo $now
 }
 
 format_dates() {
     local first
     local last
     local next
-    read first
+    read -r first
     last=$first
-    while read next; do
+    while read -r next; do
         if [ $next -eq $((last + 1)) ]; then
             last=$next
         else
@@ -92,42 +89,46 @@ for file; do
         continue
     fi
 
-    if head -n 1 "$file" | grep -q '^#!'; then
-        script=1
-    else
-        script=0
-    fi
+    if grep -q "Copyright.*SimGrid" $file ; then
+        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"
+        ### 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
+        # 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"
+        ### 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
+        ### 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
+    else
+        echo "Pass: there is no SimGrid Copyright header."
+    fi ; #
 done
 
 cat <<EOF