Not logged in

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

Overview
Comment:add support for new database-opening flags
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:70910f4055671e66fba58e76822026f22928ae3e
User & Date: brandon 2016-05-26 21:16:51
Context
2016-05-27
19:08
clean up some warnings check-in: 3143e34e51 user: brandon tags: trunk
2016-05-26
21:16
add support for new database-opening flags check-in: 70910f4055 user: brandon tags: trunk
20:12
Always create a new database with zdbc * zdb.c (zdb_open): Always create a new database check-in: f717a40f6d user: brandon tags: trunk
Changes

Changes to ChangeLog.







1
2
3
4
5
6
7






2013-11-17  Brandon Invergo  <brandon@invergo.net>

	* configure.ac: Add tests

	* Makefile.am: Add tests

2013-11-13  Brandon Invergo  <brandon@invergo.net>
>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
2016-05-26  Brandon Invergo  <brandon@invergo.net>

	* src/zdb.c (zdb_open): Always create a new database with zdbc.
	Support more open flags: sync, no-mmap, and no-lock
	* src/zdb*.c (main): Support extra opening flags

2013-11-17  Brandon Invergo  <brandon@invergo.net>

	* configure.ac: Add tests

	* Makefile.am: Add tests

2013-11-13  Brandon Invergo  <brandon@invergo.net>

Changes to src/zdb.c.

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
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

96
97
98
99
100
101
102
103
104
105
106
107
108
109
   along with zeptodb.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "zdb.h"

void *
zdb_create (char *dbfile, size_t mmap_size, size_t num_buckets,
            bool verbose)
{
  void *db;
  if (verbose)
    printf ("Creating database %s\n", dbfile);
#ifdef HAVE_KYOTOCABINET
  char mmap_str[32];
  char buckets_str[32];
................................................................................
  void *db;
  if (verbose)
    printf ("Opening database %s\n", dbfile);
#ifdef HAVE_KYOTOCABINET
  KCDB *database;
  int32_t res;
  database = kcdbnew ();
  switch (mode)
    {
    case ZDB_READER:

      res = kcdbopen (database, dbfile, KCOREADER);
      break;
    case ZDB_WRITER:
      res = kcdbopen (database, dbfile, KCOWRITER);
      break;
    case ZDB_CREATOR:


      res = kcdbopen (database, dbfile, KCOCREATE);
      break;
    }
  if (!res)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", dbfile);
  db = database;
#else
  GDBM_FILE database;
  switch (mode)
    {

    case ZDB_READER:


      database = gdbm_open (dbfile, 512, GDBM_READER,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, NULL);
      break;
    case ZDB_WRITER:
      database = gdbm_open (dbfile, 512, GDBM_WRITER,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, NULL);
      break;
    case ZDB_CREATOR:

      database = gdbm_open (dbfile, 512, GDBM_NEWDB,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP, NULL);
      break;
    }
  if (!database)
    error (EXIT_FAILURE, errno,
           "Failed to open database %s", dbfile);
  db = (void *)database;
#endif
  return db;
}

int
zdb_close (void *db, bool verbose)







|







 







|
<
|
>
|
|
|
|
|
|
>
>
|
<
<

<
|



<
<
>
|
>
>
|
|
|
|
|
|
|
|
>
|
|
<
<

<
|







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
..
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
96
97
98


99

100
101
102
103
104
105
106
107
   along with zeptodb.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "zdb.h"

void *
zdb_create (char *dbfile, size_t mmap_size, size_t num_buckets,
            bool verbose, int mode)
{
  void *db;
  if (verbose)
    printf ("Creating database %s\n", dbfile);
#ifdef HAVE_KYOTOCABINET
  char mmap_str[32];
  char buckets_str[32];
................................................................................
  void *db;
  if (verbose)
    printf ("Opening database %s\n", dbfile);
#ifdef HAVE_KYOTOCABINET
  KCDB *database;
  int32_t res;
  database = kcdbnew ();
  int kc_mode = 0;

  if ((mode & ZDB_READER) == ZDB_READER)
    kc_mode ^= KCOREADER;
  else if ((mode & ZDB_WRITER) == ZDB_WRITER)
    kc_mode ^= KCOWRITER;
  else if ((mode & ZDB_CREATOR) == ZDB_CREATOR)
    kc_mode ^= KCOCREATE;
  if ((mode & ZDB_SYNC) == ZDB_SYNC)
    kc_mode ^= KCOAUTOSYNC;
  if ((mode & ZDB_NOLOCK) == ZDB_NOLOCK)
    kc_mode ^= KCONOLOCK;
  res = kcdbopen (database, dbfile, KCOREADER);


  if (!res)

    error (EXIT_FAILURE, errno, "Failed to open database %s", dbfile);
  db = database;
#else
  GDBM_FILE database;


  int gdbm_mode = 0;
  if ((mode & ZDB_READER) == ZDB_READER)
    gdbm_mode ^= GDBM_READER;
  else if ((mode & ZDB_WRITER) == ZDB_WRITER)
    gdbm_mode ^= GDBM_WRITER;
  else if ((mode & ZDB_CREATOR) == ZDB_CREATOR)
    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);
  db = (void *)database;
#endif
  return db;
}

int
zdb_close (void *db, bool verbose)

Changes to src/zdb.h.

1
2
3
4
5
6
7
8
9
10
..
34
35
36
37
38
39
40
41
42
43



44
45
46
47
48
49
50
51
52
53
54
55
/* zdb.h

   Copyright © 2013 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................

#ifdef HAVE_KYOTOCABINET
#include <kclangc.h>
#else
#include <gdbm.h>
#endif

#define ZDB_READER 0
#define ZDB_WRITER 1
#define ZDB_CREATOR 2




void *zdb_create (char *, unsigned long int, unsigned long int, bool);
void *zdb_open (char *, int, bool);
int zdb_close (void *, bool);
int zdb_store (void *, char *, size_t, char *, size_t, bool);
void printrec (char *, char *, char *);
int zdb_fetch (void *, char *, size_t, char *);
int zdb_fetchall (void *, char *);
int zdb_remove (void *, char *, size_t, bool);
int zdb_reorganize (void *);

#endif


|







 







|
|
|
>
>
>

|










1
2
3
4
5
6
7
8
9
10
..
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* zdb.h

   Copyright © 2013, 2016 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................

#ifdef HAVE_KYOTOCABINET
#include <kclangc.h>
#else
#include <gdbm.h>
#endif

#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

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

#endif

Changes to src/zdbc.c.

1
2
3
4
5
6
7
8
9
10
..
26
27
28
29
30
31
32
33

34
35






36
37
38
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
93
94
95
96
97
98
99
100
...
110
111
112
113
114
115
116

117
118





119
120
121
122
123
124
125
126
127
128
129









130
131
132
133
134
135
136
137
138
139
140
141
142
/* zdbc.c

   Copyright © 2013 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................

static char doc[] =
  "zdbc -- a tool for creating a DBM database";

static char args_doc[] = "DATABASE";

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

  {"num-buckets", 'b', "NUM", 0, "The number of buckets to use (default=100)"},
  {"verbose", 'v', 0, 0, "Print extra information."},






  {0}
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t num_buckets;
  const char *delim;




  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 'm':
      size = arg ? strtoul (arg, NULL, 10) : 1024;
      if (size > sizeof(size_t) || size <= 0)
        {
          arguments->mmap_size = sizeof(size_t);
        }
      else
        {
          arguments->mmap_size = (size_t)size;
        }
      break;

    case 'b':
      size = arg ? strtoul (arg, NULL, 10) : 100;
      if (size > sizeof(size_t) || size <= 0)
        {
          arguments->num_buckets = sizeof(size_t);
        }
      else
        {
          arguments->num_buckets = (size_t)size;
        }
      break;






















    case 'v':
      arguments->verbose = true;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= 1)
        argp_usage (state);
      arguments->args[state->arg_num] = arg;
      break;

    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static struct argp argp = { options, parse_opt, args_doc, doc };
................................................................................
}

int
main (int argc, char **argv)
{
  FILE *input;
  struct arguments arguments;


  arguments.verbose = false;





  arguments.mmap_size = 1024;
  arguments.num_buckets = 10;

  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  if (signal (SIGINT, termination_handler) == SIG_IGN)
    signal (SIGINT, SIG_IGN);
  if (signal (SIGHUP, termination_handler) == SIG_IGN)
    signal (SIGHUP, SIG_IGN);
  if (signal (SIGTERM, termination_handler) == SIG_IGN)
    signal (SIGTERM, SIG_IGN);










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

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


|







 







|
>


>
>
>
>
>
>








|
>
>
>
>










<
<
<
<
<
<
<
<
<
<
<
<











>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<





<




<







 







>


>
>
>
>
>











>
>
>
>
>
>
>
>
>



|









1
2
3
4
5
6
7
8
9
10
..
26
27
28
29
30
31
32
33
34
35
36
37
38
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
93
94
95
96
97
98
99
100
101

102
103
104
105
106

107
108
109
110

111
112
113
114
115
116
117
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
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
/* zdbc.c

   Copyright © 2013, 2016 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................

static char doc[] =
  "zdbc -- a tool for creating a DBM database";

static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"mmap-size", 'm', "NUM", 0, "The size (in bytes) of the memory-mapped region"
   " to use (default=1024)"},
  {"num-buckets", 'b', "NUM", 0, "The number of buckets to use (default=100)"},
  {"verbose", 'v', 0, 0, "Print extra information."},
  {"sync", 's', 0, 0, "Automatically synchronize all database operations to the"
   " disk"},
  {"no-lock", 'l', 0, 0, "Do not perform any locking of the database file"},
#ifdef HAVE_GDBM
  {"no-mmap", 'n', 0, 0, "Do not memory-map the database file"},
#endif
  {0}
};

struct arguments
{
  char *args[1];
  size_t mmap_size;
  size_t num_buckets;
  bool sync;
  bool no_lock;
#ifdef HAVE_GDBM
  bool no_mmap;
#endif
  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) : 100;
      if (size > sizeof(size_t) || size <= 0)
        {
          arguments->num_buckets = sizeof(size_t);
        }
      else
        {
          arguments->num_buckets = (size_t)size;
        }
      break;
    case 'l':
      arguments->no_lock = true;
      break;
    case 'm':
      size = arg ? strtoul (arg, NULL, 10) : 1024;
      if (size > sizeof(size_t) || size <= 0)
        {
          arguments->mmap_size = sizeof(size_t);
        }
      else
        {
          arguments->mmap_size = (size_t)size;
        }
      break;
#ifdef HAVE_GDBM
    case 'n':
      arguments->no_mmap = true;
      break;
#endif
    case 's':
      arguments->sync = true;
      break;
    case 'v':
      arguments->verbose = true;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= 1)
        argp_usage (state);
      arguments->args[state->arg_num] = arg;
      break;

    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static struct argp argp = { options, parse_opt, args_doc, doc };
................................................................................
}

int
main (int argc, char **argv)
{
  FILE *input;
  struct arguments arguments;
  int mode = ZDB_CREATOR;

  arguments.verbose = false;
  arguments.sync = false;
  arguments.no_lock = false;
#ifdef HAVE_GDBM
  arguments.no_mmap = false;
#endif
  arguments.mmap_size = 1024;
  arguments.num_buckets = 10;

  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  if (signal (SIGINT, termination_handler) == SIG_IGN)
    signal (SIGINT, SIG_IGN);
  if (signal (SIGHUP, termination_handler) == SIG_IGN)
    signal (SIGHUP, SIG_IGN);
  if (signal (SIGTERM, termination_handler) == SIG_IGN)
    signal (SIGTERM, SIG_IGN);

  if (arguments.sync)
    mode ^= ZDB_SYNC;
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
#ifdef HAVE_GDBM
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;
#endif

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

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

Changes to src/zdbf.c.

1
2
3
4
5
6
7
8
9
10
..
32
33
34
35
36
37
38






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
93
94
...
144
145
146
147
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
/* zdbf.c

   Copyright © 2011, 2012, 2013 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"input", 'i', "FILE", 0, "Read queries from a file"},
  {"all", 'a', 0, 0, "Fetch all the records in the database"},
  {"delim", 'd', "CHAR", 0, "Character to print between keys and values."
   "Keys will not be printed if left unspecified."},






  {"verbose", 'v', 0, 0, "Print extra information."},
  {0}
};

struct arguments
{
  char *args[1];
  char *input_file;
  bool all;
  char *delim;





  bool verbose;
};

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

  switch (key)
    {
    case 'i':
      arguments->input_file = arg;
      break;

    case 'a':
      arguments->all = true;
      break;

    case 'd':
      if (strlen (arg) > 1)
        argp_usage (state);
      arguments->delim = arg;
      break;















    case 'v':
      arguments->verbose = true;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= 1)
        argp_usage (state);
      arguments->args[state->arg_num] = arg;
      break;

    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static struct argp argp = { options, parse_opt, args_doc, doc };
................................................................................
}

int
main (int argc, char **argv)
{
  FILE *input;
  struct arguments arguments;








  arguments.input_file = "-";
  arguments.all = false;
  arguments.verbose = false;
  arguments.delim = NULL;

  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  if (signal (SIGINT, termination_handler) == SIG_IGN)
    signal (SIGINT, SIG_IGN);
  if (signal (SIGHUP, termination_handler) == SIG_IGN)
    signal (SIGHUP, SIG_IGN);
  if (signal (SIGTERM, termination_handler) == SIG_IGN)
    signal (SIGTERM, SIG_IGN);










  /* open the database */
  database = zdb_open (arguments.args[0], ZDB_READER, 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)


|







 







>
>
>
>
>
>










>
>
>
>
>










<
<
<
<



<





<
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<





<




<







 







>
>
>
>
>
>
>
>


<











>
>
>
>
>
>
>
>
>

|







1
2
3
4
5
6
7
8
9
10
..
32
33
34
35
36
37
38
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
93
94

95
96
97
98
99

100
101
102
103

104
105
106
107
108
109
110
...
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176

177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* zdbf.c

   Copyright © 2011, 2012, 2013, 2016 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................
static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"input", 'i', "FILE", 0, "Read queries from a file"},
  {"all", 'a', 0, 0, "Fetch all the records in the database"},
  {"delim", 'd', "CHAR", 0, "Character to print between keys and values."
   "Keys will not be printed if left unspecified."},
  {"sync", 's', 0, 0, "Automatically synchronize all database operations to the"
   " disk"},
  {"no-lock", 'l', 0, 0, "Do not perform any locking of the database file"},
#ifdef HAVE_GDBM
  {"no-mmap", 'n', 0, 0, "Do not memory-map the database file"},
#endif
  {"verbose", 'v', 0, 0, "Print extra information."},
  {0}
};

struct arguments
{
  char *args[1];
  char *input_file;
  bool all;
  char *delim;
  bool sync;
  bool no_lock;
#ifdef HAVE_GDBM
  bool no_mmap;
#endif
  bool verbose;
};

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

  switch (key)
    {




    case 'a':
      arguments->all = true;
      break;

    case 'd':
      if (strlen (arg) > 1)
        argp_usage (state);
      arguments->delim = arg;
      break;

    case 'i':
      arguments->input_file = arg;
      break;
    case 'l':
      arguments->no_lock = true;
      break;
#ifdef HAVE_GDBM
    case 'n':
      arguments->no_mmap = true;
      break;
#endif
    case 's':
      arguments->sync = true;
      break;
    case 'v':
      arguments->verbose = true;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= 1)
        argp_usage (state);
      arguments->args[state->arg_num] = arg;
      break;

    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static struct argp argp = { options, parse_opt, args_doc, doc };
................................................................................
}

int
main (int argc, char **argv)
{
  FILE *input;
  struct arguments arguments;
  int mode = ZDB_READER;

  arguments.verbose = false;
  arguments.sync = false;
  arguments.no_lock = false;
#ifdef HAVE_GDBM
  arguments.no_mmap = false;
#endif
  arguments.input_file = "-";
  arguments.all = false;

  arguments.delim = NULL;

  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  if (signal (SIGINT, termination_handler) == SIG_IGN)
    signal (SIGINT, SIG_IGN);
  if (signal (SIGHUP, termination_handler) == SIG_IGN)
    signal (SIGHUP, SIG_IGN);
  if (signal (SIGTERM, termination_handler) == SIG_IGN)
    signal (SIGTERM, SIG_IGN);

  if (arguments.sync)
    mode ^= ZDB_SYNC;
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
#ifdef HAVE_GDBM
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;
#endif

  /* open the database */
  database = zdb_open (arguments.args[0], mode, 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/zdbr.c.

1
2
3
4
5
6
7
8
9
10
..
34
35
36
37
38
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
...
138
139
140
141
142
143
144
145
146









147
148
149
150
151
152
153
154
155
156
157
158
159









160
161
162
163
164
165
166
167
168
/* zdbr.c

   Copyright © 2011, 2012, 2013 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................
  "removed";

static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"input", 'i', "FILE", 0, "Read queries from a file"},
  {"reorganize", 'r', 0, 0, "Reorganize the database"},






  {"verbose", 'v', 0, 0, "Print extra information."},
  {0}
};

struct arguments
{
  char *args[1];
  char *input_file;
  bool reorg;





  bool verbose;
};

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

  switch (key)
    {
    case 'i':
      arguments->input_file = arg;
      break;









    case 'r':
      arguments->reorg = true;
      break;



    case 'v':
      arguments->verbose = true;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= 1)
        argp_usage (state);
      arguments->args[state->arg_num] = arg;
      break;

    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static struct argp argp = { options, parse_opt, args_doc, doc };
................................................................................
}

int
main (int argc, char **argv)
{
  void *database;
  FILE *input;
  int res;
  struct arguments arguments;









  arguments.input_file = "-";
  arguments.reorg = false;
  arguments.verbose = false;

  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  if (signal (SIGINT, termination_handler) == SIG_IGN)
    signal (SIGINT, SIG_IGN);
  if (signal (SIGHUP, termination_handler) == SIG_IGN)
    signal (SIGHUP, SIG_IGN);
  if (signal (SIGTERM, termination_handler) == SIG_IGN)
    signal (SIGTERM, SIG_IGN);










  /* open the database */
  database = zdb_open (arguments.args[0], ZDB_WRITER, 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 (strcmp (arguments.input_file, "-") == 0)
    input = stdin;


|







 







>
>
>
>
>
>









>
>
>
>
>













<
>
>
>
>
>
>
>
>



|
>
>



<





<




<







 







<

>
>
>
>
>
>
>
>
>


<










>
>
>
>
>
>
>
>
>

|







1
2
3
4
5
6
7
8
9
10
..
34
35
36
37
38
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
93
94
95

96
97
98
99

100
101
102
103
104
105
106
...
155
156
157
158
159
160
161

162
163
164
165
166
167
168
169
170
171
172
173

174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* zdbr.c

   Copyright © 2011, 2012, 2013, 2016 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................
  "removed";

static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"input", 'i', "FILE", 0, "Read queries from a file"},
  {"reorganize", 'r', 0, 0, "Reorganize the database"},
  {"sync", 's', 0, 0, "Automatically synchronize all database operations to the"
   " disk"},
  {"no-lock", 'l', 0, 0, "Do not perform any locking of the database file"},
#ifdef HAVE_GDBM
  {"no-mmap", 'n', 0, 0, "Do not memory-map the database file"},
#endif
  {"verbose", 'v', 0, 0, "Print extra information."},
  {0}
};

struct arguments
{
  char *args[1];
  char *input_file;
  bool reorg;
  bool sync;
  bool no_lock;
#ifdef HAVE_GDBM
  bool no_mmap;
#endif
  bool verbose;
};

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

  switch (key)
    {
    case 'i':
      arguments->input_file = arg;
      break;

    case 'l':
      arguments->no_lock = true;
      break;
#ifdef HAVE_GDBM
    case 'n':
      arguments->no_mmap = true;
      break;
#endif
    case 'r':
      arguments->reorg = true;
      break;
    case 's':
      arguments->sync = true;
      break;
    case 'v':
      arguments->verbose = true;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= 1)
        argp_usage (state);
      arguments->args[state->arg_num] = arg;
      break;

    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static struct argp argp = { options, parse_opt, args_doc, doc };
................................................................................
}

int
main (int argc, char **argv)
{
  void *database;
  FILE *input;

  struct arguments arguments;
  int mode = ZDB_WRITER;
  int res;

  arguments.verbose = false;
  arguments.sync = false;
  arguments.no_lock = false;
#ifdef HAVE_GDBM
  arguments.no_mmap = false;
#endif
  arguments.input_file = "-";
  arguments.reorg = false;


  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  if (signal (SIGINT, termination_handler) == SIG_IGN)
    signal (SIGINT, SIG_IGN);
  if (signal (SIGHUP, termination_handler) == SIG_IGN)
    signal (SIGHUP, SIG_IGN);
  if (signal (SIGTERM, termination_handler) == SIG_IGN)
    signal (SIGTERM, SIG_IGN);

  if (arguments.sync)
    mode ^= ZDB_SYNC;
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
#ifdef HAVE_GDBM
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;
#endif

  /* open the database */
  database = zdb_open (arguments.args[0], mode, 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 (strcmp (arguments.input_file, "-") == 0)
    input = stdin;

Changes to src/zdbs.c.

1
2
3
4
5
6
7
8
9
10
..
32
33
34
35
36
37
38






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
...
152
153
154
155
156
157
158

159
160






161
162
163
164
165
166
167
168
169
170
171
172
173









174
175
176
177
178
179
180
181
182
/* zdbs.c

   Copyright © 2011, 2012, 2013 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................

static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"input", 'i', "FILE", 0, "Read new records from a file"},
  {"delim", 'd', "CHAR", 0,
   "Character used to separate keys from values (default '|')"},






  {"verbose", 'v', 0, 0, "Print extra information."},
  {0}
};

struct arguments
{
  char *args[1];
  char *input_file;
  const char *delim;





  bool verbose;
};

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

  switch (key)
    {
    case 'i':
      arguments->input_file = arg;
      break;

    case 'd':
      if (strlen (arg) > 1)
        argp_usage (state);
      arguments->delim = arg;
      break;















    case 'v':
      arguments->verbose = true;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= 1)
        argp_usage (state);
      arguments->args[state->arg_num] = arg;
      break;

    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static struct argp argp = { options, parse_opt, args_doc, doc };
................................................................................
}

int
main (int argc, char **argv)
{
  FILE *input;
  struct arguments arguments;

  int result;







  arguments.input_file = "-";
  arguments.delim = "|";
  arguments.verbose = false;

  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  if (signal (SIGINT, termination_handler) == SIG_IGN)
    signal (SIGINT, SIG_IGN);
  if (signal (SIGHUP, termination_handler) == SIG_IGN)
    signal (SIGHUP, SIG_IGN);
  if (signal (SIGTERM, termination_handler) == SIG_IGN)
    signal (SIGTERM, SIG_IGN);










  /* open the database */
  database = zdb_open (arguments.args[0], ZDB_WRITER,  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 (strcmp (arguments.input_file, "-") == 0)
    input = stdin;


|







 







>
>
>
>
>
>









>
>
>
>
>










<
<
<
<





<
>
>
>
>
>
>
>
>
>
>
>
>
>
>



<





<




<







 







>


>
>
>
>
>
>


<










>
>
>
>
>
>
>
>
>

|







1
2
3
4
5
6
7
8
9
10
..
32
33
34
35
36
37
38
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
93
94
95

96
97
98
99

100
101
102
103
104
105
106
...
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* zdbs.c

   Copyright © 2011, 2012, 2013, 2016 Brandon Invergo <brandon@invergo.net>

   This file is part of zeptodb

   zeptodb is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
................................................................................

static char args_doc[] = "DATABASE";

static struct argp_option options[] = {
  {"input", 'i', "FILE", 0, "Read new records from a file"},
  {"delim", 'd', "CHAR", 0,
   "Character used to separate keys from values (default '|')"},
  {"sync", 's', 0, 0, "Automatically synchronize all database operations to the"
   " disk"},
  {"no-lock", 'l', 0, 0, "Do not perform any locking of the database file"},
#ifdef HAVE_GDBM
  {"no-mmap", 'n', 0, 0, "Do not memory-map the database file"},
#endif
  {"verbose", 'v', 0, 0, "Print extra information."},
  {0}
};

struct arguments
{
  char *args[1];
  char *input_file;
  const char *delim;
  bool sync;
  bool no_lock;
#ifdef HAVE_GDBM
  bool no_mmap;
#endif
  bool verbose;
};

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

  switch (key)
    {




    case 'd':
      if (strlen (arg) > 1)
        argp_usage (state);
      arguments->delim = arg;
      break;

    case 'i':
      arguments->input_file = arg;
      break;
    case 'l':
      arguments->no_lock = true;
      break;
#ifdef HAVE_GDBM
    case 'n':
      arguments->no_mmap = true;
      break;
#endif
    case 's':
      arguments->sync = true;
      break;
    case 'v':
      arguments->verbose = true;
      break;

    case ARGP_KEY_ARG:
      if (state->arg_num >= 1)
        argp_usage (state);
      arguments->args[state->arg_num] = arg;
      break;

    case ARGP_KEY_END:
      if (state->arg_num == 0)
        argp_usage (state);
      break;

    default:
      return ARGP_ERR_UNKNOWN;
    }
  return 0;
}

static struct argp argp = { options, parse_opt, args_doc, doc };
................................................................................
}

int
main (int argc, char **argv)
{
  FILE *input;
  struct arguments arguments;
  int mode = ZDB_WRITER;
  int result;

  arguments.verbose = false;
  arguments.sync = false;
  arguments.no_lock = false;
#ifdef HAVE_GDBM
  arguments.no_mmap = false;
#endif
  arguments.input_file = "-";
  arguments.delim = "|";


  argp_parse (&argp, argc, argv, 0, 0, &arguments);

  if (signal (SIGINT, termination_handler) == SIG_IGN)
    signal (SIGINT, SIG_IGN);
  if (signal (SIGHUP, termination_handler) == SIG_IGN)
    signal (SIGHUP, SIG_IGN);
  if (signal (SIGTERM, termination_handler) == SIG_IGN)
    signal (SIGTERM, SIG_IGN);

  if (arguments.sync)
    mode ^= ZDB_SYNC;
  if (arguments.no_lock)
    mode ^= ZDB_NOLOCK;
#ifdef HAVE_GDBM
  if (arguments.no_mmap)
    mode ^= ZDB_NOMMAP;
#endif

  /* open the database */
  database = zdb_open (arguments.args[0], mode,  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 (strcmp (arguments.input_file, "-") == 0)
    input = stdin;