summaryrefslogtreecommitdiff
path: root/bdb/examples_cxx/BtRecExample.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bdb/examples_cxx/BtRecExample.cpp')
-rw-r--r--bdb/examples_cxx/BtRecExample.cpp59
1 files changed, 18 insertions, 41 deletions
diff --git a/bdb/examples_cxx/BtRecExample.cpp b/bdb/examples_cxx/BtRecExample.cpp
index 98d9626b969..b56c3fe5837 100644
--- a/bdb/examples_cxx/BtRecExample.cpp
+++ b/bdb/examples_cxx/BtRecExample.cpp
@@ -1,35 +1,31 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1997, 1998, 1999, 2000
+ * Copyright (c) 1997-2002
* Sleepycat Software. All rights reserved.
*
- * $Id: BtRecExample.cpp,v 11.6 2000/02/19 20:57:59 bostic Exp $
+ * $Id: BtRecExample.cpp,v 11.21 2002/01/23 15:33:20 bostic Exp $
*/
-#include "db_config.h"
-
-#ifndef NO_SYSTEM_INCLUDES
#include <sys/types.h>
+
#include <errno.h>
-#include <iostream.h>
+#include <iostream>
+#include <iomanip>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <unistd.h>
-#endif
-#include <iomanip.h>
#include <db_cxx.h>
+using std::cout;
+using std::cerr;
+
#define DATABASE "access.db"
#define WORDLIST "../test/wordlist"
-void usage();
-extern "C" int getopt(int, char * const *, const char *);
-
-char *progname = "BtRecExample"; // Program name.
+const char *progname = "BtRecExample"; // Program name.
class BtRecExample
{
@@ -38,7 +34,7 @@ public:
~BtRecExample();
void run();
void stats();
- void show(char *msg, Dbt *key, Dbt *data);
+ void show(const char *msg, Dbt *key, Dbt *data);
private:
Db *dbp;
@@ -51,7 +47,7 @@ BtRecExample::BtRecExample(FILE *fp)
int ret;
// Remove the previous database.
- (void)unlink(DATABASE);
+ (void)remove(DATABASE);
dbp = new Db(NULL, 0);
@@ -60,7 +56,7 @@ BtRecExample::BtRecExample(FILE *fp)
dbp->set_pagesize(1024); // 1K page sizes.
dbp->set_flags(DB_RECNUM); // Record numbers.
- dbp->open(DATABASE, NULL, DB_BTREE, DB_CREATE, 0664);
+ dbp->open(NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664);
//
// Insert records into the database, where the key is the word
@@ -107,7 +103,7 @@ void BtRecExample::stats()
{
DB_BTREE_STAT *statp;
- dbp->stat(&statp, NULL, 0);
+ dbp->stat(&statp, 0);
cout << progname << ": database contains "
<< (u_long)statp->bt_ndata << " records\n";
@@ -191,34 +187,22 @@ void BtRecExample::run()
// show --
// Display a key/data pair.
//
-void BtRecExample::show(char *msg, Dbt *key, Dbt *data)
+void BtRecExample::show(const char *msg, Dbt *key, Dbt *data)
{
cout << msg << (char *)key->get_data()
<< " : " << (char *)data->get_data() << "\n";
}
int
-main(int argc, char *argv[])
+main()
{
- extern char *optarg;
- extern int optind;
FILE *fp;
- int ch;
-
- while ((ch = getopt(argc, argv, "")) != EOF)
- switch (ch) {
- case '?':
- default:
- usage();
- }
- argc -= optind;
- argv += optind;
// Open the word database.
if ((fp = fopen(WORDLIST, "r")) == NULL) {
fprintf(stderr, "%s: open %s: %s\n",
progname, WORDLIST, db_strerror(errno));
- exit (1);
+ return (EXIT_FAILURE);
}
try {
@@ -233,15 +217,8 @@ main(int argc, char *argv[])
}
catch (DbException &dbe) {
cerr << "Exception: " << dbe.what() << "\n";
- return dbe.get_errno();
+ return (EXIT_FAILURE);
}
- return (0);
-}
-
-void
-usage()
-{
- (void)fprintf(stderr, "usage: %s\n", progname);
- exit(1);
+ return (EXIT_SUCCESS);
}