5
# Blank line is added after, seen as a function definition, no space
9
trap "rm -f /tmp/$$ /tmp/$$a" 0 1 2 3 15
10
entab </dev/null >/dev/null
12
then echo "Go to the src/tools/entab directory and do a 'make' and 'make install'." >&2
13
echo "This will put the 'entab' command in your path." >&2
14
echo "Then run $0 again."
17
indent -? </dev/null >/dev/null 2>&1
19
then echo "You do not appear to have 'indent' installed on your system." >&2
22
indent -gnu </dev/null >/dev/null 2>&1
24
then echo "You appear to have GNU indent rather than BSD indent." >&2
25
echo "See the pgindent/README file for a description of its problems." >&2
26
EXTRA_OPTS="-cdb -bli0 -npcs -cli4 -sc"
27
else echo "Hope you installed /src/tools/pgindent/indent.bsd.patch." >&2
34
# convert // comments to /* */
35
sed 's;^\([ ]*\)//\(.*\)$;\1/* \2 */;g' |
36
# Avoid bug that converts 'x =- 1' to 'x = -1'
38
# mark some comments for special treatment later
39
sed 's;/\* *---;/*---X_X;g' |
40
# workaround for indent bug with 'else' handling
41
# indent comment so BSD indent will move it
42
sed 's;\([} ]\)else[ ]*\(/\*.*\)$;\1else\
45
# work around bug where function that defines no local variables misindents
46
# switch() case lines and line after #else. Do not do for struct/enum.
47
awk ' BEGIN {line1 = ""; line2 = ""}
56
line1 !~ "^typedef" &&
57
line1 !~ "^extern[ ][ ]*\"C\"" &&
60
print "int pgindent_func_no_var_fix;";
67
# prevent indenting of code in 'extern "C"' blocks
68
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
73
if (line1 ~ "^#ifdef[ ]*__cplusplus" &&
74
line2 ~ "^extern[ ]*\"C\"[ ]*$")
78
if (getline && $0 ~ /^{[ ]*$/)
79
print "/* Open extern \"C\" */";
84
else if (line1 ~ "^#ifdef[ ]*__cplusplus" &&
88
print "/* Close extern \"C\" */";
93
if (skips == 0 && NR >= 2)
98
if (NR >= 1 && skips <= 1)
101
# protect backslashes in DATA()
102
sed 's;^DATA(.*$;/*&*/;' |
103
# protect wrapping in CATALOG()
104
sed 's;^CATALOG(.*$;/*&*/;' >/tmp/$$a
106
# We get the list of typedef's from /src/tools/find_typedef
107
indent -bad -bap -bc -bl -d0 -cdb -nce -nfc1 -di12 -i4 -l79 \
108
-lp -nip -npro -bbb $EXTRA_OPTS \
118
-TASN1_GENERALIZEDTIME \
119
-TASN1_GENERALSTRING \
128
-TASN1_OCTET_STRING \
129
-TASN1_PRINTABLESTRING \
131
-TASN1_STRING_TABLE \
137
-TASN1_UNIVERSALSTRING \
141
-TASN1_VISIBLESTRING \
162
-TAggStatePerAggData \
164
-TAggStatePerGroupData \
178
-TAlterDatabaseSetStmt \
189
-TAnalyzeAttrFetchFunc \
206
-TArrayRefExprState \
220
-TBIT_STRING_BITNAME \
245
-TBgWriterShmemStruct \
267
-TBufferStrategyCDB \
268
-TBufferStrategyControl \
275
-TCFuncHashTabEntry \
284
-TCRYPTO_EX_DATA_FUNCS \
285
-TCRYPTO_EX_DATA_IMPL \
289
-TCRYPTO_MEM_LEAK_CB \
293
-TCacheCallbackFunction \
294
-TCancelRequestPacket \
307
-TCatalogIndexState \
308
-TChangeVarNodes_context \
319
-TCoalesceExprState \
321
-TCoerceToDomainState \
322
-TCoerceToDomainValue \
333
-TCompositeTypeStmt \
339
-TConstraintCategory \
341
-TConstraintsSetStmt \
352
-TCreateConversionStmt \
354
-TCreateFunctionStmt \
356
-TCreateOpClassItem \
357
-TCreateOpClassStmt \
360
-TCreateSchemaStmtContext \
363
-TCreateStmtContext \
364
-TCreateTableSpaceStmt \
391
-TDeclareCursorStmt \
393
-TDeferredTriggerEvent \
394
-TDeferredTriggerEventData \
395
-TDeferredTriggerEventItem \
396
-TDeferredTriggerState \
397
-TDeferredTriggerStateData \
398
-TDeferredTriggerStatus \
399
-TDeferredTriggerStatusData \
401
-TDeferredTriggersData \
410
-TDomainConstraintState \
411
-TDomainConstraintType \
418
-TDropTableSpaceStmt \
423
-TDumpableObjectType \
445
-TErrorContextCallback \
447
-TExceptionLabelMap \
450
-TExecScanAccessMtd \
458
-TExprContextCallbackFunction \
462
-TExprStateEvalFunc \
481
-TFormData_pg_aggregate \
484
-TFormData_pg_amproc \
485
-TFormData_pg_attrdef \
486
-TFormData_pg_attribute \
488
-TFormData_pg_class \
489
-TFormData_pg_constraint \
490
-TFormData_pg_conversion \
491
-TFormData_pg_database \
492
-TFormData_pg_depend \
493
-TFormData_pg_description \
494
-TFormData_pg_group \
495
-TFormData_pg_index \
496
-TFormData_pg_inherits \
497
-TFormData_pg_language \
498
-TFormData_pg_largeobject \
499
-TFormData_pg_listener \
500
-TFormData_pg_namespace \
501
-TFormData_pg_opclass \
502
-TFormData_pg_operator \
504
-TFormData_pg_rewrite \
505
-TFormData_pg_sequence \
506
-TFormData_pg_shadow \
507
-TFormData_pg_statistic \
508
-TFormData_pg_tablespace \
509
-TFormData_pg_trigger \
511
-TForm_pg_aggregate \
516
-TForm_pg_attribute \
519
-TForm_pg_constraint \
520
-TForm_pg_conversion \
523
-TForm_pg_description \
528
-TForm_pg_largeobject \
530
-TForm_pg_namespace \
537
-TForm_pg_statistic \
538
-TForm_pg_tablespace \
543
-TFsmCacheFileHeader \
544
-TFsmCacheRelHeader \
547
-TFuncCandidateList \
555
-TFunctionCallInfoData \
556
-TFunctionParameter \
558
-TFunctionScanState \
563
-TGISTPageOpaqueData \
569
-TGISTScanOpaqueData \
573
-TGUC_yy_state_type \
585
-TGucBoolAssignHook \
588
-TGucRealAssignHook \
592
-TGucStringAssignHook \
617
-THashJoinTupleData \
621
-THashPageOpaqueData \
626
-THashScanOpaqueData \
636
-THeapTupleHeaderData \
646
-TIncrementVarSublevelsUp_context \
648
-TIndexAttributeBitMap \
649
-TIndexAttributeBitMapData \
650
-TIndexBuildCallback \
651
-TIndexBulkDeleteCallback \
652
-TIndexBulkDeleteResult \
661
-TIndexScanDescData \
667
-TIndexVacuumCleanupInfo \
674
-TInnerIndexscanInfo \
675
-TInsertIndexResult \
676
-TInsertIndexResultData \
679
-TInt8TransTypeData \
682
-TInt_yy_state_type \
683
-TInt_yysigned_char \
685
-TInvalidationChunk \
686
-TInvalidationListHeader \
708
-TKEYMAP_ENTRY_ARRAY \
713
-TLHASH_COMP_FN_TYPE \
714
-TLHASH_DOALL_ARG_FN_TYPE \
715
-TLHASH_DOALL_FN_TYPE \
716
-TLHASH_HASH_FN_TYPE \
765
-TMemoryContextData \
766
-TMemoryContextMethods \
772
-TNETSCAPE_CERT_SEQUENCE \
806
-TOffsetVarNodes_context \
815
-TOpclassCandidateList \
827
-TPEM_ENCODE_SEAL_CTX \
831
-TPGAsyncStatusType \
844
-TPGSetenvStatusType \
846
-TPGTransactionStatusType \
859
-TPKCS7_ENC_CONTENT \
861
-TPKCS7_ISSUER_AND_SERIAL \
864
-TPKCS7_SIGNER_INFO \
865
-TPKCS7_SIGN_ENVELOPE \
866
-TPKCS8_PRIV_KEY_INFO \
868
-TPLpgSQL_arrayelem \
869
-TPLpgSQL_condition \
871
-TPLpgSQL_diag_item \
873
-TPLpgSQL_exception \
874
-TPLpgSQL_exceptions \
875
-TPLpgSQL_execstate \
877
-TPLpgSQL_func_hashkey \
885
-TPLpgSQL_stmt_assign \
886
-TPLpgSQL_stmt_block \
887
-TPLpgSQL_stmt_close \
888
-TPLpgSQL_stmt_dynexecute \
889
-TPLpgSQL_stmt_dynfors \
890
-TPLpgSQL_stmt_execsql \
891
-TPLpgSQL_stmt_exit \
892
-TPLpgSQL_stmt_fetch \
893
-TPLpgSQL_stmt_fori \
894
-TPLpgSQL_stmt_fors \
895
-TPLpgSQL_stmt_getdiag \
897
-TPLpgSQL_stmt_loop \
898
-TPLpgSQL_stmt_open \
899
-TPLpgSQL_stmt_perform \
900
-TPLpgSQL_stmt_raise \
901
-TPLpgSQL_stmt_return \
902
-TPLpgSQL_stmt_return_next \
903
-TPLpgSQL_stmt_select \
904
-TPLpgSQL_stmt_while \
914
-TPQEnvironmentOption \
918
-TPQnoticeProcessor \
929
-TPageFreeSpaceInfo \
935
-TParamListInfoData \
940
-TPathKeysComparison \
941
-TPattern_Prefix_Status \
943
-TPendingOperationEntry \
945
-TPerlExitListEntry \
950
-TPgStat_MsgActivity \
951
-TPgStat_MsgBestart \
956
-TPgStat_MsgResetcounter \
957
-TPgStat_MsgTabpurge \
958
-TPgStat_MsgTabstat \
959
-TPgStat_StatBeDead \
960
-TPgStat_StatBeEntry \
961
-TPgStat_StatDBEntry \
962
-TPgStat_StatTabEntry \
963
-TPgStat_TableEntry \
977
-TPostgresPollingStatusType \
979
-TPreparedStatement \
992
-TPsqlScanStateData \
1002
-TRI_QueryHashEntry \
1013
-TRTreePageOpaqueData \
1015
-TRTreeScanOpaqueData \
1017
-TRangeQueryClause \
1022
-TRawColumnDefault \
1026
-TRecordCacheEntry \
1039
-TRelationBuildDescInfo \
1046
-TRemoveOpClassStmt \
1051
-TResolveNew_context \
1053
-TResourceOwnerData \
1054
-TResourceReleaseCallback \
1055
-TResourceReleaseCallbackItem \
1056
-TResourceReleasePhase \
1077
-TSMgrRelationData \
1081
-TSQLFunctionCache \
1082
-TSQLFunctionCachePtr \
1099
-TScalarArrayOpExpr \
1100
-TScalarArrayOpExprState \
1116
-TSetFunctionReturnMode \
1121
-TSetOperationStmt \
1123
-TSharedInvalCatcacheMsg \
1124
-TSharedInvalRelcacheMsg \
1125
-TSharedInvalidationMessage \
1146
-TSortFunctionKind \
1149
-TStandardChunkHeader \
1163
-TSubqueryScanState \
1175
-TTcl_AsyncHandler \
1181
-TTcl_ChannelTypeVersion \
1183
-TTcl_CmdDeleteProc \
1186
-TTcl_CmdTraceProc \
1189
-TTcl_CreateFileHandlerProc \
1191
-TTcl_DeleteFileHandlerProc \
1192
-TTcl_DriverBlockModeProc \
1193
-TTcl_DriverClose2Proc \
1194
-TTcl_DriverCloseProc \
1195
-TTcl_DriverFlushProc \
1196
-TTcl_DriverGetHandleProc \
1197
-TTcl_DriverGetOptionProc \
1198
-TTcl_DriverHandlerProc \
1199
-TTcl_DriverInputProc \
1200
-TTcl_DriverOutputProc \
1201
-TTcl_DriverSeekProc \
1202
-TTcl_DriverSetOptionProc \
1203
-TTcl_DriverWatchProc \
1204
-TTcl_DupInternalRepProc \
1206
-TTcl_EncodingConvertProc \
1207
-TTcl_EncodingFreeProc \
1208
-TTcl_EncodingState \
1209
-TTcl_EncodingType \
1210
-TTcl_EolTranslation \
1212
-TTcl_EventCheckProc \
1213
-TTcl_EventDeleteProc \
1215
-TTcl_EventSetupProc \
1217
-TTcl_FileFreeProc \
1219
-TTcl_FreeInternalRepProc \
1226
-TTcl_InterpDeleteProc \
1227
-TTcl_MainLoopProc \
1231
-TTcl_NamespaceDeleteProc \
1232
-TTcl_NotifierProcs \
1236
-TTcl_PackageInitProc \
1241
-TTcl_QueuePosition \
1243
-TTcl_RegExpIndices \
1246
-TTcl_SetFromAnyProc \
1247
-TTcl_SetTimerProc \
1249
-TTcl_TcpAcceptProc \
1250
-TTcl_ThreadCreateProc \
1251
-TTcl_ThreadDataKey \
1259
-TTcl_UpdateStringProc \
1263
-TTcl_VarTraceProc \
1264
-TTcl_WaitForEventProc \
1272
-TTimeIntervalData \
1282
-TTransInvalidationInfo \
1285
-TTransactionState \
1286
-TTransactionStateData \
1288
-TTransactionStmtKind \
1301
-TTupleHashEntryData \
1302
-TTupleHashIterator \
1304
-TTupleHashTableData \
1326
-TUniquePathMethod \
1350
-TVariableCacheData \
1351
-TVariableResetStmt \
1353
-TVariableShowStmt \
1355
-TVariableStatData \
1362
-TWriteExtraTocPtr \
1367
-TX509_CERT_FILE_CTX \
1372
-TX509_HASH_DIR_CTX \
1375
-TX509_LOOKUP_METHOD \
1394
-TXLogLongPageHeader \
1395
-TXLogLongPageHeaderData \
1397
-TXLogPageHeaderData \
1401
-TXLogRelCacheEntry \
1420
-TXactCallbackItem \
1426
-T_LIB_VERSION_TYPE \
1432
-T_ossl_old_des_cblock \
1433
-T_ossl_old_des_key_schedule \
1435
-Tadjust_inherited_attrs_context \
1442
-Tattribute_used_context \
1450
-Tbt_incomplete_split \
1458
-TcheckExprHasAggs_context \
1459
-Tcheck_parameter_resolution_context \
1460
-Tcheck_ungrouped_columns_context \
1467
-Tconst_DES_cblock \
1468
-Tcontain_var_reference_context \
1476
-Tdeparse_namespace \
1481
-Teval_const_expressions_context \
1489
-Tfinalize_primnode_context \
1490
-Tfind_expr_references_context \
1491
-Tfind_minimum_var_level_context \
1493
-Tflatten_join_alias_vars_context \
1508
-Tgenerate_series_fctx \
1540
-Tjoin_references_context \
1547
-Tmb2wchar_with_len_converter \
1548
-Tmbdisplaylen_converter \
1563
-TpgParameterStatus \
1577
-Tplperl_proc_desc \
1579
-Tplpgsql_yysigned_char \
1581
-Tpltcl_query_desc \
1589
-Tpthread_condattr_t \
1592
-Tpthread_mutexattr_t \
1596
-Tpull_var_clause_context \
1597
-Tpull_varnos_context \
1602
-TrangeTableEntry_used_context \
1603
-Treduce_outer_joins_state \
1613
-Treplace_vars_with_subplan_refs_context \
1625
-Tsignedbitmapword \
1638
-Tsubstitute_actual_parameters_context \
1686
-Txl_btree_delete_page \
1688
-Txl_btree_metadata \
1689
-Txl_btree_newmeta \
1690
-Txl_btree_newroot \
1702
-Txl_smgr_truncate \
1710
/tmp/$$a >/tmp/$$ 2>&1
1711
if [ "$?" -ne 0 -o -s /tmp/$$ ]
1717
# restore DATA/CATALOG lines
1718
sed 's;^/\*\(DATA(.*\)\*/$;\1;' |
1719
sed 's;^/\*\(CATALOG(.*\)\*/$;\1;' |
1720
# remove tabs and retab with four spaces
1723
sed 's;^/\* Open extern \"C\" \*/$;{;' |
1724
sed 's;^/\* Close extern \"C\" \*/$;};' |
1725
sed 's;/\*---X_X;/* ---;g' |
1726
# workaround indent bug
1727
sed 's;^static[ ][ ]*;static ;g' |
1728
sed 's;^} [ ]*;} ;' |
1729
# pull in #endif comments
1730
sed 's;^#endif[ ][ ]*/\*;#endif /*;' |
1731
# work around #else indenting next line if #ifdef defines variables at top
1732
# work around misindenting of function with no variables defined
1735
if ($0 ~ "^[ ]*int[ ]*pgindent_func_no_var_fix;")
1737
if (getline && $0 != "")
1742
# add space after comments that start on tab stops
1743
sed 's;\([^ ]\)\(/\*.*\*/\)$;\1 \2;' |
1744
# move trailing * in function return type
1745
sed 's;^\([A-Za-z_][^ ]*\)[ ][ ]*\*$;\1 *;' |
1746
# remove un-needed braces around single statements
1747
# Do not use because it uglifies PG_TRY/PG_CATCH blocks and probably
1748
# isn't needed for general use.
1754
# if (line1 ~ " *{$" &&
1755
# line2 ~ " *[^;{}]*;$" &&
1764
# if (skips == 0 && NR >= 3)
1770
# if (NR >= 2 && skips <= 1)
1772
# if (NR >= 1 && skips <= 2)
1775
# remove blank line between opening brace and block comment
1781
if (line1 ~ " *{$" &&
1792
if (skips == 0 && NR >= 3)
1798
if (NR >= 2 && skips <= 1)
1800
if (NR >= 1 && skips <= 2)
1803
# remove trailing blank lines, helps with adding blank before trailing #endif
1804
awk ' BEGIN {blank_lines = 0;}
1811
for (; blank_lines > 0; blank_lines--)
1816
# remove blank line before #endif
1817
awk ' BEGIN {line1 = ""; line2 = ""; skips = 0}
1830
if (skips == 0 && NR >= 2)
1835
if (NR >= 1 && skips <= 1)
1838
# add blank line before #endif if it is the last line in the file
1839
awk ' BEGIN {line1 = ""; line2 = ""}
1847
if (NR >= 1 && line2 ~ "^#endif")
1851
# Move prototype names to the same line as return type. Useful for ctags.
1852
# Indent should do this, but it does not. It formats prototypes just
1853
# like real functions.
1854
awk ' BEGIN {paren_level = 0}
1856
if ($0 ~ /^[a-zA-Z_][a-zA-Z_0-9]*[^\(]*$/)
1859
saved_lines[++saved_len] = $0;
1860
if ((getline saved_lines[++saved_len]) == 0)
1861
print saved_lines[1];
1863
if (saved_lines[saved_len] !~ /^[a-zA-Z_][a-zA-Z_0-9]*\(/ ||
1864
saved_lines[saved_len] ~ /^[a-zA-Z_][a-zA-Z_0-9]*\(.*\)$/ ||
1865
saved_lines[saved_len] ~ /^[a-zA-Z_][a-zA-Z_0-9]*\(.*\);$/)
1867
print saved_lines[1];
1868
print saved_lines[2];
1874
if ((getline saved_lines[++saved_len]) == 0)
1876
if (saved_lines[saved_len] ~ /^[^ ]/ ||
1877
saved_lines[saved_len] !~ /,$/)
1880
for (i=1; i <= saved_len; i++)
1882
if (i == 1 && saved_lines[saved_len] ~ /\);$/)
1884
printf "%s", saved_lines[i];
1885
if (substr(saved_lines[i], length(saved_lines[i]),1) != "*")
1888
else print saved_lines[i];
1894
cat >/tmp/$$ && cat /tmp/$$ >"$FILE"
1897
# The 'for' loop makes these backup files useless so delete them