Provide source reformating script. Requires GNU indent to be
authorTim Hudson <>
Mon, 5 Jan 2015 10:17:50 +0000 (10:17 +0000)
committerMatt Caswell <>
Thu, 22 Jan 2015 09:20:07 +0000 (09:20 +0000)

Script written by Tim Hudson, with amendments by Steve Henson, Rich Salz and
Matt Caswell

Reviewed-by: Matt Caswell <>
util/ [new file with mode: 0644]
util/openssl-format-source [new file with mode: 0755]

diff --git a/util/ b/util/
new file mode 100644 (file)
index 0000000..e871431
--- /dev/null
@@ -0,0 +1,751 @@
+-T AEP_U16
+-T AEP_U32
+-T AEP_U8
+-T ASIdOrRange
+-T ASIdOrRanges
+-T ASIdentifierChoice
+-T ASIdentifiers
+-T ASN1_const_CTX
+-T Bytef
+-T CMS_AuthenticatedData
+-T CMS_CertificateChoices
+-T CMS_CompressedData
+-T CMS_ContentInfo
+-T CMS_DigestedData
+-T CMS_EncapsulatedContentInfo
+-T CMS_EncryptedContentInfo
+-T CMS_EncryptedData
+-T CMS_EnvelopedData
+-T CMS_IssuerAndSerialNumber
+-T CMS_KEKIdentifier
+-T CMS_KEKRecipientInfo
+-T CMS_KeyAgreeRecipientIdentifier
+-T CMS_KeyAgreeRecipientInfo
+-T CMS_KeyTransRecipientInfo
+-T CMS_OriginatorIdentifierOrKey
+-T CMS_OriginatorInfo
+-T CMS_OriginatorPublicKey
+-T CMS_OtherCertificateFormat
+-T CMS_OtherKeyAttribute
+-T CMS_OtherRecipientInfo
+-T CMS_OtherRevocationInfoFormat
+-T CMS_PasswordRecipientInfo
+-T CMS_Receipt
+-T CMS_ReceiptRequest
+-T CMS_ReceiptsFrom
+-T CMS_RecipientEncryptedKey
+-T CMS_RecipientIdentifier
+-T CMS_RecipientInfo
+-T CMS_RecipientKeyIdentifier
+-T CMS_RevocationInfoChoice
+-T CMS_SignedData
+-T CMS_SignerIdentifier
+-T CMS_SignerInfo
+-T CRYPTO_EX_free
+-T CRYPTO_EX_free
+-T CRYPTO_dynlock_value
+-T DES_cblock
+-T DES_key_schedule
+-T DH
+-T Dl_info
+-T EC_builtin_curve
+-T EVP_PKEY_gen_cb
+-T IPAddrBlocks
+-T IPAddressFamily
+-T IPAddressOrRange
+-T IPAddressOrRanges
+-T P256_POINT
+-T PKCS12
+-T RC5_32_KEY
+-T SHA256_CTX
+-T SHA512_CTX
+-T SRP_gN_cache
+-T SRP_user_pwd
+-T SW_U16
+-T SW_U32
+-T SW_U64
+-T UI
+-T UINT64
+-T X509
+-T X509V3_CTX
+-T X509V3_EXT_D2I
+-T X509V3_EXT_I2D
+-T X509V3_EXT_I2R
+-T X509V3_EXT_I2S
+-T X509V3_EXT_NEW
+-T X509V3_EXT_R2I
+-T X509V3_EXT_S2I
+-T X509V3_EXT_V2I
+-T X509_ALGOR
+-T X509_CINF
+-T X509_CRL
+-T X509_INFO
+-T X509_NAME
+-T X509_PKEY
+-T X509_REQ
+-T X509_SIG
+-T X509_STORE
+-T X509_TRUST
+-T X509_VAL
+-T X9_62_CURVE
+-T __int64
+-T _ossl_old_des_cblock
+-T asn1_ps_func
+-T bio_dgram_data
+-T bio_info_cb
+-T char_io
+-T conf_finish_func
+-T conf_init_func
+-T const_DES_cblock
+-T d2i_of_void
+-T des_cblock
+-T dynamic_data_ctx
+-T dynamic_fns
+-T engine_table_doall_cb
+-T i2d_of_void
+-T int_dhx942_dh
+-T nid_triple
+-T pem_password_cb
+-T pitem
+-T piterator
+-T pqueue_s
+-T session_op
+-T size_t
+-T tag_exp_arg
+-T testdata
+-T time_t
+-T time_t
+-T u32
+-T u64
+-T u8
+-T v3_ext_ctx
+-T v3_ext_method
+-T STACK_OF_CMS_CertificateChoices_
+-T STACK_OF_CMS_RecipientEncryptedKey_
+-T STACK_OF_CMS_RecipientInfo_
+-T STACK_OF_CMS_RevocationInfoChoice_
+-T STACK_OF_CMS_SignerInfo_
+-T STACK_OF_CRYPTO_dynlock_
+-T STACK_OF_IPAddressFamily_
+-T STACK_OF_IPAddressOrRange_
+-T STACK_OF_Request_
+-T STACK_OF_SRP_gN_cache_
+-T STACK_OF_SRP_user_pwd_
+-T STACK_OF_SingleResponse_
+-T STACK_OF_X509_
+-T STACK_OF_nid_triple_
+-T STACK_OF_void_
+-T clock_t
+-T custom_ext_methods
+-T hm_fragment
+-T krb5_auth_context
+-T krb5_authdata
+-T krb5_ccache
+-T krb5_context
+-T krb5_creds
+-T krb5_data
+-T krb5_deltat
+-T krb5_flags
+-T krb5_int32
+-T krb5_keyblock
+-T krb5_keytab
+-T krb5_keytab_entry
+-T krb5_octet
+-T krb5_principal
+-T krb5_principal_data
+-T krb5_rcache
+-T krb5_ticket
+-T krb5_ticket_times
+-T krb5_timestamp
+-T record_pqueue
+-T ssl_ctx_st
+-T ssl_flag_tbl
+-T ssl_st
+-T ssl_trace_tbl
+-T _stdcall
+-T tls12_lookup
diff --git a/util/openssl-format-source b/util/openssl-format-source
new file mode 100755 (executable)
index 0000000..c1aada7
--- /dev/null
@@ -0,0 +1,157 @@
+# openssl-format-source 
+# - format source tree according to OpenSSL coding style using indent
+# usage:
+#   openssl-format-source [-v] [-n] [file|directory] ...
+# note: the indent options assume GNU indent v2.2.10 which was released
+#       Feb-2009 so if you have an older indent the options may not 
+#      match what is expected
+# any marked block comment blocks have to be moved to align manually after
+# the reformatting has been completed as marking a block causes indent to 
+# not move it at all ...
+export PATH
+set -e
+if [ $# -eq 0 ]; then
+  echo "usage: $0 [-v] [-n] [-c] [sourcefile|sourcedir] ..." >&2
+  exit 1
+# locate the indent configuration file to use which generally will be 
+# in the current directory but might be elsewhere and we want consistent
+# use of the file so we set the env var to point directly to the file in
+# our priority order
+if [ -z "$INDENT_PROFILE" ]; then
+  for i in . ../openssl $HOME
+  do
+    if [ -f "$i/" ]; then
+      INDENT_PROFILE="$i/"
+      export INDENT_PROFILE
+      break
+    fi
+  done
+if [ -z "$INDENT_PROFILE" ]; then
+  # If at the top of the source tree, try the file in util
+  if [ -f "e_os.h" ]; then 
+    f=`/bin/pwd`/util/
+    if [ -f $f ]; then
+      export INDENT_PROFILE
+    fi
+  fi
+if [ -z "$INDENT_PROFILE" ]; then
+  echo "$0: unable to locate file " >&2
+  exit 1
+# Extra arguments; for adding the comment-formatting
+for i 
+  if [ "$STOPARGS" != "true" ]; then
+    case $i in
+      --) STOPARGS="true"; continue;;
+      -n) DONT="true"; continue;;
+      -v) VERBOSE="true"; 
+         continue;;
+      -c) COMMENTS="true"; 
+         INDENT_ARGS="-fc1 -fca -cdb -sc"; 
+         continue;;
+    esac
+  fi
+  if [ -d "$i" ]; then
+    LIST=`find "$i" -name '*.[ch]' -print`
+  else 
+    if [ ! -f "$i" ]; then
+      echo "$0: source file not found: $i" >&2
+      exit 1
+    fi
+    LIST="$i"
+  fi
+  for j in $LIST
+  do
+    # ignore symlinks - we only ever process the base file - so if we
+    # expand a directory tree we need to ignore any located symlinks
+    if [ -d "$i" ]; then
+      if [ -h "$j" ]; then
+       continue;
+      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
+      case $j in 
+       # the list of files that indent is unable to handle correctly
+       # that we simply leave alone for manual formatting now
+       *)
+         if [ "$COMMENTS" = "true" ]; then
+           # we have to mark single line comments as /*- ...*/ to stop indent
+           # messing with them, run expand then indent as usual but with the
+           # the process-comments options and then undo that marking, and then 
+           # finally re-run indent without process-comments so the marked-to-
+           # be-ignored comments we did automatically end up getting moved 
+           # into the right possition within the code as indent leaves marked 
+           # comments entirely untouched - we appear to have no way to avoid 
+           # the double processing and get the desired output
+           perl -0 -np \
+             -e 's/(\n#[ \t]*ifdef[ \t]+__cplusplus\n[^\n]*\n#[ \t]*endif\n)/\n\n\/**INDENT-OFF**\/$1\/**INDENT-ON**\/\n/g;' \
+             -e 's/(\n\/\*\!)/\n\/**/g;' \
+             -e 's/(STACK_OF|LHASH_OF)\(([^ \t,\)]+)\) /$1_$2_ /g;' \
+             < "$j" | \
+           perl -np \
+             -e 's/^([ \t]*)\/\*([ \t]+.*)\*\/[ \t]*$/if (length("$1$2")<75) {$c="-"}else{$c=""}; "$1\/*$c$2*\/"/e;' \
+             -e 's/^\/\* ((Copyright|=|----).*)$/\/*-$1/;' \
+             -e 's/^((DECLARE|IMPLEMENT)_(EXTERN_ASN1|ASN1|ADB|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 '/ASN1_ITEM_(ref|ptr|rptr)/ || s/^((ASN1|ADB)_[^\*]*[){=,]+[ \t]*)$/\/**INDENT-OFF**\/\n$1/;' \
+             -e 's/^(} (ASN1|ADB)_[^\*]*[\){=,;]+)$/$1\n\/**INDENT-ON**\//;' \
+             | \
+             expand | indent $INDENT_ARGS | \
+             perl -np \
+               -e 's/^([ \t]*)\/\*-(.*)\*\/[ \t]*$/$1\/*$2*\//;' \
+               -e 's/^\/\*-((Copyright|=|----).*)$/\/* $1/;' \
+             | indent | \
+             perl -0 -np \
+               -e 's/\/\*\*INDENT-(ON|OFF)\*\*\/\n//g;' \
+             | perl -np \
+               -e 's/(STACK_OF|LHASH_OF)_([^ \t,]+)_( |\/)/$1($2)$3/g;' \
+               -e 's/(STACK_OF|LHASH_OF)_([^ \t,]+)_$/$1($2)/g;' \
+             > "$tmp"
+         else
+           expand "$j" | indent $INDENT_ARGS > "$tmp"
+         fi
+         ;;
+      esac
+      mv "$tmp" "$j"
+    fi
+  done