Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6e22ba0

Browse files
committed
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.
1 parent 458857c commit 6e22ba0

File tree

3 files changed

+194
-62
lines changed

3 files changed

+194
-62
lines changed

src/tools/pgindent/README

+26-13
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,28 @@ pgindent
66
This can format all PostgreSQL *.c and *.h files, but excludes *.y, and
77
*.l files.
88

9-
1) Change directory to the top of the build tree.
9+
1) Install pg_bsd_indent (see below for details)
1010

11-
2) Download the typedef file from the buildfarm:
11+
2) Change directory to the top of the build tree.
12+
13+
3) Download the typedef file from the buildfarm:
1214

1315
wget -O src/tools/pgindent/typedefs.list http://buildfarm.postgresql.org/cgi-bin/typedefs.pl
1416

15-
3) Remove all derived files (pgindent has trouble with one of the flex macros):
17+
4) Remove all derived files (pgindent has trouble with one of the flex macros):
1618

1719
gmake maintainer-clean
1820

19-
4) Run pgindent:
21+
5) Run pgindent:
2022

2123
find . -name '*.[ch]' -type f -print | \
2224
egrep -v -f src/tools/pgindent/exclude_file_patterns | \
2325
xargs -n100 pgindent src/tools/pgindent/typedefs.list
2426

25-
5) Remove any files that generate errors and restore their original
27+
6) Remove any files that generate errors and restore their original
2628
versions.
2729

28-
6) Do a full test build:
30+
7) Do a full test build:
2931

3032
run configure
3133
# 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
3840

3941
---------------------------------------------------------------------------
4042

41-
We have standardized on NetBSD's indent. We have fixed a few bugs which
42-
requre the NetBSD source to be patched with indent.bsd.patch patch. A
43-
fully patched version is available at ftp://ftp.postgresql.org/pub/dev.
43+
BSD indent
44+
----------
45+
46+
We have standardized on NetBSD's indent, and renamed it pg_bsd_indent.
47+
We have fixed a few bugs which requre the NetBSD source to be patched
48+
with indent.bsd.patch patch. A fully patched version is available at
49+
ftp://ftp.postgresql.org/pub/dev.
4450

4551
GNU indent, version 2.2.6, has several problems, and is not recommended.
4652
These bugs become pretty major when you are doing >500k lines of code.
4753
If you don't believe me, take a directory and make a copy. Run pgindent
4854
on the copy using GNU indent, and do a diff -r. You will see what I
49-
mean. GNU indent does some things better, but mangles too.
55+
mean. GNU indent does some things better, but mangles too. For details,
56+
see:
57+
58+
http://archives.postgresql.org/pgsql-hackers/2003-10/msg00374.php
59+
http://archives.postgresql.org/pgsql-hackers/2011-04/msg01436.php
60+
61+
---------------------------------------------------------------------------
5062

51-
Notes about excluded files:
63+
Notes about excluded files
64+
--------------------------
5265

5366
src/include/storage/s_lock.h is excluded because it contains assembly code
5467
that pgindent tends to mess up.
@@ -63,8 +76,8 @@ should not be changed.
6376

6477
---------------------------------------------------------------------------
6578

66-
Obsolete typedef list creation instructions:
67-
--------------------------------------------
79+
Obsolete typedef list creation instructions
80+
-------------------------------------------
6881

6982
To use pgindent:
7083

src/tools/pgindent/indent.bsd.patch

+156-42
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
1-
src/tools/pgindent/indent.bsd.patch
2-
3-
This patch contains several fixes to NetBSD's indent and should be
4-
applied before using pgindent.
5-
6-
---------------------------------------------------------------------------
7-
8-
Index: README
9-
===================================================================
10-
RCS file: /cvsroot/src/usr.bin/indent/README,v
11-
retrieving revision 1.1
12-
diff -c -r1.1 README
13-
*** README 9 Apr 1993 12:59:06 -0000 1.1
14-
--- README 15 Nov 2005 00:25:43 -0000
1+
diff -c -r bsd_indent/Makefile pg_bsd_indent/Makefile
2+
*** bsd_indent/Makefile Mon Nov 14 19:30:11 2005
3+
--- pg_bsd_indent/Makefile Wed Oct 12 12:17:12 2011
4+
***************
5+
*** 2,10 ****
6+
# Makefile
7+
#
8+
#
9+
! TARGET = indent
10+
XFLAGS = -Wall -D__RCSID="static char *rcsid=" -D__COPYRIGHT="static char *copyright="
11+
! CFLAGS = -g
12+
LIBS =
13+
14+
$(TARGET) : args.o indent.o io.o lexi.o parse.o pr_comment.o
15+
--- 2,10 ----
16+
# Makefile
17+
#
18+
#
19+
! TARGET = pg_bsd_indent
20+
XFLAGS = -Wall -D__RCSID="static char *rcsid=" -D__COPYRIGHT="static char *copyright="
21+
! CFLAGS = -O
22+
LIBS =
23+
24+
$(TARGET) : args.o indent.o io.o lexi.o parse.o pr_comment.o
25+
***************
26+
*** 31,37 ****
27+
clean:
28+
rm -f *.o $(TARGET) log core
29+
30+
! install:
31+
! make clean
32+
! make CFLAGS=-O
33+
install -s -o bin -g bin $(TARGET) /usr/local/bin
34+
--- 31,35 ----
35+
clean:
36+
rm -f *.o $(TARGET) log core
37+
38+
! install: $(TARGET)
39+
install -s -o bin -g bin $(TARGET) /usr/local/bin
40+
diff -c -r bsd_indent/README pg_bsd_indent/README
41+
*** bsd_indent/README Wed Oct 12 11:51:58 2011
42+
--- pg_bsd_indent/README Mon Nov 14 19:30:24 2005
1543
***************
1644
*** 1,3 ****
1745
--- 1,13 ----
@@ -28,13 +56,107 @@ diff -c -r1.1 README
2856
This is the C indenter, it originally came from the University of Illinois
2957
via some distribution tape for PDP-11 Unix. It has subsequently been
3058
hacked upon by James Gosling @ CMU. It isn't very pretty, and really needs
31-
Index: indent_globs.h
32-
===================================================================
33-
RCS file: /cvsroot/src/usr.bin/indent/indent_globs.h,v
34-
retrieving revision 1.8
35-
diff -c -r1.8 indent_globs.h
36-
*** indent_globs.h 7 Aug 2003 11:14:08 -0000 1.8
37-
--- indent_globs.h 15 Nov 2005 00:25:44 -0000
59+
diff -c -r bsd_indent/args.c pg_bsd_indent/args.c
60+
*** bsd_indent/args.c Mon Nov 14 19:30:00 2005
61+
--- pg_bsd_indent/args.c Wed Oct 12 12:30:06 2011
62+
***************
63+
*** 83,88 ****
64+
--- 83,90 ----
65+
#include <string.h>
66+
#include "indent_globs.h"
67+
68+
+ #define INDENT_PG_VERSION "1.0"
69+
+
70+
/* profile types */
71+
#define PRO_SPECIAL 1 /* special case */
72+
#define PRO_BOOL 2 /* boolean */
73+
***************
74+
*** 99,106 ****
75+
--- 101,113 ----
76+
#define STDIN 3 /* use stdin */
77+
#define KEY 4 /* type (keyword) */
78+
79+
+ #define KEY_FILE 5 /* only used for args */
80+
+ #define VERSION 6 /* only used for args */
81+
+
82+
char *option_source = "?";
83+
84+
+ void add_typedefs_from_file(char *str);
85+
+
86+
/*
87+
* N.B.: because of the way the table here is scanned, options whose names are
88+
* substrings of other options must occur later; that is, with -lp vs -l, -lp
89+
***************
90+
*** 118,123 ****
91+
--- 125,136 ----
92+
"T", PRO_SPECIAL, 0, KEY, 0
93+
},
94+
{
95+
+ "U", PRO_SPECIAL, 0, KEY_FILE, 0
96+
+ },
97+
+ {
98+
+ "V", PRO_SPECIAL, 0, VERSION, 0
99+
+ },
100+
+ {
101+
"bacc", PRO_BOOL, false, ON, &blanklines_around_conditional_compilation
102+
},
103+
{
104+
***************
105+
*** 425,430 ****
106+
--- 438,456 ----
107+
}
108+
break;
109+
110+
+ case KEY_FILE:
111+
+ if (*param_start == 0)
112+
+ goto need_param;
113+
+ add_typedefs_from_file(param_start);
114+
+ break;
115+
+
116+
+ case VERSION:
117+
+ {
118+
+ printf("pg_bsd_indent %s\n", INDENT_PG_VERSION);
119+
+ exit(0);
120+
+ }
121+
+ break;
122+
+
123+
default:
124+
fprintf(stderr, "\
125+
indent: set_option: internal error: p_special %d\n", p->p_special);
126+
***************
127+
*** 459,461 ****
128+
--- 485,509 ----
129+
exit(1);
130+
}
131+
}
132+
+
133+
+
134+
+ void
135+
+ add_typedefs_from_file(char *str)
136+
+ {
137+
+ FILE *file;
138+
+ char line[BUFSIZ];
139+
+
140+
+ if ((file = fopen(param_start, "r")) == NULL)
141+
+ {
142+
+ fprintf(stderr, "indent: cannot open file %s\n", str);
143+
+ exit(1);
144+
+ }
145+
+ while ((fgets(line, BUFSIZ, file)) != NULL)
146+
+ {
147+
+ /* Remove trailing whitespace */
148+
+ if (strstr(line, " \t\n\r") != NULL)
149+
+ *strstr(line, " \t\n\r") = '\0';
150+
+ addkey(strdup(line), 4);
151+
+ }
152+
+ fclose(file);
153+
+ }
154+
Only in pg_bsd_indent/: args.o
155+
Only in bsd_indent/: indent.bsd.patch
156+
Only in pg_bsd_indent/: indent.o
157+
diff -c -r bsd_indent/indent_globs.h pg_bsd_indent/indent_globs.h
158+
*** bsd_indent/indent_globs.h Wed Oct 12 11:51:58 2011
159+
--- pg_bsd_indent/indent_globs.h Mon Nov 14 19:30:24 2005
38160
***************
39161
*** 239,245 ****
40162
scomf, /* Same line comment font */
@@ -56,13 +178,10 @@ diff -c -r1.8 indent_globs.h
56178

57179
EXTERN struct parser_state {
58180
int last_token;
59-
Index: lexi.c
60-
===================================================================
61-
RCS file: /cvsroot/src/usr.bin/indent/lexi.c,v
62-
retrieving revision 1.12
63-
diff -c -r1.12 lexi.c
64-
*** lexi.c 7 Aug 2003 11:14:09 -0000 1.12
65-
--- lexi.c 15 Nov 2005 00:25:44 -0000
181+
Only in pg_bsd_indent/: io.o
182+
diff -c -r bsd_indent/lexi.c pg_bsd_indent/lexi.c
183+
*** bsd_indent/lexi.c Wed Oct 12 11:51:58 2011
184+
--- pg_bsd_indent/lexi.c Mon Nov 14 19:30:24 2005
66185
***************
67186
*** 93,99 ****
68187
int rwcode;
@@ -102,13 +221,10 @@ diff -c -r1.12 lexi.c
102221
p->rwd = key;
103222
p->rwcode = val;
104223
p[1].rwd = 0;
105-
Index: parse.c
106-
===================================================================
107-
RCS file: /cvsroot/src/usr.bin/indent/parse.c,v
108-
retrieving revision 1.7
109-
diff -c -r1.7 parse.c
110-
*** parse.c 7 Aug 2003 11:14:09 -0000 1.7
111-
--- parse.c 15 Nov 2005 00:25:44 -0000
224+
Only in pg_bsd_indent/: lexi.o
225+
diff -c -r bsd_indent/parse.c pg_bsd_indent/parse.c
226+
*** bsd_indent/parse.c Wed Oct 12 11:51:58 2011
227+
--- pg_bsd_indent/parse.c Mon Nov 14 19:30:24 2005
112228
***************
113229
*** 231,236 ****
114230
--- 231,241 ----
@@ -123,13 +239,10 @@ diff -c -r1.7 parse.c
123239
reduce(); /* see if any reduction can be done */
124240

125241
#ifdef debug
126-
Index: pr_comment.c
127-
===================================================================
128-
RCS file: /cvsroot/src/usr.bin/indent/pr_comment.c,v
129-
retrieving revision 1.9
130-
diff -c -r1.9 pr_comment.c
131-
*** pr_comment.c 7 Aug 2003 11:14:09 -0000 1.9
132-
--- pr_comment.c 15 Nov 2005 00:25:44 -0000
242+
Only in pg_bsd_indent/: parse.o
243+
diff -c -r bsd_indent/pr_comment.c pg_bsd_indent/pr_comment.c
244+
*** bsd_indent/pr_comment.c Wed Oct 12 11:51:58 2011
245+
--- pg_bsd_indent/pr_comment.c Mon Nov 14 19:30:24 2005
133246
***************
134247
*** 148,154 ****
135248
ps.box_com = true;
@@ -173,3 +286,4 @@ diff -c -r1.9 pr_comment.c
173286
} else
174287
if (++buf_ptr >= buf_end)
175288
fill_buffer();
289+
Only in pg_bsd_indent/: pr_comment.o

src/tools/pgindent/pgindent

+12-7
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ fi
2121
TYPEDEFS="$1"
2222
shift
2323

24-
if [ -z "$INDENT" ]
25-
then
26-
INDENT=indent
27-
fi
24+
[ -z "$INDENT" ] && INDENT=pg_bsd_indent
2825

2926
trap "rm -f /tmp/$$ /tmp/$$a" 0 1 2 3 15
27+
28+
# check the environment
29+
3030
entab </dev/null >/dev/null
3131
if [ "$?" -ne 0 ]
3232
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
3636
fi
3737
$INDENT -? </dev/null >/dev/null 2>&1
3838
if [ "$?" -ne 1 ]
39-
then echo "You do not appear to have 'indent' installed on your system." >&2
39+
then echo "You do not appear to have '$INDENT' installed on your system." >&2
40+
exit 1
41+
fi
42+
if [ "`$INDENT -V`" != "$INDENT 1.0" ]
43+
then echo "You do not appear to have $INDENT version 1.0 installed on your system." >&2
4044
exit 1
4145
fi
4246
$INDENT -gnu </dev/null >/dev/null 2>&1
@@ -140,10 +144,11 @@ do
140144
# Protect wrapping in CATALOG().
141145
sed 's;^CATALOG(.*$;/*&*/;' >/tmp/$$a
142146

147+
egrep -v '^(FD_SET|date|interval|timestamp|ANY)$' "$TYPEDEFS" | sed -e '/^$/d' > /tmp/$$b
148+
143149
# We get the list of typedef's from /src/tools/find_typedef
144150
$INDENT -bad -bap -bc -bl -d0 -cdb -nce -nfc1 -di12 -i4 -l79 \
145-
-lp -nip -npro -bbb $EXTRA_OPTS \
146-
`egrep -v '^(FD_SET|date|interval|timestamp|ANY)$' "$TYPEDEFS" | sed -e '/^$/d' -e 's/.*/-T& /'` \
151+
-lp -nip -npro -bbb $EXTRA_OPTS -U/tmp/$$b \
147152
/tmp/$$a >/tmp/$$ 2>&1
148153

149154
if [ "$?" -ne 0 -o -s /tmp/$$ ]

0 commit comments

Comments
 (0)