pgindent run for 8.2.
authorBruce Momjian <[email protected]>
Wed, 4 Oct 2006 00:30:14 +0000 (00:30 +0000)
committerBruce Momjian <[email protected]>
Wed, 4 Oct 2006 00:30:14 +0000 (00:30 +0000)
522 files changed:
contrib/adminpack/adminpack.c
contrib/cube/cube.c
contrib/dblink/dblink.c
contrib/hstore/hstore.h
contrib/hstore/hstore_gist.c
contrib/hstore/hstore_io.c
contrib/hstore/hstore_op.c
contrib/intarray/_int.h
contrib/intarray/_int_bool.c
contrib/intarray/_int_gin.c
contrib/intarray/_int_gist.c
contrib/intarray/_int_tool.c
contrib/intarray/_intbig_gist.c
contrib/isn/EAN13.h
contrib/isn/ISBN.h
contrib/isn/ISMN.h
contrib/isn/ISSN.h
contrib/isn/UPC.h
contrib/isn/isn.c
contrib/ltree/_ltree_gist.c
contrib/ltree/lquery_op.c
contrib/ltree/ltree.h
contrib/ltree/ltree_gist.c
contrib/ltree/ltree_op.c
contrib/pg_buffercache/pg_buffercache_pages.c
contrib/pg_freespacemap/pg_freespacemap.c
contrib/pg_trgm/trgm_gist.c
contrib/pgbench/pgbench.c
contrib/pgcrypto/crypt-gensalt.c
contrib/pgcrypto/crypt-md5.c
contrib/pgcrypto/fortuna.c
contrib/pgcrypto/imath.c
contrib/pgcrypto/imath.h
contrib/pgcrypto/internal-sha2.c
contrib/pgcrypto/internal.c
contrib/pgcrypto/openssl.c
contrib/pgcrypto/pgcrypto.c
contrib/pgcrypto/pgp-mpi-internal.c
contrib/pgcrypto/sha2.c
contrib/pgrowlocks/pgrowlocks.c
contrib/pgstattuple/pgstattuple.c
contrib/sslinfo/sslinfo.c
contrib/tablefunc/tablefunc.c
contrib/tsearch2/common.c
contrib/tsearch2/common.h
contrib/tsearch2/dict.c
contrib/tsearch2/dict.h
contrib/tsearch2/dict_thesaurus.c
contrib/tsearch2/ginidx.c
contrib/tsearch2/gistidx.c
contrib/tsearch2/ispell/regis.c
contrib/tsearch2/ispell/regis.h
contrib/tsearch2/ispell/spell.c
contrib/tsearch2/ispell/spell.h
contrib/tsearch2/prs_dcfg.c
contrib/tsearch2/query.c
contrib/tsearch2/query.h
contrib/tsearch2/query_cleanup.h
contrib/tsearch2/query_gist.c
contrib/tsearch2/rank.c
contrib/tsearch2/snowball/russian_stem_UTF8.c
contrib/tsearch2/snowball/russian_stem_UTF8.h
contrib/tsearch2/stopword.c
contrib/tsearch2/ts_cfg.c
contrib/tsearch2/ts_lexize.c
contrib/tsearch2/ts_locale.c
contrib/tsearch2/ts_locale.h
contrib/tsearch2/ts_stat.c
contrib/tsearch2/tsvector.c
contrib/tsearch2/tsvector.h
contrib/tsearch2/wordparser/parser.c
contrib/tsearch2/wparser.c
contrib/xml2/xpath.c
src/backend/access/common/heaptuple.c
src/backend/access/common/printtup.c
src/backend/access/common/reloptions.c
src/backend/access/gin/ginarrayproc.c
src/backend/access/gin/ginbtree.c
src/backend/access/gin/ginbulk.c
src/backend/access/gin/gindatapage.c
src/backend/access/gin/ginentrypage.c
src/backend/access/gin/ginget.c
src/backend/access/gin/gininsert.c
src/backend/access/gin/ginscan.c
src/backend/access/gin/ginutil.c
src/backend/access/gin/ginvacuum.c
src/backend/access/gin/ginxlog.c
src/backend/access/gist/gist.c
src/backend/access/gist/gistget.c
src/backend/access/gist/gistproc.c
src/backend/access/gist/gistscan.c
src/backend/access/gist/gistsplit.c
src/backend/access/gist/gistutil.c
src/backend/access/gist/gistvacuum.c
src/backend/access/gist/gistxlog.c
src/backend/access/hash/hashfunc.c
src/backend/access/hash/hashpage.c
src/backend/access/heap/heapam.c
src/backend/access/heap/tuptoaster.c
src/backend/access/index/genam.c
src/backend/access/index/indexam.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/nbtree/nbtxlog.c
src/backend/access/transam/clog.c
src/backend/access/transam/multixact.c
src/backend/access/transam/slru.c
src/backend/access/transam/twophase.c
src/backend/access/transam/varsup.c
src/backend/access/transam/xact.c
src/backend/access/transam/xlog.c
src/backend/access/transam/xlogutils.c
src/backend/bootstrap/bootstrap.c
src/backend/catalog/aclchk.c
src/backend/catalog/catalog.c
src/backend/catalog/dependency.c
src/backend/catalog/heap.c
src/backend/catalog/index.c
src/backend/catalog/namespace.c
src/backend/catalog/pg_aggregate.c
src/backend/catalog/pg_depend.c
src/backend/catalog/pg_shdepend.c
src/backend/catalog/pg_type.c
src/backend/catalog/toasting.c
src/backend/commands/aggregatecmds.c
src/backend/commands/analyze.c
src/backend/commands/cluster.c
src/backend/commands/comment.c
src/backend/commands/copy.c
src/backend/commands/dbcommands.c
src/backend/commands/define.c
src/backend/commands/explain.c
src/backend/commands/functioncmds.c
src/backend/commands/indexcmds.c
src/backend/commands/opclasscmds.c
src/backend/commands/operatorcmds.c
src/backend/commands/portalcmds.c
src/backend/commands/prepare.c
src/backend/commands/proclang.c
src/backend/commands/sequence.c
src/backend/commands/tablecmds.c
src/backend/commands/tablespace.c
src/backend/commands/trigger.c
src/backend/commands/typecmds.c
src/backend/commands/user.c
src/backend/commands/vacuum.c
src/backend/commands/vacuumlazy.c
src/backend/commands/variable.c
src/backend/commands/view.c
src/backend/executor/execMain.c
src/backend/executor/execProcnode.c
src/backend/executor/execQual.c
src/backend/executor/execTuples.c
src/backend/executor/execUtils.c
src/backend/executor/functions.c
src/backend/executor/nodeAgg.c
src/backend/executor/nodeAppend.c
src/backend/executor/nodeBitmapHeapscan.c
src/backend/executor/nodeBitmapIndexscan.c
src/backend/executor/nodeHashjoin.c
src/backend/executor/nodeIndexscan.c
src/backend/executor/nodeMaterial.c
src/backend/executor/nodeMergejoin.c
src/backend/executor/nodeNestloop.c
src/backend/executor/nodeSeqscan.c
src/backend/executor/nodeSort.c
src/backend/executor/nodeSubplan.c
src/backend/executor/nodeSubqueryscan.c
src/backend/executor/nodeTidscan.c
src/backend/executor/nodeValuesscan.c
src/backend/executor/spi.c
src/backend/libpq/auth.c
src/backend/libpq/be-secure.c
src/backend/libpq/hba.c
src/backend/libpq/pqcomm.c
src/backend/main/main.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/makefuncs.c
src/backend/nodes/params.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/orindxpath.c
src/backend/optimizer/path/pathkeys.c
src/backend/optimizer/path/tidpath.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/initsplan.c
src/backend/optimizer/plan/planagg.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/prepjointree.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/pathnode.c
src/backend/optimizer/util/plancat.c
src/backend/optimizer/util/predtest.c
src/backend/optimizer/util/relnode.c
src/backend/optimizer/util/restrictinfo.c
src/backend/parser/analyze.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/win32/socket.c
src/backend/port/win32/timer.c
src/backend/port/win32_sema.c
src/backend/postmaster/autovacuum.c
src/backend/postmaster/bgwriter.c
src/backend/postmaster/pgstat.c
src/backend/postmaster/postmaster.c
src/backend/rewrite/rewriteDefine.c
src/backend/rewrite/rewriteHandler.c
src/backend/rewrite/rewriteManip.c
src/backend/rewrite/rewriteRemove.c
src/backend/storage/buffer/bufmgr.c
src/backend/storage/buffer/freelist.c
src/backend/storage/file/fd.c
src/backend/storage/freespace/freespace.c
src/backend/storage/ipc/ipci.c
src/backend/storage/ipc/procarray.c
src/backend/storage/ipc/shmem.c
src/backend/storage/lmgr/lmgr.c
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/lwlock.c
src/backend/storage/lmgr/proc.c
src/backend/storage/lmgr/s_lock.c
src/backend/storage/page/itemptr.c
src/backend/storage/smgr/md.c
src/backend/storage/smgr/smgr.c
src/backend/tcop/fastpath.c
src/backend/tcop/postgres.c
src/backend/tcop/pquery.c
src/backend/tcop/utility.c
src/backend/utils/adt/arrayfuncs.c
src/backend/utils/adt/datetime.c
src/backend/utils/adt/domains.c
src/backend/utils/adt/float.c
src/backend/utils/adt/formatting.c
src/backend/utils/adt/int.c
src/backend/utils/adt/int8.c
src/backend/utils/adt/like.c
src/backend/utils/adt/lockfuncs.c
src/backend/utils/adt/misc.c
src/backend/utils/adt/network.c
src/backend/utils/adt/numeric.c
src/backend/utils/adt/oid.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/adt/pgstatfuncs.c
src/backend/utils/adt/regexp.c
src/backend/utils/adt/ri_triggers.c
src/backend/utils/adt/ruleutils.c
src/backend/utils/adt/selfuncs.c
src/backend/utils/adt/tid.c
src/backend/utils/adt/timestamp.c
src/backend/utils/adt/varchar.c
src/backend/utils/adt/varlena.c
src/backend/utils/cache/catcache.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/typcache.c
src/backend/utils/fmgr/dfmgr.c
src/backend/utils/fmgr/fmgr.c
src/backend/utils/hash/dynahash.c
src/backend/utils/hash/hashfn.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/conversion_procs/euc_tw_and_big5/euc_tw_and_big5.c
src/backend/utils/mb/conversion_procs/utf8_and_cyrillic/utf8_and_cyrillic.c
src/backend/utils/mb/conversion_procs/utf8_and_gb18030/utf8_and_gb18030.c
src/backend/utils/mb/conversion_procs/utf8_and_iso8859/utf8_and_iso8859.c
src/backend/utils/mb/conversion_procs/utf8_and_iso8859_1/utf8_and_iso8859_1.c
src/backend/utils/mb/conversion_procs/utf8_and_win/utf8_and_win.c
src/backend/utils/mb/mbutils.c
src/backend/utils/mb/wchar.c
src/backend/utils/misc/guc.c
src/backend/utils/misc/ps_status.c
src/backend/utils/misc/tzparser.c
src/backend/utils/mmgr/aset.c
src/backend/utils/mmgr/portalmem.c
src/backend/utils/sort/logtape.c
src/backend/utils/sort/tuplesort.c
src/backend/utils/sort/tuplestore.c
src/backend/utils/time/tqual.c
src/bin/initdb/initdb.c
src/bin/pg_config/pg_config.c
src/bin/pg_ctl/pg_ctl.c
src/bin/pg_dump/dumputils.c
src/bin/pg_dump/dumputils.h
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_tar.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dumpall.c
src/bin/pg_resetxlog/pg_resetxlog.c
src/bin/psql/command.c
src/bin/psql/command.h
src/bin/psql/common.c
src/bin/psql/common.h
src/bin/psql/copy.c
src/bin/psql/describe.c
src/bin/psql/input.c
src/bin/psql/mainloop.c
src/bin/psql/mbprint.c
src/bin/psql/mbprint.h
src/bin/psql/print.c
src/bin/psql/settings.h
src/bin/psql/startup.c
src/bin/psql/stringutils.c
src/bin/psql/tab-complete.c
src/bin/psql/variables.h
src/bin/scripts/common.c
src/bin/scripts/createuser.c
src/include/access/gin.h
src/include/access/gist.h
src/include/access/gist_private.h
src/include/access/heapam.h
src/include/access/hio.h
src/include/access/htup.h
src/include/access/nbtree.h
src/include/access/reloptions.h
src/include/access/relscan.h
src/include/access/skey.h
src/include/access/slru.h
src/include/access/tupdesc.h
src/include/access/xlog_internal.h
src/include/bootstrap/bootstrap.h
src/include/c.h
src/include/catalog/pg_aggregate.h
src/include/catalog/pg_amop.h
src/include/catalog/pg_amproc.h
src/include/catalog/pg_attribute.h
src/include/catalog/pg_class.h
src/include/catalog/pg_control.h
src/include/catalog/pg_index.h
src/include/catalog/pg_operator.h
src/include/catalog/pg_proc.h
src/include/catalog/pg_shdescription.h
src/include/catalog/pg_type.h
src/include/catalog/toasting.h
src/include/commands/comment.h
src/include/commands/defrem.h
src/include/commands/explain.h
src/include/commands/prepare.h
src/include/commands/tablecmds.h
src/include/commands/user.h
src/include/executor/executor.h
src/include/executor/nodeIndexscan.h
src/include/executor/nodeValuesscan.h
src/include/executor/spi.h
src/include/executor/tuptable.h
src/include/fmgr.h
src/include/funcapi.h
src/include/getaddrinfo.h
src/include/libpq/hba.h
src/include/libpq/libpq-be.h
src/include/mb/pg_wchar.h
src/include/nodes/params.h
src/include/nodes/parsenodes.h
src/include/nodes/primnodes.h
src/include/nodes/relation.h
src/include/optimizer/cost.h
src/include/optimizer/pathnode.h
src/include/optimizer/plancat.h
src/include/optimizer/prep.h
src/include/optimizer/restrictinfo.h
src/include/parser/analyze.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/pg_trace.h
src/include/pgstat.h
src/include/port.h
src/include/port/darwin.h
src/include/port/linux.h
src/include/port/netbsd.h
src/include/port/win32.h
src/include/port/win32/dlfcn.h
src/include/port/win32/grp.h
src/include/port/win32/netdb.h
src/include/port/win32/sys/socket.h
src/include/port/win32_msvc/dirent.h
src/include/port/win32_msvc/sys/file.h
src/include/port/win32_msvc/sys/param.h
src/include/port/win32_msvc/sys/time.h
src/include/port/win32_msvc/unistd.h
src/include/port/win32_msvc/utime.h
src/include/storage/freespace.h
src/include/storage/lock.h
src/include/storage/pg_sema.h
src/include/storage/pg_shmem.h
src/include/storage/proc.h
src/include/tcop/tcopprot.h
src/include/utils/acl.h
src/include/utils/catcache.h
src/include/utils/hsearch.h
src/include/utils/lsyscache.h
src/include/utils/portal.h
src/include/utils/rel.h
src/include/utils/resowner.h
src/include/utils/selfuncs.h
src/include/utils/timestamp.h
src/include/utils/tqual.h
src/include/utils/tuplesort.h
src/include/utils/tuplestore.h
src/include/utils/typcache.h
src/include/utils/tzparser.h
src/interfaces/ecpg/compatlib/informix.c
src/interfaces/ecpg/ecpglib/connect.c
src/interfaces/ecpg/ecpglib/data.c
src/interfaces/ecpg/ecpglib/descriptor.c
src/interfaces/ecpg/ecpglib/error.c
src/interfaces/ecpg/ecpglib/execute.c
src/interfaces/ecpg/ecpglib/extern.h
src/interfaces/ecpg/ecpglib/misc.c
src/interfaces/ecpg/ecpglib/prepare.c
src/interfaces/ecpg/include/ecpglib.h
src/interfaces/ecpg/include/pgtypes_date.h
src/interfaces/ecpg/include/pgtypes_interval.h
src/interfaces/ecpg/pgtypeslib/datetime.c
src/interfaces/ecpg/pgtypeslib/interval.c
src/interfaces/ecpg/pgtypeslib/numeric.c
src/interfaces/ecpg/pgtypeslib/timestamp.c
src/interfaces/ecpg/preproc/output.c
src/interfaces/ecpg/test/expected/compat_informix-charfuncs.c
src/interfaces/ecpg/test/expected/compat_informix-dec_test.c
src/interfaces/ecpg/test/expected/compat_informix-rfmtdate.c
src/interfaces/ecpg/test/expected/compat_informix-rfmtlong.c
src/interfaces/ecpg/test/expected/compat_informix-rnull.c
src/interfaces/ecpg/test/expected/compat_informix-test_informix.c
src/interfaces/ecpg/test/expected/compat_informix-test_informix2.c
src/interfaces/ecpg/test/expected/connect-test1.c
src/interfaces/ecpg/test/expected/connect-test2.c
src/interfaces/ecpg/test/expected/connect-test3.c
src/interfaces/ecpg/test/expected/connect-test4.c
src/interfaces/ecpg/test/expected/connect-test5.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c
src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.c
src/interfaces/ecpg/test/expected/pgtypeslib-num_test.c
src/interfaces/ecpg/test/expected/pgtypeslib-num_test2.c
src/interfaces/ecpg/test/expected/preproc-comment.c
src/interfaces/ecpg/test/expected/preproc-define.c
src/interfaces/ecpg/test/expected/preproc-init.c
src/interfaces/ecpg/test/expected/preproc-type.c
src/interfaces/ecpg/test/expected/preproc-variable.c
src/interfaces/ecpg/test/expected/preproc-whenever.c
src/interfaces/ecpg/test/expected/sql-array.c
src/interfaces/ecpg/test/expected/sql-binary.c
src/interfaces/ecpg/test/expected/sql-code100.c
src/interfaces/ecpg/test/expected/sql-copystdout.c
src/interfaces/ecpg/test/expected/sql-define.c
src/interfaces/ecpg/test/expected/sql-desc.c
src/interfaces/ecpg/test/expected/sql-dynalloc.c
src/interfaces/ecpg/test/expected/sql-dynalloc2.c
src/interfaces/ecpg/test/expected/sql-dyntest.c
src/interfaces/ecpg/test/expected/sql-execute.c
src/interfaces/ecpg/test/expected/sql-fetch.c
src/interfaces/ecpg/test/expected/sql-func.c
src/interfaces/ecpg/test/expected/sql-indicators.c
src/interfaces/ecpg/test/expected/sql-quote.c
src/interfaces/ecpg/test/expected/sql-show.c
src/interfaces/ecpg/test/expected/sql-update.c
src/interfaces/ecpg/test/expected/thread-thread.c
src/interfaces/ecpg/test/expected/thread-thread_implicit.c
src/interfaces/libpq/fe-auth.c
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/fe-lobj.c
src/interfaces/libpq/fe-misc.c
src/interfaces/libpq/fe-print.c
src/interfaces/libpq/fe-protocol3.c
src/interfaces/libpq/fe-secure.c
src/interfaces/libpq/libpq-fe.h
src/interfaces/libpq/libpq-int.h
src/interfaces/libpq/win32.c
src/pl/plperl/plperl.c
src/pl/plperl/plperl.h
src/pl/plpgsql/src/pl_comp.c
src/pl/plpgsql/src/pl_exec.c
src/pl/plpgsql/src/pl_handler.c
src/pl/plpgsql/src/plpgsql.h
src/pl/plpython/plpython.c
src/pl/tcl/pltcl.c
src/port/dirent.c
src/port/getaddrinfo.c
src/port/isinf.c
src/port/open.c
src/port/path.c
src/port/pgsleep.c
src/port/qsort_arg.c
src/port/snprintf.c
src/port/sprompt.c
src/port/strlcpy.c
src/port/strtol.c
src/test/regress/pg_regress.c
src/timezone/pgtz.c

index 3213420ba15dce786c5dd57dba6fe176020abf0d..dc756e4303f461ae532c699abffcef58dde6258c 100644 (file)
@@ -4,11 +4,11 @@
  *
  *
  * Copyright (c) 2002 - 2006, PostgreSQL Global Development Group
- * 
+ *
  * Author: Andreas Pflug <[email protected]>
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/contrib/adminpack/adminpack.c,v 1.3 2006/07/11 16:35:30 momjian Exp $
+ *   $PostgreSQL: pgsql/contrib/adminpack/adminpack.c,v 1.4 2006/10/04 00:29:44 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -35,7 +35,6 @@
 #ifdef unlink
 #undef unlink
 #endif
-
 #endif
 
 extern DLLIMPORT char *DataDir;
@@ -44,20 +43,20 @@ extern DLLIMPORT char *Log_filename;
 
 PG_MODULE_MAGIC;
 
-Datum pg_file_write(PG_FUNCTION_ARGS);
-Datum pg_file_rename(PG_FUNCTION_ARGS);
-Datum pg_file_unlink(PG_FUNCTION_ARGS);
-Datum pg_logdir_ls(PG_FUNCTION_ARGS);
+Datum      pg_file_write(PG_FUNCTION_ARGS);
+Datum      pg_file_rename(PG_FUNCTION_ARGS);
+Datum      pg_file_unlink(PG_FUNCTION_ARGS);
+Datum      pg_logdir_ls(PG_FUNCTION_ARGS);
 
 PG_FUNCTION_INFO_V1(pg_file_write);
 PG_FUNCTION_INFO_V1(pg_file_rename);
 PG_FUNCTION_INFO_V1(pg_file_unlink);
 PG_FUNCTION_INFO_V1(pg_logdir_ls);
 
-typedef struct 
+typedef struct
 {
-   char *location;
-   DIR *dirdesc;
+   char       *location;
+   DIR        *dirdesc;
 } directory_fctx;
 
 /*-----------------------
@@ -65,30 +64,31 @@ typedef struct
  */
 
 /*
- * Return an absolute path. Argument may be absolute or 
+ * Return an absolute path. Argument may be absolute or
  * relative to the DataDir.
  */
-static char *absClusterPath(text *arg, bool logAllowed)
+static char *
+absClusterPath(text *arg, bool logAllowed)
 {
-   char *filename;
-   int len=VARSIZE(arg) - VARHDRSZ;
-   int dlen = strlen(DataDir);
+   char       *filename;
+   int         len = VARSIZE(arg) - VARHDRSZ;
+   int         dlen = strlen(DataDir);
 
-   filename = palloc(len+1);
+   filename = palloc(len + 1);
    memcpy(filename, VARDATA(arg), len);
    filename[len] = 0;
 
    if (strstr(filename, "..") != NULL)
-     ereport(ERROR,
-             (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
-              (errmsg("No .. allowed in filenames"))));
-   
+       ereport(ERROR,
+               (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+                (errmsg("No .. allowed in filenames"))));
+
    if (is_absolute_path(filename))
    {
-       if (logAllowed && !strncmp(filename, Log_directory, strlen(Log_directory)))
-           return filename;
+       if (logAllowed && !strncmp(filename, Log_directory, strlen(Log_directory)))
+           return filename;
        if (strncmp(filename, DataDir, dlen))
-           ereport(ERROR,
+           ereport(ERROR,
                    (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                     (errmsg("Absolute path not allowed"))));
 
@@ -96,7 +96,8 @@ static char *absClusterPath(text *arg, bool logAllowed)
    }
    else
    {
-       char *absname = palloc(dlen+len+2);
+       char       *absname = palloc(dlen + len + 2);
+
        sprintf(absname, "%s/%s", DataDir, filename);
        pfree(filename);
        return absname;
@@ -111,9 +112,9 @@ static void
 requireSuperuser(void)
 {
    if (!superuser())
-       ereport(ERROR,
+       ereport(ERROR,
                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
-                (errmsg("only superuser may access generic file functions"))));
+             (errmsg("only superuser may access generic file functions"))));
 }
 
 
@@ -122,12 +123,13 @@ requireSuperuser(void)
  * generic file handling functions
  */
 
-Datum pg_file_write(PG_FUNCTION_ARGS)
+Datum
+pg_file_write(PG_FUNCTION_ARGS)
 {
-   FILE *f;
-   char *filename;
-   text *data;
-   int64 count = 0;
+   FILE       *f;
+   char       *filename;
+   text       *data;
+   int64       count = 0;
 
    requireSuperuser();
 
@@ -136,16 +138,17 @@ Datum pg_file_write(PG_FUNCTION_ARGS)
 
    if (PG_ARGISNULL(2) || !PG_GETARG_BOOL(2))
    {
-       struct stat fst;
+       struct stat fst;
+
        if (stat(filename, &fst) >= 0)
-           ereport(ERROR,
+           ereport(ERROR,
                    (ERRCODE_DUPLICATE_FILE,
                     errmsg("file %s exists", filename)));
 
-       f = fopen(filename, "wb");
+       f = fopen(filename, "wb");
    }
    else
-       f = fopen(filename, "ab");
+       f = fopen(filename, "ab");
 
    if (!f)
    {
@@ -159,7 +162,7 @@ Datum pg_file_write(PG_FUNCTION_ARGS)
        count = fwrite(VARDATA(data), 1, VARSIZE(data) - VARHDRSZ, f);
 
        if (count != VARSIZE(data) - VARHDRSZ)
-           ereport(ERROR,
+           ereport(ERROR,
                    (errcode_for_file_access(),
                     errmsg("error writing file %s: %m", filename)));
    }
@@ -169,22 +172,25 @@ Datum pg_file_write(PG_FUNCTION_ARGS)
 }
 
 
-Datum pg_file_rename(PG_FUNCTION_ARGS)
+Datum
+pg_file_rename(PG_FUNCTION_ARGS)
 {
-    char *fn1, *fn2, *fn3;
-   int rc;
+   char       *fn1,
+              *fn2,
+              *fn3;
+   int         rc;
 
    requireSuperuser();
 
    if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
        PG_RETURN_NULL();
 
-   fn1=absClusterPath(PG_GETARG_TEXT_P(0), false);
-   fn2=absClusterPath(PG_GETARG_TEXT_P(1), false);
+   fn1 = absClusterPath(PG_GETARG_TEXT_P(0), false);
+   fn2 = absClusterPath(PG_GETARG_TEXT_P(1), false);
    if (PG_ARGISNULL(2))
-       fn3=0;
+       fn3 = 0;
    else
-       fn3=absClusterPath(PG_GETARG_TEXT_P(2), false);
+       fn3 = absClusterPath(PG_GETARG_TEXT_P(2), false);
 
    if (access(fn1, W_OK) < 0)
    {
@@ -192,7 +198,7 @@ Datum pg_file_rename(PG_FUNCTION_ARGS)
                (errcode_for_file_access(),
                 errmsg("file %s not accessible: %m", fn1)));
 
-       PG_RETURN_BOOL(false);
+       PG_RETURN_BOOL(false);
    }
 
    if (fn3 && access(fn2, W_OK) < 0)
@@ -201,7 +207,7 @@ Datum pg_file_rename(PG_FUNCTION_ARGS)
                (errcode_for_file_access(),
                 errmsg("file %s not accessible: %m", fn2)));
 
-       PG_RETURN_BOOL(false);
+       PG_RETURN_BOOL(false);
    }
 
 
@@ -212,10 +218,10 @@ Datum pg_file_rename(PG_FUNCTION_ARGS)
                (ERRCODE_DUPLICATE_FILE,
                 errmsg("cannot rename to target file %s", fn3 ? fn3 : fn2)));
    }
-   
+
    if (fn3)
    {
-       if (rename(fn2, fn3) != 0)
+       if (rename(fn2, fn3) != 0)
        {
            ereport(ERROR,
                    (errcode_for_file_access(),
@@ -231,7 +237,7 @@ Datum pg_file_rename(PG_FUNCTION_ARGS)
            {
                ereport(ERROR,
                        (errcode_for_file_access(),
-                        errmsg("could not rename %s back to %s: %m", fn3, fn2)));
+                   errmsg("could not rename %s back to %s: %m", fn3, fn2)));
            }
            else
            {
@@ -244,9 +250,9 @@ Datum pg_file_rename(PG_FUNCTION_ARGS)
    }
    else if (rename(fn1, fn2) != 0)
    {
-           ereport(WARNING,
-                   (errcode_for_file_access(),
-                    errmsg("renaming %s to %s %m", fn1, fn2)));
+       ereport(WARNING,
+               (errcode_for_file_access(),
+                errmsg("renaming %s to %s %m", fn1, fn2)));
        ereport(ERROR,
                (errcode_for_file_access(),
                 errmsg("could not rename %s to %s: %m", fn1, fn2)));
@@ -256,20 +262,21 @@ Datum pg_file_rename(PG_FUNCTION_ARGS)
 }
 
 
-Datum pg_file_unlink(PG_FUNCTION_ARGS)
+Datum
+pg_file_unlink(PG_FUNCTION_ARGS)
 {
-    char *filename;
+   char       *filename;
 
    requireSuperuser();
 
-    filename = absClusterPath(PG_GETARG_TEXT_P(0), false);
+   filename = absClusterPath(PG_GETARG_TEXT_P(0), false);
 
    if (access(filename, W_OK) < 0)
    {
-       if (errno == ENOENT)
-           PG_RETURN_BOOL(false);
+       if (errno == ENOENT)
+           PG_RETURN_BOOL(false);
        else
-           ereport(ERROR,
+           ereport(ERROR,
                    (errcode_for_file_access(),
                     errmsg("file %s not accessible: %m", filename)));
 
@@ -287,17 +294,18 @@ Datum pg_file_unlink(PG_FUNCTION_ARGS)
 }
 
 
-Datum pg_logdir_ls(PG_FUNCTION_ARGS)
+Datum
+pg_logdir_ls(PG_FUNCTION_ARGS)
 {
    FuncCallContext *funcctx;
    struct dirent *de;
    directory_fctx *fctx;
 
-   if (!superuser()) 
+   if (!superuser())
        ereport(ERROR,
                (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
                 (errmsg("only superuser can list the log directory"))));
-   
+
    if (memcmp(Log_filename, "postgresql-%Y-%m-%d_%H%M%S.log", 30) != 0)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
@@ -306,17 +314,17 @@ Datum pg_logdir_ls(PG_FUNCTION_ARGS)
    if (SRF_IS_FIRSTCALL())
    {
        MemoryContext oldcontext;
-       TupleDesc tupdesc;
+       TupleDesc   tupdesc;
 
-       funcctx=SRF_FIRSTCALL_INIT();
+       funcctx = SRF_FIRSTCALL_INIT();
        oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
 
        fctx = palloc(sizeof(directory_fctx));
        if (is_absolute_path(Log_directory))
-           fctx->location = Log_directory;
+           fctx->location = Log_directory;
        else
        {
-           fctx->location = palloc(strlen(DataDir) + strlen(Log_directory) +2);
+           fctx->location = palloc(strlen(DataDir) + strlen(Log_directory) + 2);
            sprintf(fctx->location, "%s/%s", DataDir, Log_directory);
        }
        tupdesc = CreateTemplateTupleDesc(2, false);
@@ -326,11 +334,11 @@ Datum pg_logdir_ls(PG_FUNCTION_ARGS)
                           TEXTOID, -1, 0);
 
        funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
-       
+
        fctx->dirdesc = AllocateDir(fctx->location);
 
        if (!fctx->dirdesc)
-           ereport(ERROR,
+           ereport(ERROR,
                    (errcode_for_file_access(),
                     errmsg("%s is not browsable: %m", fctx->location)));
 
@@ -338,47 +346,47 @@ Datum pg_logdir_ls(PG_FUNCTION_ARGS)
        MemoryContextSwitchTo(oldcontext);
    }
 
-   funcctx=SRF_PERCALL_SETUP();
-   fctx = (directory_fctx*) funcctx->user_fctx;
+   funcctx = SRF_PERCALL_SETUP();
+   fctx = (directory_fctx *) funcctx->user_fctx;
 
-   if (!fctx->dirdesc)  /* not a readable directory  */
+   if (!fctx->dirdesc)         /* not a readable directory  */
        SRF_RETURN_DONE(funcctx);
 
    while ((de = readdir(fctx->dirdesc)) != NULL)
    {
-       char *values[2];
-       HeapTuple tuple;
-            
-       char        *field[MAXDATEFIELDS];
+       char       *values[2];
+       HeapTuple   tuple;
+
+       char       *field[MAXDATEFIELDS];
        char        lowstr[MAXDATELEN + 1];
-       int     dtype;
-       int     nf, ftype[MAXDATEFIELDS];
+       int         dtype;
+       int         nf,
+                   ftype[MAXDATEFIELDS];
        fsec_t      fsec;
-       int     tz = 0;
-       struct      pg_tm date;
+       int         tz = 0;
+       struct pg_tm date;
 
        /*
-        * Default format:
-        *        postgresql-YYYY-MM-DD_HHMMSS.log
+        * Default format: postgresql-YYYY-MM-DD_HHMMSS.log
         */
        if (strlen(de->d_name) != 32
-           || memcmp(de->d_name, "postgresql-", 11)
+           || memcmp(de->d_name, "postgresql-", 11)
            || de->d_name[21] != '_'
            || strcmp(de->d_name + 28, ".log"))
-             continue;
+           continue;
 
        values[1] = palloc(strlen(fctx->location) + strlen(de->d_name) + 2);
        sprintf(values[1], "%s/%s", fctx->location, de->d_name);
 
-       values[0] = de->d_name + 11;       /* timestamp */
+       values[0] = de->d_name + 11;    /* timestamp */
        values[0][17] = 0;
 
-                    /* parse and decode expected timestamp */
+       /* parse and decode expected timestamp */
        if (ParseDateTime(values[0], lowstr, MAXDATELEN, field, ftype, MAXDATEFIELDS, &nf))
-           continue;
+           continue;
 
        if (DecodeDateTime(field, ftype, nf, &dtype, &date, &fsec, &tz))
-           continue;
+           continue;
 
        /* Seems the format fits the expected format; feed it into the tuple */
 
index 16ba5340fbfb34e4c8483f692dd49b0d3055ceed..9d3b46648efa99443874e4ace81cd749ab568372 100644 (file)
@@ -1,5 +1,5 @@
 /******************************************************************************
-  $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.29 2006/09/10 17:36:50 tgl Exp $
+  $PostgreSQL: pgsql/contrib/cube/cube.c,v 1.30 2006/10/04 00:29:44 momjian Exp $
 
   This file contains routines that can be bound to a Postgres backend and
   called by the backend in the process of processing queries.  The calling
@@ -159,7 +159,7 @@ Datum
 cube_in(PG_FUNCTION_ARGS)
 {
    void       *result;
-   char        *str;
+   char       *str;
 
    str = PG_GETARG_CSTRING(0);
 
@@ -170,7 +170,7 @@ cube_in(PG_FUNCTION_ARGS)
 
    cube_scanner_finish();
 
-   PG_RETURN_POINTER (result);
+   PG_RETURN_POINTER(result);
 }
 
 /* Allow conversion from text to cube to allow input of computed strings */
@@ -178,11 +178,11 @@ cube_in(PG_FUNCTION_ARGS)
 Datum
 cube(PG_FUNCTION_ARGS)
 {
-   char    *cstring;
+   char       *cstring;
 
    cstring = DatumGetCString(DirectFunctionCall1(textout, PointerGetDatum(PG_GETARG_TEXT_P(0))));
 
-   PG_RETURN_DATUM (DirectFunctionCall1 (cube_in, PointerGetDatum(cstring)));
+   PG_RETURN_DATUM(DirectFunctionCall1(cube_in, PointerGetDatum(cstring)));
 }
 
 
@@ -192,12 +192,14 @@ cube(PG_FUNCTION_ARGS)
 Datum
 cube_a_f8_f8(PG_FUNCTION_ARGS)
 {
-   int     i;
-   int     dim;
-   int     size;
-   NDBOX   *result;
-   ArrayType   *ur, *ll;
-   double  *dur, *dll;
+   int         i;
+   int         dim;
+   int         size;
+   NDBOX      *result;
+   ArrayType  *ur,
+              *ll;
+   double     *dur,
+              *dll;
 
    ur = (ArrayType *) PG_GETARG_VARLENA_P(0);
    ll = (ArrayType *) PG_GETARG_VARLENA_P(1);
@@ -205,31 +207,31 @@ cube_a_f8_f8(PG_FUNCTION_ARGS)
    if (ARR_HASNULL(ur) || ARR_HASNULL(ll))
    {
        ereport(ERROR,
-           (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
-           errmsg("Cannot work with NULL arrays")));
+               (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
+                errmsg("Cannot work with NULL arrays")));
    }
 
    dim = ARRNELEMS(ur);
    if (ARRNELEMS(ll) != dim)
    {
        ereport(ERROR,
-           (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
-           errmsg("UR and LL arrays must be of same length")));
+               (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
+                errmsg("UR and LL arrays must be of same length")));
    }
 
    dur = ARRPTR(ur);
    dll = ARRPTR(ll);
 
    size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
-   result = (NDBOX *) palloc (size);
-   memset (result, 0, size);
+   result = (NDBOX *) palloc(size);
+   memset(result, 0, size);
    result->size = size;
    result->dim = dim;
 
-   for (i=0; i<dim; i++)
+   for (i = 0; i < dim; i++)
    {
        result->x[i] = dur[i];
-       result->x[i+dim] = dll[i];
+       result->x[i + dim] = dll[i];
    }
 
    PG_RETURN_POINTER(result);
@@ -241,20 +243,20 @@ cube_a_f8_f8(PG_FUNCTION_ARGS)
 Datum
 cube_a_f8(PG_FUNCTION_ARGS)
 {
-   int     i;
-   int     dim;
-   int     size;
-   NDBOX   *result;
-   ArrayType   *ur;
-   double  *dur;
+   int         i;
+   int         dim;
+   int         size;
+   NDBOX      *result;
+   ArrayType  *ur;
+   double     *dur;
 
    ur = (ArrayType *) PG_GETARG_VARLENA_P(0);
 
    if (ARR_HASNULL(ur))
    {
        ereport(ERROR,
-           (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
-           errmsg("Cannot work with NULL arrays")));
+               (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
+                errmsg("Cannot work with NULL arrays")));
    }
 
    dim = ARRNELEMS(ur);
@@ -262,15 +264,15 @@ cube_a_f8(PG_FUNCTION_ARGS)
    dur = ARRPTR(ur);
 
    size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
-   result = (NDBOX *) palloc (size);
-   memset (result, 0, size);
+   result = (NDBOX *) palloc(size);
+   memset(result, 0, size);
    result->size = size;
    result->dim = dim;
 
-   for (i=0; i<dim; i++)
+   for (i = 0; i < dim; i++)
    {
        result->x[i] = dur[i];
-       result->x[i+dim] = dur[i];
+       result->x[i + dim] = dur[i];
    }
 
    PG_RETURN_POINTER(result);
@@ -279,10 +281,13 @@ cube_a_f8(PG_FUNCTION_ARGS)
 Datum
 cube_subset(PG_FUNCTION_ARGS)
 {
-   NDBOX       *c, *result;
-   ArrayType   *idx;
-   int          size, dim, i;
-   int         *dx;
+   NDBOX      *c,
+              *result;
+   ArrayType  *idx;
+   int         size,
+               dim,
+               i;
+   int        *dx;
 
    c = (NDBOX *) PG_GETARG_POINTER(0);
    idx = (ArrayType *) PG_GETARG_VARLENA_P(1);
@@ -290,30 +295,30 @@ cube_subset(PG_FUNCTION_ARGS)
    if (ARR_HASNULL(idx))
    {
        ereport(ERROR,
-           (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
-           errmsg("Cannot work with NULL arrays")));
+               (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
+                errmsg("Cannot work with NULL arrays")));
    }
 
-   dx = (int4 *) ARR_DATA_PTR (idx);
+   dx = (int4 *) ARR_DATA_PTR(idx);
 
    dim = ARRNELEMS(idx);
    size = offsetof(NDBOX, x[0]) + sizeof(double) * 2 * dim;
-   result = (NDBOX *) palloc (size);
-   memset (result, 0, size);
+   result = (NDBOX *) palloc(size);
+   memset(result, 0, size);
    result->size = size;
    result->dim = dim;
 
-   for (i=0; i<dim; i++)
+   for (i = 0; i < dim; i++)
    {
        if ((dx[i] <= 0) || (dx[i] > c->dim))
        {
-           pfree (result);
+           pfree(result);
            ereport(ERROR,
-               (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
-               errmsg("Index out of bounds")));
+                   (errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
+                    errmsg("Index out of bounds")));
        }
-       result->x[i] = c->x[dx[i]-1];
-       result->x[i+dim] = c->x[dx[i]+c->dim-1];
+       result->x[i] = c->x[dx[i] - 1];
+       result->x[i + dim] = c->x[dx[i] + c->dim - 1];
    }
 
    PG_RETURN_POINTER(result);
@@ -327,11 +332,11 @@ cube_out(PG_FUNCTION_ARGS)
    int         dim;
    int         i;
    int         ndig;
-   NDBOX       *cube;
+   NDBOX      *cube;
 
    initStringInfo(&buf);
 
-   cube = (NDBOX *) PG_GETARG_POINTER (0);
+   cube = (NDBOX *) PG_GETARG_POINTER(0);
 
    dim = cube->dim;
 
@@ -369,7 +374,7 @@ cube_out(PG_FUNCTION_ARGS)
        appendStringInfoChar(&buf, ')');
    }
 
-   PG_RETURN_CSTRING (buf.data);
+   PG_RETURN_CSTRING(buf.data);
 }
 
 
@@ -383,11 +388,11 @@ cube_out(PG_FUNCTION_ARGS)
 ** the predicate x op query == FALSE, where op is the oper
 ** corresponding to strategy in the pg_amop table.
 */
-Datum  
+Datum
 g_cube_consistent(PG_FUNCTION_ARGS)
 {
-   GISTENTRY *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
-   NDBOX *query = (NDBOX *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
+   GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
+   NDBOX      *query = (NDBOX *) DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(1)));
    StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
 
    /*
@@ -414,7 +419,7 @@ g_cube_union(PG_FUNCTION_ARGS)
    NDBOX      *out = (NDBOX *) NULL;
    NDBOX      *tmp;
    int        *sizep;
-   GistEntryVector *entryvec;
+   GistEntryVector *entryvec;
 
    entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
    sizep = (int *) PG_GETARG_POINTER(1);
@@ -446,15 +451,15 @@ g_cube_union(PG_FUNCTION_ARGS)
 */
 
 Datum
-g_cube_compress (PG_FUNCTION_ARGS)
+g_cube_compress(PG_FUNCTION_ARGS)
 {
-    PG_RETURN_DATUM(PG_GETARG_DATUM(0));
+   PG_RETURN_DATUM(PG_GETARG_DATUM(0));
 }
 
 Datum
-g_cube_decompress (PG_FUNCTION_ARGS)
+g_cube_decompress(PG_FUNCTION_ARGS)
 {
-    PG_RETURN_DATUM(PG_GETARG_DATUM(0));
+   PG_RETURN_DATUM(PG_GETARG_DATUM(0));
 }
 
 
@@ -463,17 +468,17 @@ g_cube_decompress (PG_FUNCTION_ARGS)
 ** As in the R-tree paper, we use change in area as our penalty metric
 */
 Datum
-g_cube_penalty (PG_FUNCTION_ARGS)
+g_cube_penalty(PG_FUNCTION_ARGS)
 {
-   GISTENTRY *origentry = (GISTENTRY *) PG_GETARG_POINTER(0);
-   GISTENTRY *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
-   float     *result = (float *) PG_GETARG_POINTER(2);
+   GISTENTRY  *origentry = (GISTENTRY *) PG_GETARG_POINTER(0);
+   GISTENTRY  *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
+   float      *result = (float *) PG_GETARG_POINTER(2);
    NDBOX      *ud;
    double      tmp1,
                tmp2;
 
    ud = cube_union_v0((NDBOX *) DatumGetPointer(origentry->key),
-                   (NDBOX *) DatumGetPointer(newentry->key));
+                      (NDBOX *) DatumGetPointer(newentry->key));
    rt_cube_size(ud, &tmp1);
    rt_cube_size((NDBOX *) DatumGetPointer(origentry->key), &tmp2);
    *result = (float) (tmp1 - tmp2);
@@ -481,7 +486,7 @@ g_cube_penalty (PG_FUNCTION_ARGS)
    /*
     * fprintf(stderr, "penalty\n"); fprintf(stderr, "\t%g\n", *result);
     */
-   PG_RETURN_FLOAT8 (*result);
+   PG_RETURN_FLOAT8(*result);
 }
 
 
@@ -493,8 +498,8 @@ g_cube_penalty (PG_FUNCTION_ARGS)
 Datum
 g_cube_picksplit(PG_FUNCTION_ARGS)
 {
-   GistEntryVector *entryvec;
-   GIST_SPLITVEC   *v;
+   GistEntryVector *entryvec;
+   GIST_SPLITVEC *v;
    OffsetNumber i,
                j;
    NDBOX      *datum_alpha,
@@ -546,9 +551,9 @@ g_cube_picksplit(PG_FUNCTION_ARGS)
            /* size_waste = size_union - size_inter; */
            union_d = cube_union_v0(datum_alpha, datum_beta);
            rt_cube_size(union_d, &size_union);
-           inter_d = (NDBOX *) DatumGetPointer (DirectFunctionCall2 
-                                (cube_inter, 
-                                 entryvec->vector[i].key, entryvec->vector[j].key));
+           inter_d = (NDBOX *) DatumGetPointer(DirectFunctionCall2
+                                               (cube_inter,
+                         entryvec->vector[i].key, entryvec->vector[j].key));
            rt_cube_size(inter_d, &size_inter);
            size_waste = size_union - size_inter;
 
@@ -649,12 +654,13 @@ g_cube_picksplit(PG_FUNCTION_ARGS)
 Datum
 g_cube_same(PG_FUNCTION_ARGS)
 {
-   NDBOX   *b1, *b2;
-   bool    *result;
-   
-   b1 = (NDBOX *) PG_GETARG_POINTER (0);
-   b2 = (NDBOX *) PG_GETARG_POINTER (1);
-   result = (bool *) PG_GETARG_POINTER (2);
+   NDBOX      *b1,
+              *b2;
+   bool       *result;
+
+   b1 = (NDBOX *) PG_GETARG_POINTER(0);
+   b2 = (NDBOX *) PG_GETARG_POINTER(1);
+   result = (bool *) PG_GETARG_POINTER(2);
 
    if (cube_cmp_v0(b1, b2) == 0)
        *result = TRUE;
@@ -664,7 +670,7 @@ g_cube_same(PG_FUNCTION_ARGS)
    /*
     * fprintf(stderr, "same: %s\n", (*result ? "TRUE" : "FALSE" ));
     */
-   PG_RETURN_POINTER (result);
+   PG_RETURN_POINTER(result);
 }
 
 /*
@@ -803,14 +809,15 @@ cube_union_v0(NDBOX * a, NDBOX * b)
 }
 
 Datum
-cube_union (PG_FUNCTION_ARGS)
+cube_union(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
 
-   PG_RETURN_POINTER(cube_union_v0(a,b));
+   PG_RETURN_POINTER(cube_union_v0(a, b));
 }
 
 /* cube_inter */
@@ -818,7 +825,9 @@ Datum
 cube_inter(PG_FUNCTION_ARGS)
 {
    int         i;
-   NDBOX      *result, *a, *b;
+   NDBOX      *result,
+              *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -874,17 +883,17 @@ cube_inter(PG_FUNCTION_ARGS)
    /*
     * Is it OK to return a non-null intersection for non-overlapping boxes?
     */
-   PG_RETURN_POINTER (result);
+   PG_RETURN_POINTER(result);
 }
 
 /* cube_size */
 Datum
 cube_size(PG_FUNCTION_ARGS)
 {
-   NDBOX       *a;
+   NDBOX      *a;
    int         i,
                j;
-   double      result;
+   double      result;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
 
@@ -892,7 +901,7 @@ cube_size(PG_FUNCTION_ARGS)
    for (i = 0, j = a->dim; i < a->dim; i++, j++)
        result = result * Abs((a->x[j] - a->x[i]));
 
-   PG_RETURN_FLOAT8 (result);
+   PG_RETURN_FLOAT8(result);
 }
 
 void
@@ -994,10 +1003,11 @@ cube_cmp_v0(NDBOX * a, NDBOX * b)
    return 0;
 }
 
-Datum 
+Datum
 cube_cmp(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -1009,7 +1019,8 @@ cube_cmp(PG_FUNCTION_ARGS)
 Datum
 cube_eq(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -1021,7 +1032,8 @@ cube_eq(PG_FUNCTION_ARGS)
 Datum
 cube_ne(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -1033,7 +1045,8 @@ cube_ne(PG_FUNCTION_ARGS)
 Datum
 cube_lt(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -1045,7 +1058,8 @@ cube_lt(PG_FUNCTION_ARGS)
 Datum
 cube_gt(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -1057,7 +1071,8 @@ cube_gt(PG_FUNCTION_ARGS)
 Datum
 cube_le(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -1069,7 +1084,8 @@ cube_le(PG_FUNCTION_ARGS)
 Datum
 cube_ge(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -1122,7 +1138,8 @@ cube_contains_v0(NDBOX * a, NDBOX * b)
 Datum
 cube_contains(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -1135,12 +1152,13 @@ cube_contains(PG_FUNCTION_ARGS)
 Datum
 cube_contained(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
 
-   PG_RETURN_BOOL (cube_contains_v0(b, a));
+   PG_RETURN_BOOL(cube_contains_v0(b, a));
 }
 
 /* Overlap */
@@ -1193,12 +1211,13 @@ cube_overlap_v0(NDBOX * a, NDBOX * b)
 Datum
 cube_overlap(PG_FUNCTION_ARGS)
 {
-   NDBOX   *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
 
-   PG_RETURN_BOOL (cube_overlap_v0(a, b));
+   PG_RETURN_BOOL(cube_overlap_v0(a, b));
 }
 
 
@@ -1213,7 +1232,8 @@ cube_distance(PG_FUNCTION_ARGS)
    int         i;
    double      d,
                distance;
-   NDBOX      *a, *b;
+   NDBOX      *a,
+              *b;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
    b = (NDBOX *) PG_GETARG_POINTER(1);
@@ -1266,7 +1286,7 @@ cube_is_point(PG_FUNCTION_ARGS)
 {
    int         i,
                j;
-   NDBOX       *a;
+   NDBOX      *a;
 
    a = (NDBOX *) PG_GETARG_POINTER(0);
 
@@ -1283,7 +1303,7 @@ cube_is_point(PG_FUNCTION_ARGS)
 Datum
 cube_dim(PG_FUNCTION_ARGS)
 {
-   NDBOX   *c;
+   NDBOX      *c;
 
    c = (NDBOX *) PG_GETARG_POINTER(0);
 
@@ -1397,8 +1417,8 @@ cube_f8(PG_FUNCTION_ARGS)
    result->dim = 1;
    result->x[0] = PG_GETARG_FLOAT8(0);
    result->x[1] = result->x[0];
-   
-   PG_RETURN_POINTER (result);
+
+   PG_RETURN_POINTER(result);
 }
 
 /* Create a one dimensional box */
@@ -1416,7 +1436,7 @@ cube_f8_f8(PG_FUNCTION_ARGS)
    result->x[0] = PG_GETARG_FLOAT8(0);
    result->x[1] = PG_GETARG_FLOAT8(1);
 
-   PG_RETURN_POINTER (result);
+   PG_RETURN_POINTER(result);
 }
 
 /* Add a dimension to an existing cube with the same values for the new
@@ -1431,7 +1451,7 @@ cube_c_f8(PG_FUNCTION_ARGS)
    int         i;
 
    c = (NDBOX *) PG_GETARG_POINTER(0);
-   x = PG_GETARG_FLOAT8 (1);
+   x = PG_GETARG_FLOAT8(1);
 
    size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) *2;
    result = (NDBOX *) palloc(size);
@@ -1446,7 +1466,7 @@ cube_c_f8(PG_FUNCTION_ARGS)
    result->x[result->dim - 1] = x;
    result->x[2 * result->dim - 1] = x;
 
-   PG_RETURN_POINTER(result);  
+   PG_RETURN_POINTER(result);
 }
 
 /* Add a dimension to an existing cube */
@@ -1455,13 +1475,14 @@ cube_c_f8_f8(PG_FUNCTION_ARGS)
 {
    NDBOX      *c;
    NDBOX      *result;
-   double      x1, x2;
+   double      x1,
+               x2;
    int         size;
    int         i;
 
    c = (NDBOX *) PG_GETARG_POINTER(0);
-   x1 = PG_GETARG_FLOAT8 (1);
-   x2 = PG_GETARG_FLOAT8 (2);
+   x1 = PG_GETARG_FLOAT8(1);
+   x2 = PG_GETARG_FLOAT8(2);
 
    size = offsetof(NDBOX, x[0]) + sizeof(double) * (c->dim + 1) *2;
    result = (NDBOX *) palloc(size);
@@ -1476,7 +1497,5 @@ cube_c_f8_f8(PG_FUNCTION_ARGS)
    result->x[result->dim - 1] = x1;
    result->x[2 * result->dim - 1] = x2;
 
-   PG_RETURN_POINTER(result);  
+   PG_RETURN_POINTER(result);
 }
-
-
index 7a46673b6b170858c0781ef3b6497ea4b84e3211..08fb6328fbcfbce44befbc212b89fcbf5329d1bf 100644 (file)
@@ -8,7 +8,7 @@
  * Darko Prenosil <[email protected]>
  * Shridhar Daithankar <[email protected]>
  *
- * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.58 2006/09/02 21:11:15 joe Exp $
+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.59 2006/10/04 00:29:44 momjian Exp $
  * Copyright (c) 2001-2006, PostgreSQL Global Development Group
  * ALL RIGHTS RESERVED;
  *
@@ -362,11 +362,11 @@ dblink_open(PG_FUNCTION_ARGS)
            DBLINK_RES_INTERNALERROR("begin error");
        PQclear(res);
        rconn->newXactForCursor = TRUE;
+
        /*
         * Since transaction state was IDLE, we force cursor count to
-        * initially be 0. This is needed as a previous ABORT might
-        * have wiped out our transaction without maintaining the
-        * cursor count for us.
+        * initially be 0. This is needed as a previous ABORT might have wiped
+        * out our transaction without maintaining the cursor count for us.
         */
        rconn->openCursorCount = 0;
    }
@@ -621,8 +621,8 @@ dblink_fetch(PG_FUNCTION_ARGS)
        if (PQnfields(res) != tupdesc->natts)
            ereport(ERROR,
                    (errcode(ERRCODE_DATATYPE_MISMATCH),
-               errmsg("remote query result rowtype does not match "
-                       "the specified FROM clause rowtype")));
+                    errmsg("remote query result rowtype does not match "
+                           "the specified FROM clause rowtype")));
 
        /* fast track when no results */
        if (funcctx->max_calls < 1)
@@ -827,7 +827,7 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
 
            if (!res ||
                (PQresultStatus(res) != PGRES_COMMAND_OK &&
-               PQresultStatus(res) != PGRES_TUPLES_OK))
+                PQresultStatus(res) != PGRES_TUPLES_OK))
            {
                if (fail)
                    DBLINK_RES_ERROR("sql error");
@@ -839,33 +839,33 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
                    SRF_RETURN_DONE(funcctx);
                }
            }
-   
+
            if (PQresultStatus(res) == PGRES_COMMAND_OK)
            {
                is_sql_cmd = true;
-   
+
                /* need a tuple descriptor representing one TEXT column */
                tupdesc = CreateTemplateTupleDesc(1, false);
                TupleDescInitEntry(tupdesc, (AttrNumber) 1, "status",
-                               TEXTOID, -1, 0);
-   
+                                  TEXTOID, -1, 0);
+
                /*
-               * and save a copy of the command status string to return as our
-               * result tuple
-               */
+                * and save a copy of the command status string to return as
+                * our result tuple
+                */
                sql_cmd_status = PQcmdStatus(res);
                funcctx->max_calls = 1;
            }
            else
                funcctx->max_calls = PQntuples(res);
-   
+
            /* got results, keep track of them */
            funcctx->user_fctx = res;
-   
+
            /* if needed, close the connection to the database and cleanup */
            if (freeconn)
                PQfinish(conn);
-   
+
            if (!is_sql_cmd)
            {
                /* get a tuple descriptor for our result type */
@@ -878,26 +878,29 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
                        /* failed to determine actual type of RECORD */
                        ereport(ERROR,
                                (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
-                           errmsg("function returning record called in context "
-                               "that cannot accept type record")));
+                       errmsg("function returning record called in context "
+                              "that cannot accept type record")));
                        break;
                    default:
                        /* result type isn't composite */
                        elog(ERROR, "return type must be a row type");
                        break;
                }
-   
+
                /* make sure we have a persistent copy of the tupdesc */
                tupdesc = CreateTupleDescCopy(tupdesc);
            }
-   
-           /* check result and tuple descriptor have the same number of columns */
+
+           /*
+            * check result and tuple descriptor have the same number of
+            * columns
+            */
            if (PQnfields(res) != tupdesc->natts)
                ereport(ERROR,
                        (errcode(ERRCODE_DATATYPE_MISMATCH),
-                   errmsg("remote query result rowtype does not match "
-                           "the specified FROM clause rowtype")));
-   
+                        errmsg("remote query result rowtype does not match "
+                               "the specified FROM clause rowtype")));
+
            /* fast track when no results */
            if (funcctx->max_calls < 1)
            {
@@ -905,11 +908,11 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
                    PQclear(res);
                SRF_RETURN_DONE(funcctx);
            }
-   
+
            /* store needed metadata for subsequent calls */
            attinmeta = TupleDescGetAttInMetadata(tupdesc);
            funcctx->attinmeta = attinmeta;
-   
+
            MemoryContextSwitchTo(oldcontext);
        }
        else
@@ -991,9 +994,9 @@ PG_FUNCTION_INFO_V1(dblink_get_connections);
 Datum
 dblink_get_connections(PG_FUNCTION_ARGS)
 {
-   HASH_SEQ_STATUS         status;
-   remoteConnHashEnt      *hentry;
-   ArrayBuildState        *astate = NULL;
+   HASH_SEQ_STATUS status;
+   remoteConnHashEnt *hentry;
+   ArrayBuildState *astate = NULL;
 
    if (remoteConnHash)
    {
@@ -1019,19 +1022,19 @@ dblink_get_connections(PG_FUNCTION_ARGS)
  *
  * Returns 1 if the connection is busy, 0 otherwise
  * Params:
- *     text connection_name - name of the connection to check
- * 
+ * text connection_name - name of the connection to check
+ *
  */
 PG_FUNCTION_INFO_V1(dblink_is_busy);
 Datum
 dblink_is_busy(PG_FUNCTION_ARGS)
 {
-   char           *msg;
-   PGconn         *conn = NULL;
-   char           *conname = NULL;
-   char           *connstr = NULL;
-   remoteConn     *rconn = NULL;
-   bool            freeconn = false;
+   char       *msg;
+   PGconn     *conn = NULL;
+   char       *conname = NULL;
+   char       *connstr = NULL;
+   remoteConn *rconn = NULL;
+   bool        freeconn = false;
 
    DBLINK_INIT;
    DBLINK_GET_CONN;
@@ -1045,27 +1048,27 @@ dblink_is_busy(PG_FUNCTION_ARGS)
 /*
  * Cancels a running request on a connection
  *
- * Returns text: 
+ * Returns text:
  * "OK" if the cancel request has been sent correctly,
- *      an error message otherwise
- * 
+ *     an error message otherwise
+ *
  * Params:
- *     text connection_name - name of the connection to check
- * 
+ * text connection_name - name of the connection to check
+ *
  */
 PG_FUNCTION_INFO_V1(dblink_cancel_query);
 Datum
 dblink_cancel_query(PG_FUNCTION_ARGS)
 {
-   char           *msg;
-   int             res = 0;
-   PGconn         *conn = NULL;
-   char           *conname = NULL;
-   char           *connstr = NULL;
-   remoteConn     *rconn = NULL;
-   bool            freeconn = false;
-   PGcancel       *cancel;
-   char            errbuf[256];
+   char       *msg;
+   int         res = 0;
+   PGconn     *conn = NULL;
+   char       *conname = NULL;
+   char       *connstr = NULL;
+   remoteConn *rconn = NULL;
+   bool        freeconn = false;
+   PGcancel   *cancel;
+   char        errbuf[256];
 
    DBLINK_INIT;
    DBLINK_GET_CONN;
@@ -1077,7 +1080,7 @@ dblink_cancel_query(PG_FUNCTION_ARGS)
    PQfreeCancel(cancel);
 
    if (res == 0)
-       PG_RETURN_TEXT_P(GET_TEXT("OK"));   
+       PG_RETURN_TEXT_P(GET_TEXT("OK"));
    else
        PG_RETURN_TEXT_P(GET_TEXT(errbuf));
 }
@@ -1086,23 +1089,23 @@ dblink_cancel_query(PG_FUNCTION_ARGS)
 /*
  * Get error message from a connection
  *
- * Returns text: 
+ * Returns text:
  * "OK" if no error, an error message otherwise
- * 
+ *
  * Params:
- *     text connection_name - name of the connection to check
- * 
+ * text connection_name - name of the connection to check
+ *
  */
 PG_FUNCTION_INFO_V1(dblink_error_message);
 Datum
 dblink_error_message(PG_FUNCTION_ARGS)
 {
-   char           *msg;
-   PGconn         *conn = NULL;
-   char           *conname = NULL;
-   char           *connstr = NULL;
-   remoteConn     *rconn = NULL;
-   bool            freeconn = false;
+   char       *msg;
+   PGconn     *conn = NULL;
+   char       *conname = NULL;
+   char       *connstr = NULL;
+   remoteConn *rconn = NULL;
+   bool        freeconn = false;
 
    DBLINK_INIT;
    DBLINK_GET_CONN;
@@ -1859,7 +1862,7 @@ get_sql_delete(Oid relid, int2vector *pkattnums, int16 pknumatts, char **tgt_pka
    char       *relname;
    TupleDesc   tupdesc;
    int         natts;
-   StringInfoData  buf;
+   StringInfoData buf;
    int         i;
 
    initStringInfo(&buf);
index 5fb5999610378f533bdb572da19d196a2e9b2285..20ae203416a38abbbe0a9082e9185365c8578387 100644 (file)
 #include "storage/bufpage.h"
 
 
-typedef struct {
-   uint16  keylen;
-   uint16  vallen;
-   uint32  
-       valisnull:1,
-       pos:31;
-} HEntry; 
-
-
-typedef struct {
-   int4    len;
-   int4    size;
-   char    data[1];
-} HStore;
+typedef struct
+{
+   uint16      keylen;
+   uint16      vallen;
+   uint32
+               valisnull:1,
+               pos:31;
+}  HEntry;
+
+
+typedef struct
+{
+   int4        len;
+   int4        size;
+   char        data[1];
+}  HStore;
 
 #define HSHRDSIZE  (2*sizeof(int4))
 #define CALCDATASIZE(x, lenstr) ( (x) * sizeof(HEntry) + HSHRDSIZE + (lenstr) )
-#define ARRPTR(x)       ( (HEntry*) ( (char*)(x) + HSHRDSIZE ) )
-#define STRPTR(x)       ( (char*)(x) + HSHRDSIZE + ( sizeof(HEntry) * ((HStore*)x)->size ) )
+#define ARRPTR(x)      ( (HEntry*) ( (char*)(x) + HSHRDSIZE ) )
+#define STRPTR(x)      ( (char*)(x) + HSHRDSIZE + ( sizeof(HEntry) * ((HStore*)x)->size ) )
 
 
-#define PG_GETARG_HS(x)    ((HStore*)PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))
+#define PG_GETARG_HS(x) ((HStore*)PG_DETOAST_DATUM(PG_GETARG_DATUM(x)))
 
-typedef struct {
-        char    *key;
-        char    *val;
-        uint16  keylen;
-        uint16  vallen;
-        bool    isnull;  
-        bool    needfree;  
-} Pairs;
+typedef struct
+{
+   char       *key;
+   char       *val;
+   uint16      keylen;
+   uint16      vallen;
+   bool        isnull;
+   bool        needfree;
+}  Pairs;
 
-int comparePairs(const void *a, const void *b);
-int uniquePairs(Pairs * a, int4 l, int4 *buflen);
+int            comparePairs(const void *a, const void *b);
+int            uniquePairs(Pairs * a, int4 l, int4 *buflen);
 
 #endif
index f1c8738266552f7c0460d7b8ba35103743da15c6..4220a5541d193f09bbbfe552e0d8671f6d3f746e 100644 (file)
@@ -7,8 +7,8 @@
 
 /* bigint defines */
 #define BITBYTE 8
-#define SIGLENINT  4          /* >122 => key will toast, so very slow!!! */
-#define SIGLEN  ( sizeof(int)*SIGLENINT )
+#define SIGLENINT  4           /* >122 => key will toast, so very slow!!! */
+#define SIGLEN ( sizeof(int)*SIGLENINT )
 #define SIGLENBIT (SIGLEN*BITBYTE)
 
 typedef char BITVEC[SIGLEN];
@@ -36,22 +36,23 @@ typedef char *BITVECP;
 #define HASHVAL(val) (((unsigned int)(val)) % SIGLENBIT)
 #define HASH(sign, val) SETBIT((sign), HASHVAL(val))
 
-typedef struct {
-   int4        len;
-   int4        flag;
-   char        data[1];
-}       GISTTYPE;
+typedef struct
+{
+   int4        len;
+   int4        flag;
+   char        data[1];
+}  GISTTYPE;
 
-#define ALLISTRUE       0x04
+#define ALLISTRUE      0x04
 
-#define ISALLTRUE(x)    ( ((GISTTYPE*)x)->flag & ALLISTRUE )
+#define ISALLTRUE(x)   ( ((GISTTYPE*)x)->flag & ALLISTRUE )
 
-#define GTHDRSIZE       ( sizeof(int4)*2  )
+#define GTHDRSIZE      ( sizeof(int4)*2  )
 #define CALCGTSIZE(flag) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )
-  
-#define GETSIGN(x)      ( (BITVECP)( (char*)x+GTHDRSIZE ) )
 
-#define SUMBIT(val) (       \
+#define GETSIGN(x)     ( (BITVECP)( (char*)x+GTHDRSIZE ) )
+
+#define SUMBIT(val) (      \
    GETBITBYTE((val),0) + \
    GETBITBYTE((val),1) + \
    GETBITBYTE((val),2) + \
@@ -67,20 +68,22 @@ typedef struct {
 #define WISH_F(a,b,c) (double)( -(double)(((a)-(b))*((a)-(b))*((a)-(b)))*(c) )
 
 PG_FUNCTION_INFO_V1(ghstore_in);
-Datum     ghstore_in(PG_FUNCTION_ARGS);
+Datum      ghstore_in(PG_FUNCTION_ARGS);
 
 PG_FUNCTION_INFO_V1(ghstore_out);
-Datum     ghstore_out(PG_FUNCTION_ARGS);
-  
+Datum      ghstore_out(PG_FUNCTION_ARGS);
+
 
 Datum
-ghstore_in(PG_FUNCTION_ARGS) {
+ghstore_in(PG_FUNCTION_ARGS)
+{
    elog(ERROR, "Not implemented");
    PG_RETURN_DATUM(0);
 }
 
 Datum
-ghstore_out(PG_FUNCTION_ARGS) {
+ghstore_out(PG_FUNCTION_ARGS)
+{
    elog(ERROR, "Not implemented");
    PG_RETURN_DATUM(0);
 }
@@ -93,36 +96,41 @@ PG_FUNCTION_INFO_V1(ghstore_picksplit);
 PG_FUNCTION_INFO_V1(ghstore_union);
 PG_FUNCTION_INFO_V1(ghstore_same);
 
-Datum     ghstore_consistent(PG_FUNCTION_ARGS);
-Datum     ghstore_compress(PG_FUNCTION_ARGS);
-Datum     ghstore_decompress(PG_FUNCTION_ARGS);
-Datum     ghstore_penalty(PG_FUNCTION_ARGS);
-Datum     ghstore_picksplit(PG_FUNCTION_ARGS);
-Datum     ghstore_union(PG_FUNCTION_ARGS);
-Datum     ghstore_same(PG_FUNCTION_ARGS);
+Datum      ghstore_consistent(PG_FUNCTION_ARGS);
+Datum      ghstore_compress(PG_FUNCTION_ARGS);
+Datum      ghstore_decompress(PG_FUNCTION_ARGS);
+Datum      ghstore_penalty(PG_FUNCTION_ARGS);
+Datum      ghstore_picksplit(PG_FUNCTION_ARGS);
+Datum      ghstore_union(PG_FUNCTION_ARGS);
+Datum      ghstore_same(PG_FUNCTION_ARGS);
 
 Datum
-ghstore_compress(PG_FUNCTION_ARGS) {
+ghstore_compress(PG_FUNCTION_ARGS)
+{
    GISTENTRY  *entry = (GISTENTRY *) PG_GETARG_POINTER(0);
    GISTENTRY  *retval = entry;
-    
-   if (entry->leafkey) {                              
-       GISTTYPE   *res = (GISTTYPE*)palloc(CALCGTSIZE(0));
-       HStore     *toastedval = (HStore *) DatumGetPointer(entry->key);
-       HStore     *val = (HStore *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
-       HEntry     *ptr = ARRPTR(val);
-       char       *words = STRPTR(val);
-
-       memset(res,0,CALCGTSIZE(0));
-       res->len=CALCGTSIZE(0);
-   
-       while(ptr-ARRPTR(val) < val->size) {
-           int h;
-           h = crc32_sz((char*)(words+ptr->pos), ptr->keylen);
-           HASH( GETSIGN(res), h);
-           if ( !ptr->valisnull ) {
-               h = crc32_sz((char *)(words+ptr->pos+ptr->keylen), ptr->vallen);
-               HASH( GETSIGN(res), h);
+
+   if (entry->leafkey)
+   {
+       GISTTYPE   *res = (GISTTYPE *) palloc(CALCGTSIZE(0));
+       HStore     *toastedval = (HStore *) DatumGetPointer(entry->key);
+       HStore     *val = (HStore *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
+       HEntry     *ptr = ARRPTR(val);
+       char       *words = STRPTR(val);
+
+       memset(res, 0, CALCGTSIZE(0));
+       res->len = CALCGTSIZE(0);
+
+       while (ptr - ARRPTR(val) < val->size)
+       {
+           int         h;
+
+           h = crc32_sz((char *) (words + ptr->pos), ptr->keylen);
+           HASH(GETSIGN(res), h);
+           if (!ptr->valisnull)
+           {
+               h = crc32_sz((char *) (words + ptr->pos + ptr->keylen), ptr->vallen);
+               HASH(GETSIGN(res), h);
            }
            ptr++;
        }
@@ -135,14 +143,16 @@ ghstore_compress(PG_FUNCTION_ARGS) {
                      entry->rel, entry->page,
                      entry->offset,
                      FALSE);
-   } else if ( !ISALLTRUE(DatumGetPointer(entry->key)) ) {
-       int4        i;
+   }
+   else if (!ISALLTRUE(DatumGetPointer(entry->key)))
+   {
+       int4        i;
        GISTTYPE   *res;
-       BITVECP  sign = GETSIGN(DatumGetPointer(entry->key));
-       
+       BITVECP     sign = GETSIGN(DatumGetPointer(entry->key));
+
        LOOPBYTE(
-           if ((sign[i] & 0xff) != 0xff)
-               PG_RETURN_POINTER(retval);
+                if ((sign[i] & 0xff) != 0xff)
+                PG_RETURN_POINTER(retval);
        );
 
        res = (GISTTYPE *) palloc(CALCGTSIZE(ALLISTRUE));
@@ -152,7 +162,7 @@ ghstore_compress(PG_FUNCTION_ARGS) {
        retval = (GISTENTRY *) palloc(sizeof(GISTENTRY));
        gistentryinit(*retval, PointerGetDatum(res),
                      entry->rel, entry->page,
-                     entry->offset, 
+                     entry->offset,
                      FALSE);
    }
 
@@ -160,15 +170,17 @@ ghstore_compress(PG_FUNCTION_ARGS) {
 }
 
 Datum
-ghstore_decompress(PG_FUNCTION_ARGS) {
+ghstore_decompress(PG_FUNCTION_ARGS)
+{
    PG_RETURN_DATUM(PG_GETARG_DATUM(0));
 }
 
 Datum
-ghstore_same(PG_FUNCTION_ARGS) {
+ghstore_same(PG_FUNCTION_ARGS)
+{
    GISTTYPE   *a = (GISTTYPE *) PG_GETARG_POINTER(0);
    GISTTYPE   *b = (GISTTYPE *) PG_GETARG_POINTER(1);
-   bool       *result = (bool *) PG_GETARG_POINTER(2);
+   bool       *result = (bool *) PG_GETARG_POINTER(2);
 
    if (ISALLTRUE(a) && ISALLTRUE(b))
        *result = true;
@@ -176,83 +188,97 @@ ghstore_same(PG_FUNCTION_ARGS) {
        *result = false;
    else if (ISALLTRUE(b))
        *result = false;
-   else {
-       int4            i;
-       BITVECP         sa = GETSIGN(a),
-               sb = GETSIGN(b);
+   else
+   {
+       int4        i;
+       BITVECP     sa = GETSIGN(a),
+                   sb = GETSIGN(b);
+
        *result = true;
        LOOPBYTE(
-           if (sa[i] != sb[i]) {
-               *result = false;
-               break;
-           }
+                if (sa[i] != sb[i])
+                {
+           *result = false;
+           break;
+       }
        );
    }
    PG_RETURN_POINTER(result);
 }
 
 static int4
-sizebitvec(BITVECP sign) {
-   int4        size = 0, i;
+sizebitvec(BITVECP sign)
+{
+   int4        size = 0,
+               i;
+
    LOOPBYTE(
-       size += SUMBIT(sign);
-       sign = (BITVECP) (((char *) sign) + 1);
+            size += SUMBIT(sign);
+   sign = (BITVECP) (((char *) sign) + 1);
    );
    return size;
 }
+
 static int
-hemdistsign(BITVECP  a, BITVECP b) {
-   int i,dist=0;
+hemdistsign(BITVECP a, BITVECP b)
+{
+   int         i,
+               dist = 0;
 
    LOOPBIT(
-       if ( GETBIT(a,i) != GETBIT(b,i) )
+           if (GETBIT(a, i) != GETBIT(b, i))
            dist++;
    );
    return dist;
 }
 
 static int
-hemdist(GISTTYPE   *a, GISTTYPE   *b) {
-   if ( ISALLTRUE(a) ) {
+hemdist(GISTTYPE * a, GISTTYPE * b)
+{
+   if (ISALLTRUE(a))
+   {
        if (ISALLTRUE(b))
            return 0;
        else
-           return SIGLENBIT-sizebitvec(GETSIGN(b));
-   } else if (ISALLTRUE(b))
-       return SIGLENBIT-sizebitvec(GETSIGN(a));
+           return SIGLENBIT - sizebitvec(GETSIGN(b));
+   }
+   else if (ISALLTRUE(b))
+       return SIGLENBIT - sizebitvec(GETSIGN(a));
 
-   return hemdistsign( GETSIGN(a), GETSIGN(b) );
+   return hemdistsign(GETSIGN(a), GETSIGN(b));
 }
 
 static int4
 unionkey(BITVECP sbase, GISTTYPE * add)
 {
-   int4        i;
-   BITVECP  sadd = GETSIGN(add);
+   int4        i;
+   BITVECP     sadd = GETSIGN(add);
 
    if (ISALLTRUE(add))
        return 1;
    LOOPBYTE(
-       sbase[i] |= sadd[i];
+            sbase[i] |= sadd[i];
    );
    return 0;
 }
 
 Datum
-ghstore_union(PG_FUNCTION_ARGS) {
-   GistEntryVector      *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
-   int4        len = entryvec->n;
-
-   int     *size = (int *) PG_GETARG_POINTER(1);
-   BITVEC    base;
-   int4        i;
-   int4        flag = 0;
+ghstore_union(PG_FUNCTION_ARGS)
+{
+   GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+   int4        len = entryvec->n;
+
+   int        *size = (int *) PG_GETARG_POINTER(1);
+   BITVEC      base;
+   int4        i;
+   int4        flag = 0;
    GISTTYPE   *result;
 
    MemSet((void *) base, 0, sizeof(BITVEC));
-   for (i = 0; i < len; i++) {
-       if (unionkey(base, GETENTRY(entryvec, i))) {
+   for (i = 0; i < len; i++)
+   {
+       if (unionkey(base, GETENTRY(entryvec, i)))
+       {
            flag = ALLISTRUE;
            break;
        }
@@ -269,64 +295,72 @@ ghstore_union(PG_FUNCTION_ARGS) {
 }
 
 Datum
-ghstore_penalty(PG_FUNCTION_ARGS) {
+ghstore_penalty(PG_FUNCTION_ARGS)
+{
    GISTENTRY  *origentry = (GISTENTRY *) PG_GETARG_POINTER(0); /* always ISSIGNKEY */
    GISTENTRY  *newentry = (GISTENTRY *) PG_GETARG_POINTER(1);
-   float      *penalty = (float *) PG_GETARG_POINTER(2);
+   float      *penalty = (float *) PG_GETARG_POINTER(2);
    GISTTYPE   *origval = (GISTTYPE *) DatumGetPointer(origentry->key);
    GISTTYPE   *newval = (GISTTYPE *) DatumGetPointer(newentry->key);
 
-   *penalty=hemdist(origval,newval);
+   *penalty = hemdist(origval, newval);
    PG_RETURN_POINTER(penalty);
 }
 
 
-typedef struct {
+typedef struct
+{
    OffsetNumber pos;
-   int4        cost;
-} SPLITCOST;
+   int4        cost;
+}  SPLITCOST;
 
 static int
-comparecost(const void *a, const void *b) {
+comparecost(const void *a, const void *b)
+{
    return ((SPLITCOST *) a)->cost - ((SPLITCOST *) b)->cost;
 }
 
 
 Datum
-ghstore_picksplit(PG_FUNCTION_ARGS) {
-   GistEntryVector      *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
+ghstore_picksplit(PG_FUNCTION_ARGS)
+{
+   GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
    OffsetNumber maxoff = entryvec->n - 2;
 
    GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
    OffsetNumber k,
                j;
-   GISTTYPE *datum_l,
+   GISTTYPE   *datum_l,
               *datum_r;
-   BITVECP  union_l,
+   BITVECP     union_l,
                union_r;
-   int4        size_alpha, size_beta;
-   int4        size_waste,
+   int4        size_alpha,
+               size_beta;
+   int4        size_waste,
                waste = -1;
-   int4        nbytes;
+   int4        nbytes;
    OffsetNumber seed_1 = 0,
                seed_2 = 0;
    OffsetNumber *left,
               *right;
-   BITVECP  ptr;
-   int          i;
+   BITVECP     ptr;
+   int         i;
    SPLITCOST  *costvector;
-   GISTTYPE *_k,
+   GISTTYPE   *_k,
               *_j;
 
    nbytes = (maxoff + 2) * sizeof(OffsetNumber);
    v->spl_left = (OffsetNumber *) palloc(nbytes);
    v->spl_right = (OffsetNumber *) palloc(nbytes);
 
-   for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k)) {
+   for (k = FirstOffsetNumber; k < maxoff; k = OffsetNumberNext(k))
+   {
        _k = GETENTRY(entryvec, k);
-       for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j)) {
-           size_waste=hemdist(_k, GETENTRY(entryvec, j));
-           if (size_waste > waste ) {
+       for (j = OffsetNumberNext(k); j <= maxoff; j = OffsetNumberNext(j))
+       {
+           size_waste = hemdist(_k, GETENTRY(entryvec, j));
+           if (size_waste > waste)
+           {
                waste = size_waste;
                seed_1 = k;
                seed_2 = j;
@@ -346,26 +380,32 @@ ghstore_picksplit(PG_FUNCTION_ARGS) {
    }
 
    /* form initial .. */
-   if (ISALLTRUE(GETENTRY(entryvec, seed_1))) {
+   if (ISALLTRUE(GETENTRY(entryvec, seed_1)))
+   {
        datum_l = (GISTTYPE *) palloc(GTHDRSIZE);
        datum_l->len = GTHDRSIZE;
        datum_l->flag = ALLISTRUE;
-   } else {
+   }
+   else
+   {
        datum_l = (GISTTYPE *) palloc(GTHDRSIZE + SIGLEN);
        datum_l->len = GTHDRSIZE + SIGLEN;
        datum_l->flag = 0;
        memcpy((void *) GETSIGN(datum_l), (void *) GETSIGN(GETENTRY(entryvec, seed_1)), sizeof(BITVEC))
-;
+           ;
    }
-   if (ISALLTRUE(GETENTRY(entryvec, seed_2))) {
+   if (ISALLTRUE(GETENTRY(entryvec, seed_2)))
+   {
        datum_r = (GISTTYPE *) palloc(GTHDRSIZE);
        datum_r->len = GTHDRSIZE;
        datum_r->flag = ALLISTRUE;
-   } else {
+   }
+   else
+   {
        datum_r = (GISTTYPE *) palloc(GTHDRSIZE + SIGLEN);
        datum_r->len = GTHDRSIZE + SIGLEN;
        datum_r->flag = 0;
-       memcpy((void *) GETSIGN(datum_r), (void *) GETSIGN(GETENTRY(entryvec, seed_2)), sizeof(BITVEC)) ;
+       memcpy((void *) GETSIGN(datum_r), (void *) GETSIGN(GETENTRY(entryvec, seed_2)), sizeof(BITVEC));
    }
 
    maxoff = OffsetNumberNext(maxoff);
@@ -375,50 +415,63 @@ ghstore_picksplit(PG_FUNCTION_ARGS) {
    {
        costvector[j - 1].pos = j;
        _j = GETENTRY(entryvec, j);
-       size_alpha = hemdist(datum_l,_j);
-       size_beta  = hemdist(datum_r,_j);
+       size_alpha = hemdist(datum_l, _j);
+       size_beta = hemdist(datum_r, _j);
        costvector[j - 1].cost = abs(size_alpha - size_beta);
    }
    qsort((void *) costvector, maxoff, sizeof(SPLITCOST), comparecost);
 
-   union_l=GETSIGN(datum_l);
-   union_r=GETSIGN(datum_r);
+   union_l = GETSIGN(datum_l);
+   union_r = GETSIGN(datum_r);
 
-   for (k = 0; k < maxoff; k++) {
+   for (k = 0; k < maxoff; k++)
+   {
        j = costvector[k].pos;
-       if (j == seed_1) {
+       if (j == seed_1)
+       {
            *left++ = j;
            v->spl_nleft++;
            continue;
-       } else if (j == seed_2) {
+       }
+       else if (j == seed_2)
+       {
            *right++ = j;
            v->spl_nright++;
            continue;
        }
        _j = GETENTRY(entryvec, j);
-       size_alpha = hemdist(datum_l,_j);
-       size_beta  = hemdist(datum_r,_j);
+       size_alpha = hemdist(datum_l, _j);
+       size_beta = hemdist(datum_r, _j);
 
-       if (size_alpha < size_beta  + WISH_F(v->spl_nleft, v->spl_nright, 0.0001)) {
-           if (ISALLTRUE(datum_l) || ISALLTRUE(_j) ) {
+       if (size_alpha < size_beta + WISH_F(v->spl_nleft, v->spl_nright, 0.0001))
+       {
+           if (ISALLTRUE(datum_l) || ISALLTRUE(_j))
+           {
                if (!ISALLTRUE(datum_l))
                    MemSet((void *) union_l, 0xff, sizeof(BITVEC));
-           } else {
-               ptr=GETSIGN(_j);
+           }
+           else
+           {
+               ptr = GETSIGN(_j);
                LOOPBYTE(
-                   union_l[i] |= ptr[i];
+                        union_l[i] |= ptr[i];
                );
            }
            *left++ = j;
            v->spl_nleft++;
-       } else {
-           if (ISALLTRUE(datum_r) || ISALLTRUE(_j) ) {
+       }
+       else
+       {
+           if (ISALLTRUE(datum_r) || ISALLTRUE(_j))
+           {
                if (!ISALLTRUE(datum_r))
                    MemSet((void *) union_r, 0xff, sizeof(BITVEC));
-           } else {
-               ptr=GETSIGN(_j);
+           }
+           else
+           {
+               ptr = GETSIGN(_j);
                LOOPBYTE(
-                   union_r[i] |= ptr[i];
+                        union_r[i] |= ptr[i];
                );
            }
            *right++ = j;
@@ -436,36 +489,41 @@ ghstore_picksplit(PG_FUNCTION_ARGS) {
 }
 
 
-Datum     
-ghstore_consistent(PG_FUNCTION_ARGS) {
-   GISTTYPE  *entry = (GISTTYPE*) DatumGetPointer( ((GISTENTRY *) PG_GETARG_POINTER(0))->key );
-   HStore *query=PG_GETARG_HS(1);
-   bool res=true;
-   HEntry  *qe = ARRPTR(query);
-   char    *qv = STRPTR(query);
-   BITVECP sign;
-
-   if ( ISALLTRUE(entry) ) {
-       PG_FREE_IF_COPY(query,1);
+Datum
+ghstore_consistent(PG_FUNCTION_ARGS)
+{
+   GISTTYPE   *entry = (GISTTYPE *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
+   HStore     *query = PG_GETARG_HS(1);
+   bool        res = true;
+   HEntry     *qe = ARRPTR(query);
+   char       *qv = STRPTR(query);
+   BITVECP     sign;
+
+   if (ISALLTRUE(entry))
+   {
+       PG_FREE_IF_COPY(query, 1);
        PG_RETURN_BOOL(true);
    }
 
-   sign=GETSIGN(entry); 
-   while(res && qe-ARRPTR(query) < query->size) {
-       int crc = crc32_sz((char *)(qv + qe->pos), qe->keylen);
-       if (GETBIT(sign,HASHVAL(crc))) {
-           if ( !qe->valisnull ) {
-               crc = crc32_sz((char *)(qv + qe->pos + qe->keylen), qe->vallen);
-               if ( !GETBIT(sign,HASHVAL(crc)) )
-                   res=false;
+   sign = GETSIGN(entry);
+   while (res && qe - ARRPTR(query) < query->size)
+   {
+       int         crc = crc32_sz((char *) (qv + qe->pos), qe->keylen);
+
+       if (GETBIT(sign, HASHVAL(crc)))
+       {
+           if (!qe->valisnull)
+           {
+               crc = crc32_sz((char *) (qv + qe->pos + qe->keylen), qe->vallen);
+               if (!GETBIT(sign, HASHVAL(crc)))
+                   res = false;
            }
-       } else
-           res=false;
+       }
+       else
+           res = false;
        qe++;
    }
 
-   PG_FREE_IF_COPY(query,1);
+   PG_FREE_IF_COPY(query, 1);
    PG_RETURN_BOOL(res);
 }
-
-
index 051a411a99346f369275e9eb7fc9e4d74fb1a3e2..e01cb4e7599fe57401bf9586336a11875b23d27a 100644 (file)
 
 PG_MODULE_MAGIC;
 
-typedef struct {
-   char *begin;
-   char *ptr;
-   char *cur;
-   char *word;
-   int wordlen;
-
-   Pairs   *pairs;
-   int pcur;
-   int plen;
-} HSParser;
+typedef struct
+{
+   char       *begin;
+   char       *ptr;
+   char       *cur;
+   char       *word;
+   int         wordlen;
+
+   Pairs      *pairs;
+   int         pcur;
+   int         plen;
+}  HSParser;
 
 #define RESIZEPRSBUF \
 do { \
-        if ( state->cur - state->word + 1 >= state->wordlen ) \
-        { \
-                int4 clen = state->cur - state->word; \
-                state->wordlen *= 2; \
-                state->word = (char*)repalloc( (void*)state->word, state->wordlen ); \
-                state->cur = state->word + clen; \
-        } \
+       if ( state->cur - state->word + 1 >= state->wordlen ) \
+       { \
+               int4 clen = state->cur - state->word; \
+               state->wordlen *= 2; \
+               state->word = (char*)repalloc( (void*)state->word, state->wordlen ); \
+               state->cur = state->word + clen; \
+       } \
 } while (0)
 
 
-#define GV_WAITVAL 0 
-#define GV_INVAL 1 
-#define GV_INESCVAL 2 
-#define GV_WAITESCIN 3 
-#define GV_WAITESCESCIN 4 
+#define GV_WAITVAL 0
+#define GV_INVAL 1
+#define GV_INESCVAL 2
+#define GV_WAITESCIN 3
+#define GV_WAITESCESCIN 4
 
 static bool
-get_val( HSParser *state, bool ignoreeq, bool *escaped ) {
-   int st = GV_WAITVAL;
-   state->wordlen=32;
-   state->cur = state->word = palloc( state->wordlen );
-   *escaped=false;
-
-   while(1) {
-       if ( st == GV_WAITVAL ) {
-           if ( *(state->ptr) == '"' ) {
-               *escaped=true;
+get_val(HSParser * state, bool ignoreeq, bool *escaped)
+{
+   int         st = GV_WAITVAL;
+
+   state->wordlen = 32;
+   state->cur = state->word = palloc(state->wordlen);
+   *escaped = false;
+
+   while (1)
+   {
+       if (st == GV_WAITVAL)
+       {
+           if (*(state->ptr) == '"')
+           {
+               *escaped = true;
                st = GV_INESCVAL;
-           } else if ( *(state->ptr) == '\0' ) {
+           }
+           else if (*(state->ptr) == '\0')
+           {
                return false;
-           } else if (  *(state->ptr) == '=' && !ignoreeq ) {
-               elog(ERROR,"Syntax error near '%c' at postion %d", *(state->ptr), (int4)(state->ptr-state->begin));
-           } else if ( *(state->ptr) == '\\' ) {
+           }
+           else if (*(state->ptr) == '=' && !ignoreeq)
+           {
+               elog(ERROR, "Syntax error near '%c' at postion %d", *(state->ptr), (int4) (state->ptr - state->begin));
+           }
+           else if (*(state->ptr) == '\\')
+           {
                st = GV_WAITESCIN;
-           } else if ( !isspace((unsigned char) *(state->ptr)) ) {
+           }
+           else if (!isspace((unsigned char) *(state->ptr)))
+           {
                *(state->cur) = *(state->ptr);
                state->cur++;
                st = GV_INVAL;
            }
-       } else if ( st == GV_INVAL ) {
-           if ( *(state->ptr) == '\\' ) {
+       }
+       else if (st == GV_INVAL)
+       {
+           if (*(state->ptr) == '\\')
+           {
                st = GV_WAITESCIN;
-           } else if ( *(state->ptr) == '=' && !ignoreeq ) {
+           }
+           else if (*(state->ptr) == '=' && !ignoreeq)
+           {
                state->ptr--;
                return true;
-           } else if ( *(state->ptr) == ',' && ignoreeq ) {
+           }
+           else if (*(state->ptr) == ',' && ignoreeq)
+           {
                state->ptr--;
                return true;
-           } else if ( isspace((unsigned char) *(state->ptr)) ) {
+           }
+           else if (isspace((unsigned char) *(state->ptr)))
+           {
                return true;
-           } else if ( *(state->ptr) == '\0' ) {
+           }
+           else if (*(state->ptr) == '\0')
+           {
                state->ptr--;
                return true;
-           } else {
+           }
+           else
+           {
                RESIZEPRSBUF;
                *(state->cur) = *(state->ptr);
                state->cur++;
            }
-       } else if ( st == GV_INESCVAL ) {
-           if ( *(state->ptr) == '\\' ) {
+       }
+       else if (st == GV_INESCVAL)
+       {
+           if (*(state->ptr) == '\\')
+           {
                st = GV_WAITESCESCIN;
-           } else if ( *(state->ptr) == '"' ) {
+           }
+           else if (*(state->ptr) == '"')
+           {
                return true;
-           } else if ( *(state->ptr) == '\0' ) {
-               elog(ERROR,"Unexpected end of string");
-           } else {
+           }
+           else if (*(state->ptr) == '\0')
+           {
+               elog(ERROR, "Unexpected end of string");
+           }
+           else
+           {
                RESIZEPRSBUF;
                *(state->cur) = *(state->ptr);
                state->cur++;
            }
-       } else if ( st == GV_WAITESCIN ) {
-           if ( *(state->ptr) == '\0' )
-               elog(ERROR,"Unexpected end of string");
+       }
+       else if (st == GV_WAITESCIN)
+       {
+           if (*(state->ptr) == '\0')
+               elog(ERROR, "Unexpected end of string");
            RESIZEPRSBUF;
            *(state->cur) = *(state->ptr);
            state->cur++;
-           st = GV_INVAL; 
-       } else if ( st == GV_WAITESCESCIN ) {
-           if ( *(state->ptr) == '\0' )
-               elog(ERROR,"Unexpected end of string");
+           st = GV_INVAL;
+       }
+       else if (st == GV_WAITESCESCIN)
+       {
+           if (*(state->ptr) == '\0')
+               elog(ERROR, "Unexpected end of string");
            RESIZEPRSBUF;
            *(state->cur) = *(state->ptr);
            state->cur++;
            st = GV_INESCVAL;
-       } else
-           elog(ERROR,"Unknown state %d at postion line %d in file '%s'", st, __LINE__, __FILE__); 
+       }
+       else
+           elog(ERROR, "Unknown state %d at postion line %d in file '%s'", st, __LINE__, __FILE__);
 
        state->ptr++;
-   } 
+   }
 
    return false;
 }
 
 #define WKEY   0
 #define WVAL   1
-#define WEQ    2
-#define WGT    3
+#define WEQ 2
+#define WGT 3
 #define WDEL   4
 
 
 static void
-parse_hstore( HSParser *state ) {
-   int st = WKEY;
-   bool escaped=false;
-
-   state->plen=16;
-   state->pairs = (Pairs*)palloc( sizeof(Pairs) * state->plen );
-   state->pcur=0;
+parse_hstore(HSParser * state)
+{
+   int         st = WKEY;
+   bool        escaped = false;
+
+   state->plen = 16;
+   state->pairs = (Pairs *) palloc(sizeof(Pairs) * state->plen);
+   state->pcur = 0;
    state->ptr = state->begin;
-   state->word=NULL;
+   state->word = NULL;
 
-   while(1) {
-       if (st == WKEY) {
-           if ( !get_val(state, false, &escaped) )
+   while (1)
+   {
+       if (st == WKEY)
+       {
+           if (!get_val(state, false, &escaped))
                return;
-           if ( state->pcur >= state->plen ) {
+           if (state->pcur >= state->plen)
+           {
                state->plen *= 2;
-               state->pairs = (Pairs*)repalloc( state->pairs, sizeof(Pairs) * state->plen );
+               state->pairs = (Pairs *) repalloc(state->pairs, sizeof(Pairs) * state->plen);
            }
-           state->pairs[ state->pcur ].key = state->word; 
-           state->pairs[ state->pcur ].keylen = state->cur - state->word;
-           state->pairs[ state->pcur ].val=NULL;
-           state->word=NULL;
+           state->pairs[state->pcur].key = state->word;
+           state->pairs[state->pcur].keylen = state->cur - state->word;
+           state->pairs[state->pcur].val = NULL;
+           state->word = NULL;
            st = WEQ;
-       } else if ( st == WEQ ) {
-           if ( *(state->ptr) == '=' ) {
+       }
+       else if (st == WEQ)
+       {
+           if (*(state->ptr) == '=')
+           {
                st = WGT;
-           } else if ( *(state->ptr) == '\0' ) {
-               elog(ERROR,"Unexpectd end of string");
-           } else if (!isspace((unsigned char) *(state->ptr))) {
-               elog(ERROR,"Syntax error near '%c' at postion %d", *(state->ptr), (int4)(state->ptr-state->begin));
            }
-       } else if ( st == WGT ) {
-           if ( *(state->ptr) == '>' ) {
+           else if (*(state->ptr) == '\0')
+           {
+               elog(ERROR, "Unexpectd end of string");
+           }
+           else if (!isspace((unsigned char) *(state->ptr)))
+           {
+               elog(ERROR, "Syntax error near '%c' at postion %d", *(state->ptr), (int4) (state->ptr - state->begin));
+           }
+       }
+       else if (st == WGT)
+       {
+           if (*(state->ptr) == '>')
+           {
                st = WVAL;
-           } else if ( *(state->ptr) == '\0' ) {
-               elog(ERROR,"Unexpectd end of string");
-           } else { 
-               elog(ERROR,"Syntax error near '%c' at postion %d", *(state->ptr), (int4)(state->ptr-state->begin));
            }
-       } else if ( st == WVAL ) {
-           if ( !get_val(state, true, &escaped) )
-               elog(ERROR,"Unexpected end of string");
-           state->pairs[ state->pcur ].val = state->word;
-           state->pairs[ state->pcur ].vallen = state->cur - state->word;
-           state->pairs[ state->pcur ].isnull = false;
-           state->pairs[ state->pcur ].needfree = true;
-           if ( state->cur - state->word == 4 && !escaped) {
+           else if (*(state->ptr) == '\0')
+           {
+               elog(ERROR, "Unexpectd end of string");
+           }
+           else
+           {
+               elog(ERROR, "Syntax error near '%c' at postion %d", *(state->ptr), (int4) (state->ptr - state->begin));
+           }
+       }
+       else if (st == WVAL)
+       {
+           if (!get_val(state, true, &escaped))
+               elog(ERROR, "Unexpected end of string");
+           state->pairs[state->pcur].val = state->word;
+           state->pairs[state->pcur].vallen = state->cur - state->word;
+           state->pairs[state->pcur].isnull = false;
+           state->pairs[state->pcur].needfree = true;
+           if (state->cur - state->word == 4 && !escaped)
+           {
                state->word[4] = '\0';
-               if ( 0==pg_strcasecmp(state->word, "null") ) 
-                   state->pairs[ state->pcur ].isnull=true;
-           } 
-           state->word=NULL;
+               if (0 == pg_strcasecmp(state->word, "null"))
+                   state->pairs[state->pcur].isnull = true;
+           }
+           state->word = NULL;
            state->pcur++;
            st = WDEL;
-       } else if ( st == WDEL ) {
-           if (  *(state->ptr) == ',' ) {
+       }
+       else if (st == WDEL)
+       {
+           if (*(state->ptr) == ',')
+           {
                st = WKEY;
-           } else if ( *(state->ptr) == '\0' ) {
+           }
+           else if (*(state->ptr) == '\0')
+           {
                return;
-           } else if (!isspace((unsigned char) *(state->ptr))) {
-               elog(ERROR,"Syntax error near '%c' at postion %d", *(state->ptr), (int4)(state->ptr-state->begin));
            }
-       } else 
-           elog(ERROR,"Unknown state %d at line %d in file '%s'", st, __LINE__, __FILE__);
+           else if (!isspace((unsigned char) *(state->ptr)))
+           {
+               elog(ERROR, "Syntax error near '%c' at postion %d", *(state->ptr), (int4) (state->ptr - state->begin));
+           }
+       }
+       else
+           elog(ERROR, "Unknown state %d at line %d in file '%s'", st, __LINE__, __FILE__);
 
        state->ptr++;
    }
-} 
+}
 
 int
-comparePairs(const void *a, const void *b) {
-   if ( ((Pairs*)a)->keylen == ((Pairs*)b)->keylen ) { 
-       int res =  strncmp(
-               ((Pairs*)a)->key,
-               ((Pairs*)b)->key,
-               ((Pairs*)a)->keylen
-           );
-       if ( res )
+comparePairs(const void *a, const void *b)
+{
+   if (((Pairs *) a)->keylen == ((Pairs *) b)->keylen)
+   {
+       int         res = strncmp(
+                                 ((Pairs *) a)->key,
+                                 ((Pairs *) b)->key,
+                                 ((Pairs *) a)->keylen
+       );
+
+       if (res)
            return res;
 
        /* guarantee that neddfree willl be later */
-       if ( ((Pairs*)b)->needfree == ((Pairs*)a)->needfree )
+       if (((Pairs *) b)->needfree == ((Pairs *) a)->needfree)
            return 0;
-       else if ( ((Pairs*)a)->needfree )
+       else if (((Pairs *) a)->needfree)
            return 1;
        else
-           return -1;  
+           return -1;
    }
-   return ( ((Pairs*)a)->keylen > ((Pairs*)b)->keylen ) ? 1 : -1;
+   return (((Pairs *) a)->keylen > ((Pairs *) b)->keylen) ? 1 : -1;
 }
 
 int
-uniquePairs(Pairs * a, int4 l, int4 *buflen) {
-   Pairs *ptr, *res;
-
-   *buflen=0;
-   if ( l < 2 ) {
-       if ( l==1 )
-           *buflen = a->keylen + ((a->isnull) ? 0 : a->vallen) ;
+uniquePairs(Pairs * a, int4 l, int4 *buflen)
+{
+   Pairs      *ptr,
+              *res;
+
+   *buflen = 0;
+   if (l < 2)
+   {
+       if (l == 1)
+           *buflen = a->keylen + ((a->isnull) ? 0 : a->vallen);
        return l;
    }
 
    qsort((void *) a, l, sizeof(Pairs), comparePairs);
-   ptr=a+1;
-   res=a;  
-   while( ptr - a < l ) {
-       if ( ptr->keylen == res->keylen && strncmp( ptr->key, res->key, res->keylen )==0 ) {
-           if ( ptr->needfree ) {
+   ptr = a + 1;
+   res = a;
+   while (ptr - a < l)
+   {
+       if (ptr->keylen == res->keylen && strncmp(ptr->key, res->key, res->keylen) == 0)
+       {
+           if (ptr->needfree)
+           {
                pfree(ptr->key);
                pfree(ptr->val);
            }
-       } else {
-           *buflen += res->keylen + (( res->isnull ) ? 0 : res->vallen);
+       }
+       else
+       {
+           *buflen += res->keylen + ((res->isnull) ? 0 : res->vallen);
            res++;
-           memcpy(res,ptr,sizeof(Pairs));
+           memcpy(res, ptr, sizeof(Pairs));
        }
 
        ptr++;
    }
 
-   *buflen += res->keylen + (( res->isnull ) ? 0 : res->vallen);
+   *buflen += res->keylen + ((res->isnull) ? 0 : res->vallen);
    return res + 1 - a;
 }
 
 static void
-freeHSParse(HSParser *state) {
-   int i;
-
-   if ( state->word ) pfree( state->word );
-   for (i=0;i<state->pcur;i++)
-       if ( state->pairs[i].needfree ) {
-           if (state->pairs[i].key) pfree(state->pairs[i].key);
-           if (state->pairs[i].val) pfree(state->pairs[i].val);
+freeHSParse(HSParser * state)
+{
+   int         i;
+
+   if (state->word)
+       pfree(state->word);
+   for (i = 0; i < state->pcur; i++)
+       if (state->pairs[i].needfree)
+       {
+           if (state->pairs[i].key)
+               pfree(state->pairs[i].key);
+           if (state->pairs[i].val)
+               pfree(state->pairs[i].val);
        }
-   pfree( state->pairs );
+   pfree(state->pairs);
 }
 
 PG_FUNCTION_INFO_V1(hstore_in);
-Datum           hstore_in(PG_FUNCTION_ARGS);
+Datum      hstore_in(PG_FUNCTION_ARGS);
 Datum
-hstore_in(PG_FUNCTION_ARGS) {
-   HSParser   state;
-   int4 len,buflen,i;
-   HStore  *out;
-   HEntry  *entries;
-   char *ptr;
-
-   state.begin =  PG_GETARG_CSTRING(0);
+hstore_in(PG_FUNCTION_ARGS)
+{
+   HSParser    state;
+   int4        len,
+               buflen,
+               i;
+   HStore     *out;
+   HEntry     *entries;
+   char       *ptr;
+
+   state.begin = PG_GETARG_CSTRING(0);
 
    parse_hstore(&state);
 
-   if ( state.pcur == 0 ) {
+   if (state.pcur == 0)
+   {
        freeHSParse(&state);
-       len = CALCDATASIZE(0,0);
+       len = CALCDATASIZE(0, 0);
        out = palloc(len);
-       out->len=len;
-       out->size=0;
+       out->len = len;
+       out->size = 0;
        PG_RETURN_POINTER(out);
    }
 
    state.pcur = uniquePairs(state.pairs, state.pcur, &buflen);
 
-   len=CALCDATASIZE(state.pcur, buflen);
+   len = CALCDATASIZE(state.pcur, buflen);
    out = palloc(len);
-   out->len=len;
-   out->size=state.pcur;
+   out->len = len;
+   out->size = state.pcur;
 
-   entries=ARRPTR(out);
+   entries = ARRPTR(out);
    ptr = STRPTR(out);
 
-   for(i=0;i<out->size;i++) {
+   for (i = 0; i < out->size; i++)
+   {
        entries[i].keylen = state.pairs[i].keylen;
        entries[i].pos = ptr - STRPTR(out);
        memcpy(ptr, state.pairs[i].key, state.pairs[i].keylen);
-       ptr+=entries[i].keylen;
+       ptr += entries[i].keylen;
 
        entries[i].valisnull = state.pairs[i].isnull;
-       if ( entries[i].valisnull )
-           entries[i].vallen=4; /* null */
-       else {
+       if (entries[i].valisnull)
+           entries[i].vallen = 4;      /* null */
+       else
+       {
            entries[i].vallen = state.pairs[i].vallen;
-           memcpy(ptr, state.pairs[i].val,state.pairs[i].vallen);
-           ptr+=entries[i].vallen;
+           memcpy(ptr, state.pairs[i].val, state.pairs[i].vallen);
+           ptr += entries[i].vallen;
        }
    }
 
@@ -308,63 +400,74 @@ hstore_in(PG_FUNCTION_ARGS) {
    PG_RETURN_POINTER(out);
 }
 
-static char*
-cpw(char *dst, char *src, int len) {
-   char *ptr = src;
+static char *
+cpw(char *dst, char *src, int len)
+{
+   char       *ptr = src;
 
-   while(ptr-src<len) {
-       if ( *ptr == '"' || *ptr == '\\' )
-           *dst++='\\';
+   while (ptr - src < len)
+   {
+       if (*ptr == '"' || *ptr == '\\')
+           *dst++ = '\\';
        *dst++ = *ptr++;
    }
    return dst;
 }
 
 PG_FUNCTION_INFO_V1(hstore_out);
-Datum           hstore_out(PG_FUNCTION_ARGS);
+Datum      hstore_out(PG_FUNCTION_ARGS);
 Datum
-hstore_out(PG_FUNCTION_ARGS) {
-   HStore *in = PG_GETARG_HS(0);
-   int buflen,i;
-   char *out,*ptr;
-   char *base = STRPTR(in);
-   HEntry  *entries = ARRPTR(in);
-
-   if ( in->size==0 ) {
-       out=palloc(1);
-       *out='\0';
-       PG_FREE_IF_COPY(in,0);
+hstore_out(PG_FUNCTION_ARGS)
+{
+   HStore     *in = PG_GETARG_HS(0);
+   int         buflen,
+               i;
+   char       *out,
+              *ptr;
+   char       *base = STRPTR(in);
+   HEntry     *entries = ARRPTR(in);
+
+   if (in->size == 0)
+   {
+       out = palloc(1);
+       *out = '\0';
+       PG_FREE_IF_COPY(in, 0);
        PG_RETURN_CSTRING(out);
    }
 
-   buflen = ( 4 /* " */ + 2 /* => */ + 2 /*, */ )*in->size + 
-       2 /* esc */ * ( in->len - CALCDATASIZE(in->size,0) );
-
-   out=ptr=palloc(buflen);
-   for(i=0;i<in->size;i++) {
-       *ptr++='"';
-       ptr = cpw( ptr, base + entries[i].pos, entries[i].keylen );
-       *ptr++='"';
-       *ptr++='=';
-       *ptr++='>';
-       if ( entries[i].valisnull ) {
-           *ptr++='N';
-           *ptr++='U';
-           *ptr++='L';
-           *ptr++='L';
-       } else {
-           *ptr++='"';
-           ptr = cpw( ptr, base + entries[i].pos + entries[i].keylen, entries[i].vallen );
-           *ptr++='"';
+   buflen = (4 /* " */ + 2 /* => */ + 2 /* , */ ) * in->size +
+       2 /* esc */ * (in->len - CALCDATASIZE(in->size, 0));
+
+   out = ptr = palloc(buflen);
+   for (i = 0; i < in->size; i++)
+   {
+       *ptr++ = '"';
+       ptr = cpw(ptr, base + entries[i].pos, entries[i].keylen);
+       *ptr++ = '"';
+       *ptr++ = '=';
+       *ptr++ = '>';
+       if (entries[i].valisnull)
+       {
+           *ptr++ = 'N';
+           *ptr++ = 'U';
+           *ptr++ = 'L';
+           *ptr++ = 'L';
+       }
+       else
+       {
+           *ptr++ = '"';
+           ptr = cpw(ptr, base + entries[i].pos + entries[i].keylen, entries[i].vallen);
+           *ptr++ = '"';
        }
 
-       if ( i+1 != in->size ) {
-           *ptr++=',';
-           *ptr++=' ';
+       if (i + 1 != in->size)
+       {
+           *ptr++ = ',';
+           *ptr++ = ' ';
        }
    }
-   *ptr='\0';
+   *ptr = '\0';
 
-   PG_FREE_IF_COPY(in,0);
+   PG_FREE_IF_COPY(in, 0);
    PG_RETURN_CSTRING(out);
 }
index 12f783cb256c3ee21cf47484baf941a292fc9d29..971e93cf314c77ced41b12794eb71cc9ae99cf1a 100644 (file)
@@ -7,20 +7,22 @@
 
 
 static HEntry *
-findkey(HStore *hs, char *key, int keylen) {
-   HEntry *StopLow  = ARRPTR(hs);
-   HEntry *StopHigh = StopLow + hs->size;
-   HEntry  *StopMiddle;
-   int    difference;
-   char *base = STRPTR(hs);
-
-   while (StopLow < StopHigh) {
+findkey(HStore * hs, char *key, int keylen)
+{
+   HEntry     *StopLow = ARRPTR(hs);
+   HEntry     *StopHigh = StopLow + hs->size;
+   HEntry     *StopMiddle;
+   int         difference;
+   char       *base = STRPTR(hs);
+
+   while (StopLow < StopHigh)
+   {
        StopMiddle = StopLow + (StopHigh - StopLow) / 2;
 
-       if ( StopMiddle->keylen == keylen )
-           difference=strncmp(base+StopMiddle->pos, key, StopMiddle->keylen);
+       if (StopMiddle->keylen == keylen)
+           difference = strncmp(base + StopMiddle->pos, key, StopMiddle->keylen);
        else
-           difference=(StopMiddle->keylen > keylen) ? 1 : -1;
+           difference = (StopMiddle->keylen > keylen) ? 1 : -1;
 
        if (difference == 0)
            return StopMiddle;
@@ -29,520 +31,583 @@ findkey(HStore *hs, char *key, int keylen) {
        else
            StopHigh = StopMiddle;
    }
-       
+
    return NULL;
 }
 
 PG_FUNCTION_INFO_V1(fetchval);
-Datum           fetchval(PG_FUNCTION_ARGS);
+Datum      fetchval(PG_FUNCTION_ARGS);
 Datum
-fetchval(PG_FUNCTION_ARGS) {
-   HStore *hs  = PG_GETARG_HS(0);
-   text   *key = PG_GETARG_TEXT_P(1);
-   HEntry  *entry;
-   text *out;
-
-   if ((entry=findkey(hs,VARDATA(key), VARSIZE(key)-VARHDRSZ))==NULL || entry->valisnull) {
-       PG_FREE_IF_COPY(hs,0);
-       PG_FREE_IF_COPY(key,1);
+fetchval(PG_FUNCTION_ARGS)
+{
+   HStore     *hs = PG_GETARG_HS(0);
+   text       *key = PG_GETARG_TEXT_P(1);
+   HEntry     *entry;
+   text       *out;
+
+   if ((entry = findkey(hs, VARDATA(key), VARSIZE(key) - VARHDRSZ)) == NULL || entry->valisnull)
+   {
+       PG_FREE_IF_COPY(hs, 0);
+       PG_FREE_IF_COPY(key, 1);
        PG_RETURN_NULL();
    }
 
-   out=palloc(VARHDRSZ+entry->vallen);
-   memcpy(VARDATA(out),STRPTR(hs) + entry->pos + entry->keylen, entry->vallen);
-   VARATT_SIZEP(out) = VARHDRSZ+entry->vallen;
+   out = palloc(VARHDRSZ + entry->vallen);
+   memcpy(VARDATA(out), STRPTR(hs) + entry->pos + entry->keylen, entry->vallen);
+   VARATT_SIZEP(out) = VARHDRSZ + entry->vallen;
 
-   PG_FREE_IF_COPY(hs,0);
-   PG_FREE_IF_COPY(key,1);
+   PG_FREE_IF_COPY(hs, 0);
+   PG_FREE_IF_COPY(key, 1);
    PG_RETURN_POINTER(out);
 }
 
 PG_FUNCTION_INFO_V1(exists);
-Datum           exists(PG_FUNCTION_ARGS);
+Datum      exists(PG_FUNCTION_ARGS);
 Datum
-exists(PG_FUNCTION_ARGS) {
-   HStore *hs  = PG_GETARG_HS(0);
-   text   *key = PG_GETARG_TEXT_P(1);
-   HEntry  *entry;
+exists(PG_FUNCTION_ARGS)
+{
+   HStore     *hs = PG_GETARG_HS(0);
+   text       *key = PG_GETARG_TEXT_P(1);
+   HEntry     *entry;
 
-   entry=findkey(hs,VARDATA(key), VARSIZE(key)-VARHDRSZ);
+   entry = findkey(hs, VARDATA(key), VARSIZE(key) - VARHDRSZ);
 
-   PG_FREE_IF_COPY(hs,0);
-   PG_FREE_IF_COPY(key,1);
+   PG_FREE_IF_COPY(hs, 0);
+   PG_FREE_IF_COPY(key, 1);
 
    PG_RETURN_BOOL(entry);
 }
 
 PG_FUNCTION_INFO_V1(defined);
-Datum           defined(PG_FUNCTION_ARGS);
+Datum      defined(PG_FUNCTION_ARGS);
 Datum
-defined(PG_FUNCTION_ARGS) {
-   HStore *hs  = PG_GETARG_HS(0);
-   text   *key = PG_GETARG_TEXT_P(1);
-   HEntry  *entry;
-   bool res;
+defined(PG_FUNCTION_ARGS)
+{
+   HStore     *hs = PG_GETARG_HS(0);
+   text       *key = PG_GETARG_TEXT_P(1);
+   HEntry     *entry;
+   bool        res;
 
-   entry=findkey(hs,VARDATA(key), VARSIZE(key)-VARHDRSZ);
+   entry = findkey(hs, VARDATA(key), VARSIZE(key) - VARHDRSZ);
 
-   res = ( entry && !entry->valisnull ) ? true : false;
+   res = (entry && !entry->valisnull) ? true : false;
 
-   PG_FREE_IF_COPY(hs,0);
-   PG_FREE_IF_COPY(key,1);
+   PG_FREE_IF_COPY(hs, 0);
+   PG_FREE_IF_COPY(key, 1);
 
    PG_RETURN_BOOL(res);
 }
 
 PG_FUNCTION_INFO_V1(delete);
-Datum           delete(PG_FUNCTION_ARGS);
+Datum      delete(PG_FUNCTION_ARGS);
 Datum
-delete(PG_FUNCTION_ARGS) {
-   HStore *hs  = PG_GETARG_HS(0);
-   text   *key = PG_GETARG_TEXT_P(1);
-   HStore *out = palloc(hs->len);
-   char *ptrs, *ptrd;
-   HEntry  *es, *ed;
-
-   out->len=hs->len;
-   out->size=hs->size; /* temprorary! */
-
-   ptrs=STRPTR(hs);
-   es  =ARRPTR(hs);
-   ptrd=STRPTR(out);
-   ed  =ARRPTR(out);
-
-   while( es - ARRPTR(hs) < hs->size ) { 
-       if ( !(es->keylen == VARSIZE(key) - VARHDRSZ && strncmp(ptrs, VARDATA(key), es->keylen)==0) ) {
-           memcpy( ed, es, sizeof(HEntry) );
-           memcpy( ptrd, ptrs, es->keylen + ( (es->valisnull) ? 0 : es->vallen ) );
+delete(PG_FUNCTION_ARGS)
+{
+   HStore     *hs = PG_GETARG_HS(0);
+   text       *key = PG_GETARG_TEXT_P(1);
+   HStore     *out = palloc(hs->len);
+   char       *ptrs,
+              *ptrd;
+   HEntry     *es,
+              *ed;
+
+   out->len = hs->len;
+   out->size = hs->size;       /* temprorary! */
+
+   ptrs = STRPTR(hs);
+   es = ARRPTR(hs);
+   ptrd = STRPTR(out);
+   ed = ARRPTR(out);
+
+   while (es - ARRPTR(hs) < hs->size)
+   {
+       if (!(es->keylen == VARSIZE(key) - VARHDRSZ && strncmp(ptrs, VARDATA(key), es->keylen) == 0))
+       {
+           memcpy(ed, es, sizeof(HEntry));
+           memcpy(ptrd, ptrs, es->keylen + ((es->valisnull) ? 0 : es->vallen));
            ed->pos = ptrd - STRPTR(out);
-           ptrd += es->keylen + ( (es->valisnull) ? 0 : es->vallen );
+           ptrd += es->keylen + ((es->valisnull) ? 0 : es->vallen);
            ed++;
        }
-       ptrs += es->keylen + ( (es->valisnull) ? 0 : es->vallen );
+       ptrs += es->keylen + ((es->valisnull) ? 0 : es->vallen);
        es++;
    }
 
-   if ( ed - ARRPTR(out) != out->size ) {
-       int buflen=ptrd-STRPTR(out);
+   if (ed - ARRPTR(out) != out->size)
+   {
+       int         buflen = ptrd - STRPTR(out);
+
        ptrd = STRPTR(out);
 
        out->size = ed - ARRPTR(out);
 
-       memmove( STRPTR(out), ptrd, buflen);
+       memmove(STRPTR(out), ptrd, buflen);
        out->len = CALCDATASIZE(out->size, buflen);
    }
-       
 
-   PG_FREE_IF_COPY(hs,0);
-   PG_FREE_IF_COPY(key,1);
+
+   PG_FREE_IF_COPY(hs, 0);
+   PG_FREE_IF_COPY(key, 1);
 
    PG_RETURN_POINTER(out);
 }
 
 PG_FUNCTION_INFO_V1(hs_concat);
-Datum           hs_concat(PG_FUNCTION_ARGS);
+Datum      hs_concat(PG_FUNCTION_ARGS);
 Datum
-hs_concat(PG_FUNCTION_ARGS) {
-   HStore *s1  = PG_GETARG_HS(0);
-   HStore *s2  = PG_GETARG_HS(1);
-   HStore *out = palloc( s1->len + s2->len );
-   char *ps1, *ps2, *pd;
-   HEntry *es1, *es2, *ed;
+hs_concat(PG_FUNCTION_ARGS)
+{
+   HStore     *s1 = PG_GETARG_HS(0);
+   HStore     *s2 = PG_GETARG_HS(1);
+   HStore     *out = palloc(s1->len + s2->len);
+   char       *ps1,
+              *ps2,
+              *pd;
+   HEntry     *es1,
+              *es2,
+              *ed;
 
    out->len = s1->len + s2->len;
    out->size = s1->size + s2->size;
 
-   ps1=STRPTR(s1);
-   ps2=STRPTR(s2);
-   pd=STRPTR(out);
-   es1=ARRPTR(s1);
-   es2=ARRPTR(s2);
-   ed=ARRPTR(out);
-
-   while( es1 - ARRPTR(s1) < s1->size && es2 - ARRPTR(s2) < s2->size ) {
-       int difference;
-       if ( es1->keylen == es2->keylen )
-           difference=strncmp(ps1, ps2, es1->keylen);
+   ps1 = STRPTR(s1);
+   ps2 = STRPTR(s2);
+   pd = STRPTR(out);
+   es1 = ARRPTR(s1);
+   es2 = ARRPTR(s2);
+   ed = ARRPTR(out);
+
+   while (es1 - ARRPTR(s1) < s1->size && es2 - ARRPTR(s2) < s2->size)
+   {
+       int         difference;
+
+       if (es1->keylen == es2->keylen)
+           difference = strncmp(ps1, ps2, es1->keylen);
        else
-           difference=(es1->keylen > es2->keylen) ? 1 : -1;
+           difference = (es1->keylen > es2->keylen) ? 1 : -1;
 
-       if ( difference == 0 ) {
-           memcpy( ed, es2, sizeof(HEntry) );
-           memcpy( pd, ps2, es2->keylen + ( (es2->valisnull) ? 0 : es2->vallen ) );
+       if (difference == 0)
+       {
+           memcpy(ed, es2, sizeof(HEntry));
+           memcpy(pd, ps2, es2->keylen + ((es2->valisnull) ? 0 : es2->vallen));
            ed->pos = pd - STRPTR(out);
-           pd += es2->keylen + ( (es2->valisnull) ? 0 : es2->vallen );
+           pd += es2->keylen + ((es2->valisnull) ? 0 : es2->vallen);
            ed++;
-           
-           ps1 += es1->keylen + ( (es1->valisnull) ? 0 : es1->vallen );
+
+           ps1 += es1->keylen + ((es1->valisnull) ? 0 : es1->vallen);
            es1++;
-           ps2 += es2->keylen + ( (es2->valisnull) ? 0 : es2->vallen );
+           ps2 += es2->keylen + ((es2->valisnull) ? 0 : es2->vallen);
            es2++;
-       } else if ( difference > 0 ) {
-           memcpy( ed, es2, sizeof(HEntry) );
-           memcpy( pd, ps2, es2->keylen + ( (es2->valisnull) ? 0 : es2->vallen ) );
+       }
+       else if (difference > 0)
+       {
+           memcpy(ed, es2, sizeof(HEntry));
+           memcpy(pd, ps2, es2->keylen + ((es2->valisnull) ? 0 : es2->vallen));
            ed->pos = pd - STRPTR(out);
-           pd += es2->keylen + ( (es2->valisnull) ? 0 : es2->vallen );
+           pd += es2->keylen + ((es2->valisnull) ? 0 : es2->vallen);
            ed++;
-           
-           ps2 += es2->keylen + ( (es2->valisnull) ? 0 : es2->vallen );
+
+           ps2 += es2->keylen + ((es2->valisnull) ? 0 : es2->vallen);
            es2++;
-       } else {
-           memcpy( ed, es1, sizeof(HEntry) );
-           memcpy( pd, ps1, es1->keylen + ( (es1->valisnull) ? 0 : es1->vallen ) );
+       }
+       else
+       {
+           memcpy(ed, es1, sizeof(HEntry));
+           memcpy(pd, ps1, es1->keylen + ((es1->valisnull) ? 0 : es1->vallen));
            ed->pos = pd - STRPTR(out);
-           pd += es1->keylen + ( (es1->valisnull) ? 0 : es1->vallen );
+           pd += es1->keylen + ((es1->valisnull) ? 0 : es1->vallen);
            ed++;
-           
-           ps1 += es1->keylen + ( (es1->valisnull) ? 0 : es1->vallen );
+
+           ps1 += es1->keylen + ((es1->valisnull) ? 0 : es1->vallen);
            es1++;
        }
    }
 
-   while( es1 - ARRPTR(s1) < s1->size ) {
-       memcpy( ed, es1, sizeof(HEntry) );
-       memcpy( pd, ps1, es1->keylen + ( (es1->valisnull) ? 0 : es1->vallen ) );
+   while (es1 - ARRPTR(s1) < s1->size)
+   {
+       memcpy(ed, es1, sizeof(HEntry));
+       memcpy(pd, ps1, es1->keylen + ((es1->valisnull) ? 0 : es1->vallen));
        ed->pos = pd - STRPTR(out);
-       pd += es1->keylen + ( (es1->valisnull) ? 0 : es1->vallen );
+       pd += es1->keylen + ((es1->valisnull) ? 0 : es1->vallen);
        ed++;
-           
-       ps1 += es1->keylen + ( (es1->valisnull) ? 0 : es1->vallen );
+
+       ps1 += es1->keylen + ((es1->valisnull) ? 0 : es1->vallen);
        es1++;
    }
 
-   while( es2 - ARRPTR(s2) < s2->size ) {
-       memcpy( ed, es2, sizeof(HEntry) );
-       memcpy( pd, ps2, es2->keylen + ( (es2->valisnull) ? 0 : es2->vallen ) );
+   while (es2 - ARRPTR(s2) < s2->size)
+   {
+       memcpy(ed, es2, sizeof(HEntry));
+       memcpy(pd, ps2, es2->keylen + ((es2->valisnull) ? 0 : es2->vallen));
        ed->pos = pd - STRPTR(out);
-       pd += es2->keylen + ( (es2->valisnull) ? 0 : es2->vallen );
+       pd += es2->keylen + ((es2->valisnull) ? 0 : es2->vallen);
        ed++;
-       
-       ps2 += es2->keylen + ( (es2->valisnull) ? 0 : es2->vallen );
+
+       ps2 += es2->keylen + ((es2->valisnull) ? 0 : es2->vallen);
        es2++;
    }
 
-   if ( ed - ARRPTR(out) != out->size ) {
-       int buflen=pd-STRPTR(out);
+   if (ed - ARRPTR(out) != out->size)
+   {
+       int         buflen = pd - STRPTR(out);
+
        pd = STRPTR(out);
 
        out->size = ed - ARRPTR(out);
 
-       memmove( STRPTR(out), pd, buflen);
+       memmove(STRPTR(out), pd, buflen);
        out->len = CALCDATASIZE(out->size, buflen);
    }
-       
-   PG_FREE_IF_COPY(s1,0);
-   PG_FREE_IF_COPY(s2,1);
+
+   PG_FREE_IF_COPY(s1, 0);
+   PG_FREE_IF_COPY(s2, 1);
 
    PG_RETURN_POINTER(out);
 }
 
 PG_FUNCTION_INFO_V1(tconvert);
-Datum           tconvert(PG_FUNCTION_ARGS);
+Datum      tconvert(PG_FUNCTION_ARGS);
 Datum
-tconvert(PG_FUNCTION_ARGS) {
-   text   *key = PG_GETARG_TEXT_P(0);
-   text   *val = PG_GETARG_TEXT_P(1);
-   int len;
-   HStore  *out;
-
-   len=CALCDATASIZE(1, VARSIZE(key) + VARSIZE(val) - 2*VARHDRSZ);
+tconvert(PG_FUNCTION_ARGS)
+{
+   text       *key = PG_GETARG_TEXT_P(0);
+   text       *val = PG_GETARG_TEXT_P(1);
+   int         len;
+   HStore     *out;
+
+   len = CALCDATASIZE(1, VARSIZE(key) + VARSIZE(val) - 2 * VARHDRSZ);
    out = palloc(len);
-   out->len=len;
-   out->size=1;
+   out->len = len;
+   out->size = 1;
 
    ARRPTR(out)->keylen = VARSIZE(key) - VARHDRSZ;
    ARRPTR(out)->vallen = VARSIZE(val) - VARHDRSZ;
    ARRPTR(out)->valisnull = false;
-   ARRPTR(out)->pos=0;
+   ARRPTR(out)->pos = 0;
 
-   memcpy( STRPTR(out), VARDATA(key), ARRPTR(out)->keylen );
-   memcpy( STRPTR(out) + ARRPTR(out)->keylen, VARDATA(val), ARRPTR(out)->vallen );
-       
-   PG_FREE_IF_COPY(key,0);
-   PG_FREE_IF_COPY(val,1);
+   memcpy(STRPTR(out), VARDATA(key), ARRPTR(out)->keylen);
+   memcpy(STRPTR(out) + ARRPTR(out)->keylen, VARDATA(val), ARRPTR(out)->vallen);
+
+   PG_FREE_IF_COPY(key, 0);
+   PG_FREE_IF_COPY(val, 1);
 
    PG_RETURN_POINTER(out);
 }
 
 PG_FUNCTION_INFO_V1(akeys);
-Datum           akeys(PG_FUNCTION_ARGS);
+Datum      akeys(PG_FUNCTION_ARGS);
 Datum
-akeys(PG_FUNCTION_ARGS) { 
-   HStore *hs  = PG_GETARG_HS(0);
-   Datum   *d;
-   ArrayType *a;
-   HEntry *ptr=ARRPTR(hs);
-   char *base=STRPTR(hs);
-
-   d=(Datum*)palloc(sizeof(Datum)*(hs->size+1));
-   while( ptr-ARRPTR(hs) < hs->size ) {
-       text *item=(text*)palloc(VARHDRSZ + ptr->keylen);
-       VARATT_SIZEP(item) = VARHDRSZ+ptr->keylen;
+akeys(PG_FUNCTION_ARGS)
+{
+   HStore     *hs = PG_GETARG_HS(0);
+   Datum      *d;
+   ArrayType  *a;
+   HEntry     *ptr = ARRPTR(hs);
+   char       *base = STRPTR(hs);
+
+   d = (Datum *) palloc(sizeof(Datum) * (hs->size + 1));
+   while (ptr - ARRPTR(hs) < hs->size)
+   {
+       text       *item = (text *) palloc(VARHDRSZ + ptr->keylen);
+
+       VARATT_SIZEP(item) = VARHDRSZ + ptr->keylen;
        memcpy(VARDATA(item), base + ptr->pos, ptr->keylen);
-       d[ ptr-ARRPTR(hs) ] = PointerGetDatum(item);
+       d[ptr - ARRPTR(hs)] = PointerGetDatum(item);
        ptr++;
    }
-   
+
    a = construct_array(
-       d,
-       hs->size,
-       TEXTOID,
-       -1,
-       false,
-       'i'
-   );
-
-   ptr=ARRPTR(hs);
-   while( ptr-ARRPTR(hs) < hs->size ) {
-       pfree(DatumGetPointer(d[ ptr-ARRPTR(hs) ]));
+                       d,
+                       hs->size,
+                       TEXTOID,
+                       -1,
+                       false,
+                       'i'
+       );
+
+   ptr = ARRPTR(hs);
+   while (ptr - ARRPTR(hs) < hs->size)
+   {
+       pfree(DatumGetPointer(d[ptr - ARRPTR(hs)]));
        ptr++;
    }
 
    pfree(d);
-   PG_FREE_IF_COPY(hs,0);
+   PG_FREE_IF_COPY(hs, 0);
 
    PG_RETURN_POINTER(a);
 }
 
 PG_FUNCTION_INFO_V1(avals);
-Datum           avals(PG_FUNCTION_ARGS);
+Datum      avals(PG_FUNCTION_ARGS);
 Datum
-avals(PG_FUNCTION_ARGS) { 
-   HStore *hs  = PG_GETARG_HS(0);
-   Datum   *d;
-   ArrayType *a;
-   HEntry *ptr=ARRPTR(hs);
-   char *base=STRPTR(hs);
-
-   d=(Datum*)palloc(sizeof(Datum)*(hs->size+1));
-   while( ptr-ARRPTR(hs) < hs->size ) {
-       int vallen = (ptr->valisnull) ? 0 : ptr->vallen; 
-       text *item=(text*)palloc(VARHDRSZ + vallen);
-       VARATT_SIZEP(item) = VARHDRSZ+vallen;
+avals(PG_FUNCTION_ARGS)
+{
+   HStore     *hs = PG_GETARG_HS(0);
+   Datum      *d;
+   ArrayType  *a;
+   HEntry     *ptr = ARRPTR(hs);
+   char       *base = STRPTR(hs);
+
+   d = (Datum *) palloc(sizeof(Datum) * (hs->size + 1));
+   while (ptr - ARRPTR(hs) < hs->size)
+   {
+       int         vallen = (ptr->valisnull) ? 0 : ptr->vallen;
+       text       *item = (text *) palloc(VARHDRSZ + vallen);
+
+       VARATT_SIZEP(item) = VARHDRSZ + vallen;
        memcpy(VARDATA(item), base + ptr->pos + ptr->keylen, vallen);
-       d[ ptr-ARRPTR(hs) ] = PointerGetDatum(item);
+       d[ptr - ARRPTR(hs)] = PointerGetDatum(item);
        ptr++;
    }
-   
+
    a = construct_array(
-       d,
-       hs->size,
-       TEXTOID,
-       -1,
-       false,
-       'i'
-   );
-
-   ptr=ARRPTR(hs);
-   while( ptr-ARRPTR(hs) < hs->size ) {
-       pfree(DatumGetPointer(d[ ptr-ARRPTR(hs) ]));
+                       d,
+                       hs->size,
+                       TEXTOID,
+                       -1,
+                       false,
+                       'i'
+       );
+
+   ptr = ARRPTR(hs);
+   while (ptr - ARRPTR(hs) < hs->size)
+   {
+       pfree(DatumGetPointer(d[ptr - ARRPTR(hs)]));
        ptr++;
    }
 
    pfree(d);
-   PG_FREE_IF_COPY(hs,0);
+   PG_FREE_IF_COPY(hs, 0);
 
    PG_RETURN_POINTER(a);
 }
 
-typedef struct {
-   HStore  *hs;
-   int     i;
-} AKStore;
+typedef struct
+{
+   HStore     *hs;
+   int         i;
+}  AKStore;
 
 static void
-setup_firstcall(FuncCallContext  *funcctx, HStore *hs) {
-   MemoryContext     oldcontext;
-   AKStore     *st;
+setup_firstcall(FuncCallContext *funcctx, HStore * hs)
+{
+   MemoryContext oldcontext;
+   AKStore    *st;
 
    oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
 
-   st=(AKStore*)palloc( sizeof(AKStore) );
-   st->i=0;
-   st->hs = (HStore*)palloc(hs->len);
-   memcpy( st->hs, hs, hs->len );
+   st = (AKStore *) palloc(sizeof(AKStore));
+   st->i = 0;
+   st->hs = (HStore *) palloc(hs->len);
+   memcpy(st->hs, hs, hs->len);
 
-   funcctx->user_fctx = (void*)st;
+   funcctx->user_fctx = (void *) st;
    MemoryContextSwitchTo(oldcontext);
 }
 
 PG_FUNCTION_INFO_V1(skeys);
-Datum           skeys(PG_FUNCTION_ARGS);
+Datum      skeys(PG_FUNCTION_ARGS);
 Datum
-skeys(PG_FUNCTION_ARGS) {
-   FuncCallContext  *funcctx;
-   AKStore *st;
+skeys(PG_FUNCTION_ARGS)
+{
+   FuncCallContext *funcctx;
+   AKStore    *st;
+
+   if (SRF_IS_FIRSTCALL())
+   {
+       HStore     *hs = PG_GETARG_HS(0);
 
-   if (SRF_IS_FIRSTCALL()) {
-       HStore *hs = PG_GETARG_HS(0);
        funcctx = SRF_FIRSTCALL_INIT();
        setup_firstcall(funcctx, hs);
-       PG_FREE_IF_COPY(hs,0);
+       PG_FREE_IF_COPY(hs, 0);
    }
 
    funcctx = SRF_PERCALL_SETUP();
-   st = (AKStore*)funcctx->user_fctx;
-   
-   if ( st->i < st->hs->size ) {
-       HEntry *ptr = &(ARRPTR(st->hs)[st->i]);
-       text *item=(text*)palloc(VARHDRSZ + ptr->keylen);
+   st = (AKStore *) funcctx->user_fctx;
+
+   if (st->i < st->hs->size)
+   {
+       HEntry     *ptr = &(ARRPTR(st->hs)[st->i]);
+       text       *item = (text *) palloc(VARHDRSZ + ptr->keylen);
 
-       VARATT_SIZEP(item) = VARHDRSZ+ptr->keylen;
+       VARATT_SIZEP(item) = VARHDRSZ + ptr->keylen;
        memcpy(VARDATA(item), STRPTR(st->hs) + ptr->pos, ptr->keylen);
        st->i++;
 
        SRF_RETURN_NEXT(funcctx, PointerGetDatum(item));
    }
-   
-   pfree( st->hs );
-   pfree( st );
 
-   SRF_RETURN_DONE(funcctx); 
+   pfree(st->hs);
+   pfree(st);
+
+   SRF_RETURN_DONE(funcctx);
 }
 
 PG_FUNCTION_INFO_V1(svals);
-Datum           svals(PG_FUNCTION_ARGS);
+Datum      svals(PG_FUNCTION_ARGS);
 Datum
-svals(PG_FUNCTION_ARGS) {
-   FuncCallContext  *funcctx;
-   AKStore *st;
+svals(PG_FUNCTION_ARGS)
+{
+   FuncCallContext *funcctx;
+   AKStore    *st;
+
+   if (SRF_IS_FIRSTCALL())
+   {
+       HStore     *hs = PG_GETARG_HS(0);
 
-   if (SRF_IS_FIRSTCALL()) {
-       HStore *hs = PG_GETARG_HS(0);
        funcctx = SRF_FIRSTCALL_INIT();
        setup_firstcall(funcctx, hs);
-       PG_FREE_IF_COPY(hs,0);
+       PG_FREE_IF_COPY(hs, 0);
    }
 
    funcctx = SRF_PERCALL_SETUP();
-   st = (AKStore*)funcctx->user_fctx;
-   
-   if ( st->i < st->hs->size ) {
-       HEntry *ptr = &(ARRPTR(st->hs)[st->i]);
+   st = (AKStore *) funcctx->user_fctx;
 
-       if ( ptr->valisnull ) {
-           ReturnSetInfo      *rsi;
+   if (st->i < st->hs->size)
+   {
+       HEntry     *ptr = &(ARRPTR(st->hs)[st->i]);
+
+       if (ptr->valisnull)
+       {
+           ReturnSetInfo *rsi;
 
            st->i++;
            (funcctx)->call_cntr++;
            rsi = (ReturnSetInfo *) fcinfo->resultinfo;
            rsi->isDone = ExprMultipleResult;
            PG_RETURN_NULL();
-       } else {
-           int vallen = ptr->vallen; 
-           text *item=(text*)palloc(VARHDRSZ + vallen);
+       }
+       else
+       {
+           int         vallen = ptr->vallen;
+           text       *item = (text *) palloc(VARHDRSZ + vallen);
 
-           VARATT_SIZEP(item) = VARHDRSZ+vallen;
+           VARATT_SIZEP(item) = VARHDRSZ + vallen;
            memcpy(VARDATA(item), STRPTR(st->hs) + ptr->pos + ptr->keylen, vallen);
            st->i++;
 
            SRF_RETURN_NEXT(funcctx, PointerGetDatum(item));
        }
    }
-   
-   pfree( st->hs );
-   pfree( st );
 
-   SRF_RETURN_DONE(funcctx); 
+   pfree(st->hs);
+   pfree(st);
+
+   SRF_RETURN_DONE(funcctx);
 }
 
 PG_FUNCTION_INFO_V1(hs_contains);
-Datum           hs_contains(PG_FUNCTION_ARGS);
+Datum      hs_contains(PG_FUNCTION_ARGS);
 Datum
-hs_contains(PG_FUNCTION_ARGS) {
-   HStore *val   = PG_GETARG_HS(0);
-   HStore *tmpl  = PG_GETARG_HS(1);
-   bool res = true;
-   HEntry  *te = ARRPTR(tmpl);
-   char    *vv = STRPTR(val);
-   char    *tv = STRPTR(tmpl);
-
-   while(res && te-ARRPTR(tmpl) < tmpl->size) {
-       HEntry *entry = findkey(val, tv + te->pos, te->keylen);
-       if ( entry ) {
-           if ( ! te->valisnull ) {
-               if ( entry->valisnull || !(
-                       te->vallen==entry->vallen && 
-                       strncmp( 
-                           vv + entry->pos + entry->keylen, 
-                           tv + te->pos + te->keylen, 
-                       te->vallen ) == 0
-                   ) )
-                   res=false;
+hs_contains(PG_FUNCTION_ARGS)
+{
+   HStore     *val = PG_GETARG_HS(0);
+   HStore     *tmpl = PG_GETARG_HS(1);
+   bool        res = true;
+   HEntry     *te = ARRPTR(tmpl);
+   char       *vv = STRPTR(val);
+   char       *tv = STRPTR(tmpl);
+
+   while (res && te - ARRPTR(tmpl) < tmpl->size)
+   {
+       HEntry     *entry = findkey(val, tv + te->pos, te->keylen);
+
+       if (entry)
+       {
+           if (!te->valisnull)
+           {
+               if (entry->valisnull || !(
+                                         te->vallen == entry->vallen &&
+                                         strncmp(
+                                            vv + entry->pos + entry->keylen,
+                                                 tv + te->pos + te->keylen,
+                                                 te->vallen) == 0
+                                         ))
+                   res = false;
            }
-       } else
+       }
+       else
            res = false;
        te++;
    }
 
-   PG_FREE_IF_COPY(val,0);
-   PG_FREE_IF_COPY(tmpl,1);
+   PG_FREE_IF_COPY(val, 0);
+   PG_FREE_IF_COPY(tmpl, 1);
 
    PG_RETURN_BOOL(res);
 }
-   
+
 PG_FUNCTION_INFO_V1(hs_contained);
-Datum           hs_contained(PG_FUNCTION_ARGS);
+Datum      hs_contained(PG_FUNCTION_ARGS);
 Datum
-hs_contained(PG_FUNCTION_ARGS) {
-   PG_RETURN_DATUM( DirectFunctionCall2(
-       hs_contains,
-       PG_GETARG_DATUM(1),
-       PG_GETARG_DATUM(0)
-   ));
+hs_contained(PG_FUNCTION_ARGS)
+{
+   PG_RETURN_DATUM(DirectFunctionCall2(
+                                       hs_contains,
+                                       PG_GETARG_DATUM(1),
+                                       PG_GETARG_DATUM(0)
+                                       ));
 }
 
 PG_FUNCTION_INFO_V1(each);
-Datum           each(PG_FUNCTION_ARGS);
+Datum      each(PG_FUNCTION_ARGS);
 Datum
-each(PG_FUNCTION_ARGS) {
-   FuncCallContext  *funcctx;
-   AKStore *st;
+each(PG_FUNCTION_ARGS)
+{
+   FuncCallContext *funcctx;
+   AKStore    *st;
 
-   if (SRF_IS_FIRSTCALL()) {
-       TupleDesc            tupdesc;
-       MemoryContext     oldcontext;
-       HStore *hs = PG_GETARG_HS(0);
+   if (SRF_IS_FIRSTCALL())
+   {
+       TupleDesc   tupdesc;
+       MemoryContext oldcontext;
+       HStore     *hs = PG_GETARG_HS(0);
 
        funcctx = SRF_FIRSTCALL_INIT();
        oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
-       st=(AKStore*)palloc( sizeof(AKStore) );
-       st->i=0;
-       st->hs = (HStore*)palloc(hs->len);
-       memcpy( st->hs, hs, hs->len );
-       funcctx->user_fctx = (void*)st;     
-           
+       st = (AKStore *) palloc(sizeof(AKStore));
+       st->i = 0;
+       st->hs = (HStore *) palloc(hs->len);
+       memcpy(st->hs, hs, hs->len);
+       funcctx->user_fctx = (void *) st;
+
        tupdesc = RelationNameGetTupleDesc("hs_each");
        funcctx->slot = TupleDescGetSlot(tupdesc);
        funcctx->attinmeta = TupleDescGetAttInMetadata(tupdesc);
 
        MemoryContextSwitchTo(oldcontext);
-       PG_FREE_IF_COPY(hs,0);
+       PG_FREE_IF_COPY(hs, 0);
    }
 
    funcctx = SRF_PERCALL_SETUP();
-   st = (AKStore*)funcctx->user_fctx;
-   
-   if ( st->i < st->hs->size ) {
-       HEntry *ptr = &(ARRPTR(st->hs)[st->i]);
-       Datum res, dvalues[2];
-       char       nulls[] = {' ', ' '};
-       text *item;
-       HeapTuple       tuple;
-
-       item=(text*)palloc(VARHDRSZ + ptr->keylen);
-       VARATT_SIZEP(item) = VARHDRSZ+ptr->keylen;
+   st = (AKStore *) funcctx->user_fctx;
+
+   if (st->i < st->hs->size)
+   {
+       HEntry     *ptr = &(ARRPTR(st->hs)[st->i]);
+       Datum       res,
+                   dvalues[2];
+       char        nulls[] = {' ', ' '};
+       text       *item;
+       HeapTuple   tuple;
+
+       item = (text *) palloc(VARHDRSZ + ptr->keylen);
+       VARATT_SIZEP(item) = VARHDRSZ + ptr->keylen;
        memcpy(VARDATA(item), STRPTR(st->hs) + ptr->pos, ptr->keylen);
        dvalues[0] = PointerGetDatum(item);
 
-       if ( ptr->valisnull ) {
-           dvalues[1]=(Datum)0;
-           nulls[1]='n';
-       } else {
-           int vallen = ptr->vallen; 
+       if (ptr->valisnull)
+       {
+           dvalues[1] = (Datum) 0;
+           nulls[1] = 'n';
+       }
+       else
+       {
+           int         vallen = ptr->vallen;
 
-           item=(text*)palloc(VARHDRSZ + vallen);
-           VARATT_SIZEP(item) = VARHDRSZ+vallen;
+           item = (text *) palloc(VARHDRSZ + vallen);
+           VARATT_SIZEP(item) = VARHDRSZ + vallen;
            memcpy(VARDATA(item), STRPTR(st->hs) + ptr->pos + ptr->keylen, vallen);
            dvalues[1] = PointerGetDatum(item);
        }
@@ -551,17 +616,15 @@ each(PG_FUNCTION_ARGS) {
        tuple = heap_formtuple(funcctx->attinmeta->tupdesc, dvalues, nulls);
        res = TupleGetDatum(funcctx->slot, tuple);
 
-       pfree( DatumGetPointer(dvalues[0]) );
-       if ( nulls[1] != 'n' ) 
-           pfree( DatumGetPointer(dvalues[1]) );
+       pfree(DatumGetPointer(dvalues[0]));
+       if (nulls[1] != 'n')
+           pfree(DatumGetPointer(dvalues[1]));
 
        SRF_RETURN_NEXT(funcctx, PointerGetDatum(res));
    }
-   
-   pfree( st->hs );
-   pfree( st );
-
-   SRF_RETURN_DONE(funcctx); 
-}
 
+   pfree(st->hs);
+   pfree(st);
 
+   SRF_RETURN_DONE(funcctx);
+}
index f40dc06a92c150a7cd9c08da55a985efd3c3c5e1..bf10f109220d5d68f9a6f6d888799ee2f7c9c861 100644 (file)
@@ -154,17 +154,17 @@ typedef struct
 #define COMPUTESIZE(size)  ( HDRSIZEQT + size * sizeof(ITEM) )
 #define GETQUERY(x)  (ITEM*)( (char*)(x)+HDRSIZEQT )
 
-#define END     0
-#define ERR     1
-#define VAL     2
-#define OPR     3
-#define OPEN    4
-#define CLOSE   5
+#define END        0
+#define ERR        1
+#define VAL        2
+#define OPR        3
+#define OPEN   4
+#define CLOSE  5
 
 bool       signconsistent(QUERYTYPE * query, BITVEC sign, bool calcnot);
 bool       execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot);
-bool       ginconsistent(QUERYTYPE * query, bool *check);
-int4       shorterquery(ITEM * q, int4 len);
+bool       ginconsistent(QUERYTYPE * query, bool *check);
+int4       shorterquery(ITEM * q, int4 len);
 
 int            compASC(const void *a, const void *b);
 
index 230c412a0486ac55fa06462cfab92323c6428094..8517010e5ed28a364afe785598f1a1917842a8c5 100644 (file)
@@ -232,7 +232,7 @@ typedef struct
  * is there value 'val' in array or not ?
  */
 static bool
-checkcondition_arr(void *checkval, ITEM *item)
+checkcondition_arr(void *checkval, ITEM * item)
 {
    int4       *StopLow = ((CHKVAL *) checkval)->arrb;
    int4       *StopHigh = ((CHKVAL *) checkval)->arre;
@@ -254,7 +254,7 @@ checkcondition_arr(void *checkval, ITEM *item)
 }
 
 static bool
-checkcondition_bit(void *checkval, ITEM *item)
+checkcondition_bit(void *checkval, ITEM * item)
 {
    return GETBIT(checkval, HASHVAL(item->val));
 }
@@ -263,7 +263,7 @@ checkcondition_bit(void *checkval, ITEM *item)
  * check for boolean condition
  */
 static bool
-execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM *item))
+execute(ITEM * curitem, void *checkval, bool calcnot, bool (*chkcond) (void *checkval, ITEM * item))
 {
 
    if (curitem->type == VAL)
@@ -319,38 +319,42 @@ execconsistent(QUERYTYPE * query, ArrayType *array, bool calcnot)
        );
 }
 
-typedef struct {
-   ITEM    *first;
-   bool    *mapped_check;
-} GinChkVal;
+typedef struct
+{
+   ITEM       *first;
+   bool       *mapped_check;
+}  GinChkVal;
 
 static bool
-checkcondition_gin(void *checkval, ITEM *item) {
-   GinChkVal   *gcv = (GinChkVal*)checkval;
+checkcondition_gin(void *checkval, ITEM * item)
+{
+   GinChkVal  *gcv = (GinChkVal *) checkval;
 
-   return gcv->mapped_check[ item - gcv->first ];
+   return gcv->mapped_check[item - gcv->first];
 }
 
 bool
-ginconsistent(QUERYTYPE * query, bool *check) {
-   GinChkVal   gcv;
-   ITEM    *items = GETQUERY(query);
-   int i, j=0;
+ginconsistent(QUERYTYPE * query, bool *check)
+{
+   GinChkVal   gcv;
+   ITEM       *items = GETQUERY(query);
+   int         i,
+               j = 0;
 
-   if ( query->size < 0 )
+   if (query->size < 0)
        return FALSE;
 
    gcv.first = items;
-   gcv.mapped_check = (bool*)palloc( sizeof(bool)*query->size );
-   for(i=0; i<query->size; i++)
-       if ( items[i].type == VAL ) 
-           gcv.mapped_check[ i ] = check[ j++ ];
-
-   return execute( 
-       GETQUERY(query) + query->size - 1,
-       (void *) &gcv, true,
-       checkcondition_gin
-   );
+   gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
+   for (i = 0; i < query->size; i++)
+       if (items[i].type == VAL)
+           gcv.mapped_check[i] = check[j++];
+
+   return execute(
+                  GETQUERY(query) + query->size - 1,
+                  (void *) &gcv, true,
+                  checkcondition_gin
+       );
 }
 
 /*
index 2a2830e578ddf58af5db5ff002416d9b0939efb2..7bb9599b3350b176a3550b9ea3faff7843fb81d2 100644 (file)
 #include "_int.h"
 
 PG_FUNCTION_INFO_V1(ginint4_queryextract);
-Datum ginint4_queryextract(PG_FUNCTION_ARGS);
+Datum      ginint4_queryextract(PG_FUNCTION_ARGS);
 
 Datum
-ginint4_queryextract(PG_FUNCTION_ARGS) {
-   uint32  *nentries = (uint32*)PG_GETARG_POINTER(1);
-   StrategyNumber  strategy = PG_GETARG_UINT16(2);
-   Datum   *res = NULL;
-   
+ginint4_queryextract(PG_FUNCTION_ARGS)
+{
+   uint32     *nentries = (uint32 *) PG_GETARG_POINTER(1);
+   StrategyNumber strategy = PG_GETARG_UINT16(2);
+   Datum      *res = NULL;
+
    *nentries = 0;
 
-   if ( strategy == BooleanSearchStrategy ) {
-       QUERYTYPE   *query = (QUERYTYPE*)PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(0));
-       ITEM        *items = GETQUERY(query);
-       int i;
+   if (strategy == BooleanSearchStrategy)
+   {
+       QUERYTYPE  *query = (QUERYTYPE *) PG_DETOAST_DATUM_COPY(PG_GETARG_POINTER(0));
+       ITEM       *items = GETQUERY(query);
+       int         i;
 
        if (query->size == 0)
            PG_RETURN_POINTER(NULL);
 
-       if ( shorterquery(items, query->size) == 0 )
-           elog(ERROR,"Query requires full scan, GIN doesn't support it");
+       if (shorterquery(items, query->size) == 0)
+           elog(ERROR, "Query requires full scan, GIN doesn't support it");
 
-       pfree( query );
+       pfree(query);
 
-       query = (QUERYTYPE*)PG_DETOAST_DATUM(PG_GETARG_POINTER(0));
+       query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(0));
        items = GETQUERY(query);
 
-       res = (Datum*)palloc(sizeof(Datum) * query->size);
+       res = (Datum *) palloc(sizeof(Datum) * query->size);
        *nentries = 0;
 
-       for(i=0;i<query->size;i++)
-           if ( items[i].type == VAL ) { 
-               res[*nentries] = Int32GetDatum( items[i].val );
+       for (i = 0; i < query->size; i++)
+           if (items[i].type == VAL)
+           {
+               res[*nentries] = Int32GetDatum(items[i].val);
                (*nentries)++;
            }
-   } else {
-       ArrayType   *query = PG_GETARG_ARRAYTYPE_P(0);
-       int4 *arr;
-       uint32 i;
+   }
+   else
+   {
+       ArrayType  *query = PG_GETARG_ARRAYTYPE_P(0);
+       int4       *arr;
+       uint32      i;
 
        CHECKARRVALID(query);
-       *nentries=ARRNELEMS(query);
-       if ( *nentries > 0 ) {
-           res = (Datum*)palloc(sizeof(Datum) * (*nentries));
-
-           arr=ARRPTR(query);
-           for(i=0;i<*nentries;i++) 
-               res[i] = Int32GetDatum( arr[i] );
+       *nentries = ARRNELEMS(query);
+       if (*nentries > 0)
+       {
+           res = (Datum *) palloc(sizeof(Datum) * (*nentries));
+
+           arr = ARRPTR(query);
+           for (i = 0; i < *nentries; i++)
+               res[i] = Int32GetDatum(arr[i]);
        }
    }
 
-   PG_RETURN_POINTER( res );
+   PG_RETURN_POINTER(res);
 }
 
 PG_FUNCTION_INFO_V1(ginint4_consistent);
-Datum ginint4_consistent(PG_FUNCTION_ARGS);
+Datum      ginint4_consistent(PG_FUNCTION_ARGS);
 
 Datum
-ginint4_consistent(PG_FUNCTION_ARGS) {
-    bool    *check = (bool*)PG_GETARG_POINTER(0);
-    StrategyNumber  strategy = PG_GETARG_UINT16(1);
-    int res=FALSE;
-
-    /* we can do not check array carefully, it's done by previous ginarrayextract call */
-
-    switch( strategy ) {
-        case RTOverlapStrategyNumber:
-        case RTContainedByStrategyNumber:
-        case RTOldContainedByStrategyNumber:
-            /* at least one element in check[] is true, so result = true */
-
-            res = TRUE;
-            break;
-        case RTSameStrategyNumber:
-        case RTContainsStrategyNumber:
-        case RTOldContainsStrategyNumber:
-            res = TRUE;
-           do {
-               ArrayType   *query = PG_GETARG_ARRAYTYPE_P(2);
-               int i, nentries=ARRNELEMS(query);
-
-               for(i=0;i<nentries;i++)
-                   if ( !check[i] ) {
-                       res = FALSE;
-                       break;
-                   }
-           } while(0);
-            break;
-        case BooleanSearchStrategy:
-           do {
-               QUERYTYPE   *query = (QUERYTYPE*)PG_DETOAST_DATUM(PG_GETARG_POINTER(2));
-               res = ginconsistent( query, check ); 
-           } while(0);
+ginint4_consistent(PG_FUNCTION_ARGS)
+{
+   bool       *check = (bool *) PG_GETARG_POINTER(0);
+   StrategyNumber strategy = PG_GETARG_UINT16(1);
+   int         res = FALSE;
+
+   /*
+    * we can do not check array carefully, it's done by previous
+    * ginarrayextract call
+    */
+
+   switch (strategy)
+   {
+       case RTOverlapStrategyNumber:
+       case RTContainedByStrategyNumber:
+       case RTOldContainedByStrategyNumber:
+           /* at least one element in check[] is true, so result = true */
+
+           res = TRUE;
+           break;
+       case RTSameStrategyNumber:
+       case RTContainsStrategyNumber:
+       case RTOldContainsStrategyNumber:
+           res = TRUE;
+           do
+           {
+               ArrayType  *query = PG_GETARG_ARRAYTYPE_P(2);
+               int         i,
+                           nentries = ARRNELEMS(query);
+
+               for (i = 0; i < nentries; i++)
+                   if (!check[i])
+                   {
+                       res = FALSE;
+                       break;
+                   }
+           } while (0);
            break;
-        default:
-            elog(ERROR, "ginint4_consistent: unknown strategy number: %d", strategy);
-    }
+       case BooleanSearchStrategy:
+           do
+           {
+               QUERYTYPE  *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_POINTER(2));
+
+               res = ginconsistent(query, check);
+           } while (0);
+           break;
+       default:
+           elog(ERROR, "ginint4_consistent: unknown strategy number: %d", strategy);
+   }
 
-    PG_RETURN_BOOL(res);
+   PG_RETURN_BOOL(res);
 }
index 71c9ad0cec517dd3af090abe2c6597f4d91df439..56eb0c08c2e53835755011fba0ce2574ffbc3a83 100644 (file)
@@ -36,19 +36,21 @@ g_int_consistent(PG_FUNCTION_ARGS)
    StrategyNumber strategy = (StrategyNumber) PG_GETARG_UINT16(2);
    bool        retval;
 
-   if (strategy == BooleanSearchStrategy) {
+   if (strategy == BooleanSearchStrategy)
+   {
        retval = execconsistent((QUERYTYPE *) query,
-                                  (ArrayType *) DatumGetPointer(entry->key),
-                                     GIST_LEAF(entry));
+                               (ArrayType *) DatumGetPointer(entry->key),
+                               GIST_LEAF(entry));
 
-       pfree( query );
+       pfree(query);
        PG_RETURN_BOOL(retval);
    }
 
    /* sort query for fast search, key is already sorted */
    CHECKARRVALID(query);
-   if (ARRISVOID(query)) {
-       pfree( query );
+   if (ARRISVOID(query))
+   {
+       pfree(query);
        PG_RETURN_BOOL(false);
    }
    PREPAREARR(query);
@@ -88,7 +90,7 @@ g_int_consistent(PG_FUNCTION_ARGS)
        default:
            retval = FALSE;
    }
-   pfree( query );
+   pfree(query);
    PG_RETURN_BOOL(retval);
 }
 
@@ -156,7 +158,7 @@ g_int_compress(PG_FUNCTION_ARGS)
 
        retval = palloc(sizeof(GISTENTRY));
        gistentryinit(*retval, PointerGetDatum(r),
-                 entry->rel, entry->page, entry->offset, FALSE);
+                     entry->rel, entry->page, entry->offset, FALSE);
 
        PG_RETURN_POINTER(retval);
    }
@@ -203,7 +205,7 @@ g_int_compress(PG_FUNCTION_ARGS)
        r = resize_intArrayType(r, len);
        retval = palloc(sizeof(GISTENTRY));
        gistentryinit(*retval, PointerGetDatum(r),
-                 entry->rel, entry->page, entry->offset, FALSE);
+                     entry->rel, entry->page, entry->offset, FALSE);
        PG_RETURN_POINTER(retval);
    }
    else
@@ -240,7 +242,7 @@ g_int_decompress(PG_FUNCTION_ARGS)
        {
            retval = palloc(sizeof(GISTENTRY));
            gistentryinit(*retval, PointerGetDatum(in),
-                entry->rel, entry->page, entry->offset, FALSE);
+                         entry->rel, entry->page, entry->offset, FALSE);
 
            PG_RETURN_POINTER(retval);
        }
@@ -331,7 +333,7 @@ typedef struct
 {
    OffsetNumber pos;
    float       cost;
-} SPLITCOST;
+}  SPLITCOST;
 
 static int
 comparecost(const void *a, const void *b)
index 82ce4b7ac5642959bd7494e0fb2ea981730731f4..2ad0ef0cc04ebf3da23cc8feb297390a2c137b19 100644 (file)
@@ -89,22 +89,27 @@ inner_int_union(ArrayType *a, ArrayType *b)
 
    if (!r)
    {
-       int     na = ARRNELEMS(a),
-               nb = ARRNELEMS(b);
-       int     *da = ARRPTR(a),
-               *db = ARRPTR(b);
-       int     i,j, *dr;
+       int         na = ARRNELEMS(a),
+                   nb = ARRNELEMS(b);
+       int        *da = ARRPTR(a),
+                  *db = ARRPTR(b);
+       int         i,
+                   j,
+                  *dr;
 
        r = new_intArrayType(na + nb);
        dr = ARRPTR(r);
 
        /* union */
        i = j = 0;
-       while (i < na && j < nb) {
-           if (da[i] == db[j]) {
+       while (i < na && j < nb)
+       {
+           if (da[i] == db[j])
+           {
                *dr++ = da[i++];
                j++;
-           } else if (da[i] < db[j])
+           }
+           else if (da[i] < db[j])
                *dr++ = da[i++];
            else
                *dr++ = db[j++];
@@ -115,7 +120,7 @@ inner_int_union(ArrayType *a, ArrayType *b)
        while (j < nb)
            *dr++ = db[j++];
 
-       r = resize_intArrayType(r, dr-ARRPTR(r));
+       r = resize_intArrayType(r, dr - ARRPTR(r));
    }
 
    if (ARRNELEMS(r) > 1)
index b25814c7ce7ba3f74a9b31104497918febc4dd52..cb80d8f6f2452cb77df4d8bd7a356dbea2c8aafc 100644 (file)
@@ -214,7 +214,7 @@ sizebitvec(BITVECP sign)
                i;
 
    LOOPBYTE(
-       size += number_of_ones[(unsigned char) sign[i]];
+            size += number_of_ones[(unsigned char) sign[i]];
    );
    return size;
 }
@@ -227,8 +227,8 @@ hemdistsign(BITVECP a, BITVECP b)
                dist = 0;
 
    LOOPBYTE(
-       diff = (unsigned char) (a[i] ^ b[i]);
-       dist += number_of_ones[diff];
+            diff = (unsigned char) (a[i] ^ b[i]);
+   dist += number_of_ones[diff];
    );
    return dist;
 }
@@ -318,7 +318,7 @@ typedef struct
 {
    OffsetNumber pos;
    int4        cost;
-} SPLITCOST;
+}  SPLITCOST;
 
 static int
 comparecost(const void *a, const void *b)
@@ -506,16 +506,17 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
 
    if (strategy == BooleanSearchStrategy)
    {
-       retval =signconsistent((QUERYTYPE *) query,
-                                     GETSIGN(DatumGetPointer(entry->key)),
-                                     false);
-       PG_FREE_IF_COPY( query, 1 );
+       retval = signconsistent((QUERYTYPE *) query,
+                               GETSIGN(DatumGetPointer(entry->key)),
+                               false);
+       PG_FREE_IF_COPY(query, 1);
        PG_RETURN_BOOL(retval);
    }
 
    CHECKARRVALID(query);
-   if (ARRISVOID(query)) {
-       PG_FREE_IF_COPY( query, 1 );
+   if (ARRISVOID(query))
+   {
+       PG_FREE_IF_COPY(query, 1);
        PG_RETURN_BOOL(FALSE);
    }
 
@@ -602,6 +603,6 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
        default:
            retval = FALSE;
    }
-   PG_FREE_IF_COPY( query, 1 );
+   PG_FREE_IF_COPY(query, 1);
    PG_RETURN_BOOL(retval);
 }
index 43886c2d6848e67883091c1ff84be93cdb287fc6..87b611a5424bf2be0bce3dd2122182f990dbd7ce 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * EAN13.h
  *   PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
  *
  * http://www.gs1.org/productssolutions/idkeys/support/prefix_list.html
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/contrib/isn/EAN13.h,v 1.1 2006/09/09 04:07:52 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/isn/EAN13.h,v 1.2 2006/10/04 00:29:45 momjian Exp $
  *
  */
 
 /* where the digit set begins, and how many of them are in the table */
 const unsigned EAN13_index[10][2] = {
-   {0,     6},
-   {6,     1},
-   {7,     1},
-   {8,     5},
-   {13,    20},
-   {33,    15},
-   {48,    19},
-   {67,    23},
-   {90,    17},
-   {107,   12},
+   {0, 6},
+   {6, 1},
+   {7, 1},
+   {8, 5},
+   {13, 20},
+   {33, 15},
+   {48, 19},
+   {67, 23},
+   {90, 17},
+   {107, 12},
 };
 const char *EAN13_range[][2] = {
-   {"000", "019"}, /* GS1 US */
-   {"020", "029"}, /* Restricted distribution (MO defined) */
-   {"030", "039"}, /* GS1 US */
-   {"040", "049"}, /* Restricted distribution (MO defined) */
-   {"050", "059"}, /* Coupons */
-   {"060", "099"}, /* GS1 US */
-   {"100", "139"}, /* GS1 US */
-   {"200", "299"}, /* Restricted distribution (MO defined) */
-   {"300", "379"}, /* GS1 France */
-   {"380", "380"}, /* GS1 Bulgaria */
-   {"383", "383"}, /* GS1 Slovenija */
-   {"385", "385"}, /* GS1 Croatia */
-   {"387", "387"}, /* GS1 BIH (Bosnia-Herzegovina) */
-   {"400", "440"}, /* GS1 Germany */
-   {"450", "459"}, /* GS1 Japan */
-   {"460", "469"}, /* GS1 Russia */
-   {"470", "470"}, /* GS1 Kyrgyzstan */
-   {"471", "471"}, /* GS1 Taiwan */
-   {"474", "474"}, /* GS1 Estonia */
-   {"475", "475"}, /* GS1 Latvia */
-   {"476", "476"}, /* GS1 Azerbaijan */
-   {"477", "477"}, /* GS1 Lithuania */
-   {"478", "478"}, /* GS1 Uzbekistan */
-   {"479", "479"}, /* GS1 Sri Lanka */
-   {"480", "480"}, /* GS1 Philippines */
-   {"481", "481"}, /* GS1 Belarus */
-   {"482", "482"}, /* GS1 Ukraine */
-   {"484", "484"}, /* GS1 Moldova */
-   {"485", "485"}, /* GS1 Armenia */
-   {"486", "486"}, /* GS1 Georgia */
-   {"487", "487"}, /* GS1 Kazakstan */
-   {"489", "489"}, /* GS1 Hong Kong */
-   {"490", "499"}, /* GS1 Japan */
-   {"500", "509"}, /* GS1 UK */
-   {"520", "520"}, /* GS1 Greece */
-   {"528", "528"}, /* GS1 Lebanon */
-   {"529", "529"}, /* GS1 Cyprus */
-   {"530", "530"}, /* GS1 Albania */
-   {"531", "531"}, /* GS1 MAC (FYR Macedonia) */
-   {"535", "535"}, /* GS1 Malta */
-   {"539", "539"}, /* GS1 Ireland */
-   {"540", "549"}, /* GS1 Belgium & Luxembourg */
-   {"560", "560"}, /* GS1 Portugal */
-   {"569", "569"}, /* GS1 Iceland */
-   {"570", "579"}, /* GS1 Denmark */
-   {"590", "590"}, /* GS1 Poland */
-   {"594", "594"}, /* GS1 Romania */
-   {"599", "599"}, /* GS1 Hungary */
-   {"600", "601"}, /* GS1 South Africa */
-   {"603", "603"}, /* GS1 Ghana */
-   {"608", "608"}, /* GS1 Bahrain */
-   {"609", "609"}, /* GS1 Mauritius */
-   {"611", "611"}, /* GS1 Morocco */
-   {"613", "613"}, /* GS1 Algeria */
-   {"616", "616"}, /* GS1 Kenya */
-   {"618", "618"}, /* GS1 Ivory Coast */
-   {"619", "619"}, /* GS1 Tunisia */
-   {"621", "621"}, /* GS1 Syria */
-   {"622", "622"}, /* GS1 Egypt */
-   {"624", "624"}, /* GS1 Libya */
-   {"625", "625"}, /* GS1 Jordan */
-   {"626", "626"}, /* GS1 Iran */
-   {"627", "627"}, /* GS1 Kuwait */
-   {"628", "628"}, /* GS1 Saudi Arabia */
-   {"629", "629"}, /* GS1 Emirates */
-   {"640", "649"}, /* GS1 Finland */
-   {"690", "695"}, /* GS1 China */
-   {"700", "709"}, /* GS1 Norway */
-   {"729", "729"}, /* GS1 Israel */
-   {"730", "739"}, /* GS1 Sweden */
-   {"740", "740"}, /* GS1 Guatemala */
-   {"741", "741"}, /* GS1 El Salvador */
-   {"742", "742"}, /* GS1 Honduras */
-   {"743", "743"}, /* GS1 Nicaragua */
-   {"744", "744"}, /* GS1 Costa Rica */
-   {"745", "745"}, /* GS1 Panama */
-   {"746", "746"}, /* GS1 Republica Dominicana */
-   {"750", "750"}, /* GS1 Mexico */
-   {"754", "755"}, /* GS1 Canada */
-   {"759", "759"}, /* GS1 Venezuela */
-   {"760", "769"}, /* GS1 Schweiz, Suisse, Svizzera */
-   {"770", "770"}, /* GS1 Colombia */
-   {"773", "773"}, /* GS1 Uruguay */
-   {"775", "775"}, /* GS1 Peru */
-   {"777", "777"}, /* GS1 Bolivia */
-   {"779", "779"}, /* GS1 Argentina */
-   {"780", "780"}, /* GS1 Chile */
-   {"784", "784"}, /* GS1 Paraguay */
-   {"786", "786"}, /* GS1 Ecuador */
-   {"789", "790"}, /* GS1 Brasil */
-   {"800", "839"}, /* GS1 Italy */
-   {"840", "849"}, /* GS1 Spain */
-   {"850", "850"}, /* GS1 Cuba */
-   {"858", "858"}, /* GS1 Slovakia */
-   {"859", "859"}, /* GS1 Czech */
-   {"860", "860"}, /* GS1 YU (Serbia & Montenegro) */
-   {"865", "865"}, /* GS1 Mongolia */
-   {"867", "867"}, /* GS1 North Korea */
-   {"869", "869"}, /* GS1 Turkey */
-   {"870", "879"}, /* GS1 Netherlands */
-   {"880", "880"}, /* GS1 South Korea */
-   {"884", "884"}, /* GS1 Cambodia */
-   {"885", "885"}, /* GS1 Thailand */
-   {"888", "888"}, /* GS1 Singapore */
-   {"890", "890"}, /* GS1 India */
-   {"893", "893"}, /* GS1 Vietnam */
-   {"899", "899"}, /* GS1 Indonesia */
-   {"900", "919"}, /* GS1 Austria */
-   {"930", "939"}, /* GS1 Australia */
-   {"940", "949"}, /* GS1 New Zealand */
-   {"950", "950"}, /* GS1 Head Office */
-   {"955", "955"}, /* GS1 Malaysia */
-   {"958", "958"}, /* GS1 Macau */
-   {"977", "977"}, /* Serial publications (ISSN) */
-   {"978", "978"}, /* Bookland (ISBN) */
-   {"979", "979"}, /* International Standard Music Number (ISMN) and ISBN contingent */
-   {"980", "980"}, /* Refund receipts */
-   {"981", "982"}, /* Common Currency Coupons */
-   {"990", "999"}, /* Coupons */
+   {"000", "019"},             /* GS1 US */
+   {"020", "029"},             /* Restricted distribution (MO defined) */
+   {"030", "039"},             /* GS1 US */
+   {"040", "049"},             /* Restricted distribution (MO defined) */
+   {"050", "059"},             /* Coupons */
+   {"060", "099"},             /* GS1 US */
+   {"100", "139"},             /* GS1 US */
+   {"200", "299"},             /* Restricted distribution (MO defined) */
+   {"300", "379"},             /* GS1 France */
+   {"380", "380"},             /* GS1 Bulgaria */
+   {"383", "383"},             /* GS1 Slovenija */
+   {"385", "385"},             /* GS1 Croatia */
+   {"387", "387"},             /* GS1 BIH (Bosnia-Herzegovina) */
+   {"400", "440"},             /* GS1 Germany */
+   {"450", "459"},             /* GS1 Japan */
+   {"460", "469"},             /* GS1 Russia */
+   {"470", "470"},             /* GS1 Kyrgyzstan */
+   {"471", "471"},             /* GS1 Taiwan */
+   {"474", "474"},             /* GS1 Estonia */
+   {"475", "475"},             /* GS1 Latvia */
+   {"476", "476"},             /* GS1 Azerbaijan */
+   {"477", "477"},             /* GS1 Lithuania */
+   {"478", "478"},             /* GS1 Uzbekistan */
+   {"479", "479"},             /* GS1 Sri Lanka */
+   {"480", "480"},             /* GS1 Philippines */
+   {"481", "481"},             /* GS1 Belarus */
+   {"482", "482"},             /* GS1 Ukraine */
+   {"484", "484"},             /* GS1 Moldova */
+   {"485", "485"},             /* GS1 Armenia */
+   {"486", "486"},             /* GS1 Georgia */
+   {"487", "487"},             /* GS1 Kazakstan */
+   {"489", "489"},             /* GS1 Hong Kong */
+   {"490", "499"},             /* GS1 Japan */
+   {"500", "509"},             /* GS1 UK */
+   {"520", "520"},             /* GS1 Greece */
+   {"528", "528"},             /* GS1 Lebanon */
+   {"529", "529"},             /* GS1 Cyprus */
+   {"530", "530"},             /* GS1 Albania */
+   {"531", "531"},             /* GS1 MAC (FYR Macedonia) */
+   {"535", "535"},             /* GS1 Malta */
+   {"539", "539"},             /* GS1 Ireland */
+   {"540", "549"},             /* GS1 Belgium & Luxembourg */
+   {"560", "560"},             /* GS1 Portugal */
+   {"569", "569"},             /* GS1 Iceland */
+   {"570", "579"},             /* GS1 Denmark */
+   {"590", "590"},             /* GS1 Poland */
+   {"594", "594"},             /* GS1 Romania */
+   {"599", "599"},             /* GS1 Hungary */
+   {"600", "601"},             /* GS1 South Africa */
+   {"603", "603"},             /* GS1 Ghana */
+   {"608", "608"},             /* GS1 Bahrain */
+   {"609", "609"},             /* GS1 Mauritius */
+   {"611", "611"},             /* GS1 Morocco */
+   {"613", "613"},             /* GS1 Algeria */
+   {"616", "616"},             /* GS1 Kenya */
+   {"618", "618"},             /* GS1 Ivory Coast */
+   {"619", "619"},             /* GS1 Tunisia */
+   {"621", "621"},             /* GS1 Syria */
+   {"622", "622"},             /* GS1 Egypt */
+   {"624", "624"},             /* GS1 Libya */
+   {"625", "625"},             /* GS1 Jordan */
+   {"626", "626"},             /* GS1 Iran */
+   {"627", "627"},             /* GS1 Kuwait */
+   {"628", "628"},             /* GS1 Saudi Arabia */
+   {"629", "629"},             /* GS1 Emirates */
+   {"640", "649"},             /* GS1 Finland */
+   {"690", "695"},             /* GS1 China */
+   {"700", "709"},             /* GS1 Norway */
+   {"729", "729"},             /* GS1 Israel */
+   {"730", "739"},             /* GS1 Sweden */
+   {"740", "740"},             /* GS1 Guatemala */
+   {"741", "741"},             /* GS1 El Salvador */
+   {"742", "742"},             /* GS1 Honduras */
+   {"743", "743"},             /* GS1 Nicaragua */
+   {"744", "744"},             /* GS1 Costa Rica */
+   {"745", "745"},             /* GS1 Panama */
+   {"746", "746"},             /* GS1 Republica Dominicana */
+   {"750", "750"},             /* GS1 Mexico */
+   {"754", "755"},             /* GS1 Canada */
+   {"759", "759"},             /* GS1 Venezuela */
+   {"760", "769"},             /* GS1 Schweiz, Suisse, Svizzera */
+   {"770", "770"},             /* GS1 Colombia */
+   {"773", "773"},             /* GS1 Uruguay */
+   {"775", "775"},             /* GS1 Peru */
+   {"777", "777"},             /* GS1 Bolivia */
+   {"779", "779"},             /* GS1 Argentina */
+   {"780", "780"},             /* GS1 Chile */
+   {"784", "784"},             /* GS1 Paraguay */
+   {"786", "786"},             /* GS1 Ecuador */
+   {"789", "790"},             /* GS1 Brasil */
+   {"800", "839"},             /* GS1 Italy */
+   {"840", "849"},             /* GS1 Spain */
+   {"850", "850"},             /* GS1 Cuba */
+   {"858", "858"},             /* GS1 Slovakia */
+   {"859", "859"},             /* GS1 Czech */
+   {"860", "860"},             /* GS1 YU (Serbia & Montenegro) */
+   {"865", "865"},             /* GS1 Mongolia */
+   {"867", "867"},             /* GS1 North Korea */
+   {"869", "869"},             /* GS1 Turkey */
+   {"870", "879"},             /* GS1 Netherlands */
+   {"880", "880"},             /* GS1 South Korea */
+   {"884", "884"},             /* GS1 Cambodia */
+   {"885", "885"},             /* GS1 Thailand */
+   {"888", "888"},             /* GS1 Singapore */
+   {"890", "890"},             /* GS1 India */
+   {"893", "893"},             /* GS1 Vietnam */
+   {"899", "899"},             /* GS1 Indonesia */
+   {"900", "919"},             /* GS1 Austria */
+   {"930", "939"},             /* GS1 Australia */
+   {"940", "949"},             /* GS1 New Zealand */
+   {"950", "950"},             /* GS1 Head Office */
+   {"955", "955"},             /* GS1 Malaysia */
+   {"958", "958"},             /* GS1 Macau */
+   {"977", "977"},             /* Serial publications (ISSN) */
+   {"978", "978"},             /* Bookland (ISBN) */
+   {"979", "979"},             /* International Standard Music Number (ISMN)
+                                * and ISBN contingent */
+   {"980", "980"},             /* Refund receipts */
+   {"981", "982"},             /* Common Currency Coupons */
+   {"990", "999"},             /* Coupons */
    {NULL, NULL}
 };
index 0b23a95ccfbabe9b71ba3e206b2fee4159e12d15..26c84afe8013f432cce0cf8ef97c3e80ea612b05 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * ISBN.h
  *   PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
  *
@@ -7,39 +7,39 @@
  * http://www.isbn.org/
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/contrib/isn/ISBN.h,v 1.1 2006/09/09 04:07:52 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/isn/ISBN.h,v 1.2 2006/10/04 00:29:45 momjian Exp $
  *
  * 0-393-04002-X => 039304002(X) <=> 039304002 <=> (978)039304002 <=> 978039304002(9) <=> 978-0-393-04002-9
  *
  *
- * ISBN         0   3    9    3    0   4    0   0   2
- * Weight       10  9    8    7    6   5    4   3   2
- * Product      0 + 27 + 72 + 21 + 0 + 20 + 0 + 0 + 4 = 144
- *              144 / 11 = 13 remainder 1
- * Check digit  11 - 1 = 10 = X
+ * ISBN            0   3    9    3    0   4    0   0   2
+ * Weight      10  9    8    7    6   5    4   3   2
+ * Product     0 + 27 + 72 + 21 + 0 + 20 + 0 + 0 + 4 = 144
+ *             144 / 11 = 13 remainder 1
+ * Check digit 11 - 1 = 10 = X
  * => 0-393-04002-X
  *
- * ISBN         9   7    8   0   3   9    3   0   4   0   0   2
- * Weight       1   3    1   3   1   3    1   3   1   3   1   3
- * Product      9 + 21 + 8 + 0 + 3 + 27 + 3 + 0 + 4 + 0 + 0 + 6 = 81
- *              81 / 10 = 8 remainder 1
- * Check digit  10 - 1 = 9
+ * ISBN            9   7    8   0   3   9    3   0   4   0   0   2
+ * Weight      1   3    1   3   1   3    1   3   1   3   1   3
+ * Product     9 + 21 + 8 + 0 + 3 + 27 + 3 + 0 + 4 + 0 + 0 + 6 = 81
+ *             81 / 10 = 8 remainder 1
+ * Check digit 10 - 1 = 9
  * => 978-0-393-04002-9
  *
  */
 
 /* where the digit set begins, and how many of them are in the table */
 const unsigned ISBN_index[10][2] = {
-   {0,     6},
-   {6,     6},
-   {12,    8},
-   {20,    10},
-   {30,    6},
-   {36,    12},
-   {48,    0},
-   {48,    5},
-   {53,    59},
-   {112,   573},
+   {0, 6},
+   {6, 6},
+   {12, 8},
+   {20, 10},
+   {30, 6},
+   {36, 12},
+   {48, 0},
+   {48, 5},
+   {53, 59},
+   {112, 573},
 };
 
 const char *ISBN_range[][2] = {
index 0451d1942c740ced7b3230dfc4d29c6050aacadd..1d7b2af8fd7ab4052cdc873beab40be3e7c00b95 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * ISMN.h
  *   PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
  *
@@ -6,23 +6,23 @@
  * http://www.ismn-international.org
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/contrib/isn/ISMN.h,v 1.1 2006/09/09 04:07:52 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/isn/ISMN.h,v 1.2 2006/10/04 00:29:45 momjian Exp $
  *
  * M-3452-4680-5 <=> (0)-3452-4680-5 <=> 0345246805 <=> 9790345246805 <=> 979-0-3452-4680-5
  *
- *             (M counts as 3)
- * ISMN         M   3   4    5   2   4   6    8   0
- * Weight       3   1   3    1   3   1   3    1   3
- * Product      9 + 3 + 12 + 5 + 6 + 4 + 18 + 8 + 0 = 65
- *              65 / 10 = 6 remainder 5
- * Check digit  10 - 5 = 5 
+ *            (M counts as 3)
+ * ISMN            M   3   4    5   2   4   6    8   0
+ * Weight      3   1   3    1   3   1   3    1   3
+ * Product     9 + 3 + 12 + 5 + 6 + 4 + 18 + 8 + 0 = 65
+ *             65 / 10 = 6 remainder 5
+ * Check digit 10 - 5 = 5
  * => M-3452-4680-5
  *
- * ISMN         9   7    9   0   3   4    5   2   4   6    8   0
- * Weight       1   3    1   3   1   3    1   3   1   3    1   3
- * Product      9 + 21 + 9 + 0 + 3 + 12 + 5 + 6 + 4 + 18 + 8 + 0 = 95
- *              95 / 10 = 9 remainder 5
- * Check digit  10 - 5 = 5 
+ * ISMN            9   7    9   0   3   4    5   2   4   6    8   0
+ * Weight      1   3    1   3   1   3    1   3   1   3    1   3
+ * Product     9 + 21 + 9 + 0 + 3 + 12 + 5 + 6 + 4 + 18 + 8 + 0 = 95
+ *             95 / 10 = 9 remainder 5
+ * Check digit 10 - 5 = 5
  * => 979-0-3452-4680-5
  *
  * Since mod10(9*1 + 7*3 + 9*1 + 0*3) = mod10(M*3) = mod10(3*3) = 9; the check digit remains the same.
 
 /* where the digit set begins, and how many of them are in the table */
 const unsigned ISMN_index[10][2] = {
-   {0,     5},
-   {5,     0},
-   {5,     0},
-   {5,     0},
-   {5,     0},
-   {5,     0},
-   {5,     0},
-   {5,     0},
-   {5,     0},
-   {5,     0},
+   {0, 5},
+   {5, 0},
+   {5, 0},
+   {5, 0},
+   {5, 0},
+   {5, 0},
+   {5, 0},
+   {5, 0},
+   {5, 0},
+   {5, 0},
 };
 const char *ISMN_range[][2] = {
    {"0-000", "0-099"},
index aeafb0c3c7dceebd1fc83ffdf561d9dc421a6e4e..063a5d97f13394d9984eb882a751243ca68e1843 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * ISSN.h
  *   PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
  *
@@ -6,25 +6,25 @@
  * http://www.issn.org/
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/contrib/isn/ISSN.h,v 1.1 2006/09/09 04:07:52 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/isn/ISSN.h,v 1.2 2006/10/04 00:29:45 momjian Exp $
  *
  * 1144-875X <=> 1144875(X) <=> 1144875 <=> (977)1144875 <=> 9771144875(00) <=> 977114487500(7) <=> 977-1144-875-00-7
  *
- * 
- * ISSN         1   1   4    4    8    7    5
- * Weight       8   7   6    5    4    3    2 
- * Product      8 + 7 + 24 + 20 + 32 + 21 + 10 = 122
- *              122 / 11 = 11 remainder 1
- * Check digit  11 - 1 = 10 = X
+ *
+ * ISSN            1   1   4    4    8    7    5
+ * Weight      8   7   6    5    4    3    2
+ * Product     8 + 7 + 24 + 20 + 32 + 21 + 10 = 122
+ *             122 / 11 = 11 remainder 1
+ * Check digit 11 - 1 = 10 = X
  * => 1144-875X
- * 
- * ISSN         9   7    7   1   1   4    4   8    7   5    0   0
- * Weight       1   3    1   3   1   3    1   3    1   3    1   3
- * Product      9 + 21 + 7 + 3 + 1 + 12 + 4 + 24 + 7 + 15 + 0 + 0 = 103
- *              103 / 10 = 10 remainder 3
- * Check digit  10 - 3 = 7
+ *
+ * ISSN            9   7    7   1   1   4    4   8    7   5    0   0
+ * Weight      1   3    1   3   1   3    1   3    1   3    1   3
+ * Product     9 + 21 + 7 + 3 + 1 + 12 + 4 + 24 + 7 + 15 + 0 + 0 = 103
+ *             103 / 10 = 10 remainder 3
+ * Check digit 10 - 3 = 7
  * => 977-1144875-00-7 ??  <- suplemental number (number of the week, month, etc.)
- *                ^^ 00 for non-daily publications (01=Monday, 02=Tuesday, ...)
+ *               ^^ 00 for non-daily publications (01=Monday, 02=Tuesday, ...)
  *
  * The hyphenation is always in after the four digits of the ISSN code.
  *
 
 /* where the digit set begins, and how many of them are in the table */
 const unsigned ISSN_index[10][2] = {
-   {0,     1},
-   {0,     1},
-   {0,     1},
-   {0,     1},
-   {0,     1},
-   {0,     1},
-   {0,     1},
-   {0,     1},
-   {0,     1},
-   {0,     1},
+   {0, 1},
+   {0, 1},
+   {0, 1},
+   {0, 1},
+   {0, 1},
+   {0, 1},
+   {0, 1},
+   {0, 1},
+   {0, 1},
+   {0, 1},
 };
 const char *ISSN_range[][2] = {
    {"0000-000", "9999-999"},
index 2491fa3ee22801d26a5721d4f806abb07d38bf51..2b58a6b5660954353ba0306a63e0f67b55eb81de 100644 (file)
@@ -1,27 +1,27 @@
-/* 
+/*
  * ISSN.h
  *   PostgreSQL type definitions for ISNs (ISBN, ISMN, ISSN, EAN13, UPC)
  *
  * No information available for UPC prefixes
- * 
+ *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/contrib/isn/UPC.h,v 1.1 2006/09/09 04:07:52 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/isn/UPC.h,v 1.2 2006/10/04 00:29:45 momjian Exp $
  *
  */
 
 /* where the digit set begins, and how many of them are in the table */
 const unsigned UPC_index[10][2] = {
-   {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},
 };
 const char *UPC_range[][2] = {
    {NULL, NULL}
index 53e23228c9228a8728df54726ee5c745e163feba..cd4fd6c84ae29d6957e6adf24aed3d7dee4503f6 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.3 2006/09/22 21:39:57 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/isn/isn.c,v 1.4 2006/10/04 00:29:45 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -29,9 +29,12 @@ PG_MODULE_MAGIC;
 
 #define MAXEAN13LEN 18
 
-enum isn_type { INVALID, ANY, EAN13, ISBN, ISMN, ISSN, UPC };
+enum isn_type
+{
+   INVALID, ANY, EAN13, ISBN, ISMN, ISSN, UPC
+};
 
-static const char *isn_names[] = { "EAN13/UPC/ISxN", "EAN13/UPC/ISxN", "EAN13", "ISBN", "ISMN", "ISSN", "UPC" };
+static const char *isn_names[] = {"EAN13/UPC/ISxN", "EAN13/UPC/ISxN", "EAN13", "ISBN", "ISMN", "ISSN", "UPC"};
 
 static bool g_weak = false;
 static bool g_initialized = false;
@@ -46,8 +49,8 @@ static bool g_initialized = false;
  **        Routines for EAN13/UPC/ISxNs.
  **
  ** Note:
- **  In this code, a normalized string is one that is known to be a valid 
- **  ISxN number containing only digits and hyphens and with enough space 
+ **  In this code, a normalized string is one that is known to be a valid
+ **  ISxN number containing only digits and hyphens and with enough space
  **  to hold the full 13 digits plus the maximum of four hyphens.
  ***********************************************************************/
 
@@ -60,14 +63,25 @@ static bool g_initialized = false;
  */
 #ifdef ISN_DEBUG
 static
-bool check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
+bool
+check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
 {
-   const char *aux1, *aux2;
-   int a, b, x=0, y=-1, i=0, j, cnt=0, init=0;
-   
-   if(TABLE == NULL || TABLE_index == NULL) return true;
-
-   while(TABLE[i][0] && TABLE[i][1]) {
+   const char *aux1,
+              *aux2;
+   int         a,
+               b,
+               x = 0,
+               y = -1,
+               i = 0,
+               j,
+               cnt = 0,
+               init = 0;
+
+   if (TABLE == NULL || TABLE_index == NULL)
+       return true;
+
+   while (TABLE[i][0] && TABLE[i][1])
+   {
        aux1 = TABLE[i][0];
        aux2 = TABLE[i][1];
 
@@ -78,30 +92,37 @@ bool check_table(const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
        b = *aux2 - '0';
 
        /* must always have the same format and length: */
-       while(*aux1 && *aux2) {
+       while (*aux1 && *aux2)
+       {
            if (!(isdigit((unsigned char) *aux1) &&
                  isdigit((unsigned char) *aux2)) &&
-               (*aux1 != *aux2 || *aux1 != '-')) 
+               (*aux1 != *aux2 || *aux1 != '-'))
                goto invalidtable;
            aux1++;
            aux2++;
        }
-       if(*aux1!=*aux2) goto invalidtable;
+       if (*aux1 != *aux2)
+           goto invalidtable;
 
        /* found a new range */
-       if(a>y) {
+       if (a > y)
+       {
            /* check current range in the index: */
-           for(j=x;j<=y;j++) {
-               if(TABLE_index[j][0] != init) goto invalidindex;
-               if(TABLE_index[j][1] != i-init) goto invalidindex;
+           for (j = x; j <= y; j++)
+           {
+               if (TABLE_index[j][0] != init)
+                   goto invalidindex;
+               if (TABLE_index[j][1] != i - init)
+                   goto invalidindex;
            }
            init = i;
            x = a;
-       } 
+       }
 
        /* Always get the new limit */
        y = b;
-       if(y<x) goto invalidtable;
+       if (y < x)
+           goto invalidtable;
        i++;
    }
 
@@ -116,18 +137,22 @@ invalidindex:
    elog(DEBUG1, "index %d is invalid", j);
    return false;
 }
-#endif /* ISN_DEBUG */
+#endif   /* ISN_DEBUG */
 
 /*----------------------------------------------------------
  * Formatting and conversion routines.
  *---------------------------------------------------------*/
 
 static
-unsigned dehyphenate(char *bufO, char *bufI)
+unsigned
+dehyphenate(char *bufO, char *bufI)
 {
-   unsigned ret = 0;
-   while(*bufI) {
-       if(isdigit((unsigned char) *bufI)) {
+   unsigned    ret = 0;
+
+   while (*bufI)
+   {
+       if (isdigit((unsigned char) *bufI))
+       {
            *bufO++ = *bufI;
            ret++;
        }
@@ -138,29 +163,40 @@ unsigned dehyphenate(char *bufO, char *bufI)
 }
 
 /*
- * hyphenate --- Try to hyphenate, in-place, the string starting at bufI 
- *                into bufO using the given hyphenation range TABLE.
- *                Assumes the input string to be used is of only digits.
+ * hyphenate --- Try to hyphenate, in-place, the string starting at bufI
+ *               into bufO using the given hyphenation range TABLE.
+ *               Assumes the input string to be used is of only digits.
  *
  * Returns the number of characters acctually hyphenated.
  */
 static
-unsigned hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
+unsigned
+hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsigned TABLE_index[10][2])
 {
-   unsigned ret = 0;
-   const char *ean_aux1, *ean_aux2, *ean_p;
-   char *firstdig, *aux1, *aux2;
-   unsigned search, upper, lower, step;
-   bool ean_in1, ean_in2;
+   unsigned    ret = 0;
+   const char *ean_aux1,
+              *ean_aux2,
+              *ean_p;
+   char       *firstdig,
+              *aux1,
+              *aux2;
+   unsigned    search,
+               upper,
+               lower,
+               step;
+   bool        ean_in1,
+               ean_in2;
 
    /* just compress the string if no further hyphenation is required */
-   if(TABLE == NULL || TABLE_index == NULL) {
-       while(*bufI) {
+   if (TABLE == NULL || TABLE_index == NULL)
+   {
+       while (*bufI)
+       {
            *bufO++ = *bufI++;
            ret++;
        }
        *bufO = '\0';
-       return (ret+1);
+       return (ret + 1);
    }
 
    /* add remaining hyphenations */
@@ -171,26 +207,41 @@ unsigned hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsign
    lower--;
 
    step = (upper - lower) / 2;
-   if(step == 0) return 0;
+   if (step == 0)
+       return 0;
    search = lower + step;
 
    firstdig = bufI;
    ean_in1 = ean_in2 = false;
    ean_aux1 = TABLE[search][0];
    ean_aux2 = TABLE[search][1];
-   do {
-       if((ean_in1 || *firstdig>=*ean_aux1) && (ean_in2 || *firstdig<=*ean_aux2)) {
-           if(*firstdig > *ean_aux1) ean_in1 = true;
-           if(*firstdig < *ean_aux2) ean_in2 = true;
-           if(ean_in1 && ean_in2) break;
+   do
+   {
+       if ((ean_in1 || *firstdig >= *ean_aux1) && (ean_in2 || *firstdig <= *ean_aux2))
+       {
+           if (*firstdig > *ean_aux1)
+               ean_in1 = true;
+           if (*firstdig < *ean_aux2)
+               ean_in2 = true;
+           if (ean_in1 && ean_in2)
+               break;
 
            firstdig++, ean_aux1++, ean_aux2++;
-           if(!(*ean_aux1 && *ean_aux2 && *firstdig)) break;
-           if(!isdigit((unsigned char) *ean_aux1)) ean_aux1++, ean_aux2++;
-       } else {
-           /* check in what direction we should go and move the pointer accordingly */
-           if(*firstdig < *ean_aux1 && !ean_in1) upper = search;
-           else lower = search;
+           if (!(*ean_aux1 && *ean_aux2 && *firstdig))
+               break;
+           if (!isdigit((unsigned char) *ean_aux1))
+               ean_aux1++, ean_aux2++;
+       }
+       else
+       {
+           /*
+            * check in what direction we should go and move the pointer
+            * accordingly
+            */
+           if (*firstdig < *ean_aux1 && !ean_in1)
+               upper = search;
+           else
+               lower = search;
 
            step = (upper - lower) / 2;
            search = lower + step;
@@ -201,150 +252,189 @@ unsigned hyphenate(char *bufO, char *bufI, const char *(*TABLE)[2], const unsign
            ean_aux1 = TABLE[search][0];
            ean_aux2 = TABLE[search][1];
        }
-   } while(step);
-   
-   if(step) {
+   } while (step);
+
+   if (step)
+   {
        aux1 = bufO;
        aux2 = bufI;
        ean_p = TABLE[search][0];
-       while(*ean_p && *aux2) {
-           if(*ean_p++!='-') *aux1++ = *aux2++;
-           else *aux1++ = '-';
+       while (*ean_p && *aux2)
+       {
+           if (*ean_p++ != '-')
+               *aux1++ = *aux2++;
+           else
+               *aux1++ = '-';
            ret++;
        }
-       *aux1++='-';
-       *aux1 = *aux2; /* add a lookahead char */
-       return (ret+1);
+       *aux1++ = '-';
+       *aux1 = *aux2;          /* add a lookahead char */
+       return (ret + 1);
    }
    return ret;
 }
 
 /*
- * weight_checkdig -- Receives a buffer with a normalized ISxN string number, 
- *                     and the length to weight.
+ * weight_checkdig -- Receives a buffer with a normalized ISxN string number,
+ *                    and the length to weight.
  *
  * Returns the weight of the number (the check digit value, 0-10)
  */
 static
-unsigned weight_checkdig(char *isn, unsigned size)
+unsigned
+weight_checkdig(char *isn, unsigned size)
 {
-   unsigned weight = 0;
-   while(*isn && size>1) {
-       if(isdigit((unsigned char) *isn)) {
+   unsigned    weight = 0;
+
+   while (*isn && size > 1)
+   {
+       if (isdigit((unsigned char) *isn))
+       {
            weight += size-- * (*isn - '0');
        }
        isn++;
    }
    weight = weight % 11;
-   if(weight != 0) weight = 11 - weight;
+   if (weight != 0)
+       weight = 11 - weight;
    return weight;
 }
 
 
 /*
- * checkdig --- Receives a buffer with a normalized ISxN string number, 
- *               and the length to check.
+ * checkdig --- Receives a buffer with a normalized ISxN string number,
+ *              and the length to check.
  *
  * Returns the check digit value (0-9)
  */
 static
-unsigned checkdig(char *num, unsigned size)
+unsigned
+checkdig(char *num, unsigned size)
 {
-   unsigned check=0, check3=0;
-   unsigned pos = 0;
-   if(*num == 'M') { /* ISMN start with 'M' */
+   unsigned    check = 0,
+               check3 = 0;
+   unsigned    pos = 0;
+
+   if (*num == 'M')
+   {                           /* ISMN start with 'M' */
        check3 = 3;
        pos = 1;
    }
-   while(*num && size>1) {
-       if(isdigit((unsigned char) *num)) {
-           if(pos++%2) check3 += *num - '0';
-           else check += *num - '0';
+   while (*num && size > 1)
+   {
+       if (isdigit((unsigned char) *num))
+       {
+           if (pos++ % 2)
+               check3 += *num - '0';
+           else
+               check += *num - '0';
            size--;
        }
        num++;
    }
-   check = (check + 3*check3) % 10;
-   if(check != 0) check = 10 - check;
+   check = (check + 3 * check3) % 10;
+   if (check != 0)
+       check = 10 - check;
    return check;
 }
 
 /*
  * ean2isn --- Try to convert an ean13 number to a UPC/ISxN number.
- *             This doesn't verify for a valid check digit.
+ *            This doesn't verify for a valid check digit.
  *
  * If errorOK is false, ereport a useful error message if the ean13 is bad.
  * If errorOK is true, just return "false" for bad input.
  */
 static
-bool ean2isn(ean13 ean, bool errorOK, ean13 *result, enum isn_type accept)
+bool
+ean2isn(ean13 ean, bool errorOK, ean13 * result, enum isn_type accept)
 {
    enum isn_type type = INVALID;
 
-   char buf[MAXEAN13LEN + 1];
-   char *firstdig, *aux;
-   unsigned digval;
-   unsigned search;
-   ean13 ret = ean;
-   
+   char        buf[MAXEAN13LEN + 1];
+   char       *firstdig,
+              *aux;
+   unsigned    digval;
+   unsigned    search;
+   ean13       ret = ean;
+
    ean >>= 1;
    /* verify it's in the EAN13 range */
-   if(ean > UINT64CONST(9999999999999))
+   if (ean > UINT64CONST(9999999999999))
        goto eantoobig;
 
    /* convert the number */
    search = 0;
    firstdig = aux = buf + 13;
-   *aux = '\0';        /* terminate string; aux points to last digit */
-   do {
-       digval = (unsigned)(ean % 10);      /* get the decimal value */ 
-       ean /= 10;                                              /* get next digit */
-       *--aux = (char)(digval + '0');          /* convert to ascii and store */
-   } while(ean && search++<12);
-   while(search++<12) *--aux = '0';            /* fill the remaining EAN13 with '0' */
-   
+   *aux = '\0';                /* terminate string; aux points to last digit */
+   do
+   {
+       digval = (unsigned) (ean % 10); /* get the decimal value */
+       ean /= 10;              /* get next digit */
+       *--aux = (char) (digval + '0'); /* convert to ascii and store */
+   } while (ean && search++ < 12);
+   while (search++ < 12)
+       *--aux = '0';           /* fill the remaining EAN13 with '0' */
+
    /* find out the data type: */
-   if(!strncmp("978", buf, 3)) { /* ISBN */
+   if (!strncmp("978", buf, 3))
+   {                           /* ISBN */
        type = ISBN;
-   } else if(!strncmp("977", buf, 3)) { /* ISSN */
+   }
+   else if (!strncmp("977", buf, 3))
+   {                           /* ISSN */
        type = ISSN;
-   } else if(!strncmp("9790", buf, 4)) { /* ISMN */
+   }
+   else if (!strncmp("9790", buf, 4))
+   {                           /* ISMN */
        type = ISMN;
-   } else if(!strncmp("979", buf, 3)) { /* ISBN-13 */
+   }
+   else if (!strncmp("979", buf, 3))
+   {                           /* ISBN-13 */
        type = ISBN;
-   } else if(*buf == '0') { /* UPC */
+   }
+   else if (*buf == '0')
+   {                           /* UPC */
        type = UPC;
-   } else {
+   }
+   else
+   {
        type = EAN13;
    }
-   if(accept != ANY && accept != EAN13 && accept != type) goto eanwrongtype;
+   if (accept != ANY && accept != EAN13 && accept != type)
+       goto eanwrongtype;
 
    *result = ret;
    return true;
-   
+
 eanwrongtype:
-   if(!errorOK) {
-       if(type!=EAN13) {
+   if (!errorOK)
+   {
+       if (type != EAN13)
+       {
            ereport(ERROR,
-               (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                errmsg("cannot cast EAN13(%s) to %s for number: \"%s\"",
-                       isn_names[type], isn_names[accept], buf)));
-       } else {
+                   (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+                    errmsg("cannot cast EAN13(%s) to %s for number: \"%s\"",
+                           isn_names[type], isn_names[accept], buf)));
+       }
+       else
+       {
            ereport(ERROR,
-               (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                errmsg("cannot cast %s to %s for number: \"%s\"",
-                       isn_names[type], isn_names[accept], buf)));
+                   (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
+                    errmsg("cannot cast %s to %s for number: \"%s\"",
+                           isn_names[type], isn_names[accept], buf)));
        }
    }
    return false;
 
 eantoobig:
-   if(!errorOK) {
-       char    eanbuf[64];
+   if (!errorOK)
+   {
+       char        eanbuf[64];
 
        /*
-        * Format the number separately to keep the machine-dependent
-        * format code out of the translatable message text
+        * Format the number separately to keep the machine-dependent format
+        * code out of the translatable message text
         */
        snprintf(eanbuf, sizeof(eanbuf), EAN13_FORMAT, ean);
        ereport(ERROR,
@@ -356,144 +446,176 @@ eantoobig:
 }
 
 /*
- * ean2UPC/ISxN --- Convert in-place a normalized EAN13 string to the corresponding 
- *                  UPC/ISxN string number. Assumes the input string is normalized.
+ * ean2UPC/ISxN --- Convert in-place a normalized EAN13 string to the corresponding
+ *                 UPC/ISxN string number. Assumes the input string is normalized.
  */
 static inline
-void ean2ISBN(char *isn)
+void
+ean2ISBN(char *isn)
 {
-   char *aux;
-   unsigned check;
+   char       *aux;
+   unsigned    check;
+
    /* the number should come in this format: 978-0-000-00000-0 */
    /* Strip the first part and calculate the new check digit */
-   hyphenate(isn, isn+4, NULL, NULL);
+   hyphenate(isn, isn + 4, NULL, NULL);
    check = weight_checkdig(isn, 10);
    aux = strchr(isn, '\0');
-   while(!isdigit((unsigned char) *--aux));
-   if(check == 10) *aux = 'X';
-   else *aux = check + '0';
+   while (!isdigit((unsigned char) *--aux));
+   if (check == 10)
+       *aux = 'X';
+   else
+       *aux = check + '0';
 }
 static inline
-void ean2ISMN(char *isn)
+void
+ean2ISMN(char *isn)
 {
    /* the number should come in this format: 979-0-000-00000-0 */
    /* Just strip the first part and change the first digit ('0') to 'M' */
-   hyphenate(isn, isn+4, NULL, NULL);
+   hyphenate(isn, isn + 4, NULL, NULL);
    isn[0] = 'M';
 }
 static inline
-void ean2ISSN(char *isn)
+void
+ean2ISSN(char *isn)
 {
-   unsigned check;
+   unsigned    check;
+
    /* the number should come in this format: 977-0000-000-00-0 */
    /* Strip the first part, crop, and calculate the new check digit */
-   hyphenate(isn, isn+4, NULL, NULL);
+   hyphenate(isn, isn + 4, NULL, NULL);
    check = weight_checkdig(isn, 8);
-   if(check == 10) isn[8] = 'X';
-   else isn[8] = check + '0';
+   if (check == 10)
+       isn[8] = 'X';
+   else
+       isn[8] = check + '0';
    isn[9] = '\0';
 }
 static inline
-void ean2UPC(char *isn)
+void
+ean2UPC(char *isn)
 {
    /* the number should come in this format: 000-000000000-0 */
    /* Strip the first part, crop, and dehyphenate */
-   dehyphenate(isn, isn+1);
+   dehyphenate(isn, isn + 1);
    isn[12] = '\0';
 }
 
 /*
  * ean2* --- Converts a string of digits into an ean13 number.
- *            Assumes the input string is a string with only digits 
- *            on it, and that it's within the range of ean13.
+ *           Assumes the input string is a string with only digits
+ *           on it, and that it's within the range of ean13.
  *
  * Returns the ean13 value of the string.
  */
 static
-ean13 str2ean(const char *num) 
+ean13
+str2ean(const char *num)
 {
-   ean13 ean = 0;  /* current ean */
-   while(*num) {
-       if(isdigit((unsigned char) *num)) ean = 10 * ean + (*num - '0');
+   ean13       ean = 0;        /* current ean */
+
+   while (*num)
+   {
+       if (isdigit((unsigned char) *num))
+           ean = 10 * ean + (*num - '0');
        num++;
    }
-    return (ean<<1); /* also give room to a flag */
+   return (ean << 1);          /* also give room to a flag */
 }
 
 /*
  * ean2string --- Try to convert an ean13 number to an hyphenated string.
- *                Assumes there's enough space in result to hold
- *                the string (maximum MAXEAN13LEN+1 bytes)
- *                This doesn't verify for a valid check digit.
+ *               Assumes there's enough space in result to hold
+ *               the string (maximum MAXEAN13LEN+1 bytes)
+ *               This doesn't verify for a valid check digit.
  *
  * If shortType is true, the returned string is in the old ISxN short format.
  * If errorOK is false, ereport a useful error message if the string is bad.
  * If errorOK is true, just return "false" for bad input.
  */
 static
-bool ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
+bool
+ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
 {
    const char *(*TABLE)[2];
    const unsigned (*TABLE_index)[2];
    enum isn_type type = INVALID;
 
-   char *firstdig, *aux;
-   unsigned digval;
-   unsigned search;
-   char valid = '\0';              /* was the number initially written with a valid check digit? */
+   char       *firstdig,
+              *aux;
+   unsigned    digval;
+   unsigned    search;
+   char        valid = '\0';   /* was the number initially written with a
+                                * valid check digit? */
 
    TABLE_index = ISBN_index;
 
-   if((ean & 1)!=0) valid = '!';
+   if ((ean & 1) != 0)
+       valid = '!';
    ean >>= 1;
    /* verify it's in the EAN13 range */
-   if(ean > UINT64CONST(9999999999999))
+   if (ean > UINT64CONST(9999999999999))
        goto eantoobig;
 
    /* convert the number */
    search = 0;
    firstdig = aux = result + MAXEAN13LEN;
-   *aux = '\0';        /* terminate string; aux points to last digit */
-   *--aux = valid;     /* append '!' for numbers with invalid but corrected check digit */
-   do {
-       digval = (unsigned)(ean % 10);      /* get the decimal value */ 
-       ean /= 10;                                              /* get next digit */
-       *--aux = (char)(digval + '0');          /* convert to ascii and store */
-       if(search == 0) *--aux = '-';           /* the check digit is always there */
-   } while(ean && search++<13);
-   while(search++<13) *--aux = '0';            /* fill the remaining EAN13 with '0' */
+   *aux = '\0';                /* terminate string; aux points to last digit */
+   *--aux = valid;             /* append '!' for numbers with invalid but
+                                * corrected check digit */
+   do
+   {
+       digval = (unsigned) (ean % 10); /* get the decimal value */
+       ean /= 10;              /* get next digit */
+       *--aux = (char) (digval + '0'); /* convert to ascii and store */
+       if (search == 0)
+           *--aux = '-';       /* the check digit is always there */
+   } while (ean && search++ < 13);
+   while (search++ < 13)
+       *--aux = '0';           /* fill the remaining EAN13 with '0' */
 
    /* The string should be in this form: ???DDDDDDDDDDDD-D" */
-   search = hyphenate(result, result+3, EAN13_range, EAN13_index);
-   
+   search = hyphenate(result, result + 3, EAN13_range, EAN13_index);
+
    /* verify it's a logically valid EAN13 */
-   if(search == 0) {
-       search = hyphenate(result, result+3, NULL, NULL);
+   if (search == 0)
+   {
+       search = hyphenate(result, result + 3, NULL, NULL);
        goto okay;
    }
 
    /* find out what type of hyphenation is needed: */
-   if(!strncmp("978-", result, search)) { /* ISBN */
+   if (!strncmp("978-", result, search))
+   {                           /* ISBN */
        /* The string should be in this form: 978-??000000000-0" */
        type = ISBN;
        TABLE = ISBN_range;
        TABLE_index = ISBN_index;
-   } else if(!strncmp("977-", result, search)) { /* ISSN */
+   }
+   else if (!strncmp("977-", result, search))
+   {                           /* ISSN */
        /* The string should be in this form: 977-??000000000-0" */
        type = ISSN;
        TABLE = ISSN_range;
        TABLE_index = ISSN_index;
-   } else if(!strncmp("979-0", result, search+1)) { /* ISMN */
+   }
+   else if (!strncmp("979-0", result, search + 1))
+   {                           /* ISMN */
        /* The string should be in this form: 979-0?000000000-0" */
        type = ISMN;
        TABLE = ISMN_range;
        TABLE_index = ISMN_index;
-   } else if(*result == '0') { /* UPC */
+   }
+   else if (*result == '0')
+   {                           /* UPC */
        /* The string should be in this form: 000-00000000000-0" */
        type = UPC;
        TABLE = UPC_range;
        TABLE_index = UPC_index;
-   } else {
+   }
+   else
+   {
        type = EAN13;
        TABLE = NULL;
        TABLE_index = NULL;
@@ -501,18 +623,20 @@ bool ean2string(ean13 ean, bool errorOK, char *result, bool shortType)
 
    /* verify it's a logically valid EAN13/UPC/ISxN */
    digval = search;
-   search = hyphenate(result+digval, result+digval+2, TABLE, TABLE_index);
+   search = hyphenate(result + digval, result + digval + 2, TABLE, TABLE_index);
 
    /* verify it's a valid EAN13 */
-   if(search == 0) {
-       search = hyphenate(result+digval, result+digval+2, NULL, NULL);
+   if (search == 0)
+   {
+       search = hyphenate(result + digval, result + digval + 2, NULL, NULL);
        goto okay;
    }
 
 okay:
    /* convert to the old short type: */
-   if(shortType) 
-       switch(type) {
+   if (shortType)
+       switch (type)
+       {
            case ISBN:
                ean2ISBN(result);
                break;
@@ -531,13 +655,13 @@ okay:
    return true;
 
 eantoobig:
-   if(!errorOK)
+   if (!errorOK)
    {
-       char    eanbuf[64];
+       char        eanbuf[64];
 
        /*
-        * Format the number separately to keep the machine-dependent
-        * format code out of the translatable message text
+        * Format the number separately to keep the machine-dependent format
+        * code out of the translatable message text
         */
        snprintf(eanbuf, sizeof(eanbuf), EAN13_FORMAT, ean);
        ereport(ERROR,
@@ -558,157 +682,222 @@ eantoobig:
  * (even if the check digit is valid)
  */
 static
-bool string2ean(const char *str, bool errorOK, ean13 *result,
-               enum isn_type accept)
+bool
+string2ean(const char *str, bool errorOK, ean13 * result,
+          enum isn_type accept)
 {
-   bool digit, last;
-   char buf[17] = "                ";
-   char *aux1 = buf + 3; /* leave space for the first part, in case it's needed */
+   bool        digit,
+               last;
+   char        buf[17] = "                ";
+   char       *aux1 = buf + 3; /* leave space for the first part, in case
+                                * it's needed */
    const char *aux2 = str;
    enum isn_type type = INVALID;
-   unsigned check = 0, rcheck = (unsigned)-1;
-   unsigned length = 0;
-   bool magic = false, valid = true;
+   unsigned    check = 0,
+               rcheck = (unsigned) -1;
+   unsigned    length = 0;
+   bool        magic = false,
+               valid = true;
 
    /* recognize and validate the number: */
-   while(*aux2 && length <= 13) {
-       last = (*(aux2+1) == '!' || *(aux2+1) == '\0'); /* is the last character */
-       digit = (isdigit((unsigned char) *aux2)!=0); /* is current character a digit? */
-       if(*aux2=='?' && last) /* automagically calculate check digit if it's '?' */
+   while (*aux2 && length <= 13)
+   {
+       last = (*(aux2 + 1) == '!' || *(aux2 + 1) == '\0');     /* is the last character */
+       digit = (isdigit((unsigned char) *aux2) != 0);  /* is current character
+                                                        * a digit? */
+       if (*aux2 == '?' && last)       /* automagically calculate check digit
+                                        * if it's '?' */
            magic = digit = true;
-       if(length == 0 &&  (*aux2=='M' || *aux2=='m')) {
+       if (length == 0 && (*aux2 == 'M' || *aux2 == 'm'))
+       {
            /* only ISMN can be here */
-           if(type != INVALID) goto eaninvalid;
+           if (type != INVALID)
+               goto eaninvalid;
            type = ISMN;
            *aux1++ = 'M';
            length++;
-       } else if(length == 7 && (digit || *aux2=='X' || *aux2=='x') && last) {
+       }
+       else if (length == 7 && (digit || *aux2 == 'X' || *aux2 == 'x') && last)
+       {
            /* only ISSN can be here */
-           if(type != INVALID) goto eaninvalid;
+           if (type != INVALID)
+               goto eaninvalid;
            type = ISSN;
            *aux1++ = toupper((unsigned char) *aux2);
            length++;
-       } else if(length == 9 && (digit || *aux2=='X' || *aux2=='x') && last) {
+       }
+       else if (length == 9 && (digit || *aux2 == 'X' || *aux2 == 'x') && last)
+       {
            /* only ISBN and ISMN can be here */
-           if(type != INVALID && type != ISMN) goto eaninvalid;
-           if(type == INVALID) type = ISBN; /* ISMN must start with 'M' */
+           if (type != INVALID && type != ISMN)
+               goto eaninvalid;
+           if (type == INVALID)
+               type = ISBN;    /* ISMN must start with 'M' */
            *aux1++ = toupper((unsigned char) *aux2);
            length++;
-       } else if(length == 11 && digit && last) {
+       }
+       else if (length == 11 && digit && last)
+       {
            /* only UPC can be here */
-           if(type != INVALID) goto eaninvalid;
+           if (type != INVALID)
+               goto eaninvalid;
            type = UPC;
            *aux1++ = *aux2;
            length++;
-       } else if(*aux2 == '-' || *aux2 == ' ') {
+       }
+       else if (*aux2 == '-' || *aux2 == ' ')
+       {
            /* skip, we could validate but I think it's worthless */
-       } else if(*aux2 == '!' && *(aux2+1) == '\0') {
+       }
+       else if (*aux2 == '!' && *(aux2 + 1) == '\0')
+       {
            /* the invalid check digit sufix was found, set it */
-           if(!magic) valid = false;
+           if (!magic)
+               valid = false;
            magic = true;
-       } else if(!digit) {
+       }
+       else if (!digit)
+       {
            goto eaninvalid;
-       } else {
+       }
+       else
+       {
            *aux1++ = *aux2;
-           if(++length > 13) goto eantoobig;
+           if (++length > 13)
+               goto eantoobig;
        }
        aux2++;
    }
-   *aux1 = '\0'; /* terminate the string */
+   *aux1 = '\0';               /* terminate the string */
 
    /* find the current check digit value */
-   if(length == 13) {
+   if (length == 13)
+   {
        /* only EAN13 can be here */
-       if(type != INVALID) goto eaninvalid;
+       if (type != INVALID)
+           goto eaninvalid;
        type = EAN13;
-       check = buf[15]-'0';
-   } else if(length == 12) {
+       check = buf[15] - '0';
+   }
+   else if (length == 12)
+   {
        /* only UPC can be here */
-       if(type != UPC) goto eaninvalid;
-       check = buf[14]-'0';
-   } else if(length == 10) {
-       if(type != ISBN && type != ISMN) goto eaninvalid;
-       if(buf[12] == 'X') check = 10;
-       else check = buf[12]-'0';
-   } else if(length == 8) {
-       if(type != INVALID && type != ISSN) goto eaninvalid;
+       if (type != UPC)
+           goto eaninvalid;
+       check = buf[14] - '0';
+   }
+   else if (length == 10)
+   {
+       if (type != ISBN && type != ISMN)
+           goto eaninvalid;
+       if (buf[12] == 'X')
+           check = 10;
+       else
+           check = buf[12] - '0';
+   }
+   else if (length == 8)
+   {
+       if (type != INVALID && type != ISSN)
+           goto eaninvalid;
        type = ISSN;
-       if(buf[10] == 'X') check = 10;
-       else check = buf[10]-'0';
-   } else goto eaninvalid;
-
-   if(type == INVALID) goto eaninvalid;
-
-   /* obtain the real check digit value, validate, and convert to ean13: */ 
-   if(accept == EAN13 && type != accept) goto eanwrongtype;
-   if(accept != ANY && type != EAN13 && type != accept) goto eanwrongtype;
-   switch(type) {
+       if (buf[10] == 'X')
+           check = 10;
+       else
+           check = buf[10] - '0';
+   }
+   else
+       goto eaninvalid;
+
+   if (type == INVALID)
+       goto eaninvalid;
+
+   /* obtain the real check digit value, validate, and convert to ean13: */
+   if (accept == EAN13 && type != accept)
+       goto eanwrongtype;
+   if (accept != ANY && type != EAN13 && type != accept)
+       goto eanwrongtype;
+   switch (type)
+   {
        case EAN13:
-           valid = (valid && ((rcheck=checkdig(buf+3, 13)) == check || magic));
+           valid = (valid && ((rcheck = checkdig(buf + 3, 13)) == check || magic));
            /* now get the subtype of EAN13: */
-           if(buf[3] == '0') type = UPC;
-           else if(!strncmp("977", buf+3, 3)) type = ISSN;
-           else if(!strncmp("978", buf+3, 3)) type = ISBN;
-           else if(!strncmp("9790", buf+3, 4)) type = ISMN;
-           else if(!strncmp("979", buf+3, 3)) type = ISBN;
-           if(accept != EAN13 && accept != ANY && type != accept) goto eanwrongtype;
+           if (buf[3] == '0')
+               type = UPC;
+           else if (!strncmp("977", buf + 3, 3))
+               type = ISSN;
+           else if (!strncmp("978", buf + 3, 3))
+               type = ISBN;
+           else if (!strncmp("9790", buf + 3, 4))
+               type = ISMN;
+           else if (!strncmp("979", buf + 3, 3))
+               type = ISBN;
+           if (accept != EAN13 && accept != ANY && type != accept)
+               goto eanwrongtype;
            break;
        case ISMN:
-           strncpy(buf, "9790", 4);  /* this isn't for sure yet, for now ISMN it's only 9790 */
-           valid = (valid && ((rcheck=checkdig(buf+3, 10)) == check || magic));
+           strncpy(buf, "9790", 4);    /* this isn't for sure yet, for now
+                                        * ISMN it's only 9790 */
+           valid = (valid && ((rcheck = checkdig(buf + 3, 10)) == check || magic));
            break;
        case ISBN:
            strncpy(buf, "978", 3);
-           valid = (valid && ((rcheck=weight_checkdig(buf+3, 10)) == check || magic));
+           valid = (valid && ((rcheck = weight_checkdig(buf + 3, 10)) == check || magic));
            break;
        case ISSN:
-           strncpy(buf+10, "00", 2); /* append 00 as the normal issue publication code */
+           strncpy(buf + 10, "00", 2); /* append 00 as the normal issue
+                                        * publication code */
            strncpy(buf, "977", 3);
-           valid = (valid && ((rcheck=weight_checkdig(buf+3, 8)) == check || magic));
+           valid = (valid && ((rcheck = weight_checkdig(buf + 3, 8)) == check || magic));
            break;
        case UPC:
            buf[2] = '0';
-           valid = (valid && ((rcheck=checkdig(buf+2, 13)) == check || magic));
+           valid = (valid && ((rcheck = checkdig(buf + 2, 13)) == check || magic));
        default:
            break;
    }
 
-  /* fix the check digit: */
-   for(aux1 = buf; *aux1 && *aux1 <= ' '; aux1++);
+   /* fix the check digit: */
+   for (aux1 = buf; *aux1 && *aux1 <= ' '; aux1++);
    aux1[12] = checkdig(aux1, 13) + '0';
    aux1[13] = '\0';
-   
-   if(!valid && !magic) goto eanbadcheck;
+
+   if (!valid && !magic)
+       goto eanbadcheck;
 
    *result = str2ean(aux1);
-   *result |= valid?0:1;
+   *result |= valid ? 0 : 1;
    return true;
 
-eanbadcheck: 
-   if(g_weak) { /* weak input mode is activated: */
-     /* set the "invalid-check-digit-on-input" flag */ 
+eanbadcheck:
+   if (g_weak)
+   {                           /* weak input mode is activated: */
+       /* set the "invalid-check-digit-on-input" flag */
        *result = str2ean(aux1);
        *result |= 1;
-   return true;
+       return true;
    }
 
-       if(!errorOK) {
-           if(rcheck == (unsigned)-1) {
-               ereport(ERROR,
+   if (!errorOK)
+   {
+       if (rcheck == (unsigned) -1)
+       {
+           ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                   errmsg("invalid %s number: \"%s\"",
+                    errmsg("invalid %s number: \"%s\"",
                            isn_names[accept], str)));
-           } else {
-               ereport(ERROR,
+       }
+       else
+       {
+           ereport(ERROR,
                    (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
-                   errmsg("invalid check digit for %s number: \"%s\", should be %c",
-                           isn_names[accept], str, (rcheck==10)?('X'):(rcheck+'0'))));
-           }
+           errmsg("invalid check digit for %s number: \"%s\", should be %c",
+                  isn_names[accept], str, (rcheck == 10) ? ('X') : (rcheck + '0'))));
        }
-       return false;
+   }
+   return false;
 
 eaninvalid:
-   if(!errorOK)
+   if (!errorOK)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("invalid input syntax for %s number: \"%s\"",
@@ -716,7 +905,7 @@ eaninvalid:
    return false;
 
 eanwrongtype:
-   if(!errorOK)
+   if (!errorOK)
        ereport(ERROR,
                (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
                 errmsg("cannot cast %s to %s for number: \"%s\"",
@@ -724,11 +913,11 @@ eanwrongtype:
    return false;
 
 eantoobig:
-   if(!errorOK)
+   if (!errorOK)
        ereport(ERROR,
-           (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
-            errmsg("value \"%s\" is out of range for %s type",
-                   str, isn_names[accept])));
+               (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
+                errmsg("value \"%s\" is out of range for %s type",
+                       str, isn_names[accept])));
    return false;
 }
 
@@ -736,18 +925,19 @@ eantoobig:
  * Exported routines.
  *---------------------------------------------------------*/
 
-void initialize(void)
+void
+initialize(void)
 {
 #ifdef ISN_DEBUG
-   if(!check_table(EAN13, EAN13_index))
+   if (!check_table(EAN13, EAN13_index))
        elog(LOG, "EAN13 failed check");
-   if(!check_table(ISBN, ISBN_index))
+   if (!check_table(ISBN, ISBN_index))
        elog(LOG, "ISBN failed check");
-   if(!check_table(ISMN, ISMN_index))
+   if (!check_table(ISMN, ISMN_index))
        elog(LOG, "ISMN failed check");
-   if(!check_table(ISSN, ISSN_index))
+   if (!check_table(ISSN, ISSN_index))
        elog(LOG, "ISSN failed check");
-   if(!check_table(UPC, UPC_index))
+   if (!check_table(UPC, UPC_index))
        elog(LOG, "UPC failed check");
 #endif
    g_initialized = true;
@@ -791,7 +981,7 @@ PG_FUNCTION_INFO_V1(ean13_in);
 Datum
 ean13_in(PG_FUNCTION_ARGS)
 {
-   const char  *str = PG_GETARG_CSTRING(0);
+   const char *str = PG_GETARG_CSTRING(0);
    ean13       result;
 
    (void) string2ean(str, false, &result, EAN13);
@@ -804,7 +994,7 @@ PG_FUNCTION_INFO_V1(isbn_in);
 Datum
 isbn_in(PG_FUNCTION_ARGS)
 {
-   const char  *str = PG_GETARG_CSTRING(0);
+   const char *str = PG_GETARG_CSTRING(0);
    ean13       result;
 
    (void) string2ean(str, false, &result, ISBN);
@@ -817,7 +1007,7 @@ PG_FUNCTION_INFO_V1(ismn_in);
 Datum
 ismn_in(PG_FUNCTION_ARGS)
 {
-   const char  *str = PG_GETARG_CSTRING(0);
+   const char *str = PG_GETARG_CSTRING(0);
    ean13       result;
 
    (void) string2ean(str, false, &result, ISMN);
@@ -830,7 +1020,7 @@ PG_FUNCTION_INFO_V1(issn_in);
 Datum
 issn_in(PG_FUNCTION_ARGS)
 {
-   const char  *str = PG_GETARG_CSTRING(0);
+   const char *str = PG_GETARG_CSTRING(0);
    ean13       result;
 
    (void) string2ean(str, false, &result, ISSN);
@@ -843,7 +1033,7 @@ PG_FUNCTION_INFO_V1(upc_in);
 Datum
 upc_in(PG_FUNCTION_ARGS)
 {
-   const char  *str = PG_GETARG_CSTRING(0);
+   const char *str = PG_GETARG_CSTRING(0);
    ean13       result;
 
    (void) string2ean(str, false, &result, UPC);
@@ -861,7 +1051,7 @@ ean13_cast_to_text(PG_FUNCTION_ARGS)
 
    (void) ean2string(val, false, buf, false);
 
-    PG_RETURN_TEXT_P(GET_TEXT(buf));
+   PG_RETURN_TEXT_P(GET_TEXT(buf));
 }
 
 PG_FUNCTION_INFO_V1(isn_cast_to_text);
@@ -873,7 +1063,7 @@ isn_cast_to_text(PG_FUNCTION_ARGS)
 
    (void) ean2string(val, false, buf, true);
 
-    PG_RETURN_TEXT_P(GET_TEXT(buf));
+   PG_RETURN_TEXT_P(GET_TEXT(buf));
 }
 
 PG_FUNCTION_INFO_V1(isbn_cast_from_ean13);
@@ -929,7 +1119,7 @@ PG_FUNCTION_INFO_V1(ean13_cast_from_text);
 Datum
 ean13_cast_from_text(PG_FUNCTION_ARGS)
 {
-   const char  *str = GET_STR(PG_GETARG_TEXT_P(0));
+   const char *str = GET_STR(PG_GETARG_TEXT_P(0));
    ean13       result;
 
    (void) string2ean(str, false, &result, EAN13);
@@ -940,7 +1130,7 @@ PG_FUNCTION_INFO_V1(isbn_cast_from_text);
 Datum
 isbn_cast_from_text(PG_FUNCTION_ARGS)
 {
-   const char  *str = GET_STR(PG_GETARG_TEXT_P(0));
+   const char *str = GET_STR(PG_GETARG_TEXT_P(0));
    ean13       result;
 
    (void) string2ean(str, false, &result, ISBN);
@@ -951,7 +1141,7 @@ PG_FUNCTION_INFO_V1(ismn_cast_from_text);
 Datum
 ismn_cast_from_text(PG_FUNCTION_ARGS)
 {
-   const char  *str = GET_STR(PG_GETARG_TEXT_P(0));
+   const char *str = GET_STR(PG_GETARG_TEXT_P(0));
    ean13       result;
 
    (void) string2ean(str, false, &result, ISMN);
@@ -962,7 +1152,7 @@ PG_FUNCTION_INFO_V1(issn_cast_from_text);
 Datum
 issn_cast_from_text(PG_FUNCTION_ARGS)
 {
-   const char  *str = GET_STR(PG_GETARG_TEXT_P(0));
+   const char *str = GET_STR(PG_GETARG_TEXT_P(0));
    ean13       result;
 
    (void) string2ean(str, false, &result, ISSN);
@@ -973,7 +1163,7 @@ PG_FUNCTION_INFO_V1(upc_cast_from_text);
 Datum
 upc_cast_from_text(PG_FUNCTION_ARGS)
 {
-   const char  *str = GET_STR(PG_GETARG_TEXT_P(0));
+   const char *str = GET_STR(PG_GETARG_TEXT_P(0));
    ean13       result;
 
    (void) string2ean(str, false, &result, UPC);
@@ -986,7 +1176,8 @@ PG_FUNCTION_INFO_V1(is_valid);
 Datum
 is_valid(PG_FUNCTION_ARGS)
 {
-   ean13 val = PG_GETARG_EAN13(0);
+   ean13       val = PG_GETARG_EAN13(0);
+
    PG_RETURN_BOOL((val & 1) == 0);
 }
 
@@ -996,13 +1187,14 @@ PG_FUNCTION_INFO_V1(make_valid);
 Datum
 make_valid(PG_FUNCTION_ARGS)
 {
-   ean13 val = PG_GETARG_EAN13(0);
+   ean13       val = PG_GETARG_EAN13(0);
+
    val &= ~((ean13) 1);
    PG_RETURN_EAN13(val);
 }
 
 #ifdef ISN_WEAK_MODE
-/* this function temporarily sets weak input flag 
+/* this function temporarily sets weak input flag
  * (to lose the strictness of check digit acceptance)
  * It's a helper function, not intended to be used!!
  */
@@ -1021,7 +1213,7 @@ accept_weak_input(PG_FUNCTION_ARGS)
    /* function has no effect */
    PG_RETURN_BOOL(false);
 }
-#endif /* ISN_WEAK_MODE */
+#endif   /* ISN_WEAK_MODE */
 
 PG_FUNCTION_INFO_V1(weak_input_status);
 Datum
index 30bf2e029644a1056743bd1444bf37ebfab833f1..0bac6475478dc9b34e72ad901ff5d8be6463bab5 100644 (file)
@@ -219,7 +219,7 @@ sizebitvec(BITVECP sign)
                i;
 
    ALOOPBYTE(
-       size += number_of_ones[(unsigned char) sign[i]];
+             size += number_of_ones[(unsigned char) sign[i]];
    );
    return size;
 }
@@ -232,8 +232,8 @@ hemdistsign(BITVECP a, BITVECP b)
                dist = 0;
 
    ALOOPBYTE(
-       diff = (unsigned char) (a[i] ^ b[i]);
-       dist += number_of_ones[diff];
+             diff = (unsigned char) (a[i] ^ b[i]);
+   dist += number_of_ones[diff];
    );
    return dist;
 }
@@ -270,7 +270,7 @@ typedef struct
 {
    OffsetNumber pos;
    int4        cost;
-} SPLITCOST;
+}  SPLITCOST;
 
 static int
 comparecost(const void *a, const void *b)
@@ -580,6 +580,6 @@ _ltree_consistent(PG_FUNCTION_ARGS)
            /* internal error */
            elog(ERROR, "unrecognized StrategyNumber: %d", strategy);
    }
-   PG_FREE_IF_COPY(query,1);
+   PG_FREE_IF_COPY(query, 1);
    PG_RETURN_BOOL(res);
 }
index 07269ceaee6f3baf46e696f48abac07e8907ee46..8522c5e0538a0404842f8cd9c15e6057c6ce4c09 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * op function for ltree and lquery
  * Teodor Sigaev <[email protected]>
- * $PostgreSQL: pgsql/contrib/ltree/lquery_op.c,v 1.10 2006/03/11 04:38:29 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/ltree/lquery_op.c,v 1.11 2006/10/04 00:29:45 momjian Exp $
  */
 
 #include "ltree.h"
@@ -46,7 +46,7 @@ getlexeme(char *start, char *end, int *len)
 }
 
 bool
-compare_subnode(ltree_level * t, char *qn, int len, int (*cmpptr) (const char *, const char *, size_t), bool anyend)
+           compare_subnode(ltree_level * t, char *qn, int len, int (*cmpptr) (const char *, const char *, size_t), bool anyend)
 {
    char       *endt = t->name + t->len;
    char       *endq = qn + len;
index b9058d5edff5687840adeb8ea34775cf330edaf6..1ff5707fb13a23ba3c7fd607f7dbc82cca221108 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/ltree/ltree.h,v 1.16 2006/07/11 16:00:44 teodor Exp $ */
+/* $PostgreSQL: pgsql/contrib/ltree/ltree.h,v 1.17 2006/10/04 00:29:45 momjian Exp $ */
 
 #ifndef __LTREE_H__
 #define __LTREE_H__
@@ -163,7 +163,7 @@ bool compare_subnode(ltree_level * t, char *q, int len,
 ltree     *lca_inner(ltree ** a, int len);
 
 #define PG_GETARG_LTREE(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
-#define PG_GETARG_LTREE_COPY(x)    ((ltree*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
+#define PG_GETARG_LTREE_COPY(x) ((ltree*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
 #define PG_GETARG_LQUERY(x) ((lquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
 #define PG_GETARG_LQUERY_COPY(x) ((lquery*)DatumGetPointer(PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(x))))
 #define PG_GETARG_LTXTQUERY(x) ((ltxtquery*)DatumGetPointer(PG_DETOAST_DATUM(PG_GETARG_DATUM(x))))
index 5cfddd7634059f7a396d61792a36e537439b5a87..0239c5fe991c183444c51d3a04e16cdd6031f200 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * GiST support for ltree
  * Teodor Sigaev <[email protected]>
- * $PostgreSQL: pgsql/contrib/ltree/ltree_gist.c,v 1.18 2006/08/08 15:45:18 teodor Exp $
+ * $PostgreSQL: pgsql/contrib/ltree/ltree_gist.c,v 1.19 2006/10/04 00:29:45 momjian Exp $
  */
 
 #include "ltree.h"
@@ -457,8 +457,10 @@ gist_isparent(ltree_gist * key, ltree * query)
 }
 
 static ltree *
-copy_ltree( ltree *src ) {
-   ltree *dst = (ltree*)palloc(src->len);
+copy_ltree(ltree * src)
+{
+   ltree      *dst = (ltree *) palloc(src->len);
+
    memcpy(dst, src, src->len);
    return dst;
 }
@@ -466,9 +468,9 @@ copy_ltree( ltree *src ) {
 static bool
 gist_ischild(ltree_gist * key, ltree * query)
 {
-   ltree      *left = copy_ltree(LTG_GETLNODE(key));
-   ltree      *right = copy_ltree(LTG_GETRNODE(key));
-   bool            res = true;
+   ltree      *left = copy_ltree(LTG_GETLNODE(key));
+   ltree      *right = copy_ltree(LTG_GETRNODE(key));
+   bool        res = true;
 
    if (left->numlevel > query->numlevel)
        left->numlevel = query->numlevel;
@@ -711,6 +713,6 @@ ltree_consistent(PG_FUNCTION_ARGS)
            elog(ERROR, "unrecognized StrategyNumber: %d", strategy);
    }
 
-   PG_FREE_IF_COPY(query,1);
+   PG_FREE_IF_COPY(query, 1);
    PG_RETURN_BOOL(res);
 }
index f4348e0161fe01472e39eaba8c720f84345a7875..9b8a360ca897e2d56490009f5d6de860fd381727 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * op function for ltree
  * Teodor Sigaev <[email protected]>
- * $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.13 2006/09/20 19:50:21 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/ltree/ltree_op.c,v 1.14 2006/10/04 00:29:45 momjian Exp $
  */
 
 #include "ltree.h"
@@ -620,8 +620,8 @@ ltreeparentsel(PG_FUNCTION_ARGS)
        /*
         * If the histogram is large enough, see what fraction of it the
         * constant is "<@" to, and assume that's representative of the
-        * non-MCV population.  Otherwise use the default selectivity for
-        * the non-MCV population.
+        * non-MCV population.  Otherwise use the default selectivity for the
+        * non-MCV population.
         */
        selec = histogram_selectivity(&vardata, &contproc,
                                      constval, varonleft,
index 2d7392884eb068ca9daf6f7a48f51829ba5b43be..3c8af235d1020cd64df255dd897cda923328794d 100644 (file)
@@ -3,7 +3,7 @@
  * pg_buffercache_pages.c
  *   display some contents of the buffer cache
  *
- *   $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.8 2006/07/23 03:07:57 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/pg_buffercache/pg_buffercache_pages.c,v 1.9 2006/10/04 00:29:45 momjian Exp $
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
@@ -74,7 +74,7 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
 
    if (SRF_IS_FIRSTCALL())
    {
-       int     i;
+       int         i;
        volatile BufferDesc *bufHdr;
 
        funcctx = SRF_FIRSTCALL_INIT();
@@ -123,9 +123,9 @@ pg_buffercache_pages(PG_FUNCTION_ARGS)
        MemoryContextSwitchTo(oldcontext);
 
        /*
-        * To get a consistent picture of the buffer state, we must lock
-        * all partitions of the buffer map.  Needless to say, this is
-        * horrible for concurrency...
+        * To get a consistent picture of the buffer state, we must lock all
+        * partitions of the buffer map.  Needless to say, this is horrible
+        * for concurrency...
         */
        for (i = 0; i < NUM_BUFFER_PARTITIONS; i++)
            LWLockAcquire(FirstBufMappingLock + i, LW_SHARED);
index 9ce8422157f50c2e7faf74fd39afba2bde506bb5..5486a98d486ab87fea66fefc8cd36c5d25a4a67a 100644 (file)
@@ -3,7 +3,7 @@
  * pg_freespacemap.c
  *   display some contents of the free space relation and page maps.
  *
- *   $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.7 2006/09/21 20:31:21 tgl Exp $
+ *   $PostgreSQL: pgsql/contrib/pg_freespacemap/pg_freespacemap.c,v 1.8 2006/10/04 00:29:45 momjian Exp $
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
 #include "storage/freespace.h"
 
 
-#define        NUM_FREESPACE_PAGES_ELEM    5
-#define        NUM_FREESPACE_RELATIONS_ELEM    7
+#define        NUM_FREESPACE_PAGES_ELEM    5
+#define        NUM_FREESPACE_RELATIONS_ELEM    7
 
 #if defined(WIN32) || defined(__CYGWIN__)
 /* Need DLLIMPORT for some things that are not so marked in main headers */
-extern DLLIMPORT int   MaxFSMPages;
-extern DLLIMPORT int   MaxFSMRelations;
+extern DLLIMPORT int MaxFSMPages;
+extern DLLIMPORT int MaxFSMRelations;
 extern DLLIMPORT volatile uint32 InterruptHoldoffCount;
 #endif
 
@@ -35,12 +35,12 @@ Datum       pg_freespacemap_relations(PG_FUNCTION_ARGS);
  */
 typedef struct
 {
-   Oid             reltablespace;
-   Oid             reldatabase;
-   Oid             relfilenode;
-   BlockNumber     relblocknumber;
-   Size            bytes;
-   bool            isindex;
+   Oid         reltablespace;
+   Oid         reldatabase;
+   Oid         relfilenode;
+   BlockNumber relblocknumber;
+   Size        bytes;
+   bool        isindex;
 }  FreeSpacePagesRec;
 
 
@@ -49,14 +49,14 @@ typedef struct
  */
 typedef struct
 {
-   Oid             reltablespace;
-   Oid             reldatabase;
-   Oid             relfilenode;
-   Size            avgrequest;
-   BlockNumber     interestingpages;
-   int             storedpages;
-   int             nextpage;
-   bool            isindex;
+   Oid         reltablespace;
+   Oid         reldatabase;
+   Oid         relfilenode;
+   Size        avgrequest;
+   BlockNumber interestingpages;
+   int         storedpages;
+   int         nextpage;
+   bool        isindex;
 }  FreeSpaceRelationsRec;
 
 
@@ -66,8 +66,8 @@ typedef struct
  */
 typedef struct
 {
-   TupleDesc           tupdesc;
-   FreeSpacePagesRec   *record;
+   TupleDesc   tupdesc;
+   FreeSpacePagesRec *record;
 }  FreeSpacePagesContext;
 
 
@@ -76,8 +76,8 @@ typedef struct
  */
 typedef struct
 {
-   TupleDesc           tupdesc;
-   FreeSpaceRelationsRec   *record;
+   TupleDesc   tupdesc;
+   FreeSpaceRelationsRec *record;
 }  FreeSpaceRelationsContext;
 
 
@@ -89,21 +89,21 @@ PG_FUNCTION_INFO_V1(pg_freespacemap_pages);
 Datum
 pg_freespacemap_pages(PG_FUNCTION_ARGS)
 {
-   FuncCallContext         *funcctx;
-   Datum                   result;
-   MemoryContext           oldcontext;
-   FreeSpacePagesContext   *fctx;              /* User function context. */
-   TupleDesc               tupledesc;
-   HeapTuple               tuple;
-   FSMHeader               *FreeSpaceMap;      /* FSM main structure. */
-   FSMRelation             *fsmrel;            /* Individual relation. */
+   FuncCallContext *funcctx;
+   Datum       result;
+   MemoryContext oldcontext;
+   FreeSpacePagesContext *fctx;    /* User function context. */
+   TupleDesc   tupledesc;
+   HeapTuple   tuple;
+   FSMHeader  *FreeSpaceMap;   /* FSM main structure. */
+   FSMRelation *fsmrel;        /* Individual relation. */
 
    if (SRF_IS_FIRSTCALL())
    {
-       int             i;
-       int             numPages;   /* Max possible no. of pages in map. */
-       int             nPages;     /* Mapped pages for a relation. */
-       
+       int         i;
+       int         numPages;   /* Max possible no. of pages in map. */
+       int         nPages;     /* Mapped pages for a relation. */
+
        /*
         * Get the free space map data structure.
         */
@@ -138,8 +138,8 @@ pg_freespacemap_pages(PG_FUNCTION_ARGS)
        fctx->tupdesc = BlessTupleDesc(tupledesc);
 
        /*
-        * Allocate numPages worth of FreeSpacePagesRec records, this is
-        * an upper bound.
+        * Allocate numPages worth of FreeSpacePagesRec records, this is an
+        * upper bound.
         */
        fctx->record = (FreeSpacePagesRec *) palloc(sizeof(FreeSpacePagesRec) * numPages);
 
@@ -147,16 +147,16 @@ pg_freespacemap_pages(PG_FUNCTION_ARGS)
        MemoryContextSwitchTo(oldcontext);
 
        /*
-        * Lock free space map and scan though all the relations.
-        * For each relation, gets all its mapped pages.
+        * Lock free space map and scan though all the relations. For each
+        * relation, gets all its mapped pages.
         */
        LWLockAcquire(FreeSpaceLock, LW_EXCLUSIVE);
 
        i = 0;
 
-       for (fsmrel = FreeSpaceMap->usageList; fsmrel; fsmrel = fsmrel->nextUsage) 
+       for (fsmrel = FreeSpaceMap->usageList; fsmrel; fsmrel = fsmrel->nextUsage)
        {
-           if (fsmrel->isIndex)    
+           if (fsmrel->isIndex)
            {
                /* Index relation. */
                IndexFSMPageData *page;
@@ -169,9 +169,9 @@ pg_freespacemap_pages(PG_FUNCTION_ARGS)
                    fctx->record[i].reltablespace = fsmrel->key.spcNode;
                    fctx->record[i].reldatabase = fsmrel->key.dbNode;
                    fctx->record[i].relfilenode = fsmrel->key.relNode;
-                   fctx->record[i].relblocknumber = IndexFSMPageGetPageNum(page);  
-                   fctx->record[i].bytes = 0;  
-                   fctx->record[i].isindex = true; 
+                   fctx->record[i].relblocknumber = IndexFSMPageGetPageNum(page);
+                   fctx->record[i].bytes = 0;
+                   fctx->record[i].isindex = true;
 
                    page++;
                    i++;
@@ -191,9 +191,9 @@ pg_freespacemap_pages(PG_FUNCTION_ARGS)
                    fctx->record[i].reldatabase = fsmrel->key.dbNode;
                    fctx->record[i].relfilenode = fsmrel->key.relNode;
                    fctx->record[i].relblocknumber = FSMPageGetPageNum(page);
-                   fctx->record[i].bytes = FSMPageGetSpace(page);  
-                   fctx->record[i].isindex = false;    
-                   
+                   fctx->record[i].bytes = FSMPageGetSpace(page);
+                   fctx->record[i].isindex = false;
+
                    page++;
                    i++;
                }
@@ -216,7 +216,7 @@ pg_freespacemap_pages(PG_FUNCTION_ARGS)
    if (funcctx->call_cntr < funcctx->max_calls)
    {
        int         i = funcctx->call_cntr;
-       FreeSpacePagesRec   *record = &fctx->record[i];
+       FreeSpacePagesRec *record = &fctx->record[i];
        Datum       values[NUM_FREESPACE_PAGES_ELEM];
        bool        nulls[NUM_FREESPACE_PAGES_ELEM];
 
@@ -261,20 +261,20 @@ PG_FUNCTION_INFO_V1(pg_freespacemap_relations);
 Datum
 pg_freespacemap_relations(PG_FUNCTION_ARGS)
 {
-   FuncCallContext         *funcctx;
-   Datum                   result;
-   MemoryContext           oldcontext;
-   FreeSpaceRelationsContext   *fctx;          /* User function context. */
-   TupleDesc               tupledesc;
-   HeapTuple               tuple;
-   FSMHeader               *FreeSpaceMap;      /* FSM main structure. */
-   FSMRelation             *fsmrel;            /* Individual relation. */
+   FuncCallContext *funcctx;
+   Datum       result;
+   MemoryContext oldcontext;
+   FreeSpaceRelationsContext *fctx;    /* User function context. */
+   TupleDesc   tupledesc;
+   HeapTuple   tuple;
+   FSMHeader  *FreeSpaceMap;   /* FSM main structure. */
+   FSMRelation *fsmrel;        /* Individual relation. */
 
    if (SRF_IS_FIRSTCALL())
    {
-       int             i;
-       int             numRelations;   /* Max no. of Relations in map. */
-       
+       int         i;
+       int         numRelations;       /* Max no. of Relations in map. */
+
        /*
         * Get the free space map data structure.
         */
@@ -313,8 +313,8 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
        fctx->tupdesc = BlessTupleDesc(tupledesc);
 
        /*
-        * Allocate numRelations worth of FreeSpaceRelationsRec records, 
-        * this is also an upper bound.
+        * Allocate numRelations worth of FreeSpaceRelationsRec records, this
+        * is also an upper bound.
         */
        fctx->record = (FreeSpaceRelationsRec *) palloc(sizeof(FreeSpaceRelationsRec) * numRelations);
 
@@ -328,12 +328,12 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
 
        i = 0;
 
-       for (fsmrel = FreeSpaceMap->usageList; fsmrel; fsmrel = fsmrel->nextUsage) 
+       for (fsmrel = FreeSpaceMap->usageList; fsmrel; fsmrel = fsmrel->nextUsage)
        {
            fctx->record[i].reltablespace = fsmrel->key.spcNode;
            fctx->record[i].reldatabase = fsmrel->key.dbNode;
            fctx->record[i].relfilenode = fsmrel->key.relNode;
-           fctx->record[i].avgrequest = (int64)fsmrel->avgRequest;
+           fctx->record[i].avgrequest = (int64) fsmrel->avgRequest;
            fctx->record[i].interestingpages = fsmrel->interestingPages;
            fctx->record[i].storedpages = fsmrel->storedPages;
            fctx->record[i].nextpage = fsmrel->nextPage;
@@ -358,7 +358,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
    if (funcctx->call_cntr < funcctx->max_calls)
    {
        int         i = funcctx->call_cntr;
-       FreeSpaceRelationsRec   *record = &fctx->record[i];
+       FreeSpaceRelationsRec *record = &fctx->record[i];
        Datum       values[NUM_FREESPACE_RELATIONS_ELEM];
        bool        nulls[NUM_FREESPACE_RELATIONS_ELEM];
 
@@ -368,6 +368,7 @@ pg_freespacemap_relations(PG_FUNCTION_ARGS)
        nulls[1] = false;
        values[2] = ObjectIdGetDatum(record->relfilenode);
        nulls[2] = false;
+
        /*
         * avgrequest isn't meaningful for an index
         */
index bfb92336d7d09f7ff16a9ece91c5c63b3c17d046..41a827ae0c3357a157a57983abb02745968a9097 100644 (file)
@@ -307,7 +307,7 @@ sizebitvec(BITVECP sign)
                i;
 
    LOOPBYTE(
-       size += number_of_ones[(unsigned char) sign[i]];
+            size += number_of_ones[(unsigned char) sign[i]];
    );
    return size;
 }
@@ -320,8 +320,8 @@ hemdistsign(BITVECP a, BITVECP b)
                dist = 0;
 
    LOOPBYTE(
-       diff = (unsigned char) (a[i] ^ b[i]);
-       dist += number_of_ones[diff];
+            diff = (unsigned char) (a[i] ^ b[i]);
+   dist += number_of_ones[diff];
    );
    return dist;
 }
@@ -393,7 +393,7 @@ typedef struct
 {
    OffsetNumber pos;
    int4        cost;
-} SPLITCOST;
+}  SPLITCOST;
 
 static int
 comparecost(const void *a, const void *b)
index 702bee80ba2c694a55c7bba54eafc57d466726c2..447e8487b0aab58e64cf2a1ee567cbe56782e7a1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.55 2006/09/16 13:31:40 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgbench/pgbench.c,v 1.56 2006/10/04 00:29:45 momjian Exp $
  *
  * pgbench: a simple benchmark program for PostgreSQL
  * written by Tatsuo Ishii
@@ -136,7 +136,7 @@ int         num_files;          /* its number */
 static char *tpc_b = {
    "\\set nbranches :scale\n"
    "\\set ntellers 10 * :scale\n"
-    "\\set naccounts 100000 * :scale\n"
+   "\\set naccounts 100000 * :scale\n"
    "\\setrandom aid 1 :naccounts\n"
    "\\setrandom bid 1 :nbranches\n"
    "\\setrandom tid 1 :ntellers\n"
@@ -154,7 +154,7 @@ static char *tpc_b = {
 static char *simple_update = {
    "\\set nbranches :scale\n"
    "\\set ntellers 10 * :scale\n"
-    "\\set naccounts 100000 * :scale\n"
+   "\\set naccounts 100000 * :scale\n"
    "\\setrandom aid 1 :naccounts\n"
    "\\setrandom bid 1 :nbranches\n"
    "\\setrandom tid 1 :ntellers\n"
@@ -168,7 +168,7 @@ static char *simple_update = {
 
 /* -S case */
 static char *select_only = {
-    "\\set naccounts 100000 * :scale\n"
+   "\\set naccounts 100000 * :scale\n"
    "\\setrandom aid 1 :naccounts\n"
    "SELECT abalance FROM accounts WHERE aid = :aid;\n"
 };
@@ -338,7 +338,7 @@ putVariable(CState * st, char *name, char *value)
    }
    else
    {
-       char *val;
+       char       *val;
 
        if ((val = strdup(value)) == NULL)
            return false;
@@ -1009,14 +1009,16 @@ process_file(char *filename)
        while (isspace((unsigned char) buf[i]))
            i++;
 
-       if (buf[i] != '\0' && strncmp(&buf[i], "--", 2) != 0) {
+       if (buf[i] != '\0' && strncmp(&buf[i], "--", 2) != 0)
+       {
            commands = process_commands(&buf[i]);
            if (commands == NULL)
            {
                fclose(fd);
                return false;
            }
-       } else
+       }
+       else
            continue;
 
        my_commands[lineno] = commands;
@@ -1530,7 +1532,7 @@ main(int argc, char **argv)
        if (state[i].ecnt > prev_ecnt && commands[state[i].state]->type == META_COMMAND)
        {
            fprintf(stderr, "Client %d aborted in state %d. Execution meta-command failed.\n", i, state[i].state);
-           remains--;              /* I've aborted */
+           remains--;          /* I've aborted */
            PQfinish(state[i].con);
            state[i].con = NULL;
        }
@@ -1610,7 +1612,7 @@ main(int argc, char **argv)
            if (state[i].ecnt > prev_ecnt && commands[state[i].state]->type == META_COMMAND)
            {
                fprintf(stderr, "Client %d aborted in state %d. Execution meta-command failed.\n", i, state[i].state);
-               remains--;              /* I've aborted */
+               remains--;      /* I've aborted */
                PQfinish(state[i].con);
                state[i].con = NULL;
            }
index 30a35b1796b6e4172b29a5fee47317caeb308cab..c3ec01b9002661d91a4a53a9bef30579da6b6911 100644 (file)
@@ -2,7 +2,7 @@
  * Written by Solar Designer and placed in the public domain.
  * See crypt_blowfish.c for more information.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/crypt-gensalt.c,v 1.9 2006/07/13 04:15:24 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/crypt-gensalt.c,v 1.10 2006/10/04 00:29:46 momjian Exp $
  *
  * This file contains salt generation functions for the traditional and
  * other common crypt(3) algorithms, except for bcrypt which is defined
@@ -64,9 +64,9 @@ _crypt_gensalt_extended_rn(unsigned long count,
    output[2] = _crypt_itoa64[(count >> 6) & 0x3f];
    output[3] = _crypt_itoa64[(count >> 12) & 0x3f];
    output[4] = _crypt_itoa64[(count >> 18) & 0x3f];
-   value = (unsigned long)(unsigned char) input[0] |
-       ((unsigned long)(unsigned char) input[1] << 8) |
-       ((unsigned long)(unsigned char) input[2] << 16);
+   value = (unsigned long) (unsigned char) input[0] |
+       ((unsigned long) (unsigned char) input[1] << 8) |
+       ((unsigned long) (unsigned char) input[2] << 16);
    output[5] = _crypt_itoa64[value & 0x3f];
    output[6] = _crypt_itoa64[(value >> 6) & 0x3f];
    output[7] = _crypt_itoa64[(value >> 12) & 0x3f];
@@ -92,9 +92,9 @@ _crypt_gensalt_md5_rn(unsigned long count,
    output[0] = '$';
    output[1] = '1';
    output[2] = '$';
-   value = (unsigned long)(unsigned char) input[0] |
-       ((unsigned long)(unsigned char) input[1] << 8) |
-       ((unsigned long)(unsigned char) input[2] << 16);
+   value = (unsigned long) (unsigned char) input[0] |
+       ((unsigned long) (unsigned char) input[1] << 8) |
+       ((unsigned long) (unsigned char) input[2] << 16);
    output[3] = _crypt_itoa64[value & 0x3f];
    output[4] = _crypt_itoa64[(value >> 6) & 0x3f];
    output[5] = _crypt_itoa64[(value >> 12) & 0x3f];
@@ -103,9 +103,9 @@ _crypt_gensalt_md5_rn(unsigned long count,
 
    if (size >= 6 && output_size >= 3 + 4 + 4 + 1)
    {
-       value = (unsigned long)(unsigned char) input[3] |
-           ((unsigned long)(unsigned char) input[4] << 8) |
-           ((unsigned long)(unsigned char) input[5] << 16);
+       value = (unsigned long) (unsigned char) input[3] |
+           ((unsigned long) (unsigned char) input[4] << 8) |
+           ((unsigned long) (unsigned char) input[5] << 16);
        output[7] = _crypt_itoa64[value & 0x3f];
        output[8] = _crypt_itoa64[(value >> 6) & 0x3f];
        output[9] = _crypt_itoa64[(value >> 12) & 0x3f];
index 556a0e9e8e82d58d3f49f18df08dadc0ca70f97b..c05e334a998becb55291006344afc90713cd27f3 100644 (file)
@@ -8,7 +8,7 @@
  *
  * $FreeBSD: src/lib/libcrypt/crypt-md5.c,v 1.5 1999/12/17 20:21:45 peter Exp $
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/crypt-md5.c,v 1.7 2006/07/13 04:15:24 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/crypt-md5.c,v 1.8 2006/10/04 00:29:46 momjian Exp $
  */
 
 #include "postgres.h"
@@ -24,7 +24,7 @@ static const char _crypt_a64[] =
 static void
 _crypt_to64(char *s, unsigned long v, int n)
 {
-       while (--n >= 0)
+   while (--n >= 0)
    {
        *s++ = _crypt_a64[v & 0x3f];
        v >>= 6;
index cd08fd2bc68def66e3caf696fe5722cfb0be6fa7..5a2596fe786cf25ef898da403f4709561cf02999 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.7 2006/07/13 04:15:24 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.8 2006/10/04 00:29:46 momjian Exp $
  */
 
 #include "postgres.h"
@@ -365,8 +365,8 @@ rekey(FState * st)
 static void
 startup_tricks(FState * st)
 {
-   int i;
-   uint8 buf[BLOCK];
+   int         i;
+   uint8       buf[BLOCK];
 
    /* Use next block as counter. */
    encrypt_counter(st, st->counter);
index 6375fd7a889c0d54ac779ec6e09183a5053ad9de..197e24f74b7690a297b880fee2436da63e1281b2 100644 (file)
@@ -1,9 +1,9 @@
 /* imath version 1.3 */
 /*
-  Name:     imath.c
-  Purpose:  Arbitrary precision integer arithmetic routines.
-  Author:   M. J. Fromberger <http://www.dartmouth.edu/~sting/>
-  Info:     Id: imath.c 21 2006-04-02 18:58:36Z sting
+  Name:        imath.c
+  Purpose: Arbitrary precision integer arithmetic routines.
+  Author:  M. J. Fromberger <http://www.dartmouth.edu/~sting/>
+  Info:        Id: imath.c 21 2006-04-02 18:58:36Z sting
 
   Copyright (C) 2002 Michael J. Fromberger, All Rights Reserved.
 
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-  NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   SOFTWARE.
  */
-/* $PostgreSQL: pgsql/contrib/pgcrypto/imath.c,v 1.5 2006/09/22 21:39:57 tgl Exp $ */
+/* $PostgreSQL: pgsql/contrib/pgcrypto/imath.c,v 1.6 2006/10/04 00:29:46 momjian Exp $ */
 
 #include "postgres.h"
 #include "px.h"
 
 /* {{{ Constants */
 
-const mp_result MP_OK     = 0;  /* no error, all is well  */
-const mp_result MP_FALSE  = 0;  /* boolean false          */
-const mp_result MP_TRUE   = -1; /* boolean true           */
-const mp_result MP_MEMORY = -2; /* out of memory          */
-const mp_result MP_RANGE  = -3; /* argument out of range  */
-const mp_result MP_UNDEF  = -4; /* result undefined       */
-const mp_result MP_TRUNC  = -5; /* output truncated       */
+const mp_result MP_OK = 0;     /* no error, all is well  */
+const mp_result MP_FALSE = 0;  /* boolean false          */
+const mp_result MP_TRUE = -1;  /* boolean true           */
+const mp_result MP_MEMORY = -2; /* out of memory         */
+const mp_result MP_RANGE = -3; /* argument out of range  */
+const mp_result MP_UNDEF = -4; /* result undefined       */
+const mp_result MP_TRUNC = -5; /* output truncated       */
 const mp_result MP_BADARG = -6; /* invalid null argument  */
 
-const mp_sign   MP_NEG  = 1;    /* value is strictly negative */
-const mp_sign   MP_ZPOS = 0;    /* value is non-negative      */
+const mp_sign MP_NEG = 1;      /* value is strictly negative */
+const mp_sign MP_ZPOS = 0;     /* value is non-negative      */
 
 static const char *s_unknown_err = "unknown result code";
 static const char *s_error_msg[] = {
-  "error code 0",
-  "boolean true",
-  "out of memory",
-  "argument out of range",
-  "result undefined",
-  "output truncated",
-  "invalid null argument",
-  NULL
+   "error code 0",
+   "boolean true",
+   "out of memory",
+   "argument out of range",
+   "result undefined",
+   "output truncated",
+   "invalid null argument",
+   NULL
 };
 
 /* }}} */
 
 /* Optional library flags */
-#define MP_CAP_DIGITS   1  /* flag bit to capitalize letter digits */
+#define MP_CAP_DIGITS  1       /* flag bit to capitalize letter digits */
 
-/* Argument checking macros 
+/* Argument checking macros
    Use CHECK() where a return value is required; NRCHECK() elsewhere */
 #define CHECK(TEST)   assert(TEST)
 #define NRCHECK(TEST) assert(TEST)
@@ -83,23 +83,23 @@ static const char *s_error_msg[] = {
    can compute log_i(n) = lg(n) * log_i(2).
  */
 static const double s_log2[] = {
-   0.000000000, 0.000000000, 1.000000000, 0.630929754,     /*  0  1  2  3 */
-   0.500000000, 0.430676558, 0.386852807, 0.356207187,     /*  4  5  6  7 */
-   0.333333333, 0.315464877, 0.301029996, 0.289064826,     /*  8  9 10 11 */
-   0.278942946, 0.270238154, 0.262649535, 0.255958025,     /* 12 13 14 15 */
-   0.250000000, 0.244650542, 0.239812467, 0.235408913,     /* 16 17 18 19 */
-   0.231378213, 0.227670249, 0.224243824, 0.221064729,     /* 20 21 22 23 */
-   0.218104292, 0.215338279, 0.212746054, 0.210309918,     /* 24 25 26 27 */
-   0.208014598, 0.205846832, 0.203795047, 0.201849087,     /* 28 29 30 31 */
-   0.200000000, 0.198239863, 0.196561632, 0.194959022,     /* 32 33 34 35 */
-   0.193426404, 0.191958720, 0.190551412, 0.189200360,     /* 36 37 38 39 */
-   0.187901825, 0.186652411, 0.185449023, 0.184288833,     /* 40 41 42 43 */
-   0.183169251, 0.182087900, 0.181042597, 0.180031327,     /* 44 45 46 47 */
-   0.179052232, 0.178103594, 0.177183820, 0.176291434,     /* 48 49 50 51 */
-   0.175425064, 0.174583430, 0.173765343, 0.172969690,     /* 52 53 54 55 */
-   0.172195434, 0.171441601, 0.170707280, 0.169991616,     /* 56 57 58 59 */
-   0.169293808, 0.168613099, 0.167948779, 0.167300179,     /* 60 61 62 63 */
-   0.166666667
+   0.000000000, 0.000000000, 1.000000000, 0.630929754, /* 0  1  2  3 */
+   0.500000000, 0.430676558, 0.386852807, 0.356207187, /* 4  5  6  7 */
+   0.333333333, 0.315464877, 0.301029996, 0.289064826, /* 8  9 10 11 */
+   0.278942946, 0.270238154, 0.262649535, 0.255958025, /* 12 13 14 15 */
+   0.250000000, 0.244650542, 0.239812467, 0.235408913, /* 16 17 18 19 */
+   0.231378213, 0.227670249, 0.224243824, 0.221064729, /* 20 21 22 23 */
+   0.218104292, 0.215338279, 0.212746054, 0.210309918, /* 24 25 26 27 */
+   0.208014598, 0.205846832, 0.203795047, 0.201849087, /* 28 29 30 31 */
+   0.200000000, 0.198239863, 0.196561632, 0.194959022, /* 32 33 34 35 */
+   0.193426404, 0.191958720, 0.190551412, 0.189200360, /* 36 37 38 39 */
+   0.187901825, 0.186652411, 0.185449023, 0.184288833, /* 40 41 42 43 */
+   0.183169251, 0.182087900, 0.181042597, 0.180031327, /* 44 45 46 47 */
+   0.179052232, 0.178103594, 0.177183820, 0.176291434, /* 48 49 50 51 */
+   0.175425064, 0.174583430, 0.173765343, 0.172969690, /* 52 53 54 55 */
+   0.172195434, 0.171441601, 0.170707280, 0.169991616, /* 56 57 58 59 */
+   0.169293808, 0.168613099, 0.167948779, 0.167300179, /* 60 61 62 63 */
+   0.166666667
 };
 
 /* }}} */
@@ -156,9 +156,9 @@ MP_USED(Z)=o_;CLAMP(Z);}while(0)
 do{mp_size ua_=MP_USED(X),o_=ua_+ua_;ZERO(MP_DIGITS(Z),o_);\
 (void) s_ksqr(MP_DIGITS(X),MP_DIGITS(Z),ua_);MP_USED(Z)=o_;CLAMP(Z);}while(0)
 
-#define UPPER_HALF(W)           ((mp_word)((W) >> MP_DIGIT_BIT))
-#define LOWER_HALF(W)           ((mp_digit)(W))
-#define HIGH_BIT_SET(W)         ((W) >> (MP_WORD_BIT - 1))
+#define UPPER_HALF(W)          ((mp_word)((W) >> MP_DIGIT_BIT))
+#define LOWER_HALF(W)          ((mp_digit)(W))
+#define HIGH_BIT_SET(W)            ((W) >> (MP_WORD_BIT - 1))
 #define ADD_WILL_OVERFLOW(W, V) ((MP_WORD_MAX - (V)) < (W))
 
 /* }}} */
@@ -175,6 +175,7 @@ static mp_word mp_flags = MP_CAP_DIGITS;
 /* Allocate a buffer of (at least) num digits, or return
    NULL if that couldn't be done.  */
 static mp_digit *s_alloc(mp_size num);
+
 #if TRACEABLE_FREE
 static void s_free(void *ptr);
 #else
@@ -183,97 +184,97 @@ static void s_free(void *ptr);
 
 /* Insure that z has at least min digits allocated, resizing if
    necessary.  Returns true if successful, false if out of memory. */
-static int       s_pad(mp_int z, mp_size min);
+static int s_pad(mp_int z, mp_size min);
 
 /* Normalize by removing leading zeroes (except when z = 0) */
 #if TRACEABLE_CLAMP
-static void      s_clamp(mp_int z);
+static void s_clamp(mp_int z);
 #endif
 
 /* Fill in a "fake" mp_int on the stack with a given value */
-static void      s_fake(mp_int z, int value, mp_digit vbuf[]);
+static void s_fake(mp_int z, int value, mp_digit vbuf[]);
 
 /* Compare two runs of digits of given length, returns <0, 0, >0 */
-static int       s_cdig(mp_digit *da, mp_digit *db, mp_size len);
+static int s_cdig(mp_digit * da, mp_digit * db, mp_size len);
 
 /* Pack the unsigned digits of v into array t */
-static int       s_vpack(int v, mp_digit t[]);
+static int s_vpack(int v, mp_digit t[]);
 
 /* Compare magnitudes of a and b, returns <0, 0, >0 */
-static int       s_ucmp(mp_int a, mp_int b);
+static int s_ucmp(mp_int a, mp_int b);
 
 /* Compare magnitudes of a and v, returns <0, 0, >0 */
-static int       s_vcmp(mp_int a, int v);
+static int s_vcmp(mp_int a, int v);
 
 /* Unsigned magnitude addition; assumes dc is big enough.
    Carry out is returned (no memory allocated). */
-static mp_digit  s_uadd(mp_digit *da, mp_digit *db, mp_digit *dc, 
-               mp_size size_a, mp_size size_b);
+static mp_digit s_uadd(mp_digit * da, mp_digit * db, mp_digit * dc,
+      mp_size size_a, mp_size size_b);
 
-/* Unsigned magnitude subtraction.  Assumes dc is big enough. */
-static void      s_usub(mp_digit *da, mp_digit *db, mp_digit *dc,
-               mp_size size_a, mp_size size_b);
+/* Unsigned magnitude subtraction. Assumes dc is big enough. */
+static void s_usub(mp_digit * da, mp_digit * db, mp_digit * dc,
+      mp_size size_a, mp_size size_b);
 
 /* Unsigned recursive multiplication.  Assumes dc is big enough. */
-static int       s_kmul(mp_digit *da, mp_digit *db, mp_digit *dc,
-           mp_size size_a, mp_size size_b);
+static int s_kmul(mp_digit * da, mp_digit * db, mp_digit * dc,
+      mp_size size_a, mp_size size_b);
 
 /* Unsigned magnitude multiplication.  Assumes dc is big enough. */
-static void      s_umul(mp_digit *da, mp_digit *db, mp_digit *dc,
-           mp_size size_a, mp_size size_b);
+static void s_umul(mp_digit * da, mp_digit * db, mp_digit * dc,
+      mp_size size_a, mp_size size_b);
 
 /* Unsigned recursive squaring.  Assumes dc is big enough. */
-static int       s_ksqr(mp_digit *da, mp_digit *dc, mp_size size_a);
+static int s_ksqr(mp_digit * da, mp_digit * dc, mp_size size_a);
 
 /* Unsigned magnitude squaring.  Assumes dc is big enough. */
-static void      s_usqr(mp_digit *da, mp_digit *dc, mp_size size_a);
+static void s_usqr(mp_digit * da, mp_digit * dc, mp_size size_a);
 
 /* Single digit addition.  Assumes a is big enough. */
-static void      s_dadd(mp_int a, mp_digit b);
+static void s_dadd(mp_int a, mp_digit b);
 
 /* Single digit multiplication.  Assumes a is big enough. */
-static void      s_dmul(mp_int a, mp_digit b);
+static void s_dmul(mp_int a, mp_digit b);
 
 /* Single digit multiplication on buffers; assumes dc is big enough. */
-static void      s_dbmul(mp_digit *da, mp_digit b, mp_digit *dc,
-            mp_size size_a);
+static void s_dbmul(mp_digit * da, mp_digit b, mp_digit * dc,
+       mp_size size_a);
 
-/* Single digit division.  Replaces a with the quotient, 
+/* Single digit division.  Replaces a with the quotient,
    returns the remainder.  */
-static mp_digit  s_ddiv(mp_int a, mp_digit b);
+static mp_digit s_ddiv(mp_int a, mp_digit b);
 
 /* Quick division by a power of 2, replaces z (no allocation) */
-static void      s_qdiv(mp_int z, mp_size p2);
+static void s_qdiv(mp_int z, mp_size p2);
 
 /* Quick remainder by a power of 2, replaces z (no allocation) */
-static void      s_qmod(mp_int z, mp_size p2);
+static void s_qmod(mp_int z, mp_size p2);
 
-/* Quick multiplication by a power of 2, replaces z. 
+/* Quick multiplication by a power of 2, replaces z.
    Allocates if necessary; returns false in case this fails. */
-static int       s_qmul(mp_int z, mp_size p2);
+static int s_qmul(mp_int z, mp_size p2);
 
 /* Quick subtraction from a power of 2, replaces z.
    Allocates if necessary; returns false in case this fails. */
-static int       s_qsub(mp_int z, mp_size p2);
+static int s_qsub(mp_int z, mp_size p2);
 
 /* Return maximum k such that 2^k divides z. */
-static int       s_dp2k(mp_int z);
+static int s_dp2k(mp_int z);
 
 /* Return k >= 0 such that z = 2^k, or -1 if there is no such k. */
-static int       s_isp2(mp_int z);
+static int s_isp2(mp_int z);
 
 /* Set z to 2^k.  May allocate; returns false in case this fails. */
-static int       s_2expt(mp_int z, int k);
+static int s_2expt(mp_int z, int k);
 
 /* Normalize a and b for division, returns normalization constant */
-static int       s_norm(mp_int a, mp_int b);
+static int s_norm(mp_int a, mp_int b);
 
 /* Compute constant mu for Barrett reduction, given modulus m, result
    replaces z, m is untouched. */
 static mp_result s_brmu(mp_int z, mp_int m);
 
 /* Reduce a modulo m, using Barrett's algorithm. */
-static int       s_reduce(mp_int x, mp_int m, mp_int mu, mp_int q1, mp_int q2);
+static int s_reduce(mp_int x, mp_int m, mp_int mu, mp_int q1, mp_int q2);
 
 /* Modular exponentiation, using Barrett reduction */
 static mp_result s_embar(mp_int a, mp_int b, mp_int m, mp_int mu, mp_int c);
@@ -284,22 +285,22 @@ static mp_result s_udiv(mp_int a, mp_int b);
 
 /* Compute the number of digits in radix r required to represent the
    given value.  Does not account for sign flags, terminators, etc. */
-static int       s_outlen(mp_int z, mp_size r);
+static int s_outlen(mp_int z, mp_size r);
 
 /* Guess how many digits of precision will be needed to represent a
    radix r value of the specified number of digits.  Returns a value
    guaranteed to be no smaller than the actual number required. */
-static mp_size   s_inlen(int len, mp_size r);
+static mp_size s_inlen(int len, mp_size r);
 
-/* Convert a character to a digit value in radix r, or 
+/* Convert a character to a digit value in radix r, or
    -1 if out of range */
-static int       s_ch2val(char c, int r);
+static int s_ch2val(char c, int r);
 
 /* Convert a digit value to a character */
-static char      s_val2ch(int v, int caps);
+static char s_val2ch(int v, int caps);
 
 /* Take 2's complement of a buffer in place */
-static void      s_2comp(unsigned char *buf, int len);
+static void s_2comp(unsigned char *buf, int len);
 
 /* Convert a value to binary, ignoring sign.  On input, *limpos is the
    bound on how many bytes should be written to buf; on output, *limpos
@@ -308,698 +309,804 @@ static mp_result s_tobin(mp_int z, unsigned char *buf, int *limpos, int pad);
 
 #if 0
 /* Dump a representation of the mp_int to standard output */
-void      s_print(char *tag, mp_int z);
-void      s_print_buf(char *tag, mp_digit *buf, mp_size num);
+void       s_print(char *tag, mp_int z);
+void       s_print_buf(char *tag, mp_digit * buf, mp_size num);
 #endif
 
 /* {{{ get_default_precision() */
 
-mp_size   mp_get_default_precision(void)
-{ 
-  return default_precision; 
+mp_size
+mp_get_default_precision(void)
+{
+   return default_precision;
 }
 
 /* }}} */
 
 /* {{{ mp_set_default_precision(s) */
 
-void      mp_set_default_precision(mp_size s)
-{ 
-  NRCHECK(s > 0);
+void
+mp_set_default_precision(mp_size s)
+{
+   NRCHECK(s > 0);
 
-  default_precision = (mp_size) ROUND_PREC(s);
+   default_precision = (mp_size) ROUND_PREC(s);
 }
 
 /* }}} */
 
 /* {{{ mp_get_multiply_threshold() */
 
-mp_size   mp_get_multiply_threshold(void)
+mp_size
+mp_get_multiply_threshold(void)
 {
-  return multiply_threshold;
+   return multiply_threshold;
 }
 
 /* }}} */
 
 /* {{{ mp_set_multiply_threshold(s) */
 
-void      mp_set_multiply_threshold(mp_size s)
+void
+mp_set_multiply_threshold(mp_size s)
 {
-  multiply_threshold = s;
+   multiply_threshold = s;
 }
 
 /* }}} */
 
 /* {{{ mp_int_init(z) */
 
-mp_result mp_int_init(mp_int z)
+mp_result
+mp_int_init(mp_int z)
 {
-  return mp_int_init_size(z, default_precision);
+   return mp_int_init_size(z, default_precision);
 }
 
 /* }}} */
 
 /* {{{ mp_int_alloc() */
 
-mp_int    mp_int_alloc(void)
+mp_int
+mp_int_alloc(void)
 {
-  mp_int out = px_alloc(sizeof(mpz_t));
+   mp_int      out = px_alloc(sizeof(mpz_t));
 
-  assert(out != NULL);
-  out->digits = NULL;
-  out->used   = 0;
-  out->alloc  = 0;
-  out->sign   = 0;
+   assert(out != NULL);
+   out->digits = NULL;
+   out->used = 0;
+   out->alloc = 0;
+   out->sign = 0;
 
-  return out;
+   return out;
 }
 
 /* }}} */
 
 /* {{{ mp_int_init_size(z, prec) */
 
-mp_result mp_int_init_size(mp_int z, mp_size prec)
+mp_result
+mp_int_init_size(mp_int z, mp_size prec)
 {
-  CHECK(z != NULL);
+   CHECK(z != NULL);
+
+   prec = (mp_size) ROUND_PREC(prec);
+   prec = MAX(prec, default_precision);
 
-  prec = (mp_size) ROUND_PREC(prec);
-  prec = MAX(prec, default_precision);
+   if ((MP_DIGITS(z) = s_alloc(prec)) == NULL)
+       return MP_MEMORY;
 
-  if((MP_DIGITS(z) = s_alloc(prec)) == NULL)
-    return MP_MEMORY;
+   z->digits[0] = 0;
+   MP_USED(z) = 1;
+   MP_ALLOC(z) = prec;
+   MP_SIGN(z) = MP_ZPOS;
 
-  z->digits[0] = 0;
-  MP_USED(z) = 1;
-  MP_ALLOC(z) = prec;
-  MP_SIGN(z) = MP_ZPOS;
-  
-  return MP_OK;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_init_copy(z, old) */
 
-mp_result mp_int_init_copy(mp_int z, mp_int old)
+mp_result
+mp_int_init_copy(mp_int z, mp_int old)
 {
-  mp_result  res;
-  mp_size    uold, target;
+   mp_result   res;
+   mp_size     uold,
+               target;
 
-  CHECK(z != NULL && old != NULL);
+   CHECK(z != NULL && old != NULL);
 
-  uold = MP_USED(old);
-  target = MAX(uold, default_precision);
+   uold = MP_USED(old);
+   target = MAX(uold, default_precision);
 
-  if((res = mp_int_init_size(z, target)) != MP_OK)
-    return res;
+   if ((res = mp_int_init_size(z, target)) != MP_OK)
+       return res;
 
-  MP_USED(z) = uold;
-  MP_SIGN(z) = MP_SIGN(old);
-  COPY(MP_DIGITS(old), MP_DIGITS(z), uold);
+   MP_USED(z) = uold;
+   MP_SIGN(z) = MP_SIGN(old);
+   COPY(MP_DIGITS(old), MP_DIGITS(z), uold);
 
-  return MP_OK;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_init_value(z, value) */
 
-mp_result mp_int_init_value(mp_int z, int value)
+mp_result
+mp_int_init_value(mp_int z, int value)
 {
-  mp_result res;
+   mp_result   res;
 
-  CHECK(z != NULL);
+   CHECK(z != NULL);
 
-  if((res = mp_int_init(z)) != MP_OK)
-    return res;
+   if ((res = mp_int_init(z)) != MP_OK)
+       return res;
 
-  return mp_int_set_value(z, value);
+   return mp_int_set_value(z, value);
 }
 
 /* }}} */
 
 /* {{{ mp_int_set_value(z, value) */
 
-mp_result  mp_int_set_value(mp_int z, int value)
+mp_result
+mp_int_set_value(mp_int z, int value)
 {
-  mp_size  ndig;
+   mp_size     ndig;
 
-  CHECK(z != NULL);
+   CHECK(z != NULL);
 
-  /* How many digits to copy */
-  ndig = (mp_size) MP_VALUE_DIGITS(value);
+   /* How many digits to copy */
+   ndig = (mp_size) MP_VALUE_DIGITS(value);
 
-  if(!s_pad(z, ndig))
-    return MP_MEMORY;
+   if (!s_pad(z, ndig))
+       return MP_MEMORY;
 
-  MP_USED(z) = (mp_size)s_vpack(value, MP_DIGITS(z));
-  MP_SIGN(z) = (value < 0) ? MP_NEG : MP_ZPOS;
+   MP_USED(z) = (mp_size) s_vpack(value, MP_DIGITS(z));
+   MP_SIGN(z) = (value < 0) ? MP_NEG : MP_ZPOS;
 
-  return MP_OK;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_clear(z) */
 
-void      mp_int_clear(mp_int z)
+void
+mp_int_clear(mp_int z)
 {
-  if(z == NULL)
-    return;
+   if (z == NULL)
+       return;
 
-  if(MP_DIGITS(z) != NULL) {
-    s_free(MP_DIGITS(z));
-    MP_DIGITS(z) = NULL;
-  }
+   if (MP_DIGITS(z) != NULL)
+   {
+       s_free(MP_DIGITS(z));
+       MP_DIGITS(z) = NULL;
+   }
 }
 
 /* }}} */
 
 /* {{{ mp_int_free(z) */
 
-void      mp_int_free(mp_int z)
+void
+mp_int_free(mp_int z)
 {
-  NRCHECK(z != NULL);
+   NRCHECK(z != NULL);
 
-  if(z->digits != NULL)
-    mp_int_clear(z);
+   if (z->digits != NULL)
+       mp_int_clear(z);
 
-  px_free(z);
+   px_free(z);
 }
 
 /* }}} */
 
 /* {{{ mp_int_copy(a, c) */
 
-mp_result mp_int_copy(mp_int a, mp_int c)
+mp_result
+mp_int_copy(mp_int a, mp_int c)
 {
-  CHECK(a != NULL && c != NULL);
+   CHECK(a != NULL && c != NULL);
 
-  if(a != c) {
-    mp_size   ua = MP_USED(a);
-    mp_digit *da, *dc;
+   if (a != c)
+   {
+       mp_size     ua = MP_USED(a);
+       mp_digit   *da,
+                  *dc;
 
-    if(!s_pad(c, ua))
-      return MP_MEMORY;
+       if (!s_pad(c, ua))
+           return MP_MEMORY;
 
-    da = MP_DIGITS(a); dc = MP_DIGITS(c);
-    COPY(da, dc, ua);
+       da = MP_DIGITS(a);
+       dc = MP_DIGITS(c);
+       COPY(da, dc, ua);
 
-    MP_USED(c) = ua;
-    MP_SIGN(c) = MP_SIGN(a);
-  }
+       MP_USED(c) = ua;
+       MP_SIGN(c) = MP_SIGN(a);
+   }
 
-  return MP_OK;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_swap(a, c) */
 
-void      mp_int_swap(mp_int a, mp_int c)
+void
+mp_int_swap(mp_int a, mp_int c)
 {
-  if(a != c) {
-    mpz_t tmp = *a;
+   if (a != c)
+   {
+       mpz_t       tmp = *a;
 
-    *a = *c;
-    *c = tmp;
-  }
+       *a = *c;
+       *c = tmp;
+   }
 }
 
 /* }}} */
 
 /* {{{ mp_int_zero(z) */
 
-void      mp_int_zero(mp_int z)
+void
+mp_int_zero(mp_int z)
 {
-  NRCHECK(z != NULL);
+   NRCHECK(z != NULL);
 
-  z->digits[0] = 0;
-  MP_USED(z) = 1;
-  MP_SIGN(z) = MP_ZPOS;
+   z->digits[0] = 0;
+   MP_USED(z) = 1;
+   MP_SIGN(z) = MP_ZPOS;
 }
 
 /* }}} */
 
 /* {{{ mp_int_abs(a, c) */
 
-mp_result mp_int_abs(mp_int a, mp_int c)
+mp_result
+mp_int_abs(mp_int a, mp_int c)
 {
-  mp_result res;
+   mp_result   res;
 
-  CHECK(a != NULL && c != NULL);
+   CHECK(a != NULL && c != NULL);
 
-  if((res = mp_int_copy(a, c)) != MP_OK)
-    return res;
+   if ((res = mp_int_copy(a, c)) != MP_OK)
+       return res;
 
-  MP_SIGN(c) = MP_ZPOS;
-  return MP_OK;
+   MP_SIGN(c) = MP_ZPOS;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_neg(a, c) */
 
-mp_result mp_int_neg(mp_int a, mp_int c)
+mp_result
+mp_int_neg(mp_int a, mp_int c)
 {
-  mp_result res;
+   mp_result   res;
 
-  CHECK(a != NULL && c != NULL);
+   CHECK(a != NULL && c != NULL);
 
-  if((res = mp_int_copy(a, c)) != MP_OK)
-    return res;
+   if ((res = mp_int_copy(a, c)) != MP_OK)
+       return res;
 
-  if(CMPZ(c) != 0)
-    MP_SIGN(c) = 1 - MP_SIGN(a);
+   if (CMPZ(c) != 0)
+       MP_SIGN(c) = 1 - MP_SIGN(a);
 
-  return MP_OK;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_add(a, b, c) */
 
-mp_result mp_int_add(mp_int a, mp_int b, mp_int c)
-{ 
-  mp_size  ua, ub, uc, max;
-
-  CHECK(a != NULL && b != NULL && c != NULL);
-
-  ua = MP_USED(a); ub = MP_USED(b); uc = MP_USED(c);
-  max = MAX(ua, ub);
-
-  if(MP_SIGN(a) == MP_SIGN(b)) {
-    /* Same sign -- add magnitudes, preserve sign of addends */
-    mp_digit carry;
+mp_result
+mp_int_add(mp_int a, mp_int b, mp_int c)
+{
+   mp_size     ua,
+               ub,
+               uc,
+               max;
 
-    if(!s_pad(c, max))
-      return MP_MEMORY;
+   CHECK(a != NULL && b != NULL && c != NULL);
 
-    carry = s_uadd(MP_DIGITS(a), MP_DIGITS(b), MP_DIGITS(c), ua, ub);
-    uc = max;
+   ua = MP_USED(a);
+   ub = MP_USED(b);
+   uc = MP_USED(c);
+   max = MAX(ua, ub);
 
-    if(carry) {
-      if(!s_pad(c, max + 1))
-   return MP_MEMORY;
+   if (MP_SIGN(a) == MP_SIGN(b))
+   {
+       /* Same sign -- add magnitudes, preserve sign of addends */
+       mp_digit    carry;
 
-      c->digits[max] = carry;
-      ++uc;
-    }
+       if (!s_pad(c, max))
+           return MP_MEMORY;
 
-    MP_USED(c) = uc;
-    MP_SIGN(c) = MP_SIGN(a);
+       carry = s_uadd(MP_DIGITS(a), MP_DIGITS(b), MP_DIGITS(c), ua, ub);
+       uc = max;
 
-  } 
-  else {
-    /* Different signs -- subtract magnitudes, preserve sign of greater */
-    mp_int  x, y;
-    int     cmp = s_ucmp(a, b); /* magnitude comparision, sign ignored */
+       if (carry)
+       {
+           if (!s_pad(c, max + 1))
+               return MP_MEMORY;
 
-    /* Set x to max(a, b), y to min(a, b) to simplify later code */
-    if(cmp >= 0) {
-      x = a; y = b;
-    } 
-    else {
-      x = b; y = a; 
-    }
+           c->digits[max] = carry;
+           ++uc;
+       }
 
-    if(!s_pad(c, MP_USED(x)))
-      return MP_MEMORY;
+       MP_USED(c) = uc;
+       MP_SIGN(c) = MP_SIGN(a);
 
-    /* Subtract smaller from larger */
-    s_usub(MP_DIGITS(x), MP_DIGITS(y), MP_DIGITS(c), MP_USED(x), MP_USED(y));
-    MP_USED(c) = MP_USED(x);
-    CLAMP(c);
-    
-    /* Give result the sign of the larger */
-    MP_SIGN(c) = MP_SIGN(x);
-  }
+   }
+   else
+   {
+       /* Different signs -- subtract magnitudes, preserve sign of greater */
+       mp_int      x,
+                   y;
+       int         cmp = s_ucmp(a, b); /* magnitude comparision, sign ignored */
+
+       /* Set x to max(a, b), y to min(a, b) to simplify later code */
+       if (cmp >= 0)
+       {
+           x = a;
+           y = b;
+       }
+       else
+       {
+           x = b;
+           y = a;
+       }
+
+       if (!s_pad(c, MP_USED(x)))
+           return MP_MEMORY;
+
+       /* Subtract smaller from larger */
+       s_usub(MP_DIGITS(x), MP_DIGITS(y), MP_DIGITS(c), MP_USED(x), MP_USED(y));
+       MP_USED(c) = MP_USED(x);
+       CLAMP(c);
+
+       /* Give result the sign of the larger */
+       MP_SIGN(c) = MP_SIGN(x);
+   }
 
-  return MP_OK;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_add_value(a, value, c) */
 
-mp_result mp_int_add_value(mp_int a, int value, mp_int c)
+mp_result
+mp_int_add_value(mp_int a, int value, mp_int c)
 {
-  mpz_t     vtmp;
-  mp_digit  vbuf[MP_VALUE_DIGITS(value)];
+   mpz_t       vtmp;
+   mp_digit    vbuf[MP_VALUE_DIGITS(value)];
 
-  s_fake(&vtmp, value, vbuf);
+   s_fake(&vtmp, value, vbuf);
 
-  return mp_int_add(a, &vtmp, c);
+   return mp_int_add(a, &vtmp, c);
 }
 
 /* }}} */
 
 /* {{{ mp_int_sub(a, b, c) */
 
-mp_result mp_int_sub(mp_int a, mp_int b, mp_int c)
+mp_result
+mp_int_sub(mp_int a, mp_int b, mp_int c)
 {
-  mp_size  ua, ub, uc, max;
+   mp_size     ua,
+               ub,
+               uc,
+               max;
 
-  CHECK(a != NULL && b != NULL && c != NULL);
+   CHECK(a != NULL && b != NULL && c != NULL);
 
-  ua = MP_USED(a); ub = MP_USED(b); uc = MP_USED(c);
-  max = MAX(ua, ub);
+   ua = MP_USED(a);
+   ub = MP_USED(b);
+   uc = MP_USED(c);
+   max = MAX(ua, ub);
 
-  if(MP_SIGN(a) != MP_SIGN(b)) {
-    /* Different signs -- add magnitudes and keep sign of a */
-    mp_digit carry;
+   if (MP_SIGN(a) != MP_SIGN(b))
+   {
+       /* Different signs -- add magnitudes and keep sign of a */
+       mp_digit    carry;
 
-    if(!s_pad(c, max))
-      return MP_MEMORY;
+       if (!s_pad(c, max))
+           return MP_MEMORY;
 
-    carry = s_uadd(MP_DIGITS(a), MP_DIGITS(b), MP_DIGITS(c), ua, ub);
-    uc = max;
+       carry = s_uadd(MP_DIGITS(a), MP_DIGITS(b), MP_DIGITS(c), ua, ub);
+       uc = max;
 
-    if(carry) {
-      if(!s_pad(c, max + 1))
-   return MP_MEMORY;
+       if (carry)
+       {
+           if (!s_pad(c, max + 1))
+               return MP_MEMORY;
 
-      c->digits[max] = carry;
-      ++uc;
-    }
+           c->digits[max] = carry;
+           ++uc;
+       }
 
-    MP_USED(c) = uc;
-    MP_SIGN(c) = MP_SIGN(a);
+       MP_USED(c) = uc;
+       MP_SIGN(c) = MP_SIGN(a);
 
-  } 
-  else {
-    /* Same signs -- subtract magnitudes */
-    mp_int  x, y;
-    mp_sign osign;
-    int     cmp = s_ucmp(a, b);
+   }
+   else
+   {
+       /* Same signs -- subtract magnitudes */
+       mp_int      x,
+                   y;
+       mp_sign     osign;
+       int         cmp = s_ucmp(a, b);
+
+       if (!s_pad(c, max))
+           return MP_MEMORY;
+
+       if (cmp >= 0)
+       {
+           x = a;
+           y = b;
+           osign = MP_ZPOS;
+       }
+       else
+       {
+           x = b;
+           y = a;
+           osign = MP_NEG;
+       }
+
+       if (MP_SIGN(a) == MP_NEG && cmp != 0)
+           osign = 1 - osign;
+
+       s_usub(MP_DIGITS(x), MP_DIGITS(y), MP_DIGITS(c), MP_USED(x), MP_USED(y));
+       MP_USED(c) = MP_USED(x);
+       CLAMP(c);
+
+       MP_SIGN(c) = osign;
+   }
 
-    if(!s_pad(c, max))
-      return MP_MEMORY;
+   return MP_OK;
+}
 
-    if(cmp >= 0) {
-      x = a; y = b; osign = MP_ZPOS;
-    } 
-    else {
-      x = b; y = a; osign = MP_NEG;
-    }
+/* }}} */
 
-    if(MP_SIGN(a) == MP_NEG && cmp != 0)
-      osign = 1 - osign;
+/* {{{ mp_int_sub_value(a, value, c) */
 
-    s_usub(MP_DIGITS(x), MP_DIGITS(y), MP_DIGITS(c), MP_USED(x), MP_USED(y));
-    MP_USED(c) = MP_USED(x);
-    CLAMP(c);
+mp_result
+mp_int_sub_value(mp_int a, int value, mp_int c)
+{
+   mpz_t       vtmp;
+   mp_digit    vbuf[MP_VALUE_DIGITS(value)];
 
-    MP_SIGN(c) = osign;
-  }
+   s_fake(&vtmp, value, vbuf);
 
-  return MP_OK;
+   return mp_int_sub(a, &vtmp, c);
 }
 
 /* }}} */
 
-/* {{{ mp_int_sub_value(a, value, c) */
+/* {{{ mp_int_mul(a, b, c) */
 
-mp_result mp_int_sub_value(mp_int a, int value, mp_int c)
+mp_result
+mp_int_mul(mp_int a, mp_int b, mp_int c)
 {
-  mpz_t     vtmp;
-  mp_digit  vbuf[MP_VALUE_DIGITS(value)];
+   mp_digit   *out;
+   mp_size     osize,
+               ua,
+               ub,
+               p = 0;
+   mp_sign     osign;
 
-  s_fake(&vtmp, value, vbuf);
+   CHECK(a != NULL && b != NULL && c != NULL);
 
-  return mp_int_sub(a, &vtmp, c);
-}
+   /* If either input is zero, we can shortcut multiplication */
+   if (mp_int_compare_zero(a) == 0 || mp_int_compare_zero(b) == 0)
+   {
+       mp_int_zero(c);
+       return MP_OK;
+   }
 
-/* }}} */
+   /* Output is positive if inputs have same sign, otherwise negative */
+   osign = (MP_SIGN(a) == MP_SIGN(b)) ? MP_ZPOS : MP_NEG;
 
-/* {{{ mp_int_mul(a, b, c) */
+   /*
+    * If the output is not equal to any of the inputs, we'll write the
+    * results there directly; otherwise, allocate a temporary space.
+    */
+   ua = MP_USED(a);
+   ub = MP_USED(b);
+   osize = ua + ub;
+
+   if (c == a || c == b)
+   {
+       p = ROUND_PREC(osize);
+       p = MAX(p, default_precision);
+
+       if ((out = s_alloc(p)) == NULL)
+           return MP_MEMORY;
+   }
+   else
+   {
+       if (!s_pad(c, osize))
+           return MP_MEMORY;
 
-mp_result mp_int_mul(mp_int a, mp_int b, mp_int c)
-{ 
-  mp_digit *out;
-  mp_size   osize, ua, ub, p = 0;
-  mp_sign   osign;
-
-  CHECK(a != NULL && b != NULL && c != NULL);
-
-  /* If either input is zero, we can shortcut multiplication */
-  if(mp_int_compare_zero(a) == 0 || mp_int_compare_zero(b) == 0) {
-    mp_int_zero(c);
-    return MP_OK;
-  }
-  
-  /* Output is positive if inputs have same sign, otherwise negative */
-  osign = (MP_SIGN(a) == MP_SIGN(b)) ? MP_ZPOS : MP_NEG;
-
-  /* If the output is not equal to any of the inputs, we'll write the
-     results there directly; otherwise, allocate a temporary space. */
-  ua = MP_USED(a); ub = MP_USED(b);
-  osize = ua + ub;
-
-  if(c == a || c == b) {
-    p = ROUND_PREC(osize);
-    p = MAX(p, default_precision);
-
-    if((out = s_alloc(p)) == NULL)
-      return MP_MEMORY;
-  } 
-  else {
-    if(!s_pad(c, osize))
-      return MP_MEMORY;
-    
-    out = MP_DIGITS(c);
-  }
-  ZERO(out, osize);
-
-  if(!s_kmul(MP_DIGITS(a), MP_DIGITS(b), out, ua, ub))
-    return MP_MEMORY;
-
-  /* If we allocated a new buffer, get rid of whatever memory c was
-     already using, and fix up its fields to reflect that.
-   */
-  if(out != MP_DIGITS(c)) {
-    s_free(MP_DIGITS(c));
-    MP_DIGITS(c) = out;
-    MP_ALLOC(c) = p;
-  }
-
-  MP_USED(c) = osize; /* might not be true, but we'll fix it ... */
-  CLAMP(c);           /* ... right here */
-  MP_SIGN(c) = osign;
-  
-  return MP_OK;
+       out = MP_DIGITS(c);
+   }
+   ZERO(out, osize);
+
+   if (!s_kmul(MP_DIGITS(a), MP_DIGITS(b), out, ua, ub))
+       return MP_MEMORY;
+
+   /*
+    * If we allocated a new buffer, get rid of whatever memory c was already
+    * using, and fix up its fields to reflect that.
+    */
+   if (out != MP_DIGITS(c))
+   {
+       s_free(MP_DIGITS(c));
+       MP_DIGITS(c) = out;
+       MP_ALLOC(c) = p;
+   }
+
+   MP_USED(c) = osize;         /* might not be true, but we'll fix it ... */
+   CLAMP(c);                   /* ... right here */
+   MP_SIGN(c) = osign;
+
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_mul_value(a, value, c) */
 
-mp_result mp_int_mul_value(mp_int a, int value, mp_int c)
+mp_result
+mp_int_mul_value(mp_int a, int value, mp_int c)
 {
-  mpz_t     vtmp;
-  mp_digit  vbuf[MP_VALUE_DIGITS(value)];
+   mpz_t       vtmp;
+   mp_digit    vbuf[MP_VALUE_DIGITS(value)];
 
-  s_fake(&vtmp, value, vbuf);
+   s_fake(&vtmp, value, vbuf);
 
-  return mp_int_mul(a, &vtmp, c);
+   return mp_int_mul(a, &vtmp, c);
 }
 
 /* }}} */
 
 /* {{{ mp_int_mul_pow2(a, p2, c) */
 
-mp_result mp_int_mul_pow2(mp_int a, int p2, mp_int c)
+mp_result
+mp_int_mul_pow2(mp_int a, int p2, mp_int c)
 {
-  mp_result res;
-  CHECK(a != NULL && c != NULL && p2 >= 0);
+   mp_result   res;
 
-  if((res = mp_int_copy(a, c)) != MP_OK)
-    return res;
+   CHECK(a != NULL && c != NULL && p2 >= 0);
 
-  if(s_qmul(c, (mp_size) p2))
-    return MP_OK;
-  else
-    return MP_MEMORY;
+   if ((res = mp_int_copy(a, c)) != MP_OK)
+       return res;
+
+   if (s_qmul(c, (mp_size) p2))
+       return MP_OK;
+   else
+       return MP_MEMORY;
 }
 
 /* }}} */
 
 /* {{{ mp_int_sqr(a, c) */
 
-mp_result mp_int_sqr(mp_int a, mp_int c)
-{ 
-  mp_digit *out;
-  mp_size   osize, p = 0;
+mp_result
+mp_int_sqr(mp_int a, mp_int c)
+{
+   mp_digit   *out;
+   mp_size     osize,
+               p = 0;
 
-  CHECK(a != NULL && c != NULL);
+   CHECK(a != NULL && c != NULL);
 
-  /* Get a temporary buffer big enough to hold the result */
-  osize = (mp_size) 2 * MP_USED(a);
-  if(a == c) {
-    p = ROUND_PREC(osize);
-    p = MAX(p, default_precision);
+   /* Get a temporary buffer big enough to hold the result */
+   osize = (mp_size) 2 *MP_USED(a);
 
-    if((out = s_alloc(p)) == NULL)
-      return MP_MEMORY;
-  } 
-  else {
-    if(!s_pad(c, osize)) 
-      return MP_MEMORY;
+   if (a == c)
+   {
+       p = ROUND_PREC(osize);
+       p = MAX(p, default_precision);
 
-    out = MP_DIGITS(c);
-  }
-  ZERO(out, osize);
+       if ((out = s_alloc(p)) == NULL)
+           return MP_MEMORY;
+   }
+   else
+   {
+       if (!s_pad(c, osize))
+           return MP_MEMORY;
 
-  s_ksqr(MP_DIGITS(a), out, MP_USED(a));
+       out = MP_DIGITS(c);
+   }
+   ZERO(out, osize);
+
+   s_ksqr(MP_DIGITS(a), out, MP_USED(a));
+
+   /*
+    * Get rid of whatever memory c was already using, and fix up its fields
+    * to reflect the new digit array it's using
+    */
+   if (out != MP_DIGITS(c))
+   {
+       s_free(MP_DIGITS(c));
+       MP_DIGITS(c) = out;
+       MP_ALLOC(c) = p;
+   }
 
-  /* Get rid of whatever memory c was already using, and fix up its
-     fields to reflect the new digit array it's using
-   */
-  if(out != MP_DIGITS(c)) {
-    s_free(MP_DIGITS(c));
-    MP_DIGITS(c) = out;
-    MP_ALLOC(c) = p;
-  }
+   MP_USED(c) = osize;         /* might not be true, but we'll fix it ... */
+   CLAMP(c);                   /* ... right here */
+   MP_SIGN(c) = MP_ZPOS;
 
-  MP_USED(c) = osize; /* might not be true, but we'll fix it ... */
-  CLAMP(c);           /* ... right here */
-  MP_SIGN(c) = MP_ZPOS;
-  
-  return MP_OK;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_div(a, b, q, r) */
 
-mp_result mp_int_div(mp_int a, mp_int b, mp_int q, mp_int r)
-{
-  int       cmp, last = 0, lg;
-  mp_result res = MP_OK;
-  mpz_t     temp[2];
-  mp_int    qout, rout;
-  mp_sign   sa = MP_SIGN(a), sb = MP_SIGN(b);
-
-  CHECK(a != NULL && b != NULL && q != r);
-  
-  if(CMPZ(b) == 0)
-    return MP_UNDEF;
-  else if((cmp = s_ucmp(a, b)) < 0) {
-    /* If |a| < |b|, no division is required:
-       q = 0, r = a
-     */
-    if(r && (res = mp_int_copy(a, r)) != MP_OK)
-      return res;
-
-    if(q)
-      mp_int_zero(q);
-
-    return MP_OK;
-  } 
-  else if(cmp == 0) {
-    /* If |a| = |b|, no division is required:
-       q = 1 or -1, r = 0
-     */
-    if(r)
-      mp_int_zero(r);
-
-    if(q) {
-      mp_int_zero(q);
-      q->digits[0] = 1;
-
-      if(sa != sb)
-   MP_SIGN(q) = MP_NEG;
-    }
-
-    return MP_OK;
-  } 
-
-  /* When |a| > |b|, real division is required.  We need someplace to
-     store quotient and remainder, but q and r are allowed to be NULL
-     or to overlap with the inputs.
-   */
-  if((lg = s_isp2(b)) < 0) {
-    if(q && b != q && (res = mp_int_copy(a, q)) == MP_OK) {
-      qout = q;
-    } 
-    else {
-      qout = TEMP(last);
-      SETUP(mp_int_init_copy(TEMP(last), a), last);
-    }
-
-    if(r && a != r && (res = mp_int_copy(b, r)) == MP_OK) {
-      rout = r;
-    } 
-    else {
-      rout = TEMP(last);
-      SETUP(mp_int_init_copy(TEMP(last), b), last);
-    }
-
-    if((res = s_udiv(qout, rout)) != MP_OK) goto CLEANUP;
-  } 
-  else {
-    if(q && (res = mp_int_copy(a, q)) != MP_OK) goto CLEANUP;
-    if(r && (res = mp_int_copy(a, r)) != MP_OK) goto CLEANUP;
-
-    if(q) s_qdiv(q, (mp_size) lg); qout = q;
-    if(r) s_qmod(r, (mp_size) lg); rout = r;
-  }
-
-  /* Recompute signs for output */
-  if(rout) { 
-    MP_SIGN(rout) = sa;
-    if(CMPZ(rout) == 0)
-      MP_SIGN(rout) = MP_ZPOS;
-  }
-  if(qout) {
-    MP_SIGN(qout) = (sa == sb) ? MP_ZPOS : MP_NEG;
-    if(CMPZ(qout) == 0)
-      MP_SIGN(qout) = MP_ZPOS;
-  }
-
-  if(q && (res = mp_int_copy(qout, q)) != MP_OK) goto CLEANUP;
-  if(r && (res = mp_int_copy(rout, r)) != MP_OK) goto CLEANUP;
-
- CLEANUP:
-  while(--last >= 0)
-    mp_int_clear(TEMP(last));
-
-  return res;
+mp_result
+mp_int_div(mp_int a, mp_int b, mp_int q, mp_int r)
+{
+   int         cmp,
+               last = 0,
+               lg;
+   mp_result   res = MP_OK;
+   mpz_t       temp[2];
+   mp_int      qout,
+               rout;
+   mp_sign     sa = MP_SIGN(a),
+               sb = MP_SIGN(b);
+
+   CHECK(a != NULL && b != NULL && q != r);
+
+   if (CMPZ(b) == 0)
+       return MP_UNDEF;
+   else if ((cmp = s_ucmp(a, b)) < 0)
+   {
+       /*
+        * If |a| < |b|, no division is required: q = 0, r = a
+        */
+       if (r && (res = mp_int_copy(a, r)) != MP_OK)
+           return res;
+
+       if (q)
+           mp_int_zero(q);
+
+       return MP_OK;
+   }
+   else if (cmp == 0)
+   {
+       /*
+        * If |a| = |b|, no division is required: q = 1 or -1, r = 0
+        */
+       if (r)
+           mp_int_zero(r);
+
+       if (q)
+       {
+           mp_int_zero(q);
+           q->digits[0] = 1;
+
+           if (sa != sb)
+               MP_SIGN(q) = MP_NEG;
+       }
+
+       return MP_OK;
+   }
+
+   /*
+    * When |a| > |b|, real division is required.  We need someplace to store
+    * quotient and remainder, but q and r are allowed to be NULL or to
+    * overlap with the inputs.
+    */
+   if ((lg = s_isp2(b)) < 0)
+   {
+       if (q && b != q && (res = mp_int_copy(a, q)) == MP_OK)
+       {
+           qout = q;
+       }
+       else
+       {
+           qout = TEMP(last);
+           SETUP(mp_int_init_copy(TEMP(last), a), last);
+       }
+
+       if (r && a != r && (res = mp_int_copy(b, r)) == MP_OK)
+       {
+           rout = r;
+       }
+       else
+       {
+           rout = TEMP(last);
+           SETUP(mp_int_init_copy(TEMP(last), b), last);
+       }
+
+       if ((res = s_udiv(qout, rout)) != MP_OK)
+           goto CLEANUP;
+   }
+   else
+   {
+       if (q && (res = mp_int_copy(a, q)) != MP_OK)
+           goto CLEANUP;
+       if (r && (res = mp_int_copy(a, r)) != MP_OK)
+           goto CLEANUP;
+
+       if (q)
+           s_qdiv(q, (mp_size) lg);
+       qout = q;
+       if (r)
+           s_qmod(r, (mp_size) lg);
+       rout = r;
+   }
+
+   /* Recompute signs for output */
+   if (rout)
+   {
+       MP_SIGN(rout) = sa;
+       if (CMPZ(rout) == 0)
+           MP_SIGN(rout) = MP_ZPOS;
+   }
+   if (qout)
+   {
+       MP_SIGN(qout) = (sa == sb) ? MP_ZPOS : MP_NEG;
+       if (CMPZ(qout) == 0)
+           MP_SIGN(qout) = MP_ZPOS;
+   }
+
+   if (q && (res = mp_int_copy(qout, q)) != MP_OK)
+       goto CLEANUP;
+   if (r && (res = mp_int_copy(rout, r)) != MP_OK)
+       goto CLEANUP;
+
+CLEANUP:
+   while (--last >= 0)
+       mp_int_clear(TEMP(last));
+
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_mod(a, m, c) */
 
-mp_result mp_int_mod(mp_int a, mp_int m, mp_int c)
+mp_result
+mp_int_mod(mp_int a, mp_int m, mp_int c)
 {
-  mp_result res;
-  mpz_t     tmp;
-  mp_int    out;
+   mp_result   res;
+   mpz_t       tmp;
+   mp_int      out;
 
-  if(m == c) {
-    if((res = mp_int_init(&tmp)) != MP_OK)
-      return res;
+   if (m == c)
+   {
+       if ((res = mp_int_init(&tmp)) != MP_OK)
+           return res;
 
-    out = &tmp;
-  } 
-  else {
-    out = c;
-  }
+       out = &tmp;
+   }
+   else
+   {
+       out = c;
+   }
 
-  if((res = mp_int_div(a, m, NULL, out)) != MP_OK)
-    goto CLEANUP;
+   if ((res = mp_int_div(a, m, NULL, out)) != MP_OK)
+       goto CLEANUP;
 
-  if(CMPZ(out) < 0)
-    res = mp_int_add(out, m, c);
-  else
-    res = mp_int_copy(out, c);
+   if (CMPZ(out) < 0)
+       res = mp_int_add(out, m, c);
+   else
+       res = mp_int_copy(out, c);
 
- CLEANUP:
-  if(out != c)
-    mp_int_clear(&tmp);
+CLEANUP:
+   if (out != c)
+       mp_int_clear(&tmp);
 
-  return res;
+   return res;
 }
 
 /* }}} */
@@ -1007,379 +1114,416 @@ mp_result mp_int_mod(mp_int a, mp_int m, mp_int c)
 
 /* {{{ mp_int_div_value(a, value, q, r) */
 
-mp_result mp_int_div_value(mp_int a, int value, mp_int q, int *r)
+mp_result
+mp_int_div_value(mp_int a, int value, mp_int q, int *r)
 {
-  mpz_t     vtmp, rtmp;
-  mp_digit  vbuf[MP_VALUE_DIGITS(value)];
-  mp_result res;
+   mpz_t       vtmp,
+               rtmp;
+   mp_digit    vbuf[MP_VALUE_DIGITS(value)];
+   mp_result   res;
 
-  if((res = mp_int_init(&rtmp)) != MP_OK) return res;
-  s_fake(&vtmp, value, vbuf);
+   if ((res = mp_int_init(&rtmp)) != MP_OK)
+       return res;
+   s_fake(&vtmp, value, vbuf);
 
-  if((res = mp_int_div(a, &vtmp, q, &rtmp)) != MP_OK)
-    goto CLEANUP;
+   if ((res = mp_int_div(a, &vtmp, q, &rtmp)) != MP_OK)
+       goto CLEANUP;
 
-  if(r)
-    (void) mp_int_to_int(&rtmp, r); /* can't fail */
+   if (r)
+       (void) mp_int_to_int(&rtmp, r); /* can't fail */
 
- CLEANUP:
-  mp_int_clear(&rtmp);
-  return res;
+CLEANUP:
+   mp_int_clear(&rtmp);
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_div_pow2(a, p2, q, r) */
 
-mp_result mp_int_div_pow2(mp_int a, int p2, mp_int q, mp_int r)
+mp_result
+mp_int_div_pow2(mp_int a, int p2, mp_int q, mp_int r)
 {
-  mp_result res = MP_OK;
+   mp_result   res = MP_OK;
+
+   CHECK(a != NULL && p2 >= 0 && q != r);
 
-  CHECK(a != NULL && p2 >= 0 && q != r);
+   if (q != NULL && (res = mp_int_copy(a, q)) == MP_OK)
+       s_qdiv(q, (mp_size) p2);
 
-  if(q != NULL && (res = mp_int_copy(a, q)) == MP_OK)
-    s_qdiv(q, (mp_size) p2);
-  
-  if(res == MP_OK && r != NULL && (res = mp_int_copy(a, r)) == MP_OK)
-    s_qmod(r, (mp_size) p2);
+   if (res == MP_OK && r != NULL && (res = mp_int_copy(a, r)) == MP_OK)
+       s_qmod(r, (mp_size) p2);
 
-  return res;
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_expt(a, b, c) */
 
-mp_result mp_int_expt(mp_int a, int b, mp_int c)
+mp_result
+mp_int_expt(mp_int a, int b, mp_int c)
 {
-  mpz_t     t;
-  mp_result res;
-  unsigned int v = abs(b);
-  
-  CHECK(b >= 0 && c != NULL);
+   mpz_t       t;
+   mp_result   res;
+   unsigned int v = abs(b);
 
-  if((res = mp_int_init_copy(&t, a)) != MP_OK)
-    return res;
+   CHECK(b >= 0 && c != NULL);
 
-  (void) mp_int_set_value(c, 1);
-  while(v != 0) {
-    if(v & 1) {
-      if((res = mp_int_mul(c, &t, c)) != MP_OK)
-   goto CLEANUP;
-    }
+   if ((res = mp_int_init_copy(&t, a)) != MP_OK)
+       return res;
 
-    v >>= 1;
-    if(v == 0) break;
+   (void) mp_int_set_value(c, 1);
+   while (v != 0)
+   {
+       if (v & 1)
+       {
+           if ((res = mp_int_mul(c, &t, c)) != MP_OK)
+               goto CLEANUP;
+       }
 
-    if((res = mp_int_sqr(&t, &t)) != MP_OK)
-      goto CLEANUP;
-  }
-  
- CLEANUP:
-  mp_int_clear(&t);
-  return res;
+       v >>= 1;
+       if (v == 0)
+           break;
+
+       if ((res = mp_int_sqr(&t, &t)) != MP_OK)
+           goto CLEANUP;
+   }
+
+CLEANUP:
+   mp_int_clear(&t);
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_expt_value(a, b, c) */
 
-mp_result mp_int_expt_value(int a, int b, mp_int c)
+mp_result
+mp_int_expt_value(int a, int b, mp_int c)
 {
-  mpz_t     t;
-  mp_result res;
-  unsigned int v = abs(b);
-  
-  CHECK(b >= 0 && c != NULL);
+   mpz_t       t;
+   mp_result   res;
+   unsigned int v = abs(b);
+
+   CHECK(b >= 0 && c != NULL);
 
-  if((res = mp_int_init_value(&t, a)) != MP_OK)
-    return res;
+   if ((res = mp_int_init_value(&t, a)) != MP_OK)
+       return res;
 
-  (void) mp_int_set_value(c, 1);
-  while(v != 0) {
-    if(v & 1) {
-      if((res = mp_int_mul(c, &t, c)) != MP_OK)
-   goto CLEANUP;
-    }
+   (void) mp_int_set_value(c, 1);
+   while (v != 0)
+   {
+       if (v & 1)
+       {
+           if ((res = mp_int_mul(c, &t, c)) != MP_OK)
+               goto CLEANUP;
+       }
 
-    v >>= 1;
-    if(v == 0) break;
+       v >>= 1;
+       if (v == 0)
+           break;
 
-    if((res = mp_int_sqr(&t, &t)) != MP_OK)
-      goto CLEANUP;
-  }
-  
- CLEANUP:
-  mp_int_clear(&t);
-  return res;
+       if ((res = mp_int_sqr(&t, &t)) != MP_OK)
+           goto CLEANUP;
+   }
+
+CLEANUP:
+   mp_int_clear(&t);
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_compare(a, b) */
 
-int       mp_int_compare(mp_int a, mp_int b)
-{ 
-  mp_sign sa;
+int
+mp_int_compare(mp_int a, mp_int b)
+{
+   mp_sign     sa;
 
-  CHECK(a != NULL && b != NULL);
+   CHECK(a != NULL && b != NULL);
 
-  sa = MP_SIGN(a);
-  if(sa == MP_SIGN(b)) {
-    int cmp = s_ucmp(a, b);
+   sa = MP_SIGN(a);
+   if (sa == MP_SIGN(b))
+   {
+       int         cmp = s_ucmp(a, b);
 
-    /* If they're both zero or positive, the normal comparison
-       applies; if both negative, the sense is reversed. */
-    if(sa == MP_ZPOS) 
-      return cmp;
-    else
-      return -cmp;
+       /*
+        * If they're both zero or positive, the normal comparison applies; if
+        * both negative, the sense is reversed.
+        */
+       if (sa == MP_ZPOS)
+           return cmp;
+       else
+           return -cmp;
 
-  } 
-  else {
-    if(sa == MP_ZPOS)
-      return 1;
-    else
-      return -1;
-  }
+   }
+   else
+   {
+       if (sa == MP_ZPOS)
+           return 1;
+       else
+           return -1;
+   }
 }
 
 /* }}} */
 
 /* {{{ mp_int_compare_unsigned(a, b) */
 
-int       mp_int_compare_unsigned(mp_int a, mp_int b)
-{ 
-  NRCHECK(a != NULL && b != NULL);
+int
+mp_int_compare_unsigned(mp_int a, mp_int b)
+{
+   NRCHECK(a != NULL && b != NULL);
 
-  return s_ucmp(a, b);
+   return s_ucmp(a, b);
 }
 
 /* }}} */
 
 /* {{{ mp_int_compare_zero(z) */
 
-int       mp_int_compare_zero(mp_int z)
-{ 
-  NRCHECK(z != NULL);
+int
+mp_int_compare_zero(mp_int z)
+{
+   NRCHECK(z != NULL);
 
-  if(MP_USED(z) == 1 && z->digits[0] == 0)
-    return 0;
-  else if(MP_SIGN(z) == MP_ZPOS)
-    return 1;
-  else 
-    return -1;
+   if (MP_USED(z) == 1 && z->digits[0] == 0)
+       return 0;
+   else if (MP_SIGN(z) == MP_ZPOS)
+       return 1;
+   else
+       return -1;
 }
 
 /* }}} */
 
 /* {{{ mp_int_compare_value(z, value) */
 
-int       mp_int_compare_value(mp_int z, int value)
+int
+mp_int_compare_value(mp_int z, int value)
 {
-  mp_sign vsign = (value < 0) ? MP_NEG : MP_ZPOS;
-  int     cmp;
+   mp_sign     vsign = (value < 0) ? MP_NEG : MP_ZPOS;
+   int         cmp;
 
-  CHECK(z != NULL);
+   CHECK(z != NULL);
 
-  if(vsign == MP_SIGN(z)) {
-    cmp = s_vcmp(z, value);
+   if (vsign == MP_SIGN(z))
+   {
+       cmp = s_vcmp(z, value);
 
-    if(vsign == MP_ZPOS)
-      return cmp;
-    else
-      return -cmp;
-  } 
-  else {
-    if(value < 0)
-      return 1;
-    else
-      return -1;
-  }
+       if (vsign == MP_ZPOS)
+           return cmp;
+       else
+           return -cmp;
+   }
+   else
+   {
+       if (value < 0)
+           return 1;
+       else
+           return -1;
+   }
 }
 
 /* }}} */
 
 /* {{{ mp_int_exptmod(a, b, m, c) */
 
-mp_result mp_int_exptmod(mp_int a, mp_int b, mp_int m, mp_int c)
-{ 
-  mp_result res;
-  mp_size   um;
-  mpz_t     temp[3];
-  mp_int    s;
-  int       last = 0;
+mp_result
+mp_int_exptmod(mp_int a, mp_int b, mp_int m, mp_int c)
+{
+   mp_result   res;
+   mp_size     um;
+   mpz_t       temp[3];
+   mp_int      s;
+   int         last = 0;
 
-  CHECK(a != NULL && b != NULL && c != NULL && m != NULL);
+   CHECK(a != NULL && b != NULL && c != NULL && m != NULL);
 
-  /* Zero moduli and negative exponents are not considered. */
-  if(CMPZ(m) == 0)
-    return MP_UNDEF;
-  if(CMPZ(b) < 0)
-    return MP_RANGE;
+   /* Zero moduli and negative exponents are not considered. */
+   if (CMPZ(m) == 0)
+       return MP_UNDEF;
+   if (CMPZ(b) < 0)
+       return MP_RANGE;
 
-  um = MP_USED(m);
-  SETUP(mp_int_init_size(TEMP(0), 2 * um), last);
-  SETUP(mp_int_init_size(TEMP(1), 2 * um), last);
+   um = MP_USED(m);
+   SETUP(mp_int_init_size(TEMP(0), 2 * um), last);
+   SETUP(mp_int_init_size(TEMP(1), 2 * um), last);
 
-  if(c == b || c == m) {
-    SETUP(mp_int_init_size(TEMP(2), 2 * um), last);
-    s = TEMP(2);
-  } 
-  else {
-    s = c;
-  }
-  
-  if((res = mp_int_mod(a, m, TEMP(0))) != MP_OK) goto CLEANUP;
+   if (c == b || c == m)
+   {
+       SETUP(mp_int_init_size(TEMP(2), 2 * um), last);
+       s = TEMP(2);
+   }
+   else
+   {
+       s = c;
+   }
 
-  if((res = s_brmu(TEMP(1), m)) != MP_OK) goto CLEANUP;
+   if ((res = mp_int_mod(a, m, TEMP(0))) != MP_OK)
+       goto CLEANUP;
 
-  if((res = s_embar(TEMP(0), b, m, TEMP(1), s)) != MP_OK)
-    goto CLEANUP;
+   if ((res = s_brmu(TEMP(1), m)) != MP_OK)
+       goto CLEANUP;
 
-  res = mp_int_copy(s, c);
+   if ((res = s_embar(TEMP(0), b, m, TEMP(1), s)) != MP_OK)
+       goto CLEANUP;
 
- CLEANUP:
-  while(--last >= 0)
-    mp_int_clear(TEMP(last));
+   res = mp_int_copy(s, c);
 
-  return res;
+CLEANUP:
+   while (--last >= 0)
+       mp_int_clear(TEMP(last));
+
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_exptmod_evalue(a, value, m, c) */
 
-mp_result mp_int_exptmod_evalue(mp_int a, int value, mp_int m, mp_int c)
+mp_result
+mp_int_exptmod_evalue(mp_int a, int value, mp_int m, mp_int c)
 {
-  mpz_t    vtmp;
-  mp_digit vbuf[MP_VALUE_DIGITS(value)];
+   mpz_t       vtmp;
+   mp_digit    vbuf[MP_VALUE_DIGITS(value)];
 
-  s_fake(&vtmp, value, vbuf);
+   s_fake(&vtmp, value, vbuf);
 
-  return mp_int_exptmod(a, &vtmp, m, c);
+   return mp_int_exptmod(a, &vtmp, m, c);
 }
 
 /* }}} */
 
 /* {{{ mp_int_exptmod_bvalue(v, b, m, c) */
 
-mp_result mp_int_exptmod_bvalue(int value, mp_int b,
-               mp_int m, mp_int c)
+mp_result
+mp_int_exptmod_bvalue(int value, mp_int b,
+                     mp_int m, mp_int c)
 {
-  mpz_t    vtmp;
-  mp_digit vbuf[MP_VALUE_DIGITS(value)];
+   mpz_t       vtmp;
+   mp_digit    vbuf[MP_VALUE_DIGITS(value)];
 
-  s_fake(&vtmp, value, vbuf);
+   s_fake(&vtmp, value, vbuf);
 
-  return mp_int_exptmod(&vtmp, b, m, c);
+   return mp_int_exptmod(&vtmp, b, m, c);
 }
 
 /* }}} */
 
 /* {{{ mp_int_exptmod_known(a, b, m, mu, c) */
 
-mp_result mp_int_exptmod_known(mp_int a, mp_int b, mp_int m, mp_int mu, mp_int c)
+mp_result
+mp_int_exptmod_known(mp_int a, mp_int b, mp_int m, mp_int mu, mp_int c)
 {
-  mp_result res;
-  mp_size   um;
-  mpz_t     temp[2];
-  mp_int    s;
-  int       last = 0;
+   mp_result   res;
+   mp_size     um;
+   mpz_t       temp[2];
+   mp_int      s;
+   int         last = 0;
+
+   CHECK(a && b && m && c);
 
-  CHECK(a && b && m && c);
+   /* Zero moduli and negative exponents are not considered. */
+   if (CMPZ(m) == 0)
+       return MP_UNDEF;
+   if (CMPZ(b) < 0)
+       return MP_RANGE;
 
-  /* Zero moduli and negative exponents are not considered. */
-  if(CMPZ(m) == 0)
-    return MP_UNDEF;
-  if(CMPZ(b) < 0)
-    return MP_RANGE;
+   um = MP_USED(m);
+   SETUP(mp_int_init_size(TEMP(0), 2 * um), last);
 
-  um = MP_USED(m);
-  SETUP(mp_int_init_size(TEMP(0), 2 * um), last);
+   if (c == b || c == m)
+   {
+       SETUP(mp_int_init_size(TEMP(1), 2 * um), last);
+       s = TEMP(1);
+   }
+   else
+   {
+       s = c;
+   }
 
-  if(c == b || c == m) {
-    SETUP(mp_int_init_size(TEMP(1), 2 * um), last);
-    s = TEMP(1);
-  } 
-  else {
-    s = c;
-  }
-  
-  if((res = mp_int_mod(a, m, TEMP(0))) != MP_OK) goto CLEANUP;
+   if ((res = mp_int_mod(a, m, TEMP(0))) != MP_OK)
+       goto CLEANUP;
 
-  if((res = s_embar(TEMP(0), b, m, mu, s)) != MP_OK)
-    goto CLEANUP;
+   if ((res = s_embar(TEMP(0), b, m, mu, s)) != MP_OK)
+       goto CLEANUP;
 
-  res = mp_int_copy(s, c);
+   res = mp_int_copy(s, c);
 
- CLEANUP:
-  while(--last >= 0)
-    mp_int_clear(TEMP(last));
+CLEANUP:
+   while (--last >= 0)
+       mp_int_clear(TEMP(last));
 
-  return res;
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_redux_const(m, c) */
 
-mp_result mp_int_redux_const(mp_int m, mp_int c)
+mp_result
+mp_int_redux_const(mp_int m, mp_int c)
 {
-  CHECK(m != NULL && c != NULL && m != c);
+   CHECK(m != NULL && c != NULL && m != c);
 
-  return s_brmu(c, m);
+   return s_brmu(c, m);
 }
 
 /* }}} */
 
 /* {{{ mp_int_invmod(a, m, c) */
 
-mp_result mp_int_invmod(mp_int a, mp_int m, mp_int c)
+mp_result
+mp_int_invmod(mp_int a, mp_int m, mp_int c)
 {
-  mp_result res;
-  mp_sign   sa;
-  int       last = 0;
-  mpz_t     temp[2];
+   mp_result   res;
+   mp_sign     sa;
+   int         last = 0;
+   mpz_t       temp[2];
 
-  CHECK(a != NULL && m != NULL && c != NULL);
+   CHECK(a != NULL && m != NULL && c != NULL);
 
-  if(CMPZ(a) == 0 || CMPZ(m) <= 0)
-    return MP_RANGE;
+   if (CMPZ(a) == 0 || CMPZ(m) <= 0)
+       return MP_RANGE;
 
-  sa = MP_SIGN(a); /* need this for the result later */
+   sa = MP_SIGN(a);            /* need this for the result later */
 
-  for(last = 0; last < 2; ++last)
-    if((res = mp_int_init(TEMP(last))) != MP_OK)
-      goto CLEANUP;
+   for (last = 0; last < 2; ++last)
+       if ((res = mp_int_init(TEMP(last))) != MP_OK)
+           goto CLEANUP;
 
-  if((res = mp_int_egcd(a, m, TEMP(0), TEMP(1), NULL)) != MP_OK) 
-    goto CLEANUP;
+   if ((res = mp_int_egcd(a, m, TEMP(0), TEMP(1), NULL)) != MP_OK)
+       goto CLEANUP;
 
-  if(mp_int_compare_value(TEMP(0), 1) != 0) {
-    res = MP_UNDEF;
-    goto CLEANUP;
-  }
+   if (mp_int_compare_value(TEMP(0), 1) != 0)
+   {
+       res = MP_UNDEF;
+       goto CLEANUP;
+   }
 
-  /* It is first necessary to constrain the value to the proper range */
-  if((res = mp_int_mod(TEMP(1), m, TEMP(1))) != MP_OK)
-    goto CLEANUP;
+   /* It is first necessary to constrain the value to the proper range */
+   if ((res = mp_int_mod(TEMP(1), m, TEMP(1))) != MP_OK)
+       goto CLEANUP;
 
-  /* Now, if 'a' was originally negative, the value we have is
-     actually the magnitude of the negative representative; to get the
-     positive value we have to subtract from the modulus.  Otherwise,
-     the value is okay as it stands.
-   */
-  if(sa == MP_NEG)
-    res = mp_int_sub(m, TEMP(1), c);
-  else
-    res = mp_int_copy(TEMP(1), c);
+   /*
+    * Now, if 'a' was originally negative, the value we have is actually the
+    * magnitude of the negative representative; to get the positive value we
+    * have to subtract from the modulus.  Otherwise, the value is okay as it
+    * stands.
+    */
+   if (sa == MP_NEG)
+       res = mp_int_sub(m, TEMP(1), c);
+   else
+       res = mp_int_copy(TEMP(1), c);
 
- CLEANUP:
-  while(--last >= 0)
-    mp_int_clear(TEMP(last));
+CLEANUP:
+   while (--last >= 0)
+       mp_int_clear(TEMP(last));
 
-  return res;
+   return res;
 }
 
 /* }}} */
@@ -1387,79 +1531,91 @@ mp_result mp_int_invmod(mp_int a, mp_int m, mp_int c)
 /* {{{ mp_int_gcd(a, b, c) */
 
 /* Binary GCD algorithm due to Josef Stein, 1961 */
-mp_result mp_int_gcd(mp_int a, mp_int b, mp_int c)
-{ 
-  int       ca, cb, k = 0;
-  mpz_t     u, v, t;
-  mp_result res;
-
-  CHECK(a != NULL && b != NULL && c != NULL);
-
-  ca = CMPZ(a);
-  cb = CMPZ(b);
-  if(ca == 0 && cb == 0)
-    return MP_UNDEF;
-  else if(ca == 0) 
-    return mp_int_abs(b, c);
-  else if(cb == 0) 
-    return mp_int_abs(a, c);
-
-  if((res = mp_int_init(&t)) != MP_OK)
-    return res;
-  if((res = mp_int_init_copy(&u, a)) != MP_OK)
-    goto U;
-  if((res = mp_int_init_copy(&v, b)) != MP_OK)
-    goto V;
-
-  MP_SIGN(&u) = MP_ZPOS; MP_SIGN(&v) = MP_ZPOS;
-
-  { /* Divide out common factors of 2 from u and v */
-    int div2_u = s_dp2k(&u), div2_v = s_dp2k(&v);
-   
-    k = MIN(div2_u, div2_v);
-    s_qdiv(&u, (mp_size) k);
-    s_qdiv(&v, (mp_size) k);
-  }
-  
-  if(mp_int_is_odd(&u)) {
-    if((res = mp_int_neg(&v, &t)) != MP_OK)
-      goto CLEANUP;
-  } 
-  else {
-    if((res = mp_int_copy(&u, &t)) != MP_OK)
-      goto CLEANUP;
-  }
-
-  for(;;) {
-    s_qdiv(&t, s_dp2k(&t));
-
-    if(CMPZ(&t) > 0) {
-      if((res = mp_int_copy(&t, &u)) != MP_OK)
-   goto CLEANUP;
-    } 
-    else {
-      if((res = mp_int_neg(&t, &v)) != MP_OK)
-   goto CLEANUP;
-    }
-
-    if((res = mp_int_sub(&u, &v, &t)) != MP_OK)
-      goto CLEANUP;
-
-    if(CMPZ(&t) == 0)
-      break;
-  } 
-
-  if((res = mp_int_abs(&u, c)) != MP_OK)
-    goto CLEANUP;
-  if(!s_qmul(c, (mp_size) k))
-    res = MP_MEMORY;
-  
- CLEANUP:
-  mp_int_clear(&v);
- V: mp_int_clear(&u);
- U: mp_int_clear(&t);
-
-  return res;
+mp_result
+mp_int_gcd(mp_int a, mp_int b, mp_int c)
+{
+   int         ca,
+               cb,
+               k = 0;
+   mpz_t       u,
+               v,
+               t;
+   mp_result   res;
+
+   CHECK(a != NULL && b != NULL && c != NULL);
+
+   ca = CMPZ(a);
+   cb = CMPZ(b);
+   if (ca == 0 && cb == 0)
+       return MP_UNDEF;
+   else if (ca == 0)
+       return mp_int_abs(b, c);
+   else if (cb == 0)
+       return mp_int_abs(a, c);
+
+   if ((res = mp_int_init(&t)) != MP_OK)
+       return res;
+   if ((res = mp_int_init_copy(&u, a)) != MP_OK)
+       goto U;
+   if ((res = mp_int_init_copy(&v, b)) != MP_OK)
+       goto V;
+
+   MP_SIGN(&u) = MP_ZPOS;
+   MP_SIGN(&v) = MP_ZPOS;
+
+   {                           /* Divide out common factors of 2 from u and v */
+       int         div2_u = s_dp2k(&u),
+                   div2_v = s_dp2k(&v);
+
+       k = MIN(div2_u, div2_v);
+       s_qdiv(&u, (mp_size) k);
+       s_qdiv(&v, (mp_size) k);
+   }
+
+   if (mp_int_is_odd(&u))
+   {
+       if ((res = mp_int_neg(&v, &t)) != MP_OK)
+           goto CLEANUP;
+   }
+   else
+   {
+       if ((res = mp_int_copy(&u, &t)) != MP_OK)
+           goto CLEANUP;
+   }
+
+   for (;;)
+   {
+       s_qdiv(&t, s_dp2k(&t));
+
+       if (CMPZ(&t) > 0)
+       {
+           if ((res = mp_int_copy(&t, &u)) != MP_OK)
+               goto CLEANUP;
+       }
+       else
+       {
+           if ((res = mp_int_neg(&t, &v)) != MP_OK)
+               goto CLEANUP;
+       }
+
+       if ((res = mp_int_sub(&u, &v, &t)) != MP_OK)
+           goto CLEANUP;
+
+       if (CMPZ(&t) == 0)
+           break;
+   }
+
+   if ((res = mp_int_abs(&u, c)) != MP_OK)
+       goto CLEANUP;
+   if (!s_qmul(c, (mp_size) k))
+       res = MP_MEMORY;
+
+CLEANUP:
+   mp_int_clear(&v);
+V: mp_int_clear(&u);
+U: mp_int_clear(&t);
+
+   return res;
 }
 
 /* }}} */
@@ -1470,308 +1626,361 @@ mp_result mp_int_gcd(mp_int a, mp_int b, mp_int c)
    of the elementary matrix operations as we go, so we can get values
    x and y satisfying c = ax + by.
  */
-mp_result mp_int_egcd(mp_int a, mp_int b, mp_int c, 
-             mp_int x, mp_int y)
-{ 
-  int       k, last = 0, ca, cb;
-  mpz_t     temp[8];
-  mp_result res;
-  
-  CHECK(a != NULL && b != NULL && c != NULL && 
-   (x != NULL || y != NULL));
-
-  ca = CMPZ(a);
-  cb = CMPZ(b);
-  if(ca == 0 && cb == 0)
-    return MP_UNDEF;
-  else if(ca == 0) {
-    if((res = mp_int_abs(b, c)) != MP_OK) return res;
-    mp_int_zero(x); (void) mp_int_set_value(y, 1); return MP_OK;
-  } 
-  else if(cb == 0) {
-    if((res = mp_int_abs(a, c)) != MP_OK) return res;
-    (void) mp_int_set_value(x, 1); mp_int_zero(y); return MP_OK;
-  }
-
-  /* Initialize temporaries:
-     A:0, B:1, C:2, D:3, u:4, v:5, ou:6, ov:7 */
-  for(last = 0; last < 4; ++last) {
-    if((res = mp_int_init(TEMP(last))) != MP_OK)
-      goto CLEANUP;
-  }
-  TEMP(0)->digits[0] = 1;
-  TEMP(3)->digits[0] = 1;
-
-  SETUP(mp_int_init_copy(TEMP(4), a), last);
-  SETUP(mp_int_init_copy(TEMP(5), b), last);
-
-  /* We will work with absolute values here */
-  MP_SIGN(TEMP(4)) = MP_ZPOS;
-  MP_SIGN(TEMP(5)) = MP_ZPOS;
-
-  { /* Divide out common factors of 2 from u and v */
-    int  div2_u = s_dp2k(TEMP(4)), div2_v = s_dp2k(TEMP(5));
-    
-    k = MIN(div2_u, div2_v);
-    s_qdiv(TEMP(4), k);
-    s_qdiv(TEMP(5), k);
-  }
-
-  SETUP(mp_int_init_copy(TEMP(6), TEMP(4)), last);
-  SETUP(mp_int_init_copy(TEMP(7), TEMP(5)), last);
-
-  for(;;) {
-    while(mp_int_is_even(TEMP(4))) {
-      s_qdiv(TEMP(4), 1);
-      
-      if(mp_int_is_odd(TEMP(0)) || mp_int_is_odd(TEMP(1))) {
-   if((res = mp_int_add(TEMP(0), TEMP(7), TEMP(0))) != MP_OK) 
-     goto CLEANUP;
-   if((res = mp_int_sub(TEMP(1), TEMP(6), TEMP(1))) != MP_OK) 
-     goto CLEANUP;
-      }
-
-      s_qdiv(TEMP(0), 1);
-      s_qdiv(TEMP(1), 1);
-    }
-    
-    while(mp_int_is_even(TEMP(5))) {
-      s_qdiv(TEMP(5), 1);
-
-      if(mp_int_is_odd(TEMP(2)) || mp_int_is_odd(TEMP(3))) {
-   if((res = mp_int_add(TEMP(2), TEMP(7), TEMP(2))) != MP_OK) 
-     goto CLEANUP;
-   if((res = mp_int_sub(TEMP(3), TEMP(6), TEMP(3))) != MP_OK) 
-     goto CLEANUP;
-      }
-
-      s_qdiv(TEMP(2), 1);
-      s_qdiv(TEMP(3), 1);
-    }
-
-    if(mp_int_compare(TEMP(4), TEMP(5)) >= 0) {
-      if((res = mp_int_sub(TEMP(4), TEMP(5), TEMP(4))) != MP_OK) goto CLEANUP;
-      if((res = mp_int_sub(TEMP(0), TEMP(2), TEMP(0))) != MP_OK) goto CLEANUP;
-      if((res = mp_int_sub(TEMP(1), TEMP(3), TEMP(1))) != MP_OK) goto CLEANUP;
-    } 
-    else {
-      if((res = mp_int_sub(TEMP(5), TEMP(4), TEMP(5))) != MP_OK) goto CLEANUP;
-      if((res = mp_int_sub(TEMP(2), TEMP(0), TEMP(2))) != MP_OK) goto CLEANUP;
-      if((res = mp_int_sub(TEMP(3), TEMP(1), TEMP(3))) != MP_OK) goto CLEANUP;
-    }
-
-    if(CMPZ(TEMP(4)) == 0) {
-      if(x && (res = mp_int_copy(TEMP(2), x)) != MP_OK) goto CLEANUP;
-      if(y && (res = mp_int_copy(TEMP(3), y)) != MP_OK) goto CLEANUP;
-      if(c) {
-   if(!s_qmul(TEMP(5), k)) {
-     res = MP_MEMORY;
-     goto CLEANUP;
-   }
-    
-   res = mp_int_copy(TEMP(5), c);
-      }
-
-      break;
-    }
-  }
-
- CLEANUP:
-  while(--last >= 0)
-    mp_int_clear(TEMP(last));
-
-  return res;
+mp_result
+mp_int_egcd(mp_int a, mp_int b, mp_int c,
+           mp_int x, mp_int y)
+{
+   int         k,
+               last = 0,
+               ca,
+               cb;
+   mpz_t       temp[8];
+   mp_result   res;
+
+   CHECK(a != NULL && b != NULL && c != NULL &&
+         (x != NULL || y != NULL));
+
+   ca = CMPZ(a);
+   cb = CMPZ(b);
+   if (ca == 0 && cb == 0)
+       return MP_UNDEF;
+   else if (ca == 0)
+   {
+       if ((res = mp_int_abs(b, c)) != MP_OK)
+           return res;
+       mp_int_zero(x);
+       (void) mp_int_set_value(y, 1);
+       return MP_OK;
+   }
+   else if (cb == 0)
+   {
+       if ((res = mp_int_abs(a, c)) != MP_OK)
+           return res;
+       (void) mp_int_set_value(x, 1);
+       mp_int_zero(y);
+       return MP_OK;
+   }
+
+   /*
+    * Initialize temporaries: A:0, B:1, C:2, D:3, u:4, v:5, ou:6, ov:7
+    */
+   for (last = 0; last < 4; ++last)
+   {
+       if ((res = mp_int_init(TEMP(last))) != MP_OK)
+           goto CLEANUP;
+   }
+   TEMP(0)->digits[0] = 1;
+   TEMP(3)->digits[0] = 1;
+
+   SETUP(mp_int_init_copy(TEMP(4), a), last);
+   SETUP(mp_int_init_copy(TEMP(5), b), last);
+
+   /* We will work with absolute values here */
+   MP_SIGN(TEMP(4)) = MP_ZPOS;
+   MP_SIGN(TEMP(5)) = MP_ZPOS;
+
+   {                           /* Divide out common factors of 2 from u and v */
+       int         div2_u = s_dp2k(TEMP(4)),
+                   div2_v = s_dp2k(TEMP(5));
+
+       k = MIN(div2_u, div2_v);
+       s_qdiv(TEMP(4), k);
+       s_qdiv(TEMP(5), k);
+   }
+
+   SETUP(mp_int_init_copy(TEMP(6), TEMP(4)), last);
+   SETUP(mp_int_init_copy(TEMP(7), TEMP(5)), last);
+
+   for (;;)
+   {
+       while (mp_int_is_even(TEMP(4)))
+       {
+           s_qdiv(TEMP(4), 1);
+
+           if (mp_int_is_odd(TEMP(0)) || mp_int_is_odd(TEMP(1)))
+           {
+               if ((res = mp_int_add(TEMP(0), TEMP(7), TEMP(0))) != MP_OK)
+                   goto CLEANUP;
+               if ((res = mp_int_sub(TEMP(1), TEMP(6), TEMP(1))) != MP_OK)
+                   goto CLEANUP;
+           }
+
+           s_qdiv(TEMP(0), 1);
+           s_qdiv(TEMP(1), 1);
+       }
+
+       while (mp_int_is_even(TEMP(5)))
+       {
+           s_qdiv(TEMP(5), 1);
+
+           if (mp_int_is_odd(TEMP(2)) || mp_int_is_odd(TEMP(3)))
+           {
+               if ((res = mp_int_add(TEMP(2), TEMP(7), TEMP(2))) != MP_OK)
+                   goto CLEANUP;
+               if ((res = mp_int_sub(TEMP(3), TEMP(6), TEMP(3))) != MP_OK)
+                   goto CLEANUP;
+           }
+
+           s_qdiv(TEMP(2), 1);
+           s_qdiv(TEMP(3), 1);
+       }
+
+       if (mp_int_compare(TEMP(4), TEMP(5)) >= 0)
+       {
+           if ((res = mp_int_sub(TEMP(4), TEMP(5), TEMP(4))) != MP_OK)
+               goto CLEANUP;
+           if ((res = mp_int_sub(TEMP(0), TEMP(2), TEMP(0))) != MP_OK)
+               goto CLEANUP;
+           if ((res = mp_int_sub(TEMP(1), TEMP(3), TEMP(1))) != MP_OK)
+               goto CLEANUP;
+       }
+       else
+       {
+           if ((res = mp_int_sub(TEMP(5), TEMP(4), TEMP(5))) != MP_OK)
+               goto CLEANUP;
+           if ((res = mp_int_sub(TEMP(2), TEMP(0), TEMP(2))) != MP_OK)
+               goto CLEANUP;
+           if ((res = mp_int_sub(TEMP(3), TEMP(1), TEMP(3))) != MP_OK)
+               goto CLEANUP;
+       }
+
+       if (CMPZ(TEMP(4)) == 0)
+       {
+           if (x && (res = mp_int_copy(TEMP(2), x)) != MP_OK)
+               goto CLEANUP;
+           if (y && (res = mp_int_copy(TEMP(3), y)) != MP_OK)
+               goto CLEANUP;
+           if (c)
+           {
+               if (!s_qmul(TEMP(5), k))
+               {
+                   res = MP_MEMORY;
+                   goto CLEANUP;
+               }
+
+               res = mp_int_copy(TEMP(5), c);
+           }
+
+           break;
+       }
+   }
+
+CLEANUP:
+   while (--last >= 0)
+       mp_int_clear(TEMP(last));
+
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_divisible_value(a, v) */
 
-int       mp_int_divisible_value(mp_int a, int v)
+int
+mp_int_divisible_value(mp_int a, int v)
 {
-  int       rem = 0;
+   int         rem = 0;
 
-  if(mp_int_div_value(a, v, NULL, &rem) != MP_OK)
-    return 0;
+   if (mp_int_div_value(a, v, NULL, &rem) != MP_OK)
+       return 0;
 
-  return rem == 0;
+   return rem == 0;
 }
 
 /* }}} */
 
 /* {{{ mp_int_is_pow2(z) */
 
-int       mp_int_is_pow2(mp_int z)
+int
+mp_int_is_pow2(mp_int z)
 {
-  CHECK(z != NULL);
+   CHECK(z != NULL);
 
-  return s_isp2(z);
+   return s_isp2(z);
 }
 
 /* }}} */
 
 /* {{{ mp_int_sqrt(a, c) */
 
-mp_result mp_int_sqrt(mp_int a, mp_int c)
+mp_result
+mp_int_sqrt(mp_int a, mp_int c)
 {
-  mp_result  res = MP_OK;
-  mpz_t      temp[2];
-  int        last = 0;
+   mp_result   res = MP_OK;
+   mpz_t       temp[2];
+   int         last = 0;
 
-  CHECK(a != NULL && c != NULL);
+   CHECK(a != NULL && c != NULL);
 
-  /* The square root of a negative value does not exist in the integers. */
-  if(MP_SIGN(a) == MP_NEG)
-    return MP_UNDEF;
+   /* The square root of a negative value does not exist in the integers. */
+   if (MP_SIGN(a) == MP_NEG)
+       return MP_UNDEF;
 
-  SETUP(mp_int_init_copy(TEMP(last), a), last);
-  SETUP(mp_int_init(TEMP(last)), last);
+   SETUP(mp_int_init_copy(TEMP(last), a), last);
+   SETUP(mp_int_init(TEMP(last)), last);
 
-  for(;;) {
-    if((res = mp_int_sqr(TEMP(0), TEMP(1))) != MP_OK)
-      goto CLEANUP;
+   for (;;)
+   {
+       if ((res = mp_int_sqr(TEMP(0), TEMP(1))) != MP_OK)
+           goto CLEANUP;
 
-    if(mp_int_compare_unsigned(a, TEMP(1)) == 0) break;
+       if (mp_int_compare_unsigned(a, TEMP(1)) == 0)
+           break;
 
-    if((res = mp_int_copy(a, TEMP(1))) != MP_OK) 
-      goto CLEANUP;
-    if((res = mp_int_div(TEMP(1), TEMP(0), TEMP(1), NULL)) != MP_OK) 
-      goto CLEANUP;
-    if((res = mp_int_add(TEMP(0), TEMP(1), TEMP(1))) != MP_OK) 
-      goto CLEANUP;
-    if((res = mp_int_div_pow2(TEMP(1), 1, TEMP(1), NULL)) != MP_OK)
-      goto CLEANUP;
+       if ((res = mp_int_copy(a, TEMP(1))) != MP_OK)
+           goto CLEANUP;
+       if ((res = mp_int_div(TEMP(1), TEMP(0), TEMP(1), NULL)) != MP_OK)
+           goto CLEANUP;
+       if ((res = mp_int_add(TEMP(0), TEMP(1), TEMP(1))) != MP_OK)
+           goto CLEANUP;
+       if ((res = mp_int_div_pow2(TEMP(1), 1, TEMP(1), NULL)) != MP_OK)
+           goto CLEANUP;
 
-    if(mp_int_compare_unsigned(TEMP(0), TEMP(1)) == 0) break;
-    if((res = mp_int_sub_value(TEMP(0), 1, TEMP(0))) != MP_OK) goto CLEANUP;
-    if(mp_int_compare_unsigned(TEMP(0), TEMP(1)) == 0) break;
+       if (mp_int_compare_unsigned(TEMP(0), TEMP(1)) == 0)
+           break;
+       if ((res = mp_int_sub_value(TEMP(0), 1, TEMP(0))) != MP_OK)
+           goto CLEANUP;
+       if (mp_int_compare_unsigned(TEMP(0), TEMP(1)) == 0)
+           break;
 
-    if((res = mp_int_copy(TEMP(1), TEMP(0))) != MP_OK) goto CLEANUP;
-  }
-  
-  res = mp_int_copy(TEMP(0), c);
+       if ((res = mp_int_copy(TEMP(1), TEMP(0))) != MP_OK)
+           goto CLEANUP;
+   }
 
- CLEANUP:
-  while(--last >= 0)
-    mp_int_clear(TEMP(last));
-  
-  return res;
+   res = mp_int_copy(TEMP(0), c);
+
+CLEANUP:
+   while (--last >= 0)
+       mp_int_clear(TEMP(last));
+
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_to_int(z, out) */
 
-mp_result mp_int_to_int(mp_int z, int *out)
+mp_result
+mp_int_to_int(mp_int z, int *out)
 {
-  unsigned int uv = 0;
-  mp_size   uz;
-  mp_digit *dz;
-  mp_sign   sz;
+   unsigned int uv = 0;
+   mp_size     uz;
+   mp_digit   *dz;
+   mp_sign     sz;
 
-  CHECK(z != NULL);
+   CHECK(z != NULL);
 
-  /* Make sure the value is representable as an int */
-  sz = MP_SIGN(z);
-  if((sz == MP_ZPOS && mp_int_compare_value(z, INT_MAX) > 0) ||
-     mp_int_compare_value(z, INT_MIN) < 0)
-    return MP_RANGE;
-     
-  uz = MP_USED(z);
-  dz = MP_DIGITS(z) + uz - 1;
-  
-  while(uz > 0) {
-    uv <<= MP_DIGIT_BIT/2;
-    uv = (uv << (MP_DIGIT_BIT/2)) | *dz--;
-    --uz;
-  }
+   /* Make sure the value is representable as an int */
+   sz = MP_SIGN(z);
+   if ((sz == MP_ZPOS && mp_int_compare_value(z, INT_MAX) > 0) ||
+       mp_int_compare_value(z, INT_MIN) < 0)
+       return MP_RANGE;
 
-  if(out)
-    *out = (sz == MP_NEG) ? -(int)uv : (int)uv;
+   uz = MP_USED(z);
+   dz = MP_DIGITS(z) + uz - 1;
 
-  return MP_OK;
+   while (uz > 0)
+   {
+       uv <<= MP_DIGIT_BIT / 2;
+       uv = (uv << (MP_DIGIT_BIT / 2)) | *dz--;
+       --uz;
+   }
+
+   if (out)
+       *out = (sz == MP_NEG) ? -(int) uv : (int) uv;
+
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_to_string(z, radix, str, limit) */
 
-mp_result mp_int_to_string(mp_int z, mp_size radix, 
-              char *str, int limit)
+mp_result
+mp_int_to_string(mp_int z, mp_size radix,
+                char *str, int limit)
 {
-  mp_result res;
-  int       cmp = 0;
-
-  CHECK(z != NULL && str != NULL && limit >= 2);
-
-  if(radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
-    return MP_RANGE;
-
-  if(CMPZ(z) == 0) {
-    *str++ = s_val2ch(0, mp_flags & MP_CAP_DIGITS);
-  } 
-  else {
-    mpz_t tmp;
-    char  *h, *t;
-
-    if((res = mp_int_init_copy(&tmp, z)) != MP_OK)
-      return res;
-
-    if(MP_SIGN(z) == MP_NEG) {
-      *str++ = '-';
-      --limit;
-    }
-    h = str;
+   mp_result   res;
+   int         cmp = 0;
 
-    /* Generate digits in reverse order until finished or limit reached */
-    for(/* */; limit > 0; --limit) {
-      mp_digit d;
+   CHECK(z != NULL && str != NULL && limit >= 2);
 
-      if((cmp = CMPZ(&tmp)) == 0)
-   break;
+   if (radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
+       return MP_RANGE;
 
-      d = s_ddiv(&tmp, (mp_digit)radix);
-      *str++ = s_val2ch(d, mp_flags & MP_CAP_DIGITS);
-    }
-    t = str - 1;
-
-    /* Put digits back in correct output order */
-    while(h < t) {
-      char tc = *h;
-      *h++ = *t;
-      *t-- = tc;
-    }
-
-    mp_int_clear(&tmp);
-  }
+   if (CMPZ(z) == 0)
+   {
+       *str++ = s_val2ch(0, mp_flags & MP_CAP_DIGITS);
+   }
+   else
+   {
+       mpz_t       tmp;
+       char       *h,
+                  *t;
+
+       if ((res = mp_int_init_copy(&tmp, z)) != MP_OK)
+           return res;
+
+       if (MP_SIGN(z) == MP_NEG)
+       {
+           *str++ = '-';
+           --limit;
+       }
+       h = str;
+
+       /* Generate digits in reverse order until finished or limit reached */
+       for ( /* */ ; limit > 0; --limit)
+       {
+           mp_digit    d;
+
+           if ((cmp = CMPZ(&tmp)) == 0)
+               break;
+
+           d = s_ddiv(&tmp, (mp_digit) radix);
+           *str++ = s_val2ch(d, mp_flags & MP_CAP_DIGITS);
+       }
+       t = str - 1;
+
+       /* Put digits back in correct output order */
+       while (h < t)
+       {
+           char        tc = *h;
+
+           *h++ = *t;
+           *t-- = tc;
+       }
+
+       mp_int_clear(&tmp);
+   }
 
-  *str = '\0';
-  if(cmp == 0)
-    return MP_OK;
-  else
-    return MP_TRUNC;
+   *str = '\0';
+   if (cmp == 0)
+       return MP_OK;
+   else
+       return MP_TRUNC;
 }
 
 /* }}} */
 
 /* {{{ mp_int_string_len(z, radix) */
 
-mp_result mp_int_string_len(mp_int z, mp_size radix)
-{ 
-  int  len;
+mp_result
+mp_int_string_len(mp_int z, mp_size radix)
+{
+   int         len;
 
-  CHECK(z != NULL);
+   CHECK(z != NULL);
 
-  if(radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
-    return MP_RANGE;
+   if (radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
+       return MP_RANGE;
 
-  len = s_outlen(z, radix) + 1; /* for terminator */
+   len = s_outlen(z, radix) + 1;       /* for terminator */
 
-  /* Allow for sign marker on negatives */
-  if(MP_SIGN(z) == MP_NEG)
-    len += 1;
+   /* Allow for sign marker on negatives */
+   if (MP_SIGN(z) == MP_NEG)
+       len += 1;
 
-  return len;
+   return len;
 }
 
 /* }}} */
@@ -1779,9 +1988,10 @@ mp_result mp_int_string_len(mp_int z, mp_size radix)
 /* {{{ mp_int_read_string(z, radix, *str) */
 
 /* Read zero-terminated string into z */
-mp_result mp_int_read_string(mp_int z, mp_size radix, const char *str)
+mp_result
+mp_int_read_string(mp_int z, mp_size radix, const char *str)
 {
-  return mp_int_read_cstring(z, radix, str, NULL);
+   return mp_int_read_cstring(z, radix, str, NULL);
 
 }
 
@@ -1789,281 +1999,308 @@ mp_result mp_int_read_string(mp_int z, mp_size radix, const char *str)
 
 /* {{{ mp_int_read_cstring(z, radix, *str, **end) */
 
-mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str, char **end)
-{ 
-  int       ch;
+mp_result
+mp_int_read_cstring(mp_int z, mp_size radix, const char *str, char **end)
+{
+   int         ch;
 
-  CHECK(z != NULL && str != NULL);
+   CHECK(z != NULL && str != NULL);
 
-  if(radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
-    return MP_RANGE;
+   if (radix < MP_MIN_RADIX || radix > MP_MAX_RADIX)
+       return MP_RANGE;
 
-  /* Skip leading whitespace */
-  while(isspace((unsigned char) *str))
-    ++str;
+   /* Skip leading whitespace */
+   while (isspace((unsigned char) *str))
+       ++str;
 
-  /* Handle leading sign tag (+/-, positive default) */
-  switch(*str) {
-  case '-':
-    MP_SIGN(z) = MP_NEG;
-    ++str;
-    break;
-  case '+':
-    ++str; /* fallthrough */
-  default:
-    MP_SIGN(z) = MP_ZPOS;
-    break;
-  }
+   /* Handle leading sign tag (+/-, positive default) */
+   switch (*str)
+   {
+       case '-':
+           MP_SIGN(z) = MP_NEG;
+           ++str;
+           break;
+       case '+':
+           ++str;              /* fallthrough */
+       default:
+           MP_SIGN(z) = MP_ZPOS;
+           break;
+   }
+
+   /* Skip leading zeroes */
+   while ((ch = s_ch2val(*str, radix)) == 0)
+       ++str;
 
-  /* Skip leading zeroes */
-  while((ch = s_ch2val(*str, radix)) == 0) 
-    ++str;
+   /* Make sure there is enough space for the value */
+   if (!s_pad(z, s_inlen(strlen(str), radix)))
+       return MP_MEMORY;
 
-  /* Make sure there is enough space for the value */
-  if(!s_pad(z, s_inlen(strlen(str), radix)))
-    return MP_MEMORY;
+   MP_USED(z) = 1;
+   z->digits[0] = 0;
+
+   while (*str != '\0' && ((ch = s_ch2val(*str, radix)) >= 0))
+   {
+       s_dmul(z, (mp_digit) radix);
+       s_dadd(z, (mp_digit) ch);
+       ++str;
+   }
 
-  MP_USED(z) = 1; z->digits[0] = 0;
+   CLAMP(z);
 
-  while(*str != '\0' && ((ch = s_ch2val(*str, radix)) >= 0)) {
-    s_dmul(z, (mp_digit)radix);
-    s_dadd(z, (mp_digit)ch);
-    ++str;
-  }
-  
-  CLAMP(z);
+   /* Override sign for zero, even if negative specified. */
+   if (CMPZ(z) == 0)
+       MP_SIGN(z) = MP_ZPOS;
 
-  /* Override sign for zero, even if negative specified. */
-  if(CMPZ(z) == 0)
-    MP_SIGN(z) = MP_ZPOS;
-  
-  if(end != NULL)
-    *end = (char *)str;
+   if (end != NULL)
+       *end = (char *) str;
 
-  /* Return a truncation error if the string has unprocessed
-     characters remaining, so the caller can tell if the whole string
-     was done */
-  if(*str != '\0') 
-    return MP_TRUNC;
-  else
-    return MP_OK;
+   /*
+    * Return a truncation error if the string has unprocessed characters
+    * remaining, so the caller can tell if the whole string was done
+    */
+   if (*str != '\0')
+       return MP_TRUNC;
+   else
+       return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_count_bits(z) */
 
-mp_result mp_int_count_bits(mp_int z)
+mp_result
+mp_int_count_bits(mp_int z)
 {
-  mp_size  nbits = 0, uz;
-  mp_digit d;
+   mp_size     nbits = 0,
+               uz;
+   mp_digit    d;
 
-  CHECK(z != NULL);
+   CHECK(z != NULL);
 
-  uz = MP_USED(z);
-  if(uz == 1 && z->digits[0] == 0)
-    return 1;
+   uz = MP_USED(z);
+   if (uz == 1 && z->digits[0] == 0)
+       return 1;
 
-  --uz;
-  nbits = uz * MP_DIGIT_BIT;
-  d = z->digits[uz];
+   --uz;
+   nbits = uz * MP_DIGIT_BIT;
+   d = z->digits[uz];
 
-  while(d != 0) {
-    d >>= 1;
-    ++nbits;
-  }
+   while (d != 0)
+   {
+       d >>= 1;
+       ++nbits;
+   }
 
-  return nbits;
+   return nbits;
 }
 
 /* }}} */
 
 /* {{{ mp_int_to_binary(z, buf, limit) */
 
-mp_result mp_int_to_binary(mp_int z, unsigned char *buf, int limit)
+mp_result
+mp_int_to_binary(mp_int z, unsigned char *buf, int limit)
 {
-  static const int PAD_FOR_2C = 1;
+   static const int PAD_FOR_2C = 1;
+
+   mp_result   res;
+   int         limpos = limit;
 
-  mp_result res;
-  int       limpos = limit;
+   CHECK(z != NULL && buf != NULL);
 
-  CHECK(z != NULL && buf != NULL);
-  
-  res = s_tobin(z, buf, &limpos, PAD_FOR_2C);
+   res = s_tobin(z, buf, &limpos, PAD_FOR_2C);
 
-  if(MP_SIGN(z) == MP_NEG)
-    s_2comp(buf, limpos);
+   if (MP_SIGN(z) == MP_NEG)
+       s_2comp(buf, limpos);
 
-  return res;
+   return res;
 }
 
 /* }}} */
 
 /* {{{ mp_int_read_binary(z, buf, len) */
 
-mp_result mp_int_read_binary(mp_int z, unsigned char *buf, int len)
+mp_result
+mp_int_read_binary(mp_int z, unsigned char *buf, int len)
 {
-  mp_size need, i;
-  unsigned char *tmp;
-  mp_digit *dz;
+   mp_size     need,
+               i;
+   unsigned char *tmp;
+   mp_digit   *dz;
+
+   CHECK(z != NULL && buf != NULL && len > 0);
 
-  CHECK(z != NULL && buf != NULL && len > 0);
+   /* Figure out how many digits are needed to represent this value */
+   need = ((len * CHAR_BIT) + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT;
+   if (!s_pad(z, need))
+       return MP_MEMORY;
 
-  /* Figure out how many digits are needed to represent this value */
-  need = ((len * CHAR_BIT) + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT;
-  if(!s_pad(z, need))
-    return MP_MEMORY;
+   mp_int_zero(z);
 
-  mp_int_zero(z);
+   /*
+    * If the high-order bit is set, take the 2's complement before reading
+    * the value (it will be restored afterward)
+    */
+   if (buf[0] >> (CHAR_BIT - 1))
+   {
+       MP_SIGN(z) = MP_NEG;
+       s_2comp(buf, len);
+   }
 
-  /* If the high-order bit is set, take the 2's complement before
-     reading the value (it will be restored afterward) */
-  if(buf[0] >> (CHAR_BIT - 1)) {
-    MP_SIGN(z) = MP_NEG;
-    s_2comp(buf, len);
-  }
-  
-  dz = MP_DIGITS(z);
-  for(tmp = buf, i = len; i > 0; --i, ++tmp) {
-    s_qmul(z, (mp_size) CHAR_BIT);
-    *dz |= *tmp;
-  }
+   dz = MP_DIGITS(z);
+   for (tmp = buf, i = len; i > 0; --i, ++tmp)
+   {
+       s_qmul(z, (mp_size) CHAR_BIT);
+       *dz |= *tmp;
+   }
 
-  /* Restore 2's complement if we took it before */
-  if(MP_SIGN(z) == MP_NEG)
-    s_2comp(buf, len);
+   /* Restore 2's complement if we took it before */
+   if (MP_SIGN(z) == MP_NEG)
+       s_2comp(buf, len);
 
-  return MP_OK;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_binary_len(z) */
 
-mp_result mp_int_binary_len(mp_int z)
+mp_result
+mp_int_binary_len(mp_int z)
 {
-  mp_result  res = mp_int_count_bits(z);
-  int        bytes = mp_int_unsigned_len(z);
+   mp_result   res = mp_int_count_bits(z);
+   int         bytes = mp_int_unsigned_len(z);
 
-  if(res <= 0)
-    return res;
+   if (res <= 0)
+       return res;
 
-  bytes = (res + (CHAR_BIT - 1)) / CHAR_BIT;
+   bytes = (res + (CHAR_BIT - 1)) / CHAR_BIT;
 
-  /* If the highest-order bit falls exactly on a byte boundary, we
-     need to pad with an extra byte so that the sign will be read
-     correctly when reading it back in. */
-  if(bytes * CHAR_BIT == res)
-    ++bytes;
+   /*
+    * If the highest-order bit falls exactly on a byte boundary, we need to
+    * pad with an extra byte so that the sign will be read correctly when
+    * reading it back in.
+    */
+   if (bytes * CHAR_BIT == res)
+       ++bytes;
 
-  return bytes;
+   return bytes;
 }
 
 /* }}} */
 
 /* {{{ mp_int_to_unsigned(z, buf, limit) */
 
-mp_result mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit)
+mp_result
+mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit)
 {
-  static const int NO_PADDING = 0;
+   static const int NO_PADDING = 0;
 
-  CHECK(z != NULL && buf != NULL);
+   CHECK(z != NULL && buf != NULL);
 
-  return s_tobin(z, buf, &limit, NO_PADDING);
+   return s_tobin(z, buf, &limit, NO_PADDING);
 }
 
 /* }}} */
 
 /* {{{ mp_int_read_unsigned(z, buf, len) */
 
-mp_result mp_int_read_unsigned(mp_int z, unsigned char *buf, int len)
+mp_result
+mp_int_read_unsigned(mp_int z, unsigned char *buf, int len)
 {
-  mp_size need, i;
-  unsigned char *tmp;
-  mp_digit *dz;
+   mp_size     need,
+               i;
+   unsigned char *tmp;
+   mp_digit   *dz;
 
-  CHECK(z != NULL && buf != NULL && len > 0);
+   CHECK(z != NULL && buf != NULL && len > 0);
 
-  /* Figure out how many digits are needed to represent this value */
-  need = ((len * CHAR_BIT) + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT;
-  if(!s_pad(z, need))
-    return MP_MEMORY;
+   /* Figure out how many digits are needed to represent this value */
+   need = ((len * CHAR_BIT) + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT;
+   if (!s_pad(z, need))
+       return MP_MEMORY;
 
-  mp_int_zero(z);
+   mp_int_zero(z);
 
-  dz = MP_DIGITS(z);
-  for(tmp = buf, i = len; i > 0; --i, ++tmp) {
-    (void) s_qmul(z, CHAR_BIT);
-    *dz |= *tmp;
-  }
+   dz = MP_DIGITS(z);
+   for (tmp = buf, i = len; i > 0; --i, ++tmp)
+   {
+       (void) s_qmul(z, CHAR_BIT);
+       *dz |= *tmp;
+   }
 
-  return MP_OK;
+   return MP_OK;
 }
 
 /* }}} */
 
 /* {{{ mp_int_unsigned_len(z) */
 
-mp_result mp_int_unsigned_len(mp_int z)
+mp_result
+mp_int_unsigned_len(mp_int z)
 {
-  mp_result  res = mp_int_count_bits(z);
-  int        bytes;
+   mp_result   res = mp_int_count_bits(z);
+   int         bytes;
 
-  if(res <= 0)
-    return res;
+   if (res <= 0)
+       return res;
 
-  bytes = (res + (CHAR_BIT - 1)) / CHAR_BIT;
+   bytes = (res + (CHAR_BIT - 1)) / CHAR_BIT;
 
-  return bytes;
+   return bytes;
 }
 
 /* }}} */
 
 /* {{{ mp_error_string(res) */
 
-const char *mp_error_string(mp_result res)
+const char *
+mp_error_string(mp_result res)
 {
-  int ix;
-  if(res > 0)
-    return s_unknown_err;
+   int         ix;
+
+   if (res > 0)
+       return s_unknown_err;
 
-  res = -res;
-  for(ix = 0; ix < res && s_error_msg[ix] != NULL; ++ix)
-    ;
+   res = -res;
+   for (ix = 0; ix < res && s_error_msg[ix] != NULL; ++ix)
+       ;
 
-  if(s_error_msg[ix] != NULL)
-    return s_error_msg[ix];
-  else
-    return s_unknown_err;
+   if (s_error_msg[ix] != NULL)
+       return s_error_msg[ix];
+   else
+       return s_unknown_err;
 }
 
 /* }}} */
 
 /*------------------------------------------------------------------------*/
-/* Private functions for internal use.  These make assumptions.           */
+/* Private functions for internal use. These make assumptions.           */
 
 /* {{{ s_alloc(num) */
 
-static mp_digit *s_alloc(mp_size num)
+static mp_digit *
+s_alloc(mp_size num)
 {
-  mp_digit *out = px_alloc(num * sizeof(mp_digit));
+   mp_digit   *out = px_alloc(num * sizeof(mp_digit));
 
-  assert(out != NULL); /* for debugging */
+   assert(out != NULL);        /* for debugging */
 
-  return out;
+   return out;
 }
 
 /* }}} */
 
 /* {{{ s_realloc(old, num) */
 
-static mp_digit *s_realloc(mp_digit *old, mp_size num)
+static mp_digit *
+s_realloc(mp_digit * old, mp_size num)
 {
-  mp_digit *new = px_realloc(old, num * sizeof(mp_digit));
+   mp_digit   *new = px_realloc(old, num * sizeof(mp_digit));
 
-  assert(new != NULL); /* for debugging */
+   assert(new != NULL);        /* for debugging */
 
-  return new;
+   return new;
 }
 
 /* }}} */
@@ -2071,9 +2308,10 @@ static mp_digit *s_realloc(mp_digit *old, mp_size num)
 /* {{{ s_free(ptr) */
 
 #if TRACEABLE_FREE
-static void s_free(void *ptr)
+static void
+s_free(void *ptr)
 {
-  px_free(ptr);
+   px_free(ptr);
 }
 #endif
 
@@ -2081,20 +2319,22 @@ static void s_free(void *ptr)
 
 /* {{{ s_pad(z, min) */
 
-static int      s_pad(mp_int z, mp_size min)
+static int
+s_pad(mp_int z, mp_size min)
 {
-  if(MP_ALLOC(z) < min) {
-    mp_size nsize = ROUND_PREC(min);
-    mp_digit *tmp = s_realloc(MP_DIGITS(z), nsize);
+   if (MP_ALLOC(z) < min)
+   {
+       mp_size     nsize = ROUND_PREC(min);
+       mp_digit   *tmp = s_realloc(MP_DIGITS(z), nsize);
 
-    if(tmp == NULL)
-      return 0;
+       if (tmp == NULL)
+           return 0;
 
-    MP_DIGITS(z) = tmp;
-    MP_ALLOC(z) = nsize;
-  }
+       MP_DIGITS(z) = tmp;
+       MP_ALLOC(z) = nsize;
+   }
 
-  return 1;
+   return 1;
 }
 
 /* }}} */
@@ -2102,15 +2342,16 @@ static int      s_pad(mp_int z, mp_size min)
 /* {{{ s_clamp(z) */
 
 #if TRACEABLE_CLAMP
-static void     s_clamp(mp_int z)
+static void
+s_clamp(mp_int z)
 {
-  mp_size   uz = MP_USED(z);
-  mp_digit *zd = MP_DIGITS(z) + uz - 1;
+   mp_size     uz = MP_USED(z);
+   mp_digit   *zd = MP_DIGITS(z) + uz - 1;
 
-  while(uz > 1 && (*zd-- == 0))
-    --uz;
+   while (uz > 1 && (*zd-- == 0))
+       --uz;
 
-  MP_USED(z) = uz;
+   MP_USED(z) = uz;
 }
 #endif
 
@@ -2118,614 +2359,711 @@ static void     s_clamp(mp_int z)
 
 /* {{{ s_fake(z, value, vbuf) */
 
-static void      s_fake(mp_int z, int value, mp_digit vbuf[])
+static void
+s_fake(mp_int z, int value, mp_digit vbuf[])
 {
-  mp_size uv = (mp_size)s_vpack(value, vbuf);
+   mp_size     uv = (mp_size) s_vpack(value, vbuf);
 
-  z->used = uv;
-  z->alloc = MP_VALUE_DIGITS(value);
-  z->sign = (value < 0) ? MP_NEG : MP_ZPOS;
-  z->digits = vbuf;
+   z->used = uv;
+   z->alloc = MP_VALUE_DIGITS(value);
+   z->sign = (value < 0) ? MP_NEG : MP_ZPOS;
+   z->digits = vbuf;
 }
 
 /* }}} */
 
 /* {{{ s_cdig(da, db, len) */
 
-static int      s_cdig(mp_digit *da, mp_digit *db, mp_size len)
+static int
+s_cdig(mp_digit * da, mp_digit * db, mp_size len)
 {
-  mp_digit *dat = da + len - 1, *dbt = db + len - 1;
+   mp_digit   *dat = da + len - 1,
+              *dbt = db + len - 1;
 
-  for(/* */; len != 0; --len, --dat, --dbt) {
-    if(*dat > *dbt)
-      return 1;
-    else if(*dat < *dbt)
-      return -1;
-  }
+   for ( /* */ ; len != 0; --len, --dat, --dbt)
+   {
+       if (*dat > *dbt)
+           return 1;
+       else if (*dat < *dbt)
+           return -1;
+   }
 
-  return 0;
+   return 0;
 }
 
 /* }}} */
 
 /* {{{ s_vpack(v, t[]) */
 
-static int       s_vpack(int v, mp_digit t[])
-{
-  unsigned int uv = (unsigned int)((v < 0) ? -v : v);
-  int          ndig = 0;
-  
-  if(uv == 0)
-    t[ndig++] = 0;
-  else {
-    while(uv != 0) {
-      t[ndig++] = (mp_digit) uv;
-      uv >>= MP_DIGIT_BIT/2;
-      uv >>= MP_DIGIT_BIT/2;
-    }
-  }
+static int
+s_vpack(int v, mp_digit t[])
+{
+   unsigned int uv = (unsigned int) ((v < 0) ? -v : v);
+   int         ndig = 0;
+
+   if (uv == 0)
+       t[ndig++] = 0;
+   else
+   {
+       while (uv != 0)
+       {
+           t[ndig++] = (mp_digit) uv;
+           uv >>= MP_DIGIT_BIT / 2;
+           uv >>= MP_DIGIT_BIT / 2;
+       }
+   }
 
-  return ndig;
+   return ndig;
 }
 
 /* }}} */
 
 /* {{{ s_ucmp(a, b) */
 
-static int      s_ucmp(mp_int a, mp_int b)
+static int
+s_ucmp(mp_int a, mp_int b)
 {
-  mp_size  ua = MP_USED(a), ub = MP_USED(b);
-  
-  if(ua > ub)
-    return 1;
-  else if(ub > ua) 
-    return -1;
-  else 
-    return s_cdig(MP_DIGITS(a), MP_DIGITS(b), ua);
+   mp_size     ua = MP_USED(a),
+               ub = MP_USED(b);
+
+   if (ua > ub)
+       return 1;
+   else if (ub > ua)
+       return -1;
+   else
+       return s_cdig(MP_DIGITS(a), MP_DIGITS(b), ua);
 }
 
 /* }}} */
 
 /* {{{ s_vcmp(a, v) */
 
-static int      s_vcmp(mp_int a, int v)
+static int
+s_vcmp(mp_int a, int v)
 {
-  mp_digit     vdig[MP_VALUE_DIGITS(v)];
-  int          ndig = 0;
-  mp_size      ua = MP_USED(a);
+   mp_digit    vdig[MP_VALUE_DIGITS(v)];
+   int         ndig = 0;
+   mp_size     ua = MP_USED(a);
 
-  ndig = s_vpack(v, vdig);
+   ndig = s_vpack(v, vdig);
 
-  if(ua > ndig)
-    return 1;
-  else if(ua < ndig)
-    return -1;
-  else
-    return s_cdig(MP_DIGITS(a), vdig, ndig);
+   if (ua > ndig)
+       return 1;
+   else if (ua < ndig)
+       return -1;
+   else
+       return s_cdig(MP_DIGITS(a), vdig, ndig);
 }
 
 /* }}} */
 
 /* {{{ s_uadd(da, db, dc, size_a, size_b) */
 
-static mp_digit s_uadd(mp_digit *da, mp_digit *db, mp_digit *dc, 
-              mp_size size_a, mp_size size_b)
+static mp_digit
+s_uadd(mp_digit * da, mp_digit * db, mp_digit * dc,
+      mp_size size_a, mp_size size_b)
 {
-  mp_size pos;
-  mp_word w = 0;
+   mp_size     pos;
+   mp_word     w = 0;
 
-  /* Insure that da is the longer of the two to simplify later code */
-  if(size_b > size_a) {
-    SWAP(mp_digit *, da, db);
-    SWAP(mp_size, size_a, size_b);
-  }
+   /* Insure that da is the longer of the two to simplify later code */
+   if (size_b > size_a)
+   {
+       SWAP(mp_digit *, da, db);
+       SWAP(mp_size, size_a, size_b);
+   }
 
-  /* Add corresponding digits until the shorter number runs out */
-  for(pos = 0; pos < size_b; ++pos, ++da, ++db, ++dc) {
-    w = w + (mp_word)*da + (mp_word)*db;
-    *dc = LOWER_HALF(w);
-    w = UPPER_HALF(w);
-  }
+   /* Add corresponding digits until the shorter number runs out */
+   for (pos = 0; pos < size_b; ++pos, ++da, ++db, ++dc)
+   {
+       w = w + (mp_word) * da + (mp_word) * db;
+       *dc = LOWER_HALF(w);
+       w = UPPER_HALF(w);
+   }
 
-  /* Propagate carries as far as necessary */
-  for(/* */; pos < size_a; ++pos, ++da, ++dc) {
-    w = w + *da;
+   /* Propagate carries as far as necessary */
+   for ( /* */ ; pos < size_a; ++pos, ++da, ++dc)
+   {
+       w = w + *da;
 
-    *dc = LOWER_HALF(w);
-    w = UPPER_HALF(w);
-  }
+       *dc = LOWER_HALF(w);
+       w = UPPER_HALF(w);
+   }
 
-  /* Return carry out */
-  return (mp_digit)w;
+   /* Return carry out */
+   return (mp_digit) w;
 }
 
 /* }}} */
 
 /* {{{ s_usub(da, db, dc, size_a, size_b) */
 
-static void     s_usub(mp_digit *da, mp_digit *db, mp_digit *dc,
-              mp_size size_a, mp_size size_b)
+static void
+s_usub(mp_digit * da, mp_digit * db, mp_digit * dc,
+      mp_size size_a, mp_size size_b)
 {
-  mp_size pos;
-  mp_word w = 0;
+   mp_size     pos;
+   mp_word     w = 0;
 
-  /* We assume that |a| >= |b| so this should definitely hold */
-  assert(size_a >= size_b);
+   /* We assume that |a| >= |b| so this should definitely hold */
+   assert(size_a >= size_b);
 
-  /* Subtract corresponding digits and propagate borrow */
-  for(pos = 0; pos < size_b; ++pos, ++da, ++db, ++dc) {
-    w = ((mp_word)MP_DIGIT_MAX + 1 +  /* MP_RADIX */
-    (mp_word)*da) - w - (mp_word)*db;
+   /* Subtract corresponding digits and propagate borrow */
+   for (pos = 0; pos < size_b; ++pos, ++da, ++db, ++dc)
+   {
+       w = ((mp_word) MP_DIGIT_MAX + 1 +       /* MP_RADIX */
+            (mp_word) * da) - w - (mp_word) * db;
 
-    *dc = LOWER_HALF(w);
-    w = (UPPER_HALF(w) == 0);
-  }
+       *dc = LOWER_HALF(w);
+       w = (UPPER_HALF(w) == 0);
+   }
 
-  /* Finish the subtraction for remaining upper digits of da */
-  for(/* */; pos < size_a; ++pos, ++da, ++dc) {
-    w = ((mp_word)MP_DIGIT_MAX + 1 +  /* MP_RADIX */
-    (mp_word)*da) - w; 
+   /* Finish the subtraction for remaining upper digits of da */
+   for ( /* */ ; pos < size_a; ++pos, ++da, ++dc)
+   {
+       w = ((mp_word) MP_DIGIT_MAX + 1 +       /* MP_RADIX */
+            (mp_word) * da) - w;
 
-    *dc = LOWER_HALF(w);
-    w = (UPPER_HALF(w) == 0);
-  }
+       *dc = LOWER_HALF(w);
+       w = (UPPER_HALF(w) == 0);
+   }
 
-  /* If there is a borrow out at the end, it violates the precondition */
-  assert(w == 0);
+   /* If there is a borrow out at the end, it violates the precondition */
+   assert(w == 0);
 }
 
 /* }}} */
 
 /* {{{ s_kmul(da, db, dc, size_a, size_b) */
 
-static int       s_kmul(mp_digit *da, mp_digit *db, mp_digit *dc,
-           mp_size size_a, mp_size size_b)
+static int
+s_kmul(mp_digit * da, mp_digit * db, mp_digit * dc,
+      mp_size size_a, mp_size size_b)
 {
-  mp_size  bot_size;
-
-  /* Make sure b is the smaller of the two input values */
-  if(size_b > size_a) {
-    SWAP(mp_digit *, da, db);
-    SWAP(mp_size, size_a, size_b);
-  }
-
-  /* Insure that the bottom is the larger half in an odd-length split;
-     the code below relies on this being true.
-   */
-  bot_size = (size_a + 1) / 2;
-
-  /* If the values are big enough to bother with recursion, use the
-     Karatsuba algorithm to compute the product; otherwise use the
-     normal multiplication algorithm
-   */
-  if(multiply_threshold && 
-     size_a >= multiply_threshold && 
-     size_b > bot_size) {
-
-    mp_digit *t1, *t2, *t3, carry;
-
-    mp_digit *a_top = da + bot_size; 
-    mp_digit *b_top = db + bot_size;
-
-    mp_size  at_size = size_a - bot_size;
-    mp_size  bt_size = size_b - bot_size;
-    mp_size  buf_size = 2 * bot_size;
-
-    /* Do a single allocation for all three temporary buffers needed;
-       each buffer must be big enough to hold the product of two
-       bottom halves, and one buffer needs space for the completed 
-       product; twice the space is plenty.
-     */
-    if((t1 = s_alloc(4 * buf_size)) == NULL) return 0;
-    t2 = t1 + buf_size; 
-    t3 = t2 + buf_size;
-    ZERO(t1, 4 * buf_size);
+   mp_size     bot_size;
 
-    /* t1 and t2 are initially used as temporaries to compute the inner product
-       (a1 + a0)(b1 + b0) = a1b1 + a1b0 + a0b1 + a0b0
-     */
-    carry = s_uadd(da, a_top, t1, bot_size, at_size); /* t1 = a1 + a0 */
-    t1[bot_size] = carry;
-
-    carry = s_uadd(db, b_top, t2, bot_size, bt_size); /* t2 = b1 + b0 */
-    t2[bot_size] = carry;
-
-    (void) s_kmul(t1, t2, t3, bot_size + 1, bot_size + 1);   /* t3 = t1 * t2 */
-
-    /* Now we'll get t1 = a0b0 and t2 = a1b1, and subtract them out so that
-       we're left with only the pieces we want:  t3 = a1b0 + a0b1
-     */
-    ZERO(t1, bot_size + 1);
-    ZERO(t2, bot_size + 1);
-    (void) s_kmul(da, db, t1, bot_size, bot_size);     /* t1 = a0 * b0 */
-    (void) s_kmul(a_top, b_top, t2, at_size, bt_size); /* t2 = a1 * b1 */
-
-    /* Subtract out t1 and t2 to get the inner product */
-    s_usub(t3, t1, t3, buf_size + 2, buf_size);
-    s_usub(t3, t2, t3, buf_size + 2, buf_size);
-
-    /* Assemble the output value */
-    COPY(t1, dc, buf_size);
-    (void) s_uadd(t3, dc + bot_size, dc + bot_size,
-         buf_size + 1, buf_size + 1);
+   /* Make sure b is the smaller of the two input values */
+   if (size_b > size_a)
+   {
+       SWAP(mp_digit *, da, db);
+       SWAP(mp_size, size_a, size_b);
+   }
 
-    (void) s_uadd(t2, dc + 2*bot_size, dc + 2*bot_size,
-         buf_size, buf_size);
-    
-    s_free(t1); /* note t2 and t3 are just internal pointers to t1 */
-  } 
-  else {
-    s_umul(da, db, dc, size_a, size_b);
-  }
+   /*
+    * Insure that the bottom is the larger half in an odd-length split; the
+    * code below relies on this being true.
+    */
+   bot_size = (size_a + 1) / 2;
+
+   /*
+    * If the values are big enough to bother with recursion, use the
+    * Karatsuba algorithm to compute the product; otherwise use the normal
+    * multiplication algorithm
+    */
+   if (multiply_threshold &&
+       size_a >= multiply_threshold &&
+       size_b > bot_size)
+   {
+
+       mp_digit   *t1,
+                  *t2,
+                  *t3,
+                   carry;
+
+       mp_digit   *a_top = da + bot_size;
+       mp_digit   *b_top = db + bot_size;
+
+       mp_size     at_size = size_a - bot_size;
+       mp_size     bt_size = size_b - bot_size;
+       mp_size     buf_size = 2 * bot_size;
+
+       /*
+        * Do a single allocation for all three temporary buffers needed; each
+        * buffer must be big enough to hold the product of two bottom halves,
+        * and one buffer needs space for the completed product; twice the
+        * space is plenty.
+        */
+       if ((t1 = s_alloc(4 * buf_size)) == NULL)
+           return 0;
+       t2 = t1 + buf_size;
+       t3 = t2 + buf_size;
+       ZERO(t1, 4 * buf_size);
+
+       /*
+        * t1 and t2 are initially used as temporaries to compute the inner
+        * product (a1 + a0)(b1 + b0) = a1b1 + a1b0 + a0b1 + a0b0
+        */
+       carry = s_uadd(da, a_top, t1, bot_size, at_size);       /* t1 = a1 + a0 */
+       t1[bot_size] = carry;
+
+       carry = s_uadd(db, b_top, t2, bot_size, bt_size);       /* t2 = b1 + b0 */
+       t2[bot_size] = carry;
+
+       (void) s_kmul(t1, t2, t3, bot_size + 1, bot_size + 1);  /* t3 = t1 * t2 */
+
+       /*
+        * Now we'll get t1 = a0b0 and t2 = a1b1, and subtract them out so
+        * that we're left with only the pieces we want:  t3 = a1b0 + a0b1
+        */
+       ZERO(t1, bot_size + 1);
+       ZERO(t2, bot_size + 1);
+       (void) s_kmul(da, db, t1, bot_size, bot_size);  /* t1 = a0 * b0 */
+       (void) s_kmul(a_top, b_top, t2, at_size, bt_size);      /* t2 = a1 * b1 */
+
+       /* Subtract out t1 and t2 to get the inner product */
+       s_usub(t3, t1, t3, buf_size + 2, buf_size);
+       s_usub(t3, t2, t3, buf_size + 2, buf_size);
+
+       /* Assemble the output value */
+       COPY(t1, dc, buf_size);
+       (void) s_uadd(t3, dc + bot_size, dc + bot_size,
+                     buf_size + 1, buf_size + 1);
+
+       (void) s_uadd(t2, dc + 2 * bot_size, dc + 2 * bot_size,
+                     buf_size, buf_size);
+
+       s_free(t1);             /* note t2 and t3 are just internal pointers
+                                * to t1 */
+   }
+   else
+   {
+       s_umul(da, db, dc, size_a, size_b);
+   }
 
-  return 1;
+   return 1;
 }
 
 /* }}} */
 
 /* {{{ s_umul(da, db, dc, size_a, size_b) */
 
-static void     s_umul(mp_digit *da, mp_digit *db, mp_digit *dc,
-              mp_size size_a, mp_size size_b)
+static void
+s_umul(mp_digit * da, mp_digit * db, mp_digit * dc,
+      mp_size size_a, mp_size size_b)
 {
-  mp_size   a, b;
-  mp_word   w;
+   mp_size     a,
+               b;
+   mp_word     w;
 
-  for(a = 0; a < size_a; ++a, ++dc, ++da) {
-    mp_digit *dct = dc;
-    mp_digit *dbt = db;
+   for (a = 0; a < size_a; ++a, ++dc, ++da)
+   {
+       mp_digit   *dct = dc;
+       mp_digit   *dbt = db;
 
-    if(*da == 0)
-      continue;
+       if (*da == 0)
+           continue;
 
-    w = 0;
-    for(b = 0; b < size_b; ++b, ++dbt, ++dct) {
-      w = (mp_word)*da * (mp_word)*dbt + w + (mp_word)*dct;
+       w = 0;
+       for (b = 0; b < size_b; ++b, ++dbt, ++dct)
+       {
+           w = (mp_word) * da * (mp_word) * dbt + w + (mp_word) * dct;
 
-      *dct = LOWER_HALF(w);
-      w = UPPER_HALF(w);
-    }
+           *dct = LOWER_HALF(w);
+           w = UPPER_HALF(w);
+       }
 
-    *dct = (mp_digit)w;
-  }
+       *dct = (mp_digit) w;
+   }
 }
 
 /* }}} */
 
 /* {{{ s_ksqr(da, dc, size_a) */
 
-static int       s_ksqr(mp_digit *da, mp_digit *dc, mp_size size_a)
-{
-  if(multiply_threshold && size_a > multiply_threshold) {
-    mp_size    bot_size = (size_a + 1) / 2;
-    mp_digit  *a_top = da + bot_size;
-    mp_digit  *t1, *t2, *t3;
-    mp_size    at_size = size_a - bot_size;
-    mp_size    buf_size = 2 * bot_size;
-
-    if((t1 = s_alloc(4 * buf_size)) == NULL) return 0;
-    t2 = t1 + buf_size;
-    t3 = t2 + buf_size;
-    ZERO(t1, 4 * buf_size);
-
-    (void) s_ksqr(da, t1, bot_size);    /* t1 = a0 ^ 2 */
-    (void) s_ksqr(a_top, t2, at_size);  /* t2 = a1 ^ 2 */
-
-    (void) s_kmul(da, a_top, t3, bot_size, at_size);  /* t3 = a0 * a1 */
-
-    /* Quick multiply t3 by 2, shifting left (can't overflow) */
-    {
-      int     i, top = bot_size + at_size;
-      mp_word w, save = 0;
+static int
+s_ksqr(mp_digit * da, mp_digit * dc, mp_size size_a)
+{
+   if (multiply_threshold && size_a > multiply_threshold)
+   {
+       mp_size     bot_size = (size_a + 1) / 2;
+       mp_digit   *a_top = da + bot_size;
+       mp_digit   *t1,
+                  *t2,
+                  *t3;
+       mp_size     at_size = size_a - bot_size;
+       mp_size     buf_size = 2 * bot_size;
+
+       if ((t1 = s_alloc(4 * buf_size)) == NULL)
+           return 0;
+       t2 = t1 + buf_size;
+       t3 = t2 + buf_size;
+       ZERO(t1, 4 * buf_size);
+
+       (void) s_ksqr(da, t1, bot_size);        /* t1 = a0 ^ 2 */
+       (void) s_ksqr(a_top, t2, at_size);      /* t2 = a1 ^ 2 */
+
+       (void) s_kmul(da, a_top, t3, bot_size, at_size);        /* t3 = a0 * a1 */
+
+       /* Quick multiply t3 by 2, shifting left (can't overflow) */
+       {
+           int         i,
+                       top = bot_size + at_size;
+           mp_word     w,
+                       save = 0;
+
+           for (i = 0; i < top; ++i)
+           {
+               w = t3[i];
+               w = (w << 1) | save;
+               t3[i] = LOWER_HALF(w);
+               save = UPPER_HALF(w);
+           }
+           t3[i] = LOWER_HALF(save);
+       }
+
+       /* Assemble the output value */
+       COPY(t1, dc, 2 * bot_size);
+       (void) s_uadd(t3, dc + bot_size, dc + bot_size,
+                     buf_size + 1, buf_size + 1);
+
+       (void) s_uadd(t2, dc + 2 * bot_size, dc + 2 * bot_size,
+                     buf_size, buf_size);
+
+       px_free(t1);            /* note that t2 and t2 are internal pointers
+                                * only */
 
-      for(i = 0; i < top; ++i) {
-   w = t3[i];
-   w = (w << 1) | save;
-   t3[i] = LOWER_HALF(w);
-   save = UPPER_HALF(w);
-      }
-      t3[i] = LOWER_HALF(save);
-    }
-
-    /* Assemble the output value */
-    COPY(t1, dc, 2 * bot_size);
-    (void) s_uadd(t3, dc + bot_size, dc + bot_size,
-         buf_size + 1, buf_size + 1);
-    
-    (void) s_uadd(t2, dc + 2*bot_size, dc + 2*bot_size,
-         buf_size, buf_size);
-
-    px_free(t1); /* note that t2 and t2 are internal pointers only */
-
-  } 
-  else {
-    s_usqr(da, dc, size_a);
-  }
+   }
+   else
+   {
+       s_usqr(da, dc, size_a);
+   }
 
-  return 1;
+   return 1;
 }
 
 /* }}} */
 
 /* {{{ s_usqr(da, dc, size_a) */
 
-static void      s_usqr(mp_digit *da, mp_digit *dc, mp_size size_a)
-{
-  mp_size  i, j;
-  mp_word  w;
-
-  for(i = 0; i < size_a; ++i, dc += 2, ++da) {
-    mp_digit  *dct = dc, *dat = da;
-
-    if(*da == 0)
-      continue;
-
-    /* Take care of the first digit, no rollover */
-    w = (mp_word)*dat * (mp_word)*dat + (mp_word)*dct;
-    *dct = LOWER_HALF(w);
-    w = UPPER_HALF(w);
-    ++dat; ++dct;
-
-    for(j = i + 1; j < size_a; ++j, ++dat, ++dct) {
-      mp_word  t = (mp_word)*da * (mp_word)*dat;
-      mp_word  u = w + (mp_word)*dct, ov = 0;
-
-      /* Check if doubling t will overflow a word */
-      if(HIGH_BIT_SET(t))
-   ov = 1;
-
-      w = t + t;
-
-      /* Check if adding u to w will overflow a word */
-      if(ADD_WILL_OVERFLOW(w, u))
-   ov = 1;
-
-      w += u;
-
-      *dct = LOWER_HALF(w);
-      w = UPPER_HALF(w);
-      if(ov) {
-   w += MP_DIGIT_MAX; /* MP_RADIX */
-   ++w;
-      }
-    }
-
-    w = w + *dct;
-    *dct = (mp_digit)w; 
-    while((w = UPPER_HALF(w)) != 0) {
-      ++dct; w = w + *dct;
-      *dct = LOWER_HALF(w);
-    }
-
-    assert(w == 0);
-  }
+static void
+s_usqr(mp_digit * da, mp_digit * dc, mp_size size_a)
+{
+   mp_size     i,
+               j;
+   mp_word     w;
+
+   for (i = 0; i < size_a; ++i, dc += 2, ++da)
+   {
+       mp_digit   *dct = dc,
+                  *dat = da;
+
+       if (*da == 0)
+           continue;
+
+       /* Take care of the first digit, no rollover */
+       w = (mp_word) * dat * (mp_word) * dat + (mp_word) * dct;
+       *dct = LOWER_HALF(w);
+       w = UPPER_HALF(w);
+       ++dat;
+       ++dct;
+
+       for (j = i + 1; j < size_a; ++j, ++dat, ++dct)
+       {
+           mp_word     t = (mp_word) * da * (mp_word) * dat;
+           mp_word     u = w + (mp_word) * dct,
+                       ov = 0;
+
+           /* Check if doubling t will overflow a word */
+           if (HIGH_BIT_SET(t))
+               ov = 1;
+
+           w = t + t;
+
+           /* Check if adding u to w will overflow a word */
+           if (ADD_WILL_OVERFLOW(w, u))
+               ov = 1;
+
+           w += u;
+
+           *dct = LOWER_HALF(w);
+           w = UPPER_HALF(w);
+           if (ov)
+           {
+               w += MP_DIGIT_MAX;      /* MP_RADIX */
+               ++w;
+           }
+       }
+
+       w = w + *dct;
+       *dct = (mp_digit) w;
+       while ((w = UPPER_HALF(w)) != 0)
+       {
+           ++dct;
+           w = w + *dct;
+           *dct = LOWER_HALF(w);
+       }
+
+       assert(w == 0);
+   }
 }
 
 /* }}} */
 
 /* {{{ s_dadd(a, b) */
 
-static void      s_dadd(mp_int a, mp_digit b)
+static void
+s_dadd(mp_int a, mp_digit b)
 {
-  mp_word   w = 0;
-  mp_digit *da = MP_DIGITS(a);
-  mp_size   ua = MP_USED(a);
+   mp_word     w = 0;
+   mp_digit   *da = MP_DIGITS(a);
+   mp_size     ua = MP_USED(a);
 
-  w = (mp_word)*da + b;
-  *da++ = LOWER_HALF(w);
-  w = UPPER_HALF(w);
+   w = (mp_word) * da + b;
+   *da++ = LOWER_HALF(w);
+   w = UPPER_HALF(w);
 
-  for(ua -= 1; ua > 0; --ua, ++da) {
-    w = (mp_word)*da + w;
+   for (ua -= 1; ua > 0; --ua, ++da)
+   {
+       w = (mp_word) * da + w;
 
-    *da = LOWER_HALF(w);
-    w = UPPER_HALF(w);
-  }
+       *da = LOWER_HALF(w);
+       w = UPPER_HALF(w);
+   }
 
-  if(w) {
-    *da = (mp_digit)w;
-    MP_USED(a) += 1;
-  }
+   if (w)
+   {
+       *da = (mp_digit) w;
+       MP_USED(a) += 1;
+   }
 }
 
 /* }}} */
 
 /* {{{ s_dmul(a, b) */
 
-static void      s_dmul(mp_int a, mp_digit b)
+static void
+s_dmul(mp_int a, mp_digit b)
 {
-  mp_word   w = 0;
-  mp_digit *da = MP_DIGITS(a);
-  mp_size   ua = MP_USED(a);
+   mp_word     w = 0;
+   mp_digit   *da = MP_DIGITS(a);
+   mp_size     ua = MP_USED(a);
 
-  while(ua > 0) {
-    w = (mp_word)*da * b + w;
-    *da++ = LOWER_HALF(w);
-    w = UPPER_HALF(w);
-    --ua;
-  }
+   while (ua > 0)
+   {
+       w = (mp_word) * da * b + w;
+       *da++ = LOWER_HALF(w);
+       w = UPPER_HALF(w);
+       --ua;
+   }
 
-  if(w) {
-    *da = (mp_digit)w;
-    MP_USED(a) += 1;
-  }
+   if (w)
+   {
+       *da = (mp_digit) w;
+       MP_USED(a) += 1;
+   }
 }
 
 /* }}} */
 
 /* {{{ s_dbmul(da, b, dc, size_a) */
 
-static void      s_dbmul(mp_digit *da, mp_digit b, mp_digit *dc, mp_size size_a)
+static void
+s_dbmul(mp_digit * da, mp_digit b, mp_digit * dc, mp_size size_a)
 {
-  mp_word  w = 0;
+   mp_word     w = 0;
 
-  while(size_a > 0) {
-    w = (mp_word)*da++ * (mp_word)b + w;
+   while (size_a > 0)
+   {
+       w = (mp_word) * da++ * (mp_word) b + w;
 
-    *dc++ = LOWER_HALF(w);
-    w = UPPER_HALF(w);
-    --size_a;
-  }
+       *dc++ = LOWER_HALF(w);
+       w = UPPER_HALF(w);
+       --size_a;
+   }
 
-  if(w)
-    *dc = LOWER_HALF(w);
+   if (w)
+       *dc = LOWER_HALF(w);
 }
 
 /* }}} */
 
 /* {{{ s_ddiv(da, d, dc, size_a) */
 
-static mp_digit  s_ddiv(mp_int a, mp_digit b)
-{
-  mp_word   w = 0, qdigit;
-  mp_size   ua = MP_USED(a);
-  mp_digit *da = MP_DIGITS(a) + ua - 1;
-  
-  for(/* */; ua > 0; --ua, --da) {
-    w = (w << MP_DIGIT_BIT) | *da;
-
-    if(w >= b) {
-      qdigit = w / b;
-      w = w % b;
-    } 
-    else {
-      qdigit = 0;
-    }
-      
-    *da = (mp_digit)qdigit;
-  }
+static mp_digit
+s_ddiv(mp_int a, mp_digit b)
+{
+   mp_word     w = 0,
+               qdigit;
+   mp_size     ua = MP_USED(a);
+   mp_digit   *da = MP_DIGITS(a) + ua - 1;
+
+   for ( /* */ ; ua > 0; --ua, --da)
+   {
+       w = (w << MP_DIGIT_BIT) | *da;
+
+       if (w >= b)
+       {
+           qdigit = w / b;
+           w = w % b;
+       }
+       else
+       {
+           qdigit = 0;
+       }
+
+       *da = (mp_digit) qdigit;
+   }
 
-  CLAMP(a);
-  return (mp_digit)w;
+   CLAMP(a);
+   return (mp_digit) w;
 }
 
 /* }}} */
 
 /* {{{ s_qdiv(z, p2) */
 
-static void     s_qdiv(mp_int z, mp_size p2)
+static void
+s_qdiv(mp_int z, mp_size p2)
 {
-  mp_size ndig = p2 / MP_DIGIT_BIT, nbits = p2 % MP_DIGIT_BIT;
-  mp_size uz = MP_USED(z);
+   mp_size     ndig = p2 / MP_DIGIT_BIT,
+               nbits = p2 % MP_DIGIT_BIT;
+   mp_size     uz = MP_USED(z);
 
-  if(ndig) {
-    mp_size  mark;
-    mp_digit *to, *from;
+   if (ndig)
+   {
+       mp_size     mark;
+       mp_digit   *to,
+                  *from;
 
-    if(ndig >= uz) {
-      mp_int_zero(z);
-      return;
-    }
+       if (ndig >= uz)
+       {
+           mp_int_zero(z);
+           return;
+       }
 
-    to = MP_DIGITS(z); from = to + ndig;
+       to = MP_DIGITS(z);
+       from = to + ndig;
 
-    for(mark = ndig; mark < uz; ++mark) 
-      *to++ = *from++;
+       for (mark = ndig; mark < uz; ++mark)
+           *to++ = *from++;
 
-    MP_USED(z) = uz - ndig;
-  }
+       MP_USED(z) = uz - ndig;
+   }
 
-  if(nbits) {
-    mp_digit d = 0, *dz, save;
-    mp_size  up = MP_DIGIT_BIT - nbits;
+   if (nbits)
+   {
+       mp_digit    d = 0,
+                  *dz,
+                   save;
+       mp_size     up = MP_DIGIT_BIT - nbits;
 
-    uz = MP_USED(z);
-    dz = MP_DIGITS(z) + uz - 1;
+       uz = MP_USED(z);
+       dz = MP_DIGITS(z) + uz - 1;
 
-    for(/* */; uz > 0; --uz, --dz) {
-      save = *dz;
+       for ( /* */ ; uz > 0; --uz, --dz)
+       {
+           save = *dz;
 
-      *dz = (*dz >> nbits) | (d << up);
-      d = save;
-    }
+           *dz = (*dz >> nbits) | (d << up);
+           d = save;
+       }
 
-    CLAMP(z);
-  }
+       CLAMP(z);
+   }
 
-  if(MP_USED(z) == 1 && z->digits[0] == 0)
-    MP_SIGN(z) = MP_ZPOS;
+   if (MP_USED(z) == 1 && z->digits[0] == 0)
+       MP_SIGN(z) = MP_ZPOS;
 }
 
 /* }}} */
 
 /* {{{ s_qmod(z, p2) */
 
-static void     s_qmod(mp_int z, mp_size p2)
+static void
+s_qmod(mp_int z, mp_size p2)
 {
-  mp_size   start = p2 / MP_DIGIT_BIT + 1, rest = p2 % MP_DIGIT_BIT;
-  mp_size   uz = MP_USED(z);
-  mp_digit  mask = (1 << rest) - 1;
+   mp_size     start = p2 / MP_DIGIT_BIT + 1,
+               rest = p2 % MP_DIGIT_BIT;
+   mp_size     uz = MP_USED(z);
+   mp_digit    mask = (1 << rest) - 1;
 
-  if(start <= uz) {
-    MP_USED(z) = start;
-    z->digits[start - 1] &= mask;
-    CLAMP(z);
-  }
+   if (start <= uz)
+   {
+       MP_USED(z) = start;
+       z->digits[start - 1] &= mask;
+       CLAMP(z);
+   }
 }
 
 /* }}} */
 
 /* {{{ s_qmul(z, p2) */
 
-static int      s_qmul(mp_int z, mp_size p2)
-{
-  mp_size   uz, need, rest, extra, i;
-  mp_digit *from, *to, d;
-
-  if(p2 == 0)
-    return 1;
-
-  uz = MP_USED(z); 
-  need = p2 / MP_DIGIT_BIT; rest = p2 % MP_DIGIT_BIT;
-
-  /* Figure out if we need an extra digit at the top end; this occurs
-     if the topmost `rest' bits of the high-order digit of z are not
-     zero, meaning they will be shifted off the end if not preserved */
-  extra = 0;
-  if(rest != 0) {
-    mp_digit *dz = MP_DIGITS(z) + uz - 1;
-
-    if((*dz >> (MP_DIGIT_BIT - rest)) != 0)
-      extra = 1;
-  }
-
-  if(!s_pad(z, uz + need + extra))
-    return 0;
+static int
+s_qmul(mp_int z, mp_size p2)
+{
+   mp_size     uz,
+               need,
+               rest,
+               extra,
+               i;
+   mp_digit   *from,
+              *to,
+               d;
+
+   if (p2 == 0)
+       return 1;
+
+   uz = MP_USED(z);
+   need = p2 / MP_DIGIT_BIT;
+   rest = p2 % MP_DIGIT_BIT;
+
+   /*
+    * Figure out if we need an extra digit at the top end; this occurs if the
+    * topmost `rest' bits of the high-order digit of z are not zero, meaning
+    * they will be shifted off the end if not preserved
+    */
+   extra = 0;
+   if (rest != 0)
+   {
+       mp_digit   *dz = MP_DIGITS(z) + uz - 1;
+
+       if ((*dz >> (MP_DIGIT_BIT - rest)) != 0)
+           extra = 1;
+   }
 
-  /* If we need to shift by whole digits, do that in one pass, then
-     to back and shift by partial digits.
-   */
-  if(need > 0) {
-    from = MP_DIGITS(z) + uz - 1;
-    to = from + need;
+   if (!s_pad(z, uz + need + extra))
+       return 0;
 
-    for(i = 0; i < uz; ++i)
-      *to-- = *from--;
+   /*
+    * If we need to shift by whole digits, do that in one pass, then to back
+    * and shift by partial digits.
+    */
+   if (need > 0)
+   {
+       from = MP_DIGITS(z) + uz - 1;
+       to = from + need;
 
-    ZERO(MP_DIGITS(z), need);
-    uz += need;
-  }
+       for (i = 0; i < uz; ++i)
+           *to-- = *from--;
 
-  if(rest) {
-    d = 0;
-    for(i = need, from = MP_DIGITS(z) + need; i < uz; ++i, ++from) {
-      mp_digit save = *from;
-      
-      *from = (*from << rest) | (d >> (MP_DIGIT_BIT - rest));
-      d = save;
-    }
+       ZERO(MP_DIGITS(z), need);
+       uz += need;
+   }
 
-    d >>= (MP_DIGIT_BIT - rest);
-    if(d != 0) {
-      *from = d;
-      uz += extra;
-    }
-  }
+   if (rest)
+   {
+       d = 0;
+       for (i = need, from = MP_DIGITS(z) + need; i < uz; ++i, ++from)
+       {
+           mp_digit    save = *from;
+
+           *from = (*from << rest) | (d >> (MP_DIGIT_BIT - rest));
+           d = save;
+       }
+
+       d >>= (MP_DIGIT_BIT - rest);
+       if (d != 0)
+       {
+           *from = d;
+           uz += extra;
+       }
+   }
 
-  MP_USED(z) = uz;
-  CLAMP(z);
+   MP_USED(z) = uz;
+   CLAMP(z);
 
-  return 1;
+   return 1;
 }
 
 /* }}} */
@@ -2733,190 +3071,218 @@ static int      s_qmul(mp_int z, mp_size p2)
 /* {{{ s_qsub(z, p2) */
 
 /* Subtract |z| from 2^p2, assuming 2^p2 > |z|, and set z to be positive */
-static int       s_qsub(mp_int z, mp_size p2)
+static int
+s_qsub(mp_int z, mp_size p2)
 {
-  mp_digit hi = (1 << (p2 % MP_DIGIT_BIT)), *zp;
-  mp_size  tdig = (p2 / MP_DIGIT_BIT), pos;
-  mp_word  w = 0;
+   mp_digit    hi = (1 << (p2 % MP_DIGIT_BIT)),
+              *zp;
+   mp_size     tdig = (p2 / MP_DIGIT_BIT),
+               pos;
+   mp_word     w = 0;
 
-  if(!s_pad(z, tdig + 1))
-    return 0;
+   if (!s_pad(z, tdig + 1))
+       return 0;
 
-  for(pos = 0, zp = MP_DIGITS(z); pos < tdig; ++pos, ++zp) {
-    w = ((mp_word) MP_DIGIT_MAX + 1) - w - (mp_word)*zp;
+   for (pos = 0, zp = MP_DIGITS(z); pos < tdig; ++pos, ++zp)
+   {
+       w = ((mp_word) MP_DIGIT_MAX + 1) - w - (mp_word) * zp;
 
-    *zp = LOWER_HALF(w);
-    w = UPPER_HALF(w) ? 0 : 1;
-  }
+       *zp = LOWER_HALF(w);
+       w = UPPER_HALF(w) ? 0 : 1;
+   }
+
+   w = ((mp_word) MP_DIGIT_MAX + 1 + hi) - w - (mp_word) * zp;
+   *zp = LOWER_HALF(w);
 
-  w = ((mp_word) MP_DIGIT_MAX + 1 + hi) - w - (mp_word)*zp;
-  *zp = LOWER_HALF(w);
+   assert(UPPER_HALF(w) != 0); /* no borrow out should be possible */
 
-  assert(UPPER_HALF(w) != 0); /* no borrow out should be possible */
-  
-  MP_SIGN(z) = MP_ZPOS;
-  CLAMP(z);
+   MP_SIGN(z) = MP_ZPOS;
+   CLAMP(z);
 
-  return 1;
+   return 1;
 }
 
 /* }}} */
 
 /* {{{ s_dp2k(z) */
 
-static int      s_dp2k(mp_int z)
+static int
+s_dp2k(mp_int z)
 {
-  int       k = 0;
-  mp_digit *dp = MP_DIGITS(z), d;
+   int         k = 0;
+   mp_digit   *dp = MP_DIGITS(z),
+               d;
 
-  if(MP_USED(z) == 1 && *dp == 0)
-    return 1;
+   if (MP_USED(z) == 1 && *dp == 0)
+       return 1;
 
-  while(*dp == 0) {
-    k += MP_DIGIT_BIT;
-    ++dp;
-  }
-  
-  d = *dp;
-  while((d & 1) == 0) {
-    d >>= 1;
-    ++k;
-  }
+   while (*dp == 0)
+   {
+       k += MP_DIGIT_BIT;
+       ++dp;
+   }
 
-  return k;
+   d = *dp;
+   while ((d & 1) == 0)
+   {
+       d >>= 1;
+       ++k;
+   }
+
+   return k;
 }
 
 /* }}} */
 
 /* {{{ s_isp2(z) */
 
-static int       s_isp2(mp_int z)
+static int
+s_isp2(mp_int z)
 {
-  mp_size uz = MP_USED(z), k = 0;
-  mp_digit *dz = MP_DIGITS(z), d;
+   mp_size     uz = MP_USED(z),
+               k = 0;
+   mp_digit   *dz = MP_DIGITS(z),
+               d;
 
-  while(uz > 1) {
-    if(*dz++ != 0)
-      return -1;
-    k += MP_DIGIT_BIT;
-    --uz;
-  }
+   while (uz > 1)
+   {
+       if (*dz++ != 0)
+           return -1;
+       k += MP_DIGIT_BIT;
+       --uz;
+   }
 
-  d = *dz;
-  while(d > 1) {
-    if(d & 1)
-      return -1;
-    ++k; d >>= 1;
-  }
+   d = *dz;
+   while (d > 1)
+   {
+       if (d & 1)
+           return -1;
+       ++k;
+       d >>= 1;
+   }
 
-  return (int) k;
+   return (int) k;
 }
 
 /* }}} */
 
 /* {{{ s_2expt(z, k) */
 
-static int       s_2expt(mp_int z, int k)
+static int
+s_2expt(mp_int z, int k)
 {
-  mp_size  ndig, rest;
-  mp_digit *dz;
+   mp_size     ndig,
+               rest;
+   mp_digit   *dz;
 
-  ndig = (k + MP_DIGIT_BIT) / MP_DIGIT_BIT;
-  rest = k % MP_DIGIT_BIT;
+   ndig = (k + MP_DIGIT_BIT) / MP_DIGIT_BIT;
+   rest = k % MP_DIGIT_BIT;
 
-  if(!s_pad(z, ndig))
-    return 0;
+   if (!s_pad(z, ndig))
+       return 0;
 
-  dz = MP_DIGITS(z);
-  ZERO(dz, ndig);
-  *(dz + ndig - 1) = (1 << rest);
-  MP_USED(z) = ndig;
+   dz = MP_DIGITS(z);
+   ZERO(dz, ndig);
+   *(dz + ndig - 1) = (1 << rest);
+   MP_USED(z) = ndig;
 
-  return 1;
+   return 1;
 }
 
 /* }}} */
 
 /* {{{ s_norm(a, b) */
 
-static int      s_norm(mp_int a, mp_int b)
+static int
+s_norm(mp_int a, mp_int b)
 {
-  mp_digit d = b->digits[MP_USED(b) - 1];
-  int      k = 0;
+   mp_digit    d = b->digits[MP_USED(b) - 1];
+   int         k = 0;
 
-  while(d < (mp_digit) (1 << (MP_DIGIT_BIT - 1))) { /* d < (MP_RADIX / 2) */
-    d <<= 1;
-    ++k;
-  }
+   while (d < (mp_digit) (1 << (MP_DIGIT_BIT - 1)))
+   {                           /* d < (MP_RADIX / 2) */
+       d <<= 1;
+       ++k;
+   }
 
-  /* These multiplications can't fail */
-  if(k != 0) {
-    (void) s_qmul(a, (mp_size) k);
-    (void) s_qmul(b, (mp_size) k);
-  }
+   /* These multiplications can't fail */
+   if (k != 0)
+   {
+       (void) s_qmul(a, (mp_size) k);
+       (void) s_qmul(b, (mp_size) k);
+   }
 
-  return k;
+   return k;
 }
 
 /* }}} */
 
 /* {{{ s_brmu(z, m) */
 
-static mp_result s_brmu(mp_int z, mp_int m)
+static mp_result
+s_brmu(mp_int z, mp_int m)
 {
-  mp_size um = MP_USED(m) * 2;
+   mp_size     um = MP_USED(m) * 2;
 
-  if(!s_pad(z, um))
-    return MP_MEMORY;
+   if (!s_pad(z, um))
+       return MP_MEMORY;
 
-  s_2expt(z, MP_DIGIT_BIT * um);
-  return mp_int_div(z, m, z, NULL);
+   s_2expt(z, MP_DIGIT_BIT * um);
+   return mp_int_div(z, m, z, NULL);
 }
 
 /* }}} */
 
 /* {{{ s_reduce(x, m, mu, q1, q2) */
 
-static int       s_reduce(mp_int x, mp_int m, mp_int mu, mp_int q1, mp_int q2)
+static int
+s_reduce(mp_int x, mp_int m, mp_int mu, mp_int q1, mp_int q2)
 {
-  mp_size   um = MP_USED(m), umb_p1, umb_m1;
+   mp_size     um = MP_USED(m),
+               umb_p1,
+               umb_m1;
 
-  umb_p1 = (um + 1) * MP_DIGIT_BIT;
-  umb_m1 = (um - 1) * MP_DIGIT_BIT;
+   umb_p1 = (um + 1) * MP_DIGIT_BIT;
+   umb_m1 = (um - 1) * MP_DIGIT_BIT;
 
-  if(mp_int_copy(x, q1) != MP_OK)
-    return 0;
+   if (mp_int_copy(x, q1) != MP_OK)
+       return 0;
 
-  /* Compute q2 = floor((floor(x / b^(k-1)) * mu) / b^(k+1)) */
-  s_qdiv(q1, umb_m1);
-  UMUL(q1, mu, q2);
-  s_qdiv(q2, umb_p1);
+   /* Compute q2 = floor((floor(x / b^(k-1)) * mu) / b^(k+1)) */
+   s_qdiv(q1, umb_m1);
+   UMUL(q1, mu, q2);
+   s_qdiv(q2, umb_p1);
 
-  /* Set x = x mod b^(k+1) */
-  s_qmod(x, umb_p1);
+   /* Set x = x mod b^(k+1) */
+   s_qmod(x, umb_p1);
 
-  /* Now, q is a guess for the quotient a / m.
-     Compute x - q * m mod b^(k+1), replacing x.  This may be off
-     by a factor of 2m, but no more than that.
-   */
-  UMUL(q2, m, q1);
-  s_qmod(q1, umb_p1);
-  (void) mp_int_sub(x, q1, x); /* can't fail */
+   /*
+    * Now, q is a guess for the quotient a / m. Compute x - q * m mod
+    * b^(k+1), replacing x.  This may be off by a factor of 2m, but no more
+    * than that.
+    */
+   UMUL(q2, m, q1);
+   s_qmod(q1, umb_p1);
+   (void) mp_int_sub(x, q1, x);    /* can't fail */
 
-  /* The result may be < 0; if it is, add b^(k+1) to pin it in the
-     proper range. */
-  if((CMPZ(x) < 0) && !s_qsub(x, umb_p1))
-    return 0;
+   /*
+    * The result may be < 0; if it is, add b^(k+1) to pin it in the proper
+    * range.
+    */
+   if ((CMPZ(x) < 0) && !s_qsub(x, umb_p1))
+       return 0;
 
-  /* If x > m, we need to back it off until it is in range.
-     This will be required at most twice.  */
-  if(mp_int_compare(x, m) >= 0)
-    (void) mp_int_sub(x, m, x);
-  if(mp_int_compare(x, m) >= 0)
-    (void) mp_int_sub(x, m, x);
+   /*
+    * If x > m, we need to back it off until it is in range. This will be
+    * required at most twice.
+    */
+   if (mp_int_compare(x, m) >= 0)
+       (void) mp_int_sub(x, m, x);
+   if (mp_int_compare(x, m) >= 0)
+       (void) mp_int_sub(x, m, x);
 
-  /* At this point, x has been properly reduced. */
-  return 1;
+   /* At this point, x has been properly reduced. */
+   return 1;
 }
 
 /* }}} */
@@ -2925,75 +3291,95 @@ static int       s_reduce(mp_int x, mp_int m, mp_int mu, mp_int q1, mp_int q2)
 
 /* Perform modular exponentiation using Barrett's method, where mu is
    the reduction constant for m.  Assumes a < m, b > 0. */
-static mp_result s_embar(mp_int a, mp_int b, mp_int m, mp_int mu, mp_int c)
-{
-  mp_digit  *db, *dbt, umu, d;
-  mpz_t     temp[3]; 
-  mp_result res;
-  int       last = 0;
-
-  umu = MP_USED(mu); db = MP_DIGITS(b); dbt = db + MP_USED(b) - 1;
-
-  while(last < 3) 
-    SETUP(mp_int_init_size(TEMP(last), 2 * umu), last);
-
-  (void) mp_int_set_value(c, 1);
-
-  /* Take care of low-order digits */
-  while(db < dbt) {
-    int      i;
-
-    for(d = *db, i = MP_DIGIT_BIT; i > 0; --i, d >>= 1) {
-      if(d & 1) {
-   /* The use of a second temporary avoids allocation */
-   UMUL(c, a, TEMP(0));
-   if(!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2))) {
-     res = MP_MEMORY; goto CLEANUP;
+static mp_result
+s_embar(mp_int a, mp_int b, mp_int m, mp_int mu, mp_int c)
+{
+   mp_digit   *db,
+              *dbt,
+               umu,
+               d;
+   mpz_t       temp[3];
+   mp_result   res;
+   int         last = 0;
+
+   umu = MP_USED(mu);
+   db = MP_DIGITS(b);
+   dbt = db + MP_USED(b) - 1;
+
+   while (last < 3)
+       SETUP(mp_int_init_size(TEMP(last), 2 * umu), last);
+
+   (void) mp_int_set_value(c, 1);
+
+   /* Take care of low-order digits */
+   while (db < dbt)
+   {
+       int         i;
+
+       for (d = *db, i = MP_DIGIT_BIT; i > 0; --i, d >>= 1)
+       {
+           if (d & 1)
+           {
+               /* The use of a second temporary avoids allocation */
+               UMUL(c, a, TEMP(0));
+               if (!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2)))
+               {
+                   res = MP_MEMORY;
+                   goto CLEANUP;
+               }
+               mp_int_copy(TEMP(0), c);
+           }
+
+
+           USQR(a, TEMP(0));
+           assert(MP_SIGN(TEMP(0)) == MP_ZPOS);
+           if (!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2)))
+           {
+               res = MP_MEMORY;
+               goto CLEANUP;
+           }
+           assert(MP_SIGN(TEMP(0)) == MP_ZPOS);
+           mp_int_copy(TEMP(0), a);
+
+
+       }
+
+       ++db;
    }
-   mp_int_copy(TEMP(0), c);
-      }
-
-
-      USQR(a, TEMP(0));
-      assert(MP_SIGN(TEMP(0)) == MP_ZPOS);
-      if(!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2))) {
-   res = MP_MEMORY; goto CLEANUP;
-      }
-      assert(MP_SIGN(TEMP(0)) == MP_ZPOS);
-      mp_int_copy(TEMP(0), a);
 
+   /* Take care of highest-order digit */
+   d = *dbt;
+   for (;;)
+   {
+       if (d & 1)
+       {
+           UMUL(c, a, TEMP(0));
+           if (!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2)))
+           {
+               res = MP_MEMORY;
+               goto CLEANUP;
+           }
+           mp_int_copy(TEMP(0), c);
+       }
+
+       d >>= 1;
+       if (!d)
+           break;
+
+       USQR(a, TEMP(0));
+       if (!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2)))
+       {
+           res = MP_MEMORY;
+           goto CLEANUP;
+       }
+       (void) mp_int_copy(TEMP(0), a);
+   }
 
-    }
-
-    ++db;
-  }
-
-  /* Take care of highest-order digit */
-  d = *dbt;
-  for(;;) {
-    if(d & 1) {
-      UMUL(c, a, TEMP(0));
-      if(!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2))) {
-   res = MP_MEMORY; goto CLEANUP;
-      }
-      mp_int_copy(TEMP(0), c);
-    }
-    
-    d >>= 1;
-    if(!d) break;
-
-    USQR(a, TEMP(0));
-    if(!s_reduce(TEMP(0), m, mu, TEMP(1), TEMP(2))) {
-      res = MP_MEMORY; goto CLEANUP;
-    }
-    (void) mp_int_copy(TEMP(0), a);
-  }
+CLEANUP:
+   while (--last >= 0)
+       mp_int_clear(TEMP(last));
 
- CLEANUP:
-  while(--last >= 0)
-    mp_int_clear(TEMP(last));
-  
-  return res;
+   return res;
 }
 
 /* }}} */
@@ -3003,92 +3389,109 @@ static mp_result s_embar(mp_int a, mp_int b, mp_int m, mp_int mu, mp_int c)
 /* Precondition:  a >= b and b > 0
    Postcondition: a' = a / b, b' = a % b
  */
-static mp_result s_udiv(mp_int a, mp_int b)
-{
-  mpz_t     q, r, t;
-  mp_size   ua, ub, qpos = 0;
-  mp_digit *da, btop;
-  mp_result res = MP_OK;
-  int       k, skip = 0;
-
-  /* Force signs to positive */
-  MP_SIGN(a) = MP_ZPOS;
-  MP_SIGN(b) = MP_ZPOS;
-
-  /* Normalize, per Knuth */
-  k = s_norm(a, b);
-
-  ua = MP_USED(a); ub = MP_USED(b); btop = b->digits[ub - 1];
-  if((res = mp_int_init_size(&q, ua)) != MP_OK) return res;
-  if((res = mp_int_init_size(&t, ua + 1)) != MP_OK) goto CLEANUP;
-
-  da = MP_DIGITS(a);
-  r.digits = da + ua - 1;  /* The contents of r are shared with a */
-  r.used   = 1;
-  r.sign   = MP_ZPOS;
-  r.alloc  = MP_ALLOC(a);
-  ZERO(t.digits, t.alloc);
-
-  /* Solve for quotient digits, store in q.digits in reverse order */
-  while(r.digits >= da) {
-    assert(qpos <= q.alloc);
-
-    if(s_ucmp(b, &r) > 0) {
-      r.digits -= 1;
-      r.used += 1;
-      
-      if(++skip > 1)
-   q.digits[qpos++] = 0;
-      
-      CLAMP(&r);
-    }
-    else {
-      mp_word  pfx = r.digits[r.used - 1];
-      mp_word  qdigit;
-      
-      if(r.used > 1 && (pfx < btop || r.digits[r.used - 2] == 0)) {
-   pfx <<= MP_DIGIT_BIT / 2;
-   pfx <<= MP_DIGIT_BIT / 2;
-   pfx |= r.digits[r.used - 2];
-      }
-
-      qdigit = pfx / btop;
-      if(qdigit > MP_DIGIT_MAX) 
-   qdigit = 1;
-      
-      s_dbmul(MP_DIGITS(b), (mp_digit) qdigit, t.digits, ub);
-      t.used = ub + 1; CLAMP(&t);
-      while(s_ucmp(&t, &r) > 0) {
-   --qdigit;
-   (void) mp_int_sub(&t, b, &t); /* cannot fail */
-      }
-      
-      s_usub(r.digits, t.digits, r.digits, r.used, t.used);
-      CLAMP(&r);
-      
-      q.digits[qpos++] = (mp_digit) qdigit;
-      ZERO(t.digits, t.used);
-      skip = 0;
-    }
-  }
-  
-  /* Put quotient digits in the correct order, and discard extra zeroes */
-  q.used = qpos;
-  REV(mp_digit, q.digits, qpos);
-  CLAMP(&q);
-
-  /* Denormalize the remainder */
-  CLAMP(a);
-  if(k != 0)
-    s_qdiv(a, k);
-  
-  mp_int_copy(a, b);  /* ok:  0 <= r < b */
-  mp_int_copy(&q, a); /* ok:  q <= a     */
-  
-  mp_int_clear(&t);
- CLEANUP:
-  mp_int_clear(&q);
-  return res;
+static mp_result
+s_udiv(mp_int a, mp_int b)
+{
+   mpz_t       q,
+               r,
+               t;
+   mp_size     ua,
+               ub,
+               qpos = 0;
+   mp_digit   *da,
+               btop;
+   mp_result   res = MP_OK;
+   int         k,
+               skip = 0;
+
+   /* Force signs to positive */
+   MP_SIGN(a) = MP_ZPOS;
+   MP_SIGN(b) = MP_ZPOS;
+
+   /* Normalize, per Knuth */
+   k = s_norm(a, b);
+
+   ua = MP_USED(a);
+   ub = MP_USED(b);
+   btop = b->digits[ub - 1];
+   if ((res = mp_int_init_size(&q, ua)) != MP_OK)
+       return res;
+   if ((res = mp_int_init_size(&t, ua + 1)) != MP_OK)
+       goto CLEANUP;
+
+   da = MP_DIGITS(a);
+   r.digits = da + ua - 1;     /* The contents of r are shared with a */
+   r.used = 1;
+   r.sign = MP_ZPOS;
+   r.alloc = MP_ALLOC(a);
+   ZERO(t.digits, t.alloc);
+
+   /* Solve for quotient digits, store in q.digits in reverse order */
+   while (r.digits >= da)
+   {
+       assert(qpos <= q.alloc);
+
+       if (s_ucmp(b, &r) > 0)
+       {
+           r.digits -= 1;
+           r.used += 1;
+
+           if (++skip > 1)
+               q.digits[qpos++] = 0;
+
+           CLAMP(&r);
+       }
+       else
+       {
+           mp_word     pfx = r.digits[r.used - 1];
+           mp_word     qdigit;
+
+           if (r.used > 1 && (pfx < btop || r.digits[r.used - 2] == 0))
+           {
+               pfx <<= MP_DIGIT_BIT / 2;
+               pfx <<= MP_DIGIT_BIT / 2;
+               pfx |= r.digits[r.used - 2];
+           }
+
+           qdigit = pfx / btop;
+           if (qdigit > MP_DIGIT_MAX)
+               qdigit = 1;
+
+           s_dbmul(MP_DIGITS(b), (mp_digit) qdigit, t.digits, ub);
+           t.used = ub + 1;
+           CLAMP(&t);
+           while (s_ucmp(&t, &r) > 0)
+           {
+               --qdigit;
+               (void) mp_int_sub(&t, b, &t);   /* cannot fail */
+           }
+
+           s_usub(r.digits, t.digits, r.digits, r.used, t.used);
+           CLAMP(&r);
+
+           q.digits[qpos++] = (mp_digit) qdigit;
+           ZERO(t.digits, t.used);
+           skip = 0;
+       }
+   }
+
+   /* Put quotient digits in the correct order, and discard extra zeroes */
+   q.used = qpos;
+   REV(mp_digit, q.digits, qpos);
+   CLAMP(&q);
+
+   /* Denormalize the remainder */
+   CLAMP(a);
+   if (k != 0)
+       s_qdiv(a, k);
+
+   mp_int_copy(a, b);          /* ok:  0 <= r < b */
+   mp_int_copy(&q, a);         /* ok:  q <= a     */
+
+   mp_int_clear(&t);
+CLEANUP:
+   mp_int_clear(&q);
+   return res;
 }
 
 /* }}} */
@@ -3096,133 +3499,147 @@ static mp_result s_udiv(mp_int a, mp_int b)
 /* {{{ s_outlen(z, r) */
 
 /* Precondition:  2 <= r < 64 */
-static int       s_outlen(mp_int z, mp_size r)
+static int
+s_outlen(mp_int z, mp_size r)
 {
-  mp_result  bits;
-  double     raw;
+   mp_result   bits;
+   double      raw;
 
-  bits = mp_int_count_bits(z);
-  raw = (double)bits * s_log2[r];
+   bits = mp_int_count_bits(z);
+   raw = (double) bits *s_log2[r];
 
-  return (int)(raw + 0.999999);
+   return (int) (raw + 0.999999);
 }
 
 /* }}} */
 
 /* {{{ s_inlen(len, r) */
 
-static mp_size   s_inlen(int len, mp_size r)
+static mp_size
+s_inlen(int len, mp_size r)
 {
-  double  raw = (double)len / s_log2[r];
-  mp_size bits = (mp_size)(raw + 0.5);
+   double      raw = (double) len / s_log2[r];
+   mp_size     bits = (mp_size) (raw + 0.5);
 
-  return (mp_size)((bits + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT);
+   return (mp_size) ((bits + (MP_DIGIT_BIT - 1)) / MP_DIGIT_BIT);
 }
 
 /* }}} */
 
 /* {{{ s_ch2val(c, r) */
 
-static int       s_ch2val(char c, int r)
+static int
+s_ch2val(char c, int r)
 {
-  int out;
+   int         out;
 
-  if(isdigit((unsigned char)c))
-    out = c - '0';
-  else if(r > 10 && isalpha((unsigned char) c))
-    out = toupper((unsigned char) c) - 'A' + 10;
-  else
-    return -1;
+   if (isdigit((unsigned char) c))
+       out = c - '0';
+   else if (r > 10 && isalpha((unsigned char) c))
+       out = toupper((unsigned char) c) - 'A' + 10;
+   else
+       return -1;
 
-  return (out >= r) ? -1 : out;
+   return (out >= r) ? -1 : out;
 }
 
 /* }}} */
 
 /* {{{ s_val2ch(v, caps) */
 
-static char      s_val2ch(int v, int caps)
+static char
+s_val2ch(int v, int caps)
 {
-  assert(v >= 0);
+   assert(v >= 0);
 
-  if(v < 10)
-    return v + '0';
-  else {
-    char out = (v - 10) + 'a';
+   if (v < 10)
+       return v + '0';
+   else
+   {
+       char        out = (v - 10) + 'a';
 
-    if(caps)
-      return toupper((unsigned char) out);
-    else
-      return out;
-  }
+       if (caps)
+           return toupper((unsigned char) out);
+       else
+           return out;
+   }
 }
 
 /* }}} */
 
 /* {{{ s_2comp(buf, len) */
 
-static void      s_2comp(unsigned char *buf, int len)
+static void
+s_2comp(unsigned char *buf, int len)
 {
-  int i;
-  unsigned short s = 1;
+   int         i;
+   unsigned short s = 1;
 
-  for(i = len - 1; i >= 0; --i) {
-    unsigned char c = ~buf[i];
+   for (i = len - 1; i >= 0; --i)
+   {
+       unsigned char c = ~buf[i];
 
-    s = c + s;
-    c = s & UCHAR_MAX;
-    s >>= CHAR_BIT;
+       s = c + s;
+       c = s & UCHAR_MAX;
+       s >>= CHAR_BIT;
 
-    buf[i] = c;
-  }
+       buf[i] = c;
+   }
 
-  /* last carry out is ignored */
+   /* last carry out is ignored */
 }
 
 /* }}} */
 
 /* {{{ s_tobin(z, buf, *limpos) */
 
-static mp_result s_tobin(mp_int z, unsigned char *buf, int *limpos, int pad)
+static mp_result
+s_tobin(mp_int z, unsigned char *buf, int *limpos, int pad)
 {
-  mp_size uz;
-  mp_digit *dz;
-  int pos = 0, limit = *limpos;
+   mp_size     uz;
+   mp_digit   *dz;
+   int         pos = 0,
+               limit = *limpos;
 
-  uz = MP_USED(z); dz = MP_DIGITS(z);
-  while(uz > 0 && pos < limit) {
-    mp_digit d = *dz++;
-    int i;
+   uz = MP_USED(z);
+   dz = MP_DIGITS(z);
+   while (uz > 0 && pos < limit)
+   {
+       mp_digit    d = *dz++;
+       int         i;
 
-    for(i = sizeof(mp_digit); i > 0 && pos < limit; --i) {
-      buf[pos++] = (unsigned char)d;
-      d >>= CHAR_BIT;
+       for (i = sizeof(mp_digit); i > 0 && pos < limit; --i)
+       {
+           buf[pos++] = (unsigned char) d;
+           d >>= CHAR_BIT;
 
-      /* Don't write leading zeroes */
-      if(d == 0 && uz == 1)
-   i = 0; /* exit loop without signaling truncation */
-    }
+           /* Don't write leading zeroes */
+           if (d == 0 && uz == 1)
+               i = 0;          /* exit loop without signaling truncation */
+       }
 
-    /* Detect truncation (loop exited with pos >= limit) */
-    if(i > 0) break;
+       /* Detect truncation (loop exited with pos >= limit) */
+       if (i > 0)
+           break;
 
-    --uz;
-  }
+       --uz;
+   }
 
-  if(pad != 0 && (buf[pos - 1] >> (CHAR_BIT - 1))) {
-    if(pos < limit)
-      buf[pos++] = 0;
-    else
-      uz = 1;
-  }
+   if (pad != 0 && (buf[pos - 1] >> (CHAR_BIT - 1)))
+   {
+       if (pos < limit)
+           buf[pos++] = 0;
+       else
+           uz = 1;
+   }
 
-  /* Digits are in reverse order, fix that */
-  REV(unsigned char, buf, pos);
+   /* Digits are in reverse order, fix that */
+   REV(unsigned char, buf, pos);
 
-  /* Return the number of bytes actually written */
-  *limpos = pos;
+   /* Return the number of bytes actually written */
+   *limpos = pos;
 
-  return (uz == 0) ? MP_OK : MP_TRUNC;
+   return (uz == 0) ? MP_OK : MP_TRUNC;
 }
 
 /* }}} */
@@ -3230,30 +3647,32 @@ static mp_result s_tobin(mp_int z, unsigned char *buf, int *limpos, int pad)
 /* {{{ s_print(tag, z) */
 
 #if 0
-void      s_print(char *tag, mp_int z)
+void
+s_print(char *tag, mp_int z)
 {
-  int  i;
+   int         i;
 
-  fprintf(stderr, "%s: %c ", tag,
-     (MP_SIGN(z) == MP_NEG) ? '-' : '+');
+   fprintf(stderr, "%s: %c ", tag,
+           (MP_SIGN(z) == MP_NEG) ? '-' : '+');
 
-  for(i = MP_USED(z) - 1; i >= 0; --i)
-    fprintf(stderr, "%0*X", (int)(MP_DIGIT_BIT / 4), z->digits[i]);
+   for (i = MP_USED(z) - 1; i >= 0; --i)
+       fprintf(stderr, "%0*X", (int) (MP_DIGIT_BIT / 4), z->digits[i]);
 
-  fputc('\n', stderr);
+   fputc('\n', stderr);
 
 }
 
-void      s_print_buf(char *tag, mp_digit *buf, mp_size num)
+void
+s_print_buf(char *tag, mp_digit * buf, mp_size num)
 {
-  int  i;
+   int         i;
 
-  fprintf(stderr, "%s: ", tag);
+   fprintf(stderr, "%s: ", tag);
 
-  for(i = num - 1; i >= 0; --i) 
-    fprintf(stderr, "%0*X", (int)(MP_DIGIT_BIT / 4), buf[i]);
+   for (i = num - 1; i >= 0; --i)
+       fprintf(stderr, "%0*X", (int) (MP_DIGIT_BIT / 4), buf[i]);
 
-  fputc('\n', stderr);
+   fputc('\n', stderr);
 }
 #endif
 
index 67adb3bf4527a1c6b50d22d9e2f5f2c4e4e9bd9b..f730b320506a476dea59e777b8ce5d6038e170de 100644 (file)
@@ -1,8 +1,8 @@
 /*
-  Name:     imath.h
-  Purpose:  Arbitrary precision integer arithmetic routines.
-  Author:   M. J. Fromberger <http://www.dartmouth.edu/~sting/>
-  Info:     Id: imath.h 21 2006-04-02 18:58:36Z sting
+  Name:        imath.h
+  Purpose: Arbitrary precision integer arithmetic routines.
+  Author:  M. J. Fromberger <http://www.dartmouth.edu/~sting/>
+  Info:        Id: imath.h 21 2006-04-02 18:58:36Z sting
 
   Copyright (C) 2002 Michael J. Fromberger, All Rights Reserved.
 
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-  NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
   BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
   ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
   SOFTWARE.
  */
-/* $PostgreSQL: pgsql/contrib/pgcrypto/imath.h,v 1.4 2006/07/19 17:05:50 neilc Exp $ */
+/* $PostgreSQL: pgsql/contrib/pgcrypto/imath.h,v 1.5 2006/10/04 00:29:46 momjian Exp $ */
 
 #ifndef IMATH_H_
 #define IMATH_H_
 
 #include <limits.h>
 
-typedef unsigned char      mp_sign;
-typedef unsigned int       mp_size;
-typedef int                mp_result;
+typedef unsigned char mp_sign;
+typedef unsigned int mp_size;
+typedef int mp_result;
+
 #ifdef USE_LONG_LONG
-typedef uint32             mp_digit;
-typedef uint64             mp_word;
-#define MP_DIGIT_MAX       0xFFFFFFFFULL
-#define MP_WORD_MAX        0xFFFFFFFFFFFFFFFFULL
+typedef uint32 mp_digit;
+typedef uint64 mp_word;
+
+#define MP_DIGIT_MAX      0xFFFFFFFFULL
+#define MP_WORD_MAX           0xFFFFFFFFFFFFFFFFULL
 #else
-typedef uint16             mp_digit;
-typedef uint32             mp_word;
-#define MP_DIGIT_MAX       0xFFFFUL
-#define MP_WORD_MAX        0xFFFFFFFFUL
+typedef uint16 mp_digit;
+typedef uint32 mp_word;
+
+#define MP_DIGIT_MAX      0xFFFFUL
+#define MP_WORD_MAX           0xFFFFFFFFUL
 #endif
 
-typedef struct mpz {
-  mp_digit   *digits;
-  mp_size     alloc;
-  mp_size     used;
-  mp_sign     sign;
-} mpz_t, *mp_int;
+typedef struct mpz
+{
+   mp_digit   *digits;
+   mp_size     alloc;
+   mp_size     used;
+   mp_sign     sign;
+}  mpz_t, *mp_int;
 
 #define MP_DIGITS(Z) ((Z)->digits)
 #define MP_ALLOC(Z)  ((Z)->alloc)
-#define MP_USED(Z)   ((Z)->used)
-#define MP_SIGN(Z)   ((Z)->sign)
+#define MP_USED(Z)  ((Z)->used)
+#define MP_SIGN(Z)  ((Z)->sign)
 
 extern const mp_result MP_OK;
 extern const mp_result MP_FALSE;
@@ -72,131 +76,140 @@ extern const mp_result MP_UNDEF;
 extern const mp_result MP_TRUNC;
 extern const mp_result MP_BADARG;
 
-#define MP_DIGIT_BIT    (sizeof(mp_digit) * CHAR_BIT)
-#define MP_WORD_BIT     (sizeof(mp_word) * CHAR_BIT)
+#define MP_DIGIT_BIT   (sizeof(mp_digit) * CHAR_BIT)
+#define MP_WORD_BIT        (sizeof(mp_word) * CHAR_BIT)
 
-#define MP_MIN_RADIX    2
-#define MP_MAX_RADIX    36
+#define MP_MIN_RADIX   2
+#define MP_MAX_RADIX   36
 
-extern const mp_sign   MP_NEG;
-extern const mp_sign   MP_ZPOS;
+extern const mp_sign MP_NEG;
+extern const mp_sign MP_ZPOS;
 
 #define mp_int_is_odd(Z)  ((Z)->digits[0] & 1)
 #define mp_int_is_even(Z) !((Z)->digits[0] & 1)
 
-mp_size   mp_get_default_precision(void);
-void      mp_set_default_precision(mp_size s);
-mp_size   mp_get_multiply_threshold(void);
-void      mp_set_multiply_threshold(mp_size s);
-
-mp_result mp_int_init(mp_int z);
-mp_int    mp_int_alloc(void);
-mp_result mp_int_init_size(mp_int z, mp_size prec);
-mp_result mp_int_init_copy(mp_int z, mp_int old);
-mp_result mp_int_init_value(mp_int z, int value);
-mp_result mp_int_set_value(mp_int z, int value);
-void      mp_int_clear(mp_int z);
-void      mp_int_free(mp_int z);
-
-mp_result mp_int_copy(mp_int a, mp_int c);           /* c = a     */
-void      mp_int_swap(mp_int a, mp_int c);           /* swap a, c */
-void      mp_int_zero(mp_int z);                     /* z = 0     */
-mp_result mp_int_abs(mp_int a, mp_int c);            /* c = |a|   */
-mp_result mp_int_neg(mp_int a, mp_int c);            /* c = -a    */
-mp_result mp_int_add(mp_int a, mp_int b, mp_int c);  /* c = a + b */
-mp_result mp_int_add_value(mp_int a, int value, mp_int c);
-mp_result mp_int_sub(mp_int a, mp_int b, mp_int c);  /* c = a - b */
-mp_result mp_int_sub_value(mp_int a, int value, mp_int c);
-mp_result mp_int_mul(mp_int a, mp_int b, mp_int c);  /* c = a * b */
-mp_result mp_int_mul_value(mp_int a, int value, mp_int c);
-mp_result mp_int_mul_pow2(mp_int a, int p2, mp_int c);
-mp_result mp_int_sqr(mp_int a, mp_int c);            /* c = a * a */
-mp_result mp_int_div(mp_int a, mp_int b,             /* q = a / b */
-            mp_int q, mp_int r);            /* r = a % b */
-mp_result mp_int_div_value(mp_int a, int value,      /* q = a / value */
-              mp_int q, int *r);        /* r = a % value */
-mp_result mp_int_div_pow2(mp_int a, int p2,          /* q = a / 2^p2  */
-             mp_int q, mp_int r);       /* r = q % 2^p2  */
-mp_result mp_int_mod(mp_int a, mp_int m, mp_int c);  /* c = a % m */
+mp_size        mp_get_default_precision(void);
+void       mp_set_default_precision(mp_size s);
+mp_size        mp_get_multiply_threshold(void);
+void       mp_set_multiply_threshold(mp_size s);
+
+mp_result  mp_int_init(mp_int z);
+mp_int     mp_int_alloc(void);
+mp_result  mp_int_init_size(mp_int z, mp_size prec);
+mp_result  mp_int_init_copy(mp_int z, mp_int old);
+mp_result  mp_int_init_value(mp_int z, int value);
+mp_result  mp_int_set_value(mp_int z, int value);
+void       mp_int_clear(mp_int z);
+void       mp_int_free(mp_int z);
+
+mp_result  mp_int_copy(mp_int a, mp_int c);    /* c = a     */
+void       mp_int_swap(mp_int a, mp_int c);    /* swap a, c */
+void       mp_int_zero(mp_int z);      /* z = 0     */
+mp_result  mp_int_abs(mp_int a, mp_int c);     /* c = |a|   */
+mp_result  mp_int_neg(mp_int a, mp_int c);     /* c = -a    */
+mp_result  mp_int_add(mp_int a, mp_int b, mp_int c);   /* c = a + b */
+mp_result  mp_int_add_value(mp_int a, int value, mp_int c);
+mp_result  mp_int_sub(mp_int a, mp_int b, mp_int c);   /* c = a - b */
+mp_result  mp_int_sub_value(mp_int a, int value, mp_int c);
+mp_result  mp_int_mul(mp_int a, mp_int b, mp_int c);   /* c = a * b */
+mp_result  mp_int_mul_value(mp_int a, int value, mp_int c);
+mp_result  mp_int_mul_pow2(mp_int a, int p2, mp_int c);
+mp_result  mp_int_sqr(mp_int a, mp_int c);     /* c = a * a */
+mp_result
+mp_int_div(mp_int a, mp_int b, /* q = a / b */
+          mp_int q, mp_int r); /* r = a % b */
+mp_result
+mp_int_div_value(mp_int a, int value,  /* q = a / value */
+                mp_int q, int *r);     /* r = a % value */
+mp_result
+mp_int_div_pow2(mp_int a, int p2,      /* q = a / 2^p2  */
+               mp_int q, mp_int r);    /* r = q % 2^p2  */
+mp_result  mp_int_mod(mp_int a, mp_int m, mp_int c);   /* c = a % m */
+
 #define   mp_int_mod_value(A, V, R) mp_int_div_value((A), (V), 0, (R))
-mp_result mp_int_expt(mp_int a, int b, mp_int c);    /* c = a^b   */
-mp_result mp_int_expt_value(int a, int b, mp_int c); /* c = a^b   */
+mp_result  mp_int_expt(mp_int a, int b, mp_int c);     /* c = a^b   */
+mp_result  mp_int_expt_value(int a, int b, mp_int c);  /* c = a^b   */
 
-int       mp_int_compare(mp_int a, mp_int b);          /* a <=> b     */
-int       mp_int_compare_unsigned(mp_int a, mp_int b); /* |a| <=> |b| */
-int       mp_int_compare_zero(mp_int z);               /* a <=> 0     */
-int       mp_int_compare_value(mp_int z, int value);   /* a <=> v     */
+int            mp_int_compare(mp_int a, mp_int b); /* a <=> b     */
+int            mp_int_compare_unsigned(mp_int a, mp_int b);        /* |a| <=> |b| */
+int            mp_int_compare_zero(mp_int z);      /* a <=> 0     */
+int            mp_int_compare_value(mp_int z, int value);  /* a <=> v     */
 
 /* Returns true if v|a, false otherwise (including errors) */
-int       mp_int_divisible_value(mp_int a, int v);
+int            mp_int_divisible_value(mp_int a, int v);
 
 /* Returns k >= 0 such that z = 2^k, if one exists; otherwise < 0 */
-int       mp_int_is_pow2(mp_int z);
+int            mp_int_is_pow2(mp_int z);
 
-mp_result mp_int_exptmod(mp_int a, mp_int b, mp_int m,
-            mp_int c);                    /* c = a^b (mod m) */
-mp_result mp_int_exptmod_evalue(mp_int a, int value, 
-               mp_int m, mp_int c);   /* c = a^v (mod m) */
-mp_result mp_int_exptmod_bvalue(int value, mp_int b,
-               mp_int m, mp_int c);   /* c = v^b (mod m) */
-mp_result mp_int_exptmod_known(mp_int a, mp_int b,
-                  mp_int m, mp_int mu,
-                  mp_int c);              /* c = a^b (mod m) */
-mp_result mp_int_redux_const(mp_int m, mp_int c); 
+mp_result
+mp_int_exptmod(mp_int a, mp_int b, mp_int m,
+              mp_int c);       /* c = a^b (mod m) */
+mp_result
+mp_int_exptmod_evalue(mp_int a, int value,
+                     mp_int m, mp_int c);      /* c = a^v (mod m) */
+mp_result
+mp_int_exptmod_bvalue(int value, mp_int b,
+                     mp_int m, mp_int c);      /* c = v^b (mod m) */
+mp_result
+mp_int_exptmod_known(mp_int a, mp_int b,
+                    mp_int m, mp_int mu,
+                    mp_int c); /* c = a^b (mod m) */
+mp_result  mp_int_redux_const(mp_int m, mp_int c);
 
-mp_result mp_int_invmod(mp_int a, mp_int m, mp_int c); /* c = 1/a (mod m) */
+mp_result  mp_int_invmod(mp_int a, mp_int m, mp_int c);        /* c = 1/a (mod m) */
 
-mp_result mp_int_gcd(mp_int a, mp_int b, mp_int c);    /* c = gcd(a, b)   */
+mp_result  mp_int_gcd(mp_int a, mp_int b, mp_int c);   /* c = gcd(a, b)   */
 
-mp_result mp_int_egcd(mp_int a, mp_int b, mp_int c,    /* c = gcd(a, b)   */
-             mp_int x, mp_int y);             /* c = ax + by     */
+mp_result
+mp_int_egcd(mp_int a, mp_int b, mp_int c,      /* c = gcd(a, b)   */
+           mp_int x, mp_int y);    /* c = ax + by     */
 
-mp_result mp_int_sqrt(mp_int a, mp_int c);          /* c = floor(sqrt(q)) */
+mp_result  mp_int_sqrt(mp_int a, mp_int c);    /* c = floor(sqrt(q)) */
 
 /* Convert to an int, if representable (returns MP_RANGE if not). */
-mp_result mp_int_to_int(mp_int z, int *out);
+mp_result  mp_int_to_int(mp_int z, int *out);
 
 /* Convert to nul-terminated string with the specified radix, writing at
    most limit characters including the nul terminator  */
-mp_result mp_int_to_string(mp_int z, mp_size radix, 
-              char *str, int limit);
+mp_result mp_int_to_string(mp_int z, mp_size radix,
+                char *str, int limit);
 
-/* Return the number of characters required to represent 
+/* Return the number of characters required to represent
    z in the given radix.  May over-estimate. */
-mp_result mp_int_string_len(mp_int z, mp_size radix);
+mp_result  mp_int_string_len(mp_int z, mp_size radix);
 
 /* Read zero-terminated string into z */
-mp_result mp_int_read_string(mp_int z, mp_size radix, const char *str);
-mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str, 
-                 char **end);
+mp_result  mp_int_read_string(mp_int z, mp_size radix, const char *str);
+mp_result mp_int_read_cstring(mp_int z, mp_size radix, const char *str,
+                   char **end);
 
 /* Return the number of significant bits in z */
-mp_result mp_int_count_bits(mp_int z);
+mp_result  mp_int_count_bits(mp_int z);
 
 /* Convert z to two's complement binary, writing at most limit bytes */
-mp_result mp_int_to_binary(mp_int z, unsigned char *buf, int limit);
+mp_result  mp_int_to_binary(mp_int z, unsigned char *buf, int limit);
 
 /* Read a two's complement binary value into z from the given buffer */
-mp_result mp_int_read_binary(mp_int z, unsigned char *buf, int len);
+mp_result  mp_int_read_binary(mp_int z, unsigned char *buf, int len);
 
 /* Return the number of bytes required to represent z in binary. */
-mp_result mp_int_binary_len(mp_int z);
+mp_result  mp_int_binary_len(mp_int z);
 
 /* Convert z to unsigned binary, writing at most limit bytes */
-mp_result mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit);
+mp_result  mp_int_to_unsigned(mp_int z, unsigned char *buf, int limit);
 
 /* Read an unsigned binary value into z from the given buffer */
-mp_result mp_int_read_unsigned(mp_int z, unsigned char *buf, int len);
+mp_result  mp_int_read_unsigned(mp_int z, unsigned char *buf, int len);
 
 /* Return the number of bytes required to represent z as unsigned output */
-mp_result mp_int_unsigned_len(mp_int z);
+mp_result  mp_int_unsigned_len(mp_int z);
 
 /* Return a statically allocated string describing error code res */
 const char *mp_error_string(mp_result res);
 
 #if 0
-void      s_print(char *tag, mp_int z);
-void      s_print_buf(char *tag, mp_digit *buf, mp_size num);
+void       s_print(char *tag, mp_int z);
+void       s_print_buf(char *tag, mp_digit * buf, mp_size num);
 #endif
 
-#endif /* end IMATH_H_ */
+#endif   /* end IMATH_H_ */
index 6e1d97c4e31f1a336a2f9f432834eff763acc37f..d5530c39ed99e4f97961ef291308e3f3e62db1a9 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/internal-sha2.c,v 1.1 2006/07/13 04:15:24 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/internal-sha2.c,v 1.2 2006/10/04 00:29:46 momjian Exp $
  */
 
 #include "postgres.h"
 #include "px.h"
 #include "sha2.h"
 
-void init_sha224(PX_MD * h);
-void init_sha256(PX_MD * h);
-void init_sha384(PX_MD * h);
-void init_sha512(PX_MD * h);
+void       init_sha224(PX_MD * h);
+void       init_sha256(PX_MD * h);
+void       init_sha384(PX_MD * h);
+void       init_sha512(PX_MD * h);
 
 /* SHA224 */
 
@@ -314,4 +314,3 @@ init_sha512(PX_MD * md)
 
    md->reset(md);
 }
-
index 4b90399cdd69858885efef74379ccad195bf1912..c0d8846a3c8a159d32deae2f79972be2a47f8cdf 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.24 2006/07/13 04:15:24 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/internal.c,v 1.25 2006/10/04 00:29:46 momjian Exp $
  */
 
 #include "postgres.h"
 static void init_md5(PX_MD * h);
 static void init_sha1(PX_MD * h);
 
-void init_sha224(PX_MD * h);
-void init_sha256(PX_MD * h);
-void init_sha384(PX_MD * h);
-void init_sha512(PX_MD * h);
+void       init_sha224(PX_MD * h);
+void       init_sha256(PX_MD * h);
+void       init_sha384(PX_MD * h);
+void       init_sha512(PX_MD * h);
 
 struct int_digest
 {
index 2ad5a63ebff9134be6764e25c5ae865fcd89bee6..7b159c4d568b8ae4cbdfc912968657b3e338e3b5 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.29 2006/09/05 23:02:28 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.30 2006/10/04 00:29:46 momjian Exp $
  */
 
 #include "postgres.h"
@@ -58,7 +58,6 @@
  */
 
 #include <openssl/aes.h>
-
 #else                          /* old OPENSSL */
 
 /*
  * Emulate newer digest API.
  */
 
-static void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
+static void
+EVP_MD_CTX_init(EVP_MD_CTX *ctx)
 {
    memset(ctx, 0, sizeof(*ctx));
 }
 
-static int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
+static int
+EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
 {
    memset(ctx, 0, sizeof(*ctx));
    return 1;
 }
 
-static int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *md, void *engine)
+static int
+EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *md, void *engine)
 {
    EVP_DigestInit(ctx, md);
    return 1;
 }
 
-static int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *res, unsigned int *len)
+static int
+EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *res, unsigned int *len)
 {
    EVP_DigestFinal(ctx, res, len);
    return 1;
 }
-
 #endif   /* old OpenSSL */
 
 /*
@@ -154,11 +156,12 @@ static int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *res, unsigned int
 #include "sha2.c"
 #include "internal-sha2.c"
 
-typedef void (*init_f)(PX_MD *md);
+typedef void (*init_f) (PX_MD * md);
 
-static int compat_find_digest(const char *name, PX_MD **res)
+static int
+compat_find_digest(const char *name, PX_MD ** res)
 {
-   init_f init = NULL;
+   init_f      init = NULL;
 
    if (pg_strcasecmp(name, "sha224") == 0)
        init = init_sha224;
@@ -175,7 +178,6 @@ static int compat_find_digest(const char *name, PX_MD **res)
    init(*res);
    return 0;
 }
-
 #else
 #define compat_find_digest(name, res)  (PXE_NO_HASH)
 #endif
@@ -184,29 +186,32 @@ static int compat_find_digest(const char *name, PX_MD **res)
  * Hashes
  */
 
-typedef struct OSSLDigest {
+typedef struct OSSLDigest
+{
    const EVP_MD *algo;
-   EVP_MD_CTX ctx;
-} OSSLDigest;
+   EVP_MD_CTX  ctx;
+}  OSSLDigest;
 
 static unsigned
 digest_result_size(PX_MD * h)
 {
-   OSSLDigest *digest = (OSSLDigest *)h->p.ptr;
+   OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
+
    return EVP_MD_CTX_size(&digest->ctx);
 }
 
 static unsigned
 digest_block_size(PX_MD * h)
 {
-   OSSLDigest *digest = (OSSLDigest *)h->p.ptr;
+   OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
+
    return EVP_MD_CTX_block_size(&digest->ctx);
 }
 
 static void
 digest_reset(PX_MD * h)
 {
-   OSSLDigest *digest = (OSSLDigest *)h->p.ptr;
+   OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
 
    EVP_DigestInit_ex(&digest->ctx, digest->algo, NULL);
 }
@@ -214,7 +219,7 @@ digest_reset(PX_MD * h)
 static void
 digest_update(PX_MD * h, const uint8 *data, unsigned dlen)
 {
-   OSSLDigest *digest = (OSSLDigest *)h->p.ptr;
+   OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
 
    EVP_DigestUpdate(&digest->ctx, data, dlen);
 }
@@ -222,7 +227,7 @@ digest_update(PX_MD * h, const uint8 *data, unsigned dlen)
 static void
 digest_finish(PX_MD * h, uint8 *dst)
 {
-   OSSLDigest *digest = (OSSLDigest *)h->p.ptr;
+   OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
 
    EVP_DigestFinal_ex(&digest->ctx, dst, NULL);
 }
@@ -230,7 +235,7 @@ digest_finish(PX_MD * h, uint8 *dst)
 static void
 digest_free(PX_MD * h)
 {
-   OSSLDigest *digest = (OSSLDigest *)h->p.ptr;
+   OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
 
    EVP_MD_CTX_cleanup(&digest->ctx);
 
@@ -560,7 +565,7 @@ ossl_des3_ecb_encrypt(PX_Cipher * c, const uint8 *data, unsigned dlen,
    ossldata   *od = c->ptr;
 
    for (i = 0; i < dlen / bs; i++)
-       DES_ecb3_encrypt((void *)(data + i * bs), (void *)(res + i * bs),
+       DES_ecb3_encrypt((void *) (data + i * bs), (void *) (res + i * bs),
                         &od->u.des3.k1, &od->u.des3.k2, &od->u.des3.k3, 1);
    return 0;
 }
@@ -574,7 +579,7 @@ ossl_des3_ecb_decrypt(PX_Cipher * c, const uint8 *data, unsigned dlen,
    ossldata   *od = c->ptr;
 
    for (i = 0; i < dlen / bs; i++)
-       DES_ecb3_encrypt((void *)(data + i * bs), (void *)(res + i * bs),
+       DES_ecb3_encrypt((void *) (data + i * bs), (void *) (res + i * bs),
                         &od->u.des3.k1, &od->u.des3.k2, &od->u.des3.k3, 0);
    return 0;
 }
index 083b31d4c2eff65527c1efa74846d20ecc6134c1..31c3a59ee5a444f24ba22d9957fd6f1619c54dd2 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.23 2006/09/05 21:26:48 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.24 2006/10/04 00:29:46 momjian Exp $
  */
 
 #include "postgres.h"
@@ -491,9 +491,9 @@ PG_FUNCTION_INFO_V1(pg_random_bytes);
 Datum
 pg_random_bytes(PG_FUNCTION_ARGS)
 {
-   int err;
-   int len = PG_GETARG_INT32(0);
-   bytea *res;
+   int         err;
+   int         len = PG_GETARG_INT32(0);
+   bytea      *res;
 
    if (len < 1 || len > 1024)
        ereport(ERROR,
@@ -504,7 +504,7 @@ pg_random_bytes(PG_FUNCTION_ARGS)
    VARATT_SIZEP(res) = VARHDRSZ + len;
 
    /* generate result */
-   err = px_get_random_bytes((uint8*)VARDATA(res), len);
+   err = px_get_random_bytes((uint8 *) VARDATA(res), len);
    if (err < 0)
        ereport(ERROR,
                (errcode(ERRCODE_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION),
index 4f2e5ec9626d5bc109cfb9840aea84685cfb5b84..d2b5d0c8de73ee0d88b7c31b738ca135ac5f540d 100644 (file)
@@ -26,7 +26,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-internal.c,v 1.6 2006/07/13 04:52:51 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/pgp-mpi-internal.c,v 1.7 2006/10/04 00:29:46 momjian Exp $
  */
 #include "postgres.h"
 
 #include "mbuf.h"
 #include "pgp.h"
 
-static mpz_t *mp_new()
+static mpz_t *
+mp_new()
 {
-   mpz_t *mp = mp_int_alloc();
+   mpz_t      *mp = mp_int_alloc();
+
    mp_int_init_size(mp, 256);
    return mp;
 }
 
-static void mp_clear_free(mpz_t *a)
+static void
+mp_clear_free(mpz_t * a)
 {
    if (!a)
        return;
@@ -52,25 +55,29 @@ static void mp_clear_free(mpz_t *a)
 }
 
 
-static int mp_px_rand(uint32 bits, mpz_t *res)
+static int
+mp_px_rand(uint32 bits, mpz_t * res)
 {
-   int err;
-   unsigned bytes = (bits + 7) / 8;
-   int last_bits = bits & 7;
-   uint8 *buf;
+   int         err;
+   unsigned    bytes = (bits + 7) / 8;
+   int         last_bits = bits & 7;
+   uint8      *buf;
 
    buf = px_alloc(bytes);
    err = px_get_random_bytes(buf, bytes);
-   if (err < 0) {
+   if (err < 0)
+   {
        px_free(buf);
        return err;
    }
 
    /* clear unnecessary bits and set last bit to one */
-   if (last_bits) {
+   if (last_bits)
+   {
        buf[0] >>= 8 - last_bits;
        buf[0] |= 1 << (last_bits - 1);
-   } else
+   }
+   else
        buf[0] |= 1 << 7;
 
    mp_int_read_unsigned(res, buf, bytes);
@@ -80,9 +87,11 @@ static int mp_px_rand(uint32 bits, mpz_t *res)
    return 0;
 }
 
-static void mp_modmul(mpz_t *a, mpz_t *b, mpz_t *p, mpz_t *res)
+static void
+mp_modmul(mpz_t * a, mpz_t * b, mpz_t * p, mpz_t * res)
 {
-   mpz_t *tmp = mp_new();
+   mpz_t      *tmp = mp_new();
+
    mp_int_mul(a, b, tmp);
    mp_int_mod(tmp, p, res);
    mp_clear_free(tmp);
@@ -92,6 +101,7 @@ static mpz_t *
 mpi_to_bn(PGP_MPI * n)
 {
    mpz_t      *bn = mp_new();
+
    mp_int_read_unsigned(bn, n->data, n->bytes);
 
    if (!bn)
@@ -107,11 +117,11 @@ mpi_to_bn(PGP_MPI * n)
 }
 
 static PGP_MPI *
-bn_to_mpi(mpz_t *bn)
+bn_to_mpi(mpz_t * bn)
 {
    int         res;
    PGP_MPI    *n;
-   int bytes;
+   int         bytes;
 
    res = pgp_mpi_alloc(mp_int_count_bits(bn), &n);
    if (res < 0)
index 98e1fc1964dc4fab64fb5a19a801e9a7d9092ede..31623fb9a6990544e9546e21248ee23cd412620a 100644 (file)
@@ -33,7 +33,7 @@
  *
  * $From: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
  *
- * $PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.7 2006/07/13 04:15:25 neilc Exp $
+ * $PostgreSQL: pgsql/contrib/pgcrypto/sha2.c,v 1.8 2006/10/04 00:29:46 momjian Exp $
  */
 
 #include "postgres.h"
@@ -534,7 +534,7 @@ SHA256_Update(SHA256_CTX * context, const uint8 *data, size_t len)
 }
 
 static void
-SHA256_Last(SHA256_CTX *context)
+SHA256_Last(SHA256_CTX * context)
 {
    unsigned int usedspace;
 
@@ -1023,4 +1023,3 @@ SHA224_Final(uint8 digest[], SHA224_CTX * context)
    /* Clean up state data: */
    memset(context, 0, sizeof(*context));
 }
-
index 13d3f2164fcdd36f9f6cf38d4d190000e81d6788..002536b920196588d10ef777abbe339f77ad31ba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $PostgreSQL: pgsql/contrib/pgrowlocks/pgrowlocks.c,v 1.4 2006/07/13 16:57:31 momjian Exp $
+ * $PostgreSQL: pgsql/contrib/pgrowlocks/pgrowlocks.c,v 1.5 2006/10/04 00:29:46 momjian Exp $
  *
  * Copyright (c) 2005-2006 Tatsuo Ishii
  *
@@ -63,11 +63,12 @@ extern Datum pgrowlocks(PG_FUNCTION_ARGS);
  */
 #undef MAKERANGEVARFROMNAMELIST_HAS_TWO_ARGS
 
-typedef struct {
+typedef struct
+{
    Relation    rel;
    HeapScanDesc scan;
-   int ncolumns;
-} MyData;
+   int         ncolumns;
+}  MyData;
 
 Datum
 pgrowlocks(PG_FUNCTION_ARGS)
@@ -78,7 +79,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
    TupleDesc   tupdesc;
    AttInMetadata *attinmeta;
    Datum       result;
-   MyData *mydata;
+   MyData     *mydata;
    Relation    rel;
 
    if (SRF_IS_FIRSTCALL())
@@ -96,8 +97,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
 
        relname = PG_GETARG_TEXT_P(0);
 #ifdef MAKERANGEVARFROMNAMELIST_HAS_TWO_ARGS
-       relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname,                                                "pgrowlocks"));
-
+       relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname, "pgrowlocks"));
 #else
        relrv = makeRangeVarFromNameList(textToQualifiedNameList(relname));
 #endif
@@ -114,7 +114,7 @@ pgrowlocks(PG_FUNCTION_ARGS)
 
    funcctx = SRF_PERCALL_SETUP();
    attinmeta = funcctx->attinmeta;
-   mydata = (MyData *)funcctx->user_fctx;
+   mydata = (MyData *) funcctx->user_fctx;
    scan = mydata->scan;
 
    /* scan the relation */
@@ -124,16 +124,16 @@ pgrowlocks(PG_FUNCTION_ARGS)
        LockBuffer(scan->rs_cbuf, BUFFER_LOCK_SHARE);
 
        if (HeapTupleSatisfiesUpdate(tuple->t_data, GetCurrentCommandId(), scan->rs_cbuf)
-           == HeapTupleBeingUpdated)
+           == HeapTupleBeingUpdated)
        {
 
-           char **values;
-           int i;
+           char      **values;
+           int         i;
 
            values = (char **) palloc(mydata->ncolumns * sizeof(char *));
 
            i = 0;
-           values[i++] = (char *)DirectFunctionCall1(tidout, PointerGetDatum(&tuple->t_self));
+           values[i++] = (char *) DirectFunctionCall1(tidout, PointerGetDatum(&tuple->t_self));
 
 #ifdef HEAP_XMAX_SHARED_LOCK
            if (tuple->t_data->t_infomask & HEAP_XMAX_SHARED_LOCK)
@@ -143,15 +143,15 @@ pgrowlocks(PG_FUNCTION_ARGS)
 #else
            values[i++] = pstrdup("Exclusive");
 #endif
-           values[i] = palloc(NCHARS*sizeof(char));
+           values[i] = palloc(NCHARS * sizeof(char));
            snprintf(values[i++], NCHARS, "%d", HeapTupleHeaderGetXmax(tuple->t_data));
 #ifdef HEAP_XMAX_SHARED_LOCK
            if (tuple->t_data->t_infomask & HEAP_XMAX_IS_MULTI)
            {
                TransactionId *xids;
-               int nxids;
-               int j;
-               int isValidXid = 0;     /* any valid xid ever exists? */
+               int         nxids;
+               int         j;
+               int         isValidXid = 0;     /* any valid xid ever exists? */
 
                values[i++] = pstrdup("true");
                nxids = GetMultiXactIdMembers(HeapTupleHeaderGetXmax(tuple->t_data), &xids);
@@ -160,45 +160,44 @@ pgrowlocks(PG_FUNCTION_ARGS)
                    elog(ERROR, "GetMultiXactIdMembers returns error");
                }
 
-               values[i] = palloc(NCHARS*nxids);
-               values[i+1] = palloc(NCHARS*nxids);
+               values[i] = palloc(NCHARS * nxids);
+               values[i + 1] = palloc(NCHARS * nxids);
                strcpy(values[i], "{");
-               strcpy(values[i+1], "{");
+               strcpy(values[i + 1], "{");
 
-               for (j=0;j<nxids;j++)
+               for (j = 0; j < nxids; j++)
                {
-                   char buf[NCHARS];
+                   char        buf[NCHARS];
 
                    if (TransactionIdIsInProgress(xids[j]))
                    {
                        if (isValidXid)
                        {
                            strcat(values[i], ",");
-                           strcat(values[i+1], ",");
+                           strcat(values[i + 1], ",");
                        }
                        snprintf(buf, NCHARS, "%d", xids[j]);
                        strcat(values[i], buf);
                        snprintf(buf, NCHARS, "%d", BackendXidGetPid(xids[j]));
-                       strcat(values[i+1], buf);
+                       strcat(values[i + 1], buf);
 
                        isValidXid = 1;
                    }
                }
 
                strcat(values[i], "}");
-               strcat(values[i+1], "}");
+               strcat(values[i + 1], "}");
                i++;
            }
            else
            {
                values[i++] = pstrdup("false");
-               values[i] = palloc(NCHARS*sizeof(char));
+               values[i] = palloc(NCHARS * sizeof(char));
                snprintf(values[i++], NCHARS, "{%d}", HeapTupleHeaderGetXmax(tuple->t_data));
 
-               values[i] = palloc(NCHARS*sizeof(char));
+               values[i] = palloc(NCHARS * sizeof(char));
                snprintf(values[i++], NCHARS, "{%d}", BackendXidGetPid(HeapTupleHeaderGetXmax(tuple->t_data)));
            }
-
 #else
            values[i++] = pstrdup("false");
            values[i++] = pstrdup("{}");
index 6ff6012073a7c172d9f5fb48a02dea46ed828e93..5bac70949d098a48d0cd5cb1e5a37b0bf39ff5c1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.24 2006/09/04 02:03:04 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/pgstattuple/pgstattuple.c,v 1.25 2006/10/04 00:29:46 momjian Exp $
  *
  * Copyright (c) 2001,2002 Tatsuo Ishii
  *
@@ -51,36 +51,36 @@ extern Datum pgstattuplebyid(PG_FUNCTION_ARGS);
  */
 typedef struct pgstattuple_type
 {
-   uint64  table_len;
-   uint64  tuple_count;
-   uint64  tuple_len;
-   uint64  dead_tuple_count;
-   uint64  dead_tuple_len;
-   uint64  free_space;         /* free/reusable space in bytes */
-} pgstattuple_type;
-
-typedef void (*pgstat_page)(pgstattuple_type *, Relation, BlockNumber);
-
-static Datum build_pgstattuple_type(pgstattuple_type *stat,
-   FunctionCallInfo fcinfo);
+   uint64      table_len;
+   uint64      tuple_count;
+   uint64      tuple_len;
+   uint64      dead_tuple_count;
+   uint64      dead_tuple_len;
+   uint64      free_space;     /* free/reusable space in bytes */
+}  pgstattuple_type;
+
+typedef void (*pgstat_page) (pgstattuple_type *, Relation, BlockNumber);
+
+static Datum build_pgstattuple_type(pgstattuple_type * stat,
+                      FunctionCallInfo fcinfo);
 static Datum pgstat_relation(Relation rel, FunctionCallInfo fcinfo);
 static Datum pgstat_heap(Relation rel, FunctionCallInfo fcinfo);
-static void pgstat_btree_page(pgstattuple_type *stat,
-   Relation rel, BlockNumber blkno);
-static void pgstat_hash_page(pgstattuple_type *stat,
-   Relation rel, BlockNumber blkno);
-static void pgstat_gist_page(pgstattuple_type *stat,
-   Relation rel, BlockNumber blkno);
+static void pgstat_btree_page(pgstattuple_type * stat,
+                 Relation rel, BlockNumber blkno);
+static void pgstat_hash_page(pgstattuple_type * stat,
+                Relation rel, BlockNumber blkno);
+static void pgstat_gist_page(pgstattuple_type * stat,
+                Relation rel, BlockNumber blkno);
 static Datum pgstat_index(Relation rel, BlockNumber start,
-   pgstat_page pagefn, FunctionCallInfo fcinfo);
-static void pgstat_index_page(pgstattuple_type *stat, Page page,
-   OffsetNumber minoff, OffsetNumber maxoff);
+            pgstat_page pagefn, FunctionCallInfo fcinfo);
+static void pgstat_index_page(pgstattuple_type * stat, Page page,
+                 OffsetNumber minoff, OffsetNumber maxoff);
 
 /*
  * build_pgstattuple_type -- build a pgstattuple_type tuple
  */
 static Datum
-build_pgstattuple_type(pgstattuple_type *stat, FunctionCallInfo fcinfo)
+build_pgstattuple_type(pgstattuple_type * stat, FunctionCallInfo fcinfo)
 {
 #define NCOLUMNS   9
 #define NCHARS     32
@@ -91,7 +91,7 @@ build_pgstattuple_type(pgstattuple_type *stat, FunctionCallInfo fcinfo)
    int         i;
    double      tuple_percent;
    double      dead_tuple_percent;
-   double      free_percent;       /* free/reusable space in % */
+   double      free_percent;   /* free/reusable space in % */
    TupleDesc   tupdesc;
    AttInMetadata *attinmeta;
 
@@ -190,49 +190,49 @@ pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
 {
    const char *err;
 
-   switch(rel->rd_rel->relkind)
+   switch (rel->rd_rel->relkind)
    {
-   case RELKIND_RELATION:
-   case RELKIND_TOASTVALUE:
-   case RELKIND_UNCATALOGED:
-   case RELKIND_SEQUENCE:
-       return pgstat_heap(rel, fcinfo);
-   case RELKIND_INDEX:
-       switch(rel->rd_rel->relam)
-       {
-       case BTREE_AM_OID:
-           return pgstat_index(rel, BTREE_METAPAGE + 1,
-               pgstat_btree_page, fcinfo);
-       case HASH_AM_OID:
-           return pgstat_index(rel, HASH_METAPAGE + 1,
-               pgstat_hash_page, fcinfo);
-       case GIST_AM_OID:
-           return pgstat_index(rel, GIST_ROOT_BLKNO + 1,
-               pgstat_gist_page, fcinfo);
-       case GIN_AM_OID:
-           err = "gin index";
+       case RELKIND_RELATION:
+       case RELKIND_TOASTVALUE:
+       case RELKIND_UNCATALOGED:
+       case RELKIND_SEQUENCE:
+           return pgstat_heap(rel, fcinfo);
+       case RELKIND_INDEX:
+           switch (rel->rd_rel->relam)
+           {
+               case BTREE_AM_OID:
+                   return pgstat_index(rel, BTREE_METAPAGE + 1,
+                                       pgstat_btree_page, fcinfo);
+               case HASH_AM_OID:
+                   return pgstat_index(rel, HASH_METAPAGE + 1,
+                                       pgstat_hash_page, fcinfo);
+               case GIST_AM_OID:
+                   return pgstat_index(rel, GIST_ROOT_BLKNO + 1,
+                                       pgstat_gist_page, fcinfo);
+               case GIN_AM_OID:
+                   err = "gin index";
+                   break;
+               default:
+                   err = "unknown index";
+                   break;
+           }
+           break;
+       case RELKIND_VIEW:
+           err = "view";
+           break;
+       case RELKIND_COMPOSITE_TYPE:
+           err = "composite type";
            break;
        default:
-           err = "unknown index";
+           err = "unknown";
            break;
-       }
-       break;
-   case RELKIND_VIEW:
-       err = "view";
-       break;
-   case RELKIND_COMPOSITE_TYPE:
-       err = "composite type";
-       break;
-   default:
-       err = "unknown";
-       break;
    }
 
    ereport(ERROR,
            (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
             errmsg("\"%s\" (%s) is not supported",
-               RelationGetRelationName(rel), err)));
-   return 0;   /* should not happen */
+                   RelationGetRelationName(rel), err)));
+   return 0;                   /* should not happen */
 }
 
 /*
@@ -241,13 +241,13 @@ pgstat_relation(Relation rel, FunctionCallInfo fcinfo)
 static Datum
 pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
 {
-   HeapScanDesc    scan;
-   HeapTuple       tuple;
-   BlockNumber     nblocks;
-   BlockNumber     block = 0;  /* next block to count free space in */
-   BlockNumber     tupblock;
-   Buffer          buffer;
-   pgstattuple_type    stat = { 0 };
+   HeapScanDesc scan;
+   HeapTuple   tuple;
+   BlockNumber nblocks;
+   BlockNumber block = 0;      /* next block to count free space in */
+   BlockNumber tupblock;
+   Buffer      buffer;
+   pgstattuple_type stat = {0};
 
    scan = heap_beginscan(rel, SnapshotAny, 0, NULL);
 
@@ -302,7 +302,7 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
 
    relation_close(rel, AccessShareLock);
 
-   stat.table_len = (uint64) nblocks * BLCKSZ;
+   stat.table_len = (uint64) nblocks *BLCKSZ;
 
    return build_pgstattuple_type(&stat, fcinfo);
 }
@@ -311,10 +311,10 @@ pgstat_heap(Relation rel, FunctionCallInfo fcinfo)
  * pgstat_btree_page -- check tuples in a btree page
  */
 static void
-pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
+pgstat_btree_page(pgstattuple_type * stat, Relation rel, BlockNumber blkno)
 {
-   Buffer              buf;
-   Page                page;
+   Buffer      buf;
+   Page        page;
 
    buf = ReadBuffer(rel, blkno);
    LockBuffer(buf, BT_READ);
@@ -328,7 +328,8 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
    }
    else
    {
-       BTPageOpaque    opaque;
+       BTPageOpaque opaque;
+
        opaque = (BTPageOpaque) PageGetSpecialPointer(page);
        if (opaque->btpo_flags & (BTP_DELETED | BTP_HALF_DEAD))
        {
@@ -338,7 +339,7 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
        else if (P_ISLEAF(opaque))
        {
            pgstat_index_page(stat, page, P_FIRSTDATAKEY(opaque),
-               PageGetMaxOffsetNumber(page));
+                             PageGetMaxOffsetNumber(page));
        }
        else
        {
@@ -353,10 +354,10 @@ pgstat_btree_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
  * pgstat_hash_page -- check tuples in a hash page
  */
 static void
-pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
+pgstat_hash_page(pgstattuple_type * stat, Relation rel, BlockNumber blkno)
 {
-   Buffer          buf;
-   Page            page;
+   Buffer      buf;
+   Page        page;
 
    _hash_getlock(rel, blkno, HASH_SHARE);
    buf = _hash_getbuf(rel, blkno, HASH_READ);
@@ -364,22 +365,23 @@ pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
 
    if (PageGetSpecialSize(page) == MAXALIGN(sizeof(HashPageOpaqueData)))
    {
-       HashPageOpaque  opaque;
+       HashPageOpaque opaque;
+
        opaque = (HashPageOpaque) PageGetSpecialPointer(page);
        switch (opaque->hasho_flag)
        {
-       case LH_UNUSED_PAGE:
-           stat->free_space += BLCKSZ;
-           break;
-       case LH_BUCKET_PAGE:
-       case LH_OVERFLOW_PAGE:
-           pgstat_index_page(stat, page, FirstOffsetNumber,
-               PageGetMaxOffsetNumber(page));
-           break;
-       case LH_BITMAP_PAGE:
-       case LH_META_PAGE:
-       default:
-           break;
+           case LH_UNUSED_PAGE:
+               stat->free_space += BLCKSZ;
+               break;
+           case LH_BUCKET_PAGE:
+           case LH_OVERFLOW_PAGE:
+               pgstat_index_page(stat, page, FirstOffsetNumber,
+                                 PageGetMaxOffsetNumber(page));
+               break;
+           case LH_BITMAP_PAGE:
+           case LH_META_PAGE:
+           default:
+               break;
        }
    }
    else
@@ -395,10 +397,10 @@ pgstat_hash_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
  * pgstat_gist_page -- check tuples in a gist page
  */
 static void
-pgstat_gist_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
+pgstat_gist_page(pgstattuple_type * stat, Relation rel, BlockNumber blkno)
 {
-   Buffer          buf;
-   Page            page;
+   Buffer      buf;
+   Page        page;
 
    buf = ReadBuffer(rel, blkno);
    LockBuffer(buf, GIST_SHARE);
@@ -408,7 +410,7 @@ pgstat_gist_page(pgstattuple_type *stat, Relation rel, BlockNumber blkno)
    if (GistPageIsLeaf(page))
    {
        pgstat_index_page(stat, page, FirstOffsetNumber,
-           PageGetMaxOffsetNumber(page));
+                         PageGetMaxOffsetNumber(page));
    }
    else
    {
@@ -427,7 +429,7 @@ pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn,
 {
    BlockNumber nblocks;
    BlockNumber blkno;
-   pgstattuple_type    stat = { 0 };
+   pgstattuple_type stat = {0};
 
    blkno = start;
    for (;;)
@@ -440,7 +442,8 @@ pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn,
        /* Quit if we've scanned the whole relation */
        if (blkno >= nblocks)
        {
-           stat.table_len = (uint64) nblocks * BLCKSZ;
+           stat.table_len = (uint64) nblocks *BLCKSZ;
+
            break;
        }
 
@@ -457,16 +460,16 @@ pgstat_index(Relation rel, BlockNumber start, pgstat_page pagefn,
  * pgstat_index_page -- for generic index page
  */
 static void
-pgstat_index_page(pgstattuple_type *stat, Page page,
-   OffsetNumber minoff, OffsetNumber maxoff)
+pgstat_index_page(pgstattuple_type * stat, Page page,
+                 OffsetNumber minoff, OffsetNumber maxoff)
 {
-   OffsetNumber    i;
+   OffsetNumber i;
 
    stat->free_space += PageGetFreeSpace(page);
 
    for (i = minoff; i <= maxoff; i = OffsetNumberNext(i))
    {
-       ItemId  itemid = PageGetItemId(page, i);
+       ItemId      itemid = PageGetItemId(page, i);
 
        if (ItemIdDeleted(itemid))
        {
index afaa7079af2886c50ba2255e91f03563bf960c20..16eea5eae3330d76a932d183dceb588cc625e789 100644 (file)
@@ -4,7 +4,7 @@
  * Written by Victor B. Wagner <[email protected]>, Cryptocom LTD
  * This file is distributed under BSD-style license.
  *
- * $PostgreSQL: pgsql/contrib/sslinfo/sslinfo.c,v 1.4 2006/09/30 18:44:37 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/sslinfo/sslinfo.c,v 1.5 2006/10/04 00:29:46 momjian Exp $
  */
 
 #include "postgres.h"
 PG_MODULE_MAGIC;
 
 
-Datum ssl_is_used(PG_FUNCTION_ARGS);
-Datum ssl_client_cert_present(PG_FUNCTION_ARGS);
-Datum ssl_client_serial(PG_FUNCTION_ARGS);
-Datum ssl_client_dn_field(PG_FUNCTION_ARGS);
-Datum ssl_issuer_field(PG_FUNCTION_ARGS);
-Datum ssl_client_dn(PG_FUNCTION_ARGS);
-Datum ssl_issuer_dn(PG_FUNCTION_ARGS);
-Datum X509_NAME_field_to_text(X509_NAME *name, text *fieldName);
-Datum X509_NAME_to_text(X509_NAME *name);
-Datum ASN1_STRING_to_text(ASN1_STRING *str);
+Datum      ssl_is_used(PG_FUNCTION_ARGS);
+Datum      ssl_client_cert_present(PG_FUNCTION_ARGS);
+Datum      ssl_client_serial(PG_FUNCTION_ARGS);
+Datum      ssl_client_dn_field(PG_FUNCTION_ARGS);
+Datum      ssl_issuer_field(PG_FUNCTION_ARGS);
+Datum      ssl_client_dn(PG_FUNCTION_ARGS);
+Datum      ssl_issuer_dn(PG_FUNCTION_ARGS);
+Datum      X509_NAME_field_to_text(X509_NAME *name, text *fieldName);
+Datum      X509_NAME_to_text(X509_NAME *name);
+Datum      ASN1_STRING_to_text(ASN1_STRING *str);
 
 
-/* 
+/*
  * Indicates whether current session uses SSL
  *
  * Function has no arguments.  Returns bool.  True if current session
  * is SSL session and false if it is local or non-ssl session.
  */
 PG_FUNCTION_INFO_V1(ssl_is_used);
-Datum ssl_is_used(PG_FUNCTION_ARGS)
+Datum
+ssl_is_used(PG_FUNCTION_ARGS)
 {
-   PG_RETURN_BOOL(MyProcPort->ssl !=NULL);
+   PG_RETURN_BOOL(MyProcPort->ssl != NULL);
 }
 
 
@@ -54,7 +55,8 @@ Datum ssl_is_used(PG_FUNCTION_ARGS)
  * is SSL session and client certificate is verified, otherwise false.
  */
 PG_FUNCTION_INFO_V1(ssl_client_cert_present);
-Datum ssl_client_cert_present(PG_FUNCTION_ARGS)
+Datum
+ssl_client_cert_present(PG_FUNCTION_ARGS)
 {
    PG_RETURN_BOOL(MyProcPort->peer != NULL);
 }
@@ -69,20 +71,22 @@ Datum ssl_client_cert_present(PG_FUNCTION_ARGS)
  * SSL connection is established without sending client certificate.
  */
 PG_FUNCTION_INFO_V1(ssl_client_serial);
-Datum ssl_client_serial(PG_FUNCTION_ARGS)
+Datum
+ssl_client_serial(PG_FUNCTION_ARGS)
 {
-   Datum result;
-   Port *port = MyProcPort;
-   X509 *peer = port->peer;
+   Datum       result;
+   Port       *port = MyProcPort;
+   X509       *peer = port->peer;
    ASN1_INTEGER *serial = NULL;
-   BIGNUM *b;
-   char *decimal;
+   BIGNUM     *b;
+   char       *decimal;
 
    if (!peer)
        PG_RETURN_NULL();
    serial = X509_get_serialNumber(peer);
    b = ASN1_INTEGER_to_BN(serial, NULL);
    decimal = BN_bn2dec(b);
+
    BN_free(b);
    result = DirectFunctionCall3(numeric_in,
                                 CStringGetDatum(decimal),
@@ -100,23 +104,25 @@ Datum ssl_client_serial(PG_FUNCTION_ARGS)
  * current database encoding if possible.  Any invalid characters are
  * replaced by question marks.
  *
- * Parameter: str - OpenSSL ASN1_STRING structure.  Memory managment
+ * Parameter: str - OpenSSL ASN1_STRING structure. Memory managment
  * of this structure is responsibility of caller.
  *
  * Returns Datum, which can be directly returned from a C language SQL
  * function.
  */
-Datum ASN1_STRING_to_text(ASN1_STRING *str)
+Datum
+ASN1_STRING_to_text(ASN1_STRING *str)
 {
-   BIO *membuf = NULL;
-   size_t size, outlen;
-   char *sp;
-   char *dp;
-   text *result;
+   BIO        *membuf = NULL;
+   size_t      size,
+               outlen;
+   char       *sp;
+   char       *dp;
+   text       *result;
 
    membuf = BIO_new(BIO_s_mem());
    (void) BIO_set_close(membuf, BIO_CLOSE);
-   ASN1_STRING_print_ex(membuf,str,
+   ASN1_STRING_print_ex(membuf, str,
                         ((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
                          | ASN1_STRFLGS_UTF8_CONVERT));
 
@@ -124,7 +130,7 @@ Datum ASN1_STRING_to_text(ASN1_STRING *str)
    BIO_write(membuf, &outlen, 1);
    size = BIO_get_mem_data(membuf, &sp);
    dp = (char *) pg_do_encoding_conversion((unsigned char *) sp,
-                                           size-1,
+                                           size - 1,
                                            PG_UTF8,
                                            GetDatabaseEncoding());
    outlen = strlen(dp);
@@ -146,18 +152,21 @@ Datum ASN1_STRING_to_text(ASN1_STRING *str)
  *
  * Parameter: X509_NAME *name - either subject or issuer of certificate
  * Parameter: text fieldName  - field name string like 'CN' or commonName
- *            to be looked up in the OpenSSL ASN1 OID database
+ *           to be looked up in the OpenSSL ASN1 OID database
  *
  * Returns result of ASN1_STRING_to_text applied to appropriate
  * part of name
  */
-Datum X509_NAME_field_to_text(X509_NAME *name, text *fieldName)
+Datum
+X509_NAME_field_to_text(X509_NAME *name, text *fieldName)
 {
-   char *sp;
-   char *string_fieldname;
-   char *dp;
-   size_t name_len = VARSIZE(fieldName) - VARHDRSZ;
-   int nid, index, i;
+   char       *sp;
+   char       *string_fieldname;
+   char       *dp;
+   size_t      name_len = VARSIZE(fieldName) - VARHDRSZ;
+   int         nid,
+               index,
+               i;
    ASN1_STRING *data;
 
    string_fieldname = palloc(name_len + 1);
@@ -175,7 +184,7 @@ Datum X509_NAME_field_to_text(X509_NAME *name, text *fieldName)
    pfree(string_fieldname);
    index = X509_NAME_get_index_by_NID(name, nid, -1);
    if (index < 0)
-       return (Datum)0;
+       return (Datum) 0;
    data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, index));
    return ASN1_STRING_to_text(data);
 }
@@ -198,10 +207,11 @@ Datum X509_NAME_field_to_text(X509_NAME *name, text *fieldName)
  * there is no field with such name in the certificate.
  */
 PG_FUNCTION_INFO_V1(ssl_client_dn_field);
-Datum ssl_client_dn_field(PG_FUNCTION_ARGS)
+Datum
+ssl_client_dn_field(PG_FUNCTION_ARGS)
 {
-   text *fieldname = PG_GETARG_TEXT_P(0);
-   Datum result;
+   text       *fieldname = PG_GETARG_TEXT_P(0);
+   Datum       result;
 
    if (!(MyProcPort->peer))
        PG_RETURN_NULL();
@@ -232,10 +242,11 @@ Datum ssl_client_dn_field(PG_FUNCTION_ARGS)
  * there is no field with such name in the certificate.
  */
 PG_FUNCTION_INFO_V1(ssl_issuer_field);
-Datum ssl_issuer_field(PG_FUNCTION_ARGS)
+Datum
+ssl_issuer_field(PG_FUNCTION_ARGS)
 {
-   text *fieldname = PG_GETARG_TEXT_P(0);
-   Datum result;
+   text       *fieldname = PG_GETARG_TEXT_P(0);
+   Datum       result;
 
    if (!(MyProcPort->peer))
        PG_RETURN_NULL();
@@ -260,21 +271,25 @@ Datum ssl_issuer_field(PG_FUNCTION_ARGS)
  * Returns: text datum which contains string representation of
  * X509_NAME
  */
-Datum X509_NAME_to_text(X509_NAME *name)
+Datum
+X509_NAME_to_text(X509_NAME *name)
 {
-   BIO *membuf = BIO_new(BIO_s_mem());
-   int i,nid,count = X509_NAME_entry_count(name);
+   BIO        *membuf = BIO_new(BIO_s_mem());
+   int         i,
+               nid,
+               count = X509_NAME_entry_count(name);
    X509_NAME_ENTRY *e;
    ASN1_STRING *v;
 
    const char *field_name;
-   size_t size,outlen;
-   char *sp;
-   char *dp;
-   text *result;
+   size_t      size,
+               outlen;
+   char       *sp;
+   char       *dp;
+   text       *result;
 
    (void) BIO_set_close(membuf, BIO_CLOSE);
-   for (i=0; i<count; i++)
+   for (i = 0; i < count; i++)
    {
        e = X509_NAME_get_entry(name, i);
        nid = OBJ_obj2nid(X509_NAME_ENTRY_get_object(e));
@@ -283,17 +298,17 @@ Datum X509_NAME_to_text(X509_NAME *name)
        if (!field_name)
            field_name = OBJ_nid2ln(nid);
        BIO_printf(membuf, "/%s=", field_name);
-       ASN1_STRING_print_ex(membuf,v,
+       ASN1_STRING_print_ex(membuf, v,
                             ((ASN1_STRFLGS_RFC2253 & ~ASN1_STRFLGS_ESC_MSB)
                              | ASN1_STRFLGS_UTF8_CONVERT));
    }
 
-   i=0;
+   i = 0;
    BIO_write(membuf, &i, 1);
    size = BIO_get_mem_data(membuf, &sp);
 
    dp = (char *) pg_do_encoding_conversion((unsigned char *) sp,
-                                           size-1,
+                                           size - 1,
                                            PG_UTF8,
                                            GetDatabaseEncoding());
    BIO_free(membuf);
@@ -301,8 +316,10 @@ Datum X509_NAME_to_text(X509_NAME *name)
    result = palloc(VARHDRSZ + outlen);
    memcpy(VARDATA(result), dp, outlen);
 
-   /* pg_do_encoding_conversion has annoying habit of returning
-    * source pointer */
+   /*
+    * pg_do_encoding_conversion has annoying habit of returning source
+    * pointer
+    */
    if (dp != sp)
        pfree(dp);
    VARATT_SIZEP(result) = outlen + VARHDRSZ;
@@ -320,7 +337,8 @@ Datum X509_NAME_to_text(X509_NAME *name)
  * Returns text datum.
  */
 PG_FUNCTION_INFO_V1(ssl_client_dn);
-Datum ssl_client_dn(PG_FUNCTION_ARGS)
+Datum
+ssl_client_dn(PG_FUNCTION_ARGS)
 {
    if (!(MyProcPort->peer))
        PG_RETURN_NULL();
@@ -338,7 +356,8 @@ Datum ssl_client_dn(PG_FUNCTION_ARGS)
  * Returns text datum.
  */
 PG_FUNCTION_INFO_V1(ssl_issuer_dn);
-Datum ssl_issuer_dn(PG_FUNCTION_ARGS)
+Datum
+ssl_issuer_dn(PG_FUNCTION_ARGS)
 {
    if (!(MyProcPort->peer))
        PG_RETURN_NULL();
index 7ab363972e5beab72962d7a8d20b5084e61a0871..b63bd21cd7d5cc5e6b4f97cab6dbb5f2049532d9 100644 (file)
@@ -1259,7 +1259,7 @@ build_tuplestore_recursively(char *key_fld,
    int         ret;
    int         proc;
    int         serial_column;
-   StringInfoData  sql;
+   StringInfoData sql;
    char      **values;
    char       *current_key;
    char       *current_key_parent;
@@ -1357,9 +1357,9 @@ build_tuplestore_recursively(char *key_fld,
        SPITupleTable *tuptable = SPI_tuptable;
        TupleDesc   spi_tupdesc = tuptable->tupdesc;
        int         i;
-       StringInfoData  branchstr;
-       StringInfoData  chk_branchstr;
-       StringInfoData  chk_current_key;
+       StringInfoData branchstr;
+       StringInfoData chk_branchstr;
+       StringInfoData chk_current_key;
 
        /* First time through, do a little more setup */
        if (level == 0)
index 6192821344370785bc6d1e00e978894956875e85..3ff3fad1bf2514bfd0b98f2d76a438c24ec9870c 100644 (file)
@@ -164,16 +164,19 @@ get_oidnamespace(Oid funcoid)
    return nspoid;
 }
 
   /* if path is relative, take it as relative to share dir */
+ /* if path is relative, take it as relative to share dir */
 char *
-to_absfilename(char *filename) {
-   if (!is_absolute_path(filename)) {
-       char        sharepath[MAXPGPATH];
-       char       *absfn;
-#ifdef  WIN32
-       char    delim = '\\';
+to_absfilename(char *filename)
+{
+   if (!is_absolute_path(filename))
+   {
+       char        sharepath[MAXPGPATH];
+       char       *absfn;
+
+#ifdef WIN32
+       char        delim = '\\';
 #else
-       char    delim = '/';
+       char        delim = '/';
 #endif
        get_share_path(my_exec_path, sharepath);
        absfn = palloc(strlen(sharepath) + strlen(filename) + 2);
index c33507e9ac74e89fb35abef8cea3a89f1400dd3c..ff6ebd6240f8b5ac826e5090ffed31c1a1dfce2e 100644 (file)
@@ -14,7 +14,7 @@ text     *mtextdup(text *in);
 
 int            text_cmp(text *a, text *b);
 
-char to_absfilename(char *filename);
+char      *to_absfilename(char *filename);
 
 #define NEXTVAL(x) ( (text*)( (char*)(x) + INTALIGN( VARSIZE(x) ) ) )
 #define ARRNELEMS(x)  ArrayGetNItems( ARR_NDIM(x), ARR_DIMS(x))
index 2c37a2696b3405d458123b1ccb33a8dd40dda506..182f5c3291044d48a0a482ef9ad1bfdd80f38505 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/tsearch2/dict.c,v 1.12 2006/05/31 14:05:31 teodor Exp $ */
+/* $PostgreSQL: pgsql/contrib/tsearch2/dict.c,v 1.13 2006/10/04 00:29:46 momjian Exp $ */
 
 /*
  * interface functions to dictionary
@@ -102,7 +102,8 @@ comparedict(const void *a, const void *b)
 }
 
 static void
-insertdict(Oid id) {
+insertdict(Oid id)
+{
    DictInfo    newdict;
 
    if (DList.len == DList.reallen)
@@ -143,7 +144,7 @@ finddict(Oid id)
            return DList.last_dict;
    }
 
-   /* insert new dictionary */ 
+   /* insert new dictionary */
    insertdict(id);
    return finddict(id); /* qsort changed order!! */ ;
 }
@@ -201,30 +202,31 @@ lexize(PG_FUNCTION_ARGS)
               *ptr;
    Datum      *da;
    ArrayType  *a;
-   DictSubState    dstate = { false, false, NULL };
+   DictSubState dstate = {false, false, NULL};
 
    SET_FUNCOID();
    dict = finddict(PG_GETARG_OID(0));
 
    ptr = res = (TSLexeme *) DatumGetPointer(
-                                       FunctionCall4(&(dict->lexize_info),
-                                       PointerGetDatum(dict->dictionary),
-                                       PointerGetDatum(VARDATA(in)),
-                                       Int32GetDatum(VARSIZE(in) - VARHDRSZ),
-                                       PointerGetDatum(&dstate)
+                                         FunctionCall4(&(dict->lexize_info),
+                                          PointerGetDatum(dict->dictionary),
+                                               PointerGetDatum(VARDATA(in)),
+                                      Int32GetDatum(VARSIZE(in) - VARHDRSZ),
+                                                    PointerGetDatum(&dstate)
                                                        )
        );
 
-   if (dstate.getnext)  {
-       dstate.isend = true;    
+   if (dstate.getnext)
+   {
+       dstate.isend = true;
        ptr = res = (TSLexeme *) DatumGetPointer(
-                                       FunctionCall4(&(dict->lexize_info),
+                                         FunctionCall4(&(dict->lexize_info),
                                           PointerGetDatum(dict->dictionary),
                                                PointerGetDatum(VARDATA(in)),
-                                       Int32GetDatum(VARSIZE(in) - VARHDRSZ),
-                                       PointerGetDatum(&dstate)
+                                      Int32GetDatum(VARSIZE(in) - VARHDRSZ),
+                                                    PointerGetDatum(&dstate)
                                                        )
-       );
+           );
    }
 
    PG_FREE_IF_COPY(in, 1);
index a0e9fe6facb52e9809c569f942cf707328fdb2df..78d5111f14f68ec046c85ff3151d5556b0a2ea0e 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/tsearch2/dict.h,v 1.7 2006/05/31 14:05:31 teodor Exp $ */
+/* $PostgreSQL: pgsql/contrib/tsearch2/dict.h,v 1.8 2006/10/04 00:29:46 momjian Exp $ */
 
 #ifndef __DICT_H__
 #define __DICT_H__
@@ -30,11 +30,14 @@ DictInfo   *finddict(Oid id);
 Oid            name2id_dict(text *name);
 void       reset_dict(void);
 
-typedef struct {
-   bool isend; /* in: marks for lexize_info about text end is reached */
-   bool getnext; /* out: dict wants next lexeme */
-   void    *private;  /* internal dict state between calls with getnext == true */
-} DictSubState;
+typedef struct
+{
+   bool        isend;          /* in: marks for lexize_info about text end is
+                                * reached */
+   bool        getnext;        /* out: dict wants next lexeme */
+   void       *private;        /* internal dict state between calls with
+                                * getnext == true */
+}  DictSubState;
 
 /* simple parser of cfg string */
 typedef struct
@@ -51,13 +54,8 @@ typedef struct
    /*
     * number of variant of split word , for example Word 'fotballklubber'
     * (norwegian) has two varian to split: ( fotball, klubb ) and ( fot,
-    * ball, klubb ). So, dictionary should return: 
-    * nvariant lexeme 
-    *   1      fotball 
-    *   1      klubb 
-    *   2      fot 
-    *   2      ball 
-    *   2      klubb
+    * ball, klubb ). So, dictionary should return: nvariant lexeme 1
+    * fotball 1      klubb 2      fot 2      ball 2      klubb
     */
    uint16      nvariant;
 
@@ -74,38 +72,43 @@ typedef struct
  * Lexize subsystem
  */
 
-typedef struct ParsedLex {
-    int        type;
-    char       *lemm;
-    int        lenlemm;
+typedef struct ParsedLex
+{
+   int         type;
+   char       *lemm;
+   int         lenlemm;
    bool        resfollow;
-    struct ParsedLex *next;
-} ParsedLex;
-
-typedef struct ListParsedLex {
-   ParsedLex   *head;
-   ParsedLex   *tail;
-} ListParsedLex;
-
-typedef struct {
-    TSCfgInfo       *cfg;
-    Oid             curDictId;
-    int             posDict;
-    DictSubState    dictState;
-    ParsedLex       *curSub;
-   ListParsedLex   towork;   /* current list to work */
-   ListParsedLex   waste;    /* list of lexemes that already lexized */
-
-   /* fields to store last variant to lexize (basically, thesaurus 
-      or similar to, which wants  several lexemes */   
-      
-   ParsedLex       *lastRes;
-   TSLexeme        *tmpRes;
-} LexizeData;
-
-
-void LexizeInit(LexizeData *ld, TSCfgInfo *cfg);
-void LexizeAddLemm(LexizeData *ld, int type, char *lemm, int lenlemm);
-TSLexeme* LexizeExec(LexizeData *ld, ParsedLex **correspondLexem);
+   struct ParsedLex *next;
+}  ParsedLex;
+
+typedef struct ListParsedLex
+{
+   ParsedLex  *head;
+   ParsedLex  *tail;
+}  ListParsedLex;
+
+typedef struct
+{
+   TSCfgInfo  *cfg;
+   Oid         curDictId;
+   int         posDict;
+   DictSubState dictState;
+   ParsedLex  *curSub;
+   ListParsedLex towork;       /* current list to work */
+   ListParsedLex waste;        /* list of lexemes that already lexized */
+
+   /*
+    * fields to store last variant to lexize (basically, thesaurus or similar
+    * to, which wants  several lexemes
+    */
+
+   ParsedLex  *lastRes;
+   TSLexeme   *tmpRes;
+}  LexizeData;
+
+
+void       LexizeInit(LexizeData * ld, TSCfgInfo * cfg);
+void       LexizeAddLemm(LexizeData * ld, int type, char *lemm, int lenlemm);
+TSLexeme   *LexizeExec(LexizeData * ld, ParsedLex ** correspondLexem);
 
 #endif
index d5d837b2cce1226aeefb5f4cb1a877eab5526ca6..12ab7f222a05823b04cb4dbf723119805cede6d2 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/tsearch2/dict_thesaurus.c,v 1.5 2006/06/06 16:25:55 teodor Exp $ */
+/* $PostgreSQL: pgsql/contrib/tsearch2/dict_thesaurus.c,v 1.6 2006/10/04 00:29:46 momjian Exp $ */
 
 /*
  * thesaurus
 /*
  * Temporay we use TSLexeme.flags for inner use...
  */
-#define    DT_USEASIS      0x1000
+#define DT_USEASIS     0x1000
 
-typedef struct LexemeInfo {
-   uint16  idsubst; /* entry's number in DictThesaurus->subst */
-   uint16  posinsubst; /* pos info in entry */
-   uint16  tnvariant;  /* total num lexemes in one variant */
+typedef struct LexemeInfo
+{
+   uint16      idsubst;        /* entry's number in DictThesaurus->subst */
+   uint16      posinsubst;     /* pos info in entry */
+   uint16      tnvariant;      /* total num lexemes in one variant */
    struct LexemeInfo *nextentry;
    struct LexemeInfo *nextvariant;
-} LexemeInfo;
+}  LexemeInfo;
 
-typedef struct {
-   char        *lexeme;
-   LexemeInfo  *entries;
-} TheLexeme; 
+typedef struct
+{
+   char       *lexeme;
+   LexemeInfo *entries;
+}  TheLexeme;
 
-typedef struct {
-   uint16  lastlexeme; /* number lexemes to substitute */
-   uint16  reslen;
-   TSLexeme    *res;   /* prepared substituted result */ 
-} TheSubstitute;
+typedef struct
+{
+   uint16      lastlexeme;     /* number lexemes to substitute */
+   uint16      reslen;
+   TSLexeme   *res;            /* prepared substituted result */
+}  TheSubstitute;
 
 typedef struct
 {
-   /* subdictionary to normalize lexemes */    
+   /* subdictionary to normalize lexemes */
    DictInfo    subdict;
 
    /* Array to search lexeme by exact match */
-   TheLexeme   *wrds;
+   TheLexeme  *wrds;
    int         nwrds;
    int         ntwrds;
 
-   /* Storage of substituted result, n-th element is for
-      n-th expression */
-   TheSubstitute   *subst;
-   int             nsubst;
+   /*
+    * Storage of substituted result, n-th element is for n-th expression
+    */
+   TheSubstitute *subst;
+   int         nsubst;
 }  DictThesaurus;
 
 PG_FUNCTION_INFO_V1(thesaurus_init);
@@ -66,184 +70,225 @@ freeDictThesaurus(DictThesaurus * d)
 }
 
 static void
-newLexeme( DictThesaurus *d, char *b, char *e, uint16 idsubst, uint16 posinsubst ) {
-   TheLexeme   *ptr;
+newLexeme(DictThesaurus * d, char *b, char *e, uint16 idsubst, uint16 posinsubst)
+{
+   TheLexeme  *ptr;
 
-   if ( d->nwrds >= d->ntwrds ) {
-       if ( d->ntwrds == 0 ) {
+   if (d->nwrds >= d->ntwrds)
+   {
+       if (d->ntwrds == 0)
+       {
            d->ntwrds = 16;
-           d->wrds = (TheLexeme*)malloc(sizeof(TheLexeme) * d->ntwrds);
-       } else {
+           d->wrds = (TheLexeme *) malloc(sizeof(TheLexeme) * d->ntwrds);
+       }
+       else
+       {
            d->ntwrds *= 2;
-           d->wrds = (TheLexeme*)realloc(d->wrds, sizeof(TheLexeme) * d->ntwrds);
+           d->wrds = (TheLexeme *) realloc(d->wrds, sizeof(TheLexeme) * d->ntwrds);
        }
        if (!d->wrds)
-           elog(ERROR,"Out of memory");
+           elog(ERROR, "Out of memory");
    }
 
    ptr = d->wrds + d->nwrds;
    d->nwrds++;
 
-   if  ( (ptr->lexeme = malloc(e-b+1)) == NULL )
-       elog(ERROR,"Out of memory");
+   if ((ptr->lexeme = malloc(e - b + 1)) == NULL)
+       elog(ERROR, "Out of memory");
 
-   memcpy(ptr->lexeme, b, e-b);
-   ptr->lexeme[e-b] = '\0';
+   memcpy(ptr->lexeme, b, e - b);
+   ptr->lexeme[e - b] = '\0';
 
-   if  ( (ptr->entries = (LexemeInfo*)malloc( sizeof(LexemeInfo) ))==NULL )
-       elog(ERROR,"Out of memory");
+   if ((ptr->entries = (LexemeInfo *) malloc(sizeof(LexemeInfo))) == NULL)
+       elog(ERROR, "Out of memory");
 
-   ptr->entries->nextentry=NULL;
+   ptr->entries->nextentry = NULL;
    ptr->entries->idsubst = idsubst;
    ptr->entries->posinsubst = posinsubst;
 }
 
 static void
-addWrd( DictThesaurus *d, char *b, char *e, uint16 idsubst, uint16 nwrd, uint16 posinsubst, bool useasis ) {
-   static  int nres=0;
-   static  int ntres = 0;
-   TheSubstitute   *ptr;
+addWrd(DictThesaurus * d, char *b, char *e, uint16 idsubst, uint16 nwrd, uint16 posinsubst, bool useasis)
+{
+   static int  nres = 0;
+   static int  ntres = 0;
+   TheSubstitute *ptr;
 
-   if ( nwrd == 0 ) {
+   if (nwrd == 0)
+   {
        nres = ntres = 0;
 
-       if ( idsubst <= d->nsubst ) {
-           if ( d->nsubst == 0 ) {
+       if (idsubst <= d->nsubst)
+       {
+           if (d->nsubst == 0)
+           {
                d->nsubst = 16;
-               d->subst = (TheSubstitute*)malloc(sizeof(TheSubstitute) * d->nsubst);
-           } else {
+               d->subst = (TheSubstitute *) malloc(sizeof(TheSubstitute) * d->nsubst);
+           }
+           else
+           {
                d->nsubst *= 2;
-               d->subst = (TheSubstitute*)realloc(d->subst, sizeof(TheSubstitute) * d->nsubst);
+               d->subst = (TheSubstitute *) realloc(d->subst, sizeof(TheSubstitute) * d->nsubst);
            }
            if (!d->subst)
-               elog(ERROR,"Out of memory");
+               elog(ERROR, "Out of memory");
        }
    }
 
    ptr = d->subst + idsubst;
 
-   ptr->lastlexeme = posinsubst-1;
+   ptr->lastlexeme = posinsubst - 1;
 
-   if ( nres+1 >= ntres ) {
-       if ( ntres == 0 ) {
+   if (nres + 1 >= ntres)
+   {
+       if (ntres == 0)
+       {
            ntres = 2;
-           ptr->res = (TSLexeme*)malloc( sizeof(TSLexeme) * ntres );
-       } else {
+           ptr->res = (TSLexeme *) malloc(sizeof(TSLexeme) * ntres);
+       }
+       else
+       {
            ntres *= 2;
-           ptr->res = (TSLexeme*)realloc( ptr->res, sizeof(TSLexeme) * ntres );
+           ptr->res = (TSLexeme *) realloc(ptr->res, sizeof(TSLexeme) * ntres);
        }
 
-       if ( !ptr->res ) 
-               elog(ERROR,"Out of memory");
+       if (!ptr->res)
+           elog(ERROR, "Out of memory");
    }
 
-   if ( (ptr->res[ nres ].lexeme = malloc(e-b+1))==0 ) 
-       elog(ERROR,"Out of memory");
-   memcpy(ptr->res[ nres ].lexeme, b, e-b);
-   ptr->res[ nres ].lexeme[e-b] = '\0';
+   if ((ptr->res[nres].lexeme = malloc(e - b + 1)) == 0)
+       elog(ERROR, "Out of memory");
+   memcpy(ptr->res[nres].lexeme, b, e - b);
+   ptr->res[nres].lexeme[e - b] = '\0';
 
-   ptr->res[ nres ].nvariant = nwrd;
-   if ( useasis )
-       ptr->res[ nres ].flags = DT_USEASIS;
+   ptr->res[nres].nvariant = nwrd;
+   if (useasis)
+       ptr->res[nres].flags = DT_USEASIS;
    else
-       ptr->res[ nres ].flags = 0;
+       ptr->res[nres].flags = 0;
 
-   ptr->res[ ++nres ].lexeme = NULL;
+   ptr->res[++nres].lexeme = NULL;
 }
 
 #define TR_WAITLEX 1
 #define TR_INLEX   2
-#define    TR_WAITSUBS 3
+#define TR_WAITSUBS 3
 #define TR_INSUBS  4
 
 static void
-thesaurusRead( char *filename, DictThesaurus *d ) {
-   FILE *fh;
-   char str[BUFSIZ];
-   int lineno=0;
-   uint16  idsubst = 0;
-   bool    useasis=false;
+thesaurusRead(char *filename, DictThesaurus * d)
+{
+   FILE       *fh;
+   char        str[BUFSIZ];
+   int         lineno = 0;
+   uint16      idsubst = 0;
+   bool        useasis = false;
 
    fh = fopen(to_absfilename(filename), "r");
    if (!fh)
-       elog(ERROR,"Thesaurus: can't open '%s' file", filename);
+       elog(ERROR, "Thesaurus: can't open '%s' file", filename);
 
-   while( fgets(str, sizeof(str), fh)) {
-       char *ptr = str;
-       int state = TR_WAITLEX;
-       char    *beginwrd = NULL;
-       uint16  posinsubst=0;
-       uint16  nwrd=0;
+   while (fgets(str, sizeof(str), fh))
+   {
+       char       *ptr = str;
+       int         state = TR_WAITLEX;
+       char       *beginwrd = NULL;
+       uint16      posinsubst = 0;
+       uint16      nwrd = 0;
 
        lineno++;
 
        /* is it comment ? */
-       while( t_isspace(ptr) )
+       while (t_isspace(ptr))
            ptr += pg_mblen(ptr);
-       if ( t_iseq(str, '#') || *str=='\0' || t_iseq(str, '\n') || t_iseq(str, '\r') )
+       if (t_iseq(str, '#') || *str == '\0' || t_iseq(str, '\n') || t_iseq(str, '\r'))
            continue;
 
        pg_verifymbstr(ptr, strlen(ptr), false);
-       while(*ptr) {
-           if ( state == TR_WAITLEX ) {
-               if ( t_iseq(ptr, ':' ) ) {
-                   if ( posinsubst == 0 ) {
+       while (*ptr)
+       {
+           if (state == TR_WAITLEX)
+           {
+               if (t_iseq(ptr, ':'))
+               {
+                   if (posinsubst == 0)
+                   {
                        fclose(fh);
                        elog(ERROR, "Thesaurus: Unexpected delimiter at %d line", lineno);
                    }
                    state = TR_WAITSUBS;
-               } else if ( !t_isspace(ptr) ) {
+               }
+               else if (!t_isspace(ptr))
+               {
                    beginwrd = ptr;
                    state = TR_INLEX;
                }
-           } else if ( state == TR_INLEX ) {
-               if ( t_iseq(ptr, ':') ) {
-                   newLexeme( d, beginwrd, ptr, idsubst, posinsubst++ );
+           }
+           else if (state == TR_INLEX)
+           {
+               if (t_iseq(ptr, ':'))
+               {
+                   newLexeme(d, beginwrd, ptr, idsubst, posinsubst++);
                    state = TR_WAITSUBS;
-               } else if ( t_isspace(ptr) ) {
-                   newLexeme( d, beginwrd, ptr, idsubst, posinsubst++ );
+               }
+               else if (t_isspace(ptr))
+               {
+                   newLexeme(d, beginwrd, ptr, idsubst, posinsubst++);
                    state = TR_WAITLEX;
                }
-           } else if ( state == TR_WAITSUBS ) {
-               if ( t_iseq(ptr, '*') ) {
+           }
+           else if (state == TR_WAITSUBS)
+           {
+               if (t_iseq(ptr, '*'))
+               {
                    useasis = true;
                    state = TR_INSUBS;
                    beginwrd = ptr + pg_mblen(ptr);
-               } else if ( t_iseq(ptr, '\\') ) {
+               }
+               else if (t_iseq(ptr, '\\'))
+               {
                    useasis = false;
                    state = TR_INSUBS;
                    beginwrd = ptr + pg_mblen(ptr);
-               } else if ( !t_isspace(ptr) ) { 
+               }
+               else if (!t_isspace(ptr))
+               {
                    useasis = false;
                    beginwrd = ptr;
                    state = TR_INSUBS;
                }
-           } else if ( state == TR_INSUBS ) {
-               if ( t_isspace(ptr) ) { 
-                   if ( ptr == beginwrd )
+           }
+           else if (state == TR_INSUBS)
+           {
+               if (t_isspace(ptr))
+               {
+                   if (ptr == beginwrd)
                        elog(ERROR, "Thesaurus: Unexpected end of line or lexeme at %d line", lineno);
-                   addWrd( d, beginwrd, ptr, idsubst, nwrd++, posinsubst, useasis );
+                   addWrd(d, beginwrd, ptr, idsubst, nwrd++, posinsubst, useasis);
                    state = TR_WAITSUBS;
                }
-           } else
-               elog(ERROR,"Thesaurus: Unknown state: %d", state);
-               
+           }
+           else
+               elog(ERROR, "Thesaurus: Unknown state: %d", state);
+
            ptr += pg_mblen(ptr);
        }
 
-       if ( state == TR_INSUBS ) {
-           if ( ptr == beginwrd )
+       if (state == TR_INSUBS)
+       {
+           if (ptr == beginwrd)
                elog(ERROR, "Thesaurus: Unexpected end of line or lexeme at %d line", lineno);
-           addWrd( d, beginwrd, ptr, idsubst, nwrd++, posinsubst, useasis );
+           addWrd(d, beginwrd, ptr, idsubst, nwrd++, posinsubst, useasis);
        }
 
        idsubst++;
 
-       if ( !(nwrd && posinsubst) ) {
+       if (!(nwrd && posinsubst))
+       {
            fclose(fh);
            elog(ERROR, "Thesaurus: Unexpected end of line at %d line", lineno);
        }
-           
+
    }
 
    d->nsubst = idsubst;
@@ -251,135 +296,160 @@ thesaurusRead( char *filename, DictThesaurus *d ) {
    fclose(fh);
 }
 
-static TheLexeme*
-addCompiledLexeme(TheLexeme   *newwrds, int *nnw, int *tnm, TSLexeme *lexeme, LexemeInfo* src, uint16 tnvariant) {
+static TheLexeme *
+addCompiledLexeme(TheLexeme * newwrds, int *nnw, int *tnm, TSLexeme * lexeme, LexemeInfo * src, uint16 tnvariant)
+{
 
-   if ( *nnw >= *tnm ) {
+   if (*nnw >= *tnm)
+   {
        *tnm *= 2;
-       newwrds = (TheLexeme*)realloc( newwrds, sizeof(TheLexeme) * *tnm);
+       newwrds = (TheLexeme *) realloc(newwrds, sizeof(TheLexeme) * *tnm);
        if (!newwrds)
-           elog(ERROR,"Out of memory");
+           elog(ERROR, "Out of memory");
    }
 
-   newwrds[ *nnw ].entries = (LexemeInfo*)malloc( sizeof(LexemeInfo) );
-   if (!newwrds[ *nnw ].entries)
-       elog(ERROR,"Out of memory");
+   newwrds[*nnw].entries = (LexemeInfo *) malloc(sizeof(LexemeInfo));
+   if (!newwrds[*nnw].entries)
+       elog(ERROR, "Out of memory");
 
-   if ( lexeme && lexeme->lexeme ) {
-       newwrds[ *nnw ].lexeme = strdup( lexeme->lexeme );
-       if ( !newwrds[ *nnw ].lexeme )
-           elog(ERROR,"Out of memory");
+   if (lexeme && lexeme->lexeme)
+   {
+       newwrds[*nnw].lexeme = strdup(lexeme->lexeme);
+       if (!newwrds[*nnw].lexeme)
+           elog(ERROR, "Out of memory");
 
-       newwrds[ *nnw ].entries->tnvariant = tnvariant;
-   } else {
-       newwrds[ *nnw ].lexeme = NULL;
-       newwrds[ *nnw ].entries->tnvariant = 1;
+       newwrds[*nnw].entries->tnvariant = tnvariant;
+   }
+   else
+   {
+       newwrds[*nnw].lexeme = NULL;
+       newwrds[*nnw].entries->tnvariant = 1;
    }
 
-   newwrds[ *nnw ].entries->idsubst = src->idsubst;
-   newwrds[ *nnw ].entries->posinsubst = src->posinsubst;
+   newwrds[*nnw].entries->idsubst = src->idsubst;
+   newwrds[*nnw].entries->posinsubst = src->posinsubst;
 
-   newwrds[ *nnw ].entries->nextentry = NULL;
+   newwrds[*nnw].entries->nextentry = NULL;
 
    (*nnw)++;
    return newwrds;
 }
 
 static int
-cmpLexemeInfo(LexemeInfo *a, LexemeInfo *b) {
-   if ( a==NULL || b==NULL )
+cmpLexemeInfo(LexemeInfo * a, LexemeInfo * b)
+{
+   if (a == NULL || b == NULL)
        return 0;
 
-   if ( a->idsubst == b->idsubst ) {
-       if ( a->posinsubst == b->posinsubst ) {
-           if ( a->tnvariant == b->tnvariant ) 
-                   return 0;
+   if (a->idsubst == b->idsubst)
+   {
+       if (a->posinsubst == b->posinsubst)
+       {
+           if (a->tnvariant == b->tnvariant)
+               return 0;
 
-           return ( a->tnvariant > b->tnvariant ) ? 1 : -1;
+           return (a->tnvariant > b->tnvariant) ? 1 : -1;
        }
 
-       return ( a->posinsubst > b->posinsubst ) ? 1 : -1;
+       return (a->posinsubst > b->posinsubst) ? 1 : -1;
    }
 
-   return ( a->idsubst > b->idsubst ) ? 1 : -1;
+   return (a->idsubst > b->idsubst) ? 1 : -1;
 }
 
 static int
-cmpLexeme(TheLexeme *a, TheLexeme* b) {
-   if ( a->lexeme == NULL ) {
-       if ( b->lexeme == NULL )
+cmpLexeme(TheLexeme * a, TheLexeme * b)
+{
+   if (a->lexeme == NULL)
+   {
+       if (b->lexeme == NULL)
            return 0;
        else
            return 1;
-   } else if ( b->lexeme == NULL )
+   }
+   else if (b->lexeme == NULL)
        return -1;
 
-   return strcmp( a->lexeme, b->lexeme );
+   return strcmp(a->lexeme, b->lexeme);
 }
 
 static int
-cmpLexemeQ(const void *a, const void *b) {
-   return cmpLexeme( (TheLexeme*)a, (TheLexeme*)b ); 
+cmpLexemeQ(const void *a, const void *b)
+{
+   return cmpLexeme((TheLexeme *) a, (TheLexeme *) b);
 }
 
-static int cmpTheLexeme(const void *a, const void *b) {
-   TheLexeme *la  = (TheLexeme*)a;
-   TheLexeme *lb  = (TheLexeme*)b;
-   int res;
+static int
+cmpTheLexeme(const void *a, const void *b)
+{
+   TheLexeme  *la = (TheLexeme *) a;
+   TheLexeme  *lb = (TheLexeme *) b;
+   int         res;
 
-   if ( (res=cmpLexeme(la, lb)) != 0 )
+   if ((res = cmpLexeme(la, lb)) != 0)
        return res;
 
    return -cmpLexemeInfo(la->entries, lb->entries);
 }
 
 static void
-compileTheLexeme(DictThesaurus *d) {
-   int         i,nnw=0, tnm=16;
-   TheLexeme   *newwrds = (TheLexeme*)malloc(sizeof(TheLexeme)*tnm), *ptrwrds;
-
-   if (!newwrds) 
-       elog(ERROR,"Out of memory");
-
-   for(i=0;i<d->nwrds;i++) {
-       TSLexeme *ptr;
-
-       ptr = (TSLexeme*) DatumGetPointer( 
-               FunctionCall4(
-                   &(d->subdict.lexize_info),
-                   PointerGetDatum(d->subdict.dictionary),
-                   PointerGetDatum(d->wrds[i].lexeme),
-                   Int32GetDatum(strlen(d->wrds[i].lexeme)),
-                   PointerGetDatum(NULL)
-               )
+compileTheLexeme(DictThesaurus * d)
+{
+   int         i,
+               nnw = 0,
+               tnm = 16;
+   TheLexeme  *newwrds = (TheLexeme *) malloc(sizeof(TheLexeme) * tnm),
+              *ptrwrds;
+
+   if (!newwrds)
+       elog(ERROR, "Out of memory");
+
+   for (i = 0; i < d->nwrds; i++)
+   {
+       TSLexeme   *ptr;
+
+       ptr = (TSLexeme *) DatumGetPointer(
+                                          FunctionCall4(
+                                                  &(d->subdict.lexize_info),
+                                     PointerGetDatum(d->subdict.dictionary),
+                                         PointerGetDatum(d->wrds[i].lexeme),
+                                   Int32GetDatum(strlen(d->wrds[i].lexeme)),
+                                                        PointerGetDatum(NULL)
+                                                        )
            );
 
-       if ( !(ptr && ptr->lexeme) ) {
-           if ( !ptr )
-               elog(ERROR,"Thesaurus: word-sample '%s' isn't recognized by subdictionary (rule %d)", 
-                       d->wrds[i].lexeme, d->wrds[i].entries->idsubst+1    );
+       if (!(ptr && ptr->lexeme))
+       {
+           if (!ptr)
+               elog(ERROR, "Thesaurus: word-sample '%s' isn't recognized by subdictionary (rule %d)",
+                    d->wrds[i].lexeme, d->wrds[i].entries->idsubst + 1);
            else
-               elog(NOTICE,"Thesaurus: word-sample '%s' is recognized as stop-word, assign any stop-word (rule %d)", 
-                   d->wrds[i].lexeme,  d->wrds[i].entries->idsubst+1);
+               elog(NOTICE, "Thesaurus: word-sample '%s' is recognized as stop-word, assign any stop-word (rule %d)",
+                    d->wrds[i].lexeme, d->wrds[i].entries->idsubst + 1);
 
-           newwrds = addCompiledLexeme( newwrds, &nnw, &tnm, NULL, d->wrds[i].entries, 0);
-       } else {
-           while( ptr->lexeme ) {
-               TSLexeme    *remptr = ptr+1;
-               int tnvar = 1;
-               int curvar = ptr->nvariant;
+           newwrds = addCompiledLexeme(newwrds, &nnw, &tnm, NULL, d->wrds[i].entries, 0);
+       }
+       else
+       {
+           while (ptr->lexeme)
+           {
+               TSLexeme   *remptr = ptr + 1;
+               int         tnvar = 1;
+               int         curvar = ptr->nvariant;
 
                /* compute n words in one variant */
-               while( remptr->lexeme ) {
-                   if ( remptr->nvariant != (remptr-1)->nvariant )
+               while (remptr->lexeme)
+               {
+                   if (remptr->nvariant != (remptr - 1)->nvariant)
                        break;
                    tnvar++;
                    remptr++;
                }
 
                remptr = ptr;
-               while( remptr->lexeme && remptr->nvariant == curvar ) {
-                   newwrds = addCompiledLexeme( newwrds, &nnw, &tnm, remptr, d->wrds[i].entries, tnvar); 
+               while (remptr->lexeme && remptr->nvariant == curvar)
+               {
+                   newwrds = addCompiledLexeme(newwrds, &nnw, &tnm, remptr, d->wrds[i].entries, tnvar);
                    remptr++;
                }
 
@@ -387,32 +457,39 @@ compileTheLexeme(DictThesaurus *d) {
            }
        }
 
-       free( d->wrds[i].lexeme );
-       free( d->wrds[i].entries );
+       free(d->wrds[i].lexeme);
+       free(d->wrds[i].entries);
    }
 
-   free( d->wrds );
+   free(d->wrds);
    d->wrds = newwrds;
    d->nwrds = nnw;
    d->ntwrds = tnm;
 
-   if ( d->nwrds > 1 ) {
-       qsort( d->wrds, d->nwrds, sizeof(TheLexeme), cmpTheLexeme ); 
+   if (d->nwrds > 1)
+   {
+       qsort(d->wrds, d->nwrds, sizeof(TheLexeme), cmpTheLexeme);
 
        /* uniq */
        newwrds = d->wrds;
        ptrwrds = d->wrds + 1;
-       while( ptrwrds - d->wrds < d->nwrds ) {
-           if ( cmpLexeme( ptrwrds, newwrds ) == 0 ) {
-               if ( cmpLexemeInfo(ptrwrds->entries, newwrds->entries) ) {
+       while (ptrwrds - d->wrds < d->nwrds)
+       {
+           if (cmpLexeme(ptrwrds, newwrds) == 0)
+           {
+               if (cmpLexemeInfo(ptrwrds->entries, newwrds->entries))
+               {
                    ptrwrds->entries->nextentry = newwrds->entries;
                    newwrds->entries = ptrwrds->entries;
-               } else
-                   free( ptrwrds->entries );
+               }
+               else
+                   free(ptrwrds->entries);
 
-               if ( ptrwrds->lexeme )
-                   free( ptrwrds->lexeme );
-           } else {
+               if (ptrwrds->lexeme)
+                   free(ptrwrds->lexeme);
+           }
+           else
+           {
                newwrds++;
                *newwrds = *ptrwrds;
            }
@@ -421,80 +498,97 @@ compileTheLexeme(DictThesaurus *d) {
        }
 
        d->nwrds = newwrds - d->wrds + 1;
-       d->wrds = (TheLexeme*)realloc( d->wrds, sizeof(TheLexeme) * d->nwrds );
+       d->wrds = (TheLexeme *) realloc(d->wrds, sizeof(TheLexeme) * d->nwrds);
    }
 }
 
 static void
-compileTheSubstitute(DictThesaurus *d) {
-   int i;
-
-   for(i=0;i<d->nsubst;i++) {
-       TSLexeme    *rem = d->subst[i].res, *outptr, *inptr;
-       int         n=2;
+compileTheSubstitute(DictThesaurus * d)
+{
+   int         i;
 
-       outptr = d->subst[i].res = (TSLexeme*)malloc( sizeof(TSLexeme) * n );
-       if ( d->subst[i].res == NULL )
-           elog(ERROR,"Out of Memory");
+   for (i = 0; i < d->nsubst; i++)
+   {
+       TSLexeme   *rem = d->subst[i].res,
+                  *outptr,
+                  *inptr;
+       int         n = 2;
+
+       outptr = d->subst[i].res = (TSLexeme *) malloc(sizeof(TSLexeme) * n);
+       if (d->subst[i].res == NULL)
+           elog(ERROR, "Out of Memory");
        outptr->lexeme = NULL;
        inptr = rem;
 
-       while( inptr && inptr->lexeme ) { 
-           TSLexeme    *lexized, tmplex[2];
+       while (inptr && inptr->lexeme)
+       {
+           TSLexeme   *lexized,
+                       tmplex[2];
 
-           if ( inptr->flags & DT_USEASIS ) { /* do not lexize */
+           if (inptr->flags & DT_USEASIS)
+           {                   /* do not lexize */
                tmplex[0] = *inptr;
-               tmplex[0].flags = 0; 
+               tmplex[0].flags = 0;
                tmplex[1].lexeme = NULL;
-               lexized = tmplex; 
-           } else {
-               lexized = (TSLexeme*) DatumGetPointer( 
-                   FunctionCall4(
-                       &(d->subdict.lexize_info),
-                       PointerGetDatum(d->subdict.dictionary),
-                       PointerGetDatum(inptr->lexeme),
-                       Int32GetDatum(strlen(inptr->lexeme)),
-                       PointerGetDatum(NULL)
-                   )
-               );
+               lexized = tmplex;
+           }
+           else
+           {
+               lexized = (TSLexeme *) DatumGetPointer(
+                                                      FunctionCall4(
+                                                  &(d->subdict.lexize_info),
+                                     PointerGetDatum(d->subdict.dictionary),
+                                             PointerGetDatum(inptr->lexeme),
+                                       Int32GetDatum(strlen(inptr->lexeme)),
+                                                       PointerGetDatum(NULL)
+                                                                    )
+                   );
            }
 
-           if ( lexized && lexized->lexeme ) {
-               int toset = (lexized->lexeme && outptr != d->subst[i].res ) ? (outptr - d->subst[i].res)  : -1;
+           if (lexized && lexized->lexeme)
+           {
+               int         toset = (lexized->lexeme && outptr != d->subst[i].res) ? (outptr - d->subst[i].res) : -1;
+
+               while (lexized->lexeme)
+               {
+                   if (outptr - d->subst[i].res + 1 >= n)
+                   {
+                       int         diff = outptr - d->subst[i].res;
 
-               while( lexized->lexeme ) {
-                   if ( outptr - d->subst[i].res + 1 >= n ) {
-                       int diff = outptr - d->subst[i].res;
                        n *= 2;
-                       d->subst[i].res = (TSLexeme*)realloc( d->subst[i].res, sizeof(TSLexeme) * n );
-                       if ( d->subst[i].res == NULL )
-                           elog(ERROR,"Out of Memory");
+                       d->subst[i].res = (TSLexeme *) realloc(d->subst[i].res, sizeof(TSLexeme) * n);
+                       if (d->subst[i].res == NULL)
+                           elog(ERROR, "Out of Memory");
                        outptr = d->subst[i].res + diff;
                    }
 
                    *outptr = *lexized;
-                   if ( (outptr->lexeme = strdup(lexized->lexeme)) == NULL )
-                       elog(ERROR,"Out of Memory");
+                   if ((outptr->lexeme = strdup(lexized->lexeme)) == NULL)
+                       elog(ERROR, "Out of Memory");
 
                    outptr++;
                    lexized++;
                }
 
-               if ( toset > 0)
+               if (toset > 0)
                    d->subst[i].res[toset].flags |= TSL_ADDPOS;
-           } else if ( lexized ) {
-               elog(NOTICE,"Thesaurus: word '%s' in substition is a stop-word, ignored (rule %d)", inptr->lexeme, i+1);
-           } else {
-               elog(ERROR,"Thesaurus: word '%s' in substition isn't recognized (rule %d)", inptr->lexeme, i+1);
+           }
+           else if (lexized)
+           {
+               elog(NOTICE, "Thesaurus: word '%s' in substition is a stop-word, ignored (rule %d)", inptr->lexeme, i + 1);
+           }
+           else
+           {
+               elog(ERROR, "Thesaurus: word '%s' in substition isn't recognized (rule %d)", inptr->lexeme, i + 1);
            }
 
-           if ( inptr->lexeme )
-               free( inptr->lexeme );
+           if (inptr->lexeme)
+               free(inptr->lexeme);
            inptr++;
        }
 
-       if ( outptr == d->subst[i].res )
-           elog(ERROR,"Thesaurus: all words in subsitution are stop word (rule %d)", i+1);
+       if (outptr == d->subst[i].res)
+           elog(ERROR, "Thesaurus: all words in subsitution are stop word (rule %d)", i + 1);
 
        d->subst[i].reslen = outptr - d->subst[i].res;
 
@@ -508,8 +602,9 @@ thesaurus_init(PG_FUNCTION_ARGS)
    DictThesaurus *d;
    Map        *cfg,
               *pcfg;
-   text       *in, *subdictname=NULL;
-   bool        fileloaded = false;
+   text       *in,
+              *subdictname = NULL;
+   bool        fileloaded = false;
 
    if (PG_ARGISNULL(0) || PG_GETARG_POINTER(0) == NULL)
        ereport(ERROR,
@@ -539,7 +634,7 @@ thesaurus_init(PG_FUNCTION_ARGS)
                         errmsg("Thesaurus file is already loaded")));
            }
            fileloaded = true;
-           thesaurusRead( pcfg->value, d );
+           thesaurusRead(pcfg->value, d);
        }
        else if (pg_strcasecmp("Dictionary", pcfg->key) == 0)
        {
@@ -548,9 +643,9 @@ thesaurus_init(PG_FUNCTION_ARGS)
                freeDictThesaurus(d);
                ereport(ERROR,
                        (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
-                        errmsg("Thesaurus: SubDictionary is already defined")));
+                    errmsg("Thesaurus: SubDictionary is already defined")));
            }
-           subdictname = char2text( pcfg->value );
+           subdictname = char2text(pcfg->value);
        }
        else
        {
@@ -571,53 +666,60 @@ thesaurus_init(PG_FUNCTION_ARGS)
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                 errmsg("Thesaurus file  isn't defined")));
 
-   if ( subdictname ) {
-       DictInfo    *subdictptr;
-       /* 
-        * we already in SPI, but name2id_dict()/finddict()
-        * invoke SPI_connect()
+   if (subdictname)
+   {
+       DictInfo   *subdictptr;
+
+       /*
+        * we already in SPI, but name2id_dict()/finddict() invoke
+        * SPI_connect()
         */
-       SPI_push(); 
+       SPI_push();
 
-       subdictptr = finddict( name2id_dict( subdictname ) );
+       subdictptr = finddict(name2id_dict(subdictname));
 
        SPI_pop();
 
        d->subdict = *subdictptr;
-   } else 
+   }
+   else
        ereport(ERROR,
                (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
                 errmsg("Thesaurus: SubDictionary isn't defined")));
 
-   compileTheLexeme( d );
+   compileTheLexeme(d);
    compileTheSubstitute(d);
 
    PG_RETURN_POINTER(d);
 }
 
-static LexemeInfo*
-findTheLexeme(DictThesaurus *d, char * lexeme) {
-   TheLexeme key = { lexeme, NULL }, *res;
+static LexemeInfo *
+findTheLexeme(DictThesaurus * d, char *lexeme)
+{
+   TheLexeme   key = {lexeme, NULL}, *res;
 
-   if ( d->nwrds == 0 )
+   if (d->nwrds == 0)
        return NULL;
 
    res = bsearch(&key, d->wrds, d->nwrds, sizeof(TheLexeme), cmpLexemeQ);
 
-   if ( res == NULL )
+   if (res == NULL)
        return NULL;
    return res->entries;
 }
 
 static bool
-matchIdSubst(LexemeInfo *stored, uint16 idsubst) {
-   bool res = true;
+matchIdSubst(LexemeInfo * stored, uint16 idsubst)
+{
+   bool        res = true;
 
-   if (stored) {
+   if (stored)
+   {
        res = false;
 
-       for(; stored; stored=stored->nextvariant) 
-           if ( stored->idsubst == idsubst ) {
+       for (; stored; stored = stored->nextvariant)
+           if (stored->idsubst == idsubst)
+           {
                res = true;
                break;
            }
@@ -626,66 +728,76 @@ matchIdSubst(LexemeInfo *stored, uint16 idsubst) {
    return res;
 }
 
-static LexemeInfo*
-findVariant( LexemeInfo *in, LexemeInfo *stored, uint16 curpos, LexemeInfo **newin, int newn) {
-   for(;;) {
-       int i;
+static LexemeInfo *
+findVariant(LexemeInfo * in, LexemeInfo * stored, uint16 curpos, LexemeInfo ** newin, int newn)
+{
+   for (;;)
+   {
+       int         i;
        LexemeInfo *ptr = newin[0];
 
-       for(i=0; i<newn; i++) {
-           while(newin[i] && newin[i]->idsubst < ptr->idsubst) 
+       for (i = 0; i < newn; i++)
+       {
+           while (newin[i] && newin[i]->idsubst < ptr->idsubst)
                newin[i] = newin[i]->nextentry;
 
-           if ( newin[i] == NULL )
+           if (newin[i] == NULL)
                return in;
 
-           if ( newin[i]->idsubst > ptr->idsubst ) {
+           if (newin[i]->idsubst > ptr->idsubst)
+           {
                ptr = newin[i];
-               i=-1;
+               i = -1;
                continue;
            }
 
-           while(newin[i]->idsubst == ptr->idsubst) {
-               if ( newin[i]->posinsubst == curpos && newin[i]->tnvariant == newn ) {
+           while (newin[i]->idsubst == ptr->idsubst)
+           {
+               if (newin[i]->posinsubst == curpos && newin[i]->tnvariant == newn)
+               {
                    ptr = newin[i];
                    break;
                }
 
                newin[i] = newin[i]->nextentry;
-               if ( newin[i] == NULL )
+               if (newin[i] == NULL)
                    return in;
            }
 
-           if ( newin[i]->idsubst != ptr->idsubst ) {
+           if (newin[i]->idsubst != ptr->idsubst)
+           {
                ptr = newin[i];
-               i=-1;
+               i = -1;
                continue;
            }
        }
 
-       if ( i==newn && matchIdSubst(stored, ptr->idsubst) && (in==NULL || !matchIdSubst(in, ptr->idsubst)) ) { /* found */
+       if (i == newn && matchIdSubst(stored, ptr->idsubst) && (in == NULL || !matchIdSubst(in, ptr->idsubst)))
+       {                       /* found */
 
            ptr->nextvariant = in;
            in = ptr;
        }
 
        /* step forward */
-       for(i=0; i<newn; i++)
+       for (i = 0; i < newn; i++)
            newin[i] = newin[i]->nextentry;
    }
 
    return NULL;
 }
 
-static TSLexeme*
-copyTSLexeme( TheSubstitute *ts ) {
-   TSLexeme    *res;
-   uint16 i;
+static TSLexeme *
+copyTSLexeme(TheSubstitute * ts)
+{
+   TSLexeme   *res;
+   uint16      i;
 
-   res = (TSLexeme*)palloc( sizeof(TSLexeme) * (ts->reslen+1) );
-   for(i=0;i<ts->reslen;i++) { 
+   res = (TSLexeme *) palloc(sizeof(TSLexeme) * (ts->reslen + 1));
+   for (i = 0; i < ts->reslen; i++)
+   {
        res[i] = ts->res[i];
-       res[i].lexeme = pstrdup( ts->res[i].lexeme );
+       res[i].lexeme = pstrdup(ts->res[i].lexeme);
    }
 
    res[ts->reslen].lexeme = NULL;
@@ -693,15 +805,17 @@ copyTSLexeme( TheSubstitute *ts ) {
    return res;
 }
 
-static TSLexeme*
-checkMatch(DictThesaurus *d, LexemeInfo *info, uint16 curpos, bool *moreres) {
+static TSLexeme *
+checkMatch(DictThesaurus * d, LexemeInfo * info, uint16 curpos, bool *moreres)
+{
    *moreres = false;
-   while(info) {
-       Assert( info->idsubst < d->nsubst );
-       if ( info->nextvariant )
+   while (info)
+   {
+       Assert(info->idsubst < d->nsubst);
+       if (info->nextvariant)
            *moreres = true;
-       if ( d->subst[ info->idsubst ].lastlexeme == curpos ) 
-           return copyTSLexeme( d->subst + info->idsubst );
+       if (d->subst[info->idsubst].lastlexeme == curpos)
+           return copyTSLexeme(d->subst + info->idsubst);
        info = info->nextvariant;
    }
 
@@ -712,79 +826,93 @@ Datum
 thesaurus_lexize(PG_FUNCTION_ARGS)
 {
    DictThesaurus *d = (DictThesaurus *) PG_GETARG_POINTER(0);
-   DictSubState    *dstate = (DictSubState*)PG_GETARG_POINTER(3);
-   TSLexeme    *res=NULL;
-   LexemeInfo *stored, *info = NULL;
-   uint16  curpos = 0;
-   bool    moreres = false;
+   DictSubState *dstate = (DictSubState *) PG_GETARG_POINTER(3);
+   TSLexeme   *res = NULL;
+   LexemeInfo *stored,
+              *info = NULL;
+   uint16      curpos = 0;
+   bool        moreres = false;
 
-   if ( dstate == NULL || PG_NARGS() < 4 )
-       elog(ERROR,"Forbidden call of thesaurus or nested call");
+   if (dstate == NULL || PG_NARGS() < 4)
+       elog(ERROR, "Forbidden call of thesaurus or nested call");
 
-   if ( dstate->isend ) 
+   if (dstate->isend)
        PG_RETURN_POINTER(NULL);
-   stored = (LexemeInfo*) dstate->private;
-
-   if (stored) 
-       curpos = stored->posinsubst+1;
-
-   res =(TSLexeme*) DatumGetPointer (
-       FunctionCall4(
-           &(d->subdict.lexize_info),
-           PointerGetDatum(d->subdict.dictionary),
-           PG_GETARG_DATUM(1),
-           PG_GETARG_INT32(2),
-           PointerGetDatum(NULL)
-       )
-   );
-
-   if ( res && res->lexeme ) {
-       TSLexeme    *ptr = res , *basevar;
+   stored = (LexemeInfo *) dstate->private;
+
+   if (stored)
+       curpos = stored->posinsubst + 1;
+
+   res = (TSLexeme *) DatumGetPointer(
+                                      FunctionCall4(
+                                                  &(d->subdict.lexize_info),
+                                     PointerGetDatum(d->subdict.dictionary),
+                                                    PG_GETARG_DATUM(1),
+                                                    PG_GETARG_INT32(2),
+                                                    PointerGetDatum(NULL)
+                                                    )
+       );
+
+   if (res && res->lexeme)
+   {
+       TSLexeme   *ptr = res,
+                  *basevar;
 
-       while( ptr->lexeme ) {
+       while (ptr->lexeme)
+       {
            uint16      nv = ptr->nvariant;
-           uint16      i,nlex = 0;
-           LexemeInfo  **infos;
+           uint16      i,
+                       nlex = 0;
+           LexemeInfo **infos;
 
            basevar = ptr;
-           while( ptr->lexeme && nv == ptr->nvariant ) {
+           while (ptr->lexeme && nv == ptr->nvariant)
+           {
                nlex++;
                ptr++;
            }
 
-           infos = (LexemeInfo**)palloc(sizeof(LexemeInfo*)*nlex);
-           for(i=0;i<nlex;i++) 
-               if ( (infos[i] = findTheLexeme(d, basevar[i].lexeme)) == NULL ) 
+           infos = (LexemeInfo **) palloc(sizeof(LexemeInfo *) * nlex);
+           for (i = 0; i < nlex; i++)
+               if ((infos[i] = findTheLexeme(d, basevar[i].lexeme)) == NULL)
                    break;
 
-           if ( i<nlex ) { 
+           if (i < nlex)
+           {
                /* no chance to find */
-               pfree( infos );
+               pfree(infos);
                continue;
            }
 
-           info = findVariant( info, stored, curpos, infos, nlex);
+           info = findVariant(info, stored, curpos, infos, nlex);
        }
-   } else if ( res ) { /* stop-word */
-       LexemeInfo  *infos = findTheLexeme(d, NULL);
-       info = findVariant( NULL, stored, curpos, &infos, 1);
-   } else {
-       info = NULL; /* word isn't recognized */
    }
+   else if (res)
+   {                           /* stop-word */
+       LexemeInfo *infos = findTheLexeme(d, NULL);
 
-   dstate->private = (void*)info;
+       info = findVariant(NULL, stored, curpos, &infos, 1);
+   }
+   else
+   {
+       info = NULL;            /* word isn't recognized */
+   }
+
+   dstate->private = (void *) info;
 
-   if ( !info ) {
+   if (!info)
+   {
        dstate->getnext = false;
        PG_RETURN_POINTER(NULL);
    }
-           
-   if ( (res=checkMatch(d, info, curpos,&moreres)) != NULL ) {
+
+   if ((res = checkMatch(d, info, curpos, &moreres)) != NULL)
+   {
        dstate->getnext = moreres;
        PG_RETURN_POINTER(res);
    }
 
    dstate->getnext = true;
 
-   PG_RETURN_POINTER(NULL);    
+   PG_RETURN_POINTER(NULL);
 }
index 4ba3fc62a04f2a9ad132454f0d0f3c6f2c5a98ad..c1bb173e1ce37b03e8d7edd9df06ae1ecb829581 100644 (file)
 #include "query_cleanup.h"
 
 PG_FUNCTION_INFO_V1(gin_extract_tsvector);
-Datum       gin_extract_tsvector(PG_FUNCTION_ARGS);
+Datum      gin_extract_tsvector(PG_FUNCTION_ARGS);
 
 Datum
-gin_extract_tsvector(PG_FUNCTION_ARGS) {
-   tsvector    *vector = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-   uint32      *nentries = (uint32*)PG_GETARG_POINTER(1);
-   Datum       *entries = NULL;
+gin_extract_tsvector(PG_FUNCTION_ARGS)
+{
+   tsvector   *vector = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+   uint32     *nentries = (uint32 *) PG_GETARG_POINTER(1);
+   Datum      *entries = NULL;
 
    *nentries = 0;
-   if ( vector->size > 0 ) {
-       int i;
-       WordEntry   *we = ARRPTR( vector );
+   if (vector->size > 0)
+   {
+       int         i;
+       WordEntry  *we = ARRPTR(vector);
 
-       *nentries = (uint32)vector->size;
-       entries = (Datum*)palloc( sizeof(Datum) * vector->size );
+       *nentries = (uint32) vector->size;
+       entries = (Datum *) palloc(sizeof(Datum) * vector->size);
 
-       for(i=0;i<vector->size;i++) {
-           text    *txt = (text*)palloc( VARHDRSZ + we->len );
+       for (i = 0; i < vector->size; i++)
+       {
+           text       *txt = (text *) palloc(VARHDRSZ + we->len);
 
-           VARATT_SIZEP(txt) = VARHDRSZ + we->len; 
-           memcpy( VARDATA(txt), STRPTR( vector ) + we->pos, we->len ); 
+           VARATT_SIZEP(txt) = VARHDRSZ + we->len;
+           memcpy(VARDATA(txt), STRPTR(vector) + we->pos, we->len);
 
-           entries[i] = PointerGetDatum( txt );
+           entries[i] = PointerGetDatum(txt);
 
            we++;
        }
@@ -49,45 +52,50 @@ gin_extract_tsvector(PG_FUNCTION_ARGS) {
 
 
 PG_FUNCTION_INFO_V1(gin_extract_tsquery);
-Datum       gin_extract_tsquery(PG_FUNCTION_ARGS);
+Datum      gin_extract_tsquery(PG_FUNCTION_ARGS);
 
 Datum
-gin_extract_tsquery(PG_FUNCTION_ARGS) {
-   QUERYTYPE *query = (QUERYTYPE*) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-   uint32      *nentries = (uint32*)PG_GETARG_POINTER(1);
-   StrategyNumber  strategy = DatumGetUInt16( PG_GETARG_DATUM(2) ); 
-   Datum       *entries = NULL;
+gin_extract_tsquery(PG_FUNCTION_ARGS)
+{
+   QUERYTYPE  *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+   uint32     *nentries = (uint32 *) PG_GETARG_POINTER(1);
+   StrategyNumber strategy = DatumGetUInt16(PG_GETARG_DATUM(2));
+   Datum      *entries = NULL;
 
    *nentries = 0;
-   if ( query->size > 0 ) {
-       int4 i, j=0, len;
-       ITEM *item;
+   if (query->size > 0)
+   {
+       int4        i,
+                   j = 0,
+                   len;
+       ITEM       *item;
 
        item = clean_NOT_v2(GETQUERY(query), &len);
-       if ( !item )
-           elog(ERROR,"Query requires full scan, GIN doesn't support it");
+       if (!item)
+           elog(ERROR, "Query requires full scan, GIN doesn't support it");
 
        item = GETQUERY(query);
 
-       for(i=0; i<query->size; i++)
-           if ( item[i].type == VAL )
+       for (i = 0; i < query->size; i++)
+           if (item[i].type == VAL)
                (*nentries)++;
 
-       entries = (Datum*)palloc( sizeof(Datum) * (*nentries) );
+       entries = (Datum *) palloc(sizeof(Datum) * (*nentries));
 
-       for(i=0; i<query->size; i++)
-           if ( item[i].type == VAL ) {
-               text    *txt;
+       for (i = 0; i < query->size; i++)
+           if (item[i].type == VAL)
+           {
+               text       *txt;
 
-               txt = (text*)palloc( VARHDRSZ + item[i].length );
+               txt = (text *) palloc(VARHDRSZ + item[i].length);
 
-               VARATT_SIZEP(txt) = VARHDRSZ + item[i].length; 
-               memcpy( VARDATA(txt), GETOPERAND( query ) + item[i].distance, item[i].length );
+               VARATT_SIZEP(txt) = VARHDRSZ + item[i].length;
+               memcpy(VARDATA(txt), GETOPERAND(query) + item[i].distance, item[i].length);
 
-               entries[j++] = PointerGetDatum( txt );
+               entries[j++] = PointerGetDatum(txt);
 
-               if ( strategy == 1 && item[i].weight != 0 )
-                   elog(ERROR,"With class of lexeme restrictions use @@@ operation");
+               if (strategy == 1 && item[i].weight != 0)
+                   elog(ERROR, "With class of lexeme restrictions use @@@ operation");
            }
 
    }
@@ -96,51 +104,54 @@ gin_extract_tsquery(PG_FUNCTION_ARGS) {
    PG_RETURN_POINTER(entries);
 }
 
-typedef struct {
-   ITEM    *frst;
-   bool    *mapped_check;
-} GinChkVal; 
+typedef struct
+{
+   ITEM       *frst;
+   bool       *mapped_check;
+}  GinChkVal;
 
 static bool
-checkcondition_gin(void *checkval, ITEM * val) {
-   GinChkVal   *gcv = (GinChkVal*)checkval;
+checkcondition_gin(void *checkval, ITEM * val)
+{
+   GinChkVal  *gcv = (GinChkVal *) checkval;
 
-   return gcv->mapped_check[ val - gcv->frst ];
+   return gcv->mapped_check[val - gcv->frst];
 }
 
 PG_FUNCTION_INFO_V1(gin_ts_consistent);
-Datum       gin_ts_consistent(PG_FUNCTION_ARGS);
+Datum      gin_ts_consistent(PG_FUNCTION_ARGS);
 
 Datum
-gin_ts_consistent(PG_FUNCTION_ARGS) {
-   bool    *check = (bool*)PG_GETARG_POINTER(0);
-   QUERYTYPE *query = (QUERYTYPE*) PG_DETOAST_DATUM(PG_GETARG_DATUM(2));
-   bool    res = FALSE;
-
-   if ( query->size > 0 ) {
-       int4 i, j=0;
-       ITEM *item;
+gin_ts_consistent(PG_FUNCTION_ARGS)
+{
+   bool       *check = (bool *) PG_GETARG_POINTER(0);
+   QUERYTYPE  *query = (QUERYTYPE *) PG_DETOAST_DATUM(PG_GETARG_DATUM(2));
+   bool        res = FALSE;
+
+   if (query->size > 0)
+   {
+       int4        i,
+                   j = 0;
+       ITEM       *item;
        GinChkVal   gcv;
 
-       gcv.frst = item = GETQUERY(query); 
-       gcv.mapped_check= (bool*)palloc( sizeof(bool) * query->size );
+       gcv.frst = item = GETQUERY(query);
+       gcv.mapped_check = (bool *) palloc(sizeof(bool) * query->size);
 
-       for(i=0; i<query->size; i++)
-           if ( item[i].type == VAL )
-               gcv.mapped_check[ i ] = check[ j++ ];
+       for (i = 0; i < query->size; i++)
+           if (item[i].type == VAL)
+               gcv.mapped_check[i] = check[j++];
 
 
        res = TS_execute(
-           GETQUERY(query),
-           &gcv,
-           true,
-           checkcondition_gin
-       );
+                        GETQUERY(query),
+                        &gcv,
+                        true,
+                        checkcondition_gin
+           );
 
    }
 
    PG_FREE_IF_COPY(query, 2);
    PG_RETURN_BOOL(res);
 }
-
-
index 5afb1a41b3b80f55c4b0f7b8413e60a8307223d9..a4d9b2312ed828ea79b9a8c0a25bbac419b0c92b 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/tsearch2/gistidx.c,v 1.14 2006/06/28 12:00:06 teodor Exp $ */
+/* $PostgreSQL: pgsql/contrib/tsearch2/gistidx.c,v 1.15 2006/10/04 00:29:46 momjian Exp $ */
 
 #include "postgres.h"
 
@@ -447,7 +447,7 @@ sizebitvec(BITVECP sign)
                i;
 
    LOOPBYTE(
-       size += number_of_ones[(unsigned char) sign[i]];
+            size += number_of_ones[(unsigned char) sign[i]];
    );
    return size;
 }
@@ -460,8 +460,8 @@ hemdistsign(BITVECP a, BITVECP b)
                dist = 0;
 
    LOOPBYTE(
-       diff = (unsigned char) (a[i] ^ b[i]);
-       dist += number_of_ones[diff];
+            diff = (unsigned char) (a[i] ^ b[i]);
+   dist += number_of_ones[diff];
    );
    return dist;
 }
@@ -533,7 +533,7 @@ typedef struct
 {
    OffsetNumber pos;
    int4        cost;
-} SPLITCOST;
+}  SPLITCOST;
 
 static int
 comparecost(const void *a, const void *b)
index 4be863431d1bd895a89665fd94d56fb47f5e41d9..904521e50783fec01dfdf4556a9388854f863449 100644 (file)
@@ -9,7 +9,7 @@ RS_isRegis(const char *str)
    {
        if (t_isalpha(str) ||
            t_iseq(str, '[') ||
-           t_iseq(str,']') ||
+           t_iseq(str, ']') ||
            t_iseq(str, '^'))
            str += pg_mblen(str);
        else
@@ -42,13 +42,13 @@ RS_compile(Regis * r, bool issuffix, char *str)
 {
    int         len = strlen(str);
    int         state = RS_IN_WAIT;
-   char            *c = (char*)str;
+   char       *c = (char *) str;
    RegisNode  *ptr = NULL;
 
    memset(r, 0, sizeof(Regis));
    r->issuffix = (issuffix) ? 1 : 0;
 
-   while(*c)
+   while (*c)
    {
        if (state == RS_IN_WAIT)
        {
@@ -62,7 +62,7 @@ RS_compile(Regis * r, bool issuffix, char *str)
                ptr->type = RSF_ONEOF;
                ptr->len = pg_mblen(c);
            }
-           else if (t_iseq(c,'['))
+           else if (t_iseq(c, '['))
            {
                if (ptr)
                    ptr = newRegisNode(ptr, len);
@@ -72,11 +72,11 @@ RS_compile(Regis * r, bool issuffix, char *str)
                state = RS_IN_ONEOF;
            }
            else
-               ts_error(ERROR, "Error in regis: %s", str );
+               ts_error(ERROR, "Error in regis: %s", str);
        }
        else if (state == RS_IN_ONEOF)
        {
-           if (t_iseq(c,'^'))
+           if (t_iseq(c, '^'))
            {
                ptr->type = RSF_NONEOF;
                state = RS_IN_NONEOF;
@@ -94,10 +94,10 @@ RS_compile(Regis * r, bool issuffix, char *str)
        {
            if (t_isalpha(c))
            {
-               COPYCHAR(ptr->data+ptr->len,  c);
-               ptr->len+=pg_mblen(c);
+               COPYCHAR(ptr->data + ptr->len, c);
+               ptr->len += pg_mblen(c);
            }
-           else if (t_iseq(c,']'))
+           else if (t_iseq(c, ']'))
                state = RS_IN_WAIT;
            else
                ts_error(ERROR, "Error in regis: %s", str);
@@ -133,28 +133,34 @@ RS_free(Regis * r)
 
 #ifdef TS_USE_WIDE
 static bool
-mb_strchr(char *str, char *c) {
-   int clen = pg_mblen(c), plen,i;
-   char    *ptr =str;
-   bool    res=false;
+mb_strchr(char *str, char *c)
+{
+   int         clen = pg_mblen(c),
+               plen,
+               i;
+   char       *ptr = str;
+   bool        res = false;
 
    clen = pg_mblen(c);
-   while( *ptr && !res) {
+   while (*ptr && !res)
+   {
        plen = pg_mblen(ptr);
-       if ( plen == clen ) {
-           i=plen;
+       if (plen == clen)
+       {
+           i = plen;
            res = true;
-           while(i--)
-               if ( *(ptr+i) != *(c+i) ) {
+           while (i--)
+               if (*(ptr + i) != *(c + i))
+               {
                    res = false;
-                   break; 
+                   break;
                }
        }
-       
+
        ptr += plen;
-   }    
+   }
 
-   return res; 
+   return res;
 }
 #else
 #define mb_strchr(s,c) ( (strchr((s),*(c)) == NULL) ? false : true )
@@ -165,21 +171,23 @@ bool
 RS_execute(Regis * r, char *str)
 {
    RegisNode  *ptr = r->node;
-   char *c = str;
-   int len=0;
+   char       *c = str;
+   int         len = 0;
 
-   while(*c) {
+   while (*c)
+   {
        len++;
        c += pg_mblen(c);
-   }   
+   }
 
    if (len < r->nchar)
        return 0;
 
    c = str;
-   if (r->issuffix) {
+   if (r->issuffix)
+   {
        len -= r->nchar;
-       while(len-- > 0)
+       while (len-- > 0)
            c += pg_mblen(c);
    }
 
@@ -189,18 +197,18 @@ RS_execute(Regis * r, char *str)
        switch (ptr->type)
        {
            case RSF_ONEOF:
-               if ( mb_strchr((char *) ptr->data, c) != true )
+               if (mb_strchr((char *) ptr->data, c) != true)
                    return false;
                break;
            case RSF_NONEOF:
-               if ( mb_strchr((char *) ptr->data, c) == true )
+               if (mb_strchr((char *) ptr->data, c) == true)
                    return false;
                break;
            default:
                ts_error(ERROR, "RS_execute: Unknown type node: %d\n", ptr->type);
        }
        ptr = ptr->next;
-       c+=pg_mblen(c);
+       c += pg_mblen(c);
    }
 
    return true;
index 5bc337c9251033a2df1a7a236bc684ac9f082893..a0b840b0a0d6ad272e3bd0883aa7256e9a03c32f 100644 (file)
@@ -27,12 +27,12 @@ typedef struct Regis
                unused:15;
 }  Regis;
 
-bool           RS_isRegis(const char *str);
+bool       RS_isRegis(const char *str);
 
-void           RS_compile(Regis * r, bool issuffix, char *str);
+void       RS_compile(Regis * r, bool issuffix, char *str);
 void       RS_free(Regis * r);
 
 /*returns true if matches */
-bool           RS_execute(Regis * r, char *str);
+bool       RS_execute(Regis * r, char *str);
 
 #endif
index 4e199f4bc07a6cc5f18494a7abd827ac4866661c..9e4d689cd41167ca5ddc7271ae1b074efe868a13 100644 (file)
@@ -41,16 +41,18 @@ strnduplicate(char *s, int len)
 }
 
 static char *
-findchar(char *str, int c) {
-   while( *str ) {
-       if ( t_iseq(str, c) ) 
+findchar(char *str, int c)
+{
+   while (*str)
+   {
+       if (t_iseq(str, c))
            return str;
-       str+=pg_mblen(str);
+       str += pg_mblen(str);
    }
 
    return NULL;
 }
-       
+
 
 /* backward string compare for suffix tree operations */
 static int
@@ -126,16 +128,16 @@ NIAddSpell(IspellDict * Conf, const char *word, const char *flag)
        if (Conf->mspell)
        {
            Conf->mspell += 1024 * 20;
-           Conf->Spell = (SPELL **) repalloc(Conf->Spell, Conf->mspell * sizeof(SPELL*));
+           Conf->Spell = (SPELL **) repalloc(Conf->Spell, Conf->mspell * sizeof(SPELL *));
        }
        else
        {
            Conf->mspell = 1024 * 20;
-           Conf->Spell = (SPELL **) palloc(Conf->mspell * sizeof(SPELL*));
+           Conf->Spell = (SPELL **) palloc(Conf->mspell * sizeof(SPELL *));
        }
    }
-   Conf->Spell[Conf->nspell] = (SPELL*)palloc(SPELLHDRSZ + strlen(word) + 1);
-   strcpy( Conf->Spell[Conf->nspell]->word ,word );
+   Conf->Spell[Conf->nspell] = (SPELL *) palloc(SPELLHDRSZ + strlen(word) + 1);
+   strcpy(Conf->Spell[Conf->nspell]->word, word);
    strncpy(Conf->Spell[Conf->nspell]->p.flag, flag, 16);
    Conf->nspell++;
    return (0);
@@ -155,7 +157,7 @@ NIImportDictionary(IspellDict * Conf, const char *filename)
        char       *s;
        const char *flag;
 
-       pg_verifymbstr( str, strlen(str), false);
+       pg_verifymbstr(str, strlen(str), false);
 
        flag = NULL;
        if ((s = findchar(str, '/')))
@@ -181,11 +183,12 @@ NIImportDictionary(IspellDict * Conf, const char *filename)
        s = str;
        while (*s)
        {
-           if (t_isspace(s)) {
+           if (t_isspace(s))
+           {
                *s = '\0';
                break;
            }
-           s+=pg_mblen(s);
+           s += pg_mblen(s);
        }
        lowerstr(str);
 
@@ -268,12 +271,13 @@ NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const
    }
    else
    {
-       int masklen = strlen(mask);
+       int         masklen = strlen(mask);
+
        Conf->Affix[Conf->naffixes].issimple = 0;
        Conf->Affix[Conf->naffixes].isregis = 0;
        Conf->Affix[Conf->naffixes].mask = (char *) malloc(masklen + 2);
-       if (type == FF_SUFFIX) 
-           sprintf(Conf->Affix[Conf->naffixes].mask, "%s$", mask); 
+       if (type == FF_SUFFIX)
+           sprintf(Conf->Affix[Conf->naffixes].mask, "%s$", mask);
        else
            sprintf(Conf->Affix[Conf->naffixes].mask, "^%s", mask);
    }
@@ -286,83 +290,121 @@ NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const
 
    Conf->Affix[Conf->naffixes].find = (find && *find) ? strdup(find) : VoidString;
    MEMOUT(Conf->Affix[Conf->naffixes].find);
-   if ( (Conf->Affix[Conf->naffixes].replen = strlen(repl)) > 0 ) {
+   if ((Conf->Affix[Conf->naffixes].replen = strlen(repl)) > 0)
+   {
        Conf->Affix[Conf->naffixes].repl = strdup(repl);
        MEMOUT(Conf->Affix[Conf->naffixes].repl);
-   } else
-        Conf->Affix[Conf->naffixes].repl = VoidString;
+   }
+   else
+       Conf->Affix[Conf->naffixes].repl = VoidString;
    Conf->naffixes++;
    return (0);
 }
 
 #define PAE_WAIT_MASK  0
-#define PAE_INMASK     1
-#define PAE_WAIT_FIND  2
-#define PAE_INFIND     3
-#define PAE_WAIT_REPL  4
-#define PAE_INREPL     5
+#define PAE_INMASK 1
+#define PAE_WAIT_FIND  2
+#define PAE_INFIND 3
+#define PAE_WAIT_REPL  4
+#define PAE_INREPL 5
 
 static bool
-parse_affentry( char *str, char *mask, char *find, char *repl, int line ) {
-   int state = PAE_WAIT_MASK;
-   char    *pmask=mask, *pfind=find, *prepl=repl;
+parse_affentry(char *str, char *mask, char *find, char *repl, int line)
+{
+   int         state = PAE_WAIT_MASK;
+   char       *pmask = mask,
+              *pfind = find,
+              *prepl = repl;
 
    *mask = *find = *repl = '\0';
 
-   while(*str) {
-       if ( state == PAE_WAIT_MASK ) {
-           if ( t_iseq(str,'#') ) 
+   while (*str)
+   {
+       if (state == PAE_WAIT_MASK)
+       {
+           if (t_iseq(str, '#'))
                return false;
-           else if (!t_isspace(str)) {
+           else if (!t_isspace(str))
+           {
                COPYCHAR(pmask, str);
                pmask += pg_mblen(str);
                state = PAE_INMASK;
            }
-       } else if ( state == PAE_INMASK ) {
-           if ( t_iseq(str,'>') ) {
-               *pmask='\0';
+       }
+       else if (state == PAE_INMASK)
+       {
+           if (t_iseq(str, '>'))
+           {
+               *pmask = '\0';
                state = PAE_WAIT_FIND;
-           } else if (!t_isspace(str)) {
+           }
+           else if (!t_isspace(str))
+           {
                COPYCHAR(pmask, str);
                pmask += pg_mblen(str);
            }
-       } else if ( state == PAE_WAIT_FIND ) {
-           if ( t_iseq(str,'-') ) {
+       }
+       else if (state == PAE_WAIT_FIND)
+       {
+           if (t_iseq(str, '-'))
+           {
                state = PAE_INFIND;
-           } else if (t_isalpha(str) || t_iseq(str,'\'') /* english 's */) {
-               COPYCHAR(prepl,str);
+           }
+           else if (t_isalpha(str) || t_iseq(str, '\'') /* english 's */ )
+           {
+               COPYCHAR(prepl, str);
                prepl += pg_mblen(str);
                state = PAE_INREPL;
-           } else if (!t_isspace(str))
+           }
+           else if (!t_isspace(str))
                ts_error(ERROR, "Affix parse error at %d line", line);
-       } else if ( state == PAE_INFIND ) {
-           if ( t_iseq(str,',') ) {
-               *pfind='\0';
+       }
+       else if (state == PAE_INFIND)
+       {
+           if (t_iseq(str, ','))
+           {
+               *pfind = '\0';
                state = PAE_WAIT_REPL;
-           } else if (t_isalpha(str)) {
-               COPYCHAR(pfind,str);
+           }
+           else if (t_isalpha(str))
+           {
+               COPYCHAR(pfind, str);
                pfind += pg_mblen(str);
-           } else if (!t_isspace(str))
+           }
+           else if (!t_isspace(str))
                ts_error(ERROR, "Affix parse error at %d line", line);
-       } else if ( state == PAE_WAIT_REPL ) {
-           if ( t_iseq(str,'-') ) {
-               break; /* void repl */
-           } else if ( t_isalpha(str) ) {
-               COPYCHAR(prepl,str);
+       }
+       else if (state == PAE_WAIT_REPL)
+       {
+           if (t_iseq(str, '-'))
+           {
+               break;          /* void repl */
+           }
+           else if (t_isalpha(str))
+           {
+               COPYCHAR(prepl, str);
                prepl += pg_mblen(str);
                state = PAE_INREPL;
-           } else if (!t_isspace(str))
+           }
+           else if (!t_isspace(str))
                ts_error(ERROR, "Affix parse error at %d line", line);
-       } else if ( state == PAE_INREPL ) {
-           if ( t_iseq(str,'#') ) {
+       }
+       else if (state == PAE_INREPL)
+       {
+           if (t_iseq(str, '#'))
+           {
                *prepl = '\0';
                break;
-           } else if ( t_isalpha(str) ) { 
-               COPYCHAR(prepl,str);
+           }
+           else if (t_isalpha(str))
+           {
+               COPYCHAR(prepl, str);
                prepl += pg_mblen(str);
-           } else if (!t_isspace(str))
+           }
+           else if (!t_isspace(str))
                ts_error(ERROR, "Affix parse error at %d line", line);
-       } else
+       }
+       else
            ts_error(ERROR, "Unknown state in parse_affentry: %d", state);
 
        str += pg_mblen(str);
@@ -370,8 +412,8 @@ parse_affentry( char *str, char *mask, char *find, char *repl, int line ) {
 
    *pmask = *pfind = *prepl = '\0';
 
-   return ( *mask && ( *find || *repl) ) ? true : false;
-} 
+   return (*mask && (*find || *repl)) ? true : false;
+}
 
 int
 NIImportAffixes(IspellDict * Conf, const char *filename)
@@ -387,8 +429,8 @@ NIImportAffixes(IspellDict * Conf, const char *filename)
    int         flag = 0;
    char        flagflags = 0;
    FILE       *affix;
-   int line=0;
-   int oldformat = 0;
+   int         line = 0;
+   int         oldformat = 0;
 
    if (!(affix = fopen(filename, "r")))
        return (1);
@@ -397,18 +439,20 @@ NIImportAffixes(IspellDict * Conf, const char *filename)
    while (fgets(str, sizeof(str), affix))
    {
        line++;
-       pg_verifymbstr( str, strlen(str), false);
-       memcpy(tmpstr, str, 32); /* compoundwords... */
-       tmpstr[32]='\0';
+       pg_verifymbstr(str, strlen(str), false);
+       memcpy(tmpstr, str, 32);    /* compoundwords... */
+       tmpstr[32] = '\0';
        lowerstr(tmpstr);
        if (STRNCMP(tmpstr, "compoundwords") == 0)
        {
            s = findchar(str, 'l');
            if (s)
            {
-               while (*s && !t_isspace(s)) s++;
-               while (*s && t_isspace(s)) s++;
-               if ( *s && pg_mblen(s) == 1 ) 
+               while (*s && !t_isspace(s))
+                   s++;
+               while (*s && t_isspace(s))
+                   s++;
+               if (*s && pg_mblen(s) == 1)
                    Conf->compoundcontrol = *s;
                oldformat++;
                continue;
@@ -433,12 +477,13 @@ NIImportAffixes(IspellDict * Conf, const char *filename)
            s = str + 4;
            flagflags = 0;
 
-           while (*s && t_isspace(s)) s++;
+           while (*s && t_isspace(s))
+               s++;
            oldformat++;
 
            /* allow only single-encoded flags */
-           if ( pg_mblen(s) != 1 ) 
-               elog(ERROR,"Multiencoded flag at line %d: %s", line, s);
+           if (pg_mblen(s) != 1)
+               elog(ERROR, "Multiencoded flag at line %d: %s", line, s);
 
            if (*s == '*')
            {
@@ -455,29 +500,31 @@ NIImportAffixes(IspellDict * Conf, const char *filename)
                s++;
 
            /* allow only single-encoded flags */
-           if ( pg_mblen(s) != 1 ) {
+           if (pg_mblen(s) != 1)
+           {
                flagflags = 0;
-               elog(ERROR,"Multiencoded flag at line %d: %s", line, s);
+               elog(ERROR, "Multiencoded flag at line %d: %s", line, s);
            }
 
            flag = (unsigned char) *s;
            continue;
        }
-       if ( STRNCMP(str, "COMPOUNDFLAG") == 0 || STRNCMP(str, "COMPOUNDMIN") == 0 || 
-                    STRNCMP(str, "PFX")==0 || STRNCMP(str, "SFX")==0 ) {
+       if (STRNCMP(str, "COMPOUNDFLAG") == 0 || STRNCMP(str, "COMPOUNDMIN") == 0 ||
+           STRNCMP(str, "PFX") == 0 || STRNCMP(str, "SFX") == 0)
+       {
 
-           if ( oldformat ) 
-               elog(ERROR,"Wrong affix file format");
+           if (oldformat)
+               elog(ERROR, "Wrong affix file format");
 
            fclose(affix);
            return NIImportOOAffixes(Conf, filename);
-           
+
        }
        if ((!suffixes) && (!prefixes))
            continue;
 
        lowerstr(str);
-       if ( !parse_affentry(str, mask, find, repl, line) )
+       if (!parse_affentry(str, mask, find, repl, line))
            continue;
 
        NIAddAffix(Conf, flag, flagflags, mask, find, repl, suffixes ? FF_SUFFIX : FF_PREFIX);
@@ -488,7 +535,8 @@ NIImportAffixes(IspellDict * Conf, const char *filename)
 }
 
 int
-NIImportOOAffixes(IspellDict * Conf, const char *filename) {
+NIImportOOAffixes(IspellDict * Conf, const char *filename)
+{
    char        str[BUFSIZ];
    char        type[BUFSIZ];
    char        sflag[BUFSIZ];
@@ -499,11 +547,11 @@ NIImportOOAffixes(IspellDict * Conf, const char *filename) {
    int         flag = 0;
    char        flagflags = 0;
    FILE       *affix;
-   int line=0;
-   int scanread = 0;
+   int         line = 0;
+   int         scanread = 0;
    char        scanbuf[BUFSIZ];
 
-   sprintf(scanbuf,"%%6s %%%ds %%%ds %%%ds %%%ds", BUFSIZ/5, BUFSIZ/5, BUFSIZ/5, BUFSIZ/5);
+   sprintf(scanbuf, "%%6s %%%ds %%%ds %%%ds %%%ds", BUFSIZ / 5, BUFSIZ / 5, BUFSIZ / 5, BUFSIZ / 5);
 
    if (!(affix = fopen(filename, "r")))
        return (1);
@@ -512,14 +560,17 @@ NIImportOOAffixes(IspellDict * Conf, const char *filename) {
    while (fgets(str, sizeof(str), affix))
    {
        line++;
-       if ( *str == '\0' || t_isspace(str) || t_iseq(str,'#') )
+       if (*str == '\0' || t_isspace(str) || t_iseq(str, '#'))
            continue;
-       pg_verifymbstr( str, strlen(str), false);
+       pg_verifymbstr(str, strlen(str), false);
 
-       if ( STRNCMP(str, "COMPOUNDFLAG")==0 ) {
-           char *s = str+strlen("COMPOUNDFLAG");
-           while (*s && t_isspace(s)) s++;
-           if ( *s && pg_mblen(s) == 1 ) 
+       if (STRNCMP(str, "COMPOUNDFLAG") == 0)
+       {
+           char       *s = str + strlen("COMPOUNDFLAG");
+
+           while (*s && t_isspace(s))
+               s++;
+           if (*s && pg_mblen(s) == 1)
                Conf->compoundcontrol = *s;
            continue;
        }
@@ -527,28 +578,31 @@ NIImportOOAffixes(IspellDict * Conf, const char *filename) {
        scanread = sscanf(str, scanbuf, type, sflag, find, repl, mask);
 
        lowerstr(type);
-       if ( scanread<4 || (STRNCMP(type,"sfx") && STRNCMP(type,"pfx")) )
+       if (scanread < 4 || (STRNCMP(type, "sfx") && STRNCMP(type, "pfx")))
            continue;
 
-       if ( scanread == 4 ) {
-           if ( strlen(sflag) != 1 )
+       if (scanread == 4)
+       {
+           if (strlen(sflag) != 1)
                continue;
            flag = *sflag;
-           isSuffix = (STRNCMP(type,"sfx")==0) ? true : false;
+           isSuffix = (STRNCMP(type, "sfx") == 0) ? true : false;
            lowerstr(find);
-           if ( t_iseq(find,'y') )
+           if (t_iseq(find, 'y'))
                flagflags |= FF_CROSSPRODUCT;
            else
                flagflags = 0;
-       } else {
-           if ( strlen(sflag) != 1 || flag != *sflag || flag==0 )
+       }
+       else
+       {
+           if (strlen(sflag) != 1 || flag != *sflag || flag == 0)
                continue;
            lowerstr(repl);
            lowerstr(find);
            lowerstr(mask);
-           if ( t_iseq(find,'0') )
+           if (t_iseq(find, '0'))
                *find = '\0';
-           if ( t_iseq(repl,'0') )
+           if (t_iseq(repl, '0'))
                *repl = '\0';
 
            NIAddAffix(Conf, flag, flagflags, mask, find, repl, isSuffix ? FF_SUFFIX : FF_PREFIX);
@@ -658,7 +712,7 @@ NISortDictionary(IspellDict * Conf)
    int         naffix = 3;
 
    /* compress affixes */
-   qsort((void *) Conf->Spell, Conf->nspell, sizeof(SPELL*), cmpspellaffix);
+   qsort((void *) Conf->Spell, Conf->nspell, sizeof(SPELL *), cmpspellaffix);
    for (i = 1; i < Conf->nspell; i++)
        if (strcmp(Conf->Spell[i]->p.flag, Conf->Spell[i - 1]->p.flag))
            naffix++;
@@ -685,7 +739,7 @@ NISortDictionary(IspellDict * Conf)
        Conf->Spell[i]->p.d.len = strlen(Conf->Spell[i]->word);
    }
 
-   qsort((void *) Conf->Spell, Conf->nspell, sizeof(SPELL*), cmpspell);
+   qsort((void *) Conf->Spell, Conf->nspell, sizeof(SPELL *), cmpspell);
    Conf->Dictionary = mkSPNode(Conf, 0, Conf->nspell, 0);
 
    for (i = 0; i < Conf->nspell; i++)
@@ -806,7 +860,7 @@ NISortAffixes(IspellDict * Conf)
    CMPDAffix  *ptr;
    int         firstsuffix = -1;
 
-   if (Conf->naffixes==0)
+   if (Conf->naffixes == 0)
        return;
 
    if (Conf->naffixes > 1)
@@ -822,7 +876,7 @@ NISortAffixes(IspellDict * Conf)
        {
            if (firstsuffix < 0)
                firstsuffix = i;
-           if ((Affix->flagflags & FF_COMPOUNDONLYAFX) && Affix->replen>0 )
+           if ((Affix->flagflags & FF_COMPOUNDONLYAFX) && Affix->replen > 0)
            {
                if (ptr == Conf->CompoundAffix ||
                    strbncmp((const unsigned char *) (ptr - 1)->affix,
@@ -907,14 +961,16 @@ CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *ne
    {
        strcpy(newword, word);
        strcpy(newword + len - Affix->replen, Affix->find);
-       if ( baselen ) /* store length of non-changed part of word */ 
+       if (baselen)            /* store length of non-changed part of word */
            *baselen = len - Affix->replen;
    }
    else
    {
-       /* if prefix is a all non-chaged part's length then all word contains only prefix and suffix,
-          so out */
-       if ( baselen && *baselen + strlen(Affix->find) <= Affix->replen )
+       /*
+        * if prefix is a all non-chaged part's length then all word contains
+        * only prefix and suffix, so out
+        */
+       if (baselen && *baselen + strlen(Affix->find) <= Affix->replen)
            return NULL;
        strcpy(newword, Affix->find);
        strcat(newword, word + Affix->replen);
@@ -944,6 +1000,7 @@ CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *ne
            int         wmasklen,
                        masklen = strlen(Affix->mask);
            pg_wchar   *mask;
+
            mask = (pg_wchar *) palloc((masklen + 1) * sizeof(pg_wchar));
            wmasklen = pg_mb2wchar_with_len(Affix->mask, mask, masklen);
 
@@ -1040,7 +1097,7 @@ NormalizeSubWord(IspellDict * Conf, char *word, char flag)
     */
    while (snode)
    {
-       int baselen=0;
+       int         baselen = 0;
 
        /* find possible suffix */
        suffix = FinfAffixes(snode, word, wrdlen, &slevel, FF_SUFFIX);
@@ -1111,7 +1168,8 @@ typedef struct SplitVar
 static int
 CheckCompoundAffixes(CMPDAffix ** ptr, char *word, int len, bool CheckInPlace)
 {
-   if ( CheckInPlace ) {
+   if (CheckInPlace)
+   {
        while ((*ptr)->affix)
        {
            if (len > (*ptr)->len && strncmp((*ptr)->affix, word, (*ptr)->len) == 0)
@@ -1122,13 +1180,16 @@ CheckCompoundAffixes(CMPDAffix ** ptr, char *word, int len, bool CheckInPlace)
            }
            (*ptr)++;
        }
-   } else {
-       char *affbegin;
+   }
+   else
+   {
+       char       *affbegin;
+
        while ((*ptr)->affix)
        {
            if (len > (*ptr)->len && (affbegin = strstr(word, (*ptr)->affix)) != NULL)
            {
-               len = (*ptr)->len + (affbegin-word);
+               len = (*ptr)->len + (affbegin - word);
                (*ptr)++;
                return len;
            }
@@ -1227,8 +1288,8 @@ SplitToVariants(IspellDict * Conf, SPNode * snode, SplitVar * orig, char *word,
            }
        }
 
-       if ( !node )
-           break; 
+       if (!node)
+           break;
 
        StopLow = node->data;
        StopHigh = node->data + node->length;
@@ -1243,7 +1304,8 @@ SplitToVariants(IspellDict * Conf, SPNode * snode, SplitVar * orig, char *word,
                StopHigh = StopMiddle;
        }
 
-       if (StopLow < StopHigh) {
+       if (StopLow < StopHigh)
+       {
 
            /* find infinitive */
            if (StopMiddle->isword && StopMiddle->compoundallow && notprobed[level])
@@ -1264,7 +1326,7 @@ SplitToVariants(IspellDict * Conf, SPNode * snode, SplitVar * orig, char *word,
                    {
                        /* then we will search more big word at the same point */
                        SplitVar   *ptr = var;
-   
+
                        while (ptr->next)
                            ptr = ptr->next;
                        ptr->next = SplitToVariants(Conf, node, var, word, wordlen, startpos, level);
@@ -1279,8 +1341,9 @@ SplitToVariants(IspellDict * Conf, SPNode * snode, SplitVar * orig, char *word,
                }
            }
            node = StopMiddle->node;
-       } else
-           node = NULL;  
+       }
+       else
+           node = NULL;
        level++;
    }
 
@@ -1436,9 +1499,12 @@ NIFree(IspellDict * Conf)
            else
                pg_regfree(&(Affix[i].reg.regex));
        }
-       if ( Affix[i].mask != VoidString ) free(Affix[i].mask);
-       if ( Affix[i].find != VoidString ) free(Affix[i].find);
-       if ( Affix[i].repl != VoidString ) free(Affix[i].repl);
+       if (Affix[i].mask != VoidString)
+           free(Affix[i].mask);
+       if (Affix[i].find != VoidString)
+           free(Affix[i].find);
+       if (Affix[i].repl != VoidString)
+           free(Affix[i].repl);
    }
    if (Conf->Spell)
    {
index 5734881947e9b6a1309108783a0920b926b3e323..50a5947680e7cda064c08a659e7b5b23909c9179 100644 (file)
@@ -42,8 +42,8 @@ typedef struct spell_struct
            int         affix;
            int         len;
        }           d;
-   }   p;
-   char    word[1];
+   }           p;
+   char        word[1];
 }  SPELL;
 
 #define SPELLHDRSZ (offsetof(SPELL, word))
@@ -110,7 +110,7 @@ typedef struct
 
    int         nspell;
    int         mspell;
-   SPELL      **Spell;
+   SPELL     **Spell;
 
    AffixNode  *Suffix;
    AffixNode  *Prefix;
index 42fd6712e6d835b9a96a2ef434857407fd6a8670..c519f5f3d4d45d2823780f39b5a86a7fb3a0d033 100644 (file)
@@ -33,9 +33,9 @@ nstrdup(char *ptr, int len)
    {
        if (t_iseq(ptr, '\\'))
            ptr++;
-       COPYCHAR( cptr, ptr );
-       cptr+=pg_mblen(ptr);
-       ptr+=pg_mblen(ptr);
+       COPYCHAR(cptr, ptr);
+       cptr += pg_mblen(ptr);
+       ptr += pg_mblen(ptr);
    }
    *cptr = '\0';
 
@@ -53,9 +53,9 @@ parse_cfgdict(text *in, Map ** m)
 
    while (ptr - VARDATA(in) < VARSIZE(in) - VARHDRSZ)
    {
-       if ( t_iseq(ptr, ',') )
+       if (t_iseq(ptr, ','))
            num++;
-       ptr+=pg_mblen(ptr);
+       ptr += pg_mblen(ptr);
    }
 
    *m = mptr = (Map *) palloc(sizeof(Map) * (num + 2));
@@ -84,7 +84,7 @@ parse_cfgdict(text *in, Map ** m)
                mptr->key = nstrdup(begin, ptr - begin);
                state = CS_WAITEQ;
            }
-           else if (t_iseq(ptr,'='))
+           else if (t_iseq(ptr, '='))
            {
                mptr->key = nstrdup(begin, ptr - begin);
                state = CS_WAITVALUE;
@@ -163,7 +163,7 @@ parse_cfgdict(text *in, Map ** m)
                     errmsg("bad parser state"),
                     errdetail("%d at position %d.",
                               state, (int) (ptr - VARDATA(in)))));
-       ptr+=pg_mblen(ptr);
+       ptr += pg_mblen(ptr);
    }
 
    if (state == CS_IN2VALUE)
index 6aeff0078d1d687d4e1b38732bf28a3c3a7a5dfe..c325e453d4fb6e818afda2ec0593cb7fcb70828a 100644 (file)
@@ -108,11 +108,11 @@ get_weight(char *buf, int2 *weight)
 {
    *weight = 0;
 
-   if ( !t_iseq(buf, ':') )
+   if (!t_iseq(buf, ':'))
        return buf;
 
    buf++;
-   while ( *buf && pg_mblen(buf) == 1 )
+   while (*buf && pg_mblen(buf) == 1)
    {
        switch (*buf)
        {
@@ -153,25 +153,26 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, int2
        {
            case WAITFIRSTOPERAND:
            case WAITOPERAND:
-               if ( t_iseq(state->buf, '!') )
+               if (t_iseq(state->buf, '!'))
                {
-                   (state->buf)++; /* can safely ++, t_iseq guarantee that pg_mblen()==1 */
+                   (state->buf)++;     /* can safely ++, t_iseq guarantee
+                                        * that pg_mblen()==1 */
                    *val = (int4) '!';
                    return OPR;
                }
-               else if ( t_iseq(state->buf, '(') )
+               else if (t_iseq(state->buf, '('))
                {
                    state->count++;
                    (state->buf)++;
                    return OPEN;
                }
-               else if ( t_iseq(state->buf, ':') )
+               else if (t_iseq(state->buf, ':'))
                {
                    ereport(ERROR,
                            (errcode(ERRCODE_SYNTAX_ERROR),
                             errmsg("error at start of operand")));
                }
-               else if ( !t_isspace(state->buf) )
+               else if (!t_isspace(state->buf))
                {
                    state->valstate.prsbuf = state->buf;
                    if (gettoken_tsvector(&(state->valstate)))
@@ -191,14 +192,14 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, int2
                }
                break;
            case WAITOPERATOR:
-               if ( t_iseq(state->buf, '&') || t_iseq(state->buf, '|') )
+               if (t_iseq(state->buf, '&') || t_iseq(state->buf, '|'))
                {
                    state->state = WAITOPERAND;
                    *val = (int4) *(state->buf);
                    (state->buf)++;
                    return OPR;
                }
-               else if ( t_iseq(state->buf, ')') )
+               else if (t_iseq(state->buf, ')'))
                {
                    (state->buf)++;
                    state->count--;
@@ -206,7 +207,7 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, int2
                }
                else if (*(state->buf) == '\0')
                    return (state->count) ? ERR : END;
-               else if ( !t_isspace(state->buf) )
+               else if (!t_isspace(state->buf))
                    return ERR;
                break;
            case WAITSINGLEOPERAND:
@@ -221,7 +222,7 @@ gettoken_query(QPRS_STATE * state, int4 *val, int4 *lenval, char **strval, int2
                return ERR;
                break;
        }
-       state->buf+=pg_mblen(state->buf);
+       state->buf += pg_mblen(state->buf);
    }
    return END;
 }
@@ -604,7 +605,7 @@ findoprnd(ITEM * ptr, int4 *pos)
  * input
  */
 static QUERYTYPE *
-queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int cfg_id, bool isplain)
+           queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int cfg_id, bool isplain)
 {
    QPRS_STATE  state;
    int4        i;
@@ -701,8 +702,9 @@ queryin(char *buf, void (*pushval) (QPRS_STATE *, int, char *, int, int2), int c
 Datum
 tsquery_in(PG_FUNCTION_ARGS)
 {
-   char * in = (char*)PG_GETARG_POINTER(0);
-   pg_verifymbstr( in, strlen(in), false);
+   char       *in = (char *) PG_GETARG_POINTER(0);
+
+   pg_verifymbstr(in, strlen(in), false);
 
    SET_FUNCOID();
    PG_RETURN_POINTER(queryin((char *) in, pushval_asis, 0, false));
@@ -739,23 +741,23 @@ infix(INFIX * in, bool first)
    if (in->curpol->type == VAL)
    {
        char       *op = in->op + in->curpol->distance;
-       int     clen;
+       int         clen;
 
-       RESIZEBUF(in, in->curpol->length * (pg_database_encoding_max_length()+1) + 2 + 5);
+       RESIZEBUF(in, in->curpol->length * (pg_database_encoding_max_length() + 1) + 2 + 5);
        *(in->cur) = '\'';
        in->cur++;
        while (*op)
        {
-           if ( t_iseq(op, '\'') )
+           if (t_iseq(op, '\''))
            {
                *(in->cur) = '\'';
                in->cur++;
            }
-           COPYCHAR(in->cur,op);
+           COPYCHAR(in->cur, op);
 
            clen = pg_mblen(op);
-           op+=clen;
-           in->cur+=clen;
+           op += clen;
+           in->cur += clen;
        }
        *(in->cur) = '\'';
        in->cur++;
index bf1fe18c33a315838d1c85b690b08e92cefa7249..b4d586a684b085c043c0eb611a269a73a0edf97d 100644 (file)
@@ -48,7 +48,7 @@ typedef struct
 #define CLOSE          5
 #define VALSTOP            6       /* for stop words */
 
-bool TS_execute(ITEM *curitem, void *checkval,
-          bool calcnot, bool (*chkcond) (void *checkval, ITEM *val));
+bool TS_execute(ITEM * curitem, void *checkval,
+          bool calcnot, bool (*chkcond) (void *checkval, ITEM * val));
 
 #endif
index f6ce893609c248e7d6bd2cec8bca1431820e5e05..5879f644e649717f24f31c967bfa47d4883076e3 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "query.h"
 
-ITEM      *clean_NOT_v2(ITEM *ptr, int4 *len);
-ITEM      *clean_fakeval_v2(ITEM *ptr, int4 *len);
+ITEM      *clean_NOT_v2(ITEM * ptr, int4 *len);
+ITEM      *clean_fakeval_v2(ITEM * ptr, int4 *len);
 
 #endif
index ffa765560d9c30d7fee41613d670d5ecbefb7951..aafb6901092475404329bb6cfae01a5ccffbcb8f 100644 (file)
@@ -29,7 +29,7 @@ makesign(QUERYTYPE * a)
    for (i = 0; i < a->size; i++)
    {
        if (ptr->type == VAL)
-           sign |= ((TPQTGist)1) << (ptr->val % SIGLEN);
+           sign |= ((TPQTGist) 1) << (ptr->val % SIGLEN);
        ptr++;
    }
 
@@ -104,7 +104,7 @@ tsq_mcontained(PG_FUNCTION_ARGS)
                                        PG_GETARG_DATUM(1),
                                        PG_GETARG_DATUM(0)
                                        )
-   );
+       );
 }
 
 PG_FUNCTION_INFO_V1(gtsq_in);
@@ -272,7 +272,7 @@ typedef struct
 {
    OffsetNumber pos;
    int4        cost;
-} SPLITCOST;
+}  SPLITCOST;
 
 static int
 comparecost(const void *a, const void *b)
index 7ffa62051f563dedb7f82f18d3aeefabb4ebfd5b..41e633580d59207bf84ad1406b3a9e488e075608 100644 (file)
@@ -41,13 +41,13 @@ static float weights[] = {0.1, 0.2, 0.4, 1.0};
 
 #define wpos(wep)  ( w[ WEP_GETWEIGHT(wep) ] )
 
-#define    RANK_NO_NORM        0x00
-#define RANK_NORM_LOGLENGTH    0x01
-#define RANK_NORM_LENGTH   0x02
-#define    RANK_NORM_EXTDIST   0x04
+#define RANK_NO_NORM       0x00
+#define RANK_NORM_LOGLENGTH        0x01
+#define RANK_NORM_LENGTH   0x02
+#define RANK_NORM_EXTDIST  0x04
 #define RANK_NORM_UNIQ     0x08
 #define RANK_NORM_LOGUNIQ  0x10
-#define DEF_NORM_METHOD    RANK_NO_NORM
+#define DEF_NORM_METHOD        RANK_NO_NORM
 
 static float calc_rank_or(float *w, tsvector * t, QUERYTYPE * q);
 static float calc_rank_and(float *w, tsvector * t, QUERYTYPE * q);
@@ -334,19 +334,20 @@ calc_rank(float *w, tsvector * t, QUERYTYPE * q, int4 method)
    if (res < 0)
        res = 1e-20;
 
-   if ( (method & RANK_NORM_LOGLENGTH) && t->size>0 )
+   if ((method & RANK_NORM_LOGLENGTH) && t->size > 0)
        res /= log((double) (cnt_length(t) + 1)) / log(2.0);
 
-   if ( method & RANK_NORM_LENGTH ) {
+   if (method & RANK_NORM_LENGTH)
+   {
        len = cnt_length(t);
-       if ( len>0 )
+       if (len > 0)
            res /= (float) len;
    }
 
-   if ( (method & RANK_NORM_UNIQ) && t->size > 0 )
-       res /= (float)( t->size );
+   if ((method & RANK_NORM_UNIQ) && t->size > 0)
+       res /= (float) (t->size);
 
-   if ( (method & RANK_NORM_LOGUNIQ) && t->size > 0 )
+   if ((method & RANK_NORM_LOGUNIQ) && t->size > 0)
        res /= log((double) (t->size + 1)) / log(2.0);
 
    return res;
@@ -457,17 +458,18 @@ reset_istrue_flag(QUERYTYPE * query)
    }
 }
 
-typedef struct {
-   int pos;
-   int p;
-   int q;
-   DocRepresentation   *begin;
-   DocRepresentation   *end;
-} Extention;
+typedef struct
+{
+   int         pos;
+   int         p;
+   int         q;
+   DocRepresentation *begin;
+   DocRepresentation *end;
+}  Extention;
 
 
 static bool
-Cover(DocRepresentation * doc, int len, QUERYTYPE * query, Extention *ext)
+Cover(DocRepresentation * doc, int len, QUERYTYPE * query, Extention * ext)
 {
    DocRepresentation *ptr;
    int         lastpos = ext->pos;
@@ -513,7 +515,8 @@ Cover(DocRepresentation * doc, int len, QUERYTYPE * query, Extention *ext)
            ptr->item[i]->istrue = 1;
        if (TS_execute(GETQUERY(query), NULL, true, checkcondition_ITEM))
        {
-           if (ptr->pos < ext->p) {
+           if (ptr->pos < ext->p)
+           {
                ext->begin = ptr;
                ext->p = ptr->pos;
            }
@@ -629,69 +632,77 @@ get_docrep(tsvector * txt, QUERYTYPE * query, int *doclen)
 }
 
 static float4
-calc_rank_cd(float4 *arrdata, tsvector *txt, QUERYTYPE *query, int method) {
+calc_rank_cd(float4 *arrdata, tsvector * txt, QUERYTYPE * query, int method)
+{
    DocRepresentation *doc;
-   int             len,
+   int         len,
                i,
                doclen = 0;
    Extention   ext;
    double      Wdoc = 0.0;
    double      invws[lengthof(weights)];
-   double      SumDist=0.0, PrevExtPos=0.0, CurExtPos=0.0;
-   int     NExtent=0;
+   double      SumDist = 0.0,
+               PrevExtPos = 0.0,
+               CurExtPos = 0.0;
+   int         NExtent = 0;
 
    for (i = 0; i < lengthof(weights); i++)
    {
-       invws[i] = ((double)((arrdata[i] >= 0) ? arrdata[i] : weights[i]));
+       invws[i] = ((double) ((arrdata[i] >= 0) ? arrdata[i] : weights[i]));
        if (invws[i] > 1.0)
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                     errmsg("weight out of range")));
-       invws[i] = 1.0/invws[i]; 
+       invws[i] = 1.0 / invws[i];
    }
 
    doc = get_docrep(txt, query, &doclen);
-   if (!doc) 
+   if (!doc)
        return 0.0;
 
-   MemSet( &ext, 0, sizeof(Extention) );
-   while (Cover(doc, doclen, query, &ext)) {
-       double  Cpos = 0.0;
-       double  InvSum = 0.0;
+   MemSet(&ext, 0, sizeof(Extention));
+   while (Cover(doc, doclen, query, &ext))
+   {
+       double      Cpos = 0.0;
+       double      InvSum = 0.0;
        DocRepresentation *ptr = ext.begin;
 
-       while ( ptr<=ext.end ) {
-           InvSum += invws[ ptr->wclass ];
+       while (ptr <= ext.end)
+       {
+           InvSum += invws[ptr->wclass];
            ptr++;
        }
 
-       Cpos = ((double)( ext.end-ext.begin+1 )) / InvSum;
-       Wdoc += Cpos / ( (double)(( 1 + (ext.q - ext.p) - (ext.end - ext.begin) )) ); 
+       Cpos = ((double) (ext.end - ext.begin + 1)) / InvSum;
+       Wdoc += Cpos / ((double) ((1 + (ext.q - ext.p) - (ext.end - ext.begin))));
 
-       CurExtPos = ((double)(ext.q + ext.p))/2.0; 
-       if ( NExtent>0 && CurExtPos > PrevExtPos /* prevent devision by zero in a case of multiple lexize */ ) 
-           SumDist += 1.0/( CurExtPos - PrevExtPos );
+       CurExtPos = ((double) (ext.q + ext.p)) / 2.0;
+       if (NExtent > 0 && CurExtPos > PrevExtPos       /* prevent devision by
+                                                        * zero in a case of
+               multiple lexize */ )
+           SumDist += 1.0 / (CurExtPos - PrevExtPos);
 
        PrevExtPos = CurExtPos;
-       NExtent++; 
+       NExtent++;
    }
 
-   if ( (method & RANK_NORM_LOGLENGTH) && txt->size > 0 )
+   if ((method & RANK_NORM_LOGLENGTH) && txt->size > 0)
        Wdoc /= log((double) (cnt_length(txt) + 1));
 
-   if ( method & RANK_NORM_LENGTH ) {
+   if (method & RANK_NORM_LENGTH)
+   {
        len = cnt_length(txt);
-       if ( len>0 )
+       if (len > 0)
            Wdoc /= (double) len;
    }
 
-   if ( (method & RANK_NORM_EXTDIST) && SumDist > 0 ) 
-       Wdoc /= ((double)NExtent) / SumDist;
+   if ((method & RANK_NORM_EXTDIST) && SumDist > 0)
+       Wdoc /= ((double) NExtent) / SumDist;
 
-   if ( (method & RANK_NORM_UNIQ) && txt->size > 0 )
-       Wdoc /= (double)( txt->size );
+   if ((method & RANK_NORM_UNIQ) && txt->size > 0)
+       Wdoc /= (double) (txt->size);
 
-   if ( (method & RANK_NORM_LOGUNIQ) && txt->size > 0 )
+   if ((method & RANK_NORM_LOGUNIQ) && txt->size > 0)
        Wdoc /= log((double) (txt->size + 1)) / log(2.0);
 
    for (i = 0; i < doclen; i++)
@@ -699,13 +710,13 @@ calc_rank_cd(float4 *arrdata, tsvector *txt, QUERYTYPE *query, int method) {
            pfree(doc[i].item);
    pfree(doc);
 
-   return (float4)Wdoc;
-} 
+   return (float4) Wdoc;
+}
 
 Datum
 rank_cd(PG_FUNCTION_ARGS)
 {
-   ArrayType *win =  (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+   ArrayType  *win = (ArrayType *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
    tsvector   *txt = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
    QUERYTYPE  *query = (QUERYTYPE *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(2));
    int         method = DEF_NORM_METHOD;
@@ -729,7 +740,7 @@ rank_cd(PG_FUNCTION_ARGS)
    if (PG_NARGS() == 4)
        method = PG_GETARG_INT32(3);
 
-   res = calc_rank_cd( (float4 *) ARR_DATA_PTR(win), txt, query, method);
+   res = calc_rank_cd((float4 *) ARR_DATA_PTR(win), txt, query, method);
 
    PG_FREE_IF_COPY(win, 0);
    PG_FREE_IF_COPY(txt, 1);
@@ -744,10 +755,10 @@ rank_cd_def(PG_FUNCTION_ARGS)
 {
    tsvector   *txt = (tsvector *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
    QUERYTYPE  *query = (QUERYTYPE *) PG_DETOAST_DATUM_COPY(PG_GETARG_DATUM(1));
-   float4 res;
+   float4      res;
+
+   res = calc_rank_cd(weights, txt, query, (PG_NARGS() == 3) ? PG_GETARG_DATUM(2) : DEF_NORM_METHOD);
 
-   res = calc_rank_cd( weights, txt, query, (PG_NARGS() == 3) ? PG_GETARG_DATUM(2) : DEF_NORM_METHOD);
-   
    PG_FREE_IF_COPY(txt, 0);
    PG_FREE_IF_COPY(query, 1);
 
@@ -791,7 +802,7 @@ get_covers(PG_FUNCTION_ARGS)
    text       *out;
    char       *cptr;
    DocRepresentation *doc;
-   int             olddwpos = 0;
+   int         olddwpos = 0;
    int         ncover = 1;
    Extention   ext;
 
@@ -833,7 +844,7 @@ get_covers(PG_FUNCTION_ARGS)
    }
    qsort((void *) dw, dlen, sizeof(DocWord), compareDocWord);
 
-   MemSet( &ext, 0, sizeof(Extention) );
+   MemSet(&ext, 0, sizeof(Extention));
    while (Cover(doc, rlen, query, &ext))
    {
        dwptr = dw + olddwpos;
index 99f84db7907fb95bac15754bac1f5a4d9b67788b..994ff267cab62cf17c4efa5bcb33b39a99d2f182 100644 (file)
 
 #include "header.h"
 
-extern int russian_UTF_8_stem(struct SN_env * z);
-static int r_tidy_up(struct SN_env * z);
-static int r_derivational(struct SN_env * z);
-static int r_noun(struct SN_env * z);
-static int r_verb(struct SN_env * z);
-static int r_reflexive(struct SN_env * z);
-static int r_adjectival(struct SN_env * z);
-static int r_adjective(struct SN_env * z);
-static int r_perfective_gerund(struct SN_env * z);
-static int r_R2(struct SN_env * z);
-static int r_mark_regions(struct SN_env * z);
-
-extern struct SN_env * russian_UTF_8_create_env(void);
+extern int russian_UTF_8_stem(struct SN_env * z);
+static int r_tidy_up(struct SN_env * z);
+static int r_derivational(struct SN_env * z);
+static int r_noun(struct SN_env * z);
+static int r_verb(struct SN_env * z);
+static int r_reflexive(struct SN_env * z);
+static int r_adjectival(struct SN_env * z);
+static int r_adjective(struct SN_env * z);
+static int r_perfective_gerund(struct SN_env * z);
+static int r_R2(struct SN_env * z);
+static int r_mark_regions(struct SN_env * z);
+
+extern struct SN_env *russian_UTF_8_create_env(void);
 extern void russian_UTF_8_close_env(struct SN_env * z);
 
-static symbol s_0_0[10] = { 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8, 0xD1, 0x81, 0xD1, 0x8C };
-static symbol s_0_1[12] = { 0xD1, 0x8B, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8, 0xD1, 0x81, 0xD1, 0x8C };
-static symbol s_0_2[12] = { 0xD0, 0xB8, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8, 0xD1, 0x81, 0xD1, 0x8C };
-static symbol s_0_3[2] = { 0xD0, 0xB2 };
-static symbol s_0_4[4] = { 0xD1, 0x8B, 0xD0, 0xB2 };
-static symbol s_0_5[4] = { 0xD0, 0xB8, 0xD0, 0xB2 };
-static symbol s_0_6[6] = { 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8 };
-static symbol s_0_7[8] = { 0xD1, 0x8B, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8 };
-static symbol s_0_8[8] = { 0xD0, 0xB8, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8 };
+static symbol s_0_0[10] = {0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8, 0xD1, 0x81, 0xD1, 0x8C};
+static symbol s_0_1[12] = {0xD1, 0x8B, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8, 0xD1, 0x81, 0xD1, 0x8C};
+static symbol s_0_2[12] = {0xD0, 0xB8, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8, 0xD1, 0x81, 0xD1, 0x8C};
+static symbol s_0_3[2] = {0xD0, 0xB2};
+static symbol s_0_4[4] = {0xD1, 0x8B, 0xD0, 0xB2};
+static symbol s_0_5[4] = {0xD0, 0xB8, 0xD0, 0xB2};
+static symbol s_0_6[6] = {0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8};
+static symbol s_0_7[8] = {0xD1, 0x8B, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8};
+static symbol s_0_8[8] = {0xD0, 0xB8, 0xD0, 0xB2, 0xD1, 0x88, 0xD0, 0xB8};
 
 static struct among a_0[9] =
 {
-/*  0 */ { 10, s_0_0, -1, 1, 0},
-/*  1 */ { 12, s_0_1, 0, 2, 0},
-/*  2 */ { 12, s_0_2, 0, 2, 0},
-/*  3 */ { 2, s_0_3, -1, 1, 0},
-/*  4 */ { 4, s_0_4, 3, 2, 0},
-/*  5 */ { 4, s_0_5, 3, 2, 0},
-/*  6 */ { 6, s_0_6, -1, 1, 0},
-/*  7 */ { 8, s_0_7, 6, 2, 0},
-/*  8 */ { 8, s_0_8, 6, 2, 0}
+    /*  0 */ {10, s_0_0, -1, 1, 0},
+    /*  1 */ {12, s_0_1, 0, 2, 0},
+    /*  2 */ {12, s_0_2, 0, 2, 0},
+    /*  3 */ {2, s_0_3, -1, 1, 0},
+    /*  4 */ {4, s_0_4, 3, 2, 0},
+    /*  5 */ {4, s_0_5, 3, 2, 0},
+    /*  6 */ {6, s_0_6, -1, 1, 0},
+    /*  7 */ {8, s_0_7, 6, 2, 0},
+    /*  8 */ {8, s_0_8, 6, 2, 0}
 };
 
-static symbol s_1_0[6] = { 0xD0, 0xB5, 0xD0, 0xBC, 0xD1, 0x83 };
-static symbol s_1_1[6] = { 0xD0, 0xBE, 0xD0, 0xBC, 0xD1, 0x83 };
-static symbol s_1_2[4] = { 0xD1, 0x8B, 0xD1, 0x85 };
-static symbol s_1_3[4] = { 0xD0, 0xB8, 0xD1, 0x85 };
-static symbol s_1_4[4] = { 0xD1, 0x83, 0xD1, 0x8E };
-static symbol s_1_5[4] = { 0xD1, 0x8E, 0xD1, 0x8E };
-static symbol s_1_6[4] = { 0xD0, 0xB5, 0xD1, 0x8E };
-static symbol s_1_7[4] = { 0xD0, 0xBE, 0xD1, 0x8E };
-static symbol s_1_8[4] = { 0xD1, 0x8F, 0xD1, 0x8F };
-static symbol s_1_9[4] = { 0xD0, 0xB0, 0xD1, 0x8F };
-static symbol s_1_10[4] = { 0xD1, 0x8B, 0xD0, 0xB5 };
-static symbol s_1_11[4] = { 0xD0, 0xB5, 0xD0, 0xB5 };
-static symbol s_1_12[4] = { 0xD0, 0xB8, 0xD0, 0xB5 };
-static symbol s_1_13[4] = { 0xD0, 0xBE, 0xD0, 0xB5 };
-static symbol s_1_14[6] = { 0xD1, 0x8B, 0xD0, 0xBC, 0xD0, 0xB8 };
-static symbol s_1_15[6] = { 0xD0, 0xB8, 0xD0, 0xBC, 0xD0, 0xB8 };
-static symbol s_1_16[4] = { 0xD1, 0x8B, 0xD0, 0xB9 };
-static symbol s_1_17[4] = { 0xD0, 0xB5, 0xD0, 0xB9 };
-static symbol s_1_18[4] = { 0xD0, 0xB8, 0xD0, 0xB9 };
-static symbol s_1_19[4] = { 0xD0, 0xBE, 0xD0, 0xB9 };
-static symbol s_1_20[4] = { 0xD1, 0x8B, 0xD0, 0xBC };
-static symbol s_1_21[4] = { 0xD0, 0xB5, 0xD0, 0xBC };
-static symbol s_1_22[4] = { 0xD0, 0xB8, 0xD0, 0xBC };
-static symbol s_1_23[4] = { 0xD0, 0xBE, 0xD0, 0xBC };
-static symbol s_1_24[6] = { 0xD0, 0xB5, 0xD0, 0xB3, 0xD0, 0xBE };
-static symbol s_1_25[6] = { 0xD0, 0xBE, 0xD0, 0xB3, 0xD0, 0xBE };
+static symbol s_1_0[6] = {0xD0, 0xB5, 0xD0, 0xBC, 0xD1, 0x83};
+static symbol s_1_1[6] = {0xD0, 0xBE, 0xD0, 0xBC, 0xD1, 0x83};
+static symbol s_1_2[4] = {0xD1, 0x8B, 0xD1, 0x85};
+static symbol s_1_3[4] = {0xD0, 0xB8, 0xD1, 0x85};
+static symbol s_1_4[4] = {0xD1, 0x83, 0xD1, 0x8E};
+static symbol s_1_5[4] = {0xD1, 0x8E, 0xD1, 0x8E};
+static symbol s_1_6[4] = {0xD0, 0xB5, 0xD1, 0x8E};
+static symbol s_1_7[4] = {0xD0, 0xBE, 0xD1, 0x8E};
+static symbol s_1_8[4] = {0xD1, 0x8F, 0xD1, 0x8F};
+static symbol s_1_9[4] = {0xD0, 0xB0, 0xD1, 0x8F};
+static symbol s_1_10[4] = {0xD1, 0x8B, 0xD0, 0xB5};
+static symbol s_1_11[4] = {0xD0, 0xB5, 0xD0, 0xB5};
+static symbol s_1_12[4] = {0xD0, 0xB8, 0xD0, 0xB5};
+static symbol s_1_13[4] = {0xD0, 0xBE, 0xD0, 0xB5};
+static symbol s_1_14[6] = {0xD1, 0x8B, 0xD0, 0xBC, 0xD0, 0xB8};
+static symbol s_1_15[6] = {0xD0, 0xB8, 0xD0, 0xBC, 0xD0, 0xB8};
+static symbol s_1_16[4] = {0xD1, 0x8B, 0xD0, 0xB9};
+static symbol s_1_17[4] = {0xD0, 0xB5, 0xD0, 0xB9};
+static symbol s_1_18[4] = {0xD0, 0xB8, 0xD0, 0xB9};
+static symbol s_1_19[4] = {0xD0, 0xBE, 0xD0, 0xB9};
+static symbol s_1_20[4] = {0xD1, 0x8B, 0xD0, 0xBC};
+static symbol s_1_21[4] = {0xD0, 0xB5, 0xD0, 0xBC};
+static symbol s_1_22[4] = {0xD0, 0xB8, 0xD0, 0xBC};
+static symbol s_1_23[4] = {0xD0, 0xBE, 0xD0, 0xBC};
+static symbol s_1_24[6] = {0xD0, 0xB5, 0xD0, 0xB3, 0xD0, 0xBE};
+static symbol s_1_25[6] = {0xD0, 0xBE, 0xD0, 0xB3, 0xD0, 0xBE};
 
 static struct among a_1[26] =
 {
-/*  0 */ { 6, s_1_0, -1, 1, 0},
-/*  1 */ { 6, s_1_1, -1, 1, 0},
-/*  2 */ { 4, s_1_2, -1, 1, 0},
-/*  3 */ { 4, s_1_3, -1, 1, 0},
-/*  4 */ { 4, s_1_4, -1, 1, 0},
-/*  5 */ { 4, s_1_5, -1, 1, 0},
-/*  6 */ { 4, s_1_6, -1, 1, 0},
-/*  7 */ { 4, s_1_7, -1, 1, 0},
-/*  8 */ { 4, s_1_8, -1, 1, 0},
-/*  9 */ { 4, s_1_9, -1, 1, 0},
-/* 10 */ { 4, s_1_10, -1, 1, 0},
-/* 11 */ { 4, s_1_11, -1, 1, 0},
-/* 12 */ { 4, s_1_12, -1, 1, 0},
-/* 13 */ { 4, s_1_13, -1, 1, 0},
-/* 14 */ { 6, s_1_14, -1, 1, 0},
-/* 15 */ { 6, s_1_15, -1, 1, 0},
-/* 16 */ { 4, s_1_16, -1, 1, 0},
-/* 17 */ { 4, s_1_17, -1, 1, 0},
-/* 18 */ { 4, s_1_18, -1, 1, 0},
-/* 19 */ { 4, s_1_19, -1, 1, 0},
-/* 20 */ { 4, s_1_20, -1, 1, 0},
-/* 21 */ { 4, s_1_21, -1, 1, 0},
-/* 22 */ { 4, s_1_22, -1, 1, 0},
-/* 23 */ { 4, s_1_23, -1, 1, 0},
-/* 24 */ { 6, s_1_24, -1, 1, 0},
-/* 25 */ { 6, s_1_25, -1, 1, 0}
+    /*  0 */ {6, s_1_0, -1, 1, 0},
+    /*  1 */ {6, s_1_1, -1, 1, 0},
+    /*  2 */ {4, s_1_2, -1, 1, 0},
+    /*  3 */ {4, s_1_3, -1, 1, 0},
+    /*  4 */ {4, s_1_4, -1, 1, 0},
+    /*  5 */ {4, s_1_5, -1, 1, 0},
+    /*  6 */ {4, s_1_6, -1, 1, 0},
+    /*  7 */ {4, s_1_7, -1, 1, 0},
+    /*  8 */ {4, s_1_8, -1, 1, 0},
+    /*  9 */ {4, s_1_9, -1, 1, 0},
+    /* 10 */ {4, s_1_10, -1, 1, 0},
+    /* 11 */ {4, s_1_11, -1, 1, 0},
+    /* 12 */ {4, s_1_12, -1, 1, 0},
+    /* 13 */ {4, s_1_13, -1, 1, 0},
+    /* 14 */ {6, s_1_14, -1, 1, 0},
+    /* 15 */ {6, s_1_15, -1, 1, 0},
+    /* 16 */ {4, s_1_16, -1, 1, 0},
+    /* 17 */ {4, s_1_17, -1, 1, 0},
+    /* 18 */ {4, s_1_18, -1, 1, 0},
+    /* 19 */ {4, s_1_19, -1, 1, 0},
+    /* 20 */ {4, s_1_20, -1, 1, 0},
+    /* 21 */ {4, s_1_21, -1, 1, 0},
+    /* 22 */ {4, s_1_22, -1, 1, 0},
+    /* 23 */ {4, s_1_23, -1, 1, 0},
+    /* 24 */ {6, s_1_24, -1, 1, 0},
+    /* 25 */ {6, s_1_25, -1, 1, 0}
 };
 
-static symbol s_2_0[4] = { 0xD0, 0xB2, 0xD1, 0x88 };
-static symbol s_2_1[6] = { 0xD1, 0x8B, 0xD0, 0xB2, 0xD1, 0x88 };
-static symbol s_2_2[6] = { 0xD0, 0xB8, 0xD0, 0xB2, 0xD1, 0x88 };
-static symbol s_2_3[2] = { 0xD1, 0x89 };
-static symbol s_2_4[4] = { 0xD1, 0x8E, 0xD1, 0x89 };
-static symbol s_2_5[6] = { 0xD1, 0x83, 0xD1, 0x8E, 0xD1, 0x89 };
-static symbol s_2_6[4] = { 0xD0, 0xB5, 0xD0, 0xBC };
-static symbol s_2_7[4] = { 0xD0, 0xBD, 0xD0, 0xBD };
+static symbol s_2_0[4] = {0xD0, 0xB2, 0xD1, 0x88};
+static symbol s_2_1[6] = {0xD1, 0x8B, 0xD0, 0xB2, 0xD1, 0x88};
+static symbol s_2_2[6] = {0xD0, 0xB8, 0xD0, 0xB2, 0xD1, 0x88};
+static symbol s_2_3[2] = {0xD1, 0x89};
+static symbol s_2_4[4] = {0xD1, 0x8E, 0xD1, 0x89};
+static symbol s_2_5[6] = {0xD1, 0x83, 0xD1, 0x8E, 0xD1, 0x89};
+static symbol s_2_6[4] = {0xD0, 0xB5, 0xD0, 0xBC};
+static symbol s_2_7[4] = {0xD0, 0xBD, 0xD0, 0xBD};
 
 static struct among a_2[8] =
 {
-/*  0 */ { 4, s_2_0, -1, 1, 0},
-/*  1 */ { 6, s_2_1, 0, 2, 0},
-/*  2 */ { 6, s_2_2, 0, 2, 0},
-/*  3 */ { 2, s_2_3, -1, 1, 0},
-/*  4 */ { 4, s_2_4, 3, 1, 0},
-/*  5 */ { 6, s_2_5, 4, 2, 0},
-/*  6 */ { 4, s_2_6, -1, 1, 0},
-/*  7 */ { 4, s_2_7, -1, 1, 0}
+    /*  0 */ {4, s_2_0, -1, 1, 0},
+    /*  1 */ {6, s_2_1, 0, 2, 0},
+    /*  2 */ {6, s_2_2, 0, 2, 0},
+    /*  3 */ {2, s_2_3, -1, 1, 0},
+    /*  4 */ {4, s_2_4, 3, 1, 0},
+    /*  5 */ {6, s_2_5, 4, 2, 0},
+    /*  6 */ {4, s_2_6, -1, 1, 0},
+    /*  7 */ {4, s_2_7, -1, 1, 0}
 };
 
-static symbol s_3_0[4] = { 0xD1, 0x81, 0xD1, 0x8C };
-static symbol s_3_1[4] = { 0xD1, 0x81, 0xD1, 0x8F };
+static symbol s_3_0[4] = {0xD1, 0x81, 0xD1, 0x8C};
+static symbol s_3_1[4] = {0xD1, 0x81, 0xD1, 0x8F};
 
 static struct among a_3[2] =
 {
-/*  0 */ { 4, s_3_0, -1, 1, 0},
-/*  1 */ { 4, s_3_1, -1, 1, 0}
+    /*  0 */ {4, s_3_0, -1, 1, 0},
+    /*  1 */ {4, s_3_1, -1, 1, 0}
 };
 
-static symbol s_4_0[4] = { 0xD1, 0x8B, 0xD1, 0x82 };
-static symbol s_4_1[4] = { 0xD1, 0x8E, 0xD1, 0x82 };
-static symbol s_4_2[6] = { 0xD1, 0x83, 0xD1, 0x8E, 0xD1, 0x82 };
-static symbol s_4_3[4] = { 0xD1, 0x8F, 0xD1, 0x82 };
-static symbol s_4_4[4] = { 0xD0, 0xB5, 0xD1, 0x82 };
-static symbol s_4_5[6] = { 0xD1, 0x83, 0xD0, 0xB5, 0xD1, 0x82 };
-static symbol s_4_6[4] = { 0xD0, 0xB8, 0xD1, 0x82 };
-static symbol s_4_7[4] = { 0xD0, 0xBD, 0xD1, 0x8B };
-static symbol s_4_8[6] = { 0xD0, 0xB5, 0xD0, 0xBD, 0xD1, 0x8B };
-static symbol s_4_9[4] = { 0xD1, 0x82, 0xD1, 0x8C };
-static symbol s_4_10[6] = { 0xD1, 0x8B, 0xD1, 0x82, 0xD1, 0x8C };
-static symbol s_4_11[6] = { 0xD0, 0xB8, 0xD1, 0x82, 0xD1, 0x8C };
-static symbol s_4_12[6] = { 0xD0, 0xB5, 0xD1, 0x88, 0xD1, 0x8C };
-static symbol s_4_13[6] = { 0xD0, 0xB8, 0xD1, 0x88, 0xD1, 0x8C };
-static symbol s_4_14[2] = { 0xD1, 0x8E };
-static symbol s_4_15[4] = { 0xD1, 0x83, 0xD1, 0x8E };
-static symbol s_4_16[4] = { 0xD0, 0xBB, 0xD0, 0xB0 };
-static symbol s_4_17[6] = { 0xD1, 0x8B, 0xD0, 0xBB, 0xD0, 0xB0 };
-static symbol s_4_18[6] = { 0xD0, 0xB8, 0xD0, 0xBB, 0xD0, 0xB0 };
-static symbol s_4_19[4] = { 0xD0, 0xBD, 0xD0, 0xB0 };
-static symbol s_4_20[6] = { 0xD0, 0xB5, 0xD0, 0xBD, 0xD0, 0xB0 };
-static symbol s_4_21[6] = { 0xD0, 0xB5, 0xD1, 0x82, 0xD0, 0xB5 };
-static symbol s_4_22[6] = { 0xD0, 0xB8, 0xD1, 0x82, 0xD0, 0xB5 };
-static symbol s_4_23[6] = { 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5 };
-static symbol s_4_24[8] = { 0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5 };
-static symbol s_4_25[8] = { 0xD0, 0xB5, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5 };
-static symbol s_4_26[4] = { 0xD0, 0xBB, 0xD0, 0xB8 };
-static symbol s_4_27[6] = { 0xD1, 0x8B, 0xD0, 0xBB, 0xD0, 0xB8 };
-static symbol s_4_28[6] = { 0xD0, 0xB8, 0xD0, 0xBB, 0xD0, 0xB8 };
-static symbol s_4_29[2] = { 0xD0, 0xB9 };
-static symbol s_4_30[4] = { 0xD1, 0x83, 0xD0, 0xB9 };
-static symbol s_4_31[4] = { 0xD0, 0xB5, 0xD0, 0xB9 };
-static symbol s_4_32[2] = { 0xD0, 0xBB };
-static symbol s_4_33[4] = { 0xD1, 0x8B, 0xD0, 0xBB };
-static symbol s_4_34[4] = { 0xD0, 0xB8, 0xD0, 0xBB };
-static symbol s_4_35[4] = { 0xD1, 0x8B, 0xD0, 0xBC };
-static symbol s_4_36[4] = { 0xD0, 0xB5, 0xD0, 0xBC };
-static symbol s_4_37[4] = { 0xD0, 0xB8, 0xD0, 0xBC };
-static symbol s_4_38[2] = { 0xD0, 0xBD };
-static symbol s_4_39[4] = { 0xD0, 0xB5, 0xD0, 0xBD };
-static symbol s_4_40[4] = { 0xD0, 0xBB, 0xD0, 0xBE };
-static symbol s_4_41[6] = { 0xD1, 0x8B, 0xD0, 0xBB, 0xD0, 0xBE };
-static symbol s_4_42[6] = { 0xD0, 0xB8, 0xD0, 0xBB, 0xD0, 0xBE };
-static symbol s_4_43[4] = { 0xD0, 0xBD, 0xD0, 0xBE };
-static symbol s_4_44[6] = { 0xD0, 0xB5, 0xD0, 0xBD, 0xD0, 0xBE };
-static symbol s_4_45[6] = { 0xD0, 0xBD, 0xD0, 0xBD, 0xD0, 0xBE };
+static symbol s_4_0[4] = {0xD1, 0x8B, 0xD1, 0x82};
+static symbol s_4_1[4] = {0xD1, 0x8E, 0xD1, 0x82};
+static symbol s_4_2[6] = {0xD1, 0x83, 0xD1, 0x8E, 0xD1, 0x82};
+static symbol s_4_3[4] = {0xD1, 0x8F, 0xD1, 0x82};
+static symbol s_4_4[4] = {0xD0, 0xB5, 0xD1, 0x82};
+static symbol s_4_5[6] = {0xD1, 0x83, 0xD0, 0xB5, 0xD1, 0x82};
+static symbol s_4_6[4] = {0xD0, 0xB8, 0xD1, 0x82};
+static symbol s_4_7[4] = {0xD0, 0xBD, 0xD1, 0x8B};
+static symbol s_4_8[6] = {0xD0, 0xB5, 0xD0, 0xBD, 0xD1, 0x8B};
+static symbol s_4_9[4] = {0xD1, 0x82, 0xD1, 0x8C};
+static symbol s_4_10[6] = {0xD1, 0x8B, 0xD1, 0x82, 0xD1, 0x8C};
+static symbol s_4_11[6] = {0xD0, 0xB8, 0xD1, 0x82, 0xD1, 0x8C};
+static symbol s_4_12[6] = {0xD0, 0xB5, 0xD1, 0x88, 0xD1, 0x8C};
+static symbol s_4_13[6] = {0xD0, 0xB8, 0xD1, 0x88, 0xD1, 0x8C};
+static symbol s_4_14[2] = {0xD1, 0x8E};
+static symbol s_4_15[4] = {0xD1, 0x83, 0xD1, 0x8E};
+static symbol s_4_16[4] = {0xD0, 0xBB, 0xD0, 0xB0};
+static symbol s_4_17[6] = {0xD1, 0x8B, 0xD0, 0xBB, 0xD0, 0xB0};
+static symbol s_4_18[6] = {0xD0, 0xB8, 0xD0, 0xBB, 0xD0, 0xB0};
+static symbol s_4_19[4] = {0xD0, 0xBD, 0xD0, 0xB0};
+static symbol s_4_20[6] = {0xD0, 0xB5, 0xD0, 0xBD, 0xD0, 0xB0};
+static symbol s_4_21[6] = {0xD0, 0xB5, 0xD1, 0x82, 0xD0, 0xB5};
+static symbol s_4_22[6] = {0xD0, 0xB8, 0xD1, 0x82, 0xD0, 0xB5};
+static symbol s_4_23[6] = {0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5};
+static symbol s_4_24[8] = {0xD1, 0x83, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5};
+static symbol s_4_25[8] = {0xD0, 0xB5, 0xD0, 0xB9, 0xD1, 0x82, 0xD0, 0xB5};
+static symbol s_4_26[4] = {0xD0, 0xBB, 0xD0, 0xB8};
+static symbol s_4_27[6] = {0xD1, 0x8B, 0xD0, 0xBB, 0xD0, 0xB8};
+static symbol s_4_28[6] = {0xD0, 0xB8, 0xD0, 0xBB, 0xD0, 0xB8};
+static symbol s_4_29[2] = {0xD0, 0xB9};
+static symbol s_4_30[4] = {0xD1, 0x83, 0xD0, 0xB9};
+static symbol s_4_31[4] = {0xD0, 0xB5, 0xD0, 0xB9};
+static symbol s_4_32[2] = {0xD0, 0xBB};
+static symbol s_4_33[4] = {0xD1, 0x8B, 0xD0, 0xBB};
+static symbol s_4_34[4] = {0xD0, 0xB8, 0xD0, 0xBB};
+static symbol s_4_35[4] = {0xD1, 0x8B, 0xD0, 0xBC};
+static symbol s_4_36[4] = {0xD0, 0xB5, 0xD0, 0xBC};
+static symbol s_4_37[4] = {0xD0, 0xB8, 0xD0, 0xBC};
+static symbol s_4_38[2] = {0xD0, 0xBD};
+static symbol s_4_39[4] = {0xD0, 0xB5, 0xD0, 0xBD};
+static symbol s_4_40[4] = {0xD0, 0xBB, 0xD0, 0xBE};
+static symbol s_4_41[6] = {0xD1, 0x8B, 0xD0, 0xBB, 0xD0, 0xBE};
+static symbol s_4_42[6] = {0xD0, 0xB8, 0xD0, 0xBB, 0xD0, 0xBE};
+static symbol s_4_43[4] = {0xD0, 0xBD, 0xD0, 0xBE};
+static symbol s_4_44[6] = {0xD0, 0xB5, 0xD0, 0xBD, 0xD0, 0xBE};
+static symbol s_4_45[6] = {0xD0, 0xBD, 0xD0, 0xBD, 0xD0, 0xBE};
 
 static struct among a_4[46] =
 {
-/*  0 */ { 4, s_4_0, -1, 2, 0},
-/*  1 */ { 4, s_4_1, -1, 1, 0},
-/*  2 */ { 6, s_4_2, 1, 2, 0},
-/*  3 */ { 4, s_4_3, -1, 2, 0},
-/*  4 */ { 4, s_4_4, -1, 1, 0},
-/*  5 */ { 6, s_4_5, 4, 2, 0},
-/*  6 */ { 4, s_4_6, -1, 2, 0},
-/*  7 */ { 4, s_4_7, -1, 1, 0},
-/*  8 */ { 6, s_4_8, 7, 2, 0},
-/*  9 */ { 4, s_4_9, -1, 1, 0},
-/* 10 */ { 6, s_4_10, 9, 2, 0},
-/* 11 */ { 6, s_4_11, 9, 2, 0},
-/* 12 */ { 6, s_4_12, -1, 1, 0},
-/* 13 */ { 6, s_4_13, -1, 2, 0},
-/* 14 */ { 2, s_4_14, -1, 2, 0},
-/* 15 */ { 4, s_4_15, 14, 2, 0},
-/* 16 */ { 4, s_4_16, -1, 1, 0},
-/* 17 */ { 6, s_4_17, 16, 2, 0},
-/* 18 */ { 6, s_4_18, 16, 2, 0},
-/* 19 */ { 4, s_4_19, -1, 1, 0},
-/* 20 */ { 6, s_4_20, 19, 2, 0},
-/* 21 */ { 6, s_4_21, -1, 1, 0},
-/* 22 */ { 6, s_4_22, -1, 2, 0},
-/* 23 */ { 6, s_4_23, -1, 1, 0},
-/* 24 */ { 8, s_4_24, 23, 2, 0},
-/* 25 */ { 8, s_4_25, 23, 2, 0},
-/* 26 */ { 4, s_4_26, -1, 1, 0},
-/* 27 */ { 6, s_4_27, 26, 2, 0},
-/* 28 */ { 6, s_4_28, 26, 2, 0},
-/* 29 */ { 2, s_4_29, -1, 1, 0},
-/* 30 */ { 4, s_4_30, 29, 2, 0},
-/* 31 */ { 4, s_4_31, 29, 2, 0},
-/* 32 */ { 2, s_4_32, -1, 1, 0},
-/* 33 */ { 4, s_4_33, 32, 2, 0},
-/* 34 */ { 4, s_4_34, 32, 2, 0},
-/* 35 */ { 4, s_4_35, -1, 2, 0},
-/* 36 */ { 4, s_4_36, -1, 1, 0},
-/* 37 */ { 4, s_4_37, -1, 2, 0},
-/* 38 */ { 2, s_4_38, -1, 1, 0},
-/* 39 */ { 4, s_4_39, 38, 2, 0},
-/* 40 */ { 4, s_4_40, -1, 1, 0},
-/* 41 */ { 6, s_4_41, 40, 2, 0},
-/* 42 */ { 6, s_4_42, 40, 2, 0},
-/* 43 */ { 4, s_4_43, -1, 1, 0},
-/* 44 */ { 6, s_4_44, 43, 2, 0},
-/* 45 */ { 6, s_4_45, 43, 1, 0}
+    /*  0 */ {4, s_4_0, -1, 2, 0},
+    /*  1 */ {4, s_4_1, -1, 1, 0},
+    /*  2 */ {6, s_4_2, 1, 2, 0},
+    /*  3 */ {4, s_4_3, -1, 2, 0},
+    /*  4 */ {4, s_4_4, -1, 1, 0},
+    /*  5 */ {6, s_4_5, 4, 2, 0},
+    /*  6 */ {4, s_4_6, -1, 2, 0},
+    /*  7 */ {4, s_4_7, -1, 1, 0},
+    /*  8 */ {6, s_4_8, 7, 2, 0},
+    /*  9 */ {4, s_4_9, -1, 1, 0},
+    /* 10 */ {6, s_4_10, 9, 2, 0},
+    /* 11 */ {6, s_4_11, 9, 2, 0},
+    /* 12 */ {6, s_4_12, -1, 1, 0},
+    /* 13 */ {6, s_4_13, -1, 2, 0},
+    /* 14 */ {2, s_4_14, -1, 2, 0},
+    /* 15 */ {4, s_4_15, 14, 2, 0},
+    /* 16 */ {4, s_4_16, -1, 1, 0},
+    /* 17 */ {6, s_4_17, 16, 2, 0},
+    /* 18 */ {6, s_4_18, 16, 2, 0},
+    /* 19 */ {4, s_4_19, -1, 1, 0},
+    /* 20 */ {6, s_4_20, 19, 2, 0},
+    /* 21 */ {6, s_4_21, -1, 1, 0},
+    /* 22 */ {6, s_4_22, -1, 2, 0},
+    /* 23 */ {6, s_4_23, -1, 1, 0},
+    /* 24 */ {8, s_4_24, 23, 2, 0},
+    /* 25 */ {8, s_4_25, 23, 2, 0},
+    /* 26 */ {4, s_4_26, -1, 1, 0},
+    /* 27 */ {6, s_4_27, 26, 2, 0},
+    /* 28 */ {6, s_4_28, 26, 2, 0},
+    /* 29 */ {2, s_4_29, -1, 1, 0},
+    /* 30 */ {4, s_4_30, 29, 2, 0},
+    /* 31 */ {4, s_4_31, 29, 2, 0},
+    /* 32 */ {2, s_4_32, -1, 1, 0},
+    /* 33 */ {4, s_4_33, 32, 2, 0},
+    /* 34 */ {4, s_4_34, 32, 2, 0},
+    /* 35 */ {4, s_4_35, -1, 2, 0},
+    /* 36 */ {4, s_4_36, -1, 1, 0},
+    /* 37 */ {4, s_4_37, -1, 2, 0},
+    /* 38 */ {2, s_4_38, -1, 1, 0},
+    /* 39 */ {4, s_4_39, 38, 2, 0},
+    /* 40 */ {4, s_4_40, -1, 1, 0},
+    /* 41 */ {6, s_4_41, 40, 2, 0},
+    /* 42 */ {6, s_4_42, 40, 2, 0},
+    /* 43 */ {4, s_4_43, -1, 1, 0},
+    /* 44 */ {6, s_4_44, 43, 2, 0},
+    /* 45 */ {6, s_4_45, 43, 1, 0}
 };
 
-static symbol s_5_0[2] = { 0xD1, 0x83 };
-static symbol s_5_1[4] = { 0xD1, 0x8F, 0xD1, 0x85 };
-static symbol s_5_2[6] = { 0xD0, 0xB8, 0xD1, 0x8F, 0xD1, 0x85 };
-static symbol s_5_3[4] = { 0xD0, 0xB0, 0xD1, 0x85 };
-static symbol s_5_4[2] = { 0xD1, 0x8B };
-static symbol s_5_5[2] = { 0xD1, 0x8C };
-static symbol s_5_6[2] = { 0xD1, 0x8E };
-static symbol s_5_7[4] = { 0xD1, 0x8C, 0xD1, 0x8E };
-static symbol s_5_8[4] = { 0xD0, 0xB8, 0xD1, 0x8E };
-static symbol s_5_9[2] = { 0xD1, 0x8F };
-static symbol s_5_10[4] = { 0xD1, 0x8C, 0xD1, 0x8F };
-static symbol s_5_11[4] = { 0xD0, 0xB8, 0xD1, 0x8F };
-static symbol s_5_12[2] = { 0xD0, 0xB0 };
-static symbol s_5_13[4] = { 0xD0, 0xB5, 0xD0, 0xB2 };
-static symbol s_5_14[4] = { 0xD0, 0xBE, 0xD0, 0xB2 };
-static symbol s_5_15[2] = { 0xD0, 0xB5 };
-static symbol s_5_16[4] = { 0xD1, 0x8C, 0xD0, 0xB5 };
-static symbol s_5_17[4] = { 0xD0, 0xB8, 0xD0, 0xB5 };
-static symbol s_5_18[2] = { 0xD0, 0xB8 };
-static symbol s_5_19[4] = { 0xD0, 0xB5, 0xD0, 0xB8 };
-static symbol s_5_20[4] = { 0xD0, 0xB8, 0xD0, 0xB8 };
-static symbol s_5_21[6] = { 0xD1, 0x8F, 0xD0, 0xBC, 0xD0, 0xB8 };
-static symbol s_5_22[8] = { 0xD0, 0xB8, 0xD1, 0x8F, 0xD0, 0xBC, 0xD0, 0xB8 };
-static symbol s_5_23[6] = { 0xD0, 0xB0, 0xD0, 0xBC, 0xD0, 0xB8 };
-static symbol s_5_24[2] = { 0xD0, 0xB9 };
-static symbol s_5_25[4] = { 0xD0, 0xB5, 0xD0, 0xB9 };
-static symbol s_5_26[6] = { 0xD0, 0xB8, 0xD0, 0xB5, 0xD0, 0xB9 };
-static symbol s_5_27[4] = { 0xD0, 0xB8, 0xD0, 0xB9 };
-static symbol s_5_28[4] = { 0xD0, 0xBE, 0xD0, 0xB9 };
-static symbol s_5_29[4] = { 0xD1, 0x8F, 0xD0, 0xBC };
-static symbol s_5_30[6] = { 0xD0, 0xB8, 0xD1, 0x8F, 0xD0, 0xBC };
-static symbol s_5_31[4] = { 0xD0, 0xB0, 0xD0, 0xBC };
-static symbol s_5_32[4] = { 0xD0, 0xB5, 0xD0, 0xBC };
-static symbol s_5_33[6] = { 0xD0, 0xB8, 0xD0, 0xB5, 0xD0, 0xBC };
-static symbol s_5_34[4] = { 0xD0, 0xBE, 0xD0, 0xBC };
-static symbol s_5_35[2] = { 0xD0, 0xBE };
+static symbol s_5_0[2] = {0xD1, 0x83};
+static symbol s_5_1[4] = {0xD1, 0x8F, 0xD1, 0x85};
+static symbol s_5_2[6] = {0xD0, 0xB8, 0xD1, 0x8F, 0xD1, 0x85};
+static symbol s_5_3[4] = {0xD0, 0xB0, 0xD1, 0x85};
+static symbol s_5_4[2] = {0xD1, 0x8B};
+static symbol s_5_5[2] = {0xD1, 0x8C};
+static symbol s_5_6[2] = {0xD1, 0x8E};
+static symbol s_5_7[4] = {0xD1, 0x8C, 0xD1, 0x8E};
+static symbol s_5_8[4] = {0xD0, 0xB8, 0xD1, 0x8E};
+static symbol s_5_9[2] = {0xD1, 0x8F};
+static symbol s_5_10[4] = {0xD1, 0x8C, 0xD1, 0x8F};
+static symbol s_5_11[4] = {0xD0, 0xB8, 0xD1, 0x8F};
+static symbol s_5_12[2] = {0xD0, 0xB0};
+static symbol s_5_13[4] = {0xD0, 0xB5, 0xD0, 0xB2};
+static symbol s_5_14[4] = {0xD0, 0xBE, 0xD0, 0xB2};
+static symbol s_5_15[2] = {0xD0, 0xB5};
+static symbol s_5_16[4] = {0xD1, 0x8C, 0xD0, 0xB5};
+static symbol s_5_17[4] = {0xD0, 0xB8, 0xD0, 0xB5};
+static symbol s_5_18[2] = {0xD0, 0xB8};
+static symbol s_5_19[4] = {0xD0, 0xB5, 0xD0, 0xB8};
+static symbol s_5_20[4] = {0xD0, 0xB8, 0xD0, 0xB8};
+static symbol s_5_21[6] = {0xD1, 0x8F, 0xD0, 0xBC, 0xD0, 0xB8};
+static symbol s_5_22[8] = {0xD0, 0xB8, 0xD1, 0x8F, 0xD0, 0xBC, 0xD0, 0xB8};
+static symbol s_5_23[6] = {0xD0, 0xB0, 0xD0, 0xBC, 0xD0, 0xB8};
+static symbol s_5_24[2] = {0xD0, 0xB9};
+static symbol s_5_25[4] = {0xD0, 0xB5, 0xD0, 0xB9};
+static symbol s_5_26[6] = {0xD0, 0xB8, 0xD0, 0xB5, 0xD0, 0xB9};
+static symbol s_5_27[4] = {0xD0, 0xB8, 0xD0, 0xB9};
+static symbol s_5_28[4] = {0xD0, 0xBE, 0xD0, 0xB9};
+static symbol s_5_29[4] = {0xD1, 0x8F, 0xD0, 0xBC};
+static symbol s_5_30[6] = {0xD0, 0xB8, 0xD1, 0x8F, 0xD0, 0xBC};
+static symbol s_5_31[4] = {0xD0, 0xB0, 0xD0, 0xBC};
+static symbol s_5_32[4] = {0xD0, 0xB5, 0xD0, 0xBC};
+static symbol s_5_33[6] = {0xD0, 0xB8, 0xD0, 0xB5, 0xD0, 0xBC};
+static symbol s_5_34[4] = {0xD0, 0xBE, 0xD0, 0xBC};
+static symbol s_5_35[2] = {0xD0, 0xBE};
 
 static struct among a_5[36] =
 {
-/*  0 */ { 2, s_5_0, -1, 1, 0},
-/*  1 */ { 4, s_5_1, -1, 1, 0},
-/*  2 */ { 6, s_5_2, 1, 1, 0},
-/*  3 */ { 4, s_5_3, -1, 1, 0},
-/*  4 */ { 2, s_5_4, -1, 1, 0},
-/*  5 */ { 2, s_5_5, -1, 1, 0},
-/*  6 */ { 2, s_5_6, -1, 1, 0},
-/*  7 */ { 4, s_5_7, 6, 1, 0},
-/*  8 */ { 4, s_5_8, 6, 1, 0},
-/*  9 */ { 2, s_5_9, -1, 1, 0},
-/* 10 */ { 4, s_5_10, 9, 1, 0},
-/* 11 */ { 4, s_5_11, 9, 1, 0},
-/* 12 */ { 2, s_5_12, -1, 1, 0},
-/* 13 */ { 4, s_5_13, -1, 1, 0},
-/* 14 */ { 4, s_5_14, -1, 1, 0},
-/* 15 */ { 2, s_5_15, -1, 1, 0},
-/* 16 */ { 4, s_5_16, 15, 1, 0},
-/* 17 */ { 4, s_5_17, 15, 1, 0},
-/* 18 */ { 2, s_5_18, -1, 1, 0},
-/* 19 */ { 4, s_5_19, 18, 1, 0},
-/* 20 */ { 4, s_5_20, 18, 1, 0},
-/* 21 */ { 6, s_5_21, 18, 1, 0},
-/* 22 */ { 8, s_5_22, 21, 1, 0},
-/* 23 */ { 6, s_5_23, 18, 1, 0},
-/* 24 */ { 2, s_5_24, -1, 1, 0},
-/* 25 */ { 4, s_5_25, 24, 1, 0},
-/* 26 */ { 6, s_5_26, 25, 1, 0},
-/* 27 */ { 4, s_5_27, 24, 1, 0},
-/* 28 */ { 4, s_5_28, 24, 1, 0},
-/* 29 */ { 4, s_5_29, -1, 1, 0},
-/* 30 */ { 6, s_5_30, 29, 1, 0},
-/* 31 */ { 4, s_5_31, -1, 1, 0},
-/* 32 */ { 4, s_5_32, -1, 1, 0},
-/* 33 */ { 6, s_5_33, 32, 1, 0},
-/* 34 */ { 4, s_5_34, -1, 1, 0},
-/* 35 */ { 2, s_5_35, -1, 1, 0}
+    /*  0 */ {2, s_5_0, -1, 1, 0},
+    /*  1 */ {4, s_5_1, -1, 1, 0},
+    /*  2 */ {6, s_5_2, 1, 1, 0},
+    /*  3 */ {4, s_5_3, -1, 1, 0},
+    /*  4 */ {2, s_5_4, -1, 1, 0},
+    /*  5 */ {2, s_5_5, -1, 1, 0},
+    /*  6 */ {2, s_5_6, -1, 1, 0},
+    /*  7 */ {4, s_5_7, 6, 1, 0},
+    /*  8 */ {4, s_5_8, 6, 1, 0},
+    /*  9 */ {2, s_5_9, -1, 1, 0},
+    /* 10 */ {4, s_5_10, 9, 1, 0},
+    /* 11 */ {4, s_5_11, 9, 1, 0},
+    /* 12 */ {2, s_5_12, -1, 1, 0},
+    /* 13 */ {4, s_5_13, -1, 1, 0},
+    /* 14 */ {4, s_5_14, -1, 1, 0},
+    /* 15 */ {2, s_5_15, -1, 1, 0},
+    /* 16 */ {4, s_5_16, 15, 1, 0},
+    /* 17 */ {4, s_5_17, 15, 1, 0},
+    /* 18 */ {2, s_5_18, -1, 1, 0},
+    /* 19 */ {4, s_5_19, 18, 1, 0},
+    /* 20 */ {4, s_5_20, 18, 1, 0},
+    /* 21 */ {6, s_5_21, 18, 1, 0},
+    /* 22 */ {8, s_5_22, 21, 1, 0},
+    /* 23 */ {6, s_5_23, 18, 1, 0},
+    /* 24 */ {2, s_5_24, -1, 1, 0},
+    /* 25 */ {4, s_5_25, 24, 1, 0},
+    /* 26 */ {6, s_5_26, 25, 1, 0},
+    /* 27 */ {4, s_5_27, 24, 1, 0},
+    /* 28 */ {4, s_5_28, 24, 1, 0},
+    /* 29 */ {4, s_5_29, -1, 1, 0},
+    /* 30 */ {6, s_5_30, 29, 1, 0},
+    /* 31 */ {4, s_5_31, -1, 1, 0},
+    /* 32 */ {4, s_5_32, -1, 1, 0},
+    /* 33 */ {6, s_5_33, 32, 1, 0},
+    /* 34 */ {4, s_5_34, -1, 1, 0},
+    /* 35 */ {2, s_5_35, -1, 1, 0}
 };
 
-static symbol s_6_0[6] = { 0xD0, 0xBE, 0xD1, 0x81, 0xD1, 0x82 };
-static symbol s_6_1[8] = { 0xD0, 0xBE, 0xD1, 0x81, 0xD1, 0x82, 0xD1, 0x8C };
+static symbol s_6_0[6] = {0xD0, 0xBE, 0xD1, 0x81, 0xD1, 0x82};
+static symbol s_6_1[8] = {0xD0, 0xBE, 0xD1, 0x81, 0xD1, 0x82, 0xD1, 0x8C};
 
 static struct among a_6[2] =
 {
-/*  0 */ { 6, s_6_0, -1, 1, 0},
-/*  1 */ { 8, s_6_1, -1, 1, 0}
+    /*  0 */ {6, s_6_0, -1, 1, 0},
+    /*  1 */ {8, s_6_1, -1, 1, 0}
 };
 
-static symbol s_7_0[6] = { 0xD0, 0xB5, 0xD0, 0xB9, 0xD1, 0x88 };
-static symbol s_7_1[2] = { 0xD1, 0x8C };
-static symbol s_7_2[8] = { 0xD0, 0xB5, 0xD0, 0xB9, 0xD1, 0x88, 0xD0, 0xB5 };
-static symbol s_7_3[2] = { 0xD0, 0xBD };
+static symbol s_7_0[6] = {0xD0, 0xB5, 0xD0, 0xB9, 0xD1, 0x88};
+static symbol s_7_1[2] = {0xD1, 0x8C};
+static symbol s_7_2[8] = {0xD0, 0xB5, 0xD0, 0xB9, 0xD1, 0x88, 0xD0, 0xB5};
+static symbol s_7_3[2] = {0xD0, 0xBD};
 
 static struct among a_7[4] =
 {
-/*  0 */ { 6, s_7_0, -1, 1, 0},
-/*  1 */ { 2, s_7_1, -1, 3, 0},
-/*  2 */ { 8, s_7_2, -1, 1, 0},
-/*  3 */ { 2, s_7_3, -1, 2, 0}
+    /*  0 */ {6, s_7_0, -1, 1, 0},
+    /*  1 */ {2, s_7_1, -1, 3, 0},
+    /*  2 */ {8, s_7_2, -1, 1, 0},
+    /*  3 */ {2, s_7_3, -1, 2, 0}
 };
 
-static unsigned char g_v[] = { 33, 65, 8, 232 };
-
-static symbol s_0[] = { 0xD0, 0xB0 };
-static symbol s_1[] = { 0xD1, 0x8F };
-static symbol s_2[] = { 0xD0, 0xB0 };
-static symbol s_3[] = { 0xD1, 0x8F };
-static symbol s_4[] = { 0xD0, 0xB0 };
-static symbol s_5[] = { 0xD1, 0x8F };
-static symbol s_6[] = { 0xD0, 0xBD };
-static symbol s_7[] = { 0xD0, 0xBD };
-static symbol s_8[] = { 0xD0, 0xBD };
-static symbol s_9[] = { 0xD0, 0xB8 };
-
-static int r_mark_regions(struct SN_env * z) {
-    z->I[0] = z->l;
-    z->I[1] = z->l;
-    {   int c = z->c; /* do, line 61 */
-        while(1) { /* gopast, line 62 */
-            if (!(in_grouping_U(z, g_v, 1072, 1103))) goto lab1;
-            break;
-        lab1:
-            {   int c = skip_utf8(z->p, z->c, 0, z->l, 1);
-                if (c < 0) goto lab0;
-                z->c = c; /* gopast, line 62 */
-            }
-        }
-        z->I[0] = z->c; /* setmark pV, line 62 */
-        while(1) { /* gopast, line 62 */
-            if (!(out_grouping_U(z, g_v, 1072, 1103))) goto lab2;
-            break;
-        lab2:
-            {   int c = skip_utf8(z->p, z->c, 0, z->l, 1);
-                if (c < 0) goto lab0;
-                z->c = c; /* gopast, line 62 */
-            }
-        }
-        while(1) { /* gopast, line 63 */
-            if (!(in_grouping_U(z, g_v, 1072, 1103))) goto lab3;
-            break;
-        lab3:
-            {   int c = skip_utf8(z->p, z->c, 0, z->l, 1);
-                if (c < 0) goto lab0;
-                z->c = c; /* gopast, line 63 */
-            }
-        }
-        while(1) { /* gopast, line 63 */
-            if (!(out_grouping_U(z, g_v, 1072, 1103))) goto lab4;
-            break;
-        lab4:
-            {   int c = skip_utf8(z->p, z->c, 0, z->l, 1);
-                if (c < 0) goto lab0;
-                z->c = c; /* gopast, line 63 */
-            }
-        }
-        z->I[1] = z->c; /* setmark p2, line 63 */
-    lab0:
-        z->c = c;
-    }
-    return 1;
+static unsigned char g_v[] = {33, 65, 8, 232};
+
+static symbol s_0[] = {0xD0, 0xB0};
+static symbol s_1[] = {0xD1, 0x8F};
+static symbol s_2[] = {0xD0, 0xB0};
+static symbol s_3[] = {0xD1, 0x8F};
+static symbol s_4[] = {0xD0, 0xB0};
+static symbol s_5[] = {0xD1, 0x8F};
+static symbol s_6[] = {0xD0, 0xBD};
+static symbol s_7[] = {0xD0, 0xBD};
+static symbol s_8[] = {0xD0, 0xBD};
+static symbol s_9[] = {0xD0, 0xB8};
+
+static int
+r_mark_regions(struct SN_env * z)
+{
+   z->I[0] = z->l;
+   z->I[1] = z->l;
+   {
+       int         c = z->c;   /* do, line 61 */
+
+       while (1)
+       {                       /* gopast, line 62 */
+           if (!(in_grouping_U(z, g_v, 1072, 1103)))
+               goto lab1;
+           break;
+   lab1:
+           {
+               int         c = skip_utf8(z->p, z->c, 0, z->l, 1);
+
+               if (c < 0)
+                   goto lab0;
+               z->c = c;       /* gopast, line 62 */
+           }
+       }
+       z->I[0] = z->c;         /* setmark pV, line 62 */
+       while (1)
+       {                       /* gopast, line 62 */
+           if (!(out_grouping_U(z, g_v, 1072, 1103)))
+               goto lab2;
+           break;
+   lab2:
+           {
+               int         c = skip_utf8(z->p, z->c, 0, z->l, 1);
+
+               if (c < 0)
+                   goto lab0;
+               z->c = c;       /* gopast, line 62 */
+           }
+       }
+       while (1)
+       {                       /* gopast, line 63 */
+           if (!(in_grouping_U(z, g_v, 1072, 1103)))
+               goto lab3;
+           break;
+   lab3:
+           {
+               int         c = skip_utf8(z->p, z->c, 0, z->l, 1);
+
+               if (c < 0)
+                   goto lab0;
+               z->c = c;       /* gopast, line 63 */
+           }
+       }
+       while (1)
+       {                       /* gopast, line 63 */
+           if (!(out_grouping_U(z, g_v, 1072, 1103)))
+               goto lab4;
+           break;
+   lab4:
+           {
+               int         c = skip_utf8(z->p, z->c, 0, z->l, 1);
+
+               if (c < 0)
+                   goto lab0;
+               z->c = c;       /* gopast, line 63 */
+           }
+       }
+       z->I[1] = z->c;         /* setmark p2, line 63 */
+lab0:
+       z->c = c;
+   }
+   return 1;
 }
 
-static int r_R2(struct SN_env * z) {
-    if (!(z->I[1] <= z->c)) return 0;
-    return 1;
+static int
+r_R2(struct SN_env * z)
+{
+   if (!(z->I[1] <= z->c))
+       return 0;
+   return 1;
 }
 
-static int r_perfective_gerund(struct SN_env * z) {
-    int among_var;
-    z->ket = z->c; /* [, line 72 */
-    among_var = find_among_b(z, a_0, 9); /* substring, line 72 */
-    if (!(among_var)) return 0;
-    z->bra = z->c; /* ], line 72 */
-    switch(among_var) {
-        case 0: return 0;
-        case 1:
-            {   int m = z->l - z->c; (void) m; /* or, line 76 */
-                if (!(eq_s_b(z, 2, s_0))) goto lab1;
-                goto lab0;
-            lab1:
-                z->c = z->l - m;
-                if (!(eq_s_b(z, 2, s_1))) return 0;
-            }
-        lab0:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 76 */
-                if (ret < 0) return ret;
-            }
-            break;
-        case 2:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 83 */
-                if (ret < 0) return ret;
-            }
-            break;
-    }
-    return 1;
+static int
+r_perfective_gerund(struct SN_env * z)
+{
+   int         among_var;
+
+   z->ket = z->c;              /* [, line 72 */
+   among_var = find_among_b(z, a_0, 9);        /* substring, line 72 */
+   if (!(among_var))
+       return 0;
+   z->bra = z->c;              /* ], line 72 */
+   switch (among_var)
+   {
+       case 0:
+           return 0;
+       case 1:
+           {
+               int         m = z->l - z->c;
+
+               (void) m;       /* or, line 76 */
+               if (!(eq_s_b(z, 2, s_0)))
+                   goto lab1;
+               goto lab0;
+       lab1:
+               z->c = z->l - m;
+               if (!(eq_s_b(z, 2, s_1)))
+                   return 0;
+           }
+   lab0:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 76 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+       case 2:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 83 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+   }
+   return 1;
 }
 
-static int r_adjective(struct SN_env * z) {
-    int among_var;
-    z->ket = z->c; /* [, line 88 */
-    among_var = find_among_b(z, a_1, 26); /* substring, line 88 */
-    if (!(among_var)) return 0;
-    z->bra = z->c; /* ], line 88 */
-    switch(among_var) {
-        case 0: return 0;
-        case 1:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 97 */
-                if (ret < 0) return ret;
-            }
-            break;
-    }
-    return 1;
+static int
+r_adjective(struct SN_env * z)
+{
+   int         among_var;
+
+   z->ket = z->c;              /* [, line 88 */
+   among_var = find_among_b(z, a_1, 26);       /* substring, line 88 */
+   if (!(among_var))
+       return 0;
+   z->bra = z->c;              /* ], line 88 */
+   switch (among_var)
+   {
+       case 0:
+           return 0;
+       case 1:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 97 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+   }
+   return 1;
 }
 
-static int r_adjectival(struct SN_env * z) {
-    int among_var;
-    {   int ret = r_adjective(z);
-        if (ret == 0) return 0; /* call adjective, line 102 */
-        if (ret < 0) return ret;
-    }
-    {   int m = z->l - z->c; (void) m; /* try, line 109 */
-        z->ket = z->c; /* [, line 110 */
-        among_var = find_among_b(z, a_2, 8); /* substring, line 110 */
-        if (!(among_var)) { z->c = z->l - m; goto lab0; }
-        z->bra = z->c; /* ], line 110 */
-        switch(among_var) {
-            case 0: { z->c = z->l - m; goto lab0; }
-            case 1:
-                {   int m = z->l - z->c; (void) m; /* or, line 115 */
-                    if (!(eq_s_b(z, 2, s_2))) goto lab2;
-                    goto lab1;
-                lab2:
-                    z->c = z->l - m;
-                    if (!(eq_s_b(z, 2, s_3))) { z->c = z->l - m; goto lab0; }
-                }
-            lab1:
-                {   int ret;
-                    ret = slice_del(z); /* delete, line 115 */
-                    if (ret < 0) return ret;
-                }
-                break;
-            case 2:
-                {   int ret;
-                    ret = slice_del(z); /* delete, line 122 */
-                    if (ret < 0) return ret;
-                }
-                break;
-        }
-    lab0:
-        ;
-    }
-    return 1;
+static int
+r_adjectival(struct SN_env * z)
+{
+   int         among_var;
+
+   {
+       int         ret = r_adjective(z);
+
+       if (ret == 0)
+           return 0;           /* call adjective, line 102 */
+       if (ret < 0)
+           return ret;
+   }
+   {
+       int         m = z->l - z->c;
+
+       (void) m;               /* try, line 109 */
+       z->ket = z->c;          /* [, line 110 */
+       among_var = find_among_b(z, a_2, 8);    /* substring, line 110 */
+       if (!(among_var))
+       {
+           z->c = z->l - m;
+           goto lab0;
+       }
+       z->bra = z->c;          /* ], line 110 */
+       switch (among_var)
+       {
+           case 0:
+               {
+                   z->c = z->l - m;
+                   goto lab0;
+               }
+           case 1:
+               {
+                   int         m = z->l - z->c;
+
+                   (void) m;   /* or, line 115 */
+                   if (!(eq_s_b(z, 2, s_2)))
+                       goto lab2;
+                   goto lab1;
+           lab2:
+                   z->c = z->l - m;
+                   if (!(eq_s_b(z, 2, s_3)))
+                   {
+                       z->c = z->l - m;
+                       goto lab0;
+                   }
+               }
+       lab1:
+               {
+                   int         ret;
+
+                   ret = slice_del(z); /* delete, line 115 */
+                   if (ret < 0)
+                       return ret;
+               }
+               break;
+           case 2:
+               {
+                   int         ret;
+
+                   ret = slice_del(z); /* delete, line 122 */
+                   if (ret < 0)
+                       return ret;
+               }
+               break;
+       }
+lab0:
+       ;
+   }
+   return 1;
 }
 
-static int r_reflexive(struct SN_env * z) {
-    int among_var;
-    z->ket = z->c; /* [, line 129 */
-    among_var = find_among_b(z, a_3, 2); /* substring, line 129 */
-    if (!(among_var)) return 0;
-    z->bra = z->c; /* ], line 129 */
-    switch(among_var) {
-        case 0: return 0;
-        case 1:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 132 */
-                if (ret < 0) return ret;
-            }
-            break;
-    }
-    return 1;
+static int
+r_reflexive(struct SN_env * z)
+{
+   int         among_var;
+
+   z->ket = z->c;              /* [, line 129 */
+   among_var = find_among_b(z, a_3, 2);        /* substring, line 129 */
+   if (!(among_var))
+       return 0;
+   z->bra = z->c;              /* ], line 129 */
+   switch (among_var)
+   {
+       case 0:
+           return 0;
+       case 1:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 132 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+   }
+   return 1;
 }
 
-static int r_verb(struct SN_env * z) {
-    int among_var;
-    z->ket = z->c; /* [, line 137 */
-    among_var = find_among_b(z, a_4, 46); /* substring, line 137 */
-    if (!(among_var)) return 0;
-    z->bra = z->c; /* ], line 137 */
-    switch(among_var) {
-        case 0: return 0;
-        case 1:
-            {   int m = z->l - z->c; (void) m; /* or, line 143 */
-                if (!(eq_s_b(z, 2, s_4))) goto lab1;
-                goto lab0;
-            lab1:
-                z->c = z->l - m;
-                if (!(eq_s_b(z, 2, s_5))) return 0;
-            }
-        lab0:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 143 */
-                if (ret < 0) return ret;
-            }
-            break;
-        case 2:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 151 */
-                if (ret < 0) return ret;
-            }
-            break;
-    }
-    return 1;
+static int
+r_verb(struct SN_env * z)
+{
+   int         among_var;
+
+   z->ket = z->c;              /* [, line 137 */
+   among_var = find_among_b(z, a_4, 46);       /* substring, line 137 */
+   if (!(among_var))
+       return 0;
+   z->bra = z->c;              /* ], line 137 */
+   switch (among_var)
+   {
+       case 0:
+           return 0;
+       case 1:
+           {
+               int         m = z->l - z->c;
+
+               (void) m;       /* or, line 143 */
+               if (!(eq_s_b(z, 2, s_4)))
+                   goto lab1;
+               goto lab0;
+       lab1:
+               z->c = z->l - m;
+               if (!(eq_s_b(z, 2, s_5)))
+                   return 0;
+           }
+   lab0:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 143 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+       case 2:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 151 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+   }
+   return 1;
 }
 
-static int r_noun(struct SN_env * z) {
-    int among_var;
-    z->ket = z->c; /* [, line 160 */
-    among_var = find_among_b(z, a_5, 36); /* substring, line 160 */
-    if (!(among_var)) return 0;
-    z->bra = z->c; /* ], line 160 */
-    switch(among_var) {
-        case 0: return 0;
-        case 1:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 167 */
-                if (ret < 0) return ret;
-            }
-            break;
-    }
-    return 1;
+static int
+r_noun(struct SN_env * z)
+{
+   int         among_var;
+
+   z->ket = z->c;              /* [, line 160 */
+   among_var = find_among_b(z, a_5, 36);       /* substring, line 160 */
+   if (!(among_var))
+       return 0;
+   z->bra = z->c;              /* ], line 160 */
+   switch (among_var)
+   {
+       case 0:
+           return 0;
+       case 1:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 167 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+   }
+   return 1;
 }
 
-static int r_derivational(struct SN_env * z) {
-    int among_var;
-    z->ket = z->c; /* [, line 176 */
-    among_var = find_among_b(z, a_6, 2); /* substring, line 176 */
-    if (!(among_var)) return 0;
-    z->bra = z->c; /* ], line 176 */
-    {   int ret = r_R2(z);
-        if (ret == 0) return 0; /* call R2, line 176 */
-        if (ret < 0) return ret;
-    }
-    switch(among_var) {
-        case 0: return 0;
-        case 1:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 179 */
-                if (ret < 0) return ret;
-            }
-            break;
-    }
-    return 1;
+static int
+r_derivational(struct SN_env * z)
+{
+   int         among_var;
+
+   z->ket = z->c;              /* [, line 176 */
+   among_var = find_among_b(z, a_6, 2);        /* substring, line 176 */
+   if (!(among_var))
+       return 0;
+   z->bra = z->c;              /* ], line 176 */
+   {
+       int         ret = r_R2(z);
+
+       if (ret == 0)
+           return 0;           /* call R2, line 176 */
+       if (ret < 0)
+           return ret;
+   }
+   switch (among_var)
+   {
+       case 0:
+           return 0;
+       case 1:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 179 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+   }
+   return 1;
 }
 
-static int r_tidy_up(struct SN_env * z) {
-    int among_var;
-    z->ket = z->c; /* [, line 184 */
-    among_var = find_among_b(z, a_7, 4); /* substring, line 184 */
-    if (!(among_var)) return 0;
-    z->bra = z->c; /* ], line 184 */
-    switch(among_var) {
-        case 0: return 0;
-        case 1:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 188 */
-                if (ret < 0) return ret;
-            }
-            z->ket = z->c; /* [, line 189 */
-            if (!(eq_s_b(z, 2, s_6))) return 0;
-            z->bra = z->c; /* ], line 189 */
-            if (!(eq_s_b(z, 2, s_7))) return 0;
-            {   int ret;
-                ret = slice_del(z); /* delete, line 189 */
-                if (ret < 0) return ret;
-            }
-            break;
-        case 2:
-            if (!(eq_s_b(z, 2, s_8))) return 0;
-            {   int ret;
-                ret = slice_del(z); /* delete, line 192 */
-                if (ret < 0) return ret;
-            }
-            break;
-        case 3:
-            {   int ret;
-                ret = slice_del(z); /* delete, line 194 */
-                if (ret < 0) return ret;
-            }
-            break;
-    }
-    return 1;
+static int
+r_tidy_up(struct SN_env * z)
+{
+   int         among_var;
+
+   z->ket = z->c;              /* [, line 184 */
+   among_var = find_among_b(z, a_7, 4);        /* substring, line 184 */
+   if (!(among_var))
+       return 0;
+   z->bra = z->c;              /* ], line 184 */
+   switch (among_var)
+   {
+       case 0:
+           return 0;
+       case 1:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 188 */
+               if (ret < 0)
+                   return ret;
+           }
+           z->ket = z->c;      /* [, line 189 */
+           if (!(eq_s_b(z, 2, s_6)))
+               return 0;
+           z->bra = z->c;      /* ], line 189 */
+           if (!(eq_s_b(z, 2, s_7)))
+               return 0;
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 189 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+       case 2:
+           if (!(eq_s_b(z, 2, s_8)))
+               return 0;
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 192 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+       case 3:
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 194 */
+               if (ret < 0)
+                   return ret;
+           }
+           break;
+   }
+   return 1;
 }
 
-extern int russian_UTF_8_stem(struct SN_env * z) {
-    {   int c = z->c; /* do, line 201 */
-        {   int ret = r_mark_regions(z);
-            if (ret == 0) goto lab0; /* call mark_regions, line 201 */
-            if (ret < 0) return ret;
-        }
-    lab0:
-        z->c = c;
-    }
-    z->lb = z->c; z->c = z->l; /* backwards, line 202 */
-
-    {   int m3; /* setlimit, line 202 */
-        int m = z->l - z->c; (void) m;
-        if (z->c < z->I[0]) return 0;
-        z->c = z->I[0]; /* tomark, line 202 */
-        m3 = z->lb; z->lb = z->c;
-        z->c = z->l - m;
-        {   int m = z->l - z->c; (void) m; /* do, line 203 */
-            {   int m = z->l - z->c; (void) m; /* or, line 204 */
-                {   int ret = r_perfective_gerund(z);
-                    if (ret == 0) goto lab3; /* call perfective_gerund, line 204 */
-                    if (ret < 0) return ret;
-                }
-                goto lab2;
-            lab3:
-                z->c = z->l - m;
-                {   int m = z->l - z->c; (void) m; /* try, line 205 */
-                    {   int ret = r_reflexive(z);
-                        if (ret == 0) { z->c = z->l - m; goto lab4; } /* call reflexive, line 205 */
-                        if (ret < 0) return ret;
-                    }
-                lab4:
-                    ;
-                }
-                {   int m = z->l - z->c; (void) m; /* or, line 206 */
-                    {   int ret = r_adjectival(z);
-                        if (ret == 0) goto lab6; /* call adjectival, line 206 */
-                        if (ret < 0) return ret;
-                    }
-                    goto lab5;
-                lab6:
-                    z->c = z->l - m;
-                    {   int ret = r_verb(z);
-                        if (ret == 0) goto lab7; /* call verb, line 206 */
-                        if (ret < 0) return ret;
-                    }
-                    goto lab5;
-                lab7:
-                    z->c = z->l - m;
-                    {   int ret = r_noun(z);
-                        if (ret == 0) goto lab1; /* call noun, line 206 */
-                        if (ret < 0) return ret;
-                    }
-                }
-            lab5:
-                ;
-            }
-        lab2:
-        lab1:
-            z->c = z->l - m;
-        }
-        {   int m = z->l - z->c; (void) m; /* try, line 209 */
-            z->ket = z->c; /* [, line 209 */
-            if (!(eq_s_b(z, 2, s_9))) { z->c = z->l - m; goto lab8; }
-            z->bra = z->c; /* ], line 209 */
-            {   int ret;
-                ret = slice_del(z); /* delete, line 209 */
-                if (ret < 0) return ret;
-            }
-        lab8:
-            ;
-        }
-        {   int m = z->l - z->c; (void) m; /* do, line 212 */
-            {   int ret = r_derivational(z);
-                if (ret == 0) goto lab9; /* call derivational, line 212 */
-                if (ret < 0) return ret;
-            }
-        lab9:
-            z->c = z->l - m;
-        }
-        {   int m = z->l - z->c; (void) m; /* do, line 213 */
-            {   int ret = r_tidy_up(z);
-                if (ret == 0) goto lab10; /* call tidy_up, line 213 */
-                if (ret < 0) return ret;
-            }
-        lab10:
-            z->c = z->l - m;
-        }
-        z->lb = m3;
-    }
-    z->c = z->lb;
-    return 1;
+extern int
+russian_UTF_8_stem(struct SN_env * z)
+{
+   {
+       int         c = z->c;   /* do, line 201 */
+
+       {
+           int         ret = r_mark_regions(z);
+
+           if (ret == 0)
+               goto lab0;      /* call mark_regions, line 201 */
+           if (ret < 0)
+               return ret;
+       }
+lab0:
+       z->c = c;
+   }
+   z->lb = z->c;
+   z->c = z->l;                /* backwards, line 202 */
+
+   {
+       int         m3;         /* setlimit, line 202 */
+       int         m = z->l - z->c;
+
+       (void) m;
+       if (z->c < z->I[0])
+           return 0;
+       z->c = z->I[0];         /* tomark, line 202 */
+       m3 = z->lb;
+       z->lb = z->c;
+       z->c = z->l - m;
+       {
+           int         m = z->l - z->c;
+
+           (void) m;           /* do, line 203 */
+           {
+               int         m = z->l - z->c;
+
+               (void) m;       /* or, line 204 */
+               {
+                   int         ret = r_perfective_gerund(z);
+
+                   if (ret == 0)
+                       goto lab3;      /* call perfective_gerund, line 204 */
+                   if (ret < 0)
+                       return ret;
+               }
+               goto lab2;
+       lab3:
+               z->c = z->l - m;
+               {
+                   int         m = z->l - z->c;
+
+                   (void) m;   /* try, line 205 */
+                   {
+                       int         ret = r_reflexive(z);
+
+                       if (ret == 0)
+                       {
+                           z->c = z->l - m;
+                           goto lab4;
+                       }       /* call reflexive, line 205 */
+                       if (ret < 0)
+                           return ret;
+                   }
+           lab4:
+                   ;
+               }
+               {
+                   int         m = z->l - z->c;
+
+                   (void) m;   /* or, line 206 */
+                   {
+                       int         ret = r_adjectival(z);
+
+                       if (ret == 0)
+                           goto lab6;  /* call adjectival, line 206 */
+                       if (ret < 0)
+                           return ret;
+                   }
+                   goto lab5;
+           lab6:
+                   z->c = z->l - m;
+                   {
+                       int         ret = r_verb(z);
+
+                       if (ret == 0)
+                           goto lab7;  /* call verb, line 206 */
+                       if (ret < 0)
+                           return ret;
+                   }
+                   goto lab5;
+           lab7:
+                   z->c = z->l - m;
+                   {
+                       int         ret = r_noun(z);
+
+                       if (ret == 0)
+                           goto lab1;  /* call noun, line 206 */
+                       if (ret < 0)
+                           return ret;
+                   }
+               }
+       lab5:
+               ;
+           }
+   lab2:
+   lab1:
+           z->c = z->l - m;
+       }
+       {
+           int         m = z->l - z->c;
+
+           (void) m;           /* try, line 209 */
+           z->ket = z->c;      /* [, line 209 */
+           if (!(eq_s_b(z, 2, s_9)))
+           {
+               z->c = z->l - m;
+               goto lab8;
+           }
+           z->bra = z->c;      /* ], line 209 */
+           {
+               int         ret;
+
+               ret = slice_del(z);     /* delete, line 209 */
+               if (ret < 0)
+                   return ret;
+           }
+   lab8:
+           ;
+       }
+       {
+           int         m = z->l - z->c;
+
+           (void) m;           /* do, line 212 */
+           {
+               int         ret = r_derivational(z);
+
+               if (ret == 0)
+                   goto lab9;  /* call derivational, line 212 */
+               if (ret < 0)
+                   return ret;
+           }
+   lab9:
+           z->c = z->l - m;
+       }
+       {
+           int         m = z->l - z->c;
+
+           (void) m;           /* do, line 213 */
+           {
+               int         ret = r_tidy_up(z);
+
+               if (ret == 0)
+                   goto lab10; /* call tidy_up, line 213 */
+               if (ret < 0)
+                   return ret;
+           }
+   lab10:
+           z->c = z->l - m;
+       }
+       z->lb = m3;
+   }
+   z->c = z->lb;
+   return 1;
 }
 
-extern struct SN_env * russian_UTF_8_create_env(void) { return SN_create_env(0, 2, 0); }
-
-extern void russian_UTF_8_close_env(struct SN_env * z) { SN_close_env(z); }
+extern struct SN_env *russian_UTF_8_create_env(void)
+{
+   return SN_create_env(0, 2, 0);
+}
 
+extern void russian_UTF_8_close_env(struct SN_env * z)
+{
+   SN_