pgindent run. Make it all clean.
authorBruce Momjian <[email protected]>
Thu, 22 Mar 2001 04:01:46 +0000 (04:01 +0000)
committerBruce Momjian <[email protected]>
Thu, 22 Mar 2001 04:01:46 +0000 (04:01 +0000)
555 files changed:
contrib/cube/buffer.c
contrib/cube/buffer.h
contrib/cube/cube.c
contrib/cube/cubedata.h
contrib/earthdistance/earthdistance.c
contrib/findoidjoins/findoidjoins.c
contrib/fulltextindex/fti.c
contrib/lo/lo.c
contrib/oid2name/oid2name.c
contrib/pg_controldata/pg_controldata.c
contrib/pg_dumplo/lo_export.c
contrib/pg_dumplo/lo_import.c
contrib/pg_dumplo/main.c
contrib/pg_dumplo/pg_dumplo.h
contrib/pg_dumplo/utils.c
contrib/pg_logger/pg_logger.c
contrib/pg_resetxlog/pg_resetxlog.c
contrib/pgcrypto/encode.c
contrib/pgcrypto/encode.h
contrib/pgcrypto/internal.c
contrib/pgcrypto/krb.c
contrib/pgcrypto/md5.c
contrib/pgcrypto/md5.h
contrib/pgcrypto/mhash.c
contrib/pgcrypto/openssl.c
contrib/pgcrypto/pgcrypto.c
contrib/pgcrypto/pgcrypto.h
contrib/pgcrypto/sha1.c
contrib/pgcrypto/sha1.h
contrib/rserv/rserv.c
contrib/seg/buffer.c
contrib/seg/buffer.h
contrib/seg/seg.c
contrib/seg/segdata.h
contrib/soundex/soundex.c
contrib/spi/insert_username.c
contrib/spi/moddatetime.c
contrib/spi/timetravel.c
contrib/vacuumlo/vacuumlo.c
src/backend/access/common/heaptuple.c
src/backend/access/common/indextuple.c
src/backend/access/common/printtup.c
src/backend/access/common/tupdesc.c
src/backend/access/gist/gist.c
src/backend/access/gist/gistget.c
src/backend/access/gist/gistscan.c
src/backend/access/hash/hash.c
src/backend/access/hash/hashfunc.c
src/backend/access/heap/heapam.c
src/backend/access/heap/hio.c
src/backend/access/heap/tuptoaster.c
src/backend/access/index/istrat.c
src/backend/access/nbtree/nbtcompare.c
src/backend/access/nbtree/nbtinsert.c
src/backend/access/nbtree/nbtpage.c
src/backend/access/nbtree/nbtree.c
src/backend/access/nbtree/nbtsearch.c
src/backend/access/nbtree/nbtsort.c
src/backend/access/nbtree/nbtutils.c
src/backend/access/rtree/rtget.c
src/backend/access/rtree/rtproc.c
src/backend/access/rtree/rtree.c
src/backend/access/rtree/rtscan.c
src/backend/access/transam/rmgr.c
src/backend/access/transam/transam.c
src/backend/access/transam/transsup.c
src/backend/access/transam/varsup.c
src/backend/access/transam/xact.c
src/backend/access/transam/xid.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xlogutils.c
src/backend/catalog/aclchk.c
src/backend/catalog/catalog.c
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/catalog/indexing.c
src/backend/catalog/pg_aggregate.c
src/backend/catalog/pg_largeobject.c
src/backend/catalog/pg_operator.c
src/backend/catalog/pg_proc.c
src/backend/catalog/pg_type.c
src/backend/commands/analyze.c
src/backend/commands/async.c
src/backend/commands/cluster.c
src/backend/commands/command.c
src/backend/commands/comment.c
src/backend/commands/copy.c
src/backend/commands/creatinh.c
src/backend/commands/dbcommands.c
src/backend/commands/define.c
src/backend/commands/explain.c
src/backend/commands/indexcmds.c
src/backend/commands/proclang.c
src/backend/commands/remove.c
src/backend/commands/rename.c
src/backend/commands/sequence.c
src/backend/commands/trigger.c
src/backend/commands/user.c
src/backend/commands/vacuum.c
src/backend/commands/variable.c
src/backend/commands/view.c
src/backend/executor/execAmi.c
src/backend/executor/execJunk.c
src/backend/executor/execMain.c
src/backend/executor/execQual.c
src/backend/executor/execScan.c
src/backend/executor/execTuples.c
src/backend/executor/execUtils.c
src/backend/executor/functions.c
src/backend/executor/nodeAgg.c
src/backend/executor/nodeGroup.c
src/backend/executor/nodeHash.c
src/backend/executor/nodeHashjoin.c
src/backend/executor/nodeIndexscan.c
src/backend/executor/nodeLimit.c
src/backend/executor/nodeMaterial.c
src/backend/executor/nodeMergejoin.c
src/backend/executor/nodeNestloop.c
src/backend/executor/nodeResult.c
src/backend/executor/nodeSeqscan.c
src/backend/executor/nodeSetOp.c
src/backend/executor/nodeSubplan.c
src/backend/executor/nodeSubqueryscan.c
src/backend/executor/nodeTidscan.c
src/backend/executor/spi.c
src/backend/lib/bit.c
src/backend/libpq/auth.c
src/backend/libpq/be-fsstubs.c
src/backend/libpq/crypt.c
src/backend/libpq/password.c
src/backend/libpq/pqcomm.c
src/backend/libpq/pqpacket.c
src/backend/libpq/pqsignal.c
src/backend/main/main.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/list.c
src/backend/nodes/makefuncs.c
src/backend/nodes/nodeFuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/print.c
src/backend/nodes/read.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/geqo/geqo_eval.c
src/backend/optimizer/geqo/geqo_main.c
src/backend/optimizer/path/_deadcode/predmig.c
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/path/clausesel.c
src/backend/optimizer/path/costsize.c
src/backend/optimizer/path/indxpath.c
src/backend/optimizer/path/joinpath.c
src/backend/optimizer/path/joinrels.c
src/backend/optimizer/path/pathkeys.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/initsplan.c
src/backend/optimizer/plan/planmain.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/setrefs.c
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/prep/prepkeyset.c
src/backend/optimizer/prep/prepqual.c
src/backend/optimizer/prep/preptlist.c
src/backend/optimizer/prep/prepunion.c
src/backend/optimizer/util/clauses.c
src/backend/optimizer/util/joininfo.c
src/backend/optimizer/util/pathnode.c
src/backend/optimizer/util/plancat.c
src/backend/optimizer/util/tlist.c
src/backend/optimizer/util/var.c
src/backend/parser/analyze.c
src/backend/parser/keywords.c
src/backend/parser/parse_clause.c
src/backend/parser/parse_coerce.c
src/backend/parser/parse_expr.c
src/backend/parser/parse_func.c
src/backend/parser/parse_node.c
src/backend/parser/parse_oper.c
src/backend/parser/parse_relation.c
src/backend/parser/parse_target.c
src/backend/parser/parse_type.c
src/backend/parser/parser.c
src/backend/port/beos/sem.c
src/backend/port/beos/shm.c
src/backend/port/beos/support.c
src/backend/port/darwin/sem.c
src/backend/port/dynloader/aix.c
src/backend/port/dynloader/aix.h
src/backend/port/dynloader/beos.c
src/backend/port/dynloader/darwin.c
src/backend/port/dynloader/darwin.h
src/backend/port/dynloader/hpux.c
src/backend/port/dynloader/solaris.h
src/backend/port/qnx4/shm.c
src/backend/port/strtol.c
src/backend/postmaster/postmaster.c
src/backend/regex/engine.c
src/backend/regex/regcomp.c
src/backend/regex/regexec.c
src/backend/rewrite/rewriteDefine.c
src/backend/rewrite/rewriteHandler.c
src/backend/rewrite/rewriteManip.c
src/backend/rewrite/rewriteRemove.c
src/backend/rewrite/rewriteSupport.c
src/backend/storage/buffer/buf_init.c
src/backend/storage/buffer/buf_table.c
src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/localbuf.c
src/backend/storage/buffer/s_lock.c
src/backend/storage/file/buffile.c
src/backend/storage/file/fd.c
src/backend/storage/ipc/ipc.c
src/backend/storage/ipc/ipci.c
src/backend/storage/ipc/shmem.c
src/backend/storage/ipc/shmqueue.c
src/backend/storage/ipc/sinval.c
src/backend/storage/ipc/sinvaladt.c
src/backend/storage/ipc/spin.c
src/backend/storage/large_object/inv_api.c
src/backend/storage/lmgr/deadlock.c
src/backend/storage/lmgr/lmgr.c
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/proc.c
src/backend/storage/page/bufpage.c
src/backend/storage/smgr/md.c
src/backend/storage/smgr/smgr.c
src/backend/tcop/dest.c
src/backend/tcop/fastpath.c
src/backend/tcop/postgres.c
src/backend/tcop/pquery.c
src/backend/tcop/utility.c
src/backend/tioga/tgRecipe.c
src/backend/tioga/tgRecipe.h
src/backend/utils/adt/acl.c
src/backend/utils/adt/arrayfuncs.c
src/backend/utils/adt/ascii.c
src/backend/utils/adt/bool.c
src/backend/utils/adt/cash.c
src/backend/utils/adt/date.c
src/backend/utils/adt/datetime.c
src/backend/utils/adt/datum.c
src/backend/utils/adt/float.c
src/backend/utils/adt/format_type.c
src/backend/utils/adt/formatting.c
src/backend/utils/adt/geo_ops.c
src/backend/utils/adt/inet_net_ntop.c
src/backend/utils/adt/int.c
src/backend/utils/adt/int8.c
src/backend/utils/adt/like.c
src/backend/utils/adt/mac.c
src/backend/utils/adt/misc.c
src/backend/utils/adt/nabstime.c
src/backend/utils/adt/network.c
src/backend/utils/adt/not_in.c
src/backend/utils/adt/numeric.c
src/backend/utils/adt/numutils.c
src/backend/utils/adt/oid.c
src/backend/utils/adt/oracle_compat.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/adt/pg_lzcompress.c
src/backend/utils/adt/quote.c
src/backend/utils/adt/regexp.c
src/backend/utils/adt/regproc.c
src/backend/utils/adt/ri_triggers.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/adt/selfuncs.c
src/backend/utils/adt/sets.c
src/backend/utils/adt/tid.c
src/backend/utils/adt/timestamp.c
src/backend/utils/adt/varbit.c
src/backend/utils/adt/varchar.c
src/backend/utils/adt/varlena.c
src/backend/utils/cache/catcache.c
src/backend/utils/cache/fcache.c
src/backend/utils/cache/inval.c
src/backend/utils/cache/lsyscache.c
src/backend/utils/cache/relcache.c
src/backend/utils/cache/syscache.c
src/backend/utils/cache/temprel.c
src/backend/utils/error/elog.c
src/backend/utils/error/exc.c
src/backend/utils/fmgr/dfmgr.c
src/backend/utils/fmgr/fmgr.c
src/backend/utils/hash/dynahash.c
src/backend/utils/hash/pg_crc.c
src/backend/utils/init/globals.c
src/backend/utils/init/miscinit.c
src/backend/utils/init/postinit.c
src/backend/utils/mb/conv.c
src/backend/utils/mb/liketest.c
src/backend/utils/mb/palloc.c
src/backend/utils/mb/utftest.c
src/backend/utils/mb/wchar.c
src/backend/utils/misc/database.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/ps_status.c
src/backend/utils/mmgr/aset.c
src/backend/utils/mmgr/mcxt.c
src/backend/utils/mmgr/portalmem.c
src/backend/utils/sort/tuplesort.c
src/backend/utils/sort/tuplestore.c
src/bin/pg_dump/common.c
src/bin/pg_dump/pg_backup.h
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_backup_custom.c
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_backup_db.h
src/bin/pg_dump/pg_backup_files.c
src/bin/pg_dump/pg_backup_null.c
src/bin/pg_dump/pg_backup_tar.c
src/bin/pg_dump/pg_backup_tar.h
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dump.h
src/bin/pg_dump/pg_restore.c
src/bin/pg_id/pg_id.c
src/bin/pg_passwd/pg_passwd.c
src/bin/psql/command.c
src/bin/psql/copy.c
src/bin/psql/describe.c
src/bin/psql/help.c
src/bin/psql/large_obj.c
src/bin/psql/mainloop.c
src/bin/psql/print.c
src/bin/psql/prompt.c
src/bin/psql/startup.c
src/bin/psql/tab-complete.c
src/include/access/gist.h
src/include/access/hash.h
src/include/access/heapam.h
src/include/access/htup.h
src/include/access/istrat.h
src/include/access/itup.h
src/include/access/nbtree.h
src/include/access/printtup.h
src/include/access/rtree.h
src/include/access/strat.h
src/include/access/transam.h
src/include/access/tupmacs.h
src/include/access/tuptoaster.h
src/include/access/xact.h
src/include/access/xlog.h
src/include/access/xlogdefs.h
src/include/access/xlogutils.h
src/include/c.h
src/include/catalog/catalog.h
src/include/catalog/catversion.h
src/include/catalog/heap.h
src/include/catalog/index.h
src/include/catalog/indexing.h
src/include/catalog/pg_aggregate.h
src/include/catalog/pg_amop.h
src/include/catalog/pg_attribute.h
src/include/catalog/pg_class.h
src/include/catalog/pg_control.h
src/include/catalog/pg_database.h
src/include/catalog/pg_largeobject.h
src/include/catalog/pg_operator.h
src/include/catalog/pg_proc.h
src/include/catalog/pg_rewrite.h
src/include/catalog/pg_type.h
src/include/commands/command.h
src/include/commands/comment.h
src/include/commands/dbcommands.h
src/include/commands/sequence.h
src/include/commands/trigger.h
src/include/commands/vacuum.h
src/include/executor/execFlatten.h
src/include/executor/executor.h
src/include/executor/hashjoin.h
src/include/executor/nodeHash.h
src/include/fmgr.h
src/include/lib/dllist.h
src/include/libpq/auth.h
src/include/libpq/hba.h
src/include/libpq/libpq.h
src/include/libpq/pqcomm.h
src/include/mb/pg_wchar.h
src/include/miscadmin.h
src/include/nodes/execnodes.h
src/include/nodes/memnodes.h
src/include/nodes/nodes.h
src/include/nodes/parsenodes.h
src/include/nodes/plannodes.h
src/include/nodes/primnodes.h
src/include/nodes/relation.h
src/include/optimizer/clauses.h
src/include/optimizer/geqo.h
src/include/optimizer/geqo_pool.h
src/include/optimizer/pathnode.h
src/include/optimizer/paths.h
src/include/optimizer/plancat.h
src/include/optimizer/planmain.h
src/include/optimizer/prep.h
src/include/optimizer/restrictinfo.h
src/include/parser/parse_clause.h
src/include/parser/parse_coerce.h
src/include/parser/parse_func.h
src/include/parser/parse_node.h
src/include/parser/parse_oper.h
src/include/parser/parse_relation.h
src/include/port/beos.h
src/include/port/darwin.h
src/include/port/darwin/sem.h
src/include/port/freebsd.h
src/include/port/netbsd.h
src/include/port/openbsd.h
src/include/port/osf.h
src/include/port/solaris.h
src/include/port/win.h
src/include/postgres.h
src/include/postgres_ext.h
src/include/regex/regex.h
src/include/regex/utils.h
src/include/rewrite/rewriteManip.h
src/include/rewrite/rewriteSupport.h
src/include/storage/buf_internals.h
src/include/storage/bufmgr.h
src/include/storage/bufpage.h
src/include/storage/ipc.h
src/include/storage/itemid.h
src/include/storage/itemptr.h
src/include/storage/large_object.h
src/include/storage/lmgr.h
src/include/storage/lock.h
src/include/storage/proc.h
src/include/storage/relfilenode.h
src/include/storage/shmem.h
src/include/storage/sinvaladt.h
src/include/storage/smgr.h
src/include/storage/spin.h
src/include/tcop/tcopprot.h
src/include/utils/acl.h
src/include/utils/array.h
src/include/utils/ascii.h
src/include/utils/builtins.h
src/include/utils/catcache.h
src/include/utils/date.h
src/include/utils/datum.h
src/include/utils/elog.h
src/include/utils/fcache.h
src/include/utils/fmgrtab.h
src/include/utils/geo_decls.h
src/include/utils/guc.h
src/include/utils/hsearch.h
src/include/utils/inet.h
src/include/utils/lsyscache.h
src/include/utils/memutils.h
src/include/utils/nabstime.h
src/include/utils/numeric.h
src/include/utils/palloc.h
src/include/utils/pg_crc.h
src/include/utils/pg_locale.h
src/include/utils/portal.h
src/include/utils/ps_status.h
src/include/utils/rel.h
src/include/utils/syscache.h
src/include/utils/temprel.h
src/include/utils/timestamp.h
src/include/utils/tuplestore.h
src/include/utils/varbit.h
src/interfaces/cli/example1.c
src/interfaces/cli/example2.c
src/interfaces/cli/sqlcli.h
src/interfaces/ecpg/include/ecpgerrno.h
src/interfaces/ecpg/include/ecpglib.h
src/interfaces/ecpg/include/sqlca.h
src/interfaces/ecpg/lib/connect.c
src/interfaces/ecpg/lib/data.c
src/interfaces/ecpg/lib/descriptor.c
src/interfaces/ecpg/lib/error.c
src/interfaces/ecpg/lib/execute.c
src/interfaces/ecpg/lib/extern.h
src/interfaces/ecpg/lib/typename.c
src/interfaces/ecpg/preproc/descriptor.c
src/interfaces/ecpg/preproc/ecpg.c
src/interfaces/ecpg/preproc/ecpg_keywords.c
src/interfaces/ecpg/preproc/extern.h
src/interfaces/ecpg/preproc/keywords.c
src/interfaces/ecpg/preproc/type.c
src/interfaces/libpgeasy/examples/pginsert.c
src/interfaces/libpgeasy/examples/pgnulltest.c
src/interfaces/libpgeasy/examples/pgwordcount.c
src/interfaces/libpgeasy/halt.c
src/interfaces/libpgeasy/libpgeasy.h
src/interfaces/libpgtcl/pgtcl.c
src/interfaces/libpgtcl/pgtclCmds.c
src/interfaces/libpgtcl/pgtclCmds.h
src/interfaces/libpq/fe-auth.c
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-misc.c
src/interfaces/libpq/fe-print.c
src/interfaces/libpq/libpq-fe.h
src/interfaces/libpq/libpq-int.h
src/interfaces/odbc/bind.c
src/interfaces/odbc/bind.h
src/interfaces/odbc/columninfo.c
src/interfaces/odbc/columninfo.h
src/interfaces/odbc/connection.c
src/interfaces/odbc/connection.h
src/interfaces/odbc/convert.c
src/interfaces/odbc/convert.h
src/interfaces/odbc/dlg_specific.c
src/interfaces/odbc/dlg_specific.h
src/interfaces/odbc/drvconn.c
src/interfaces/odbc/environ.c
src/interfaces/odbc/environ.h
src/interfaces/odbc/execute.c
src/interfaces/odbc/gpps.c
src/interfaces/odbc/gpps.h
src/interfaces/odbc/info.c
src/interfaces/odbc/iodbc.h
src/interfaces/odbc/isql.h
src/interfaces/odbc/isqlext.h
src/interfaces/odbc/lobj.c
src/interfaces/odbc/lobj.h
src/interfaces/odbc/misc.c
src/interfaces/odbc/misc.h
src/interfaces/odbc/multibyte.c
src/interfaces/odbc/multibyte.h
src/interfaces/odbc/options.c
src/interfaces/odbc/parse.c
src/interfaces/odbc/pgtypes.c
src/interfaces/odbc/pgtypes.h
src/interfaces/odbc/psqlodbc.c
src/interfaces/odbc/psqlodbc.h
src/interfaces/odbc/qresult.c
src/interfaces/odbc/qresult.h
src/interfaces/odbc/resource.h
src/interfaces/odbc/results.c
src/interfaces/odbc/setup.c
src/interfaces/odbc/socket.c
src/interfaces/odbc/socket.h
src/interfaces/odbc/statement.c
src/interfaces/odbc/statement.h
src/interfaces/odbc/tuple.c
src/interfaces/odbc/tuple.h
src/interfaces/odbc/tuplelist.c
src/interfaces/odbc/tuplelist.h
src/interfaces/perl5/ppport.h
src/interfaces/python/pgmodule.c
src/pl/plperl/plperl.c
src/pl/plperl/ppport.h
src/pl/plpgsql/src/pl_comp.c
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/pl_funcs.c
src/pl/plpgsql/src/pl_handler.c
src/pl/plpgsql/src/plpgsql.h
src/pl/tcl/pltcl.c
src/test/examples/testlo.c
src/test/regress/regress.c
src/tools/entab/halt.c
src/tutorial/beard.c
src/tutorial/funcs.c
src/tutorial/funcs_new.c
src/utils/dllinit.c

index 0bcc2d19b57f61ca1ffb35d1cac49d5c7856d8d5..bab7ae303c629980518be73bf6647a9f6a02ee37 100644 (file)
@@ -4,76 +4,81 @@
 
 #include "utils/elog.h"
 
-static char *       PARSE_BUFFER;
-static char *       PARSE_BUFFER_PTR; 
-static unsigned int PARSE_BUFFER_SIZE; 
+static char *PARSE_BUFFER;
+static char *PARSE_BUFFER_PTR;
+static unsigned int PARSE_BUFFER_SIZE;
 static unsigned int SCANNER_POS;
 
-void         set_parse_buffer( char* s );
-void         reset_parse_buffer( void );
-int          read_parse_buffer( void );
-char *       parse_buffer( void );
-char *       parse_buffer_ptr( void );
-unsigned int parse_buffer_curr_char( void );
-unsigned int parse_buffer_size( void );
-unsigned int parse_buffer_pos( void );
+void           set_parse_buffer(char *s);
+void           reset_parse_buffer(void);
+int                    read_parse_buffer(void);
+char      *parse_buffer(void);
+char      *parse_buffer_ptr(void);
+unsigned int parse_buffer_curr_char(void);
+unsigned int parse_buffer_size(void);
+unsigned int parse_buffer_pos(void);
 
-extern void cube_flush_scanner_buffer(void); /* defined in cubescan.l */
+extern void cube_flush_scanner_buffer(void);   /* defined in cubescan.l */
 
-void set_parse_buffer( char* s )
+void
+set_parse_buffer(char *s)
 {
-  PARSE_BUFFER = s;
-  PARSE_BUFFER_SIZE = strlen(s);
-  if ( PARSE_BUFFER_SIZE == 0 ) {
-    elog(ERROR, "cube_in: can't parse an empty string");
-  }
-  PARSE_BUFFER_PTR = PARSE_BUFFER;
-  SCANNER_POS = 0;
+       PARSE_BUFFER = s;
+       PARSE_BUFFER_SIZE = strlen(s);
+       if (PARSE_BUFFER_SIZE == 0)
+               elog(ERROR, "cube_in: can't parse an empty string");
+       PARSE_BUFFER_PTR = PARSE_BUFFER;
+       SCANNER_POS = 0;
 }
 
-void reset_parse_buffer( void )
+void
+reset_parse_buffer(void)
 {
-  PARSE_BUFFER_PTR = PARSE_BUFFER;
-  SCANNER_POS = 0;
-  cube_flush_scanner_buffer();
+       PARSE_BUFFER_PTR = PARSE_BUFFER;
+       SCANNER_POS = 0;
+       cube_flush_scanner_buffer();
 }
 
-int read_parse_buffer( void )
+int
+read_parse_buffer(void)
 {
-  int c;
-  /*
-  c = *PARSE_BUFFER_PTR++;
-  SCANNER_POS++;
-  */
-  c = PARSE_BUFFER[SCANNER_POS];
-  if(SCANNER_POS < PARSE_BUFFER_SIZE)
-    SCANNER_POS++;
-  return c;
+       int                     c;
+
+       /*
+        * c = *PARSE_BUFFER_PTR++; SCANNER_POS++;
+        */
+       c = PARSE_BUFFER[SCANNER_POS];
+       if (SCANNER_POS < PARSE_BUFFER_SIZE)
+               SCANNER_POS++;
+       return c;
 }
 
-char * parse_buffer( void )
+char *
+parse_buffer(void)
 {
-  return PARSE_BUFFER;
+       return PARSE_BUFFER;
 }
 
-unsigned int parse_buffer_curr_char( void )
+unsigned int
+parse_buffer_curr_char(void)
 {
-  return PARSE_BUFFER[SCANNER_POS];
+       return PARSE_BUFFER[SCANNER_POS];
 }
 
-char * parse_buffer_ptr( void )
+char *
+parse_buffer_ptr(void)
 {
-  return PARSE_BUFFER_PTR;
+       return PARSE_BUFFER_PTR;
 }
 
-unsigned int parse_buffer_pos( void )
+unsigned int
+parse_buffer_pos(void)
 {
-  return SCANNER_POS;
+       return SCANNER_POS;
 }
 
-unsigned int parse_buffer_size( void )
+unsigned int
+parse_buffer_size(void)
 {
-  return PARSE_BUFFER_SIZE;
+       return PARSE_BUFFER_SIZE;
 }
-
-
index fd41a7b69b713e2b4dc23716af8905477ff8a379..eef9124dac5eff3cbbc4236b13970b4a6862cf46 100644 (file)
@@ -1,8 +1,8 @@
-extern void set_parse_buffer( char* s );
-extern void reset_parse_buffer( void );
-extern int read_parse_buffer( void );
-extern char * parse_buffer( void );
-extern char * parse_buffer_ptr( void );
-extern unsigned int parse_buffer_curr_char( void );
-extern unsigned int parse_buffer_pos( void );
-extern unsigned int parse_buffer_size( void );
+extern void set_parse_buffer(char *s);
+extern void reset_parse_buffer(void);
+extern int     read_parse_buffer(void);
+extern char *parse_buffer(void);
+extern char *parse_buffer_ptr(void);
+extern unsigned int parse_buffer_curr_char(void);
+extern unsigned int parse_buffer_pos(void);
+extern unsigned int parse_buffer_size(void);
index 35ac34f0b047322e9b7e26ec0036a192c189f497..4d6169a48020fe9ea42390e4fee2b1ebc123a6f9 100644 (file)
 
 #include "cubedata.h"
 
-#define max(a,b)        ((a) >  (b) ? (a) : (b))
-#define min(a,b)        ((a) <= (b) ? (a) : (b))
-#define abs(a)          ((a) <  (0) ? (-a) : (a))
+#define max(a,b)               ((a) >  (b) ? (a) : (b))
+#define min(a,b)               ((a) <= (b) ? (a) : (b))
+#define abs(a)                 ((a) <  (0) ? (-a) : (a))
 
-extern void  set_parse_buffer(char *str);
-extern int   cube_yyparse();
+extern void set_parse_buffer(char *str);
+extern int     cube_yyparse();
 
 /*
 ** Input/Output routines
 */
-NDBOX *      cube_in(char *str);
-char *       cube_out(NDBOX *cube);
+NDBOX     *cube_in(char *str);
+char      *cube_out(NDBOX * cube);
 
 
-/* 
+/*
 ** GiST support methods
 */
-bool             g_cube_consistent(GISTENTRY *entry, NDBOX *query, StrategyNumber strategy); 
-GISTENTRY *      g_cube_compress(GISTENTRY *entry);
-GISTENTRY *      g_cube_decompress(GISTENTRY *entry);
-float *          g_cube_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result);
-GIST_SPLITVEC *  g_cube_picksplit(bytea *entryvec, GIST_SPLITVEC *v);
-bool             g_cube_leaf_consistent(NDBOX *key, NDBOX *query, StrategyNumber strategy);
-bool             g_cube_internal_consistent(NDBOX *key, NDBOX *query, StrategyNumber strategy);
-NDBOX *          g_cube_union(bytea *entryvec, int *sizep);
-NDBOX *          g_cube_binary_union(NDBOX *r1, NDBOX *r2, int *sizep);
-bool *           g_cube_same(NDBOX *b1, NDBOX *b2, bool *result);
+bool           g_cube_consistent(GISTENTRY *entry, NDBOX * query, StrategyNumber strategy);
+GISTENTRY  *g_cube_compress(GISTENTRY *entry);
+GISTENTRY  *g_cube_decompress(GISTENTRY *entry);
+float     *g_cube_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result);
+GIST_SPLITVEC *g_cube_picksplit(bytea *entryvec, GIST_SPLITVEC *v);
+bool           g_cube_leaf_consistent(NDBOX * key, NDBOX * query, StrategyNumber strategy);
+bool           g_cube_internal_consistent(NDBOX * key, NDBOX * query, StrategyNumber strategy);
+NDBOX     *g_cube_union(bytea *entryvec, int *sizep);
+NDBOX     *g_cube_binary_union(NDBOX * r1, NDBOX * r2, int *sizep);
+bool      *g_cube_same(NDBOX * b1, NDBOX * b2, bool *result);
 
 /*
 ** R-tree suport functions
 */
-bool         cube_same(NDBOX *a, NDBOX *b);
-bool         cube_different(NDBOX *a, NDBOX *b);
-bool         cube_contains(NDBOX *a, NDBOX *b);
-bool         cube_contained (NDBOX *a, NDBOX *b);
-bool         cube_overlap(NDBOX *a, NDBOX *b);
-NDBOX *      cube_union(NDBOX *a, NDBOX *b);
-NDBOX *      cube_inter(NDBOX *a, NDBOX *b);
-float *      cube_size(NDBOX *a);
-void         rt_cube_size(NDBOX *a, float *sz);
+bool           cube_same(NDBOX * a, NDBOX * b);
+bool           cube_different(NDBOX * a, NDBOX * b);
+bool           cube_contains(NDBOX * a, NDBOX * b);
+bool           cube_contained(NDBOX * a, NDBOX * b);
+bool           cube_overlap(NDBOX * a, NDBOX * b);
+NDBOX     *cube_union(NDBOX * a, NDBOX * b);
+NDBOX     *cube_inter(NDBOX * a, NDBOX * b);
+float     *cube_size(NDBOX * a);
+void           rt_cube_size(NDBOX * a, float *sz);
 
 /*
 ** These make no sense for this type, but R-tree wants them
 */
-bool         cube_over_left(NDBOX *a, NDBOX *b);
-bool         cube_over_right(NDBOX *a, NDBOX *b);
-bool         cube_left(NDBOX *a, NDBOX *b);
-bool         cube_right(NDBOX *a, NDBOX *b);
+bool           cube_over_left(NDBOX * a, NDBOX * b);
+bool           cube_over_right(NDBOX * a, NDBOX * b);
+bool           cube_left(NDBOX * a, NDBOX * b);
+bool           cube_right(NDBOX * a, NDBOX * b);
 
 /*
 ** miscellaneous
 */
-bool         cube_lt(NDBOX *a, NDBOX *b);
-bool         cube_gt(NDBOX *a, NDBOX *b);
-float *      cube_distance(NDBOX *a, NDBOX *b);
+bool           cube_lt(NDBOX * a, NDBOX * b);
+bool           cube_gt(NDBOX * a, NDBOX * b);
+float     *cube_distance(NDBOX * a, NDBOX * b);
 
-/* 
+/*
 ** Auxiliary funxtions
 */
-static       float distance_1D(float a1, float a2, float b1, float b2);
-static       NDBOX *swap_corners (NDBOX *a);
+static float distance_1D(float a1, float a2, float b1, float b2);
+static NDBOX *swap_corners(NDBOX * a);
 
 
 /*****************************************************************************
@@ -88,68 +88,71 @@ static       NDBOX *swap_corners (NDBOX *a);
 NDBOX *
 cube_in(char *str)
 {
-  void * result;
+       void       *result;
 
-  set_parse_buffer( str );
+       set_parse_buffer(str);
 
-  if ( cube_yyparse(&result) != 0 ) {
-    return NULL;
-  } 
+       if (cube_yyparse(&result) != 0)
+               return NULL;
 
-  return ( (NDBOX *)result );
+       return ((NDBOX *) result);
 }
 
 /*
  * You might have noticed a slight inconsistency between the following
  * declaration and the SQL definition:
- *     CREATE FUNCTION cube_out(opaque) RETURNS opaque ...
+ *        CREATE FUNCTION cube_out(opaque) RETURNS opaque ...
  * The reason is that the argument pass into cube_out is really just a
  * pointer. POSTGRES thinks all output functions are:
- *     char *out_func(char *);
+ *        char *out_func(char *);
  */
 char *
-cube_out(NDBOX *cube)
+cube_out(NDBOX * cube)
 {
-    char *result;
-    char *p;
-    int equal = 1;
-    int dim = cube->dim;
-    int i;
-
-    if (cube == NULL)
-       return(NULL);
-
-    p = result = (char *) palloc(100);
-
-    /* while printing the first (LL) corner, check if it is equal
-    to the scond one */
-    p += sprintf(p, "(");
-    for ( i=0; i < dim; i++ ) {
-      p += sprintf(p, "%g", cube->x[i]);
-      p += sprintf(p, ", ");
-      if ( cube->x[i] != cube->x[i+dim] ) {
-       equal = 0;
-      }
-    }
-    p -= 2; /* get rid of the last ", " */
-    p += sprintf(p, ")");
-
-    if ( !equal ) {
-    p += sprintf(p, ",(");
-      for ( i=dim; i < dim * 2; i++ ) {
-       p += sprintf(p, "%g", cube->x[i]);
-       p += sprintf(p, ", ");
-      }
-      p -= 2; 
-      p += sprintf(p, ")");
-    }
-      
-    return(result);
+       char       *result;
+       char       *p;
+       int                     equal = 1;
+       int                     dim = cube->dim;
+       int                     i;
+
+       if (cube == NULL)
+               return (NULL);
+
+       p = result = (char *) palloc(100);
+
+       /*
+        * while printing the first (LL) corner, check if it is equal to the
+        * scond one
+        */
+       p += sprintf(p, "(");
+       for (i = 0; i < dim; i++)
+       {
+               p += sprintf(p, "%g", cube->x[i]);
+               p += sprintf(p, ", ");
+               if (cube->x[i] != cube->x[i + dim])
+                       equal = 0;
+       }
+       p -= 2;                                         /* get rid of the last ", " */
+       p += sprintf(p, ")");
+
+       if (!equal)
+       {
+               p += sprintf(p, ",(");
+               for (i = dim; i < dim * 2; i++)
+               {
+                       p += sprintf(p, "%g", cube->x[i]);
+                       p += sprintf(p, ", ");
+               }
+               p -= 2;
+               p += sprintf(p, ")");
+       }
+
+       return (result);
 }
 
 
 /*****************************************************************************
- *                         GiST functions
+ *                                                GiST functions
  *****************************************************************************/
 
 /*
@@ -158,19 +161,20 @@ cube_out(NDBOX *cube)
 ** the predicate x op query == FALSE, where op is the oper
 ** corresponding to strategy in the pg_amop table.
 */
-bool 
+bool
 g_cube_consistent(GISTENTRY *entry,
-              NDBOX *query,
-              StrategyNumber strategy)
+                                 NDBOX * query,
+                                 StrategyNumber strategy)
 {
-    /*
-    ** if entry is not leaf, use g_cube_internal_consistent,
-    ** else use g_cube_leaf_consistent
-    */
-    if (GIST_LEAF(entry))
-      return(g_cube_leaf_consistent((NDBOX *)(entry->pred), query, strategy));
-    else
-      return(g_cube_internal_consistent((NDBOX *)(entry->pred), query, strategy));
+
+       /*
+        * * if entry is not leaf, use g_cube_internal_consistent, * else use
+        * g_cube_leaf_consistent
+        */
+       if (GIST_LEAF(entry))
+               return (g_cube_leaf_consistent((NDBOX *) (entry->pred), query, strategy));
+       else
+               return (g_cube_internal_consistent((NDBOX *) (entry->pred), query, strategy));
 }
 
 
@@ -181,48 +185,55 @@ g_cube_consistent(GISTENTRY *entry,
 NDBOX *
 g_cube_union(bytea *entryvec, int *sizep)
 {
-    int numranges, i;
-    NDBOX *out = (NDBOX *)NULL;
-    NDBOX *tmp;
-
-    /*
-    fprintf(stderr, "union\n");
-    */
-    numranges = (VARSIZE(entryvec) - VARHDRSZ)/sizeof(GISTENTRY); 
-    tmp = (NDBOX *)(((GISTENTRY *)(VARDATA(entryvec)))[0]).pred;
-    /*
-    *sizep = sizeof(NDBOX); -- NDBOX has variable size
-    */
-    *sizep = tmp->size;
-
-    for (i = 1; i < numranges; i++) {
-      out = g_cube_binary_union(tmp, (NDBOX *)
-                                (((GISTENTRY *)(VARDATA(entryvec)))[i]).pred,
-                                sizep);
-      /*
-       fprintf(stderr, "\t%s ^ %s -> %s\n", cube_out(tmp), cube_out((NDBOX *)(((GISTENTRY *)(VARDATA(entryvec)))[i]).pred), cube_out(out));
-      */
-      if (i > 1) pfree(tmp);
-      tmp = out;
-    }
-
-    return(out);
+       int                     numranges,
+                               i;
+       NDBOX      *out = (NDBOX *) NULL;
+       NDBOX      *tmp;
+
+       /*
+        * fprintf(stderr, "union\n");
+        */
+       numranges = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
+       tmp = (NDBOX *) (((GISTENTRY *) (VARDATA(entryvec)))[0]).pred;
+
+       /*
+        * sizep = sizeof(NDBOX); -- NDBOX has variable size
+        */
+       *sizep = tmp->size;
+
+       for (i = 1; i < numranges; i++)
+       {
+               out = g_cube_binary_union(tmp, (NDBOX *)
+                                                  (((GISTENTRY *) (VARDATA(entryvec)))[i]).pred,
+                                                                 sizep);
+
+               /*
+                * fprintf(stderr, "\t%s ^ %s -> %s\n", cube_out(tmp),
+                * cube_out((NDBOX *)(((GISTENTRY
+                * *)(VARDATA(entryvec)))[i]).pred), cube_out(out));
+                */
+               if (i > 1)
+                       pfree(tmp);
+               tmp = out;
+       }
+
+       return (out);
 }
 
 /*
 ** GiST Compress and Decompress methods for boxes
 ** do not do anything.
 */
-GISTENTRY *
+GISTENTRY  *
 g_cube_compress(GISTENTRY *entry)
 {
-    return(entry);
+       return (entry);
 }
 
-GISTENTRY *
+GISTENTRY  *
 g_cube_decompress(GISTENTRY *entry)
 {
-    return(entry);
+       return (entry);
 }
 
 /*
@@ -232,398 +243,448 @@ g_cube_decompress(GISTENTRY *entry)
 float *
 g_cube_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result)
 {
-    Datum ud;
-    float tmp1, tmp2;
-    
-    ud = (Datum)cube_union((NDBOX *)(origentry->pred), (NDBOX *)(newentry->pred));
-    rt_cube_size((NDBOX *)ud, &tmp1);
-    rt_cube_size((NDBOX *)(origentry->pred), &tmp2);
-    *result = tmp1 - tmp2;
-    pfree((char *)ud);
-    /*
-    fprintf(stderr, "penalty\n");
-    fprintf(stderr, "\t%g\n", *result);
-    */
-    return(result);
+       Datum           ud;
+       float           tmp1,
+                               tmp2;
+
+       ud = (Datum) cube_union((NDBOX *) (origentry->pred), (NDBOX *) (newentry->pred));
+       rt_cube_size((NDBOX *) ud, &tmp1);
+       rt_cube_size((NDBOX *) (origentry->pred), &tmp2);
+       *result = tmp1 - tmp2;
+       pfree((char *) ud);
+
+       /*
+        * fprintf(stderr, "penalty\n"); fprintf(stderr, "\t%g\n", *result);
+        */
+       return (result);
 }
 
 
 
 /*
 ** The GiST PickSplit method for boxes
-** We use Guttman's poly time split algorithm 
+** We use Guttman's poly time split algorithm
 */
 GIST_SPLITVEC *
 g_cube_picksplit(bytea *entryvec,
-             GIST_SPLITVEC *v)
+                                GIST_SPLITVEC *v)
 {
-    OffsetNumber i, j;
-    NDBOX *datum_alpha, *datum_beta;
-    NDBOX *datum_l, *datum_r;
-    NDBOX *union_d, *union_dl, *union_dr;
-    NDBOX *inter_d;
-    bool firsttime;
-    float size_alpha, size_beta, size_union, size_inter;
-    float size_waste, waste;
-    float size_l, size_r;
-    int nbytes;
-    OffsetNumber seed_1 = 0, seed_2 = 0;
-    OffsetNumber *left, *right;
-    OffsetNumber maxoff;
-
-    /*
-    fprintf(stderr, "picksplit\n");
-    */
-    maxoff = ((VARSIZE(entryvec) - VARHDRSZ)/sizeof(GISTENTRY)) - 2;
-    nbytes =  (maxoff + 2) * sizeof(OffsetNumber);
-    v->spl_left = (OffsetNumber *) palloc(nbytes);
-    v->spl_right = (OffsetNumber *) palloc(nbytes);
-    
-    firsttime = true;
-    waste = 0.0;
-    
-    for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i)) {
-       datum_alpha = (NDBOX *)(((GISTENTRY *)(VARDATA(entryvec)))[i].pred);
-       for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j)) {
-           datum_beta = (NDBOX *)(((GISTENTRY *)(VARDATA(entryvec)))[j].pred);
-           
-           /* compute the wasted space by unioning these guys */
-           /* size_waste = size_union - size_inter; */
-           union_d = (NDBOX *)cube_union(datum_alpha, datum_beta);
-           rt_cube_size(union_d, &size_union);
-           inter_d = (NDBOX *)cube_inter(datum_alpha, datum_beta);
-           rt_cube_size(inter_d, &size_inter);
-           size_waste = size_union - size_inter;
-           
-           pfree(union_d);
-           
-           if (inter_d != (NDBOX *) NULL)
-               pfree(inter_d);
-           
-           /*
-            *  are these a more promising split than what we've
-            *  already seen?
-            */
-           
-           if (size_waste > waste || firsttime) {
-               waste = size_waste;
-               seed_1 = i;
-               seed_2 = j;
-               firsttime = false;
-           }
-       }
-    }
-    
-    left = v->spl_left;
-    v->spl_nleft = 0;
-    right = v->spl_right;
-    v->spl_nright = 0;
-    
-    datum_alpha = (NDBOX *)(((GISTENTRY *)(VARDATA(entryvec)))[seed_1].pred);
-    datum_l = (NDBOX *)cube_union(datum_alpha, datum_alpha);
-    rt_cube_size((NDBOX *)datum_l, &size_l);
-    datum_beta = (NDBOX *)(((GISTENTRY *)(VARDATA(entryvec)))[seed_2].pred);;
-    datum_r = (NDBOX *)cube_union(datum_beta, datum_beta);
-    rt_cube_size((NDBOX *)datum_r, &size_r);
-    
-    /*
-     *  Now split up the regions between the two seeds.  An important
-     *  property of this split algorithm is that the split vector v
-     *  has the indices of items to be split in order in its left and
-     *  right vectors.  We exploit this property by doing a merge in
-     *  the code that actually splits the page.
-     *
-     *  For efficiency, we also place the new index tuple in this loop.
-     *  This is handled at the very end, when we have placed all the
-     *  existing tuples and i == maxoff + 1.
-     */
-    
-    maxoff = OffsetNumberNext(maxoff);
-    for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) {
-       
+       OffsetNumber i,
+                               j;
+       NDBOX      *datum_alpha,
+                          *datum_beta;
+       NDBOX      *datum_l,
+                          *datum_r;
+       NDBOX      *union_d,
+                          *union_dl,
+                          *union_dr;
+       NDBOX      *inter_d;
+       bool            firsttime;
+       float           size_alpha,
+                               size_beta,
+                               size_union,
+                               size_inter;
+       float           size_waste,
+                               waste;
+       float           size_l,
+                               size_r;
+       int                     nbytes;
+       OffsetNumber seed_1 = 0,
+                               seed_2 = 0;
+       OffsetNumber *left,
+                          *right;
+       OffsetNumber maxoff;
+
        /*
-        *  If we've already decided where to place this item, just
-        *  put it on the right list.  Otherwise, we need to figure
-        *  out which page needs the least enlargement in order to
-        *  store the item.
+        * fprintf(stderr, "picksplit\n");
         */
-       
-       if (i == seed_1) {
-           *left++ = i;
-           v->spl_nleft++;
-           continue;
-       } else if (i == seed_2) {
-           *right++ = i;
-           v->spl_nright++;
-           continue;
+       maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2;
+       nbytes = (maxoff + 2) * sizeof(OffsetNumber);
+       v->spl_left = (OffsetNumber *) palloc(nbytes);
+       v->spl_right = (OffsetNumber *) palloc(nbytes);
+
+       firsttime = true;
+       waste = 0.0;
+
+       for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i))
+       {
+               datum_alpha = (NDBOX *) (((GISTENTRY *) (VARDATA(entryvec)))[i].pred);
+               for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j))
+               {
+                       datum_beta = (NDBOX *) (((GISTENTRY *) (VARDATA(entryvec)))[j].pred);
+
+                       /* compute the wasted space by unioning these guys */
+                       /* size_waste = size_union - size_inter; */
+                       union_d = (NDBOX *) cube_union(datum_alpha, datum_beta);
+                       rt_cube_size(union_d, &size_union);
+                       inter_d = (NDBOX *) cube_inter(datum_alpha, datum_beta);
+                       rt_cube_size(inter_d, &size_inter);
+                       size_waste = size_union - size_inter;
+
+                       pfree(union_d);
+
+                       if (inter_d != (NDBOX *) NULL)
+                               pfree(inter_d);
+
+                       /*
+                        * are these a more promising split than what we've already
+                        * seen?
+                        */
+
+                       if (size_waste > waste || firsttime)
+                       {
+                               waste = size_waste;
+                               seed_1 = i;
+                               seed_2 = j;
+                               firsttime = false;
+                       }
+               }
        }
-       
-       /* okay, which page needs least enlargement? */ 
-       datum_alpha = (NDBOX *)(((GISTENTRY *)(VARDATA(entryvec)))[i].pred);
-       union_dl = (NDBOX *)cube_union(datum_l, datum_alpha);
-       union_dr = (NDBOX *)cube_union(datum_r, datum_alpha);
-       rt_cube_size((NDBOX *)union_dl, &size_alpha);
-       rt_cube_size((NDBOX *)union_dr, &size_beta);
-       
-       /* pick which page to add it to */
-       if (size_alpha - size_l < size_beta - size_r) {
-           pfree(datum_l);
-           pfree(union_dr);
-           datum_l = union_dl;
-           size_l = size_alpha;
-           *left++ = i;
-           v->spl_nleft++;
-       } else {
-           pfree(datum_r);
-           pfree(union_dl);
-           datum_r = union_dr;
-           size_r = size_alpha;
-           *right++ = i;
-           v->spl_nright++;
+
+       left = v->spl_left;
+       v->spl_nleft = 0;
+       right = v->spl_right;
+       v->spl_nright = 0;
+
+       datum_alpha = (NDBOX *) (((GISTENTRY *) (VARDATA(entryvec)))[seed_1].pred);
+       datum_l = (NDBOX *) cube_union(datum_alpha, datum_alpha);
+       rt_cube_size((NDBOX *) datum_l, &size_l);
+       datum_beta = (NDBOX *) (((GISTENTRY *) (VARDATA(entryvec)))[seed_2].pred);;
+       datum_r = (NDBOX *) cube_union(datum_beta, datum_beta);
+       rt_cube_size((NDBOX *) datum_r, &size_r);
+
+       /*
+        * Now split up the regions between the two seeds.      An important
+        * property of this split algorithm is that the split vector v has the
+        * indices of items to be split in order in its left and right
+        * vectors.  We exploit this property by doing a merge in the code
+        * that actually splits the page.
+        *
+        * For efficiency, we also place the new index tuple in this loop. This
+        * is handled at the very end, when we have placed all the existing
+        * tuples and i == maxoff + 1.
+        */
+
+       maxoff = OffsetNumberNext(maxoff);
+       for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+       {
+
+               /*
+                * If we've already decided where to place this item, just put it
+                * on the right list.  Otherwise, we need to figure out which page
+                * needs the least enlargement in order to store the item.
+                */
+
+               if (i == seed_1)
+               {
+                       *left++ = i;
+                       v->spl_nleft++;
+                       continue;
+               }
+               else if (i == seed_2)
+               {
+                       *right++ = i;
+                       v->spl_nright++;
+                       continue;
+               }
+
+               /* okay, which page needs least enlargement? */
+               datum_alpha = (NDBOX *) (((GISTENTRY *) (VARDATA(entryvec)))[i].pred);
+               union_dl = (NDBOX *) cube_union(datum_l, datum_alpha);
+               union_dr = (NDBOX *) cube_union(datum_r, datum_alpha);
+               rt_cube_size((NDBOX *) union_dl, &size_alpha);
+               rt_cube_size((NDBOX *) union_dr, &size_beta);
+
+               /* pick which page to add it to */
+               if (size_alpha - size_l < size_beta - size_r)
+               {
+                       pfree(datum_l);
+                       pfree(union_dr);
+                       datum_l = union_dl;
+                       size_l = size_alpha;
+                       *left++ = i;
+                       v->spl_nleft++;
+               }
+               else
+               {
+                       pfree(datum_r);
+                       pfree(union_dl);
+                       datum_r = union_dr;
+                       size_r = size_alpha;
+                       *right++ = i;
+                       v->spl_nright++;
+               }
        }
-    }
-    *left = *right = FirstOffsetNumber;        /* sentinel value, see dosplit() */
-    
-    v->spl_ldatum = (char *)datum_l;
-    v->spl_rdatum = (char *)datum_r;
+       *left = *right = FirstOffsetNumber; /* sentinel value, see dosplit() */
 
-    return v;
+       v->spl_ldatum = (char *) datum_l;
+       v->spl_rdatum = (char *) datum_r;
+
+       return v;
 }
 
 /*
 ** Equality method
 */
 bool *
-g_cube_same(NDBOX *b1, NDBOX *b2, bool *result)
+g_cube_same(NDBOX * b1, NDBOX * b2, bool *result)
 {
-  if (cube_same(b1, b2))
-    *result = TRUE;
-  else *result = FALSE;
-  /*
-  fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE" ));
-  */
-  return(result);
+       if (cube_same(b1, b2))
+               *result = TRUE;
+       else
+               *result = FALSE;
+
+       /*
+        * fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE" ));
+        */
+       return (result);
 }
 
-/* 
+/*
 ** SUPPORT ROUTINES
 */
-bool 
-g_cube_leaf_consistent(NDBOX *key,
-                    NDBOX *query,
-                    StrategyNumber strategy)
+bool
+g_cube_leaf_consistent(NDBOX * key,
+                                          NDBOX * query,
+                                          StrategyNumber strategy)
 {
-  bool retval;
-
-  /*
-  fprintf(stderr, "leaf_consistent, %d\n", strategy);
-  */
-  switch(strategy) {
-  case RTLeftStrategyNumber:
-    retval = (bool)cube_left(key, query);
-    break;
-  case RTOverLeftStrategyNumber:
-    retval = (bool)cube_over_left(key,query);
-    break;
-  case RTOverlapStrategyNumber:
-    retval = (bool)cube_overlap(key, query);
-    break;
-  case RTOverRightStrategyNumber:
-    retval = (bool)cube_over_right(key, query);
-    break;
-  case RTRightStrategyNumber:
-    retval = (bool)cube_right(key, query);
-    break;
-  case RTSameStrategyNumber:
-    retval = (bool)cube_same(key, query);
-    break;
-  case RTContainsStrategyNumber:
-    retval = (bool)cube_contains(key, query);
-    break;
-  case RTContainedByStrategyNumber:
-    retval = (bool)cube_contained(key,query);
-    break;
-  default:
-    retval = FALSE;
-  }
-  return(retval);
+       bool            retval;
+
+       /*
+        * fprintf(stderr, "leaf_consistent, %d\n", strategy);
+        */
+       switch (strategy)
+       {
+               case RTLeftStrategyNumber:
+                       retval = (bool) cube_left(key, query);
+                       break;
+               case RTOverLeftStrategyNumber:
+                       retval = (bool) cube_over_left(key, query);
+                       break;
+               case RTOverlapStrategyNumber:
+                       retval = (bool) cube_overlap(key, query);
+                       break;
+               case RTOverRightStrategyNumber:
+                       retval = (bool) cube_over_right(key, query);
+                       break;
+               case RTRightStrategyNumber:
+                       retval = (bool) cube_right(key, query);
+                       break;
+               case RTSameStrategyNumber:
+                       retval = (bool) cube_same(key, query);
+                       break;
+               case RTContainsStrategyNumber:
+                       retval = (bool) cube_contains(key, query);
+                       break;
+               case RTContainedByStrategyNumber:
+                       retval = (bool) cube_contained(key, query);
+                       break;
+               default:
+                       retval = FALSE;
+       }
+       return (retval);
 }
 
-bool 
-g_cube_internal_consistent(NDBOX *key,
-                       NDBOX *query,
-                       StrategyNumber strategy)
+bool
+g_cube_internal_consistent(NDBOX * key,
+                                                  NDBOX * query,
+                                                  StrategyNumber strategy)
 {
-  bool retval;
-  
-  /*
-  fprintf(stderr, "internal_consistent, %d\n", strategy);
-  */
-  switch(strategy) {
-  case RTLeftStrategyNumber:
-  case RTOverLeftStrategyNumber:
-    retval = (bool)cube_over_left(key,query);
-    break;
-  case RTOverlapStrategyNumber:
-    retval = (bool)cube_overlap(key, query);
-    break;
-  case RTOverRightStrategyNumber:
-  case RTRightStrategyNumber:
-    retval = (bool)cube_right(key, query);
-    break;
-  case RTSameStrategyNumber:
-  case RTContainsStrategyNumber:
-    retval = (bool)cube_contains(key, query);
-    break;
-  case RTContainedByStrategyNumber:
-    retval = (bool)cube_overlap(key, query);
-    break;
-  default:
-    retval = FALSE;
-    }
-  return(retval);
+       bool            retval;
+
+       /*
+        * fprintf(stderr, "internal_consistent, %d\n", strategy);
+        */
+       switch (strategy)
+       {
+               case RTLeftStrategyNumber:
+               case RTOverLeftStrategyNumber:
+                       retval = (bool) cube_over_left(key, query);
+                       break;
+               case RTOverlapStrategyNumber:
+                       retval = (bool) cube_overlap(key, query);
+                       break;
+               case RTOverRightStrategyNumber:
+               case RTRightStrategyNumber:
+                       retval = (bool) cube_right(key, query);
+                       break;
+               case RTSameStrategyNumber:
+               case RTContainsStrategyNumber:
+                       retval = (bool) cube_contains(key, query);
+                       break;
+               case RTContainedByStrategyNumber:
+                       retval = (bool) cube_overlap(key, query);
+                       break;
+               default:
+                       retval = FALSE;
+       }
+       return (retval);
 }
 
 NDBOX *
-g_cube_binary_union(NDBOX *r1, NDBOX *r2, int *sizep)
+g_cube_binary_union(NDBOX * r1, NDBOX * r2, int *sizep)
 {
-    NDBOX *retval;
+       NDBOX      *retval;
 
-    retval = cube_union(r1, r2);
-    *sizep = retval->size;
+       retval = cube_union(r1, r2);
+       *sizep = retval->size;
 
-    return (retval);
+       return (retval);
 }
 
 
 /* cube_union */
-NDBOX *cube_union(NDBOX *box_a, NDBOX *box_b)
+NDBOX *
+cube_union(NDBOX * box_a, NDBOX * box_b)
 {
-  int i;
-  NDBOX *result;
-  NDBOX *a = swap_corners(box_a);
-  NDBOX *b = swap_corners(box_b);
-
-  if ( a->dim >= b->dim ) {
-    result = palloc(a->size);
-    result->size = a->size;
-    result->dim = a->dim;
-  }
-  else {
-    result = palloc(b->size);
-    result->size = b->size;
-    result->dim = b->dim;
-  }
-
-  /* swap the box pointers if needed */
-  if ( a->dim < b->dim ) {
-    NDBOX * tmp = b; b = a; a = tmp;
-  }
-
-  /* use the potentially smaller of the two boxes (b) to fill in 
-     the result, padding absent dimensions with zeroes*/
-  for ( i = 0; i < b->dim; i++ ) {
-    result->x[i] = b->x[i];
-    result->x[i + a->dim] = b->x[i + b->dim];
-  }
-  for ( i = b->dim; i < a->dim; i++ ) {
-    result->x[i] = 0;
-    result->x[i + a->dim] = 0;
-  }
-    
-  /* compute the union */
-  for ( i = 0; i < a->dim; i++ ) {
-    result->x[i] = min(a->x[i], result->x[i]);
-  }
-  for ( i = a->dim; i < a->dim * 2; i++ ) {
-    result->x[i] = max(a->x[i], result->x[i]);
-  }
-
-  pfree(a);
-  pfree(b);
-
-  return(result);
+       int                     i;
+       NDBOX      *result;
+       NDBOX      *a = swap_corners(box_a);
+       NDBOX      *b = swap_corners(box_b);
+
+       if (a->dim >= b->dim)
+       {
+               result = palloc(a->size);
+               result->size = a->size;
+               result->dim = a->dim;
+       }
+       else
+       {
+               result = palloc(b->size);
+               result->size = b->size;
+               result->dim = b->dim;
+       }
+
+       /* swap the box pointers if needed */
+       if (a->dim < b->dim)
+       {
+               NDBOX      *tmp = b;
+
+               b = a;
+               a = tmp;
+       }
+
+       /*
+        * use the potentially smaller of the two boxes (b) to fill in the
+        * result, padding absent dimensions with zeroes
+        */
+       for (i = 0; i < b->dim; i++)
+       {
+               result->x[i] = b->x[i];
+               result->x[i + a->dim] = b->x[i + b->dim];
+       }
+       for (i = b->dim; i < a->dim; i++)
+       {
+               result->x[i] = 0;
+               result->x[i + a->dim] = 0;
+       }
+
+       /* compute the union */
+       for (i = 0; i < a->dim; i++)
+               result->x[i] = min(a->x[i], result->x[i]);
+       for (i = a->dim; i < a->dim * 2; i++)
+               result->x[i] = max(a->x[i], result->x[i]);
+
+       pfree(a);
+       pfree(b);
+
+       return (result);
 }
 
 /* cube_inter */
-NDBOX *cube_inter(NDBOX *box_a, NDBOX *box_b)
+NDBOX *
+cube_inter(NDBOX * box_a, NDBOX * box_b)
 {
-  int i;
-  NDBOX * result;
-  NDBOX *a = swap_corners(box_a);
-  NDBOX *b = swap_corners(box_b);
-  
-  if ( a->dim >= b->dim ) {
-    result = palloc(a->size);
-    result->size = a->size;
-    result->dim = a->dim;
-  }
-  else {
-    result = palloc(b->size);
-    result->size = b->size;
-    result->dim = b->dim;
-  }
-
-  /* swap the box pointers if needed */
-  if ( a->dim < b->dim ) {
-    NDBOX * tmp = b; b = a; a = tmp;
-  }
-
-  /* use the potentially  smaller of the two boxes (b) to fill in 
-     the result, padding absent dimensions with zeroes*/
-  for ( i = 0; i < b->dim; i++ ) {
-    result->x[i] = b->x[i];
-    result->x[i + a->dim] = b->x[i + b->dim];
-  }
-  for ( i = b->dim; i < a->dim; i++ ) {
-    result->x[i] = 0;
-    result->x[i + a->dim] = 0;
-  }
-    
-  /* compute the intersection */
-  for ( i = 0; i < a->dim; i++ ) {
-    result->x[i] = max(a->x[i], result->x[i]);
-  }
-  for ( i = a->dim; i < a->dim * 2; i++ ) {
-    result->x[i] = min(a->x[i], result->x[i]);
-  }
-  
-  pfree(a);
-  pfree(b);
-
-  /* Is it OK to return a non-null intersection for non-overlapping boxes? */
-  return(result);
+       int                     i;
+       NDBOX      *result;
+       NDBOX      *a = swap_corners(box_a);
+       NDBOX      *b = swap_corners(box_b);
+
+       if (a->dim >= b->dim)
+       {
+               result = palloc(a->size);
+               result->size = a->size;
+               result->dim = a->dim;
+       }
+       else
+       {
+               result = palloc(b->size);
+               result->size = b->size;
+               result->dim = b->dim;
+       }
+
+       /* swap the box pointers if needed */
+       if (a->dim < b->dim)
+       {
+               NDBOX      *tmp = b;
+
+               b = a;
+               a = tmp;
+       }
+
+       /*
+        * use the potentially  smaller of the two boxes (b) to fill in the
+        * result, padding absent dimensions with zeroes
+        */
+       for (i = 0; i < b->dim; i++)
+       {
+               result->x[i] = b->x[i];
+               result->x[i + a->dim] = b->x[i + b->dim];
+       }
+       for (i = b->dim; i < a->dim; i++)
+       {
+               result->x[i] = 0;
+               result->x[i + a->dim] = 0;
+       }
+
+       /* compute the intersection */
+       for (i = 0; i < a->dim; i++)
+               result->x[i] = max(a->x[i], result->x[i]);
+       for (i = a->dim; i < a->dim * 2; i++)
+               result->x[i] = min(a->x[i], result->x[i]);
+
+       pfree(a);
+       pfree(b);
+
+       /*
+        * Is it OK to return a non-null intersection for non-overlapping
+        * boxes?
+        */
+       return (result);
 }
 
 /* cube_size */
-float *cube_size(NDBOX *a)
+float *
+cube_size(NDBOX * a)
 {
-  int i,j;
-  float *result;
-
-  result = (float *) palloc(sizeof(float));
-  
-  *result = 1.0;
-  for ( i = 0, j = a->dim; i < a->dim; i++,j++ ) {
-    *result=(*result)*abs((a->x[j] - a->x[i]));
-  }
-  
-  return(result);
+       int                     i,
+                               j;
+       float      *result;
+
+       result = (float *) palloc(sizeof(float));
+
+       *result = 1.0;
+       for (i = 0, j = a->dim; i < a->dim; i++, j++)
+               *result = (*result) * abs((a->x[j] - a->x[i]));
+
+       return (result);
 }
 
 void
-rt_cube_size(NDBOX *a, float *size)
+rt_cube_size(NDBOX * a, float *size)
 {
-  int i,j;
-  if (a == (NDBOX *) NULL)
-    *size = 0.0;
-  else {
-    *size = 1.0;
-    for ( i = 0, j = a->dim; i < a->dim; i++,j++ ) {
-      *size=(*size)*abs((a->x[j] - a->x[i]));
-    }
-  }
-  return;
+       int                     i,
+                               j;
+
+       if (a == (NDBOX *) NULL)
+               *size = 0.0;
+       else
+       {
+               *size = 1.0;
+               for (i = 0, j = a->dim; i < a->dim; i++, j++)
+                       *size = (*size) * abs((a->x[j] - a->x[i]));
+       }
+       return;
 }
 
 /* The following four methods compare the projections of the boxes
@@ -631,428 +692,489 @@ rt_cube_size(NDBOX *a, float *size)
    larger than 2, but it seems that R-tree requires all its strategies
    map to real functions that return something */
 
-/*  is the right edge of (a) located to the left of 
-    the right edge of (b)? */
-bool cube_over_left(NDBOX *box_a, NDBOX *box_b)
+/*     is the right edge of (a) located to the left of
+       the right edge of (b)? */
+bool
+cube_over_left(NDBOX * box_a, NDBOX * box_b)
 {
-  NDBOX *a;
-  NDBOX *b;
-  
-  if ( (box_a==NULL) || (box_b==NULL) )
-    return(FALSE);
+       NDBOX      *a;
+       NDBOX      *b;
+
+       if ((box_a == NULL) || (box_b == NULL))
+               return (FALSE);
 
-  a = swap_corners(box_a);
-  b = swap_corners(box_b);
+       a = swap_corners(box_a);
+       b = swap_corners(box_b);
 
-  return( a->x[a->dim - 1] <= b->x[b->dim - 1] && !cube_left(a, b) && !cube_right(a, b) );
+       return (a->x[a->dim - 1] <= b->x[b->dim - 1] && !cube_left(a, b) && !cube_right(a, b));
 }
 
-/*  is the left edge of (a) located to the right of 
-    the left edge of (b)? */
-bool cube_over_right(NDBOX *box_a, NDBOX *box_b)
+/*     is the left edge of (a) located to the right of
+       the left edge of (b)? */
+bool
+cube_over_right(NDBOX * box_a, NDBOX * box_b)
 {
-  NDBOX *a;
-  NDBOX *b;
-  
-  if ( (box_a==NULL) || (box_b==NULL) )
-    return(FALSE);
+       NDBOX      *a;
+       NDBOX      *b;
 
-  a = swap_corners(box_a);
-  b = swap_corners(box_b);
+       if ((box_a == NULL) || (box_b == NULL))
+               return (FALSE);
 
-  return( a->x[a->dim - 1] >= b->x[b->dim - 1] && !cube_left(a, b) && !cube_right(a, b) );
+       a = swap_corners(box_a);
+       b = swap_corners(box_b);
+
+       return (a->x[a->dim - 1] >= b->x[b->dim - 1] && !cube_left(a, b) && !cube_right(a, b));
 }
 
 
 /* return 'true' if the projection of 'a' is
    entirely on the left of the projection of 'b' */
-bool cube_left(NDBOX *box_a, NDBOX *box_b)
+bool
+cube_left(NDBOX * box_a, NDBOX * box_b)
 {
-  NDBOX *a;
-  NDBOX *b;
-  
-  if ( (box_a==NULL) || (box_b==NULL) )
-    return(FALSE);
+       NDBOX      *a;
+       NDBOX      *b;
+
+       if ((box_a == NULL) || (box_b == NULL))
+               return (FALSE);
 
-  a = swap_corners(box_a);
-  b = swap_corners(box_b);
+       a = swap_corners(box_a);
+       b = swap_corners(box_b);
 
-  return( a->x[a->dim - 1] < b->x[0]);
+       return (a->x[a->dim - 1] < b->x[0]);
 }
 
 /* return 'true' if the projection of 'a' is
    entirely on the right  of the projection of 'b' */
-bool cube_right(NDBOX *box_a, NDBOX *box_b)
+bool
+cube_right(NDBOX * box_a, NDBOX * box_b)
 {
-  NDBOX *a;
-  NDBOX *b;
-  
-  if ( (box_a==NULL) || (box_b==NULL) )
-    return(FALSE);
+       NDBOX      *a;
+       NDBOX      *b;
 
-  a = swap_corners(box_a);
-  b = swap_corners(box_b);
+       if ((box_a == NULL) || (box_b == NULL))
+               return (FALSE);
 
-  return( a->x[0] > b->x[b->dim - 1]);
+       a = swap_corners(box_a);
+       b = swap_corners(box_b);
+
+       return (a->x[0] > b->x[b->dim - 1]);
 }
 
 /* make up a metric in which one box will be 'lower' than the other
    -- this can be useful for srting and to determine uniqueness */
-bool cube_lt(NDBOX *box_a, NDBOX *box_b)
+bool
+cube_lt(NDBOX * box_a, NDBOX * box_b)
 {
-  int i;
-  int dim;
-  NDBOX *a;
-  NDBOX *b;
-  
-  if ( (box_a==NULL) || (box_b==NULL) )
-    return(FALSE);
-
-  a = swap_corners(box_a);
-  b = swap_corners(box_b);
-  dim = min(a->dim, b->dim);
-
-  /* if all common dimensions are equal, the cube with more dimensions wins */
-  if ( cube_same(a, b) ) {
-    if (a->dim < b->dim) {
-      return(TRUE);
-    }
-    else {
-      return(FALSE);
-    }
-  }
-
-  /* compare the common dimensions */
-  for ( i = 0; i < dim; i++ ) {
-    if ( a->x[i] > b->x[i] )
-      return(FALSE); 
-    if ( a->x[i] < b->x[i] )
-      return(TRUE); 
-  }
-  for ( i = 0; i < dim; i++ ) {
-    if ( a->x[i + a->dim] > b->x[i + b->dim] )
-      return(FALSE); 
-    if ( a->x[i + a->dim] < b->x[i + b->dim] )
-      return(TRUE); 
-  }
-
-  /* compare extra dimensions to zero */
-  if ( a->dim > b->dim ) {
-    for ( i = dim; i < a->dim; i++ ) {
-      if ( a->x[i] > 0 )
-       return(FALSE); 
-      if ( a->x[i] < 0 )
-       return(TRUE); 
-    }
-    for ( i = 0; i < dim; i++ ) {
-      if ( a->x[i + a->dim] > 0 )
-       return(FALSE); 
-      if ( a->x[i + a->dim] < 0 )
-       return(TRUE); 
-    }
-  }
-  if ( a->dim < b->dim ) {
-    for ( i = dim; i < b->dim; i++ ) {
-      if ( b->x[i] > 0 )
-       return(TRUE); 
-      if ( b->x[i] < 0 )
-       return(FALSE); 
-    }
-    for ( i = 0; i < dim; i++ ) {
-      if ( b->x[i + b->dim] > 0 )
-       return(TRUE); 
-      if ( b->x[i + b->dim] < 0 )
-       return(FALSE);
-    }
-  }
-    
-  return(FALSE);
+       int                     i;
+       int                     dim;
+       NDBOX      *a;
+       NDBOX      *b;
+
+       if ((box_a == NULL) || (box_b == NULL))
+               return (FALSE);
+
+       a = swap_corners(box_a);
+       b = swap_corners(box_b);
+       dim = min(a->dim, b->dim);
+
+       /*
+        * if all common dimensions are equal, the cube with more dimensions
+        * wins
+        */
+       if (cube_same(a, b))
+       {
+               if (a->dim < b->dim)
+                       return (TRUE);
+               else
+                       return (FALSE);
+       }
+
+       /* compare the common dimensions */
+       for (i = 0; i < dim; i++)
+       {
+               if (a->x[i] > b->x[i])
+                       return (FALSE);
+               if (a->x[i] < b->x[i])
+                       return (TRUE);
+       }
+       for (i = 0; i < dim; i++)
+       {
+               if (a->x[i + a->dim] > b->x[i + b->dim])
+                       return (FALSE);
+               if (a->x[i + a->dim] < b->x[i + b->dim])
+                       return (TRUE);
+       }
+
+       /* compare extra dimensions to zero */
+       if (a->dim > b->dim)
+       {
+               for (i = dim; i < a->dim; i++)
+               {
+                       if (a->x[i] > 0)
+                               return (FALSE);
+                       if (a->x[i] < 0)
+                               return (TRUE);
+               }
+               for (i = 0; i < dim; i++)
+               {
+                       if (a->x[i + a->dim] > 0)
+                               return (FALSE);
+                       if (a->x[i + a->dim] < 0)
+                               return (TRUE);
+               }
+       }
+       if (a->dim < b->dim)
+       {
+               for (i = dim; i < b->dim; i++)
+               {
+                       if (b->x[i] > 0)
+                               return (TRUE);
+                       if (b->x[i] < 0)
+                               return (FALSE);
+               }
+               for (i = 0; i < dim; i++)
+               {
+                       if (b->x[i + b->dim] > 0)
+                               return (TRUE);
+                       if (b->x[i + b->dim] < 0)
+                               return (FALSE);
+               }
+       }
+
+       return (FALSE);
 }
 
 
-bool cube_gt(NDBOX *box_a, NDBOX *box_b)
+bool
+cube_gt(NDBOX * box_a, NDBOX * box_b)
 {
-  int i;
-  int dim;
-  NDBOX *a;
-  NDBOX *b;
-  
-  if ( (box_a==NULL) || (box_b==NULL) )
-    return(FALSE);
-
-  a = swap_corners(box_a);
-  b = swap_corners(box_b);
-  dim = min(a->dim, b->dim);
-
-  /* if all common dimensions are equal, the cube with more dimensions wins */
-  if ( cube_same(a, b) ) {
-    if (a->dim > b->dim) {
-      return(TRUE);
-    }
-    else {
-      return(FALSE);
-    }
-  }
-
-  /* compare the common dimensions */
-  for ( i = 0; i < dim; i++ ) {
-    if ( a->x[i] < b->x[i] )
-      return(FALSE); 
-    if ( a->x[i] > b->x[i] )
-      return(TRUE); 
-  }
-  for ( i = 0; i < dim; i++ ) {
-    if ( a->x[i + a->dim] < b->x[i + b->dim] )
-      return(FALSE); 
-    if ( a->x[i + a->dim] > b->x[i + b->dim] )
-      return(TRUE); 
-  }
-
-
-  /* compare extra dimensions to zero */
-  if ( a->dim > b->dim ) {
-    for ( i = dim; i < a->dim; i++ ) {
-      if ( a->x[i] < 0 )
-       return(FALSE); 
-      if ( a->x[i] > 0 )
-       return(TRUE); 
-    }
-    for ( i = 0; i < dim; i++ ) {
-      if ( a->x[i + a->dim] < 0 )
-       return(FALSE); 
-      if ( a->x[i + a->dim] > 0 )
-       return(TRUE); 
-    }
-  }
-  if ( a->dim < b->dim ) {
-    for ( i = dim; i < b->dim; i++ ) {
-      if ( b->x[i] < 0 )
-       return(TRUE); 
-      if ( b->x[i] > 0 )
-       return(FALSE); 
-    }
-    for ( i = 0; i < dim; i++ ) {
-      if ( b->x[i + b->dim] < 0 )
-       return(TRUE); 
-      if ( b->x[i + b->dim] > 0 )
-       return(FALSE);
-    }
-  }
-
-  return(FALSE);
+       int                     i;
+       int                     dim;
+       NDBOX      *a;
+       NDBOX      *b;
+
+       if ((box_a == NULL) || (box_b == NULL))
+               return (FALSE);
+
+       a = swap_corners(box_a);
+       b = swap_corners(box_b);
+       dim = min(a->dim, b->dim);
+
+       /*
+        * if all common dimensions are equal, the cube with more dimensions
+        * wins
+        */
+       if (cube_same(a, b))
+       {
+               if (a->dim > b->dim)
+                       return (TRUE);
+               else
+                       return (FALSE);
+       }
+
+       /* compare the common dimensions */
+       for (i = 0; i < dim; i++)
+       {
+               if (a->x[i] < b->x[i])
+                       return (FALSE);
+               if (a->x[i] > b->x[i])
+                       return (TRUE);
+       }
+       for (i = 0; i < dim; i++)
+       {
+               if (a->x[i + a->dim] < b->x[i + b->dim])
+                       return (FALSE);
+               if (a->x[i + a->dim] > b->x[i + b->dim])
+                       return (TRUE);
+       }
+
+
+       /* compare extra dimensions to zero */
+       if (a->dim > b->dim)
+       {
+               for (i = dim; i < a->dim; i++)
+               {
+                       if (a->x[i] < 0)
+                               return (FALSE);
+                       if (a->x[i] > 0)
+                               return (TRUE);
+               }
+               for (i = 0; i < dim; i++)
+               {
+                       if (a->x[i + a->dim] < 0)
+                               return (FALSE);
+                       if (a->x[i + a->dim] > 0)
+                               return (TRUE);
+               }
+       }
+       if (a->dim < b->dim)
+       {
+               for (i = dim; i < b->dim; i++)
+               {
+                       if (b->x[i] < 0)
+                               return (TRUE);
+                       if (b->x[i] > 0)
+                               return (FALSE);
+               }
+               for (i = 0; i < dim; i++)
+               {
+                       if (b->x[i + b->dim] < 0)
+                               return (TRUE);
+                       if (b->x[i + b->dim] > 0)
+                               return (FALSE);
+               }
+       }
+
+       return (FALSE);
 }
 
 
 /* Equal */
-bool cube_same(NDBOX *box_a, NDBOX *box_b)
+bool
+cube_same(NDBOX * box_a, NDBOX * box_b)
 {
-  int i;
-  NDBOX *a;
-  NDBOX *b;
-  
-  if ( (box_a==NULL) || (box_b==NULL) )
-    return(FALSE);
-
-  a = swap_corners(box_a);
-  b = swap_corners(box_b);
-
-  /* swap the box pointers if necessary */
-  if ( a->dim < b->dim ) {
-    NDBOX * tmp = b; b = a; a = tmp;
-  }
-
-  for ( i = 0; i < b->dim; i++ ) {
-    if ( a->x[i] != b->x[i] )
-      return(FALSE);
-    if ( a->x[i + a->dim] != b->x[i + b->dim] )
-      return(FALSE);
-  }
-
-  /* all dimensions of (b) are compared to those of (a);
-     instead of those in (a) absent in (b), compare (a) to zero */
-  for ( i = b->dim; i < a->dim; i++ ) {
-     if ( a->x[i] != 0 )
-      return(FALSE);
-     if ( a->x[i + a->dim] != 0 )
-      return(FALSE);
-  }
-
-  pfree(a);
-  pfree(b);
-
-  return(TRUE);
+       int                     i;
+       NDBOX      *a;
+       NDBOX      *b;
+
+       if ((box_a == NULL) || (box_b == NULL))
+               return (FALSE);
+
+       a = swap_corners(box_a);
+       b = swap_corners(box_b);
+
+       /* swap the box pointers if necessary */
+       if (a->dim < b->dim)
+       {
+               NDBOX      *tmp = b;
+
+               b = a;
+               a = tmp;
+       }
+
+       for (i = 0; i < b->dim; i++)
+       {
+               if (a->x[i] != b->x[i])
+                       return (FALSE);
+               if (a->x[i + a->dim] != b->x[i + b->dim])
+                       return (FALSE);
+       }
+
+       /*
+        * all dimensions of (b) are compared to those of (a); instead of
+        * those in (a) absent in (b), compare (a) to zero
+        */
+       for (i = b->dim; i < a->dim; i++)
+       {
+               if (a->x[i] != 0)
+                       return (FALSE);
+               if (a->x[i + a->dim] != 0)
+                       return (FALSE);
+       }
+
+       pfree(a);
+       pfree(b);
+
+       return (TRUE);
 }
 
 /* Different */
-bool cube_different(NDBOX *box_a, NDBOX *box_b)
+bool
+cube_different(NDBOX * box_a, NDBOX * box_b)
 {
-  return(!cube_same(box_a, box_b));
+       return (!cube_same(box_a, box_b));
 }
 
 
 /* Contains */
 /* Box(A) CONTAINS Box(B) IFF pt(A) < pt(B) */
-bool cube_contains(NDBOX *box_a, NDBOX *box_b)
+bool
+cube_contains(NDBOX * box_a, NDBOX * box_b)
 {
-  int i;
-  NDBOX *a;
-  NDBOX *b;
-
-  if ( (box_a==NULL) || (box_b==NULL) )
-    return(FALSE);
-
-  a = swap_corners(box_a);
-  b = swap_corners(box_b);
-
-  if ( a->dim < b->dim ) {
-    /* the further comparisons will make sense if the 
-       excess dimensions of (b) were zeroes */
-    for ( i = a->dim; i < b->dim; i++ ) {
-      if ( b->x[i] != 0 )
-       return(FALSE);
-      if ( b->x[i + b->dim] != 0 )
-       return(FALSE);
-    }
-  }
-
-  /* Can't care less about the excess dimensions of (a), if any */
-  for ( i = 0; i < min(a->dim, b->dim); i++ ) {
-    if ( a->x[i] > b->x[i] )
-      return(FALSE);
-    if ( a->x[i + a->dim] < b->x[i + b->dim] )
-      return(FALSE);
-  }
-
-  pfree(a);
-  pfree(b);
-
-  return(TRUE);
+       int                     i;
+       NDBOX      *a;
+       NDBOX      *b;
+
+       if ((box_a == NULL) || (box_b == NULL))
+               return (FALSE);
+
+       a = swap_corners(box_a);
+       b = swap_corners(box_b);
+
+       if (a->dim < b->dim)
+       {
+
+               /*
+                * the further comparisons will make sense if the excess
+                * dimensions of (b) were zeroes
+                */
+               for (i = a->dim; i < b->dim; i++)
+               {
+                       if (b->x[i] != 0)
+                               return (FALSE);
+                       if (b->x[i + b->dim] != 0)
+                               return (FALSE);
+               }
+       }
+
+       /* Can't care less about the excess dimensions of (a), if any */
+       for (i = 0; i < min(a->dim, b->dim); i++)
+       {
+               if (a->x[i] > b->x[i])
+                       return (FALSE);
+               if (a->x[i + a->dim] < b->x[i + b->dim])
+                       return (FALSE);
+       }
+
+       pfree(a);
+       pfree(b);
+
+       return (TRUE);
 }
 
 /* Contained */
 /* Box(A) Contained by Box(B) IFF Box(B) Contains Box(A) */
-bool cube_contained (NDBOX *a, NDBOX *b)
+bool
+cube_contained(NDBOX * a, NDBOX * b)
 {
-  if (cube_contains(b,a) == TRUE)
-    return(TRUE);
-  else
-    return(FALSE);
+       if (cube_contains(b, a) == TRUE)
+               return (TRUE);
+       else
+               return (FALSE);
 }
 
 /* Overlap */
 /* Box(A) Overlap Box(B) IFF (pt(a)LL < pt(B)UR) && (pt(b)LL < pt(a)UR) */
-bool cube_overlap(NDBOX *box_a, NDBOX *box_b)
+bool
+cube_overlap(NDBOX * box_a, NDBOX * box_b)
 {
-  int i;
-  NDBOX *a;
-  NDBOX *b;
-
-  /* This *very bad* error was found in the source: 
-       if ( (a==NULL) || (b=NULL) )
-               return(FALSE);
-  */
-  if ( (box_a==NULL) || (box_b==NULL) )
-    return(FALSE);
-
-  a = swap_corners(box_a);
-  b = swap_corners(box_b);
-
-  /* swap the box pointers if needed */
-  if ( a->dim < b->dim ) {
-    NDBOX * tmp = b; b = a; a = tmp;
-  }
-
-  /* compare within the dimensions of (b) */
-  for ( i = 0; i < b->dim; i++ ) {
-    if ( a->x[i] > b->x[i + b->dim] )
-      return(FALSE);
-    if ( a->x[i + a->dim] < b->x[i] )
-      return(FALSE);
-  }
-
-  /* compare to zero those dimensions in (a) absent in (b) */
-  for ( i = b->dim; i < a->dim; i++ ) {
-     if ( a->x[i] > 0 )
-      return(FALSE);
-     if ( a->x[i + a->dim] < 0 )
-      return(FALSE);
-  }
-
-  pfree(a);
-  pfree(b);
-
-  return(TRUE);
+       int                     i;
+       NDBOX      *a;
+       NDBOX      *b;
+
+       /*
+        * This *very bad* error was found in the source: if ( (a==NULL) ||
+        * (b=NULL) ) return(FALSE);
+        */
+       if ((box_a == NULL) || (box_b == NULL))
+               return (FALSE);
+
+       a = swap_corners(box_a);
+       b = swap_corners(box_b);
+
+       /* swap the box pointers if needed */
+       if (a->dim < b->dim)
+       {
+               NDBOX      *tmp = b;
+
+               b = a;
+               a = tmp;
+       }
+
+       /* compare within the dimensions of (b) */
+       for (i = 0; i < b->dim; i++)
+       {
+               if (a->x[i] > b->x[i + b->dim])
+                       return (FALSE);
+               if (a->x[i + a->dim] < b->x[i])
+                       return (FALSE);
+       }
+
+       /* compare to zero those dimensions in (a) absent in (b) */
+       for (i = b->dim; i < a->dim; i++)
+       {
+               if (a->x[i] > 0)
+                       return (FALSE);
+               if (a->x[i + a->dim] < 0)
+                       return (FALSE);
+       }
+
+       pfree(a);
+       pfree(b);
+
+       return (TRUE);
 }
 
 
 /* Distance */
 /* The distance is computed as a per axis sum of the squared distances
-   between 1D projections of the boxes onto Cartesian axes. Assuming zero 
-   distance between overlapping projections, this metric coincides with the 
+   between 1D projections of the boxes onto Cartesian axes. Assuming zero
+   distance between overlapping projections, this metric coincides with the
    "common sense" geometric distance */
-float *cube_distance(NDBOX *a, NDBOX *b)
+float *
+cube_distance(NDBOX * a, NDBOX * b)
 {
-  int i;
-  double d, distance;
-  float *result;
-
-  result = (float *) palloc(sizeof(float));
-  
-  /* swap the box pointers if needed */
-  if ( a->dim < b->dim ) {
-    NDBOX * tmp = b; b = a; a = tmp;
-  }
-
-  distance = 0.0;
-  /* compute within the dimensions of (b) */
-  for ( i = 0; i < b->dim; i++ ) {
-    d = distance_1D(a->x[i], a->x[i + a->dim], b->x[i], b->x[i + b->dim]);
-    distance += d*d;
-  }
-
-  /* compute distance to zero for those dimensions in (a) absent in (b) */
-  for ( i = b->dim; i < a->dim; i++ ) {
-    d = distance_1D(a->x[i], a->x[i + a->dim], 0.0, 0.0);
-    distance += d*d;
-  }
-  
-  *result = (float)sqrt(distance);
-
-  return(result);
+       int                     i;
+       double          d,
+                               distance;
+       float      *result;
+
+       result = (float *) palloc(sizeof(float));
+
+       /* swap the box pointers if needed */
+       if (a->dim < b->dim)
+       {
+               NDBOX      *tmp = b;
+
+               b = a;
+               a = tmp;
+       }
+
+       distance = 0.0;
+       /* compute within the dimensions of (b) */
+       for (i = 0; i < b->dim; i++)
+       {
+               d = distance_1D(a->x[i], a->x[i + a->dim], b->x[i], b->x[i + b->dim]);
+               distance += d * d;
+       }
+
+       /* compute distance to zero for those dimensions in (a) absent in (b) */
+       for (i = b->dim; i < a->dim; i++)
+       {
+               d = distance_1D(a->x[i], a->x[i + a->dim], 0.0, 0.0);
+               distance += d * d;
+       }
+
+       *result = (float) sqrt(distance);
+
+       return (result);
 }
 
-static float distance_1D(float a1, float a2, float b1, float b2)
+static float
+distance_1D(float a1, float a2, float b1, float b2)
 {
-  /* interval (a) is entirely on the left of (b) */
-  if( (a1 <= b1) && (a2 <= b1) && (a1 <= b2) && (a2 <= b2) ) {
-    return ( min( b1, b2 ) - max( a1, a2 ) );
-  }
-
-  /* interval (a) is entirely on the right of (b) */
-  if( (a1 > b1) && (a2 > b1) && (a1 > b2) && (a2 > b2) ) {
-    return ( min( a1, a2 ) - max( b1, b2 ) );
-  }
-  
-  /* the rest are all sorts of intersections */
-  return(0.0);
+       /* interval (a) is entirely on the left of (b) */
+       if ((a1 <= b1) && (a2 <= b1) && (a1 <= b2) && (a2 <= b2))
+               return (min(b1, b2) - max(a1, a2));
+
+       /* interval (a) is entirely on the right of (b) */
+       if ((a1 > b1) && (a2 > b1) && (a1 > b2) && (a2 > b2))
+               return (min(a1, a2) - max(b1, b2));
+
+       /* the rest are all sorts of intersections */
+       return (0.0);
 }
 
 /* normalize the box's co-ordinates by placing min(xLL,xUR) to LL
-   and max(xLL,xUR) to UR 
+   and max(xLL,xUR) to UR
 */
-static NDBOX *swap_corners ( NDBOX *a )
+static NDBOX *
+swap_corners(NDBOX * a)
 {
-  int i, j;
-  NDBOX * result;
-  
-  result = palloc(a->size);
-  result->size = a->size;
-  result->dim = a->dim;
-
-  for ( i = 0, j = a->dim; i < a->dim; i++, j++ ) {
-    result->x[i] = min(a->x[i],a->x[j]);
-    result->x[j] = max(a->x[i],a->x[j]);
-  }
-
-  return(result);
+       int                     i,
+                               j;
+       NDBOX      *result;
+
+       result = palloc(a->size);
+       result->size = a->size;
+       result->dim = a->dim;
+
+       for (i = 0, j = a->dim; i < a->dim; i++, j++)
+       {
+               result->x[i] = min(a->x[i], a->x[j]);
+               result->x[j] = max(a->x[i], a->x[j]);
+       }
+
+       return (result);
 }
index 18bb6485464a4f4ee897c410a0098735e3aea6a5..359fab287160596ba34a8ac26e67a92d3c2ddfa3 100644 (file)
@@ -1,5 +1,6 @@
-typedef struct NDBOX {
-  unsigned int size;                   /* required to be a Postgres varlena type */
-  unsigned int dim;
-  float x[1];
-} NDBOX;
+typedef struct NDBOX
+{
+       unsigned int size;                      /* required to be a Postgres varlena type */
+       unsigned int dim;
+       float           x[1];
+}                      NDBOX;
index 2383256be9b816662580bff03876dce81bd978cf..c1962272f4fb64775e21a858d40f43d9f6dbee02 100644 (file)
@@ -9,7 +9,7 @@
 const int      EARTH_RADIUS = 3958.747716;
 const int      TWO_PI = 2.0 * M_PI;
 
-double *geo_distance(Point *pt1, Point *pt2);
+double    *geo_distance(Point *pt1, Point *pt2);
 
 
 /******************************************************
index 7d76bf719fcd84b1fc9f955f579a7d12cb4a75ba..8aabe58672c2290feef15003312aa1264da2d9eb 100644 (file)
@@ -20,7 +20,7 @@ main(int argc, char **argv)
        char            attname[256];
        char            typname[256];
        int                     count;
-       char        optstr[256];
+       char            optstr[256];
 
        if (argc != 2)
                halt("Usage:  %s database\n", argv[0]);
index 1f9c398fea5ca2b2aeba035d8182f1d5b51fd557..a797505e7016dbb56b36d90fc99fe769568bdf82 100644 (file)
@@ -62,11 +62,11 @@ select p.* from product p, title_fti f1, title_fti f2 where
    that can build the final query automatigally?
    */
 
-extern Datum   fti(PG_FUNCTION_ARGS);
-static char       *breakup(char *, char *);
-static bool            is_stopword(char *);
+extern Datum fti(PG_FUNCTION_ARGS);
+static char *breakup(char *, char *);
+static bool is_stopword(char *);
 
-static bool            new_tuple = false;
+static bool new_tuple = false;
 
 
 /* THIS LIST MUST BE IN SORTED ORDER, A BINARY SEARCH IS USED!!!! */
index 33fa4cf98dd1d0991406c77d85a64d5bba217d22..1dcdc3585010fb43d8f2d6e889428162f251e56b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     PostgreSQL type definitions for managed LargeObjects.
  *
- *     $Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.7 2001/02/10 02:31:25 tgl Exp $
+ *     $Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.8 2001/03/22 03:59:09 momjian Exp $
  *
  */
 
@@ -36,7 +36,7 @@ Blob     *lo_in(char *str);   /* Create from String           */
 char      *lo_out(Blob * addr);/* Output oid as String         */
 Oid                    lo_oid(Blob * addr);/* Return oid as an oid             */
 Blob      *lo(Oid oid);                /* Return Blob based on oid */
-Datum          lo_manage(PG_FUNCTION_ARGS); /* Trigger handler                 */
+Datum          lo_manage(PG_FUNCTION_ARGS);            /* Trigger handler                 */
 
 /*
  * This creates a large object, and sets its OID to the value in the
@@ -69,7 +69,7 @@ lo_in(char *str)
                 * There is no Oid passed, so create a new one
                 */
                oid = DatumGetObjectId(DirectFunctionCall1(lo_creat,
-                                                          Int32GetDatum(INV_READ | INV_WRITE)));
+                                                                  Int32GetDatum(INV_READ | INV_WRITE)));
                if (oid == InvalidOid)
                        elog(ERROR, "lo_in: InvalidOid returned from lo_creat");
        }
index 1eaa73335c08d17552008e3672e162e3ed4f3486..a823c5f50b3992b9d3c40f0046b8c9b24d050c14 100644 (file)
@@ -1,6 +1,6 @@
-/* 
+/*
   oid2name; a postgresql 7.1 (+?) app to map OIDs on the filesystem
-   to table and database names.  
+   to table and database names.
 
   b. palmer, [email protected] 1-17-2001
 
 #include "libpq-fe.h"
 
 /* these are the opts structures for command line params */
-struct options {
-  int getdatabase;
-  int gettable;
-  int getoid;
-  
-  int systables;
-
-  int remotehost;
-  int remoteport;
-  int remoteuser;
-  int remotepass;
-
-  int _oid;
-  char _dbname[128];
-  char _tbname[128];
-
-  char _hostname[128];
-  char _port[6];
-  char _username[128];
-  char _password[128];
+struct options
+{
+       int                     getdatabase;
+       int                     gettable;
+       int                     getoid;
+
+       int                     systables;
+
+       int                     remotehost;
+       int                     remoteport;
+       int                     remoteuser;
+       int                     remotepass;
+
+       int                     _oid;
+       char            _dbname[128];
+       char            _tbname[128];
+
+       char            _hostname[128];
+       char            _port[6];
+       char            _username[128];
+       char            _password[128];
 };
 
 /* function prototypes */
-void get_opts(int, char **, struct options *);
-PGconn *sql_conn(char *, struct options *);
-void sql_exec_error (int);
-int sql_exec(PGconn *, char *, int);
-void sql_exec_dumpdb(PGconn *);
-void sql_exec_dumptable(PGconn *, int);
-void sql_exec_searchtable(PGconn *, char *);
-void sql_exec_searchoid(PGconn *, int);
+void           get_opts(int, char **, struct options *);
+PGconn    *sql_conn(char *, struct options *);
+void           sql_exec_error(int);
+int                    sql_exec(PGconn *, char *, int);
+void           sql_exec_dumpdb(PGconn *);
+void           sql_exec_dumptable(PGconn *, int);
+void           sql_exec_searchtable(PGconn *, char *);
+void           sql_exec_searchoid(PGconn *, int);
 
 /* fuction to parse command line options and check for some usage errors. */
-void get_opts(int argc, char **argv, struct options *my_opts)
+void
+get_opts(int argc, char **argv, struct options * my_opts)
 {
-  char c;
+       char            c;
 
-  /* set the defaults */
-  my_opts->getdatabase = 0;
-  my_opts->gettable = 0;
-  my_opts->getoid = 0;
+       /* set the defaults */
+       my_opts->getdatabase = 0;
+       my_opts->gettable = 0;
+       my_opts->getoid = 0;
 
-  my_opts->systables = 0;
+       my_opts->systables = 0;
 
-  my_opts->remotehost = 0;
-  my_opts->remoteport = 0;
-  my_opts->remoteuser = 0;
-  my_opts->remotepass = 0;
+       my_opts->remotehost = 0;
+       my_opts->remoteport = 0;
+       my_opts->remoteuser = 0;
+       my_opts->remotepass = 0;
 
-  /* get opts */
-  while( (c = getopt(argc, argv, "H:p:U:P:d:t:o:xh?")) != EOF)
-    {
-      switch(c)
+       /* get opts */
+       while ((c = getopt(argc, argv, "H:p:U:P:d:t:o:xh?")) != EOF)
        {
-         /* specify the database */
-       case 'd':
-         my_opts->getdatabase = 1;
-         sscanf(optarg, "%s", my_opts->_dbname);
-         break;
-
-         /* specify the table name */
-       case 't':
-         /* make sure we set the database first */
-         if(!my_opts->getdatabase)
-           {
-             fprintf(stderr, "Sorry,  but you must specify a database to dump from.\n");
-             exit(1);
-           }
-         /* make sure we don't try to do a -o also */
-         if(my_opts->getoid)
-           {
-             fprintf(stderr, "Sorry, you can only specify either oid or table\n");
-             exit(1);
-           }
-
-         my_opts->gettable = 1;
-         sscanf(optarg, "%s", my_opts->_tbname);
-
-         break;
-
-         /* specify the oid int */
-       case 'o':
-         /* make sure we set the database first */
-         if(!my_opts->getdatabase)
-           {
-             fprintf(stderr, "Sorry,  but you must specify a database to dump from.\n");
-             exit(1);
-           }
-         /* make sure we don't try to do a -t also */
-         if(my_opts->gettable)
-           {
-             fprintf(stderr, "Sorry, you can only specify either oid or table\n");
-             exit(1);
-           }
-
-         my_opts->getoid = 1;
-         sscanf(optarg, "%i", &my_opts->_oid);
-
-         break;
-
-         /* host to connect to */
-       case 'H':
-         my_opts->remotehost = 1;
-         sscanf(optarg, "%s", my_opts->_hostname);
-         break;
-
-         /* port to connect to on remote host */
-       case 'p':
-         my_opts->remoteport = 1;
-         sscanf(optarg, "%s", my_opts->_port);
-         break;
-
-         /* username */
-       case 'U':
-         my_opts->remoteuser = 1;
-         sscanf(optarg, "%s", my_opts->_username);
-         break;
-
-         /* password */
-       case 'P':
-         my_opts->remotepass = 1;
-         sscanf(optarg, "%s", my_opts->_password);
-         break;
-
-         /* display system tables */
-       case 'x':
-
-         my_opts->systables = 1;
-         break;
-
-         /* help! (ugly in code for easier editing) */
-       case '?':
-       case 'h':
-         fprintf(stderr, "\n\
+               switch (c)
+               {
+                               /* specify the database */
+                       case 'd':
+                               my_opts->getdatabase = 1;
+                               sscanf(optarg, "%s", my_opts->_dbname);
+                               break;
+
+                               /* specify the table name */
+                       case 't':
+                               /* make sure we set the database first */
+                               if (!my_opts->getdatabase)
+                               {
+                                       fprintf(stderr, "Sorry,  but you must specify a database to dump from.\n");
+                                       exit(1);
+                               }
+                               /* make sure we don't try to do a -o also */
+                               if (my_opts->getoid)
+                               {
+                                       fprintf(stderr, "Sorry, you can only specify either oid or table\n");
+                                       exit(1);
+                               }
+
+                               my_opts->gettable = 1;
+                               sscanf(optarg, "%s", my_opts->_tbname);
+
+                               break;
+
+                               /* specify the oid int */
+                       case 'o':
+                               /* make sure we set the database first */
+                               if (!my_opts->getdatabase)
+                               {
+                                       fprintf(stderr, "Sorry,  but you must specify a database to dump from.\n");
+                                       exit(1);
+                               }
+                               /* make sure we don't try to do a -t also */
+                               if (my_opts->gettable)
+                               {
+                                       fprintf(stderr, "Sorry, you can only specify either oid or table\n");
+                                       exit(1);
+                               }
+
+                               my_opts->getoid = 1;
+                               sscanf(optarg, "%i", &my_opts->_oid);
+
+                               break;
+
+                               /* host to connect to */
+                       case 'H':
+                               my_opts->remotehost = 1;
+                               sscanf(optarg, "%s", my_opts->_hostname);
+                               break;
+
+                               /* port to connect to on remote host */
+                       case 'p':
+                               my_opts->remoteport = 1;
+                               sscanf(optarg, "%s", my_opts->_port);
+                               break;
+
+                               /* username */
+                       case 'U':
+                               my_opts->remoteuser = 1;
+                               sscanf(optarg, "%s", my_opts->_username);
+                               break;
+
+                               /* password */
+                       case 'P':
+                               my_opts->remotepass = 1;
+                               sscanf(optarg, "%s", my_opts->_password);
+                               break;
+
+                               /* display system tables */
+                       case 'x':
+
+                               my_opts->systables = 1;
+                               break;
+
+                               /* help! (ugly in code for easier editing) */
+                       case '?':
+                       case 'h':
+                               fprintf(stderr, "\n\
 Usage: pg_oid2name [-d database [-x] ] [-t table | -o oid] \n\
-        dafault action        display all databases
+        dafault action        display all databases\n\
         -d database           database to oid2name\n\
         -x                    display system tables\n\
         -t table | -o oid     search for table name (-t) or\n\
-                               oid (-o) in -d database
+                               oid (-o) in -d database\n\
         -H host               connect to remote host\n\
         -p port               host port to connect to\n\
         -U username           username to connect with\n\
         -P password           password for username\n\n\
 ");
-         exit(1);
-         break;
+                               exit(1);
+                               break;
+               }
        }
-    }
 }
 
 /* establish connection with database. */
-PGconn *sql_conn(char *dbName, struct options *my_opts)
+PGconn *
+sql_conn(char *dbName, struct options * my_opts)
 {
-  char *pghost, *pgport;
-  char *pgoptions, *pgtty;
-  char *pguser, *pgpass;
-
-  PGconn *conn;
-
-  pghost = NULL;
-  pgport = NULL;
-  
-  pgoptions = NULL;           /* special options to start up the backend
-                                 * server */
-  pgtty = NULL;               /* debugging tty for the backend server */
-
-  pguser = NULL;
-  pgpass = NULL;
-
-  /* override the NULLs with the user params if passed */
-  if(my_opts->remotehost)
-    {
-      pghost = (char *) malloc (128);
-      sscanf(my_opts->_hostname, "%s", pghost);
-    }
-    
-  if(my_opts->remoteport)
-    {
-      pgport = (char *) malloc (6);
-      sscanf(my_opts->_port, "%s", pgport);
-    }
-
-  if(my_opts->remoteuser)
-    {
-      pguser = (char *) malloc (128);
-      sscanf(my_opts->_username, "%s", pguser);
-    }
-
-  if(my_opts->remotepass)
-    {
-      pgpass = (char *) malloc (128);
-      sscanf(my_opts->_password, "%s", pgpass);
-    }
-
-  /* login */
-  conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, pguser, pgpass);
-
-  /* deal with errors */
-  if (PQstatus(conn) == CONNECTION_BAD)
-    {
-      fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
-      fprintf(stderr, "%s", PQerrorMessage(conn));
-      
-      
-      PQfinish(conn);
-      exit(1);
-
-    }
-
-  /* return the conn if good */
-  return conn;
+       char       *pghost,
+                          *pgport;
+       char       *pgoptions,
+                          *pgtty;
+       char       *pguser,
+                          *pgpass;
+
+       PGconn     *conn;
+
+       pghost = NULL;
+       pgport = NULL;
+
+       pgoptions = NULL;                       /* special options to start up the backend
+                                                                * server */
+       pgtty = NULL;                           /* debugging tty for the backend server */
+
+       pguser = NULL;
+       pgpass = NULL;
+
+       /* override the NULLs with the user params if passed */
+       if (my_opts->remotehost)
+       {
+               pghost = (char *) malloc(128);
+               sscanf(my_opts->_hostname, "%s", pghost);
+       }
+
+       if (my_opts->remoteport)
+       {
+               pgport = (char *) malloc(6);
+               sscanf(my_opts->_port, "%s", pgport);
+       }
+
+       if (my_opts->remoteuser)
+       {
+               pguser = (char *) malloc(128);
+               sscanf(my_opts->_username, "%s", pguser);
+       }
+
+       if (my_opts->remotepass)
+       {
+               pgpass = (char *) malloc(128);
+               sscanf(my_opts->_password, "%s", pgpass);
+       }
+
+       /* login */
+       conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, pguser, pgpass);
+
+       /* deal with errors */
+       if (PQstatus(conn) == CONNECTION_BAD)
+       {
+               fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
+               fprintf(stderr, "%s", PQerrorMessage(conn));
+
+
+               PQfinish(conn);
+               exit(1);
+
+       }
+
+       /* return the conn if good */
+       return conn;
 }
 
 /* If the sql_ command has an error,  this function looks up the error number and prints it out. */
-void sql_exec_error (int error_number)
+void
+sql_exec_error(int error_number)
 {
-  fprintf(stderr, "Error number %i.\n", error_number);
-  switch(error_number)
-    {
-    case 3:
-      fprintf(stderr,  "Error:  PGRES_COPY_OUT\n");
-      break;
-      
-    case 4:
-      fprintf(stderr,  "Error:  PGRES_COPY_IN\n");
-      break;
-      
-    case 5:
-      fprintf(stderr,  "Error:  PGRES_BAD_RESPONCE\n");
-      break;
-      
-    case 6:
-      fprintf(stderr,  "Error:  PGRES_NONFATAL_ERROR\n");
-      break;
-      
-    case 7:
-      fprintf(stderr,  "Error:  PGRES_FATAL_ERROR\n");
-      break;
-    }
+       fprintf(stderr, "Error number %i.\n", error_number);
+       switch (error_number)
+       {
+               case 3:
+                       fprintf(stderr, "Error:  PGRES_COPY_OUT\n");
+                       break;
+
+               case 4:
+                       fprintf(stderr, "Error:  PGRES_COPY_IN\n");
+                       break;
+
+               case 5:
+                       fprintf(stderr, "Error:  PGRES_BAD_RESPONCE\n");
+                       break;
+
+               case 6:
+                       fprintf(stderr, "Error:  PGRES_NONFATAL_ERROR\n");
+                       break;
+
+               case 7:
+                       fprintf(stderr, "Error:  PGRES_FATAL_ERROR\n");
+                       break;
+       }
 }
 
 /* actual code to make call to the database and print the output data */
-int sql_exec(PGconn *conn, char *todo, int match)
+int
+sql_exec(PGconn *conn, char *todo, int match)
 {
-  PGresult *res;
-
-  int numbfields;
-  int error_number;
-  int i, len;
-
-  /* make the call */
-  res = PQexec(conn, todo);
-
-  /* check and deal with errors */
-  if (!res || PQresultStatus(res) > 2)
-    {
-      error_number = PQresultStatus(res);
-      fprintf(stderr, "There was an error in the SQL command:\n%s\n", todo);
-      sql_exec_error(error_number);
-      fprintf(stderr,  "PQerrorMessage = %s\n", PQerrorMessage(conn));
-           
-      PQclear(res);
-      PQfinish(conn);
-      exit(-1);
-    }
-
-  /* get the number of fields */
-  numbfields = PQntuples(res);
-
-  /* if we only expect 1 and there mode than,  return -2 */
-  if(match == 1 && numbfields > 1)
-    return -2;
-
-  /* return -1 if there aren't any returns */
-  if(match == 1 && numbfields < 1)
-    return -1;
-
-  /* for each row,  dump the information */
-  for(i = 0; i < numbfields; i++)
-    {
-      len = strlen(PQgetvalue(res, i, 0));
-
-      fprintf(stdout, "%-6s = %s\n", PQgetvalue(res, i, 0), PQgetvalue(res, i, 1));
-    }
-
-  /* clean the PGconn once done */
-  PQclear(res);
-
-  return 0;
+       PGresult   *res;
+
+       int                     numbfields;
+       int                     error_number;
+       int                     i,
+                               len;
+
+       /* make the call */
+       res = PQexec(conn, todo);
+
+       /* check and deal with errors */
+       if (!res || PQresultStatus(res) > 2)
+       {
+               error_number = PQresultStatus(res);
+               fprintf(stderr, "There was an error in the SQL command:\n%s\n", todo);
+               sql_exec_error(error_number);
+               fprintf(stderr, "PQerrorMessage = %s\n", PQerrorMessage(conn));
+
+               PQclear(res);
+               PQfinish(conn);
+               exit(-1);
+       }
+
+       /* get the number of fields */
+       numbfields = PQntuples(res);
+
+       /* if we only expect 1 and there mode than,  return -2 */
+       if (match == 1 && numbfields > 1)
+               return -2;
+
+       /* return -1 if there aren't any returns */
+       if (match == 1 && numbfields < 1)
+               return -1;
+
+       /* for each row,  dump the information */
+       for (i = 0; i < numbfields; i++)
+       {
+               len = strlen(PQgetvalue(res, i, 0));
+
+               fprintf(stdout, "%-6s = %s\n", PQgetvalue(res, i, 0), PQgetvalue(res, i, 1));
+       }
+
+       /* clean the PGconn once done */
+       PQclear(res);
+
+       return 0;
 }
 
 /* dump all databases know by the system table */
-void sql_exec_dumpdb(PGconn *conn)
+void
+sql_exec_dumpdb(PGconn *conn)
 {
-  char *todo;
+       char       *todo;
 
-  todo = (char *) malloc (1024);
+       todo = (char *) malloc(1024);
 
-  /* get the oid and database name from the system pg_database table */
-  sprintf(todo, "select oid,datname from pg_database");
+       /* get the oid and database name from the system pg_database table */
+       sprintf(todo, "select oid,datname from pg_database");
 
-  sql_exec(conn, todo, 0);
+       sql_exec(conn, todo, 0);
 }
 
 /* display all tables in whatever db we are connected to.  don't display the
    system tables by default */
-void sql_exec_dumptable(PGconn *conn, int systables)
+void
+sql_exec_dumptable(PGconn *conn, int systables)
 {
-  char *todo;
+       char       *todo;
 
-  todo = (char *) malloc (1024);
+       todo = (char *) malloc(1024);
 
-  /* don't exclude the systables if this is set */
-  if(systables == 1)
-    sprintf(todo, "select relfilenode,relname from pg_class order by relname");
-  else
-    sprintf(todo, "select relfilenode,relname from pg_class where relname not like 'pg_%%' order by relname");
+       /* don't exclude the systables if this is set */
+       if (systables == 1)
+               sprintf(todo, "select relfilenode,relname from pg_class order by relname");
+       else
+               sprintf(todo, "select relfilenode,relname from pg_class where relname not like 'pg_%%' order by relname");
 
-  sql_exec(conn, todo, 0);
+       sql_exec(conn, todo, 0);
 }
 
 /* display the oid for a given tablename for whatever db we are connected
-   to.  do we want to allow %bar% in the search?  Not now. */
-void sql_exec_searchtable(PGconn *conn, char *tablename)
+   to. do we want to allow %bar% in the search?  Not now. */
+void
+sql_exec_searchtable(PGconn *conn, char *tablename)
 {
-  int returnvalue;
-  char *todo;
-
-  todo = (char *) malloc (1024);
-
-  /* get the oid and tablename where the name matches tablename */
-  sprintf(todo, "select relfilenode,relname from pg_class where relname = '%s'", tablename);
-
-  returnvalue = sql_exec(conn, todo, 1);
-
-  /* deal with the return errors */
-  if(returnvalue == -1)
-    {
-      printf("No tables with that name found\n");
-    }
-  
-  if(returnvalue == -2)
-    {
-      printf("VERY scary:  more than one table with that name found!!\n");
-    }
+       int                     returnvalue;
+       char       *todo;
+
+       todo = (char *) malloc(1024);
+
+       /* get the oid and tablename where the name matches tablename */
+       sprintf(todo, "select relfilenode,relname from pg_class where relname = '%s'", tablename);
+
+       returnvalue = sql_exec(conn, todo, 1);
+
+       /* deal with the return errors */
+       if (returnvalue == -1)
+               printf("No tables with that name found\n");
+
+       if (returnvalue == -2)
+               printf("VERY scary:  more than one table with that name found!!\n");
 }
 
 /* same as above */
-void sql_exec_searchoid(PGconn *conn, int oid)
+void
+sql_exec_searchoid(PGconn *conn, int oid)
 {
-  int returnvalue;
-  char *todo;
+       int                     returnvalue;
+       char       *todo;
+
+       todo = (char *) malloc(1024);
 
-  todo = (char *) malloc (1024);
+       sprintf(todo, "select relfilenode,relname from pg_class where oid = %i", oid);
 
-  sprintf(todo, "select relfilenode,relname from pg_class where oid = %i", oid);
+       returnvalue = sql_exec(conn, todo, 1);
 
-  returnvalue = sql_exec(conn, todo, 1);
+       if (returnvalue == -1)
+               printf("No tables with that oid found\n");
 
-  if(returnvalue == -1)
-    {
-      printf("No tables with that oid found\n");
-    }
-  
-  if(returnvalue == -2)
-    {
-      printf("VERY scary:  more than one table with that oid found!!\n");
-    }
+       if (returnvalue == -2)
+               printf("VERY scary:  more than one table with that oid found!!\n");
 }
 
-int main(int argc, char **argv)
+int
+main(int argc, char **argv)
 {
-  struct options *my_opts;
-  PGconn *pgconn;
-
-  my_opts = (struct options *) malloc (sizeof(struct options));
-
-  /* parse the opts */
-  get_opts(argc, argv, my_opts);
-
-  /* display all the tables in the database */
-  if(my_opts->getdatabase & my_opts->gettable)
-    {
-      printf("Oid of table %s from database \"%s\":\n", my_opts->_tbname, my_opts->_dbname);
-      printf("_______________________________\n");
-
-      pgconn = sql_conn(my_opts->_dbname, my_opts);
-      sql_exec_searchtable(pgconn, my_opts->_tbname);
-      PQfinish(pgconn);
-
-      exit(1);
-    }
-  
-  /* search for the tablename of the given OID */
-  if(my_opts->getdatabase & my_opts->getoid)
-    {
-      printf("Tablename of oid %i from database \"%s\":\n", my_opts->_oid, my_opts->_dbname);
-      printf("---------------------------------\n");
-
-      pgconn = sql_conn(my_opts->_dbname, my_opts);
-      sql_exec_searchoid(pgconn, my_opts->_oid);
-      PQfinish(pgconn);
-
-      exit(1);
-    }
-
-  /* search for the oid for the given tablename */
-  if(my_opts->getdatabase)
-    {
-      printf("All tables from database \"%s\":\n", my_opts->_dbname);
-      printf("---------------------------------\n");
-
-      pgconn = sql_conn(my_opts->_dbname, my_opts);
-      sql_exec_dumptable(pgconn, my_opts->systables);
-      PQfinish(pgconn);
-
-      exit(1);
-    }
-
-  /* display all the databases for the server we are connected to.. */
-  printf("All databases:\n");
-  printf("---------------------------------\n");  
-  
-  pgconn = sql_conn("template1", my_opts);
-  sql_exec_dumpdb(pgconn);
-  PQfinish(pgconn);
-
-  exit(0);
+       struct options *my_opts;
+       PGconn     *pgconn;
+
+       my_opts = (struct options *) malloc(sizeof(struct options));
+
+       /* parse the opts */
+       get_opts(argc, argv, my_opts);
+
+       /* display all the tables in the database */
+       if (my_opts->getdatabase & my_opts->gettable)
+       {
+               printf("Oid of table %s from database \"%s\":\n", my_opts->_tbname, my_opts->_dbname);
+               printf("_______________________________\n");
+
+               pgconn = sql_conn(my_opts->_dbname, my_opts);
+               sql_exec_searchtable(pgconn, my_opts->_tbname);
+               PQfinish(pgconn);
+
+               exit(1);
+       }
+
+       /* search for the tablename of the given OID */
+       if (my_opts->getdatabase & my_opts->getoid)
+       {
+               printf("Tablename of oid %i from database \"%s\":\n", my_opts->_oid, my_opts->_dbname);
+               printf("---------------------------------\n");
+
+               pgconn = sql_conn(my_opts->_dbname, my_opts);
+               sql_exec_searchoid(pgconn, my_opts->_oid);
+               PQfinish(pgconn);
+
+               exit(1);
+       }
+
+       /* search for the oid for the given tablename */
+       if (my_opts->getdatabase)
+       {
+               printf("All tables from database \"%s\":\n", my_opts->_dbname);
+               printf("---------------------------------\n");
+
+               pgconn = sql_conn(my_opts->_dbname, my_opts);
+               sql_exec_dumptable(pgconn, my_opts->systables);
+               PQfinish(pgconn);
+
+               exit(1);
+       }
+
+       /* display all the databases for the server we are connected to.. */
+       printf("All databases:\n");
+       printf("---------------------------------\n");
+
+       pgconn = sql_conn("template1", my_opts);
+       sql_exec_dumpdb(pgconn);
+       PQfinish(pgconn);
+
+       exit(0);
 }
index dc666c1fcf29d12952e4a8bc95eef6dc79378523..93fe9a54c9b5cd3596d03df329e7996815302543 100644 (file)
@@ -6,7 +6,7 @@
  * copyright (c) Oliver Elphick <[email protected]>, 2001;
  * licence: BSD
  *
- * $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/pg_controldata.c,v 1.2 2001/03/13 01:17:40 tgl Exp $
+ * $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/pg_controldata.c,v 1.3 2001/03/22 03:59:09 momjian Exp $
  */
 #include "postgres.h"
 
@@ -24,7 +24,7 @@ dbState(DBState state)
 {
        switch (state)
        {
-               case DB_STARTUP:
+                       case DB_STARTUP:
                        return "STARTUP";
                case DB_SHUTDOWNED:
                        return "SHUTDOWNED";
@@ -43,16 +43,17 @@ int
 main()
 {
        ControlFileData ControlFile;
-       int fd;
-       char ControlFilePath[MAXPGPATH];
-       char *DataDir;
-       crc64 crc;
-       char pgctime_str[32];
-       char ckpttime_str[32];
+       int                     fd;
+       char            ControlFilePath[MAXPGPATH];
+       char       *DataDir;
+       crc64           crc;
+       char            pgctime_str[32];
+       char            ckpttime_str[32];
 
        DataDir = getenv("PGDATA");
-       if ( DataDir == NULL ) {
-               fprintf(stderr,"PGDATA is not defined\n");
+       if (DataDir == NULL)
+       {
+               fprintf(stderr, "PGDATA is not defined\n");
                exit(1);
        }
 
@@ -73,8 +74,8 @@ main()
 
        /* Check the CRC. */
        INIT_CRC64(crc);
-       COMP_CRC64(crc, 
-                          (char*) &ControlFile + sizeof(crc64),
+       COMP_CRC64(crc,
+                          (char *) &ControlFile + sizeof(crc64),
                           sizeof(ControlFileData) - sizeof(crc64));
        FIN_CRC64(crc);
 
@@ -93,7 +94,7 @@ main()
                   "Database state:                       %s\n"
                   "pg_control last modified:             %s\n"
                   "Current log file id:                  %u\n"
-              "Next log file segment:                %u\n"
+                  "Next log file segment:                %u\n"
                   "Latest checkpoint location:           %X/%X\n"
                   "Prior checkpoint location:            %X/%X\n"
                   "Latest checkpoint's REDO location:    %X/%X\n"
index 5a2a1614a571106709a770540c82fc92505bafba..6a62c88bc6f91e4c48064f9583020fc50bfb3f75 100644 (file)
@@ -1,20 +1,20 @@
 /* -------------------------------------------------------------------------
  * pg_dumplo
  *
- * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.5 2001/01/24 19:42:44 momjian Exp $
+ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_export.c,v 1.6 2001/03/22 03:59:10 momjian Exp $
  *
  *                                     Karel Zak 1999-2000
  * -------------------------------------------------------------------------
  */
 
-#include <stdio.h>     
+#include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
-#include <errno.h>                            
+#include <errno.h>
 #include <time.h>
 
 #include <libpq-fe.h>
 
 #include "pg_dumplo.h"
 
-extern int     errno;        
+extern int     errno;
 
 
-void 
-load_lolist( LODumpMaster *pgLO ) 
+void
+load_lolist(LODumpMaster * pgLO)
 {
-       LOlist          *ll;
-       int             i;
-       int             n;
+       LOlist     *ll;
+       int                     i;
+       int                     n;
 
-       /* ----------
+       /* ----------
         * Now find any candidate tables who have columns of type oid.
         *
         * NOTE: System tables including pg_largeobject will be ignored.
@@ -40,8 +40,8 @@ load_lolist( LODumpMaster *pgLO )
         *
         * NOTE: the system oid column is ignored, as it has attnum < 1.
         * This shouldn't matter for correctness, but it saves time.
-        * ----------
-        */     
+        * ----------
+        */
        pgLO->res = PQexec(pgLO->conn,
                                           "SELECT c.relname, a.attname "
                                           "FROM pg_class c, pg_attribute a, pg_type t "
@@ -52,43 +52,49 @@ load_lolist( LODumpMaster *pgLO )
                                           "    AND c.relkind = 'r' "
                                           "    AND c.relname NOT LIKE 'pg_%'");
 
-       if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK) {
+       if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK)
+       {
                fprintf(stderr, "%s: Failed to get LO OIDs:\n%s", progname,
                                PQerrorMessage(pgLO->conn));
                exit(RE_ERROR);
        }
 
-       if ((n = PQntuples(pgLO->res)) == 0) {
+       if ((n = PQntuples(pgLO->res)) == 0)
+       {
                fprintf(stderr, "%s: No OID columns in the database.\n", progname);
                exit(RE_ERROR);
-       }
-       
+       }
+
        pgLO->lolist = (LOlist *) malloc((n + 1) * sizeof(LOlist));
-       
-       if (!pgLO->lolist) {
+
+       if (!pgLO->lolist)
+       {
                fprintf(stderr, "%s: can't allocate memory\n", progname);
                exit(RE_ERROR);
-       }
-       
-       for (i = 0, ll = pgLO->lolist; i < n; i++, ll++) {
+       }
+
+       for (i = 0, ll = pgLO->lolist; i < n; i++, ll++)
+       {
                ll->lo_table = strdup(PQgetvalue(pgLO->res, i, 0));
-               ll->lo_attr  = strdup(PQgetvalue(pgLO->res, i, 1));
+               ll->lo_attr = strdup(PQgetvalue(pgLO->res, i, 1));
        }
-       ll->lo_table = ll->lo_attr = (char *) NULL;
-       
+       ll->lo_table = ll->lo_attr = (char *) NULL;
+
        PQclear(pgLO->res);
 }
 
-void 
-pglo_export(LODumpMaster *pgLO)
+void
+pglo_export(LODumpMaster * pgLO)
 {
-       LOlist          *ll;
-       int             tuples;
+       LOlist     *ll;
+       int                     tuples;
        char            path[BUFSIZ],
-                       Qbuff[QUERY_BUFSIZ];
-       
-       if (pgLO->action != ACTION_SHOW) {
-               time_t  t;
+                               Qbuff[QUERY_BUFSIZ];
+
+       if (pgLO->action != ACTION_SHOW)
+       {
+               time_t          t;
+
                time(&t);
                fprintf(pgLO->index, "#\n# This is the PostgreSQL large object dump index\n#\n");
                fprintf(pgLO->index, "#\tDate:     %s", ctime(&t));
@@ -97,90 +103,102 @@ pglo_export(LODumpMaster *pgLO)
                fprintf(pgLO->index, "#\tUser:     %s\n", pgLO->user);
                fprintf(pgLO->index, "#\n# oid\ttable\tattribut\tinfile\n#\n");
        }
-       
+
        pgLO->counter = 0;
 
-       for(ll=pgLO->lolist; ll->lo_table != NULL; ll++) {
-               
+       for (ll = pgLO->lolist; ll->lo_table != NULL; ll++)
+       {
+
                /* ----------
                 * Query: find the LOs referenced by this column
                 * ----------
                 */
                sprintf(Qbuff, "SELECT DISTINCT l.loid FROM \"%s\" x, pg_largeobject l WHERE x.\"%s\" = l.loid",
                                ll->lo_table, ll->lo_attr);
-               
+
                /* puts(Qbuff); */
-                       
+
                pgLO->res = PQexec(pgLO->conn, Qbuff);
 
-        if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK) {
+               if (PQresultStatus(pgLO->res) != PGRES_TUPLES_OK)
+               {
                        fprintf(stderr, "%s: Failed to get LO OIDs:\n%s", progname,
                                        PQerrorMessage(pgLO->conn));
-        }
-               else if ((tuples = PQntuples(pgLO->res)) == 0) {
+               }
+               else if ((tuples = PQntuples(pgLO->res)) == 0)
+               {
                        if (!pgLO->quiet && pgLO->action == ACTION_EXPORT_ATTR)
                                printf("%s: no large objects in \"%s\".\"%s\"\n",
-                                          progname, ll->lo_table, ll->lo_attr);        
-               } else {
-               
-                       int     t;
-                       char    *val;
-       
+                                          progname, ll->lo_table, ll->lo_attr);
+               }
+               else
+               {
+
+                       int                     t;
+                       char       *val;
+
                        /* ----------
                         * Create DIR/FILE
                         * ----------
                         */
-                       if (pgLO->action != ACTION_SHOW) {
-                       
+                       if (pgLO->action != ACTION_SHOW)
+                       {
+
                                sprintf(path, "%s/%s/%s", pgLO->space, pgLO->db,
                                                ll->lo_table);
 
-                               if (mkdir(path, DIR_UMASK) == -1) {
-                                       if (errno != EEXIST) {
+                               if (mkdir(path, DIR_UMASK) == -1)
+                               {
+                                       if (errno != EEXIST)
+                                       {
                                                perror(path);
-                                               exit(RE_ERROR);                                 
-                                       }       
+                                               exit(RE_ERROR);
+                                       }
                                }
 
                                sprintf(path, "%s/%s/%s/%s", pgLO->space, pgLO->db,
-                                               ll->lo_table, ll->lo_attr);          
-                               
-                               if (mkdir(path, DIR_UMASK) == -1) {
-                                       if (errno != EEXIST) {
+                                               ll->lo_table, ll->lo_attr);
+
+                               if (mkdir(path, DIR_UMASK) == -1)
+                               {
+                                       if (errno != EEXIST)
+                                       {
                                                perror(path);
-                                               exit(RE_ERROR);                                 
-                                       }       
+                                               exit(RE_ERROR);
+                                       }
                                }
-                               
+
                                if (!pgLO->quiet)
-                                       printf("dump %s.%s (%d large obj)\n", 
-                                               ll->lo_table, ll->lo_attr, tuples);
+                                       printf("dump %s.%s (%d large obj)\n",
+                                                  ll->lo_table, ll->lo_attr, tuples);
                        }
 
                        pgLO->counter += tuples;
-                       
-                       for(t=0; t<tuples; t++) {
-                               Oid lo;
-                               
+
+                       for (t = 0; t < tuples; t++)
+                       {
+                               Oid                     lo;
+
                                val = PQgetvalue(pgLO->res, t, 0);
-                               
+
                                lo = atooid(val);
-                               
-                               if (pgLO->action == ACTION_SHOW) {
+
+                               if (pgLO->action == ACTION_SHOW)
+                               {
                                        printf("%s.%s: %u\n", ll->lo_table, ll->lo_attr, lo);
                                        continue;
                                }
-                               
-                               sprintf(path, "%s/%s/%s/%s/%s", pgLO->space, 
-                                       pgLO->db, ll->lo_table, ll->lo_attr, val);
-                               
-                               if (lo_export(pgLO->conn, lo, path) < 0) 
+
+                               sprintf(path, "%s/%s/%s/%s/%s", pgLO->space,
+                                               pgLO->db, ll->lo_table, ll->lo_attr, val);
+
+                               if (lo_export(pgLO->conn, lo, path) < 0)
                                        fprintf(stderr, "%s: lo_export failed:\n%s", progname,
                                                        PQerrorMessage(pgLO->conn));
-                                       
-                               else 
-                                       fprintf(pgLO->index, "%s\t%s\t%s\t%s/%s/%s/%s\n", val, 
-                                               ll->lo_table, ll->lo_attr, pgLO->db, ll->lo_table, ll->lo_attr, val);
+
+                               else
+                                       fprintf(pgLO->index, "%s\t%s\t%s\t%s/%s/%s/%s\n", val,
+                                                       ll->lo_table, ll->lo_attr, pgLO->db, ll->lo_table, ll->lo_attr, val);
                        }
                }
 
index 996bdf9e27e1f935495d562418a9658b9daf59fb..ff8929d6d6e252eac14a0b0cbfd761eb712b90cf 100644 (file)
@@ -1,20 +1,20 @@
 /* -------------------------------------------------------------------------
  * pg_dumplo
  *
- * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.3 2001/01/24 19:42:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/lo_import.c,v 1.4 2001/03/22 03:59:10 momjian Exp $
  *
  *                                     Karel Zak 1999-2000
  * -------------------------------------------------------------------------
  */
 
-#include <stdio.h>     
+#include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
-#include <errno.h>                            
+#include <errno.h>
 #include <time.h>
 
 #include <libpq-fe.h>
 
 #include "pg_dumplo.h"
 
-extern int     errno;        
+extern int     errno;
 
-void 
-pglo_import(LODumpMaster *pgLO)
+void
+pglo_import(LODumpMaster * pgLO)
 {
        LOlist          loa;
-       Oid             new_oid;
-       char            tab[MAX_TABLE_NAME], attr[MAX_ATTR_NAME],
-                       path[BUFSIZ], lo_path[BUFSIZ],
-                       Qbuff[QUERY_BUFSIZ];
-       
-       while(fgets(Qbuff, QUERY_BUFSIZ, pgLO->index)) {
-               
+       Oid                     new_oid;
+       char            tab[MAX_TABLE_NAME],
+                               attr[MAX_ATTR_NAME],
+                               path[BUFSIZ],
+                               lo_path[BUFSIZ],
+                               Qbuff[QUERY_BUFSIZ];
+
+       while (fgets(Qbuff, QUERY_BUFSIZ, pgLO->index))
+       {
+
                if (*Qbuff == '#')
                        continue;
 
-               if (! pgLO->remove && ! pgLO->quiet)
+               if (!pgLO->remove && !pgLO->quiet)
                        printf(Qbuff);
-               
-               sscanf(Qbuff, "%u\t%s\t%s\t%s\n", &loa.lo_oid, tab, attr, path); 
+
+               sscanf(Qbuff, "%u\t%s\t%s\t%s\n", &loa.lo_oid, tab, attr, path);
                loa.lo_table = tab;
-               loa.lo_attr  = attr;
+               loa.lo_attr = attr;
 
-               sprintf(lo_path, "%s/%s", pgLO->space, path); 
+               sprintf(lo_path, "%s/%s", pgLO->space, path);
 
                /* ----------
                 * Import LO
                 * ----------
                 */
-               if ((new_oid = lo_import(pgLO->conn, lo_path)) == 0) {
-               
+               if ((new_oid = lo_import(pgLO->conn, lo_path)) == 0)
+               {
+
                        fprintf(stderr, "%s: %s\n", progname, PQerrorMessage(pgLO->conn));
-                       
+
                        PQexec(pgLO->conn, "ROLLBACK");
                        fprintf(stderr, "\n%s: ROLLBACK\n", progname);
                        exit(RE_ERROR);
                }
 
-               if (pgLO->remove) {
+               if (pgLO->remove)
+               {
                        notice(pgLO, FALSE);
-                       if (lo_unlink(pgLO->conn, loa.lo_oid) < 0) 
-                               fprintf(stderr, "%s: can't remove LO %u:\n%s", 
-                                       progname, loa.lo_oid, PQerrorMessage(pgLO->conn));
-                                       
+                       if (lo_unlink(pgLO->conn, loa.lo_oid) < 0)
+                               fprintf(stderr, "%s: can't remove LO %u:\n%s",
+                                               progname, loa.lo_oid, PQerrorMessage(pgLO->conn));
+
                        else if (!pgLO->quiet)
-                               printf("remove old %u and create new %u\n", 
-                                       loa.lo_oid, new_oid);   
-                       notice(pgLO, TRUE);     
+                               printf("remove old %u and create new %u\n",
+                                          loa.lo_oid, new_oid);
+                       notice(pgLO, TRUE);
                }
-               
+
                pgLO->counter++;
-       
+
                /* ----------
                 * UPDATE oid in tab
                 * ----------
                 */
-               sprintf(Qbuff, "UPDATE \"%s\" SET \"%s\"=%u WHERE \"%s\"=%u", 
+               sprintf(Qbuff, "UPDATE \"%s\" SET \"%s\"=%u WHERE \"%s\"=%u",
                        loa.lo_table, loa.lo_attr, new_oid, loa.lo_attr, loa.lo_oid);
 
-               /*fprintf(stderr, Qbuff);*/
-                       
+               /* fprintf(stderr, Qbuff); */
+
                pgLO->res = PQexec(pgLO->conn, Qbuff);
-       
-               if (PQresultStatus(pgLO->res) != PGRES_COMMAND_OK) {
-                       fprintf(stderr, "%s: %s\n",progname, PQerrorMessage(pgLO->conn));
+
+               if (PQresultStatus(pgLO->res) != PGRES_COMMAND_OK)
+               {
+                       fprintf(stderr, "%s: %s\n", progname, PQerrorMessage(pgLO->conn));
                        PQclear(pgLO->res);
                        PQexec(pgLO->conn, "ROLLBACK");
                        fprintf(stderr, "\n%s: ROLLBACK\n", progname);
                        exit(RE_ERROR);
-               }       
+               }
                PQclear(pgLO->res);
-       }       
- }
+       }
+}
index e8ff2f72e095b7e9c063744dfd83af475a9e99f4..3878aeca0273b0e2f3137e98e44cbc9e72ffc263 100644 (file)
@@ -1,7 +1,7 @@
 /* -------------------------------------------------------------------------
  * pg_dumplo
  *
- * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.6 2001/02/10 02:31:25 tgl Exp $
+ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.7 2001/03/22 03:59:10 momjian Exp $
  *
  *                                     Karel Zak 1999-2000
  * -------------------------------------------------------------------------
 #include "postgres_fe.h"
 #endif
 
-#include <stdio.h>     
+#include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
-#include <errno.h>                            
+#include <errno.h>
 
 #include <libpq-fe.h>
 #include <libpq/libpq-fs.h>
 
-#include "pg_dumplo.h" 
+#include "pg_dumplo.h"
 
 #ifdef HAVE_GETOPT_LONG
-       #include <getopt.h>
-       #define no_argument 0
-       #define required_argument 1
+#include <getopt.h>
+#define no_argument 0
+#define required_argument 1
 #endif
-        
-extern int     errno;        
 
-char   *progname = NULL;
+extern int     errno;
 
-int main(int argc, char **argv);
+char      *progname = NULL;
+
+int                    main(int argc, char **argv);
 static void usage(void);
-static void parse_lolist (LODumpMaster *pgLO);
-        
+static void parse_lolist(LODumpMaster * pgLO);
+
 
 /*-----
  *     The mother of all C functions
  *-----
  */
-int 
+int
 main(int argc, char **argv)
-{      
-       LODumpMaster    _pgLO, *pgLO = &_pgLO;
-       char            *pwd = NULL;
-
-       pgLO->argv      = argv;
-       pgLO->argc      = argc;
-       pgLO->action    = 0;
-       pgLO->lolist    = NULL;
-       pgLO->user      = NULL;
-       pgLO->db        = NULL;
-       pgLO->host      = NULL;
-       pgLO->space     = NULL;
-       pgLO->index     = NULL;
-       pgLO->remove    = FALSE;
-       pgLO->quiet     = FALSE; 
-       pgLO->counter   = 0;
+{
+       LODumpMaster _pgLO,
+                          *pgLO = &_pgLO;
+       char       *pwd = NULL;
+
+       pgLO->argv = argv;
+       pgLO->argc = argc;
+       pgLO->action = 0;
+       pgLO->lolist = NULL;
+       pgLO->user = NULL;
+       pgLO->db = NULL;
+       pgLO->host = NULL;
+       pgLO->space = NULL;
+       pgLO->index = NULL;
+       pgLO->remove = FALSE;
+       pgLO->quiet = FALSE;
+       pgLO->counter = 0;
        pgLO->lolist_start = 0;
-       
+
        progname = argv[0];
 
        /* ----------
         * Parse ARGV
         * ----------
         */
-       if (argc > 1) {
-               int     arg;
-               extern int optind;
-
-#ifdef HAVE_GETOPT_LONG        
-               int     l_index=0;      
-               static struct option l_opt[] = {
-                       { "help",       no_argument, 0, 'h' },          
-                       { "user",       required_argument, 0, 'u' },
-                       { "pwd",        required_argument, 0, 'p' },
-                       { "db",         required_argument, 0, 'd' },
-                       { "host",       required_argument, 0, 'h' },
-                       { "space",      required_argument, 0, 's' },
-                       { "import",     no_argument, 0, 'i' },
-                       { "export",     no_argument, 0, 'e' },
-                       { "remove",     no_argument, 0, 'r' },
-                       { "quiet",      no_argument, 0, 'q' },
-                       { "all",        no_argument, 0, 'a' },
-                       { "show",       no_argument, 0, 'w' },
-                       { NULL, 0, 0, 0 }
-               };      
-
-               while((arg = getopt_long(argc, argv, "?aehu:p:qd:l:t:irs:w", l_opt, &l_index)) != -1) {
+       if (argc > 1)
+       {
+               int                     arg;
+               extern int      optind;
+
+#ifdef HAVE_GETOPT_LONG
+               int                     l_index = 0;
+               static struct option l_opt[] = {
+                       {"help", no_argument, 0, 'h'},
+                       {"user", required_argument, 0, 'u'},
+                       {"pwd", required_argument, 0, 'p'},
+                       {"db", required_argument, 0, 'd'},
+                       {"host", required_argument, 0, 'h'},
+                       {"space", required_argument, 0, 's'},
+                       {"import", no_argument, 0, 'i'},
+                       {"export", no_argument, 0, 'e'},
+                       {"remove", no_argument, 0, 'r'},
+                       {"quiet", no_argument, 0, 'q'},
+                       {"all", no_argument, 0, 'a'},
+                       {"show", no_argument, 0, 'w'},
+                       {NULL, 0, 0, 0}
+               };
+
+               while ((arg = getopt_long(argc, argv, "?aehu:p:qd:l:t:irs:w", l_opt, &l_index)) != -1)
+               {
 #else
-               while((arg = getopt(argc, argv, "?aehu:p:qd:l:t:irs:w")) != -1) {                
+               while ((arg = getopt(argc, argv, "?aehu:p:qd:l:t:irs:w")) != -1)
+               {
 #endif
-                       switch(arg) {
-                       case '?':
-                       case 'h':
-                               usage();
+                       switch (arg)
+                       {
+                               case '?':
+                               case 'h':
+                                       usage();
                                        exit(RE_OK);
-                       case 'u':       
-                               pgLO->user = strdup(optarg);
-                               break;   
-                       case 't':       
-                               pgLO->host = strdup(optarg);
-                               break;          
-                       case 'p':       
-                               pwd = strdup(optarg);
-                               break;                          
-                       case 'd':       
-                               pgLO->db = strdup(optarg);
-                               break;
-                       case 's':       
-                               pgLO->space = strdup(optarg);
-                               break;  
-                       case 'i':       
-                               pgLO->action = ACTION_IMPORT;
-                               break;  
-                       case 'l':
-                               pgLO->action = ACTION_EXPORT_ATTR;
-                               pgLO->lolist_start = optind-1;
-                               parse_lolist (pgLO);
-                               break;
-                       case 'e':       
-                       case 'a':
+                               case 'u':
+                                       pgLO->user = strdup(optarg);
+                                       break;
+                               case 't':
+                                       pgLO->host = strdup(optarg);
+                                       break;
+                               case 'p':
+                                       pwd = strdup(optarg);
+                                       break;
+                               case 'd':
+                                       pgLO->db = strdup(optarg);
+                                       break;
+                               case 's':
+                                       pgLO->space = strdup(optarg);
+                                       break;
+                               case 'i':
+                                       pgLO->action = ACTION_IMPORT;
+                                       break;
+                               case 'l':
+                                       pgLO->action = ACTION_EXPORT_ATTR;
+                                       pgLO->lolist_start = optind - 1;
+                                       parse_lolist(pgLO);
+                                       break;
+                               case 'e':
+                               case 'a':
                                        pgLO->action = ACTION_EXPORT_ALL;
                                        break;
                                case 'w':
                                        pgLO->action = ACTION_SHOW;
-                                       break;  
-                       case 'r':
-                               pgLO->remove = TRUE;
-                               break;
-                       case 'q':
-                               pgLO->quiet = TRUE;     
-                               break;
-                       default:
-                               fprintf(stderr, "%s: bad arg -%c\n", progname, arg);
-                               usage();
-                               exit(RE_ERROR);
+                                       break;
+                               case 'r':
+                                       pgLO->remove = TRUE;
+                                       break;
+                               case 'q':
+                                       pgLO->quiet = TRUE;
+                                       break;
+                               default:
+                                       fprintf(stderr, "%s: bad arg -%c\n", progname, arg);
+                                       usage();
+                                       exit(RE_ERROR);
                        }
-               }       
-       } else {
+               }
+       }
+       else
+       {
                usage();
-               exit(RE_ERROR);
-       }       
+               exit(RE_ERROR);
+       }
 
        /* ----------
         * Check space
         * ----------
         */
-       if (! pgLO->space && ! pgLO->action == ACTION_SHOW) {
-               if (!(pgLO->space = getenv("PWD"))) {
+       if (!pgLO->space && !pgLO->action == ACTION_SHOW)
+       {
+               if (!(pgLO->space = getenv("PWD")))
+               {
                        fprintf(stderr, "%s: not set space for dump-tree (option '-s' or $PWD).\n", progname);
                        exit(RE_ERROR);
-               }       
+               }
        }
-       
-       if (!pgLO->action) {
+
+       if (!pgLO->action)
+       {
                fprintf(stderr, "%s: What do you want - export or import?\n", progname);
                exit(RE_ERROR);
        }
-       
+
        /* ----------
         * Make connection
         * ----------
         */
-       pgLO->conn = PQsetdbLogin(pgLO->host, NULL, NULL, NULL, pgLO->db, 
-                       pgLO->user, pwd);
-        
-       if (PQstatus(pgLO->conn) == CONNECTION_BAD) {
+       pgLO->conn = PQsetdbLogin(pgLO->host, NULL, NULL, NULL, pgLO->db,
+                                                         pgLO->user, pwd);
+
+       if (PQstatus(pgLO->conn) == CONNECTION_BAD)
+       {
                fprintf(stderr, "%s (connection): %s\n", progname, PQerrorMessage(pgLO->conn));
                exit(RE_ERROR);
-       }  
+       }
        pgLO->host = PQhost(pgLO->conn) ? PQhost(pgLO->conn) : "localhost";
-       pgLO->db   = PQdb(pgLO->conn); 
-       pgLO->user = PQuser(pgLO->conn);        
-       
-       
+       pgLO->db = PQdb(pgLO->conn);
+       pgLO->user = PQuser(pgLO->conn);
+
+
        /* ----------
         * Init index file
         * ----------
         */
-       if (pgLO->action != ACTION_SHOW) 
+       if (pgLO->action != ACTION_SHOW)
                index_file(pgLO);
-       
+
        PQexec(pgLO->conn, "BEGIN");
 
-       switch(pgLO->action) {
-       
+       switch (pgLO->action)
+       {
+
                case ACTION_SHOW:
                case ACTION_EXPORT_ALL:
                        load_lolist(pgLO);
                        /* FALL THROUGH */
-                               
+
                case ACTION_EXPORT_ATTR:
                        pglo_export(pgLO);
-                       if (!pgLO->quiet) {
+                       if (!pgLO->quiet)
+                       {
                                if (pgLO->action == ACTION_SHOW)
                                        printf("\nDatabase '%s' contains %d large objects.\n\n", pgLO->db, pgLO->counter);
-                               else    
+                               else
                                        printf("\nExported %d large objects.\n\n", pgLO->counter);
                        }
                        break;
-               
+
                case ACTION_IMPORT:
                        pglo_import(pgLO);
                        if (!pgLO->quiet)
                                printf("\nImported %d large objects.\n\n", pgLO->counter);
-                       break;                  
-       }       
+                       break;
+       }
 
        PQexec(pgLO->conn, "COMMIT");
-       PQfinish(pgLO->conn);   
-       
+       PQfinish(pgLO->conn);
+
        if (pgLO->action != ACTION_SHOW)
                fclose(pgLO->index);
-       
+
        exit(RE_OK);
 }
 
 static void
-parse_lolist (LODumpMaster *pgLO)
+parse_lolist(LODumpMaster * pgLO)
 {
-       LOlist          *ll;
-       char            **d, 
-                       *loc,
-                       buff[MAX_TABLE_NAME + MAX_ATTR_NAME +1];
+       LOlist     *ll;
+       char      **d,
+                          *loc,
+                               buff[MAX_TABLE_NAME + MAX_ATTR_NAME + 1];
 
        pgLO->lolist = (LOlist *) malloc(pgLO->argc * sizeof(LOlist));
-       
-       if (! pgLO->lolist) {
+
+       if (!pgLO->lolist)
+       {
                fprintf(stderr, "%s: can't allocate memory\n", progname);
                exit(RE_ERROR);
        }
-       
-       for(    d=pgLO->argv + pgLO->lolist_start, ll=pgLO->lolist; 
-               *d != NULL; 
-               d++, ll++) {
-               
+
+       for (d = pgLO->argv + pgLO->lolist_start, ll = pgLO->lolist;
+                *d != NULL;
+                d++, ll++)
+       {
+
                strncpy(buff, *d, MAX_TABLE_NAME + MAX_ATTR_NAME);
-               
-               if ((loc = strchr(buff, '.')) == NULL) {
+
+               if ((loc = strchr(buff, '.')) == NULL)
+               {
                        fprintf(stderr, "%s: '%s' is bad 'table.attr'\n", progname, buff);
-                       exit(RE_ERROR); 
+                       exit(RE_ERROR);
                }
                *loc = '\0';
                ll->lo_table = strdup(buff);
@@ -254,55 +270,55 @@ parse_lolist (LODumpMaster *pgLO)
 }
 
 
-static void 
+static void
 usage()
 {
        printf("\npg_dumplo %s - PostgreSQL large objects dump\n", VERSION);
-        puts("pg_dumplo [option]\n\n"
+       puts("pg_dumplo [option]\n\n"
 
 #ifdef HAVE_GETOPT_LONG
-       
-       "-h --help                    this help\n"      
-       "-u --user=<username>         username for connection to server\n"
-       "-p --password=<password>     password for connection to server\n"      
-       "-d --db=<database>           database name\n"  
-       "-t --host=<hostname>         server hostname\n"                
-       "-s --space=<dir>             directory with dump tree (for export/import)\n"
-       "-i --import                  import large obj dump tree to DB\n"
-        "-e --export                  export (dump) large obj to dump tree\n"
-       "-l <table.attr ...>          dump attribute (columns) with LO to dump tree\n"
-       "-a --all                     dump all LO in DB (default)\n"
-       "-r --remove                  if is set '-i' try remove old LO\n"
-        "-q --quiet                   run quietly\n"
-       "-w --show                    not dump, but show all LO in DB\n" 
-       ); /* puts() */ 
+
+                "-h --help                    this help\n"
+          "-u --user=<username>         username for connection to server\n"
+          "-p --password=<password>     password for connection to server\n"
+                "-d --db=<database>           database name\n"
+                "-t --host=<hostname>         server hostname\n"
+                "-s --space=<dir>             directory with dump tree (for export/import)\n"
+                "-i --import                  import large obj dump tree to DB\n"
+       "-e --export                  export (dump) large obj to dump tree\n"
+                "-l <table.attr ...>          dump attribute (columns) with LO to dump tree\n"
+                "-a --all                     dump all LO in DB (default)\n"
+                "-r --remove                  if is set '-i' try remove old LO\n"
+                "-q --quiet                   run quietly\n"
+                "-w --show                    not dump, but show all LO in DB\n"
+               );                                              /* puts() */
 
 #else
-       "-h                           this help\n"      
-       "-u <username>                username for connection to server\n"
-       "-p <password>                password for connection to server\n"      
-       "-d <database>                database name\n"  
-       "-t <hostname>                server hostname\n"                
-       "-s <dir>                     directory with dump tree (for export/import)\n"
-       "-i                           import large obj dump tree to DB\n"
-        "-e                           export (dump) large obj to dump tree\n"
-       "-l <table.attr ...>          dump attribute (columns) with LO to dump tree\n"
-       "-a                           dump all LO in DB (default)\n"
-       "-r                           if is set '-i' try remove old LO\n"
-       "-q                           run quietly\n" 
-        "-w                           not dump, but show all LO in DB\n"
-       ); /* puts() */ 
+                "-h                           this help\n"
+          "-u <username>                username for connection to server\n"
+          "-p <password>                password for connection to server\n"
+                "-d <database>                database name\n"
+                "-t <hostname>                server hostname\n"
+                "-s <dir>                     directory with dump tree (for export/import)\n"
+                "-i                           import large obj dump tree to DB\n"
+       "-e                           export (dump) large obj to dump tree\n"
+                "-l <table.attr ...>          dump attribute (columns) with LO to dump tree\n"
+                "-a                           dump all LO in DB (default)\n"
+                "-r                           if is set '-i' try remove old LO\n"
+                "-q                           run quietly\n"
+                "-w                           not dump, but show all LO in DB\n"
+               );                                              /* puts() */
 
 #endif
 
        puts(
-       "Example (dump):   pg_dumplo -d my_db -s /my_dump/dir -l t1.a t1.b t2.a\n"
-       "                  pg_dumplo -a -d my_db -s /my_dump/dir\n"
-       "Example (import): pg_dumplo -i -d my_db -s /my_dump/dir\n"     
-       "Example (show):   pg_dumplo -w -d my_db\n\n"   
-       "Note:  * option '-l' must be last option!\n"   
-       "       * option '-i' without option '-r' make new large obj in DB\n" 
-       "         not rewrite old, the '-i' UPDATE oid numbers in table.attr only!\n"
-       "       * if is not set option -s, the pg_dumplo use $PWD\n" 
-       ); /* puts()*/  
+                "Example (dump):   pg_dumplo -d my_db -s /my_dump/dir -l t1.a t1.b t2.a\n"
+                "                  pg_dumplo -a -d my_db -s /my_dump/dir\n"
+                "Example (import): pg_dumplo -i -d my_db -s /my_dump/dir\n"
+                "Example (show):   pg_dumplo -w -d my_db\n\n"
+                "Note:  * option '-l' must be last option!\n"
+       "       * option '-i' without option '-r' make new large obj in DB\n"
+                "         not rewrite old, the '-i' UPDATE oid numbers in table.attr only!\n"
+                "       * if is not set option -s, the pg_dumplo use $PWD\n"
+               );                                              /* puts() */
 }
index 7513c71b9baf2382849d61b7dc3f2a20f4abd9eb..3ab25495cb1f2b69903b01e2f3b8d3e863b9bc40 100644 (file)
@@ -1,7 +1,7 @@
 /* -------------------------------------------------------------------------
  * pg_dumplo
  *
- * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/pg_dumplo.h,v 1.3 2001/01/24 19:42:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/pg_dumplo.h,v 1.4 2001/03/22 03:59:10 momjian Exp $
  *
  *                                     Karel Zak 1999-2000
  * -------------------------------------------------------------------------
 /* ----------
  * Define
  * ----------
- */        
+ */
 #define QUERY_BUFSIZ   (8*1024)
 #define DIR_UMASK      0755
 #define FILE_UMASK     0644
 
-#define        TRUE            1
+#define TRUE           1
 #define FALSE          0
 #define RE_OK          0
 #define RE_ERROR       1
  * LO struct
  * ----------
  */
-typedef struct { 
-       char    *lo_table,
-                       *lo_attr;
-       Oid             lo_oid;
-} LOlist;
+typedef struct
+{
+       char       *lo_table,
+                          *lo_attr;
+       Oid                     lo_oid;
+}                      LOlist;
 
-typedef struct {
-       int             action;
-       LOlist          *lolist;
-       char            **argv,
-                       *user,
-                       *db,
-                       *host,
-                       *space;
-       FILE            *index;
-       int             counter,
-                       argc,
-                       lolist_start,
-                       remove,
-                       quiet;
-       PGresult        *res;
-       PGconn          *conn;
-} LODumpMaster;
+typedef struct
+{
+       int                     action;
+       LOlist     *lolist;
+       char      **argv,
+                          *user,
+                          *db,
+                          *host,
+                          *space;
+       FILE       *index;
+       int                     counter,
+                               argc,
+                               lolist_start,
+                               remove,
+                               quiet;
+       PGresult   *res;
+       PGconn     *conn;
+}                      LODumpMaster;
 
-typedef enum { 
+typedef enum
+{
        ACTION_NONE,
        ACTION_SHOW,
-       ACTION_EXPORT_ATTR,     
-       ACTION_EXPORT_ALL,      
+       ACTION_EXPORT_ATTR,
+       ACTION_EXPORT_ALL,
        ACTION_IMPORT
-} PGLODUMP_ACTIONS;
+}                      PGLODUMP_ACTIONS;
 
 extern char *progname;
 
-extern void    notice          (LODumpMaster *pgLO, int set);
-extern void    index_file      (LODumpMaster *pgLO);
-extern void    load_lolist     (LODumpMaster *pgLO);
-extern void    pglo_export     (LODumpMaster *pgLO);
-extern void    pglo_import     (LODumpMaster *pgLO);
+extern void notice(LODumpMaster * pgLO, int set);
+extern void index_file(LODumpMaster * pgLO);
+extern void load_lolist(LODumpMaster * pgLO);
+extern void pglo_export(LODumpMaster * pgLO);
+extern void pglo_import(LODumpMaster * pgLO);
 
-#endif /* PG_DUMPLO_H */
+#endif  /* PG_DUMPLO_H */
index dc3f5bbf9a117b7fd346ea2ef4f3dafb4a7825cd..d36ee4be083377dd51908c910130c66239ac1fe6 100644 (file)
@@ -1,20 +1,20 @@
 /* -------------------------------------------------------------------------
  * pg_dumplo
  *
- * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/utils.c,v 1.3 2001/01/24 19:42:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/utils.c,v 1.4 2001/03/22 03:59:10 momjian Exp $
  *
  *                                     Karel Zak 1999-2000
  * -------------------------------------------------------------------------
  */
 
-#include <stdio.h>     
+#include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <fcntl.h>
-#include <errno.h>                            
+#include <errno.h>
 #include <time.h>
 
 #include <libpq-fe.h>
 
 #include "pg_dumplo.h"
 
-extern int     errno;        
+extern int     errno;
+
+static void Dummy_NoticeProcessor(void *arg, const char *message);
+static void Default_NoticeProcessor(void *arg, const char *message);
 
-static void Dummy_NoticeProcessor(void * arg, const char * message);
-static void Default_NoticeProcessor(void * arg, const char * message);
-    
 
 void
-index_file(LODumpMaster *pgLO)
+index_file(LODumpMaster * pgLO)
 {
-       char    path[BUFSIZ];
+       char            path[BUFSIZ];
 
        if (pgLO->action == ACTION_SHOW)
                return;
-       
-       sprintf(path, "%s/%s", pgLO->space, pgLO->db); 
-       
+
+       sprintf(path, "%s/%s", pgLO->space, pgLO->db);
+
        if (pgLO->action == ACTION_EXPORT_ATTR ||
-           pgLO->action == ACTION_EXPORT_ALL) {
-           
-               if (mkdir(path, DIR_UMASK) == -1) {
-                       if (errno != EEXIST) {
+               pgLO->action == ACTION_EXPORT_ALL)
+       {
+
+               if (mkdir(path, DIR_UMASK) == -1)
+               {
+                       if (errno != EEXIST)
+                       {
                                perror(path);
-                               exit(RE_ERROR); 
-                       }       
+                               exit(RE_ERROR);
+                       }
                }
-               
-               sprintf(path, "%s/lo_dump.index", path);          
 
-               if ((pgLO->index = fopen(path, "w")) == NULL) {
+               sprintf(path, "%s/lo_dump.index", path);
+
+               if ((pgLO->index = fopen(path, "w")) == NULL)
+               {
                        perror(path);
                        exit(RE_ERROR);
                }
-               
-       } else if (pgLO->action != ACTION_NONE ) {
-       
-               sprintf(path, "%s/lo_dump.index", path);          
 
-               if ((pgLO->index = fopen(path, "r")) == NULL) {
+       }
+       else if (pgLO->action != ACTION_NONE)
+       {
+
+               sprintf(path, "%s/lo_dump.index", path);
+
+               if ((pgLO->index = fopen(path, "r")) == NULL)
+               {
                        perror(path);
                        exit(RE_ERROR);
                }
        }
 }
 
-static 
-void Dummy_NoticeProcessor(void * arg, const char * message)
+static
+void
+Dummy_NoticeProcessor(void *arg, const char *message)
 {
-    ;
+       ;
 }
 
-static 
-void Default_NoticeProcessor(void * arg, const char * message)
+static
+void
+Default_NoticeProcessor(void *arg, const char *message)
 {
-     fprintf(stderr, "%s", message);
+       fprintf(stderr, "%s", message);
 }
 
-void 
-notice(LODumpMaster *pgLO, int set)
-{         
-       if (set)PQsetNoticeProcessor(pgLO->conn, Default_NoticeProcessor, NULL);
-       else    PQsetNoticeProcessor(pgLO->conn, Dummy_NoticeProcessor, NULL);  
+void
+notice(LODumpMaster * pgLO, int set)
+{
+       if (set)
+               PQsetNoticeProcessor(pgLO->conn, Default_NoticeProcessor, NULL);
+       else
+               PQsetNoticeProcessor(pgLO->conn, Dummy_NoticeProcessor, NULL);
 }
index af56a249c662a0687a9e3d2128c9b0d56a0c4632..cc2fdbed30d2ef544f056723089e3d2d5d3091b0 100644 (file)
@@ -2,10 +2,10 @@
  *
  * Copyright 2001 by Nathan Myers <[email protected]>
  * This software is distributed free of charge with no warranty of any kind.
- * You have permission to make copies for any purpose, provided that (1) 
- * this copyright notice is retained unchanged, and (2) you agree to 
- * absolve the author of all responsibility for all consequences arising 
- * from any use.  
+ * You have permission to make copies for any purpose, provided that (1)
+ * this copyright notice is retained unchanged, and (2) you agree to
+ * absolve the author of all responsibility for all consequences arising
+ * from any use.
  */
 
 #include <stdio.h>
 #include <syslog.h>
 #include <string.h>
 
-struct {
-    const char *tag;
-    int size;
-    int priority;
-} tags[] = {
-    { "",         0,                 LOG_NOTICE },
-    { "emerg:",   sizeof("emerg"),   LOG_EMERG },
-    { "alert:",   sizeof("alert"),   LOG_ALERT },
-    { "crit:",    sizeof("crit"),    LOG_CRIT },
-    { "err:",     sizeof("err"),     LOG_ERR },
-    { "error:",   sizeof("error"),   LOG_ERR },
-    { "warning:", sizeof("warning"), LOG_WARNING },
-    { "notice:",  sizeof("notice"),  LOG_NOTICE },
-    { "info:",    sizeof("info"),    LOG_INFO },
-    { "debug:",   sizeof("debug"),   LOG_DEBUG }
+struct
+{
+       const char *tag;
+       int                     size;
+       int                     priority;
+}                      tags[] =
+
+{
+       {
+               "", 0, LOG_NOTICE
+       },
+       {
+               "emerg:", sizeof("emerg"), LOG_EMERG
+       },
+       {
+               "alert:", sizeof("alert"), LOG_ALERT
+       },
+       {
+               "crit:", sizeof("crit"), LOG_CRIT
+       },
+       {
+               "err:", sizeof("err"), LOG_ERR
+       },
+       {
+               "error:", sizeof("error"), LOG_ERR
+       },
+       {
+               "warning:", sizeof("warning"), LOG_WARNING
+       },
+       {
+               "notice:", sizeof("notice"), LOG_NOTICE
+       },
+       {
+               "info:", sizeof("info"), LOG_INFO
+       },
+       {
+               "debug:", sizeof("debug"), LOG_DEBUG
+       }
 };
 
-int main()
+int
+main()
 {
-    char buf[301];
-    int c;
-    char *pos = buf;
-    const char *colon = 0;
+       char            buf[301];
+       int                     c;
+       char       *pos = buf;
+       const char *colon = 0;
 
 #ifndef DEBUG
-    openlog("postgresql", LOG_CONS, LOG_LOCAL1);
+       openlog("postgresql", LOG_CONS, LOG_LOCAL1);
 #endif
-    while ( (c = getchar()) != EOF) {
-        if (c == '\r') {
-          continue;
-        }
-        if (c == '\n') {
-            int level = sizeof(tags)/sizeof(*tags);
-            char *bol;
+       while ((c = getchar()) != EOF)
+       {
+               if (c == '\r')
+                       continue;
+               if (c == '\n')
+               {
+                       int                     level = sizeof(tags) / sizeof(*tags);
+                       char       *bol;
 
-            if (colon == 0 || (size_t)(colon - buf) > sizeof("warning")) {
-                level = 1;
-            }
-            *pos = 0;
-            while (--level) {
-                if (pos - buf >= tags[level].size
-                    && strncmp(buf, tags[level].tag, tags[level].size) == 0) {
-                    break; 
-                }
-            }
-            bol = buf + tags[level].size;
-            if (bol > buf && *bol == ' ') {
-                ++bol;
-            }
-            if (pos - bol > 0) {
+                       if (colon == 0 || (size_t) (colon - buf) > sizeof("warning"))
+                               level = 1;
+                       *pos = 0;
+                       while (--level)
+                       {
+                               if (pos - buf >= tags[level].size
+                                && strncmp(buf, tags[level].tag, tags[level].size) == 0)
+                                       break;
+                       }
+                       bol = buf + tags[level].size;
+                       if (bol > buf && *bol == ' ')
+                               ++bol;
+                       if (pos - bol > 0)
+                       {
 #ifndef DEBUG
-                syslog(tags[level].priority, "%s", bol);
+                               syslog(tags[level].priority, "%s", bol);
 #else
-                printf("%d/%s\n", tags[level].priority, bol);
+                               printf("%d/%s\n", tags[level].priority, bol);
 #endif
-            }
-            pos = buf;
-            colon = (char const *)0;
-            continue;
-        }
-        if (c == ':' && !colon) {
-            colon = pos;
-        }
-        if ((size_t)(pos - buf) < sizeof(buf)-1) {
-            *pos++ = c;
-        }
-    }
-    return 0;
+                       }
+                       pos = buf;
+                       colon = (char const *) 0;
+                       continue;
+               }
+               if (c == ':' && !colon)
+                       colon = pos;
+               if ((size_t) (pos - buf) < sizeof(buf) - 1)
+                       *pos++ = c;
+       }
+       return 0;
 }
-
index 5137cddd9137c85e32a399ddfb6d6ce4753a5b15..848bbb9267418d54ce66e61c008d5f75419dc904 100644 (file)
@@ -5,15 +5,15 @@
  *       Can also rebuild pg_control if needed.
  *
  * The theory of operation is fairly simple:
- *    1. Read the existing pg_control (which will include the last
+ *       1. Read the existing pg_control (which will include the last
  *              checkpoint record).  If it is an old format then update to
  *              current format.
  *       2. If pg_control is corrupt, attempt to intuit reasonable values,
  *              by scanning the old xlog if necessary.
  *       3. Modify pg_control to reflect a "shutdown" state with a checkpoint
- *          record at the start of xlog.
+ *              record at the start of xlog.
  *       4. Flush the existing xlog files and write a new segment with
- *          just a checkpoint record in it.  The new segment is positioned
+ *              just a checkpoint record in it.  The new segment is positioned
  *              just past the end of the old xlog, so that existing LSNs in
  *              data pages will appear to be "in the past".
  * This is all pretty straightforward except for the intuition part of
@@ -23,7 +23,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.2 2001/03/16 05:08:39 tgl Exp $
+ * $Header: /cvsroot/pgsql/contrib/pg_resetxlog/Attic/pg_resetxlog.c,v 1.3 2001/03/22 03:59:10 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -63,7 +63,7 @@
  * Compute ID and segment from an XLogRecPtr.
  *
  * For XLByteToSeg, do the computation at face value.  For XLByteToPrevSeg,
- * a boundary byte is taken to be in the previous segment.  This is suitable
+ * a boundary byte is taken to be in the previous segment.     This is suitable
  * for deciding which segment to write given a pointer to a record end,
  * for example.
  */
@@ -109,8 +109,9 @@ static char *DataDir;                       /* locations of important stuff */
 static char XLogDir[MAXPGPATH];
 static char ControlFilePath[MAXPGPATH];
 
-static ControlFileData ControlFile;    /* pg_control values */
-static uint32 newXlogId, newXlogSeg; /* ID/Segment of new XLOG segment */
+static ControlFileData ControlFile;            /* pg_control values */
+static uint32 newXlogId,
+                       newXlogSeg;                     /* ID/Segment of new XLOG segment */
 static bool guessed = false;   /* T if we had to guess at any values */
 
 
@@ -139,17 +140,18 @@ XLogFileOpen(uint32 log, uint32 seg)
 static bool
 ReadControlFile(void)
 {
-       int             fd;
-       int             len;
-       char   *buffer;
-       crc64   crc;
+       int                     fd;
+       int                     len;
+       char       *buffer;
+       crc64           crc;
 
        if ((fd = open(ControlFilePath, O_RDONLY)) < 0)
        {
+
                /*
-                * If pg_control is not there at all, or we can't read it,
-                * the odds are we've been handed a bad DataDir path, so give up.
-                * User can do "touch pg_control" to force us to proceed.
+                * If pg_control is not there at all, or we can't read it, the
+                * odds are we've been handed a bad DataDir path, so give up. User
+                * can do "touch pg_control" to force us to proceed.
                 */
                perror("Failed to open $PGDATA/global/pg_control for reading");
                if (errno == ENOENT)
@@ -175,7 +177,7 @@ ReadControlFile(void)
        {
                /* Seems to be current version --- check the CRC. */
                INIT_CRC64(crc);
-               COMP_CRC64(crc, 
+               COMP_CRC64(crc,
                                   buffer + sizeof(crc64),
                                   sizeof(ControlFileData) - sizeof(crc64));
                FIN_CRC64(crc);
@@ -193,6 +195,7 @@ ReadControlFile(void)
                guessed = true;
                return true;
        }
+
        /*
         * Maybe it's a 7.1beta pg_control.
         */
@@ -217,75 +220,75 @@ ReadControlFile(void)
 
 typedef struct crc64V0
 {
-       uint32                  crc1;
-       uint32                  crc2;
-} crc64V0;
+       uint32          crc1;
+       uint32          crc2;
+}                      crc64V0;
 
 static uint32 crc_tableV0[] = {
-0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
-0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
-0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
-0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
-0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
-0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
-0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
-0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
-0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
-0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
-0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
-0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
-0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
-0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
-0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
-0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
-0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
-0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
-0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
-0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
-0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
-0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
-0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
-0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
-0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
-0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
-0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
-0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
-0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
-0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
-0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
-0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
-0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
-0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
-0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
-0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
-0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
-0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
-0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
-0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
-0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
-0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
-0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+       0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+       0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+       0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+       0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+       0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+       0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+       0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+       0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+       0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+       0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+       0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+       0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+       0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+       0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+       0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+       0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+       0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+       0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+       0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+       0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+       0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+       0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+       0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+       0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+       0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+       0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+       0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+       0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+       0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+       0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+       0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+       0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+       0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+       0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+       0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+       0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+       0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+       0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+       0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+       0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+       0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+       0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+       0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
 };
 
 #define INIT_CRC64V0(crc)      ((crc).crc1 = 0xffffffff, (crc).crc2 = 0xffffffff)
 #define FIN_CRC64V0(crc)       ((crc).crc1 ^= 0xffffffff, (crc).crc2 ^= 0xffffffff)
 #define COMP_CRC64V0(crc, data, len)   \
 {\
-        uint32       __c1 = (crc).crc1;\
-        uint32       __c2 = (crc).crc2;\
-        char        *__data = (char *) (data);\
-        uint32       __len = (len);\
+               uint32           __c1 = (crc).crc1;\
+               uint32           __c2 = (crc).crc2;\
+               char            *__data = (char *) (data);\
+               uint32           __len = (len);\
 \
-        while (__len >= 2)\
-        {\
-                __c1 = crc_tableV0[(__c1 ^ *__data++) & 0xff] ^ (__c1 >> 8);\
-                __c2 = crc_tableV0[(__c2 ^ *__data++) & 0xff] ^ (__c2 >> 8);\
-                __len -= 2;\
-        }\
-        if (__len > 0)\
-                __c1 = crc_tableV0[(__c1 ^ *__data++) & 0xff] ^ (__c1 >> 8);\
-        (crc).crc1 = __c1;\
-        (crc).crc2 = __c2;\
+               while (__len >= 2)\
+               {\
+                               __c1 = crc_tableV0[(__c1 ^ *__data++) & 0xff] ^ (__c1 >> 8);\
+                               __c2 = crc_tableV0[(__c2 ^ *__data++) & 0xff] ^ (__c2 >> 8);\
+                               __len -= 2;\
+               }\
+               if (__len > 0)\
+                               __c1 = crc_tableV0[(__c1 ^ *__data++) & 0xff] ^ (__c1 >> 8);\
+               (crc).crc1 = __c1;\
+               (crc).crc2 = __c2;\
 }
 
 #define EQ_CRC64V0(c1,c2)  ((c1).crc1 == (c2).crc1 && (c1).crc2 == (c2).crc2)
@@ -295,51 +298,51 @@ static uint32 crc_tableV0[] = {
 
 typedef struct ControlFileDataV0
 {
-       crc64V0                 crc;
-       uint32                  logId;          /* current log file id */
-       uint32                  logSeg;         /* current log file segment (1-based) */
-       XLogRecPtr              checkPoint;     /* last check point record ptr */
-       time_t                  time;           /* time stamp of last modification */
-       DBState                 state;          /* see enum above */
-       uint32                  blcksz;         /* block size for this DB */
-       uint32                  relseg_size; /* blocks per segment of large relation */
-       uint32                  catalog_version_no;     /* internal version number */
-       char                    lc_collate[LOCALE_NAME_BUFLEN_V0];
-       char                    lc_ctype[LOCALE_NAME_BUFLEN_V0];
-       char                    archdir[MAXPGPATH];     /* where to move offline log files */
-} ControlFileDataV0;
+       crc64V0         crc;
+       uint32          logId;                  /* current log file id */
+       uint32          logSeg;                 /* current log file segment (1-based) */
+       XLogRecPtr      checkPoint;             /* last check point record ptr */
+       time_t          time;                   /* time stamp of last modification */
+       DBState         state;                  /* see enum above */
+       uint32          blcksz;                 /* block size for this DB */
+       uint32          relseg_size;    /* blocks per segment of large relation */
+       uint32          catalog_version_no;             /* internal version number */
+       char            lc_collate[LOCALE_NAME_BUFLEN_V0];
+       char            lc_ctype[LOCALE_NAME_BUFLEN_V0];
+       char            archdir[MAXPGPATH];             /* where to move offline log files */
+}                      ControlFileDataV0;
 
 typedef struct CheckPointV0
 {
-       XLogRecPtr              redo;           /* next RecPtr available when we */
-                                                               /* began to create CheckPoint */
-                                                               /* (i.e. REDO start point) */
-       XLogRecPtr              undo;           /* first record of oldest in-progress */
-                                                               /* transaction when we started */
-                                                               /* (i.e. UNDO end point) */
-       StartUpID               ThisStartUpID;
-       TransactionId   nextXid;
-       Oid                             nextOid;
-       bool                    Shutdown;
-} CheckPointV0;
+       XLogRecPtr      redo;                   /* next RecPtr available when we */
+       /* began to create CheckPoint */
+       /* (i.e. REDO start point) */
+       XLogRecPtr      undo;                   /* first record of oldest in-progress */
+       /* transaction when we started */
+       /* (i.e. UNDO end point) */
+       StartUpID       ThisStartUpID;
+       TransactionId nextXid;
+       Oid                     nextOid;
+       bool            Shutdown;
+}                      CheckPointV0;
 
 typedef struct XLogRecordV0
 {
-       crc64V0                 xl_crc;
-       XLogRecPtr              xl_prev;        /* ptr to previous record in log */
-       XLogRecPtr              xl_xact_prev; /* ptr to previous record of this xact */
-       TransactionId   xl_xid;         /* xact id */
-       uint16                  xl_len;         /* total len of record *data* */
-       uint8                   xl_info;
-       RmgrId                  xl_rmid;        /* resource manager inserted this record */
-} XLogRecordV0;
+       crc64V0         xl_crc;
+       XLogRecPtr      xl_prev;                /* ptr to previous record in log */
+       XLogRecPtr      xl_xact_prev;   /* ptr to previous record of this xact */
+       TransactionId xl_xid;           /* xact id */
+       uint16          xl_len;                 /* total len of record *data* */
+       uint8           xl_info;
+       RmgrId          xl_rmid;                /* resource manager inserted this record */
+}                      XLogRecordV0;
 
 #define SizeOfXLogRecordV0     DOUBLEALIGN(sizeof(XLogRecordV0))
 
 typedef struct XLogContRecordV0
 {
-       uint16                  xl_len;         /* len of data left */
-} XLogContRecordV0;
+       uint16          xl_len;                 /* len of data left */
+}                      XLogContRecordV0;
 
 #define SizeOfXLogContRecordV0 DOUBLEALIGN(sizeof(XLogContRecordV0))
 
@@ -347,16 +350,16 @@ typedef struct XLogContRecordV0
 
 typedef struct XLogPageHeaderDataV0
 {
-       uint32                xlp_magic;
-       uint16                xlp_info;
-} XLogPageHeaderDataV0;
+       uint32          xlp_magic;
+       uint16          xlp_info;
+}                      XLogPageHeaderDataV0;
 
 #define SizeOfXLogPHDV0   DOUBLEALIGN(sizeof(XLogPageHeaderDataV0))
 
 typedef XLogPageHeaderDataV0 *XLogPageHeaderV0;
 
 
-static bool RecordIsValidV0(XLogRecordV0 *record);
+static bool RecordIsValidV0(XLogRecordV0 * record);
 static XLogRecordV0 *ReadRecordV0(XLogRecPtr *RecPtr, char *buffer);
 static bool ValidXLOGHeaderV0(XLogPageHeaderV0 hdr);
 
@@ -376,7 +379,7 @@ CheckControlVersion0(char *buffer, int len)
                return false;
        /* Check CRC the version-0 way. */
        INIT_CRC64V0(crc);
-       COMP_CRC64V0(crc, 
+       COMP_CRC64V0(crc,
                                 buffer + sizeof(crc64V0),
                                 sizeof(ControlFileDataV0) - sizeof(crc64V0));
        FIN_CRC64V0(crc);
@@ -409,12 +412,13 @@ CheckControlVersion0(char *buffer, int len)
                                                  (char *) malloc(_INTL_MAXLOGRECSZ));
        if (record == NULL)
        {
+
                /*
                 * We have to guess at the checkpoint contents.
                 */
                guessed = true;
                ControlFile.checkPointCopy.ThisStartUpID = 0;
-               ControlFile.checkPointCopy.nextXid = (TransactionId) 514; /* XXX */
+               ControlFile.checkPointCopy.nextXid = (TransactionId) 514;               /* XXX */
                ControlFile.checkPointCopy.nextOid = BootstrapObjectIdData;
                return true;
        }
@@ -435,26 +439,26 @@ CheckControlVersion0(char *buffer, int len)
  * We assume all of the record has been read into memory at *record.
  */
 static bool
-RecordIsValidV0(XLogRecordV0 *record)
+RecordIsValidV0(XLogRecordV0 * record)
 {
        crc64V0         crc;
        uint32          len = record->xl_len;
 
        /*
         * NB: this code is not right for V0 records containing backup blocks,
-        * but for now it's only going to be applied to checkpoint records,
-        * so I'm not going to worry about it...
+        * but for now it's only going to be applied to checkpoint records, so
+        * I'm not going to worry about it...
         */
        INIT_CRC64V0(crc);
        COMP_CRC64V0(crc, XLogRecGetData(record), len);
-       COMP_CRC64V0(crc, (char*) record + sizeof(crc64V0),
+       COMP_CRC64V0(crc, (char *) record + sizeof(crc64V0),
                                 SizeOfXLogRecordV0 - sizeof(crc64V0));
        FIN_CRC64V0(crc);
 
        if (!EQ_CRC64V0(record->xl_crc, crc))
                return false;
 
-       return(true);
+       return (true);
 }
 
 /*
@@ -489,7 +493,7 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer)
                readFile = XLogFileOpen(readId, readSeg);
                if (readFile < 0)
                        goto next_record_is_invalid;
-               readOff = (uint32) (-1); /* force read to occur below */
+               readOff = (uint32) (-1);/* force read to occur below */
        }
 
        targetPageOff = ((RecPtr->xrecoff % XLogSegSize) / BLCKSZ) * BLCKSZ;
@@ -510,10 +514,13 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer)
 
        if (record->xl_len == 0)
                goto next_record_is_invalid;
+
        /*
-        * Compute total length of record including any appended backup blocks.
+        * Compute total length of record including any appended backup
+        * blocks.
         */
        total_len = SizeOfXLogRecordV0 + record->xl_len;
+
        /*
         * Make sure it will fit in buffer (currently, it is mechanically
         * impossible for this test to fail, but it seems like a good idea
@@ -526,7 +533,7 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer)
        {
                /* Need to reassemble record */
                XLogContRecordV0 *contrecord;
-               uint32                  gotlen = len;
+               uint32          gotlen = len;
 
                memcpy(buffer, record, len);
                record = (XLogRecordV0 *) buffer;
@@ -551,13 +558,13 @@ ReadRecordV0(XLogRecPtr *RecPtr, char *buffer)
                        if (!(((XLogPageHeaderV0) readBuf)->xlp_info & XLP_FIRST_IS_CONTRECORD))
                                goto next_record_is_invalid;
                        contrecord = (XLogContRecordV0 *) ((char *) readBuf + SizeOfXLogPHDV0);
-                       if (contrecord->xl_len == 0 || 
+                       if (contrecord->xl_len == 0 ||
                                total_len != (contrecord->xl_len + gotlen))
                                goto next_record_is_invalid;
                        len = BLCKSZ - SizeOfXLogPHDV0 - SizeOfXLogContRecordV0;
                        if (contrecord->xl_len > len)
                        {
-                               memcpy(buffer, (char *)contrecord + SizeOfXLogContRecordV0, len);
+                               memcpy(buffer, (char *) contrecord + SizeOfXLogContRecordV0, len);
                                gotlen += len;
                                buffer += len;
                                continue;
@@ -587,7 +594,7 @@ next_record_is_invalid:;
  * Check whether the xlog header of a page just read in looks valid.
  *
  * This is just a convenience subroutine to avoid duplicated code in
- * ReadRecord.  It's not intended for use from anywhere else.
+ * ReadRecord. It's not intended for use from anywhere else.
  */
 static bool
 ValidXLOGHeaderV0(XLogPageHeaderV0 hdr)
@@ -610,6 +617,7 @@ GuessControlValues(void)
 {
 #ifdef USE_LOCALE
        char       *localeptr;
+
 #endif
 
        /*
@@ -625,7 +633,7 @@ GuessControlValues(void)
        ControlFile.checkPointCopy.redo.xrecoff = SizeOfXLogPHD;
        ControlFile.checkPointCopy.undo = ControlFile.checkPointCopy.redo;
        ControlFile.checkPointCopy.ThisStartUpID = 0;
-       ControlFile.checkPointCopy.nextXid = (TransactionId) 514; /* XXX */
+       ControlFile.checkPointCopy.nextXid = (TransactionId) 514;       /* XXX */
        ControlFile.checkPointCopy.nextOid = BootstrapObjectIdData;
        ControlFile.checkPointCopy.time = time(NULL);
 
@@ -677,7 +685,7 @@ PrintControlValues(void)
                   "pg_control version number:            %u\n"
                   "Catalog version number:               %u\n"
                   "Current log file id:                  %u\n"
-              "Next log file segment:                %u\n"
+                  "Next log file segment:                %u\n"
                   "Latest checkpoint's StartUpID:        %u\n"
                   "Latest checkpoint's NextXID:          %u\n"
                   "Latest checkpoint's NextOID:          %u\n"
@@ -707,11 +715,11 @@ static void
 RewriteControlFile(void)
 {
        int                     fd;
-       char            buffer[BLCKSZ]; /* need not be aligned */
+       char            buffer[BLCKSZ]; /* need not be aligned */
 
        /*
-        * Adjust fields as needed to force an empty XLOG starting at the
-        * next available segment.
+        * Adjust fields as needed to force an empty XLOG starting at the next
+        * available segment.
         */
        newXlogId = ControlFile.logId;
        newXlogSeg = ControlFile.logSeg;
@@ -734,17 +742,17 @@ RewriteControlFile(void)
 
        /* Contents are protected with a CRC */
        INIT_CRC64(ControlFile.crc);
-       COMP_CRC64(ControlFile.crc, 
-                          (char*) &ControlFile + sizeof(crc64),
+       COMP_CRC64(ControlFile.crc,
+                          (char *) &ControlFile + sizeof(crc64),
                           sizeof(ControlFileData) - sizeof(crc64));
        FIN_CRC64(ControlFile.crc);
 
        /*
-        * We write out BLCKSZ bytes into pg_control, zero-padding the
-        * excess over sizeof(ControlFileData).  This reduces the odds
-        * of premature-EOF errors when reading pg_control.  We'll still
-        * fail when we check the contents of the file, but hopefully with
-        * a more specific error than "couldn't read pg_control".
+        * We write out BLCKSZ bytes into pg_control, zero-padding the excess
+        * over sizeof(ControlFileData).  This reduces the odds of
+        * premature-EOF errors when reading pg_control.  We'll still fail
+        * when we check the contents of the file, but hopefully with a more
+        * specific error than "couldn't read pg_control".
         */
        if (sizeof(ControlFileData) > BLCKSZ)
        {
@@ -786,9 +794,9 @@ RewriteControlFile(void)
 static void
 KillExistingXLOG(void)
 {
-       DIR                        *xldir;
-       struct dirent  *xlde;
-       char                    path[MAXPGPATH];
+       DIR                *xldir;
+       struct dirent *xlde;
+       char            path[MAXPGPATH];
 
        xldir = opendir(XLogDir);
        if (xldir == NULL)
@@ -803,7 +811,7 @@ KillExistingXLOG(void)
                if (strlen(xlde->d_name) == 16 &&
                        strspn(xlde->d_name, "0123456789ABCDEF") == 16)
                {
-                       sprintf(path, "%s%c%s", XLogDir, SEP_CHAR, xlde->d_name);
+                       sprintf(path, "%s%c%s", XLogDir, SEP_CHAR, xlde->d_name);
                        if (unlink(path) < 0)
                        {
                                perror(path);
@@ -858,7 +866,7 @@ WriteEmptyXLOG(void)
 
        INIT_CRC64(crc);
        COMP_CRC64(crc, &ControlFile.checkPointCopy, sizeof(CheckPoint));
-       COMP_CRC64(crc, (char*) record + sizeof(crc64),
+       COMP_CRC64(crc, (char *) record + sizeof(crc64),
                           SizeOfXLogRecord - sizeof(crc64));
        FIN_CRC64(crc);
        record->xl_crc = crc;
@@ -914,13 +922,13 @@ usage(void)
 
 
 int
-main(int argc, char ** argv)
+main(int argc, char **argv)
 {
-       int             argn;
-       bool    force = false;
-       bool    noupdate = false;
-       int             fd;
-       char    path[MAXPGPATH];
+       int                     argn;
+       bool            force = false;
+       bool            noupdate = false;
+       int                     fd;
+       char            path[MAXPGPATH];
 
        for (argn = 1; argn < argc; argn++)
        {
@@ -934,7 +942,7 @@ main(int argc, char ** argv)
                        usage();
        }
 
-       if (argn != argc-1)                     /* one required non-switch argument */
+       if (argn != argc - 1)           /* one required non-switch argument */
                usage();
 
        DataDir = argv[argn++];
@@ -946,7 +954,8 @@ main(int argc, char ** argv)
 
        /*
         * Check for a postmaster lock file --- if there is one, refuse to
-        * proceed, on grounds we might be interfering with a live installation.
+        * proceed, on grounds we might be interfering with a live
+        * installation.
         */
        snprintf(path, MAXPGPATH, "%s%cpostmaster.pid", DataDir, SEP_CHAR);
 
@@ -973,8 +982,8 @@ main(int argc, char ** argv)
                GuessControlValues();
 
        /*
-        * If we had to guess anything, and -f was not given, just print
-        * the guessed values and exit.  Also print if -n is given.
+        * If we had to guess anything, and -f was not given, just print the
+        * guessed values and exit.  Also print if -n is given.
         */
        if ((guessed && !force) || noupdate)
        {
index 0ad0a8f56ce60ad34b8f8bd64d87c756ecea0fc0..b6db217c836ed3a794de0adb864431ac2533b30c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * encode.c
  *             Various data encoding/decoding things.
- * 
+ *
  * Copyright (c) 2001 Marko Kreen
  * All rights reserved.
  *
@@ -9,15 +9,15 @@
  * 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.
+ *       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.
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE AUTHOR 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)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: encode.c,v 1.3 2001/02/10 02:31:25 tgl Exp $
+ * $Id: encode.c,v 1.4 2001/03/22 03:59:10 momjian Exp $
  */
 
 #include "postgres.h"
@@ -43,9 +43,9 @@
 #endif
 
 static pg_coding *
-find_coding(pg_coding *hbuf, text *name, int silent);
+                       find_coding(pg_coding * hbuf, text *name, int silent);
 static pg_coding *
-pg_find_coding(pg_coding *res, char *name);
+                       pg_find_coding(pg_coding * res, char *name);
 
 
 /* SQL function: encode(bytea, text) returns text */
@@ -54,34 +54,37 @@ PG_FUNCTION_INFO_V1(encode);
 Datum
 encode(PG_FUNCTION_ARGS)
 {
-       text *arg;
-       text *name;
-       uint len, rlen, rlen0;
-       pg_coding *c, cbuf;
-       text *res;
-       
+       text       *arg;
+       text       *name;
+       uint            len,
+                               rlen,
+                               rlen0;
+       pg_coding  *c,
+                               cbuf;
+       text       *res;
+
        if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
                PG_RETURN_NULL();
-       
-       name = PG_GETARG_TEXT_P(1);     
-       c = find_coding(&cbuf, name, 0); /* will give error if fails */
+
+       name = PG_GETARG_TEXT_P(1);
+       c = find_coding(&cbuf, name, 0);        /* will give error if fails */
 
        arg = PG_GETARG_TEXT_P(0);
        len = VARSIZE(arg) - VARHDRSZ;
-       
+
        rlen0 = c->encode_len(len);
-       
-       res = (text *)palloc(rlen0 + VARHDRSZ);
-       
+
+       res = (text *) palloc(rlen0 + VARHDRSZ);
+
        rlen = c->encode(VARDATA(arg), len, VARDATA(res));
        VARATT_SIZEP(res) = rlen + VARHDRSZ;
 
        if (rlen > rlen0)
                elog(FATAL, "pg_encode: overflow, encode estimate too small");
-       
+
        PG_FREE_IF_COPY(arg, 0);
        PG_FREE_IF_COPY(name, 1);
-       
+
        PG_RETURN_TEXT_P(res);
 }
 
@@ -91,54 +94,58 @@ PG_FUNCTION_INFO_V1(decode);
 Datum
 decode(PG_FUNCTION_ARGS)
 {
-       text *arg;
-       text *name;
-       uint len, rlen, rlen0;
-       pg_coding *c, cbuf;
-       text *res;
-       
+       text       *arg;
+       text       *name;
+       uint            len,
+                               rlen,
+                               rlen0;
+       pg_coding  *c,
+                               cbuf;
+       text       *res;
+
        if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
                PG_RETURN_NULL();
-       
-       name = PG_GETARG_TEXT_P(1);     
-       c = find_coding(&cbuf, name, 0); /* will give error if fails */
+
+       name = PG_GETARG_TEXT_P(1);
+       c = find_coding(&cbuf, name, 0);        /* will give error if fails */
 
        arg = PG_GETARG_TEXT_P(0);
        len = VARSIZE(arg) - VARHDRSZ;
-       
+
        rlen0 = c->decode_len(len);
-       
-       res = (text *)palloc(rlen0 + VARHDRSZ);
-       
+
+       res = (text *) palloc(rlen0 + VARHDRSZ);
+
        rlen = c->decode(VARDATA(arg), len, VARDATA(res));
        VARATT_SIZEP(res) = rlen + VARHDRSZ;
 
        if (rlen > rlen0)
                elog(FATAL, "pg_decode: overflow, decode estimate too small");
-       
+
        PG_FREE_IF_COPY(arg, 0);
        PG_FREE_IF_COPY(name, 1);
-       
+
        PG_RETURN_TEXT_P(res);
 }
 
 static pg_coding *
-find_coding(pg_coding *dst, text *name, int silent)
+find_coding(pg_coding * dst, text *name, int silent)
 {
-       pg_coding *p;
-       char buf[NAMEDATALEN];
-       uint len;
-       
+       pg_coding  *p;
+       char            buf[NAMEDATALEN];
+       uint            len;
+
        len = VARSIZE(name) - VARHDRSZ;
-       if (len >= NAMEDATALEN) {
+       if (len >= NAMEDATALEN)
+       {
                if (silent)
                        return NULL;
                elog(ERROR, "Encoding type does not exist (name too long)");
        }
-               
+
        memcpy(buf, VARDATA(name), len);
        buf[len] = 0;
-       
+
        p = pg_find_coding(dst, buf);
 
        if (p == NULL && !silent)
@@ -151,21 +158,23 @@ static char *hextbl = "0123456789abcdef";
 uint
 hex_encode(uint8 *src, uint len, uint8 *dst)
 {
-       uint8 *end = src + len;
-       while (src < end) {
+       uint8      *end = src + len;
+
+       while (src < end)
+       {
                *dst++ = hextbl[(*src >> 4) & 0xF];
                *dst++ = hextbl[*src & 0xF];
                src++;
        }
-       return len*2;
+       return len * 2;
 }
 
 /* probably should use lookup table */
 static uint8
 get_hex(char c)
 {
-       uint8 res = 0;
-       
+       uint8           res = 0;
+
        if (c >= '0' && c <= '9')
                res = c - '0';
        else if (c >= 'a' && c <= 'f')
@@ -174,19 +183,26 @@ get_hex(char c)
                res = c - 'A' + 10;
        else
                elog(ERROR, "Bad hex code: '%c'", c);
-       
+
        return res;
 }
 
 uint
 hex_decode(uint8 *src, uint len, uint8 *dst)
 {
-       uint8 *s, *srcend, v1, v2, *p = dst;
-       
+       uint8      *s,
+                          *srcend,
+                               v1,
+                               v2,
+                          *p = dst;
+
        srcend = src + len;
-       s = src; p = dst;
-       while (s < srcend) {
-               if (*s == ' ' || *s == '\n' || *s == '\t' || *s == '\r') {
+       s = src;
+       p = dst;
+       while (s < srcend)
+       {
+               if (*s == ' ' || *s == '\n' || *s == '\t' || *s == '\r')
+               {
                        s++;
                        continue;
                }
@@ -196,30 +212,36 @@ hex_decode(uint8 *src, uint len, uint8 *dst)
                v2 = get_hex(*s++);
                *p++ = v1 | v2;
        }
-       
+
        return p - dst;
 }
 
 
 static unsigned char _base64[] =
-       "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
 uint
 b64_encode(uint8 *src, uint len, uint8 *dst)
 {
-       uint8 *s, *p, *end = src + len, *lend = dst + 76;
-       int pos = 2;
+       uint8      *s,
+                          *p,
+                          *end = src + len,
+                          *lend = dst + 76;
+       int                     pos = 2;
        unsigned long buf = 0;
 
-       s = src; p = dst;
-       
-       while (s < end) {
+       s = src;
+       p = dst;
+
+       while (s < end)
+       {
                buf |= *s << (pos << 3);
                pos--;
                s++;
-               
+
                /* write it out */
-               if (pos < 0) {
+               if (pos < 0)
+               {
                        *p++ = _base64[(buf >> 18) & 0x3f];
                        *p++ = _base64[(buf >> 12) & 0x3f];
                        *p++ = _base64[(buf >> 6) & 0x3f];
@@ -228,12 +250,14 @@ b64_encode(uint8 *src, uint len, uint8 *dst)
                        pos = 2;
                        buf = 0;
                }
-               if (p >= lend) {
+               if (p >= lend)
+               {
                        *p++ = '\n';
                        lend = p + 76;
                }
        }
-       if (pos != 2) {
+       if (pos != 2)
+       {
                *p++ = _base64[(buf >> 18) & 0x3f];
                *p++ = _base64[(buf >> 12) & 0x3f];
                *p++ = (pos == 0) ? _base64[(buf >> 6) & 0x3f] : '=';
@@ -247,14 +271,17 @@ b64_encode(uint8 *src, uint len, uint8 *dst)
 uint
 b64_decode(uint8 *src, uint len, uint8 *dst)
 {
-       char *srcend = src + len, *s = src;
-       uint8 *p = dst;
-       char c;
-       uint b = 0;
+       char       *srcend = src + len,
+                          *s = src;
+       uint8      *p = dst;
+       char            c;
+       uint            b = 0;
        unsigned long buf = 0;
-       int pos = 0, end = 0;
-       
-       while (s < srcend) {
+       int                     pos = 0,
+                               end = 0;
+
+       while (s < srcend)
+       {
                c = *s++;
                if (c >= 'A' && c <= 'Z')
                        b = c - 'A';
@@ -266,16 +293,21 @@ b64_decode(uint8 *src, uint len, uint8 *dst)
                        b = 62;
                else if (c == '/')
                        b = 63;
-               else if (c == '=') {
+               else if (c == '=')
+               {
                        /* end sequence */
-                       if (!end) {
-                               if (pos == 2) end = 1;
-                               else if (pos == 3) end = 2;
+                       if (!end)
+                       {
+                               if (pos == 2)
+                                       end = 1;
+                               else if (pos == 3)
+                                       end = 2;
                                else
                                        elog(ERROR, "base64: unexpected '='");
                        }
                        b = 0;
-               } else if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
+               }
+               else if (c == ' ' || c == '\t' || c == '\n' || c == '\r')
                        continue;
                else
                        elog(ERROR, "base64: Invalid symbol");
@@ -283,7 +315,8 @@ b64_decode(uint8 *src, uint len, uint8 *dst)
                /* add it to buffer */
                buf = (buf << 6) + b;
                pos++;
-               if (pos == 4) {
+               if (pos == 4)
+               {
                        *p++ = (buf >> 16) & 255;
                        if (end == 0 || end > 1)
                                *p++ = (buf >> 8) & 255;
@@ -326,21 +359,22 @@ b64_dec_len(uint srclen)
 }
 
 static pg_coding
-encoding_list [] = {
-       { "hex", hex_enc_len, hex_dec_len, hex_encode, hex_decode},
-       { "base64", b64_enc_len, b64_dec_len, b64_encode, b64_decode},
-       { NULL, NULL, NULL, NULL, NULL}
+                       encoding_list[] = {
+       {"hex", hex_enc_len, hex_dec_len, hex_encode, hex_decode},
+       {"base64", b64_enc_len, b64_dec_len, b64_encode, b64_decode},
+       {NULL, NULL, NULL, NULL, NULL}
 };
 
 
 static pg_coding *
-pg_find_coding(pg_coding *res, char *name)
+pg_find_coding(pg_coding * res, char *name)
 {
-       pg_coding *p;
-       for (p = encoding_list; p->name; p++) {
+       pg_coding  *p;
+
+       for (p = encoding_list; p->name; p++)
+       {
                if (!strcasecmp(p->name, name))
                        return p;
        }
        return NULL;
 }
-
index 33e6508cb1e6d5a725108c2c975410ccfaeb3e75..451e06d75b0afef6a6a732609dba635624904df5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * pg_encode.h
  *             encode.c
- * 
+ *
  * Copyright (c) 2001 Marko Kreen
  * All rights reserved.
  *
@@ -9,15 +9,15 @@
  * 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.
+ *       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.
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE AUTHOR 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)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: encode.h,v 1.1 2001/01/24 03:46:16 momjian Exp $
+ * $Id: encode.h,v 1.2 2001/03/22 03:59:10 momjian Exp $
  */
 
 #ifndef __PG_ENCODE_H
 #define __PG_ENCODE_H
 
 /* exported functions */
-Datum encode(PG_FUNCTION_ARGS);
-Datum decode(PG_FUNCTION_ARGS);
+Datum          encode(PG_FUNCTION_ARGS);
+Datum          decode(PG_FUNCTION_ARGS);
 
 typedef struct _pg_coding pg_coding;
-struct _pg_coding {
-       char *name;
-       uint (*encode_len)(uint dlen);
-       uint (*decode_len)(uint dlen);
-       uint (*encode)(uint8 *data, uint dlen, uint8 *res);
-       uint (*decode)(uint8 *data, uint dlen, uint8 *res);
+struct _pg_coding
+{
+       char       *name;
+       uint            (*encode_len) (uint dlen);
+       uint            (*decode_len) (uint dlen);
+       uint            (*encode) (uint8 *data, uint dlen, uint8 *res);
+       uint            (*decode) (uint8 *data, uint dlen, uint8 *res);
 };
 
 /* They are for outside usage in C code, if needed */
-uint hex_encode(uint8 *src, uint len, uint8 *dst);
-uint hex_decode(uint8 *src, uint len, uint8 *dst);
-uint b64_encode(uint8 *src, uint len, uint8 *dst);
-uint b64_decode(uint8 *src, uint len, uint8 *dst);
-
-uint hex_enc_len(uint srclen);
-uint hex_dec_len(uint srclen);
-uint b64_enc_len(uint srclen);
-uint b64_dec_len(uint srclen);
+uint           hex_encode(uint8 *src, uint len, uint8 *dst);
+uint           hex_decode(uint8 *src, uint len, uint8 *dst);
+uint           b64_encode(uint8 *src, uint len, uint8 *dst);
+uint           b64_decode(uint8 *src, uint len, uint8 *dst);
 
-#endif /* __PG_ENCODE_H */
+uint           hex_enc_len(uint srclen);
+uint           hex_dec_len(uint srclen);
+uint           b64_enc_len(uint srclen);
+uint           b64_dec_len(uint srclen);
 
+#endif  /* __PG_ENCODE_H */
index 3c6e6fc80b7bb12ed191524444f41673eebe292a..2d4a52717e0228237d20654191cc8adc8efee603 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * internal.c
  *             Wrapper for builtin functions
- * 
+ *
  * Copyright (c) 2000 Marko Kreen
  * All rights reserved.
  *
@@ -9,15 +9,15 @@
  * 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.
+ *       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.
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE AUTHOR 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)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: internal.c,v 1.2 2001/02/10 02:31:25 tgl Exp $
+ * $Id: internal.c,v 1.3 2001/03/22 03:59:10 momjian Exp $
  */
 
 #include "postgres.h"
 #endif
 
 static uint
-pg_md5_len(pg_digest *h);
+                       pg_md5_len(pg_digest * h);
 static uint8 *
-pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
+                       pg_md5_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
 
 static uint
-pg_sha1_len(pg_digest *h);
+                       pg_sha1_len(pg_digest * h);
 static uint8 *
-pg_sha1_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
+                       pg_sha1_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
 
 static pg_digest
-int_digest_list [] = {
-       { "md5", pg_md5_len, pg_md5_digest, {0}},
-       { "sha1", pg_sha1_len, pg_sha1_digest, {0}},
-       { NULL, NULL, NULL, {0}}
+                       int_digest_list[] = {
+       {"md5", pg_md5_len, pg_md5_digest, {0}},
+       {"sha1", pg_sha1_len, pg_sha1_digest, {0}},
+       {NULL, NULL, NULL, {0}}
 };
 
 static uint
-pg_md5_len(pg_digest *h) {
+pg_md5_len(pg_digest * h)
+{
        return MD5_DIGEST_LENGTH;
 }
 
 static uint8 *
-pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
+pg_md5_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
 {
-       MD5_CTX ctx;
+       MD5_CTX         ctx;
 
        MD5Init(&ctx);
        MD5Update(&ctx, src, len);
@@ -83,32 +84,31 @@ pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
 }
 
 static uint
-pg_sha1_len(pg_digest *h) {
+pg_sha1_len(pg_digest * h)
+{
        return SHA1_DIGEST_LENGTH;
 }
 
 static uint8 *
-pg_sha1_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
+pg_sha1_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
 {
-       SHA1_CTX ctx;
+       SHA1_CTX        ctx;
 
        SHA1Init(&ctx);
        SHA1Update(&ctx, src, len);
        SHA1Final(buf, &ctx);
-       
+
        return buf;
 }
 
 
-pg_digest *
-pg_find_digest(pg_digest *h, char *name)
+pg_digest  *
+pg_find_digest(pg_digest * h, char *name)
 {
-       pg_digest *p;
+       pg_digest  *p;
 
        for (p = int_digest_list; p->name; p++)
                if (!strcasecmp(p->name, name))
                        return p;
        return NULL;
 }
-
-
index 14ac44b29d33bc35d0ccfb77fe54dc0ff3156180..95df07ca27cd801dc7766d933bd4c7575e462c3f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * krb.c
  *             Wrapper for Kerberos5 libdes SHA1/MD5.
- * 
+ *
  * Copyright (c) 2000 Marko Kreen
  * All rights reserved.
  *
@@ -9,15 +9,15 @@
  * 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.
+ *       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.
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE AUTHOR 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)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * 
+ *
  * NOTES
  *     It is possible that this works with other SHA1/MD5
  *     implementations too.
  *
- * $Id: krb.c,v 1.3 2001/02/20 15:34:14 momjian Exp $
+ * $Id: krb.c,v 1.4 2001/03/22 03:59:10 momjian Exp $
  */
 
 #include "postgres.h"
 #endif
 
 static uint
-pg_md5_len(pg_digest *h);
+                       pg_md5_len(pg_digest * h);
 static uint8 *
-pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
+                       pg_md5_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
 
 static uint
-pg_sha1_len(pg_digest *h);
+                       pg_sha1_len(pg_digest * h);
 static uint8 *
-pg_sha1_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
+                       pg_sha1_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
 
 static pg_digest
-int_digest_list [] = {
-       { "md5", pg_md5_len, pg_md5_digest, {0}},
-       { "sha1", pg_sha1_len, pg_sha1_digest, {0}},
-       { NULL, NULL, NULL, {0}}
+                       int_digest_list[] = {
+       {"md5", pg_md5_len, pg_md5_digest, {0}},
+       {"sha1", pg_sha1_len, pg_sha1_digest, {0}},
+       {NULL, NULL, NULL, {0}}
 };
 
 static uint
-pg_md5_len(pg_digest *h) {
+pg_md5_len(pg_digest * h)
+{
        return MD5_DIGEST_LENGTH;
 }
 
 static uint8 *
-pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
+pg_md5_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
 {
-       MD5_CTX ctx;
+       MD5_CTX         ctx;
 
        MD5Init(&ctx);
        MD5Update(&ctx, src, len);
@@ -88,32 +89,31 @@ pg_md5_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
 }
 
 static uint
-pg_sha1_len(pg_digest *h) {
+pg_sha1_len(pg_digest * h)
+{
        return SHA1_DIGEST_LENGTH;
 }
 
 static uint8 *
-pg_sha1_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
+pg_sha1_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
 {
-       SHA1_CTX ctx;
+       SHA1_CTX        ctx;
 
        SHA1Init(&ctx);
        SHA1Update(&ctx, src, len);
        SHA1Final(buf, &ctx);
-       
+
        return buf;
 }
 
 
-pg_digest *
-pg_find_digest(pg_digest *h, char *name)
+pg_digest  *
+pg_find_digest(pg_digest * h, char *name)
 {
-       pg_digest *p;
+       pg_digest  *p;
 
        for (p = int_digest_list; p->name; p++)
                if (!strcasecmp(p->name, name))
                        return p;
        return NULL;
 }
-
-
index d53872023126750dae06a0ffd83c2561fff3cd15..a5cfae34970332707f431100a5228159d73236a0 100644 (file)
@@ -1,5 +1,5 @@
-/*     $Id: md5.c,v 1.4 2001/02/10 02:31:25 tgl Exp $  */
-/*     $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $     */
+/*     $Id: md5.c,v 1.5 2001/03/22 03:59:10 momjian Exp $      */
+/*        $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -9,18 +9,18 @@
  * 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.
+ *       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.
+ *       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 project nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE PROJECT 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)
 /* Integer part of 4294967296 times abs(sin(i)), where i is in radians. */
 static const uint32 T[65] = {
        0,
-       0xd76aa478,     0xe8c7b756,     0x242070db,     0xc1bdceee,
-       0xf57c0faf,     0x4787c62a,     0xa8304613,     0xfd469501,
-       0x698098d8,     0x8b44f7af,     0xffff5bb1,     0x895cd7be,
-       0x6b901122,     0xfd987193,     0xa679438e,     0x49b40821,
-
-       0xf61e2562,     0xc040b340,     0x265e5a51,     0xe9b6c7aa,
-       0xd62f105d,     0x2441453,      0xd8a1e681,     0xe7d3fbc8,
-       0x21e1cde6,     0xc33707d6,     0xf4d50d87,     0x455a14ed,
-       0xa9e3e905,     0xfcefa3f8,     0x676f02d9,     0x8d2a4c8a,
-
-       0xfffa3942,     0x8771f681,     0x6d9d6122,     0xfde5380c,
-       0xa4beea44,     0x4bdecfa9,     0xf6bb4b60,     0xbebfbc70,
-       0x289b7ec6,     0xeaa127fa,     0xd4ef3085,     0x4881d05,
-       0xd9d4d039,     0xe6db99e5,     0x1fa27cf8,     0xc4ac5665,
-
-       0xf4292244,     0x432aff97,     0xab9423a7,     0xfc93a039,
-       0x655b59c3,     0x8f0ccc92,     0xffeff47d,     0x85845dd1,
-       0x6fa87e4f,     0xfe2ce6e0,     0xa3014314,     0x4e0811a1,
-       0xf7537e82,     0xbd3af235,     0x2ad7d2bb,     0xeb86d391,
+       0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,
+       0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501,
+       0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be,
+       0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821,
+
+       0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa,
+       0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8,
+       0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed,
+       0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a,
+
+       0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c,
+       0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70,
+       0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x4881d05,
+       0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665,
+
+       0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039,
+       0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1,
+       0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1,
+       0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391,
 };
 
 static const uint8 md5_paddat[MD5_BUFLEN] = {
-       0x80,   0,      0,      0,      0,      0,      0,      0,
-       0,      0,      0,      0,      0,      0,      0,      0,
-       0,      0,      0,      0,      0,      0,      0,      0,
-       0,      0,      0,      0,      0,      0,      0,      0,
-       0,      0,      0,      0,      0,      0,      0,      0,
-       0,      0,      0,      0,      0,      0,      0,      0,
-       0,      0,      0,      0,      0,      0,      0,      0,
-       0,      0,      0,      0,      0,      0,      0,      0,      
+       0x80, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
+       0, 0, 0, 0, 0, 0, 0, 0,
 };
 
-static void md5_calc (uint8 *, md5_ctxt *);
+static void md5_calc(uint8 *, md5_ctxt *);
 
-void md5_init(ctxt)
-       md5_ctxt *ctxt;
+void
+md5_init(ctxt)
+md5_ctxt   *ctxt;
 {
        ctxt->md5_n = 0;
        ctxt->md5_i = 0;
@@ -139,56 +140,64 @@ void md5_init(ctxt)
        bzero(ctxt->md5_buf, sizeof(ctxt->md5_buf));
 }
 
-void md5_loop(ctxt, input, len)
-       md5_ctxt *ctxt;
-       uint8 *input;
-       unsigned int len; /* number of bytes */
+void
+md5_loop(ctxt, input, len)
+md5_ctxt   *ctxt;
+uint8     *input;
+unsigned int len;                              /* number of bytes */
 {
-       unsigned int gap, i;
+       unsigned int gap,
+                               i;
 
-       ctxt->md5_n += len * 8; /* byte to bit */
+       ctxt->md5_n += len * 8;         /* byte to bit */
        gap = MD5_BUFLEN - ctxt->md5_i;
 
-       if (len >= gap) {
-               bcopy((void *)input, (void *)(ctxt->md5_buf + ctxt->md5_i),
-                       gap);
+       if (len >= gap)
+       {
+               bcopy((void *) input, (void *) (ctxt->md5_buf + ctxt->md5_i),
+                         gap);
                md5_calc(ctxt->md5_buf, ctxt);
 
-               for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN) {
-                       md5_calc((uint8 *)(input + i), ctxt);
-               }
-               
+               for (i = gap; i + MD5_BUFLEN <= len; i += MD5_BUFLEN)
+                       md5_calc((uint8 *) (input + i), ctxt);
+
                ctxt->md5_i = len - i;
-               bcopy((void *)(input + i), (void *)ctxt->md5_buf, ctxt->md5_i);
-       } else {
-               bcopy((void *)input, (void *)(ctxt->md5_buf + ctxt->md5_i),
-                       len);
+               bcopy((void *) (input + i), (void *) ctxt->md5_buf, ctxt->md5_i);
+       }
+       else
+       {
+               bcopy((void *) input, (void *) (ctxt->md5_buf + ctxt->md5_i),
+                         len);
                ctxt->md5_i += len;
        }
 }
 
-void md5_pad(ctxt)
-       md5_ctxt *ctxt;
+void
+md5_pad(ctxt)
+md5_ctxt   *ctxt;
 {
        unsigned int gap;
 
-       /* Don't count up padding. Keep md5_n. */       
+       /* Don't count up padding. Keep md5_n. */
        gap = MD5_BUFLEN - ctxt->md5_i;
-       if (gap > 8) {
-               bcopy((void *)md5_paddat,
-                     (void *)(ctxt->md5_buf + ctxt->md5_i),
-                     gap - sizeof(ctxt->md5_n));
-       } else {
+       if (gap > 8)
+       {
+               bcopy((void *) md5_paddat,
+                         (void *) (ctxt->md5_buf + ctxt->md5_i),
+                         gap - sizeof(ctxt->md5_n));
+       }
+       else
+       {
                /* including gap == 8 */
-               bcopy((void *)md5_paddat, (void *)(ctxt->md5_buf + ctxt->md5_i),
-                       gap);
+               bcopy((void *) md5_paddat, (void *) (ctxt->md5_buf + ctxt->md5_i),
+                         gap);
                md5_calc(ctxt->md5_buf, ctxt);
-               bcopy((void *)(md5_paddat + gap),
-                     (void *)ctxt->md5_buf,
-                     MD5_BUFLEN - sizeof(ctxt->md5_n));
+               bcopy((void *) (md5_paddat + gap),
+                         (void *) ctxt->md5_buf,
+                         MD5_BUFLEN - sizeof(ctxt->md5_n));
        }
 
-       /* 8 byte word */       
+       /* 8 byte word */
 #if BYTE_ORDER == LITTLE_ENDIAN
        bcopy(&ctxt->md5_n8[0], &ctxt->md5_buf[56], 8);
 #endif
@@ -206,98 +215,192 @@ void md5_pad(ctxt)
        md5_calc(ctxt->md5_buf, ctxt);
 }
 
-void md5_result(digest, ctxt)
-       uint8 *digest;
-       md5_ctxt *ctxt;
+void
+md5_result(digest, ctxt)
+uint8     *digest;
+md5_ctxt   *ctxt;
 {
        /* 4 byte words */
 #if BYTE_ORDER == LITTLE_ENDIAN
        bcopy(&ctxt->md5_st8[0], digest, 16);
 #endif
 #if BYTE_ORDER == BIG_ENDIAN
-       digest[ 0] = ctxt->md5_st8[ 3]; digest[ 1] = ctxt->md5_st8[ 2];
-       digest[ 2] = ctxt->md5_st8[ 1]; digest[ 3] = ctxt->md5_st8[ 0];
-       digest[ 4] = ctxt->md5_st8[ 7]; digest[ 5] = ctxt->md5_st8[ 6];
-       digest[ 6] = ctxt->md5_st8[ 5]; digest[ 7] = ctxt->md5_st8[ 4];
-       digest[ 8] = ctxt->md5_st8[11]; digest[ 9] = ctxt->md5_st8[10];
-       digest[10] = ctxt->md5_st8[ 9]; digest[11] = ctxt->md5_st8[ 8];
-       digest[12] = ctxt->md5_st8[15]; digest[13] = ctxt->md5_st8[14];
-       digest[14] = ctxt->md5_st8[13]; digest[15] = ctxt->md5_st8[12];
+       digest[0] = ctxt->md5_st8[3];
+       digest[1] = ctxt->md5_st8[2];
+       digest[2] = ctxt->md5_st8[1];
+       digest[3] = ctxt->md5_st8[0];
+       digest[4] = ctxt->md5_st8[7];
+       digest[5] = ctxt->md5_st8[6];
+       digest[6] = ctxt->md5_st8[5];
+       digest[7] = ctxt->md5_st8[4];
+       digest[8] = ctxt->md5_st8[11];
+       digest[9] = ctxt->md5_st8[10];
+       digest[10] = ctxt->md5_st8[9];
+       digest[11] = ctxt->md5_st8[8];
+       digest[12] = ctxt->md5_st8[15];
+       digest[13] = ctxt->md5_st8[14];
+       digest[14] = ctxt->md5_st8[13];
+       digest[15] = ctxt->md5_st8[12];
 #endif
 }
 
 #if BYTE_ORDER == BIG_ENDIAN
-uint32 X[16];
+uint32         X[16];
+
 #endif
 
-static void md5_calc(b64, ctxt)
-       uint8 *b64;
-       md5_ctxt *ctxt;
+static void
+md5_calc(b64, ctxt)
+uint8     *b64;
+md5_ctxt   *ctxt;
 {
-       uint32 A = ctxt->md5_sta;
-       uint32 B = ctxt->md5_stb;
-       uint32 C = ctxt->md5_stc;
-       uint32 D = ctxt->md5_std;
+       uint32          A = ctxt->md5_sta;
+       uint32          B = ctxt->md5_stb;
+       uint32          C = ctxt->md5_stc;
+       uint32          D = ctxt->md5_std;
+
 #if BYTE_ORDER == LITTLE_ENDIAN
-       uint32 *X = (uint32 *)b64;
-#endif 
+       uint32     *X = (uint32 *) b64;
+
+#endif
 #if BYTE_ORDER == BIG_ENDIAN
        /* 4 byte words */
        /* what a brute force but fast! */
-       uint8 *y = (uint8 *)X;
-       y[ 0] = b64[ 3]; y[ 1] = b64[ 2]; y[ 2] = b64[ 1]; y[ 3] = b64[ 0];
-       y[ 4] = b64[ 7]; y[ 5] = b64[ 6]; y[ 6] = b64[ 5]; y[ 7] = b64[ 4];
-       y[ 8] = b64[11]; y[ 9] = b64[10]; y[10] = b64[ 9]; y[11] = b64[ 8];
-       y[12] = b64[15]; y[13] = b64[14]; y[14] = b64[13]; y[15] = b64[12];
-       y[16] = b64[19]; y[17] = b64[18]; y[18] = b64[17]; y[19] = b64[16];
-       y[20] = b64[23]; y[21] = b64[22]; y[22] = b64[21]; y[23] = b64[20];
-       y[24] = b64[27]; y[25] = b64[26]; y[26] = b64[25]; y[27] = b64[24];
-       y[28] = b64[31]; y[29] = b64[30]; y[30] = b64[29]; y[31] = b64[28];
-       y[32] = b64[35]; y[33] = b64[34]; y[34] = b64[33]; y[35] = b64[32];
-       y[36] = b64[39]; y[37] = b64[38]; y[38] = b64[37]; y[39] = b64[36];
-       y[40] = b64[43]; y[41] = b64[42]; y[42] = b64[41]; y[43] = b64[40];
-       y[44] = b64[47]; y[45] = b64[46]; y[46] = b64[45]; y[47] = b64[44];
-       y[48] = b64[51]; y[49] = b64[50]; y[50] = b64[49]; y[51] = b64[48];
-       y[52] = b64[55]; y[53] = b64[54]; y[54] = b64[53]; y[55] = b64[52];
-       y[56] = b64[59]; y[57] = b64[58]; y[58] = b64[57]; y[59] = b64[56];
-       y[60] = b64[63]; y[61] = b64[62]; y[62] = b64[61]; y[63] = b64[60];
+       uint8      *y = (uint8 *) X;
+
+       y[0] = b64[3];
+       y[1] = b64[2];
+       y[2] = b64[1];
+       y[3] = b64[0];
+       y[4] = b64[7];
+       y[5] = b64[6];
+       y[6] = b64[5];
+       y[7] = b64[4];
+       y[8] = b64[11];
+       y[9] = b64[10];
+       y[10] = b64[9];
+       y[11] = b64[8];
+       y[12] = b64[15];
+       y[13] = b64[14];
+       y[14] = b64[13];
+       y[15] = b64[12];
+       y[16] = b64[19];
+       y[17] = b64[18];
+       y[18] = b64[17];
+       y[19] = b64[16];
+       y[20] = b64[23];
+       y[21] = b64[22];
+       y[22] = b64[21];
+       y[23] = b64[20];
+       y[24] = b64[27];
+       y[25] = b64[26];
+       y[26] = b64[25];
+       y[27] = b64[24];
+       y[28] = b64[31];
+       y[29] = b64[30];
+       y[30] = b64[29];
+       y[31] = b64[28];
+       y[32] = b64[35];
+       y[33] = b64[34];
+       y[34] = b64[33];
+       y[35] = b64[32];
+       y[36] = b64[39];
+       y[37] = b64[38];
+       y[38] = b64[37];
+       y[39] = b64[36];
+       y[40] = b64[43];
+       y[41] = b64[42];
+       y[42] = b64[41];
+       y[43] = b64[40];
+       y[44] = b64[47];
+       y[45] = b64[46];
+       y[46] = b64[45];
+       y[47] = b64[44];
+       y[48] = b64[51];
+       y[49] = b64[50];
+       y[50] = b64[49];
+       y[51] = b64[48];
+       y[52] = b64[55];
+       y[53] = b64[54];
+       y[54] = b64[53];
+       y[55] = b64[52];
+       y[56] = b64[59];
+       y[57] = b64[58];
+       y[58] = b64[57];
+       y[59] = b64[56];
+       y[60] = b64[63];
+       y[61] = b64[62];
+       y[62] = b64[61];
+       y[63] = b64[60];
 #endif
 
-       ROUND1(A, B, C, D,  0, Sa,  1); ROUND1(D, A, B, C,  1, Sb,  2);
-       ROUND1(C, D, A, B,  2, Sc,  3); ROUND1(B, C, D, A,  3, Sd,  4);
-       ROUND1(A, B, C, D,  4, Sa,  5); ROUND1(D, A, B, C,  5, Sb,  6);
-       ROUND1(C, D, A, B,  6, Sc,  7); ROUND1(B, C, D, A,  7, Sd,  8);
-       ROUND1(A, B, C, D,  8, Sa,  9); ROUND1(D, A, B, C,  9, Sb, 10);
-       ROUND1(C, D, A, B, 10, Sc, 11); ROUND1(B, C, D, A, 11, Sd, 12);
-       ROUND1(A, B, C, D, 12, Sa, 13); ROUND1(D, A, B, C, 13, Sb, 14);
-       ROUND1(C, D, A, B, 14, Sc, 15); ROUND1(B, C, D, A, 15, Sd, 16);
-       
-       ROUND2(A, B, C, D,  1, Se, 17); ROUND2(D, A, B, C,  6, Sf, 18);
-       ROUND2(C, D, A, B, 11, Sg, 19); ROUND2(B, C, D, A,  0, Sh, 20);
-       ROUND2(A, B, C, D,  5, Se, 21); ROUND2(D, A, B, C, 10, Sf, 22);
-       ROUND2(C, D, A, B, 15, Sg, 23); ROUND2(B, C, D, A,  4, Sh, 24);
-       ROUND2(A, B, C, D,  9, Se, 25); ROUND2(D, A, B, C, 14, Sf, 26);
-       ROUND2(C, D, A, B,  3, Sg, 27); ROUND2(B, C, D, A,  8, Sh, 28);
-       ROUND2(A, B, C, D, 13, Se, 29); ROUND2(D, A, B, C,  2, Sf, 30);
-       ROUND2(C, D, A, B,  7, Sg, 31); ROUND2(B, C, D, A, 12, Sh, 32);
-
-       ROUND3(A, B, C, D,  5, Si, 33); ROUND3(D, A, B, C,  8, Sj, 34);
-       ROUND3(C, D, A, B, 11, Sk, 35); ROUND3(B, C, D, A, 14, Sl, 36);
-       ROUND3(A, B, C, D,  1, Si, 37); ROUND3(D, A, B, C,  4, Sj, 38);
-       ROUND3(C, D, A, B,  7, Sk, 39); ROUND3(B, C, D, A, 10, Sl, 40);
-       ROUND3(A, B, C, D, 13, Si, 41); ROUND3(D, A, B, C,  0, Sj, 42);
-       ROUND3(C, D, A, B,  3, Sk, 43); ROUND3(B, C, D, A,  6, Sl, 44);
-       ROUND3(A, B, C, D,  9, Si, 45); ROUND3(D, A, B, C, 12, Sj, 46);
-       ROUND3(C, D, A, B, 15, Sk, 47); ROUND3(B, C, D, A,  2, Sl, 48);
-       
-       ROUND4(A, B, C, D,  0, Sm, 49); ROUND4(D, A, B, C,  7, Sn, 50); 
-       ROUND4(C, D, A, B, 14, So, 51); ROUND4(B, C, D, A,  5, Sp, 52); 
-       ROUND4(A, B, C, D, 12, Sm, 53); ROUND4(D, A, B, C,  3, Sn, 54); 
-       ROUND4(C, D, A, B, 10, So, 55); ROUND4(B, C, D, A,  1, Sp, 56); 
-       ROUND4(A, B, C, D,  8, Sm, 57); ROUND4(D, A, B, C, 15, Sn, 58); 
-       ROUND4(C, D, A, B,  6, So, 59); ROUND4(B, C, D, A, 13, Sp, 60); 
-       ROUND4(A, B, C, D,  4, Sm, 61); ROUND4(D, A, B, C, 11, Sn, 62); 
-       ROUND4(C, D, A, B,  2, So, 63); ROUND4(B, C, D, A,  9, Sp, 64);
+       ROUND1(A, B, C, D, 0, Sa, 1);
+       ROUND1(D, A, B, C, 1, Sb, 2);
+       ROUND1(C, D, A, B, 2, Sc, 3);
+       ROUND1(B, C, D, A, 3, Sd, 4);
+       ROUND1(A, B, C, D, 4, Sa, 5);
+       ROUND1(D, A, B, C, 5, Sb, 6);
+       ROUND1(C, D, A, B, 6, Sc, 7);
+       ROUND1(B, C, D, A, 7, Sd, 8);
+       ROUND1(A, B, C, D, 8, Sa, 9);
+       ROUND1(D, A, B, C, 9, Sb, 10);
+       ROUND1(C, D, A, B, 10, Sc, 11);
+       ROUND1(B, C, D, A, 11, Sd, 12);
+       ROUND1(A, B, C, D, 12, Sa, 13);
+       ROUND1(D, A, B, C, 13, Sb, 14);
+       ROUND1(C, D, A, B, 14, Sc, 15);
+       ROUND1(B, C, D, A, 15, Sd, 16);
+
+       ROUND2(A, B, C, D, 1, Se, 17);
+       ROUND2(D, A, B, C, 6, Sf, 18);
+       ROUND2(C, D, A, B, 11, Sg, 19);
+       ROUND2(B, C, D, A, 0, Sh, 20);
+       ROUND2(A, B, C, D, 5, Se, 21);
+       ROUND2(D, A, B, C, 10, Sf, 22);
+       ROUND2(C, D, A, B, 15, Sg, 23);
+       ROUND2(B, C, D, A, 4, Sh, 24);
+       ROUND2(A, B, C, D, 9, Se, 25);
+       ROUND2(D, A, B, C, 14, Sf, 26);
+       ROUND2(C, D, A, B, 3, Sg, 27);
+       ROUND2(B, C, D, A, 8, Sh, 28);
+       ROUND2(A, B, C, D, 13, Se, 29);
+       ROUND2(D, A, B, C, 2, Sf, 30);
+       ROUND2(C, D, A, B, 7, Sg, 31);
+       ROUND2(B, C, D, A, 12, Sh, 32);
+
+       ROUND3(A, B, C, D, 5, Si, 33);
+       ROUND3(D, A, B, C, 8, Sj, 34);
+       ROUND3(C, D, A, B, 11, Sk, 35);
+       ROUND3(B, C, D, A, 14, Sl, 36);
+       ROUND3(A, B, C, D, 1, Si, 37);
+       ROUND3(D, A, B, C, 4, Sj, 38);
+       ROUND3(C, D, A, B, 7, Sk, 39);
+       ROUND3(B, C, D, A, 10, Sl, 40);
+       ROUND3(A, B, C, D, 13, Si, 41);
+       ROUND3(D, A, B, C, 0, Sj, 42);
+       ROUND3(C, D, A, B, 3, Sk, 43);
+       ROUND3(B, C, D, A, 6, Sl, 44);
+       ROUND3(A, B, C, D, 9, Si, 45);
+       ROUND3(D, A, B, C, 12, Sj, 46);
+       ROUND3(C, D, A, B, 15, Sk, 47);
+       ROUND3(B, C, D, A, 2, Sl, 48);
+
+       ROUND4(A, B, C, D, 0, Sm, 49);
+       ROUND4(D, A, B, C, 7, Sn, 50);
+       ROUND4(C, D, A, B, 14, So, 51);
+       ROUND4(B, C, D, A, 5, Sp, 52);
+       ROUND4(A, B, C, D, 12, Sm, 53);
+       ROUND4(D, A, B, C, 3, Sn, 54);
+       ROUND4(C, D, A, B, 10, So, 55);
+       ROUND4(B, C, D, A, 1, Sp, 56);
+       ROUND4(A, B, C, D, 8, Sm, 57);
+       ROUND4(D, A, B, C, 15, Sn, 58);
+       ROUND4(C, D, A, B, 6, So, 59);
+       ROUND4(B, C, D, A, 13, Sp, 60);
+       ROUND4(A, B, C, D, 4, Sm, 61);
+       ROUND4(D, A, B, C, 11, Sn, 62);
+       ROUND4(C, D, A, B, 2, So, 63);
+       ROUND4(B, C, D, A, 9, Sp, 64);
 
        ctxt->md5_sta += A;
        ctxt->md5_stb += B;
index b724c34ba0a342483f8ba22307fed47b6830ba17..54ca2558dff0f2e803ff7f2e813008676b502221 100644 (file)
@@ -1,5 +1,5 @@
-/*     $Id: md5.h,v 1.3 2001/01/09 16:07:13 momjian Exp $      */
-/*     $KAME: md5.h,v 1.3 2000/02/22 14:01:18 itojun Exp $     */
+/*     $Id: md5.h,v 1.4 2001/03/22 03:59:10 momjian Exp $      */
+/*        $KAME: md5.h,v 1.3 2000/02/22 14:01:18 itojun Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -9,18 +9,18 @@
  * 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.
+ *       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.
+ *       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 project nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE PROJECT 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)
 
 #define MD5_BUFLEN     64
 
-typedef struct {
-       union {
+typedef struct
+{
+       union
+       {
                uint32          md5_state32[4];
                uint8           md5_state8[16];
-       } md5_st;
+       }                       md5_st;
 
 #define md5_sta                md5_st.md5_state32[0]
 #define md5_stb                md5_st.md5_state32[1]
@@ -47,21 +49,22 @@ typedef struct {
 #define md5_std                md5_st.md5_state32[3]
 #define md5_st8                md5_st.md5_state8
 
-       union {
+       union
+       {
                uint64          md5_count64;
                uint8           md5_count8[8];
-       } md5_count;
+       }                       md5_count;
 #define md5_n  md5_count.md5_count64
 #define md5_n8 md5_count.md5_count8
 
-       unsigned int    md5_i;
-       uint8                   md5_buf[MD5_BUFLEN];
-} md5_ctxt;
+       unsigned int md5_i;
+       uint8           md5_buf[MD5_BUFLEN];
+}                      md5_ctxt;
 
-extern void md5_init (md5_ctxt *);
-extern void md5_loop (md5_ctxt *, uint8 *, unsigned int);
-extern void md5_pad (md5_ctxt *);
-extern void md5_result (uint8 *, md5_ctxt *);
+extern void md5_init(md5_ctxt *);
+extern void md5_loop(md5_ctxt *, uint8 *, unsigned int);
+extern void md5_pad(md5_ctxt *);
+extern void md5_result(uint8 *, md5_ctxt *);
 
 /* compatibility */
 #define MD5_CTX                md5_ctxt
@@ -73,4 +76,4 @@ do {                          \
        md5_result((x), (y));   \
 } while (0)
 
-#endif /* ! _NETINET6_MD5_H_*/
+#endif  /* ! _NETINET6_MD5_H_ */
index 34ac7e9c7ac0073818dc2b0f8de5519ab9b9d289..d6ada96d149eca11499bb42a87770de021f88062 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * mhash.c
  *             Wrapper for mhash library.
- * 
+ *
  * Copyright (c) 2000 Marko Kreen
  * All rights reserved.
  *
@@ -9,15 +9,15 @@
  * 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.
+ *       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.
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE AUTHOR 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)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: mhash.c,v 1.2 2001/02/10 02:31:26 tgl Exp $
+ * $Id: mhash.c,v 1.3 2001/03/22 03:59:10 momjian Exp $
  */
 
 #include "postgres.h"
 #include <mhash.h>
 
 static uint
-pg_mhash_len(pg_digest *hash);
-static uint8 *
-pg_mhash_digest(pg_digest *hash, uint8 *src,
-               uint len, uint8 *buf);
+                       pg_mhash_len(pg_digest * hash);
+static uint8 *pg_mhash_digest(pg_digest * hash, uint8 *src,
+                               uint len, uint8 *buf);
 
 static uint
-pg_mhash_len(pg_digest *h) {
+pg_mhash_len(pg_digest * h)
+{
        return mhash_get_block_size(h->misc.code);
 }
 
 static uint8 *
-pg_mhash_digest(pg_digest *h, uint8 *src, uint len, uint8 *dst)
+pg_mhash_digest(pg_digest * h, uint8 *src, uint len, uint8 *dst)
 {
-       uint8 *res;
-       
-       MHASH mh = mhash_init(h->misc.code);
+       uint8      *res;
+
+       MHASH           mh = mhash_init(h->misc.code);
+
        mhash(mh, src, len);
        res = mhash_end(mh);
-       
+
        memcpy(dst, res, mhash_get_block_size(h->misc.code));
        mhash_free(res);
-       
+
        return dst;
 }
 
-pg_digest *
-pg_find_digest(pg_digest *h, char *name)
+pg_digest  *
+pg_find_digest(pg_digest * h, char *name)
 {
-       size_t hnum, i, b;
-       char *mname;
-       
+       size_t          hnum,
+                               i,
+                               b;
+       char       *mname;
+
        hnum = mhash_count();
-       for (i = 0; i <= hnum; i++) {
+       for (i = 0; i <= hnum; i++)
+       {
                mname = mhash_get_hash_name(i);
                if (mname == NULL)
                        continue;
                b = strcasecmp(name, mname);
                free(mname);
-               if (!b) {
+               if (!b)
+               {
                        h->name = mhash_get_hash_name(i);
                        h->length = pg_mhash_len;
                        h->digest = pg_mhash_digest;
@@ -84,4 +89,3 @@ pg_find_digest(pg_digest *h, char *name)
        }
        return NULL;
 }
-
index 18fb07548877785e614ad37e0fcfa614061c8900..866d26f0ffcf04453c8759ee62ba66ea0fc40508 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * openssl.c
  *             Wrapper for OpenSSL library.
- * 
+ *
  * Copyright (c) 2000 Marko Kreen
  * All rights reserved.
  *
@@ -9,15 +9,15 @@
  * 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.
+ *       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.
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE AUTHOR 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)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: openssl.c,v 1.2 2001/02/10 02:31:26 tgl Exp $
+ * $Id: openssl.c,v 1.3 2001/03/22 03:59:10 momjian Exp $
  */
 
 #include "postgres.h"
 #include <evp.h>
 
 static uint
-pg_ossl_len(pg_digest *h);
+                       pg_ossl_len(pg_digest * h);
 static uint8 *
-pg_ossl_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf);
+                       pg_ossl_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf);
 
 static uint
-pg_ossl_len(pg_digest *h) {
-       return EVP_MD_size((EVP_MD*)h->misc.ptr);
+pg_ossl_len(pg_digest * h)
+{
+       return EVP_MD_size((EVP_MD *) h->misc.ptr);
 }
 
 static uint8 *
-pg_ossl_digest(pg_digest *h, uint8 *src, uint len, uint8 *buf)
+pg_ossl_digest(pg_digest * h, uint8 *src, uint len, uint8 *buf)
 {
-       EVP_MD *md = (EVP_MD*)h->misc.ptr;
-       EVP_MD_CTX ctx;
+       EVP_MD     *md = (EVP_MD *) h->misc.ptr;
+       EVP_MD_CTX      ctx;
 
        EVP_DigestInit(&ctx, md);
        EVP_DigestUpdate(&ctx, src, len);
        EVP_DigestFinal(&ctx, buf, NULL);
-       
+
        return buf;
 }
 
-static int pg_openssl_initialized = 0;
+static int     pg_openssl_initialized = 0;
 
-pg_digest *
-pg_find_digest(pg_digest *h, char *name)
+pg_digest  *
+pg_find_digest(pg_digest * h, char *name)
 {
        const EVP_MD *md;
 
-       if (!pg_openssl_initialized) {
+       if (!pg_openssl_initialized)
+       {
                OpenSSL_add_all_digests();
                pg_openssl_initialized = 1;
        }
-       
+
        md = EVP_get_digestbyname(name);
        if (md == NULL)
                return NULL;
-       
+
        h->name = name;
        h->length = pg_ossl_len;
        h->digest = pg_ossl_digest;
-       h->misc.ptr = (void*)md;
-       
+       h->misc.ptr = (void *) md;
+
        return h;
 }
-
-
index 1feb3e4806aea309dc74e56d32de90963f30cb84..31e5a845bd6686baf4ed77d26653e35f48c950e1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * pgcrypto.c
  *             Cryptographic digests for PostgreSQL.
- * 
+ *
  * Copyright (c) 2000 Marko Kreen
  * All rights reserved.
  *
@@ -9,15 +9,15 @@
  * 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.
+ *       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.
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE AUTHOR 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)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: pgcrypto.c,v 1.6 2001/02/10 02:31:26 tgl Exp $
+ * $Id: pgcrypto.c,v 1.7 2001/03/22 03:59:10 momjian Exp $
  */
 
 #include "postgres.h"
 
 
 /* exported functions */
-Datum digest(PG_FUNCTION_ARGS);
-Datum digest_exists(PG_FUNCTION_ARGS);
+Datum          digest(PG_FUNCTION_ARGS);
+Datum          digest_exists(PG_FUNCTION_ARGS);
 
 /* private stuff */
 static pg_digest *
-find_digest(pg_digest *hbuf, text *name, int silent);
+                       find_digest(pg_digest * hbuf, text *name, int silent);
 
 
 /* SQL function: hash(text, text) returns text */
@@ -58,31 +58,33 @@ PG_FUNCTION_INFO_V1(digest);
 Datum
 digest(PG_FUNCTION_ARGS)
 {
-       text *arg;
-       text *name;
-       uint len, hlen;
-       pg_digest *h, _hbuf;
-       text *res;
-       
+       text       *arg;
+       text       *name;
+       uint            len,
+                               hlen;
+       pg_digest  *h,
+                               _hbuf;
+       text       *res;
+
        if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
                PG_RETURN_NULL();
-       
-       name = PG_GETARG_TEXT_P(1);     
-       h = find_digest(&_hbuf, name, 0); /* will give error if fails */
+
+       name = PG_GETARG_TEXT_P(1);
+       h = find_digest(&_hbuf, name, 0);       /* will give error if fails */
 
        hlen = h->length(h);
-       
-       res = (text *)palloc(hlen + VARHDRSZ);
+
+       res = (text *) palloc(hlen + VARHDRSZ);
        VARATT_SIZEP(res) = hlen + VARHDRSZ;
-       
+
        arg = PG_GETARG_TEXT_P(0);
        len = VARSIZE(arg) - VARHDRSZ;
-       
+
        h->digest(h, VARDATA(arg), len, VARDATA(res));
-       
+
        PG_FREE_IF_COPY(arg, 0);
        PG_FREE_IF_COPY(name, 1);
-       
+
        PG_RETURN_TEXT_P(res);
 }
 
@@ -92,16 +94,17 @@ PG_FUNCTION_INFO_V1(digest_exists);
 Datum
 digest_exists(PG_FUNCTION_ARGS)
 {
-       text *name;
-       pg_digest _hbuf, *res;
+       text       *name;
+       pg_digest       _hbuf,
+                          *res;
 
        if (PG_ARGISNULL(0))
                PG_RETURN_NULL();
-       
+
        name = PG_GETARG_TEXT_P(0);
-       
+
        res = find_digest(&_hbuf, name, 1);
-       
+
        PG_FREE_IF_COPY(name, 0);
 
        if (res != NULL)
@@ -110,26 +113,26 @@ digest_exists(PG_FUNCTION_ARGS)
 }
 
 static pg_digest *
-find_digest(pg_digest *hbuf, text *name, int silent)
+find_digest(pg_digest * hbuf, text *name, int silent)
 {
-       pg_digest *p;
-       char buf[NAMEDATALEN];
-       uint len;
-       
+       pg_digest  *p;
+       char            buf[NAMEDATALEN];
+       uint            len;
+
        len = VARSIZE(name) - VARHDRSZ;
-       if (len >= NAMEDATALEN) {
+       if (len >= NAMEDATALEN)
+       {
                if (silent)
                        return NULL;
                elog(ERROR, "Hash type does not exist (name too long)");
        }
-               
+
        memcpy(buf, VARDATA(name), len);
        buf[len] = 0;
-       
+
        p = pg_find_digest(hbuf, buf);
 
        if (p == NULL && !silent)
                elog(ERROR, "Hash type does not exist: '%s'", buf);
        return p;
 }
-
index 039d6cef79cb684f409bbc5ae849c25753ba2558..1700b89b15840bd839ef136e3a61eeea8ebe0a46 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * pgcrypto.h
  *             Header file for pgcrypto.
- * 
+ *
  * Copyright (c) 2000 Marko Kreen
  * All rights reserved.
  *
@@ -9,15 +9,15 @@
  * 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.
+ *       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.
+ *       notice, this list of conditions and the following disclaimer in the
+ *       documentation and/or other materials provided with the distribution.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE AUTHOR 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)
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: pgcrypto.h,v 1.2 2001/01/09 16:07:13 momjian Exp $
+ * $Id: pgcrypto.h,v 1.3 2001/03/22 03:59:10 momjian Exp $
  */
 
 #ifndef _PG_CRYPTO_H
 #define _PG_CRYPTO_H
 
 typedef struct _pg_digest pg_digest;
-struct _pg_digest {
-       char *name;
-       uint (*length)(pg_digest *h);
-       uint8 *(*digest)(pg_digest *h, uint8 *data,
-                       uint dlen, uint8 *buf);
+struct _pg_digest
+{
+       char       *name;
+       uint            (*length) (pg_digest * h);
+       uint8      *(*digest) (pg_digest * h, uint8 *data,
+                                                                          uint dlen, uint8 *buf);
        /* private */
-       union {
-               uint code;
+       union
+       {
+               uint            code;
                const void *ptr;
-       } misc;
+       }                       misc;
 };
 
-extern pg_digest *pg_find_digest(pg_digest *hbuf, char *name);
+extern pg_digest *pg_find_digest(pg_digest * hbuf, char *name);
 
 #endif
index 63c28dc7e945709932647614a52bed1801cc47cb..db9f1a17c60b89bad0ee743954b6feba98a08f47 100644 (file)
@@ -1,5 +1,5 @@
-/*     $Id: sha1.c,v 1.4 2001/02/10 02:31:26 tgl Exp $ */
-/*     $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $    */
+/*     $Id: sha1.c,v 1.5 2001/03/22 03:59:10 momjian Exp $ */
+/*        $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $    */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -9,18 +9,18 @@
  * 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.
+ *       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.
+ *       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 project nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE PROJECT 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)
 
 /* sanity check */
 #if BYTE_ORDER != BIG_ENDIAN
-# if BYTE_ORDER != LITTLE_ENDIAN
-#  define unsupported 1
-# endif
+#if BYTE_ORDER != LITTLE_ENDIAN
+#define unsupported 1
+#endif
 #endif
 
 #ifndef unsupported
 
 /* constant table */
-static uint32 _K[] = { 0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6 };
-#define        K(t)    _K[(t) / 20]
+static uint32 _K[] = {0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6};
+
+#define K(t)   _K[(t) / 20]
 
-#define        F0(b, c, d)     (((b) & (c)) | ((~(b)) & (d)))
-#define        F1(b, c, d)     (((b) ^ (c)) ^ (d))
-#define        F2(b, c, d)     (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
-#define        F3(b, c, d)     (((b) ^ (c)) ^ (d))
+#define F0(b, c, d) (((b) & (c)) | ((~(b)) & (d)))
+#define F1(b, c, d) (((b) ^ (c)) ^ (d))
+#define F2(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d)))
+#define F3(b, c, d) (((b) ^ (c)) ^ (d))
 
-#define        S(n, x)         (((x) << (n)) | ((x) >> (32 - n)))
+#define S(n, x)                (((x) << (n)) | ((x) >> (32 - n)))
 
-#define        H(n)    (ctxt->h.b32[(n)])
-#define        COUNT   (ctxt->count)
-#define        BCOUNT  (ctxt->c.b64[0] / 8)
-#define        W(n)    (ctxt->m.b32[(n)])
+#define H(n)   (ctxt->h.b32[(n)])
+#define COUNT  (ctxt->count)
+#define BCOUNT (ctxt->c.b64[0] / 8)
+#define W(n)   (ctxt->m.b32[(n)])
 
-#define        PUTBYTE(x)      { \
+#define PUTBYTE(x)     { \
        ctxt->m.b8[(COUNT % 64)] = (x);         \
        COUNT++;                                \
        COUNT %= 64;                            \
        ctxt->c.b64[0] += 8;                    \
        if (COUNT % 64 == 0)                    \
                sha1_step(ctxt);                \
-     }
+        }
 
-#define        PUTPAD(x)       { \
+#define PUTPAD(x)      { \
        ctxt->m.b8[(COUNT % 64)] = (x);         \
        COUNT++;                                \
        COUNT %= 64;                            \
        if (COUNT % 64 == 0)                    \
                sha1_step(ctxt);                \
-     }
+        }
 
-static void sha1_step (struct sha1_ctxt *);
+static void sha1_step(struct sha1_ctxt *);
 
 static void
 sha1_step(ctxt)
-       struct sha1_ctxt *ctxt;
+struct sha1_ctxt *ctxt;
 {
-       uint32  a, b, c, d, e;
-       size_t t, s;
-       uint32  tmp;
+       uint32          a,
+                               b,
+                               c,
+                               d,
+                               e;
+       size_t          t,
+                               s;
+       uint32          tmp;
 
 #if BYTE_ORDER == LITTLE_ENDIAN
        struct sha1_ctxt tctxt;
+
        bcopy(&ctxt->m.b8[0], &tctxt.m.b8[0], 64);
-       ctxt->m.b8[0] = tctxt.m.b8[3]; ctxt->m.b8[1] = tctxt.m.b8[2];
-       ctxt->m.b8[2] = tctxt.m.b8[1]; ctxt->m.b8[3] = tctxt.m.b8[0];
-       ctxt->m.b8[4] = tctxt.m.b8[7]; ctxt->m.b8[5] = tctxt.m.b8[6];
-       ctxt->m.b8[6] = tctxt.m.b8[5]; ctxt->m.b8[7] = tctxt.m.b8[4];
-       ctxt->m.b8[8] = tctxt.m.b8[11]; ctxt->m.b8[9] = tctxt.m.b8[10];
-       ctxt->m.b8[10] = tctxt.m.b8[9]; ctxt->m.b8[11] = tctxt.m.b8[8];
-       ctxt->m.b8[12] = tctxt.m.b8[15]; ctxt->m.b8[13] = tctxt.m.b8[14];
-       ctxt->m.b8[14] = tctxt.m.b8[13]; ctxt->m.b8[15] = tctxt.m.b8[12];
-       ctxt->m.b8[16] = tctxt.m.b8[19]; ctxt->m.b8[17] = tctxt.m.b8[18];
-       ctxt->m.b8[18] = tctxt.m.b8[17]; ctxt->m.b8[19] = tctxt.m.b8[16];
-       ctxt->m.b8[20] = tctxt.m.b8[23]; ctxt->m.b8[21] = tctxt.m.b8[22];
-       ctxt->m.b8[22] = tctxt.m.b8[21]; ctxt->m.b8[23] = tctxt.m.b8[20];
-       ctxt->m.b8[24] = tctxt.m.b8[27]; ctxt->m.b8[25] = tctxt.m.b8[26];
-       ctxt->m.b8[26] = tctxt.m.b8[25]; ctxt->m.b8[27] = tctxt.m.b8[24];
-       ctxt->m.b8[28] = tctxt.m.b8[31]; ctxt->m.b8[29] = tctxt.m.b8[30];
-       ctxt->m.b8[30] = tctxt.m.b8[29]; ctxt->m.b8[31] = tctxt.m.b8[28];
-       ctxt->m.b8[32] = tctxt.m.b8[35]; ctxt->m.b8[33] = tctxt.m.b8[34];
-       ctxt->m.b8[34] = tctxt.m.b8[33]; ctxt->m.b8[35] = tctxt.m.b8[32];
-       ctxt->m.b8[36] = tctxt.m.b8[39]; ctxt->m.b8[37] = tctxt.m.b8[38];
-       ctxt->m.b8[38] = tctxt.m.b8[37]; ctxt->m.b8[39] = tctxt.m.b8[36];
-       ctxt->m.b8[40] = tctxt.m.b8[43]; ctxt->m.b8[41] = tctxt.m.b8[42];
-       ctxt->m.b8[42] = tctxt.m.b8[41]; ctxt->m.b8[43] = tctxt.m.b8[40];
-       ctxt->m.b8[44] = tctxt.m.b8[47]; ctxt->m.b8[45] = tctxt.m.b8[46];
-       ctxt->m.b8[46] = tctxt.m.b8[45]; ctxt->m.b8[47] = tctxt.m.b8[44];
-       ctxt->m.b8[48] = tctxt.m.b8[51]; ctxt->m.b8[49] = tctxt.m.b8[50];
-       ctxt->m.b8[50] = tctxt.m.b8[49]; ctxt->m.b8[51] = tctxt.m.b8[48];
-       ctxt->m.b8[52] = tctxt.m.b8[55]; ctxt->m.b8[53] = tctxt.m.b8[54];
-       ctxt->m.b8[54] = tctxt.m.b8[53]; ctxt->m.b8[55] = tctxt.m.b8[52];
-       ctxt->m.b8[56] = tctxt.m.b8[59]; ctxt->m.b8[57] = tctxt.m.b8[58];
-       ctxt->m.b8[58] = tctxt.m.b8[57]; ctxt->m.b8[59] = tctxt.m.b8[56];
-       ctxt->m.b8[60] = tctxt.m.b8[63]; ctxt->m.b8[61] = tctxt.m.b8[62];
-       ctxt->m.b8[62] = tctxt.m.b8[61]; ctxt->m.b8[63] = tctxt.m.b8[60];
+       ctxt->m.b8[0] = tctxt.m.b8[3];
+       ctxt->m.b8[1] = tctxt.m.b8[2];
+       ctxt->m.b8[2] = tctxt.m.b8[1];
+       ctxt->m.b8[3] = tctxt.m.b8[0];
+       ctxt->m.b8[4] = tctxt.m.b8[7];
+       ctxt->m.b8[5] = tctxt.m.b8[6];
+       ctxt->m.b8[6] = tctxt.m.b8[5];
+       ctxt->m.b8[7] = tctxt.m.b8[4];
+       ctxt->m.b8[8] = tctxt.m.b8[11];
+       ctxt->m.b8[9] = tctxt.m.b8[10];
+       ctxt->m.b8[10] = tctxt.m.b8[9];
+       ctxt->m.b8[11] = tctxt.m.b8[8];
+       ctxt->m.b8[12] = tctxt.m.b8[15];
+       ctxt->m.b8[13] = tctxt.m.b8[14];
+       ctxt->m.b8[14] = tctxt.m.b8[13];
+       ctxt->m.b8[15] = tctxt.m.b8[12];
+       ctxt->m.b8[16] = tctxt.m.b8[19];
+       ctxt->m.b8[17] = tctxt.m.b8[18];
+       ctxt->m.b8[18] = tctxt.m.b8[17];
+       ctxt->m.b8[19] = tctxt.m.b8[16];
+       ctxt->m.b8[20] = tctxt.m.b8[23];
+       ctxt->m.b8[21] = tctxt.m.b8[22];
+       ctxt->m.b8[22] = tctxt.m.b8[21];
+       ctxt->m.b8[23] = tctxt.m.b8[20];
+       ctxt->m.b8[24] = tctxt.m.b8[27];
+       ctxt->m.b8[25] = tctxt.m.b8[26];
+       ctxt->m.b8[26] = tctxt.m.b8[25];
+       ctxt->m.b8[27] = tctxt.m.b8[24];
+       ctxt->m.b8[28] = tctxt.m.b8[31];
+       ctxt->m.b8[29] = tctxt.m.b8[30];
+       ctxt->m.b8[30] = tctxt.m.b8[29];
+       ctxt->m.b8[31] = tctxt.m.b8[28];
+       ctxt->m.b8[32] = tctxt.m.b8[35];
+       ctxt->m.b8[33] = tctxt.m.b8[34];
+       ctxt->m.b8[34] = tctxt.m.b8[33];
+       ctxt->m.b8[35] = tctxt.m.b8[32];
+       ctxt->m.b8[36] = tctxt.m.b8[39];
+       ctxt->m.b8[37] = tctxt.m.b8[38];
+       ctxt->m.b8[38] = tctxt.m.b8[37];
+       ctxt->m.b8[39] = tctxt.m.b8[36];
+       ctxt->m.b8[40] = tctxt.m.b8[43];
+       ctxt->m.b8[41] = tctxt.m.b8[42];
+       ctxt->m.b8[42] = tctxt.m.b8[41];
+       ctxt->m.b8[43] = tctxt.m.b8[40];
+       ctxt->m.b8[44] = tctxt.m.b8[47];
+       ctxt->m.b8[45] = tctxt.m.b8[46];
+       ctxt->m.b8[46] = tctxt.m.b8[45];
+       ctxt->m.b8[47] = tctxt.m.b8[44];
+       ctxt->m.b8[48] = tctxt.m.b8[51];
+       ctxt->m.b8[49] = tctxt.m.b8[50];
+       ctxt->m.b8[50] = tctxt.m.b8[49];
+       ctxt->m.b8[51] = tctxt.m.b8[48];
+       ctxt->m.b8[52] = tctxt.m.b8[55];
+       ctxt->m.b8[53] = tctxt.m.b8[54];
+       ctxt->m.b8[54] = tctxt.m.b8[53];
+       ctxt->m.b8[55] = tctxt.m.b8[52];
+       ctxt->m.b8[56] = tctxt.m.b8[59];
+       ctxt->m.b8[57] = tctxt.m.b8[58];
+       ctxt->m.b8[58] = tctxt.m.b8[57];
+       ctxt->m.b8[59] = tctxt.m.b8[56];
+       ctxt->m.b8[60] = tctxt.m.b8[63];
+       ctxt->m.b8[61] = tctxt.m.b8[62];
+       ctxt->m.b8[62] = tctxt.m.b8[61];
+       ctxt->m.b8[63] = tctxt.m.b8[60];
 #endif
 
-       a = H(0); b = H(1); c = H(2); d = H(3); e = H(4);
+       a = H(0);
+       b = H(1);
+       c = H(2);
+       d = H(3);
+       e = H(4);
 
-       for (t = 0; t < 20; t++) {
+       for (t = 0; t < 20; t++)
+       {
                s = t & 0x0f;
-               if (t >= 16) {
-                       W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
-               }
+               if (t >= 16)
+                       W(s) = S(1, W((s + 13) & 0x0f) ^ W((s + 8) & 0x0f) ^ W((s + 2) & 0x0f) ^ W(s));
                tmp = S(5, a) + F0(b, c, d) + e + W(s) + K(t);
-               e = d; d = c; c = S(30, b); b = a; a = tmp;
+               e = d;
+               d = c;
+               c = S(30, b);
+               b = a;
+               a = tmp;
        }
-       for (t = 20; t < 40; t++) {
+       for (t = 20; t < 40; t++)
+       {
                s = t & 0x0f;
-               W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
+               W(s) = S(1, W((s + 13) & 0x0f) ^ W((s + 8) & 0x0f) ^ W((s + 2) & 0x0f) ^ W(s));
                tmp = S(5, a) + F1(b, c, d) + e + W(s) + K(t);
-               e = d; d = c; c = S(30, b); b = a; a = tmp;
+               e = d;
+               d = c;
+               c = S(30, b);
+               b = a;
+               a = tmp;
        }
-       for (t = 40; t < 60; t++) {
+       for (t = 40; t < 60; t++)
+       {
                s = t & 0x0f;
-               W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
+               W(s) = S(1, W((s + 13) & 0x0f) ^ W((s + 8) & 0x0f) ^ W((s + 2) & 0x0f) ^ W(s));
                tmp = S(5, a) + F2(b, c, d) + e + W(s) + K(t);
-               e = d; d = c; c = S(30, b); b = a; a = tmp;
+               e = d;
+               d = c;
+               c = S(30, b);
+               b = a;
+               a = tmp;
        }
-       for (t = 60; t < 80; t++) {
+       for (t = 60; t < 80; t++)
+       {
                s = t & 0x0f;
-               W(s) = S(1, W((s+13) & 0x0f) ^ W((s+8) & 0x0f) ^ W((s+2) & 0x0f) ^ W(s));
+               W(s) = S(1, W((s + 13) & 0x0f) ^ W((s + 8) & 0x0f) ^ W((s + 2) & 0x0f) ^ W(s));
                tmp = S(5, a) + F3(b, c, d) + e + W(s) + K(t);
-               e = d; d = c; c = S(30, b); b = a; a = tmp;
+               e = d;
+               d = c;
+               c = S(30, b);
+               b = a;
+               a = tmp;
        }
 
        H(0) = H(0) + a;
@@ -170,7 +232,7 @@ sha1_step(ctxt)
 
 void
 sha1_init(ctxt)
-       struct sha1_ctxt *ctxt;
+struct sha1_ctxt *ctxt;
 {
        bzero(ctxt, sizeof(struct sha1_ctxt));
        H(0) = 0x67452301;
@@ -182,55 +244,65 @@ sha1_init(ctxt)
 
 void
 sha1_pad(ctxt)
-       struct sha1_ctxt *ctxt;
+struct sha1_ctxt *ctxt;
 {
-       size_t padlen;          /*pad length in bytes*/
-       size_t padstart;
+       size_t          padlen;                 /* pad length in bytes */
+       size_t          padstart;
 
        PUTPAD(0x80);
 
        padstart = COUNT % 64;
        padlen = 64 - padstart;
-       if (padlen < 8) {
+       if (padlen < 8)
+       {
                bzero(&ctxt->m.b8[padstart], padlen);
                COUNT += padlen;
                COUNT %= 64;
                sha1_step(ctxt);
                padstart = COUNT % 64;  /* should be 0 */
-               padlen = 64 - padstart; /* should be 64 */
+               padlen = 64 - padstart; /* should be 64 */
        }
        bzero(&ctxt->m.b8[padstart], padlen - 8);
        COUNT += (padlen - 8);
        COUNT %= 64;
 #if BYTE_ORDER == BIG_ENDIAN
-       PUTPAD(ctxt->c.b8[0]); PUTPAD(ctxt->c.b8[1]);
-       PUTPAD(ctxt->c.b8[2]); PUTPAD(ctxt->c.b8[3]);
-       PUTPAD(ctxt->c.b8[4]); PUTPAD(ctxt->c.b8[5]);
-       PUTPAD(ctxt->c.b8[6]); PUTPAD(ctxt->c.b8[7]);
+       PUTPAD(ctxt->c.b8[0]);
+       PUTPAD(ctxt->c.b8[1]);
+       PUTPAD(ctxt->c.b8[2]);
+       PUTPAD(ctxt->c.b8[3]);
+       PUTPAD(ctxt->c.b8[4]);
+       PUTPAD(ctxt->c.b8[5]);
+       PUTPAD(ctxt->c.b8[6]);
+       PUTPAD(ctxt->c.b8[7]);
 #else
-       PUTPAD(ctxt->c.b8[7]); PUTPAD(ctxt->c.b8[6]);
-       PUTPAD(ctxt->c.b8[5]); PUTPAD(ctxt->c.b8[4]);
-       PUTPAD(ctxt->c.b8[3]); PUTPAD(ctxt->c.b8[2]);
-       PUTPAD(ctxt->c.b8[1]); PUTPAD(ctxt->c.b8[0]);
+       PUTPAD(ctxt->c.b8[7]);
+       PUTPAD(ctxt->c.b8[6]);
+       PUTPAD(ctxt->c.b8[5]);
+       PUTPAD(ctxt->c.b8[4]);
+       PUTPAD(ctxt->c.b8[3]);
+       PUTPAD(ctxt->c.b8[2]);
+       PUTPAD(ctxt->c.b8[1]);
+       PUTPAD(ctxt->c.b8[0]);
 #endif
 }
 
 void
 sha1_loop(ctxt, input0, len)
-       struct sha1_ctxt *ctxt;
-       const caddr_t input0;
-       size_t len;
+struct sha1_ctxt *ctxt;
+const caddr_t input0;
+size_t         len;
 {
        const uint8 *input;
-       size_t gaplen;
-       size_t gapstart;
-       size_t off;
-       size_t copysiz;
+       size_t          gaplen;
+       size_t          gapstart;
+       size_t          off;
+       size_t          copysiz;
 
-       input = (const uint8 *)input0;
+       input = (const uint8 *) input0;
        off = 0;
 
-       while (off < len) {
+       while (off < len)
+       {
                gapstart = COUNT % 64;
                gaplen = 64 - gapstart;
 
@@ -247,27 +319,37 @@ sha1_loop(ctxt, input0, len)
 
 void
 sha1_result(ctxt, digest0)
-       struct sha1_ctxt *ctxt;
-       caddr_t digest0;
+struct sha1_ctxt *ctxt;
+caddr_t                digest0;
 {
-       uint8 *digest;
+       uint8      *digest;
 
-       digest = (uint8 *)digest0;
+       digest = (uint8 *) digest0;
        sha1_pad(ctxt);
 #if BYTE_ORDER == BIG_ENDIAN
        bcopy(&ctxt->h.b8[0], digest, 20);
 #else
-       digest[0] = ctxt->h.b8[3]; digest[1] = ctxt->h.b8[2];
-       digest[2] = ctxt->h.b8[1]; digest[3] = ctxt->h.b8[0];
-       digest[4] = ctxt->h.b8[7]; digest[5] = ctxt->h.b8[6];
-       digest[6] = ctxt->h.b8[5]; digest[7] = ctxt->h.b8[4];
-       digest[8] = ctxt->h.b8[11]; digest[9] = ctxt->h.b8[10];
-       digest[10] = ctxt->h.b8[9]; digest[11] = ctxt->h.b8[8];
-       digest[12] = ctxt->h.b8[15]; digest[13] = ctxt->h.b8[14];
-       digest[14] = ctxt->h.b8[13]; digest[15] = ctxt->h.b8[12];
-       digest[16] = ctxt->h.b8[19]; digest[17] = ctxt->h.b8[18];
-       digest[18] = ctxt->h.b8[17]; digest[19] = ctxt->h.b8[16];
+       digest[0] = ctxt->h.b8[3];
+       digest[1] = ctxt->h.b8[2];
+       digest[2] = ctxt->h.b8[1];
+       digest[3] = ctxt->h.b8[0];
+       digest[4] = ctxt->h.b8[7];
+       digest[5] = ctxt->h.b8[6];
+       digest[6] = ctxt->h.b8[5];
+       digest[7] = ctxt->h.b8[4];
+       digest[8] = ctxt->h.b8[11];
+       digest[9] = ctxt->h.b8[10];
+       digest[10] = ctxt->h.b8[9];
+       digest[11] = ctxt->h.b8[8];
+       digest[12] = ctxt->h.b8[15];
+       digest[13] = ctxt->h.b8[14];
+       digest[14] = ctxt->h.b8[13];
+       digest[15] = ctxt->h.b8[12];
+       digest[16] = ctxt->h.b8[19];
+       digest[17] = ctxt->h.b8[18];
+       digest[18] = ctxt->h.b8[17];
+       digest[19] = ctxt->h.b8[16];
 #endif
 }
 
-#endif /*unsupported*/
+#endif  /* unsupported */
index cb08a1af83ebf7fb0dc243d8a61746963d3f7d77..cddc8651e4fa12d53370d942b81a1568a558e345 100644 (file)
@@ -1,5 +1,5 @@
-/*     $Id: sha1.h,v 1.3 2001/01/09 16:07:13 momjian Exp $     */
-/*     $KAME: sha1.h,v 1.4 2000/02/22 14:01:18 itojun Exp $    */
+/*     $Id: sha1.h,v 1.4 2001/03/22 03:59:10 momjian Exp $ */
+/*        $KAME: sha1.h,v 1.4 2000/02/22 14:01:18 itojun Exp $    */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -9,18 +9,18 @@
  * 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.
+ *       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.
+ *       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 project nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
+ *       may be used to endorse or promote products derived from this software
+ *       without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT OR CONTRIBUTORS BE LIABLE
+ * ARE DISCLAIMED.     IN NO EVENT SHALL THE PROJECT 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)
 #ifndef _NETINET6_SHA1_H_
 #define _NETINET6_SHA1_H_
 
-struct sha1_ctxt {
-       union {
+struct sha1_ctxt
+{
+       union
+       {
                uint8           b8[20];
                uint32          b32[5];
-       } h;
-       union {
+       }                       h;
+       union
+       {
                uint8           b8[8];
                uint64          b64[1];
-       } c;
-       union {
+       }                       c;
+       union
+       {
                uint8           b8[64];
                uint32          b32[16];
-       } m;
-       uint8                   count;
+       }                       m;
+       uint8           count;
 };
 
-extern void sha1_init (struct sha1_ctxt *);
-extern void sha1_pad (struct sha1_ctxt *);
-extern void sha1_loop (struct sha1_ctxt *, const caddr_t, size_t);
-extern void sha1_result (struct sha1_ctxt *, caddr_t);
+extern void sha1_init(struct sha1_ctxt *);
+extern void sha1_pad(struct sha1_ctxt *);
+extern void sha1_loop(struct sha1_ctxt *, const caddr_t, size_t);
+extern void sha1_result(struct sha1_ctxt *, caddr_t);
 
 /* compatibilty with other SHA1 source codes */
 typedef struct sha1_ctxt SHA1_CTX;
+
 #define SHA1Init(x)            sha1_init((x))
-#define SHA1Update(x, y, z)    sha1_loop((x), (y), (z))
+#define SHA1Update(x, y, z) sha1_loop((x), (y), (z))
 #define SHA1Final(x, y)                sha1_result((y), (x))
 
-#define        SHA1_RESULTLEN  (160/8)
+#define SHA1_RESULTLEN (160/8)
 
-#endif /*_NETINET6_SHA1_H_*/
+#endif  /* _NETINET6_SHA1_H_ */
index 518dd68a539d5488deac454b3ed8a95876145015..4a7d3aed350d5d8a872d9368479b4bab1e00cb6b 100644 (file)
 PG_FUNCTION_INFO_V1(_rserv_log_);
 PG_FUNCTION_INFO_V1(_rserv_sync_);
 PG_FUNCTION_INFO_V1(_rserv_debug_);
-Datum _rserv_log_(PG_FUNCTION_ARGS);
-Datum _rserv_sync_(PG_FUNCTION_ARGS);
-Datum _rserv_debug_(PG_FUNCTION_ARGS);
+Datum          _rserv_log_(PG_FUNCTION_ARGS);
+Datum          _rserv_sync_(PG_FUNCTION_ARGS);
+Datum          _rserv_debug_(PG_FUNCTION_ARGS);
+
 #else
 HeapTuple      _rserv_log_(void);
 int32          _rserv_sync_(int32);
 int32          _rserv_debug_(int32);
+
 #endif
 
 static int     debug = 0;
 
-static charOutputValue(char *key, char *buf, int size);
+static char *OutputValue(char *key, char *buf, int size);
 
 #ifdef PG_FUNCTION_INFO_V1
 Datum
@@ -68,7 +70,7 @@ _rserv_log_()
        nargs = trigger->tgnargs;
        args = trigger->tgargs;
 
-       if (nargs != 1)                 /* odd number of arguments! */
+       if (nargs != 1)                         /* odd number of arguments! */
                elog(ERROR, "_rserv_log_: need in *one* argument");
 
        keynum = atoi(args[0]);
@@ -79,7 +81,7 @@ _rserv_log_()
        rel = CurrentTriggerData->tg_relation;
        tupdesc = rel->rd_att;
 
-       deleted = (TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event)) ? 
+       deleted = (TRIGGER_FIRED_BY_DELETE(CurrentTriggerData->tg_event)) ?
                1 : 0;
 
        if (TRIGGER_FIRED_BY_UPDATE(CurrentTriggerData->tg_event))
@@ -115,7 +117,7 @@ _rserv_log_()
                if (strcmp(newkey, key) == 0)
                        newkey = NULL;
                else
-                       deleted = 1;    /* old key was deleted */
+                       deleted = 1;            /* old key was deleted */
        }
 
        if (strpbrk(key, "\\    \n'"))
@@ -124,7 +126,7 @@ _rserv_log_()
                okey = key;
 
        sprintf(sql, "update _RSERV_LOG_ set logid = %d, logtime = now(), "
-                       "deleted = %d where reloid = %u and key = '%s'", 
+                       "deleted = %d where reloid = %u and key = '%s'",
                        GetCurrentTransactionId(), deleted, rel->rd_id, okey);
 
        if (debug)
@@ -145,7 +147,7 @@ _rserv_log_()
                sprintf(sql, "insert into _RSERV_LOG_ "
                                "(reloid, logid, logtime, deleted, key) "
                                "values (%u, %d, now(), %d, '%s')",
-                               rel->rd_id, GetCurrentTransactionId(), 
+                               rel->rd_id, GetCurrentTransactionId(),
                                deleted, okey);
 
                if (debug)
@@ -169,7 +171,7 @@ _rserv_log_()
 
                sprintf(sql, "insert into _RSERV_LOG_ "
                                "(reloid, logid, logtime, deleted, key) "
-                               "values (%u, %d, now(), 0, '%s')", 
+                               "values (%u, %d, now(), 0, '%s')",
                                rel->rd_id, GetCurrentTransactionId(), okey);
 
                if (debug)
@@ -202,13 +204,14 @@ _rserv_sync_(int32 server)
 #endif
 {
 #ifdef PG_FUNCTION_INFO_V1
-       int32 server = PG_GETARG_INT32(0);
+       int32           server = PG_GETARG_INT32(0);
+
 #endif
-       char    sql[8192];
-       char    buf[8192];
-       char   *active = buf;
-       uint32  xcnt;
-       int             ret;
+       char            sql[8192];
+       char            buf[8192];
+       char       *active = buf;
+       uint32          xcnt;
+       int                     ret;
 
        if (SerializableSnapshot == NULL)
                elog(ERROR, "_rserv_sync_: SerializableSnapshot is NULL");
@@ -217,7 +220,7 @@ _rserv_sync_(int32 server)
        for (xcnt = 0; xcnt < SerializableSnapshot->xcnt; xcnt++)
        {
                sprintf(buf + strlen(buf), "%s%u", (xcnt) ? ", " : "",
-                       SerializableSnapshot->xip[xcnt]);
+                               SerializableSnapshot->xip[xcnt]);
        }
 
        if ((ret = SPI_connect()) < 0)
@@ -225,7 +228,7 @@ _rserv_sync_(int32 server)
 
        sprintf(sql, "insert into _RSERV_SYNC_ "
                        "(server, syncid, synctime, status, minid, maxid, active) "
-                       "values (%u, currval('_rserv_sync_seq_'), now(), 0, %d, %d, '%s')", 
+         "values (%u, currval('_rserv_sync_seq_'), now(), 0, %d, %d, '%s')",
                        server, SerializableSnapshot->xmin, SerializableSnapshot->xmax, active);
 
        ret = SPI_exec(sql, 0);
@@ -247,18 +250,19 @@ _rserv_debug_(int32 newval)
 #endif
 {
 #ifdef PG_FUNCTION_INFO_V1
-       int32   newval = PG_GETARG_INT32(0);
+       int32           newval = PG_GETARG_INT32(0);
+
 #endif
-       int32   oldval = debug;
+       int32           oldval = debug;
 
        debug = newval;
 
        return (oldval);
 }
 
-#define        ExtendBy        1024
+#define ExtendBy       1024
 
-static char*
+static char *
 OutputValue(char *key, char *buf, int size)
 {
        int                     i = 0;
@@ -267,39 +271,45 @@ OutputValue(char *key, char *buf, int size)
        int                     slen = 0;
 
        size--;
-       for ( ; ; )
+       for (;;)
        {
                switch (*key)
                {
-                       case '\\':      subst ="\\\\";
-                                               slen = 2;
-                                               break;
-                       case '  ':      subst = "\\011";
-                                               slen = 4;
-                                               break;
-                       case '\n':      subst = "\\012";
-                                               slen = 4;
-                                               break;
-                       case '\'':      subst = "\\047";
-                                               slen = 4;
-                                               break;
-                       case '\0':      out[i] = 0;
-                                               return(out);
-                       default:        slen = 1;
-                                               break;
+                       case '\\':
+                               subst = "\\\\";
+                               slen = 2;
+                               break;
+                       case '  ':
+                               subst = "\\011";
+                               slen = 4;
+                               break;
+                       case '\n':
+                               subst = "\\012";
+                               slen = 4;
+                               break;
+                       case '\'':
+                               subst = "\\047";
+                               slen = 4;
+                               break;
+                       case '\0':
+                               out[i] = 0;
+                               return (out);
+                       default:
+                               slen = 1;
+                               break;
                }
 
                if (i + slen >= size)
                {
                        if (out == buf)
                        {
-                               out = (char*) palloc(size + ExtendBy);
+                               out = (char *) palloc(size + ExtendBy);
                                strncpy(out, buf, i);
                                size += ExtendBy;
                        }
                        else
                        {
-                               out = (char*) repalloc(out, size + ExtendBy);
+                               out = (char *) repalloc(out, size + ExtendBy);
                                size += ExtendBy;
                        }
                }
@@ -314,6 +324,6 @@ OutputValue(char *key, char *buf, int size)
                key++;
        }
 
-       return(out);
+       return (out);
 
 }
index f4dfc1edcd30d68a2b17e56628e5d62a7ecf3f1f..baeba5e51529807212bad1a861c399c30ac532f3 100644 (file)
@@ -4,76 +4,81 @@
 
 #include "utils/elog.h"
 
-static char *       PARSE_BUFFER;
-static char *       PARSE_BUFFER_PTR; 
-static unsigned int PARSE_BUFFER_SIZE; 
+static char *PARSE_BUFFER;
+static char *PARSE_BUFFER_PTR;
+static unsigned int PARSE_BUFFER_SIZE;
 static unsigned int SCANNER_POS;
 
-void         set_parse_buffer( char* s );
-void         reset_parse_buffer( void );
-int          read_parse_buffer( void );
-char *       parse_buffer( void );
-char *       parse_buffer_ptr( void );
-unsigned int parse_buffer_curr_char( void );
-unsigned int parse_buffer_size( void );
-unsigned int parse_buffer_pos( void );
+void           set_parse_buffer(char *s);
+void           reset_parse_buffer(void);
+int                    read_parse_buffer(void);
+char      *parse_buffer(void);
+char      *parse_buffer_ptr(void);
+unsigned int parse_buffer_curr_char(void);
+unsigned int parse_buffer_size(void);
+unsigned int parse_buffer_pos(void);
 
-extern void seg_flush_scanner_buffer(void); /* defined in segscan.l */
+extern void seg_flush_scanner_buffer(void);            /* defined in segscan.l */
 
-void set_parse_buffer( char* s )
+void
+set_parse_buffer(char *s)
 {
-  PARSE_BUFFER = s;
-  PARSE_BUFFER_SIZE = strlen(s);
-  if ( PARSE_BUFFER_SIZE == 0 ) {
-    elog(ERROR, "seg_in: can't parse an empty string");
-  }
-  PARSE_BUFFER_PTR = PARSE_BUFFER;
-  SCANNER_POS = 0;
+       PARSE_BUFFER = s;
+       PARSE_BUFFER_SIZE = strlen(s);
+       if (PARSE_BUFFER_SIZE == 0)
+               elog(ERROR, "seg_in: can't parse an empty string");
+       PARSE_BUFFER_PTR = PARSE_BUFFER;
+       SCANNER_POS = 0;
 }
 
-void reset_parse_buffer( void )
+void
+reset_parse_buffer(void)
 {
-  PARSE_BUFFER_PTR = PARSE_BUFFER;
-  SCANNER_POS = 0;
-  seg_flush_scanner_buffer();
+       PARSE_BUFFER_PTR = PARSE_BUFFER;
+       SCANNER_POS = 0;
+       seg_flush_scanner_buffer();
 }
 
-int read_parse_buffer( void )
+int
+read_parse_buffer(void)
 {
-  int c;
-  /*
-  c = *PARSE_BUFFER_PTR++;
-  SCANNER_POS++;
-  */
-  c = PARSE_BUFFER[SCANNER_POS];
-  if(SCANNER_POS < PARSE_BUFFER_SIZE)
-    SCANNER_POS++;
-  return c;
+       int                     c;
+
+       /*
+        * c = *PARSE_BUFFER_PTR++; SCANNER_POS++;
+        */
+       c = PARSE_BUFFER[SCANNER_POS];
+       if (SCANNER_POS < PARSE_BUFFER_SIZE)
+               SCANNER_POS++;
+       return c;
 }
 
-char * parse_buffer( void )
+char *
+parse_buffer(void)
 {
-  return PARSE_BUFFER;
+       return PARSE_BUFFER;
 }
 
-unsigned int parse_buffer_curr_char( void )
+unsigned int
+parse_buffer_curr_char(void)
 {
-  return PARSE_BUFFER[SCANNER_POS];
+       return PARSE_BUFFER[SCANNER_POS];
 }
 
-char * parse_buffer_ptr( void )
+char *
+parse_buffer_ptr(void)
 {
-  return PARSE_BUFFER_PTR;
+       return PARSE_BUFFER_PTR;
 }
 
-unsigned int parse_buffer_pos( void )
+unsigned int
+parse_buffer_pos(void)
 {
-  return SCANNER_POS;
+       return SCANNER_POS;
 }
 
-unsigned int parse_buffer_size( void )
+unsigned int
+parse_buffer_size(void)
 {
-  return PARSE_BUFFER_SIZE;
+       return PARSE_BUFFER_SIZE;
 }
-
-
index fd41a7b69b713e2b4dc23716af8905477ff8a379..eef9124dac5eff3cbbc4236b13970b4a6862cf46 100644 (file)
@@ -1,8 +1,8 @@
-extern void set_parse_buffer( char* s );
-extern void reset_parse_buffer( void );
-extern int read_parse_buffer( void );
-extern char * parse_buffer( void );
-extern char * parse_buffer_ptr( void );
-extern unsigned int parse_buffer_curr_char( void );
-extern unsigned int parse_buffer_pos( void );
-extern unsigned int parse_buffer_size( void );
+extern void set_parse_buffer(char *s);
+extern void reset_parse_buffer(void);
+extern int     read_parse_buffer(void);
+extern char *parse_buffer(void);
+extern char *parse_buffer_ptr(void);
+extern unsigned int parse_buffer_curr_char(void);
+extern unsigned int parse_buffer_pos(void);
+extern unsigned int parse_buffer_size(void);
index 1609b42b1eaa11c90dba7e8d197ecc6898edece8..3ed7926389190689ab755e23edbcdee8b9f591b1 100644 (file)
 
 #include "segdata.h"
 
-#define max(a,b)        ((a) >  (b) ? (a) : (b))
-#define min(a,b)        ((a) <= (b) ? (a) : (b))
-#define abs(a)          ((a) <  (0) ? (-a) : (a))
+#define max(a,b)               ((a) >  (b) ? (a) : (b))
+#define min(a,b)               ((a) <= (b) ? (a) : (b))
+#define abs(a)                 ((a) <  (0) ? (-a) : (a))
 
-/* 
+/*
 #define GIST_DEBUG
-#define GIST_QUERY_DEBUG 
+#define GIST_QUERY_DEBUG
 */
 
-extern void  set_parse_buffer(char *str);
-extern int   seg_yyparse();
+extern void set_parse_buffer(char *str);
+extern int     seg_yyparse();
+
 /*
-extern int   seg_yydebug;
+extern int      seg_yydebug;
 */
 
 /*
 ** Input/Output routines
 */
-SEG *        seg_in(char *str);
-char *       seg_out(SEG *seg);
-float32      seg_lower(SEG *seg);
-float32      seg_upper(SEG *seg);
-float32      seg_center(SEG *seg);
+SEG               *seg_in(char *str);
+char      *seg_out(SEG * seg);
+float32                seg_lower(SEG * seg);
+float32                seg_upper(SEG * seg);
+float32                seg_center(SEG * seg);
 
-/* 
+/*
 ** GiST support methods
 */
-bool             gseg_consistent(GISTENTRY *entry, SEG *query, StrategyNumber strategy);
-GISTENTRY *      gseg_compress(GISTENTRY *entry);
-GISTENTRY *      gseg_decompress(GISTENTRY *entry);
-float *          gseg_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result);
-GIST_SPLITVEC *  gseg_picksplit(bytea *entryvec, GIST_SPLITVEC *v);
-bool             gseg_leaf_consistent(SEG *key, SEG *query, StrategyNumber strategy);
-bool             gseg_internal_consistent(SEG *key, SEG *query, StrategyNumber strategy);
-SEG *            gseg_union(bytea *entryvec, int *sizep);
-SEG *            gseg_binary_union(SEG *r1, SEG *r2, int *sizep);
-bool *           gseg_same(SEG *b1, SEG *b2, bool *result);
+bool           gseg_consistent(GISTENTRY *entry, SEG * query, StrategyNumber strategy);
+GISTENTRY  *gseg_compress(GISTENTRY *entry);
+GISTENTRY  *gseg_decompress(GISTENTRY *entry);
+float     *gseg_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result);
+GIST_SPLITVEC *gseg_picksplit(bytea *entryvec, GIST_SPLITVEC *v);
+bool           gseg_leaf_consistent(SEG * key, SEG * query, StrategyNumber strategy);
+bool           gseg_internal_consistent(SEG * key, SEG * query, StrategyNumber strategy);
+SEG               *gseg_union(bytea *entryvec, int *sizep);
+SEG               *gseg_binary_union(SEG * r1, SEG * r2, int *sizep);
+bool      *gseg_same(SEG * b1, SEG * b2, bool *result);
 
 
 /*
 ** R-tree suport functions
 */
-bool     seg_same(SEG *a, SEG *b);
-bool     seg_contains_int(SEG *a, int *b);
-bool     seg_contains_float4(SEG *a, float4 *b);
-bool     seg_contains_float8(SEG *a, float8 *b);
-bool     seg_contains(SEG *a, SEG *b);
-bool     seg_contained(SEG *a, SEG *b);
-bool     seg_overlap(SEG *a, SEG *b);
-bool     seg_left(SEG *a, SEG *b);
-bool     seg_over_left(SEG *a, SEG *b);
-bool     seg_right(SEG *a, SEG *b);
-bool     seg_over_right(SEG *a, SEG *b);
-SEG *    seg_union(SEG *a, SEG *b);
-SEG *    seg_inter(SEG *a, SEG *b);
-void     rt_seg_size(SEG *a, float* sz);
-float *  seg_size(SEG *a);
+bool           seg_same(SEG * a, SEG * b);
+bool           seg_contains_int(SEG * a, int *b);
+bool           seg_contains_float4(SEG * a, float4 *b);
+bool           seg_contains_float8(SEG * a, float8 *b);
+bool           seg_contains(SEG * a, SEG * b);
+bool           seg_contained(SEG * a, SEG * b);
+bool           seg_overlap(SEG * a, SEG * b);
+bool           seg_left(SEG * a, SEG * b);
+bool           seg_over_left(SEG * a, SEG * b);
+bool           seg_right(SEG * a, SEG * b);
+bool           seg_over_right(SEG * a, SEG * b);
+SEG               *seg_union(SEG * a, SEG * b);
+SEG               *seg_inter(SEG * a, SEG * b);
+void           rt_seg_size(SEG * a, float *sz);
+float     *seg_size(SEG * a);
 
 /*
 ** Various operators
 */
-int32    seg_cmp(SEG *a, SEG *b);
-bool     seg_lt(SEG *a, SEG *b);
-bool     seg_le(SEG *a, SEG *b);
-bool     seg_gt(SEG *a, SEG *b);
-bool     seg_ge(SEG *a, SEG *b);
-bool     seg_different(SEG *a, SEG *b);
-
-/* 
+int32          seg_cmp(SEG * a, SEG * b);
+bool           seg_lt(SEG * a, SEG * b);
+bool           seg_le(SEG * a, SEG * b);
+bool           seg_gt(SEG * a, SEG * b);
+bool           seg_ge(SEG * a, SEG * b);
+bool           seg_different(SEG * a, SEG * b);
+
+/*
 ** Auxiliary funxtions
 */
-static int    restore(char *s, float val, int n);
-int    significant_digits (char* s);
+static int     restore(char *s, float val, int n);
+int                    significant_digits(char *s);
 
 
 /*****************************************************************************
@@ -98,104 +99,113 @@ int    significant_digits (char* s);
 SEG *
 seg_in(char *str)
 {
-  SEG * result = palloc(sizeof(SEG));
-  set_parse_buffer( str );
-  
-  /*
-  seg_yydebug = 1;
-  */
-  if ( seg_yyparse(result) != 0 ) {
-    pfree ( result );
-    return NULL;
-  }  
-  return ( result );
+       SEG                *result = palloc(sizeof(SEG));
+
+       set_parse_buffer(str);
+
+       /*
+        * seg_yydebug = 1;
+        */
+       if (seg_yyparse(result) != 0)
+       {
+               pfree(result);
+               return NULL;
+       }
+       return (result);
 }
 
 /*
  * You might have noticed a slight inconsistency between the following
  * declaration and the SQL definition:
- *     CREATE FUNCTION seg_out(opaque) RETURNS opaque ...
+ *        CREATE FUNCTION seg_out(opaque) RETURNS opaque ...
  * The reason is that the argument passed into seg_out is really just a
  * pointer. POSTGRES thinks all output functions are:
- *     char *out_func(char *);
+ *        char *out_func(char *);
  */
 char *
-seg_out(SEG *seg)
+seg_out(SEG * seg)
 {
-    char *result;
-    char *p;
-
-    if (seg == NULL) return(NULL);
-
-    p = result = (char *) palloc(40);
-
-    if ( seg->l_ext == '>' || seg->l_ext == '<' || seg->l_ext == '~' ) {
-      p += sprintf(p, "%c", seg->l_ext);
-    }
-      
-    if ( seg->lower == seg->upper && seg->l_ext == seg->u_ext ) {
-      /* indicates that this interval was built by seg_in off a single point */
-      p += restore(p, seg->lower, seg->l_sigd);
-    }
-    else {
-      if ( seg->l_ext != '-' ) {
-       /* print the lower boudary if exists */
-       p += restore(p, seg->lower, seg->l_sigd);
-       p += sprintf(p, " ");
-      }
-      p += sprintf(p, "..");
-      if ( seg->u_ext != '-' ) {
-       /* print the upper boudary if exists */
-       p += sprintf(p, " ");
-       if ( seg->u_ext == '>' || seg->u_ext == '<' || seg->l_ext == '~' ) {
-         p += sprintf(p, "%c", seg->u_ext);
+       char       *result;
+       char       *p;
+
+       if (seg == NULL)
+               return (NULL);
+
+       p = result = (char *) palloc(40);
+
+       if (seg->l_ext == '>' || seg->l_ext == '<' || seg->l_ext == '~')
+               p += sprintf(p, "%c", seg->l_ext);
+
+       if (seg->lower == seg->upper && seg->l_ext == seg->u_ext)
+       {
+
+               /*
+                * indicates that this interval was built by seg_in off a single
+                * point
+                */
+               p += restore(p, seg->lower, seg->l_sigd);
+       }
+       else
+       {
+               if (seg->l_ext != '-')
+               {
+                       /* print the lower boudary if exists */
+                       p += restore(p, seg->lower, seg->l_sigd);
+                       p += sprintf(p, " ");
+               }
+               p += sprintf(p, "..");
+               if (seg->u_ext != '-')
+               {
+                       /* print the upper boudary if exists */
+                       p += sprintf(p, " ");
+                       if (seg->u_ext == '>' || seg->u_ext == '<' || seg->l_ext == '~')
+                               p += sprintf(p, "%c", seg->u_ext);
+                       p += restore(p, seg->upper, seg->u_sigd);
+               }
        }
-       p += restore(p, seg->upper, seg->u_sigd);
-      }
-    }
 
-    return(result);
+       return (result);
 }
 
 float32
-seg_center(SEG *seg)
+seg_center(SEG * seg)
 {
-        float32 result = (float32) palloc(sizeof(float32data));
+       float32         result = (float32) palloc(sizeof(float32data));
 
-        if (!seg)
-                return (float32) NULL;
+       if (!seg)
+               return (float32) NULL;
 
-        *result = ((float)seg->lower + (float)seg->upper)/2.0;
-        return (result);
+       *result = ((float) seg->lower + (float) seg->upper) / 2.0;
+       return (result);
 }
 
 float32
-seg_lower(SEG *seg)
+seg_lower(SEG * seg)
 {
-        float32 result = (float32) palloc(sizeof(float32data));
+       float32         result = (float32) palloc(sizeof(float32data));
 
-        if (!seg)
-                return (float32) NULL;
+       if (!seg)
+               return (float32) NULL;
 
-        *result = (float)seg->lower;
-        return (result);
+       *result = (float) seg->lower;
+       return (result);
 }
 
 float32
-seg_upper(SEG *seg)
+seg_upper(SEG * seg)
 {
-        float32 result = (float32) palloc(sizeof(float32data));
+       float32         result = (float32) palloc(sizeof(float32data));
 
-        if (!seg)
-                return (float32) NULL;
+       if (!seg)
+               return (float32) NULL;
 
-        *result = (float)seg->upper;
-        return (result);
+       *result = (float) seg->upper;
+       return (result);
 }
 
 
 /*****************************************************************************
- *                         GiST functions
+ *                                                GiST functions
  *****************************************************************************/
 
 /*
@@ -204,19 +214,20 @@ seg_upper(SEG *seg)
 ** the predicate x op query == FALSE, where op is the oper
 ** corresponding to strategy in the pg_amop table.
 */
-bool 
+bool
 gseg_consistent(GISTENTRY *entry,
-              SEG *query,
-              StrategyNumber strategy)
+                               SEG * query,
+                               StrategyNumber strategy)
 {
-    /*
-    ** if entry is not leaf, use gseg_internal_consistent,
-    ** else use gseg_leaf_consistent
-    */
-    if (GIST_LEAF(entry))
-      return(gseg_leaf_consistent((SEG *)(entry->pred), query, strategy));
-    else
-      return(gseg_internal_consistent((SEG *)(entry->pred), query, strategy));
+
+       /*
+        * * if entry is not leaf, use gseg_internal_consistent, * else use
+        * gseg_leaf_consistent
+        */
+       if (GIST_LEAF(entry))
+               return (gseg_leaf_consistent((SEG *) (entry->pred), query, strategy));
+       else
+               return (gseg_internal_consistent((SEG *) (entry->pred), query, strategy));
 }
 
 /*
@@ -226,49 +237,54 @@ gseg_consistent(GISTENTRY *entry,
 SEG *
 gseg_union(bytea *entryvec, int *sizep)
 {
-    int numranges, i;
-    SEG *out = (SEG *)NULL;
-    SEG *tmp;
+       int                     numranges,
+                               i;
+       SEG                *out = (SEG *) NULL;
+       SEG                *tmp;
 
 #ifdef GIST_DEBUG
-    fprintf(stderr, "union\n");
+       fprintf(stderr, "union\n");
 #endif
 
-    numranges = (VARSIZE(entryvec) - VARHDRSZ)/sizeof(GISTENTRY); 
-    tmp = (SEG *)(((GISTENTRY *)(VARDATA(entryvec)))[0]).pred;
-    *sizep = sizeof(SEG);
+       numranges = (VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY);
+       tmp = (SEG *) (((GISTENTRY *) (VARDATA(entryvec)))[0]).pred;
+       *sizep = sizeof(SEG);
 
-    for (i = 1; i < numranges; i++) {
-       out = gseg_binary_union(tmp, (SEG *)
-                                (((GISTENTRY *)(VARDATA(entryvec)))[i]).pred,
-                                sizep);
+       for (i = 1; i < numranges; i++)
+       {
+               out = gseg_binary_union(tmp, (SEG *)
+                                                  (((GISTENTRY *) (VARDATA(entryvec)))[i]).pred,
+                                                               sizep);
 #ifdef GIST_DEBUG
-       /*
-       fprintf(stderr, "\t%s ^ %s -> %s\n", seg_out(tmp), seg_out((SEG *)(((GISTENTRY *)(VARDATA(entryvec)))[i]).pred), seg_out(out));
-       */
+
+               /*
+                * fprintf(stderr, "\t%s ^ %s -> %s\n", seg_out(tmp), seg_out((SEG
+                * *)(((GISTENTRY *)(VARDATA(entryvec)))[i]).pred), seg_out(out));
+                */
 #endif
 
-       if (i > 1) pfree(tmp);
-       tmp = out;
-    }
+               if (i > 1)
+                       pfree(tmp);
+               tmp = out;
+       }
 
-    return(out);
+       return (out);
 }
 
 /*
 ** GiST Compress and Decompress methods for segments
 ** do not do anything.
 */
-GISTENTRY *
+GISTENTRY  *
 gseg_compress(GISTENTRY *entry)
 {
-    return(entry);
+       return (entry);
 }
 
-GISTENTRY *
+GISTENTRY  *
 gseg_decompress(GISTENTRY *entry)
 {
-    return(entry);
+       return (entry);
 }
 
 /*
@@ -278,287 +294,312 @@ gseg_decompress(GISTENTRY *entry)
 float *
 gseg_penalty(GISTENTRY *origentry, GISTENTRY *newentry, float *result)
 {
-    Datum ud;
-    float tmp1, tmp2;
-    
-    ud = (Datum)seg_union((SEG *)(origentry->pred), (SEG *)(newentry->pred));
-    rt_seg_size((SEG *)ud, &tmp1);
-    rt_seg_size((SEG *)(origentry->pred), &tmp2);
-    *result = tmp1 - tmp2;
-    pfree((char *)ud);
+       Datum           ud;
+       float           tmp1,
+                               tmp2;
+
+       ud = (Datum) seg_union((SEG *) (origentry->pred), (SEG *) (newentry->pred));
+       rt_seg_size((SEG *) ud, &tmp1);
+       rt_seg_size((SEG *) (origentry->pred), &tmp2);
+       *result = tmp1 - tmp2;
+       pfree((char *) ud);
 
 #ifdef GIST_DEBUG
-    fprintf(stderr, "penalty\n");
-    fprintf(stderr, "\t%g\n", *result);
+       fprintf(stderr, "penalty\n");
+       fprintf(stderr, "\t%g\n", *result);
 #endif
 
-    return(result);
+       return (result);
 }
 
 
 
 /*
 ** The GiST PickSplit method for segments
-** We use Guttman's poly time split algorithm 
+** We use Guttman's poly time split algorithm
 */
 GIST_SPLITVEC *
 gseg_picksplit(bytea *entryvec,
-             GIST_SPLITVEC *v)
+                          GIST_SPLITVEC *v)
 {
-    OffsetNumber i, j;
-    SEG *datum_alpha, *datum_beta;
-    SEG *datum_l, *datum_r;
-    SEG *union_d, *union_dl, *union_dr;
-    SEG *inter_d;
-    bool firsttime;
-    float size_alpha, size_beta, size_union, size_inter;
-    float size_waste, waste;
-    float size_l, size_r;
-    int nbytes;
-    OffsetNumber seed_1 = 0, seed_2 = 0;
-    OffsetNumber *left, *right;
-    OffsetNumber maxoff;
+       OffsetNumber i,
+                               j;
+       SEG                *datum_alpha,
+                          *datum_beta;
+       SEG                *datum_l,
+                          *datum_r;
+       SEG                *union_d,
+                          *union_dl,
+                          *union_dr;
+       SEG                *inter_d;
+       bool            firsttime;
+       float           size_alpha,
+                               size_beta,
+                               size_union,
+                               size_inter;
+       float           size_waste,
+                               waste;
+       float           size_l,
+                               size_r;
+       int                     nbytes;
+       OffsetNumber seed_1 = 0,
+                               seed_2 = 0;
+       OffsetNumber *left,
+                          *right;
+       OffsetNumber maxoff;
 
 #ifdef GIST_DEBUG
-    fprintf(stderr, "picksplit\n");
+       fprintf(stderr, "picksplit\n");
 #endif
 
-    maxoff = ((VARSIZE(entryvec) - VARHDRSZ)/sizeof(GISTENTRY)) - 2;
-    nbytes =  (maxoff + 2) * sizeof(OffsetNumber);
-    v->spl_left = (OffsetNumber *) palloc(nbytes);
-    v->spl_right = (OffsetNumber *) palloc(nbytes);
-    
-    firsttime = true;
-    waste = 0.0;
-    
-    for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i)) {
-       datum_alpha = (SEG *)(((GISTENTRY *)(VARDATA(entryvec)))[i].pred);
-       for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j)) {
-           datum_beta = (SEG *)(((GISTENTRY *)(VARDATA(entryvec)))[j].pred);
-           
-           /* compute the wasted space by unioning these guys */
-           /* size_waste = size_union - size_inter; */
-           union_d = (SEG *)seg_union(datum_alpha, datum_beta);
-           rt_seg_size(union_d, &size_union);
-           inter_d = (SEG *)seg_inter(datum_alpha, datum_beta);
-           rt_seg_size(inter_d, &size_inter);
-           size_waste = size_union - size_inter;
-           
-           pfree(union_d);
-           
-           if (inter_d != (SEG *) NULL)
-               pfree(inter_d);
-           
-           /*
-            *  are these a more promising split that what we've
-            *  already seen?
-            */
-           
-           if (size_waste > waste || firsttime) {
-               waste = size_waste;
-               seed_1 = i;
-               seed_2 = j;
-               firsttime = false;
-           }
+       maxoff = ((VARSIZE(entryvec) - VARHDRSZ) / sizeof(GISTENTRY)) - 2;
+       nbytes = (maxoff + 2) * sizeof(OffsetNumber);
+       v->spl_left = (OffsetNumber *) palloc(nbytes);
+       v->spl_right = (OffsetNumber *) palloc(nbytes);
+
+       firsttime = true;
+       waste = 0.0;
+
+       for (i = FirstOffsetNumber; i < maxoff; i = OffsetNumberNext(i))
+       {
+               datum_alpha = (SEG *) (((GISTENTRY *) (VARDATA(entryvec)))[i].pred);
+               for (j = OffsetNumberNext(i); j <= maxoff; j = OffsetNumberNext(j))
+               {
+                       datum_beta = (SEG *) (((GISTENTRY *) (VARDATA(entryvec)))[j].pred);
+
+                       /* compute the wasted space by unioning these guys */
+                       /* size_waste = size_union - size_inter; */
+                       union_d = (SEG *) seg_union(datum_alpha, datum_beta);
+                       rt_seg_size(union_d, &size_union);
+                       inter_d = (SEG *) seg_inter(datum_alpha, datum_beta);
+                       rt_seg_size(inter_d, &size_inter);
+                       size_waste = size_union - size_inter;
+
+                       pfree(union_d);
+
+                       if (inter_d != (SEG *) NULL)
+                               pfree(inter_d);
+
+                       /*
+                        * are these a more promising split that what we've already
+                        * seen?
+                        */
+
+                       if (size_waste > waste || firsttime)
+                       {
+                               waste = size_waste;
+                               seed_1 = i;
+                               seed_2 = j;
+                               firsttime = false;
+                       }
+               }
        }
-    }
-    
-    left = v->spl_left;
-    v->spl_nleft = 0;
-    right = v->spl_right;
-    v->spl_nright = 0;
-    
-    datum_alpha = (SEG *)(((GISTENTRY *)(VARDATA(entryvec)))[seed_1].pred);
-    datum_l = (SEG *)seg_union(datum_alpha, datum_alpha);
-    rt_seg_size((SEG *)datum_l, &size_l);
-    datum_beta = (SEG *)(((GISTENTRY *)(VARDATA(entryvec)))[seed_2].pred);;
-    datum_r = (SEG *)seg_union(datum_beta, datum_beta);
-    rt_seg_size((SEG *)datum_r, &size_r);
-    
-    /*
-     *  Now split up the regions between the two seeds.  An important
-     *  property of this split algorithm is that the split vector v
-     *  has the indices of items to be split in order in its left and
-     *  right vectors.  We exploit this property by doing a merge in
-     *  the code that actually splits the page.
-     *
-     *  For efficiency, we also place the new index tuple in this loop.
-     *  This is handled at the very end, when we have placed all the
-     *  existing tuples and i == maxoff + 1.
-     */
-    
-    maxoff = OffsetNumberNext(maxoff);
-    for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) {
-       
+
+       left = v->spl_left;
+       v->spl_nleft = 0;
+       right = v->spl_right;
+       v->spl_nright = 0;
+
+       datum_alpha = (SEG *) (((GISTENTRY *) (VARDATA(entryvec)))[seed_1].pred);
+       datum_l = (SEG *) seg_union(datum_alpha, datum_alpha);
+       rt_seg_size((SEG *) datum_l, &size_l);
+       datum_beta = (SEG *) (((GISTENTRY *) (VARDATA(entryvec)))[seed_2].pred);;
+       datum_r = (SEG *) seg_union(datum_beta, datum_beta);
+       rt_seg_size((SEG *) datum_r, &size_r);
+
        /*
-        *  If we've already decided where to place this item, just
-        *  put it on the right list.  Otherwise, we need to figure
-        *  out which page needs the least enlargement in order to
-        *  store the item.
+        * Now split up the regions between the two seeds.      An important
+        * property of this split algorithm is that the split vector v has the
+        * indices of items to be split in order in its left and right
+        * vectors.  We exploit this property by doing a merge in the code
+        * that actually splits the page.
+        *
+        * For efficiency, we also place the new index tuple in this loop. This
+        * is handled at the very end, when we have placed all the existing
+        * tuples and i == maxoff + 1.
         */
-       
-       if (i == seed_1) {
-           *left++ = i;
-           v->spl_nleft++;
-           continue;
-       } else if (i == seed_2) {
-           *right++ = i;
-           v->spl_nright++;
-           continue;
-       }
-       
-       /* okay, which page needs least enlargement? */ 
-       datum_alpha = (SEG *)(((GISTENTRY *)(VARDATA(entryvec)))[i].pred);
-       union_dl = (SEG *)seg_union(datum_l, datum_alpha);
-       union_dr = (SEG *)seg_union(datum_r, datum_alpha);
-       rt_seg_size((SEG *)union_dl, &size_alpha);
-       rt_seg_size((SEG *)union_dr, &size_beta);
-       
-       /* pick which page to add it to */
-       if (size_alpha - size_l < size_beta - size_r) {
-           pfree(datum_l);
-           pfree(union_dr);
-           datum_l = union_dl;
-           size_l = size_alpha;
-           *left++ = i;
-           v->spl_nleft++;
-       } else {
-           pfree(datum_r);
-           pfree(union_dl);
-           datum_r = union_dr;
-           size_r = size_alpha;
-           *right++ = i;
-           v->spl_nright++;
+
+       maxoff = OffsetNumberNext(maxoff);
+       for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+       {
+
+               /*
+                * If we've already decided where to place this item, just put it
+                * on the right list.  Otherwise, we need to figure out which page
+                * needs the least enlargement in order to store the item.
+                */
+
+               if (i == seed_1)
+               {
+                       *left++ = i;
+                       v->spl_nleft++;
+                       continue;
+               }
+               else if (i == seed_2)
+               {
+                       *right++ = i;
+                       v->spl_nright++;
+                       continue;
+               }
+
+               /* okay, which page needs least enlargement? */
+               datum_alpha = (SEG *) (((GISTENTRY *) (VARDATA(entryvec)))[i].pred);
+               union_dl = (SEG *) seg_union(datum_l, datum_alpha);
+               union_dr = (SEG *) seg_union(datum_r, datum_alpha);
+               rt_seg_size((SEG *) union_dl, &size_alpha);
+               rt_seg_size((SEG *) union_dr, &size_beta);
+
+               /* pick which page to add it to */
+               if (size_alpha - size_l < size_beta - size_r)
+               {
+                       pfree(datum_l);
+                       pfree(union_dr);
+                       datum_l = union_dl;
+                       size_l = size_alpha;
+                       *left++ = i;
+                       v->spl_nleft++;
+               }
+               else
+               {
+                       pfree(datum_r);
+                       pfree(union_dl);
+                       datum_r = union_dr;
+                       size_r = size_alpha;
+                       *right++ = i;
+                       v->spl_nright++;
+               }
        }
-    }
-    *left = *right = FirstOffsetNumber;        /* sentinel value, see dosplit() */
-    
-    v->spl_ldatum = (char *)datum_l;
-    v->spl_rdatum = (char *)datum_r;
+       *left = *right = FirstOffsetNumber; /* sentinel value, see dosplit() */
+
+       v->spl_ldatum = (char *) datum_l;
+       v->spl_rdatum = (char *) datum_r;
 
-    return v;
+       return v;
 }
 
 /*
 ** Equality methods
 */
 bool *
-gseg_same(SEG *b1, SEG *b2, bool *result)
+gseg_same(SEG * b1, SEG * b2, bool *result)
 {
-  if (seg_same(b1, b2))
-    *result = TRUE;
-  else *result = FALSE;
+       if (seg_same(b1, b2))
+               *result = TRUE;
+       else
+               *result = FALSE;
 
 #ifdef GIST_DEBUG
-  fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE" ));
+       fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE"));
 #endif
 
-  return(result);
+       return (result);
 }
 
-/* 
+/*
 ** SUPPORT ROUTINES
 */
-bool 
-gseg_leaf_consistent(SEG *key,
-                    SEG *query,
-                    StrategyNumber strategy)
+bool
+gseg_leaf_consistent(SEG * key,
+                                        SEG * query,
+                                        StrategyNumber strategy)
 {
-    bool retval;
+       bool            retval;
 
 #ifdef GIST_QUERY_DEBUG
-  fprintf(stderr, "leaf_consistent, %d\n", strategy);
+       fprintf(stderr, "leaf_consistent, %d\n", strategy);
 #endif
 
-    switch(strategy) {
-    case RTLeftStrategyNumber:
-      retval = (bool)seg_left(key, query);
-      break;
-    case RTOverLeftStrategyNumber:
-      retval = (bool)seg_over_left(key,query);
-      break;
-    case RTOverlapStrategyNumber:
-      retval = (bool)seg_overlap(key, query);
-      break;
-    case RTOverRightStrategyNumber:
-      retval = (bool)seg_over_right(key, query);
-      break;
-    case RTRightStrategyNumber:
-      retval = (bool)seg_right(key, query);
-      break;
-    case RTSameStrategyNumber:
-      retval = (bool)seg_same(key, query);
-      break;
-    case RTContainsStrategyNumber:
-      retval = (bool)seg_contains(key, query);
-      break;
-    case RTContainedByStrategyNumber:
-      retval = (bool)seg_contained(key,query);
-      break;
-    default:
-      retval = FALSE;
-    }
-    return(retval);
+       switch (strategy)
+       {
+               case RTLeftStrategyNumber:
+                       retval = (bool) seg_left(key, query);
+                       break;
+               case RTOverLeftStrategyNumber:
+                       retval = (bool) seg_over_left(key, query);
+                       break;
+               case RTOverlapStrategyNumber:
+                       retval = (bool) seg_overlap(key, query);
+                       break;
+               case RTOverRightStrategyNumber:
+                       retval = (bool) seg_over_right(key, query);
+                       break;
+               case RTRightStrategyNumber:
+                       retval = (bool) seg_right(key, query);
+                       break;
+               case RTSameStrategyNumber:
+                       retval = (bool) seg_same(key, query);
+                       break;
+               case RTContainsStrategyNumber:
+                       retval = (bool) seg_contains(key, query);
+                       break;
+               case RTContainedByStrategyNumber:
+                       retval = (bool) seg_contained(key, query);
+                       break;
+               default:
+                       retval = FALSE;
+       }
+       return (retval);
 }
 
-bool 
-gseg_internal_consistent(SEG *key,
-                       SEG *query,
-                       StrategyNumber strategy)
+bool
+gseg_internal_consistent(SEG * key,
+                                                SEG * query,
+                                                StrategyNumber strategy)
 {
-    bool retval;
+       bool            retval;
 
 #ifdef GIST_QUERY_DEBUG
-  fprintf(stderr, "internal_consistent, %d\n", strategy);
+       fprintf(stderr, "internal_consistent, %d\n", strategy);
 #endif
 
-    switch(strategy) {
-    case RTLeftStrategyNumber:
-    case RTOverLeftStrategyNumber:
-      retval = (bool)seg_over_left(key,query);
-      break;
-    case RTOverlapStrategyNumber:
-      retval = (bool)seg_overlap(key, query);
-      break;
-    case RTOverRightStrategyNumber:
-    case RTRightStrategyNumber:
-      retval = (bool)seg_right(key, query);
-      break;
-    case RTSameStrategyNumber:
-    case RTContainsStrategyNumber:
-      retval = (bool)seg_contains(key, query);
-      break;
-    case RTContainedByStrategyNumber:
-      retval = (bool)seg_overlap(key, query);
-      break;
-    default:
-      retval = FALSE;
-    }
-    return(retval);
+       switch (strategy)
+       {
+               case RTLeftStrategyNumber:
+               case RTOverLeftStrategyNumber:
+                       retval = (bool) seg_over_left(key, query);
+                       break;
+               case RTOverlapStrategyNumber:
+                       retval = (bool) seg_overlap(key, query);
+                       break;
+               case RTOverRightStrategyNumber:
+               case RTRightStrategyNumber:
+                       retval = (bool) seg_right(key, query);
+                       break;
+               case RTSameStrategyNumber:
+               case RTContainsStrategyNumber:
+                       retval = (bool) seg_contains(key, query);
+                       break;
+               case RTContainedByStrategyNumber:
+                       retval = (bool) seg_overlap(key, query);
+                       break;
+               default:
+                       retval = FALSE;
+       }
+       return (retval);
 }
 
 SEG *
-gseg_binary_union(SEG *r1, SEG *r2, int *sizep)
+gseg_binary_union(SEG * r1, SEG * r2, int *sizep)
 {
-    SEG *retval;
+       SEG                *retval;
 
-    retval = seg_union(r1, r2);
-    *sizep = sizeof(SEG);
+       retval = seg_union(r1, r2);
+       *sizep = sizeof(SEG);
 
-    return (retval);
+       return (retval);
 }
 
 
 bool
-seg_contains(SEG *a, SEG *b)
+seg_contains(SEG * a, SEG * b)
 {
-  return ( (a->lower <= b->lower) && (a->upper >= b->upper) );
+       return ((a->lower <= b->lower) && (a->upper >= b->upper));
 }
 
 bool
-seg_contained(SEG *a, SEG *b)
+seg_contained(SEG * a, SEG * b)
 {
-  return ( seg_contains(b, a) );
+       return (seg_contains(b, a));
 }
 
 /*****************************************************************************
@@ -566,209 +607,214 @@ seg_contained(SEG *a, SEG *b)
  *****************************************************************************/
 
 bool
-seg_same(SEG *a, SEG *b)
+seg_same(SEG * a, SEG * b)
 {
-  return seg_cmp(a, b) == 0;
+       return seg_cmp(a, b) == 0;
 }
 
-/*  seg_overlap -- does a overlap b?
+/*     seg_overlap -- does a overlap b?
  */
 bool
-seg_overlap(SEG *a, SEG *b)
+seg_overlap(SEG * a, SEG * b)
 {
-  return (
-         ((a->upper >= b->upper) && (a->lower <= b->upper)) 
-         ||
-         ((b->upper >= a->upper) && (b->lower <= a->upper))
-         );
+       return (
+                       ((a->upper >= b->upper) && (a->lower <= b->upper))
+                       ||
+                       ((b->upper >= a->upper) && (b->lower <= a->upper))
+       );
 }
 
-/*  seg_overleft -- is the right edge of (a) located to the left of the right edge of (b)?
+/*     seg_overleft -- is the right edge of (a) located to the left of the right edge of (b)?
  */
 bool
-seg_over_left(SEG *a, SEG *b)
+seg_over_left(SEG * a, SEG * b)
 {
-        return ( a->upper <= b->upper && !seg_left(a, b) && !seg_right(a, b));
+       return (a->upper <= b->upper && !seg_left(a, b) && !seg_right(a, b));
 }
 
-/*  seg_left -- is (a) entirely on the left of (b)?
+/*     seg_left -- is (a) entirely on the left of (b)?
  */
 bool
-seg_left(SEG *a, SEG *b)
+seg_left(SEG * a, SEG * b)
 {
-        return ( a->upper < b->lower );
+       return (a->upper < b->lower);
 }
 
-/*  seg_right -- is (a) entirely on the right of (b)?
+/*     seg_right -- is (a) entirely on the right of (b)?
  */
 bool
-seg_right(SEG *a, SEG *b)
+seg_right(SEG * a, SEG * b)
 {
-        return ( a->lower > b->upper );
+       return (a->lower > b->upper);
 }
 
-/*  seg_overright -- is the left edge of (a) located to the right of the left edge of (b)?
+/*     seg_overright -- is the left edge of (a) located to the right of the left edge of (b)?
  */
 bool
-seg_over_right(SEG *a, SEG *b)
+seg_over_right(SEG * a, SEG * b)
 {
-        return (a->lower >= b->lower && !seg_left(a, b) && !seg_right(a, b));
+       return (a->lower >= b->lower && !seg_left(a, b) && !seg_right(a, b));
 }
 
 
 SEG *
-seg_union(SEG *a, SEG *b)
+seg_union(SEG * a, SEG * b)
 {
-  SEG *n;
-  
-  n = (SEG *) palloc(sizeof(*n));
-
-  /* take max of upper endpoints */
-  if (a->upper > b->upper)
-  {
-         n->upper = a->upper;
-         n->u_sigd = a->u_sigd;
-         n->u_ext = a->u_ext;
-  }
-  else
-  {
-         n->upper = b->upper;
-         n->u_sigd = b->u_sigd;
-         n->u_ext = b->u_ext;
-  }
-
-  /* take min of lower endpoints */
-  if (a->lower < b->lower)
-  {
-         n->lower = a->lower;
-         n->l_sigd = a->l_sigd;
-         n->l_ext = a->l_ext;
-  }
-  else
-  {
-         n->lower = b->lower;
-         n->l_sigd = b->l_sigd;
-         n->l_ext = b->l_ext;
-  }
-
-  return (n);
+       SEG                *n;
+
+       n = (SEG *) palloc(sizeof(*n));
+
+       /* take max of upper endpoints */
+       if (a->upper > b->upper)
+       {
+               n->upper = a->upper;
+               n->u_sigd = a->u_sigd;
+               n->u_ext = a->u_ext;
+       }
+       else
+       {
+               n->upper = b->upper;
+               n->u_sigd = b->u_sigd;
+               n->u_ext = b->u_ext;
+       }
+
+       /* take min of lower endpoints */
+       if (a->lower < b->lower)
+       {
+               n->lower = a->lower;
+               n->l_sigd = a->l_sigd;
+               n->l_ext = a->l_ext;
+       }
+       else
+       {
+               n->lower = b->lower;
+               n->l_sigd = b->l_sigd;
+               n->l_ext = b->l_ext;
+       }
+
+       return (n);
 }
 
 
 SEG *
-seg_inter(SEG *a, SEG *b)
+seg_inter(SEG * a, SEG * b)
 {
-  SEG *n;
-  
-  n = (SEG *) palloc(sizeof(*n));
-
-  /* take min of upper endpoints */
-  if (a->upper < b->upper)
-  {
-         n->upper = a->upper;
-         n->u_sigd = a->u_sigd;
-         n->u_ext = a->u_ext;
-  }
-  else
-  {
-         n->upper = b->upper;
-         n->u_sigd = b->u_sigd;
-         n->u_ext = b->u_ext;
-  }
-
-  /* take max of lower endpoints */
-  if (a->lower > b->lower)
-  {
-         n->lower = a->lower;
-         n->l_sigd = a->l_sigd;
-         n->l_ext = a->l_ext;
-  }
-  else
-  {
-         n->lower = b->lower;
-         n->l_sigd = b->l_sigd;
-         n->l_ext = b->l_ext;
-  }
-
-  return (n);
+       SEG                *n;
+
+       n = (SEG *) palloc(sizeof(*n));
+
+       /* take min of upper endpoints */
+       if (a->upper < b->upper)
+       {
+               n->upper = a->upper;
+               n->u_sigd = a->u_sigd;
+               n->u_ext = a->u_ext;
+       }
+       else
+       {
+               n->upper = b->upper;
+               n->u_sigd = b->u_sigd;
+               n->u_ext = b->u_ext;
+       }
+
+       /* take max of lower endpoints */
+       if (a->lower > b->lower)
+       {
+               n->lower = a->lower;
+               n->l_sigd = a->l_sigd;
+               n->l_ext = a->l_ext;
+       }
+       else
+       {
+               n->lower = b->lower;
+               n->l_sigd = b->l_sigd;
+               n->l_ext = b->l_ext;
+       }
+
+       return (n);
 }
 
 void
-rt_seg_size(SEG *a, float *size)
+rt_seg_size(SEG * a, float *size)
 {
-  if (a == (SEG *) NULL || a->upper <= a->lower)
-    *size = 0.0;
-  else
-    *size = (float) abs(a->upper - a->lower);
-  
-  return;
+       if (a == (SEG *) NULL || a->upper <= a->lower)
+               *size = 0.0;
+       else
+               *size = (float) abs(a->upper - a->lower);
+
+       return;
 }
 
 float *
-seg_size(SEG *a)
+seg_size(SEG * a)
 {
-  float *result;
+       float      *result;
+
+       result = (float *) palloc(sizeof(float));
 
-  result = (float *) palloc(sizeof(float));
-  
-  *result = (float) abs(a->upper - a->lower);
+       *result = (float) abs(a->upper - a->lower);
 
-  return(result);
+       return (result);
 }
 
 
 /*****************************************************************************
- *                 Miscellaneous operators
+ *                                Miscellaneous operators
  *****************************************************************************/
 int32
-seg_cmp(SEG *a, SEG *b)
+seg_cmp(SEG * a, SEG * b)
 {
+
        /*
         * First compare on lower boundary position
         */
-       if ( a->lower < b->lower )
+       if (a->lower < b->lower)
                return -1;
-       if ( a->lower > b->lower )
+       if (a->lower > b->lower)
                return 1;
+
        /*
         * a->lower == b->lower, so consider type of boundary.
         *
-        * A '-' lower bound is < any other kind (this could only be relevant
-        * if -HUGE is used as a regular data value).
-        * A '<' lower bound is < any other kind except '-'.
-        * A '>' lower bound is > any other kind.
+        * A '-' lower bound is < any other kind (this could only be relevant if
+        * -HUGE is used as a regular data value). A '<' lower bound is < any
+        * other kind except '-'. A '>' lower bound is > any other kind.
         */
-       if ( a->l_ext != b->l_ext )
+       if (a->l_ext != b->l_ext)
        {
-               if ( a->l_ext == '-')
+               if (a->l_ext == '-')
                        return -1;
-               if ( b->l_ext == '-')
+               if (b->l_ext == '-')
                        return 1;
-               if ( a->l_ext == '<')
+               if (a->l_ext == '<')
                        return -1;
-               if ( b->l_ext == '<')
+               if (b->l_ext == '<')
                        return 1;
-               if ( a->l_ext == '>')
+               if (a->l_ext == '>')
                        return 1;
-               if ( b->l_ext == '>')
+               if (b->l_ext == '>')
                        return -1;
        }
+
        /*
         * For other boundary types, consider # of significant digits first.
         */
-       if ( a->l_sigd < b->l_sigd ) /* (a) is blurred and is likely to include (b) */
+       if (a->l_sigd < b->l_sigd)      /* (a) is blurred and is likely to include
+                                                                * (b) */
                return -1;
-       if ( a->l_sigd > b->l_sigd ) /* (a) is less blurred and is likely to be included in (b) */
+       if (a->l_sigd > b->l_sigd)      /* (a) is less blurred and is likely to be
+                                                                * included in (b) */
                return 1;
+
        /*
         * For same # of digits, an approximate boundary is more blurred than
         * exact.
         */
-       if ( a->l_ext != b->l_ext )
+       if (a->l_ext != b->l_ext)
        {
-               if ( a->l_ext == '~' ) /* (a) is approximate, while (b) is exact */
+               if (a->l_ext == '~')    /* (a) is approximate, while (b) is exact */
                        return -1;
-               if ( b->l_ext == '~' )
+               if (b->l_ext == '~')
                        return 1;
                /* can't get here unless data is corrupt */
                elog(ERROR, "seg_cmp: bogus lower boundary types %d %d",
@@ -780,50 +826,54 @@ seg_cmp(SEG *a, SEG *b)
        /*
         * First compare on upper boundary position
         */
-       if ( a->upper < b->upper )
+       if (a->upper < b->upper)
                return -1;
-       if ( a->upper > b->upper )
+       if (a->upper > b->upper)
                return 1;
+
        /*
         * a->upper == b->upper, so consider type of boundary.
         *
-        * A '-' upper bound is > any other kind (this could only be relevant
-        * if HUGE is used as a regular data value).
-        * A '<' upper bound is < any other kind.
-        * A '>' upper bound is > any other kind except '-'.
+        * A '-' upper bound is > any other kind (this could only be relevant if
+        * HUGE is used as a regular data value). A '<' upper bound is < any
+        * other kind. A '>' upper bound is > any other kind except '-'.
         */
-       if ( a->u_ext != b->u_ext )
+       if (a->u_ext != b->u_ext)
        {
-               if ( a->u_ext == '-')
+               if (a->u_ext == '-')
                        return 1;
-               if ( b->u_ext == '-')
+               if (b->u_ext == '-')
                        return -1;
-               if ( a->u_ext == '<')
+               if (a->u_ext == '<')
                        return -1;
-               if ( b->u_ext == '<')
+               if (b->u_ext == '<')
                        return 1;
-               if ( a->u_ext == '>')
+               if (a->u_ext == '>')
                        return 1;
-               if ( b->u_ext == '>')
+               if (b->u_ext == '>')
                        return -1;
        }
+
        /*
         * For other boundary types, consider # of significant digits first.
         * Note result here is converse of the lower-boundary case.
         */
-       if ( a->u_sigd < b->u_sigd ) /* (a) is blurred and is likely to include (b) */
+       if (a->u_sigd < b->u_sigd)      /* (a) is blurred and is likely to include
+                                                                * (b) */
                return 1;
-       if ( a->u_sigd > b->u_sigd ) /* (a) is less blurred and is likely to be included in (b) */
+       if (a->u_sigd > b->u_sigd)      /* (a) is less blurred and is likely to be
+                                                                * included in (b) */
                return -1;
+
        /*
         * For same # of digits, an approximate boundary is more blurred than
         * exact.  Again, result is converse of lower-boundary case.
         */
-       if ( a->u_ext != b->u_ext )
+       if (a->u_ext != b->u_ext)
        {
-               if ( a->u_ext == '~' ) /* (a) is approximate, while (b) is exact */
+               if (a->u_ext == '~')    /* (a) is approximate, while (b) is exact */
                        return 1;
-               if ( b->u_ext == '~' )
+               if (b->u_ext == '~')
                        return -1;
                /* can't get here unless data is corrupt */
                elog(ERROR, "seg_cmp: bogus upper boundary types %d %d",
@@ -834,40 +884,40 @@ seg_cmp(SEG *a, SEG *b)
 }
 
 bool
-seg_lt(SEG *a, SEG *b)
+seg_lt(SEG * a, SEG * b)
 {
-  return seg_cmp(a, b) < 0;
+       return seg_cmp(a, b) < 0;
 }
 
 bool
-seg_le(SEG *a, SEG *b)
+seg_le(SEG * a, SEG * b)
 {
-  return seg_cmp(a, b) <= 0;
+       return seg_cmp(a, b) <= 0;
 }
 
 bool
-seg_gt(SEG *a, SEG *b)
+seg_gt(SEG * a, SEG * b)
 {
-  return seg_cmp(a, b) > 0;
+       return seg_cmp(a, b) > 0;
 }
 
 
 bool
-seg_ge(SEG *a, SEG *b)
+seg_ge(SEG * a, SEG * b)
 {
-  return seg_cmp(a, b) >= 0;
+       return seg_cmp(a, b) >= 0;
 }
 
 bool
-seg_different(SEG *a, SEG *b)
+seg_different(SEG * a, SEG * b)
 {
-  return seg_cmp(a, b) != 0;
+       return seg_cmp(a, b) != 0;
 }
 
 
 
 /*****************************************************************************
- *                 Auxiliary functions
+ *                                Auxiliary functions
  *****************************************************************************/
 
 /* The purpose of this routine is to print the floating point
@@ -875,126 +925,150 @@ seg_different(SEG *a, SEG *b)
  * is similar to %.ng except it prints 8.00 where %.ng would
  * print 8
  */
-static int restore ( char * result, float val, int n )
+static int
+restore(char *result, float val, int n)
 {
-  static char efmt[8] = {'%', '-', '1', '5', '.', '#', 'e', 0};
-  char buf[25] = {
-    '0', '0', '0', '0', '0',
-    '0', '0', '0', '0', '0',
-    '0', '0', '0', '0', '0',
-    '0', '0', '0', '0', '0',
-    '0', '0', '0', '0', '\0'
-  };
-  char *p;
-  char *mant;
-  int exp;
-  int i, dp, sign;
-  /* put a cap on the number of siugnificant digits to avoid
-     nonsense in the output */
-  n = min(n, FLT_DIG);
-
-  /* remember the sign */
-  sign = ( val < 0 ? 1 : 0 );
-
-  efmt[5] = '0' + (n-1)%10; /* makes %-15.(n-1)e -- this format guarantees that 
-                            the exponent is always present */
-
-  sprintf(result, efmt, val);
-
-  /* trim the spaces left by the %e */
-  for( p = result; *p != ' '; p++ ); *p = '\0';
-
-  /* get the exponent */
-  mant = (char *)strtok( strdup(result), "e" );
-  exp = atoi(strtok( NULL, "e" ));
-
-  if ( exp == 0 ) {
-    /* use the supplied mantyssa with sign */
-    strcpy((char *)index(result, 'e'), "");
-  }
-  else {
-    if ( abs( exp ) <= 4 ) {
-      /* remove the decimal point from the mantyssa and write the digits to the buf array */
-      for( p = result + sign, i = 10, dp = 0; *p != 'e'; p++, i++ ) {
-       buf[i] = *p;
-       if( *p == '.' ) {
-         dp = i--; /* skip the decimal point */
-       }
-      }
-      if (dp == 0) dp = i--; /* no decimal point was found in the above for() loop */
-  
-      if ( exp > 0 ) {
-       if ( dp - 10 + exp >= n ) { 
-         /* 
-            the decimal point is behind the last significant digit;
-            the digits in between must be converted to the exponent
-            and the decimal point placed after the first digit
-          */
-         exp = dp - 10 + exp - n;
-         buf[10+n] = '\0'; 
-         
-         /* insert the decimal point */
-         if ( n > 1 ) {
-           dp = 11;
-           for ( i = 23; i > dp; i-- ) {
-             buf[i] = buf[i-1];
-           }
-           buf[dp] = '.';
-         }
-         
-         /* adjust the exponent by the number of digits after the decimal point */
-         if ( n > 1 ) {
-           sprintf(&buf[11+n], "e%d", exp + n - 1);
-         }
-         else {
-           sprintf(&buf[11], "e%d", exp + n - 1);
-         }
-         
-         if ( sign ) {
-           buf[9] = '-'; 
-           strcpy(result, &buf[9]);
-         }
-         else {
-           strcpy(result, &buf[10]);
-         }
-       }
-       else { /* insert the decimal point */
-         dp += exp;
-         for ( i = 23; i > dp; i-- ) {
-           buf[i] = buf[i-1];
-         }
-         buf[11+n] = '\0';
-         buf[dp] = '.';
-         if ( sign ) {
-           buf[9] = '-';
-           strcpy(result, &buf[9]);
-         }
-         else {
-           strcpy(result, &buf[10]);
-         }
+       static char efmt[8] = {'%', '-', '1', '5', '.', '#', 'e', 0};
+       char            buf[25] = {
+               '0', '0', '0', '0', '0',
+               '0', '0', '0', '0', '0',
+               '0', '0', '0', '0', '0',
+               '0', '0', '0', '0', '0',
+               '0', '0', '0', '0', '\0'
+       };
+       char       *p;
+       char       *mant;
+       int                     exp;
+       int                     i,
+                               dp,
+                               sign;
+
+       /*
+        * put a cap on the number of siugnificant digits to avoid nonsense in
+        * the output
+        */
+       n = min(n, FLT_DIG);
+
+       /* remember the sign */
+       sign = (val < 0 ? 1 : 0);
+
+       efmt[5] = '0' + (n - 1) % 10;           /* makes %-15.(n-1)e -- this
+                                                                                * format guarantees that the
+                                                                                * exponent is always present */
+
+       sprintf(result, efmt, val);
+
+       /* trim the spaces left by the %e */
+       for (p = result; *p != ' '; p++);
+       *p = '\0';
+
+       /* get the exponent */
+       mant = (char *) strtok(strdup(result), "e");
+       exp = atoi(strtok(NULL, "e"));
+
+       if (exp == 0)
+       {
+               /* use the supplied mantyssa with sign */
+               strcpy((char *) index(result, 'e'), "");
        }
-      }
-      else { /* exp <= 0 */
-       dp += exp - 1;
-       buf[10+n] = '\0'; 
-       buf[dp] = '.'; 
-       if ( sign ) {
-         buf[dp-2] = '-'; 
-         strcpy(result, &buf[dp-2]);
+       else
+       {
+               if (abs(exp) <= 4)
+               {
+
+                       /*
+                        * remove the decimal point from the mantyssa and write the
+                        * digits to the buf array
+                        */
+                       for (p = result + sign, i = 10, dp = 0; *p != 'e'; p++, i++)
+                       {
+                               buf[i] = *p;
+                               if (*p == '.')
+                               {
+                                       dp = i--;       /* skip the decimal point */
+                               }
+                       }
+                       if (dp == 0)
+                               dp = i--;               /* no decimal point was found in the above
+                                                                * for() loop */
+
+                       if (exp > 0)
+                       {
+                               if (dp - 10 + exp >= n)
+                               {
+
+                                       /*
+                                        * the decimal point is behind the last significant
+                                        * digit; the digits in between must be converted to
+                                        * the exponent and the decimal point placed after the
+                                        * first digit
+                                        */
+                                       exp = dp - 10 + exp - n;
+                                       buf[10 + n] = '\0';
+
+                                       /* insert the decimal point */
+                                       if (n > 1)
+                                       {
+                                               dp = 11;
+                                               for (i = 23; i > dp; i--)
+                                                       buf[i] = buf[i - 1];
+                                               buf[dp] = '.';
+                                       }
+
+                                       /*
+                                        * adjust the exponent by the number of digits after
+                                        * the decimal point
+                                        */
+                                       if (n > 1)
+                                               sprintf(&buf[11 + n], "e%d", exp + n - 1);
+                                       else
+                                               sprintf(&buf[11], "e%d", exp + n - 1);
+
+                                       if (sign)
+                                       {
+                                               buf[9] = '-';
+                                               strcpy(result, &buf[9]);
+                                       }
+                                       else
+                                               strcpy(result, &buf[10]);
+                               }
+                               else
+                               {                               /* insert the decimal point */
+                                       dp += exp;
+                                       for (i = 23; i > dp; i--)
+                                               buf[i] = buf[i - 1];
+                                       buf[11 + n] = '\0';
+                                       buf[dp] = '.';
+                                       if (sign)
+                                       {
+                                               buf[9] = '-';
+                                               strcpy(result, &buf[9]);
+                                       }
+                                       else
+                                               strcpy(result, &buf[10]);
+                               }
+                       }
+                       else
+                       {                                       /* exp <= 0 */
+                               dp += exp - 1;
+                               buf[10 + n] = '\0';
+                               buf[dp] = '.';
+                               if (sign)
+                               {
+                                       buf[dp - 2] = '-';
+                                       strcpy(result, &buf[dp - 2]);
+                               }
+                               else
+                                       strcpy(result, &buf[dp - 1]);
+                       }
+               }
+
+               /* do nothing for abs(exp) > 4; %e must be OK */
+               /* just get rid of zeroes after [eE]- and +zeroes after [Ee]. */
+
+               /* ... this is not done yet. */
        }
-       else {
-         strcpy(result, &buf[dp-1]);
-       }   
-      }
-    }
-
-    /* do nothing for abs(exp) > 4; %e must be OK */
-    /* just get rid of zeroes after [eE]- and +zeroes after [Ee]. */
-    
-    /* ... this is not done yet. */
-  }
-  return ( strlen ( result ) );
+       return (strlen(result));
 }
 
 
@@ -1003,47 +1077,56 @@ static int restore ( char * result, float val, int n )
 */
 
 bool
-seg_contains_int(SEG *a, int *b)
+seg_contains_int(SEG * a, int *b)
 {
-  return ( (a->lower <= *b) && (a->upper >= *b) );
+       return ((a->lower <= *b) && (a->upper >= *b));
 }
 
 bool
-seg_contains_float4(SEG *a, float4 *b)
+seg_contains_float4(SEG * a, float4 *b)
 {
-  return ( (a->lower <= *b) && (a->upper >= *b) );
+       return ((a->lower <= *b) && (a->upper >= *b));
 }
 
 bool
-seg_contains_float8(SEG *a, float8 *b)
+seg_contains_float8(SEG * a, float8 *b)
 {
-  return ( (a->lower <= *b) && (a->upper >= *b) );
+       return ((a->lower <= *b) && (a->upper >= *b));
 }
 
-/* find out the number of significant digits in a string representing 
+/* find out the number of significant digits in a string representing
  * a floating point number
  */
-int significant_digits ( char* s )
+int
+significant_digits(char *s)
 {
-  char * p = s;
-  int n, c, zeroes;
+       char       *p = s;
+       int                     n,
+                               c,
+                               zeroes;
 
-  zeroes = 1;
-  /* skip leading zeroes and sign */
-  for ( c = *p; (c == '0' || c == '+' || c == '-') && c != 0; c = *(++p) );
+       zeroes = 1;
+       /* skip leading zeroes and sign */
+       for (c = *p; (c == '0' || c == '+' || c == '-') && c != 0; c = *(++p));
 
-  /* skip decimal point and following zeroes */
-  for ( c = *p; (c == '0' || c == '.' ) && c != 0; c = *(++p) ) {
-    if ( c != '.') zeroes++;
-  }
+       /* skip decimal point and following zeroes */
+       for (c = *p; (c == '0' || c == '.') && c != 0; c = *(++p))
+       {
+               if (c != '.')
+                       zeroes++;
+       }
 
-  /* count significant digits (n) */
-  for ( c = *p, n = 0; c != 0; c = *(++p) ) {
-    if ( !( (c >= '0' && c <= '9') || (c == '.') ) ) break;
-    if ( c != '.') n++;
-  }
+       /* count significant digits (n) */
+       for (c = *p, n = 0; c != 0; c = *(++p))
+       {
+               if (!((c >= '0' && c <= '9') || (c == '.')))
+                       break;
+               if (c != '.')
+                       n++;
+       }
 
-  if (!n) return ( zeroes );
+       if (!n)
+               return (zeroes);
 
-  return( n );
+       return (n);
 }
index 709f576340c0109c2b5cb62c80648e878d21d5e7..773883bbb722d17ca5acf1b8d5d14595c0db280b 100644 (file)
@@ -1,8 +1,9 @@
-typedef struct SEG {
-  float lower;
-  float upper;
-  char  l_sigd;
-  char  u_sigd;  
-  char  l_ext;
-  char  u_ext;  
-} SEG;
+typedef struct SEG
+{
+       float           lower;
+       float           upper;
+       char            l_sigd;
+       char            u_sigd;
+       char            l_ext;
+       char            u_ext;
+}                      SEG;
index 5a7e238e3804f611a5c5a1d63a8a1c40d3b3d114..ff1b0f7aecd563709a84ff74916de131478334c1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Header: /cvsroot/pgsql/contrib/soundex/Attic/soundex.c,v 1.10 2001/02/10 02:31:26 tgl Exp $ */
+/* $Header: /cvsroot/pgsql/contrib/soundex/Attic/soundex.c,v 1.11 2001/03/22 03:59:10 momjian Exp $ */
 #include "postgres.h"
 
 #include <ctype.h>
@@ -7,7 +7,7 @@
 #include "utils/builtins.h"
 
 
-Datum text_soundex(PG_FUNCTION_ARGS);
+Datum          text_soundex(PG_FUNCTION_ARGS);
 
 static void soundex(const char *instr, char *outstr);
 
@@ -37,11 +37,12 @@ text_soundex(PG_FUNCTION_ARGS)
        PG_RETURN_TEXT_P(_textin(outstr));
 }
 
-#endif /* not SOUNDEX_TEST */
+#endif  /* not SOUNDEX_TEST */
 
 
-/*                                  ABCDEFGHIJKLMNOPQRSTUVWXYZ */
+/*                                                                     ABCDEFGHIJKLMNOPQRSTUVWXYZ */
 static const char *soundex_table = "01230120022455012623010202";
+
 #define soundex_code(letter) soundex_table[toupper((unsigned char) (letter)) - 'A']
 
 
@@ -98,7 +99,7 @@ soundex(const char *instr, char *outstr)
 
 #ifdef SOUNDEX_TEST
 int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
 {
        if (argc < 2)
        {
@@ -107,11 +108,12 @@ main (int argc, char *argv[])
        }
        else
        {
-               char output[SOUNDEX_LEN + 1];
+               char            output[SOUNDEX_LEN + 1];
 
                soundex(argv[1], output);
                printf("soundex(%s) = %s\n", argv[1], output);
                return 0;
        }
 }
-#endif /* SOUNDEX_TEST */
+
+#endif  /* SOUNDEX_TEST */
index 3d083bf2f035b800be86c4c3d25dca9bd3392250..0bedaa98aedc9fa749ca82c90000e705135c3475 100644 (file)
@@ -10,7 +10,7 @@
 #include "commands/trigger.h"  /* -"- and triggers */
 #include "miscadmin.h"                 /* for GetUserName() */
 
-extern Datum   insert_username(PG_FUNCTION_ARGS);
+extern Datum insert_username(PG_FUNCTION_ARGS);
 
 PG_FUNCTION_INFO_V1(insert_username);
 
@@ -65,7 +65,7 @@ insert_username(PG_FUNCTION_ARGS)
 
        /* create fields containing name */
        newval = DirectFunctionCall1(textin,
-                                                                CStringGetDatum(GetUserName(GetUserId())));
+                                                         CStringGetDatum(GetUserName(GetUserId())));
 
        /* construct new tuple */
        rettuple = SPI_modifytuple(rel, rettuple, 1, &attnum, &newval, NULL);
index 73b151851888d29eb2d2ebdcf00a28dbe012a899..bd45dc72b3d49dae89dd0e8efe9ba24c2cc87c36 100644 (file)
@@ -15,7 +15,7 @@ OH, me, I'm Terry Mackintosh <[email protected]>
 #include "executor/spi.h"              /* this is what you need to work with SPI */
 #include "commands/trigger.h"  /* -"- and triggers */
 
-extern Datum   moddatetime(PG_FUNCTION_ARGS);
+extern Datum moddatetime(PG_FUNCTION_ARGS);
 
 PG_FUNCTION_INFO_V1(moddatetime);
 
index 90341e208d244a96ffc6e0a3fd70c8cdf742495e..bc8a1112f4bd186c467f8698487f2131b2405f67 100644 (file)
@@ -373,7 +373,7 @@ set_timetravel(PG_FUNCTION_ARGS)
        else
                TTOff = realloc(TTOff, (nTTOff + 1) * sizeof(char *));
        s = rname = DatumGetCString(DirectFunctionCall1(nameout,
-                                                                                                       NameGetDatum(relname)));
+                                                                                                NameGetDatum(relname)));
        d = TTOff[nTTOff] = malloc(strlen(rname) + 1);
        while (*s)
                *d++ = tolower((unsigned char) *s++);
index 4fdad73e095926d9e6a9e849cd08af93d273f9fd..002c77fb61478522b3f7c487b8197fcf3366a8b5 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.8 2001/01/24 19:42:45 momjian Exp $
+ *       $Header: /cvsroot/pgsql/contrib/vacuumlo/vacuumlo.c,v 1.9 2001/03/22 03:59:11 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -76,6 +76,7 @@ vacuumlo(char *database, int verbose)
                return -1;
        }
        PQclear(res);
+
        /*
         * Vacuum the temp table so that planner will generate decent plans
         * for the DELETEs below.
@@ -96,13 +97,13 @@ vacuumlo(char *database, int verbose)
        /*
         * Now find any candidate tables who have columns of type oid.
         *
-        * NOTE: the temp table formed above is ignored, because its real
-        * table name will be pg_something.  Also, pg_largeobject will be
-        * ignored.  If either of these were scanned, obviously we'd end up
-        * with nothing to delete...
+        * NOTE: the temp table formed above is ignored, because its real table
+        * name will be pg_something.  Also, pg_largeobject will be ignored.
+        * If either of these were scanned, obviously we'd end up with nothing
+        * to delete...
         *
-        * NOTE: the system oid column is ignored, as it has attnum < 1.
-        * This shouldn't matter for correctness, but it saves time.
+        * NOTE: the system oid column is ignored, as it has attnum < 1. This
+        * shouldn't matter for correctness, but it saves time.
         */
        buf[0] = '\0';
        strcat(buf, "SELECT c.relname, a.attname ");
@@ -135,9 +136,9 @@ vacuumlo(char *database, int verbose)
                        fprintf(stdout, "Checking %s in %s\n", field, table);
 
                /*
-                * We use a DELETE with implicit join for efficiency.  This
-                * is a Postgres-ism and not portable to other DBMSs, but
-                * then this whole program is a Postgres-ism.
+                * We use a DELETE with implicit join for efficiency.  This is a
+                * Postgres-ism and not portable to other DBMSs, but then this
+                * whole program is a Postgres-ism.
                 */
                sprintf(buf, "DELETE FROM vacuum_l WHERE lo = \"%s\".\"%s\" ",
                                table, field);
@@ -157,10 +158,10 @@ vacuumlo(char *database, int verbose)
        PQclear(res);
 
        /*
-        * Run the actual deletes in a single transaction.  Note that this
+        * Run the actual deletes in a single transaction.      Note that this
         * would be a bad idea in pre-7.1 Postgres releases (since rolling
-        * back a table delete used to cause problems), but it should
-        * be safe now.
+        * back a table delete used to cause problems), but it should be safe
+        * now.
         */
        res = PQexec(conn, "begin");
        PQclear(res);
index 03d180e36fe75fc2895be38ac151db24f75202c2..9bb08054943beac01ebd6cf0bf551e578b33d777 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.69 2001/01/24 19:42:46 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/common/heaptuple.c,v 1.70 2001/03/22 03:59:11 momjian Exp $
  *
  * NOTES
  *       The old interface functions have been converted to macros
@@ -306,8 +306,8 @@ nocachegetattr(HeapTuple tuple,
                        int                     j;
 
                        /*
-                        * In for(), we test <= and not < because we want to see
-                        * if we can go past it in initializing offsets.
+                        * In for(), we test <= and not < because we want to see if we
+                        * can go past it in initializing offsets.
                         */
                        for (j = 0; j <= attnum; j++)
                        {
@@ -321,9 +321,9 @@ nocachegetattr(HeapTuple tuple,
        }
 
        /*
-        * If slow is false, and we got here, we know that we have a tuple with
-        * no nulls or varlenas before the target attribute. If possible, we
-        * also want to initialize the remainder of the attribute cached
+        * If slow is false, and we got here, we know that we have a tuple
+        * with no nulls or varlenas before the target attribute. If possible,
+        * we also want to initialize the remainder of the attribute cached
         * offset values.
         */
        if (!slow)
index e503d9b888d0f2ece68510decae60effe48516cb..da8129f307f5d3f82cba3fd07bb320048b2e251a 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.52 2001/02/22 21:48:48 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/common/indextuple.c,v 1.53 2001/03/22 03:59:11 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -45,9 +45,11 @@ index_formtuple(TupleDesc tupleDescriptor,
        bool            hasnull = false;
        uint16          tupmask = 0;
        int                     numberOfAttributes = tupleDescriptor->natts;
+
 #ifdef TOAST_INDEX_HACK
        Datum           untoasted_value[INDEX_MAX_KEYS];
        bool            untoasted_free[INDEX_MAX_KEYS];
+
 #endif
 
        if (numberOfAttributes > INDEX_MAX_KEYS)
@@ -57,7 +59,7 @@ index_formtuple(TupleDesc tupleDescriptor,
 #ifdef TOAST_INDEX_HACK
        for (i = 0; i < numberOfAttributes; i++)
        {
-               Form_pg_attribute  att = tupleDescriptor->attrs[i];
+               Form_pg_attribute att = tupleDescriptor->attrs[i];
 
                untoasted_value[i] = value[i];
                untoasted_free[i] = false;
@@ -73,20 +75,20 @@ index_formtuple(TupleDesc tupleDescriptor,
                if (VARATT_IS_EXTERNAL(value[i]))
                {
                        untoasted_value[i] = PointerGetDatum(
-                               heap_tuple_fetch_attr(
-                                       (varattrib *) DatumGetPointer(value[i])));
+                                                                                                heap_tuple_fetch_attr(
+                                                          (varattrib *) DatumGetPointer(value[i])));
                        untoasted_free[i] = true;
                }
 
                /*
-                * If value is above size target, and is of a compressible datatype,
-                * try to compress it in-line.
+                * If value is above size target, and is of a compressible
+                * datatype, try to compress it in-line.
                 */
                if (VARATT_SIZE(untoasted_value[i]) > TOAST_INDEX_TARGET &&
                        !VARATT_IS_EXTENDED(untoasted_value[i]) &&
                        (att->attstorage == 'x' || att->attstorage == 'm'))
                {
-                       Datum   cvalue = toast_compress_datum(untoasted_value[i]);
+                       Datum           cvalue = toast_compress_datum(untoasted_value[i]);
 
                        if (DatumGetPointer(cvalue) != NULL)
                        {
@@ -146,8 +148,8 @@ index_formtuple(TupleDesc tupleDescriptor,
        /*
         * We do this because DataFill wants to initialize a "tupmask" which
         * is used for HeapTuples, but we want an indextuple infomask.  The
-        * only relevant info is the "has variable attributes" field.
-        * We have already set the hasnull bit above.
+        * only relevant info is the "has variable attributes" field. We have
+        * already set the hasnull bit above.
         */
 
        if (tupmask & HEAP_HASVARLENA)
@@ -315,9 +317,9 @@ nocache_index_getattr(IndexTuple tup,
        }
 
        /*
-        * If slow is false, and we got here, we know that we have a tuple with
-        * no nulls or varlenas before the target attribute. If possible, we
-        * also want to initialize the remainder of the attribute cached
+        * If slow is false, and we got here, we know that we have a tuple
+        * with no nulls or varlenas before the target attribute. If possible,
+        * we also want to initialize the remainder of the attribute cached
         * offset values.
         */
        if (!slow)
@@ -391,9 +393,7 @@ nocache_index_getattr(IndexTuple tup,
                                usecache = false;
                        }
                        else
-                       {
                                off += att[i]->attlen;
-                       }
                }
 
                off = att_align(off, att[attnum]->attlen, att[attnum]->attalign);
index 4f47ef0d451003637d657e5f0ac6aba269e1ac6f..d44bfe973e040d25bad6a40e5da49717ceb03e75 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.57 2001/01/24 19:42:47 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/common/printtup.c,v 1.58 2001/03/22 03:59:11 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -51,7 +51,7 @@ getTypeOutputInfo(Oid type, Oid *typOutput, Oid *typElem,
 
        *typOutput = pt->typoutput;
        *typElem = pt->typelem;
-       *typIsVarlena = (! pt->typbyval) && (pt->typlen == -1);
+       *typIsVarlena = (!pt->typbyval) && (pt->typlen == -1);
        ReleaseSysCache(typeTuple);
        return OidIsValid(*typOutput);
 }
@@ -200,9 +200,10 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
                        continue;
                if (OidIsValid(thisState->typoutput))
                {
+
                        /*
-                        * If we have a toasted datum, forcibly detoast it here to avoid
-                        * memory leakage inside the type's output routine.
+                        * If we have a toasted datum, forcibly detoast it here to
+                        * avoid memory leakage inside the type's output routine.
                         */
                        if (thisState->typisvarlena)
                                attr = PointerGetDatum(PG_DETOAST_DATUM(origattr));
@@ -210,9 +211,9 @@ printtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
                                attr = origattr;
 
                        outputstr = DatumGetCString(FunctionCall3(&thisState->finfo,
-                                                                               attr,
-                                                                               ObjectIdGetDatum(thisState->typelem),
-                                                                               Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
+                                                                                                         attr,
+                                                                       ObjectIdGetDatum(thisState->typelem),
+                                                 Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
 
                        pq_sendcountedtext(&buf, outputstr, strlen(outputstr));
 
@@ -308,9 +309,10 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
                if (getTypeOutputInfo(typeinfo->attrs[i]->atttypid,
                                                          &typoutput, &typelem, &typisvarlena))
                {
+
                        /*
-                        * If we have a toasted datum, forcibly detoast it here to avoid
-                        * memory leakage inside the type's output routine.
+                        * If we have a toasted datum, forcibly detoast it here to
+                        * avoid memory leakage inside the type's output routine.
                         */
                        if (typisvarlena)
                                attr = PointerGetDatum(PG_DETOAST_DATUM(origattr));
@@ -318,9 +320,9 @@ debugtup(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
                                attr = origattr;
 
                        value = DatumGetCString(OidFunctionCall3(typoutput,
-                                                                       attr,
-                                                                       ObjectIdGetDatum(typelem),
-                                                                       Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
+                                                                                                        attr,
+                                                                                          ObjectIdGetDatum(typelem),
+                                                 Int32GetDatum(typeinfo->attrs[i]->atttypmod)));
 
                        printatt((unsigned) i + 1, typeinfo->attrs[i], value);
 
@@ -405,6 +407,7 @@ printtup_internal(HeapTuple tuple, TupleDesc typeinfo, DestReceiver *self)
                /* send # of bytes, and opaque data */
                if (thisState->typisvarlena)
                {
+
                        /*
                         * If we have a toasted datum, must detoast before sending.
                         */
index 86bc1a56f82dbf7f7f2188f52d593bce8aed84f4..e07c6296d15abf14681d816e3c4be2efdd77bdab 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.71 2001/01/24 19:42:47 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.72 2001/03/22 03:59:11 momjian Exp $
  *
  * NOTES
  *       some of the executor utility code such as "ExecTypeFromTL" should be
@@ -242,9 +242,9 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
                /*
                 * We do not need to check every single field here, and in fact
                 * some fields such as attdispersion probably shouldn't be
-                * compared.  We can also disregard attnum (it was used to
-                * place the row in the attrs array) and everything derived
-                * from the column datatype.
+                * compared.  We can also disregard attnum (it was used to place
+                * the row in the attrs array) and everything derived from the
+                * column datatype.
                 */
                if (strcmp(NameStr(attr1->attname), NameStr(attr2->attname)) != 0)
                        return false;
@@ -276,8 +276,8 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
 
                        /*
                         * We can't assume that the items are always read from the
-                        * system catalogs in the same order; so use the adnum field to
-                        * identify the matching item to compare.
+                        * system catalogs in the same order; so use the adnum field
+                        * to identify the matching item to compare.
                         */
                        for (j = 0; j < n; defval2++, j++)
                        {
@@ -298,9 +298,9 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
                        ConstrCheck *check2 = constr2->check;
 
                        /*
-                        * Similarly, don't assume that the checks are always read
-                        * in the same order; match them up by name and contents.
-                        * (The name *should* be unique, but...)
+                        * Similarly, don't assume that the checks are always read in
+                        * the same order; match them up by name and contents. (The
+                        * name *should* be unique, but...)
                         */
                        for (j = 0; j < n; check2++, j++)
                        {
index 9e3f935bd67985239881ba1db0d0b0bb4d9b89d2..1c5577b88a066a1ecebfd6ce317147efc28d489c 100644 (file)
@@ -6,7 +6,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.71 2001/03/07 21:20:26 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/gist/gist.c,v 1.72 2001/03/22 03:59:12 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 #include "access/xlogutils.h"
 
-/* result's status */ 
+/* result's status */
 #define INSERTED       0x01
 #define SPLITED                0x02
 
 /* non-export function prototypes */
-static void gistdoinsert(Relation r, 
-                       IndexTuple itup,
-                       InsertIndexResult *res,
-                       GISTSTATE *GISTstate);
-static int gistlayerinsert( Relation r, BlockNumber blkno,
-                       IndexTuple **itup,
-                       int *len,
-                       InsertIndexResult *res,
-                       GISTSTATE *giststate );
-static OffsetNumber gistwritebuffer( Relation r, 
-                       Page page, 
-                       IndexTuple *itup, 
-                       int len, 
-                       OffsetNumber off,
-                       GISTSTATE *giststate );
-static int gistnospace( Page page,
-                       IndexTuple *itvec, int len );
-static IndexTuple * gistreadbuffer( Relation r, 
-                       Buffer buffer, int *len );
-static IndexTuple * gistjoinvector( 
-                       IndexTuple *itvec, int *len, 
-                       IndexTuple *additvec, int addlen );
-static IndexTuple gistunion( Relation r, IndexTuple *itvec, 
-                       int len, GISTSTATE *giststate );
-static IndexTuple gistgetadjusted( Relation r, 
-                       IndexTuple oldtup, 
-                       IndexTuple addtup, 
-                       GISTSTATE *giststate );
-static IndexTuple * gistSplit(Relation r,
-                       Buffer buffer,
-                       IndexTuple *itup,
-                       int *len,
-                       GISTSTATE *giststate,
-                       InsertIndexResult *res);
-static void gistnewroot(GISTSTATE *giststate, Relation r, 
+static void gistdoinsert(Relation r,
+                        IndexTuple itup,
+                        InsertIndexResult *res,
+                        GISTSTATE *GISTstate);
+static int gistlayerinsert(Relation r, BlockNumber blkno,
+                               IndexTuple **itup,
+                               int *len,
+                               InsertIndexResult *res,
+                               GISTSTATE *giststate);
+static OffsetNumber gistwritebuffer(Relation r,
+                               Page page,
+                               IndexTuple *itup,
+                               int len,
+                               OffsetNumber off,
+                               GISTSTATE *giststate);
+static int gistnospace(Page page,
+                       IndexTuple *itvec, int len);
+static IndexTuple *gistreadbuffer(Relation r,
+                          Buffer buffer, int *len);
+static IndexTuple *gistjoinvector(
+                          IndexTuple *itvec, int *len,
+                          IndexTuple *additvec, int addlen);
+static IndexTuple gistunion(Relation r, IndexTuple *itvec,
+                 int len, GISTSTATE *giststate);
+static IndexTuple gistgetadjusted(Relation r,
+                               IndexTuple oldtup,
+                               IndexTuple addtup,
+                               GISTSTATE *giststate);
+static IndexTuple *gistSplit(Relation r,
+                 Buffer buffer,
+                 IndexTuple *itup,
+                 int *len,
+                 GISTSTATE *giststate,
+                 InsertIndexResult *res);
+static void gistnewroot(GISTSTATE *giststate, Relation r,
                        IndexTuple *itup, int len);
 static void GISTInitBuffer(Buffer b, uint32 f);
-static OffsetNumber gistchoose(Relation r, Page p, 
-                       IndexTuple it,
-                       GISTSTATE *giststate);
-static IndexTuple gist_tuple_replacekey(Relation r, 
-                       GISTENTRY entry, IndexTuple t);
-static void gistcentryinit(GISTSTATE *giststate, 
-                       GISTENTRY *e, char *pr,
-                       Relation r, Page pg, 
-                       OffsetNumber o, int b, bool l);
+static OffsetNumber gistchoose(Relation r, Page p,
+                  IndexTuple it,
+                  GISTSTATE *giststate);
+static IndexTuple gist_tuple_replacekey(Relation r,
+                                         GISTENTRY entry, IndexTuple t);
+static void gistcentryinit(GISTSTATE *giststate,
+                          GISTENTRY *e, char *pr,
+                          Relation r, Page pg,
+                          OffsetNumber o, int b, bool l);
 
 #undef GISTDEBUG
 #ifdef GISTDEBUG
 static void gist_dumptree(Relation r, int level, BlockNumber blk, OffsetNumber coff);
+
 #endif
 
 /*
@@ -88,12 +89,14 @@ static void gist_dumptree(Relation r, int level, BlockNumber blk, OffsetNumber c
 Datum
 gistbuild(PG_FUNCTION_ARGS)
 {
-       Relation                heap = (Relation) PG_GETARG_POINTER(0);
-       Relation                index = (Relation) PG_GETARG_POINTER(1);
-       IndexInfo          *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
-       Node               *oldPred = (Node *) PG_GETARG_POINTER(3);
+       Relation        heap = (Relation) PG_GETARG_POINTER(0);
+       Relation        index = (Relation) PG_GETARG_POINTER(1);
+       IndexInfo  *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
+       Node       *oldPred = (Node *) PG_GETARG_POINTER(3);
+
 #ifdef NOT_USED
-       IndexStrategy   istrat = (IndexStrategy) PG_GETARG_POINTER(4);
+       IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
+
 #endif
        HeapScanDesc hscan;
        HeapTuple       htup;
@@ -105,9 +108,11 @@ gistbuild(PG_FUNCTION_ARGS)
        int                     nhtups,
                                nitups;
        Node       *pred = indexInfo->ii_Predicate;
+
 #ifndef OMIT_PARTIAL_INDEX
        TupleTable      tupleTable;
        TupleTableSlot *slot;
+
 #endif
        ExprContext *econtext;
        GISTSTATE       giststate;
@@ -181,6 +186,7 @@ gistbuild(PG_FUNCTION_ARGS)
                nhtups++;
 
 #ifndef OMIT_PARTIAL_INDEX
+
                /*
                 * If oldPred != NULL, this is an EXTEND INDEX command, so skip
                 * this tuple if it was already in the existing partial index
@@ -262,9 +268,7 @@ gistbuild(PG_FUNCTION_ARGS)
 
 #ifndef OMIT_PARTIAL_INDEX
        if (pred != NULL || oldPred != NULL)
-       {
                ExecDropTupleTable(tupleTable, true);
-       }
 #endif  /* OMIT_PARTIAL_INDEX */
        FreeExprContext(econtext);
 
@@ -297,7 +301,7 @@ gistbuild(PG_FUNCTION_ARGS)
        }
 
 #ifdef GISTDEBUG
-gist_dumptree(index, 0, GISTP_ROOT, 0);
+       gist_dumptree(index, 0, GISTP_ROOT, 0);
 #endif
 
        PG_RETURN_VOID();
@@ -312,12 +316,14 @@ gist_dumptree(index, 0, GISTP_ROOT, 0);
 Datum
 gistinsert(PG_FUNCTION_ARGS)
 {
-       Relation                r = (Relation) PG_GETARG_POINTER(0);
-       Datum              *datum = (Datum *) PG_GETARG_POINTER(1);
-       char               *nulls = (char *) PG_GETARG_POINTER(2);
-       ItemPointer             ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
+       Relation        r = (Relation) PG_GETARG_POINTER(0);
+       Datum      *datum = (Datum *) PG_GETARG_POINTER(1);
+       char       *nulls = (char *) PG_GETARG_POINTER(2);
+       ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
+
 #ifdef NOT_USED
-       Relation                heapRel = (Relation) PG_GETARG_POINTER(4);
+       Relation        heapRel = (Relation) PG_GETARG_POINTER(4);
+
 #endif
        InsertIndexResult res;
        IndexTuple      itup;
@@ -380,7 +386,7 @@ gistPageAddItem(GISTSTATE *giststate,
 {
        GISTENTRY       tmpcentry;
        IndexTuple      itup = (IndexTuple) item;
-       OffsetNumber    retval;
+       OffsetNumber retval;
 
        /*
         * recompress the item given that we now know the exact page and
@@ -394,7 +400,7 @@ gistPageAddItem(GISTSTATE *giststate,
                                   offsetNumber, dentry->bytes, FALSE);
        *newtup = gist_tuple_replacekey(r, tmpcentry, itup);
        retval = PageAddItem(page, (Item) *newtup, IndexTupleSize(*newtup),
-                                               offsetNumber, flags);
+                                                offsetNumber, flags);
        if (retval == InvalidOffsetNumber)
                elog(ERROR, "gist: failed to add index item to %s",
                         RelationGetRelationName(r));
@@ -405,189 +411,213 @@ gistPageAddItem(GISTSTATE *giststate,
        return (retval);
 }
 
-static void 
-gistdoinsert( Relation r, 
-               IndexTuple itup, 
-               InsertIndexResult *res, 
-               GISTSTATE *giststate ) {
+static void
+gistdoinsert(Relation r,
+                        IndexTuple itup,
+                        InsertIndexResult *res,
+                        GISTSTATE *giststate)
+{
        IndexTuple *instup;
-       int i,ret,len = 1;
+       int                     i,
+                               ret,
+                               len = 1;
+
+       instup = (IndexTuple *) palloc(sizeof(IndexTuple));
+       instup[0] = (IndexTuple) palloc(IndexTupleSize(itup));
+       memcpy(instup[0], itup, IndexTupleSize(itup));
 
-       instup = ( IndexTuple* ) palloc( sizeof(IndexTuple) );
-       instup[0] = ( IndexTuple ) palloc( IndexTupleSize( itup ) );
-       memcpy( instup[0], itup, IndexTupleSize( itup ) );
        ret = gistlayerinsert(r, GISTP_ROOT, &instup, &len, res, giststate);
-       if ( ret & SPLITED )
-               gistnewroot( giststate, r, instup, len );
+       if (ret & SPLITED)
+               gistnewroot(giststate, r, instup, len);
 
-       for(i=0;i<len;i++)
-               pfree( instup[i] );
-       pfree( instup );
+       for (i = 0; i < len; i++)
+               pfree(instup[i]);
+       pfree(instup);
 }
 
 static int
-gistlayerinsert( Relation r, BlockNumber blkno, 
-                        IndexTuple **itup,       /* in - out, has compressed entry */
-                        int *len    ,           /* in - out */
-                        InsertIndexResult *res, /* out */
-                        GISTSTATE *giststate ) {
-       Buffer  buffer;
-       Page    page;
-       OffsetNumber    child;
-       int ret;
+gistlayerinsert(Relation r, BlockNumber blkno,
+                               IndexTuple **itup,              /* in - out, has compressed entry */
+                               int *len,               /* in - out */
+                               InsertIndexResult *res, /* out */
+                               GISTSTATE *giststate)
+{
+       Buffer          buffer;
+       Page            page;
+       OffsetNumber child;
+       int                     ret;
        GISTPageOpaque opaque;
 
        buffer = ReadBuffer(r, blkno);
        page = (Page) BufferGetPage(buffer);
        opaque = (GISTPageOpaque) PageGetSpecialPointer(page);
 
-       if (!(opaque->flags & F_LEAF)) {
+       if (!(opaque->flags & F_LEAF))
+       {
                /* internal page, so we must walk on tree */
                /* len IS equial 1 */
-               ItemId iid;
+               ItemId          iid;
                BlockNumber nblkno;
                ItemPointerData oldtid;
-               IndexTuple oldtup;
-       
-               child = gistchoose( r, page, *(*itup), giststate );
+               IndexTuple      oldtup;
+
+               child = gistchoose(r, page, *(*itup), giststate);
                iid = PageGetItemId(page, child);
                oldtup = (IndexTuple) PageGetItem(page, iid);
                nblkno = ItemPointerGetBlockNumber(&(oldtup->t_tid));
 
-               /* 
-                * After this call:
-                * 1. if child page was splited, then itup contains
-                * keys for each page
-                * 2. if  child page wasn't splited, then itup contains
-                * additional for adjustement of current key 
+               /*
+                * After this call: 1. if child page was splited, then itup
+                * contains keys for each page 2. if  child page wasn't splited,
+                * then itup contains additional for adjustement of current key
                 */
-               ret = gistlayerinsert( r, nblkno, itup, len, res, giststate );
+               ret = gistlayerinsert(r, nblkno, itup, len, res, giststate);
 
                /* nothing inserted in child */
-               if ( ! (ret & INSERTED) ) {
+               if (!(ret & INSERTED))
+               {
                        ReleaseBuffer(buffer);
-                       return 0x00;    
+                       return 0x00;
                }
 
-               /* child does not splited */ 
-               if ( ! (ret & SPLITED) ) {
-                       IndexTuple newtup = gistgetadjusted( r, oldtup, (*itup)[0], giststate ); 
-                       if ( ! newtup ) {
+               /* child does not splited */
+               if (!(ret & SPLITED))
+               {
+                       IndexTuple      newtup = gistgetadjusted(r, oldtup, (*itup)[0], giststate);
+
+                       if (!newtup)
+                       {
                                /* not need to update key */
                                ReleaseBuffer(buffer);
                                return 0x00;
                        }
 
-                       pfree( (*itup)[0] ); /* !!! */
+                       pfree((*itup)[0]);      /* !!! */
                        (*itup)[0] = newtup;
                }
 
-               /* key is modified, so old version must be deleted */ 
+               /* key is modified, so old version must be deleted */
                ItemPointerSet(&oldtid, blkno, child);
                DirectFunctionCall2(gistdelete,
-                       PointerGetDatum(r),
-                       PointerGetDatum(&oldtid));
+                                                       PointerGetDatum(r),
+                                                       PointerGetDatum(&oldtid));
        }
 
-       ret = INSERTED; 
+       ret = INSERTED;
 
-       if (  gistnospace(page, (*itup), *len) ) {
+       if (gistnospace(page, (*itup), *len))
+       {
                /* no space for insertion */
                IndexTuple *itvec;
-               int tlen;
+               int                     tlen;
 
                ret |= SPLITED;
-               itvec = gistreadbuffer( r, buffer, &tlen );
-               itvec = gistjoinvector( itvec, &tlen, (*itup), *len ); 
-               pfree( (*itup) );
-               (*itup) = gistSplit( r, buffer, itvec, &tlen, giststate, 
-                       (opaque->flags & F_LEAF) ? res : NULL ); /*res only for inserting in leaf*/
-               ReleaseBuffer( buffer );
-               pfree( itvec );
-               *len = tlen;   /* now tlen >= 2 */
-       } else {
+               itvec = gistreadbuffer(r, buffer, &tlen);
+               itvec = gistjoinvector(itvec, &tlen, (*itup), *len);
+               pfree((*itup));
+               (*itup) = gistSplit(r, buffer, itvec, &tlen, giststate,
+                                                       (opaque->flags & F_LEAF) ? res : NULL);         /* res only for
+                                                                                                                                                * inserting in leaf */
+               ReleaseBuffer(buffer);
+               pfree(itvec);
+               *len = tlen;                    /* now tlen >= 2 */
+       }
+       else
+       {
                /* enogth space */
-               OffsetNumber off, l;
+               OffsetNumber off,
+                                       l;
 
-               off = ( PageIsEmpty(page) ) ? 
-                               FirstOffsetNumber
+               off = (PageIsEmpty(page)) ?
+                       FirstOffsetNumber
                        :
-                               OffsetNumberNext(PageGetMaxOffsetNumber(page));
-               l = gistwritebuffer( r, page, (*itup), *len, off, giststate );
+                       OffsetNumberNext(PageGetMaxOffsetNumber(page));
+               l = gistwritebuffer(r, page, (*itup), *len, off, giststate);
                WriteBuffer(buffer);
 
-               /* set res if insert into leaf page, in
-                this case, len = 1 always */
-               if ( res && (opaque->flags & F_LEAF) )
+               /*
+                * set res if insert into leaf page, in this case, len = 1 always
+                */
+               if (res && (opaque->flags & F_LEAF))
                        ItemPointerSet(&((*res)->pointerData), blkno, l);
 
-               if ( *len > 1 ) { /* previos insert ret & SPLITED != 0 */ 
-                       int i;
-                       /* child was splited, so we must form union
-                        * for insertion in parent */
-                       IndexTuple newtup = gistunion(r, (*itup), *len, giststate);
-                       for(i=0; i<*len; i++)
-                               pfree( (*itup)[i] );
+               if (*len > 1)
+               {                                               /* previos insert ret & SPLITED != 0 */
+                       int                     i;
+
+                       /*
+                        * child was splited, so we must form union for insertion in
+                        * parent
+                        */
+                       IndexTuple      newtup = gistunion(r, (*itup), *len, giststate);
+
+                       for (i = 0; i < *len; i++)
+                               pfree((*itup)[i]);
                        (*itup)[0] = newtup;
                        *len = 1;
                }
        }
-       
-       return ret; 
-}    
 
-/* 
+       return ret;
+}
+
+/*
  * Write itup vector to page, has no control of free space
  */
 static OffsetNumber
-gistwritebuffer( Relation r, Page page, IndexTuple *itup, 
-               int len, OffsetNumber off, GISTSTATE *giststate) {
+gistwritebuffer(Relation r, Page page, IndexTuple *itup,
+                               int len, OffsetNumber off, GISTSTATE *giststate)
+{
        OffsetNumber l = InvalidOffsetNumber;
-       int i;
-       GISTENTRY       tmpdentry;
-       IndexTuple newtup;
-               
-       for(i=0; i<len; i++) { 
-               l = gistPageAddItem(giststate, r, page, 
-                       (Item) itup[i], IndexTupleSize(itup[i]),   
-                       off, LP_USED, &tmpdentry, &newtup);
-               off = OffsetNumberNext( off );
+       int                     i;
+       GISTENTRY       tmpdentry;
+       IndexTuple      newtup;
+
+       for (i = 0; i < len; i++)
+       {
+               l = gistPageAddItem(giststate, r, page,
+                                                       (Item) itup[i], IndexTupleSize(itup[i]),
+                                                       off, LP_USED, &tmpdentry, &newtup);
+               off = OffsetNumberNext(off);
                if (tmpdentry.pred != (((char *) itup[i]) + sizeof(IndexTupleData)) && tmpdentry.pred)
                        pfree(tmpdentry.pred);
                if (itup[i] != newtup)
                        pfree(newtup);
        }
-       return l; 
+       return l;
 }
 
 /*
  * Check space for itup vector on page
  */
-static int 
-gistnospace( Page page, IndexTuple *itvec, int len ) {
-       int size = 0;
-       int i;
-       for(i=0; i<len; i++) 
-               size += IndexTupleSize( itvec[i] )+4; /* ??? */
+static int
+gistnospace(Page page, IndexTuple *itvec, int len)
+{
+       int                     size = 0;
+       int                     i;
 
-       return  (PageGetFreeSpace(page) < size);
-} 
+       for (i = 0; i < len; i++)
+               size += IndexTupleSize(itvec[i]) + 4;   /* ??? */
+
+       return (PageGetFreeSpace(page) < size);
+}
 
 /*
  * Read buffer into itup vector
  */
 static IndexTuple *
-gistreadbuffer( Relation r, Buffer buffer, int *len /*out*/) {
-       OffsetNumber i, maxoff;
-       IndexTuple   *itvec;
-       Page p = (Page) BufferGetPage(buffer);
+gistreadbuffer(Relation r, Buffer buffer, int *len /* out */ )
+{
+       OffsetNumber i,
+                               maxoff;
+       IndexTuple *itvec;
+       Page            p = (Page) BufferGetPage(buffer);
 
-       *len=0;
+       *len = 0;
        maxoff = PageGetMaxOffsetNumber(p);
-       itvec = palloc( sizeof(IndexTuple) * maxoff );
-       for(i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
-               itvec[ (*len)++ ] = (IndexTuple) PageGetItem(p, PageGetItemId(p, i));
+       itvec = palloc(sizeof(IndexTuple) * maxoff);
+       for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+               itvec[(*len)++] = (IndexTuple) PageGetItem(p, PageGetItemId(p, i));
 
        return itvec;
 }
@@ -596,9 +626,10 @@ gistreadbuffer( Relation r, Buffer buffer, int *len /*out*/) {
  * join two vectors into one
  */
 static IndexTuple *
-gistjoinvector( IndexTuple *itvec, int *len, IndexTuple *additvec, int addlen ) {
-       itvec = (IndexTuple*) repalloc( (void*)itvec, sizeof(IndexTuple) * ( (*len) + addlen ) );
-       memmove( &itvec[*len], additvec, sizeof(IndexTuple) * addlen );
+gistjoinvector(IndexTuple *itvec, int *len, IndexTuple *additvec, int addlen)
+{
+       itvec = (IndexTuple *) repalloc((void *) itvec, sizeof(IndexTuple) * ((*len) + addlen));
+       memmove(&itvec[*len], additvec, sizeof(IndexTuple) * addlen);
        *len += addlen;
        return itvec;
 }
@@ -607,115 +638,124 @@ gistjoinvector( IndexTuple *itvec, int *len, IndexTuple *additvec, int addlen )
  * return union of itup vector
  */
 static IndexTuple
-gistunion( Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate ) {
-       bytea   *evec;
-       char    *datum;
-       int     datumsize, i;
-       GISTENTRY centry;
-       char isnull;
-       IndexTuple newtup;
+gistunion(Relation r, IndexTuple *itvec, int len, GISTSTATE *giststate)
+{
+       bytea      *evec;
+       char       *datum;
+       int                     datumsize,
+                               i;
+       GISTENTRY       centry;
+       char            isnull;
+       IndexTuple      newtup;
 
        evec = (bytea *) palloc(len * sizeof(GISTENTRY) + VARHDRSZ);
        VARATT_SIZEP(evec) = len * sizeof(GISTENTRY) + VARHDRSZ;
 
-       for ( i = 0 ; i< len ; i++ ) 
+       for (i = 0; i < len; i++)
                gistdentryinit(giststate, &((GISTENTRY *) VARDATA(evec))[i],
-                       (char*) itvec[i] + sizeof(IndexTupleData), 
-                       (Relation)NULL, (Page)NULL, (OffsetNumber)NULL,
-                       IndexTupleSize((IndexTuple)itvec[i]) - sizeof(IndexTupleData), FALSE);
+                                          (char *) itvec[i] + sizeof(IndexTupleData),
+                                          (Relation) NULL, (Page) NULL, (OffsetNumber) NULL,
+                                          IndexTupleSize((IndexTuple) itvec[i]) - sizeof(IndexTupleData), FALSE);
 
        datum = (char *)
                DatumGetPointer(FunctionCall2(&giststate->unionFn,
-                       PointerGetDatum(evec),
-                       PointerGetDatum(&datumsize)));
+                                                                         PointerGetDatum(evec),
+                                                                         PointerGetDatum(&datumsize)));
+
+       for (i = 0; i < len; i++)
+               if (((GISTENTRY *) VARDATA(evec))[i].pred &&
+                       ((GISTENTRY *) VARDATA(evec))[i].pred !=
+                       ((char *) (itvec[i]) + sizeof(IndexTupleData)))
+                       pfree(((GISTENTRY *) VARDATA(evec))[i].pred);
 
-       for ( i = 0 ; i< len ; i++ )
-               if ( ((GISTENTRY *) VARDATA(evec))[i].pred &&
-                  ((GISTENTRY *) VARDATA(evec))[i].pred != 
-                  ((char*)( itvec[i] )+ sizeof(IndexTupleData)) )
-                       pfree( ((GISTENTRY *) VARDATA(evec))[i].pred ); 
-            
-       pfree( evec );
+       pfree(evec);
 
-       gistcentryinit(giststate, &centry, datum, 
-               (Relation)NULL, (Page)NULL, (OffsetNumber)NULL,
-               datumsize, FALSE);
+       gistcentryinit(giststate, &centry, datum,
+                                  (Relation) NULL, (Page) NULL, (OffsetNumber) NULL,
+                                  datumsize, FALSE);
 
        isnull = (centry.pred) ? ' ' : 'n';
-       newtup = (IndexTuple) index_formtuple( r->rd_att, (Datum *) &centry.pred, &isnull );
+       newtup = (IndexTuple) index_formtuple(r->rd_att, (Datum *) &centry.pred, &isnull);
        if (centry.pred != datum)
-               pfree( datum );
+               pfree(datum);
 
        return newtup;
-} 
+}
 
 /*
  * Forms union of oldtup and addtup, if union == oldtup then return NULL
  */
 static IndexTuple
-gistgetadjusted( Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate ) {
-       bytea   *evec;
-       char    *datum;
-       int     datumsize;
-       bool    result;
-       char    isnull;
-       GISTENTRY centry, *ev0p, *ev1p;
-       IndexTuple newtup = NULL;
-       
+gistgetadjusted(Relation r, IndexTuple oldtup, IndexTuple addtup, GISTSTATE *giststate)
+{
+       bytea      *evec;
+       char       *datum;
+       int                     datumsize;
+       bool            result;
+       char            isnull;
+       GISTENTRY       centry,
+                          *ev0p,
+                          *ev1p;
+       IndexTuple      newtup = NULL;
+
        evec = (bytea *) palloc(2 * sizeof(GISTENTRY) + VARHDRSZ);
        VARATT_SIZEP(evec) = 2 * sizeof(GISTENTRY) + VARHDRSZ;
 
        gistdentryinit(giststate, &((GISTENTRY *) VARDATA(evec))[0],
-               (char*) oldtup + sizeof(IndexTupleData), (Relation) NULL, 
-               (Page) NULL, (OffsetNumber) 0,
-               IndexTupleSize((IndexTuple)oldtup) - sizeof(IndexTupleData), FALSE);
+                          (char *) oldtup + sizeof(IndexTupleData), (Relation) NULL,
+                                  (Page) NULL, (OffsetNumber) 0,
+       IndexTupleSize((IndexTuple) oldtup) - sizeof(IndexTupleData), FALSE);
        ev0p = &((GISTENTRY *) VARDATA(evec))[0];
 
        gistdentryinit(giststate, &((GISTENTRY *) VARDATA(evec))[1],
-               (char*) addtup + sizeof(IndexTupleData), (Relation) NULL,
-               (Page) NULL, (OffsetNumber) 0,
-               IndexTupleSize((IndexTuple)addtup) - sizeof(IndexTupleData), FALSE);
+                          (char *) addtup + sizeof(IndexTupleData), (Relation) NULL,
+                                  (Page) NULL, (OffsetNumber) 0,
+       IndexTupleSize((IndexTuple) addtup) - sizeof(IndexTupleData), FALSE);
        ev1p = &((GISTENTRY *) VARDATA(evec))[1];
 
        datum = (char *)
                DatumGetPointer(FunctionCall2(&giststate->unionFn,
-                       PointerGetDatum(evec),
-                       PointerGetDatum(&datumsize)));
+                                                                         PointerGetDatum(evec),
+                                                                         PointerGetDatum(&datumsize)));
 
-       if ( ! ( ev0p->pred && ev1p->pred ) ) {
-               result = ( ev0p->pred == NULL && ev1p->pred == NULL );
-       } else {
+       if (!(ev0p->pred && ev1p->pred))
+               result = (ev0p->pred == NULL && ev1p->pred == NULL);
+       else
+       {
                FunctionCall3(&giststate->equalFn,
-                       PointerGetDatum(ev0p->pred),
-                       PointerGetDatum(datum),
-                       PointerGetDatum(&result));
+                                         PointerGetDatum(ev0p->pred),
+                                         PointerGetDatum(datum),
+                                         PointerGetDatum(&result));
        }
 
-       if ( result ) {
+       if (result)
+       {
                /* not need to update key */
-               pfree( datum );
-       } else {
+               pfree(datum);
+       }
+       else
+       {
                gistcentryinit(giststate, &centry, datum, ev0p->rel, ev0p->page,
-                       ev0p->offset, datumsize, FALSE);
+                                          ev0p->offset, datumsize, FALSE);
 
                isnull = (centry.pred) ? ' ' : 'n';
-               newtup = (IndexTuple) index_formtuple( r->rd_att, (Datum *) &centry.pred, &isnull );
-               newtup->t_tid = oldtup->t_tid; 
+               newtup = (IndexTuple) index_formtuple(r->rd_att, (Datum *) &centry.pred, &isnull);
+               newtup->t_tid = oldtup->t_tid;
                if (centry.pred != datum)
-                       pfree( datum );
+                       pfree(datum);
        }
 
-       if ( ev0p->pred && 
-            ev0p->pred != (char*) oldtup + sizeof(IndexTupleData)  ) 
-               pfree( ev0p->pred ); 
-       if ( ev1p->pred && 
-            ev1p->pred != (char*) addtup + sizeof(IndexTupleData)  ) 
-               pfree( ev1p->pred ); 
-       pfree( evec );
+       if (ev0p->pred &&
+               ev0p->pred != (char *) oldtup + sizeof(IndexTupleData))
+               pfree(ev0p->pred);
+       if (ev1p->pred &&
+               ev1p->pred != (char *) addtup + sizeof(IndexTupleData))
+               pfree(ev1p->pred);
+       pfree(evec);
 
-       return newtup;  
+       return newtup;
 }
+
 /*
  *     gistSplit -- split a page in the tree.
  */
@@ -728,19 +768,27 @@ gistSplit(Relation r,
                  InsertIndexResult *res)
 {
        Page            p;
-       Buffer          leftbuf, rightbuf;
-       Page            left, right;
-       OffsetNumber    *spl_left, *spl_right;
-       IndexTuple      *lvectup, *rvectup, *newtup;
-       int leftoff, rightoff;
-       BlockNumber lbknum, rbknum;
+       Buffer          leftbuf,
+                               rightbuf;
+       Page            left,
+                               right;
+       OffsetNumber *spl_left,
+                          *spl_right;
+       IndexTuple *lvectup,
+                          *rvectup,
+                          *newtup;
+       int                     leftoff,
+                               rightoff;
+       BlockNumber lbknum,
+                               rbknum;
        GISTPageOpaque opaque;
-       char       isnull;
+       char            isnull;
        GIST_SPLITVEC v;
        bytea      *entryvec;
        bool       *decompvec;
        GISTENTRY       tmpentry;
-       int i, nlen;
+       int                     i,
+                               nlen;
 
        p = (Page) BufferGetPage(buffer);
        opaque = (GISTPageOpaque) PageGetSpecialPointer(p);
@@ -773,17 +821,17 @@ gistSplit(Relation r,
        right = (Page) BufferGetPage(rightbuf);
 
        /* generate the item array */
-       entryvec = (bytea *) palloc(VARHDRSZ + (*len+1) * sizeof(GISTENTRY));
-       decompvec = (bool *) palloc(VARHDRSZ + (*len+1) * sizeof(bool));
-       VARATT_SIZEP(entryvec) = (*len+1) * sizeof(GISTENTRY) + VARHDRSZ;
+       entryvec = (bytea *) palloc(VARHDRSZ + (*len + 1) * sizeof(GISTENTRY));
+       decompvec = (bool *) palloc(VARHDRSZ + (*len + 1) * sizeof(bool));
+       VARATT_SIZEP(entryvec) = (*len + 1) * sizeof(GISTENTRY) + VARHDRSZ;
        for (i = 1; i <= *len; i++)
        {
                gistdentryinit(giststate, &((GISTENTRY *) VARDATA(entryvec))[i],
-                                          (((char *) itup[i-1]) + sizeof(IndexTupleData)),
+                                          (((char *) itup[i - 1]) + sizeof(IndexTupleData)),
                                           r, p, i,
-                                IndexTupleSize(itup[i-1]) - sizeof(IndexTupleData), FALSE);
+                       IndexTupleSize(itup[i - 1]) - sizeof(IndexTupleData), FALSE);
                if ((char *) (((GISTENTRY *) VARDATA(entryvec))[i].pred)
-                       == (((char *) itup[i-1]) + sizeof(IndexTupleData)))
+                       == (((char *) itup[i - 1]) + sizeof(IndexTupleData)))
                        decompvec[i] = FALSE;
                else
                        decompvec[i] = TRUE;
@@ -791,8 +839,8 @@ gistSplit(Relation r,
 
        /* now let the user-defined picksplit function set up the split vector */
        FunctionCall2(&giststate->picksplitFn,
-               PointerGetDatum(entryvec),
-               PointerGetDatum(&v));
+                                 PointerGetDatum(entryvec),
+                                 PointerGetDatum(&v));
 
        /* clean up the entry vector: its preds need to be deleted, too */
        for (i = 1; i <= *len; i++)
@@ -801,35 +849,43 @@ gistSplit(Relation r,
        pfree(entryvec);
        pfree(decompvec);
 
-       spl_left = v.spl_left; spl_right = v.spl_right;
-       
+       spl_left = v.spl_left;
+       spl_right = v.spl_right;
+
        /* form left and right vector */
-       lvectup = (IndexTuple*) palloc( sizeof( IndexTuple )*v.spl_nleft );
-       rvectup = (IndexTuple*) palloc( sizeof( IndexTuple )*v.spl_nright );
+       lvectup = (IndexTuple *) palloc(sizeof(IndexTuple) * v.spl_nleft);
+       rvectup = (IndexTuple *) palloc(sizeof(IndexTuple) * v.spl_nright);
        leftoff = rightoff = 0;
-       for( i=1; i <= *len; i++ ) {
-               if (i == *(spl_left) || ( i==*len && *(spl_left) != FirstOffsetNumber ) ) {
-                       lvectup[ leftoff++ ] = itup[ i-1 ];
+       for (i = 1; i <= *len; i++)
+       {
+               if (i == *(spl_left) || (i == *len && *(spl_left) != FirstOffsetNumber))
+               {
+                       lvectup[leftoff++] = itup[i - 1];
                        spl_left++;
-               } else { 
-                       rvectup[ rightoff++ ] = itup[ i-1 ];
+               }
+               else
+               {
+                       rvectup[rightoff++] = itup[i - 1];
                        spl_right++;
                }
        }
 
        /* write on disk (may be need another split) */
-       if ( gistnospace(right, rvectup, v.spl_nright) ) {
+       if (gistnospace(right, rvectup, v.spl_nright))
+       {
                nlen = v.spl_nright;
-               newtup = gistSplit(r, rightbuf, rvectup, &nlen, giststate, 
-                       ( res && rvectup[ nlen-1 ] == itup[ *len - 1 ] ) ? res : NULL );
-               ReleaseBuffer( rightbuf );
-       } else {
+               newtup = gistSplit(r, rightbuf, rvectup, &nlen, giststate,
+                         (res && rvectup[nlen - 1] == itup[*len - 1]) ? res : NULL);
+               ReleaseBuffer(rightbuf);
+       }
+       else
+       {
                OffsetNumber l;
-       
-               l = gistwritebuffer( r, right, rvectup, v.spl_nright, FirstOffsetNumber, giststate );
+
+               l = gistwritebuffer(r, right, rvectup, v.spl_nright, FirstOffsetNumber, giststate);
                WriteBuffer(rightbuf);
 
-               if ( res )
+               if (res)
                        ItemPointerSet(&((*res)->pointerData), rbknum, l);
                gistcentryinit(giststate, &tmpentry, v.spl_rdatum, (Relation) NULL,
                                           (Page) NULL, (OffsetNumber) 0,
@@ -839,32 +895,35 @@ gistSplit(Relation r,
                v.spl_rdatum = tmpentry.pred;
 
                nlen = 1;
-               newtup = (IndexTuple*) palloc( sizeof(IndexTuple) * 1);
-               isnull = ( v.spl_rdatum ) ? ' ' : 'n';
+               newtup = (IndexTuple *) palloc(sizeof(IndexTuple) * 1);
+               isnull = (v.spl_rdatum) ? ' ' : 'n';
                newtup[0] = (IndexTuple) index_formtuple(r->rd_att, (Datum *) &(v.spl_rdatum), &isnull);
                ItemPointerSet(&(newtup[0]->t_tid), rbknum, 1);
        }
 
-       if ( gistnospace(left, lvectup, v.spl_nleft) ) {
-               int llen = v.spl_nleft;
+       if (gistnospace(left, lvectup, v.spl_nleft))
+       {
+               int                     llen = v.spl_nleft;
                IndexTuple *lntup;
 
-               lntup = gistSplit(r, leftbuf, lvectup, &llen, giststate, 
-                       ( res && lvectup[ llen-1 ] == itup[ *len - 1 ] ) ? res : NULL );
-               ReleaseBuffer( leftbuf );
+               lntup = gistSplit(r, leftbuf, lvectup, &llen, giststate,
+                         (res && lvectup[llen - 1] == itup[*len - 1]) ? res : NULL);
+               ReleaseBuffer(leftbuf);
 
-               newtup = gistjoinvector( newtup, &nlen, lntup, llen );
-               pfree( lntup ); 
-       } else {
+               newtup = gistjoinvector(newtup, &nlen, lntup, llen);
+               pfree(lntup);
+       }
+       else
+       {
                OffsetNumber l;
-       
-               l = gistwritebuffer( r, left, lvectup, v.spl_nleft, FirstOffsetNumber, giststate );
-               if ( BufferGetBlockNumber(buffer) != GISTP_ROOT)
+
+               l = gistwritebuffer(r, left, lvectup, v.spl_nleft, FirstOffsetNumber, giststate);
+               if (BufferGetBlockNumber(buffer) != GISTP_ROOT)
                        PageRestoreTempPage(left, p);
 
                WriteBuffer(leftbuf);
 
-               if ( res )
+               if (res)
                        ItemPointerSet(&((*res)->pointerData), lbknum, l);
                gistcentryinit(giststate, &tmpentry, v.spl_ldatum, (Relation) NULL,
                                           (Page) NULL, (OffsetNumber) 0,
@@ -874,10 +933,10 @@ gistSplit(Relation r,
                v.spl_ldatum = tmpentry.pred;
 
                nlen += 1;
-               newtup = (IndexTuple*) repalloc( (void*)newtup, sizeof(IndexTuple) * nlen);
-               isnull = ( v.spl_ldatum ) ? ' ' : 'n';
-               newtup[nlen-1] = (IndexTuple) index_formtuple(r->rd_att, (Datum *) &(v.spl_ldatum), &isnull);
-               ItemPointerSet(&(newtup[nlen-1]->t_tid), lbknum, 1);
+               newtup = (IndexTuple *) repalloc((void *) newtup, sizeof(IndexTuple) * nlen);
+               isnull = (v.spl_ldatum) ? ' ' : 'n';
+               newtup[nlen - 1] = (IndexTuple) index_formtuple(r->rd_att, (Datum *) &(v.spl_ldatum), &isnull);
+               ItemPointerSet(&(newtup[nlen - 1]->t_tid), lbknum, 1);
        }
 
 
@@ -885,10 +944,10 @@ gistSplit(Relation r,
        gistadjscans(r, GISTOP_SPLIT, BufferGetBlockNumber(buffer), FirstOffsetNumber);
 
        /* !!! pfree */
-       pfree( rvectup );
-       pfree( lvectup );
-       pfree( v.spl_left );
-       pfree( v.spl_right );
+       pfree(rvectup);
+       pfree(lvectup);
+       pfree(v.spl_left);
+       pfree(v.spl_right);
 
        *len = nlen;
        return newtup;
@@ -903,8 +962,8 @@ gistnewroot(GISTSTATE *giststate, Relation r, IndexTuple *itup, int len)
        b = ReadBuffer(r, GISTP_ROOT);
        GISTInitBuffer(b, 0);
        p = BufferGetPage(b);
-       
-       gistwritebuffer( r, p, itup, len, FirstOffsetNumber, giststate );
+
+       gistwritebuffer(r, p, itup, len, FirstOffsetNumber, giststate);
        WriteBuffer(b);
 }
 
@@ -1000,8 +1059,8 @@ gistfreestack(GISTSTACK *s)
 Datum
 gistdelete(PG_FUNCTION_ARGS)
 {
-       Relation                r = (Relation) PG_GETARG_POINTER(0);
-       ItemPointer             tid = (ItemPointer) PG_GETARG_POINTER(1);
+       Relation        r = (Relation) PG_GETARG_POINTER(0);
+       ItemPointer tid = (ItemPointer) PG_GETARG_POINTER(1);
        BlockNumber blkno;
        OffsetNumber offnum;
        Buffer          buf;
@@ -1101,7 +1160,7 @@ gist_tuple_replacekey(Relation r, GISTENTRY entry, IndexTuple t)
        char       *datum = (((char *) t) + sizeof(IndexTupleData));
 
        /* if new entry fits in index tuple, copy it in */
-       if ((Size) entry.bytes < IndexTupleSize(t) - sizeof(IndexTupleData) || (Size) entry.bytes == 0 )
+       if ((Size) entry.bytes < IndexTupleSize(t) - sizeof(IndexTupleData) || (Size) entry.bytes == 0)
        {
                memcpy(datum, entry.pred, entry.bytes);
                /* clear out old size */
@@ -1116,9 +1175,9 @@ gist_tuple_replacekey(Relation r, GISTENTRY entry, IndexTuple t)
                /* generate a new index tuple for the compressed entry */
                TupleDesc       tupDesc = r->rd_att;
                IndexTuple      newtup;
-               char       isnull;
+               char            isnull;
 
-               isnull = ( entry.pred ) ? ' ' : 'n';
+               isnull = (entry.pred) ? ' ' : 'n';
                newtup = (IndexTuple) index_formtuple(tupDesc,
                                                                                          (Datum *) &(entry.pred),
                                                                                          &isnull);
@@ -1181,38 +1240,40 @@ gist_dumptree(Relation r, int level, BlockNumber blk, OffsetNumber coff)
        Page            page;
        GISTPageOpaque opaque;
        IndexTuple      which;
-       ItemId          iid;
-       OffsetNumber i,maxoff;
-       BlockNumber     cblk;
-       char    *pred;
+       ItemId          iid;
+       OffsetNumber i,
+                               maxoff;
+       BlockNumber cblk;
+       char       *pred;
 
-       pred  = (char*) palloc( sizeof(char)*level+1 );
+       pred = (char *) palloc(sizeof(char) * level + 1);
        MemSet(pred, '\t', level);
-       pred[level]='\0';
+       pred[level] = '\0';
 
        buffer = ReadBuffer(r, blk);
        page = (Page) BufferGetPage(buffer);
        opaque = (GISTPageOpaque) PageGetSpecialPointer(page);
-       
-       maxoff = PageGetMaxOffsetNumber( page );
-       
-       elog(NOTICE,"%sPage: %d %s blk: %d maxoff: %d free: %d", pred, coff, ( opaque->flags & F_LEAF ) ? "LEAF" : "INTE", (int)blk, (int)maxoff, PageGetFreeSpace(page));
-       
-       for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i)) {
+
+       maxoff = PageGetMaxOffsetNumber(page);
+
+       elog(NOTICE, "%sPage: %d %s blk: %d maxoff: %d free: %d", pred, coff, (opaque->flags & F_LEAF) ? "LEAF" : "INTE", (int) blk, (int) maxoff, PageGetFreeSpace(page));
+
+       for (i = FirstOffsetNumber; i <= maxoff; i = OffsetNumberNext(i))
+       {
                iid = PageGetItemId(page, i);
                which = (IndexTuple) PageGetItem(page, iid);
                cblk = ItemPointerGetBlockNumber(&(which->t_tid));
-#ifdef PRINTTUPLE              
-               elog(NOTICE,"%s  Tuple. blk: %d size: %d", pred, (int)cblk, IndexTupleSize( which ) );
-#endif 
-       
-               if ( ! ( opaque->flags & F_LEAF ) ) { 
-                       gist_dumptree( r, level+1, cblk, i );
-               }
+#ifdef PRINTTUPLE
+               elog(NOTICE, "%s  Tuple. blk: %d size: %d", pred, (int) cblk, IndexTupleSize(which));
+#endif
+
+               if (!(opaque->flags & F_LEAF))
+                       gist_dumptree(r, level + 1, cblk, i);
        }
        ReleaseBuffer(buffer);
        pfree(pred);
 }
+
 #endif  /* defined GISTDEBUG */
 
 void
@@ -1220,15 +1281,14 @@ gist_redo(XLogRecPtr lsn, XLogRecord *record)
 {
        elog(STOP, "gist_redo: unimplemented");
 }
+
 void
 gist_undo(XLogRecPtr lsn, XLogRecord *record)
 {
        elog(STOP, "gist_undo: unimplemented");
 }
+
 void
-gist_desc(char *buf, uint8 xl_info, charrec)
+gist_desc(char *buf, uint8 xl_info, char *rec)
 {
 }
-
index f7b49430d07936683eeca20a03b06f167489d726..8f3b5dd475c96ce0c1b4cacddb51d0ceeae2264b 100644 (file)
@@ -32,8 +32,8 @@ static bool gistindex_keytest(IndexTuple tuple, TupleDesc tupdesc,
 Datum
 gistgettuple(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc           s = (IndexScanDesc) PG_GETARG_POINTER(0);
-       ScanDirection           dir = (ScanDirection) PG_GETARG_INT32(1);
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       ScanDirection dir = (ScanDirection) PG_GETARG_INT32(1);
        RetrieveIndexResult res;
 
        /* if we have it cached in the scan desc, just return the value */
index d37a8c077631bb941ba31447da9981c023db5ea5..ba21fee3c33ea834a7856dcfe0b4416cde6d387c 100644 (file)
@@ -72,9 +72,9 @@ gistbeginscan(PG_FUNCTION_ARGS)
 Datum
 gistrescan(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   s = (IndexScanDesc) PG_GETARG_POINTER(0);
-       bool                    fromEnd = PG_GETARG_BOOL(1);
-       ScanKey                 key = (ScanKey) PG_GETARG_POINTER(2);
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       bool            fromEnd = PG_GETARG_BOOL(1);
+       ScanKey         key = (ScanKey) PG_GETARG_POINTER(2);
        GISTScanOpaque p;
        int                     i;
 
@@ -160,7 +160,7 @@ gistrescan(PG_FUNCTION_ARGS)
 Datum
 gistmarkpos(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
        GISTScanOpaque p;
        GISTSTACK  *o,
                           *n,
@@ -196,7 +196,7 @@ gistmarkpos(PG_FUNCTION_ARGS)
 Datum
 gistrestrpos(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
        GISTScanOpaque p;
        GISTSTACK  *o,
                           *n,
@@ -232,8 +232,8 @@ gistrestrpos(PG_FUNCTION_ARGS)
 Datum
 gistendscan(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   s = (IndexScanDesc) PG_GETARG_POINTER(0);
-       GISTScanOpaque  p;
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       GISTScanOpaque p;
 
        p = (GISTScanOpaque) s->opaque;
 
index 44a8b225e8f42d886078d9e9f6afe7409f297b9d..aa76ba232a05c21da94012fbefbc287924aa154f 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.49 2001/02/22 21:48:49 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/hash/hash.c,v 1.50 2001/03/22 03:59:12 momjian Exp $
  *
  * NOTES
  *       This file contains only the public interface routines.
@@ -41,12 +41,14 @@ bool                BuildingHash = false;
 Datum
 hashbuild(PG_FUNCTION_ARGS)
 {
-       Relation                heap = (Relation) PG_GETARG_POINTER(0);
-       Relation                index = (Relation) PG_GETARG_POINTER(1);
-       IndexInfo          *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
-       Node               *oldPred = (Node *) PG_GETARG_POINTER(3);
+       Relation        heap = (Relation) PG_GETARG_POINTER(0);
+       Relation        index = (Relation) PG_GETARG_POINTER(1);
+       IndexInfo  *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
+       Node       *oldPred = (Node *) PG_GETARG_POINTER(3);
+
 #ifdef NOT_USED
-       IndexStrategy   istrat = (IndexStrategy) PG_GETARG_POINTER(4);
+       IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
+
 #endif
        HeapScanDesc hscan;
        HeapTuple       htup;
@@ -59,9 +61,11 @@ hashbuild(PG_FUNCTION_ARGS)
                                nitups;
        HashItem        hitem;
        Node       *pred = indexInfo->ii_Predicate;
+
 #ifndef OMIT_PARTIAL_INDEX
        TupleTable      tupleTable;
        TupleTableSlot *slot;
+
 #endif
        ExprContext *econtext;
        InsertIndexResult res = NULL;
@@ -117,6 +121,7 @@ hashbuild(PG_FUNCTION_ARGS)
                nhtups++;
 
 #ifndef OMIT_PARTIAL_INDEX
+
                /*
                 * If oldPred != NULL, this is an EXTEND INDEX command, so skip
                 * this tuple if it was already in the existing partial index
@@ -191,9 +196,7 @@ hashbuild(PG_FUNCTION_ARGS)
 
 #ifndef OMIT_PARTIAL_INDEX
        if (pred != NULL || oldPred != NULL)
-       {
                ExecDropTupleTable(tupleTable, true);
-       }
 #endif  /* OMIT_PARTIAL_INDEX */
        FreeExprContext(econtext);
 
@@ -241,12 +244,14 @@ hashbuild(PG_FUNCTION_ARGS)
 Datum
 hashinsert(PG_FUNCTION_ARGS)
 {
-       Relation                rel = (Relation) PG_GETARG_POINTER(0);
-       Datum              *datum = (Datum *) PG_GETARG_POINTER(1);
-       char               *nulls = (char *) PG_GETARG_POINTER(2);
-       ItemPointer             ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
+       Relation        rel = (Relation) PG_GETARG_POINTER(0);
+       Datum      *datum = (Datum *) PG_GETARG_POINTER(1);
+       char       *nulls = (char *) PG_GETARG_POINTER(2);
+       ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
+
 #ifdef NOT_USED
-       Relation                heapRel = (Relation) PG_GETARG_POINTER(4);
+       Relation        heapRel = (Relation) PG_GETARG_POINTER(4);
+
 #endif
        InsertIndexResult res;
        HashItem        hitem;
@@ -276,8 +281,8 @@ hashinsert(PG_FUNCTION_ARGS)
 Datum
 hashgettuple(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc           scan = (IndexScanDesc) PG_GETARG_POINTER(0);
-       ScanDirection           dir = (ScanDirection) PG_GETARG_INT32(1);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       ScanDirection dir = (ScanDirection) PG_GETARG_INT32(1);
        RetrieveIndexResult res;
 
        /*
@@ -326,11 +331,13 @@ hashbeginscan(PG_FUNCTION_ARGS)
 Datum
 hashrescan(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+
 #ifdef NOT_USED                                        /* XXX surely it's wrong to ignore this? */
-       bool                    fromEnd = PG_GETARG_BOOL(1);
+       bool            fromEnd = PG_GETARG_BOOL(1);
+
 #endif
-       ScanKey                 scankey = (ScanKey) PG_GETARG_POINTER(2);
+       ScanKey         scankey = (ScanKey) PG_GETARG_POINTER(2);
        ItemPointer iptr;
        HashScanOpaque so;
 
@@ -367,7 +374,7 @@ hashrescan(PG_FUNCTION_ARGS)
 Datum
 hashendscan(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
        ItemPointer iptr;
        HashScanOpaque so;
 
@@ -405,7 +412,7 @@ hashendscan(PG_FUNCTION_ARGS)
 Datum
 hashmarkpos(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
        ItemPointer iptr;
        HashScanOpaque so;
 
@@ -437,7 +444,7 @@ hashmarkpos(PG_FUNCTION_ARGS)
 Datum
 hashrestrpos(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
        ItemPointer iptr;
        HashScanOpaque so;
 
@@ -468,8 +475,8 @@ hashrestrpos(PG_FUNCTION_ARGS)
 Datum
 hashdelete(PG_FUNCTION_ARGS)
 {
-       Relation                rel = (Relation) PG_GETARG_POINTER(0);
-       ItemPointer             tid = (ItemPointer) PG_GETARG_POINTER(1);
+       Relation        rel = (Relation) PG_GETARG_POINTER(0);
+       ItemPointer tid = (ItemPointer) PG_GETARG_POINTER(1);
 
        /* adjust any active scans that will be affected by this deletion */
        _hash_adjscans(rel, tid);
@@ -491,8 +498,8 @@ hash_undo(XLogRecPtr lsn, XLogRecord *record)
 {
        elog(STOP, "hash_undo: unimplemented");
 }
+
 void
-hash_desc(char *buf, uint8 xl_info, charrec)
+hash_desc(char *buf, uint8 xl_info, char *rec)
 {
 }
index 30defc1a57b03bc5502aea9d70fe3f7fc0c28f3b..4cb157c702c15f3183b537f7fcf9d44d02f2aa9e 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.29 2001/01/24 19:42:47 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/hash/hashfunc.c,v 1.30 2001/03/22 03:59:13 momjian Exp $
  *
  * NOTES
  *       These functions are stored in pg_amproc.      For each operator class
 Datum
 hashchar(PG_FUNCTION_ARGS)
 {
-       PG_RETURN_UINT32(~ ((uint32) PG_GETARG_CHAR(0)));
+       PG_RETURN_UINT32(~((uint32) PG_GETARG_CHAR(0)));
 }
 
 Datum
 hashint2(PG_FUNCTION_ARGS)
 {
-       PG_RETURN_UINT32(~ ((uint32) PG_GETARG_INT16(0)));
+       PG_RETURN_UINT32(~((uint32) PG_GETARG_INT16(0)));
 }
 
 Datum
 hashint4(PG_FUNCTION_ARGS)
 {
-       PG_RETURN_UINT32(~ PG_GETARG_UINT32(0));
+       PG_RETURN_UINT32(~PG_GETARG_UINT32(0));
 }
 
 Datum
 hashint8(PG_FUNCTION_ARGS)
 {
        /* we just use the low 32 bits... */
-       PG_RETURN_UINT32(~ ((uint32) PG_GETARG_INT64(0)));
+       PG_RETURN_UINT32(~((uint32) PG_GETARG_INT64(0)));
 }
 
 Datum
 hashoid(PG_FUNCTION_ARGS)
 {
-       PG_RETURN_UINT32(~ ((uint32) PG_GETARG_OID(0)));
+       PG_RETURN_UINT32(~((uint32) PG_GETARG_OID(0)));
 }
 
 Datum
@@ -93,7 +93,7 @@ hashint2vector(PG_FUNCTION_ARGS)
 Datum
 hashname(PG_FUNCTION_ARGS)
 {
-       char       *key = NameStr(* PG_GETARG_NAME(0));
+       char       *key = NameStr(*PG_GETARG_NAME(0));
 
        return hash_any((char *) key, NAMEDATALEN);
 }
index 9748daa194ddf308e653a44cf9e8121b64fa9e10..b55717744c18daeaf1cf5508cb1aac9af446e924 100644 (file)
@@ -8,14 +8,14 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.110 2001/01/24 19:42:47 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.111 2001/03/22 03:59:13 momjian Exp $
  *
  *
  * INTERFACE ROUTINES
  *             heapgettup              - fetch next heap tuple from a scan
  *             heap_open               - open a heap relation by relationId
  *             heap_openr              - open a heap relation by name
- *             heap_open[r]_nofail     - same, but return NULL on failure instead of elog
+ *             heap_open[r]_nofail - same, but return NULL on failure instead of elog
  *             heap_close              - close a heap relation
  *             heap_beginscan  - begin relation scan
  *             heap_rescan             - restart a relation scan
 
 #include "access/xlogutils.h"
 
-XLogRecPtr     log_heap_move(Relation reln, Buffer oldbuf, ItemPointerData from, 
-                                                       Buffer newbuf, HeapTuple newtup);
-XLogRecPtr     log_heap_clean(Relation reln, Buffer buffer,
-                                                       char *unused, int unlen);
+XLogRecPtr log_heap_move(Relation reln, Buffer oldbuf, ItemPointerData from,
+                         Buffer newbuf, HeapTuple newtup);
+XLogRecPtr log_heap_clean(Relation reln, Buffer buffer,
+                          char *unused, int unlen);
 
 /* comments are in heap_update */
-static xl_heaptid      _locked_tuple_;
+static xl_heaptid _locked_tuple_;
 static void _heap_unlock_tuple(void *data);
-static XLogRecPtr log_heap_update(Relation reln, Buffer oldbuf, 
-                       ItemPointerData from, Buffer newbuf, HeapTuple newtup, bool move);
+static XLogRecPtr log_heap_update(Relation reln, Buffer oldbuf,
+          ItemPointerData from, Buffer newbuf, HeapTuple newtup, bool move);
 
 
 /* ----------------------------------------------------------------
@@ -249,7 +249,7 @@ heapgettup(Relation relation,
        OffsetNumber lineoff;
        int                     linesleft;
        ItemPointer tid = (tuple->t_data == NULL) ?
-               (ItemPointer) NULL : &(tuple->t_self);
+       (ItemPointer) NULL : &(tuple->t_self);
 
        /* ----------------
         *      increment access statistics
@@ -286,7 +286,7 @@ heapgettup(Relation relation,
 
        if (!ItemPointerIsValid(tid))
                Assert(!PointerIsValid(tid));
-    
+
        tuple->t_tableOid = relation->rd_id;
 
        /* ----------------
@@ -538,9 +538,9 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
                         (
                          (tupleDesc)->attrs[(attnum) - 1]->attcacheoff >= 0 ?
                          (
-                               fetchatt((tupleDesc)->attrs[(attnum) - 1],
-                                                (char *) (tup)->t_data + (tup)->t_data->t_hoff +
-                                                       (tupleDesc)->attrs[(attnum) - 1]->attcacheoff)
+                          fetchatt((tupleDesc)->attrs[(attnum) - 1],
+                                               (char *) (tup)->t_data + (tup)->t_data->t_hoff +
+                                               (tupleDesc)->attrs[(attnum) - 1]->attcacheoff)
                           )
                          :
                          nocachegetattr((tup), (attnum), (tupleDesc), (isnull))
@@ -564,7 +564,8 @@ fastgetattr(HeapTuple tup, int attnum, TupleDesc tupleDesc,
                         )
        );
 }
-#endif /* defined(DISABLE_COMPLEX_MACRO)*/
+
+#endif  /* defined(DISABLE_COMPLEX_MACRO) */
 
 
 /* ----------------------------------------------------------------
@@ -791,8 +792,8 @@ heap_beginscan(Relation relation,
        scan->rs_nkeys = (short) nkeys;
 
        /*
-        * we do this here instead of in initscan() because heap_rescan
-        * also calls initscan() and we don't want to allocate memory again
+        * we do this here instead of in initscan() because heap_rescan also
+        * calls initscan() and we don't want to allocate memory again
         */
        if (nkeys)
                scan->rs_key = (ScanKey) palloc(sizeof(ScanKeyData) * nkeys);
@@ -1316,7 +1317,7 @@ heap_get_latest_tid(Relation relation,
 Oid
 heap_insert(Relation relation, HeapTuple tup)
 {
-       Buffer buffer;
+       Buffer          buffer;
 
        /* increment access statistics */
        IncrHeapAccessStat(local_insert);
@@ -1350,7 +1351,7 @@ heap_insert(Relation relation, HeapTuple tup)
         * toasted attributes from some other relation, invoke the toaster.
         * ----------
         */
-    if (HeapTupleHasExtended(tup) ||
+       if (HeapTupleHasExtended(tup) ||
                (MAXALIGN(tup->t_len) > TOAST_TUPLE_THRESHOLD))
                heap_tuple_toast_attrs(relation, tup, NULL);
 #endif
@@ -1364,17 +1365,17 @@ heap_insert(Relation relation, HeapTuple tup)
 
        /* XLOG stuff */
        {
-               xl_heap_insert  xlrec;
-               xl_heap_header  xlhdr;
-               XLogRecPtr              recptr;
-               XLogRecData             rdata[3];
-               Page                    page = BufferGetPage(buffer);
-               uint8                   info = XLOG_HEAP_INSERT;
+               xl_heap_insert xlrec;
+               xl_heap_header xlhdr;
+               XLogRecPtr      recptr;
+               XLogRecData rdata[3];
+               Page            page = BufferGetPage(buffer);
+               uint8           info = XLOG_HEAP_INSERT;
 
                xlrec.target.node = relation->rd_node;
                xlrec.target.tid = tup->t_self;
                rdata[0].buffer = InvalidBuffer;
-               rdata[0].data = (char*)&xlrec;
+               rdata[0].data = (char *) &xlrec;
                rdata[0].len = SizeOfHeapInsert;
                rdata[0].next = &(rdata[1]);
 
@@ -1383,12 +1384,12 @@ heap_insert(Relation relation, HeapTuple tup)
                xlhdr.t_hoff = tup->t_data->t_hoff;
                xlhdr.mask = tup->t_data->t_infomask;
                rdata[1].buffer = buffer;
-               rdata[1].data = (char*)&xlhdr;
+               rdata[1].data = (char *) &xlhdr;
                rdata[1].len = SizeOfHeapHeader;
                rdata[1].next = &(rdata[2]);
 
                rdata[2].buffer = buffer;
-               rdata[2].data = (char*) tup->t_data + offsetof(HeapTupleHeaderData, t_bits);
+               rdata[2].data = (char *) tup->t_data + offsetof(HeapTupleHeaderData, t_bits);
                rdata[2].len = tup->t_len - offsetof(HeapTupleHeaderData, t_bits);
                rdata[2].next = NULL;
 
@@ -1411,10 +1412,10 @@ heap_insert(Relation relation, HeapTuple tup)
        WriteBuffer(buffer);
 
        /*
-        * If tuple is cachable, mark it for rollback from the caches
-        * in case we abort.  Note it is OK to do this after WriteBuffer
-        * releases the buffer, because the "tup" data structure is all
-        * in local memory, not in the shared buffer.
+        * If tuple is cachable, mark it for rollback from the caches in case
+        * we abort.  Note it is OK to do this after WriteBuffer releases the
+        * buffer, because the "tup" data structure is all in local memory,
+        * not in the shared buffer.
         */
        RelationMark4RollbackHeapTuple(relation, tup);
 
@@ -1513,14 +1514,14 @@ l1:
                                                         HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
        /* XLOG stuff */
        {
-               xl_heap_delete  xlrec;
-               XLogRecPtr              recptr;
-               XLogRecData             rdata[2];
+               xl_heap_delete xlrec;
+               XLogRecPtr      recptr;
+               XLogRecData rdata[2];
 
                xlrec.target.node = relation->rd_node;
                xlrec.target.tid = tp.t_self;
                rdata[0].buffer = InvalidBuffer;
-               rdata[0].data = (char*)&xlrec;
+               rdata[0].data = (char *) &xlrec;
                rdata[0].len = SizeOfHeapDelete;
                rdata[0].next = &(rdata[1]);
 
@@ -1551,9 +1552,10 @@ l1:
 #endif
 
        /*
-        * Mark tuple for invalidation from system caches at next command boundary.
-        * We have to do this before WriteBuffer because we need to look at the
-        * contents of the tuple, so we need to hold our refcount on the buffer.
+        * Mark tuple for invalidation from system caches at next command
+        * boundary. We have to do this before WriteBuffer because we need to
+        * look at the contents of the tuple, so we need to hold our refcount
+        * on the buffer.
         */
        RelationInvalidateHeapTuple(relation, &tp);
 
@@ -1567,7 +1569,7 @@ l1:
  *
  * This routine may be used to delete a tuple when concurrent updates of
  * the target tuple are not expected (for example, because we have a lock
- * on the relation associated with the tuple).  Any failure is reported
+ * on the relation associated with the tuple). Any failure is reported
  * via elog().
  */
 void
@@ -1636,6 +1638,7 @@ heap_update(Relation relation, ItemPointer otid, HeapTuple newtup,
        oldtup.t_data = (HeapTupleHeader) PageGetItem(dp, lp);
        oldtup.t_len = ItemIdGetLength(lp);
        oldtup.t_self = *otid;
+
        /*
         * Note: beyond this point, use oldtup not otid to refer to old tuple.
         * otid may very well point at newtup->t_self, which we will overwrite
@@ -1701,23 +1704,24 @@ l2:
 
        /*
         * If the toaster needs to be activated, OR if the new tuple will not
-        * fit on the same page as the old, then we need to release the context
-        * lock (but not the pin!) on the old tuple's buffer while we are off
-        * doing TOAST and/or table-file-extension work.  We must mark the old
-        * tuple to show that it's already being updated, else other processes
-        * may try to update it themselves. To avoid second XLOG log record,
-        * we use xact mgr hook to unlock old tuple without reading log if xact
-        * will abort before update is logged. In the event of crash prio logging,
-        * TQUAL routines will see HEAP_XMAX_UNLOGGED flag...
+        * fit on the same page as the old, then we need to release the
+        * context lock (but not the pin!) on the old tuple's buffer while we
+        * are off doing TOAST and/or table-file-extension work.  We must mark
+        * the old tuple to show that it's already being updated, else other
+        * processes may try to update it themselves. To avoid second XLOG log
+        * record, we use xact mgr hook to unlock old tuple without reading
+        * log if xact will abort before update is logged. In the event of
+        * crash prio logging, TQUAL routines will see HEAP_XMAX_UNLOGGED
+        * flag...
         *
-        * NOTE: this trick is useless currently but saved for future
-        * when we'll implement UNDO and will re-use transaction IDs
-        * after postmaster startup.
+        * NOTE: this trick is useless currently but saved for future when we'll
+        * implement UNDO and will re-use transaction IDs after postmaster
+        * startup.
         *
         * We need to invoke the toaster if there are already any toasted values
         * present, or if the new tuple is over-threshold.
         */
-       need_toast = (HeapTupleHasExtended(&oldtup) || 
+       need_toast = (HeapTupleHasExtended(&oldtup) ||
                                  HeapTupleHasExtended(newtup) ||
                                  (MAXALIGN(newtup->t_len) > TOAST_TUPLE_THRESHOLD));
 
@@ -1726,7 +1730,7 @@ l2:
        {
                _locked_tuple_.node = relation->rd_node;
                _locked_tuple_.tid = oldtup.t_self;
-               XactPushRollback(_heap_unlock_tuple, (void*) &_locked_tuple_);
+               XactPushRollback(_heap_unlock_tuple, (void *) &_locked_tuple_);
 
                TransactionIdStore(GetCurrentTransactionId(),
                                                   &(oldtup.t_data->t_xmax));
@@ -1762,7 +1766,7 @@ l2:
        /* NO ELOG(ERROR) from here till changes are logged */
        START_CRIT_SECTION();
 
-       RelationPutHeapTuple(relation, newbuf, newtup); /* insert new tuple */
+       RelationPutHeapTuple(relation, newbuf, newtup);         /* insert new tuple */
 
        if (already_marked)
        {
@@ -1784,7 +1788,7 @@ l2:
 
        /* XLOG stuff */
        {
-               XLogRecPtr      recptr = log_heap_update(relation, buffer, oldtup.t_self, 
+               XLogRecPtr      recptr = log_heap_update(relation, buffer, oldtup.t_self,
                                                                                         newbuf, newtup, false);
 
                if (newbuf != buffer)
@@ -1814,10 +1818,10 @@ l2:
        WriteBuffer(buffer);
 
        /*
-        * If new tuple is cachable, mark it for rollback from the caches
-        * in case we abort.  Note it is OK to do this after WriteBuffer
-        * releases the buffer, because the "newtup" data structure is all
-        * in local memory, not in the shared buffer.
+        * If new tuple is cachable, mark it for rollback from the caches in
+        * case we abort.  Note it is OK to do this after WriteBuffer releases
+        * the buffer, because the "newtup" data structure is all in local
+        * memory, not in the shared buffer.
         */
        RelationMark4RollbackHeapTuple(relation, newtup);
 
@@ -1829,7 +1833,7 @@ l2:
  *
  * This routine may be used to update a tuple when concurrent updates of
  * the target tuple are not expected (for example, because we have a lock
- * on the relation associated with the tuple).  Any failure is reported
+ * on the relation associated with the tuple). Any failure is reported
  * via elog().
  */
 void
@@ -2129,14 +2133,14 @@ heap_restrpos(HeapScanDesc scan)
 XLogRecPtr
 log_heap_clean(Relation reln, Buffer buffer, char *unused, int unlen)
 {
-       xl_heap_clean   xlrec;
-       XLogRecPtr              recptr;
-       XLogRecData             rdata[3];
+       xl_heap_clean xlrec;
+       XLogRecPtr      recptr;
+       XLogRecData rdata[3];
 
        xlrec.node = reln->rd_node;
        xlrec.block = BufferGetBlockNumber(buffer);
        rdata[0].buffer = InvalidBuffer;
-       rdata[0].data = (char*)&xlrec;
+       rdata[0].data = (char *) &xlrec;
        rdata[0].len = SizeOfHeapClean;
        rdata[0].next = &(rdata[1]);
 
@@ -2157,27 +2161,27 @@ log_heap_clean(Relation reln, Buffer buffer, char *unused, int unlen)
 
        recptr = XLogInsert(RM_HEAP_ID, XLOG_HEAP_CLEAN, rdata);
 
-       return(recptr);
+       return (recptr);
 }
 
 static XLogRecPtr
-log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from, 
+log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
                                Buffer newbuf, HeapTuple newtup, bool move)
 {
-       char                    tbuf[MAXALIGN(sizeof(xl_heap_header)) + 2 * sizeof(TransactionId)];
-       xl_heap_update  xlrec;
-       xl_heap_header *xlhdr = (xl_heap_header*) tbuf;
-       int                             hsize = SizeOfHeapHeader;
-       XLogRecPtr              recptr;
-       XLogRecData             rdata[4];
-       Page                    page = BufferGetPage(newbuf);
-       uint8                   info = (move) ? XLOG_HEAP_MOVE : XLOG_HEAP_UPDATE;
+       char            tbuf[MAXALIGN(sizeof(xl_heap_header)) + 2 * sizeof(TransactionId)];
+       xl_heap_update xlrec;
+       xl_heap_header *xlhdr = (xl_heap_header *) tbuf;
+       int                     hsize = SizeOfHeapHeader;
+       XLogRecPtr      recptr;
+       XLogRecData rdata[4];
+       Page            page = BufferGetPage(newbuf);
+       uint8           info = (move) ? XLOG_HEAP_MOVE : XLOG_HEAP_UPDATE;
 
        xlrec.target.node = reln->rd_node;
        xlrec.target.tid = from;
        xlrec.newtid = newtup->t_self;
        rdata[0].buffer = InvalidBuffer;
-       rdata[0].data = (char*)&xlrec;
+       rdata[0].data = (char *) &xlrec;
        rdata[0].len = SizeOfHeapUpdate;
        rdata[0].next = &(rdata[1]);
 
@@ -2190,9 +2194,9 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
        xlhdr->t_natts = newtup->t_data->t_natts;
        xlhdr->t_hoff = newtup->t_data->t_hoff;
        xlhdr->mask = newtup->t_data->t_infomask;
-       if (move)       /* remember xmin & xmax */
+       if (move)                                       /* remember xmin & xmax */
        {
-               TransactionId   xmax;
+               TransactionId xmax;
 
                if (newtup->t_data->t_infomask & HEAP_XMAX_INVALID ||
                        newtup->t_data->t_infomask & HEAP_MARKED_FOR_UPDATE)
@@ -2200,17 +2204,17 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
                else
                        xmax = newtup->t_data->t_xmax;
                memcpy(tbuf + hsize, &xmax, sizeof(TransactionId));
-               memcpy(tbuf + hsize + sizeof(TransactionId), 
-                               &(newtup->t_data->t_xmin), sizeof(TransactionId));
+               memcpy(tbuf + hsize + sizeof(TransactionId),
+                          &(newtup->t_data->t_xmin), sizeof(TransactionId));
                hsize += (2 * sizeof(TransactionId));
        }
        rdata[2].buffer = newbuf;
-       rdata[2].data = (char*)xlhdr;
+       rdata[2].data = (char *) xlhdr;
        rdata[2].len = hsize;
        rdata[2].next = &(rdata[3]);
 
        rdata[3].buffer = newbuf;
-       rdata[3].data = (char*) newtup->t_data + offsetof(HeapTupleHeaderData, t_bits);
+       rdata[3].data = (char *) newtup->t_data + offsetof(HeapTupleHeaderData, t_bits);
        rdata[3].len = newtup->t_len - offsetof(HeapTupleHeaderData, t_bits);
        rdata[3].next = NULL;
 
@@ -2224,23 +2228,23 @@ log_heap_update(Relation reln, Buffer oldbuf, ItemPointerData from,
 
        recptr = XLogInsert(RM_HEAP_ID, info, rdata);
 
-       return(recptr);
+       return (recptr);
 }
 
 XLogRecPtr
-log_heap_move(Relation reln, Buffer oldbuf, ItemPointerData from, 
-                               Buffer newbuf, HeapTuple newtup)
+log_heap_move(Relation reln, Buffer oldbuf, ItemPointerData from,
+                         Buffer newbuf, HeapTuple newtup)
 {
-       return(log_heap_update(reln, oldbuf, from, newbuf, newtup, true));
+       return (log_heap_update(reln, oldbuf, from, newbuf, newtup, true));
 }
 
 static void
 heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record)
 {
-       xl_heap_clean  *xlrec = (xl_heap_clean*) XLogRecGetData(record);
-       Relation                reln;
-       Buffer                  buffer;
-       Page                    page;
+       xl_heap_clean *xlrec = (xl_heap_clean *) XLogRecGetData(record);
+       Relation        reln;
+       Buffer          buffer;
+       Page            page;
 
        if (!redo || (record->xl_info & XLR_BKP_BLOCK_1))
                return;
@@ -2266,15 +2270,15 @@ heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record)
 
        if (record->xl_len > SizeOfHeapClean)
        {
-               char                    unbuf[BLCKSZ];
-               OffsetNumber   *unused = (OffsetNumber*)unbuf;
-               char               *unend;
-               ItemId                  lp;
+               char            unbuf[BLCKSZ];
+               OffsetNumber *unused = (OffsetNumber *) unbuf;
+               char       *unend;
+               ItemId          lp;
 
-               memcpy(unbuf, (char*)xlrec + SizeOfHeapClean, record->xl_len - SizeOfHeapClean);
+               memcpy(unbuf, (char *) xlrec + SizeOfHeapClean, record->xl_len - SizeOfHeapClean);
                unend = unbuf + (record->xl_len - SizeOfHeapClean);
 
-               while((char*)unused < unend)
+               while ((char *) unused < unend)
                {
                        lp = ((PageHeader) page)->pd_linp + *unused;
                        lp->lp_flags &= ~LP_USED;
@@ -2289,13 +2293,13 @@ heap_xlog_clean(bool redo, XLogRecPtr lsn, XLogRecord *record)
 static void
 heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
 {
-       xl_heap_delete *xlrec = (xl_heap_delete*) XLogRecGetData(record);
-       Relation                reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
-       Buffer                  buffer;
-       Page                    page;
-       OffsetNumber    offnum;
-       ItemId                  lp = NULL;
-       HeapTupleHeader htup;
+       xl_heap_delete *xlrec = (xl_heap_delete *) XLogRecGetData(record);
+       Relation        reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
+       Buffer          buffer;
+       Page            page;
+       OffsetNumber offnum;
+       ItemId          lp = NULL;
+       HeapTupleHeader htup;
 
        if (redo && (record->xl_info & XLR_BKP_BLOCK_1))
                return;
@@ -2303,7 +2307,7 @@ heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
        if (!RelationIsValid(reln))
                return;
 
-       buffer = XLogReadBuffer(false, reln, 
+       buffer = XLogReadBuffer(false, reln,
                                                ItemPointerGetBlockNumber(&(xlrec->target.tid)));
        if (!BufferIsValid(buffer))
                elog(STOP, "heap_delete_%sdo: no block", (redo) ? "re" : "un");
@@ -2320,7 +2324,8 @@ heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
                        return;
                }
        }
-       else if (XLByteLT(PageGetLSN(page), lsn))       /* changes are not applied ?! */
+       else if (XLByteLT(PageGetLSN(page), lsn))       /* changes are not applied
+                                                                                                * ?! */
                elog(STOP, "heap_delete_undo: bad page LSN");
 
        offnum = ItemPointerGetOffsetNumber(&(xlrec->target.tid));
@@ -2337,7 +2342,7 @@ heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
                htup->t_xmax = record->xl_xid;
                htup->t_cmax = FirstCommandId;
                htup->t_infomask &= ~(HEAP_XMAX_COMMITTED |
-                                                               HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
+                                                         HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
                PageSetLSN(page, lsn);
                PageSetSUI(page, ThisStartUpID);
                UnlockAndWriteBuffer(buffer);
@@ -2350,12 +2355,12 @@ heap_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
 static void
 heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
 {
-       xl_heap_insert *xlrec = (xl_heap_insert*) XLogRecGetData(record);
-       Relation                reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
-       Buffer                  buffer;
-       Page                    page;
-       OffsetNumber    offnum;
-       HeapTupleHeader htup;
+       xl_heap_insert *xlrec = (xl_heap_insert *) XLogRecGetData(record);
+       Relation        reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
+       Buffer          buffer;
+       Page            page;
+       OffsetNumber offnum;
+       HeapTupleHeader htup;
 
        if (redo && (record->xl_info & XLR_BKP_BLOCK_1))
                return;
@@ -2363,7 +2368,7 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
        if (!RelationIsValid(reln))
                return;
 
-       buffer = XLogReadBuffer((redo) ? true : false, reln, 
+       buffer = XLogReadBuffer((redo) ? true : false, reln,
                                                ItemPointerGetBlockNumber(&(xlrec->target.tid)));
        if (!BufferIsValid(buffer))
                return;
@@ -2375,9 +2380,9 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
 
        if (redo)
        {
-               char                    tbuf[MaxTupleSize];
-               xl_heap_header  xlhdr;
-               uint32                  newlen;
+               char            tbuf[MaxTupleSize];
+               xl_heap_header xlhdr;
+               uint32          newlen;
 
                if (record->xl_info & XLOG_HEAP_INIT_PAGE)
                {
@@ -2396,9 +2401,9 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
                        elog(STOP, "heap_insert_redo: invalid max offset number");
 
                newlen = record->xl_len - SizeOfHeapInsert - SizeOfHeapHeader;
-               memcpy((char*)&xlhdr, (char*)xlrec + SizeOfHeapInsert, SizeOfHeapHeader);
-               memcpy(tbuf + offsetof(HeapTupleHeaderData, t_bits), 
-                       (char*)xlrec + SizeOfHeapInsert + SizeOfHeapHeader, newlen);
+               memcpy((char *) &xlhdr, (char *) xlrec + SizeOfHeapInsert, SizeOfHeapHeader);
+               memcpy(tbuf + offsetof(HeapTupleHeaderData, t_bits),
+                  (char *) xlrec + SizeOfHeapInsert + SizeOfHeapHeader, newlen);
                newlen += offsetof(HeapTupleHeaderData, t_bits);
                htup = (HeapTupleHeader) tbuf;
                htup->t_oid = xlhdr.t_oid;
@@ -2408,19 +2413,20 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
                htup->t_cmin = FirstCommandId;
                htup->t_xmax = htup->t_cmax = 0;
                htup->t_infomask = HEAP_XMAX_INVALID | xlhdr.mask;
-               
-               offnum = PageAddItem(page, (Item)htup, newlen, offnum, 
-                                                       LP_USED | OverwritePageMode);
+
+               offnum = PageAddItem(page, (Item) htup, newlen, offnum,
+                                                        LP_USED | OverwritePageMode);
                if (offnum == InvalidOffsetNumber)
                        elog(STOP, "heap_insert_redo: failed to add tuple");
                PageSetLSN(page, lsn);
-               PageSetSUI(page, ThisStartUpID);        /* prev sui */
+               PageSetSUI(page, ThisStartUpID);                /* prev sui */
                UnlockAndWriteBuffer(buffer);
                return;
        }
 
        /* undo insert */
-       if (XLByteLT(PageGetLSN(page), lsn))    /* changes are not applied ?! */
+       if (XLByteLT(PageGetLSN(page), lsn))            /* changes are not applied
+                                                                                                * ?! */
                elog(STOP, "heap_insert_undo: bad page LSN");
 
        elog(STOP, "heap_insert_undo: unimplemented");
@@ -2432,16 +2438,16 @@ heap_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
 static void
 heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
 {
-       xl_heap_update *xlrec = (xl_heap_update*) XLogRecGetData(record);
-       Relation                reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
-       Buffer                  buffer;
-       bool                    samepage = 
-               (ItemPointerGetBlockNumber(&(xlrec->newtid)) == 
-               ItemPointerGetBlockNumber(&(xlrec->target.tid)));
-       Page                    page;
-       OffsetNumber    offnum;
-       ItemId                  lp = NULL;
-       HeapTupleHeader htup;
+       xl_heap_update *xlrec = (xl_heap_update *) XLogRecGetData(record);
+       Relation        reln = XLogOpenRelation(redo, RM_HEAP_ID, xlrec->target.node);
+       Buffer          buffer;
+       bool            samepage =
+       (ItemPointerGetBlockNumber(&(xlrec->newtid)) ==
+        ItemPointerGetBlockNumber(&(xlrec->target.tid)));
+       Page            page;
+       OffsetNumber offnum;
+       ItemId          lp = NULL;
+       HeapTupleHeader htup;
 
        if (!RelationIsValid(reln))
                return;
@@ -2451,7 +2457,7 @@ heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
 
        /* Deal with old tuple version */
 
-       buffer = XLogReadBuffer(false, reln, 
+       buffer = XLogReadBuffer(false, reln,
                                                ItemPointerGetBlockNumber(&(xlrec->target.tid)));
        if (!BufferIsValid(buffer))
                elog(STOP, "heap_update_%sdo: no block", (redo) ? "re" : "un");
@@ -2470,7 +2476,8 @@ heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
                        goto newt;
                }
        }
-       else if (XLByteLT(PageGetLSN(page), lsn))       /* changes are not applied ?! */
+       else if (XLByteLT(PageGetLSN(page), lsn))       /* changes are not applied
+                                                                                                * ?! */
                elog(STOP, "heap_update_undo: bad old tuple page LSN");
 
        offnum = ItemPointerGetOffsetNumber(&(xlrec->target.tid));
@@ -2487,7 +2494,7 @@ heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
                if (move)
                {
                        TransactionIdStore(record->xl_xid, (TransactionId *) &(htup->t_cmin));
-                       htup->t_infomask &= 
+                       htup->t_infomask &=
                                ~(HEAP_XMIN_COMMITTED | HEAP_XMIN_INVALID | HEAP_MOVED_IN);
                        htup->t_infomask |= HEAP_MOVED_OFF;
                }
@@ -2496,7 +2503,7 @@ heap_xlog_update(bool redo, XLogRecPtr lsn, XLogRecord *record, bool move)
                        htup->t_xmax = record->xl_xid;
                        htup->t_cmax = FirstCommandId;
                        htup->t_infomask &= ~(HEAP_XMAX_COMMITTED |
-                                                               HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
+                                                        HEAP_XMAX_INVALID | HEAP_MARKED_FOR_UPDATE);
                }
                if (samepage)
                        goto newsame;
@@ -2514,11 +2521,11 @@ newt:;
 
        if (redo &&
                ((record->xl_info & XLR_BKP_BLOCK_2) ||
-               ((record->xl_info & XLR_BKP_BLOCK_1) && samepage)))
+                ((record->xl_info & XLR_BKP_BLOCK_1) && samepage)))
                return;
 
-       buffer = XLogReadBuffer((redo) ? true : false, reln, 
-                                       ItemPointerGetBlockNumber(&(xlrec->newtid)));
+       buffer = XLogReadBuffer((redo) ? true : false, reln,
+                                                       ItemPointerGetBlockNumber(&(xlrec->newtid)));
        if (!BufferIsValid(buffer))
                return;
 
@@ -2531,10 +2538,10 @@ newsame:;
 
        if (redo)
        {
-               char                    tbuf[MaxTupleSize];
-               xl_heap_header  xlhdr;
-               int                             hsize;
-               uint32                  newlen;
+               char            tbuf[MaxTupleSize];
+               xl_heap_header xlhdr;
+               int                     hsize;
+               uint32          newlen;
 
                if (record->xl_info & XLOG_HEAP_INIT_PAGE)
                {
@@ -2557,9 +2564,9 @@ newsame:;
                        hsize += (2 * sizeof(TransactionId));
 
                newlen = record->xl_len - hsize;
-               memcpy((char*)&xlhdr, (char*)xlrec + SizeOfHeapUpdate, SizeOfHeapHeader);
-               memcpy(tbuf + offsetof(HeapTupleHeaderData, t_bits), 
-                       (char*)xlrec + hsize, newlen);
+               memcpy((char *) &xlhdr, (char *) xlrec + SizeOfHeapUpdate, SizeOfHeapHeader);
+               memcpy(tbuf + offsetof(HeapTupleHeaderData, t_bits),
+                          (char *) xlrec + hsize, newlen);
                newlen += offsetof(HeapTupleHeaderData, t_bits);
                htup = (HeapTupleHeader) tbuf;
                htup->t_oid = xlhdr.t_oid;
@@ -2568,13 +2575,13 @@ newsame:;
                if (move)
                {
                        hsize = SizeOfHeapUpdate + SizeOfHeapHeader;
-                       memcpy(&(htup->t_xmax), (char*)xlrec + hsize, sizeof(TransactionId));
-                       memcpy(&(htup->t_xmin), 
-                               (char*)xlrec + hsize + sizeof(TransactionId), sizeof(TransactionId));
+                       memcpy(&(htup->t_xmax), (char *) xlrec + hsize, sizeof(TransactionId));
+                       memcpy(&(htup->t_xmin),
+                                  (char *) xlrec + hsize + sizeof(TransactionId), sizeof(TransactionId));
                        TransactionIdStore(record->xl_xid, (TransactionId *) &(htup->t_cmin));
                        htup->t_infomask = xlhdr.mask;
-                       htup->t_infomask &= ~(HEAP_XMIN_COMMITTED | 
-                                               HEAP_XMIN_INVALID | HEAP_MOVED_OFF);
+                       htup->t_infomask &= ~(HEAP_XMIN_COMMITTED |
+                                                                 HEAP_XMIN_INVALID | HEAP_MOVED_OFF);
                        htup->t_infomask |= HEAP_MOVED_IN;
                }
                else
@@ -2584,19 +2591,20 @@ newsame:;
                        htup->t_xmax = htup->t_cmax = 0;
                        htup->t_infomask = HEAP_XMAX_INVALID | xlhdr.mask;
                }
-               
-               offnum = PageAddItem(page, (Item)htup, newlen, offnum,
-                                                       LP_USED | OverwritePageMode);
+
+               offnum = PageAddItem(page, (Item) htup, newlen, offnum,
+                                                        LP_USED | OverwritePageMode);
                if (offnum == InvalidOffsetNumber)
                        elog(STOP, "heap_update_redo: failed to add tuple");
                PageSetLSN(page, lsn);
-               PageSetSUI(page, ThisStartUpID);        /* prev sui */
+               PageSetSUI(page, ThisStartUpID);                /* prev sui */
                UnlockAndWriteBuffer(buffer);
                return;
        }
 
        /* undo */
-       if (XLByteLT(PageGetLSN(page), lsn))    /* changes are not applied ?! */
+       if (XLByteLT(PageGetLSN(page), lsn))            /* changes are not applied
+                                                                                                * ?! */
                elog(STOP, "heap_update_undo: bad new tuple page LSN");
 
        elog(STOP, "heap_update_undo: unimplemented");
@@ -2606,19 +2614,19 @@ newsame:;
 static void
 _heap_unlock_tuple(void *data)
 {
-       xl_heaptid         *xltid = (xl_heaptid*) data;
-       Relation                reln = XLogOpenRelation(false, RM_HEAP_ID, xltid->node);
-       Buffer                  buffer;
-       Page                    page;
-       OffsetNumber    offnum;
-       ItemId                  lp;
-       HeapTupleHeader htup;
+       xl_heaptid *xltid = (xl_heaptid *) data;
+       Relation        reln = XLogOpenRelation(false, RM_HEAP_ID, xltid->node);
+       Buffer          buffer;
+       Page            page;
+       OffsetNumber offnum;
+       ItemId          lp;
+       HeapTupleHeader htup;
 
        if (!RelationIsValid(reln))
                elog(STOP, "_heap_unlock_tuple: can't open relation");
 
-       buffer = XLogReadBuffer(false, reln, 
-                                               ItemPointerGetBlockNumber(&(xltid->tid)));
+       buffer = XLogReadBuffer(false, reln,
+                                                       ItemPointerGetBlockNumber(&(xltid->tid)));
        if (!BufferIsValid(buffer))
                elog(STOP, "_heap_unlock_tuple: can't read buffer");
 
@@ -2636,8 +2644,8 @@ _heap_unlock_tuple(void *data)
 
        htup = (HeapTupleHeader) PageGetItem(page, lp);
 
-       if (htup->t_xmax != GetCurrentTransactionId() || 
-                       htup->t_cmax != GetCurrentCommandId())
+       if (htup->t_xmax != GetCurrentTransactionId() ||
+               htup->t_cmax != GetCurrentCommandId())
                elog(STOP, "_heap_unlock_tuple: invalid xmax/cmax in rollback");
        htup->t_infomask &= ~HEAP_XMAX_UNLOGGED;
        htup->t_infomask |= HEAP_XMAX_INVALID;
@@ -2645,9 +2653,10 @@ _heap_unlock_tuple(void *data)
        return;
 }
 
-void heap_redo(XLogRecPtr lsn, XLogRecord *record)
+void
+heap_redo(XLogRecPtr lsn, XLogRecord *record)
 {
-       uint8   info = record->xl_info & ~XLR_INFO_MASK;
+       uint8           info = record->xl_info & ~XLR_INFO_MASK;
 
        info &= XLOG_HEAP_OPMASK;
        if (info == XLOG_HEAP_INSERT)
@@ -2664,9 +2673,10 @@ void heap_redo(XLogRecPtr lsn, XLogRecord *record)
                elog(STOP, "heap_redo: unknown op code %u", info);
 }
 
-void heap_undo(XLogRecPtr lsn, XLogRecord *record)
+void
+heap_undo(XLogRecPtr lsn, XLogRecord *record)
 {
-       uint8   info = record->xl_info & ~XLR_INFO_MASK;
+       uint8           info = record->xl_info & ~XLR_INFO_MASK;
 
        info &= XLOG_HEAP_OPMASK;
        if (info == XLOG_HEAP_INSERT)
@@ -2687,46 +2697,50 @@ static void
 out_target(char *buf, xl_heaptid *target)
 {
        sprintf(buf + strlen(buf), "node %u/%u; tid %u/%u",
-               target->node.tblNode, target->node.relNode,
-               ItemPointerGetBlockNumber(&(target->tid)), 
-               ItemPointerGetOffsetNumber(&(target->tid)));
+                       target->node.tblNode, target->node.relNode,
+                       ItemPointerGetBlockNumber(&(target->tid)),
+                       ItemPointerGetOffsetNumber(&(target->tid)));
 }
+
 void
-heap_desc(char *buf, uint8 xl_info, charrec)
+heap_desc(char *buf, uint8 xl_info, char *rec)
 {
-       uint8   info = xl_info & ~XLR_INFO_MASK;
+       uint8           info = xl_info & ~XLR_INFO_MASK;
 
        info &= XLOG_HEAP_OPMASK;
        if (info == XLOG_HEAP_INSERT)
        {
-               xl_heap_insert  *xlrec = (xl_heap_insert*) rec;
+               xl_heap_insert *xlrec = (xl_heap_insert *) rec;
+
                strcat(buf, "insert: ");
                out_target(buf, &(xlrec->target));
        }
        else if (info == XLOG_HEAP_DELETE)
        {
-               xl_heap_delete  *xlrec = (xl_heap_delete*) rec;
+               xl_heap_delete *xlrec = (xl_heap_delete *) rec;
+
                strcat(buf, "delete: ");
                out_target(buf, &(xlrec->target));
        }
        else if (info == XLOG_HEAP_UPDATE || info == XLOG_HEAP_MOVE)
        {
-               xl_heap_update  *xlrec = (xl_heap_update*) rec;
+               xl_heap_update *xlrec = (xl_heap_update *) rec;
+
                if (info == XLOG_HEAP_UPDATE)
                        strcat(buf, "update: ");
                else
                        strcat(buf, "move: ");
                out_target(buf, &(xlrec->target));
                sprintf(buf + strlen(buf), "; new %u/%u",
-                       ItemPointerGetBlockNumber(&(xlrec->newtid)), 
-                       ItemPointerGetOffsetNumber(&(xlrec->newtid)));
+                               ItemPointerGetBlockNumber(&(xlrec->newtid)),
+                               ItemPointerGetOffsetNumber(&(xlrec->newtid)));
        }
        else if (info == XLOG_HEAP_CLEAN)
        {
-               xl_heap_clean   *xlrec = (xl_heap_clean*) rec;
+               xl_heap_clean *xlrec = (xl_heap_clean *) rec;
+
                sprintf(buf + strlen(buf), "clean: node %u/%u; blk %u",
-                       xlrec->node.tblNode, xlrec->node.relNode, xlrec->block);
+                               xlrec->node.tblNode, xlrec->node.relNode, xlrec->block);
        }
        else
                strcat(buf, "UNKNOWN");
index 64e7262e86889525ad104df3194df81173ad5d0c..94dedbf87b90fce87f3db64c27a22c61bb8ac659 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Id: hio.c,v 1.35 2001/01/24 19:42:48 momjian Exp $
+ *       $Id: hio.c,v 1.36 2001/03/22 03:59:13 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -19,7 +19,7 @@
 #include "access/hio.h"
 
 /*
- * RelationPutHeapTuple        - place tuple at specified page
+ * RelationPutHeapTuple - place tuple at specified page
  *
  * !!! ELOG(ERROR) IS DISALLOWED HERE !!!
  *
@@ -69,7 +69,7 @@ RelationPutHeapTuple(Relation relation,
  *
  * Returns (locked) buffer with free space >= given len.
  *
- * Note that we use LockPage to lock relation for extension. We can 
+ * Note that we use LockPage to lock relation for extension. We can
  * do this as long as in all other places we use page-level locking
  * for indices only. Alternatively, we could define pseudo-table as
  * we do for transactions with XactLockTable.
@@ -92,7 +92,7 @@ RelationGetBufferForTuple(Relation relation, Size len)
         */
        if (len > MaxTupleSize)
                elog(ERROR, "Tuple is too big: size %lu, max size %ld",
-                        (unsigned long)len, MaxTupleSize);
+                        (unsigned long) len, MaxTupleSize);
 
        if (!relation->rd_myxactonly)
                LockPage(relation, 0, ExclusiveLock);
@@ -140,13 +140,13 @@ RelationGetBufferForTuple(Relation relation, Size len)
                {
                        /* We should not get here given the test at the top */
                        elog(STOP, "Tuple is too big: size %lu",
-                               (unsigned long)len);
+                                (unsigned long) len);
                }
        }
 
        if (!relation->rd_myxactonly)
                UnlockPage(relation, 0, ExclusiveLock);
 
-       return(buffer);
+       return (buffer);
 
 }
index a3cf6ae7116a7e4dc11eb40752e1dfe74efc9c9f..d0e60681e7793cd424a6abfbf762afa00b7dc819 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.17 2001/02/15 20:57:01 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/heap/tuptoaster.c,v 1.18 2001/03/22 03:59:13 momjian Exp $
  *
  *
  * INTERFACE ROUTINES
 
 #undef TOAST_DEBUG
 
-static void                    toast_delete(Relation rel, HeapTuple oldtup);
-static void                    toast_delete_datum(Relation rel, Datum value);
-static void                    toast_insert_or_update(Relation rel, HeapTuple newtup,
-                                                               HeapTuple oldtup);
-static Datum           toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value);
-static varattrib   *toast_fetch_datum(varattrib *attr);
+static void toast_delete(Relation rel, HeapTuple oldtup);
+static void toast_delete_datum(Relation rel, Datum value);
+static void toast_insert_or_update(Relation rel, HeapTuple newtup,
+                                          HeapTuple oldtup);
+static Datum toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value);
+static varattrib *toast_fetch_datum(varattrib *attr);
 
 
 /* ----------
@@ -70,14 +70,14 @@ heap_tuple_toast_attrs(Relation rel, HeapTuple newtup, HeapTuple oldtup)
 /* ----------
  * heap_tuple_fetch_attr -
  *
- *     Public entry point to get back a toasted value 
+ *     Public entry point to get back a toasted value
  *     external storage (possibly still in compressed format).
  * ----------
  */
-varattrib *
+varattrib  *
 heap_tuple_fetch_attr(varattrib *attr)
 {
-       varattrib       *result;
+       varattrib  *result;
 
        if (VARATT_IS_EXTERNAL(attr))
        {
@@ -94,7 +94,7 @@ heap_tuple_fetch_attr(varattrib *attr)
                 * ----------
                 */
                result = attr;
-    }
+       }
 
        return result;
 }
@@ -107,10 +107,10 @@ heap_tuple_fetch_attr(varattrib *attr)
  *     or external storage.
  * ----------
  */
-varattrib *
+varattrib  *
 heap_tuple_untoast_attr(varattrib *attr)
 {
-       varattrib       *result;
+       varattrib  *result;
 
        if (VARATT_IS_EXTERNAL(attr))
        {
@@ -121,14 +121,14 @@ heap_tuple_untoast_attr(varattrib *attr)
                         * Fetch it from the toast heap and decompress.
                         * ----------
                         */
-                       varattrib *tmp;
+                       varattrib  *tmp;
 
                        tmp = toast_fetch_datum(attr);
-                       result = (varattrib *)palloc(attr->va_content.va_external.va_rawsize
-                                                               + VARHDRSZ);
+                       result = (varattrib *) palloc(attr->va_content.va_external.va_rawsize
+                                                                                 + VARHDRSZ);
                        VARATT_SIZEP(result) = attr->va_content.va_external.va_rawsize
-                                                               + VARHDRSZ;
-                       pglz_decompress((PGLZ_Header *)tmp, VARATT_DATA(result));
+                               + VARHDRSZ;
+                       pglz_decompress((PGLZ_Header *) tmp, VARATT_DATA(result));
 
                        pfree(tmp);
                }
@@ -147,11 +147,11 @@ heap_tuple_untoast_attr(varattrib *attr)
                 * This is a compressed value inside of the main tuple
                 * ----------
                 */
-               result = (varattrib *)palloc(attr->va_content.va_compressed.va_rawsize
-                                                       + VARHDRSZ);
+               result = (varattrib *) palloc(attr->va_content.va_compressed.va_rawsize
+                                                                         + VARHDRSZ);
                VARATT_SIZEP(result) = attr->va_content.va_compressed.va_rawsize
-                                                       + VARHDRSZ;
-               pglz_decompress((PGLZ_Header *)attr, VARATT_DATA(result));
+                       + VARHDRSZ;
+               pglz_decompress((PGLZ_Header *) attr, VARATT_DATA(result));
        }
        else
                /* ----------
@@ -173,21 +173,21 @@ heap_tuple_untoast_attr(varattrib *attr)
 static void
 toast_delete(Relation rel, HeapTuple oldtup)
 {
-       TupleDesc                       tupleDesc;
-       Form_pg_attribute  *att;
-       int                                     numAttrs;
-       int                                     i;
-       Datum                           value;
-       bool                            isnull;
+       TupleDesc       tupleDesc;
+       Form_pg_attribute *att;
+       int                     numAttrs;
+       int                     i;
+       Datum           value;
+       bool            isnull;
 
        /* ----------
         * Get the tuple descriptor, the number of and attribute
         * descriptors.
         * ----------
         */
-       tupleDesc       = rel->rd_att;
-       numAttrs        = tupleDesc->natts;
-       att                     = tupleDesc->attrs;
+       tupleDesc = rel->rd_att;
+       numAttrs = tupleDesc->natts;
+       att = tupleDesc->attrs;
 
        /* ----------
         * Check for external stored attributes and delete them
@@ -216,35 +216,35 @@ toast_delete(Relation rel, HeapTuple oldtup)
 static void
 toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
 {
-       TupleDesc                       tupleDesc;
-       Form_pg_attribute  *att;
-       int                                     numAttrs;
-       int                                     i;
-       bool                            old_isnull;
-       bool                            new_isnull;
-
-       bool                            need_change = false;
-       bool                            need_free   = false;
-       bool                            need_delold = false;
-       bool                            has_nulls   = false;
-
-       Size                            maxDataLen;
-
-       char                            toast_action[MaxHeapAttributeNumber];
-       char                            toast_nulls[MaxHeapAttributeNumber];
-       Datum                           toast_values[MaxHeapAttributeNumber];
-       int32                           toast_sizes[MaxHeapAttributeNumber];
-       bool                            toast_free[MaxHeapAttributeNumber];
-       bool                            toast_delold[MaxHeapAttributeNumber];
+       TupleDesc       tupleDesc;
+       Form_pg_attribute *att;
+       int                     numAttrs;
+       int                     i;
+       bool            old_isnull;
+       bool            new_isnull;
+
+       bool            need_change = false;
+       bool            need_free = false;
+       bool            need_delold = false;
+       bool            has_nulls = false;
+
+       Size            maxDataLen;
+
+       char            toast_action[MaxHeapAttributeNumber];
+       char            toast_nulls[MaxHeapAttributeNumber];
+       Datum           toast_values[MaxHeapAttributeNumber];
+       int32           toast_sizes[MaxHeapAttributeNumber];
+       bool            toast_free[MaxHeapAttributeNumber];
+       bool            toast_delold[MaxHeapAttributeNumber];
 
        /* ----------
         * Get the tuple descriptor, the number of and attribute
         * descriptors and the location of the tuple values.
         * ----------
         */
-       tupleDesc       = rel->rd_att;
-       numAttrs        = tupleDesc->natts;
-       att                     = tupleDesc->attrs;
+       tupleDesc = rel->rd_att;
+       numAttrs = tupleDesc->natts;
+       att = tupleDesc->attrs;
 
        /* ----------
         * Then collect information about the values given
@@ -255,14 +255,14 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
         *              'x'             incompressible, but OK to move off
         * ----------
         */
-       memset(toast_action,    ' ', numAttrs * sizeof(char));
-       memset(toast_nulls,     ' ', numAttrs * sizeof(char));
-       memset(toast_free,      0,   numAttrs * sizeof(bool));
-       memset(toast_delold,    0,   numAttrs * sizeof(bool));
+       memset(toast_action, ' ', numAttrs * sizeof(char));
+       memset(toast_nulls, ' ', numAttrs * sizeof(char));
+       memset(toast_free, 0, numAttrs * sizeof(bool));
+       memset(toast_delold, 0, numAttrs * sizeof(bool));
        for (i = 0; i < numAttrs; i++)
        {
-               varattrib          *old_value;
-               varattrib          *new_value;
+               varattrib  *old_value;
+               varattrib  *new_value;
 
                if (oldtup != NULL)
                {
@@ -270,25 +270,25 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                         * For UPDATE get the old and new values of this attribute
                         * ----------
                         */
-                       old_value = (varattrib *)DatumGetPointer(
-                                               heap_getattr(oldtup, i + 1, tupleDesc, &old_isnull));
-                       toast_values[i] = 
-                                               heap_getattr(newtup, i + 1, tupleDesc, &new_isnull);
-                       new_value = (varattrib *)DatumGetPointer(toast_values[i]);
+                       old_value = (varattrib *) DatumGetPointer(
+                                       heap_getattr(oldtup, i + 1, tupleDesc, &old_isnull));
+                       toast_values[i] =
+                               heap_getattr(newtup, i + 1, tupleDesc, &new_isnull);
+                       new_value = (varattrib *) DatumGetPointer(toast_values[i]);
 
                        /* ----------
                         * If the old value is an external stored one, check if it
                         * has changed so we have to delete it later.
                         * ----------
                         */
-                       if (!old_isnull && att[i]->attlen == -1 && 
-                                               VARATT_IS_EXTERNAL(old_value))
+                       if (!old_isnull && att[i]->attlen == -1 &&
+                               VARATT_IS_EXTERNAL(old_value))
                        {
                                if (new_isnull || !VARATT_IS_EXTERNAL(new_value) ||
-                                               old_value->va_content.va_external.va_rowid !=
-                                               new_value->va_content.va_external.va_rowid ||
-                                               old_value->va_content.va_external.va_attno !=
-                                               new_value->va_content.va_external.va_attno)
+                                       old_value->va_content.va_external.va_rowid !=
+                                       new_value->va_content.va_external.va_rowid ||
+                                       old_value->va_content.va_external.va_attno !=
+                                       new_value->va_content.va_external.va_attno)
                                {
                                        /* ----------
                                         * The old external store value isn't needed any
@@ -318,8 +318,8 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                         * For INSERT simply get the new value
                         * ----------
                         */
-                       toast_values[i] = 
-                                               heap_getattr(newtup, i + 1, tupleDesc, &new_isnull);
+                       toast_values[i] =
+                               heap_getattr(newtup, i + 1, tupleDesc, &new_isnull);
                }
 
                /* ----------
@@ -356,7 +356,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                        if (VARATT_IS_EXTERNAL(DatumGetPointer(toast_values[i])))
                        {
                                toast_values[i] = PointerGetDatum(heap_tuple_untoast_attr(
-                                       (varattrib *)DatumGetPointer(toast_values[i])));
+                                               (varattrib *) DatumGetPointer(toast_values[i])));
                                toast_free[i] = true;
                                need_change = true;
                                need_free = true;
@@ -366,7 +366,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                         * Remember the size of this attribute
                         * ----------
                         */
-                       toast_sizes[i]  = VARATT_SIZE(DatumGetPointer(toast_values[i]));
+                       toast_sizes[i] = VARATT_SIZE(DatumGetPointer(toast_values[i]));
                }
                else
                {
@@ -375,7 +375,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                         * ----------
                         */
                        toast_action[i] = 'p';
-                       toast_sizes[i]  = att[i]->attlen;
+                       toast_sizes[i] = att[i]->attlen;
                }
        }
 
@@ -384,7 +384,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
         *
         *      1: Inline compress attributes with attstorage 'x'
         *      2: Store attributes with attstorage 'x' or 'e' external
-        *  3: Inline compress attributes with attstorage 'm'
+        *      3: Inline compress attributes with attstorage 'm'
         *      4: Store attributes with attstorage 'm' external
         * ----------
         */
@@ -398,12 +398,12 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
         * ----------
         */
        while (MAXALIGN(ComputeDataSize(tupleDesc, toast_values, toast_nulls)) >
-                               maxDataLen)
+                  maxDataLen)
        {
-               int             biggest_attno = -1;
-               int32   biggest_size  = MAXALIGN(sizeof(varattrib));
-               Datum   old_value;
-               Datum   new_value;
+               int                     biggest_attno = -1;
+               int32           biggest_size = MAXALIGN(sizeof(varattrib));
+               Datum           old_value;
+               Datum           new_value;
 
                /* ----------
                 * Search for the biggest yet uncompressed internal attribute
@@ -420,7 +420,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                        if (toast_sizes[i] > biggest_size)
                        {
                                biggest_attno = i;
-                               biggest_size  = toast_sizes[i];
+                               biggest_size = toast_sizes[i];
                        }
                }
 
@@ -431,24 +431,28 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                 * Attempt to compress it inline
                 * ----------
                 */
-               i                                       = biggest_attno;
-               old_value                       = toast_values[i];
-               new_value                       = toast_compress_datum(old_value);
+               i = biggest_attno;
+               old_value = toast_values[i];
+               new_value = toast_compress_datum(old_value);
 
                if (DatumGetPointer(new_value) != NULL)
                {
                        /* successful compression */
                        if (toast_free[i])
                                pfree(DatumGetPointer(old_value));
-                       toast_values[i] = new_value;
-                       toast_free[i]   = true;
-                       toast_sizes[i]  = VARATT_SIZE(toast_values[i]);
-                       need_change             = true;
-                       need_free               = true;
+                       toast_values[i] = new_value;
+                       toast_free[i] = true;
+                       toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+                       need_change = true;
+                       need_free = true;
                }
                else
                {
-                       /* incompressible data, ignore on subsequent compression passes */
+
+                       /*
+                        * incompressible data, ignore on subsequent compression
+                        * passes
+                        */
                        toast_action[i] = 'x';
                }
        }
@@ -459,11 +463,11 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
         * ----------
         */
        while (MAXALIGN(ComputeDataSize(tupleDesc, toast_values, toast_nulls)) >
-                               maxDataLen && rel->rd_rel->reltoastrelid != InvalidOid)
+                  maxDataLen && rel->rd_rel->reltoastrelid != InvalidOid)
        {
-               int             biggest_attno = -1;
-               int32   biggest_size  = MAXALIGN(sizeof(varattrib));
-               Datum   old_value;
+               int                     biggest_attno = -1;
+               int32           biggest_size = MAXALIGN(sizeof(varattrib));
+               Datum           old_value;
 
                /* ----------
                 * Search for the biggest yet inlined attribute with
@@ -481,7 +485,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                        if (toast_sizes[i] > biggest_size)
                        {
                                biggest_attno = i;
-                               biggest_size  = toast_sizes[i];
+                               biggest_size = toast_sizes[i];
                        }
                }
 
@@ -492,21 +496,21 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                 * Store this external
                 * ----------
                 */
-               i                                       = biggest_attno;
-               old_value                       = toast_values[i];
-               toast_action[i]         = 'p';
-               toast_values[i]         = toast_save_datum(rel,
-                                                                       newtup->t_data->t_oid,
-                                                                       i + 1,
-                                                                       toast_values[i]);
+               i = biggest_attno;
+               old_value = toast_values[i];
+               toast_action[i] = 'p';
+               toast_values[i] = toast_save_datum(rel,
+                                                                                  newtup->t_data->t_oid,
+                                                                                  i + 1,
+                                                                                  toast_values[i]);
                if (toast_free[i])
                        pfree(DatumGetPointer(old_value));
 
-               toast_free[i]           = true;
-               toast_sizes[i]          = VARATT_SIZE(toast_values[i]);
+               toast_free[i] = true;
+               toast_sizes[i] = VARATT_SIZE(toast_values[i]);
 
                need_change = true;
-               need_free   = true;
+               need_free = true;
        }
 
        /* ----------
@@ -515,12 +519,12 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
         * ----------
         */
        while (MAXALIGN(ComputeDataSize(tupleDesc, toast_values, toast_nulls)) >
-                               maxDataLen)
+                  maxDataLen)
        {
-               int             biggest_attno = -1;
-               int32   biggest_size  = MAXALIGN(sizeof(varattrib));
-               Datum   old_value;
-               Datum   new_value;
+               int                     biggest_attno = -1;
+               int32           biggest_size = MAXALIGN(sizeof(varattrib));
+               Datum           old_value;
+               Datum           new_value;
 
                /* ----------
                 * Search for the biggest yet uncompressed internal attribute
@@ -537,7 +541,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                        if (toast_sizes[i] > biggest_size)
                        {
                                biggest_attno = i;
-                               biggest_size  = toast_sizes[i];
+                               biggest_size = toast_sizes[i];
                        }
                }
 
@@ -548,24 +552,28 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                 * Attempt to compress it inline
                 * ----------
                 */
-               i                                       = biggest_attno;
-               old_value                       = toast_values[i];
-               new_value                       = toast_compress_datum(old_value);
+               i = biggest_attno;
+               old_value = toast_values[i];
+               new_value = toast_compress_datum(old_value);
 
                if (DatumGetPointer(new_value) != NULL)
                {
                        /* successful compression */
                        if (toast_free[i])
                                pfree(DatumGetPointer(old_value));
-                       toast_values[i] = new_value;
-                       toast_free[i]   = true;
-                       toast_sizes[i]  = VARATT_SIZE(toast_values[i]);
-                       need_change             = true;
-                       need_free               = true;
+                       toast_values[i] = new_value;
+                       toast_free[i] = true;
+                       toast_sizes[i] = VARATT_SIZE(toast_values[i]);
+                       need_change = true;
+                       need_free = true;
                }
                else
                {
-                       /* incompressible data, ignore on subsequent compression passes */
+
+                       /*
+                        * incompressible data, ignore on subsequent compression
+                        * passes
+                        */
                        toast_action[i] = 'x';
                }
        }
@@ -575,11 +583,11 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
         * ----------
         */
        while (MAXALIGN(ComputeDataSize(tupleDesc, toast_values, toast_nulls)) >
-                               maxDataLen && rel->rd_rel->reltoastrelid != InvalidOid)
+                  maxDataLen && rel->rd_rel->reltoastrelid != InvalidOid)
        {
-               int             biggest_attno = -1;
-               int32   biggest_size  = MAXALIGN(sizeof(varattrib));
-               Datum   old_value;
+               int                     biggest_attno = -1;
+               int32           biggest_size = MAXALIGN(sizeof(varattrib));
+               Datum           old_value;
 
                /* ----------
                 * Search for the biggest yet inlined attribute with
@@ -597,7 +605,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                        if (toast_sizes[i] > biggest_size)
                        {
                                biggest_attno = i;
-                               biggest_size  = toast_sizes[i];
+                               biggest_size = toast_sizes[i];
                        }
                }
 
@@ -608,21 +616,21 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                 * Store this external
                 * ----------
                 */
-               i                                       = biggest_attno;
-               old_value                       = toast_values[i];
-               toast_action[i]         = 'p';
-               toast_values[i]         = toast_save_datum(rel,
-                                                                       newtup->t_data->t_oid,
-                                                                       i + 1,
-                                                                       toast_values[i]);
+               i = biggest_attno;
+               old_value = toast_values[i];
+               toast_action[i] = 'p';
+               toast_values[i] = toast_save_datum(rel,
+                                                                                  newtup->t_data->t_oid,
+                                                                                  i + 1,
+                                                                                  toast_values[i]);
                if (toast_free[i])
                        pfree(DatumGetPointer(old_value));
 
-               toast_free[i]           = true;
-               toast_sizes[i]          = VARATT_SIZE(toast_values[i]);
+               toast_free[i] = true;
+               toast_sizes[i] = VARATT_SIZE(toast_values[i]);
 
                need_change = true;
-               need_free   = true;
+               need_free = true;
        }
 
        /* ----------
@@ -632,10 +640,10 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
         */
        if (need_change)
        {
-               char               *new_data;
-               int32                   new_len;
-               MemoryContext   oldcxt;
-               HeapTupleHeader olddata;
+               char       *new_data;
+               int32           new_len;
+               MemoryContext oldcxt;
+               HeapTupleHeader olddata;
 
                /* ----------
                 * Calculate the new size of the tuple
@@ -662,24 +670,24 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
                 * ----------
                 */
                memcpy(new_data, newtup->t_data, newtup->t_data->t_hoff);
-               newtup->t_data = (HeapTupleHeader)new_data;
+               newtup->t_data = (HeapTupleHeader) new_data;
                newtup->t_len = new_len;
 
-               DataFill((char *)(MAXALIGN((long)new_data +
-                                               offsetof(HeapTupleHeaderData, t_bits) + 
-                                               ((has_nulls) ? BITMAPLEN(numAttrs) : 0))),
-                               tupleDesc,
-                               toast_values,
-                               toast_nulls,
-                               &(newtup->t_data->t_infomask),
-                               has_nulls ? newtup->t_data->t_bits : NULL);
+               DataFill((char *) (MAXALIGN((long) new_data +
+                                                                 offsetof(HeapTupleHeaderData, t_bits) +
+                                                          ((has_nulls) ? BITMAPLEN(numAttrs) : 0))),
+                                tupleDesc,
+                                toast_values,
+                                toast_nulls,
+                                &(newtup->t_data->t_infomask),
+                                has_nulls ? newtup->t_data->t_bits : NULL);
 
                /* ----------
                 * In the case we modified a previously modified tuple again,
                 * free the memory from the previous run
                 * ----------
                 */
-               if ((char *)olddata != ((char *)newtup + HEAPTUPLESIZE))
+               if ((char *) olddata != ((char *) newtup + HEAPTUPLESIZE))
                        pfree(olddata);
 
                /* ----------
@@ -723,7 +731,7 @@ toast_insert_or_update(Relation rel, HeapTuple newtup, HeapTuple oldtup)
 Datum
 toast_compress_datum(Datum value)
 {
-       varattrib          *tmp;
+       varattrib  *tmp;
 
        tmp = (varattrib *) palloc(sizeof(PGLZ_Header) + VARATT_SIZE(value));
        pglz_compress(VARATT_DATA(value), VARATT_SIZE(value) - VARHDRSZ,
@@ -754,45 +762,45 @@ toast_compress_datum(Datum value)
 static Datum
 toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
 {
-       Relation                        toastrel;
-       Relation                        toastidx;
-       HeapTuple                       toasttup;
-       InsertIndexResult       idxres;
-       TupleDesc                       toasttupDesc;
-       Datum                           t_values[3];
-       char                            t_nulls[3];
-       varattrib                  *result;
-       char                            chunk_data[VARHDRSZ + TOAST_MAX_CHUNK_SIZE];
-       int32                           chunk_size;
-       int32                           chunk_seq = 0;
-       char                       *data_p;
-       int32                           data_todo;
+       Relation        toastrel;
+       Relation        toastidx;
+       HeapTuple       toasttup;
+       InsertIndexResult idxres;
+       TupleDesc       toasttupDesc;
+       Datum           t_values[3];
+       char            t_nulls[3];
+       varattrib  *result;
+       char            chunk_data[VARHDRSZ + TOAST_MAX_CHUNK_SIZE];
+       int32           chunk_size;
+       int32           chunk_seq = 0;
+       char       *data_p;
+       int32           data_todo;
 
        /* ----------
         * Create the varattrib reference
         * ----------
         */
-       result = (varattrib *)palloc(sizeof(varattrib));
+       result = (varattrib *) palloc(sizeof(varattrib));
 
-       result->va_header       = sizeof(varattrib) | VARATT_FLAG_EXTERNAL;
+       result->va_header = sizeof(varattrib) | VARATT_FLAG_EXTERNAL;
        if (VARATT_IS_COMPRESSED(value))
        {
                result->va_header |= VARATT_FLAG_COMPRESSED;
-               result->va_content.va_external.va_rawsize = 
-                                       ((varattrib *)value)->va_content.va_compressed.va_rawsize;
+               result->va_content.va_external.va_rawsize =
+                       ((varattrib *) value)->va_content.va_compressed.va_rawsize;
        }
        else
                result->va_content.va_external.va_rawsize = VARATT_SIZE(value);
-                                       
-       result->va_content.va_external.va_extsize               = 
-                                       VARATT_SIZE(value) - VARHDRSZ;
-       result->va_content.va_external.va_valueid               = newoid();
-       result->va_content.va_external.va_toastrelid    = 
-                                       rel->rd_rel->reltoastrelid;
-       result->va_content.va_external.va_toastidxid    = 
-                                       rel->rd_rel->reltoastidxid;
-       result->va_content.va_external.va_rowid                 = mainoid;
-       result->va_content.va_external.va_attno                 = attno;
+
+       result->va_content.va_external.va_extsize =
+               VARATT_SIZE(value) - VARHDRSZ;
+       result->va_content.va_external.va_valueid = newoid();
+       result->va_content.va_external.va_toastrelid =
+               rel->rd_rel->reltoastrelid;
+       result->va_content.va_external.va_toastidxid =
+               rel->rd_rel->reltoastidxid;
+       result->va_content.va_external.va_rowid = mainoid;
+       result->va_content.va_external.va_attno = attno;
 
        /* ----------
         * Initialize constant parts of the tuple data
@@ -808,8 +816,8 @@ toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
         * Get the data to process
         * ----------
         */
-       data_p          = VARATT_DATA(value);
-       data_todo       = VARATT_SIZE(value) - VARHDRSZ;
+       data_p = VARATT_DATA(value);
+       data_todo = VARATT_SIZE(value) - VARHDRSZ;
 
        /* ----------
         * Open the toast relation
@@ -818,9 +826,9 @@ toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
        toastrel = heap_open(rel->rd_rel->reltoastrelid, RowExclusiveLock);
        toasttupDesc = toastrel->rd_att;
        toastidx = index_open(rel->rd_rel->reltoastidxid);
-       
+
        /* ----------
-        * Split up the item into chunks 
+        * Split up the item into chunks
         * ----------
         */
        while (data_todo > 0)
@@ -848,8 +856,8 @@ toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
                 */
                heap_insert(toastrel, toasttup);
                idxres = index_insert(toastidx, t_values, t_nulls,
-                                               &(toasttup->t_self),
-                                               toastrel);
+                                                         &(toasttup->t_self),
+                                                         toastrel);
                if (idxres == NULL)
                        elog(ERROR, "Failed to insert index entry for TOAST tuple");
 
@@ -888,14 +896,14 @@ toast_save_datum(Relation rel, Oid mainoid, int16 attno, Datum value)
 static void
 toast_delete_datum(Relation rel, Datum value)
 {
-       register varattrib         *attr = (varattrib *)value;
-       Relation                                toastrel;
-       Relation                                toastidx;
-       ScanKeyData                             toastkey;
-       IndexScanDesc                   toastscan;
-       HeapTupleData                   toasttup;
-       RetrieveIndexResult             indexRes;
-       Buffer                                  buffer;
+       register varattrib *attr = (varattrib *) value;
+       Relation        toastrel;
+       Relation        toastidx;
+       ScanKeyData toastkey;
+       IndexScanDesc toastscan;
+       HeapTupleData toasttup;
+       RetrieveIndexResult indexRes;
+       Buffer          buffer;
 
        if (!VARATT_IS_EXTERNAL(attr))
                return;
@@ -904,8 +912,8 @@ toast_delete_datum(Relation rel, Datum value)
         * Open the toast relation and it's index
         * ----------
         */
-       toastrel        = heap_open(attr->va_content.va_external.va_toastrelid,
-                                       RowExclusiveLock);
+       toastrel = heap_open(attr->va_content.va_external.va_toastrelid,
+                                                RowExclusiveLock);
        toastidx = index_open(attr->va_content.va_external.va_toastidxid);
 
        /* ----------
@@ -913,10 +921,10 @@ toast_delete_datum(Relation rel, Datum value)
         * ----------
         */
        ScanKeyEntryInitialize(&toastkey,
-                                       (bits16) 0, 
-                                       (AttrNumber) 1, 
-                                       (RegProcedure) F_OIDEQ, 
-                                       ObjectIdGetDatum(attr->va_content.va_external.va_valueid));
+                                                  (bits16) 0,
+                                                  (AttrNumber) 1,
+                                                  (RegProcedure) F_OIDEQ,
+                         ObjectIdGetDatum(attr->va_content.va_external.va_valueid));
 
        /* ----------
         * Read the chunks by index
@@ -961,36 +969,36 @@ toast_delete_datum(Relation rel, Datum value)
 static varattrib *
 toast_fetch_datum(varattrib *attr)
 {
-       Relation                                toastrel;
-       Relation                                toastidx;
-       ScanKeyData                             toastkey;
-       IndexScanDesc                   toastscan;
-       HeapTupleData                   toasttup;
-       HeapTuple                               ttup;
-       TupleDesc                               toasttupDesc;
-       RetrieveIndexResult             indexRes;
-       Buffer                                  buffer;
-
-       varattrib                          *result;
-       int32                                   ressize;
-       int32                                   residx;
-       int                                             numchunks;
-       Pointer                                 chunk;
-       bool                                    isnull;
-       int32                                   chunksize;
-
-       char                               *chunks_found;
-       char                               *chunks_expected;
+       Relation        toastrel;
+       Relation        toastidx;
+       ScanKeyData toastkey;
+       IndexScanDesc toastscan;
+       HeapTupleData toasttup;
+       HeapTuple       ttup;
+       TupleDesc       toasttupDesc;
+       RetrieveIndexResult indexRes;
+       Buffer          buffer;
+
+       varattrib  *result;
+       int32           ressize;
+       int32           residx;
+       int                     numchunks;
+       Pointer         chunk;
+       bool            isnull;
+       int32           chunksize;
+
+       char       *chunks_found;
+       char       *chunks_expected;
 
        ressize = attr->va_content.va_external.va_extsize;
-    numchunks = ((ressize - 1) / TOAST_MAX_CHUNK_SIZE) + 1;
+       numchunks = ((ressize - 1) / TOAST_MAX_CHUNK_SIZE) + 1;
 
-       chunks_found    = palloc(numchunks);
+       chunks_found = palloc(numchunks);
        chunks_expected = palloc(numchunks);
-       memset(chunks_found,    0, numchunks);
+       memset(chunks_found, 0, numchunks);
        memset(chunks_expected, 1, numchunks);
 
-       result = (varattrib *)palloc(ressize + VARHDRSZ);
+       result = (varattrib *) palloc(ressize + VARHDRSZ);
        VARATT_SIZEP(result) = ressize + VARHDRSZ;
        if (VARATT_IS_COMPRESSED(attr))
                VARATT_SIZEP(result) |= VARATT_FLAG_COMPRESSED;
@@ -999,8 +1007,8 @@ toast_fetch_datum(varattrib *attr)
         * Open the toast relation and it's index
         * ----------
         */
-       toastrel        = heap_open(attr->va_content.va_external.va_toastrelid,
-                                       AccessShareLock);
+       toastrel = heap_open(attr->va_content.va_external.va_toastrelid,
+                                                AccessShareLock);
        toasttupDesc = toastrel->rd_att;
        toastidx = index_open(attr->va_content.va_external.va_toastidxid);
 
@@ -1009,10 +1017,10 @@ toast_fetch_datum(varattrib *attr)
         * ----------
         */
        ScanKeyEntryInitialize(&toastkey,
-                                       (bits16) 0, 
-                                       (AttrNumber) 1, 
-                                       (RegProcedure) F_OIDEQ, 
-                                       ObjectIdGetDatum(attr->va_content.va_external.va_valueid));
+                                                  (bits16) 0,
+                                                  (AttrNumber) 1,
+                                                  (RegProcedure) F_OIDEQ,
+                         ObjectIdGetDatum(attr->va_content.va_external.va_valueid));
 
        /* ----------
         * Read the chunks by index
@@ -1049,7 +1057,7 @@ toast_fetch_datum(varattrib *attr)
                        elog(ERROR, "unexpected chunk number %d for toast value %d",
                                 residx,
                                 attr->va_content.va_external.va_valueid);
-               if (residx < numchunks-1)
+               if (residx < numchunks - 1)
                {
                        if (chunksize != TOAST_MAX_CHUNK_SIZE)
                                elog(ERROR, "unexpected chunk size %d in chunk %d for toast value %d",
@@ -1072,7 +1080,7 @@ toast_fetch_datum(varattrib *attr)
                 * Copy the data into proper place in our result
                 * ----------
                 */
-               memcpy(((char *)VARATT_DATA(result)) + residx * TOAST_MAX_CHUNK_SIZE,
+               memcpy(((char *) VARATT_DATA(result)) + residx * TOAST_MAX_CHUNK_SIZE,
                           VARATT_DATA(chunk),
                           chunksize);
 
@@ -1085,7 +1093,7 @@ toast_fetch_datum(varattrib *attr)
         */
        if (memcmp(chunks_found, chunks_expected, numchunks) != 0)
                elog(ERROR, "not all toast chunks found for value %d",
-                                               attr->va_content.va_external.va_valueid);
+                        attr->va_content.va_external.va_valueid);
        pfree(chunks_expected);
        pfree(chunks_found);
 
index 1cc2c42c01c38cdd464e90bafeb2387749e8b166..3b01639206842c18ed41bab52633eb92da33311a 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.48 2001/01/24 19:42:48 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/index/Attic/istrat.c,v 1.49 2001/03/22 03:59:13 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -239,8 +239,8 @@ StrategyTermEvaluate(StrategyTerm term,
                                break;
 
                        case SK_NEGATE:
-                               result = ! DatumGetBool(FunctionCall2(&entry->sk_func,
-                                                                                                         left, right));
+                               result = !DatumGetBool(FunctionCall2(&entry->sk_func,
+                                                                                                        left, right));
                                break;
 
                        case SK_COMMUTE:
@@ -249,8 +249,8 @@ StrategyTermEvaluate(StrategyTerm term,
                                break;
 
                        case SK_NEGATE | SK_COMMUTE:
-                               result = ! DatumGetBool(FunctionCall2(&entry->sk_func,
-                                                                                                         right, left));
+                               result = !DatumGetBool(FunctionCall2(&entry->sk_func,
+                                                                                                        right, left));
                                break;
 
                        default:
@@ -263,6 +263,7 @@ StrategyTermEvaluate(StrategyTerm term,
 
        return result;
 }
+
 #endif
 
 /* ----------------
@@ -465,6 +466,7 @@ RelationInvokeStrategy(Relation relation,
 
 
 }
+
 #endif
 
 /* ----------------
@@ -519,7 +521,7 @@ OperatorRelationFillScanKeyEntry(Relation operatorRelation,
 
        if (!RegProcedureIsValid(entry->sk_procedure))
                elog(ERROR,
-                        "OperatorRelationFillScanKeyEntry: no procedure for operator %u",
+               "OperatorRelationFillScanKeyEntry: no procedure for operator %u",
                         operatorObjectId);
 
        fmgr_info(entry->sk_procedure, &entry->sk_func);
@@ -597,9 +599,7 @@ IndexSupportInitialize(IndexStrategy indexStrategy,
        }
 
        if (cachesearch)
-       {
                ReleaseSysCache(tuple);
-       }
        else
        {
                heap_endscan(scan);
index 435a7f72dde871bdf066272f9daf88d6db1ac823..fc85906d9b2b426dbf1d3c46dd54b0b407cfdd5c 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.40 2001/01/24 19:42:48 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtcompare.c,v 1.41 2001/03/22 03:59:14 momjian Exp $
  *
  * NOTES
  *
@@ -150,8 +150,8 @@ btoidvectorcmp(PG_FUNCTION_ARGS)
 Datum
 btabstimecmp(PG_FUNCTION_ARGS)
 {
-       AbsoluteTime    a = PG_GETARG_ABSOLUTETIME(0);
-       AbsoluteTime    b = PG_GETARG_ABSOLUTETIME(1);
+       AbsoluteTime a = PG_GETARG_ABSOLUTETIME(0);
+       AbsoluteTime b = PG_GETARG_ABSOLUTETIME(1);
 
        if (AbsoluteTimeIsBefore(a, b))
                PG_RETURN_INT32(-1);
@@ -236,9 +236,10 @@ bttextcmp(PG_FUNCTION_ARGS)
 
        if (res == 0 && VARSIZE(a) != VARSIZE(b))
        {
+
                /*
-                * The two strings are the same in the first len bytes,
-                * and they are of different lengths.
+                * The two strings are the same in the first len bytes, and they
+                * are of different lengths.
                 */
                if (VARSIZE(a) < VARSIZE(b))
                        res = -1;
index 325e585e3cc28a35b218db176353acaaab3c4739..f2112de6777d72b1714789ef059ee03f9e953a58 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.81 2001/02/07 23:35:33 vadim Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.82 2001/03/22 03:59:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 typedef struct
 {
        /* context data for _bt_checksplitloc */
-       Size    newitemsz;                      /* size of new item to be inserted */
-       bool    non_leaf;                       /* T if splitting an internal node */
+       Size            newitemsz;              /* size of new item to be inserted */
+       bool            non_leaf;               /* T if splitting an internal node */
 
-       bool    have_split;                     /* found a valid split? */
+       bool            have_split;             /* found a valid split? */
 
        /* these fields valid only if have_split is true */
-       bool    newitemonleft;          /* new item on left or right of best split */
+       bool            newitemonleft;  /* new item on left or right of best split */
        OffsetNumber firstright;        /* best split point */
-       int             best_delta;                     /* best size delta so far */
+       int                     best_delta;             /* best size delta so far */
 } FindSplitData;
 
 extern bool FixBTree;
 
-Buffer _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release);
+Buffer         _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release);
 static void _bt_fixtree(Relation rel, BlockNumber blkno);
-static void _bt_fixbranch(Relation rel, BlockNumber lblkno, 
-                               BlockNumber rblkno, BTStack true_stack);
+static void _bt_fixbranch(Relation rel, BlockNumber lblkno,
+                         BlockNumber rblkno, BTStack true_stack);
 static void _bt_fixlevel(Relation rel, Buffer buf, BlockNumber limit);
 static void _bt_fixup(Relation rel, Buffer buf);
 static OffsetNumber _bt_getoff(Page page, BlockNumber blkno);
@@ -47,34 +47,34 @@ static OffsetNumber _bt_getoff(Page page, BlockNumber blkno);
 static Buffer _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf);
 
 static TransactionId _bt_check_unique(Relation rel, BTItem btitem,
-                                                                         Relation heapRel, Buffer buf,
-                                                                         ScanKey itup_scankey);
+                                Relation heapRel, Buffer buf,
+                                ScanKey itup_scankey);
 static InsertIndexResult _bt_insertonpg(Relation rel, Buffer buf,
-                                                                               BTStack stack,
-                                                                               int keysz, ScanKey scankey,
-                                                                               BTItem btitem,
-                                                                               OffsetNumber afteritem);
-static void _bt_insertuple(Relation rel, Buffer buf, 
-                                               Size itemsz, BTItem btitem, OffsetNumber newitemoff);
+                          BTStack stack,
+                          int keysz, ScanKey scankey,
+                          BTItem btitem,
+                          OffsetNumber afteritem);
+static void _bt_insertuple(Relation rel, Buffer buf,
+                          Size itemsz, BTItem btitem, OffsetNumber newitemoff);
 static Buffer _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
-                                               OffsetNumber newitemoff, Size newitemsz,
-                                               BTItem newitem, bool newitemonleft,
-                                               OffsetNumber *itup_off, BlockNumber *itup_blkno);
+                 OffsetNumber newitemoff, Size newitemsz,
+                 BTItem newitem, bool newitemonleft,
+                 OffsetNumber *itup_off, BlockNumber *itup_blkno);
 static OffsetNumber _bt_findsplitloc(Relation rel, Page page,
-                                                                        OffsetNumber newitemoff,
-                                                                        Size newitemsz,
-                                                                        bool *newitemonleft);
+                                OffsetNumber newitemoff,
+                                Size newitemsz,
+                                bool *newitemonleft);
 static void _bt_checksplitloc(FindSplitData *state, OffsetNumber firstright,
-                                                         int leftfree, int rightfree,
-                                                         bool newitemonleft, Size firstrightitemsz);
+                                 int leftfree, int rightfree,
+                                 bool newitemonleft, Size firstrightitemsz);
 static Buffer _bt_getstackbuf(Relation rel, BTStack stack, int access);
 static void _bt_pgaddtup(Relation rel, Page page,
-                                                Size itemsize, BTItem btitem,
-                                                OffsetNumber itup_off, const char *where);
+                        Size itemsize, BTItem btitem,
+                        OffsetNumber itup_off, const char *where);
 static bool _bt_isequal(TupleDesc itupdesc, Page page, OffsetNumber offnum,
-                                               int keysz, ScanKey scankey);
+                       int keysz, ScanKey scankey);
 
-static Relation                _xlheapRel;     /* temporary hack */
+static Relation _xlheapRel;            /* temporary hack */
 
 /*
  *     _bt_doinsert() -- Handle insertion of a single btitem in the tree.
@@ -114,8 +114,8 @@ top:
        buf = _bt_moveright(rel, buf, natts, itup_scankey, BT_WRITE);
 
        /*
-        * If we're not allowing duplicates, make sure the key isn't
-        * already in the index.  XXX this belongs somewhere else, likely
+        * If we're not allowing duplicates, make sure the key isn't already
+        * in the index.  XXX this belongs somewhere else, likely
         */
        if (index_is_unique)
        {
@@ -134,7 +134,7 @@ top:
                }
        }
 
-       _xlheapRel = heapRel;   /* temporary hack */
+       _xlheapRel = heapRel;           /* temporary hack */
 
        /* do the insertion */
        res = _bt_insertonpg(rel, buf, stack, natts, itup_scankey, btitem, 0);
@@ -150,7 +150,7 @@ top:
  *     _bt_check_unique() -- Check for violation of unique index constraint
  *
  * Returns NullTransactionId if there is no conflict, else an xact ID we
- * must wait for to see if it commits a conflicting tuple.  If an actual
+ * must wait for to see if it commits a conflicting tuple.     If an actual
  * conflict is detected, no return --- just elog().
  */
 static TransactionId
@@ -171,8 +171,8 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
        maxoff = PageGetMaxOffsetNumber(page);
 
        /*
-        * Find first item >= proposed new item.  Note we could also get
-        * pointer to end-of-page here.
+        * Find first item >= proposed new item.  Note we could also get a
+        * pointer to end-of-page here.
         */
        offset = _bt_binsrch(rel, buf, natts, itup_scankey);
 
@@ -187,24 +187,24 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
                BlockNumber nblkno;
 
                /*
-                * _bt_compare returns 0 for (1,NULL) and (1,NULL) - this's
-                * how we handling NULLs - and so we must not use _bt_compare
-                * in real comparison, but only for ordering/finding items on
-                * pages. - vadim 03/24/97
+                * _bt_compare returns 0 for (1,NULL) and (1,NULL) - this's how we
+                * handling NULLs - and so we must not use _bt_compare in real
+                * comparison, but only for ordering/finding items on pages. -
+                * vadim 03/24/97
                 *
-                * make sure the offset points to an actual key
-                * before trying to compare it...
+                * make sure the offset points to an actual key before trying to
+                * compare it...
                 */
                if (offset <= maxoff)
                {
-                       if (! _bt_isequal(itupdesc, page, offset, natts, itup_scankey))
+                       if (!_bt_isequal(itupdesc, page, offset, natts, itup_scankey))
                                break;                  /* we're past all the equal tuples */
 
                        /*
-                        * Have to check is inserted heap tuple deleted one (i.e.
-                        * just moved to another place by vacuum)!  We only need to
-                        * do this once, but don't want to do it at all unless
-                        * we see equal tuples, so as not to slow down unequal case.
+                        * Have to check is inserted heap tuple deleted one (i.e. just
+                        * moved to another place by vacuum)!  We only need to do this
+                        * once, but don't want to do it at all unless we see equal
+                        * tuples, so as not to slow down unequal case.
                         */
                        if (chtup)
                        {
@@ -220,11 +220,11 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
                        cbti = (BTItem) PageGetItem(page, PageGetItemId(page, offset));
                        htup.t_self = cbti->bti_itup.t_tid;
                        heap_fetch(heapRel, SnapshotDirty, &htup, &buffer);
-                       if (htup.t_data != NULL)                /* it is a duplicate */
+                       if (htup.t_data != NULL)        /* it is a duplicate */
                        {
                                TransactionId xwait =
-                                       (TransactionIdIsValid(SnapshotDirty->xmin)) ?
-                                       SnapshotDirty->xmin : SnapshotDirty->xmax;
+                               (TransactionIdIsValid(SnapshotDirty->xmin)) ?
+                               SnapshotDirty->xmin : SnapshotDirty->xmax;
 
                                /*
                                 * If this tuple is being updated by other transaction
@@ -238,6 +238,7 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
                                        /* Tell _bt_doinsert to wait... */
                                        return xwait;
                                }
+
                                /*
                                 * Otherwise we have a definite conflict.
                                 */
@@ -304,7 +305,7 @@ _bt_check_unique(Relation rel, BTItem btitem, Relation heapRel,
  *             NOTE: if the new key is equal to one or more existing keys, we can
  *             legitimately place it anywhere in the series of equal keys --- in fact,
  *             if the new key is equal to the page's "high key" we can place it on
- *             the next page.  If it is equal to the high key, and there's not room
+ *             the next page.  If it is equal to the high key, and there's not room
  *             to insert the new tuple on the current page without splitting, then
  *             we can move right hoping to find more free space and avoid a split.
  *             (We should not move right indefinitely, however, since that leads to
@@ -358,16 +359,14 @@ _bt_insertonpg(Relation rel,
         */
        if (itemsz > (PageGetPageSize(page) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) / 3 - sizeof(ItemIdData))
                elog(ERROR, "btree: index item size %lu exceeds maximum %lu",
-                        (unsigned long)itemsz,
-                        (PageGetPageSize(page) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) /3 - sizeof(ItemIdData));
+                        (unsigned long) itemsz,
+                        (PageGetPageSize(page) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) / 3 - sizeof(ItemIdData));
 
        /*
         * Determine exactly where new item will go.
         */
        if (afteritem > 0)
-       {
                newitemoff = afteritem + 1;
-       }
        else
        {
                /*----------
@@ -383,12 +382,12 @@ _bt_insertonpg(Relation rel,
                 * on every insert.  We implement "get tired" as a random choice,
                 * since stopping after scanning a fixed number of pages wouldn't work
                 * well (we'd never reach the right-hand side of previously split
-                * pages).  Currently the probability of moving right is set at 0.99,
+                * pages).      Currently the probability of moving right is set at 0.99,
                 * which may seem too high to change the behavior much, but it does an
                 * excellent job of preventing O(N^2) behavior with many equal keys.
                 *----------
                 */
-               bool    movedright = false;
+               bool            movedright = false;
 
                while (PageGetFreeSpace(page) < itemsz &&
                           !P_RIGHTMOST(lpageop) &&
@@ -396,7 +395,7 @@ _bt_insertonpg(Relation rel,
                           random() > (MAX_RANDOM_VALUE / 100))
                {
                        /* step right one page */
-                       BlockNumber             rblkno = lpageop->btpo_next;
+                       BlockNumber rblkno = lpageop->btpo_next;
 
                        _bt_relbuf(rel, buf, BT_WRITE);
                        buf = _bt_getbuf(rel, rblkno, BT_WRITE);
@@ -404,10 +403,11 @@ _bt_insertonpg(Relation rel,
                        lpageop = (BTPageOpaque) PageGetSpecialPointer(page);
                        movedright = true;
                }
+
                /*
-                * Now we are on the right page, so find the insert position.
-                * If we moved right at all, we know we should insert at the
-                * start of the page, else must find the position by searching.
+                * Now we are on the right page, so find the insert position. If
+                * we moved right at all, we know we should insert at the start of
+                * the page, else must find the position by searching.
                 */
                if (movedright)
                        newitemoff = P_FIRSTDATAKEY(lpageop);
@@ -418,9 +418,9 @@ _bt_insertonpg(Relation rel,
        /*
         * Do we need to split the page to fit the item on it?
         *
-        * Note: PageGetFreeSpace() subtracts sizeof(ItemIdData) from its
-        * result, so this comparison is correct even though we appear to
-        * be accounting only for the item and not for its line pointer.
+        * Note: PageGetFreeSpace() subtracts sizeof(ItemIdData) from its result,
+        * so this comparison is correct even though we appear to be
+        * accounting only for the item and not for its line pointer.
         */
        if (PageGetFreeSpace(page) < itemsz)
        {
@@ -468,7 +468,7 @@ _bt_insertonpg(Relation rel,
 
                if (is_root)
                {
-                       Buffer  rootbuf;
+                       Buffer          rootbuf;
 
                        Assert(stack == (BTStack) NULL);
                        /* create a new root node and release the split buffers */
@@ -481,7 +481,7 @@ _bt_insertonpg(Relation rel,
                {
                        InsertIndexResult newres;
                        BTItem          new_item;
-                       BTStackData     fakestack;
+                       BTStackData fakestack;
                        BTItem          ritem;
                        Buffer          pbuf;
 
@@ -489,10 +489,11 @@ _bt_insertonpg(Relation rel,
                        if (stack == (BTStack) NULL)
                        {
                                elog(DEBUG, "btree: concurrent ROOT page split");
+
                                /*
                                 * If root page splitter failed to create new root page
-                                * then old root' btpo_parent still points to metapage.
-                                * We have to fix root page in this case.
+                                * then old root' btpo_parent still points to metapage. We
+                                * have to fix root page in this case.
                                 */
                                if (BTreeInvalidParent(lpageop))
                                {
@@ -531,9 +532,9 @@ _bt_insertonpg(Relation rel,
                         * item! We want to find parent pointing to where we are,
                         * right ?        - vadim 05/27/97
                         *
-                        * Interestingly, this means we didn't *really* need to stack
-                        * the parent key at all; all we really care about is the
-                        * saved block and offset as a starting point for our search...
+                        * Interestingly, this means we didn't *really* need to stack the
+                        * parent key at all; all we really care about is the saved
+                        * block and offset as a starting point for our search...
                         */
                        ItemPointerSet(&(stack->bts_btitem.bti_itup.t_tid),
                                                   bknum, P_HIKEY);
@@ -583,25 +584,26 @@ formres:;
 }
 
 static void
-_bt_insertuple(Relation rel, Buffer buf, 
-                               Size itemsz, BTItem btitem, OffsetNumber newitemoff)
+_bt_insertuple(Relation rel, Buffer buf,
+                          Size itemsz, BTItem btitem, OffsetNumber newitemoff)
 {
-       Page                    page = BufferGetPage(buf);
-       BTPageOpaque    pageop = (BTPageOpaque) PageGetSpecialPointer(page);
+       Page            page = BufferGetPage(buf);
+       BTPageOpaque pageop = (BTPageOpaque) PageGetSpecialPointer(page);
 
        START_CRIT_SECTION();
        _bt_pgaddtup(rel, page, itemsz, btitem, newitemoff, "page");
        /* XLOG stuff */
        {
-               xl_btree_insert         xlrec;
-               uint8                           flag = XLOG_BTREE_INSERT;
-               XLogRecPtr                      recptr;
-               XLogRecData                     rdata[2];
-               BTItemData                      truncitem;
-                       xlrec.target.node = rel->rd_node;
+               xl_btree_insert xlrec;
+               uint8           flag = XLOG_BTREE_INSERT;
+               XLogRecPtr      recptr;
+               XLogRecData rdata[2];
+               BTItemData      truncitem;
+
+               xlrec.target.node = rel->rd_node;
                ItemPointerSet(&(xlrec.target.tid), BufferGetBlockNumber(buf), newitemoff);
                rdata[0].buffer = InvalidBuffer;
-               rdata[0].data = (char*)&xlrec;
+               rdata[0].data = (char *) &xlrec;
                rdata[0].len = SizeOfBtreeInsert;
                rdata[0].next = &(rdata[1]);
 
@@ -610,14 +612,14 @@ _bt_insertuple(Relation rel, Buffer buf,
                {
                        truncitem = *btitem;
                        truncitem.bti_itup.t_info = sizeof(BTItemData);
-                       rdata[1].data = (char*)&truncitem;
+                       rdata[1].data = (char *) &truncitem;
                        rdata[1].len = sizeof(BTItemData);
                }
                else
                {
-                       rdata[1].data = (char*)btitem;
-                       rdata[1].len = IndexTupleDSize(btitem->bti_itup) + 
-                                               (sizeof(BTItemData) - sizeof(IndexTupleData));
+                       rdata[1].data = (char *) btitem;
+                       rdata[1].len = IndexTupleDSize(btitem->bti_itup) +
+                               (sizeof(BTItemData) - sizeof(IndexTupleData));
                }
                rdata[1].buffer = buf;
                rdata[1].next = NULL;
@@ -700,8 +702,8 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
 
        /*
         * If the page we're splitting is not the rightmost page at its level
-        * in the tree, then the first entry on the page is the high key
-        * for the page.  We need to copy that to the right half.  Otherwise
+        * in the tree, then the first entry on the page is the high key for
+        * the page.  We need to copy that to the right half.  Otherwise
         * (meaning the rightmost page case), all the items on the right half
         * will be user data.
         */
@@ -779,13 +781,13 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
                if (i < firstright)
                {
                        _bt_pgaddtup(rel, leftpage, itemsz, item, leftoff,
-                                                        "left sibling");
+                                                "left sibling");
                        leftoff = OffsetNumberNext(leftoff);
                }
                else
                {
                        _bt_pgaddtup(rel, rightpage, itemsz, item, rightoff,
-                                                        "right sibling");
+                                                "right sibling");
                        rightoff = OffsetNumberNext(rightoff);
                }
        }
@@ -812,11 +814,11 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
        }
 
        /*
-        * We have to grab the right sibling (if any) and fix the prev
-        * pointer there. We are guaranteed that this is deadlock-free
-        * since no other writer will be holding a lock on that page
-        * and trying to move left, and all readers release locks on a page
-        * before trying to fetch its neighbors.
+        * We have to grab the right sibling (if any) and fix the prev pointer
+        * there. We are guaranteed that this is deadlock-free since no other
+        * writer will be holding a lock on that page and trying to move left,
+        * and all readers release locks on a page before trying to fetch its
+        * neighbors.
         */
 
        if (!P_RIGHTMOST(ropaque))
@@ -834,12 +836,12 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
         */
        START_CRIT_SECTION();
        {
-               xl_btree_split  xlrec;
-               int                             flag = (newitemonleft) ? 
-                                                               XLOG_BTREE_SPLEFT : XLOG_BTREE_SPLIT;
-               BlockNumber             blkno;
-               XLogRecPtr              recptr;
-               XLogRecData             rdata[4];
+               xl_btree_split xlrec;
+               int                     flag = (newitemonleft) ?
+               XLOG_BTREE_SPLEFT : XLOG_BTREE_SPLIT;
+               BlockNumber blkno;
+               XLogRecPtr      recptr;
+               XLogRecData rdata[4];
 
                xlrec.target.node = rel->rd_node;
                ItemPointerSet(&(xlrec.target.tid), *itup_blkno, *itup_off);
@@ -856,31 +858,33 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
                BlockIdSet(&(xlrec.parentblk), lopaque->btpo_parent);
                BlockIdSet(&(xlrec.leftblk), lopaque->btpo_prev);
                BlockIdSet(&(xlrec.rightblk), ropaque->btpo_next);
-               /* 
-                * Dirrect access to page is not good but faster - we should 
+
+               /*
+                * Dirrect access to page is not good but faster - we should
                 * implement some new func in page API.
                 */
-               xlrec.leftlen = ((PageHeader)leftpage)->pd_special -
-                                                       ((PageHeader)leftpage)->pd_upper;
+               xlrec.leftlen = ((PageHeader) leftpage)->pd_special -
+                       ((PageHeader) leftpage)->pd_upper;
                rdata[0].buffer = InvalidBuffer;
-               rdata[0].data = (char*)&xlrec;
+               rdata[0].data = (char *) &xlrec;
                rdata[0].len = SizeOfBtreeSplit;
                rdata[0].next = &(rdata[1]);
 
                rdata[1].buffer = InvalidBuffer;
-               rdata[1].data = (char*)leftpage + ((PageHeader)leftpage)->pd_upper;
+               rdata[1].data = (char *) leftpage + ((PageHeader) leftpage)->pd_upper;
                rdata[1].len = xlrec.leftlen;
                rdata[1].next = &(rdata[2]);
 
                rdata[2].buffer = InvalidBuffer;
-               rdata[2].data = (char*)rightpage + ((PageHeader)rightpage)->pd_upper;
-               rdata[2].len = ((PageHeader)rightpage)->pd_special -
-                                                       ((PageHeader)rightpage)->pd_upper;
+               rdata[2].data = (char *) rightpage + ((PageHeader) rightpage)->pd_upper;
+               rdata[2].len = ((PageHeader) rightpage)->pd_special -
+                       ((PageHeader) rightpage)->pd_upper;
                rdata[2].next = NULL;
 
                if (!P_RIGHTMOST(ropaque))
                {
-                       BTPageOpaque    sopaque = (BTPageOpaque) PageGetSpecialPointer(spage);
+                       BTPageOpaque sopaque = (BTPageOpaque) PageGetSpecialPointer(spage);
+
                        sopaque->btpo_prev = BufferGetBlockNumber(rbuf);
 
                        rdata[2].next = &(rdata[3]);
@@ -942,7 +946,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
  *
  * We return the index of the first existing tuple that should go on the
  * righthand page, plus a boolean indicating whether the new tuple goes on
- * the left or right page.  The bool is necessary to disambiguate the case
+ * the left or right page.     The bool is necessary to disambiguate the case
  * where firstright == newitemoff.
  */
 static OffsetNumber
@@ -968,23 +972,23 @@ _bt_findsplitloc(Relation rel,
        /* Passed-in newitemsz is MAXALIGNED but does not include line pointer */
        newitemsz += sizeof(ItemIdData);
        state.newitemsz = newitemsz;
-       state.non_leaf = ! P_ISLEAF(opaque);
+       state.non_leaf = !P_ISLEAF(opaque);
        state.have_split = false;
 
        /* Total free space available on a btree page, after fixed overhead */
        leftspace = rightspace =
                PageGetPageSize(page) - sizeof(PageHeaderData) -
                MAXALIGN(sizeof(BTPageOpaqueData))
-               + sizeof(ItemIdData);
+               +sizeof(ItemIdData);
 
        /*
-        * Finding the best possible split would require checking all the possible
-        * split points, because of the high-key and left-key special cases.
-        * That's probably more work than it's worth; instead, stop as soon as
-        * we find a "good-enough" split, where good-enough is defined as an
-        * imbalance in free space of no more than pagesize/16 (arbitrary...)
-        * This should let us stop near the middle on most pages, instead of
-        * plowing to the end.
+        * Finding the best possible split would require checking all the
+        * possible split points, because of the high-key and left-key special
+        * cases. That's probably more work than it's worth; instead, stop as
+        * soon as we find a "good-enough" split, where good-enough is defined
+        * as an imbalance in free space of no more than pagesize/16
+        * (arbitrary...) This should let us stop near the middle on most
+        * pages, instead of plowing to the end.
         */
        goodenough = leftspace / 16;
 
@@ -1024,6 +1028,7 @@ _bt_findsplitloc(Relation rel,
                 */
                leftfree = leftspace - dataitemstoleft - (int) itemsz;
                rightfree = rightspace - (dataitemtotal - dataitemstoleft);
+
                /*
                 * Will the new item go to left or right of split?
                 */
@@ -1051,10 +1056,10 @@ _bt_findsplitloc(Relation rel,
        }
 
        /*
-        * I believe it is not possible to fail to find a feasible split,
-        * but just in case ...
+        * I believe it is not possible to fail to find a feasible split, but
+        * just in case ...
         */
-       if (! state.have_split)
+       if (!state.have_split)
                elog(FATAL, "_bt_findsplitloc: can't find a feasible split point for %s",
                         RelationGetRelationName(rel));
 
@@ -1071,6 +1076,7 @@ _bt_checksplitloc(FindSplitData *state, OffsetNumber firstright,
                                  int leftfree, int rightfree,
                                  bool newitemonleft, Size firstrightitemsz)
 {
+
        /*
         * Account for the new item on whichever side it is to be put.
         */
@@ -1078,19 +1084,21 @@ _bt_checksplitloc(FindSplitData *state, OffsetNumber firstright,
                leftfree -= (int) state->newitemsz;
        else
                rightfree -= (int) state->newitemsz;
+
        /*
-        * If we are not on the leaf level, we will be able to discard the
-        * key data from the first item that winds up on the right page.
+        * If we are not on the leaf level, we will be able to discard the key
+        * data from the first item that winds up on the right page.
         */
        if (state->non_leaf)
                rightfree += (int) firstrightitemsz -
                        (int) (MAXALIGN(sizeof(BTItemData)) + sizeof(ItemIdData));
+
        /*
         * If feasible split point, remember best delta.
         */
        if (leftfree >= 0 && rightfree >= 0)
        {
-               int             delta = leftfree - rightfree;
+               int                     delta = leftfree - rightfree;
 
                if (delta < 0)
                        delta = -delta;
@@ -1134,10 +1142,11 @@ _bt_getstackbuf(Relation rel, BTStack stack, int access)
        maxoff = PageGetMaxOffsetNumber(page);
 
        start = stack->bts_offset;
+
        /*
-        * _bt_insertonpg set bts_offset to InvalidOffsetNumber in the
-        * case of concurrent ROOT page split.  Also, watch out for
-        * possibility that page has a high key now when it didn't before.
+        * _bt_insertonpg set bts_offset to InvalidOffsetNumber in the case of
+        * concurrent ROOT page split.  Also, watch out for possibility that
+        * page has a high key now when it didn't before.
         */
        if (start < P_FIRSTDATAKEY(opaque))
                start = P_FIRSTDATAKEY(opaque);
@@ -1159,11 +1168,15 @@ _bt_getstackbuf(Relation rel, BTStack stack, int access)
                                return buf;
                        }
                }
-               /* by here, the item we're looking for moved right at least one page */
+
+               /*
+                * by here, the item we're looking for moved right at least one
+                * page
+                */
                if (P_RIGHTMOST(opaque))
                {
                        _bt_relbuf(rel, buf, access);
-                       return(InvalidBuffer);
+                       return (InvalidBuffer);
                }
 
                blkno = opaque->btpo_next;
@@ -1190,27 +1203,27 @@ _bt_getstackbuf(Relation rel, BTStack stack, int access)
  *
  *             On entry, lbuf (the old root) and rbuf (its new peer) are write-
  *             locked. On exit, a new root page exists with entries for the
- *             two new children, metapage is updated and unlocked/unpinned. 
- *      The new root buffer is returned to caller which has to unlock/unpin
- *      lbuf, rbuf & rootbuf.
+ *             two new children, metapage is updated and unlocked/unpinned.
+ *             The new root buffer is returned to caller which has to unlock/unpin
+ *             lbuf, rbuf & rootbuf.
  */
 static Buffer
 _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
 {
-       Buffer                  rootbuf;
-       Page                    lpage,
-                                       rpage,
-                                       rootpage;
-       BlockNumber             lbkno,
-                                       rbkno;
-       BlockNumber             rootblknum;
-       BTPageOpaque    rootopaque;
-       ItemId                  itemid;
-       BTItem                  item;
-       Size                    itemsz;
-       BTItem                  new_item;
-       Buffer                  metabuf;
-       Page                    metapg;
+       Buffer          rootbuf;
+       Page            lpage,
+                               rpage,
+                               rootpage;
+       BlockNumber lbkno,
+                               rbkno;
+       BlockNumber rootblknum;
+       BTPageOpaque rootopaque;
+       ItemId          itemid;
+       BTItem          item;
+       Size            itemsz;
+       BTItem          new_item;
+       Buffer          metabuf;
+       Page            metapg;
        BTMetaPageData *metad;
 
        /* get a new root page */
@@ -1236,9 +1249,9 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
        rpage = BufferGetPage(rbuf);
 
        /*
-        * Make sure pages in old root level have valid parent links --- we will
-        * need this in _bt_insertonpg() if a concurrent root split happens (see
-        * README).
+        * Make sure pages in old root level have valid parent links --- we
+        * will need this in _bt_insertonpg() if a concurrent root split
+        * happens (see README).
         */
        ((BTPageOpaque) PageGetSpecialPointer(lpage))->btpo_parent =
                ((BTPageOpaque) PageGetSpecialPointer(rpage))->btpo_parent =
@@ -1264,8 +1277,8 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
        pfree(new_item);
 
        /*
-        * Create downlink item for right page.  The key for it is obtained from
-        * the "high key" position in the left page.
+        * Create downlink item for right page.  The key for it is obtained
+        * from the "high key" position in the left page.
         */
        itemid = PageGetItemId(lpage, P_HIKEY);
        itemsz = ItemIdGetLength(itemid);
@@ -1285,26 +1298,26 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
 
        /* XLOG stuff */
        {
-               xl_btree_newroot        xlrec;
-               XLogRecPtr                      recptr;
-               XLogRecData                     rdata[2];
+               xl_btree_newroot xlrec;
+               XLogRecPtr      recptr;
+               XLogRecData rdata[2];
 
                xlrec.node = rel->rd_node;
                xlrec.level = metad->btm_level;
                BlockIdSet(&(xlrec.rootblk), rootblknum);
                rdata[0].buffer = InvalidBuffer;
-               rdata[0].data = (char*)&xlrec;
+               rdata[0].data = (char *) &xlrec;
                rdata[0].len = SizeOfBtreeNewroot;
                rdata[0].next = &(rdata[1]);
 
-               /* 
-                * Dirrect access to page is not good but faster - we should 
+               /*
+                * Dirrect access to page is not good but faster - we should
                 * implement some new func in page API.
                 */
                rdata[1].buffer = InvalidBuffer;
-               rdata[1].data = (char*)rootpage + ((PageHeader) rootpage)->pd_upper;
-               rdata[1].len = ((PageHeader)rootpage)->pd_special - 
-                                                       ((PageHeader)rootpage)->pd_upper;
+               rdata[1].data = (char *) rootpage + ((PageHeader) rootpage)->pd_upper;
+               rdata[1].len = ((PageHeader) rootpage)->pd_special -
+                       ((PageHeader) rootpage)->pd_upper;
                rdata[1].next = NULL;
 
                recptr = XLogInsert(RM_BTREE_ID, XLOG_BTREE_NEWROOT, rdata);
@@ -1325,7 +1338,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
        /* write and let go of metapage buffer */
        _bt_wrtbuf(rel, metabuf);
 
-       return(rootbuf);
+       return (rootbuf);
 }
 
 /*
@@ -1339,24 +1352,31 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
 Buffer
 _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release)
 {
-       Buffer                  rootbuf;
-       BlockNumber             rootblk;
-       Page                    rootpage;
-       XLogRecPtr              rootLSN;
-       Page                    oldrootpage = BufferGetPage(oldrootbuf);
-       BTPageOpaque    oldrootopaque = (BTPageOpaque)
-                                               PageGetSpecialPointer(oldrootpage);
-       Buffer                  buf, leftbuf, rightbuf;
-       Page                    page, leftpage, rightpage;
-       BTPageOpaque    opaque, leftopaque, rightopaque;
-       OffsetNumber    newitemoff;
-       BTItem                  btitem, ritem;
-       Size                    itemsz;
-
-       if (! P_LEFTMOST(oldrootopaque) || P_RIGHTMOST(oldrootopaque))
+       Buffer          rootbuf;
+       BlockNumber rootblk;
+       Page            rootpage;
+       XLogRecPtr      rootLSN;
+       Page            oldrootpage = BufferGetPage(oldrootbuf);
+       BTPageOpaque oldrootopaque = (BTPageOpaque)
+       PageGetSpecialPointer(oldrootpage);
+       Buffer          buf,
+                               leftbuf,
+                               rightbuf;
+       Page            page,
+                               leftpage,
+                               rightpage;
+       BTPageOpaque opaque,
+                               leftopaque,
+                               rightopaque;
+       OffsetNumber newitemoff;
+       BTItem          btitem,
+                               ritem;
+       Size            itemsz;
+
+       if (!P_LEFTMOST(oldrootopaque) || P_RIGHTMOST(oldrootopaque))
                elog(ERROR, "bt_fixroot: not valid old root page");
 
-       /* Read right neighbor and create new root page*/
+       /* Read right neighbor and create new root page */
        leftbuf = _bt_getbuf(rel, oldrootopaque->btpo_next, BT_WRITE);
        leftpage = BufferGetPage(leftbuf);
        leftopaque = (BTPageOpaque) PageGetSpecialPointer(leftpage);
@@ -1377,26 +1397,26 @@ _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release)
         *
         * If concurrent process will split one of pages on this level then it
         * will see either btpo_parent == metablock or btpo_parent == rootblk.
-        * In first case it will give up its locks and walk to the leftmost page
-        * (oldrootbuf) in _bt_fixup() - ie it will wait for us and let us
-        * continue. In second case it will try to lock rootbuf keeping its locks
-        * on buffers we already passed, also waiting for us. If we'll have to
-        * unlock rootbuf (split it) and that process will have to split page
-        * of new level we created (level of rootbuf) then it will wait while
-        * we create upper level. Etc.
+        * In first case it will give up its locks and walk to the leftmost
+        * page (oldrootbuf) in _bt_fixup() - ie it will wait for us and let
+        * us continue. In second case it will try to lock rootbuf keeping its
+        * locks on buffers we already passed, also waiting for us. If we'll
+        * have to unlock rootbuf (split it) and that process will have to
+        * split page of new level we created (level of rootbuf) then it will
+        * wait while we create upper level. Etc.
         */
-       while(! P_RIGHTMOST(leftopaque))
+       while (!P_RIGHTMOST(leftopaque))
        {
                rightbuf = _bt_getbuf(rel, leftopaque->btpo_next, BT_WRITE);
                rightpage = BufferGetPage(rightbuf);
                rightopaque = (BTPageOpaque) PageGetSpecialPointer(rightpage);
 
                /*
-                * Update LSN & StartUpID of child page buffer to ensure that
-                * it will be written on disk after flushing log record for new
-                * root creation. Unfortunately, for the moment (?) we do not
-                * log this operation and so possibly break our rule to log entire
-                * page content on first after checkpoint modification.
+                * Update LSN & StartUpID of child page buffer to ensure that it
+                * will be written on disk after flushing log record for new root
+                * creation. Unfortunately, for the moment (?) we do not log this
+                * operation and so possibly break our rule to log entire page
+                * content on first after checkpoint modification.
                 */
                HOLD_INTERRUPTS();
                rightopaque->btpo_parent = rootblk;
@@ -1416,17 +1436,17 @@ _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release)
 
                if (PageGetFreeSpace(page) < itemsz)
                {
-                       Buffer                  newbuf;
-                       OffsetNumber    firstright;
-                       OffsetNumber    itup_off;
-                       BlockNumber             itup_blkno;
-                       bool                    newitemonleft;
+                       Buffer          newbuf;
+                       OffsetNumber firstright;
+                       OffsetNumber itup_off;
+                       BlockNumber itup_blkno;
+                       bool            newitemonleft;
 
                        firstright = _bt_findsplitloc(rel, page,
-                                                       newitemoff, itemsz, &newitemonleft);
+                                                                        newitemoff, itemsz, &newitemonleft);
                        newbuf = _bt_split(rel, buf, firstright,
-                                               newitemoff, itemsz, btitem, newitemonleft,
-                                               &itup_off, &itup_blkno);
+                                                          newitemoff, itemsz, btitem, newitemonleft,
+                                                          &itup_off, &itup_blkno);
                        /* Keep lock on new "root" buffer ! */
                        if (buf != rootbuf)
                                _bt_relbuf(rel, buf, BT_WRITE);
@@ -1450,10 +1470,10 @@ _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release)
 
        /*
         * Here we hold locks on old root buffer, new root buffer we've
-        * created with _bt_newroot() - rootbuf, - and buf we've used
-        * for last insert ops - buf. If rootbuf != buf then we have to
-        * create at least one more level. And if "release" is TRUE
-        * then we give up oldrootbuf.
+        * created with _bt_newroot() - rootbuf, - and buf we've used for last
+        * insert ops - buf. If rootbuf != buf then we have to create at least
+        * one more level. And if "release" is TRUE then we give up
+        * oldrootbuf.
         */
        if (release)
                _bt_wrtbuf(rel, oldrootbuf);
@@ -1461,10 +1481,10 @@ _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release)
        if (rootbuf != buf)
        {
                _bt_wrtbuf(rel, buf);
-               return(_bt_fixroot(rel, rootbuf, true));
+               return (_bt_fixroot(rel, rootbuf, true));
        }
 
-       return(rootbuf);
+       return (rootbuf);
 }
 
 /*
@@ -1474,17 +1494,17 @@ _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release)
 static void
 _bt_fixtree(Relation rel, BlockNumber blkno)
 {
-       Buffer                  buf;
-       Page                    page;
-       BTPageOpaque    opaque;
-       BlockNumber             pblkno;
+       Buffer          buf;
+       Page            page;
+       BTPageOpaque opaque;
+       BlockNumber pblkno;
 
-       for ( ; ; )
+       for (;;)
        {
                buf = _bt_getbuf(rel, blkno, BT_READ);
                page = BufferGetPage(buf);
                opaque = (BTPageOpaque) PageGetSpecialPointer(page);
-               if (! P_LEFTMOST(opaque) || P_ISLEAF(opaque))
+               if (!P_LEFTMOST(opaque) || P_ISLEAF(opaque))
                        elog(ERROR, "bt_fixtree[%s]: invalid start page (need to recreate index)", RelationGetRelationName(rel));
                pblkno = opaque->btpo_parent;
 
@@ -1534,25 +1554,26 @@ _bt_fixtree(Relation rel, BlockNumber blkno)
 static void
 _bt_fixlevel(Relation rel, Buffer buf, BlockNumber limit)
 {
-       BlockNumber             blkno = BufferGetBlockNumber(buf);
-       Page                    page;
-       BTPageOpaque    opaque;
-       BlockNumber             cblkno[3];
-       OffsetNumber    coff[3];
-       Buffer                  cbuf[3];
-       Page                    cpage[3];
-       BTPageOpaque    copaque[3];
-       BTItem                  btitem;
-       int                             cidx, i;
-       bool                    goodbye = false;
-       char                    tbuf[BLCKSZ];
+       BlockNumber blkno = BufferGetBlockNumber(buf);
+       Page            page;
+       BTPageOpaque opaque;
+       BlockNumber cblkno[3];
+       OffsetNumber coff[3];
+       Buffer          cbuf[3];
+       Page            cpage[3];
+       BTPageOpaque copaque[3];
+       BTItem          btitem;
+       int                     cidx,
+                               i;
+       bool            goodbye = false;
+       char            tbuf[BLCKSZ];
 
        page = BufferGetPage(buf);
        /* copy page to temp storage */
        memmove(tbuf, page, PageGetPageSize(page));
        _bt_relbuf(rel, buf, BT_READ);
 
-       page = (Page)tbuf;
+       page = (Page) tbuf;
        opaque = (BTPageOpaque) PageGetSpecialPointer(page);
 
        /* Initialize first child data */
@@ -1564,20 +1585,21 @@ _bt_fixlevel(Relation rel, Buffer buf, BlockNumber limit)
        cbuf[0] = _bt_getbuf(rel, cblkno[0], BT_READ);
        cpage[0] = BufferGetPage(cbuf[0]);
        copaque[0] = (BTPageOpaque) PageGetSpecialPointer(cpage[0]);
-       if (P_LEFTMOST(opaque) && ! P_LEFTMOST(copaque[0]))
+       if (P_LEFTMOST(opaque) && !P_LEFTMOST(copaque[0]))
                elog(ERROR, "bt_fixtlevel[%s]: non-leftmost child page of leftmost parent (need to recreate index)", RelationGetRelationName(rel));
        /* caller should take care and avoid this */
        if (P_RIGHTMOST(copaque[0]))
                elog(ERROR, "bt_fixtlevel[%s]: invalid start child (need to recreate index)", RelationGetRelationName(rel));
 
-       for ( ; ; )
+       for (;;)
        {
+
                /*
-                * Read up to 2 more child pages and look for pointers
-                * to them in *saved* parent page
+                * Read up to 2 more child pages and look for pointers to them in
+                * *saved* parent page
                 */
                coff[1] = coff[2] = InvalidOffsetNumber;
-               for (cidx = 0; cidx < 2; )
+               for (cidx = 0; cidx < 2;)
                {
                        cidx++;
                        cblkno[cidx] = (copaque[cidx - 1])->btpo_next;
@@ -1609,20 +1631,20 @@ _bt_fixlevel(Relation rel, Buffer buf, BlockNumber limit)
                if (coff[1] == InvalidOffsetNumber ||
                        (cidx == 2 && coff[2] == InvalidOffsetNumber))
                {
-                       Buffer                  newbuf;
-                       Page                    newpage;
-                       BTPageOpaque    newopaque;
-                       BTItem                  ritem;
-                       Size                    itemsz;
-                       OffsetNumber    newitemoff;
-                       BlockNumber             parblk[3];
-                       BTStackData             stack;
+                       Buffer          newbuf;
+                       Page            newpage;
+                       BTPageOpaque newopaque;
+                       BTItem          ritem;
+                       Size            itemsz;
+                       OffsetNumber newitemoff;
+                       BlockNumber parblk[3];
+                       BTStackData stack;
 
                        stack.bts_parent = NULL;
                        stack.bts_blkno = blkno;
                        stack.bts_offset = InvalidOffsetNumber;
                        ItemPointerSet(&(stack.bts_btitem.bti_itup.t_tid),
-                                                       cblkno[0], P_HIKEY);
+                                                  cblkno[0], P_HIKEY);
 
                        buf = _bt_getstackbuf(rel, &stack, BT_WRITE);
                        if (buf == InvalidBuffer)
@@ -1644,19 +1666,19 @@ _bt_fixlevel(Relation rel, Buffer buf, BlockNumber limit)
                                if (coff[i] != InvalidOffsetNumber)
                                {
                                        if (parblk[i] == parblk[i - 1] &&
-                                                               coff[i] != coff[i - 1] + 1)
+                                               coff[i] != coff[i - 1] + 1)
                                                elog(ERROR, "bt_fixlevel[%s]: invalid item order(2) (need to recreate index)", RelationGetRelationName(rel));
                                        continue;
                                }
                                /* Have to check next page ? */
-                               if ((! P_RIGHTMOST(opaque)) &&
-                                       coff[i - 1] == PageGetMaxOffsetNumber(page))    /* yes */
+                               if ((!P_RIGHTMOST(opaque)) &&
+                                       coff[i - 1] == PageGetMaxOffsetNumber(page))            /* yes */
                                {
                                        newbuf = _bt_getbuf(rel, opaque->btpo_next, BT_WRITE);
                                        newpage = BufferGetPage(newbuf);
                                        newopaque = (BTPageOpaque) PageGetSpecialPointer(newpage);
                                        coff[i] = _bt_getoff(newpage, cblkno[i]);
-                                       if (coff[i] != InvalidOffsetNumber)     /* found ! */
+                                       if (coff[i] != InvalidOffsetNumber) /* found ! */
                                        {
                                                if (coff[i] != P_FIRSTDATAKEY(newopaque))
                                                        elog(ERROR, "bt_fixlevel[%s]: invalid item order(3) (need to recreate index)", RelationGetRelationName(rel));
@@ -1673,7 +1695,7 @@ _bt_fixlevel(Relation rel, Buffer buf, BlockNumber limit)
                                }
                                /* insert pointer */
                                ritem = (BTItem) PageGetItem(cpage[i - 1],
-                                                                       PageGetItemId(cpage[i - 1], P_HIKEY));
+                                                                  PageGetItemId(cpage[i - 1], P_HIKEY));
                                btitem = _bt_formitem(&(ritem->bti_itup));
                                ItemPointerSet(&(btitem->bti_itup.t_tid), cblkno[i], P_HIKEY);
                                itemsz = IndexTupleDSize(btitem->bti_itup)
@@ -1684,16 +1706,16 @@ _bt_fixlevel(Relation rel, Buffer buf, BlockNumber limit)
 
                                if (PageGetFreeSpace(page) < itemsz)
                                {
-                                       OffsetNumber    firstright;
-                                       OffsetNumber    itup_off;
-                                       BlockNumber             itup_blkno;
-                                       bool                    newitemonleft;
+                                       OffsetNumber firstright;
+                                       OffsetNumber itup_off;
+                                       BlockNumber itup_blkno;
+                                       bool            newitemonleft;
 
                                        firstright = _bt_findsplitloc(rel, page,
-                                                                       newitemoff, itemsz, &newitemonleft);
+                                                                        newitemoff, itemsz, &newitemonleft);
                                        newbuf = _bt_split(rel, buf, firstright,
-                                                               newitemoff, itemsz, btitem, newitemonleft,
-                                                               &itup_off, &itup_blkno);
+                                                          newitemoff, itemsz, btitem, newitemonleft,
+                                                                          &itup_off, &itup_blkno);
                                        /* what buffer we need in ? */
                                        if (newitemonleft)
                                                _bt_relbuf(rel, newbuf, BT_WRITE);
@@ -1720,7 +1742,7 @@ _bt_fixlevel(Relation rel, Buffer buf, BlockNumber limit)
                        /* copy page with pointer to cblkno[cidx] to temp storage */
                        memmove(tbuf, page, PageGetPageSize(page));
                        _bt_relbuf(rel, buf, BT_WRITE);
-                       page = (Page)tbuf;
+                       page = (Page) tbuf;
                        opaque = (BTPageOpaque) PageGetSpecialPointer(page);
                }
 
@@ -1760,18 +1782,19 @@ _bt_fixlevel(Relation rel, Buffer buf, BlockNumber limit)
  * but it doesn't guarantee full consistency of tree.)
  */
 static void
-_bt_fixbranch(Relation rel, BlockNumber lblkno, 
-                               BlockNumber rblkno, BTStack true_stack)
+_bt_fixbranch(Relation rel, BlockNumber lblkno,
+                         BlockNumber rblkno, BTStack true_stack)
 {
-       BlockNumber             blkno = true_stack->bts_blkno;
-       BTStackData             stack;
-       BTPageOpaque    opaque;
-       Buffer                  buf, rbuf;
-       Page                    page;
-       OffsetNumber    offnum;
+       BlockNumber blkno = true_stack->bts_blkno;
+       BTStackData stack;
+       BTPageOpaque opaque;
+       Buffer          buf,
+                               rbuf;
+       Page            page;
+       OffsetNumber offnum;
 
        true_stack = true_stack->bts_parent;
-       for ( ; ; )
+       for (;;)
        {
                buf = _bt_getbuf(rel, blkno, BT_READ);
 
@@ -1779,8 +1802,8 @@ _bt_fixbranch(Relation rel, BlockNumber lblkno,
                _bt_fixlevel(rel, buf, rblkno);
 
                /*
-                * Here parent level should have pointers for both
-                * lblkno and rblkno and we have to find them.
+                * Here parent level should have pointers for both lblkno and
+                * rblkno and we have to find them.
                 */
                stack.bts_parent = NULL;
                stack.bts_blkno = blkno;
@@ -1792,7 +1815,7 @@ _bt_fixbranch(Relation rel, BlockNumber lblkno,
                page = BufferGetPage(buf);
                offnum = _bt_getoff(page, rblkno);
 
-               if (offnum != InvalidOffsetNumber)      /* right pointer found */
+               if (offnum != InvalidOffsetNumber)              /* right pointer found */
                {
                        if (offnum <= stack.bts_offset)
                                elog(ERROR, "bt_fixbranch[%s]: invalid item order (need to recreate index)", RelationGetRelationName(rel));
@@ -1829,10 +1852,10 @@ _bt_fixbranch(Relation rel, BlockNumber lblkno,
                }
 
                /*
-                * Well, we are on the level that was root or unexistent when
-                * we started traversing tree down. If btpo_parent is updated
-                * then we'll use it to continue, else we'll fix/restore upper
-                * levels entirely.
+                * Well, we are on the level that was root or unexistent when we
+                * started traversing tree down. If btpo_parent is updated then
+                * we'll use it to continue, else we'll fix/restore upper levels
+                * entirely.
                 */
                if (!BTreeInvalidParent(opaque))
                {
@@ -1874,18 +1897,18 @@ _bt_fixbranch(Relation rel, BlockNumber lblkno,
 static void
 _bt_fixup(Relation rel, Buffer buf)
 {
-       Page                    page;
-       BTPageOpaque    opaque;
-       BlockNumber             blkno;
+       Page            page;
+       BTPageOpaque opaque;
+       BlockNumber blkno;
 
-       for ( ; ; )
+       for (;;)
        {
                page = BufferGetPage(buf);
                opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+
                /*
-                * If someone else already created parent pages
-                * then it's time for _bt_fixtree() to check upper
-                * levels and fix them, if required.
+                * If someone else already created parent pages then it's time for
+                * _bt_fixtree() to check upper levels and fix them, if required.
                 */
                if (!BTreeInvalidParent(opaque))
                {
@@ -1904,13 +1927,12 @@ _bt_fixup(Relation rel, Buffer buf)
        }
 
        /*
-        * Ok, we are on the leftmost page, it's write locked
-        * by us and its btpo_parent points to meta page - time
-        * for _bt_fixroot().
+        * Ok, we are on the leftmost page, it's write locked by us and its
+        * btpo_parent points to meta page - time for _bt_fixroot().
         */
        elog(NOTICE, "bt_fixup[%s]: fixing root page", RelationGetRelationName(rel));
-        buf = _bt_fixroot(rel, buf, true);
-        _bt_relbuf(rel, buf, BT_WRITE);
+       buf = _bt_fixroot(rel, buf, true);
+       _bt_relbuf(rel, buf, BT_WRITE);
 
        return;
 }
@@ -1918,23 +1940,23 @@ _bt_fixup(Relation rel, Buffer buf)
 static OffsetNumber
 _bt_getoff(Page page, BlockNumber blkno)
 {
-       BTPageOpaque    opaque = (BTPageOpaque) PageGetSpecialPointer(page);
-       OffsetNumber    maxoff = PageGetMaxOffsetNumber(page);
-       OffsetNumber    offnum = P_FIRSTDATAKEY(opaque);
-       BlockNumber             curblkno;
-       ItemId                  itemid;
-       BTItem                  item;
-
-       for ( ; offnum <= maxoff; offnum++)
+       BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+       OffsetNumber maxoff = PageGetMaxOffsetNumber(page);
+       OffsetNumber offnum = P_FIRSTDATAKEY(opaque);
+       BlockNumber curblkno;
+       ItemId          itemid;
+       BTItem          item;
+
+       for (; offnum <= maxoff; offnum++)
        {
                itemid = PageGetItemId(page, offnum);
                item = (BTItem) PageGetItem(page, itemid);
                curblkno = ItemPointerGetBlockNumber(&(item->bti_itup.t_tid));
                if (curblkno == blkno)
-                       return(offnum);
+                       return (offnum);
        }
 
-       return(InvalidOffsetNumber);
+       return (InvalidOffsetNumber);
 }
 
 /*
@@ -1961,9 +1983,9 @@ _bt_pgaddtup(Relation rel,
                         const char *where)
 {
        BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
-       BTItemData truncitem;
+       BTItemData      truncitem;
 
-       if (! P_ISLEAF(opaque) && itup_off == P_FIRSTDATAKEY(opaque))
+       if (!P_ISLEAF(opaque) && itup_off == P_FIRSTDATAKEY(opaque))
        {
                memcpy(&truncitem, btitem, sizeof(BTItemData));
                truncitem.bti_itup.t_info = sizeof(BTItemData);
index 4c854fe79134377f012d85648ec9f1117c779e4e..460d6c834c179fe652b2c37b9ceed0d86763a11e 100644 (file)
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.50 2001/02/07 23:35:33 vadim Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.51 2001/03/22 03:59:14 momjian Exp $
  *
  *     NOTES
  *        Postgres btree pages look like ordinary relation pages.      The opaque
@@ -28,7 +28,7 @@
 #include "miscadmin.h"
 #include "storage/lmgr.h"
 
-extern bool FixBTree;  /* comments in nbtree.c */
+extern bool FixBTree;                  /* comments in nbtree.c */
 extern Buffer _bt_fixroot(Relation rel, Buffer oldrootbuf, bool release);
 
 /*
@@ -100,7 +100,7 @@ _bt_metapinit(Relation rel)
  *
  *             The access type parameter (BT_READ or BT_WRITE) controls whether
  *             a new root page will be created or not.  If access = BT_READ,
- *             and no root page exists, we just return InvalidBuffer.  For
+ *             and no root page exists, we just return InvalidBuffer.  For
  *             BT_WRITE, we try to create the root page if it doesn't exist.
  *             NOTE that the returned root page will have only a read lock set
  *             on it even if access = BT_WRITE!
@@ -178,20 +178,20 @@ _bt_getroot(Relation rel, int access)
 
                        /* XLOG stuff */
                        {
-                               xl_btree_newroot        xlrec;
-                               XLogRecPtr                      recptr;
-                               XLogRecData                     rdata;
+                               xl_btree_newroot xlrec;
+                               XLogRecPtr      recptr;
+                               XLogRecData rdata;
 
                                xlrec.node = rel->rd_node;
                                xlrec.level = 1;
                                BlockIdSet(&(xlrec.rootblk), rootblkno);
                                rdata.buffer = InvalidBuffer;
-                               rdata.data = (char*)&xlrec;
+                               rdata.data = (char *) &xlrec;
                                rdata.len = SizeOfBtreeNewroot;
                                rdata.next = NULL;
 
                                recptr = XLogInsert(RM_BTREE_ID,
-                                                       XLOG_BTREE_NEWROOT|XLOG_BTREE_LEAF, &rdata);
+                                                  XLOG_BTREE_NEWROOT | XLOG_BTREE_LEAF, &rdata);
 
                                PageSetLSN(rootpage, recptr);
                                PageSetSUI(rootpage, ThisStartUpID);
@@ -212,6 +212,7 @@ _bt_getroot(Relation rel, int access)
                }
                else
                {
+
                        /*
                         * Metadata initialized by someone else.  In order to
                         * guarantee no deadlocks, we have to release the metadata
@@ -232,30 +233,31 @@ _bt_getroot(Relation rel, int access)
        /*
         * Race condition:      If the root page split between the time we looked
         * at the metadata page and got the root buffer, then we got the wrong
-        * buffer.  Release it and try again.
+        * buffer.      Release it and try again.
         */
        rootpage = BufferGetPage(rootbuf);
        rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
 
-       if (! P_ISROOT(rootopaque))
+       if (!P_ISROOT(rootopaque))
        {
+
                /*
-                * It happened, but if root page splitter failed to create
-                * new root page then we'll go in loop trying to call
-                * _bt_getroot again and again.
+                * It happened, but if root page splitter failed to create new
+                * root page then we'll go in loop trying to call _bt_getroot
+                * again and again.
                 */
                if (FixBTree)
                {
-                       Buffer  newrootbuf;
+                       Buffer          newrootbuf;
 
-check_parent:;
-                       if (BTreeInvalidParent(rootopaque))     /* unupdated! */
+       check_parent:;
+                       if (BTreeInvalidParent(rootopaque)) /* unupdated! */
                        {
                                LockBuffer(rootbuf, BUFFER_LOCK_UNLOCK);
                                LockBuffer(rootbuf, BT_WRITE);
 
                                /* handle concurrent fix of root page */
-                               if (BTreeInvalidParent(rootopaque))     /* unupdated! */
+                               if (BTreeInvalidParent(rootopaque))             /* unupdated! */
                                {
                                        elog(NOTICE, "bt_getroot[%s]: fixing root page", RelationGetRelationName(rel));
                                        newrootbuf = _bt_fixroot(rel, rootbuf, true);
@@ -266,20 +268,22 @@ check_parent:;
                                        rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
                                        /* New root might be splitted while changing lock */
                                        if (P_ISROOT(rootopaque))
-                                               return(rootbuf);
+                                               return (rootbuf);
                                        /* rootbuf is read locked */
                                        goto check_parent;
                                }
-                               else    /* someone else already fixed root */
+                               else
+/* someone else already fixed root */
                                {
                                        LockBuffer(rootbuf, BUFFER_LOCK_UNLOCK);
                                        LockBuffer(rootbuf, BT_READ);
                                }
                        }
+
                        /*
-                        * Ok, here we have old root page with btpo_parent pointing
-                        * to upper level - check parent page because of there is
-                        * good chance that parent is root page.
+                        * Ok, here we have old root page with btpo_parent pointing to
+                        * upper level - check parent page because of there is good
+                        * chance that parent is root page.
                         */
                        newrootbuf = _bt_getbuf(rel, rootopaque->btpo_parent, BT_READ);
                        _bt_relbuf(rel, rootbuf, BT_READ);
@@ -287,7 +291,7 @@ check_parent:;
                        rootpage = BufferGetPage(rootbuf);
                        rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
                        if (P_ISROOT(rootopaque))
-                               return(rootbuf);
+                               return (rootbuf);
                        /* no luck -:( */
                }
 
@@ -366,7 +370,7 @@ _bt_relbuf(Relation rel, Buffer buf, int access)
  *             and a pin on the buffer.
  *
  * NOTE: actually, the buffer manager just marks the shared buffer page
- * dirty here, the real I/O happens later.  Since we can't persuade the
+ * dirty here, the real I/O happens later.     Since we can't persuade the
  * Unix kernel to schedule disk writes in a particular order, there's not
  * much point in worrying about this.  The most we can say is that all the
  * writes will occur before commit.
@@ -468,14 +472,14 @@ _bt_pagedel(Relation rel, ItemPointer tid)
        PageIndexTupleDelete(page, offno);
        /* XLOG stuff */
        {
-               xl_btree_delete xlrec;
-               XLogRecPtr              recptr;
-               XLogRecData             rdata[2];
+               xl_btree_delete xlrec;
+               XLogRecPtr      recptr;
+               XLogRecData rdata[2];
 
                xlrec.target.node = rel->rd_node;
                xlrec.target.tid = *tid;
                rdata[0].buffer = InvalidBuffer;
-               rdata[0].data = (char*)&xlrec;
+               rdata[0].data = (char *) &xlrec;
                rdata[0].len = SizeOfBtreeDelete;
                rdata[0].next = &(rdata[1]);
 
index f02dfcbd128b57f7702f4c85efc07f98479b7a7a..97d99da4fde7bbbfe009c7c7baf04dc557390cd9 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.78 2001/02/07 23:35:33 vadim Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtree.c,v 1.79 2001/03/22 03:59:15 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -30,7 +30,8 @@
 
 bool           BuildingBtree = false;          /* see comment in btbuild() */
 bool           FastBuild = true;       /* use sort/build instead */
-                                                               /* of insertion build */
+
+ /* of insertion build */
 
 
 /*
@@ -52,12 +53,14 @@ static void _bt_restscan(IndexScanDesc scan);
 Datum
 btbuild(PG_FUNCTION_ARGS)
 {
-       Relation                heap = (Relation) PG_GETARG_POINTER(0);
-       Relation                index = (Relation) PG_GETARG_POINTER(1);
-       IndexInfo          *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
-       Node               *oldPred = (Node *) PG_GETARG_POINTER(3);
+       Relation        heap = (Relation) PG_GETARG_POINTER(0);
+       Relation        index = (Relation) PG_GETARG_POINTER(1);
+       IndexInfo  *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
+       Node       *oldPred = (Node *) PG_GETARG_POINTER(3);
+
 #ifdef NOT_USED
-       IndexStrategy   istrat = (IndexStrategy) PG_GETARG_POINTER(4);
+       IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
+
 #endif
        HeapScanDesc hscan;
        HeapTuple       htup;
@@ -69,9 +72,11 @@ btbuild(PG_FUNCTION_ARGS)
        int                     nhtups,
                                nitups;
        Node       *pred = indexInfo->ii_Predicate;
+
 #ifndef OMIT_PARTIAL_INDEX
        TupleTable      tupleTable;
        TupleTableSlot *slot;
+
 #endif
        ExprContext *econtext;
        InsertIndexResult res = NULL;
@@ -79,15 +84,16 @@ btbuild(PG_FUNCTION_ARGS)
        BTItem          btitem;
        bool            usefast;
        Snapshot        snapshot;
-       TransactionId   XmaxRecent;
+       TransactionId XmaxRecent;
+
        /*
-        * spool2 is needed only when the index is an unique index.
-        * Dead tuples are put into spool2 instead of spool in
-        * order to avoid uniqueness check.
+        * spool2 is needed only when the index is an unique index. Dead
+        * tuples are put into spool2 instead of spool in order to avoid
+        * uniqueness check.
         */
-       BTSpool         *spool2 = NULL;
+       BTSpool    *spool2 = NULL;
        bool            tupleIsAlive;
-       int             dead_count;
+       int                     dead_count;
 
        /* note that this is a new btree */
        BuildingBtree = true;
@@ -103,7 +109,7 @@ btbuild(PG_FUNCTION_ARGS)
 #ifdef BTREE_BUILD_STATS
        if (Show_btree_build_stats)
                ResetUsage();
-#endif /* BTREE_BUILD_STATS */
+#endif  /* BTREE_BUILD_STATS */
 
        /* initialize the btree index metadata page (if this is a new index) */
        if (oldPred == NULL)
@@ -155,10 +161,10 @@ btbuild(PG_FUNCTION_ARGS)
        if (usefast)
        {
                spool = _bt_spoolinit(index, indexInfo->ii_Unique);
+
                /*
-                * Different from spool,the uniqueness isn't checked
-                * for spool2.
-                */
+                * Different from spool,the uniqueness isn't checked for spool2.
+                */
                if (indexInfo->ii_Unique)
                        spool2 = _bt_spoolinit(index, false);
        }
@@ -187,12 +193,13 @@ btbuild(PG_FUNCTION_ARGS)
                }
                else
                        tupleIsAlive = true;
-               
+
                MemoryContextReset(econtext->ecxt_per_tuple_memory);
 
                nhtups++;
 
 #ifndef OMIT_PARTIAL_INDEX
+
                /*
                 * If oldPred != NULL, this is an EXTEND INDEX command, so skip
                 * this tuple if it was already in the existing partial index
@@ -253,8 +260,7 @@ btbuild(PG_FUNCTION_ARGS)
                 * btree pages - NULLs greater NOT_NULLs and NULL = NULL is TRUE.
                 * Sure, it's just rule for placing/finding items and no more -
                 * keytest'll return FALSE for a = 5 for items having 'a' isNULL.
-                * Look at _bt_compare for how it works.
-                *                               - vadim 03/23/97
+                * Look at _bt_compare for how it works. - vadim 03/23/97
                 *
                 * if (itup->t_info & INDEX_NULL_MASK) { pfree(itup); continue; }
                 */
@@ -271,7 +277,8 @@ btbuild(PG_FUNCTION_ARGS)
                {
                        if (tupleIsAlive || !spool2)
                                _bt_spool(btitem, spool);
-                       else /* dead tuples are put into spool2 */
+                       else
+/* dead tuples are put into spool2 */
                        {
                                dead_count++;
                                _bt_spool(btitem, spool2);
@@ -288,7 +295,7 @@ btbuild(PG_FUNCTION_ARGS)
 
        /* okay, all heap tuples are indexed */
        heap_endscan(hscan);
-       if (spool2 && !dead_count) /* spool2 was found to be unnecessary */
+       if (spool2 && !dead_count)      /* spool2 was found to be unnecessary */
        {
                _bt_spooldestroy(spool2);
                spool2 = NULL;
@@ -296,9 +303,7 @@ btbuild(PG_FUNCTION_ARGS)
 
 #ifndef OMIT_PARTIAL_INDEX
        if (pred != NULL || oldPred != NULL)
-       {
                ExecDropTupleTable(tupleTable, true);
-       }
 #endif  /* OMIT_PARTIAL_INDEX */
        FreeExprContext(econtext);
 
@@ -322,7 +327,7 @@ btbuild(PG_FUNCTION_ARGS)
                ShowUsage();
                ResetUsage();
        }
-#endif /* BTREE_BUILD_STATS */
+#endif  /* BTREE_BUILD_STATS */
 
        /*
         * Since we just counted the tuples in the heap, we update its stats
@@ -368,11 +373,11 @@ btbuild(PG_FUNCTION_ARGS)
 Datum
 btinsert(PG_FUNCTION_ARGS)
 {
-       Relation                rel = (Relation) PG_GETARG_POINTER(0);
-       Datum              *datum = (Datum *) PG_GETARG_POINTER(1);
-       char               *nulls = (char *) PG_GETARG_POINTER(2);
-       ItemPointer             ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
-       Relation                heapRel = (Relation) PG_GETARG_POINTER(4);
+       Relation        rel = (Relation) PG_GETARG_POINTER(0);
+       Datum      *datum = (Datum *) PG_GETARG_POINTER(1);
+       char       *nulls = (char *) PG_GETARG_POINTER(2);
+       ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
+       Relation        heapRel = (Relation) PG_GETARG_POINTER(4);
        InsertIndexResult res;
        BTItem          btitem;
        IndexTuple      itup;
@@ -396,8 +401,8 @@ btinsert(PG_FUNCTION_ARGS)
 Datum
 btgettuple(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc           scan = (IndexScanDesc) PG_GETARG_POINTER(0);
-       ScanDirection           dir = (ScanDirection) PG_GETARG_INT32(1);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       ScanDirection dir = (ScanDirection) PG_GETARG_INT32(1);
        RetrieveIndexResult res;
 
        /*
@@ -408,10 +413,11 @@ btgettuple(PG_FUNCTION_ARGS)
 
        if (ItemPointerIsValid(&(scan->currentItemData)))
        {
+
                /*
                 * Restore scan position using heap TID returned by previous call
-                * to btgettuple(). _bt_restscan() re-grabs the read lock on
-                * the buffer, too.
+                * to btgettuple(). _bt_restscan() re-grabs the read lock on the
+                * buffer, too.
                 */
                _bt_restscan(scan);
                res = _bt_next(scan, dir);
@@ -421,8 +427,8 @@ btgettuple(PG_FUNCTION_ARGS)
 
        /*
         * Save heap TID to use it in _bt_restscan.  Then release the read
-        * lock on the buffer so that we aren't blocking other backends.
-        * NOTE: we do keep the pin on the buffer!
+        * lock on the buffer so that we aren't blocking other backends. NOTE:
+        * we do keep the pin on the buffer!
         */
        if (res)
        {
@@ -461,11 +467,13 @@ btbeginscan(PG_FUNCTION_ARGS)
 Datum
 btrescan(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+
 #ifdef NOT_USED                                        /* XXX surely it's wrong to ignore this? */
-       bool                    fromEnd = PG_GETARG_BOOL(1);
+       bool            fromEnd = PG_GETARG_BOOL(1);
+
 #endif
-       ScanKey                 scankey = (ScanKey) PG_GETARG_POINTER(2);
+       ScanKey         scankey = (ScanKey) PG_GETARG_POINTER(2);
        ItemPointer iptr;
        BTScanOpaque so;
 
@@ -540,7 +548,7 @@ btmovescan(IndexScanDesc scan, Datum v)
 Datum
 btendscan(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
        ItemPointer iptr;
        BTScanOpaque so;
 
@@ -578,7 +586,7 @@ btendscan(PG_FUNCTION_ARGS)
 Datum
 btmarkpos(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
        ItemPointer iptr;
        BTScanOpaque so;
 
@@ -610,7 +618,7 @@ btmarkpos(PG_FUNCTION_ARGS)
 Datum
 btrestrpos(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   scan = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0);
        ItemPointer iptr;
        BTScanOpaque so;
 
@@ -640,8 +648,8 @@ btrestrpos(PG_FUNCTION_ARGS)
 Datum
 btdelete(PG_FUNCTION_ARGS)
 {
-       Relation                rel = (Relation) PG_GETARG_POINTER(0);
-       ItemPointer             tid = (ItemPointer) PG_GETARG_POINTER(1);
+       Relation        rel = (Relation) PG_GETARG_POINTER(0);
+       ItemPointer tid = (ItemPointer) PG_GETARG_POINTER(1);
 
        /* adjust any active scans that will be affected by this deletion */
        _bt_adjscans(rel, tid);
@@ -671,8 +679,8 @@ _bt_restscan(IndexScanDesc scan)
        BlockNumber blkno;
 
        /*
-        * Get back the read lock we were holding on the buffer.
-        * (We still have a reference-count pin on it, though.)
+        * Get back the read lock we were holding on the buffer. (We still
+        * have a reference-count pin on it, though.)
         */
        LockBuffer(buf, BT_READ);
 
@@ -689,13 +697,13 @@ _bt_restscan(IndexScanDesc scan)
        if (!ItemPointerIsValid(&target))
        {
                ItemPointerSetOffsetNumber(current,
-                                                                  OffsetNumberPrev(P_FIRSTDATAKEY(opaque)));
+                                                          OffsetNumberPrev(P_FIRSTDATAKEY(opaque)));
                return;
        }
 
        /*
-        * The item we were on may have moved right due to insertions.
-        * Find it again.
+        * The item we were on may have moved right due to insertions. Find it
+        * again.
         */
        for (;;)
        {
@@ -717,7 +725,8 @@ _bt_restscan(IndexScanDesc scan)
                }
 
                /*
-                * By here, the item we're looking for moved right at least one page
+                * By here, the item we're looking for moved right at least one
+                * page
                 */
                if (P_RIGHTMOST(opaque))
                        elog(FATAL, "_bt_restscan: my bits moved right off the end of the world!"
@@ -742,14 +751,14 @@ _bt_restore_page(Page page, char *from, int len)
        Size            itemsz;
        char       *end = from + len;
 
-       for ( ; from < end; )
+       for (; from < end;)
        {
                memcpy(&btdata, from, sizeof(BTItemData));
                itemsz = IndexTupleDSize(btdata.bti_itup) +
-                                       (sizeof(BTItemData) - sizeof(IndexTupleData));
+                       (sizeof(BTItemData) - sizeof(IndexTupleData));
                itemsz = MAXALIGN(itemsz);
                if (PageAddItem(page, (Item) from, itemsz,
-                               FirstOffsetNumber, LP_USED) == InvalidOffsetNumber)
+                                         FirstOffsetNumber, LP_USED) == InvalidOffsetNumber)
                        elog(STOP, "_bt_restore_page: can't add item to page");
                from += itemsz;
        }
@@ -758,20 +767,20 @@ _bt_restore_page(Page page, char *from, int len)
 static void
 btree_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
 {
-       xl_btree_delete    *xlrec;
-       Relation                        reln;
-       Buffer                          buffer;
-       Page                            page;
+       xl_btree_delete *xlrec;
+       Relation        reln;
+       Buffer          buffer;
+       Page            page;
 
        if (!redo || (record->xl_info & XLR_BKP_BLOCK_1))
                return;
 
-       xlrec = (xl_btree_delete*) XLogRecGetData(record);
+       xlrec = (xl_btree_delete *) XLogRecGetData(record);
        reln = XLogOpenRelation(redo, RM_BTREE_ID, xlrec->target.node);
        if (!RelationIsValid(reln))
                return;
-       buffer = XLogReadBuffer(false, reln, 
-                               ItemPointerGetBlockNumber(&(xlrec->target.tid)));
+       buffer = XLogReadBuffer(false, reln,
+                                               ItemPointerGetBlockNumber(&(xlrec->target.tid)));
        if (!BufferIsValid(buffer))
                elog(STOP, "btree_delete_redo: block unfound");
        page = (Page) BufferGetPage(buffer);
@@ -796,21 +805,21 @@ btree_xlog_delete(bool redo, XLogRecPtr lsn, XLogRecord *record)
 static void
 btree_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
 {
-       xl_btree_insert    *xlrec;
-       Relation                        reln;
-       Buffer                          buffer;
-       Page                            page;
-       BTPageOpaque            pageop;
+       xl_btree_insert *xlrec;
+       Relation        reln;
+       Buffer          buffer;
+       Page            page;
+       BTPageOpaque pageop;
 
        if (redo && (record->xl_info & XLR_BKP_BLOCK_1))
                return;
 
-       xlrec = (xl_btree_insert*) XLogRecGetData(record);
+       xlrec = (xl_btree_insert *) XLogRecGetData(record);
        reln = XLogOpenRelation(redo, RM_BTREE_ID, xlrec->target.node);
        if (!RelationIsValid(reln))
                return;
-       buffer = XLogReadBuffer(false, reln, 
-                               ItemPointerGetBlockNumber(&(xlrec->target.tid)));
+       buffer = XLogReadBuffer(false, reln,
+                                               ItemPointerGetBlockNumber(&(xlrec->target.tid)));
        if (!BufferIsValid(buffer))
                elog(STOP, "btree_insert_%sdo: block unfound", (redo) ? "re" : "un");
        page = (Page) BufferGetPage(buffer);
@@ -825,11 +834,11 @@ btree_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
                        UnlockAndReleaseBuffer(buffer);
                        return;
                }
-               if (PageAddItem(page, (Item)((char*)xlrec + SizeOfBtreeInsert),
-                                       record->xl_len - SizeOfBtreeInsert,
-                                       ItemPointerGetOffsetNumber(&(xlrec->target.tid)),       
-                                       LP_USED) == InvalidOffsetNumber)
-                               elog(STOP, "btree_insert_redo: failed to add item");
+               if (PageAddItem(page, (Item) ((char *) xlrec + SizeOfBtreeInsert),
+                                               record->xl_len - SizeOfBtreeInsert,
+                                               ItemPointerGetOffsetNumber(&(xlrec->target.tid)),
+                                               LP_USED) == InvalidOffsetNumber)
+                       elog(STOP, "btree_insert_redo: failed to add item");
 
                PageSetLSN(page, lsn);
                PageSetSUI(page, ThisStartUpID);
@@ -840,7 +849,7 @@ btree_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
                if (XLByteLT(PageGetLSN(page), lsn))
                        elog(STOP, "btree_insert_undo: bad page LSN");
 
-               if (! P_ISLEAF(pageop))
+               if (!P_ISLEAF(pageop))
                {
                        UnlockAndReleaseBuffer(buffer);
                        return;
@@ -855,14 +864,14 @@ btree_xlog_insert(bool redo, XLogRecPtr lsn, XLogRecord *record)
 static void
 btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
 {
-       xl_btree_split     *xlrec = (xl_btree_split*) XLogRecGetData(record);
-       Relation                        reln;
-       BlockNumber                     blkno;
-       Buffer                          buffer;
-       Page                            page;
-       BTPageOpaque            pageop;
-       char                       *op = (redo) ? "redo" : "undo";
-       bool                            isleaf = (record->xl_info & XLOG_BTREE_LEAF);
+       xl_btree_split *xlrec = (xl_btree_split *) XLogRecGetData(record);
+       Relation        reln;
+       BlockNumber blkno;
+       Buffer          buffer;
+       Page            page;
+       BTPageOpaque pageop;
+       char       *op = (redo) ? "redo" : "undo";
+       bool            isleaf = (record->xl_info & XLOG_BTREE_LEAF);
 
        reln = XLogOpenRelation(redo, RM_BTREE_ID, xlrec->target.node);
        if (!RelationIsValid(reln))
@@ -870,7 +879,7 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
 
        /* Left (original) sibling */
        blkno = (onleft) ? ItemPointerGetBlockNumber(&(xlrec->target.tid)) :
-                                       BlockIdGetBlockNumber(&(xlrec->otherblk));
+               BlockIdGetBlockNumber(&(xlrec->otherblk));
        buffer = XLogReadBuffer(false, reln, blkno);
        if (!BufferIsValid(buffer))
                elog(STOP, "btree_split_%s: lost left sibling", op);
@@ -892,13 +901,14 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
                        pageop->btpo_next = ItemPointerGetBlockNumber(&(xlrec->target.tid));
                pageop->btpo_flags = (isleaf) ? BTP_LEAF : 0;
 
-               _bt_restore_page(page, (char*)xlrec + SizeOfBtreeSplit, xlrec->leftlen);
+               _bt_restore_page(page, (char *) xlrec + SizeOfBtreeSplit, xlrec->leftlen);
 
                PageSetLSN(page, lsn);
                PageSetSUI(page, ThisStartUpID);
                UnlockAndWriteBuffer(buffer);
        }
-       else    /* undo */
+       else
+/* undo */
        {
                if (XLByteLT(PageGetLSN(page), lsn))
                        elog(STOP, "btree_split_undo: bad left sibling LSN");
@@ -906,8 +916,8 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
        }
 
        /* Right (new) sibling */
-       blkno = (onleft) ? BlockIdGetBlockNumber(&(xlrec->otherblk)) : 
-                                       ItemPointerGetBlockNumber(&(xlrec->target.tid));
+       blkno = (onleft) ? BlockIdGetBlockNumber(&(xlrec->otherblk)) :
+               ItemPointerGetBlockNumber(&(xlrec->target.tid));
        buffer = XLogReadBuffer((redo) ? true : false, reln, blkno);
        if (!BufferIsValid(buffer))
                elog(STOP, "btree_split_%s: lost right sibling", op);
@@ -922,21 +932,22 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
        if (redo)
        {
                pageop->btpo_parent = BlockIdGetBlockNumber(&(xlrec->parentblk));
-               pageop->btpo_prev = (onleft) ? 
-                               ItemPointerGetBlockNumber(&(xlrec->target.tid)) :
-                               BlockIdGetBlockNumber(&(xlrec->otherblk));
+               pageop->btpo_prev = (onleft) ?
+                       ItemPointerGetBlockNumber(&(xlrec->target.tid)) :
+                       BlockIdGetBlockNumber(&(xlrec->otherblk));
                pageop->btpo_next = BlockIdGetBlockNumber(&(xlrec->rightblk));
                pageop->btpo_flags = (isleaf) ? BTP_LEAF : 0;
 
                _bt_restore_page(page,
-                               (char*)xlrec + SizeOfBtreeSplit + xlrec->leftlen,
-                               record->xl_len - SizeOfBtreeSplit - xlrec->leftlen);
+                                         (char *) xlrec + SizeOfBtreeSplit + xlrec->leftlen,
+                                        record->xl_len - SizeOfBtreeSplit - xlrec->leftlen);
 
                PageSetLSN(page, lsn);
                PageSetSUI(page, ThisStartUpID);
                UnlockAndWriteBuffer(buffer);
        }
-       else    /* undo */
+       else
+/* undo */
        {
                if (XLByteLT(PageGetLSN(page), lsn))
                        elog(STOP, "btree_split_undo: bad right sibling LSN");
@@ -965,9 +976,9 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
                return;
        }
        pageop = (BTPageOpaque) PageGetSpecialPointer(page);
-       pageop->btpo_prev = (onleft) ? 
-                       BlockIdGetBlockNumber(&(xlrec->otherblk)) :
-                       ItemPointerGetBlockNumber(&(xlrec->target.tid));
+       pageop->btpo_prev = (onleft) ?
+               BlockIdGetBlockNumber(&(xlrec->otherblk)) :
+               ItemPointerGetBlockNumber(&(xlrec->target.tid));
 
        PageSetLSN(page, lsn);
        PageSetSUI(page, ThisStartUpID);
@@ -977,14 +988,14 @@ btree_xlog_split(bool redo, bool onleft, XLogRecPtr lsn, XLogRecord *record)
 static void
 btree_xlog_newroot(bool redo, XLogRecPtr lsn, XLogRecord *record)
 {
-       xl_btree_newroot   *xlrec = (xl_btree_newroot*) XLogRecGetData(record);
-       Relation                        reln;
-       Buffer                          buffer;
-       Page                            page;
-       BTPageOpaque            pageop;
-       Buffer                          metabuf;
-       Page                            metapg;
-       BTMetaPageData          md;
+       xl_btree_newroot *xlrec = (xl_btree_newroot *) XLogRecGetData(record);
+       Relation        reln;
+       Buffer          buffer;
+       Page            page;
+       BTPageOpaque pageop;
+       Buffer          metabuf;
+       Page            metapg;
+       BTMetaPageData md;
 
        if (!redo)
                return;
@@ -1011,8 +1022,8 @@ btree_xlog_newroot(bool redo, XLogRecPtr lsn, XLogRecord *record)
 
        if (record->xl_len > SizeOfBtreeNewroot)
                _bt_restore_page(page,
-                               (char*)xlrec + SizeOfBtreeNewroot,
-                               record->xl_len - SizeOfBtreeNewroot);
+                                                (char *) xlrec + SizeOfBtreeNewroot,
+                                                record->xl_len - SizeOfBtreeNewroot);
 
        PageSetLSN(page, lsn);
        PageSetSUI(page, ThisStartUpID);
@@ -1037,7 +1048,7 @@ btree_xlog_newroot(bool redo, XLogRecPtr lsn, XLogRecord *record)
 void
 btree_redo(XLogRecPtr lsn, XLogRecord *record)
 {
-       uint8   info = record->xl_info & ~XLR_INFO_MASK;
+       uint8           info = record->xl_info & ~XLR_INFO_MASK;
 
        info &= ~XLOG_BTREE_LEAF;
        if (info == XLOG_BTREE_DELETE)
@@ -1045,9 +1056,9 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record)
        else if (info == XLOG_BTREE_INSERT)
                btree_xlog_insert(true, lsn, record);
        else if (info == XLOG_BTREE_SPLIT)
-               btree_xlog_split(true, false, lsn, record);     /* new item on the right */
+               btree_xlog_split(true, false, lsn, record);             /* new item on the right */
        else if (info == XLOG_BTREE_SPLEFT)
-               btree_xlog_split(true, true, lsn, record);      /* new item on the left */
+               btree_xlog_split(true, true, lsn, record);              /* new item on the left */
        else if (info == XLOG_BTREE_NEWROOT)
                btree_xlog_newroot(true, lsn, record);
        else
@@ -1057,7 +1068,7 @@ btree_redo(XLogRecPtr lsn, XLogRecord *record)
 void
 btree_undo(XLogRecPtr lsn, XLogRecord *record)
 {
-       uint8   info = record->xl_info & ~XLR_INFO_MASK;
+       uint8           info = record->xl_info & ~XLR_INFO_MASK;
 
        info &= ~XLOG_BTREE_LEAF;
        if (info == XLOG_BTREE_DELETE)
@@ -1065,9 +1076,9 @@ btree_undo(XLogRecPtr lsn, XLogRecord *record)
        else if (info == XLOG_BTREE_INSERT)
                btree_xlog_insert(false, lsn, record);
        else if (info == XLOG_BTREE_SPLIT)
-               btree_xlog_split(false, false, lsn, record);/* new item on the right */
+               btree_xlog_split(false, false, lsn, record);    /* new item on the right */
        else if (info == XLOG_BTREE_SPLEFT)
-               btree_xlog_split(false, true, lsn, record);     /* new item on the left */
+               btree_xlog_split(false, true, lsn, record);             /* new item on the left */
        else if (info == XLOG_BTREE_NEWROOT)
                btree_xlog_newroot(false, lsn, record);
        else
@@ -1078,45 +1089,49 @@ static void
 out_target(char *buf, xl_btreetid *target)
 {
        sprintf(buf + strlen(buf), "node %u/%u; tid %u/%u",
-               target->node.tblNode, target->node.relNode,
-               ItemPointerGetBlockNumber(&(target->tid)), 
-               ItemPointerGetOffsetNumber(&(target->tid)));
+                       target->node.tblNode, target->node.relNode,
+                       ItemPointerGetBlockNumber(&(target->tid)),
+                       ItemPointerGetOffsetNumber(&(target->tid)));
 }
+
 void
-btree_desc(char *buf, uint8 xl_info, charrec)
+btree_desc(char *buf, uint8 xl_info, char *rec)
 {
-       uint8   info = xl_info & ~XLR_INFO_MASK;
+       uint8           info = xl_info & ~XLR_INFO_MASK;
 
        info &= ~XLOG_BTREE_LEAF;
        if (info == XLOG_BTREE_INSERT)
        {
-               xl_btree_insert *xlrec = (xl_btree_insert*) rec;
+               xl_btree_insert *xlrec = (xl_btree_insert *) rec;
+
                strcat(buf, "insert: ");
                out_target(buf, &(xlrec->target));
        }
        else if (info == XLOG_BTREE_DELETE)
        {
-               xl_btree_delete *xlrec = (xl_btree_delete*) rec;
+               xl_btree_delete *xlrec = (xl_btree_delete *) rec;
+
                strcat(buf, "delete: ");
                out_target(buf, &(xlrec->target));
        }
        else if (info == XLOG_BTREE_SPLIT || info == XLOG_BTREE_SPLEFT)
        {
-               xl_btree_split  *xlrec = (xl_btree_split*) rec;
-               sprintf(buf + strlen(buf), "split(%s): ", 
-                       (info == XLOG_BTREE_SPLIT) ? "right" : "left");
+               xl_btree_split *xlrec = (xl_btree_split *) rec;
+
+               sprintf(buf + strlen(buf), "split(%s): ",
+                               (info == XLOG_BTREE_SPLIT) ? "right" : "left");
                out_target(buf, &(xlrec->target));
                sprintf(buf + strlen(buf), "; oth %u; rgh %u",
-                       BlockIdGetBlockNumber(&xlrec->otherblk),
-                       BlockIdGetBlockNumber(&xlrec->rightblk));
+                               BlockIdGetBlockNumber(&xlrec->otherblk),
+                               BlockIdGetBlockNumber(&xlrec->rightblk));
        }
        else if (info == XLOG_BTREE_NEWROOT)
        {
-               xl_btree_newroot        *xlrec = (xl_btree_newroot*) rec;
+               xl_btree_newroot *xlrec = (xl_btree_newroot *) rec;
+
                sprintf(buf + strlen(buf), "root: node %u/%u; blk %u",
-                       xlrec->node.tblNode, xlrec->node.relNode,
-                       BlockIdGetBlockNumber(&xlrec->rootblk));
+                               xlrec->node.tblNode, xlrec->node.relNode,
+                               BlockIdGetBlockNumber(&xlrec->rootblk));
        }
        else
                strcat(buf, "UNKNOWN");
index 6f41ab9c847e6ff5faa83f2ffade653b325d81bf..d8b8e0682a09f6391bb32f848a361b5466b85b9b 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.63 2001/01/24 19:42:49 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsearch.c,v 1.64 2001/03/22 03:59:15 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -32,20 +32,20 @@ static RetrieveIndexResult _bt_endpoint(IndexScanDesc scan, ScanDirection dir);
  *
  * NOTE that the returned buffer is read-locked regardless of the access
  * parameter.  However, access = BT_WRITE will allow an empty root page
- * to be created and returned.  When access = BT_READ, an empty index
+ * to be created and returned. When access = BT_READ, an empty index
  * will result in *bufP being set to InvalidBuffer.
  */
 BTStack
 _bt_search(Relation rel, int keysz, ScanKey scankey,
                   Buffer *bufP, int access)
 {
-       BTStack stack_in = NULL;
+       BTStack         stack_in = NULL;
 
        /* Get the root page to start with */
        *bufP = _bt_getroot(rel, access);
 
        /* If index is empty and access = BT_READ, no root page is created. */
-       if (! BufferIsValid(*bufP))
+       if (!BufferIsValid(*bufP))
                return (BTStack) NULL;
 
        /* Loop iterates once per level descended in the tree */
@@ -79,13 +79,13 @@ _bt_search(Relation rel, int keysz, ScanKey scankey,
                par_blkno = BufferGetBlockNumber(*bufP);
 
                /*
-                * We need to save the bit image of the index entry we chose in the
-                * parent page on a stack. In case we split the tree, we'll use this
-                * bit image to figure out what our real parent page is, in case the
-                * parent splits while we're working lower in the tree.  See the paper
-                * by Lehman and Yao for how this is detected and handled. (We use the
-                * child link to disambiguate duplicate keys in the index -- Lehman
-                * and Yao disallow duplicate keys.)
+                * We need to save the bit image of the index entry we chose in
+                * the parent page on a stack. In case we split the tree, we'll
+                * use this bit image to figure out what our real parent page is,
+                * in case the parent splits while we're working lower in the
+                * tree.  See the paper by Lehman and Yao for how this is detected
+                * and handled. (We use the child link to disambiguate duplicate
+                * keys in the index -- Lehman and Yao disallow duplicate keys.)
                 */
                new_stack = (BTStack) palloc(sizeof(BTStackData));
                new_stack->bts_blkno = par_blkno;
@@ -98,9 +98,9 @@ _bt_search(Relation rel, int keysz, ScanKey scankey,
                *bufP = _bt_getbuf(rel, blkno, BT_READ);
 
                /*
-                * Race -- the page we just grabbed may have split since we read its
-                * pointer in the parent.  If it has, we may need to move right to its
-                * new sibling.  Do that.
+                * Race -- the page we just grabbed may have split since we read
+                * its pointer in the parent.  If it has, we may need to move
+                * right to its new sibling.  Do that.
                 */
                *bufP = _bt_moveright(rel, *bufP, keysz, scankey, BT_READ);
 
@@ -127,7 +127,7 @@ _bt_search(Relation rel, int keysz, ScanKey scankey,
  *
  *             On entry, we have the buffer pinned and a lock of the proper type.
  *             If we move right, we release the buffer and lock and acquire the
- *             same on the right sibling.  Return value is the buffer we stop at.
+ *             same on the right sibling.      Return value is the buffer we stop at.
  */
 Buffer
 _bt_moveright(Relation rel,
@@ -153,7 +153,7 @@ _bt_moveright(Relation rel,
                   _bt_compare(rel, keysz, scankey, page, P_HIKEY) > 0)
        {
                /* step right one page */
-               BlockNumber             rblkno = opaque->btpo_next;
+               BlockNumber rblkno = opaque->btpo_next;
 
                _bt_relbuf(rel, buf, access);
                buf = _bt_getbuf(rel, rblkno, access);
@@ -184,7 +184,7 @@ _bt_moveright(Relation rel,
  * find all leaf keys >= given scankey.
  *
  * This procedure is not responsible for walking right, it just examines
- * the given page.  _bt_binsrch() has no lock or refcount side effects
+ * the given page.     _bt_binsrch() has no lock or refcount side effects
  * on the buffer.
  */
 OffsetNumber
@@ -299,7 +299,7 @@ _bt_compare(Relation rel,
         * Force result ">" if target item is first data item on an internal
         * page --- see NOTE above.
         */
-       if (! P_ISLEAF(opaque) && offnum == P_FIRSTDATAKEY(opaque))
+       if (!P_ISLEAF(opaque) && offnum == P_FIRSTDATAKEY(opaque))
                return 1;
 
        btitem = (BTItem) PageGetItem(page, PageGetItemId(page, offnum));
@@ -327,7 +327,7 @@ _bt_compare(Relation rel,
                datum = index_getattr(itup, entry->sk_attno, itupdesc, &isNull);
 
                /* see comments about NULLs handling in btbuild */
-               if (entry->sk_flags & SK_ISNULL)        /* key is NULL */
+               if (entry->sk_flags & SK_ISNULL)                /* key is NULL */
                {
                        if (isNull)
                                result = 0;             /* NULL "=" NULL */
@@ -458,10 +458,10 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
        _bt_orderkeys(rel, so);
 
        /*
-        * Quit now if _bt_orderkeys() discovered that the scan keys can
-        * never be satisfied (eg, x == 1 AND x > 2).
+        * Quit now if _bt_orderkeys() discovered that the scan keys can never
+        * be satisfied (eg, x == 1 AND x > 2).
         */
-       if (! so->qual_ok)
+       if (!so->qual_ok)
                return (RetrieveIndexResult) NULL;
 
        /*
@@ -484,17 +484,16 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
                                break;
                        strat = _bt_getstrat(rel, attno,
                                                                 so->keyData[i].sk_procedure);
+
                        /*
                         * Can we use this key as a starting boundary for this attr?
                         *
-                        * We can use multiple keys if they look like, say, = >= =
-                        * but we have to stop after accepting a > or < boundary.
+                        * We can use multiple keys if they look like, say, = >= = but we
+                        * have to stop after accepting a > or < boundary.
                         */
                        if (strat == strat_total ||
                                strat == BTEqualStrategyNumber)
-                       {
                                nKeyIs[keysCount++] = i;
-                       }
                        else if (ScanDirectionIsBackward(dir) &&
                                         (strat == BTLessStrategyNumber ||
                                          strat == BTLessEqualStrategyNumber))
@@ -536,7 +535,11 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
        for (i = 0; i < keysCount; i++)
        {
                j = nKeyIs[i];
-               /* _bt_orderkeys disallows it, but it's place to add some code later */
+
+               /*
+                * _bt_orderkeys disallows it, but it's place to add some code
+                * later
+                */
                if (so->keyData[j].sk_flags & SK_ISNULL)
                {
                        pfree(nKeyIs);
@@ -562,7 +565,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
        /* don't need to keep the stack around... */
        _bt_freestack(stack);
 
-       if (! BufferIsValid(buf))
+       if (!BufferIsValid(buf))
        {
                /* Only get here if index is completely empty */
                ItemPointerSetInvalid(current);
@@ -601,6 +604,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
        switch (strat_total)
        {
                case BTLessStrategyNumber:
+
                        /*
                         * Back up one to arrive at last item < scankey
                         */
@@ -612,6 +616,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
                        break;
 
                case BTLessEqualStrategyNumber:
+
                        /*
                         * We need to find the last item <= scankey, so step forward
                         * till we find one > scankey, then step back one.
@@ -645,9 +650,10 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
                        break;
 
                case BTEqualStrategyNumber:
+
                        /*
-                        * Make sure we are on the first equal item; might have to step
-                        * forward if currently at end of page.
+                        * Make sure we are on the first equal item; might have to
+                        * step forward if currently at end of page.
                         */
                        if (offnum > PageGetMaxOffsetNumber(page))
                        {
@@ -661,7 +667,8 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
                        }
                        result = _bt_compare(rel, keysCount, scankeys, page, offnum);
                        if (result != 0)
-                               goto nomatches; /* no equal items! */
+                               goto nomatches; /* no equal items! */
+
                        /*
                         * If a backward scan was specified, need to start with last
                         * equal item not first one.
@@ -685,6 +692,7 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
                        break;
 
                case BTGreaterEqualStrategyNumber:
+
                        /*
                         * We want the first item >= scankey, which is where we are...
                         * unless we're not anywhere at all...
@@ -700,9 +708,10 @@ _bt_first(IndexScanDesc scan, ScanDirection dir)
                        break;
 
                case BTGreaterStrategyNumber:
+
                        /*
-                        * We want the first item > scankey, so make sure we are on
-                        * an item and then step over any equal items.
+                        * We want the first item > scankey, so make sure we are on an
+                        * item and then step over any equal items.
                         */
                        if (offnum > PageGetMaxOffsetNumber(page))
                        {
@@ -850,11 +859,12 @@ _bt_step(IndexScanDesc scan, Buffer *bufP, ScanDirection dir)
                                *bufP = _bt_getbuf(rel, blkno, BT_READ);
                                page = BufferGetPage(*bufP);
                                opaque = (BTPageOpaque) PageGetSpecialPointer(page);
+
                                /*
                                 * If the adjacent page just split, then we have to walk
-                                * right to find the block that's now adjacent to where
-                                * we were.  Because pages only split right, we don't have
-                                * to worry about this failing to terminate.
+                                * right to find the block that's now adjacent to where we
+                                * were.  Because pages only split right, we don't have to
+                                * worry about this failing to terminate.
                                 */
                                while (opaque->btpo_next != obknum)
                                {
@@ -912,12 +922,12 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
 
        /*
         * Scan down to the leftmost or rightmost leaf page.  This is a
-        * simplified version of _bt_search().  We don't maintain a stack
+        * simplified version of _bt_search().  We don't maintain a stack
         * since we know we won't need it.
         */
        buf = _bt_getroot(rel, BT_READ);
 
-       if (! BufferIsValid(buf))
+       if (!BufferIsValid(buf))
        {
                /* empty index... */
                ItemPointerSetInvalid(current);
@@ -981,7 +991,8 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
                Assert(P_RIGHTMOST(opaque));
 
                start = PageGetMaxOffsetNumber(page);
-               if (start < P_FIRSTDATAKEY(opaque))     /* watch out for empty page */
+               if (start < P_FIRSTDATAKEY(opaque))             /* watch out for empty
+                                                                                                * page */
                        start = P_FIRSTDATAKEY(opaque);
        }
        else
@@ -995,8 +1006,8 @@ _bt_endpoint(IndexScanDesc scan, ScanDirection dir)
        so->btso_curbuf = buf;
 
        /*
-        * Left/rightmost page could be empty due to deletions,
-        * if so step till we find a nonempty page.
+        * Left/rightmost page could be empty due to deletions, if so step
+        * till we find a nonempty page.
         */
        if (start > maxoff)
        {
index e9224a485afe0937d24391c024bf8416637742e2..2aca6bf7cfc5bc47042dbe0a67211278e34f28b3 100644 (file)
@@ -6,7 +6,7 @@
  *
  * We use tuplesort.c to sort the given index tuples into order.
  * Then we scan the index tuples in order and build the btree pages
- * for each level.  We load source tuples into leaf-level pages.
+ * for each level.     We load source tuples into leaf-level pages.
  * Whenever we fill a page at one level, we add a link to it to its
  * parent level (starting a new parent level if necessary).  When
  * done, we write out each final page on each level, adding it to
@@ -35,7 +35,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.59 2001/01/24 19:42:49 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtsort.c,v 1.60 2001/03/22 03:59:15 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -57,7 +57,7 @@ struct BTSpool
 };
 
 /*
- * Status record for a btree page being built.  We have one of these
+ * Status record for a btree page being built. We have one of these
  * for each active tree level.
  *
  * The reason we need to store a copy of the minimum key is that we'll
@@ -73,11 +73,13 @@ typedef struct BTPageState
 {
        Buffer          btps_buf;               /* current buffer & page */
        Page            btps_page;
-       BTItem          btps_minkey;    /* copy of minimum key (first item) on page */
+       BTItem          btps_minkey;    /* copy of minimum key (first item) on
+                                                                * page */
        OffsetNumber btps_lastoff;      /* last item offset loaded */
        int                     btps_level;             /* tree level (0 = leaf) */
-       Size            btps_full;              /* "full" if less than this much free space */
-       struct BTPageState *btps_next; /* link to parent level, if any */
+       Size            btps_full;              /* "full" if less than this much free
+                                                                * space */
+       struct BTPageState *btps_next;          /* link to parent level, if any */
 } BTPageState;
 
 
@@ -92,7 +94,7 @@ static void _bt_blnewpage(Relation index, Buffer *buf, Page *page, int flags);
 static BTPageState *_bt_pagestate(Relation index, int flags, int level);
 static void _bt_slideleft(Relation index, Buffer buf, Page page);
 static void _bt_sortaddtup(Page page, Size itemsize,
-                                                  BTItem btitem, OffsetNumber itup_off);
+                          BTItem btitem, OffsetNumber itup_off);
 static void _bt_buildadd(Relation index, BTPageState *state, BTItem bti);
 static void _bt_uppershutdown(Relation index, BTPageState *state);
 static void _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2);
@@ -162,7 +164,7 @@ _bt_leafbuild(BTSpool *btspool, BTSpool *btspool2)
                ShowUsage();
                ResetUsage();
        }
-#endif /* BTREE_BUILD_STATS */
+#endif  /* BTREE_BUILD_STATS */
        tuplesort_performsort(btspool->sortstate);
 
        if (btspool2)
@@ -269,9 +271,9 @@ _bt_sortaddtup(Page page,
                           OffsetNumber itup_off)
 {
        BTPageOpaque opaque = (BTPageOpaque) PageGetSpecialPointer(page);
-       BTItemData truncitem;
+       BTItemData      truncitem;
 
-       if (! P_ISLEAF(opaque) && itup_off == P_FIRSTKEY)
+       if (!P_ISLEAF(opaque) && itup_off == P_FIRSTKEY)
        {
                memcpy(&truncitem, btitem, sizeof(BTItemData));
                truncitem.bti_itup.t_info = sizeof(BTItemData);
@@ -290,7 +292,7 @@ _bt_sortaddtup(Page page,
  * We must be careful to observe the page layout conventions of nbtsearch.c:
  * - rightmost pages start data items at P_HIKEY instead of at P_FIRSTKEY.
  * - on non-leaf pages, the key portion of the first item need not be
- *   stored, we should store only the link.
+ *      stored, we should store only the link.
  *
  * A leaf page being built looks like:
  *
@@ -347,11 +349,12 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
         */
        if (btisz > (PageGetPageSize(npage) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) / 3 - sizeof(ItemIdData))
                elog(ERROR, "btree: index item size %lu exceeds maximum %ld",
-                        (unsigned long)btisz,
-                        (PageGetPageSize(npage) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) /3 - sizeof(ItemIdData));
+                        (unsigned long) btisz,
+                        (PageGetPageSize(npage) - sizeof(PageHeaderData) - MAXALIGN(sizeof(BTPageOpaqueData))) / 3 - sizeof(ItemIdData));
 
        if (pgspc < btisz || pgspc < state->btps_full)
        {
+
                /*
                 * Item won't fit on this page, or we feel the page is full enough
                 * already.  Finish off the page and write it out.
@@ -388,9 +391,9 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
                ((PageHeader) opage)->pd_lower -= sizeof(ItemIdData);
 
                /*
-                * Link the old buffer into its parent, using its minimum key.
-                * If we don't have a parent, we have to create one;
-                * this adds a new btree level.
+                * Link the old buffer into its parent, using its minimum key. If
+                * we don't have a parent, we have to create one; this adds a new
+                * btree level.
                 */
                if (state->btps_next == (BTPageState *) NULL)
                {
@@ -405,8 +408,8 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
 
                /*
                 * Save a copy of the minimum key for the new page.  We have to
-                * copy it off the old page, not the new one, in case we are
-                * not at leaf level.
+                * copy it off the old page, not the new one, in case we are not
+                * at leaf level.
                 */
                state->btps_minkey = _bt_formitem(&(obti->bti_itup));
 
@@ -414,13 +417,13 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
                 * Set the sibling links for both pages, and parent links too.
                 *
                 * It's not necessary to set the parent link at all, because it's
-                * only used for handling concurrent root splits, but we may as well
-                * do it as a debugging aid.  Note we set new page's link as well
-                * as old's, because if the new page turns out to be the last of
-                * the level, _bt_uppershutdown won't change it.  The links may be
-                * out of date by the time the build finishes, but that's OK; they
-                * need only point to a left-sibling of the true parent.  See the
-                * README file for more info.
+                * only used for handling concurrent root splits, but we may as
+                * well do it as a debugging aid.  Note we set new page's link as
+                * well as old's, because if the new page turns out to be the last
+                * of the level, _bt_uppershutdown won't change it.  The links may
+                * be out of date by the time the build finishes, but that's OK;
+                * they need only point to a left-sibling of the true parent.  See
+                * the README file for more info.
                 */
                {
                        BTPageOpaque oopaque = (BTPageOpaque) PageGetSpecialPointer(opage);
@@ -434,7 +437,7 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
                }
 
                /*
-                * Write out the old page.  We never want to see it again, so we
+                * Write out the old page.      We never want to see it again, so we
                 * can give up our lock (if we had one; most likely BuildingBtree
                 * is set, so we aren't locking).
                 */
@@ -449,8 +452,8 @@ _bt_buildadd(Relation index, BTPageState *state, BTItem bti)
        /*
         * If the new item is the first for its page, stash a copy for later.
         * Note this will only happen for the first item on a level; on later
-        * pages, the first item for a page is copied from the prior page
-        * in the code above.
+        * pages, the first item for a page is copied from the prior page in
+        * the code above.
         */
        if (last_off == P_HIKEY)
        {
@@ -493,8 +496,8 @@ _bt_uppershutdown(Relation index, BTPageState *state)
                 *
                 * If we're at the top, it's the root, so attach it to the metapage.
                 * Otherwise, add an entry for it to its parent using its minimum
-                * key.  This may cause the last page of the parent level to split,
-                * but that's not a problem -- we haven't gotten to it yet.
+                * key.  This may cause the last page of the parent level to
+                * split, but that's not a problem -- we haven't gotten to it yet.
                 */
                if (s->btps_next == (BTPageState *) NULL)
                {
@@ -513,7 +516,7 @@ _bt_uppershutdown(Relation index, BTPageState *state)
 
                /*
                 * This is the rightmost page, so the ItemId array needs to be
-                * slid back one slot.  Then we can dump out the page.
+                * slid back one slot.  Then we can dump out the page.
                 */
                _bt_slideleft(index, s->btps_buf, s->btps_page);
                _bt_wrtbuf(index, s->btps_buf);
@@ -529,22 +532,29 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
 {
        BTPageState *state = NULL;
        bool            merge = (btspool2 != NULL);
-       BTItem          bti, bti2 = NULL;
-       bool            should_free, should_free2, load1;
+       BTItem          bti,
+                               bti2 = NULL;
+       bool            should_free,
+                               should_free2,
+                               load1;
        TupleDesc       tupdes = RelationGetDescr(index);
-       int             i, keysz = RelationGetNumberOfAttributes(index);
+       int                     i,
+                               keysz = RelationGetNumberOfAttributes(index);
        ScanKey         indexScanKey = NULL;
 
        if (merge)
        {
+
                /*
-                * Another BTSpool for dead tuples exists.
-                * Now we have to merge btspool and btspool2.
-                */
-               ScanKey entry;
-               Datum   attrDatum1, attrDatum2;
-               bool    isFirstNull, isSecondNull;
-               int32   compare;
+                * Another BTSpool for dead tuples exists. Now we have to merge
+                * btspool and btspool2.
+                */
+               ScanKey         entry;
+               Datum           attrDatum1,
+                                       attrDatum2;
+               bool            isFirstNull,
+                                       isSecondNull;
+               int32           compare;
 
                /* the preparation of merge */
                bti = (BTItem) tuplesort_getindextuple(btspool->sortstate, true, &should_free);
@@ -552,7 +562,7 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
                indexScanKey = _bt_mkscankey_nodata(index);
                for (;;)
                {
-                       load1 = true; /* load BTSpool next ? */
+                       load1 = true;           /* load BTSpool next ? */
                        if (NULL == bti2)
                        {
                                if (NULL == bti)
@@ -564,8 +574,8 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
                                for (i = 1; i <= keysz; i++)
                                {
                                        entry = indexScanKey + i - 1;
-                                       attrDatum1 = index_getattr((IndexTuple)bti, i, tupdes, &isFirstNull);
-                                       attrDatum2 = index_getattr((IndexTuple)bti2, i, tupdes, &isSecondNull);
+                                       attrDatum1 = index_getattr((IndexTuple) bti, i, tupdes, &isFirstNull);
+                                       attrDatum2 = index_getattr((IndexTuple) bti2, i, tupdes, &isSecondNull);
                                        if (isFirstNull)
                                        {
                                                if (!isSecondNull)
@@ -586,7 +596,7 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
                                                }
                                                else if (compare < 0)
                                                        break;
-                                       }       
+                                       }
                                }
                        }
                        else
@@ -613,7 +623,8 @@ _bt_load(Relation index, BTSpool *btspool, BTSpool *btspool2)
                }
                _bt_freeskey(indexScanKey);
        }
-       else    /* merge is unnecessary */
+       else
+/* merge is unnecessary */
        {
                while (bti = (BTItem) tuplesort_getindextuple(btspool->sortstate, true, &should_free), bti != (BTItem) NULL)
                {
index 507205f2be781ad0d619710051a01c4c3bf613d0..2a37147d68ec75ba7fe7e954162a2745fe6fd148 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.42 2001/01/24 19:42:49 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtutils.c,v 1.43 2001/03/22 03:59:15 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -124,7 +124,7 @@ _bt_freestack(BTStack stack)
  * Construct a BTItem from a plain IndexTuple.
  *
  * This is now useless code, since a BTItem *is* an index tuple with
- * no extra stuff.  We hang onto it for the moment to preserve the
+ * no extra stuff.     We hang onto it for the moment to preserve the
  * notational distinction, in case we want to add some extra stuff
  * again someday.
  */
@@ -165,7 +165,7 @@ _bt_formitem(IndexTuple itup)
  * are "x = 1 AND y < 4 AND z < 5", then _bt_checkkeys will reject a tuple
  * (1,2,7), but we must continue the scan in case there are tuples (1,3,z).
  * But once we reach tuples like (1,4,z) we can stop scanning because no
- * later tuples could match.  This is reflected by setting 
+ * later tuples could match.  This is reflected by setting
  * so->numberOfRequiredKeys to the number of leading keys that must be
  * matched to continue the scan.  numberOfRequiredKeys is equal to the
  * number of leading "=" keys plus the key(s) for the first non "="
@@ -178,7 +178,7 @@ _bt_formitem(IndexTuple itup)
  *
  * XXX this routine is one of many places that fail to handle SK_COMMUTE
  * scankeys properly.  Currently, the planner is careful never to generate
- * any indexquals that would require SK_COMMUTE to be set.  Someday we ought
+ * any indexquals that would require SK_COMMUTE to be set.     Someday we ought
  * to try to fix this, though it's not real critical as long as indexable
  * operators all have commutators...
  *
@@ -191,7 +191,7 @@ _bt_formitem(IndexTuple itup)
 void
 _bt_orderkeys(Relation relation, BTScanOpaque so)
 {
-       ScanKeyData     xform[BTMaxStrategyNumber];
+       ScanKeyData xform[BTMaxStrategyNumber];
        bool            init[BTMaxStrategyNumber];
        uint16          numberOfKeys = so->numberOfKeys;
        ScanKey         key;
@@ -240,14 +240,14 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
        /*
         * Initialize for processing of keys for attr 1.
         *
-        * xform[i] holds a copy of the current scan key of strategy type i+1,
-        * if any; init[i] is TRUE if we have found such a key for this attr.
+        * xform[i] holds a copy of the current scan key of strategy type i+1, if
+        * any; init[i] is TRUE if we have found such a key for this attr.
         */
        attno = 1;
        map = IndexStrategyGetStrategyMap(RelationGetIndexStrategy(relation),
                                                                          BTMaxStrategyNumber,
                                                                          attno);
-       MemSet(xform, 0, sizeof(xform)); /* not really necessary */
+       MemSet(xform, 0, sizeof(xform));        /* not really necessary */
        MemSet(init, 0, sizeof(init));
 
        /*
@@ -255,7 +255,7 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
         * pass to handle after-last-key processing.  Actual exit from the
         * loop is at the "break" statement below.
         */
-       for (i = 0; ; cur++, i++)
+       for (i = 0;; cur++, i++)
        {
                if (i < numberOfKeys)
                {
@@ -263,7 +263,9 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
                        if (cur->sk_flags & SK_ISNULL)
                        {
                                so->qual_ok = false;
-                               /* Quit processing so we don't try to invoke comparison
+
+                               /*
+                                * Quit processing so we don't try to invoke comparison
                                 * routines on NULLs.
                                 */
                                return;
@@ -271,8 +273,8 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
                }
 
                /*
-                * If we are at the end of the keys for a particular attr,
-                * finish up processing and emit the cleaned-up keys.
+                * If we are at the end of the keys for a particular attr, finish
+                * up processing and emit the cleaned-up keys.
                 */
                if (i == numberOfKeys || cur->sk_attno != attno)
                {
@@ -296,7 +298,7 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
                                eq = &xform[BTEqualStrategyNumber - 1];
                                for (j = BTMaxStrategyNumber; --j >= 0;)
                                {
-                                       if (! init[j] ||
+                                       if (!init[j] ||
                                                j == (BTEqualStrategyNumber - 1))
                                                continue;
                                        chk = &xform[j];
@@ -313,6 +315,7 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
                        }
                        else
                        {
+
                                /*
                                 * No "=" for this key, so we're done with required keys
                                 */
@@ -355,8 +358,8 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
                         * Emit the cleaned-up keys back into the key[] array in the
                         * correct order.  Note we are overwriting our input here!
                         * It's OK because (a) xform[] is a physical copy of the keys
-                        * we want, (b) we cannot emit more keys than we input, so
-                        * we won't overwrite as-yet-unprocessed keys.
+                        * we want, (b) we cannot emit more keys than we input, so we
+                        * won't overwrite as-yet-unprocessed keys.
                         */
                        for (j = BTMaxStrategyNumber; --j >= 0;)
                        {
@@ -383,7 +386,7 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
                        map = IndexStrategyGetStrategyMap(RelationGetIndexStrategy(relation),
                                                                                          BTMaxStrategyNumber,
                                                                                          attno);
-                       MemSet(xform, 0, sizeof(xform)); /* not really necessary */
+                       MemSet(xform, 0, sizeof(xform));        /* not really necessary */
                        MemSet(init, 0, sizeof(init));
                }
 
@@ -409,7 +412,8 @@ _bt_orderkeys(Relation relation, BTScanOpaque so)
                        if (DatumGetBool(test))
                                xform[j].sk_argument = cur->sk_argument;
                        else if (j == (BTEqualStrategyNumber - 1))
-                               so->qual_ok = false; /* key == a && key == b, but a != b */
+                               so->qual_ok = false;    /* key == a && key == b, but a !=
+                                                                                * b */
                }
                else
                {
@@ -473,16 +477,18 @@ _bt_checkkeys(IndexScanDesc scan, IndexTuple tuple,
 
                if (isNull)
                {
+
                        /*
                         * Since NULLs are sorted after non-NULLs, we know we have
                         * reached the upper limit of the range of values for this
-                        * index attr.  On a forward scan, we can stop if this qual
-                        * is one of the "must match" subset.  On a backward scan,
+                        * index attr.  On a forward scan, we can stop if this qual is
+                        * one of the "must match" subset.      On a backward scan,
                         * however, we should keep going.
                         */
                        if (keysok < so->numberOfRequiredKeys &&
                                ScanDirectionIsForward(dir))
                                *continuescan = false;
+
                        /*
                         * In any case, this indextuple doesn't match the qual.
                         */
@@ -498,9 +504,10 @@ _bt_checkkeys(IndexScanDesc scan, IndexTuple tuple,
 
                if (DatumGetBool(test) == !!(key->sk_flags & SK_NEGATE))
                {
+
                        /*
-                        * Tuple fails this qual.  If it's a required qual, then
-                        * we can conclude no further tuples will pass, either.
+                        * Tuple fails this qual.  If it's a required qual, then we
+                        * can conclude no further tuples will pass, either.
                         */
                        if (keysok < so->numberOfRequiredKeys)
                                *continuescan = false;
index df0f5e9c80e6cca2c763b112febaf4b329c27292..c8fa6b18d684054e051cf86edd3a2da66d1db357 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtget.c,v 1.24 2001/01/24 19:42:49 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtget.c,v 1.25 2001/03/22 03:59:16 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -30,8 +30,8 @@ static ItemPointer rtheapptr(Relation r, ItemPointer itemp);
 Datum
 rtgettuple(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc           s = (IndexScanDesc) PG_GETARG_POINTER(0);
-       ScanDirection           dir = (ScanDirection) PG_GETARG_INT32(1);
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       ScanDirection dir = (ScanDirection) PG_GETARG_INT32(1);
        RetrieveIndexResult res;
 
        /* if we have it cached in the scan desc, just return the value */
index fd610caebe1768eb083480954608f6c85612a06b..400be10ccb3ded1ed9aa23d9bbfc7f0557747b20 100644 (file)
@@ -6,7 +6,7 @@
  * NOTE: for largely-historical reasons, the intersection functions should
  * return a NULL pointer (*not* an SQL null value) to indicate "no
  * intersection".  The size functions must be prepared to accept such
- * a pointer and return 0.  This convention means that only pass-by-reference
+ * a pointer and return 0.     This convention means that only pass-by-reference
  * data types can be used as the output of the union and intersection
  * routines, but that's not a big problem.
  *
@@ -15,7 +15,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.31 2001/01/24 19:42:49 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtproc.c,v 1.32 2001/03/22 03:59:16 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -70,6 +70,7 @@ Datum
 rt_box_size(PG_FUNCTION_ARGS)
 {
        BOX                *a = PG_GETARG_BOX_P(0);
+
        /* NB: size is an output argument */
        float      *size = (float *) PG_GETARG_POINTER(1);
 
@@ -98,8 +99,8 @@ rt_bigbox_size(PG_FUNCTION_ARGS)
 Datum
 rt_poly_union(PG_FUNCTION_ARGS)
 {
-       POLYGON    *a = PG_GETARG_POLYGON_P(0);
-       POLYGON    *b = PG_GETARG_POLYGON_P(1);
+       POLYGON    *a = PG_GETARG_POLYGON_P(0);
+       POLYGON    *b = PG_GETARG_POLYGON_P(1);
        POLYGON    *p;
 
        p = (POLYGON *) palloc(sizeof(POLYGON));
@@ -122,8 +123,8 @@ rt_poly_union(PG_FUNCTION_ARGS)
 Datum
 rt_poly_inter(PG_FUNCTION_ARGS)
 {
-       POLYGON    *a = PG_GETARG_POLYGON_P(0);
-       POLYGON    *b = PG_GETARG_POLYGON_P(1);
+       POLYGON    *a = PG_GETARG_POLYGON_P(0);
+       POLYGON    *b = PG_GETARG_POLYGON_P(1);
        POLYGON    *p;
 
        p = (POLYGON *) palloc(sizeof(POLYGON));
@@ -155,13 +156,15 @@ Datum
 rt_poly_size(PG_FUNCTION_ARGS)
 {
        Pointer         aptr = PG_GETARG_POINTER(0);
+
        /* NB: size is an output argument */
        float      *size = (float *) PG_GETARG_POINTER(1);
-       POLYGON    *a;
+       POLYGON    *a;
        double          xdim,
                                ydim;
 
-       /* Can't just use GETARG because of possibility that input is NULL;
+       /*
+        * Can't just use GETARG because of possibility that input is NULL;
         * since POLYGON is toastable, GETARG will try to inspect its value
         */
        if (aptr == NULL)
index 45382d5ef3cd441dce716e91e109dd0d2a1f5a07..3752a59e99a3259dcef8feb7660927baf8308a4a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.60 2001/03/07 21:20:26 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtree.c,v 1.61 2001/03/22 03:59:16 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -68,12 +68,12 @@ static InsertIndexResult rtdoinsert(Relation r, IndexTuple itup,
 static void rttighten(Relation r, RTSTACK *stk, Datum datum, int att_size,
                  RTSTATE *rtstate);
 static InsertIndexResult rtdosplit(Relation r, Buffer buffer, RTSTACK *stack,
-               IndexTuple itup, RTSTATE *rtstate);
+                 IndexTuple itup, RTSTATE *rtstate);
 static void rtintinsert(Relation r, RTSTACK *stk, IndexTuple ltup,
                        IndexTuple rtup, RTSTATE *rtstate);
 static void rtnewroot(Relation r, IndexTuple lt, IndexTuple rt);
 static void rtpicksplit(Relation r, Page page, SPLITVEC *v, IndexTuple itup,
-                 RTSTATE *rtstate);
+                       RTSTATE *rtstate);
 static void RTInitBuffer(Buffer b, uint32 f);
 static OffsetNumber choose(Relation r, Page p, IndexTuple it,
           RTSTATE *rtstate);
@@ -84,12 +84,14 @@ static void initRtstate(RTSTATE *rtstate, Relation index);
 Datum
 rtbuild(PG_FUNCTION_ARGS)
 {
-       Relation                heap = (Relation) PG_GETARG_POINTER(0);
-       Relation                index = (Relation) PG_GETARG_POINTER(1);
-       IndexInfo          *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
-       Node               *oldPred = (Node *) PG_GETARG_POINTER(3);
+       Relation        heap = (Relation) PG_GETARG_POINTER(0);
+       Relation        index = (Relation) PG_GETARG_POINTER(1);
+       IndexInfo  *indexInfo = (IndexInfo *) PG_GETARG_POINTER(2);
+       Node       *oldPred = (Node *) PG_GETARG_POINTER(3);
+
 #ifdef NOT_USED
-       IndexStrategy   istrat = (IndexStrategy) PG_GETARG_POINTER(4);
+       IndexStrategy istrat = (IndexStrategy) PG_GETARG_POINTER(4);
+
 #endif
        HeapScanDesc hscan;
        HeapTuple       htup;
@@ -101,9 +103,11 @@ rtbuild(PG_FUNCTION_ARGS)
        int                     nhtups,
                                nitups;
        Node       *pred = indexInfo->ii_Predicate;
+
 #ifndef OMIT_PARTIAL_INDEX
        TupleTable      tupleTable;
        TupleTableSlot *slot;
+
 #endif
        ExprContext *econtext;
        InsertIndexResult res = NULL;
@@ -171,6 +175,7 @@ rtbuild(PG_FUNCTION_ARGS)
                nhtups++;
 
 #ifndef OMIT_PARTIAL_INDEX
+
                /*
                 * If oldPred != NULL, this is an EXTEND INDEX command, so skip
                 * this tuple if it was already in the existing partial index
@@ -232,9 +237,7 @@ rtbuild(PG_FUNCTION_ARGS)
 
 #ifndef OMIT_PARTIAL_INDEX
        if (pred != NULL || oldPred != NULL)
-       {
                ExecDropTupleTable(tupleTable, true);
-       }
 #endif  /* OMIT_PARTIAL_INDEX */
        FreeExprContext(econtext);
 
@@ -278,12 +281,14 @@ rtbuild(PG_FUNCTION_ARGS)
 Datum
 rtinsert(PG_FUNCTION_ARGS)
 {
-       Relation                r = (Relation) PG_GETARG_POINTER(0);
-       Datum              *datum = (Datum *) PG_GETARG_POINTER(1);
-       char               *nulls = (char *) PG_GETARG_POINTER(2);
-       ItemPointer             ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
+       Relation        r = (Relation) PG_GETARG_POINTER(0);
+       Datum      *datum = (Datum *) PG_GETARG_POINTER(1);
+       char       *nulls = (char *) PG_GETARG_POINTER(2);
+       ItemPointer ht_ctid = (ItemPointer) PG_GETARG_POINTER(3);
+
 #ifdef NOT_USED
-       Relation                heapRel = (Relation) PG_GETARG_POINTER(4);
+       Relation        heapRel = (Relation) PG_GETARG_POINTER(4);
+
 #endif
        InsertIndexResult res;
        IndexTuple      itup;
@@ -412,7 +417,7 @@ rttighten(Relation r,
        p = BufferGetPage(b);
 
        oldud = IndexTupleGetDatum(PageGetItem(p,
-                                                                                  PageGetItemId(p, stk->rts_child)));
+                                                                         PageGetItemId(p, stk->rts_child)));
 
        FunctionCall2(&rtstate->sizeFn, oldud,
                                  PointerGetDatum(&old_size));
@@ -564,7 +569,7 @@ rtdosplit(Relation r,
        res = (InsertIndexResult) palloc(sizeof(InsertIndexResultData));
 
        /* now insert the new index tuple */
-       if (*spl_left == maxoff+1)
+       if (*spl_left == maxoff + 1)
        {
                if (PageAddItem(left, (Item) itup, IndexTupleSize(itup),
                                                leftoff, LP_USED) == InvalidOffsetNumber)
@@ -576,7 +581,7 @@ rtdosplit(Relation r,
        }
        else
        {
-               Assert(*spl_right == maxoff+1);
+               Assert(*spl_right == maxoff + 1);
                if (PageAddItem(right, (Item) itup, IndexTupleSize(itup),
                                                rightoff, LP_USED) == InvalidOffsetNumber)
                        elog(ERROR, "rtdosplit: failed to add index item to %s",
@@ -665,10 +670,10 @@ rtintinsert(Relation r,
        old = (IndexTuple) PageGetItem(p, PageGetItemId(p, stk->rts_child));
 
        /*
-        * This is a hack.      Right now, we force rtree internal keys to be constant
-        * size. To fix this, need delete the old key and add both left and
-        * right for the two new pages.  The insertion of left may force a
-        * split if the new left key is bigger than the old key.
+        * This is a hack.      Right now, we force rtree internal keys to be
+        * constant size. To fix this, need delete the old key and add both
+        * left and right for the two new pages.  The insertion of left may
+        * force a split if the new left key is bigger than the old key.
         */
 
        if (IndexTupleSize(old) != IndexTupleSize(ltup))
@@ -734,7 +739,7 @@ rtnewroot(Relation r, IndexTuple lt, IndexTuple rt)
  * We return two vectors of index item numbers, one for the items to be
  * put on the left page, one for the items to be put on the right page.
  * In addition, the item to be added (itup) is listed in the appropriate
- * vector.  It is represented by item number N+1 (N = # of items on page).
+ * vector.     It is represented by item number N+1 (N = # of items on page).
  *
  * Both vectors appear in sequence order with a terminating sentinel value
  * of InvalidOffsetNumber.
@@ -747,9 +752,9 @@ rtnewroot(Relation r, IndexTuple lt, IndexTuple rt)
  *
  * We must also deal with a consideration not found in Guttman's algorithm:
  * variable-length data.  In particular, the incoming item might be
- * large enough that not just any split will work.  In the worst case,
+ * large enough that not just any split will work.     In the worst case,
  * our "split" may have to be the new item on one page and all the existing
- * items on the other.  Short of that, we have to take care that we do not
+ * items on the other. Short of that, we have to take care that we do not
  * make a split that leaves both pages too full for the new item.
  */
 static void
@@ -794,9 +799,10 @@ rtpicksplit(Relation r,
                                right_avail_space;
 
        /*
-        * First, make sure the new item is not so large that we can't possibly
-        * fit it on a page, even by itself.  (It's sufficient to make this test
-        * here, since any oversize tuple must lead to a page split attempt.)
+        * First, make sure the new item is not so large that we can't
+        * possibly fit it on a page, even by itself.  (It's sufficient to
+        * make this test here, since any oversize tuple must lead to a page
+        * split attempt.)
         */
        newitemsz = IndexTupleTotalSize(itup);
        if (newitemsz > RTPageAvailSpace)
@@ -804,7 +810,8 @@ rtpicksplit(Relation r,
                         (unsigned long) newitemsz, (unsigned long) RTPageAvailSpace);
 
        maxoff = PageGetMaxOffsetNumber(page);
-       newitemoff = OffsetNumberNext(maxoff); /* phony index for new item */
+       newitemoff = OffsetNumberNext(maxoff);          /* phony index for new
+                                                                                                * item */
 
        /* Make arrays big enough for worst case, including sentinel */
        nbytes = (maxoff + 2) * sizeof(OffsetNumber);
@@ -827,8 +834,8 @@ rtpicksplit(Relation r,
                        item_2_sz = IndexTupleTotalSize(item_2);
 
                        /*
-                        * Ignore seed pairs that don't leave room for the new item
-                        * on either split page.
+                        * Ignore seed pairs that don't leave room for the new item on
+                        * either split page.
                         */
                        if (newitemsz + item_1_sz > RTPageAvailSpace &&
                                newitemsz + item_2_sz > RTPageAvailSpace)
@@ -841,8 +848,10 @@ rtpicksplit(Relation r,
                                                  PointerGetDatum(&size_union));
                        inter_d = FunctionCall2(&rtstate->interFn,
                                                                        datum_alpha, datum_beta);
-                       /* The interFn may return a NULL pointer (not an SQL null!)
-                        * to indicate no intersection.  sizeFn must cope with this.
+
+                       /*
+                        * The interFn may return a NULL pointer (not an SQL null!) to
+                        * indicate no intersection.  sizeFn must cope with this.
                         */
                        FunctionCall2(&rtstate->sizeFn, inter_d,
                                                  PointerGetDatum(&size_inter));
@@ -869,6 +878,7 @@ rtpicksplit(Relation r,
 
        if (firsttime)
        {
+
                /*
                 * There is no possible split except to put the new item on its
                 * own page.  Since we still have to compute the union rectangles,
@@ -916,14 +926,14 @@ rtpicksplit(Relation r,
 
        for (i = FirstOffsetNumber; i <= newitemoff; i = OffsetNumberNext(i))
        {
-               bool    left_feasible,
-                               right_feasible,
-                               choose_left;
+               bool            left_feasible,
+                                       right_feasible,
+                                       choose_left;
 
                /*
                 * If we've already decided where to place this item, just put it
-                * on the correct list.  Otherwise, we need to figure out which page
-                * needs the least enlargement in order to store the item.
+                * on the correct list.  Otherwise, we need to figure out which
+                * page needs the least enlargement in order to store the item.
                 */
 
                if (i == seed_1)
@@ -961,12 +971,13 @@ rtpicksplit(Relation r,
                                          PointerGetDatum(&size_beta));
 
                /*
-                * We prefer the page that shows smaller enlargement of its union area
-                * (Guttman's algorithm), but we must take care that at least one page
-                * will still have room for the new item after this one is added.
+                * We prefer the page that shows smaller enlargement of its union
+                * area (Guttman's algorithm), but we must take care that at least
+                * one page will still have room for the new item after this one
+                * is added.
                 *
-                * (We know that all the old items together can fit on one page,
-                * so we need not worry about any other problem than failing to fit
+                * (We know that all the old items together can fit on one page, so
+                * we need not worry about any other problem than failing to fit
                 * the new item.)
                 */
                left_feasible = (left_avail_space >= item_1_sz &&
@@ -987,7 +998,7 @@ rtpicksplit(Relation r,
                else
                {
                        elog(ERROR, "rtpicksplit: failed to find a workable page split");
-                       choose_left = false; /* keep compiler quiet */
+                       choose_left = false;/* keep compiler quiet */
                }
 
                if (choose_left)
@@ -1012,7 +1023,7 @@ rtpicksplit(Relation r,
                }
        }
 
-       *left = *right = InvalidOffsetNumber; /* add ending sentinels */
+       *left = *right = InvalidOffsetNumber;           /* add ending sentinels */
 
        v->spl_ldatum = datum_l;
        v->spl_rdatum = datum_r;
@@ -1096,8 +1107,8 @@ freestack(RTSTACK *s)
 Datum
 rtdelete(PG_FUNCTION_ARGS)
 {
-       Relation                r = (Relation) PG_GETARG_POINTER(0);
-       ItemPointer             tid = (ItemPointer) PG_GETARG_POINTER(1);
+       Relation        r = (Relation) PG_GETARG_POINTER(0);
+       ItemPointer tid = (ItemPointer) PG_GETARG_POINTER(1);
        BlockNumber blkno;
        OffsetNumber offnum;
        Buffer          buf;
@@ -1203,14 +1214,14 @@ rtree_redo(XLogRecPtr lsn, XLogRecord *record)
 {
        elog(STOP, "rtree_redo: unimplemented");
 }
+
 void
 rtree_undo(XLogRecPtr lsn, XLogRecord *record)
 {
        elog(STOP, "rtree_undo: unimplemented");
 }
+
 void
-rtree_desc(char *buf, uint8 xl_info, charrec)
+rtree_desc(char *buf, uint8 xl_info, char *rec)
 {
 }
index 605d51b5d330a0b8a5767c5bac41bb02baf69b49..f3e6d52fe67314abb06c34e929f90cce963c94b7 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtscan.c,v 1.35 2001/01/24 19:42:50 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/rtree/Attic/rtscan.c,v 1.36 2001/03/22 03:59:16 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -75,9 +75,9 @@ rtbeginscan(PG_FUNCTION_ARGS)
 Datum
 rtrescan(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   s = (IndexScanDesc) PG_GETARG_POINTER(0);
-       bool                    fromEnd = PG_GETARG_BOOL(1);
-       ScanKey                 key = (ScanKey) PG_GETARG_POINTER(2);
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       bool            fromEnd = PG_GETARG_BOOL(1);
+       ScanKey         key = (ScanKey) PG_GETARG_POINTER(2);
        RTreeScanOpaque p;
        RegProcedure internal_proc;
        int                     i;
@@ -162,7 +162,7 @@ rtrescan(PG_FUNCTION_ARGS)
 Datum
 rtmarkpos(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
        RTreeScanOpaque p;
        RTSTACK    *o,
                           *n,
@@ -198,7 +198,7 @@ rtmarkpos(PG_FUNCTION_ARGS)
 Datum
 rtrestrpos(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
        RTreeScanOpaque p;
        RTSTACK    *o,
                           *n,
@@ -234,7 +234,7 @@ rtrestrpos(PG_FUNCTION_ARGS)
 Datum
 rtendscan(PG_FUNCTION_ARGS)
 {
-       IndexScanDesc   s = (IndexScanDesc) PG_GETARG_POINTER(0);
+       IndexScanDesc s = (IndexScanDesc) PG_GETARG_POINTER(0);
        RTreeScanOpaque p;
 
        p = (RTreeScanOpaque) s->opaque;
index b25db74da8cb493c74a9c19e906dd97102988997..625b0db32023cd3e91a26f29774f3f9931a726b9 100644 (file)
@@ -9,21 +9,21 @@
 #include "storage/smgr.h"
 #include "commands/sequence.h"
 
-RmgrData   RmgrTable[] = {
-{"XLOG", xlog_redo, xlog_undo, xlog_desc},
-{"Transaction", xact_redo, xact_undo, xact_desc},
-{"Storage", smgr_redo, smgr_undo, smgr_desc},
-{"Reserved 3", NULL, NULL, NULL},
-{"Reserved 4", NULL, NULL, NULL},
-{"Reserved 5", NULL, NULL, NULL},
-{"Reserved 6", NULL, NULL, NULL},
-{"Reserved 7", NULL, NULL, NULL},
-{"Reserved 8", NULL, NULL, NULL},
-{"Reserved 9", NULL, NULL, NULL},
-{"Heap", heap_redo, heap_undo, heap_desc},
-{"Btree", btree_redo, btree_undo, btree_desc},
-{"Hash", hash_redo, hash_undo, hash_desc},
-{"Rtree", rtree_redo, rtree_undo, rtree_desc},
-{"Gist", gist_redo, gist_undo, gist_desc},
-{"Sequence", seq_redo, seq_undo, seq_desc}
+RmgrData       RmgrTable[] = {
+       {"XLOG", xlog_redo, xlog_undo, xlog_desc},
+       {"Transaction", xact_redo, xact_undo, xact_desc},
+       {"Storage", smgr_redo, smgr_undo, smgr_desc},
+       {"Reserved 3", NULL, NULL, NULL},
+       {"Reserved 4", NULL, NULL, NULL},
+       {"Reserved 5", NULL, NULL, NULL},
+       {"Reserved 6", NULL, NULL, NULL},
+       {"Reserved 7", NULL, NULL, NULL},
+       {"Reserved 8", NULL, NULL, NULL},
+       {"Reserved 9", NULL, NULL, NULL},
+       {"Heap", heap_redo, heap_undo, heap_desc},
+       {"Btree", btree_redo, btree_undo, btree_desc},
+       {"Hash", hash_redo, hash_undo, hash_desc},
+       {"Rtree", rtree_redo, rtree_undo, rtree_desc},
+       {"Gist", gist_redo, gist_undo, gist_desc},
+       {"Sequence", seq_redo, seq_undo, seq_desc}
 };
index 642890579261bab492869afa82b2eeab73c26808..29e72e84175cd1c7f62e8037d0519f9448eaa4bb 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.41 2001/03/18 20:18:59 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/transam/transam.c,v 1.42 2001/03/22 03:59:17 momjian Exp $
  *
  * NOTES
  *       This file contains the high level access-method interface to the
@@ -427,8 +427,8 @@ InitializeTransactionLog(void)
                TransactionLogUpdate(AmiTransactionId, XID_COMMIT);
                TransactionIdStore(AmiTransactionId, &cachedTestXid);
                cachedTestXidStatus = XID_COMMIT;
-               Assert(!IsUnderPostmaster && 
-                               ShmemVariableCache->nextXid <= FirstTransactionId);
+               Assert(!IsUnderPostmaster &&
+                          ShmemVariableCache->nextXid <= FirstTransactionId);
                ShmemVariableCache->nextXid = FirstTransactionId;
        }
        else if (RecoveryCheckingEnabled())
index e4ff7979cf9034abc9eadf2c48b999d88e3dc4d9..c433506eae65b5d462a5e4180509ba71b4a93e47 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.28 2001/01/24 19:42:51 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/transam/Attic/transsup.c,v 1.29 2001/03/22 03:59:17 momjian Exp $
  *
  * NOTES
  *       This file contains support functions for the high
@@ -186,7 +186,7 @@ TransBlockGetXidStatus(Block tblock,
        bits8           bit2;
        BitIndex        offset;
 
-       tblock = (Block) ((char*) tblock + sizeof(XLogRecPtr));
+       tblock = (Block) ((char *) tblock + sizeof(XLogRecPtr));
 
        /* ----------------
         *      calculate the index into the transaction data where
@@ -229,7 +229,7 @@ TransBlockSetXidStatus(Block tblock,
        Index           index;
        BitIndex        offset;
 
-       tblock = (Block) ((char*) tblock + sizeof(XLogRecPtr));
+       tblock = (Block) ((char *) tblock + sizeof(XLogRecPtr));
 
        /* ----------------
         *      calculate the index into the transaction data where
index d6097b2567c2e8061528e72534ee3a026ce99f69..34c607eab9f3cd547dc279622c33a1c48348cbc9 100644 (file)
@@ -6,7 +6,7 @@
  * Copyright (c) 2000, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.37 2001/03/18 20:18:59 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/transam/varsup.c,v 1.38 2001/03/22 03:59:17 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -23,8 +23,8 @@
 #define VAR_OID_PREFETCH               8192
 
 /* Spinlocks for serializing generation of XIDs and OIDs, respectively */
-SPINLOCK XidGenLockId;
-SPINLOCK OidGenLockId;
+SPINLOCK       XidGenLockId;
+SPINLOCK       OidGenLockId;
 
 /* pointer to "variable cache" in shared memory (set up by shmem.c) */
 VariableCache ShmemVariableCache = NULL;
@@ -32,9 +32,10 @@ VariableCache ShmemVariableCache = NULL;
 void
 GetNewTransactionId(TransactionId *xid)
 {
+
        /*
-        * During bootstrap initialization, we return the special
-        * bootstrap transaction id.
+        * During bootstrap initialization, we return the special bootstrap
+        * transaction id.
         */
        if (AMI_OVERRIDE)
        {
@@ -60,9 +61,10 @@ GetNewTransactionId(TransactionId *xid)
 void
 ReadNewTransactionId(TransactionId *xid)
 {
+
        /*
-        * During bootstrap initialization, we return the special
-        * bootstrap transaction id.
+        * During bootstrap initialization, we return the special bootstrap
+        * transaction id.
         */
        if (AMI_OVERRIDE)
        {
@@ -80,7 +82,7 @@ ReadNewTransactionId(TransactionId *xid)
  * ----------------------------------------------------------------
  */
 
-static Oid lastSeenOid = InvalidOid;
+static Oid     lastSeenOid = InvalidOid;
 
 void
 GetNewObjectId(Oid *oid_return)
@@ -119,10 +121,10 @@ CheckMaxObjectId(Oid assigned_oid)
        }
 
        /* If we are in the logged oid range, just bump nextOid up */
-       if (assigned_oid <= ShmemVariableCache->nextOid + 
-                                               ShmemVariableCache->oidCount - 1)
+       if (assigned_oid <= ShmemVariableCache->nextOid +
+               ShmemVariableCache->oidCount - 1)
        {
-               ShmemVariableCache->oidCount -= 
+               ShmemVariableCache->oidCount -=
                        assigned_oid - ShmemVariableCache->nextOid + 1;
                ShmemVariableCache->nextOid = assigned_oid + 1;
                SpinRelease(OidGenLockId);
@@ -130,10 +132,9 @@ CheckMaxObjectId(Oid assigned_oid)
        }
 
        /*
-        * We have exceeded the logged oid range.
-        * We should lock the database and kill all other backends
-        * but we are loading oid's that we can not guarantee are unique
-        * anyway, so we must rely on the user.
+        * We have exceeded the logged oid range. We should lock the database
+        * and kill all other backends but we are loading oid's that we can
+        * not guarantee are unique anyway, so we must rely on the user.
         */
 
        XLogPutNextOid(assigned_oid + VAR_OID_PREFETCH);
index 1331c8e9834c4749c9f9c62d5fec1d1165cb8d13..6a8e6c0639f9926c1b0e63d6c2137b9213fda5af 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.99 2001/03/13 01:17:05 tgl Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.100 2001/03/22 03:59:18 momjian Exp $
  *
  * NOTES
  *             Transaction aborts can now occur two ways:
@@ -222,9 +222,10 @@ int                        DefaultXactIsoLevel = XACT_READ_COMMITTED;
 int                    XactIsoLevel;
 
 int                    CommitDelay = 0;        /* precommit delay in microseconds */
-int                    CommitSiblings = 5;     /* number of concurrent xacts needed to sleep */
+int                    CommitSiblings = 5; /* number of concurrent xacts needed to
+                                                                * sleep */
 
-static void (*_RollbackFunc)(void*) = NULL;
+static void (*_RollbackFunc) (void *) = NULL;
 static void *_RollbackData = NULL;
 
 /* ----------------
@@ -666,39 +667,40 @@ RecordTransactionCommit()
 
        if (MyLastRecPtr.xrecoff != 0)
        {
-               XLogRecData             rdata;
-               xl_xact_commit  xlrec;
-               XLogRecPtr              recptr;
+               XLogRecData rdata;
+               xl_xact_commit xlrec;
+               XLogRecPtr      recptr;
 
                BufmgrCommit();
 
                xlrec.xtime = time(NULL);
                rdata.buffer = InvalidBuffer;
-               rdata.data = (char *)(&xlrec);
+               rdata.data = (char *) (&xlrec);
                rdata.len = SizeOfXactCommit;
                rdata.next = NULL;
 
                START_CRIT_SECTION();
+
                /*
                 * SHOULD SAVE ARRAY OF RELFILENODE-s TO DROP
                 */
                recptr = XLogInsert(RM_XACT_ID, XLOG_XACT_COMMIT, &rdata);
 
-               /* 
-                * Sleep before commit! So we can flush more than one
-                * commit records per single fsync.  (The idea is some other
-                * backend may do the XLogFlush while we're sleeping.  This
-                * needs work still, because on most Unixen, the minimum
-                * select() delay is 10msec or more, which is way too long.)
+               /*
+                * Sleep before commit! So we can flush more than one commit
+                * records per single fsync.  (The idea is some other backend may
+                * do the XLogFlush while we're sleeping.  This needs work still,
+                * because on most Unixen, the minimum select() delay is 10msec or
+                * more, which is way too long.)
                 *
-                * We do not sleep if enableFsync is not turned on, nor if there
-                * are fewer than CommitSiblings other backends with active
+                * We do not sleep if enableFsync is not turned on, nor if there are
+                * fewer than CommitSiblings other backends with active
                 * transactions.
                 */
                if (CommitDelay > 0 && enableFsync &&
                        CountActiveBackends() >= CommitSiblings)
                {
-                       struct timeval  delay;
+                       struct timeval delay;
 
                        delay.tv_sec = 0;
                        delay.tv_usec = CommitDelay;
@@ -812,13 +814,13 @@ RecordTransactionAbort(void)
         */
        if (MyLastRecPtr.xrecoff != 0 && !TransactionIdDidCommit(xid))
        {
-               XLogRecData             rdata;
-               xl_xact_abort   xlrec;
-               XLogRecPtr              recptr;
+               XLogRecData rdata;
+               xl_xact_abort xlrec;
+               XLogRecPtr      recptr;
 
                xlrec.xtime = time(NULL);
                rdata.buffer = InvalidBuffer;
-               rdata.data = (char *)(&xlrec);
+               rdata.data = (char *) (&xlrec);
                rdata.len = SizeOfXactAbort;
                rdata.next = NULL;
 
@@ -879,7 +881,7 @@ AtAbort_Memory(void)
 {
        /* ----------------
         *      Make sure we are in a valid context (not a child of
-        *      TransactionCommandContext...).  Note that it is possible
+        *      TransactionCommandContext...).  Note that it is possible
         *      for this code to be called when we aren't in a transaction
         *      at all; go directly to TopMemoryContext in that case.
         * ----------------
@@ -896,9 +898,7 @@ AtAbort_Memory(void)
                MemoryContextResetAndDeleteChildren(TransactionCommandContext);
        }
        else
-       {
                MemoryContextSwitchTo(TopMemoryContext);
-       }
 }
 
 
@@ -1021,6 +1021,7 @@ CurrentXactInProgress(void)
 {
        return CurrentTransactionState->state == TRANS_INPROGRESS;
 }
+
 #endif
 
 /* --------------------------------
@@ -1106,7 +1107,7 @@ CommitTransaction(void)
        AtCommit_Memory();
        AtEOXact_Files();
 
-       SharedBufferChanged = false; /* safest place to do it */
+       SharedBufferChanged = false;/* safest place to do it */
 
        /* ----------------
         *      done with commit processing, set current transaction
@@ -1143,15 +1144,16 @@ AbortTransaction(void)
 
        /*
         * Release any spinlocks or buffer context locks we might be holding
-        * as quickly as possible.  (Real locks, however, must be held till
-        * we finish aborting.)  Releasing spinlocks is critical since we
-        * might try to grab them again while cleaning up!
+        * as quickly as possible.      (Real locks, however, must be held till we
+        * finish aborting.)  Releasing spinlocks is critical since we might
+        * try to grab them again while cleaning up!
         */
        ProcReleaseSpins(NULL);
        UnlockBuffers();
+
        /*
-        * Also clean up any open wait for lock, since the lock manager
-        * will choke if we try to wait for another lock before doing this.
+        * Also clean up any open wait for lock, since the lock manager will
+        * choke if we try to wait for another lock before doing this.
         */
        LockWaitCancel();
 
@@ -1203,7 +1205,7 @@ AbortTransaction(void)
        AtEOXact_Files();
        AtAbort_Locks();
 
-       SharedBufferChanged = false; /* safest place to do it */
+       SharedBufferChanged = false;/* safest place to do it */
 
        /* ----------------
         *      State remains TRANS_ABORT until CleanupTransaction().
@@ -1327,8 +1329,8 @@ StartTransactionCommand(void)
        }
 
        /*
-        * We must switch to TransactionCommandContext before returning.
-        * This is already done if we called StartTransaction, otherwise not.
+        * We must switch to TransactionCommandContext before returning. This
+        * is already done if we called StartTransaction, otherwise not.
         */
        Assert(TransactionCommandContext != NULL);
        MemoryContextSwitchTo(TransactionCommandContext);
@@ -1757,7 +1759,7 @@ IsTransactionBlock(void)
 void
 xact_redo(XLogRecPtr lsn, XLogRecord *record)
 {
-       uint8   info = record->xl_info & ~XLR_INFO_MASK;
+       uint8           info = record->xl_info & ~XLR_INFO_MASK;
 
        if (info == XLOG_XACT_COMMIT)
        {
@@ -1765,9 +1767,7 @@ xact_redo(XLogRecPtr lsn, XLogRecord *record)
                /* SHOULD REMOVE FILES OF ALL DROPPED RELATIONS */
        }
        else if (info == XLOG_XACT_ABORT)
-       {
                TransactionIdAbort(record->xl_xid);
-       }
        else
                elog(STOP, "xact_redo: unknown op code %u", info);
 }
@@ -1775,43 +1775,43 @@ xact_redo(XLogRecPtr lsn, XLogRecord *record)
 void
 xact_undo(XLogRecPtr lsn, XLogRecord *record)
 {
-       uint8   info = record->xl_info & ~XLR_INFO_MASK;
+       uint8           info = record->xl_info & ~XLR_INFO_MASK;
 
-       if (info == XLOG_XACT_COMMIT)   /* shouldn't be called by XLOG */
+       if (info == XLOG_XACT_COMMIT)           /* shouldn't be called by XLOG */
                elog(STOP, "xact_undo: can't undo committed xaction");
        else if (info != XLOG_XACT_ABORT)
                elog(STOP, "xact_redo: unknown op code %u", info);
 }
+
 void
-xact_desc(char *buf, uint8 xl_info, charrec)
+xact_desc(char *buf, uint8 xl_info, char *rec)
 {
-       uint8   info = xl_info & ~XLR_INFO_MASK;
+       uint8           info = xl_info & ~XLR_INFO_MASK;
 
        if (info == XLOG_XACT_COMMIT)
        {
-               xl_xact_commit  *xlrec = (xl_xact_commit*) rec;
-               struct tm           *tm = localtime(&xlrec->xtime);
+               xl_xact_commit *xlrec = (xl_xact_commit *) rec;
+               struct tm  *tm = localtime(&xlrec->xtime);
 
                sprintf(buf + strlen(buf), "commit: %04u-%02u-%02u %02u:%02u:%02u",
-                       tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
-                       tm->tm_hour, tm->tm_min, tm->tm_sec);
+                               tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+                               tm->tm_hour, tm->tm_min, tm->tm_sec);
        }
        else if (info == XLOG_XACT_ABORT)
        {
-               xl_xact_abort   *xlrec = (xl_xact_abort*) rec;
-               struct tm           *tm = localtime(&xlrec->xtime);
+               xl_xact_abort *xlrec = (xl_xact_abort *) rec;
+               struct tm  *tm = localtime(&xlrec->xtime);
 
                sprintf(buf + strlen(buf), "abort: %04u-%02u-%02u %02u:%02u:%02u",
-                       tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
-                       tm->tm_hour, tm->tm_min, tm->tm_sec);
+                               tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
+                               tm->tm_hour, tm->tm_min, tm->tm_sec);
        }
        else
                strcat(buf, "UNKNOWN");
 }
 
 void
-XactPushRollback(void (*func) (void *), void* data)
+                       XactPushRollback(void (*func) (void *), void *data)
 {
 #ifdef XLOG_II
        if (_RollbackFunc != NULL)
index 6ee28d1a2b058faa4e1890d21a68da425b698a61..624d6da850c88f2df23ecccf690b73802957206a 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- *     $Id: xid.c,v 1.29 2001/01/24 19:42:51 momjian Exp $
+ *     $Id: xid.c,v 1.30 2001/03/22 03:59:18 momjian Exp $
  *
  * OLD COMMENTS
  * XXX WARNING
@@ -26,8 +26,8 @@
 /*
  * TransactionId is typedef'd as uint32, so...
  */
-#define PG_GETARG_TRANSACTIONID(n)  PG_GETARG_UINT32(n)
-#define PG_RETURN_TRANSACTIONID(x)  PG_RETURN_UINT32(x)
+#define PG_GETARG_TRANSACTIONID(n)     PG_GETARG_UINT32(n)
+#define PG_RETURN_TRANSACTIONID(x)     PG_RETURN_UINT32(x)
 
 
 extern TransactionId NullTransactionId;
@@ -49,6 +49,7 @@ Datum
 xidout(PG_FUNCTION_ARGS)
 {
        TransactionId transactionId = PG_GETARG_TRANSACTIONID(0);
+
        /* maximum 32 bit unsigned integer representation takes 10 chars */
        char       *representation = palloc(11);
 
index 9994025dd69dd45b215e93200ab0bf2a487f61d3..59d783264bbc78b911e19c9aa99d68713af18f22 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.62 2001/03/18 20:18:59 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.63 2001/03/22 03:59:18 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 /*
  * This chunk of hackery attempts to determine which file sync methods
  * are available on the current platform, and to choose an appropriate
- * default method.  We assume that fsync() is always available, and that
+ * default method.     We assume that fsync() is always available, and that
  * configure determined whether fdatasync() is.
  */
 #define SYNC_METHOD_FSYNC              0
 #define SYNC_METHOD_FDATASYNC  1
-#define SYNC_METHOD_OPEN               2 /* used for both O_SYNC and O_DSYNC */
+#define SYNC_METHOD_OPEN               2               /* used for both O_SYNC and
+                                                                                * O_DSYNC */
 
 #if defined(O_SYNC)
-# define OPEN_SYNC_FLAG                O_SYNC
+#define OPEN_SYNC_FLAG    O_SYNC
 #else
-# if defined(O_FSYNC)
-#  define OPEN_SYNC_FLAG       O_FSYNC
-# endif
+#if defined(O_FSYNC)
+#define OPEN_SYNC_FLAG   O_FSYNC
+#endif
 #endif
 
 #if defined(OPEN_SYNC_FLAG)
-# if defined(O_DSYNC) && (O_DSYNC != OPEN_SYNC_FLAG)
-#  define OPEN_DATASYNC_FLAG   O_DSYNC
-# endif
+#if defined(O_DSYNC) && (O_DSYNC != OPEN_SYNC_FLAG)
+#define OPEN_DATASYNC_FLAG       O_DSYNC
+#endif
 #endif
 
 #if defined(OPEN_DATASYNC_FLAG)
-# define DEFAULT_SYNC_METHOD_STR       "open_datasync"
-# define DEFAULT_SYNC_METHOD           SYNC_METHOD_OPEN
-# define DEFAULT_SYNC_FLAGBIT          OPEN_DATASYNC_FLAG
+#define DEFAULT_SYNC_METHOD_STR    "open_datasync"
+#define DEFAULT_SYNC_METHOD               SYNC_METHOD_OPEN
+#define DEFAULT_SYNC_FLAGBIT      OPEN_DATASYNC_FLAG
 #else
-# if defined(HAVE_FDATASYNC)
-#  define DEFAULT_SYNC_METHOD_STR      "fdatasync"
-#  define DEFAULT_SYNC_METHOD          SYNC_METHOD_FDATASYNC
-#  define DEFAULT_SYNC_FLAGBIT         0
-# else
-#  define DEFAULT_SYNC_METHOD_STR      "fsync"
-#  define DEFAULT_SYNC_METHOD          SYNC_METHOD_FSYNC
-#  define DEFAULT_SYNC_FLAGBIT         0
-# endif
+#if defined(HAVE_FDATASYNC)
+#define DEFAULT_SYNC_METHOD_STR   "fdatasync"
+#define DEFAULT_SYNC_METHOD              SYNC_METHOD_FDATASYNC
+#define DEFAULT_SYNC_FLAGBIT     0
+#else
+#define DEFAULT_SYNC_METHOD_STR   "fsync"
+#define DEFAULT_SYNC_METHOD              SYNC_METHOD_FSYNC
+#define DEFAULT_SYNC_FLAGBIT     0
+#endif
 #endif
 
 
 /* Max time to wait to acquire XLog activity locks */
-#define XLOG_LOCK_TIMEOUT                      (5*60*1000000) /* 5 minutes */
+#define XLOG_LOCK_TIMEOUT                      (5*60*1000000)          /* 5 minutes */
 /* Max time to wait to acquire checkpoint lock */
-#define CHECKPOINT_LOCK_TIMEOUT                (20*60*1000000) /* 20 minutes */
+#define CHECKPOINT_LOCK_TIMEOUT                (20*60*1000000)         /* 20 minutes */
 
 /* User-settable parameters */
 int                    CheckPointSegments = 3;
 int                    XLOGbuffers = 8;
-int                    XLOGfiles = 0;  /* how many files to pre-allocate during ckpt */
+int                    XLOGfiles = 0;          /* how many files to pre-allocate during
+                                                                * ckpt */
 int                    XLOG_DEBUG = 0;
 char      *XLOG_sync_method = NULL;
 const char     XLOG_sync_method_default[] = DEFAULT_SYNC_METHOD_STR;
-char           XLOG_archive_dir[MAXPGPATH]; /* null string means delete 'em */
+char           XLOG_archive_dir[MAXPGPATH];            /* null string means
+                                                                                                * delete 'em */
 
 /* these are derived from XLOG_sync_method by assign_xlog_sync_method */
 static int     sync_method = DEFAULT_SYNC_METHOD;
@@ -135,7 +138,7 @@ static XLogRecPtr ProcLastRecPtr = {0, 0};
 /*
  * RedoRecPtr is this backend's local copy of the REDO record pointer
  * (which is almost but not quite the same as a pointer to the most recent
- * CHECKPOINT record).  We update this from the shared-memory copy,
+ * CHECKPOINT record). We update this from the shared-memory copy,
  * XLogCtl->Insert.RedoRecPtr, whenever we can safely do so (ie, when we
  * hold the Insert spinlock).  See XLogInsert for details.
  */
@@ -164,12 +167,12 @@ SPINLOCK  ControlFileLockId;
  *
  * XLogCtl->LogwrtResult and XLogCtl->Write.LogwrtResult are both "always
  * right", since both are updated by a write or flush operation before
- * it releases logwrt_lck.  The point of keeping XLogCtl->Write.LogwrtResult
+ * it releases logwrt_lck.     The point of keeping XLogCtl->Write.LogwrtResult
  * is that it can be examined/modified by code that already holds logwrt_lck
  * without needing to grab info_lck as well.
  *
  * XLogCtl->Insert.LogwrtResult may lag behind the reality of the other two,
- * but is updated when convenient.  Again, it exists for the convenience of
+ * but is updated when convenient.     Again, it exists for the convenience of
  * code that is already holding insert_lck but not the other locks.
  *
  * The unshared LogwrtResult may lag behind any or all of these, and again
@@ -187,25 +190,25 @@ typedef struct XLogwrtRqst
 {
        XLogRecPtr      Write;                  /* last byte + 1 to write out */
        XLogRecPtr      Flush;                  /* last byte + 1 to flush */
-} XLogwrtRqst;
+}                      XLogwrtRqst;
 
 typedef struct XLogwrtResult
 {
        XLogRecPtr      Write;                  /* last byte + 1 written out */
        XLogRecPtr      Flush;                  /* last byte + 1 flushed */
-} XLogwrtResult;
+}                      XLogwrtResult;
 
 /*
  * Shared state data for XLogInsert.
  */
 typedef struct XLogCtlInsert
 {
-       XLogwrtResult   LogwrtResult;   /* a recent value of LogwrtResult */
-       XLogRecPtr              PrevRecord;             /* start of previously-inserted record */
-       uint16                  curridx;                /* current block index in cache */
-       XLogPageHeader  currpage;               /* points to header of block in cache */
-       char               *currpos;            /* current insertion point in cache */
-       XLogRecPtr              RedoRecPtr;             /* current redo point for insertions */
+       XLogwrtResult LogwrtResult; /* a recent value of LogwrtResult */
+       XLogRecPtr      PrevRecord;             /* start of previously-inserted record */
+       uint16          curridx;                /* current block index in cache */
+       XLogPageHeader currpage;        /* points to header of block in cache */
+       char       *currpos;            /* current insertion point in cache */
+       XLogRecPtr      RedoRecPtr;             /* current redo point for insertions */
 } XLogCtlInsert;
 
 /*
@@ -213,8 +216,8 @@ typedef struct XLogCtlInsert
  */
 typedef struct XLogCtlWrite
 {
-       XLogwrtResult   LogwrtResult;   /* current value of LogwrtResult */
-       uint16                  curridx;                /* cache index of next block to write */
+       XLogwrtResult LogwrtResult; /* current value of LogwrtResult */
+       uint16          curridx;                /* cache index of next block to write */
 } XLogCtlWrite;
 
 /*
@@ -223,30 +226,31 @@ typedef struct XLogCtlWrite
 typedef struct XLogCtlData
 {
        /* Protected by insert_lck: */
-       XLogCtlInsert   Insert;
+       XLogCtlInsert Insert;
        /* Protected by info_lck: */
-       XLogwrtRqst             LogwrtRqst;
-       XLogwrtResult   LogwrtResult;
+       XLogwrtRqst LogwrtRqst;
+       XLogwrtResult LogwrtResult;
        /* Protected by logwrt_lck: */
-       XLogCtlWrite    Write;
+       XLogCtlWrite Write;
+
        /*
         * These values do not change after startup, although the pointed-to
-        * pages and xlblocks values certainly do.  Permission to read/write
+        * pages and xlblocks values certainly do.      Permission to read/write
         * the pages and xlblocks values depends on insert_lck and logwrt_lck.
         */
-       char               *pages;                      /* buffers for unwritten XLOG pages */
-       XLogRecPtr         *xlblocks;           /* 1st byte ptr-s + BLCKSZ */
-       uint32                  XLogCacheByte;  /* # bytes in xlog buffers */
-       uint32                  XLogCacheBlck;  /* highest allocated xlog buffer index */
-       StartUpID               ThisStartUpID;
+       char       *pages;                      /* buffers for unwritten XLOG pages */
+       XLogRecPtr *xlblocks;           /* 1st byte ptr-s + BLCKSZ */
+       uint32          XLogCacheByte;  /* # bytes in xlog buffers */
+       uint32          XLogCacheBlck;  /* highest allocated xlog buffer index */
+       StartUpID       ThisStartUpID;
 
        /* This value is not protected by *any* spinlock... */
-       XLogRecPtr              RedoRecPtr;             /* see SetRedoRecPtr/GetRedoRecPtr */
+       XLogRecPtr      RedoRecPtr;             /* see SetRedoRecPtr/GetRedoRecPtr */
 
-       slock_t                 insert_lck;             /* XLogInsert lock */
-       slock_t                 info_lck;               /* locks shared LogwrtRqst/LogwrtResult */
-       slock_t                 logwrt_lck;             /* XLogWrite/XLogFlush lock */
-       slock_t                 chkp_lck;               /* checkpoint lock */
+       slock_t         insert_lck;             /* XLogInsert lock */
+       slock_t         info_lck;               /* locks shared LogwrtRqst/LogwrtResult */
+       slock_t         logwrt_lck;             /* XLogWrite/XLogFlush lock */
+       slock_t         chkp_lck;               /* checkpoint lock */
 } XLogCtlData;
 
 static XLogCtlData *XLogCtl = NULL;
@@ -271,7 +275,7 @@ static ControlFileData *ControlFile = NULL;
        ( \
          (recptr).xlogid = XLogCtl->xlblocks[curridx].xlogid, \
          (recptr).xrecoff = \
-               XLogCtl->xlblocks[curridx].xrecoff - INSERT_FREESPACE(Insert) \
+               XLogCtl->xlblocks[curridx].xrecoff - INSERT_FREESPACE(Insert) \
        )
 
 
@@ -303,7 +307,7 @@ static ControlFileData *ControlFile = NULL;
  * Compute ID and segment from an XLogRecPtr.
  *
  * For XLByteToSeg, do the computation at face value.  For XLByteToPrevSeg,
- * a boundary byte is taken to be in the previous segment.  This is suitable
+ * a boundary byte is taken to be in the previous segment.     This is suitable
  * for deciding which segment to write given a pointer to a record end,
  * for example.
  */
@@ -354,8 +358,8 @@ static ControlFileData *ControlFile = NULL;
 
 
 /* File path names */
-static char            XLogDir[MAXPGPATH];
-static char            ControlFilePath[MAXPGPATH];
+static char XLogDir[MAXPGPATH];
+static char ControlFilePath[MAXPGPATH];
 
 /*
  * Private, possibly out-of-date copy of shared LogwrtResult.
@@ -384,8 +388,10 @@ static int readFile = -1;
 static uint32 readId = 0;
 static uint32 readSeg = 0;
 static uint32 readOff = 0;
+
 /* Buffer for currently read page (BLCKSZ bytes) */
 static char *readBuf = NULL;
+
 /* State information for XLOG reading */
 static XLogRecPtr ReadRecPtr;
 static XLogRecPtr EndRecPtr;
@@ -397,16 +403,16 @@ static bool InRedo = false;
 
 static bool AdvanceXLInsertBuffer(void);
 static void XLogWrite(XLogwrtRqst WriteRqst);
-static int     XLogFileInit(uint32 log, uint32 seg,
-                                                bool *use_existent, bool use_lock);
+static int XLogFileInit(uint32 log, uint32 seg,
+                        bool *use_existent, bool use_lock);
 static int     XLogFileOpen(uint32 log, uint32 seg, bool econt);
 static void PreallocXlogFiles(XLogRecPtr endptr);
 static void MoveOfflineLogs(uint32 log, uint32 seg);
 static XLogRecord *ReadRecord(XLogRecPtr *RecPtr, int emode, char *buffer);
 static bool ValidXLOGHeader(XLogPageHeader hdr, int emode, bool checkSUI);
 static XLogRecord *ReadCheckpointRecord(XLogRecPtr RecPtr,
-                                                                               const char *whichChkpt,
-                                                                               char *buffer);
+                                        const char *whichChkpt,
+                                        char *buffer);
 static void WriteControlFile(void);
 static void ReadControlFile(void);
 static char *str_time(time_t tnow);
@@ -432,44 +438,44 @@ static void issue_xlog_fsync(void);
 XLogRecPtr
 XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata)
 {
-       XLogCtlInsert  *Insert = &XLogCtl->Insert;
-       XLogRecord         *record;
+       XLogCtlInsert *Insert = &XLogCtl->Insert;
+       XLogRecord *record;
        XLogContRecord *contrecord;
-       XLogRecPtr              RecPtr;
-       XLogRecPtr              WriteRqst;
-       uint32                  freespace;
-       uint16                  curridx;
-       XLogRecData        *rdt;
-       Buffer                  dtbuf[XLR_MAX_BKP_BLOCKS];
-       bool                    dtbuf_bkp[XLR_MAX_BKP_BLOCKS];
-       BkpBlock                dtbuf_xlg[XLR_MAX_BKP_BLOCKS];
-       XLogRecPtr              dtbuf_lsn[XLR_MAX_BKP_BLOCKS];
-       XLogRecData             dtbuf_rdt[2 * XLR_MAX_BKP_BLOCKS];
-       crc64                   rdata_crc;
-       uint32                  len,
-                                       write_len;
-       unsigned                i;
-       bool                    do_logwrt;
-       bool                    updrqst;
-       bool                    no_tran = (rmid == RM_XLOG_ID) ? true : false;
+       XLogRecPtr      RecPtr;
+       XLogRecPtr      WriteRqst;
+       uint32          freespace;
+       uint16          curridx;
+       XLogRecData *rdt;
+       Buffer          dtbuf[XLR_MAX_BKP_BLOCKS];
+       bool            dtbuf_bkp[XLR_MAX_BKP_BLOCKS];
+       BkpBlock        dtbuf_xlg[XLR_MAX_BKP_BLOCKS];
+       XLogRecPtr      dtbuf_lsn[XLR_MAX_BKP_BLOCKS];
+       XLogRecData dtbuf_rdt[2 * XLR_MAX_BKP_BLOCKS];
+       crc64           rdata_crc;
+       uint32          len,
+                               write_len;
+       unsigned        i;
+       bool            do_logwrt;
+       bool            updrqst;
+       bool            no_tran = (rmid == RM_XLOG_ID) ? true : false;
 
        if (info & XLR_INFO_MASK)
        {
                if ((info & XLR_INFO_MASK) != XLOG_NO_TRAN)
-                       elog(STOP, "XLogInsert: invalid info mask %02X", 
+                       elog(STOP, "XLogInsert: invalid info mask %02X",
                                 (info & XLR_INFO_MASK));
                no_tran = true;
                info &= ~XLR_INFO_MASK;
        }
 
        /*
-        * In bootstrap mode, we don't actually log anything but XLOG resources;
-        * return a phony record pointer.
+        * In bootstrap mode, we don't actually log anything but XLOG
+        * resources; return a phony record pointer.
         */
        if (IsBootstrapProcessingMode() && rmid != RM_XLOG_ID)
        {
                RecPtr.xlogid = 0;
-               RecPtr.xrecoff = SizeOfXLogPHD; /* start of 1st checkpoint record */
+               RecPtr.xrecoff = SizeOfXLogPHD; /* start of 1st checkpoint record */
                return (RecPtr);
        }
 
@@ -479,16 +485,17 @@ XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata)
         * header isn't added into the CRC yet since we don't know the final
         * length or info bits quite yet.
         *
-        * We may have to loop back to here if a race condition is detected below.
-        * We could prevent the race by doing all this work while holding the
-        * insert spinlock, but it seems better to avoid doing CRC calculations
-        * while holding the lock.  This means we have to be careful about
-        * modifying the rdata list until we know we aren't going to loop back
-        * again.  The only change we allow ourselves to make earlier is to set
-        * rdt->data = NULL in list items we have decided we will have to back
-        * up the whole buffer for.  This is OK because we will certainly decide
-        * the same thing again for those items if we do it over; doing it here
-        * saves an extra pass over the list later.
+        * We may have to loop back to here if a race condition is detected
+        * below. We could prevent the race by doing all this work while
+        * holding the insert spinlock, but it seems better to avoid doing CRC
+        * calculations while holding the lock.  This means we have to be
+        * careful about modifying the rdata list until we know we aren't
+        * going to loop back again.  The only change we allow ourselves to
+        * make earlier is to set rdt->data = NULL in list items we have
+        * decided we will have to back up the whole buffer for.  This is OK
+        * because we will certainly decide the same thing again for those
+        * items if we do it over; doing it here saves an extra pass over the
+        * list later.
         */
 begin:;
        for (i = 0; i < XLR_MAX_BKP_BLOCKS; i++)
@@ -499,7 +506,7 @@ begin:;
 
        INIT_CRC64(rdata_crc);
        len = 0;
-       for (rdt = rdata; ; )
+       for (rdt = rdata;;)
        {
                if (rdt->buffer == InvalidBuffer)
                {
@@ -528,13 +535,14 @@ begin:;
                                {
                                        /* OK, put it in this slot */
                                        dtbuf[i] = rdt->buffer;
+
                                        /*
                                         * XXX We assume page LSN is first data on page
                                         */
-                                       dtbuf_lsn[i] = *((XLogRecPtr*)BufferGetBlock(rdt->buffer));
+                                       dtbuf_lsn[i] = *((XLogRecPtr *) BufferGetBlock(rdt->buffer));
                                        if (XLByteLE(dtbuf_lsn[i], RedoRecPtr))
                                        {
-                                               crc64   dtcrc;
+                                               crc64           dtcrc;
 
                                                dtbuf_bkp[i] = true;
                                                rdt->data = NULL;
@@ -545,7 +553,7 @@ begin:;
                                                dtbuf_xlg[i].node = BufferGetFileNode(dtbuf[i]);
                                                dtbuf_xlg[i].block = BufferGetBlockNumber(dtbuf[i]);
                                                COMP_CRC64(dtcrc,
-                                                                  (char*) &(dtbuf_xlg[i]) + sizeof(crc64),
+                                                               (char *) &(dtbuf_xlg[i]) + sizeof(crc64),
                                                                   sizeof(BkpBlock) - sizeof(crc64));
                                                FIN_CRC64(dtcrc);
                                                dtbuf_xlg[i].crc = dtcrc;
@@ -571,7 +579,7 @@ begin:;
        /*
         * NOTE: the test for len == 0 here is somewhat fishy, since in theory
         * all of the rmgr data might have been suppressed in favor of backup
-        * blocks.  Currently, all callers of XLogInsert provide at least some
+        * blocks.      Currently, all callers of XLogInsert provide at least some
         * not-in-a-buffer data and so len == 0 should never happen, but that
         * may not be true forever.  If you need to remove the len == 0 check,
         * also remove the check for xl_len == 0 in ReadRecord, below.
@@ -589,16 +597,16 @@ begin:;
                /* try to update LogwrtResult while waiting for insert lock */
                if (!TAS(&(XLogCtl->info_lck)))
                {
-                       XLogwrtRqst     LogwrtRqst;
+                       XLogwrtRqst LogwrtRqst;
 
                        LogwrtRqst = XLogCtl->LogwrtRqst;
                        LogwrtResult = XLogCtl->LogwrtResult;
                        S_UNLOCK(&(XLogCtl->info_lck));
 
                        /*
-                        * If cache is half filled then try to acquire logwrt lock
-                        * and do LOGWRT work, but only once per XLogInsert call.
-                        * Ignore any fractional blocks in performing this check.
+                        * If cache is half filled then try to acquire logwrt lock and
+                        * do LOGWRT work, but only once per XLogInsert call. Ignore
+                        * any fractional blocks in performing this check.
                         */
                        LogwrtRqst.Write.xrecoff -= LogwrtRqst.Write.xrecoff % BLCKSZ;
                        if (do_logwrt &&
@@ -625,8 +633,9 @@ begin:;
 
        /*
         * Check to see if my RedoRecPtr is out of date.  If so, may have to
-        * go back and recompute everything.  This can only happen just after a
-        * checkpoint, so it's better to be slow in this case and fast otherwise.
+        * go back and recompute everything.  This can only happen just after
+        * a checkpoint, so it's better to be slow in this case and fast
+        * otherwise.
         */
        if (!XLByteEQ(RedoRecPtr, Insert->RedoRecPtr))
        {
@@ -640,9 +649,10 @@ begin:;
                        if (dtbuf_bkp[i] == false &&
                                XLByteLE(dtbuf_lsn[i], RedoRecPtr))
                        {
+
                                /*
-                                * Oops, this buffer now needs to be backed up, but we didn't
-                                * think so above.  Start over.
+                                * Oops, this buffer now needs to be backed up, but we
+                                * didn't think so above.  Start over.
                                 */
                                S_UNLOCK(&(XLogCtl->insert_lck));
                                END_CRIT_SECTION();
@@ -658,8 +668,9 @@ begin:;
         * this loop, write_len includes the backup block data.
         *
         * Also set the appropriate info bits to show which buffers were backed
-        * up.  The i'th XLR_SET_BKP_BLOCK bit corresponds to the i'th distinct
-        * buffer value (ignoring InvalidBuffer) appearing in the rdata list.
+        * up.  The i'th XLR_SET_BKP_BLOCK bit corresponds to the i'th
+        * distinct buffer value (ignoring InvalidBuffer) appearing in the
+        * rdata list.
         */
        write_len = len;
        for (i = 0; i < XLR_MAX_BKP_BLOCKS; i++)
@@ -671,13 +682,13 @@ begin:;
 
                rdt->next = &(dtbuf_rdt[2 * i]);
 
-               dtbuf_rdt[2 * i].data = (char*) &(dtbuf_xlg[i]);
+               dtbuf_rdt[2 * i].data = (char *) &(dtbuf_xlg[i]);
                dtbuf_rdt[2 * i].len = sizeof(BkpBlock);
                write_len += sizeof(BkpBlock);
 
                rdt = dtbuf_rdt[2 * i].next = &(dtbuf_rdt[2 * i + 1]);
 
-               dtbuf_rdt[2 * i + 1].data = (char*) BufferGetBlock(dtbuf[i]);
+               dtbuf_rdt[2 * i + 1].data = (char *) BufferGetBlock(dtbuf[i]);
                dtbuf_rdt[2 * i + 1].len = BLCKSZ;
                write_len += BLCKSZ;
                dtbuf_rdt[2 * i + 1].next = NULL;
@@ -711,7 +722,7 @@ begin:;
        record->xl_rmid = rmid;
 
        /* Now we can finish computing the main CRC */
-       COMP_CRC64(rdata_crc, (char*) record + sizeof(crc64),
+       COMP_CRC64(rdata_crc, (char *) record + sizeof(crc64),
                           SizeOfXLogRecord - sizeof(crc64));
        FIN_CRC64(rdata_crc);
        record->xl_crc = rdata_crc;
@@ -729,7 +740,7 @@ begin:;
 
        if (XLOG_DEBUG)
        {
-               char    buf[8192];
+               char            buf[8192];
 
                sprintf(buf, "INSERT @ %u/%u: ", RecPtr.xlogid, RecPtr.xrecoff);
                xlog_outrec(buf, record);
@@ -791,18 +802,19 @@ begin:;
 
        /* Ensure next record will be properly aligned */
        Insert->currpos = (char *) Insert->currpage +
-                       MAXALIGN(Insert->currpos - (char *) Insert->currpage);
+               MAXALIGN(Insert->currpos - (char *) Insert->currpage);
        freespace = INSERT_FREESPACE(Insert);
 
        /*
-        * The recptr I return is the beginning of the *next* record.
-        * This will be stored as LSN for changed data pages...
+        * The recptr I return is the beginning of the *next* record. This
+        * will be stored as LSN for changed data pages...
         */
        INSERT_RECPTR(RecPtr, Insert, curridx);
 
        /* Need to update shared LogwrtRqst if some block was filled up */
        if (freespace < SizeOfXLogRecord)
-               updrqst = true; /* curridx is filled and available for writing out */
+               updrqst = true;                 /* curridx is filled and available for
+                                                                * writing out */
        else
                curridx = PrevBufIdx(curridx);
        WriteRqst = XLogCtl->xlblocks[curridx];
@@ -850,9 +862,9 @@ AdvanceXLInsertBuffer(void)
                LogwrtResult = Insert->LogwrtResult;
 
        /*
-        * Get ending-offset of the buffer page we need to replace (this may be
-        * zero if the buffer hasn't been used yet).  Fall through if it's already
-        * written out.
+        * Get ending-offset of the buffer page we need to replace (this may
+        * be zero if the buffer hasn't been used yet).  Fall through if it's
+        * already written out.
         */
        OldPageRqstPtr = XLogCtl->xlblocks[nextidx];
        if (!XLByteLE(OldPageRqstPtr, LogwrtResult.Write))
@@ -870,7 +882,7 @@ AdvanceXLInsertBuffer(void)
                        {
                                if (XLByteLT(XLogCtl->LogwrtRqst.Write, FinishedPageRqstPtr))
                                        XLogCtl->LogwrtRqst.Write = FinishedPageRqstPtr;
-                               update_needed = false; /* Did the shared-request update */
+                               update_needed = false;  /* Did the shared-request update */
                                LogwrtResult = XLogCtl->LogwrtResult;
                                S_UNLOCK(&(XLogCtl->info_lck));
 
@@ -883,8 +895,8 @@ AdvanceXLInsertBuffer(void)
                        }
 
                        /*
-                        * LogwrtResult lock is busy or we know the page is still dirty.
-                        * Try to acquire logwrt lock and write full blocks.
+                        * LogwrtResult lock is busy or we know the page is still
+                        * dirty. Try to acquire logwrt lock and write full blocks.
                         */
                        if (!TAS(&(XLogCtl->logwrt_lck)))
                        {
@@ -896,9 +908,10 @@ AdvanceXLInsertBuffer(void)
                                        Insert->LogwrtResult = LogwrtResult;
                                        break;
                                }
+
                                /*
-                                * Have to write buffers while holding insert lock.
-                                * This is not good, so only write as much as we absolutely
+                                * Have to write buffers while holding insert lock. This
+                                * is not good, so only write as much as we absolutely
                                 * must.
                                 */
                                WriteRqst.Write = OldPageRqstPtr;
@@ -933,14 +946,15 @@ AdvanceXLInsertBuffer(void)
        }
        Insert->curridx = nextidx;
        Insert->currpage = (XLogPageHeader) (XLogCtl->pages + nextidx * BLCKSZ);
-       Insert->currpos = ((char*) Insert->currpage) + SizeOfXLogPHD;
+       Insert->currpos = ((char *) Insert->currpage) + SizeOfXLogPHD;
+
        /*
-        * Be sure to re-zero the buffer so that bytes beyond what we've written
-        * will look like zeroes and not valid XLOG records...
+        * Be sure to re-zero the buffer so that bytes beyond what we've
+        * written will look like zeroes and not valid XLOG records...
         */
-       MemSet((char*) Insert->currpage, 0, BLCKSZ);
+       MemSet((char *) Insert->currpage, 0, BLCKSZ);
        Insert->currpage->xlp_magic = XLOG_PAGE_MAGIC;
-       /* Insert->currpage->xlp_info = 0; */   /* done by memset */
+       /* Insert->currpage->xlp_info = 0; *//* done by memset */
        Insert->currpage->xlp_sui = ThisStartUpID;
 
        return update_needed;
@@ -959,11 +973,15 @@ XLogWrite(XLogwrtRqst WriteRqst)
        bool            ispartialpage;
        bool            use_existent;
 
-       /* Update local LogwrtResult (caller probably did this already, but...) */
+       /*
+        * Update local LogwrtResult (caller probably did this already,
+        * but...)
+        */
        LogwrtResult = Write->LogwrtResult;
 
        while (XLByteLT(LogwrtResult.Write, WriteRqst.Write))
        {
+
                /*
                 * Make sure we're not ahead of the insert process.  This could
                 * happen if we're passed a bogus WriteRqst.Write that is past the
@@ -979,6 +997,7 @@ XLogWrite(XLogwrtRqst WriteRqst)
 
                if (!XLByteInPrevSeg(LogwrtResult.Write, openLogId, openLogSeg))
                {
+
                        /*
                         * Switch to new logfile segment.
                         */
@@ -1011,11 +1030,12 @@ XLogWrite(XLogwrtRqst WriteRqst)
                                ControlFile->logSeg = openLogSeg + 1;