WIP pgindent replacement

Started by Andrew Dunstanover 14 years ago22 messages
#1Andrew Dunstan
andrew@dunslane.net
2 attachment(s)

Attached is a WIP possible replacement for pgindent. Instead of a shell
script invoking a mishmash of awk and sed, some of which is pretty
impenetrable, it uses a single engine (perl) to do all the pre and post
indent processing. Of course, if your regex-fu and perl-fu is not up the
scratch this too might be impenetrable, but all but a couple of the
recipes are reduced to single lines, and I'd argue that they are all at
least as comprehensible as what they replace.

Attached also is a diff file showing what it does differently from the
existing script. I think that these are all things where the new script
is more correct than the existing script. Most of the changes come into
two categories:

* places where the existing script fails to combine the function
return type and the function name on a single line in function
prototypes.
* places where unwanted blank lines are removed by the new script
but not by the existing script.

Features include:

* command line compatibility with the existing script, so you can do:
find ../../.. -name '*.[ch]' -type f -print | egrep -v -f
exclude_file_patterns | xargs -n100 ./pgindent.pl typedefs.list
* a new way of doing the same thing much more nicely:
./pgindent.pl --search-base=../../.. --typedefs=typedefs.list
--excludes=exclude_file_patterns
* only passes relevant typedefs to indent, not the whole huge list
* should in principle be runnable on Windows, unlike existing script
(I haven't tested yet)
* no semantic tab literals; tabs are only generated using \t and
tested for using \t, \h or \s as appropriate. This makes debugging
the script much less frustrating. If something looks like a space
it should be a space.

In one case I used perl's extended regex mode to comment a fairly hairy
regex. This should probably be done a bit more, maybe for all of them.

If anybody is so inclined, this could be used as a basis for removing
the use of bsd indent altogether, as has been suggested before, as well
as external entab/detab.

Comments welcome.

cheers

andrew

Attachments:

pgindent.plapplication/x-perl; name=pgindent.plDownload
indent.difftext/x-patch; name=indent.diffDownload
diff --git a/contrib/btree_gist/btree_bit.c b/contrib/btree_gist/btree_bit.c
index 8675d24..f69faaa 100644
--- a/contrib/btree_gist/btree_bit.c
+++ b/contrib/btree_gist/btree_bit.c
@@ -95,7 +95,6 @@ gbt_bit_xfrm(bytea *leaf)
 static GBT_VARKEY *
 gbt_bit_l2n(GBT_VARKEY *leaf)
 {
-
 	GBT_VARKEY *out = leaf;
 	GBT_VARKEY_R r = gbt_var_key_readable(leaf);
 	bytea	   *o;
diff --git a/contrib/btree_gist/btree_text.c b/contrib/btree_gist/btree_text.c
index 3d4f8c1..b55dc7c 100644
--- a/contrib/btree_gist/btree_text.c
+++ b/contrib/btree_gist/btree_text.c
@@ -119,7 +119,6 @@ gbt_text_compress(PG_FUNCTION_ARGS)
 Datum
 gbt_bpchar_compress(PG_FUNCTION_ARGS)
 {
-
 	GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
 	GISTENTRY  *retval;
 
diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c
index 9d3a591..185bed0 100644
--- a/contrib/btree_gist/btree_ts.c
+++ b/contrib/btree_gist/btree_ts.c
@@ -380,7 +380,6 @@ gbt_ts_union(PG_FUNCTION_ARGS)
 Datum
 gbt_ts_penalty(PG_FUNCTION_ARGS)
 {
-
 	tsKEY	   *origentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
 	tsKEY	   *newentry = (tsKEY *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
 	float	   *result = (float *) PG_GETARG_POINTER(2);
diff --git a/contrib/btree_gist/btree_utils_num.c b/contrib/btree_gist/btree_utils_num.c
index a3da580..8b8cd31 100644
--- a/contrib/btree_gist/btree_utils_num.c
+++ b/contrib/btree_gist/btree_utils_num.c
@@ -134,7 +134,6 @@ gbt_num_union(GBT_NUMKEY *out, const GistEntryVector *entryvec, const gbtree_nin
 bool
 gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo)
 {
-
 	GBT_NUMKEY_R b1,
 				b2;
 
@@ -156,7 +155,6 @@ gbt_num_same(const GBT_NUMKEY *a, const GBT_NUMKEY *b, const gbtree_ninfo *tinfo
 void
 gbt_num_bin_union(Datum *u, GBT_NUMKEY *e, const gbtree_ninfo *tinfo)
 {
-
 	GBT_NUMKEY_R rd;
 
 	rd.lower = &e[0];
diff --git a/contrib/btree_gist/btree_utils_var.c b/contrib/btree_gist/btree_utils_var.c
index e73799b..dc3ad38 100644
--- a/contrib/btree_gist/btree_utils_var.c
+++ b/contrib/btree_gist/btree_utils_var.c
@@ -54,7 +54,6 @@ gbt_var_decompress(PG_FUNCTION_ARGS)
 GBT_VARKEY_R
 gbt_var_key_readable(const GBT_VARKEY *k)
 {
-
 	GBT_VARKEY_R r;
 
 	r.lower = (bytea *) &(((char *) k)[VARHDRSZ]);
@@ -106,7 +105,6 @@ gbt_var_leaf2node(GBT_VARKEY *leaf, const gbtree_vinfo *tinfo)
 static int32
 gbt_var_node_cp_len(const GBT_VARKEY *node, const gbtree_vinfo *tinfo)
 {
-
 	GBT_VARKEY_R r = gbt_var_key_readable(node);
 	int32		i = 0;
 	int32		l = 0;
@@ -270,7 +268,6 @@ gbt_var_bin_union(Datum *u, GBT_VARKEY *e, Oid collation,
 GISTENTRY *
 gbt_var_compress(GISTENTRY *entry, const gbtree_vinfo *tinfo)
 {
-
 	GISTENTRY  *retval;
 
 	if (entry->leafkey)
@@ -299,7 +296,6 @@ GBT_VARKEY *
 gbt_var_union(const GistEntryVector *entryvec, int32 *size, Oid collation,
 			  const gbtree_vinfo *tinfo)
 {
-
 	int			i = 0,
 				numranges = entryvec->n;
 	GBT_VARKEY *cur;
diff --git a/contrib/pg_upgrade/exec.c b/contrib/pg_upgrade/exec.c
index b7d8266..51bc63b 100644
--- a/contrib/pg_upgrade/exec.c
+++ b/contrib/pg_upgrade/exec.c
@@ -94,7 +94,6 @@ is_server_running(const char *datadir)
 void
 verify_directories(void)
 {
-
 	prep_status("Checking current, bin, and data directories");
 
 	if (access(".", R_OK | W_OK
diff --git a/contrib/pg_upgrade/file.c b/contrib/pg_upgrade/file.c
index a7e4009..01ebb80 100644
--- a/contrib/pg_upgrade/file.c
+++ b/contrib/pg_upgrade/file.c
@@ -131,7 +131,6 @@ linkAndUpdateFile(pageCnvCtx *pageConverter,
 static int
 copy_file(const char *srcfile, const char *dstfile, bool force)
 {
-
 #define COPY_BUF_SIZE (50 * BLCKSZ)
 
 	int			src_fd;
diff --git a/contrib/pg_upgrade/page.c b/contrib/pg_upgrade/page.c
index 22a587f..e84690a 100644
--- a/contrib/pg_upgrade/page.c
+++ b/contrib/pg_upgrade/page.c
@@ -173,6 +173,4 @@ loadConverterPlugin(uint16 newPageVersion, uint16 oldPageVersion)
 	}
 }
 
-
-
 #endif
diff --git a/contrib/pgcrypto/imath.h b/contrib/pgcrypto/imath.h
index f2b02d0..cd48c14 100644
--- a/contrib/pgcrypto/imath.h
+++ b/contrib/pgcrypto/imath.h
@@ -117,14 +117,11 @@ mp_result	mp_int_mul_value(mp_int a, int value, mp_int c);
 mp_result	mp_int_mul_pow2(mp_int a, int p2, mp_int c);
 mp_result	mp_int_sqr(mp_int a, mp_int c);		/* c = a * a */
 
-mp_result
-mp_int_div(mp_int a, mp_int b,	/* q = a / b */
+mp_result mp_int_div(mp_int a, mp_int b,	/* q = a / b */
 		   mp_int q, mp_int r); /* r = a % b */
-mp_result
-mp_int_div_value(mp_int a, int value,	/* q = a / value */
+mp_result mp_int_div_value(mp_int a, int value,	/* q = a / value */
 				 mp_int q, int *r);		/* r = a % value */
-mp_result
-mp_int_div_pow2(mp_int a, int p2,		/* q = a / 2^p2  */
+mp_result mp_int_div_pow2(mp_int a, int p2,		/* q = a / 2^p2  */
 				mp_int q, mp_int r);	/* r = q % 2^p2  */
 mp_result	mp_int_mod(mp_int a, mp_int m, mp_int c);	/* c = a % m */
 
@@ -143,17 +140,13 @@ int			mp_int_divisible_value(mp_int a, int v);
 /* Returns k >= 0 such that z = 2^k, if one exists; otherwise < 0 */
 int			mp_int_is_pow2(mp_int z);
 
-mp_result
-mp_int_exptmod(mp_int a, mp_int b, mp_int m,
+mp_result mp_int_exptmod(mp_int a, mp_int b, mp_int m,
 			   mp_int c);		/* c = a^b (mod m) */
-mp_result
-mp_int_exptmod_evalue(mp_int a, int value,
+mp_result mp_int_exptmod_evalue(mp_int a, int value,
 					  mp_int m, mp_int c);		/* c = a^v (mod m) */
-mp_result
-mp_int_exptmod_bvalue(int value, mp_int b,
+mp_result mp_int_exptmod_bvalue(int value, mp_int b,
 					  mp_int m, mp_int c);		/* c = v^b (mod m) */
-mp_result
-mp_int_exptmod_known(mp_int a, mp_int b,
+mp_result mp_int_exptmod_known(mp_int a, mp_int b,
 					 mp_int m, mp_int mu,
 					 mp_int c); /* c = a^b (mod m) */
 mp_result	mp_int_redux_const(mp_int m, mp_int c);
@@ -162,8 +155,7 @@ mp_result	mp_int_invmod(mp_int a, mp_int m, mp_int c);		/* c = 1/a (mod m) */
 
 mp_result	mp_int_gcd(mp_int a, mp_int b, mp_int c);	/* c = gcd(a, b)   */
 
-mp_result
-mp_int_egcd(mp_int a, mp_int b, mp_int c,		/* c = gcd(a, b)   */
+mp_result mp_int_egcd(mp_int a, mp_int b, mp_int c,		/* c = gcd(a, b)   */
 			mp_int x, mp_int y);	/* c = ax + by	   */
 
 mp_result	mp_int_sqrt(mp_int a, mp_int c);	/* c = floor(sqrt(q)) */
diff --git a/contrib/pgcrypto/pgp.h b/contrib/pgcrypto/pgp.h
index 7ae01cc..3022abf 100644
--- a/contrib/pgcrypto/pgp.h
+++ b/contrib/pgcrypto/pgp.h
@@ -265,8 +265,7 @@ int			pgp_s2k_read(PullFilter *src, PGP_S2K *s2k);
 int			pgp_s2k_process(PGP_S2K *s2k, int cipher, const uint8 *key, int klen);
 
 typedef struct PGP_CFB PGP_CFB;
-int
-pgp_cfb_create(PGP_CFB **ctx_p, int algo,
+int pgp_cfb_create(PGP_CFB **ctx_p, int algo,
 			   const uint8 *key, int key_len, int recync, uint8 *iv);
 void		pgp_cfb_free(PGP_CFB *ctx);
 int			pgp_cfb_encrypt(PGP_CFB *ctx, const uint8 *data, int len, uint8 *dst);
diff --git a/src/backend/access/gin/ginbtree.c b/src/backend/access/gin/ginbtree.c
index 739fa8a..3160bce 100644
--- a/src/backend/access/gin/ginbtree.c
+++ b/src/backend/access/gin/ginbtree.c
@@ -177,7 +177,6 @@ void
 ginFindParents(GinBtree btree, GinBtreeStack *stack,
 			   BlockNumber rootBlkno)
 {
-
 	Page		page;
 	Buffer		buffer;
 	BlockNumber blkno,
diff --git a/src/backend/access/gist/gistutil.c b/src/backend/access/gist/gistutil.c
index 1754a10..9736f49 100644
--- a/src/backend/access/gist/gistutil.c
+++ b/src/backend/access/gist/gistutil.c
@@ -242,7 +242,6 @@ gistMakeUnionKey(GISTSTATE *giststate, int attno,
 				 GISTENTRY *entry2, bool isnull2,
 				 Datum *dst, bool *dstisnull)
 {
-
 	int			dstsize;
 
 	static char storage[2 * sizeof(GISTENTRY) + GEVHDRSZ];
diff --git a/src/backend/optimizer/geqo/geqo_cx.c b/src/backend/optimizer/geqo/geqo_cx.c
index afae948..9f6d5e4 100644
--- a/src/backend/optimizer/geqo/geqo_cx.c
+++ b/src/backend/optimizer/geqo/geqo_cx.c
@@ -47,7 +47,6 @@ int
 cx(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring,
    int num_gene, City *city_table)
 {
-
 	int			i,
 				start_pos,
 				curr_pos;
diff --git a/src/backend/optimizer/geqo/geqo_px.c b/src/backend/optimizer/geqo/geqo_px.c
index 808ff6a..99289bc 100644
--- a/src/backend/optimizer/geqo/geqo_px.c
+++ b/src/backend/optimizer/geqo/geqo_px.c
@@ -46,7 +46,6 @@ void
 px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene,
    City *city_table)
 {
-
 	int			num_positions;
 	int			i,
 				pos,
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 726a1f4..3749668 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -1044,7 +1044,6 @@ suff_search(char *str, KeySuffix *suf, int type)
 static void
 NUMDesc_prepare(NUMDesc *num, FormatNode *n)
 {
-
 	if (n->type != NODE_TYPE_ACTION)
 		return;
 
diff --git a/src/backend/utils/adt/tsquery_rewrite.c b/src/backend/utils/adt/tsquery_rewrite.c
index e2faed2..b2c61e0 100644
--- a/src/backend/utils/adt/tsquery_rewrite.c
+++ b/src/backend/utils/adt/tsquery_rewrite.c
@@ -47,7 +47,6 @@ addone(int *counters, int last, int total)
 static QTNode *
 findeq(QTNode *node, QTNode *ex, QTNode *subs, bool *isfind)
 {
-
 	if ((node->sign & ex->sign) != ex->sign ||
 		node->valnode->type != ex->valnode->type)
 		return node;
@@ -197,7 +196,6 @@ dofindsubquery(QTNode *root, QTNode *ex, QTNode *subs, bool *isfind)
 static QTNode *
 dropvoidsubtree(QTNode *root)
 {
-
 	if (!root)
 		return NULL;
 
diff --git a/src/bin/pgevent/pgevent.c b/src/bin/pgevent/pgevent.c
index 1fcde86..11747ae 100644
--- a/src/bin/pgevent/pgevent.c
+++ b/src/bin/pgevent/pgevent.c
@@ -20,8 +20,7 @@
 HANDLE		g_module = NULL;	/* hModule of DLL */
 
 /* Prototypes */
-STDAPI
-DllRegisterServer(void);
+STDAPI DllRegisterServer(void);
 STDAPI		DllUnregisterServer(void);
 BOOL WINAPI DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved);
 
diff --git a/src/include/access/sysattr.h b/src/include/access/sysattr.h
index 1b3e64a..bc52adc 100644
--- a/src/include/access/sysattr.h
+++ b/src/include/access/sysattr.h
@@ -27,5 +27,4 @@
 #define TableOidAttributeNumber					(-7)
 #define FirstLowInvalidHeapAttributeNumber		(-8)
 
-
 #endif   /* SYSATTR_H */
diff --git a/src/include/storage/predicate_internals.h b/src/include/storage/predicate_internals.h
index 495983f..b89e9bb 100644
--- a/src/include/storage/predicate_internals.h
+++ b/src/include/storage/predicate_internals.h
@@ -468,5 +468,4 @@ typedef struct TwoPhasePredicateRecord
  */
 extern PredicateLockData *GetPredicateLockStatusData(void);
 
-
 #endif   /* PREDICATE_INTERNALS_H */
diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h
index a1ca012..8caddb4 100644
--- a/src/include/utils/guc_tables.h
+++ b/src/include/utils/guc_tables.h
@@ -256,5 +256,4 @@ extern const char *config_enum_lookup_by_value(struct config_enum * record, int
 extern bool config_enum_lookup_by_name(struct config_enum * record,
 						   const char *value, int *retval);
 
-
 #endif   /* GUC_TABLES_H */
diff --git a/src/interfaces/ecpg/compatlib/informix.c b/src/interfaces/ecpg/compatlib/informix.c
index 3b30864..d6de3ea 100644
--- a/src/interfaces/ecpg/compatlib/informix.c
+++ b/src/interfaces/ecpg/compatlib/informix.c
@@ -311,7 +311,6 @@ deccvlong(long lng, decimal *np)
 int
 decdiv(decimal *n1, decimal *n2, decimal *result)
 {
-
 	int			i;
 
 	errno = 0;
diff --git a/src/interfaces/ecpg/pgtypeslib/datetime.c b/src/interfaces/ecpg/pgtypeslib/datetime.c
index 41377a6..82ce55e 100644
--- a/src/interfaces/ecpg/pgtypeslib/datetime.c
+++ b/src/interfaces/ecpg/pgtypeslib/datetime.c
@@ -52,7 +52,6 @@ PGTYPESdate_from_timestamp(timestamp dt)
 date
 PGTYPESdate_from_asc(char *str, char **endptr)
 {
-
 	date		dDate;
 	fsec_t		fsec;
 	struct tm	tt,
diff --git a/src/interfaces/ecpg/pgtypeslib/numeric.c b/src/interfaces/ecpg/pgtypeslib/numeric.c
index 7257c81..c56dda0 100644
--- a/src/interfaces/ecpg/pgtypeslib/numeric.c
+++ b/src/interfaces/ecpg/pgtypeslib/numeric.c
@@ -1362,7 +1362,6 @@ done:
 int
 PGTYPESnumeric_cmp(numeric *var1, numeric *var2)
 {
-
 	/* use cmp_abs function to calculate the result */
 
 	/* both are positive: normal comparation with cmp_abs */
diff --git a/src/interfaces/ecpg/pgtypeslib/timestamp.c b/src/interfaces/ecpg/pgtypeslib/timestamp.c
index 8354e46..9604ee4 100644
--- a/src/interfaces/ecpg/pgtypeslib/timestamp.c
+++ b/src/interfaces/ecpg/pgtypeslib/timestamp.c
@@ -949,7 +949,6 @@ int
 PGTYPEStimestamp_add_interval(timestamp * tin, interval * span, timestamp * tout)
 {
 
-
 	if (TIMESTAMP_NOT_FINITE(*tin))
 		*tout = *tin;
 
diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c
index 5fa3be0..d8c62a1 100644
--- a/src/interfaces/libpq/fe-print.c
+++ b/src/interfaces/libpq/fe-print.c
@@ -330,7 +330,6 @@ do_field(const PQprintOpt *po, const PGresult *res,
 		 unsigned char *fieldNotNum, int *fieldMax,
 		 const int fieldMaxLen, FILE *fout)
 {
-
 	const char *pval,
 			   *p;
 	int			plen;
@@ -442,7 +441,6 @@ do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax,
 		  const char **fieldNames, unsigned char *fieldNotNum,
 		  const int fs_len, const PGresult *res)
 {
-
 	int			j;				/* for loop index */
 	char	   *border = NULL;
 
@@ -529,7 +527,6 @@ output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
 		   unsigned char *fieldNotNum, int *fieldMax, char *border,
 		   const int row_index)
 {
-
 	int			field_index;	/* for loop index */
 
 	if (po->html3)
diff --git a/src/interfaces/libpq/libpq-events.h b/src/interfaces/libpq/libpq-events.h
index 05417d0..4a3740c 100644
--- a/src/interfaces/libpq/libpq-events.h
+++ b/src/interfaces/libpq/libpq-events.h
@@ -24,7 +24,7 @@ extern		"C"
 #endif
 
 /* Callback Event Ids */
-			typedef enum
+typedef enum
 {
 	PGEVT_REGISTER,
 	PGEVT_CONNRESET,
diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h
index d780275..80ada5e 100644
--- a/src/interfaces/libpq/libpq-fe.h
+++ b/src/interfaces/libpq/libpq-fe.h
@@ -504,24 +504,21 @@ extern unsigned char *PQescapeBytea(const unsigned char *from, size_t from_lengt
 
 /* === in fe-print.c === */
 
-extern void
-PQprint(FILE *fout,				/* output stream */
+extern void PQprint(FILE *fout,				/* output stream */
 		const PGresult *res,
 		const PQprintOpt *ps);	/* option structure */
 
 /*
  * really old printing routines
  */
-extern void
-PQdisplayTuples(const PGresult *res,
+extern void PQdisplayTuples(const PGresult *res,
 				FILE *fp,		/* where to send the output */
 				int fillAlign,	/* pad the fields with spaces */
 				const char *fieldSep,	/* field separator */
 				int printHeader,	/* display headers? */
 				int quiet);
 
-extern void
-PQprintTuples(const PGresult *res,
+extern void PQprintTuples(const PGresult *res,
 			  FILE *fout,		/* output stream */
 			  int printAttName, /* print attribute names */
 			  int terseOutput,	/* delimiter bars */
diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h
index c4810cb..07ff81e 100644
--- a/src/pl/plperl/plperl.h
+++ b/src/pl/plperl/plperl.h
@@ -102,6 +102,4 @@ void		plperl_spi_freeplan(char *);
 void		plperl_spi_cursor_close(char *);
 char	   *plperl_sv_to_literal(SV *, char *);
 
-
-
 #endif   /* PL_PERL_H */
#2Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#1)
Re: WIP pgindent replacement

Andrew Dunstan wrote:

Attached is a WIP possible replacement for pgindent. Instead of a shell
script invoking a mishmash of awk and sed, some of which is pretty
impenetrable, it uses a single engine (perl) to do all the pre and post
indent processing. Of course, if your regex-fu and perl-fu is not up the
scratch this too might be impenetrable, but all but a couple of the
recipes are reduced to single lines, and I'd argue that they are all at
least as comprehensible as what they replace.

I am excited Andrew has done this. It has been on my TODO list for a
while --- I was hoping someday we could switch to GNU indent but gave up
after the GNU indent report from Greg Stark that exactly matched my
experience years ago:

http://archives.postgresql.org/pgsql-hackers/2011-04/msg01436.php

Basically, GNU indent has new bugs, but bugs that are harder to work
around than the BSD indent bugs.

Once I heard that I realized we were going to be using BSD indent for
many more years to come and rewriting the shell script in Perl was the
next logical step, which Andrew has done.

This will also allow us to use pgindent on Windows that has Perl
installed --- we should create a DOS binary of bsd indent so Windows
users scan run it.

I would also like to add a command-line way to detect our patched
version of BSD indent so we know we are using the right binary. I will
do that once the Perl version is committed to git.

Thanks Andrew.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andrew Dunstan (#1)
Re: WIP pgindent replacement

Andrew Dunstan <andrew@dunslane.net> writes:

Attached is a WIP possible replacement for pgindent. Instead of a shell
script invoking a mishmash of awk and sed, some of which is pretty
impenetrable, it uses a single engine (perl) to do all the pre and post
indent processing.

Hm ... this should offer the chance of running on Windows, but otherwise
I'm not sure it does very much for us, if you still have to have a
patched version of NetBSD indent underneath.

If anybody is so inclined, this could be used as a basis for removing
the use of bsd indent altogether, as has been suggested before, as well
as external entab/detab.

Now *that* I would get excited about. But surely it would be a huge
amount more work?

regards, tom lane

#4Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#3)
Re: WIP pgindent replacement

On 06/21/2011 11:15 PM, Tom Lane wrote:

Andrew Dunstan<andrew@dunslane.net> writes:

Attached is a WIP possible replacement for pgindent. Instead of a shell
script invoking a mishmash of awk and sed, some of which is pretty
impenetrable, it uses a single engine (perl) to do all the pre and post
indent processing.

Hm ... this should offer the chance of running on Windows, but otherwise
I'm not sure it does very much for us, if you still have to have a
patched version of NetBSD indent underneath.

Well, to start with it provides a nicer way to invoke pgindent for the
whole repo.

And it will be relatively easy to incorporate new stuff, for example
what Greg Smith was doing in his wrapper script.

It's true that the script contains an unfortunately large number of
workarounds for the limitations and failure modes of the patched bsd
indent we've been using. Some of those are currently working less than
perfectly, and I found it fairly difficult to understand exactly what
they were doing. I hope what I have produced will be a bit clearer and
more maintainable than what it replaces, as well as working a bit better
and more robustly.

If anybody is so inclined, this could be used as a basis for removing
the use of bsd indent altogether, as has been suggested before, as well
as external entab/detab.

Now *that* I would get excited about. But surely it would be a huge
amount more work?

Yes, which is why I decided to do this - I certainly don't currently
have time to re-implement indent.

cheers

andrew

#5David Christensen
david@endpoint.com
In reply to: Andrew Dunstan (#1)
Re: WIP pgindent replacement

# Avoid bug that converts 'x =- 1' to 'x = -1'

$source =~ s!=- !-= !g;

I haven't looked at the shell script this replaces, but is that the correct substitution pattern? (BTW, I'm not seeing the token =- anywhere except in the Makefile, which wouldn't be run against, no? Am I missing something?)

Regards,

David
--
David Christensen
End Point Corporation
david@endpoint.com

#6Andrew Dunstan
andrew@dunslane.net
In reply to: David Christensen (#5)
Re: WIP pgindent replacement

On 06/22/2011 02:03 AM, David Christensen wrote:

# Avoid bug that converts 'x =- 1' to 'x = -1'
$source =~ s!=- !-= !g;

I haven't looked at the shell script this replaces, but is that the correct substitution pattern? (BTW, I'm not seeing the token =- anywhere except in the Makefile, which wouldn't be run against, no? Am I missing something?)

It's exactly what the current script does. The reason you don't see this
anywhere is that previous pgindent runs have removed it. We don't undo
the transformation. But maybe we should just get rid of it.

cheers

andrew

#7Andrew Dunstan
andrew@dunslane.net
In reply to: Andrew Dunstan (#6)
Re: WIP pgindent replacement

On 06/22/2011 08:35 AM, Andrew Dunstan wrote:

On 06/22/2011 02:03 AM, David Christensen wrote:

# Avoid bug that converts 'x =- 1' to 'x = -1'
$source =~ s!=- !-= !g;

I haven't looked at the shell script this replaces, but is that the
correct substitution pattern? (BTW, I'm not seeing the token =-
anywhere except in the Makefile, which wouldn't be run against, no?
Am I missing something?)

It's exactly what the current script does. The reason you don't see
this anywhere is that previous pgindent runs have removed it. We don't
undo the transformation. But maybe we should just get rid of it.

Further research shows that C89 explicitly dropped support for the old
K&R "=-" operator, so we probably *should* remove this in case it
introduces an unintended bug.

cheers

andrew

#8Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#7)
Re: WIP pgindent replacement

Andrew Dunstan wrote:

On 06/22/2011 08:35 AM, Andrew Dunstan wrote:

On 06/22/2011 02:03 AM, David Christensen wrote:

# Avoid bug that converts 'x =- 1' to 'x = -1'
$source =~ s!=- !-= !g;

I haven't looked at the shell script this replaces, but is that the
correct substitution pattern? (BTW, I'm not seeing the token =-
anywhere except in the Makefile, which wouldn't be run against, no?
Am I missing something?)

It's exactly what the current script does. The reason you don't see
this anywhere is that previous pgindent runs have removed it. We don't
undo the transformation. But maybe we should just get rid of it.

Further research shows that C89 explicitly dropped support for the old
K&R "=-" operator, so we probably *should* remove this in case it
introduces an unintended bug.

Well, the point is if someone does use that, it isn't going to generate
a pgindent error, but rather produce incorrect C code because =- is
going to be changed. FYI, my gcc 2.95.3 allows =- and does work as
intended.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#9Andrew Dunstan
andrew@dunslane.net
In reply to: Bruce Momjian (#8)
Re: WIP pgindent replacement

On 06/22/2011 09:08 AM, Bruce Momjian wrote:

Andrew Dunstan wrote:

On 06/22/2011 08:35 AM, Andrew Dunstan wrote:

On 06/22/2011 02:03 AM, David Christensen wrote:

# Avoid bug that converts 'x =- 1' to 'x = -1'
$source =~ s!=- !-= !g;

I haven't looked at the shell script this replaces, but is that the
correct substitution pattern? (BTW, I'm not seeing the token =-
anywhere except in the Makefile, which wouldn't be run against, no?
Am I missing something?)

It's exactly what the current script does. The reason you don't see
this anywhere is that previous pgindent runs have removed it. We don't
undo the transformation. But maybe we should just get rid of it.

Further research shows that C89 explicitly dropped support for the old
K&R "=-" operator, so we probably *should* remove this in case it
introduces an unintended bug.

Well, the point is if someone does use that, it isn't going to generate
a pgindent error, but rather produce incorrect C code because =- is
going to be changed. FYI, my gcc 2.95.3 allows =- and does work as
intended.

As intended by whom? If the effect of "x=4; x =- 1;" is to subtract 1
from x then that's simply wrong by C89. It should assign -1 to x. The
"=-" must be parsed as two operators in C89, assignment and unary minus.
pgindent should not under any circumstances change the semantics of the
program being indented, and that's what this transformation does for
compilers conforming to the standard we explicitly follow.

What happens when your ancient gcc is told to apply the ansi standard?

cheers

andrew

#10Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#9)
Re: WIP pgindent replacement

Andrew Dunstan wrote:

Further research shows that C89 explicitly dropped support for the old
K&R "=-" operator, so we probably *should* remove this in case it
introduces an unintended bug.

Well, the point is if someone does use that, it isn't going to generate
a pgindent error, but rather produce incorrect C code because =- is
going to be changed. FYI, my gcc 2.95.3 allows =- and does work as
intended.

As intended by whom? If the effect of "x=4; x =- 1;" is to subtract 1
from x then that's simply wrong by C89. It should assign -1 to x. The
"=-" must be parsed as two operators in C89, assignment and unary minus.
pgindent should not under any circumstances change the semantics of the
program being indented, and that's what this transformation does for
compilers conforming to the standard we explicitly follow.

What happens when your ancient gcc is told to apply the ansi standard?

I see now that my test wasn't complete. You are right it assigns -1 so
we can remove this from pgupgrade.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#11Bruce Momjian
bruce@momjian.us
In reply to: Bruce Momjian (#10)
Re: WIP pgindent replacement

On Wed, Jun 22, 2011 at 10:16:28AM -0400, Bruce Momjian wrote:

Andrew Dunstan wrote:

Further research shows that C89 explicitly dropped support for the old
K&R "=-" operator, so we probably *should* remove this in case it
introduces an unintended bug.

Well, the point is if someone does use that, it isn't going to generate
a pgindent error, but rather produce incorrect C code because =- is
going to be changed. FYI, my gcc 2.95.3 allows =- and does work as
intended.

As intended by whom? If the effect of "x=4; x =- 1;" is to subtract 1
from x then that's simply wrong by C89. It should assign -1 to x. The
"=-" must be parsed as two operators in C89, assignment and unary minus.
pgindent should not under any circumstances change the semantics of the
program being indented, and that's what this transformation does for
compilers conforming to the standard we explicitly follow.

What happens when your ancient gcc is told to apply the ansi standard?

I see now that my test wasn't complete. You are right it assigns -1 so
we can remove this from pgindent.

Per report form last year, removed from pgindent.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#12Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#1)
1 attachment(s)
Re: WIP pgindent replacement

On Tue, Jun 21, 2011 at 08:27:45PM -0400, Andrew Dunstan wrote:

Attached is a WIP possible replacement for pgindent. Instead of a
shell script invoking a mishmash of awk and sed, some of which is
pretty impenetrable, it uses a single engine (perl) to do all the
pre and post indent processing. Of course, if your regex-fu and
perl-fu is not up the scratch this too might be impenetrable, but
all but a couple of the recipes are reduced to single lines, and I'd
argue that they are all at least as comprehensible as what they
replace.

Attached also is a diff file showing what it does differently from
the existing script. I think that these are all things where the new
script is more correct than the existing script. Most of the changes
come into two categories:

* places where the existing script fails to combine the function
return type and the function name on a single line in function
prototypes.
* places where unwanted blank lines are removed by the new script
but not by the existing script.

Features include:

* command line compatibility with the existing script, so you can do:
find ../../.. -name '*.[ch]' -type f -print | egrep -v -f
exclude_file_patterns | xargs -n100 ./pgindent.pl typedefs.list
* a new way of doing the same thing much more nicely:
./pgindent.pl --search-base=../../.. --typedefs=typedefs.list
--excludes=exclude_file_patterns
* only passes relevant typedefs to indent, not the whole huge list
* should in principle be runnable on Windows, unlike existing script
(I haven't tested yet)
* no semantic tab literals; tabs are only generated using \t and
tested for using \t, \h or \s as appropriate. This makes debugging
the script much less frustrating. If something looks like a space
it should be a space.

In one case I used perl's extended regex mode to comment a fairly
hairy regex. This should probably be done a bit more, maybe for all
of them.

If anybody is so inclined, this could be used as a basis for
removing the use of bsd indent altogether, as has been suggested
before, as well as external entab/detab.

Thirteen months after Andrew posted this WIP, I have restructured and
tested this code, and it is now ready to replace the pgindent shell
script as pgindent.pl, attached.

I have tested this version by re-running the 9.1 and 9.2 pgindent runs
and comparing the output, and it is just like Andrew said --- it is the
same, except for the two improvements he mentioned.

A Perl version of pgindent has several advantages:

* more portable; less dependent on utility command variances
* able to run on Windows, assuming someone makes entab and
pg_bsd_indent Windows binaries
* able to fix more limitations of pgindent

I will add documentation about the arguments.

Many thanks to Andrew for his fine work on this. Any objections?

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachments:

pgindent.newtext/plain; charset=us-asciiDownload
#13Andrew Dunstan
andrew@dunslane.net
In reply to: Bruce Momjian (#12)
Re: WIP pgindent replacement

On 08/02/2012 11:09 PM, Bruce Momjian wrote:

Thirteen months after Andrew posted this WIP, I have restructured and
tested this code, and it is now ready to replace the pgindent shell
script as pgindent.pl, attached.

I have tested this version by re-running the 9.1 and 9.2 pgindent runs
and comparing the output, and it is just like Andrew said --- it is the
same, except for the two improvements he mentioned.

A Perl version of pgindent has several advantages:

* more portable; less dependent on utility command variances
* able to run on Windows, assuming someone makes entab and
pg_bsd_indent Windows binaries
* able to fix more limitations of pgindent

I will add documentation about the arguments.

Many thanks to Andrew for his fine work on this. Any objections?

Thanks for not forgetting this.

I think we generally don't put file type extensions on commands, so this
should probably just be renamed pgindent. If someone wants to go back to
the old shell script they can still get it from git.

cheers

andrew

#14Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#13)
Re: WIP pgindent replacement

On Fri, Aug 3, 2012 at 08:26:50AM -0400, Andrew Dunstan wrote:

On 08/02/2012 11:09 PM, Bruce Momjian wrote:

Thirteen months after Andrew posted this WIP, I have restructured and
tested this code, and it is now ready to replace the pgindent shell
script as pgindent.pl, attached.

I have tested this version by re-running the 9.1 and 9.2 pgindent runs
and comparing the output, and it is just like Andrew said --- it is the
same, except for the two improvements he mentioned.

A Perl version of pgindent has several advantages:

* more portable; less dependent on utility command variances
* able to run on Windows, assuming someone makes entab and
pg_bsd_indent Windows binaries
* able to fix more limitations of pgindent

I will add documentation about the arguments.

Many thanks to Andrew for his fine work on this. Any objections?

Thanks for not forgetting this.

I think we generally don't put file type extensions on commands, so
this should probably just be renamed pgindent. If someone wants to
go back to the old shell script they can still get it from git.

Of course. I was just noticing that most of the Perl scripts in
/src/tools and src/tools/msvc have a .pl extension on the file name, so
I was following that style. Is that valid?

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#15Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#14)
Re: WIP pgindent replacement

Bruce Momjian <bruce@momjian.us> writes:

On Fri, Aug 3, 2012 at 08:26:50AM -0400, Andrew Dunstan wrote:

I think we generally don't put file type extensions on commands, so
this should probably just be renamed pgindent. If someone wants to
go back to the old shell script they can still get it from git.

Of course. I was just noticing that most of the Perl scripts in
/src/tools and src/tools/msvc have a .pl extension on the file name, so
I was following that style. Is that valid?

Well, you're replacing the old script, so it has to keep the same name.

IMO adding such an extension to an executable script isn't a terribly
good practice, because it turns what ought to be an implementation
detail into part of the script's API. Had the shell script been named
pgindent.sh to begin with, we'd now be stuck with the unpalatable
alternatives of changing the name or using an extension that lies
about the implementation language. I don't much care for putting
in an assumption that the Perl implementation will never be replaced,
either.

regards, tom lane

#16Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#15)
Re: WIP pgindent replacement

On Fri, Aug 3, 2012 at 10:33 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Bruce Momjian <bruce@momjian.us> writes:

On Fri, Aug 3, 2012 at 08:26:50AM -0400, Andrew Dunstan wrote:

I think we generally don't put file type extensions on commands, so
this should probably just be renamed pgindent. If someone wants to
go back to the old shell script they can still get it from git.

Of course. I was just noticing that most of the Perl scripts in
/src/tools and src/tools/msvc have a .pl extension on the file name, so
I was following that style. Is that valid?

Well, you're replacing the old script, so it has to keep the same name.

IMO adding such an extension to an executable script isn't a terribly
good practice, because it turns what ought to be an implementation
detail into part of the script's API. Had the shell script been named
pgindent.sh to begin with, we'd now be stuck with the unpalatable
alternatives of changing the name or using an extension that lies
about the implementation language. I don't much care for putting
in an assumption that the Perl implementation will never be replaced,
either.

+1.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#17Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#15)
Re: WIP pgindent replacement

On Fri, Aug 3, 2012 at 10:33:21AM -0400, Tom Lane wrote:

Bruce Momjian <bruce@momjian.us> writes:

On Fri, Aug 3, 2012 at 08:26:50AM -0400, Andrew Dunstan wrote:

I think we generally don't put file type extensions on commands, so
this should probably just be renamed pgindent. If someone wants to
go back to the old shell script they can still get it from git.

Of course. I was just noticing that most of the Perl scripts in
/src/tools and src/tools/msvc have a .pl extension on the file name, so
I was following that style. Is that valid?

Well, you're replacing the old script, so it has to keep the same name.

IMO adding such an extension to an executable script isn't a terribly
good practice, because it turns what ought to be an implementation
detail into part of the script's API. Had the shell script been named
pgindent.sh to begin with, we'd now be stuck with the unpalatable
alternatives of changing the name or using an extension that lies
about the implementation language. I don't much care for putting
in an assumption that the Perl implementation will never be replaced,
either.

OK, sure, we can keep the pgindent name --- I was just trying to be
consistent. One problem with the lack of an extension is that there is
no easy way for the Perl cleanup instructions to find all the Perl
executables --- right now it looks for an extension. Do we have other
Perl scripts in our tree that don't end in *.pl or *.pm? I didn't find
any with this script:

$ find . -type f -exec file {} \;|grep Perl
./src/backend/catalog/Catalog.pm: Perl5 module source text
./src/tools/msvc/MSBuildProject.pm: Perl5 module source text
./src/tools/msvc/Project.pm: Perl5 module source text
./src/tools/msvc/Mkvcbuild.pm: Perl5 module source text
./src/tools/msvc/Install.pm: Perl5 module source text
./src/tools/msvc/Solution.pm: Perl5 module source text
./src/tools/msvc/VCBuildProject.pm: Perl5 module source text
./src/tools/msvc/VSObjectFactory.pm: Perl5 module source text

We can hard-code pgindent as one we chould perltidy.

FYI, personally, I have never been a big fan of using *.pl for things I
normally run, like scripts in /usr/local/bin, but I sometimes use *.pl
for utility stuff.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#18Andrew Dunstan
andrew@dunslane.net
In reply to: Bruce Momjian (#17)
Re: WIP pgindent replacement

On 08/03/2012 10:51 AM, Bruce Momjian wrote:

OK, sure, we can keep the pgindent name --- I was just trying to be
consistent. One problem with the lack of an extension is that there is
no easy way for the Perl cleanup instructions to find all the Perl
executables --- right now it looks for an extension. Do we have other
Perl scripts in our tree that don't end in *.pl or *.pm? I didn't find
any with this script:

$ find . -type f -exec file {} \;|grep Perl
./src/backend/catalog/Catalog.pm: Perl5 module source text
./src/tools/msvc/MSBuildProject.pm: Perl5 module source text
./src/tools/msvc/Project.pm: Perl5 module source text
./src/tools/msvc/Mkvcbuild.pm: Perl5 module source text
./src/tools/msvc/Install.pm: Perl5 module source text
./src/tools/msvc/Solution.pm: Perl5 module source text
./src/tools/msvc/VCBuildProject.pm: Perl5 module source text
./src/tools/msvc/VSObjectFactory.pm: Perl5 module source text

Try:

find . -exec file {} \; | egrep 'perl script|perl -w script|Perl5
module'

cheers

andrew

#19Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#18)
Re: WIP pgindent replacement

On Fri, Aug 3, 2012 at 12:51:03PM -0400, Andrew Dunstan wrote:

On 08/03/2012 10:51 AM, Bruce Momjian wrote:

OK, sure, we can keep the pgindent name --- I was just trying to be
consistent. One problem with the lack of an extension is that there is
no easy way for the Perl cleanup instructions to find all the Perl
executables --- right now it looks for an extension. Do we have other
Perl scripts in our tree that don't end in *.pl or *.pm? I didn't find
any with this script:

$ find . -type f -exec file {} \;|grep Perl
./src/backend/catalog/Catalog.pm: Perl5 module source text
./src/tools/msvc/MSBuildProject.pm: Perl5 module source text
./src/tools/msvc/Project.pm: Perl5 module source text
./src/tools/msvc/Mkvcbuild.pm: Perl5 module source text
./src/tools/msvc/Install.pm: Perl5 module source text
./src/tools/msvc/Solution.pm: Perl5 module source text
./src/tools/msvc/VCBuildProject.pm: Perl5 module source text
./src/tools/msvc/VSObjectFactory.pm: Perl5 module source text

Try:

find . -exec file {} \; | egrep 'perl script|perl -w script|Perl5
module'

OK, I used:

$ find . -type f -exec file {} \;|
egrep -i 'perl.*(script|module)'|grep -v '\.p[lm]:'

and got:

./src/pl/plperl/ppport.h: awk script text
./src/tools/pginclude/pgcheckdefines: a /usr/bin/perl -w script text executable
./src/tools/git_changelog: a /usr/bin/perl script text executable

The last two are Perl scripts without Perl file extensions, so let's
just go with 'pgindent' and I will hard-code those into the perltidy
instructions.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#20Andrew Dunstan
andrew@dunslane.net
In reply to: Bruce Momjian (#19)
Re: WIP pgindent replacement

On 08/03/2012 01:23 PM, Bruce Momjian wrote:

On Fri, Aug 3, 2012 at 12:51:03PM -0400, Andrew Dunstan wrote:

On 08/03/2012 10:51 AM, Bruce Momjian wrote:

OK, sure, we can keep the pgindent name --- I was just trying to be
consistent. One problem with the lack of an extension is that there is
no easy way for the Perl cleanup instructions to find all the Perl
executables --- right now it looks for an extension. Do we have other
Perl scripts in our tree that don't end in *.pl or *.pm? I didn't find
any with this script:

$ find . -type f -exec file {} \;|grep Perl
./src/backend/catalog/Catalog.pm: Perl5 module source text
./src/tools/msvc/MSBuildProject.pm: Perl5 module source text
./src/tools/msvc/Project.pm: Perl5 module source text
./src/tools/msvc/Mkvcbuild.pm: Perl5 module source text
./src/tools/msvc/Install.pm: Perl5 module source text
./src/tools/msvc/Solution.pm: Perl5 module source text
./src/tools/msvc/VCBuildProject.pm: Perl5 module source text
./src/tools/msvc/VSObjectFactory.pm: Perl5 module source text

Try:

find . -exec file {} \; | egrep 'perl script|perl -w script|Perl5
module'

OK, I used:

$ find . -type f -exec file {} \;|
egrep -i 'perl.*(script|module)'|grep -v '\.p[lm]:'

and got:

./src/pl/plperl/ppport.h: awk script text
./src/tools/pginclude/pgcheckdefines: a /usr/bin/perl -w script text executable
./src/tools/git_changelog: a /usr/bin/perl script text executable

The last two are Perl scripts without Perl file extensions, so let's
just go with 'pgindent' and I will hard-code those into the perltidy
instructions.

Your pattern has produced a false positive, though. Wouldn't it be
better not to hardcode anything?

cheers

andrew

#21Bruce Momjian
bruce@momjian.us
In reply to: Andrew Dunstan (#20)
Re: WIP pgindent replacement

On Fri, Aug 3, 2012 at 02:08:34PM -0400, Andrew Dunstan wrote:

$ find . -type f -exec file {} \;|
egrep -i 'perl.*(script|module)'|grep -v '\.p[lm]:'

and got:

./src/pl/plperl/ppport.h: awk script text
./src/tools/pginclude/pgcheckdefines: a /usr/bin/perl -w script text executable
./src/tools/git_changelog: a /usr/bin/perl script text executable

The last two are Perl scripts without Perl file extensions, so let's
just go with 'pgindent' and I will hard-code those into the perltidy
instructions.

Your pattern has produced a false positive, though. Wouldn't it be
better not to hardcode anything?

You mean use an actual 'grep' to find the Perl programs --- I can do
that.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

#22Bruce Momjian
bruce@momjian.us
In reply to: Bruce Momjian (#21)
Re: WIP pgindent replacement

On Fri, Aug 3, 2012 at 02:53:08PM -0400, Bruce Momjian wrote:

On Fri, Aug 3, 2012 at 02:08:34PM -0400, Andrew Dunstan wrote:

$ find . -type f -exec file {} \;|
egrep -i 'perl.*(script|module)'|grep -v '\.p[lm]:'

and got:

./src/pl/plperl/ppport.h: awk script text
./src/tools/pginclude/pgcheckdefines: a /usr/bin/perl -w script text executable
./src/tools/git_changelog: a /usr/bin/perl script text executable

The last two are Perl scripts without Perl file extensions, so let's
just go with 'pgindent' and I will hard-code those into the perltidy
instructions.

Your pattern has produced a false positive, though. Wouldn't it be
better not to hardcode anything?

You mean use an actual 'grep' to find the Perl programs --- I can do
that.

OK, pgindent replaced by Perl version. I had to go with both a file
extension check and 'file' output check because some Perl scripts only
match one category; checks are:

(
find . -name \*.pl -o -name \*.pm

find . -type f -exec file {} \; |
egrep -i ':.*perl[0-9]*\>' |
cut -d: -f1
) |
sort -u |
xargs perltidy --profile=src/tools/pgindent/perltidyrc

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +