Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add support for --block-size
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3025c4b3b61ac38ad6f5f1de848520a701677279
User & Date: brandon 2016-06-12 17:49:21
Context
2016-06-12
17:49
update ChangeLog check-in: 2cad563fc9 user: brandon tags: trunk
17:49
add support for --block-size check-in: 3025c4b3b6 user: brandon tags: trunk
17:00
remove support for kyotocabinet and add support for mmap-size and cache-size for all executables check-in: c8eb4e153d user: brandon tags: trunk
Changes

Changes to src/zdb.c.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
   along with zeptodb.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "zdb.h"

GDBM_FILE
zdb_open (char *dbfile, int mode, size_t mmap_size, size_t cache_size,
          bool verbose)
{
  if (verbose)
    printf ("Opening database %s\n", dbfile);
  GDBM_FILE database;
  int gdbm_mode = 0;
  if ((mode & ZDB_READER) == ZDB_READER)
    gdbm_mode ^= GDBM_READER;
................................................................................
    gdbm_mode ^= GDBM_NEWDB;
  if ((mode & ZDB_SYNC) == ZDB_SYNC)
    gdbm_mode ^= GDBM_SYNC;
  if ((mode & ZDB_NOLOCK) == ZDB_NOLOCK)
    gdbm_mode ^= GDBM_NOLOCK;
  if ((mode & ZDB_NOMMAP) == ZDB_NOMMAP)
    gdbm_mode ^= GDBM_NOMMAP;
  database = gdbm_open (dbfile, 512, gdbm_mode,
                        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, NULL);
  if (!database)
    error (EXIT_FAILURE, errno, "Failed to open database %s", dbfile);
  gdbm_setopt (database, GDBM_SETMAXMAPSIZE, &mmap_size, sizeof (size_t));
  gdbm_setopt (database, GDBM_SETCACHESIZE, &cache_size, sizeof (size_t));
  return database;
}
................................................................................
}

int
zdb_store (GDBM_FILE database, char *key_str, size_t key_size, char *value_str,
           size_t value_size, bool verbose)
{
  if (verbose)
    printf ("Storing %s|%s                             \r", key_str, value_str);
  datum key, value;
  value.dptr = value_str;
  value.dsize = value_size;
  key.dptr = key_str;
  key.dsize = key_size;
  if (gdbm_store (database, key, value, GDBM_REPLACE))
    return 1;
................................................................................
  return 0;
}

void
zdb_print_info (GDBM_FILE database)
{
  size_t cache_size;
  size_t mmap_size_out;
  int mmap;
  gdbm_count_t num_records;
  gdbm_setopt (database, GDBM_GETCACHESIZE, &cache_size, sizeof (size_t));
  gdbm_setopt (database, GDBM_GETMAXMAPSIZE, &mmap_size_out, sizeof (size_t));
  gdbm_setopt (database, GDBM_GETMMAP, &mmap, sizeof (int));
  if (gdbm_count (database, &num_records))
    error (0, errno, "Error counting records");
  printf ("Bucket cache size:\t%zd\n", cache_size);
  if (mmap)
    {
      puts ("Memory-map enabled:\ttrue");
      printf ("Memory-map size:\t%zd\n", mmap_size_out);
    }
  else
    {
      puts ("Memory-map enabled:\tfalse");
    }
  printf ("Number of records:\t%lld\n", num_records);
  return;
}







|







 







|







 







|







 







|



|







|








18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
   along with zeptodb.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "zdb.h"

GDBM_FILE
zdb_open (char *dbfile, int mode, size_t mmap_size, size_t cache_size,
          size_t block_size, bool verbose)
{
  if (verbose)
    printf ("Opening database %s\n", dbfile);
  GDBM_FILE database;
  int gdbm_mode = 0;
  if ((mode & ZDB_READER) == ZDB_READER)
    gdbm_mode ^= GDBM_READER;
................................................................................
    gdbm_mode ^= GDBM_NEWDB;
  if ((mode & ZDB_SYNC) == ZDB_SYNC)
    gdbm_mode ^= GDBM_SYNC;
  if ((mode & ZDB_NOLOCK) == ZDB_NOLOCK)
    gdbm_mode ^= GDBM_NOLOCK;
  if ((mode & ZDB_NOMMAP) == ZDB_NOMMAP)
    gdbm_mode ^= GDBM_NOMMAP;
  database = gdbm_open (dbfile, (int) block_size, gdbm_mode,
                        S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, NULL);
  if (!database)
    error (EXIT_FAILURE, errno, "Failed to open database %s", dbfile);
  gdbm_setopt (database, GDBM_SETMAXMAPSIZE, &mmap_size, sizeof (size_t));
  gdbm_setopt (database, GDBM_SETCACHESIZE, &cache_size, sizeof (size_t));
  return database;
}
................................................................................
}

int
zdb_store (GDBM_FILE database, char *key_str, size_t key_size, char *value_str,
           size_t value_size, bool verbose)
{
  if (verbose)
    printf ("Storing %s|%s                             \n", key_str, value_str);
  datum key, value;
  value.dptr = value_str;
  value.dsize = value_size;
  key.dptr = key_str;
  key.dsize = key_size;
  if (gdbm_store (database, key, value, GDBM_REPLACE))
    return 1;
................................................................................
  return 0;
}

void
zdb_print_info (GDBM_FILE database)
{
  size_t cache_size;
  size_t mmap_size;
  int mmap;
  gdbm_count_t num_records;
  gdbm_setopt (database, GDBM_GETCACHESIZE, &cache_size, sizeof (size_t));
  gdbm_setopt (database, GDBM_GETMAXMAPSIZE, &mmap_size, sizeof (size_t));
  gdbm_setopt (database, GDBM_GETMMAP, &mmap, sizeof (int));
  if (gdbm_count (database, &num_records))
    error (0, errno, "Error counting records");
  printf ("Bucket cache size:\t%zd\n", cache_size);
  if (mmap)
    {
      puts ("Memory-map enabled:\ttrue");
      printf ("Memory-map size:\t%zd\n", mmap_size);
    }
  else
    {
      puts ("Memory-map enabled:\tfalse");
    }
  printf ("Number of records:\t%lld\n", num_records);
  return;
}

Changes to src/zdb.h.

36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define ZDB_READER 1<<0
#define ZDB_WRITER 1<<1
#define ZDB_CREATOR 1<<2
#define ZDB_SYNC 1<<3
#define ZDB_NOLOCK 1<<4
#define ZDB_NOMMAP 1<<5

GDBM_FILE zdb_open (char *, int, size_t, size_t, bool);
int zdb_close (GDBM_FILE , bool);
int zdb_store (GDBM_FILE , char *, size_t, char *, size_t, bool);
void printrec (char *, char *, char *);
int zdb_fetch (GDBM_FILE , char *, size_t, char *);
int zdb_fetchall (GDBM_FILE , char *);
int zdb_remove (GDBM_FILE , char *, size_t, bool);
int zdb_reorganize (GDBM_FILE );
void zdb_print_info (GDBM_FILE db);

#endif







|










36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define ZDB_READER 1<<0
#define ZDB_WRITER 1<<1
#define ZDB_CREATOR 1<<2
#define ZDB_SYNC 1<<3
#define ZDB_NOLOCK 1<<4
#define ZDB_NOMMAP 1<<5

GDBM_FILE zdb_open (char *, int, size_t, size_t, size_t, bool);
int zdb_close (GDBM_FILE , bool);
int zdb_store (GDBM_FILE , char *, size_t, char *, size_t, bool);
void printrec (char *, char *, char *);
int zdb_fetch (GDBM_FILE , char *, size_t, char *);
int zdb_fetchall (GDBM_FILE , char *);
int zdb_remove (GDBM_FILE , char *, size_t, bool);
int zdb_reorganize (GDBM_FILE );
void zdb_print_info (GDBM_FILE db);

#endif

Changes to src/zdbc.c.

39
40
41
42
43
44
45


46
47
48
49
50
51
52
..
55
56
57
58
59
60
61

62
63
64
65
66
67
68
69
70
71
72
73
74











75
76
77
78
79
80
81
...
140
141
142
143
144
145
146

147
148
149
150
151
152
153
...
165
166
167
168
169
170
171
172

173
174
175
176
177
178
179
180
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},


  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {"sync", (int)'s', (const char *)NULL, 0,
................................................................................
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t cache_size;

  bool no_mmap;
  bool no_lock;
  bool verbose;
  bool sync;
};

static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {











    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
................................................................................
{
  struct arguments arguments;
  int mode = ZDB_CREATOR;
  error_t argp_result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;

  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;
  arguments.sync = false;

  argp_result = argp_parse (&argp, argc, argv, 0, 0, &arguments);
  if (argp_result)
................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                         arguments.cache_size,  arguments.verbose);

  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to create database %s", arguments.args[0]);
  else if (zdb_close (database, arguments.verbose) != 0)
    error (EXIT_FAILURE, errno,
           "Failed to close database %s", arguments.args[0]);
  exit (EXIT_SUCCESS);
}







>
>







 







>













>
>
>
>
>
>
>
>
>
>
>







 







>







 







|
>








39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
..
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
...
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},
  {"block-size", (int)'b', "NUM", 0,
   "The block size to use (default=512)", 0},
  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {"sync", (int)'s', (const char *)NULL, 0,
................................................................................
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t cache_size;
  size_t block_size;
  bool no_mmap;
  bool no_lock;
  bool verbose;
  bool sync;
};

static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {
    case 'b':
      size = arg ? strtoul (arg, NULL, 10) : 512UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
        {
          arguments->cache_size = (size_t)size;
        }
      break;
    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
................................................................................
{
  struct arguments arguments;
  int mode = ZDB_CREATOR;
  error_t argp_result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;
  arguments.block_size = 512;
  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;
  arguments.sync = false;

  argp_result = argp_parse (&argp, argc, argv, 0, 0, &arguments);
  if (argp_result)
................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                       arguments.cache_size,  arguments.block_size,
                       arguments.verbose);
  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to create database %s", arguments.args[0]);
  else if (zdb_close (database, arguments.verbose) != 0)
    error (EXIT_FAILURE, errno,
           "Failed to close database %s", arguments.args[0]);
  exit (EXIT_SUCCESS);
}

Changes to src/zdbf.c.

41
42
43
44
45
46
47


48
49
50
51
52
53
54
..
65
66
67
68
69
70
71

72
73
74
75
76
77
78
..
82
83
84
85
86
87
88











89
90
91
92
93
94
95
...
221
222
223
224
225
226
227

228
229
230
231
232
233
234
...
249
250
251
252
253
254
255
256

257
258
259
260
261
262
263
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},


  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {"input", (int)'i', "FILE", 0,
................................................................................

struct arguments
{
  char *args[1];
  char *input_file;
  size_t mmap_size;
  size_t cache_size;

  bool no_mmap;
  bool no_lock;
  bool verbose;
  bool all;
  char *delim;
  bool sync;
};
................................................................................
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {
    case 'a':
      arguments->all = true;











      break;
    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
................................................................................
  FILE *input;
  struct arguments arguments;
  int mode = ZDB_READER;
  error_t argp_result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;

  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;
  arguments.sync = false;
  arguments.input_file = NULL;
  arguments.all = false;
  arguments.delim = NULL;
................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                       arguments.cache_size, arguments.verbose);

  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", arguments.args[0]);

  /* if the "all" argument was passed, output all the records */
  /* and exit */
  if (arguments.all != 0)







>
>







 







>







 







>
>
>
>
>
>
>
>
>
>
>







 







>







 







|
>







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
..
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
...
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},
  {"block-size", (int)'c', "NUM", 0,
   "The block size to use (default=512)", 0},
  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {"input", (int)'i', "FILE", 0,
................................................................................

struct arguments
{
  char *args[1];
  char *input_file;
  size_t mmap_size;
  size_t cache_size;
  size_t block_size;
  bool no_mmap;
  bool no_lock;
  bool verbose;
  bool all;
  char *delim;
  bool sync;
};
................................................................................
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {
    case 'a':
      arguments->all = true;
      break;
    case 'b':
      size = arg ? strtoul (arg, NULL, 10) : 512UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
        {
          arguments->cache_size = (size_t)size;
        }
      break;
    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
................................................................................
  FILE *input;
  struct arguments arguments;
  int mode = ZDB_READER;
  error_t argp_result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;
  arguments.block_size = 512;
  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;
  arguments.sync = false;
  arguments.input_file = NULL;
  arguments.all = false;
  arguments.delim = NULL;
................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                       arguments.cache_size, arguments.block_size,
                       arguments.verbose);
  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", arguments.args[0]);

  /* if the "all" argument was passed, output all the records */
  /* and exit */
  if (arguments.all != 0)

Changes to src/zdbi.c.

39
40
41
42
43
44
45


46
47
48
49
50
51
52
..
53
54
55
56
57
58
59

60
61
62
63
64
65
66
67
68
69
70
71











72
73
74
75
76
77
78
...
134
135
136
137
138
139
140

141
142
143
144
145
146
147
...
156
157
158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},


  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {(const char *)NULL, 0, (const char *)NULL, 0, (const char *)NULL, 0}
................................................................................
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t cache_size;

  bool no_mmap;
  bool no_lock;
  bool verbose;
};

static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {











    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
................................................................................
{
  struct arguments arguments;
  int mode = ZDB_READER;
  error_t argp_result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;

  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;

  argp_result = argp_parse (&argp, argc, argv, 0, 0, &arguments);
  if (argp_result)
    error (EXIT_FAILURE, argp_result, "Failed to parse arguments");
................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                       arguments.cache_size, arguments.verbose);

  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", arguments.args[0]);
  zdb_print_info (database);
  if (zdb_close (database, arguments.verbose) != 0)
    error (EXIT_FAILURE, errno,
           "Failed to close database %s", arguments.args[0]);
  exit (EXIT_SUCCESS);
}







>
>







 







>












>
>
>
>
>
>
>
>
>
>
>







 







>







 







|
>









39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
..
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},
  {"block-size", (int)'c', "NUM", 0,
   "The block size to use (default=512)", 0},
  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {(const char *)NULL, 0, (const char *)NULL, 0, (const char *)NULL, 0}
................................................................................
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t cache_size;
  size_t block_size;
  bool no_mmap;
  bool no_lock;
  bool verbose;
};

static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {
    case 'b':
      size = arg ? strtoul (arg, NULL, 10) : 512UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
        {
          arguments->cache_size = (size_t)size;
        }
      break;
    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
................................................................................
{
  struct arguments arguments;
  int mode = ZDB_READER;
  error_t argp_result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;
  arguments.block_size = 512;
  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;

  argp_result = argp_parse (&argp, argc, argv, 0, 0, &arguments);
  if (argp_result)
    error (EXIT_FAILURE, argp_result, "Failed to parse arguments");
................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                       arguments.cache_size, arguments.block_size,
                       arguments.verbose);
  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", arguments.args[0]);
  zdb_print_info (database);
  if (zdb_close (database, arguments.verbose) != 0)
    error (EXIT_FAILURE, errno,
           "Failed to close database %s", arguments.args[0]);
  exit (EXIT_SUCCESS);
}

Changes to src/zdbr.c.

45
46
47
48
49
50
51


52
53
54
55
56
57
58
..
65
66
67
68
69
70
71

72
73
74
75
76
77
78
..
80
81
82
83
84
85
86











87
88
89
90
91
92
93
...
216
217
218
219
220
221
222

223
224
225
226
227
228
229
...
243
244
245
246
247
248
249
250

251
252
253
254
255
256
257
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},


  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {"input", (int)'i', "FILE", 0,
................................................................................
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t cache_size;

  bool no_mmap;
  bool no_lock;
  bool verbose;
  char *input_file;
  bool reorg;
  bool sync;
};
................................................................................
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {











    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
................................................................................
  FILE *input;
  struct arguments arguments;
  int mode = ZDB_WRITER;
  error_t argp_result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;

  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;
  arguments.sync = false;
  arguments.input_file = NULL;
  arguments.reorg = false;

................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                       arguments.cache_size, arguments.verbose);

  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", arguments.args[0]);

  /* if an input file was provided, use it, otherwise use stdin */
  if (!arguments.input_file || strcmp (arguments.input_file, "-") == 0)
    input = stdin;







>
>







 







>







 







>
>
>
>
>
>
>
>
>
>
>







 







>







 







|
>







45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
..
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},
  {"block-size", (int)'c', "NUM", 0,
   "The block size to use (default=512)", 0},
  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {"input", (int)'i', "FILE", 0,
................................................................................
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t cache_size;
  size_t block_size;
  bool no_mmap;
  bool no_lock;
  bool verbose;
  char *input_file;
  bool reorg;
  bool sync;
};
................................................................................
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {
    case 'b':
      size = arg ? strtoul (arg, NULL, 10) : 512UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
        {
          arguments->cache_size = (size_t)size;
        }
      break;
    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
................................................................................
  FILE *input;
  struct arguments arguments;
  int mode = ZDB_WRITER;
  error_t argp_result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;
  arguments.block_size = 512;
  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;
  arguments.sync = false;
  arguments.input_file = NULL;
  arguments.reorg = false;

................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                       arguments.cache_size, arguments.block_size,
                       arguments.verbose);
  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", arguments.args[0]);

  /* if an input file was provided, use it, otherwise use stdin */
  if (!arguments.input_file || strcmp (arguments.input_file, "-") == 0)
    input = stdin;

Changes to src/zdbs.c.

42
43
44
45
46
47
48


49
50
51
52
53
54
55
..
62
63
64
65
66
67
68

69
70
71
72
73
74
75
..
77
78
79
80
81
82
83











84
85
86
87
88
89
90
...
244
245
246
247
248
249
250

251
252
253
254
255
256
257
...
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},


  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {"input", (int)'i', "FILE", 0,
................................................................................
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t cache_size;

  bool no_mmap;
  bool no_lock;
  bool verbose;
  char *input_file;
  const char *delim;
  bool sync;
};
................................................................................
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {











    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
................................................................................
  struct arguments arguments;
  int mode = ZDB_WRITER;
  error_t argp_result;
  int result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;

  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;
  arguments.sync = false;
  arguments.input_file = NULL;
  arguments.delim = "|";

................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                       arguments.cache_size, arguments.verbose);

  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", arguments.args[0]);

  /* if an input file was provided, use it, otherwise use stdin */
  if (!arguments.input_file || strcmp (arguments.input_file, "-") == 0)
    input = stdin;







>
>







 







>







 







>
>
>
>
>
>
>
>
>
>
>







 







>







 







|
>







42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
..
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
...
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
...
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size",   (int)'m', "NUM", 0,
   "The size (in bytes) of the memory-mapped region to use (default=1024)", 0},
  {"cache-size", (int)'c', "NUM", 0,
   "The bucket cache size to use (default=128)", 0},
  {"block-size", (int)'c', "NUM", 0,
   "The block size to use (default=512)", 0},
  {"no-mmap", (int)'n', (const char *)NULL, 0,
   "Do not memory-map the database file", 0},
  {"no-lock", (int)'l', (const char *)NULL, 0,
   "Do not perform any locking of the database file", 0},
  {"verbose", (int)'v', (const char *)NULL, 0,
   "Print extra information.", 0},
  {"input", (int)'i', "FILE", 0,
................................................................................
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t cache_size;
  size_t block_size;
  bool no_mmap;
  bool no_lock;
  bool verbose;
  char *input_file;
  const char *delim;
  bool sync;
};
................................................................................
static error_t
parse_opt (int key, char *arg, struct argp_state *state)
{
  struct arguments *arguments = state->input;
  unsigned long int size;
  switch (key)
    {
    case 'b':
      size = arg ? strtoul (arg, NULL, 10) : 512UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
        {
          arguments->cache_size = (size_t)size;
        }
      break;
    case 'c':
      size = arg ? strtoul (arg, NULL, 10) : 128UL;
      if (size > SIZE_MAX)
        {
          arguments->cache_size = SIZE_MAX;
        }
      else
................................................................................
  struct arguments arguments;
  int mode = ZDB_WRITER;
  error_t argp_result;
  int result;

  arguments.mmap_size = 1024;
  arguments.cache_size = 128;
  arguments.block_size = 512;
  arguments.no_mmap = false;
  arguments.no_lock = false;
  arguments.verbose = false;
  arguments.sync = false;
  arguments.input_file = NULL;
  arguments.delim = "|";

................................................................................
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;

  /* open the database */
  database = zdb_open (arguments.args[0], mode, arguments.mmap_size,
                       arguments.cache_size, arguments.block_size,
                       arguments.verbose);
  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", arguments.args[0]);

  /* if an input file was provided, use it, otherwise use stdin */
  if (!arguments.input_file || strcmp (arguments.input_file, "-") == 0)
    input = stdin;