1999-08-13 09:37:52 +04:00
|
|
|
/************************************************
|
|
|
|
|
|
|
|
sdbminit.c -
|
|
|
|
|
|
|
|
$Author$
|
|
|
|
created at: Fri May 7 08:34:24 JST 1999
|
|
|
|
|
2001-02-14 08:52:06 +03:00
|
|
|
Copyright (C) 1995-2001 Yukihiro Matsumoto
|
1999-08-13 09:37:52 +04:00
|
|
|
|
|
|
|
************************************************/
|
|
|
|
|
|
|
|
#include "ruby.h"
|
|
|
|
|
|
|
|
#include "sdbm.h"
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2002-02-27 07:52:21 +03:00
|
|
|
static VALUE rb_cDBM, rb_eDBMError;
|
1999-08-13 09:37:52 +04:00
|
|
|
|
|
|
|
struct dbmdata {
|
|
|
|
int di_size;
|
|
|
|
DBM *di_dbm;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
closed_sdbm()
|
|
|
|
{
|
2002-02-27 07:52:21 +03:00
|
|
|
rb_raise(rb_eDBMError, "closed SDBM file");
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GetDBM(obj, dbmp) {\
|
|
|
|
Data_Get_Struct(obj, struct dbmdata, dbmp);\
|
2004-12-09 10:31:22 +03:00
|
|
|
if (dbmp == 0) closed_sdbm();\
|
1999-08-13 09:37:52 +04:00
|
|
|
if (dbmp->di_dbm == 0) closed_sdbm();\
|
|
|
|
}
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
#define GetDBM2(obj, data, dbm) {\
|
|
|
|
GetDBM(obj, data);\
|
|
|
|
(dbm) = dbmp->di_dbm;\
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:37:52 +04:00
|
|
|
static void
|
2006-02-13 07:53:22 +03:00
|
|
|
free_sdbm(struct dbmdata *dbmp)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (dbmp->di_dbm) sdbm_close(dbmp->di_dbm);
|
* array.c, bignum.c, cont.c, dir.c, dln.c, encoding.c, enumerator.c,
enumerator.c (enumerator_allocate), eval_jump.c, file.c, hash.c,
io.c, load.c, pack.c, proc.c, random.c, re.c, ruby.c, st.c,
string.c, thread.c, thread_pthread.c, time.c, util.c, variable.c,
vm.c, gc.c:
allocated memory objects by xmalloc (ruby_xmalloc) should be
freed by xfree (ruby_xfree).
* ext/curses/curses.c, ext/dbm/dbm.c, ext/digest/digest.c,
ext/gdbm/gdbm.c, ext/json/ext/parser/parser.c,
ext/json/ext/parser/unicode.c, ext/openssl/ossl_cipher.c,
ext/openssl/ossl_hmac.c, ext/openssl/ossl_pkey_ec.c,
ext/sdbm/init.c, ext/strscan/strscan.c, ext/zlib/zlib.c:
ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-06-08 14:01:40 +04:00
|
|
|
ruby_xfree(dbmp);
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_close(VALUE obj)
|
2001-05-06 19:06:00 +04:00
|
|
|
{
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
|
|
|
|
GetDBM(obj, dbmp);
|
|
|
|
sdbm_close(dbmp->di_dbm);
|
|
|
|
dbmp->di_dbm = 0;
|
|
|
|
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2005-06-20 12:17:53 +04:00
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_closed(VALUE obj)
|
2005-06-20 12:17:53 +04:00
|
|
|
{
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
|
|
|
|
Data_Get_Struct(obj, struct dbmdata, dbmp);
|
|
|
|
if (dbmp == 0)
|
|
|
|
return Qtrue;
|
|
|
|
if (dbmp->di_dbm == 0)
|
|
|
|
return Qtrue;
|
|
|
|
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
2002-02-27 07:52:21 +03:00
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_alloc(VALUE klass)
|
2002-02-27 07:52:21 +03:00
|
|
|
{
|
2002-12-20 14:30:13 +03:00
|
|
|
return Data_Wrap_Struct(klass, 0, free_sdbm, 0);
|
2002-02-27 07:52:21 +03:00
|
|
|
}
|
|
|
|
|
2001-05-06 19:06:00 +04:00
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_initialize(int argc, VALUE *argv, VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
VALUE file, vmode;
|
|
|
|
DBM *dbm;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
if (rb_scan_args(argc, argv, "11", &file, &vmode) == 1) {
|
|
|
|
mode = 0666; /* default value */
|
|
|
|
}
|
|
|
|
else if (NIL_P(vmode)) {
|
|
|
|
mode = -1; /* return nil if DB not exist */
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
mode = NUM2INT(vmode);
|
|
|
|
}
|
2008-10-20 12:05:44 +04:00
|
|
|
FilePathValue(file);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
|
|
|
dbm = 0;
|
|
|
|
if (mode >= 0)
|
2006-08-31 14:30:33 +04:00
|
|
|
dbm = sdbm_open(RSTRING_PTR(file), O_RDWR|O_CREAT, mode);
|
1999-08-13 09:37:52 +04:00
|
|
|
if (!dbm)
|
2006-08-31 14:30:33 +04:00
|
|
|
dbm = sdbm_open(RSTRING_PTR(file), O_RDWR, 0);
|
1999-08-13 09:37:52 +04:00
|
|
|
if (!dbm)
|
2006-08-31 14:30:33 +04:00
|
|
|
dbm = sdbm_open(RSTRING_PTR(file), O_RDONLY, 0);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
|
|
|
if (!dbm) {
|
|
|
|
if (mode == -1) return Qnil;
|
2006-08-31 14:30:33 +04:00
|
|
|
rb_sys_fail(RSTRING_PTR(file));
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
2001-05-06 19:06:00 +04:00
|
|
|
dbmp = ALLOC(struct dbmdata);
|
|
|
|
DATA_PTR(obj) = dbmp;
|
1999-08-13 09:37:52 +04:00
|
|
|
dbmp->di_dbm = dbm;
|
|
|
|
dbmp->di_size = -1;
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2001-05-06 19:06:00 +04:00
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_s_open(int argc, VALUE *argv, VALUE klass)
|
2001-05-06 19:06:00 +04:00
|
|
|
{
|
|
|
|
VALUE obj = Data_Wrap_Struct(klass, 0, free_sdbm, 0);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2001-05-06 19:06:00 +04:00
|
|
|
if (NIL_P(fsdbm_initialize(argc, argv, obj))) {
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rb_block_given_p()) {
|
|
|
|
return rb_ensure(rb_yield, obj, fsdbm_close, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_fetch(VALUE obj, VALUE keystr, VALUE ifnone)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, value;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
|
2008-10-20 12:05:44 +04:00
|
|
|
ExportStringValue(keystr);
|
2006-08-31 14:30:33 +04:00
|
|
|
key.dptr = RSTRING_PTR(keystr);
|
|
|
|
key.dsize = RSTRING_LEN(keystr);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
value = sdbm_fetch(dbm, key);
|
|
|
|
if (value.dptr == 0) {
|
2000-07-04 11:04:42 +04:00
|
|
|
if (ifnone == Qnil && rb_block_given_p())
|
2008-10-20 12:05:44 +04:00
|
|
|
return rb_yield(rb_external_str_new(key.dptr, key.dsize));
|
2000-07-04 11:04:42 +04:00
|
|
|
return ifnone;
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
2008-10-20 12:05:44 +04:00
|
|
|
return rb_external_str_new(value.dptr, value.dsize);
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
2000-07-04 11:04:42 +04:00
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_aref(VALUE obj, VALUE keystr)
|
2000-07-04 11:04:42 +04:00
|
|
|
{
|
|
|
|
return fsdbm_fetch(obj, keystr, Qnil);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_fetch_m(int argc, VALUE *argv, VALUE obj)
|
2000-07-04 11:04:42 +04:00
|
|
|
{
|
2001-05-06 19:06:00 +04:00
|
|
|
VALUE keystr, valstr, ifnone;
|
2000-07-04 11:04:42 +04:00
|
|
|
|
|
|
|
rb_scan_args(argc, argv, "11", &keystr, &ifnone);
|
2001-05-06 19:06:00 +04:00
|
|
|
valstr = fsdbm_fetch(obj, keystr, ifnone);
|
|
|
|
if (argc == 1 && !rb_block_given_p() && NIL_P(valstr))
|
|
|
|
rb_raise(rb_eIndexError, "key not found");
|
|
|
|
|
|
|
|
return valstr;
|
2000-07-04 11:04:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2008-11-08 01:07:05 +03:00
|
|
|
fsdbm_key(VALUE obj, VALUE valstr)
|
2000-07-04 11:04:42 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
|
2008-10-20 12:05:44 +04:00
|
|
|
ExportStringValue(valstr);
|
2006-08-31 14:30:33 +04:00
|
|
|
val.dptr = RSTRING_PTR(valstr);
|
|
|
|
val.dsize = RSTRING_LEN(valstr);
|
2000-07-04 11:04:42 +04:00
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
2000-07-04 11:04:42 +04:00
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2006-08-31 14:30:33 +04:00
|
|
|
if (val.dsize == RSTRING_LEN(valstr) &&
|
|
|
|
memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0)
|
2008-10-20 12:05:44 +04:00
|
|
|
return rb_external_str_new(key.dptr, key.dsize);
|
2000-07-04 11:04:42 +04:00
|
|
|
}
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2008-11-08 01:07:05 +03:00
|
|
|
static VALUE
|
|
|
|
fsdbm_index(VALUE hash, VALUE value)
|
|
|
|
{
|
|
|
|
rb_warn("SDBM#index is deprecated; use SDBM#key");
|
|
|
|
return fsdbm_key(hash, value);
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:37:52 +04:00
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_select(VALUE obj)
|
2002-02-27 07:52:21 +03:00
|
|
|
{
|
2004-06-11 17:33:47 +04:00
|
|
|
VALUE new = rb_ary_new();
|
|
|
|
datum key, val;
|
|
|
|
DBM *dbm;
|
|
|
|
struct dbmdata *dbmp;
|
2002-02-27 07:52:21 +03:00
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
2004-06-11 17:33:47 +04:00
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
2004-12-09 05:19:50 +03:00
|
|
|
VALUE assoc, v;
|
2004-06-11 17:33:47 +04:00
|
|
|
val = sdbm_fetch(dbm, key);
|
2008-10-20 12:05:44 +04:00
|
|
|
assoc = rb_assoc_new(rb_external_str_new(key.dptr, key.dsize),
|
|
|
|
rb_external_str_new(val.dptr, val.dsize));
|
2004-12-09 05:19:50 +03:00
|
|
|
v = rb_yield(assoc);
|
|
|
|
if (RTEST(v)) {
|
2004-06-11 17:33:47 +04:00
|
|
|
rb_ary_push(new, assoc);
|
2004-12-09 05:19:50 +03:00
|
|
|
}
|
|
|
|
GetDBM2(obj, dbmp, dbm);
|
2002-02-27 07:52:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2003-05-06 10:51:31 +04:00
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_values_at(int argc, VALUE *argv, VALUE obj)
|
2003-05-06 10:51:31 +04:00
|
|
|
{
|
|
|
|
VALUE new = rb_ary_new2(argc);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<argc; i++) {
|
|
|
|
rb_ary_push(new, fsdbm_fetch(obj, argv[i], Qnil));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
2004-05-07 12:44:24 +04:00
|
|
|
static void
|
2006-02-13 07:53:22 +03:00
|
|
|
fdbm_modify(VALUE obj)
|
2004-05-07 12:44:24 +04:00
|
|
|
{
|
|
|
|
rb_secure(4);
|
2004-05-08 12:12:08 +04:00
|
|
|
if (OBJ_FROZEN(obj)) rb_error_frozen("SDBM");
|
2004-05-07 12:44:24 +04:00
|
|
|
}
|
|
|
|
|
1999-08-13 09:37:52 +04:00
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_delete(VALUE obj, VALUE keystr)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, value;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
2002-02-27 07:52:21 +03:00
|
|
|
VALUE valstr;
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2004-05-07 12:44:24 +04:00
|
|
|
fdbm_modify(obj);
|
2008-10-20 12:05:44 +04:00
|
|
|
ExportStringValue(keystr);
|
2006-08-31 14:30:33 +04:00
|
|
|
key.dptr = RSTRING_PTR(keystr);
|
|
|
|
key.dsize = RSTRING_LEN(keystr);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
2001-05-06 19:06:00 +04:00
|
|
|
dbmp->di_size = -1;
|
1999-08-13 09:37:52 +04:00
|
|
|
|
|
|
|
value = sdbm_fetch(dbm, key);
|
|
|
|
if (value.dptr == 0) {
|
2002-02-27 07:52:21 +03:00
|
|
|
if (rb_block_given_p()) return rb_yield(keystr);
|
1999-08-13 09:37:52 +04:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2002-02-27 07:52:21 +03:00
|
|
|
/* need to save value before sdbm_delete() */
|
2008-10-20 12:05:44 +04:00
|
|
|
valstr = rb_external_str_new(value.dptr, value.dsize);
|
2002-02-27 07:52:21 +03:00
|
|
|
|
1999-08-13 09:37:52 +04:00
|
|
|
if (sdbm_delete(dbm, key)) {
|
|
|
|
dbmp->di_size = -1;
|
2002-02-27 07:52:21 +03:00
|
|
|
rb_raise(rb_eDBMError, "dbm_delete failed");
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
else if (dbmp->di_size >= 0) {
|
|
|
|
dbmp->di_size--;
|
|
|
|
}
|
2002-02-27 07:52:21 +03:00
|
|
|
return valstr;
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_shift(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
VALUE keystr, valstr;
|
|
|
|
|
2004-05-07 12:44:24 +04:00
|
|
|
fdbm_modify(obj);
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
key = sdbm_firstkey(dbm);
|
|
|
|
if (!key.dptr) return Qnil;
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2008-10-20 12:05:44 +04:00
|
|
|
keystr = rb_external_str_new(key.dptr, key.dsize);
|
|
|
|
valstr = rb_external_str_new(val.dptr, val.dsize);
|
2001-05-06 19:06:00 +04:00
|
|
|
sdbm_delete(dbm, key);
|
|
|
|
if (dbmp->di_size >= 0) {
|
|
|
|
dbmp->di_size--;
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:37:52 +04:00
|
|
|
return rb_assoc_new(keystr, valstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_delete_if(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
VALUE keystr, valstr;
|
2001-05-06 19:06:00 +04:00
|
|
|
VALUE ret, ary = rb_ary_new();
|
|
|
|
int i, status = 0, n;
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2004-05-07 12:44:24 +04:00
|
|
|
fdbm_modify(obj);
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
2001-05-06 19:06:00 +04:00
|
|
|
n = dbmp->di_size;
|
|
|
|
dbmp->di_size = -1;
|
1999-08-13 09:37:52 +04:00
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2008-10-20 12:05:44 +04:00
|
|
|
keystr = rb_external_str_new(key.dptr, key.dsize);
|
|
|
|
valstr = rb_external_str_new(val.dptr, val.dsize);
|
2001-05-06 19:06:00 +04:00
|
|
|
ret = rb_protect(rb_yield, rb_assoc_new(rb_str_dup(keystr), valstr), &status);
|
|
|
|
if (status != 0) break;
|
|
|
|
if (RTEST(ret)) rb_ary_push(ary, keystr);
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
2001-05-06 19:06:00 +04:00
|
|
|
}
|
|
|
|
|
2006-09-02 18:42:08 +04:00
|
|
|
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
|
|
|
keystr = RARRAY_PTR(ary)[i];
|
2008-10-20 12:05:44 +04:00
|
|
|
ExportStringValue(keystr);
|
2006-08-31 14:30:33 +04:00
|
|
|
key.dptr = RSTRING_PTR(keystr);
|
|
|
|
key.dsize = RSTRING_LEN(keystr);
|
2001-05-06 19:06:00 +04:00
|
|
|
if (sdbm_delete(dbm, key)) {
|
2002-02-27 07:52:21 +03:00
|
|
|
rb_raise(rb_eDBMError, "sdbm_delete failed");
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
}
|
2001-05-06 19:06:00 +04:00
|
|
|
if (status) rb_jump_tag(status);
|
2006-09-02 18:42:08 +04:00
|
|
|
if (n > 0) dbmp->di_size = n - RARRAY_LEN(ary);
|
2001-05-06 19:06:00 +04:00
|
|
|
|
1999-08-13 09:37:52 +04:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_clear(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
|
2004-05-07 12:44:24 +04:00
|
|
|
fdbm_modify(obj);
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
dbmp->di_size = -1;
|
2001-05-06 19:06:00 +04:00
|
|
|
while (key = sdbm_firstkey(dbm), key.dptr) {
|
1999-08-13 09:37:52 +04:00
|
|
|
if (sdbm_delete(dbm, key)) {
|
2002-02-27 07:52:21 +03:00
|
|
|
rb_raise(rb_eDBMError, "sdbm_delete failed");
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
}
|
2001-05-06 19:06:00 +04:00
|
|
|
dbmp->di_size = 0;
|
|
|
|
|
1999-08-13 09:37:52 +04:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_invert(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
VALUE keystr, valstr;
|
|
|
|
VALUE hash = rb_hash_new();
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2008-10-20 12:05:44 +04:00
|
|
|
keystr = rb_external_str_new(key.dptr, key.dsize);
|
|
|
|
valstr = rb_external_str_new(val.dptr, val.dsize);
|
1999-08-13 09:37:52 +04:00
|
|
|
rb_hash_aset(hash, valstr, keystr);
|
|
|
|
}
|
2001-05-06 19:06:00 +04:00
|
|
|
return hash;
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_store(VALUE obj, VALUE keystr, VALUE valstr)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
|
|
|
|
if (valstr == Qnil) {
|
|
|
|
fsdbm_delete(obj, keystr);
|
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
2004-05-07 12:44:24 +04:00
|
|
|
fdbm_modify(obj);
|
2008-10-20 12:05:44 +04:00
|
|
|
ExportStringValue(keystr);
|
|
|
|
ExportStringValue(valstr);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2006-08-31 14:30:33 +04:00
|
|
|
key.dptr = RSTRING_PTR(keystr);
|
|
|
|
key.dsize = RSTRING_LEN(keystr);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2006-08-31 14:30:33 +04:00
|
|
|
val.dptr = RSTRING_PTR(valstr);
|
|
|
|
val.dsize = RSTRING_LEN(valstr);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
dbmp->di_size = -1;
|
|
|
|
if (sdbm_store(dbm, key, val, DBM_REPLACE)) {
|
|
|
|
#ifdef HAVE_DBM_CLAERERR
|
|
|
|
sdbm_clearerr(dbm);
|
|
|
|
#endif
|
|
|
|
if (errno == EPERM) rb_sys_fail(0);
|
2002-02-27 07:52:21 +03:00
|
|
|
rb_raise(rb_eDBMError, "sdbm_store failed");
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return valstr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
update_i(VALUE pair, VALUE dbm)
|
|
|
|
{
|
|
|
|
Check_Type(pair, T_ARRAY);
|
2006-09-02 18:42:08 +04:00
|
|
|
if (RARRAY_LEN(pair) < 2) {
|
2006-02-13 07:53:22 +03:00
|
|
|
rb_raise(rb_eArgError, "pair must be [key, value]");
|
|
|
|
}
|
2006-09-02 18:42:08 +04:00
|
|
|
fsdbm_store(dbm, RARRAY_PTR(pair)[0], RARRAY_PTR(pair)[1]);
|
2006-02-13 07:53:22 +03:00
|
|
|
return Qnil;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
fsdbm_update(VALUE obj, VALUE other)
|
|
|
|
{
|
|
|
|
rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
fsdbm_replace(VALUE obj, VALUE other)
|
|
|
|
{
|
|
|
|
fsdbm_clear(obj);
|
|
|
|
rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
fsdbm_length(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
int i = 0;
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
if (dbmp->di_size > 0) return INT2FIX(dbmp->di_size);
|
|
|
|
|
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
dbmp->di_size = i;
|
|
|
|
|
|
|
|
return INT2FIX(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_empty_p(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
int i = 0;
|
|
|
|
|
2000-06-16 11:44:16 +04:00
|
|
|
GetDBM(obj, dbmp);
|
1999-08-13 09:37:52 +04:00
|
|
|
if (dbmp->di_size < 0) {
|
|
|
|
dbm = dbmp->di_dbm;
|
|
|
|
|
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
i = dbmp->di_size;
|
|
|
|
}
|
|
|
|
if (i == 0) return Qtrue;
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_each_value(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
|
* ext/dbm/dbm.c (fdbm_each_value, fdbm_each_key, fdbm_each_pair):
GDBM#{each,each_pair,each_key,each_value}: Return an enumerator
if no block is given.
* ext/gdbm/gdbm.c (fgdbm_each_value, fgdbm_each_key,
fgdbm_each_pair): GDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/openssl/ossl_config.c (ossl_config_each):
OpenSSL::Config#each: Return an enumerator if no block is given.
* ext/readline/readline.c (hist_each): Readline::HISTORY#each:
Return an enumerator if no block is given.
* ext/sdbm/init.c (fsdbm_each_value, fsdbm_each_key,
fsdbm_each_pair): SDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/stringio/stringio.c (strio_each_byte, strio_each):
StringIO#{each,each_line,each_byte}: Return an enumerator if no
block is given.
* ext/stringio/stringio.c (Init_stringio): Add #lines and #bytes,
which are aliases to #each_line and #each_byte, respectively.
* ext/win32ole/win32ole.c (fole_each): WIN32OLE#each: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (rb_gzreader_each_byte, rb_gzreader_each):
Zlib::GzipReader#{each,each_line,each_byte}: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (Init_zlib): Add Zlib::GzipReader#lines and
#bytes, which are aliases to #each_line and #each_byte,
respectively.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-21 12:48:33 +04:00
|
|
|
RETURN_ENUMERATOR(obj, 0, 0);
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2008-10-20 12:05:44 +04:00
|
|
|
rb_yield(rb_external_str_new(val.dptr, val.dsize));
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_each_key(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
|
* ext/dbm/dbm.c (fdbm_each_value, fdbm_each_key, fdbm_each_pair):
GDBM#{each,each_pair,each_key,each_value}: Return an enumerator
if no block is given.
* ext/gdbm/gdbm.c (fgdbm_each_value, fgdbm_each_key,
fgdbm_each_pair): GDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/openssl/ossl_config.c (ossl_config_each):
OpenSSL::Config#each: Return an enumerator if no block is given.
* ext/readline/readline.c (hist_each): Readline::HISTORY#each:
Return an enumerator if no block is given.
* ext/sdbm/init.c (fsdbm_each_value, fsdbm_each_key,
fsdbm_each_pair): SDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/stringio/stringio.c (strio_each_byte, strio_each):
StringIO#{each,each_line,each_byte}: Return an enumerator if no
block is given.
* ext/stringio/stringio.c (Init_stringio): Add #lines and #bytes,
which are aliases to #each_line and #each_byte, respectively.
* ext/win32ole/win32ole.c (fole_each): WIN32OLE#each: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (rb_gzreader_each_byte, rb_gzreader_each):
Zlib::GzipReader#{each,each_line,each_byte}: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (Init_zlib): Add Zlib::GzipReader#lines and
#bytes, which are aliases to #each_line and #each_byte,
respectively.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-21 12:48:33 +04:00
|
|
|
RETURN_ENUMERATOR(obj, 0, 0);
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
2008-10-20 12:05:44 +04:00
|
|
|
rb_yield(rb_external_str_new(key.dptr, key.dsize));
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_each_pair(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
DBM *dbm;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
VALUE keystr, valstr;
|
|
|
|
|
* ext/dbm/dbm.c (fdbm_each_value, fdbm_each_key, fdbm_each_pair):
GDBM#{each,each_pair,each_key,each_value}: Return an enumerator
if no block is given.
* ext/gdbm/gdbm.c (fgdbm_each_value, fgdbm_each_key,
fgdbm_each_pair): GDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/openssl/ossl_config.c (ossl_config_each):
OpenSSL::Config#each: Return an enumerator if no block is given.
* ext/readline/readline.c (hist_each): Readline::HISTORY#each:
Return an enumerator if no block is given.
* ext/sdbm/init.c (fsdbm_each_value, fsdbm_each_key,
fsdbm_each_pair): SDBM#{each,each_pair,each_key,each_value}:
Return an enumerator if no block is given.
* ext/stringio/stringio.c (strio_each_byte, strio_each):
StringIO#{each,each_line,each_byte}: Return an enumerator if no
block is given.
* ext/stringio/stringio.c (Init_stringio): Add #lines and #bytes,
which are aliases to #each_line and #each_byte, respectively.
* ext/win32ole/win32ole.c (fole_each): WIN32OLE#each: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (rb_gzreader_each_byte, rb_gzreader_each):
Zlib::GzipReader#{each,each_line,each_byte}: Return an
enumerator if no block is given.
* ext/zlib/zlib.c (Init_zlib): Add Zlib::GzipReader#lines and
#bytes, which are aliases to #each_line and #each_byte,
respectively.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16125 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-04-21 12:48:33 +04:00
|
|
|
RETURN_ENUMERATOR(obj, 0, 0);
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2008-10-20 12:05:44 +04:00
|
|
|
keystr = rb_external_str_new(key.dptr, key.dsize);
|
|
|
|
valstr = rb_external_str_new(val.dptr, val.dsize);
|
1999-08-13 09:37:52 +04:00
|
|
|
rb_yield(rb_assoc_new(keystr, valstr));
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_keys(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
VALUE ary;
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
ary = rb_ary_new();
|
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
2008-10-20 12:05:44 +04:00
|
|
|
rb_ary_push(ary, rb_external_str_new(key.dptr, key.dsize));
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_values(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
VALUE ary;
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
ary = rb_ary_new();
|
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2008-10-20 12:05:44 +04:00
|
|
|
rb_ary_push(ary, rb_external_str_new(val.dptr, val.dsize));
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_has_key(VALUE obj, VALUE keystr)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
|
2008-10-20 12:05:44 +04:00
|
|
|
ExportStringValue(keystr);
|
2006-08-31 14:30:33 +04:00
|
|
|
key.dptr = RSTRING_PTR(keystr);
|
|
|
|
key.dsize = RSTRING_LEN(keystr);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
val = sdbm_fetch(dbm, key);
|
|
|
|
if (val.dptr) return Qtrue;
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_has_value(VALUE obj, VALUE valstr)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
|
2008-10-20 12:05:44 +04:00
|
|
|
ExportStringValue(valstr);
|
2006-08-31 14:30:33 +04:00
|
|
|
val.dptr = RSTRING_PTR(valstr);
|
|
|
|
val.dsize = RSTRING_LEN(valstr);
|
1999-08-13 09:37:52 +04:00
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2006-08-31 14:30:33 +04:00
|
|
|
if (val.dsize == RSTRING_LEN(valstr) &&
|
|
|
|
memcmp(val.dptr, RSTRING_PTR(valstr), val.dsize) == 0)
|
1999-08-13 09:37:52 +04:00
|
|
|
return Qtrue;
|
|
|
|
}
|
|
|
|
return Qfalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_to_a(VALUE obj)
|
1999-08-13 09:37:52 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
VALUE ary;
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
1999-08-13 09:37:52 +04:00
|
|
|
ary = rb_ary_new();
|
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2008-10-20 12:05:44 +04:00
|
|
|
rb_ary_push(ary, rb_assoc_new(rb_external_str_new(key.dptr, key.dsize),
|
|
|
|
rb_external_str_new(val.dptr, val.dsize)));
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
2000-07-04 11:04:42 +04:00
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_to_hash(VALUE obj)
|
2000-07-04 11:04:42 +04:00
|
|
|
{
|
|
|
|
datum key, val;
|
|
|
|
struct dbmdata *dbmp;
|
|
|
|
DBM *dbm;
|
|
|
|
VALUE hash;
|
|
|
|
|
2004-12-09 05:19:50 +03:00
|
|
|
GetDBM2(obj, dbmp, dbm);
|
2000-07-04 11:04:42 +04:00
|
|
|
hash = rb_hash_new();
|
|
|
|
for (key = sdbm_firstkey(dbm); key.dptr; key = sdbm_nextkey(dbm)) {
|
|
|
|
val = sdbm_fetch(dbm, key);
|
2008-10-20 12:05:44 +04:00
|
|
|
rb_hash_aset(hash, rb_external_str_new(key.dptr, key.dsize),
|
|
|
|
rb_external_str_new(val.dptr, val.dsize));
|
2000-07-04 11:04:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
2006-02-13 07:53:22 +03:00
|
|
|
fsdbm_reject(VALUE obj)
|
2000-07-04 11:04:42 +04:00
|
|
|
{
|
|
|
|
return rb_hash_delete_if(fsdbm_to_hash(obj));
|
|
|
|
}
|
|
|
|
|
1999-08-13 09:37:52 +04:00
|
|
|
void
|
|
|
|
Init_sdbm()
|
|
|
|
{
|
2002-02-27 07:52:21 +03:00
|
|
|
rb_cDBM = rb_define_class("SDBM", rb_cObject);
|
|
|
|
rb_eDBMError = rb_define_class("SDBMError", rb_eStandardError);
|
|
|
|
rb_include_module(rb_cDBM, rb_mEnumerable);
|
|
|
|
|
2002-12-20 14:30:13 +03:00
|
|
|
rb_define_alloc_func(rb_cDBM, fsdbm_alloc);
|
2002-02-27 07:52:21 +03:00
|
|
|
rb_define_singleton_method(rb_cDBM, "open", fsdbm_s_open, -1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cDBM, "initialize", fsdbm_initialize, -1);
|
|
|
|
rb_define_method(rb_cDBM, "close", fsdbm_close, 0);
|
2005-06-20 12:17:53 +04:00
|
|
|
rb_define_method(rb_cDBM, "closed?", fsdbm_closed, 0);
|
2002-02-27 07:52:21 +03:00
|
|
|
rb_define_method(rb_cDBM, "[]", fsdbm_aref, 1);
|
|
|
|
rb_define_method(rb_cDBM, "fetch", fsdbm_fetch_m, -1);
|
|
|
|
rb_define_method(rb_cDBM, "[]=", fsdbm_store, 2);
|
|
|
|
rb_define_method(rb_cDBM, "store", fsdbm_store, 2);
|
|
|
|
rb_define_method(rb_cDBM, "index", fsdbm_index, 1);
|
2008-11-08 06:15:28 +03:00
|
|
|
rb_define_method(rb_cDBM, "key", fsdbm_key, 1);
|
2004-06-11 17:33:47 +04:00
|
|
|
rb_define_method(rb_cDBM, "select", fsdbm_select, 0);
|
2003-05-06 10:51:31 +04:00
|
|
|
rb_define_method(rb_cDBM, "values_at", fsdbm_values_at, -1);
|
2002-02-27 07:52:21 +03:00
|
|
|
rb_define_method(rb_cDBM, "length", fsdbm_length, 0);
|
|
|
|
rb_define_method(rb_cDBM, "size", fsdbm_length, 0);
|
|
|
|
rb_define_method(rb_cDBM, "empty?", fsdbm_empty_p, 0);
|
|
|
|
rb_define_method(rb_cDBM, "each", fsdbm_each_pair, 0);
|
|
|
|
rb_define_method(rb_cDBM, "each_value", fsdbm_each_value, 0);
|
|
|
|
rb_define_method(rb_cDBM, "each_key", fsdbm_each_key, 0);
|
|
|
|
rb_define_method(rb_cDBM, "each_pair", fsdbm_each_pair, 0);
|
|
|
|
rb_define_method(rb_cDBM, "keys", fsdbm_keys, 0);
|
|
|
|
rb_define_method(rb_cDBM, "values", fsdbm_values, 0);
|
|
|
|
rb_define_method(rb_cDBM, "shift", fsdbm_shift, 0);
|
|
|
|
rb_define_method(rb_cDBM, "delete", fsdbm_delete, 1);
|
|
|
|
rb_define_method(rb_cDBM, "delete_if", fsdbm_delete_if, 0);
|
|
|
|
rb_define_method(rb_cDBM, "reject!", fsdbm_delete_if, 0);
|
|
|
|
rb_define_method(rb_cDBM, "reject", fsdbm_reject, 0);
|
|
|
|
rb_define_method(rb_cDBM, "clear", fsdbm_clear, 0);
|
|
|
|
rb_define_method(rb_cDBM,"invert", fsdbm_invert, 0);
|
|
|
|
rb_define_method(rb_cDBM,"update", fsdbm_update, 1);
|
|
|
|
rb_define_method(rb_cDBM,"replace", fsdbm_replace, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cDBM, "include?", fsdbm_has_key, 1);
|
|
|
|
rb_define_method(rb_cDBM, "has_key?", fsdbm_has_key, 1);
|
|
|
|
rb_define_method(rb_cDBM, "member?", fsdbm_has_key, 1);
|
|
|
|
rb_define_method(rb_cDBM, "has_value?", fsdbm_has_value, 1);
|
|
|
|
rb_define_method(rb_cDBM, "key?", fsdbm_has_key, 1);
|
|
|
|
rb_define_method(rb_cDBM, "value?", fsdbm_has_value, 1);
|
|
|
|
|
|
|
|
rb_define_method(rb_cDBM, "to_a", fsdbm_to_a, 0);
|
|
|
|
rb_define_method(rb_cDBM, "to_hash", fsdbm_to_hash, 0);
|
1999-08-13 09:37:52 +04:00
|
|
|
}
|