mirror of
https://github.com/postgres/postgres.git
synced 2025-05-06 19:59:18 +03:00
Modify pgindent to use a renamed pg_bsd_indent binary. New features
include the ability to supply a typedef file, rather than list them on the command line. Also improve the README.
This commit is contained in:
parent
458857cc9d
commit
6e22ba03a9
@ -6,26 +6,28 @@ pgindent
|
|||||||
This can format all PostgreSQL *.c and *.h files, but excludes *.y, and
|
This can format all PostgreSQL *.c and *.h files, but excludes *.y, and
|
||||||
*.l files.
|
*.l files.
|
||||||
|
|
||||||
1) Change directory to the top of the build tree.
|
1) Install pg_bsd_indent (see below for details)
|
||||||
|
|
||||||
2) Download the typedef file from the buildfarm:
|
2) Change directory to the top of the build tree.
|
||||||
|
|
||||||
|
3) Download the typedef file from the buildfarm:
|
||||||
|
|
||||||
wget -O src/tools/pgindent/typedefs.list http://buildfarm.postgresql.org/cgi-bin/typedefs.pl
|
wget -O src/tools/pgindent/typedefs.list http://buildfarm.postgresql.org/cgi-bin/typedefs.pl
|
||||||
|
|
||||||
3) Remove all derived files (pgindent has trouble with one of the flex macros):
|
4) Remove all derived files (pgindent has trouble with one of the flex macros):
|
||||||
|
|
||||||
gmake maintainer-clean
|
gmake maintainer-clean
|
||||||
|
|
||||||
4) Run pgindent:
|
5) Run pgindent:
|
||||||
|
|
||||||
find . -name '*.[ch]' -type f -print | \
|
find . -name '*.[ch]' -type f -print | \
|
||||||
egrep -v -f src/tools/pgindent/exclude_file_patterns | \
|
egrep -v -f src/tools/pgindent/exclude_file_patterns | \
|
||||||
xargs -n100 pgindent src/tools/pgindent/typedefs.list
|
xargs -n100 pgindent src/tools/pgindent/typedefs.list
|
||||||
|
|
||||||
5) Remove any files that generate errors and restore their original
|
6) Remove any files that generate errors and restore their original
|
||||||
versions.
|
versions.
|
||||||
|
|
||||||
6) Do a full test build:
|
7) Do a full test build:
|
||||||
|
|
||||||
run configure
|
run configure
|
||||||
# stop is only necessary if it's going to install in a location with an
|
# stop is only necessary if it's going to install in a location with an
|
||||||
@ -38,17 +40,28 @@ This can format all PostgreSQL *.c and *.h files, but excludes *.y, and
|
|||||||
|
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
We have standardized on NetBSD's indent. We have fixed a few bugs which
|
BSD indent
|
||||||
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.
|
|
||||||
|
We have standardized on NetBSD's indent, and renamed it pg_bsd_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.
|
GNU indent, version 2.2.6, has several problems, and is not recommended.
|
||||||
These bugs become pretty major when you are doing >500k 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
|
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
|
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.
|
mean. GNU indent does some things better, but mangles too. For details,
|
||||||
|
see:
|
||||||
|
|
||||||
Notes about excluded files:
|
http://archives.postgresql.org/pgsql-hackers/2003-10/msg00374.php
|
||||||
|
http://archives.postgresql.org/pgsql-hackers/2011-04/msg01436.php
|
||||||
|
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Notes about excluded files
|
||||||
|
--------------------------
|
||||||
|
|
||||||
src/include/storage/s_lock.h is excluded because it contains assembly code
|
src/include/storage/s_lock.h is excluded because it contains assembly code
|
||||||
that pgindent tends to mess up.
|
that pgindent tends to mess up.
|
||||||
@ -63,8 +76,8 @@ should not be changed.
|
|||||||
|
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
Obsolete typedef list creation instructions:
|
Obsolete typedef list creation instructions
|
||||||
--------------------------------------------
|
-------------------------------------------
|
||||||
|
|
||||||
To use pgindent:
|
To use pgindent:
|
||||||
|
|
||||||
|
@ -1,17 +1,45 @@
|
|||||||
src/tools/pgindent/indent.bsd.patch
|
diff -c -r bsd_indent/Makefile pg_bsd_indent/Makefile
|
||||||
|
*** bsd_indent/Makefile Mon Nov 14 19:30:11 2005
|
||||||
This patch contains several fixes to NetBSD's indent and should be
|
--- pg_bsd_indent/Makefile Wed Oct 12 12:17:12 2011
|
||||||
applied before using pgindent.
|
***************
|
||||||
|
*** 2,10 ****
|
||||||
---------------------------------------------------------------------------
|
# Makefile
|
||||||
|
#
|
||||||
Index: README
|
#
|
||||||
===================================================================
|
! TARGET = indent
|
||||||
RCS file: /cvsroot/src/usr.bin/indent/README,v
|
XFLAGS = -Wall -D__RCSID="static char *rcsid=" -D__COPYRIGHT="static char *copyright="
|
||||||
retrieving revision 1.1
|
! CFLAGS = -g
|
||||||
diff -c -r1.1 README
|
LIBS =
|
||||||
*** README 9 Apr 1993 12:59:06 -0000 1.1
|
|
||||||
--- README 15 Nov 2005 00:25:43 -0000
|
$(TARGET) : args.o indent.o io.o lexi.o parse.o pr_comment.o
|
||||||
|
--- 2,10 ----
|
||||||
|
# Makefile
|
||||||
|
#
|
||||||
|
#
|
||||||
|
! TARGET = pg_bsd_indent
|
||||||
|
XFLAGS = -Wall -D__RCSID="static char *rcsid=" -D__COPYRIGHT="static char *copyright="
|
||||||
|
! CFLAGS = -O
|
||||||
|
LIBS =
|
||||||
|
|
||||||
|
$(TARGET) : args.o indent.o io.o lexi.o parse.o pr_comment.o
|
||||||
|
***************
|
||||||
|
*** 31,37 ****
|
||||||
|
clean:
|
||||||
|
rm -f *.o $(TARGET) log core
|
||||||
|
|
||||||
|
! install:
|
||||||
|
! make clean
|
||||||
|
! make CFLAGS=-O
|
||||||
|
install -s -o bin -g bin $(TARGET) /usr/local/bin
|
||||||
|
--- 31,35 ----
|
||||||
|
clean:
|
||||||
|
rm -f *.o $(TARGET) log core
|
||||||
|
|
||||||
|
! install: $(TARGET)
|
||||||
|
install -s -o bin -g bin $(TARGET) /usr/local/bin
|
||||||
|
diff -c -r bsd_indent/README pg_bsd_indent/README
|
||||||
|
*** bsd_indent/README Wed Oct 12 11:51:58 2011
|
||||||
|
--- pg_bsd_indent/README Mon Nov 14 19:30:24 2005
|
||||||
***************
|
***************
|
||||||
*** 1,3 ****
|
*** 1,3 ****
|
||||||
--- 1,13 ----
|
--- 1,13 ----
|
||||||
@ -28,13 +56,107 @@ diff -c -r1.1 README
|
|||||||
This is the C indenter, it originally came from the University of Illinois
|
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
|
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
|
hacked upon by James Gosling @ CMU. It isn't very pretty, and really needs
|
||||||
Index: indent_globs.h
|
diff -c -r bsd_indent/args.c pg_bsd_indent/args.c
|
||||||
===================================================================
|
*** bsd_indent/args.c Mon Nov 14 19:30:00 2005
|
||||||
RCS file: /cvsroot/src/usr.bin/indent/indent_globs.h,v
|
--- pg_bsd_indent/args.c Wed Oct 12 12:30:06 2011
|
||||||
retrieving revision 1.8
|
***************
|
||||||
diff -c -r1.8 indent_globs.h
|
*** 83,88 ****
|
||||||
*** indent_globs.h 7 Aug 2003 11:14:08 -0000 1.8
|
--- 83,90 ----
|
||||||
--- indent_globs.h 15 Nov 2005 00:25:44 -0000
|
#include <string.h>
|
||||||
|
#include "indent_globs.h"
|
||||||
|
|
||||||
|
+ #define INDENT_PG_VERSION "1.0"
|
||||||
|
+
|
||||||
|
/* profile types */
|
||||||
|
#define PRO_SPECIAL 1 /* special case */
|
||||||
|
#define PRO_BOOL 2 /* boolean */
|
||||||
|
***************
|
||||||
|
*** 99,106 ****
|
||||||
|
--- 101,113 ----
|
||||||
|
#define STDIN 3 /* use stdin */
|
||||||
|
#define KEY 4 /* type (keyword) */
|
||||||
|
|
||||||
|
+ #define KEY_FILE 5 /* only used for args */
|
||||||
|
+ #define VERSION 6 /* only used for args */
|
||||||
|
+
|
||||||
|
char *option_source = "?";
|
||||||
|
|
||||||
|
+ void add_typedefs_from_file(char *str);
|
||||||
|
+
|
||||||
|
/*
|
||||||
|
* N.B.: because of the way the table here is scanned, options whose names are
|
||||||
|
* substrings of other options must occur later; that is, with -lp vs -l, -lp
|
||||||
|
***************
|
||||||
|
*** 118,123 ****
|
||||||
|
--- 125,136 ----
|
||||||
|
"T", PRO_SPECIAL, 0, KEY, 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
+ "U", PRO_SPECIAL, 0, KEY_FILE, 0
|
||||||
|
+ },
|
||||||
|
+ {
|
||||||
|
+ "V", PRO_SPECIAL, 0, VERSION, 0
|
||||||
|
+ },
|
||||||
|
+ {
|
||||||
|
"bacc", PRO_BOOL, false, ON, &blanklines_around_conditional_compilation
|
||||||
|
},
|
||||||
|
{
|
||||||
|
***************
|
||||||
|
*** 425,430 ****
|
||||||
|
--- 438,456 ----
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
+ case KEY_FILE:
|
||||||
|
+ if (*param_start == 0)
|
||||||
|
+ goto need_param;
|
||||||
|
+ add_typedefs_from_file(param_start);
|
||||||
|
+ break;
|
||||||
|
+
|
||||||
|
+ case VERSION:
|
||||||
|
+ {
|
||||||
|
+ printf("pg_bsd_indent %s\n", INDENT_PG_VERSION);
|
||||||
|
+ exit(0);
|
||||||
|
+ }
|
||||||
|
+ break;
|
||||||
|
+
|
||||||
|
default:
|
||||||
|
fprintf(stderr, "\
|
||||||
|
indent: set_option: internal error: p_special %d\n", p->p_special);
|
||||||
|
***************
|
||||||
|
*** 459,461 ****
|
||||||
|
--- 485,509 ----
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+ void
|
||||||
|
+ add_typedefs_from_file(char *str)
|
||||||
|
+ {
|
||||||
|
+ FILE *file;
|
||||||
|
+ char line[BUFSIZ];
|
||||||
|
+
|
||||||
|
+ if ((file = fopen(param_start, "r")) == NULL)
|
||||||
|
+ {
|
||||||
|
+ fprintf(stderr, "indent: cannot open file %s\n", str);
|
||||||
|
+ exit(1);
|
||||||
|
+ }
|
||||||
|
+ while ((fgets(line, BUFSIZ, file)) != NULL)
|
||||||
|
+ {
|
||||||
|
+ /* Remove trailing whitespace */
|
||||||
|
+ if (strstr(line, " \t\n\r") != NULL)
|
||||||
|
+ *strstr(line, " \t\n\r") = '\0';
|
||||||
|
+ addkey(strdup(line), 4);
|
||||||
|
+ }
|
||||||
|
+ fclose(file);
|
||||||
|
+ }
|
||||||
|
Only in pg_bsd_indent/: args.o
|
||||||
|
Only in bsd_indent/: indent.bsd.patch
|
||||||
|
Only in pg_bsd_indent/: indent.o
|
||||||
|
diff -c -r bsd_indent/indent_globs.h pg_bsd_indent/indent_globs.h
|
||||||
|
*** bsd_indent/indent_globs.h Wed Oct 12 11:51:58 2011
|
||||||
|
--- pg_bsd_indent/indent_globs.h Mon Nov 14 19:30:24 2005
|
||||||
***************
|
***************
|
||||||
*** 239,245 ****
|
*** 239,245 ****
|
||||||
scomf, /* Same line comment font */
|
scomf, /* Same line comment font */
|
||||||
@ -56,13 +178,10 @@ diff -c -r1.8 indent_globs.h
|
|||||||
|
|
||||||
EXTERN struct parser_state {
|
EXTERN struct parser_state {
|
||||||
int last_token;
|
int last_token;
|
||||||
Index: lexi.c
|
Only in pg_bsd_indent/: io.o
|
||||||
===================================================================
|
diff -c -r bsd_indent/lexi.c pg_bsd_indent/lexi.c
|
||||||
RCS file: /cvsroot/src/usr.bin/indent/lexi.c,v
|
*** bsd_indent/lexi.c Wed Oct 12 11:51:58 2011
|
||||||
retrieving revision 1.12
|
--- pg_bsd_indent/lexi.c Mon Nov 14 19:30:24 2005
|
||||||
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 ****
|
*** 93,99 ****
|
||||||
int rwcode;
|
int rwcode;
|
||||||
@ -102,13 +221,10 @@ diff -c -r1.12 lexi.c
|
|||||||
p->rwd = key;
|
p->rwd = key;
|
||||||
p->rwcode = val;
|
p->rwcode = val;
|
||||||
p[1].rwd = 0;
|
p[1].rwd = 0;
|
||||||
Index: parse.c
|
Only in pg_bsd_indent/: lexi.o
|
||||||
===================================================================
|
diff -c -r bsd_indent/parse.c pg_bsd_indent/parse.c
|
||||||
RCS file: /cvsroot/src/usr.bin/indent/parse.c,v
|
*** bsd_indent/parse.c Wed Oct 12 11:51:58 2011
|
||||||
retrieving revision 1.7
|
--- pg_bsd_indent/parse.c Mon Nov 14 19:30:24 2005
|
||||||
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,236 ****
|
||||||
--- 231,241 ----
|
--- 231,241 ----
|
||||||
@ -123,13 +239,10 @@ diff -c -r1.7 parse.c
|
|||||||
reduce(); /* see if any reduction can be done */
|
reduce(); /* see if any reduction can be done */
|
||||||
|
|
||||||
#ifdef debug
|
#ifdef debug
|
||||||
Index: pr_comment.c
|
Only in pg_bsd_indent/: parse.o
|
||||||
===================================================================
|
diff -c -r bsd_indent/pr_comment.c pg_bsd_indent/pr_comment.c
|
||||||
RCS file: /cvsroot/src/usr.bin/indent/pr_comment.c,v
|
*** bsd_indent/pr_comment.c Wed Oct 12 11:51:58 2011
|
||||||
retrieving revision 1.9
|
--- pg_bsd_indent/pr_comment.c Mon Nov 14 19:30:24 2005
|
||||||
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 ****
|
*** 148,154 ****
|
||||||
ps.box_com = true;
|
ps.box_com = true;
|
||||||
@ -173,3 +286,4 @@ diff -c -r1.9 pr_comment.c
|
|||||||
} else
|
} else
|
||||||
if (++buf_ptr >= buf_end)
|
if (++buf_ptr >= buf_end)
|
||||||
fill_buffer();
|
fill_buffer();
|
||||||
|
Only in pg_bsd_indent/: pr_comment.o
|
||||||
|
@ -21,12 +21,12 @@ fi
|
|||||||
TYPEDEFS="$1"
|
TYPEDEFS="$1"
|
||||||
shift
|
shift
|
||||||
|
|
||||||
if [ -z "$INDENT" ]
|
[ -z "$INDENT" ] && INDENT=pg_bsd_indent
|
||||||
then
|
|
||||||
INDENT=indent
|
|
||||||
fi
|
|
||||||
|
|
||||||
trap "rm -f /tmp/$$ /tmp/$$a" 0 1 2 3 15
|
trap "rm -f /tmp/$$ /tmp/$$a" 0 1 2 3 15
|
||||||
|
|
||||||
|
# check the environment
|
||||||
|
|
||||||
entab </dev/null >/dev/null
|
entab </dev/null >/dev/null
|
||||||
if [ "$?" -ne 0 ]
|
if [ "$?" -ne 0 ]
|
||||||
then echo "Go to the src/tools/entab directory and do a 'make' and 'make install'." >&2
|
then echo "Go to the src/tools/entab directory and do a 'make' and 'make install'." >&2
|
||||||
@ -36,7 +36,11 @@ then echo "Go to the src/tools/entab directory and do a 'make' and 'make install
|
|||||||
fi
|
fi
|
||||||
$INDENT -? </dev/null >/dev/null 2>&1
|
$INDENT -? </dev/null >/dev/null 2>&1
|
||||||
if [ "$?" -ne 1 ]
|
if [ "$?" -ne 1 ]
|
||||||
then echo "You do not appear to have 'indent' installed on your system." >&2
|
then echo "You do not appear to have '$INDENT' installed on your system." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ "`$INDENT -V`" != "$INDENT 1.0" ]
|
||||||
|
then echo "You do not appear to have $INDENT version 1.0 installed on your system." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
$INDENT -gnu </dev/null >/dev/null 2>&1
|
$INDENT -gnu </dev/null >/dev/null 2>&1
|
||||||
@ -140,10 +144,11 @@ do
|
|||||||
# Protect wrapping in CATALOG().
|
# Protect wrapping in CATALOG().
|
||||||
sed 's;^CATALOG(.*$;/*&*/;' >/tmp/$$a
|
sed 's;^CATALOG(.*$;/*&*/;' >/tmp/$$a
|
||||||
|
|
||||||
|
egrep -v '^(FD_SET|date|interval|timestamp|ANY)$' "$TYPEDEFS" | sed -e '/^$/d' > /tmp/$$b
|
||||||
|
|
||||||
# We get the list of typedef's from /src/tools/find_typedef
|
# We get the list of typedef's from /src/tools/find_typedef
|
||||||
$INDENT -bad -bap -bc -bl -d0 -cdb -nce -nfc1 -di12 -i4 -l79 \
|
$INDENT -bad -bap -bc -bl -d0 -cdb -nce -nfc1 -di12 -i4 -l79 \
|
||||||
-lp -nip -npro -bbb $EXTRA_OPTS \
|
-lp -nip -npro -bbb $EXTRA_OPTS -U/tmp/$$b \
|
||||||
`egrep -v '^(FD_SET|date|interval|timestamp|ANY)$' "$TYPEDEFS" | sed -e '/^$/d' -e 's/.*/-T& /'` \
|
|
||||||
/tmp/$$a >/tmp/$$ 2>&1
|
/tmp/$$a >/tmp/$$ 2>&1
|
||||||
|
|
||||||
if [ "$?" -ne 0 -o -s /tmp/$$ ]
|
if [ "$?" -ne 0 -o -s /tmp/$$ ]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user