This can format all PostgreSQL *.c and *.h files, but excludes *.y, and *.l
files.
-Get the list of typedef's included in pgindent by running this on the
-pgsql/bin and pgsql/lib directories:
+To use it, first get the list of typedef's to be included in pgindent by
+running this on the pgsql/bin and pgsql/lib directories:
- /src/tools/find_typedef /usr/local/pgsql/bin /usr/local/pgsql/lib
+ src/tools/find_typedef /usr/local/pgsql/bin /usr/local/pgsql/lib
and update the list in pgindent. This requires the binaries have debug
symbols.
find . -name '*.[ch]' -type f -print | grep -v 's_lock.h' | xargs -n100 pgindent
-The stock BSD indent has two bugs. First, a comment after the word 'else'
-causes the rest of the file to be ignored. Second, it silently ignores
-typedefs after getting the first 100.
-
-Both problems are worked-around in this script. We also include a patch
-for the second bug in:
-
- /src/tools/pgindent/indent.bsd.patch
-
-Even with the workaround, installation of the patch produces better
-output. You can get a patched BSD indent from ftp://ftp.postgresql.org/pub/dev.
+We have standardized on NetBSD's indent. We have fixed a few bugs which
+requre the NetBSD source to be patched with indent.bsd.patch patch. A
+fully patched version is available at ftp://ftp.postgresql.org/pub/dev.
GNU indent, version 2.2.6, has several problems, and is not recommended.
-These bugs become pretty major when you are doing >400k lines of code.
+These bugs become pretty major when you are doing >500k lines of code.
If you don't believe me, take a directory and make a copy. Run pgindent
on the copy using GNU indent, and do a diff -r. You will see what I
mean. GNU indent does some things better, but mangles too.
-This increases the number of typedef's understood by BSD indent from 100
-to 4096. The second patch allows it to understand 0x7fU and 0LL constants.
+This patch contains several fixes to NetBSD's indent and should be
+applied before using pgindent.
---------------------------------------------------------------------------
-*** ./lexi.c.orig Mon Sep 8 17:55:47 1997
---- ./lexi.c Mon Sep 8 17:02:10 1997
+Index: README
+===================================================================
+RCS file: /cvsroot/src/usr.bin/indent/README,v
+retrieving revision 1.1
+diff -c -r1.1 README
+*** README 9 Apr 1993 12:59:06 -0000 1.1
+--- README 15 Nov 2005 00:25:43 -0000
***************
-*** 58,64 ****
- int rwcode;
+*** 1,3 ****
+--- 1,13 ----
++
++ This patch is from NetBSD current, 2005-11-14. It contains all the
++ patches need for its use in PostgreSQL.
++
++ bjm
++
++ ---------------------------------------------------------------------------
++
++
++
+ This is the C indenter, it originally came from the University of Illinois
+ via some distribution tape for PDP-11 Unix. It has subsequently been
+ hacked upon by James Gosling @ CMU. It isn't very pretty, and really needs
+Index: indent_globs.h
+===================================================================
+RCS file: /cvsroot/src/usr.bin/indent/indent_globs.h,v
+retrieving revision 1.8
+diff -c -r1.8 indent_globs.h
+*** indent_globs.h 7 Aug 2003 11:14:08 -0000 1.8
+--- indent_globs.h 15 Nov 2005 00:25:44 -0000
+***************
+*** 239,245 ****
+ scomf, /* Same line comment font */
+ bodyf; /* major body font */
+
+! #define STACK_SIZE 150
+
+ EXTERN struct parser_state {
+ int last_token;
+--- 239,249 ----
+ scomf, /* Same line comment font */
+ bodyf; /* major body font */
+
+! /*
+! * This controls the maximum number of 'else if' clauses supported.
+! * If it is exceeded, comments are placed in column 100.
+! */
+! #define STACK_SIZE 1000
+
+ EXTERN struct parser_state {
+ int last_token;
+Index: lexi.c
+===================================================================
+RCS file: /cvsroot/src/usr.bin/indent/lexi.c,v
+retrieving revision 1.12
+diff -c -r1.12 lexi.c
+*** lexi.c 7 Aug 2003 11:14:09 -0000 1.12
+--- lexi.c 15 Nov 2005 00:25:44 -0000
+***************
+*** 93,99 ****
+ int rwcode;
};
-! struct templ specials[100] =
+! struct templ specials[1000] =
{
- "switch", 1,
- "case", 2,
---- 58,64 ----
- int rwcode;
+ {"switch", 1},
+ {"case", 2},
+--- 93,99 ----
+ int rwcode;
};
-! struct templ specials[4096] =
+! struct templ specials[16384] =
{
- "switch", 1,
- "case", 2,
+ {"switch", 1},
+ {"case", 2},
+***************
+*** 622,629 ****
+ else
+ p++;
+ if (p >= specials + sizeof specials / sizeof specials[0])
+! return; /* For now, table overflows are silently
+! * ignored */
+ p->rwd = key;
+ p->rwcode = val;
+ p[1].rwd = 0;
+--- 622,632 ----
+ else
+ p++;
+ if (p >= specials + sizeof specials / sizeof specials[0])
+! {
+! fprintf(stderr, "indent: typedef table overflow\n");
+! exit(1);
+! }
+!
+ p->rwd = key;
+ p->rwcode = val;
+ p[1].rwd = 0;
+Index: parse.c
+===================================================================
+RCS file: /cvsroot/src/usr.bin/indent/parse.c,v
+retrieving revision 1.7
+diff -c -r1.7 parse.c
+*** parse.c 7 Aug 2003 11:14:09 -0000 1.7
+--- parse.c 15 Nov 2005 00:25:44 -0000
+***************
+*** 231,236 ****
+--- 231,241 ----
+
+ } /* end of switch */
+
++ if (ps.tos >= STACK_SIZE) {
++ fprintf(stderr, "indent: stack size overflow\n");
++ exit(1);
++ }
++
+ reduce(); /* see if any reduction can be done */
+
+ #ifdef debug
+Index: pr_comment.c
+===================================================================
+RCS file: /cvsroot/src/usr.bin/indent/pr_comment.c,v
+retrieving revision 1.9
+diff -c -r1.9 pr_comment.c
+*** pr_comment.c 7 Aug 2003 11:14:09 -0000 1.9
+--- pr_comment.c 15 Nov 2005 00:25:44 -0000
+***************
+*** 148,154 ****
+ ps.box_com = true;
+ ps.com_col = 1;
+ } else {
+! if (*buf_ptr == '-' || *buf_ptr == '*' || *buf_ptr == '\n') {
+ ps.box_com = true; /* a comment with a '-', '*'
+ * or newline immediately
+ * after the start comment is
+--- 148,158 ----
+ ps.box_com = true;
+ ps.com_col = 1;
+ } else {
+! /*
+! * Don't process '\n' or every comment is treated as a
+! * block comment, meaning there is no wrapping.
+! */
+! if (*buf_ptr == '-' || *buf_ptr == '*') {
+ ps.box_com = true; /* a comment with a '-', '*'
+ * or newline immediately
+ * after the start comment is
***************
-*** 186,192 ****
- *e_token++ = *buf_ptr++;
- }
- }
-! if (*buf_ptr == 'L' || *buf_ptr == 'l')
- *e_token++ = *buf_ptr++;
- }
- else
---- 186,203 ----
- *e_token++ = *buf_ptr++;
- }
- }
-! if (*buf_ptr == 'F' || *buf_ptr == 'f') {
-! /* float constant */
-! *e_token++ = *buf_ptr++;
-! } else {
-! /* integer constant (U, L, UL, LL, ULL) */
-! if (*buf_ptr == 'U' || *buf_ptr == 'u')
-! *e_token++ = *buf_ptr++;
-! if (*buf_ptr == 'L' || *buf_ptr == 'l')
-! *e_token++ = *buf_ptr++;
-! if (*buf_ptr == 'L' || *buf_ptr == 'l')
-! *e_token++ = *buf_ptr++;
-! }
- }
- else
- while (chartype[*buf_ptr] == alphanum) { /* copy it over */
+*** 328,333 ****
+--- 332,350 ----
+ goto end_of_comment;
+ }
+ } while (*buf_ptr == ' ' || *buf_ptr == '\t');
++
++ /*
++ * If there is a blank comment line, we need to prefix
++ * the line with the same three spaces that "/* " takes up.
++ * Without this code, blank stared lines in comments have
++ * three too-many characters on the line when wrapped.
++ */
++ if (s_com == e_com) {
++ *e_com++ = ' '; /* add blanks for continuation */
++ *e_com++ = ' ';
++ *e_com++ = ' ';
++ now_col += 3;
++ }
+ } else
+ if (++buf_ptr >= buf_end)
+ fill_buffer();
indent -bad -bap -bc -bl -d0 -cdb -nce -nfc1 -di12 -i4 -l79 \
-lp -nip -npro -bbb $EXTRA_OPTS \
-TAES_KEY \
+-TAMT \
+-TAMTS \
+-TANY \
-TASN1_BIT_STRING \
-TASN1_BMPSTRING \
-TASN1_BOOLEAN \
-TASN1_UTF8STRING \
-TASN1_VALUE \
-TASN1_VISIBLESTRING \
+-TAV \
-TA_Const \
-TA_Expr \
-TA_Expr_Kind \
-TAuthRequest \
-TBF_KEY \
-TBIGNUM \
+-TBINOP \
-TBIO \
-TBIO_F_BUFFER_CTX \
-TBIO_METHOD \
-TBIO_dummy \
-TBIT_STRING_BITNAME \
+-TBLOCK \
-TBMS_Membership \
-TBN_BLINDING \
-TBN_CTX \
-TCIRCLE \
-TCOMP_CTX \
-TCOMP_METHOD \
+-TCONDOP \
+-TCOP \
-TCPFunction \
-TCPPFunction \
-TCRYPTO_EX_DATA \
-TCRYPTO_EX_new \
-TCRYPTO_MEM_LEAK_CB \
-TCRYPTO_dynlock \
+-TCURCUR \
+-TCV \
-TCacheCallbackFunction \
-TCancelRequestPacket \
-TCaseExpr \
-TCheckPointStmt \
-TChromosome \
-TCity \
+-TClientData \
-TClosePortalStmt \
-TClosePtr \
-TClusterStmt \
-TEolType \
-TErrorContextCallback \
-TErrorData \
+-TExceptionLabelMap \
-TExecContext \
-TExecContextData \
-TExecScanAccessMtd \
-TExprDoneCond \
-TExprState \
-TExprStateEvalFunc \
+-TFF \
-TFILE \
-TFSMHeader \
-TFSMPageData \
-TGISTScanOpaqueData \
-TGISTSearchStack \
-TGIST_SPLITVEC \
+-TGP \
-TGUC_yy_size_t \
-TGUC_yy_state_type \
+-TGV \
+-TGVOP \
-TGene \
-TGenericExprState \
-TGeqoEvalData \
-THASHHDR \
-THASHSEGMENT \
-THASH_SEQ_STATUS \
+-THE \
+-THEK \
-THISTORY_STATE \
-THIST_ENTRY \
-THTAB \
-THTSU_Result \
-THTSV_Result \
+-THV \
-THash \
-THashAllocFunc \
-THashBuildState \
-THeapTupleFields \
-THeapTupleHeader \
-THeapTupleHeaderData \
+-TI16 \
+-TI32 \
+-TI8 \
+-TIO \
-TIOFuncSelector \
+-TIV \
+-TIV64 \
-TIdList \
-TInClauseInfo \
-TIncrementVarSublevelsUp_context \
-TItemOffset \
-TItemPointer \
-TItemPointerData \
+-TJMPENV \
-TJoin \
-TJoinExpr \
-TJoinHashEntry \
-TLHASH_HASH_FN_TYPE \
-TLHASH_NODE \
-TLINE \
+-TLISTOP \
-TLOCALLOCK \
-TLOCALLOCKOWNER \
-TLOCALLOCKTAG \
-TLOCKMETHODID \
-TLOCKMODE \
-TLOCKTAG \
+-TLOGOP \
+-TLOOP \
-TLSEG \
-TLVRelStats \
-TLWLock \
-TLogStmtLevel \
-TLogicalTape \
-TLogicalTapeSet \
+-TMAGIC \
-TMD2_CTX \
-TMD4_CTX \
-TMD5_CTX \
-TMDC2_CTX \
+-TMGVTBL \
-TMaterial \
-TMaterialPath \
-TMaterialState \
-TNUMDesc \
-TNUMProc \
-TNUM_poz \
+-TNV \
-TName \
-TNameData \
-TNamespaceInfo \
-TNumericDigit \
-TNumericVar \
-TOBJ_NAME \
+-TOP \
-TObjectAddress \
-TObjectAddresses \
-TObjectClass \
-TOperator \
-TOprInfo \
-TOutputContext \
+-TOutrec \
+-TPADOFFSET \
-TPATH \
-TPBE2PARAM \
-TPBEPARAM \
-TPEM_CTX \
-TPEM_ENCODE_SEAL_CTX \
-TPEM_USER \
+-TPERL_CONTEXT \
+-TPERL_SI \
+-TPGAsyncStatusType \
-TPGErrorVerbosity \
-TPGFInfoFunction \
-TPGFunction \
-TPGLZ_Header \
-TPGLZ_HistEntry \
-TPGLZ_Strategy \
+-TPGMessageField \
+-TPGNoticeHooks \
-TPGPROC \
+-TPGQueryClass \
-TPGRUsage \
-TPGSemaphore \
-TPGSemaphoreData \
+-TPGSetenvStatusType \
-TPGShmemHeader \
-TPGTransactionStatusType \
-TPGVerbosity \
-TPG_Lock_Status \
-TPGcancel \
-TPGconn \
+-TPGlobjfuncs \
-TPGnotify \
+-TPGresAttDesc \
+-TPGresAttValue \
-TPGresult \
+-TPGresult_data \
-TPKCS7 \
-TPKCS7_DIGEST \
-TPKCS7_ENCRYPT \
-TPKCS7_SIGNER_INFO \
-TPKCS7_SIGN_ENVELOPE \
-TPKCS8_PRIV_KEY_INFO \
+-TPLPGSQL_YYSTYPE \
-TPLTemplate \
+-TPLpgSQL_arrayelem \
+-TPLpgSQL_condition \
+-TPLpgSQL_datum \
+-TPLpgSQL_diag_item \
+-TPLpgSQL_dstring \
+-TPLpgSQL_exception \
+-TPLpgSQL_exception_block \
+-TPLpgSQL_execstate \
+-TPLpgSQL_expr \
+-TPLpgSQL_func_hashkey \
+-TPLpgSQL_function \
+-TPLpgSQL_ns \
+-TPLpgSQL_nsitem \
+-TPLpgSQL_rec \
+-TPLpgSQL_recfield \
+-TPLpgSQL_row \
+-TPLpgSQL_stmt \
+-TPLpgSQL_stmt_assign \
+-TPLpgSQL_stmt_block \
+-TPLpgSQL_stmt_close \
+-TPLpgSQL_stmt_dynexecute \
+-TPLpgSQL_stmt_dynfors \
+-TPLpgSQL_stmt_execsql \
+-TPLpgSQL_stmt_exit \
+-TPLpgSQL_stmt_fetch \
+-TPLpgSQL_stmt_fori \
+-TPLpgSQL_stmt_fors \
+-TPLpgSQL_stmt_getdiag \
+-TPLpgSQL_stmt_if \
+-TPLpgSQL_stmt_loop \
+-TPLpgSQL_stmt_open \
+-TPLpgSQL_stmt_perform \
+-TPLpgSQL_stmt_raise \
+-TPLpgSQL_stmt_return \
+-TPLpgSQL_stmt_return_next \
+-TPLpgSQL_stmt_select \
+-TPLpgSQL_stmt_while \
+-TPLpgSQL_trigarg \
+-TPLpgSQL_type \
+-TPLpgSQL_var \
+-TPLpgSQL_variable \
+-TPMOP \
-TPMSignalReason \
-TPOLYGON \
-TPQArgBlock \
+-TPQEnvironmentOption \
-TPQExpBuffer \
-TPQExpBufferData \
-TPQconninfoOption \
-TPROCLOCKTAG \
-TPROC_HDR \
-TPROC_QUEUE \
+-TPV \
+-TPVOP \
-TPacketLen \
-TPage \
-TPageFreeSpaceInfo \
-TPattern_Type \
-TPendingOperationEntry \
-TPendingRelDelete \
+-TPerlExitListEntry \
+-TPerlInterpreter \
-TPgStat_Counter \
-TPgStat_Info \
-TPgStat_Msg \
-TQuerySource \
-TRC2_KEY \
-TRC4_KEY \
+-TREGEXP \
-TRIPEMD160_CTX \
-TRI_QueryHashEntry \
-TRI_QueryKey \
-TSSL_METHOD \
-TSSL_SESSION \
-TSTACK \
+-TSTRLEN \
+-TSUBLEXINFO \
+-TSV \
+-TSVOP \
-TSaveArchivePtr \
-TScalarArrayOpExpr \
-TScalarArrayOpExprState \
-TShmemIndexEnt \
-TShutdownMode \
-TSigHandler \
+-TSighandler_t \
+-TSigsave_t \
-TSize \
-TSlruCtl \
-TSlruCtlData \
-TTableDataInfo \
-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 \
+-TThread \
-TTidPath \
-TTidScan \
-TTidScanState \
-TTypeFuncClass \
-TTypeInfo \
-TTypeName \
+-TU16 \
+-TU32 \
+-TU8 \
-TUI \
-TUI_METHOD \
-TUI_STRING \
-TUNDO_LIST \
+-TUNOP \
+-TUV \
-TUnique \
-TUniquePath \
-TUniquePathMethod \
-TXLogRelDesc \
-TXLogwrtResult \
-TXLogwrtRqst \
+-TXPV \
+-TXPVAV \
+-TXPVBM \
+-TXPVCV \
+-TXPVFM \
+-TXPVGV \
+-TXPVHV \
+-TXPVIO \
+-TXPVIV \
+-TXPVLV \
+-TXPVMG \
+-TXPVNV \
+-TXPVUV \
+-TXRV \
-TXactCallback \
-TXactCallbackItem \
-TXactEvent \
-Tchr \
-Tclock_t \
-Tclockid_t \
+-Tcodes_t \
-Tcolor \
+-Tcomment_t \
-Tconst_DES_cblock \
-Tcontain_var_reference_context \
+-Tcv_flags_t \
-Tdaddr_t \
+-Tdate \
-Tdatetkn \
+-Tdecimal \
-Tdeparse_context \
-Tdeparse_namespace \
-Tdev_t \
-Teval_const_expressions_context \
-TexecRowMark \
-Texecution_state \
+-Texpectation \
-Tf_smgr \
-Tfd_mask \
-Tfd_set \
+-Tfilter_t \
-Tfinalize_primnode_context \
-Tfind_expr_references_context \
-Tfind_minimum_var_level_context \
-Tint8 \
-Tint8_t \
-Tint8m_t \
+-Tinterval \
-Tintf \
-TitemIdSort \
-TitemIdSortData \
-TlclContext \
-TlclTocEntry \
-Tldiv_t \
+-Tline_t \
-TmXactCacheEnt \
-Tmacaddr \
-Tmb2wchar_with_len_converter \
-Tmode_t \
-Tnlink_t \
-Tnls_uint32 \
+-Tnumeric \
-TobjectType \
-Toff_t \
-Toidvector \
+-Top_tr_array \
+-Topcode \
+-Topindex \
-ToptType \
-Tpcolor \
-Tpem_password_cb \
+-TpgParameterStatus \
+-Tpg_conv_map \
-Tpg_crc32 \
-Tpg_enc \
-Tpg_enc2name \
-Tpgsql_thing_t \
-Tpgthreadlock_t \
-Tpid_t \
+-Tplperl_proc_desc \
+-Tplpgsql_HashEnt \
+-Tplpgsql_yysigned_char \
+-Tpltcl_proc_desc \
+-Tpltcl_query_desc \
-Tpqbool \
-Tpqsigfunc \
-TprintQueryOpt \
-Tptrdiff_t \
-Tpull_var_clause_context \
-Tpull_varnos_context \
+-Tpvcontents \
-Tq128_t \
-Tqaddr_t \
-Tquad_t \
-TrangeTableEntry_used_context \
-Treduce_outer_joins_state \
+-Tregcomp_t \
-Tregex_t \
+-Tregexec_t \
+-Tregexp \
-Tregister_t \
-Tregmatch_t \
+-Tregnode \
-Tregoff_t \
-Tregproc \
-TremoteDep \
-Trewrite_event \
-Trm_detail_t \
-Trune_t \
+-Trunops_proc_t \
-Tsa_family_t \
-Tsegsz_t \
-Tsequence_magic \
-Tssize_t \
-Tssl_crock_st \
-Tstack_t \
+-Tstrconst \
-Tsubstitute_actual_parameters_context \
+-Tsvindex \
+-Tsvtype \
-Tswblk_t \
-Ttcflag_t \
-Ttcp_seq \
-TteReqs \
-Ttext \
-Ttime_t \
+-Ttimestamp \
-Ttlist_vinfo \
-Tts_db_fctx \
-TuInt \