Fix format script.
[openssl.git] / util / openssl-format-source
index e1606a7f40c7cbbae0c8c1494f151639e9b63678..4ea2f1bbd9f883b733d1cd0d894257ab75f4e08c 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
@@ -88,7 +90,7 @@ do
       case `basename $j` in 
        # the list of files that indent is unable to handle correctly
        # that we simply leave alone for manual formatting now
-       obj_dat.h|aes_core.c|aes_x86core.c)
+       obj_dat.h|aes_core.c|aes_x86core.c|ecp_nistz256.c)
          echo "skipping $j"
          ;;
        *)
@@ -114,11 +116,11 @@ do
              -e 's/^((DECLARE|IMPLEMENT)_(EXTERN_ASN1|ASN1|ADB|STACK_OF|PKCS12_STACK_OF).*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \
              -e 's/^([ \t]*(make_dh|make_dh_bn|make_rfc5114_td)\(.*\)[ \t,]*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \
              -e 's/^(ASN1_ADB_TEMPLATE\(.*)$/\/**INDENT-OFF**\/\n$1\n\/**INDENT-ON**\//;' \
-             -e 's/^((ASN1|ADB)_.*_END\(.*[\){=,;]+[ \t]*)$/$1\n\/**INDENT-ON**\//;' \
+             -e 's/^((ASN1|ADB)_.*_(end|END)\(.*[\){=,;]+[ \t]*)$/$1\n\/**INDENT-ON**\//;' \
              -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