diff options
author | Tom Lane | 2017-06-20 19:09:25 +0000 |
---|---|---|
committer | Tom Lane | 2017-06-20 19:09:25 +0000 |
commit | 456f854a313e967c3aeb9a6395e2552c132a5162 (patch) | |
tree | ef5d9c16bb216f31aef5145f5b884a1903ea3860 | |
parent | c8cfba85a9e3c2920d987ce6103ccc22b2554e71 (diff) |
Add build infrastructure to build in Postgres environment.
Add a Makefile that works with the PGXS infrastructure.
Add err.h and err.c, taken from FreeBSD 11 and cut down to just
the minimum support needed by indent.
Add README.pg_bsd_indent with simple build instructions,
and .gitignore.
-rw-r--r-- | .gitignore | 10 | ||||
-rw-r--r-- | Makefile | 31 | ||||
-rw-r--r-- | README.pg_bsd_indent | 21 | ||||
-rw-r--r-- | err.c | 67 | ||||
-rw-r--r-- | err.h | 45 |
5 files changed, 174 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c5d8dc --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Global excludes across all subdirectories +*.o +*.obj +*.exe + +# Local excludes in root directory +/pg_bsd_indent +/*.out +/*.list +/tests.diff diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e8768c8 --- /dev/null +++ b/Makefile @@ -0,0 +1,31 @@ +#------------------------------------------------------------------------- +# +# Makefile for pg_bsd_indent +# +# Copyright (c) 2017, PostgreSQL Global Development Group +# +#------------------------------------------------------------------------- + +PGFILEDESC = "pg_bsd_indent - indent C code nicely" +PGAPPICON = win32 + +PROGRAM = pg_bsd_indent +OBJS = args.o err.o indent.o io.o lexi.o parse.o pr_comment.o $(WIN32RES) + +# clean junk left behind by "make check" +EXTRA_CLEAN = *.out *.list tests.diff + +PG_CONFIG = pg_config +PGXS := $(shell $(PG_CONFIG) --pgxs) +include $(PGXS) + +check: $(PROGRAM) + rm -f tests.diff + cp $(srcdir)/tests/*.list . + for testsrc in $(srcdir)/tests/*.0; do \ + test=`basename "$$testsrc" .0`; \ + ./$(PROGRAM) $$testsrc $$test.out -P$(srcdir)/tests/$$test.pro || echo FAILED >>$$test.out; \ + diff -u $$testsrc.stdout $$test.out >>tests.diff 2>&1 || true; \ + done + @cat tests.diff + @test '!' -s tests.diff diff --git a/README.pg_bsd_indent b/README.pg_bsd_indent new file mode 100644 index 0000000..747130d --- /dev/null +++ b/README.pg_bsd_indent @@ -0,0 +1,21 @@ +pg_bsd_indent + +This is a lightly modified version of the "indent" program maintained +by the FreeBSD project. The modifications are mostly to make it portable +to non-BSD-ish platforms, though we do have one formatting switch we +couldn't convince upstream to take. + +To build it, you will need a Postgres installation, version 9.5 or newer. +(Once built, the program doesn't depend on that installation.) + +To build, just say "make"; or if pg_config from your Postgres installation +isn't in your PATH, say + make PG_CONFIG=path/to/pg_config +Optionally, run "make check" for some simple sanity checks. + +To install, copy pg_bsd_indent to somewhere in your usual PATH. +(If you say "make install", it will try to put it in your Postgres +installation directory, which is most likely not what you want for +long-term use.) + +TODO: add build support and instructions for Windows @@ -0,0 +1,67 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * This is cut down to just the minimum that we need to build indent. + */ +#include "c.h" + +#include <err.h> +#include <errno.h> +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +void +err(int eval, const char *fmt, ...) +{ + int code = errno; + va_list ap; + va_start(ap, fmt); + if (fmt != NULL) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, ": "); + } + fprintf(stderr, "%s\n", strerror(code)); + va_end(ap); + exit(eval); +} + +void +errx(int eval, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + if (fmt != NULL) + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + va_end(ap); + exit(eval); +} @@ -0,0 +1,45 @@ +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)err.h 8.1 (Berkeley) 6/2/93 + * $FreeBSD: stable/11/include/err.h 203964 2010-02-16 19:39:50Z imp $ + */ + +#ifndef _ERR_H_ +#define _ERR_H_ + +/* + * This is cut down to just the minimum that we need to build indent. + */ + +void err(int, const char *, ...) + pg_attribute_noreturn() pg_attribute_printf(2, 3); +void errx(int, const char *, ...) + pg_attribute_noreturn() pg_attribute_printf(2, 3); + +#endif /* !_ERR_H_ */ |