Updates to reformat script.
[openssl.git] / util / openssl-format-source
index 242c5ba81a6dab02a9c6aac8ceda6a8f4e15f676..6380a100b456016a953f22e4b49b3d38bf24d513 100755 (executable)
@@ -30,6 +30,8 @@ VERBOSE=false
 DONT=false
 STOPARGS=false
 COMMENTS=false
+CHANGED=false
+DEBUG=""
 
 # for this exercise, we want to force the openssl style, so we roll
 # our own indent profile, which is at a well known location
@@ -54,6 +56,10 @@ do
       -c) COMMENTS="true"; 
          INDENT_ARGS="-fc1 -fca -cdb -sc"; 
          continue;;
+      -nc) COMMENTS="true";
+         continue;;
+      -d) DEBUG='eval tee "$j.pre" |'
+         continue;;
     esac
   fi
 
@@ -77,10 +83,6 @@ do
       fi
     fi
 
-    if [ "$VERBOSE" = "true" ]; then
-      echo "$j"
-    fi
-
     if [ "$DONT" = "false" ]; then
       tmp=$(mktemp /tmp/indent.XXXXXX)
       trap 'rm -f "$tmp"' HUP INT TERM EXIT
@@ -118,7 +120,7 @@ do
              -e '/ASN1_(ITEM_ref|ITEM_ptr|ITEM_rptr|PCTX)/ || s/^((ASN1|ADB)_[^\*]*[){=,]+[ \t]*)$/\/**INDENT-OFF**\/\n$1/;' \
              -e 's/^(} (ASN1|ADB)_[^\*]*[\){=,;]+)$/$1\n\/**INDENT-ON**\//;' \
              | \
-             indent $INDENT_ARGS | \
+             $DEBUG indent $INDENT_ARGS | \
              perl -np \
                -e 's/^([ \t]*)\/\*-(.*)\*\/[ \t]*$/$1\/*$2*\//;' \
                -e 's/^\/\*-((Copyright|=|----).*)$/\/* $1/;' \
@@ -133,7 +135,18 @@ do
          else
            expand "$j" | indent $INDENT_ARGS > "$tmp"
          fi;
-         mv "$tmp" "$j"
+         if cmp -s "$tmp" "$j"; then
+           if [ "$VERBOSE" = "true" ]; then
+             echo "$j unchanged"
+           fi
+           rm "$tmp"
+         else
+           if [ "$VERBOSE" = "true" ]; then
+             echo "$j changed"
+           fi
+           CHANGED=true
+           mv "$tmp" "$j"
+         fi
          ;;
       esac
     fi
@@ -141,3 +154,11 @@ do
 done
 
 
+if [ "$VERBOSE" = "true" ]; then
+  echo
+  if [ "$CHANGED" = "true" ]; then
+    echo "SOURCE WAS MODIFIED"
+  else
+    echo "SOURCE WAS NOT MODIFIED"
+  fi
+fi