Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
blackwinter committed Jan 18, 2012
0 parents commit ef82664
Show file tree
Hide file tree
Showing 24 changed files with 2,405 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
doc
doc.local
pkg
tmp
.gh-pages
1 change: 1 addition & 0 deletions .rspec
@@ -0,0 +1 @@
--colour
663 changes: 663 additions & 0 deletions COPYING

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions ChangeLog
@@ -0,0 +1,5 @@
= Revision history for libcdb-ruby

== 0.0.1 [2012-01-12]

* Birthday :-)
96 changes: 96 additions & 0 deletions README
@@ -0,0 +1,96 @@
= libcdb-ruby - Ruby bindings for CDB Constant Databases.

== VERSION

This documentation refers to libcdb-ruby version 0.0.1


== DESCRIPTION

The libcdb-ruby library provides Ruby bindings for the
TinyCDB[http://corpit.ru/mjt/tinycdb.html] package for
creating and reading {constant databases}[http://cr.yp.to/cdb.html].

require 'libcdb'

# creating
LibCDB::CDB.open('foo.cdb', 'w') { |cdb|
cdb['a'] = 'one'
cdb['b'] = '123'
}

# reading
LibCDB::CDB.open('foo.cdb') { |cdb|
cdb['a'] #=> "one"
cdb['b'] #=> "123"
cdb['c'] #=> nil
}

# hybrid
LibCDB::CDB.open('foo.cdb', 'w+') { |cdb|
cdb['a'] = 'one'
cdb['b'] = '123'

cdb['a'] #=> "one"
cdb['b'] #=> "123"
cdb['c'] #=> nil

cdb['a'] = 'two'
cdb['c'] = 'xyz'

cdb['a'] #=> "two"
cdb['b'] #=> nil
cdb['c'] #=> "xyz"
}

# update existing database
LibCDB::CDB.open('foo.cdb', 'r+') { |cdb|
cdb.store(cdb.to_h)

cdb['d'] = '42'

cdb['a'] #=> "two"
cdb['b'] #=> nil
cdb['c'] #=> "xyz"
cdb['d'] #=> "42"
}


== SUPPORTED PLATFORMS

Linux:: 1.8 & 1.9
Windows:: 1.9 only


== LINKS

<b></b>
Documentation:: http://blackwinter.github.com/libcdb-ruby
Source code:: http://github.com/blackwinter/libcdb-ruby
RubyGem:: http://rubygems.org/gems/libcdb-ruby
TinyCDB:: http://corpit.ru/mjt/tinycdb.html
CDB:: http://cr.yp.to/cdb.html


== AUTHORS

* Jens Wille <mailto:jens.wille@uni-koeln.de>


== LICENSE AND COPYRIGHT

Copyright (C) 2012 University of Cologne,
Albertus-Magnus-Platz, 50923 Cologne, Germany

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

libcdb-ruby is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
License for more details.

You should have received a copy of the GNU Affero General Public License
along with libcdb-ruby. If not, see <http://www.gnu.org/licenses/>.
30 changes: 30 additions & 0 deletions Rakefile
@@ -0,0 +1,30 @@
require File.expand_path(%q{../lib/libcdb/version}, __FILE__)

begin
require 'hen'

cco = []

if dir = ENV['TINYCDB']
cco << "--with-cdb-include=#{dir}"
cco << "--with-cdb-lib=#{dir}"
end

if dir = ENV['MINGW32']
cco << "--with-cflags=\"-I#{dir}/include -L#{dir}/lib\""
end

Hen.lay! {{
:gem => {
:name => %q{libcdb-ruby},
:version => LibCDB::CDB::VERSION,
:summary => %q{Ruby bindings for CDB Constant Databases.},
:author => %q{Jens Wille},
:email => %q{jens.wille@uni-koeln.de},
:homepage => :blackwinter,
:extension => { :cross_config_options => cco }
}
}}
rescue LoadError => err
warn "Please install the `hen' gem. (#{err})"
end
4 changes: 4 additions & 0 deletions TODO
@@ -0,0 +1,4 @@
* More specs!!
* More Documentation!
* Atomic updates? (rename after create)
* Benchmarks?
11 changes: 11 additions & 0 deletions ext/libcdb/extconf.rb
@@ -0,0 +1,11 @@
require 'mkmf'

dir_config('cdb')

if have_library('cdb', 'cdb_init') && have_header('cdb.h') && have_macro('TINYCDB_VERSION', 'cdb.h')
have_header('ruby/io.h')
have_header('ruby/st.h')
create_makefile('libcdb/libcdb_ruby')
else
abort '*** ERROR: missing required library to compile this module'
end
16 changes: 16 additions & 0 deletions ext/libcdb/libcdb.c
@@ -0,0 +1,16 @@
#include "ruby_libcdb.h"

void
Init_libcdb_ruby(void) {
char libcdb_version[8];
snprintf(libcdb_version, 7, "%g", TINYCDB_VERSION);

/*
* LibCDB namespace.
*/
mLibCDB = rb_define_module("LibCDB");

rcdb_init_cdb();
rcdb_init_reader();
rcdb_init_writer();
}
8 changes: 8 additions & 0 deletions ext/libcdb/libcdb_ruby.def
@@ -0,0 +1,8 @@
LIBRARY libcdb_ruby.so
EXPORTS
Init_libcdb_ruby

cCDBReader DATA
cCDBWriter DATA
mLibCDB DATA
cCDB DATA
15 changes: 15 additions & 0 deletions ext/libcdb/ruby_cdb.c
@@ -0,0 +1,15 @@
#include "ruby_libcdb.h"

void
rcdb_init_cdb(void) {
char libcdb_version[8];
snprintf(libcdb_version, 7, "%g", TINYCDB_VERSION);

/*
* See README.
*/
cCDB = rb_define_class_under(mLibCDB, "CDB", rb_cObject);

/* The TinyCDB library version. */
rb_define_const(cCDB, "LIBCDB_VERSION", rb_str_new2(libcdb_version));
}
13 changes: 13 additions & 0 deletions ext/libcdb/ruby_cdb.h
@@ -0,0 +1,13 @@
#ifndef __RUBY_CDB_H__
#define __RUBY_CDB_H__

#ifdef HAVE_RUBY_IO_H
#define GetFileFD(fptr) (fptr)->fd
#else
#define GetFileFD(fptr) fileno((fptr)->f)
#endif

VALUE cCDB;
void rcdb_init_cdb(void);

#endif /* __RUBY_CDB_H__ */

0 comments on commit ef82664

Please sign in to comment.