#!/bin/sh

# Known bugs:
#
# Blank line is added after, seen as a function definition, no space
# after *:
#	y = (int) x *y;

trap "rm -f /tmp/$$ /tmp/$$a" 0 1 2 3 15
entab </dev/null >/dev/null
if [ "$?" -ne 0 ]
then	echo "Go to the src/tools/entab directory and do a 'make' and 'make install'." >&2
	echo "This will put the 'entab' command in your path." >&2
	echo "Then run $0 again."
	exit 1
fi
indent -version </dev/null >/dev/null 2>&1
if [ "$?" -ne 1 ]
then	echo "You do not appear to have 'indent' installed on your system." >&2
	exit 1
fi
indent -gnu </dev/null >/dev/null 2>&1
if [ "$?" -eq 0 ]
then	echo "You appear to have GNU indent rather than BSD indent." >&2
	echo "See the pgindent/README file for a description of its problems." >&2
	EXTRA_OPTS="-cdb -bli0 -npcs -cli4 -sc"
else	echo "Hope you installed /src/tools/pgindent/indent.bsd.patch." >&2
	EXTRA_OPTS="-cli1"
fi

for FILE
do
	cat "$FILE" |
# convert // comments to /* */
	sed 's;^\([ 	]*\)//\(.*\)$;\1/* \2 */;g' |
# Avoid bug that converts 'x =- 1' to 'x = -1'
	sed 's;=- ;-= ;g' |
# mark some comments for special treatment later
	sed 's;/\*  *---;/*---X_X;g' |
# workaround for indent bug with 'else' handling
	sed 's;\([} 	]\)else[ 	]*\(/\*.*\)$;\1else\
\2;g' | 
	detab -t4 -qc |
# work around bug where function that defines no local variables misindents
# switch() case lines and line after #else.  Do not do for struct/enum.
	awk '	BEGIN	{line1 = ""; line2 = ""}
		{
			line2 = $0;
	 		if (NR >= 2)
				print line1;
			if (NR >= 2 &&
			    line2 ~ "^{[ 	]*$" &&
			    line1 !~ "^struct" &&
			    line1 !~ "^enum" &&
			    line1 !~ "^typedef" &&
			    line1 !~ "^extern[ 	][ 	]*\"C\"" &&
			    line1 !~ "=" &&
			    line1 ~ ")")
				print "int	pgindent_func_no_var_fix;";
			line1 = line2;
		}
		END {
			if (NR >= 1)
				print line1;
		}' |
# prevent indenting of code in 'extern "C"' blocks
	awk '	BEGIN	{line1 = ""; line2 = ""; skips = 0}
		{
			line2 = $0;
			if (skips > 0)
				skips--;
			if (line1 ~ "^#ifdef[ 	]*__cplusplus" &&
			    line2 ~ "^extern[ 	]*\"C\"[ 	]*$")
			{
				print line1;
				print line2;
				if (getline && $0 ~ /^{[ 	]*$/)
					print "/* Open extern \"C\" */";
				else	print $0;
				line2 = "";
				skips = 2;
			}
			else if (line1 ~ "^#ifdef[ 	]*__cplusplus" &&
			    line2 ~ "^}[ 	]*$")
			{
				print line1;
				print "/* Close extern \"C\" */";
				line2 = "";
				skips = 2;
			}
			else
	 			if (skips == 0 && NR >= 2)
					print line1;
			line1 = line2;
		}
		END {
			if (NR >= 1 && skips <= 1)
				print line1;
		}' |
# protect backslashes in DATA()
	sed 's;^DATA(.*$;/*&*/;' |
# protect wrapping in CATALOG()
	sed 's;^CATALOG(.*$;/*&*/;' >/tmp/$$a

# We get the list of typedef's from /src/tools/find_typedef
	indent -bad -bap -bc -bl -d0 -cdb -nce -nfc1 -di12 -i4 -l75 \
		-lp -nip -npro -bbb $EXTRA_OPTS \
-TASN1_BIT_STRING \
-TASN1_BMPSTRING \
-TASN1_BOOLEAN \
-TASN1_CTX \
-TASN1_ENUMERATED \
-TASN1_GENERALIZEDTIME \
-TASN1_GENERALSTRING \
-TASN1_HEADER \
-TASN1_IA5STRING \
-TASN1_INTEGER \
-TASN1_METHOD \
-TASN1_NULL \
-TASN1_OBJECT \
-TASN1_OCTET_STRING \
-TASN1_PRINTABLESTRING \
-TASN1_STRING \
-TASN1_STRING_TABLE \
-TASN1_T61STRING \
-TASN1_TIME \
-TASN1_TYPE \
-TASN1_UNIVERSALSTRING \
-TASN1_UTCTIME \
-TASN1_UTF8STRING \
-TASN1_VISIBLESTRING \
-TA_Const \
-TA_Expr \
-TA_Expr_Kind \
-TA_Indices \
-TAbsoluteTime \
-TAcl \
-TAclId \
-TAclItem \
-TAclMode \
-TAclObjectKind \
-TAclResult \
-TAgg \
-TAggHashEntry \
-TAggHashEntryData \
-TAggInfo \
-TAggState \
-TAggStatePerAgg \
-TAggStatePerAggData \
-TAggStatePerGroup \
-TAggStatePerGroupData \
-TAggStrategy \
-TAggref \
-TAggrefExprState \
-TAlgCode \
-TAlias \
-TAllocBlock \
-TAllocBlockData \
-TAllocChunk \
-TAllocChunkData \
-TAllocPointer \
-TAllocSet \
-TAllocSetContext \
-TAlterDatabaseSetStmt \
-TAlterDomainStmt \
-TAlterGroupStmt \
-TAlterSeqStmt \
-TAlterTableStmt \
-TAlterUserSetStmt \
-TAlterUserStmt \
-TAppend \
-TAppendPath \
-TAppendState \
-TArchive \
-TArchiveEntryPtr \
-TArchiveFormat \
-TArchiveHandle \
-TArchiveMode \
-TArrayBuildState \
-TArrayExpr \
-TArrayExprState \
-TArrayMetaState \
-TArrayRef \
-TArrayRefExprState \
-TArrayType \
-TAtom \
-TAttInMetadata \
-TAttrDefault \
-TAttrNumber \
-TAuthRequest \
-TBF_KEY \
-TBIGNUM \
-TBIO \
-TBIO_F_BUFFER_CTX \
-TBIO_METHOD \
-TBIO_dummy \
-TBIT_STRING_BITNAME \
-TBMS_Membership \
-TBN_BLINDING \
-TBN_CTX \
-TBN_MONT_CTX \
-TBN_RECP_CTX \
-TBOX \
-TBTBuildState \
-TBTItem \
-TBTItemData \
-TBTMetaPageData \
-TBTPageOpaque \
-TBTPageOpaqueData \
-TBTPageState \
-TBTScanOpaque \
-TBTScanOpaqueData \
-TBTSpool \
-TBTStack \
-TBTStackData \
-TBUF_MEM \
-TBackend \
-TBackendId \
-TBitmapset \
-TBkpBlock \
-TBlock \
-TBlockId \
-TBlockIdData \
-TBlockNumber \
-TBoolExpr \
-TBoolExprState \
-TBoolExprType \
-TBoolPtr \
-TBoolTestType \
-TBooleanTest \
-TBpChar \
-TBucket \
-TBufFile \
-TBufFlags \
-TBuffer \
-TBufferDesc \
-TBufferLookupEnt \
-TBufferTag \
-TByte \
-TBytef \
-TCAST_KEY \
-TCATEGORY \
-TCBC_PARAM \
-TCIRCLE \
-TCOMP_CTX \
-TCOMP_METHOD \
-TCONSTRAINTCATEGORY \
-TCPFunction \
-TCPPFunction \
-TCRYPTO_EX_DATA \
-TCRYPTO_EX_DATA_FUNCS \
-TCRYPTO_EX_dup \
-TCRYPTO_EX_free \
-TCRYPTO_EX_new \
-TCRYPTO_dynlock \
-TCacheCallbackFunction \
-TCancelRequestPacket \
-TCaseExpr \
-TCaseExprState \
-TCaseWhen \
-TCaseWhenState \
-TCash \
-TCatCList \
-TCatCTup \
-TCatCache \
-TCatCacheHeader \
-TCatalogIndexState \
-TChangeVarNodes_context \
-TCheckPoint \
-TCheckPointStmt \
-TChromosome \
-TCity \
-TClientData \
-TClosePortalStmt \
-TClosePtr \
-TClusterStmt \
-TCmdType \
-TCoalesceExpr \
-TCoalesceExprState \
-TCoerceToDomain \
-TCoerceToDomainState \
-TCoerceToDomainValue \
-TCoercionCodes \
-TCoercionContext \
-TCoercionForm \
-TColormap \
-TColumnDef \
-TColumnRef \
-TCommandDest \
-TCommandId \
-TCommentStmt \
-TCompositeTypeStmt \
-TConnStatusType \
-TConst \
-TConstrCheck \
-TConstrType \
-TConstraint \
-TConstraintsSetStmt \
-TControlFileData \
-TCopyDest \
-TCopyReadResult \
-TCopyStmt \
-TCost \
-TCostSelector \
-TCreateCastStmt \
-TCreateConversionStmt \
-TCreateDomainStmt \
-TCreateFunctionStmt \
-TCreateGroupStmt \
-TCreateOpClassItem \
-TCreateOpClassStmt \
-TCreatePLangStmt \
-TCreateSchemaStmt \
-TCreateSchemaStmtContext \
-TCreateSeqStmt \
-TCreateStmt \
-TCreateStmtContext \
-TCreateTrigStmt \
-TCreateUserStmt \
-TCreatedbStmt \
-TCred \
-TCursor \
-TCustomOutPtr \
-TDBState \
-TDCHCacheEntry \
-TDCH_poz \
-TDEADLOCK_INFO \
-TDH \
-TDH_METHOD \
-TDIR \
-TDR_printtup \
-TDSA \
-TDSA_METHOD \
-TDSA_SIG \
-TDataDumperPtr \
-TDateADT \
-TDatum \
-TDatumPtr \
-TDatumTuple \
-TDeallocateStmt \
-TDeclareCursorStmt \
-TDefElem \
-TDeferredTriggerEvent \
-TDeferredTriggerEventData \
-TDeferredTriggerEventItem \
-TDeferredTriggerStatus \
-TDeferredTriggerStatusData \
-TDeferredTriggers \
-TDeferredTriggersData \
-TDefineStmt \
-TDeleteStmt \
-TDependencyType \
-TDepth \
-TDestReceiver \
-TDisplay \
-TDistinctExpr \
-TDl_info \
-TDlelem \
-TDllist \
-TDomainConstraintState \
-TDomainConstraintType \
-TDrawable \
-TDropBehavior \
-TDropCastStmt \
-TDropGroupStmt \
-TDropPLangStmt \
-TDropPropertyStmt \
-TDropStmt \
-TDropUserStmt \
-TDropdbStmt \
-TDumpContext \
-TDynamicFileList \
-TEDGE \
-TERR_STATE \
-TERR_STRING_DATA \
-TEState \
-TEVP_CIPHER \
-TEVP_CIPHER_CTX \
-TEVP_CIPHER_INFO \
-TEVP_ENCODE_CTX \
-TEVP_MD \
-TEVP_MD_CTX \
-TEVP_PBE_KEYGEN \
-TEVP_PKEY \
-TEdge \
-TEndBlobPtr \
-TEndBlobsPtr \
-TEndDataPtr \
-TEolType \
-TErrorContextCallback \
-TErrorData \
-TExecScanAccessMtd \
-TExecStatus \
-TExecStatusType \
-TExecuteStmt \
-TExplainState \
-TExplainStmt \
-TExpr \
-TExprContext \
-TExprContextCallbackFunction \
-TExprContext_CB \
-TExprDoneCond \
-TExprFieldSelect \
-TExprState \
-TFILE \
-TFSMHeader \
-TFSMPageData \
-TFSMRelation \
-TFUNMAP \
-TFastList \
-TFetchDirection \
-TFetchStmt \
-TFieldSelect \
-TFile \
-TFileName \
-TFindSplitData \
-TFkConstraint \
-TFmgrBuiltin \
-TFmgrInfo \
-TFont \
-TFormData_pg_aggregate \
-TFormData_pg_am \
-TFormData_pg_amop \
-TFormData_pg_amproc \
-TFormData_pg_attrdef \
-TFormData_pg_attribute \
-TFormData_pg_cast \
-TFormData_pg_class \
-TFormData_pg_constraint \
-TFormData_pg_conversion \
-TFormData_pg_database \
-TFormData_pg_depend \
-TFormData_pg_description \
-TFormData_pg_group \
-TFormData_pg_index \
-TFormData_pg_inherits \
-TFormData_pg_language \
-TFormData_pg_largeobject \
-TFormData_pg_listener \
-TFormData_pg_namespace \
-TFormData_pg_opclass \
-TFormData_pg_operator \
-TFormData_pg_proc \
-TFormData_pg_rewrite \
-TFormData_pg_sequence \
-TFormData_pg_shadow \
-TFormData_pg_statistic \
-TFormData_pg_trigger \
-TFormData_pg_type \
-TForm_pg_aggregate \
-TForm_pg_am \
-TForm_pg_amop \
-TForm_pg_amproc \
-TForm_pg_attrdef \
-TForm_pg_attribute \
-TForm_pg_cast \
-TForm_pg_class \
-TForm_pg_constraint \
-TForm_pg_conversion \
-TForm_pg_database \
-TForm_pg_depend \
-TForm_pg_description \
-TForm_pg_group \
-TForm_pg_index \
-TForm_pg_inherits \
-TForm_pg_language \
-TForm_pg_largeobject \
-TForm_pg_listener \
-TForm_pg_namespace \
-TForm_pg_opclass \
-TForm_pg_operator \
-TForm_pg_proc \
-TForm_pg_rewrite \
-TForm_pg_sequence \
-TForm_pg_shadow \
-TForm_pg_statistic \
-TForm_pg_trigger \
-TForm_pg_type \
-TFormatNode \
-TFromExpr \
-TFsmCacheFileHeader \
-TFsmCacheRelHeader \
-TFuncCall \
-TFuncCallContext \
-TFuncCandidateList \
-TFuncDetailCode \
-TFuncExpr \
-TFuncExprState \
-TFuncInfo \
-TFuncWithArgs \
-TFunction \
-TFunctionCallInfo \
-TFunctionCallInfoData \
-TFunctionScan \
-TFunctionScanState \
-TGC \
-TGContext \
-TGISTBuildState \
-TGISTENTRY \
-TGISTPageOpaque \
-TGISTPageOpaqueData \
-TGISTSTACK \
-TGISTSTATE \
-TGISTScanList \
-TGISTScanListData \
-TGISTScanOpaque \
-TGISTScanOpaqueData \
-TGIST_SPLITVEC \
-TGUC_yy_size_t \
-TGUC_yy_state_type \
-TGene \
-TGenericExprState \
-TGrantObjectType \
-TGrantStmt \
-TGroup \
-TGroupClause \
-TGroupState \
-TGucContext \
-TGucSource \
-THASHACTION \
-THASHBUCKET \
-THASHCTL \
-THASHELEMENT \
-THASHHDR \
-THASHSEGMENT \
-THASH_SEQ_STATUS \
-THISTORY_STATE \
-THIST_ENTRY \
-THTAB \
-THTSV_Result \
-THash \
-THashBuildState \
-THashItem \
-THashItemData \
-THashJoin \
-THashJoinState \
-THashJoinTable \
-THashJoinTuple \
-THashJoinTupleData \
-THashMetaPage \
-THashMetaPageData \
-THashPageOpaque \
-THashPageOpaqueData \
-THashPath \
-THashScanList \
-THashScanListData \
-THashScanOpaque \
-THashScanOpaqueData \
-THashState \
-THashTableData \
-THeapScanDesc \
-THeapScanDescData \
-THeapTuple \
-THeapTupleData \
-THeapTupleHeader \
-THeapTupleHeaderData \
-TIOFuncSelector \
-TIdList \
-TInClauseInfo \
-TIncrementVarSublevelsUp_context \
-TIndex \
-TIndexAttributeBitMap \
-TIndexAttributeBitMapData \
-TIndexAttrs \
-TIndexBuildCallback \
-TIndexBulkDeleteCallback \
-TIndexBulkDeleteResult \
-TIndexElem \
-TIndexFSMPageData \
-TIndexInfo \
-TIndexList \
-TIndexOptInfo \
-TIndexPath \
-TIndexScan \
-TIndexScanDesc \
-TIndexScanDescData \
-TIndexScanDescPtr \
-TIndexScanState \
-TIndexStmt \
-TIndexStrategy \
-TIndexStrategyData \
-TIndexTuple \
-TIndexTupleData \
-TIndexVacuumCleanupInfo \
-TIndirectBlock \
-TInhInfo \
-TInhOption \
-TInhPaths \
-TInhRelation \
-TInnerIndexscanInfo \
-TInsertIndexResult \
-TInsertIndexResultData \
-TInsertStmt \
-TInstrumentation \
-TInt8TransTypeData \
-TIntArray \
-TInt_yy_size_t \
-TInt_yy_state_type \
-TInt_yysigned_char \
-TInterval \
-TInvalidationChunk \
-TInvalidationListHeader \
-TIpcMemoryId \
-TIpcMemoryKey \
-TIpcSemaphoreId \
-TIpcSemaphoreKey \
-TItem \
-TItemId \
-TItemIdData \
-TItemIdFlags \
-TItemLength \
-TItemOffset \
-TItemPointer \
-TItemPointerData \
-TJoin \
-TJoinExpr \
-TJoinInfo \
-TJoinPath \
-TJoinState \
-TJoinType \
-TJunkFilter \
-TKEYMAP_ENTRY \
-TKEYMAP_ENTRY_ARRAY \
-TKeyCode \
-TKeySuffix \
-TKeySym \
-TKeyWord \
-TKeymap \
-TLHASH \
-TLHASH_NODE \
-TLINE \
-TLOCK \
-TLOCKMASK \
-TLOCKMETHOD \
-TLOCKMETHODTABLE \
-TLOCKMODE \
-TLOCKTAG \
-TLSEG \
-TLVRelStats \
-TLWLock \
-TLWLockId \
-TLWLockMode \
-TLargeObjectDesc \
-TLimit \
-TLimitState \
-TLimitStateCond \
-TList \
-TListenStmt \
-TLoadStmt \
-TLocationIndex \
-TLockData \
-TLockInfo \
-TLockInfoData \
-TLockRelId \
-TLockStmt \
-TLogicalTape \
-TLogicalTapeSet \
-TMD2_CTX \
-TMD4_CTX \
-TMD5_CTX \
-TMDC2_CTX \
-TMask \
-TMaterial \
-TMaterialPath \
-TMaterialState \
-TMdfdVec \
-TMemoryContext \
-TMemoryContextData \
-TMemoryContextMethods \
-TMergeJoin \
-TMergeJoinState \
-TMergePath \
-TMsgType \
-TMyVarInfo \
-TNETSCAPE_CERT_SEQUENCE \
-TNETSCAPE_SPKAC \
-TNETSCAPE_SPKI \
-TNUMCacheEntry \
-TNUMDesc \
-TNUMProc \
-TNUM_poz \
-TName \
-TNameData \
-TNamespaceInfo \
-TNestLoop \
-TNestLoopState \
-TNestPath \
-TNode \
-TNodeTag \
-TNotifyStmt \
-TNullIfExpr \
-TNullTest \
-TNullTestType \
-TNumeric \
-TNumericData \
-TNumericDigit \
-TNumericVar \
-TOBJ_NAME \
-TObjectAddress \
-TObjectAddresses \
-TObjectClasses \
-TObjectType \
-TOffset \
-TOffsetNumber \
-TOffsetVarNodes_context \
-TOid \
-TOidOptions \
-TOldstyle_fnextra \
-TOnCommitAction \
-TOnCommitItem \
-TOpClassCacheEnt \
-TOpExpr \
-TOpclassCandidateList \
-TOpclassInfo \
-TOperator \
-TOprInfo \
-TOutputContext \
-TOverflowPageAddress \
-TPATH \
-TPBE2PARAM \
-TPBEPARAM \
-TPBKDF2PARAM \
-TPEM_CTX \
-TPEM_ENCODE_SEAL_CTX \
-TPEM_USER \
-TPGErrorVerbosity \
-TPGFInfoFunction \
-TPGFunction \
-TPGLZ_DecompState \
-TPGLZ_Header \
-TPGLZ_HistEntry \
-TPGLZ_Strategy \
-TPGPROC \
-TPGSemaphore \
-TPGSemaphoreData \
-TPGShmemHeader \
-TPGTransactionStatusType \
-TPGVerbosity \
-TPG_Lock_Status \
-TPGconn \
-TPGnotify \
-TPGresult \
-TPKCS7 \
-TPKCS7_DIGEST \
-TPKCS7_ENCRYPT \
-TPKCS7_ENC_CONTENT \
-TPKCS7_ENVELOPE \
-TPKCS7_ISSUER_AND_SERIAL \
-TPKCS7_RECIP_INFO \
-TPKCS7_SIGNED \
-TPKCS7_SIGNER_INFO \
-TPKCS7_SIGN_ENVELOPE \
-TPKCS8_PRIV_KEY_INFO \
-TPMSignalReason \
-TPOLYGON \
-TPQArgBlock \
-TPQExpBuffer \
-TPQExpBufferData \
-TPQconninfoOption \
-TPQnoticeProcessor \
-TPQnoticeReceiver \
-TPQprintOpt \
-TPROCLOCK \
-TPROCLOCKTAG \
-TPROC_HDR \
-TPROC_QUEUE \
-TPacketLen \
-TPage \
-TPageFreeSpaceInfo \
-TPageHeader \
-TPageHeaderData \
-TPageOffset \
-TParam \
-TParamExecData \
-TParamListInfo \
-TParamListInfoData \
-TParamRef \
-TParseState \
-TPath \
-TPathKeyItem \
-TPathKeysComparison \
-TPattern_Prefix_Status \
-TPattern_Type \
-TPendingRelDelete \
-TPgStat_Counter \
-TPgStat_Info \
-TPgStat_Msg \
-TPgStat_MsgActivity \
-TPgStat_MsgBestart \
-TPgStat_MsgBeterm \
-TPgStat_MsgDropdb \
-TPgStat_MsgDummy \
-TPgStat_MsgHdr \
-TPgStat_MsgResetcounter \
-TPgStat_MsgTabpurge \
-TPgStat_MsgTabstat \
-TPgStat_StatBeDead \
-TPgStat_StatBeEntry \
-TPgStat_StatDBEntry \
-TPgStat_StatTabEntry \
-TPgStat_TableEntry \
-TPg_finfo_record \
-TPixmap \
-TPlan \
-TPlanState \
-TPlannerParamItem \
-TPoint \
-TPointer \
-TPool \
-TPort \
-TPortal \
-TPortalData \
-TPortalHashEnt \
-TPortalStrategy \
-TPostgresPollingStatusType \
-TPrepareStmt \
-TPreparedStatement \
-TPrintExtraTocPtr \
-TPrintTocDataPtr \
-TPrinttupAttrInfo \
-TPrivGrantee \
-TPrivTarget \
-TProcState \
-TProcessingMode \
-TProjectionInfo \
-TProtocolVersion \
-TPsqlSettings \
-TQualCost \
-TQuery \
-TQueryDesc \
-TQuerySource \
-TRC2_KEY \
-TRC4_KEY \
-TRIPEMD160_CTX \
-TRI_OpreqHashEntry \
-TRI_QueryHashEntry \
-TRI_QueryKey \
-TRSA \
-TRSA_METHOD \
-TRTBuildState \
-TRTEKind \
-TRTSTACK \
-TRTSTATE \
-TRTScanList \
-TRTScanListData \
-TRTreePageOpaque \
-TRTreePageOpaqueData \
-TRTreeScanOpaque \
-TRTreeScanOpaqueData \
-TRangeFunction \
-TRangeQueryClause \
-TRangeSubselect \
-TRangeTblEntry \
-TRangeTblRef \
-TRangeVar \
-TRawColumnDefault \
-TReadBufPtr \
-TReadBytePtr \
-TReadExtraTocPtr \
-TRegProcedure \
-TReindexStmt \
-TRelFileNode \
-TRelIdCacheEnt \
-TRelNameCacheEnt \
-TRelNodeCacheEnt \
-TRelOptInfo \
-TRelOptKind \
-TRelToCheck \
-TRelToCluster \
-TRelabelType \
-TRelation \
-TRelationBuildDescInfo \
-TRelationData \
-TRelationPtr \
-TRelativeTime \
-TRelids \
-TRemoveAggrStmt \
-TRemoveFuncStmt \
-TRemoveOpClassStmt \
-TRemoveOperStmt \
-TRenameStmt \
-TResTarget \
-TResdom \
-TResolveNew_context \
-TRestoreOptions \
-TRestrictInfo \
-TResult \
-TResultPath \
-TResultRelInfo \
-TResultState \
-TReturnSetInfo \
-TRewriteRule \
-TRmgrData \
-TRmgrId \
-TRuleLock \
-TRuleStmt \
-TSHA_CTX \
-TSHMEM_OFFSET \
-TSHM_QUEUE \
-TSISeg \
-TSPITupleTable \
-TSPLITCOST \
-TSPLITVEC \
-TSQLFunctionCache \
-TSQLFunctionCachePtr \
-TSSL \
-TSSL2_STATE \
-TSSL3_BUFFER \
-TSSL3_RECORD \
-TSSL3_STATE \
-TSSL_CIPHER \
-TSSL_COMP \
-TSSL_CTX \
-TSSL_METHOD \
-TSSL_SESSION \
-TSTACK \
-TSaveArchivePtr \
-TScalarArrayOpExpr \
-TScalarArrayOpExprState \
-TScalarItem \
-TScalarMCVItem \
-TScan \
-TScanDirection \
-TScanKey \
-TScanKeyData \
-TScanKeyword \
-TScanState \
-TScreen \
-TScreenFormat \
-TSelectStmt \
-TSelectivity \
-TSeqScan \
-TSeqScanState \
-TSeqTable \
-TSeqTableData \
-TSetFunctionReturnMode \
-TSetOp \
-TSetOpCmd \
-TSetOpState \
-TSetOperation \
-TSetOperationStmt \
-TSetToDefault \
-TSharedInvalCatcacheMsg \
-TSharedInvalRelcacheMsg \
-TSharedInvalidationMessage \
-TShmemIndexEnt \
-TSigHandler \
-TSize \
-TSlruCtl \
-TSlruCtlData \
-TSlruErrorCause \
-TSlruLock \
-TSlruLockData \
-TSlruPageStatus \
-TSlruShared \
-TSlruSharedData \
-TSnapshot \
-TSnapshotData \
-TSockAddr \
-TSort \
-TSortClause \
-TSortFunctionKind \
-TSortGroupBy \
-TSortState \
-TSplitNumber \
-TStandardChunkHeader \
-TStartBlobPtr \
-TStartBlobsPtr \
-TStartDataPtr \
-TStartUpID \
-TStartupPacket \
-TStrategyEvaluation \
-TStrategyEvaluationData \
-TStrategyExpression \
-TStrategyExpressionData \
-TStrategyMap \
-TStrategyMapData \
-TStrategyNumber \
-TStrategyOperator \
-TStrategyOperatorData \
-TStrategyTerm \
-TStrategyTermData \
-TStrategyTransformMap \
-TStrategyTransformMapData \
-TStringInfo \
-TStringInfoData \
-TSubLink \
-TSubLinkType \
-TSubPlan \
-TSubPlanState \
-TSubqueryScan \
-TSubqueryScanState \
-TSysScanDesc \
-TSysScanDescData \
-TTAR_MEMBER \
-TTBlockState \
-TTStoreState \
-TTableInfo \
-TTargetEntry \
-TTclStubHooks \
-TTclStubs \
-TTcl_AppInitProc \
-TTcl_AsyncHandler \
-TTcl_AsyncProc \
-TTcl_CallFrame \
-TTcl_Channel \
-TTcl_ChannelProc \
-TTcl_ChannelType \
-TTcl_ChannelTypeVersion \
-TTcl_CloseProc \
-TTcl_CmdDeleteProc \
-TTcl_CmdInfo \
-TTcl_CmdProc \
-TTcl_CmdTraceProc \
-TTcl_Command \
-TTcl_Condition \
-TTcl_CreateFileHandlerProc \
-TTcl_DString \
-TTcl_DeleteFileHandlerProc \
-TTcl_DriverBlockModeProc \
-TTcl_DriverClose2Proc \
-TTcl_DriverCloseProc \
-TTcl_DriverFlushProc \
-TTcl_DriverGetHandleProc \
-TTcl_DriverGetOptionProc \
-TTcl_DriverHandlerProc \
-TTcl_DriverInputProc \
-TTcl_DriverOutputProc \
-TTcl_DriverSeekProc \
-TTcl_DriverSetOptionProc \
-TTcl_DriverWatchProc \
-TTcl_DupInternalRepProc \
-TTcl_Encoding \
-TTcl_EncodingConvertProc \
-TTcl_EncodingFreeProc \
-TTcl_EncodingState \
-TTcl_EncodingType \
-TTcl_EolTranslation \
-TTcl_Event \
-TTcl_EventCheckProc \
-TTcl_EventDeleteProc \
-TTcl_EventProc \
-TTcl_EventSetupProc \
-TTcl_ExitProc \
-TTcl_FileFreeProc \
-TTcl_FileProc \
-TTcl_FreeInternalRepProc \
-TTcl_FreeProc \
-TTcl_HashEntry \
-TTcl_HashSearch \
-TTcl_HashTable \
-TTcl_IdleProc \
-TTcl_Interp \
-TTcl_InterpDeleteProc \
-TTcl_MainLoopProc \
-TTcl_MathProc \
-TTcl_Mutex \
-TTcl_Namespace \
-TTcl_NamespaceDeleteProc \
-TTcl_NotifierProcs \
-TTcl_Obj \
-TTcl_ObjCmdProc \
-TTcl_ObjType \
-TTcl_PackageInitProc \
-TTcl_PanicProc \
-TTcl_Parse \
-TTcl_PathType \
-TTcl_Pid \
-TTcl_QueuePosition \
-TTcl_RegExp \
-TTcl_RegExpIndices \
-TTcl_RegExpInfo \
-TTcl_SavedResult \
-TTcl_SetFromAnyProc \
-TTcl_SetTimerProc \
-TTcl_Stat_ \
-TTcl_TcpAcceptProc \
-TTcl_ThreadCreateProc \
-TTcl_ThreadDataKey \
-TTcl_ThreadId \
-TTcl_Time \
-TTcl_TimerProc \
-TTcl_TimerToken \
-TTcl_Token \
-TTcl_Trace \
-TTcl_UniChar \
-TTcl_UpdateStringProc \
-TTcl_Value \
-TTcl_ValueType \
-TTcl_Var \
-TTcl_VarTraceProc \
-TTcl_WaitForEventProc \
-TThingFile \
-TTidPath \
-TTidScan \
-TTidScanState \
-TTime \
-TTimeADT \
-TTimeInterval \
-TTimeIntervalData \
-TTimeTzADT \
-TTimestamp \
-TTimestampTz \
-TTimevalStruct \
-TTkStubHooks \
-TTkStubs \
-TTk_3DBorder \
-TTk_Anchor \
-TTk_ArgvInfo \
-TTk_BindingTable \
-TTk_Canvas \
-TTk_CanvasTextInfo \
-TTk_ClientMessageProc \
-TTk_ConfigSpec \
-TTk_ConfigTypes \
-TTk_Cursor \
-TTk_CustomOption \
-TTk_Dash \
-TTk_ErrorHandler \
-TTk_ErrorProc \
-TTk_EventProc \
-TTk_FakeWin \
-TTk_Font \
-TTk_FontMetrics \
-TTk_GenericProc \
-TTk_GeomLostSlaveProc \
-TTk_GeomMgr \
-TTk_GeomRequestProc \
-TTk_GetSelProc \
-TTk_Image \
-TTk_ImageChangedProc \
-TTk_ImageCreateProc \
-TTk_ImageDeleteProc \
-TTk_ImageDisplayProc \
-TTk_ImageFileMatchProc \
-TTk_ImageFileReadProc \
-TTk_ImageFileWriteProc \
-TTk_ImageFreeProc \
-TTk_ImageGetProc \
-TTk_ImageMaster \
-TTk_ImagePostscriptProc \
-TTk_ImageStringMatchProc \
-TTk_ImageStringReadProc \
-TTk_ImageStringWriteProc \
-TTk_ImageType \
-TTk_Item \
-TTk_ItemAreaProc \
-TTk_ItemConfigureProc \
-TTk_ItemCoordProc \
-TTk_ItemCreateProc \
-TTk_ItemCursorProc \
-TTk_ItemDCharsProc \
-TTk_ItemDeleteProc \
-TTk_ItemDisplayProc \
-TTk_ItemIndexProc \
-TTk_ItemInsertProc \
-TTk_ItemPointProc \
-TTk_ItemPostscriptProc \
-TTk_ItemScaleProc \
-TTk_ItemSelectionProc \
-TTk_ItemTranslateProc \
-TTk_ItemType \
-TTk_Justify \
-TTk_LostSelProc \
-TTk_OptionParseProc \
-TTk_OptionPrintProc \
-TTk_OptionSpec \
-TTk_OptionTable \
-TTk_OptionType \
-TTk_Outline \
-TTk_PhotoHandle \
-TTk_PhotoImageBlock \
-TTk_PhotoImageFormat \
-TTk_PostscriptInfo \
-TTk_RestrictAction \
-TTk_RestrictProc \
-TTk_SavedOption \
-TTk_SavedOptions \
-TTk_SelectionProc \
-TTk_SmoothMethod \
-TTk_State \
-TTk_TSOffset \
-TTk_TextLayout \
-TTk_Uid \
-TTk_Window \
-TTmFromChar \
-TTmToChar \
-TTocEntry \
-TTocSortCompareFn \
-TTrackItem \
-TTransState \
-TTransactionId \
-TTransactionState \
-TTransactionStateData \
-TTransactionStmt \
-TTransactionStmtKind \
-TTrigger \
-TTriggerData \
-TTriggerDesc \
-TTriggerEvent \
-TTruncateStmt \
-TTupOutputState \
-TTupSortStatus \
-TTupStoreStatus \
-TTupleConstr \
-TTupleDesc \
-TTupleHashEntry \
-TTupleHashEntryData \
-TTupleHashIterator \
-TTupleHashTable \
-TTupleHashTableData \
-TTupleTable \
-TTupleTableData \
-TTupleTableSlot \
-TTuplesortstate \
-TTuplestorestate \
-TType \
-TTypeCast \
-TTypeInfo \
-TTypeName \
-TUNDO_LIST \
-TUnique \
-TUniquePath \
-TUniqueState \
-TUnlistenStmt \
-TUpdateStmt \
-TUserAuth \
-TVFunction \
-TVRelStats \
-TVTupleLink \
-TVTupleLinkData \
-TVTupleMove \
-TVTupleMoveData \
-TVacAttrStats \
-TVacPage \
-TVacPageData \
-TVacPageList \
-TVacPageListData \
-TVacRUsage \
-TVacuumStmt \
-TValue \
-TVar \
-TVarBit \
-TVarChar \
-TVariableCache \
-TVariableCacheData \
-TVariableResetStmt \
-TVariableSetStmt \
-TVariableShowStmt \
-TVariableSpace \
-TVfd \
-TViewStmt \
-TVisual \
-TVisualID \
-TWAIT_ORDER \
-TWindow \
-TWriteBufPtr \
-TWriteBytePtr \
-TWriteDataPtr \
-TWriteExtraTocPtr \
-TX509 \
-TX509_ALGOR \
-TX509_ATTRIBUTE \
-TX509_CERT_AUX \
-TX509_CERT_FILE_CTX \
-TX509_CINF \
-TX509_CRL \
-TX509_CRL_INFO \
-TX509_EXTENSION \
-TX509_HASH_DIR_CTX \
-TX509_INFO \
-TX509_LOOKUP \
-TX509_LOOKUP_METHOD \
-TX509_NAME \
-TX509_NAME_ENTRY \
-TX509_OBJECT \
-TX509_OBJECTS \
-TX509_PKEY \
-TX509_PUBKEY \
-TX509_REQ \
-TX509_REQ_INFO \
-TX509_REVOKED \
-TX509_SIG \
-TX509_STORE \
-TX509_STORE_CTX \
-TX509_TRUST \
-TX509_VAL \
-TXActivateDeactivateEvent \
-TXActivateEvent \
-TXAnyEvent \
-TXArc \
-TXButtonEvent \
-TXButtonPressedEvent \
-TXButtonReleasedEvent \
-TXChar2b \
-TXCharStruct \
-TXCirculateEvent \
-TXCirculateRequestEvent \
-TXClientMessageEvent \
-TXColor \
-TXColormapEvent \
-TXConfigureEvent \
-TXConfigureRequestEvent \
-TXConnectionWatchProc \
-TXCreateWindowEvent \
-TXCrossingEvent \
-TXDeactivateEvent \
-TXDestroyWindowEvent \
-TXEDataObject \
-TXEnterWindowEvent \
-TXErrorEvent \
-TXErrorHandler \
-TXEvent \
-TXExposeEvent \
-TXExtCodes \
-TXExtData \
-TXFocusChangeEvent \
-TXFocusInEvent \
-TXFocusOutEvent \
-TXFontProp \
-TXFontSet \
-TXFontSetExtents \
-TXFontStruct \
-TXGCValues \
-TXGraphicsExposeEvent \
-TXGravityEvent \
-TXHostAddress \
-TXIC \
-TXICCallback \
-TXICProc \
-TXID \
-TXIDProc \
-TXIM \
-TXIMCallback \
-TXIMCaretDirection \
-TXIMCaretStyle \
-TXIMFeedback \
-TXIMHotKeyState \
-TXIMHotKeyTrigger \
-TXIMHotKeyTriggers \
-TXIMPreeditCaretCallbackStruct \
-TXIMPreeditDrawCallbackStruct \
-TXIMPreeditState \
-TXIMPreeditStateNotifyCallbackStruct \
-TXIMProc \
-TXIMResetState \
-TXIMStatusDataType \
-TXIMStatusDrawCallbackStruct \
-TXIMStringConversionCallbackStruct \
-TXIMStringConversionFeedback \
-TXIMStringConversionOperation \
-TXIMStringConversionPosition \
-TXIMStringConversionText \
-TXIMStringConversionType \
-TXIMStyle \
-TXIMStyles \
-TXIMText \
-TXIMValuesList \
-TXIOErrorHandler \
-TXImage \
-TXKeyEvent \
-TXKeyPressedEvent \
-TXKeyReleasedEvent \
-TXKeyboardControl \
-TXKeyboardState \
-TXKeymapEvent \
-TXLeaveWindowEvent \
-TXLogContRecord \
-TXLogCtlData \
-TXLogCtlInsert \
-TXLogCtlWrite \
-TXLogPageHeader \
-TXLogPageHeaderData \
-TXLogRecData \
-TXLogRecPtr \
-TXLogRecord \
-TXLogRelCacheEntry \
-TXLogRelDesc \
-TXLogwrtResult \
-TXLogwrtRqst \
-TXMapEvent \
-TXMapRequestEvent \
-TXMappingEvent \
-TXModifierKeymap \
-TXMotionEvent \
-TXNoExposeEvent \
-TXOC \
-TXOM \
-TXOMCharSetList \
-TXOMFontInfo \
-TXOMOrientation \
-TXOrientation \
-TXPixmapFormatValues \
-TXPoint \
-TXPointer \
-TXPointerMovedEvent \
-TXPropertyEvent \
-TXRectangle \
-TXReparentEvent \
-TXResizeRequestEvent \
-TXSegment \
-TXSelectionClearEvent \
-TXSelectionEvent \
-TXSelectionRequestEvent \
-TXSetWindowAttributes \
-TXTextItem \
-TXTextItem16 \
-TXTimeCoord \
-TXUnmapEvent \
-TXVaNestedList \
-TXVirtualEvent \
-TXVisibilityEvent \
-TXWindowAttributes \
-TXWindowChanges \
-TXidStatus \
-TXmbTextItem \
-TXwcTextItem \
-TYYSTYPE \
-TYY_BUFFER_STATE \
-TYY_CHAR \
-T_LIB_VERSION_TYPE \
-T_RuneEntry \
-T_RuneLocale \
-T_RuneRange \
-T_SPI_connection \
-T_SPI_plan \
-T_XPrivDisplay \
-Tac_extra \
-Taclitem \
-Tadjust_inherited_attrs_context \
-Talc_extra \
-Talloc_func \
-Tam_extra \
-Tanyarray \
-Tassoc_list \
-Tatc_extra \
-Tattribute_used_context \
-TbackslashResult \
-Tbio_info_cb \
-Tbit_64 \
-Tbitmapword \
-Tbits16 \
-Tbits32 \
-Tbits8 \
-Tbool \
-Tbool16 \
-Tbool32 \
-Tbool8 \
-Tbt_incomplete_split \
-Tbytea \
-Tcached_re_str \
-Tcaddr_t \
-Tcc_t \
-Tcelt \
-Tchar \
-Tcharf \
-TcheckExprHasAggs_context \
-Tcheck_parameter_resolution_context \
-Tcheck_ungrouped_columns_context \
-Tchr \
-Tclock_t \
-Tclockid_t \
-Tcolor \
-Tconst_des_cblock \
-Tcontain_var_reference_context \
-Tcrc64 \
-Tdaddr_t \
-Tdatetkn \
-Tdeparse_context \
-Tdeparse_namespace \
-Tdes_cblock \
-Tdes_key_schedule \
-Tdev_t \
-Tdiv_t \
-Tdouble \
-TevalPlanQual \
-TexecRowMark \
-Texecution_state \
-Tf_smgr \
-Tfd_mask \
-Tfd_set \
-Tfinalize_primnode_context \
-Tfind_expr_references_context \
-Tfind_minimum_var_level_context \
-Tfixpt_t \
-Tflatten_join_alias_vars_context \
-Tfloat \
-Tfloat32 \
-Tfloat32data \
-Tfloat4 \
-Tfloat64 \
-Tfloat64data \
-Tfloat8 \
-Tfp_except \
-Tfp_rnd \
-Tfpclass_t \
-Tfpos_t \
-Tfree_func \
-Tfsec_t \
-Tfunc_ptr \
-Tgid_t \
-TgzFile \
-Thashnode \
-ThbaPort \
-Thelp_handler \
-Tin_addr_t \
-Tin_port_t \
-Tinet \
-Tinet_struct \
-Tino_t \
-Tint \
-Tint16 \
-Tint16_t \
-Tint16m_t \
-Tint2 \
-Tint2vector \
-Tint32 \
-Tint32_t \
-Tint32m_t \
-Tint4 \
-Tint64 \
-Tint64_t \
-Tint64m_t \
-Tint8 \
-Tint8_t \
-Tint8m_t \
-Tintf \
-Tjmp_buf \
-Tjoin_references_context \
-Tkey_t \
-TlclContext \
-TlclTocEntry \
-Tldiv_t \
-Tmacaddr \
-Tmb2wchar_with_len_converter \
-Tmblen_converter \
-TmixedStruct \
-Tmode_t \
-Tnlink_t \
-Toff_t \
-Toidvector \
-ToptType \
-Tpcolor \
-Tpem_password_cb \
-Tpg_enc \
-Tpg_enc2name \
-Tpg_encname \
-Tpg_local_to_utf \
-Tpg_utf_to_local \
-Tpg_wchar \
-Tpg_wchar_tbl \
-Tpgsql_thing_t \
-Tpid_t \
-Tpqbool \
-Tpqsigfunc \
-TprintQueryOpt \
-TprintTableOpt \
-TpromptStatus_t \
-Tpthread_attr_t \
-Tpthread_cond_t \
-Tpthread_condattr_t \
-Tpthread_key_t \
-Tpthread_mutex_t \
-Tpthread_mutexattr_t \
-Tpthread_once_t \
-Tpthread_t \
-Tptrdiff_t \
-Tpull_var_clause_context \
-Tpull_varnos_context \
-Tq128_t \
-Tqaddr_t \
-Tquad_t \
-TrangeTableEntry_used_context \
-Treduce_outer_joins_state \
-Tregex_t \
-Tregister_t \
-Tregmatch_t \
-Tregoff_t \
-Tregproc \
-Treplace_vars_with_subplan_refs_context \
-Trewrite_event \
-Trm_detail_t \
-Trune_t \
-Tsa_family_t \
-Tsegsz_t \
-Tsequence_magic \
-Tsig_atomic_t \
-Tsig_t \
-Tsighandler_cxt \
-Tsigjmp_buf \
-Tsignedbitmapword \
-Tsigset_t \
-Tsize_t \
-Tslock_t \
-Tsmgrid \
-Tsocklen_t \
-Tspeed_t \
-TsqlparseInfo \
-TsqlparseState \
-Tssize_t \
-Tssl_crock_st \
-Tstack_t \
-Tsubstitute_actual_parameters_context \
-Tswblk_t \
-Ttcflag_t \
-Ttcp_seq \
-TteReqs \
-Ttext \
-Ttime_t \
-TuInt \
-TuIntf \
-TuLong \
-TuLongf \
-Tu_char \
-Tu_int \
-Tu_int16_t \
-Tu_int16m_t \
-Tu_int32_t \
-Tu_int32m_t \
-Tu_int64_t \
-Tu_int64m_t \
-Tu_int8_t \
-Tu_int8m_t \
-Tu_long \
-Tu_quad_t \
-Tu_short \
-Tuchr \
-Tuid_t \
-Tuint \
-Tuint16 \
-Tuint32 \
-Tuint64 \
-Tuint8 \
-Tunknown \
-Tushort \
-Tva_list \
-Tvarattrib \
-Tvm_offset_t \
-Tvm_size_t \
-Tvoid \
-Tvoidp \
-Tvoidpf \
-Twchar_t \
-Tword16 \
-Tword32 \
-Tword8 \
-Txl_btree_delete \
-Txl_btree_delete_page \
-Txl_btree_insert \
-Txl_btree_metadata \
-Txl_btree_newmeta \
-Txl_btree_newpage \
-Txl_btree_newroot \
-Txl_btree_split \
-Txl_btreetid \
-Txl_heap_clean \
-Txl_heap_delete \
-Txl_heap_header \
-Txl_heap_insert \
-Txl_heap_update \
-Txl_heaptid \
-Txl_seq_rec \
-Txl_xact_abort \
-Txl_xact_commit \
-Tyy_size_t \
-Tyy_state_type \
-Tyysigned_char \
-Tz_stream \
-Tz_streamp \
/tmp/$$a >/tmp/$$ 2>&1
	if [ "$?" -ne 0 -o -s /tmp/$$ ]
	then	echo
		echo "$FILE"
		cat /tmp/$$
	fi
	cat /tmp/$$a |
# restore DATA/CATALOG lines
	sed 's;^/\*\(DATA(.*\)\*/$;\1;' |
	sed 's;^/\*\(CATALOG(.*\)\*/$;\1;' |
# remove tabs and retab with four spaces
	detab -t8 -qc |
	entab -t4 -qc |
	sed 's;^/\* Open extern \"C\" \*/$;{;' |
	sed 's;^/\* Close extern \"C\" \*/$;};' |
	sed 's;/\*---X_X;/* ---;g' |
# workaround indent bug
	sed 's;^static[ 	][ 	]*;static ;g' |
	sed 's;^}	[ 	]*;}	;' |
# pull in #endif comments
	sed 's;^#endif[ 	][ 	]*/\*;#endif   /*;' |
# work around #else indenting next line if #ifdef defines variables at top
# work around misindenting of function with no variables defined
	awk '
	{
		if ($0 ~ "^[ 	]*int[ 	]*pgindent_func_no_var_fix;")
		{
			if (getline && $0 != "")
				print $0;
		}
		else 	print $0;
	}' |
# add space after comments that start on tab stops
	sed 's;\([^ 	]\)\(/\*.*\*/\)$;\1	\2;' |
# move trailing * in function return type
	sed 's;^\([A-Za-z_][^ 	]*\)[ 	][ 	]*\*$;\1 *;' |
# remove un-needed braces around single statements
	awk '
	{
			line3 = $0;  
			if (skips > 0)
				skips--;
			if (line1 ~ "		*{$" &&
			    line2 ~ "		*[^;{}]*;$" &&
			    line3 ~ "		*}$")
			{
				print line2;
				line2 = "";
				line3 = "";
				skips = 3;
			}
			else
	 			if (skips == 0 && NR >= 3)
					print line1;
			line1 = line2;
			line2 = line3;
		}
		END {
			if (NR >= 2 && skips <= 1)
				print line1;
			if (NR >= 1 && skips <= 2)
				print line2;
		}' |
# remove blank line between opening brace and block comment
	awk '
	{
			line3 = $0;  
			if (skips > 0)
				skips--;
			if (line1 ~ "	*{$" &&
			    line2 ~ "^$" &&
			    line3 ~ "		*/\\*$")
			{
				print line1;
				print line3;
				line2 = "";
				line3 = "";
				skips = 3;
			}
			else
	 			if (skips == 0 && NR >= 3)
					print line1;
			line1 = line2;
			line2 = line3;
		}
		END {
			if (NR >= 2 && skips <= 1)
				print line1;
			if (NR >= 1 && skips <= 2)
				print line2;
		}' |
# remove trailing blank lines, helps with adding blank before trailing #endif
	awk '	BEGIN	{blank_lines = 0;}
		{
			line1 = $0;
	 		if (line1 ~ /^$/)
				blank_lines++;
			else
			{
				for (; blank_lines > 0; blank_lines--)
					printf "\n";
				print line1;
			}
		}' |
# remove blank line before #endif
	awk '	BEGIN	{line1 = ""; line2 = ""; skips = 0}
		{
			line2 = $0;
			if (skips > 0)
				skips--;
			if (line1 ~ "^$" &&
			    line2 ~ "^#endif")
			{
				print line2;
				line2 = "";
				skips = 2;
			}
			else
	 			if (skips == 0 && NR >= 2)
					print line1;
			line1 = line2;
		}
		END {
			if (NR >= 1 && skips <= 1)
				print line1;
		}' |
# add blank line before #endif if it is the last line in the file
	awk '	BEGIN	{line1 = ""; line2 = ""}
		{
			line2 = $0;
	 		if (NR >= 2)
				print line1;
			line1 = line2;
		}
		END {
			if (NR >= 1 && line2 ~ "^#endif")
				printf "\n";
			print line1;
		}' |
#  Move prototype names to the same line as return type.  Useful for ctags. 
#  Indent should do this, but it does not.  It formats prototypes just
#  like real functions.
	awk '	BEGIN	{paren_level = 0}  
	{
		if ($0 ~ /^[a-zA-Z_][a-zA-Z_0-9]*[^\(]*$/)
		{
			saved_len = 0;
			saved_lines[++saved_len] = $0;
			if ((getline saved_lines[++saved_len]) == 0)
				print saved_lines[1];
			else
			if (saved_lines[saved_len] !~ /^[a-zA-Z_][a-zA-Z_0-9]*\(/ ||
			    saved_lines[saved_len] ~  /^[a-zA-Z_][a-zA-Z_0-9]*\(.*\)$/ ||
			    saved_lines[saved_len] ~  /^[a-zA-Z_][a-zA-Z_0-9]*\(.*\);$/)
			{
				print saved_lines[1];
				print saved_lines[2];
			}
			else
			{
				while (1)
				{
					if ((getline saved_lines[++saved_len]) == 0)
						break;
					if (saved_lines[saved_len] ~ /^[^ 	]/ ||
					    saved_lines[saved_len] !~ /,$/)
						break;
				}
				for (i=1; i <= saved_len; i++)
				{
					if (i == 1 && saved_lines[saved_len] ~ /\);$/)
					{
						printf "%s", saved_lines[i];
						if (substr(saved_lines[i], length(saved_lines[i]),1) != "*")
							printf " ";
					}
					else	print saved_lines[i];
				}
			}
		}
		else	print $0;
	}' |
	cat >/tmp/$$ && cat /tmp/$$ >"$FILE"
done

# The 'for' loop makes these backup files useless so delete them
rm -f *a.BAK
